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:
The Variscite VAR-SOM-MX8M-NANO comes with eMMC, which holds U-Boot, the kernel image and the ext4 root file system.

eMMC structure

0-8 MiB      : Non-partitioned space, saved for U-Boot.
8 MiB-End: "rootfs" - An ext4 partition containing the root file system (including Linux image and the device tree blobs under /boot).

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
    ├── imx-boot-sd.bin
    └── rootfs.tar.gz

Prepare the images for flashing to eMMC

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-fslc-yocto/build_xwayland/tmp/deploy/images/imx8mn-var-som
$ export P2_MOUNT_DIR=/media/rootfs/
$ sudo mkdir -p ${P2_MOUNT_DIR}/opt/images/Yocto/

eMMC images:

$ sudo cp ${YOCTO_IMGS_PATH}/imx-boot ${P2_MOUNT_DIR}/opt/images/Yocto/imx-boot-sd.bin

File System:
$ sudo cp ${YOCTO_IMGS_PATH}/fsl-image-gui-imx8mn-var-som.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 eMMC (Run and follow usage instructions)

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:

$ export node=/dev/mmcblk2 
$ cd /opt/images/Yocto

Make sure the eMMC is not mounted:

$ umount ${node}p*

Delete current data on eMMC:

$ for((i=1; i<=16; i++)); do [ -e ${node}p${i} ] && dd if=/dev/zero of=${node}p${i} bs=1M count=1 conv=fsync; done
$ dd if=/dev/zero of=${node} bs=1M count=8 conv=fsync

Create a partition table:

$ (echo n; echo p; echo 1; echo 16384; echo; echo p; echo w) | fdisk -u $node
$ sync

Format the partitions:

$ mkfs.ext4 ${node}p1 -L rootfs
$ sync

Flash U-Boot:

$ dd if=imx-boot-sd.bin of=${node} bs=1K seek=32 conv=fsync

Extract the rootfs archive:

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

$ sync
$ umount /run/media/mmcblk2p1


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.