Sunday, June 20, 2010

UBIFS how to ^_^

UBIFS howto:


STEP 1:Install UBIFS tools with the follow packages. If you have the mkfs.ubifs then go to

Step 2 Use UBI
1. config kernel option and compile UBI / UBIFS /ext2 into the kernel
(1) Enable UBI and Emulate MTD devices
Path:
"Device Drivers"
-> "Memory Technology Device (MTD) support"
-> "UBI - Unsorted block images",

(2) Enable UBIFS
Path:
"File systems"
-> "Miscellaneous filesystems"
-> "UBIFS file system support"
(2) Enable Ext2
Path:
"File systems"
-> " Second extended fs support "

2. make image
(1)create UBIFS rootfs image
mkfs.ubifs -r filesys/ -m 4096 -e 516096 -c 2047 -o ubifs.img
ubinize -o ubi.img -m 4096 -p 512KiB ubinize.cfg

where ubinize.cfg contains:
[ubifs]
mode=ubi
image=ubifs.img --rootfs image name
vol_id=0
vol_size=128MiB --volume size
vol_type=dynamic
vol_name=ubifs ---UBI volume name
vol_flags=autoresize


3. mount rootfs
(1) mount ubifs root file system on redboot
fis load kernel
exec -c "noinitrd console=ttymxc0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs rw"

(*assume the kernel had 5 partitions. But the UBI will create new partition when attach the UBI ,so root=/dev/mtdblock6)

4 mount a partition via UBI
(1) ubifs
ubiformat /dev/mtdXX
ubiattach /dev/ubi_ctrl -m XX
ubimkvol /dev/ubi0 -N ubi_name -s 512MiB
mount -t ubifs ubi0:ubi_name /mnt/ubifs
ubiupdatevol /dev/ubi0_0 –t - wipe out an existing UBI volume


Note:
About -o sync option in mount, this will make UBIFS to run in synchronous mode, which will disable write-back cache and small write buffers.
If -o sync is not used in mount, then we should run “sync” (symbolic link to BusyBox), to sync write-back cache and small write buffers to NAND, before we reset Dickens.
Above being said, as we don’t have a mechanism to power down gracefully, UBIFS synchronous mode (-o sync) is recommended at this moment.

Monday, June 14, 2010

how to build mtd-utilities

1) Download mtd-utils from the link.

ftp://ftp.infradead.org/pub/mtd-utils/

(PS: Reference link http://elinux.org/CompilingMTDUtils)

2) Preparation for x86 build.

i) zlib
ii) lzo
iii) uuid

(PS: For ubuntu 10.04, user can install the packages from "Synaptic Package Manager" or "apt-get".)

3) Build with the following command.

WITHOUT_XATTR=1 make
sudo su
DESTDIR=/usr/local make install

To compile external mtd-utils-1.3.x, build e2fsprogs, lzo, zlib in ltib first. No need to modify the Makefile.

Then run the following:

Setting the following flags.

ZLIBCPPFLAGS="-I/home/usr/include" ZLIBLDFLAGS="-L/home/usr/lib" CROSS=arm-none-linux-gnueabi- WITHOUT_XATTR=1 make

Sunday, February 21, 2010

Adding new U-Boot commands

U-Boot providing interactive commands to end user but it may be necessary to add extra commands. There is a standard command interface
and it is defined in include/command.h. Every command defined a cmd_tbl_t structure.

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

struct cmd_tbl_s {
char *name; /* Command Name */
int maxargs; /* maximum number of arguments */
int repeatable; /* autorepeat allowed? */
/* Implementation function */
int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
char *usage; /* Usage message (short) */
#ifdef CONFIG_SYS_LONGHELP
char *help; /* Help message (long) */
#endif
#ifdef CONFIG_AUTO_COMPLETE
/* do auto completion on the arguments */
int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};

The command structure defined the name of the command, max number of the arguments, autorepeat, implementation function, usage and help.

The command console is defined in common/command.c. The find_cmd() is used to match the correspnding command function.

Below is an example to show how to read the cpu id.

#define read_cpuid(reg) \
({ \
unsigned int __val; \
asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
: "=r" (__val) \
: \
: "cc"); \
__val; \
})

int do_cpuid(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
printf("cpu id: %x\n", read_cpuid(0));
printf("cache type: %x\n", read_cpuid(1));
printf("chip id: %x\n", *(volatile unsigned int *)0xd4282c00);
return 0;
}

U_BOOT_CMD(
cpuid, 6, 1, do_cpuid,
"cpuid - read cpu id\n",
" - read cpu id\n"
);

Thursday, January 21, 2010

Uboot for PXA (2)

Compilation for UBOOT
=====================
Pre-request: User should install the corresponding cross tool chain in advance.

It is a very simple procedures, user has to choose the target platform first.

user:/home/user/u-boot-arm/make ARCH=arm CROSS_COMPILE=arm-marvel-linux-gnueabi- aspenite_config

Then user should able to build the uboot as below.

user:/home/user/u-boot-arm/make ARCH=arm CROSS_COMPILE=arm-marvel-linux-gnueabi-

(PS:The output binary is placed in the same directory.)

CPU directory
=============

uboot is starting from \u-boot-arm\cpu\pxa\start.s & it defined the standard arm reset vector table
as below.

.globl _start
_start: b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq

_undefined_instruction: .word undefined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abort: .word prefetch_abort
_data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word fiq

.balignl 16,0xdeadbeef

Below codes are impoerant & defined control by u-boot-arm\board\pxa\aspenite\u-boot.lds

_TEXT_BASE:
.word TEXT_BASE

.globl _armboot_start
_armboot_start:
.word _start

/*
* These are defined in the board-specific linker script.
*/
.globl _bss_start
_bss_start:
.word __bss_start

.globl _bss_end
_bss_end:
.word _end

Then it is the actual reset codes.

reset:
mrs r0,cpsr /* set the CPU to SVC32 mode */
bic r0,r0,#0x1f /* (superviser mode, M=10011) */
orr r0,r0,#0x13
msr cpsr,r0

Then it will call cpu_init_crit & performing very low level init stuffs. Normally, user no need to touch
these pieces of codes. It init clock, timer, interrupts & then determmine copy itself from flash into RAM (relocation) for execution.

The stack is setup as below.

_TEXT_BASE:
.word TEXT_BASE

.globl _armboot_start
_armboot_start:
.word _start

/*
* These are defined in the board-specific linker script.
*/
.globl _bss_start
_bss_start:
.word __bss_start

.globl _bss_end
_bss_end:
.word _end

Finally, it will jump to the C codes (Congrtulation ^_^)

ldr pc, _start_armboot

The start_armboot function is defined in lib_arm/board.c

cpu.c

It is defined those I-D caches function & doing IRQ setup if necessary.

interrupt.c

The pxa u-boot doesn't setup any interrupts.

serial.c

It is the serial port init, pxa_setbrg_dev().

Board directory
===============

Board directory mainly includes all the board specify stuffs.

u-boot.lds //linker script
aspenite_pxa168.c // development board init.

board_init() in the aspenite_pxa168.c is important, it enables clock, init gpio, regulator ...etc.

lib_arm directory
=================

start.s will finally call start_armboot and it is defined in /lib_arm/board.c

It is mainly call the mem_malloc_init function and all the peripherials init functions.

Conclusion
==========

The uboot is very powerful & it has many features to be explored.

Tuesday, January 19, 2010

Uboot for PXA (1)

UBOOT is a loader based on PPC boot loader.

The file structure is simply shown as below:

u-boot-arm
|_board
|_common
|_cpu
|_disk
|_doc
|_drivers
|_examples
|_fs
|_include
|_lib_arm
|_lib_avr32
|_lib_blackfin
|_lib_generic
|_lib_i386
|_lib_m68k
|_lib_microblaze
|_lib_mips
|_lib_nios
|_lib_nios2
|_lib_ppc
|_lib_sh
|_lib_sparc
|_libfdt
|_nand_spl
|_net
|_nenand_ipl
|_post
|_tools
...
...
...

board: All supporting target boards ard defined in this directory. For example \u-boot-arm\board\pxa\aspenite
A board_init function is defined in aspenite_168.c

cpu: All supoorting CPU type are defined in this directory. For example \u-boot-arm\cpu\pxa
All CPU env init including interrupts are defined. start.s is the first pieces of codes running
in the system. Its main task is to copy the whole uboot from flash into ram & start execution.

common: This is the directory stored all the uboot commands. We normally look at cmb_boot.c & cmd_bootm.c
It has the function to verify the kernel & doing decompression.)

drivers: This directory provides all the interface drivers.

fs: This directory provides all the supporting file system.

lib_arm: This directory providing all the common libraries for arm platform.

include: All headers are placed in this directory. For example u-boot-arm\include\asm-arm\arch-pxa & u-boot-arm\include\asm-arm\arch-pxa168