Yocto NAND Flash Burning

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

1 Introduction

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

The SOM's internal storage:
The Variscite VAR-SOM-MX8X comes with eMMC, which holds U-Boot, the kernel image and the ext4 root file system.

2 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).

3 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.

3.1 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

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

{{#ifeq: imx8 | imx8 || Linux:

$ sudo cp ${YOCTO_IMGS_PATH}/Image.gz ${P2_MOUNT_DIR}/opt/images/Yocto/

Device Tree:

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

eMMC images:

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

File System:
$ sudo cp ${YOCTO_IMGS_PATH}/fsl-image-gui-imx8qxp-var-som.tar.gz ${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.tar.gz

3.2 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)

3.3 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/mmcblk0 
$ 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/mmcblk0p1
$ mount ${node}p1 /run/media/mmcblk0p1
$ tar xvpf rootfs.tar.gz -C /run/media/mmcblk0p1

$ sync
$ umount /run/media/mmcblk0p1

4 Summary

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.