512MB NAND UBIFS Nand Boot¶
- Table of contents
- 512MB NAND UBIFS Nand Boot
NOTE 07-31-2013: Currently 512MB and greater nand is only supported in the mityarm-linux-v3.2 branch of the am335x kernel git and the CONFIG_NAND_MITYARM_LARGE_PAGE_SUPPORT must be enabled.
NOTE 10-25-2013: 512MB and greater nand are supported in the mityarm-linux-v3.2 branch of the am335x kernel git. This should auto-detect the bigger nand and choose the correct partition table and BCH.
NOTE 7-20-2020: For the 4.4 kernels and newer use device tree overlays to configure the correct nand. If booting from a fitimage, u-boot selects the correct overlay.
NAND Partition Table¶
+------------+-->0x00000000-> SPL (256KB) start (SPL copy on 1st block) | | | |-->0x0003FFFF-> SPL end | |-->0x00040000-> SPL.backup1 (256KB) start (SPL copy on 2nd block) | | | |-->0x0007FFFF-> SPL.backup1 end | |-->0x00080000-> SPL.backup2 (256KB) start (SPL copy on 3rd block) | | | |-->0x000bFFFF-> SPL.backup2 end | |-->0x000c0000-> SPL.backup3 (256KB) start (SPL copy on 4th block) | | | |-->0x000FFFFF-> SPL.backup3 end | |-->0x00100000-> U-Boot (2MB) start | | | |-->0x002FFFFF-> U-Boot end | |-->0x00300000-> ENV (256KB) start | | | | | |-->0x0033FFFF-> ENV end | |-->0x00340000-> Linux Kernel (5MB) start | | | | | | | | | |-->0x0083FFFF-> Linux Kernel end | |-->0x00840000-> File system (503.75MB) start | | | | | | | | | | | | | | | | | | | | | | | | +------------+-->0x20000000-> NAND end (Free end)
U-boot mtdparts
setenv mtdparts 'mtdparts=nand:256k@0(mlo),256k@256k(mlo1),256k@512k(mlo2),256k@768k(mlo3),2m@1m(uboot),256k@3m(env),5m@3328k(kernel),-@8448k(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 4096 -e 253952 -c 1580 ubinize -o ubi.img -m 4096 -p 256KiB -s 4096 -O 4096 ubinize.cfg
The -e option is the erase block size and the -c is the maximum logical erase block count. Note that 253952*1580=382MiB. 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 1991 which will fill the partition and give about 482MiB 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 4096 -O 4096 ubiattach -m 8 -O 4096 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 40000 $filesize nand write.i $kloadaddr 80000 $filesize nand write.i $kloadaddr c0000 $filesize
- Flash U-boot to Nand
mw.b $kloadaddr ff 200000 load mmc 0 $kloadaddr u-boot.img nand write.i $kloadaddr 100000 $filesize
- Flash Kernel to Nand
mw.b $kloadaddr ff 500000 load mmc 0 $kloadaddr uImage (or fitImage) nand write.i $kloadaddr 340000 $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 0x00840000 <filesize> <---- Round up to block size (0x40000)
Mount ubifs image in Linux¶
ubiattach -m 8 -O 4096 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-512mb-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,4096 nand_root_fs_type=ubifs rootwait=1 nand_src_addr=0x0340000 bootargs=console=${console} root=${nand_root} noinitrd rootfstype=${nand_root_fs_type} ip=${ip_method} nand_boot=echo Booting from nand ...; nandecc hw 1; 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-512MB-rootfs"
Raw kernel boot args
console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=8,4096 noinitrd rootfstype=ubifs rootwait=1 ip=none
Go to top