Flash from NAND

I created a second persistent ubifs partition on my Colibri MX7 to store a “factory image”. We do something similar with a TK1 system. Now i am wondering how i can access these stored files from u-boot? The ‘ubi’ command does only provide a “raw” read functionality…
Thanks in advance!

The U-Boot in Colibri iMX7 does not have file system support. So it is not possible to access the file inside the file system. You can enable UBIFS support, but it will not allow to write files.

The typical approach is to create two root file systems (two volumes) and alter the kernel command line to choose either rootfs1 or rootfs2.

Reading from UBI should be enough for my purpose as long as i am able to load the ubifs image file into RAM and write it into the rootfs partition like (pseudo u-boot command):

fatload ubi:factorydata ${fdt_addr_r} ubifs.img && ubi write ${fdt_addr_r} rootfs ${filesize}

Would this be possible?

You can store any binaries in a UBI volume, just make sure to define it as a static UBI volume. This example creates a 256MiB static volume:

nand erase.part ubi
ubi part ubi
ubi create kernel 0x800000 static && ubi create dtb 0x20000 static
ubi create m4firmware 0xe0000 static
ubi create rootfsbak 0x10000000 static
ubi create rootfs 0 dynamic

Now you can write the image in that volume:

 fatload ${interface} 0:1 ${fdt_addr_r} ${board_name}/ubifs.img && ubi write ${fdt_addr_r} rootfsbak ${filesize}

And from there, you can load it into the real rootfs volume at any time:

ubi read ${fdt_addr_r} rootfsbak

Unfortunately, to write it you need to know the size. In the fatload case the command sets the environment variable $filesize, but ubi read seems not to do that. So you have to hardcode the size. In my case, this was (179924992 bytes or 0xAB97000 in hex).

setenv filesize 0xAB97000
ubi write ${fdt_addr_r} rootfs ${filesize}

Thank you for the detailed instructions. I guess this is a good way to backup the rootfs itself. Anyway, what would i need to do to enable the ubifs support in u-boot? When i try to mount this partition i am getting the following error:
ubifsmount ubi:data
Error reading superblock on volume ‘ubi:data’ errno=-19!

This should actually work. Are you sure you flashed a UBIFS in that volume?

This works for me:

Colibri iMX7 # ubifsmount ubi:rootfs
Colibri iMX7 # ubifs
  ubifsload ubifsls ubifsmount ubifsumount
Colibri iMX7 # ubifsls
<DIR>        6536  Thu Oct 05 04:19:21 2017  bin
<DIR>         160  Thu Oct 05 02:50:33 2017  dev

Just pushed a fix for the filesize issue to our 2016.11-toradex-next branch. If you build a new U-Boot from scratch it will set the filesize and allow to write the UBI rootfs volume read from a static UBI backup volume.

http://git.toradex.com/cgit/u-boot-toradex.git/log/?h=2016.11-toradex-next

Strange… does not work for me:

ubifsmount ubi:rootfs
Error reading superblock on volume ‘ubi:rootfs’ errno=-19!

And:

ubifsmount ubi:data
Error reading superblock on volume ‘ubi:data’ errno=-30!

Ok i managed to mount the ubi partition ‘rootfs’ within u-boot and i am able to load files, e.g.: “load ubi 0 ${fdt_addr_r} /home/root/myfile”.
However, i cannot mount other partitions, like ‘m4firmware’ or my ‘data’ partition. I always get the error: “Error reading superblock on volume ‘ubi0:m4firmware’ errno=-22!”. How ca i mount there partitions? Rootfs was flashed with an ubifs.img, could this be the reason?

Those are not UBIFS volumes. These are just static UBI volumes, which means they do not contain a file system, but just a single file (raw data)… You can read ubi read ${loadaddr} <volume>

At least my persistent ‘data’ partition is a dynamic partition, but i cannot mount it.

setenv prepare_rootfs 'ubi create data 0x8000000 dynamic && ubi create rootfs 0 dynamic'

U-Boot is not able to create a file system. You need to create the file system in Linux by mounting the volume like this:

mount -t ubifs ubi0:data /mnt/

Or create a UBI image with two UBIFS in it. But this is somewhat more involved…

You can use the Toradex Easy Installer with a custom image.json to specify two UBIFS image, see Toradex Easy Installer.

Mounting the filesystem in Linux did the trick. Thanks!