Search by Tags

Updating NAND-based modules from userspace

 

Article updated at 06 Jul 2022
Compare with Revision


Introduction

Some of the Toradex System-on-Modules use NAND Flash for their on-module persistent storage, such as the Colibri VF50/VF61, the Colibri iMX6ULL, the Colibri iMX7S, and the Colibri iMX7D 512MB (the Colibri iMX7D 1GB uses eMMC instead). If you are looking for more general information about flash memories in Toradex SoMs, refer to Flash Memory Overview on Toradex Products.

On these NAND-based devices, the Linux BSP uses the MTD subsystem and UBIFS. UBIFS is different from traditional filesystems in that it doesn't work on top of a block device (such as SD cards, USB memory sticks, hard drives, or eMMC). UBIFS, instead, works on top of raw NAND. For this reason, the way to deal with volumes and partitions is different.

In this article, we're going to show how to update U-Boot, the Linux Kernel, the Device Tree, and the M4 firmware (only for i.MX 7-based modules) from regular Linux userspace. Note that we do not officially support updating NAND-based modules from userspace, therefore it is up to you to check if the instructions work for a specific BSP version and SoM. The only supported method for installing an entire image into a Toradex SoM is Toradex Easy Installer.

Prerequisites

First, verify the partition layout as follows:

root@colibri-imx7:~# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00080000 00020000 "mx7-bcb"
mtd1: 00180000 00020000 "u-boot1"
mtd2: 00180000 00020000 "u-boot2"
mtd3: 00080000 00020000 "u-boot-env"
mtd4: 1fc00000 00020000 "ubi"

Updating U-Boot

For redundancy sake, U-Boot is located on two MTD partitions: /dev/mtd1 and /dev/mtd2. To update U-Boot, first erase the partition:

root@colibri-imx7:~# flash_erase /dev/mtd1 0 0
Erasing 128 Kibyte @ 160000 -- 100 % complete

Then write the new bootloader:

root@colibri-imx7:~# nandwrite /dev/mtd1 u-boot-colibri-imx7-2016.11-2.7.3-gitrf0e4149.imx 
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000

Repeat the process for the second partition:

root@colibri-imx7:~# flash_erase /dev/mtd2 0 0
Erasing 128 Kibyte @ 160000 -- 100 % complete 
root@colibri-imx7:~# nandwrite /dev/mtd2 u-boot-colibri-imx7-2016.11-2.7.3-gitrf0e4149.imx
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000

Updating the Kernel

The Kernel, the Device Tree and the Root Filesystem are all located on volumes in the ubi MTD partition.

You can check each volume name by running:

root@colibri-imx7:~# cat /sys/class/ubi/ubi0_0/name 
kernel

Then, to update the kernel, run:

root@colibri-imx7:~# ubiupdatevol /dev/ubi0_0 zImage

Updating the Device Tree

root@colibri-imx7:~# cat /sys/class/ubi/ubi0_1/name
dtb
root@colibri-imx7:~# ubiupdatevol /dev/ubi0_1 imx7d-colibri-eval-v3.dtb    

Updating the M4 Firmware

For i.MX 7 devices, you can use the same procedure to update the firmware running on the M4 core:

root@colibri-imx7:~# cat /sys/class/ubi/ubi0_2/name
m4firmware
root@colibri-imx7:~# ubiupdatevol /dev/ubi0_2 app.elf