HOWTO Build, flash, and boot from NAND flash on Variscite iMX6

The Variscite i.MX6 hardware can boot from either NAND flash or SD card. Flashing must be done from kernel userspace, and the following packages will need to be enabled to do so:

  • imx-kobs (provides kobs-ng)
  • Target mtd-utils (NAND utilities)

U-boot NAND config target

By default, Timesys provides bootloaders suitable for writing to SD card; in order to build U-boot binaries suitable for NAND flash, you need to reconfigure the U-boot config target. The default value is: mx6var_som_sd, this needs to be changed to: mx6var_som_nand. If you have previously built U-boot, you will need to distclean and re-build U-boot by issuing:

$ make u-boot-distclean && make

Once U-boot has been rebuilt for NAND, you will need to copy the following two files to your SD card, or into your NFS mounted rootfs, so that they can be flashed from userspace:

  • factory/build_armv7l-timesys-linux-gnueabi/images/bootloader/SPL
  • factory/build_armv7l-timesys-linux-gnueabi/images/bootloader/u-boot.img

If you also wish to flash kernel and UBIFS rootfs, copy the kernel uImage, dtb, and rootfs.ubi into your boot media/NFS as well. These are located at their respective directories in the Factory build_*/images/ directory, or contained within the installed SDK.

Variscite i.MX6 NAND partition

By default, the following partitions exist on the 512MB NAND flash part. Higher capacity NAND devices may differ.
You will be operating on /dev/mtd0 thru /dev/mtd3.

# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00200000 00020000 "spl" 
mtd1: 00200000 00020000 "bootloader" 
mtd2: 00600000 00020000 "kernel" 
mtd3: 1f600000 00020000 "rootfs" 
mtd4: 01000000 00020000 "android_boot" 
mtd5: 01c00000 00020000 "android_recovery" 
mtd6: 1d000000 00020000 "android_rootfs" 

Flashing U-boot SPL/u-boot.img

flash_eraseall /dev/mtd0 
kobs-ng init -x /path/to/SPL --search_exponent=1 -v
flash_eraseall /dev/mtd1 
nandwrite -p /dev/mtd1 /path/to/u-boot.img

Flashing Kernel image

In userspace:

flash_eraseall /dev/mtd2
nandwrite -p /dev/mtd2 /path/to/uImage
nandwrite -p /dev/mtd1 -s 0x1e0000 /path/to/var_dvk_mx6.dtb

Flashing UBIFS rootfs

In userspace:

flash_eraseall /dev/mtd3
ubiformat /dev/mtd3 -f /path/to/rootfs.ubi -s 2048 -O 2048

U-boot arguments to boot from NAND

Once you've flashed the UBIFS to NAND, set the following bootargs to boot into the UBIFS:

VAR_SOM_MX6(nand) U-Boot> setenv bootargs console=ttymxc0,115200 ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs

Load the kernel and DTB according to your preference, and then boot.