mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function
@ 2024-03-08  9:15 Uwe Kleine-König
  2024-03-08  9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2024-03-08  9:15 UTC (permalink / raw)
  To: barebox; +Cc: Uwe Kleine-König

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This is a preparation for the next commit that fixes mtd partition
creation.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/of/partition.c | 81 ++++++++++++++++++++++++------------------
 1 file changed, 47 insertions(+), 34 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 7c9f443ee7bd..d11e1d1690f9 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -167,10 +167,55 @@ static void delete_subnodes(struct device_node *np)
 	}
 }
 
+static int of_fixup_one_partition(struct device_node *partnode, loff_t partoffset,
+				  loff_t size, const char *partname,
+				  unsigned int flags)
+{
+	int na, ns, len = 0;
+	char *name;
+	void *p;
+	u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
+	struct device_node *part;
+	int ret;
+
+	name = basprintf("partition@%0llx", partoffset);
+	if (!name)
+		return -ENOMEM;
+
+	part = of_new_node(partnode, name);
+	free(name);
+	if (!part)
+		return -ENOMEM;
+
+	p = of_new_property(part, "label", partname, strlen(partname) + 1);
+	if (!p)
+		return -ENOMEM;
+
+	na = of_n_addr_cells(part);
+	ns = of_n_size_cells(part);
+
+	of_write_number(tmp + len, partoffset, na);
+	len += na * 4;
+	of_write_number(tmp + len, size, ns);
+	len += ns * 4;
+
+	ret = of_set_property(part, "reg", tmp, len, 1);
+	if (ret)
+		return ret;
+
+	if (flags & DEVFS_PARTITION_READONLY) {
+		ret = of_set_property(part, "read-only", NULL, 0, 1);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 {
 	struct cdev *partcdev;
-	struct device_node *part, *partnode;
+	struct device_node *partnode;
 	int ret;
 	int n_cells, n_parts = 0;
 
@@ -223,10 +268,6 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 		return ret;
 
 	list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
-		int na, ns, len = 0;
-		char *name;
-		void *p;
-		u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
 		loff_t partoffset;
 
 		if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
@@ -237,37 +278,9 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 		else
 			partoffset = partcdev->offset;
 
-		name = basprintf("partition@%0llx", partoffset);
-		if (!name)
-			return -ENOMEM;
-
-		part = of_new_node(partnode, name);
-		free(name);
-		if (!part)
-			return -ENOMEM;
-
-		p = of_new_property(part, "label", partcdev->partname,
-                                strlen(partcdev->partname) + 1);
-		if (!p)
-			return -ENOMEM;
-
-		na = of_n_addr_cells(part);
-		ns = of_n_size_cells(part);
-
-		of_write_number(tmp + len, partoffset, na);
-		len += na * 4;
-		of_write_number(tmp + len, partcdev->size, ns);
-		len += ns * 4;
-
-		ret = of_set_property(part, "reg", tmp, len, 1);
+		ret = of_fixup_one_partition(partnode, partoffset, partcdev->size, partcdev->partname, partcdev->flags);
 		if (ret)
 			return ret;
-
-		if (partcdev->flags & DEVFS_PARTITION_READONLY) {
-			ret = of_set_property(part, "read-only", NULL, 0, 1);
-			if (ret)
-				return ret;
-		}
 	}
 
 	return 0;

base-commit: ed7c14536d521793199abf0597164a46ba68e8e5
-- 
2.43.0




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-08 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  9:15 [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function Uwe Kleine-König
2024-03-08  9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
2024-03-08  9:27   ` Ahmad Fatoum
2024-03-08 10:14     ` Uwe Kleine-König
2024-03-08 10:51       ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox