DART-6UL NAND Flash Burning

From Variscite Wiki
Revision as of 15:06, 1 September 2016 by Eran (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DART-6UL - Flashing the internal storage device

Introduction

The Variscite DART-6UL has either an on-SOM NAND flash or eMMC, and either of them can be used to boot from and to hold the file system.
For NAND flash we use a UBI file system and for eMMC we use ext4.

NAND flash structure

These are the defined MTD partitions on the NAND flash:
0x000000000000-0x000000200000 : "spl"
0x000000200000-0x000000400000 : "u-boot"
0x000000400000-0x000000600000 : "u-boot_env"
0x000000600000-0x000000e00000 : "kernel"
0x000000e00000-End                       : "rootfs"

eMMC structure

0-4 MiB      : Non-partitioned space, saved for U-Boot.
4-12 MiB    : "BOOT-VAR6UL" - 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 eMMC/NAND flash

The resulted images are located at tmp/deploy/images/imx6ul-var-dart:

File Name Description
fsl-image-gui-imx6ul-var-dart.tar.bz2 Tarball with rootfs files. Used here for writing to eMMC.
fsl-image-gui-imx6ul-var-dart.ubi A complete UBI image containing a UBIFS volume, for writing to NAND flash.
zImage Linux kernel image. Used here for both eMMC and NAND flash.
SPL-sd SPL image. Used here for eMMC.
SPL-nand SPL built for NAND flash.
u-boot.img-sd U-Boot image. Used here for eMMC.
u-boot.img-nand U-Boot built for NAND flash.
zImage-imx6ul-var-dart-emmc_wifi.dtb eMMC and WiFi enabled (SD card and NAND flash disabled).
zImage-imx6ul-var-dart-nand_wifi.dtb NAND flash and WiFi enabled (SD card and eMMC disabled).
zImage-imx6ul-var-dart-sd_emmc.dtb eMMC and SD card enabled (NAND flash and WiFi disabled).
zImage-imx6ul-var-dart-sd_nand.dtb NAND flash and SD card enabled (eMMC and WiFi disabled).

Installing the Yocto binaries

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

Images locations

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

/opt/images/
└── Yocto
    ├── imx6ul-var-dart-emmc_wifi.dtb
    ├── imx6ul-var-dart-nand_wifi.dtb
    ├── imx6ul-var-dart-sd_emmc.dtb
    ├── imx6ul-var-dart-sd_nand.dtb
    ├── rootfs.tar.bz2
    ├── rootfs.ubi
    ├── SPL-nand
    ├── SPL-sd
    ├── u-boot.img-nand
    ├── u-boot.img-sd
    └── zImage

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-mx6ul-mx7-yocto-jethro/build_x11/tmp/deploy/images/imx6ul-var-dart
$ export P2_MOUNT_DIR=/media/rootfs/
Linux:
$ sudo cp ${YOCTO_IMGS_PATH}/zImage					${P2_MOUNT_DIR}/opt/images/Yocto/

NAND images:

Device Trees:
$ sudo cp ${YOCTO_IMGS_PATH}/zImage-imx6ul-var-dart-nand_wifi.dtb	${P2_MOUNT_DIR}/opt/images/Yocto/imx6ul-var-dart-nand_wifi.dtb
$ sudo cp ${YOCTO_IMGS_PATH}/zImage-imx6ul-var-dart-sd_nand.dtb		${P2_MOUNT_DIR}/opt/images/Yocto/imx6ul-var-dart-sd_nand.dtb

U-Boot and SPL:
$ 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}/fsl-image-gui-imx6ul-var-dart.ubi		${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.ubi

eMMC images:

Device Trees:
$ sudo cp ${YOCTO_IMGS_PATH}/zImage-imx6ul-var-dart-emmc_wifi.dtb	${P2_MOUNT_DIR}/opt/images/Yocto/imx6ul-var-dart-emmc_wifi.dtb
$ sudo cp ${YOCTO_IMGS_PATH}/zImage-imx6ul-var-dart-sd_emmc.dtb		${P2_MOUNT_DIR}/opt/images/Yocto/imx6ul-var-dart-sd_emmc.dtb

U-Boot and SPL:
$ 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}/fsl-image-gui-imx6ul-var-dart.tar.bz2	${P2_MOUNT_DIR}/opt/images/Yocto/rootfs.tar.bz2

Flashing script

The flashing script is located on the SD card at /usr/bin/:

install_yocto.sh	- Flash Yocto into NAND flash or eMMC (Run and follow usage instructions)

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 U-Boot and SPL to NAND flash:

$ 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_erase /dev/mtd2 0 0

Flash the Linux Kernel image & the selected Device Tree blob to NAND flash:

$ flash_erase /dev/mtd3 0 0
$ nandwrite -p /dev/mtd3 zImage

$ nandwrite -p /dev/mtd3 -s 0x7e0000 imx6ul-var-dart-nand_wifi.dtb
or
$ nandwrite -p /dev/mtd3 -s 0x7e0000 imx6ul-var-dart-sd_nand.dtb

Flash the UBI File System to NAND flash:

$ ubiformat /dev/mtd4 -f rootfs.ubi

Manual step-by-step flashing to eMMC

Flashing the eMMC requires several steps including flashing of U-Boot and the Linux kernel, 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/mmcblk1
$ 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 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.vfat ${node}p1 -n BOOT-VAR6UL
$ mkfs.ext4 ${node}p2 -L rootfs
$ sync

Flash U-Boot and SPL to eMMC:

$ 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:

$ mkdir /run/media/mmcblk1p1
$ mount -t vfat ${node}p1		/run/media/mmcblk1p1
$ cp imx6ul-var-dart-emmc_wifi.dtb	/run/media/mmcblk1p1/
$ cp imx6ul-var-dart-sd_emmc.dtb	/run/media/mmcblk1p1/
$ cp zImage				/run/media/mmcblk1p1/
$ sync
$ umount /run/media/mmcblk1p1

Extract the rootfs archive:

$ mkdir /run/media/mmcblk1p2
$ mount ${node}p2 /run/media/mmcblk1p2
$ tar xvpf rootfs.tar.bz2 -C /run/media/mmcblk1p2
$ sync
$ umount /run/media/mmcblk1p2

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 flash or 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.