[openwrt/openwrt] gemini: override IB-4220-B partitions for firmware

LEDE Commits lede-commits at lists.infradead.org
Tue Feb 10 23:48:24 PST 2026


linusw pushed a commit to openwrt/openwrt.git, branch openwrt-25.12:
https://git.openwrt.org/dd4423f29854c7436b07d2b43b4aefe82125ac7a

commit dd4423f29854c7436b07d2b43b4aefe82125ac7a
Author: Linus Walleij <linusw at kernel.org>
AuthorDate: Mon Jan 26 08:21:29 2026 +0100

    gemini: override IB-4220-B partitions for firmware
    
    To optimize the flash usage and to make firmware upgrades
    simpler, catenate the three firmware partitions "Kern",
    "Ramdisk" and "Application" into one, and use all of this
    for the combined MTD-splitted kernel+rootfs.
    
    This works fine as long as the kernel is placed in the
    beginning of this firmware partition and we leave the
    RedBoot partition as is, so the boot loader still can load
    the kernel from the first two RedBoot partitions.
    
    Using the RedBoot partitions "as is" can be considered
    harmful, because when you flash to a RedBoot partition the
    file size is used for downsizing of the partition and make
    firmware upgrades fail if they are larger than the RedBoot
    partition size after flashing, despite there is actually
    flash there. So overriding with fixed partitions is just
    generally a good idea.
    
    Link: https://github.com/openwrt/openwrt/pull/21820
    (cherry picked from commit 387752dc76ba2de2510147427ff1361dfd90c556)
    Link: https://github.com/openwrt/openwrt/pull/21973
    Signed-off-by: Linus Walleij <linusw at kernel.org>
---
 .../gemini/base-files/lib/upgrade/platform.sh      | 52 ++++++++++----
 target/linux/gemini/config-6.12                    |  1 +
 target/linux/gemini/image/Makefile                 | 78 +++++++++++++++++----
 ...emini-augment-DTS-with-botched-partitions.patch | 80 ++++++++++++++++++++++
 4 files changed, 187 insertions(+), 24 deletions(-)

diff --git a/target/linux/gemini/base-files/lib/upgrade/platform.sh b/target/linux/gemini/base-files/lib/upgrade/platform.sh
index 0547be8fb0..19a6488f31 100644
--- a/target/linux/gemini/base-files/lib/upgrade/platform.sh
+++ b/target/linux/gemini/base-files/lib/upgrade/platform.sh
@@ -56,8 +56,8 @@ gemini_check_redboot_parts() {
 	fi
 }
 
-gemini_do_platform_upgrade() {
-	echo "Extract the three firmware parts"
+gemini_do_redboot_upgrade() {
+	echo "Extract the three firmware parts from tarfile"
 	echo 3 > /proc/sys/vm/drop_caches
 	echo "COMMENCING UPGRADE. BE PATIENT, THIS IS NOT FAST!"
 	KFSZ=$(tar xfz "$1" zImage -O | wc -c)
@@ -74,16 +74,45 @@ gemini_do_platform_upgrade() {
 	[ $? -ne 0 ] && exit 1
 }
 
+# This converts the old RedBoot partitioning to the new shared
+# "firmware" partition.
+gemini_do_flat_redboot_upgrade() {
+	ESZ=131072
+	KSZ=$(($ESZ * $2))
+	RSZ=$(($ESZ * $3))
+	KRSZ=$(($KSZ + $RSZ))
+	ASZ=$(($ESZ * $4))
+	echo "Partition sizes: Kern ${KSZ}, Ramdisk ${RSZ}, Application ${ASZ}"
+	echo "Extract Kern from flat image ${1}"
+	echo "Write Kern from flat image ${1}"
+	dd if="$1" bs=1 count=${KSZ} | mtd write - Kern
+	echo "Write rd.gz from flat image ${1}"
+	dd if="$1" bs=1 skip=${KSZ} count=${RSZ} | mtd write - Ramdisk
+	echo "Write hddapp.tgz from flat image ${1}"
+	dd if="$1" bs=1 skip=${KRSZ} count=${ASZ} | mtd write - Application
+}
+
+# Check if we have the new partition scheme, else do it the old
+# way.
+gemini_do_combined_upgrade() {
+	NAME=`cat ${MTDSYSFS}/mtd1/name`
+	if test "x${NAME}" == "xfirmware" ; then
+		PART_NAME=firmware
+		default_do_upgrade "$1"
+	else
+		gemini_check_redboot_parts "$1" $2 $3 $4
+		gemini_do_flat_redboot_upgrade "$1" $2 $3 $4
+	fi
+}
+
 platform_check_image() {
 	local board=$(board_name)
 
 	case "$board" in
-	dlink,dir-685)
-		return 0
-		;;
-	raidsonic,ib-4220-b|\
+	dlink,dir-685|\
 	itian,sq201|\
-	storlink,gemini324)
+	storlink,gemini324|\
+	raidsonic,ib-4220-b)
 		return 0
 		;;
 	esac
@@ -100,14 +129,13 @@ platform_do_upgrade() {
 		PART_NAME=firmware
 		default_do_upgrade "$1"
 		;;
+	raidsonic,ib-4220-b)
+		gemini_do_combined_upgrade "$1" 24 48 48
+		;;
 	itian,sq201|\
 	storlink,gemini324)
 		gemini_check_redboot_parts "$1" 16 48 48
-		gemini_do_platform_upgrade "$1"
-		;;
-	raidsonic,ib-4220-b)
-		gemini_check_redboot_parts "$1" 24 48 48
-		gemini_do_platform_upgrade "$1"
+		gemini_do_redboot_upgrade "$1"
 		;;
 	esac
 }
diff --git a/target/linux/gemini/config-6.12 b/target/linux/gemini/config-6.12
index da7cec5cfe..ad8e5e1438 100644
--- a/target/linux/gemini/config-6.12
+++ b/target/linux/gemini/config-6.12
@@ -281,6 +281,7 @@ CONFIG_MTD_PHYSMAP=y
 CONFIG_MTD_PHYSMAP_GEMINI=y
 CONFIG_MTD_REDBOOT_PARTS=y
 CONFIG_MTD_SPLIT_FIRMWARE=y
+CONFIG_MTD_SPLIT_OPENWRT_PROLOG=y
 CONFIG_MTD_SPLIT_WRGG_FW=y
 CONFIG_NAMESPACES=y
 CONFIG_NEED_DMA_MAP_STATE=y
diff --git a/target/linux/gemini/image/Makefile b/target/linux/gemini/image/Makefile
index 1b5961db4e..d4c54014ad 100644
--- a/target/linux/gemini/image/Makefile
+++ b/target/linux/gemini/image/Makefile
@@ -89,14 +89,23 @@ endef
 # 0x000000320000-0x000000920000 : "Ramdisk" - second part of the kernel and
 #                                 some padding goes here
 # 0x000000920000-0x000000f20000 : "Application" - rootfs goes here
+
+define CreateStorlinkProlog
+	# 512 bytes copy routine
+	dd if=$(KDIR)/copy-kernel-$(2).bin of=$(1)
+	# Add OpenWrt prolog header (used by partition splitter)
+	echo "OPENWRT-PROLOG-512" >> $(1)
+	stat -c %s ${IMAGE_KERNEL} >> $(1)
+	$(call Image/pad-to,$(1),512)
+endef
+
 define CreateStorlinkTarfile
 	mkdir -p $@.tmp
 
 	# "Application" partition is the rootfs
 	mv $@ $@.tmp/hddapp.tgz
-	# 512 bytes copy routine
-	dd if=$(KDIR)/copy-kernel-$(2).bin of=$@.tmp/zImage
-	$(call Image/pad-to,$@.tmp/zImage,512)
+	$(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >>$@.tmp/hddapp.tgz
+	$(call CreateStorlinkProlog,$@.tmp/zImage,$(2))
 	# Copy first part of the kernel into zImage
 	dd if=$(IMAGE_KERNEL) of=$@.tmp/zImage bs=1 seek=512 count=$(3)
 	$(call Image/pad-to,$@.tmp/zImage,128k)
@@ -114,14 +123,60 @@ define CreateStorlinkTarfile
 	exit 0
 endef
 
+define CreateStorlinkFactoryfile
+	mkdir -p $@.tmp
+	$(call CreateStorlinkProlog,$@.tmp/zImage,$(2))
+	# Copy first part of the kernel into zImage
+	dd if=$(IMAGE_KERNEL) of=$@.tmp/zImage bs=1 seek=512 count=$(3)
+	$(call Image/pad-to,$@.tmp/zImage,128k)
+	# Put the rest of the kernel into the "ramdisk"
+	dd if=$(IMAGE_KERNEL) of=$@-ramdisk bs=1 skip=$(3) conv=sync
+	$(call Image/pad-to,$@-ramdisk,128k)
+	# Append the root filesystem right after this
+	dd if=$(IMAGE_ROOTFS) >> $@-ramdisk
+	$(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >> $@-ramdisk
+	# Now rd.gz is too big so split off rd.gz and the tail into "hddapp.gz"
+	dd if=$@-ramdisk of=$@.tmp/rd.gz bs=1 count=6144k conv=sync
+	dd if=$@-ramdisk of=$@.tmp/hddapp.tgz bs=1 skip=6144k count=6144k conv=sync
+	rm -f $@-ramdisk
+	# Taglabel
+	cp ./ImageInfo-$(1) $@.tmp/ImageInfo
+
+	sed -i -e "s/DATESTR/`date +%Y%m%d $(if $(SOURCE_DATE_EPOCH),--date "@$(SOURCE_DATE_EPOCH)")`/g" $@.tmp/ImageInfo
+
+	(cd $@.tmp; tar --sort=name --owner=0 --group=0 --numeric-owner -czf $@ * \
+		$(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)"))
+
+	rm -rf $@.tmp
+	exit 0
+endef
+
+define CreateStorlinkSysupgradefile
+	$(call CreateStorlinkProlog,$@,$(2))
+	# Catenate the kernel
+	dd if=$(IMAGE_KERNEL) >> $@
+	$(call Image/pad-to,$@,128k)
+	# Append the root filesystem right after this
+	dd if=$(IMAGE_ROOTFS) >> $@
+	$(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >> $@
+endef
+
 # 2048k "Kern" partition
-define Build/storlink-default-image
+define Build/storlink-2048k-default-image
 	$(call CreateStorlinkTarfile,$(1),2048k,2096640)
 endef
 
+define Build/storlink-2048k-sysupgrade-image
+	$(call CreateStorlinkSysupgradefile,$(1),2048k)
+endef
+
 # 3072k "Kern" partition
-define Build/raidsonic-ib-4220-b-image
-	$(call CreateStorlinkTarfile,$(1),3072k,3145216)
+define Build/storlink-3072k-factory-image
+	$(call CreateStorlinkFactoryfile,$(1),3072k,3145216)
+endef
+
+define Build/storlink-3072k-sysupgrade-image
+	$(call CreateStorlinkSysupgradefile,$(1),3072k)
 endef
 
 # WBD-111 and WBD-222:
@@ -203,9 +258,9 @@ define Device/storlink-reference
 	# Ramdisk      6144k remaining zImage
 	# Application  6144k
 	IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 128k | \
-		storlink-default-image $(1)
+		storlink-2048k-default-image $(1)
 	IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | pad-to 128k | \
-		storlink-default-image $(1) | append-metadata
+		storlink-2048k-default-image $(1) | append-metadata
 	DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
 endef
 
@@ -227,10 +282,9 @@ define Device/raidsonic_ib-4220-b
 	# Kern         3072k - 512 | = 3145216
 	# Ramdisk      6144k       | = 9216k
 	# Application  6144k       | = 15360k
-	IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 128k | \
-		raidsonic-ib-4220-b-image $(1)
-	IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | pad-to 128k | \
-		raidsonic-ib-4220-b-image $(1) | append-metadata
+	IMAGE/factory.bin := storlink-3072k-factory-image $(1)
+	IMAGE/sysupgrade.bin := storlink-3072k-sysupgrade-image $(1) |\
+			append-metadata
 endef
 TARGET_DEVICES += raidsonic_ib-4220-b
 
diff --git a/target/linux/gemini/patches-6.12/303-gemini-augment-DTS-with-botched-partitions.patch b/target/linux/gemini/patches-6.12/303-gemini-augment-DTS-with-botched-partitions.patch
new file mode 100644
index 0000000000..e007de3acf
--- /dev/null
+++ b/target/linux/gemini/patches-6.12/303-gemini-augment-DTS-with-botched-partitions.patch
@@ -0,0 +1,80 @@
+From 1b5c6be7b6dc6c096e1fd55ce10809d350e3afab Mon Sep 17 00:00:00 2001
+From: Linus Walleij <linusw at kernel.org>
+Date: Mon, 26 Jan 2026 08:09:04 +0100
+Subject: [PATCH] gemini: augment DTS with botched partitions
+
+We override the RedBoot FIS partition table with a custom one
+using fixed-partitions.
+
+Mostly this is a 1-to-1 copy, but the three partitions called
+"Kern", "Ramdisk" and "Application" are combined into one
+called "firmware" which is optimal for OpenWrt.
+
+The RedBoot bootloader still sees the three partitions and will
+load the first two into memory to boot the system, which
+is fine: the kernel will still be there.
+
+To avoid confusing the MTD partition splitter we also need to
+remove any command line root partition arguments.
+
+Signed-off-by: Linus Walleij <linusw at kernel.org>
+---
+ arch/arm/boot/dts/gemini/gemini-nas4220b.dts | 39 ++++++++++++++++++--
+ 1 file changed, 35 insertions(+), 4 deletions(-)
+
+--- a/arch/arm/boot/dts/gemini/gemini-nas4220b.dts
++++ b/arch/arm/boot/dts/gemini/gemini-nas4220b.dts
+@@ -20,7 +20,7 @@
+ 	};
+ 
+ 	chosen {
+-		bootargs = "console=ttyS0,19200n8 root=/dev/mtdblock3 rw rootfstype=squashfs,jffs2 rootwait";
++		bootargs = "console=ttyS0,19200n8";
+ 		stdout-path = &uart0;
+ 	};
+ 
+@@ -82,10 +82,41 @@
+ 			/* 16MB of flash */
+ 			reg = <0x30000000 0x01000000>;
+ 
++			/*
++			 * Override the RedBoot partition table with fixed partitions
++			 * in order to create a coherent "firmware" partition so that
++			 * we can have optimal flash usage with OpenWrt in a big
++			 * MTD-splitted "firmware" partition.
++			 */
+ 			partitions {
+-				compatible = "redboot-fis";
+-				/* Eraseblock at 0xfe0000 */
+-				fis-index-block = <0x7f>;
++				compatible = "fixed-partitions";
++				#address-cells = <1>;
++				#size-cells = <1>;
++				partition at 0 {
++					label = "BOOT";
++					reg = <0x00000000 0x00020000>;
++					read-only;
++				};
++				partition at 1 {
++					compatible = "openwrt,executable-prolog";
++					label = "firmware";
++					reg = <0x00020000 0x00f00000>;
++				};
++				partition at 2 {
++					label = "VCTL";
++					reg = <0x00f20000 0x00020000>;
++					read-only;
++				};
++				partition at 3 {
++					label = "CurConf";
++					reg = <0x00f40000 0x000a0000>;
++					read-only;
++				};
++				partition at 4 {
++					label = "FIS directory";
++					reg = <0x00fe0000 0x00020000>;
++					read-only;
++				};
+ 			};
+ 		};
+ 




More information about the lede-commits mailing list