Skip to contentSkip to conversation

common: fdt_support: Check mtdparts cell size

PATCH Superseded Stefan Mavrodiev 2 participants 3 messages Apr 12, 2019 – Apr 22, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: fdt_support: Check mtdparts cell size

When using fdt_fixup_mtdparts() offset and length cell sizes are limited to 4 bytes (1 cell). However if the mtd device is bigger then 4GiB, then #address-cells and #size-cells are 8 bytes (2 cells) [1].

This patch read #size-cells and uses either fdt32_t or fdt64_t cell size. The default is fdt32_t.

[1] Documentation/devicetree/bindings/mtd/partition.txt

---
 common/fdt_support.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
common/fdt_support.c +24 -9
index 42583e3ed8..b0501e12e6 100644
@@ -724,11 +724,6 @@ int fdt_increase_size(void *fdt, int add_len)
 #include <jffs2/load_kernel.h>
 #include <mtd_node.h>
 
-struct reg_cell {
-	unsigned int r0;
-	unsigned int r1;
-};
-
 static int fdt_del_subnodes(const void *blob, int parent_offset)
 {
 	int off, ndepth;
@@ -787,15 +782,22 @@ int fdt_node_set_part_info(void *blob, int parent_offset,
 {
 	struct list_head *pentry;
 	struct part_info *part;
-	struct reg_cell cell;
 	int off, ndepth = 0;
 	int part_num, ret;
+	int sizecell;
 	char buf[64];
 
 	ret = fdt_del_partitions(blob, parent_offset);
 	if (ret < 0)
 		return ret;
 
+	/*
+	 * Check if size/address is 1 or 2 cells.
+	 * We assume #address-cells and #size-cells have same value.
+	 */
+	sizecell = fdt_getprop_u32_default_node(blob, parent_offset,
+						0, "#size-cells", 1);
+
 	/*
 	 * Check if it is nand {}; subnode, adjust
 	 * the offset in this case
@@ -844,10 +846,23 @@ add_ro:
 				goto err_prop;
 		}
 
-		cell.r0 = cpu_to_fdt32(part->offset);
-		cell.r1 = cpu_to_fdt32(part->size);
 add_reg:
-		ret = fdt_setprop(blob, newoff, "reg", &cell, sizeof(cell));
+		if (sizecell == 2) {
+			fdt64_t cell[2];
+
+			cell[0] = cpu_to_fdt64(part->offset);
+			cell[1] = cpu_to_fdt64(part->size);
+			ret = fdt_setprop(blob, newoff,
+					  "reg", cell, sizeof(cell));
+		} else {
+			fdt32_t cell[2];
+
+			cell[0] = cpu_to_fdt32(part->offset);
+			cell[1] = cpu_to_fdt32(part->size);
+			ret = fdt_setprop(blob, newoff,
+					  "reg", cell, sizeof(cell));
+		}
+
 		if (ret == -FDT_ERR_NOSPACE) {
 			ret = fdt_increase_size(blob, 512);
 			if (!ret)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 common: fdt_support: Check mtdparts cell size

Hi Stefan,

Quoted 61 lines · Stefan Mavrodiev

When using fdt_fixup_mtdparts() offset and length cell sizes are limited to 4 bytes (1 cell). However if the mtd device is bigger then 4GiB, then #address-cells and #size-cells are 8 bytes (2 cells) [1].

This patch read #size-cells and uses either fdt32_t or fdt64_t cell size. The default is fdt32_t.

[1] Documentation/devicetree/bindings/mtd/partition.txt

---
 common/fdt_support.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
common/fdt_support.c +8 -7
index 42583e3ed8..b0501e12e6 100644
@@ -724,11 +724,6 @@ int fdt_increase_size(void *fdt, int add_len)
 #include <jffs2/load_kernel.h>
 #include <mtd_node.h>
 
-struct reg_cell {
-       unsigned int r0;
-       unsigned int r1;
-};
-
 static int fdt_del_subnodes(const void *blob, int parent_offset)
 {
        int off, ndepth;
@@ -787,15 +782,22 @@ int fdt_node_set_part_info(void *blob, int parent_offset,
 {
        struct list_head *pentry;
        struct part_info *part;
-       struct reg_cell cell;
        int off, ndepth = 0;
        int part_num, ret;
+       int sizecell;
        char buf[64];
 
        ret = fdt_del_partitions(blob, parent_offset);
        if (ret < 0)
                return ret;
 
+       /*
+        * Check if size/address is 1 or 2 cells.
+        * We assume #address-cells and #size-cells have same value.
+        */
+       sizecell = fdt_getprop_u32_default_node(blob, parent_offset,
+                                               0, "#size-cells", 1);
+
        /*
         * Check if it is nand {}; subnode, adjust
         * the offset in this case
@@ -844,10 +846,23 @@ add_ro:
                                goto err_prop;
                }
 
-               cell.r0 = cpu_to_fdt32(part->offset);

common/fdt_support.c add_ro: · line 856

Quoted 10 lines
common/fdt_support.c +7 -2
-               cell.r1 = cpu_to_fdt32(part->size);
 add_reg:
-               ret = fdt_setprop(blob, newoff, "reg", &cell, sizeof(cell));
+               if (sizecell == 2) {
+                       fdt64_t cell[2];
+
+                       cell[0] = cpu_to_fdt64(part->offset);
+                       cell[1] = cpu_to_fdt64(part->size);
+                       ret = fdt_setprop(blob, newoff,
+                                         "reg", cell, sizeof(cell));

Can you use fdt_setprop_u64() and ..._u32() instead?

Quoted 13 lines
common/fdt_support.c +9 -1
+               } else {
+                       fdt32_t cell[2];
+
+                       cell[0] = cpu_to_fdt32(part->offset);
+                       cell[1] = cpu_to_fdt32(part->size);
+                       ret = fdt_setprop(blob, newoff,
+                                         "reg", cell, sizeof(cell));
+               }
+
                if (ret == -FDT_ERR_NOSPACE) {
                        ret = fdt_increase_size(blob, 512);
                        if (!ret)
--
Quoted 2 lines

2.17.1

Regards,
SImon

#2 lore raw

PATCH 1/1 common: fdt_support: Check mtdparts cell size

Quoted 62 lines · Simon Glass

Hi Stefan,

Quoted 59 lines · Stefan Mavrodiev

When using fdt_fixup_mtdparts() offset and length cell sizes are limited to 4 bytes (1 cell). However if the mtd device is bigger then 4GiB, then #address-cells and #size-cells are 8 bytes (2 cells) [1].

This patch read #size-cells and uses either fdt32_t or fdt64_t cell size. The default is fdt32_t.

[1] Documentation/devicetree/bindings/mtd/partition.txt

---
  common/fdt_support.c | 33 ++++++++++++++++++++++++---------
  1 file changed, 24 insertions(+), 9 deletions(-)
common/fdt_support.c +8 -6
index 42583e3ed8..b0501e12e6 100644
@@ -724,11 +724,6 @@ int fdt_increase_size(void *fdt, int add_len)
  #include <jffs2/load_kernel.h>
  #include <mtd_node.h>
 
-struct reg_cell {
-       unsigned int r0;
-       unsigned int r1;
-};
-
  static int fdt_del_subnodes(const void *blob, int parent_offset)
  {
         int off, ndepth;
@@ -787,15 +782,22 @@ int fdt_node_set_part_info(void *blob, int parent_offset,
  {
         struct list_head *pentry;
         struct part_info *part;
-       struct reg_cell cell;
         int off, ndepth = 0;
         int part_num, ret;
+       int sizecell;
         char buf[64];
 
         ret = fdt_del_partitions(blob, parent_offset);
         if (ret < 0)
                 return ret;
 
+       /*
+        * Check if size/address is 1 or 2 cells.
+        * We assume #address-cells and #size-cells have same value.
+        */
+       sizecell = fdt_getprop_u32_default_node(blob, parent_offset,
+                                               0, "#size-cells", 1);
+
         /*
          * Check if it is nand {}; subnode, adjust
          * the offset in this case
@@ -844,10 +846,23 @@ add_ro:
                                 goto err_prop;
                 }
 
Quoted 12 lines

common/fdt_support.c add_ro: · line 856

Quoted 11 lines
common/fdt_support.c +7 -3
-               cell.r0 = cpu_to_fdt32(part->offset);
-               cell.r1 = cpu_to_fdt32(part->size);
  add_reg:
-               ret = fdt_setprop(blob, newoff, "reg", &cell, sizeof(cell));
+               if (sizecell == 2) {
+                       fdt64_t cell[2];
+
+                       cell[0] = cpu_to_fdt64(part->offset);
+                       cell[1] = cpu_to_fdt64(part->size);
+                       ret = fdt_setprop(blob, newoff,
+                                         "reg", cell, sizeof(cell));

Can you use fdt_setprop_u64() and ..._u32() instead?

Sure.

Quoted 10 lines
Quoted 10 lines
common/fdt_support.c +9 -0
+               } else {
+                       fdt32_t cell[2];
+
+                       cell[0] = cpu_to_fdt32(part->offset);
+                       cell[1] = cpu_to_fdt32(part->size);
+                       ret = fdt_setprop(blob, newoff,
+                                         "reg", cell, sizeof(cell));
+               }
+
Quoted 8 lines
Quoted 6 lines
common/fdt_support.c +0 -1
                 if (ret == -FDT_ERR_NOSPACE) {
                         ret = fdt_increase_size(blob, 512);
                         if (!ret)
--

2.17.1

Regards,
SImon

Best regards,
Stefan Mavrodiev