Skip to contentSkip to conversation

dt-bindings: mtd: explicitly document nesting partitions descriptions

PATCH In review Rafał Miłecki 3 participants 4 messages Jul 13, 2018 – Jul 26, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dt-bindings: mtd: explicitly document nesting partitions descriptions

From: Rafał Miłecki <[email protected]>

Documentation was already saying that fixed and dynamic partitioning can be mixed but was missing a clear description and examples. This commit adds a proper documentation of how descriptions can be nested and how layouts can be mixed.

This addition is important for partitions that contain subpartitions. In such cases partitions have to be properly described in order to let system handle them correctly.

Depending on situation, nesting descriptions may provide more accurate logic/structure and/or allow mixing partitioning types (various "compatible" values).

---
V2: Rewrote example: I can include "brcm,trx" now as its Documentation
has been pushed into mtd git tree.
Updated commit message.

---
 .../devicetree/bindings/mtd/partition.txt          | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)
Documentation/devicetree/bindings/mtd/partition.txt +46 -0
index a8f382642ba9..afbbd870496d 100644
@@ -14,6 +14,13 @@ method is used for a given flash device. To describe the method there should be
 a subnode of the flash device that is named 'partitions'. It must have a
 'compatible' property, which is used to identify the method to use.
 
+When a single partition is represented with a DT node (it depends on a used
+format) it may also be described using above rules ('compatible' and optionally
+some extra properties / subnodes). It allows describing more complex,
+hierarchical (multi-level) layouts and should be used if there is some
+significant relation between partitions or some partition internally uses
+another partitioning method.
+
 Available bindings are listed in the "partitions" subdirectory.
 
 
@@ -109,3 +116,42 @@ flash@2 {
 		};
 	};
 };
+
+flash@3 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		partition@0 {
+			label = "bootloader";
+			reg = <0x000000 0x100000>;
+			read-only;
+		};
+
+		firmware@100000 {
+			label = "firmware";
+			reg = <0x100000 0xe00000>;
+			compatible = "brcm,trx";
+		};
+
+		calibration@f00000 {
+			label = "calibration";
+			reg = <0xf00000 0x100000>;
+			compatible = "fixed-partitions";
+			ranges = <0 0xf00000 0x100000>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			partition@0 {
+				label = "wifi0";
+				reg = <0x000000 0x080000>;
+			};
+
+			partition@80000 {
+				label = "wifi1";
+				reg = <0x080000 0x080000>;
+			};
+		};
+	};
+};
Signature · 6 lines
2.13.7


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

PATCH v2 2/2 mtd: partitions: use DT info for parsing partitions with "compatible" prop

From: Rafał Miłecki <[email protected]>

So far only flash devices could be described in DT regarding partitions parsing. That could be done with "partitions" subnode and a proper "compatible" string.

Some devices may use hierarchical (multi-level) layouts and may mix used layouts (fixed and dynamic). Describing that in DT is done by specifying "compatible" for DT-represented partition plus optionally more properties and/or subnodes.

To support such layouts each DT partition has to be checked for additional description.

Please note this implementation will work in parallel with support for partition type specified for non-DT setups. That already works since commit 1a0915be1926 ("mtd: partitions: add support for partition parsers").

---
V2: Updated commit message (more details + info about non-DT cases)

---
 drivers/mtd/mtdpart.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/mtd/mtdpart.c +13 -20
index f8d3a015cdad..52e2cb35fc79 100644
@@ -322,22 +322,6 @@ static inline void free_partition(struct mtd_part *p)
 	kfree(p);
 }
 
-/**
- * mtd_parse_part - parse MTD partition looking for subpartitions
- *
- * @slave: part that is supposed to be a container and should be parsed
- * @types: NULL-terminated array with names of partition parsers to try
- *
- * Some partitions are kind of containers with extra subpartitions (volumes).
- * There can be various formats of such containers. This function tries to use
- * specified parsers to analyze given partition and registers found
- * subpartitions on success.
- */
-static int mtd_parse_part(struct mtd_part *slave, const char *const *types)
-{
-	return parse_mtd_partitions(&slave->mtd, types, NULL);
-}
-
 static struct mtd_part *allocate_partition(struct mtd_info *parent,
 			const struct mtd_partition *part, int partno,
 			uint64_t cur_offset)
@@ -735,8 +719,8 @@ int add_mtd_partitions(struct mtd_info *master,
 
 		add_mtd_device(&slave->mtd);
 		mtd_add_partition_attrs(slave);
-		if (parts[i].types)
-			mtd_parse_part(slave, parts[i].types);
+		/* Look for subpartitions */
+		parse_mtd_partitions(&slave->mtd, parts[i].types, NULL);
 
 		cur_offset = slave->offset + slave->mtd.size;
 	}
@@ -812,6 +796,12 @@ static const char * const default_mtd_part_types[] = {
 	NULL
 };
 
+/* Check DT only when looking for subpartitions. */
+static const char * const default_subpartition_types[] = {
+	"ofpart",
+	NULL
+};
+
 static int mtd_part_do_parse(struct mtd_part_parser *parser,
 			     struct mtd_info *master,
 			     struct mtd_partitions *pparts,
@@ -882,7 +872,9 @@ static int mtd_part_of_parse(struct mtd_info *master,
 	const char *fixed = "fixed-partitions";
 	int ret, err = 0;
 
-	np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
+	np = mtd_get_of_node(master);
+	if (!mtd_is_partition(master))
+		np = of_get_child_by_name(np, "partitions");
 	of_property_for_each_string(np, "compatible", prop, compat) {
 		parser = mtd_part_get_compatible_parser(compat);
 		if (!parser)
@@ -945,7 +937,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
 	int ret, err = 0;
 
 	if (!types)
-		types = default_mtd_part_types;
+		types = mtd_is_partition(master) ? default_subpartition_types :
+			default_mtd_part_types;
 
 	for ( ; *types; types++) {
 		/*
Signature · 6 lines
2.13.7


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Reviewed-by on v2 1/2
#2 lore raw
In reply to Rafał Miłecki
Quoted 15 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Documentation was already saying that fixed and dynamic partitioning can be mixed but was missing a clear description and examples. This commit adds a proper documentation of how descriptions can be nested and how layouts can be mixed.

This addition is important for partitions that contain subpartitions. In such cases partitions have to be properly described in order to let system handle them correctly.

Depending on situation, nesting descriptions may provide more accurate logic/structure and/or allow mixing partitioning types (various "compatible" values).

Quoted 8 lines

---
V2: Rewrote example: I can include "brcm,trx" now as its Documentation
has been pushed into mtd git tree.
Updated commit message.

---
 .../devicetree/bindings/mtd/partition.txt          | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw
In reply to Rafał Miłecki
Quoted 11 lines · On Fri, 13 Jul 2018 16:32:20 +0200 Rafał Miłecki <[email protected]> wrote:

From: Rafał Miłecki <[email protected]>

Documentation was already saying that fixed and dynamic partitioning can be mixed but was missing a clear description and examples. This commit adds a proper documentation of how descriptions can be nested and how layouts can be mixed.

This addition is important for partitions that contain subpartitions. In such cases partitions have to be properly described in order to let system handle them correctly.

Quoted 5 lines

Depending on situation, nesting descriptions may provide more accurate logic/structure and/or allow mixing partitioning types (various "compatible" values).

Applied both patches.

Thanks,

Boris

Quoted 59 lines

---
V2: Rewrote example: I can include "brcm,trx" now as its Documentation
has been pushed into mtd git tree.
Updated commit message.

---
 .../devicetree/bindings/mtd/partition.txt          | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)
Documentation/devicetree/bindings/mtd/partition.txt +36 -0
index a8f382642ba9..afbbd870496d 100644
@@ -14,6 +14,13 @@ method is used for a given flash device. To describe the method there should be
 a subnode of the flash device that is named 'partitions'. It must have a
 'compatible' property, which is used to identify the method to use.
 
+When a single partition is represented with a DT node (it depends on a used
+format) it may also be described using above rules ('compatible' and optionally
+some extra properties / subnodes). It allows describing more complex,
+hierarchical (multi-level) layouts and should be used if there is some
+significant relation between partitions or some partition internally uses
+another partitioning method.
+
 Available bindings are listed in the "partitions" subdirectory.
 
 
@@ -109,3 +116,42 @@ flash@2 {
 		};
 	};
 };
+
+flash@3 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		partition@0 {
+			label = "bootloader";
+			reg = <0x000000 0x100000>;
+			read-only;
+		};
+
+		firmware@100000 {
+			label = "firmware";
+			reg = <0x100000 0xe00000>;
+			compatible = "brcm,trx";
+		};
+
+		calibration@f00000 {
+			label = "calibration";
+			reg = <0xf00000 0x100000>;
+			compatible = "fixed-partitions";
+			ranges = <0 0xf00000 0x100000>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			partition@0 {
+				label = "wifi0";

Documentation/devicetree/bindings/mtd/partition.txt flash@2 { · line 157

Quoted 10 lines
Documentation/devicetree/bindings/mtd/partition.txt +10 -0
+				reg = <0x000000 0x080000>;
+			};
+
+			partition@80000 {
+				label = "wifi1";
+				reg = <0x080000 0x080000>;
+			};
+		};
+	};
+};

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/