Installing to NAND

= Installing to nand =

Once you have linux running from SD card and tuned for your device and application you can try installing it to the nand.

backup nand
dd if=/dev/nand of=/some/place/with/enough/space

You can attach an USB stick, ssh in from another machine, etc. ssh root@ dd if=/dev/nand | dd of=/some/file

To access original nanda partition

losetup -fro 16777216 /some/file

This should work so long as the original layout of the nand was correct. Check with sfdisk and nand-part to confirm that your layout matches.

build u-boot for nand
The u-boot-sunxi does not support booting from nand in the development branch(yet). A version close to the upstream sunxi u-boot with some fixes is available in the lichee-dev branch.

cd u-boot-sunxi git checkout origin/lichee-dev -b lichee-dev

The lychee-dev u-boot has useless default boot command. In include/configs/sun4i.h change this line:

#define CONFIG_BOOTCOMMAND    "fatload nand 0 0x43000000 script.bin; fatload nand 0 0x48000000 uImage; bootm 0x48000000\0"

If you wanted to set the default kernel arguments you could change the line (untested)

#define CONFIG_BOOTCOMMAND    "setenv bootargs root=/dev/nandb console=something some more kernel arguments;fatload nand 0 0x43000000 script.bin; fatload nand 0 0x48000000 uImage; bootm 0x48000000\0"

Now you can build u-boot.

make sun4i

install u-boot
mount /dev/nanda /mnt

Check that nanda filesystem size is 16MB (eg. with df), that the partition is 16MB and starts at 16MB offset. Some devices might have broken partition. See formatting flash below.

cp u-boot.bin /mnt/linux umount /mnt

install kernel
Default commandline is not passed by the above u-boot command so bake it into kernel.

cd linux-sunxi

In .config change the line

CONFIG_CMDLINE="console=ttyS0,115200 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:1280x1024p60 root=/dev/nandb rootwait panic=10"

Rebuild the kernle with the new commandline

make uImage

Copy the kernel to nanda

mount /dev/nanda /mnt cp arch/arm/boot/uImage /mnt/ umount /mnt

format nand
Look at your partition layout - original flash layout has about half dozen partitions.

cd sunxi-tools ./nand-part

check partition table copy 0: OK check partition table copy 1: OK  check partition table copy 2: OK  check partition table copy 3: OK  partition  0: name =   bootloader, partition start =    32768, partition size =    32768 partition 1: name =     A10-root, partition start =    65536, partition size =  5701632 2 partitions

Note that nanda is 16MB and it is at 16MB offset. 2x the size of nanda + size of nandb adds to size of nand. This is after repartitioning. To achieve this layout copy the name and length of nandb above (for 4G nand).

The nand-part tool will write the partition table (positioned at the first 16MB of the nand device) without actually touching the data in the filesystem, so the partitions wich the alignment doesn't change will remain accessible.

nand-part has two modes of operation: nand-part -f a20 /dev/nand 32768 'boot 32768' 'root 7405568'
 * If the option '-f a10' or '-f a20' is specified, all the partitions will have to be specified, such as:

In the above command will create a partition named 'boot' starting at 16MB (important), 16MB long, and a partition named 'root' 3616MB long (7405568/2/1024)

nand-part /dev/nand 'root 7405568' In the above command all the partitions after 'boot' will be removed and replaced with one called 'root' 3616MB long.
 * If the -f option is not specified, the start is not specified and the first 'boot' partition won't be touched, such as

Check with sfdisk that the partition layout changed. Reboot if you are unsure. Old kernels do not support repartitioning NAND.

sfdisk -s

/dev/nand:   3989504 /dev/nanda:    16384 /dev/nandb:  3956736

After reboot check that sfdisk output matches nand-part output. Create filesystem of your choice on nandb

mke2fs -j -L A10-root-nand /dev/nandb

As an additional note, some verions of Allwinner-boot will check that there is actually a partition called 'boot' and will not work otherwise.

copy files
Since my kernel sources are quite large and would not fit on the internal nand with gnome and whatnot I moved all the dev files to /opt and excluded it from the nand filesystem.

mount /dev/nandb /mnt cd / tar -cf - --exclude dev --exclude run --exclude proc --exclude sys --exclude tmp --exclude mnt --exclude opt. | tar -xvf - -C /mnt mkdir /mnt/{dev,run,proc,sys,tmp,mnt,opt} chmod 1777 /mnt/tmp