Home/Support/Support Forum/Update UBIFS root filesystem via update_flash tool
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Update UBIFS root filesystem via update_flash tool

0 votes
Hi all,

I have a UBIFS root file system using an image created via Yocto recipes with the Digi Embedded Yocto minimal (non-graphical) build as a starting point.

As part of a firmware update procedure, I'd like to be able to update the root file system from within Linux using the update_flash utility. Ideally, this can be done in place.

This seems to work fine if I uses a JFFS2 root file system, viz.

CCARDIMX28 # flpart
Nr | Name | Start | Size | Type | FS | Flags

0 | Bstrm-U-Boot | 0 | 3 MiB | Bootstream | | fixed
1 | NVRAM | 3 MiB | 512 KiB | NVRAM | | fixed
2 | FDT | 3584 KiB | 512 KiB | Device Tree | |
3 | Kernel | 4 MiB | 5 MiB | Linux/Android-Kernel | |
4 | RootFS | 9 MiB | 50 MiB | Filesystem | JFFS2 | mounted readonly rootfs
5 | Kernel-s | 59 MiB | 5 MiB | Linux/Android-Kernel | |
6 | RootFS-s | 64 MiB | 50 MiB | Filesystem | UBIFS | mounted readonly rootfs
7 | UserFS | 114 MiB | 14 MiB | Filesystem | JFFS2 |

root@ccardimx28js:~# update_flash /dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.jffs2.sum 4
Partition 4 is NAND ()
Full Size: 51200 KiB
Good Size: 51200 KiB
--- JFFS2 partition 4 will be fully erased
Verifying File(s): /dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.jffs2.sum
!!! Remounting /
Updating:
/dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.jffs2.sum (27483 KiB)
Erasing: complete
Flashing: complete
CRC32: 0x25be97fe
Done

However, with UBIFS, I get errors about needing to detach the UBI volume. I cannot detach the volume to proceed as I get errors about the device being busy.

CARDIMX28 # flpart
Nr | Name | Start | Size | Type | FS | Flags

0 | Bstrm-U-Boot | 0 | 3 MiB | Bootstream | | fixed
1 | NVRAM | 3 MiB | 512 KiB | NVRAM | | fixed
2 | FDT | 3584 KiB | 512 KiB | Device Tree | |
3 | Kernel | 4 MiB | 5 MiB | Linux/Android-Kernel | |
4 | RootFS | 9 MiB | 50 MiB | Filesystem | UBIFS | mounted readonly rootfs
5 | Kernel-s | 59 MiB | 5 MiB | Linux/Android-Kernel | |
6 | RootFS-s | 64 MiB | 50 MiB | Filesystem | UBIFS | mounted readonly rootfs
7 | UserFS | 114 MiB | 14 MiB | Filesystem | JFFS2 |

t@ccardimx28js:~# update_flash /dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.ubifs 4
Partition 4 is NAND ()
Full Size: 51200 KiB
Good Size: 51200 KiB
Verifying File(s): /dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.ubifs
Updating:
/dev/dey-image-minimal-ccardimx28js-20150923215237.128.rootfs.ubifs (31496 KiB)
Flashing: FAILED! (ubiformat: error!: please, first detach mtd4 (/dev/mtd4) from ubi0)

Is there any procedure available to do this with a UBIFS rootfs? I don't want to have to do things in uboot nor to make my firmware update state-machine more complex, i.e. I'd like to be able to run update_flash "in place" as I can do with a JFFS2 filesystem.

Thanks in advance.
asked Sep 30, 2015 in Linux by jfmonaco New to the Community (15 points)

Please log in or register to answer this question.

1 Answer

0 votes
 
Best answer
Short answer is "no". You cannot update rootfs you are ruinning from.
Here is a long answer:
update_flash was meant to be used on raw MTD devices (flash) and in the CC6 we have the EMMC with appears as a real block device to Linux.

As the images created by DEY have the filesystem metadata embedded in the image, you can use the standard dd command to copy images to the block devices.

For example:
dd if=dey-image-minimal-ccimx6sbc.boot.vfat of=/dev/mmcblk0p2 bs=64K
dd if=dey-image-minimal-ccimx6sbc.ext4 of=/dev/mmcblk0p4 bs=64K
will update mmcblk0p2 and mmcblk0p4 partitions with the contents of the images. Actually it will overwrite everything, so you will lose the previous contents. If you now reboot the target, you will see those partitions auto-mounted:
root@ccimx6sbc:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 987.7M 330.4M 610.3M 35% /
devtmpfs 295.1M 4.0K 295.1M 0% /dev
tmpfs 503.2M 272.0K 503.0M 0% /run
tmpfs 503.2M 60.0K 503.2M 0% /var/volatile
/dev/mmcblk0p2 63.9M 4.1M 59.8M 6% /mnt/linux2
/dev/mmcblk0p1 63.9M 4.1M 59.8M 6% /mnt/linux
/dev/mmcblk0p4 987.7M 117.9M 822.8M 13% /media/mmcblk0p4

A limitation is updating the rootfs you are currently booting from. You need to have the block device unmounted before running the dd command. You should not update the rootfs you are running on.
This would need to be done either booting from a initramfs kernel, from NFS, or updating to the alternate root filesystem partition and altering the u-boot environment to pass the new rootfs to the kernel as boot media.
answered Sep 30, 2015 by LeonidM Veteran of the Digi Community (3,171 points)
selected Oct 1, 2015 by jfmonaco
Thanks Leonid.

Is this limitation for UBIFS root filesystems only?

The process of "inplace" updating the currently running rootfs seems to work when it uses a JFFS2 filesystem. The progress messages also suggest that the system is unmounting and remounting the volume behind the scenes in the JFFS2 case.
Yes, I am talking about UBIFS, also I've never tried to update JFFS2 on eMMC
...