How to Update UBIFS rootfs on CompuLab SBC-FX6

Requirements

Your build must contain the mtd-utils package as a userspace package.
This is located in Desktop Factory at:

Target Software > Software Packages > System > Filesystems > mtd-utils

The first section of instructions assumes you have configured Factory to produce an UBIFS formatted rootfs for the SBC-FX6.
This file, rootfs.ubifs, is found in the build_*/images/rfs/ directory of a Factory build.
The UBIFS format is currently only available in Desktop Factory.

You must be able to boot from a medium other than NAND - SD card or Network are typical options; the rootfs.ubifs image must be accessible/present in your boot medium.

Boot into userspace, confirm MTD is accesible.

As noted previously, boot your target using either an SD card, Network mounted rootfs, or USB drive.
Once at the prompt, confirm MTD partitions are present:

# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 000c0000 00001000 "uboot" 
mtd1: 00040000 00001000 "uboot environment" 
mtd2: 00100000 00001000 "reserved" 
mtd3: 00800000 00080000 "linux" 
mtd4: 3f800000 00080000 "rootfs" 

1. Erase "rootfs" mtd partition

Here, <mtddev> corresponds to the rootfs partition, shown above: /dev/mtd4

  1. flash_erase <mtddev> 0 0
# flash_erase /dev/mtd4 0 0
Erasing 512 Kibyte @ 2d00000 --  4 % complete flash_erase: Skipping bad block at 02d80000
Erasing 512 Kibyte @ 3f580000 -- 99 % complete flash_erase: Skipping bad block at 3f600000
flash_erase: Skipping bad block at 3f680000
flash_erase: Skipping bad block at 3f700000
flash_erase: Skipping bad block at 3f780000
Erasing 512 Kibyte @ 3f780000 -- 100 % complete

2. Format mtd rootfs partition:

# ubiformat /dev/mtd4

3. Attach to rootfs mtd partition

-m: Specifies partition to attach to
-d: Number assigned to partition (assigned automatically if not passed)

# ubiattach /dev/ubi_ctrl -m 4 -d 0

4. Create an UBI volume on the partition:

-m: specifies to use all of the available space
-N: name the partition, in this case "rootfs"

# ubimkvol /dev/ubi0 -m -N rootfs
Set volume size to 1033740288
Volume ID 0, size 2003 LEBs (1033740288 bytes, 985.9 MiB), LEB size 516096 bytes (504.0 KiB), dynamic, name "rootfs", alignment 1

5. Write rootfs.ubi image into partition:

ubiupdatevol accepts the ubi-volume we are attached to - ubi0_0 which was created when we attached previously - and the rootfs.ubifs we want to flash.

# ubiupdatevol /dev/ubi0_0 /path/to/rootfs.ubifs

6. Mount the newly written rootfs to confirm success (optional)

# mkdir /mnt/ubi_rootfs
# mount -t ubifs ubi0_0 /mnt/ubi_rootfs/
UBIFS: mounted UBI device 0, volume 0, name "rootfs" 
UBIFS: file system size:   1028579328 bytes (1004472 KiB, 980 MiB, 1993 LEBs)
UBIFS: journal size:       10452992 bytes (10208 KiB, 9 MiB, 21 LEBs)
UBIFS: media format:       w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root:  0 bytes (0 KiB)

Alternate method

This also requires mtd-utils to be present in the rootfs.
Additionally, rootfs.tar.gz from your Factory build must be accessible.
Rather than write an UBIFS image to NAND, we will simply mount the NAND partition as an UBIFS type, and decompress the tarball onto it.

Complete the above process through step 4, then follow below:

h2 1. Create a directory to mount UBIFS filesystem:

# mkdir -p /media/rootfs

h2 2. Mount UBIFS partition:

# mount -t ubifs ubi0:rootfs /media/rootfs/
UBIFS: mounted UBI device 0, volume 0, name "rootfs" 
UBIFS: file system size:   1028579328 bytes (1004472 KiB, 980 MiB, 1993 LEBs)
UBIFS: journal size:       10452992 bytes (10208 KiB, 9 MiB, 21 LEBs)
UBIFS: media format:       w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root:  0 bytes (0 KiB)

h2 3. Decompress the rootfs.tar.gz file into this mounted partition:

# tar -xvf /path/to/rootfs.tar.gz -C /media/rootfs && sync

h2 4. Unmount the UBI partition:

# umount /media/rootfs

Boot parameters for NAND:

Change your boot arguments to boot into the UBIFS rootfs as shown below:

console=ttymxc3,115200 ip=dhcp rootfstype=ubifs ubi.mtd=rootfs root=ubi0:rootfs rw