256MB NAND UBIFS Nand Boot¶
- Table of contents
- 256MB NAND UBIFS Nand Boot
NAND Partition Table¶
+------------+-->0x00000000-> SPL (128KB) start (SPL copy on 1st block) | | | |-->0x0001FFFF-> SPL end | |-->0x00020000-> SPL.backup1 (128KB) start (SPL copy on 2nd block) | | | |-->0x0003FFFF-> SPL.backup1 end | |-->0x00040000-> SPL.backup2 (128KB) start (SPL copy on 3rd block) | | | |-->0x0005FFFF-> SPL.backup2 end | |-->0x00060000-> SPL.backup3 (128KB) start (SPL copy on 4th block) | | | |-->0x0007FFFF-> SPL.backup3 end | |-->0x00080000-> U-Boot (1.875MB) start | | | |-->0x0025FFFF-> U-Boot end | |-->0x00260000-> ENV (128KB) start | | | | | |-->0x0027FFFF-> ENV end | |-->0x00280000-> Linux Kernel (5MB) start | | | | | | | | | |-->0x0077FFFF-> Linux Kernel end | |-->0x00780000-> File system (248.5MB) start | | | | | | | | | | | | | | | | | | | | | | | | +------------+-->0x10000000-> NAND end (Free end)
U-boot mtdparts
setenv mtdparts 'mtdparts=nand:128k@0(mlo),128k@128k(mlo1),128k@256k(mlo2),128k@384k(mlo3),1920k@512k(uboot),128k@2432k(env),5m@2560k(kernel),-@7680k(userfs)'
Creating UBIFS file system¶
Do this on PC. It is very slow on embedded device.
Copy files to SD card to be used during flash.
- Create config: ubinize.cfg
mtd-utils# vi ubinize.cfg [ubifs] <== Section header mode=ubi <== Volume mode (other option is static) image=ubifs.img <== Source image vol_id=0 <== Volume ID in UBI image vol_size=192MiB <== Volume size vol_type=dynamic <== Allow for dynamic resize vol_name=rootfs <== Volume name vol_flags=autoresize <== Autoresize volume at first mount
- Create image: ubi.img
sudo mkfs.ubifs -r filesystem/ -F -o ubifs.img -m 2048 -e 126976 -c 1580 ubinize -o ubi.img -m 2048 -p 128KiB -s 2048 -O 2048 ubinize.cfg
The -e option is the erase block size and the -c is the maximum logical erase block count. Note that 126976*1580=191MiB. Which sets the max size the filesystem can grow to.
Where "filesystem/" is an exported root filesystem less than 192MiB as set in the ubinize.cfg file. This can be increased to fit a larger filesystem by increasing the LEB (-c) number to 1965 which will fill the partition and give about 240.7MiB of filesystem space. The ubinize.cfg is set to autoresize so if the image is smaller than the available space it will expand to fit the first time ubiattach is called on it.
Note: The "-F" option enables free space fixup. The version of mkfs.ubifs that ships with older versions of ubuntu will probably not have this option. If you are using the ubiformat tool from linux to flash you image than you can do without it. If you are flashing from u-boot it is a necessary option and you may have to build the latest version of mtd-utils.
Flashing Nand from Linux¶
MLO, u-boot.img, and uImage can be found on first partition of sd card /media/mmcblk0p1
ubi.img was created above and should be able to fit on the third partition of sd card /media/mmcblk0p3
- Mount the boot partition of SD card and go to directory
- Flash MLO to Nand
flash_erase /dev/mtd1 0 0 nandwrite -p /dev/mtd1 MLO flash_erase /dev/mtd2 0 0 nandwrite -p /dev/mtd2 MLO flash_erase /dev/mtd3 0 0 nandwrite -p /dev/mtd3 MLO flash_erase /dev/mtd4 0 0 nandwrite -p /dev/mtd4 MLO
- Flash U-boot to Nand
flash_erase /dev/mtd5 0 0 nandwrite -p /dev/mtd5 u-boot.img
- Flash Kernel to Nand
flash_erase /dev/mtd7 0 0 nandwrite -p /dev/mtd7 uImage (or fitImage)
- Mount the partition of SD card with ubi.img and cd
- Flash Filesystem to Nand
ubiformat /dev/mtd8 -f ubi.img -s 2048 -O 2048 ubiattach -m 8 -O 2048 mount -t ubifs ubi0_0 /mnt/card sync
Flashing Nand from U-boot¶
MLO, u-boot.img, and uImage can be found on first partition of sd card /media/mmcblk0p1
ubi.img was created above and should be able to fit on the third partition of sd card /media/mmcblk0p3
Note: Writing the ubifs image from u-boot is not recommended.
http://lists.infradead.org/pipermail/linux-mtd/2011-June/035801.html
http://www.linux-mtd.infradead.org/faq/ubifs.html#L_free_space_fixup
- Erase all nand
nand erase.chip
- Flash MLO to Nand
mw.b $kloadaddr ff 40000 load mmc 0 $kloadaddr MLO nand write.i $kloadaddr 0 $filesize nand write.i $kloadaddr 20000 $filesize nand write.i $kloadaddr 40000 $filesize nand write.i $kloadaddr 60000 $filesize
- Flash U-boot to Nand
mw.b $kloadaddr ff 200000 load mmc 0 $kloadaddr u-boot.img nand write.i $kloadaddr 80000 $filesize
- Flash Kernel to Nand
mw.b $kloadaddr ff 500000 load mmc 0 $kloadaddr uImage (or fitImage) nand write.i $kloadaddr 280000 $filesize
- Flash Filesystem to Nand
ls mmc 0:3 <--- Copy filesize from output mw.b $kloadaddr 0xFF <filesize> load mmc 0:3 $kloadaddr ubi.img nand write.i $kloadaddr 0x00780000 <filesize> <---- Round up to block size (0x40000)
Mount ubifs image in Linux¶
ubiattach -m 8 -O 2048 mount -t ubifs ubi0:rootfs /mnt/nand sync <--- TI recommends running sync after first successful mount or boot
Booting from Nand¶
- Attached is a working uboot environment. Will boot from mmc if mmc card is present otherwise will boot nand.: uEnv-256mb-nand.txt
Minimal uboot environment:
bootcmd=run nand_boot; ip_method=none kloadaddr=0x80007fc0 nand_img_siz=0x500000 nand_root=ubi0:rootfs rw ubi.mtd=8,2048 nand_root_fs_type=ubifs rootwait=1 nand_src_addr=0x0280000 bootargs='console=${console} root=${nand_root} noinitrd rootfstype=${nand_root_fs_type} ip=${ip_method}' nand_boot=echo Booting from nand ...; nandecc hw 2; nand read.i ${kloadaddr} ${nand_src_addr} ${nand_img_siz}; bootm ${kloadaddr}
PLEASE NOTE: the
ubi0:rootfs
value in the nand_root
variable MUST match the vol_name
defined in the ubinize.cfg
file. For Yocto-generatedubifs images, the
vol_name
may be set to ${MACHINE}-rootfs
.* If you are having problems with booting, please confirm the volume name by mounting the
rootfs
from Linux:
root@mitysom-335x-512MB:~# mount -t ubifs ubi0_0 /mnt/nand [ 35.578779] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 2375 [ 35.682824] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "mitysom-335x-rootfs"
Raw kernel boot args
console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=8,2048 noinitrd rootfstype=ubifs rootwait=1 ip=none
Go to top