diff mbox series

[v2,2/4] mtdsplit_squashfs: allow devicetree to define the name of the new partition

Message ID 20210517095712.24332-3-avalentin@marcant.net
State Superseded
Headers show
Series Add support for ZyXEL LTE3301-Plus | expand

Commit Message

André Valentin May 17, 2021, 9:57 a.m. UTC
mtdsplit_squashfs always splits into rootfs and rootfs_data. Wit this
patch is not possible to give the new partition a different name.

Example:
partition@140000 {
	reg = <0x140000 0x1ea0000>;
	compatible = "openwrt,uimage", "denx,uimage", "openwrt,squashfs";
	label = "firmware";
	openwrt,offset = <380>;
	openwrt,data-partition-name = "ubi";
};
This splits at first the uImage into kernel and rootfs, after that
rootfs is splitted into rootfs (only squash) and the new ubi partition.

Signed-off-by: André Valentin <avalentin@marcant.net>
---
 .../drivers/mtd/mtdsplit/mtdsplit_squashfs.c     | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_squashfs.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_squashfs.c
index f6353da65b..9fdc425844 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_squashfs.c
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_squashfs.c
@@ -18,6 +18,7 @@ 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/byteorder/generic.h>
+#include <linux/of.h>
 
 #include "mtdsplit.h"
 
@@ -26,10 +27,12 @@  mtdsplit_parse_squashfs(struct mtd_info *master,
 			const struct mtd_partition **pparts,
 			struct mtd_part_parser_data *data)
 {
+	struct device_node *np;
 	struct mtd_partition *part;
 	struct mtd_info *parent_mtd;
 	size_t part_offset;
 	size_t squashfs_len;
+	const char *part_name = NULL;
 	int err;
 
 	err = mtd_get_squashfs_len(master, 0, &squashfs_len);
@@ -46,7 +49,18 @@  mtdsplit_parse_squashfs(struct mtd_info *master,
 		return -ENOMEM;
 	}
 
-	part->name = ROOTFS_SPLIT_NAME;
+	np = mtd_get_of_node(parent_mtd);
+	if (np && of_device_is_compatible(np, "openwrt,squashfs")) {
+		err = of_property_read_string(np, "openwrt,data-partition-name", &part_name);
+		if (err)
+			pr_debug("failed to retrieve openwrt,data-partition-name.\n");
+	}
+
+	if (part_name == NULL) {
+		part->name = ROOTFS_SPLIT_NAME;
+	} else {
+		part->name = part_name;
+	}
 	part->offset = mtd_roundup_to_eb(part_offset + squashfs_len,
 					 parent_mtd) - part_offset;
 	part->size = mtd_rounddown_to_eb(master->size - part->offset, master);