Yocto NAND Flash Burning

From Variscite Wiki
Installing Yocto to the SOM's internal storage


All SOMs can either boot from an SD card or from their internal storage.

The SOM's internal storage:

  • VAR-SOM-MX6 and VAR-SOM-SOLO/DUAL SOMs use the on-SOM NAND flash to boot.

The file system can reside either on the NAND flash or the eMMC.
When the file system resides on the NAND flash, a UBIFS file system is used.
When the file system resides on the eMMC, an ext4 file system is used.
Regardless of the file system type and location, U-Boot will always boot from the NAND flash.
By default, the kernel image and device tree blob are also written to the NAND flash (again, regardless of the file system type and location).

  • VAR-DART-MX6 has only an on-SOM eMMC which can be used to boot from and to hold the filesystem.

NAND flash structure


These are the defined MTD partitions on the NAND flash:
0x000000000000-0x000000200000 : "spl"
0x000000200000-0x000000400000 : "bootloader"
0x000000400000-0x000000c00000 : "kernel"
0x000000c00000-End                          : "rootfs"

eMMC structure


0 MiB-End: "rootfs" - An ext4 partition containing the root file system (including the kernel modules).


0-4 MiB      : Non-partitioned space, saved for U-Boot.
4-12 MiB    : BOOT-VARMX6 - A FAT16 partition containing the Linux image and the device tree blob/s.
12 MiB-End: "rootfs" - An ext4 partition containing the root file system (including the kernel modules).

Yocto Built binaries for NAND flash / eMMC

The resulting images are located at tmp/deploy/images/var-som-mx6.

Image Name
b2qt-embedded-qt5-image-var-som-mx6. This image is for SD card boot.
It can be flashed as-is on an SD card that can then be used to boot your system,
according to the relevant startup-guide of your product
(usually requires to press the boot select button, or toggle a DIP switch).
For detailed information refer to the Create a bootable SD card section below.
b2qt-embedded-qt5-image-var-som-mx6.tar.gz Tarball with rootfs files.
Can be used to create an NFS root file system on the host.
See the Yocto Setup TFTP/NFS section for more info.
Also used to create our extended SD card.
See the Create a bootable SD card section below.
b2qt-embedded-qt5-image-var-som-mx6_128kbpeb.ubi A complete UBI image containing a UBIFS volume, for writing to NAND flash with 128KiB PEB.
b2qt-embedded-qt5-image-var-som-mx6_256kbpeb.ubi A complete UBI image containing a UBIFS volume, for writing to NAND flash with 256KiB PEB.
uImage Linux kernel image, same binary for SD card/eMMC or NAND flash.
SPL-sd SPL built for SD card boot or eMMC boot.
SPL-nand SPL built for NAND flash.
u-boot.img-sd U-Boot built for SD card boot or eMMC boot.
u-boot.img-nand U-Boot built for NAND flash.
Device Tree Name
SOM type
Carrier Board type
LCD Type
Evaluation Kit name
uImage-imx6q-var-som-cap.dtb VAR-SOM-MX6_V2 (Quad / Dual) VAR-MX6CustomBoard Capacitive touch VAR-DVK-MX6_V2-PRO
uImage-imx6q-var-som-res.dtb VAR-SOM-MX6_V2 (Quad / Dual) VAR-MX6CustomBoard Resistive touch VAR-DVK-MX6_V2-PRO
uImage-imx6q-var-som-vsc.dtb VAR-SOM-MX6_V2 (Quad / Dual) VAR-SOLOCustomBoard Capacitive LVDS touch N/A
uImage-imx6dl-var-som-cap.dtb VAR-SOM-MX6_V2 (DualLite / Solo) VAR-MX6CustomBoard Capacitive touch N/A
uImage-imx6dl-var-som-res.dtb VAR-SOM-MX6_V2 (DualLite / Solo) VAR-MX6CustomBoard Resistive touch N/A
uImage-imx6dl-var-som-vsc.dtb VAR-SOM-MX6_V2 (DualLite / Solo) VAR-SOLOCustomBoard Capacitive LVDS touch N/A
uImage-imx6qp-var-som-cap.dtb VAR-SOM-MX6_V2 (QuadPlus / DualPlus) VAR-MX6CustomBoard Capacitive touch N/A
uImage-imx6qp-var-som-res.dtb VAR-SOM-MX6_V2 (QuadPlus / DualPlus) VAR-MX6CustomBoard Resistive touch N/A
uImage-imx6qp-var-som-vsc.dtb VAR-SOM-MX6_V2 (QuadPlus / DualPlus) VAR-SOLOCustomBoard Capacitive LVDS touch N/A
uImage-imx6dl-var-som-solo-cap.dtb VAR-SOM-SOLO / VAR-SOM-DUAL VAR-MX6CustomBoard Capacitive touch N/A
uImage-imx6dl-var-som-solo-res.dtb VAR-SOM-SOLO / VAR-SOM-DUAL VAR-MX6CustomBoard Resistive touch N/A
uImage-imx6dl-var-som-solo-vsc.dtb VAR-SOM-SOLO / VAR-SOM-DUAL VAR-SOLOCustomBoard Capacitive LVDS touch VAR-DVK-SOLO/DUAL
uImage-imx6q-var-dart.dtb DART-MX6 VAR-DT6CustomBoard Capacitive LVDS touch VAR-DVK-DT6

Installing the Yocto binaries

If you followed the Create an extended SD card steps, the Yocto binaries and the flashing scripts will be included in your SD card.
The flashing scripts are easy-to-use example scripts for flashing images into NAND flash / eMMC.
There is also a section below describing how to flash the images manually.

Images locations

Following is the directory structure on your SD card, which elaborates the files' location that the below installation scripts are expecting:

└── Yocto
    ├── SPL-nand
    ├── SPL-sd
    ├── imx6dl-var-som-cap.dtb
    ├── imx6dl-var-som-res.dtb
    ├── imx6dl-var-som-solo-cap.dtb
    ├── imx6dl-var-som-solo-res.dtb
    ├── imx6dl-var-som-solo-vsc.dtb
    ├── imx6dl-var-som-vsc.dtb
    ├── imx6q-var-dart.dtb
    ├── imx6q-var-som-cap.dtb
    ├── imx6q-var-som-res.dtb
    ├── imx6q-var-som-vsc.dtb
    ├── imx6qp-var-som-cap.dtb
    ├── imx6qp-var-som-res.dtb
    ├── imx6qp-var-som-vsc.dtb
    ├── rootfs.tar.gz
    ├── rootfs_128kbpeb.ubi
    ├── rootfs_256kbpeb.ubi
    ├── u-boot.img-nand
    ├── u-boot.img-sd
    └── uImage

Prepare the images for NAND flash / eMMC flashing

Plug the bootable SD card into your host machine and mount the rootfs partition - here we assume it is mounted on /media/rootfs.
Copy all the mentioned yocto-built binaries to the SD card:


$ export YOCTO_IMGS_PATH=~/var-b2qt/build-var-som-mx6/tmp/deploy/images/var-som-mx6
$ export P2_MOUNT_DIR=/media/rootfs/
$ sudo mkdir -p ${P2_MOUNT_DIR}/opt/images/Yocto/


$ sudo cp ${YOCTO_IMGS_PATH}/uImage ${P2_MOUNT_DIR}/opt/images/Yocto/

Device Tree:

$ for f in ${YOCTO_IMGS_PATH}/*.dtb; do if [[ -L $f ]] && [[ $f != *var-som-mx6.dtb ]]; then sudo cp $f ${P2_MOUNT_DIR}/opt/images/Yocto/; fi done
$ sudo rename 's/uImage-imx/imx/' ${P2_MOUNT_DIR}/opt/images/Yocto/*.dtb

NAND images:

$ sudo cp ${YOCTO_IMGS_PATH}/SPL-nand ${P2_MOUNT_DIR}/opt/images/Yocto/

$ sudo cp ${YOCTO_IMGS_PATH}/u-boot.img-nand ${P2_MOUNT_DIR}/opt/images/Yocto/

File System:
$ sudo cp ${YOCTO_IMGS_PATH}/b2qt-embedded-qt5-image-var-som-mx6.ubi ${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.ubi

eMMC images:

File System:
$ sudo cp ${YOCTO_IMGS_PATH}/b2qt-embedded-qt5-image-var-som-mx6.tar.gz ${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.tar.gz 
  • DART-MX6
$ sudo cp ${YOCTO_IMGS_PATH}/SPL-sd ${P2_MOUNT_DIR}/opt/images/Yocto/

$ sudo cp ${YOCTO_IMGS_PATH}/u-boot.img-sd ${P2_MOUNT_DIR}/opt/images/Yocto/

File System:
$ sudo cp ${YOCTO_IMGS_PATH}/b2qt-embedded-qt5-image-var-som-mx6.tar.gz ${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.tar.gz

Flashing scripts

The flashing scripts are located on the SD card at /usr/bin/:

install_yocto.sh	- Flash Yocto into NAND flash or eMMC (Run and follow usage instructions)
(install_yocto_emmc.sh	- This script is being called by install_yocto.sh when choosing to install the rootfs to eMMC - it should not be called directly!)

Manual step-by-step flashing to NAND flash

Use the prepared SD card to boot the board and run the following:

$ cd /opt/images/Yocto

Flash SPL & U-Boot:

$ flash_erase /dev/mtd0 0 0
$ kobs-ng init -x SPL-nand --search_exponent=1 -v
$ flash_erase /dev/mtd1 0 0
$ nandwrite -p /dev/mtd1 u-boot.img-nand

Flash the Linux Kernel image & Device Tree:
You need to use the right .dtb file for you hardware setup. See the table above for a complete description.

$ flash_erase /dev/mtd2 0 0
$ nandwrite -p /dev/mtd2 uImage
$ nandwrite -p /dev/mtd1 -s 0x1e0000 <DEVICE_TREE_FILE>

Flash the (UBI) File System to NAND flash:

$ ubiformat /dev/mtd3 -f rootfs.ubi

Manual step-by-step flashing to eMMC

Flashing the eMMC requires several steps including partitioning, file system formatting and image extraction.
We recommend to use our provided scripts to perform this task.

Use the prepared SD card to boot the board and run the following:

  • DART-MX6
$ export node=/dev/mmcblk2
$ cd /opt/images/Yocto
$ export node=/dev/mmcblk0 
$ cd /opt/images/Yocto

Make sure the eMMC is not mounted:

$ umount ${node}p*

Delete current data on eMMC:

$ dd if=/dev/zero of=${node}p1 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p2 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p3 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p4 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p5 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p6 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p7 bs=1024 count=1024
$ sync
$ (echo d; echo 1; echo d; echo 2; echo d; echo 3; echo d; echo w) | fdisk ${node}
$ sync
$ dd if=/dev/zero of=${node} bs=1M count=4
$ sync

Create a partition table:

$ (echo n; echo p; echo 1; echo; echo; echo p; echo w) | fdisk -u ${node}
$ sync
  • DART-MX6
$(echo n; echo p; echo 1; echo 8192; echo 24575; echo t; echo c; \
  echo n; echo p; echo 2; echo 24576; echo; \
  echo p; echo w) | fdisk -u ${node}
$ sync

Format the partitions:

$ mkfs.ext4 ${node}p1 -L rootfs
  • DART-MX6
$ mkfs.vfat ${node}p1 -n BOOT-VARMX6
$ mkfs.ext4 ${node}p2 -L rootfs

Flash SPL and U-Boot to eMMC:

  • DART-MX6 only
$ dd if=SPL-sd of=${node} bs=1K seek=1; sync
$ dd if=u-boot.img-sd of=${node} bs=1K seek=69; sync

Copy the Linux kernel image and the device tree blobs to the BOOT partition:

  • DART-MX6 only
$ mkdir /run/media/mmcblk0p1
$ mount -t vfat ${node}p1	/run/media/mmcblk0p1/
$ cp *emmc*.dtb			/run/media/mmcblk0p1/
$ cp uImage			/run/media/mmcblk0p1/
$ sync
$ umount /run/media/mmcblk0p1

Extract the rootfs archive:

$ mkdir /run/media/mmcblk0p1
$ mount ${node}p1 /run/media/mmcblk0p1
$ tar xvpf rootfs.tar.gz -C /run/media/mmcblk0p1
$ sync
$ umount /run/media/mmcblk0p1

Set the U-Boot env. variable "rootfs_device" to "emmc" by one of the following two methods:

$ fw_setenv rootfs_device emmc
(A "Warning: Bad CRC, using default environment" message is expected, since this is the first write of the U-Boot environment to the NAND flash)

Reboot and stop at the U-Boot command line, and enter the following:
=> setenv rootfs_device emmc
=> saveenv


We described the results of a Yocto build, how to copy it to a bootable SD card and how to flash it to NAND and eMMC.
With our extended SD card and our recovery SD card we provide an installation script located at /usr/bin/install_yocto.sh. It is much safer to use it instead of flashing the system manually.