[PATCH] mtdsplit_uimage: Split also after offsetted uImage

Linus Walleij linus.walleij at linaro.org
Tue Jan 23 14:17:26 PST 2024


The uImage splitter recognizes a rootfs either:

1. Right after the uImage if it comes first in the
   partition or
2. Before the uImage if it is located at an offset
   inside the partition.

Add a third case:

3. After the uImage also at an offset inside the
   partition, if and only if 1 and 2 fails.

The reason why this is needed is because on the
BCM6328-based Inteno XG6846 we need to put a small
U-Boot binary first in the partition, then the uImage,
then the rootfs.

The U-Boot binary that comes first cannot be split off
into its own partition in this case because it needs
to be part of the bigger "firmware" partition. Which
we use for installation and upgrades.

Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
---
 .../files/drivers/mtd/mtdsplit/mtdsplit_uimage.c      | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
index a3e55fb1fe38..de043fb9f702 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
@@ -217,11 +217,22 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
 		if (ret) {
 			pr_debug("no rootfs before uImage in \"%s\"\n",
 				 master->name);
-			goto err_free_buf;
-		}
 
-		rootfs_offset = 0;
-		rootfs_size = uimage_offset;
+			/* Try after the uImage */
+			ret = mtd_find_rootfs_from(master, uimage_offset + uimage_size,
+						   master->size, &rootfs_offset, &type);
+			if (ret) {
+				pr_debug("no rootfs after uImage either in \"%s\"\n",
+					 master->name);
+				goto err_free_buf;
+			}
+
+			rootfs_size = master->size - rootfs_offset;
+			uimage_size = rootfs_offset - uimage_offset;
+		} else {
+			rootfs_offset = 0;
+			rootfs_size = uimage_offset;
+		}
 	}
 
 	if (rootfs_size == 0) {

---
base-commit: 1b7e62b20b1735fcdc498a35e005afcd775abcf4
change-id: 20240123-offsetted-uimage-splitter-f5b65f0df2ed

Best regards,
-- 
Linus Walleij <linus.walleij at linaro.org>




More information about the openwrt-devel mailing list