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

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.

  • 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;
nand_root=ubi0:rootfs rw ubi.mtd=8,4096
nand_root_fs_type=ubifs rootwait=1
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}

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: 600 MB)