Project

General

Profile

1GB NAND UBIFS Nand Boot

NOTE 10-25-2013: The 512MB and greater nand is 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. When booting from a fitimage, u-boot selects the correct overlay.

NAND Partition Table

+------------+-->0x00000000-> SPL (512KB) start         (SPL copy on 1st block)
|            |
|            |-->0x0007FFFF-> SPL end 
|            |-->0x00080000-> SPL.backup1 (512KB) start (SPL copy on 2nd block)
|            |
|            |-->0x000FFFFF-> SPL.backup1 end 
|            |-->0x00100000-> SPL.backup2 (512KB) start (SPL copy on 3rd block)
|            |
|            |-->0x0017FFFF-> SPL.backup2 end 
|            |-->0x00180000-> SPL.backup3 (512KB) start (SPL copy on 4th block)
|            |
|            |-->0x001FFFFF-> SPL.backup3 end
|            |-->0x00200000-> U-Boot (2MB) start
|            |                                    
|            |-->0x003FFFFF-> U-Boot end 
|            |-->0x00400000-> ENV (512KB) start
|            |
|            |
|            |-->0x0047FFFF-> ENV end
|            |-->0x00480000-> Linux Kernel (5MB) start
|            |
|            |
|            |
|            |
|            |-->0x0097FFFF-> Linux Kernel end
|            |-->0x00980000-> File system (1014MB) start
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
|            |
+------------+-->0x40000000-> NAND end (Free end)

U-boot mtdparts

setenv mtdparts 'mtdparts=nand:512k@0(mlo),512k@512k(mlo1),512k@1024k(mlo2),512k@1536k(mlo3),2m@2m(uboot),512k@4m(env),5m@4608k(kernel),-@9728k(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 516096 -c 2028
    ubinize -o ubi.img -m 4096 -p 512KiB -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 524288*2028=1014MiB. 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. 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  80000 $filesize
    nand write.i $kloadaddr 100000 $filesize
    nand write.i $kloadaddr 180000 $filesize
    
  • Flash U-boot to Nand
    mw.b $kloadaddr ff 200000
    load mmc 0 $kloadaddr u-boot.img
    nand write.i $kloadaddr 200000 $filesize
    
  • Flash Kernel to Nand
    mw.b $kloadaddr ff 500000
    load mmc 0 $kloadaddr uImage (or fitImage)
    nand write.i $kloadaddr 480000 $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=0x0480000
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-generated
ubifs 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-1GB-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
Add picture from clipboard (Maximum size: 1 GB)