Help with NAND layout settings for userdata/overlay

I'm adding support to a device based on MT7621A chipset. I already figured out the format for the stock image and I'm successfully flashing a basic Openwrt v23.05.

The firmware image has a kernel partition and rootfs (ubi) partition image.

The issue is that the stock bootloader checks the CRC32 value of the rootfs partition so it must be marked as read-only on the dts file or it won't boot on the next restart.

Right now i have this:

&nand {
        status = "okay";

        partitions {
                compatible = "fixed-partitions";
                #address-cells = <1>;
                #size-cells = <1>;

                partition@0 {
                        label = "bootloader";
                        reg = <0x0 0x80000>;
                        read-only;
                };

                partition@80000 {
                        label = "config";
                        reg = <0x80000 0x80000>;
                        read-only;
                };

                factory: partition@100000 {
                        label = "factory";
                        reg = <0x100000 0x40000>;
                        read-only;
                };

                partition@140000 {
                        label = "kernel";
                        reg = <0x140000 0x400000>;
                        read-only;
                };

                partition@540000 {
                        label = "ubi";
                        reg = <0x540000 0x2000000>;
                        /* default bootloader checks partition's crc */
                        read-only;
                };

                partition@2540000 {
                        label = "free_space_on_nand";
                        reg = <0x2540000 0x2300000>;
                };
        };
};

I have no idea how to setup or config the free space available on nand as an overlay partition or something, I'm open to ideas :slight_smile:

I have been looking into this for a few days before asking for help.

Pretty sure, that you don't set up the free space in the DTS.
You just declare the whole ubi partition.

It's then divided between the read-only rootfs and the writable rootfs_data during build time.

Just for reference:
https://openwrt.org/docs/techref/flash.layout#partitioning_of_nand_flash-based_devices
I'm sure, you've read it already...

Disclaimer: still learning how the build system works myself, so all that might be garbage as well :laughing:

I tried this and somehow it still manages to modify the read-only rootfs partition and the checksum fails:

&nand {
        status = "okay";

        partitions {
                compatible = "fixed-partitions";
                #address-cells = <1>;
                #size-cells = <1>;

                partition@0 {
                        label = "bootloader";
                        reg = <0x0 0x80000>;
                        read-only;
                };

                /* uboot env */
                partition@80000 {
                        label = "config";
                        reg = <0x80000 0x80000>;
                        read-only;
                };

                factory: partition@100000 {
                        label = "factory";
                        reg = <0x100000 0x40000>;
                        read-only;
                };

                partition@140000 {
                        label = "kernel";
                        reg = <0x140000 0x400000>;
                        read-only;
                };

                partition@540000 {
                        label = "ubi";
                        reg = <0x540000 0x4300000>;

                        partition@0 {
                                label = "rootfs";
                                reg = <0x0 0x2000000>;

                                /* default bootloader checks partition's crc */
                                read-only;
                        };

                        partition@2000000 {
                                label = "rootfs_data";
                                reg = <0x2000000 0x2300000>;
                        };
                };
};


Checking kernel 1...............................................Kernel OK
Checking rootfs 1.....................................................................................................................
 rootfs type=[1] len=[7471104], crc32=[0xC97A5E41], live crc32=[0xE49A85E9]..rootfs crc32 incorrect!