ZyXEL GS1900-24E - move overlay to 'recovery partition'

Hi,

I just got a ZyXEL GS1900-24E (realtek/rtl838x). After sysupgrade there is just 512k free space on the overlay, but there is a stock second recovery partition wich isn't used by default.

Can i move the overlay there to get more free space? Do i have to change uboot env oder kernel args to do that?

In case of bricking i can use uboot+tftp, so im fine with killing the backup partition...

Thanks!

cat /proc/mtd

root@OpenWrt:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "u-boot-env2"
mtd3: 00100000 00010000 "jffs"
mtd4: 00100000 00010000 "jffs2"
mtd5: 006d0000 00010000 "firmware"
mtd6: 00350000 00010000 "kernel"
mtd7: 00380000 00010000 "rootfs"
mtd8: 00080000 00010000 "rootfs_data"
mtd9: 006d0000 00010000 "runtime2"

root@OpenWrt:~# mount
/dev/root on /rom type squashfs (ro,relatime,errors=continue)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /tmp/root type tmpfs (rw,noatime,mode=755)
tmpfs on /dev type tmpfs (rw,nosuid,noexec,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
bpffs on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,noatime,mode=700)
/dev/mtdblock8 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

Stock kernel log:
0x00000000-0x00040000 : "LOADER"
0x00040000-0x00050000 : "BDINFO"
0x00050000-0x00060000 : "SYSINFO"
0x00060000-0x00160000 : "JFFS2 CFG"
0x00160000-0x00260000 : "JFFS2 LOG"
0x00260000-0x00930000 : "RUNTIME"
0x00930000-0x01000000 : "RUNTIME2"

Openwrt kernel log:

0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000050000 : "u-boot-env"
0x000000050000-0x000000060000 : "u-boot-env2"
0x000000060000-0x000000160000 : "jffs"
0x000000160000-0x000000260000 : "jffs2"
0x000000260000-0x000000930000 : "firmware"
2 uimage-fw partitions found on MTD device firmware
Creating 2 MTD partitions on "firmware":
0x000000000000-0x0000002c0000 : "kernel"
0x0000002c0000-0x0000006d0000 : "rootfs"
mtd: device 7 (rootfs) set to be root filesystem
1 squashfs-split partitions found on MTD device rootfs
0x0000004c0000-0x0000006d0000 : "rootfs_data"
0x000000930000-0x000001000000 : "runtime2"

So runtime2 seems to be the 'recovery system' what i want to use as overlay

So i'ts down to the question how i move the overlay mount command

I looked into make menuconfig, but can't find a path config there

I don't think i can just delete the recovery partition and expand the rootfs_data cuz its size is hardcoded in the source right?

There is no uboot or cmdline command wich specify that, is it possible to add an overwrite there? Chatgpt tells me the following, will that work?
setenv bootcmd 'run bootargs; mount -t jffs2 /dev/mtdblock9 /overlay; bootm'

Editing /etc/config/fstab could work but won't survive a sysupgrade right?

Thanks

Nope, it is how rootfs_data is laid out in dts file, eg if vendor uboot can boot kernel from "free space" start etc.

So i tested everything and nothing works...
Kernel dont use bootcmd
Overlay partition can be remounted while running, but don't see the new space available
Extroot cant use jffs2

So i think i have to recompile the kernel with a different partition table. But i wonder why this partition is kept by openwrt? Recovery? I didn't got any problems after wiping it.

Mabe someone can help me.
I searched the source for the partition definition and found it here:
https://github.com/openwrt/openwrt/blob/main/target/linux/realtek/dts-5.15/rtl8380_zyxel_gs1900.dtsi

Summary

&spi0 {
status = "okay";

flash@0 {
	compatible = "jedec,spi-nor";
	reg = <0>;
	spi-max-frequency = <10000000>;

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

		partition@0 {
			label = "u-boot";
			reg = <0x0 0x40000>;
			read-only;
		};
		partition@40000 {
			label = "u-boot-env";
			reg = <0x40000 0x10000>;
			read-only;
		};
		partition@50000 {
			label = "u-boot-env2";
			reg = <0x50000 0x10000>;
		};
		partition@60000 {
			label = "jffs";
			reg = <0x60000 0x100000>;
		};
		partition@160000 {
			label = "jffs2";
			reg = <0x160000 0x100000>;
		};
		partition@b260000 {
			label = "firmware";
			reg = <0x260000 0x6d0000>;
			compatible = "openwrt,uimage", "denx,uimage";
			openwrt,ih-magic = <0x83800000>;
		};
		partition@930000 {
			label = "rootfs_data";
			reg = <0x930000 0x6d0000>;
		};
	};
};

};

But there isn´t the definition of the sub-partitions of "firmware", i want to change "rootfs_data". can anyone tell me where this is defined?

or is it enough to expand the firmware partition and the builder will use the free space for rootfs_data?

thanks

Ok i figured that out at least partially.

Change partition layout, double the system partition and delete the recovery partition:
target/linux/realtek/dts-5.15/rtl8380_zyxel_gs1900.dtsi, line 94:
reg = <0x260000 0xda0000>; //reg = <0x260000 0x6d0000>;

  • delete following partition@930000 {.....}*

Change max image size so make don´t complain about a too big image
I dunno how this size is calculated (thats not the partition size?), i just doubled it:
target/linux/realtek/image/common.mk: line 61,
IMAGE_SIZE := 13952k #6976k

And now openwrt uses the free space on the partition:

proc/mtd | df -h

root@OpenWrt:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "u-boot-env2"
mtd3: 00100000 00010000 "jffs"
mtd4: 00100000 00010000 "jffs2"
mtd5: 00da0000 00010000 "firmware"
mtd6: 00350000 00010000 "kernel"
mtd7: 00a50000 00010000 "rootfs"
mtd8: 006b0000 00010000 "rootfs_data"

root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 3.8M 3.8M 0 100% /rom
tmpfs 59.2M 232.0K 59.0M 0% /tmp
/dev/mtdblock8 6.7M 368.0K 6.3M 5% /overlay
overlayfs:/overlay 6.7M 368.0K 6.3M 5% /
tmpfs 512.0K 0 512.0K 0% /dev

The only downside of this is that we loose ability to use the stock uboot recovery, but i don´t think many people care about that?
Mabe it's possible to split the device definition in two, one with stock partition layout and one with space to use?

2 Likes

I'd be interested in this, I have the GS1900-48 and attempted a DTS edit but ended up with no overlay space at all.

1 Like

Can you post "cat /proc/mtd" and "dmesg" ?
I have formated the old runtime2 partition before, mabe he complains about the image he finds there...

I'll test again soon, I have a few ideas to try out.

Fixed it, I now have a 6MB overlay partition using the old runtime2 space:

diff --git a/target/linux/realtek/dts-5.15/rtl8393_zyxel_gs1900-48.dts b/target/linux/realtek/dts-5.15/rtl8393_zyxel_gs1900-48.dts
index c7ddd8313a..201f0afc1b 100644
--- a/target/linux/realtek/dts-5.15/rtl8393_zyxel_gs1900-48.dts
+++ b/target/linux/realtek/dts-5.15/rtl8393_zyxel_gs1900-48.dts
@@ -131,14 +131,10 @@
                        };
                        partition@260000 {
                                label = "firmware";
-                               reg = <0x260000 0x6d0000>;
+                               reg = <0x260000 0xca0000>;
                                compatible = "openwrt,uimage", "denx,uimage";
                                openwrt,ih-magic = <0x83800000>;
                        };
-                       partition@930000 {
-                               label = "runtime2";
-                               reg = <0x930000 0x6d0000>;
-                       };
                };
        };
 };
diff --git a/target/linux/realtek/image/common.mk b/target/linux/realtek/image/common.mk
index 37370f1999..7f071b794a 100644
--- a/target/linux/realtek/image/common.mk
+++ b/target/linux/realtek/image/common.mk
@@ -58,7 +58,7 @@ endef
 
 define Device/zyxel_gs1900
   DEVICE_VENDOR := ZyXEL
-  IMAGE_SIZE := 6976k
+  IMAGE_SIZE := 12928k
   UIMAGE_MAGIC := 0x83800000
   KERNEL_INITRAMFS := \
        kernel-bin | \

Here's what it looks like:

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 3.0M      3.0M         0 100% /rom
tmpfs                    59.1M     40.0K     59.0M   0% /tmp
tmpfs                    59.1M     68.0K     59.0M   0% /tmp/root
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock8            6.4M    360.0K      6.0M   6% /overlay
overlayfs:/overlay        6.4M    360.0K      6.0M   6% /
root@OpenWrt:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00010000 00010000 "u-boot-env2"
mtd3: 00100000 00010000 "jffs"
mtd4: 00100000 00010000 "jffs2"
mtd5: 00ca0000 00010000 "firmware"
mtd6: 00360000 00010000 "kernel"
mtd7: 00940000 00010000 "rootfs"
mtd8: 00660000 00010000 "rootfs_data"

Nice, what was the problem?

How do u calculate the image_size?

Image size was 1024K less than another post which was also wiping the prior JFFS partition. I had errors wiping the JFFS but simply extending over the extra runtime2 partition gives a nice bump.
For reference I could have gone larger, but this is just a limit on the image builder. The actual size should be 6976K larger than before, the value of 0x6d0000 in KB.

I might try with 13952K in future but I think the overlay size is dictated by the partition table. For whatever reason when I removed the earlier partitions I was seeing errors creating the overlay FS, and messages about insufficient erase blocks.