Friday, May 15, 2015

Upgrading JFFS2 Filesystem from linux

For embedded systems field upgrade of software application and BSP is common requirement. Updating U-boot and uImage (linux kernel) is fairly easy but upgrading filesystem from linux is bit tricky. You can-not erase the filesystem partition containing filesystem image, upgrade images and mtd-utils because it will turn your system to brick. This situation may arise if you have limited flash and can not afford to create separate partition for storing upgrade images. If you want to use most of the flash for filesystem and also store upgrade images in the same filesystem partition, here is a way to do so

A useful trick is to make use of linux implementation of traditional shared memory. This method is however neither failsafe and nor atomic. It can still brick the board if there is any sort of interruption (power failure ) while upgrading. Since it is easy and fast, so worth giving a shot. Suppose the latest filesystem image 'rootfs.jffs2' is placed in 'update' directory under 'opt'. Copy it to /dev/shm

# cp /opt/update/rootfs.jffs2 /dev/shm

Copy all the utils, needed for upgrade to shared memory too

cp  /usr/sbin/flash_erase /dev/shm/
cp  /usr/sbin/flashcp /dev/shm/
cp  /sbin/reboot /dev/shm/

Erase the partition where jffs2 filesystem resides, in my case it is mtd0 of size 29 Mb.

/dev/shm/flash_erase /dev/mtd0 0 232
/dev/shm/flashcp -v /dev/shm/rootfs.jffs2 /dev/mtd0
/dev/shm/reboot


One can also try to upgrade filesystem from u-boot using fsload but unfortunately, it was not able to load large filesystem properly.