I use UBIFS as main general purpose MTD file system in my embedded projects. When customer is updating our embedded device, he updates root filesystem completely. I believe it is more error prone than updating single applications or files. It is not possible to update live attached UBI volume, so if you wish to update flash contents it is mandatory umount root filesystem and detach the UBI volume.
There are few ways to do it:
- reboot the device and start it from different (minimal) flash partition as root filesystem (you have to maintain two root filesystems, the real one, and the minimal one used for update),
- use pivot_root/chroot pair to switch to different rootfs and then umount main root filesystem (unfortunately, it did not worked for me),
- create minimal root filesystem on the fly, and boot into it using kexec kernel system call.
The third way is my favorite, basic steps to perform UBI file system update are as follow:
- Create file for temporary file system.
- Mount the temporary file as loop device.
- Create required directory structure.
- Copy all required files (busybox, libraries, kernel modules, modutils, ubiformat, etc) to the mounted root filesystem.
- Copy your update script, or update application into the mounted directory
- Umount the temporary file.
- Use kexec to boot with the kernel, use temporary file as initial ramdisk, execute your update script, or update application as the init process (use “init=/your_update_script.sh” kernel command line parameter).
- After “warm reboot” your UBI volume is not attached and you can update it with ubiformat.
I suggest attaching update script to your update package, as it is possible to customize tasks inside this script and it is possible to do whatever you want during this script execution.