Mtd: high barrier to entry to start develop

Hello. After a couple of customizations of my image for dir 620 rev A1 and unknown fails after flash i finally decided to understand on what's going on. And i don't get at all why mtd6 aka rootfs_data has such a partition size.

For now, what I got so far from my mtd table after two of flashings:

root@(none):~# cat /proc/mtd
dev: size erasesize name
mtd0: 00030000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "factory"
mtd3: 007b0000 00010000 "firmware"
mtd4: 0018f018 00010000 "kernel"
mtd5: 00620fe8 00010000 "rootfs"
mtd6: 002e0000 00010000 "rootfs_data"


dev:    size   erasesize  name
mtd0: 00030000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "factory"
mtd3: 007b0000 00010000 "firmware"
mtd4: 0018eff9 00010000 "kernel"
mtd5: 00621007 00010000 "rootfs"
mtd6: 002e0000 00010000 "rootfs_data"

For me it is clear, that the whole mtd size (8Mb for my device) consists of :
u-boot+u-boot-env+factory (some vendor-specific stuff?)+firmware
And the latest one is subject to change by openwrt.
Both kernel and rootfs are part of squashfs that saved 'as is' in mtd3 (mtd4+mtd5=mtd3). And the size of squashfs is controlled by openwrt build system against 007b0000 right hardcoded.

So far so good. Now the question is what is logical mtd6 is? It is supposed to be overlay_fs over root_fs and be writable? But why it has always been size 002e0000? why doesn't it has a size
(007b0000 - sizeof(squashfs)) instead? Isn't a reason why after some firmware stop working because settings just 'grab' place from real squashfs?
Or how it works at all?

The partition map is defined in the .dts (see here for your device). As you can see, firmware is the last "physical" partition. This is split into "kernel" and "rootfs" by OpenWrt and the latter being split into the "ROM" part and the writable "rootfs_data" part.
This is also visualized and explained in the Wiki:

ok. thx. Now i know where 1st level split is done. Now remains to understand how 2nd and 3rd split is done

UPDATE: btw under examples above in wiki i don't see any contradiction while in my case if i have squashfs file of size 6554418, i expect to see 'remains'

8060928−6554418=1506510 (= 16FCCE₁₆) which is less than proposed by openwrt 002e0000. Thats why my firmware doesnt work

You may want to take a look here:;a=tree;f=target/linux/generic/files/drivers/mtd/mtdsplit

In case of your device, the firmware partition contains a legacy U-Boot uImage kernel with appended squashfs rootfs followed by free space to be used for user data. Hence look at mtdsplit_uimage.c will create a virtual partition rootfs which contains everything after the uImage. Then mtdsplit_squashfs.c will allocate all the remaining space after the squashfs into yet another virtual partition rootfs_data.

1 Like

tnx to everyone. My error in understanding was that checking against squashfs file size here was a rigorous one, however, it is not true. The real image is much less and calculated by kernel size+squashfs using header size for latter from header which corresponds to bytes used from superblock

Next, the real issue i encountered after reflashing of firmware has at least two reasons:

  1. non-recoveriable dhcp-based ip connection after static one. Something similar here
  2. Sometimes router cannot launch because of inconsistent settings. In particular, cannot read network change + static lease simultaneously.