linuxflashfilesystemsrootfsubifs

Create backup of a raw flash partition then format it to UBI then update the UBI volume


First I am erasing already existing flash partition with UBI volume using "flash erase" and "flash write" which will write new contents to raw flash in U-Boot, then I format the partition which will erase the new contents and create a UBI volume which will be updated with older contents in a init script.

I need to get backup of the new contents before formatting and update the backup with the new contents to the UBI volume I create after formatting in that init script.

I tried to dump the raw flash partition using "dd" which gets my whole backup partition which is of size 120MiB but since UBI headers occupy some space in MTD my UBI device only has 116MiB sapce and the UBI volume only has 115MiB , hence I can not update the 120MiB backup bin to my 115MiB ubi volume.

Second thing I tried to convert the flash partition contents to a UBI image and update it in the volume , this was done but during mounting the partition I faced these errors :

UBIFS error (ubi0:0 pid 196): ubifs_read_node: bad node type (0 but expected 6)
UBIFS error (ubi0:0 pid 196): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Not a node, first 24 bytes:00000000: 55 42 49 23 01 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 08 00                          UBI#....................
CPU: 0 PID: 196 Comm: block Tainted: P           O      5.4.55 #0
Hardware name: econet,en7581 (DT)
Call trace:
 dump_backtrace+0x0/0x110
 show_stack+0x14/0x20
 dump_stack+0xac/0xec
 ubifs_read_node+0x220/0x244
 ubifs_read_superblock+0x56c/0xc40
 ubifs_mount+0x9d4/0x139c
 legacy_get_tree+0x2c/0x60
 vfs_get_tree+0x24/0xb0
 do_mount+0x548/0x9dc
 ksys_mount+0x8c/0xf0
 __arm64_sys_mount+0x1c/0x30
 el0_svc_handler+0x8c/0x140
 el0_svc+0x8/0x208

This is the ubinize command I used :

ubinize -o /tmp/rootfs.ubi -m 4096 -p 256KiB -s 4096 /tmp/ubinize.cfg

and this is the contents of ubinize.cfg

[rootfs]
mode=ubi
vol_id=0
vol_size=115MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize

I tried changing PEB size and vol_size nothing seems to work


Solution

  • Error has been fixed when the ubifs image is created with LEB size not including the UBI headers and ubinize that image and flash erase and write that ubi image.