Skip to contentSkip to conversation

fdt: add common memory fixup function

PATCH New Martin Krause 3 participants 7 messages Oct 26, 2007 – Nov 27, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt: add common memory fixup function

Add the function fdt_memory() to fixup the /memory node of the fdt with the memory values detected by U-Boot (taken from bd->bi_memstart and bd->bi_memsize).

The new function is called for all boards which define CONFIG_OF_LIBFDT.

This patch removes already existing board specific memory fixup routines for boards wich have CONFIG_OF_LIBFDT defined and switches them to the new routine. Boards wich use the CONIFG_OF_FLAT_TREE method are not touched.

---
Updated patch. Please ignore all former versions.

Best Regards,
Martin Krause

 board/cds/common/ft_board.c |    9 ---------
 board/cm5200/cm5200.c       |   22 ++--------------------
 common/cmd_bootm.c          |   10 ++++++++++
 common/fdt_support.c        |   41 +++++++++++++++++++++++++++++++++++++++++
 cpu/mpc83xx/cpu.c           |   17 -----------------
 include/fdt_support.h       |    1 +
 6 files changed, 54 insertions(+), 46 deletions(-)
board/cds/common/ft_board.c +0 -9
index 9d97905..be0e824 100644
@@ -56,20 +56,11 @@ static void cds_pci_fixup(void *blob)
 void
 ft_board_setup(void *blob, bd_t *bd)
 {
-	u32 *p;
-	int len;
-
 #ifdef CONFIG_PCI
 	ft_pci_setup(blob, bd);
 #endif
 	ft_cpu_setup(blob, bd);
 
-	p = ft_get_prop(blob, "/memory/reg", &len);
-	if (p != NULL) {
-		*p++ = cpu_to_be32(bd->bi_memstart);
-		*p = cpu_to_be32(bd->bi_memsize);
-	}
-
 	cds_pci_fixup(blob);
 }
 #endif
board/cm5200/cm5200.c +2 -20
index e2ab5b8..b2a64c7 100644
@@ -256,14 +256,13 @@ static void compose_hostname(hw_id_t hw_id, char *buf)
 
 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
 /*
- * Update 'model' and 'memory' properties in the blob according to the module
- * that we are running on.
+ * Update 'model' property in the blob according to the module that we are
+ * running on.
  */
 static void ft_blob_update(void *blob, bd_t *bd)
 {
 	int len, ret, nodeoffset = 0;
 	char module_name[MODULE_NAME_MAXLEN] = {0};
-	ulong memory_data[2] = {0};
 
 	compose_module_name(hw_id, module_name);
 	len = strlen(module_name) + 1;
@@ -272,23 +271,6 @@ static void ft_blob_update(void *blob, bd_t *bd)
 	if (ret < 0)
 	printf("ft_blob_update(): cannot set /model property err:%s\n",
 		fdt_strerror(ret));
-
-	memory_data[0] = cpu_to_be32(bd->bi_memstart);
-	memory_data[1] = cpu_to_be32(bd->bi_memsize);
-
-	nodeoffset = fdt_find_node_by_path (blob, "/memory");
-	if (nodeoffset >= 0) {
-		ret = fdt_setprop(blob, nodeoffset, "reg", memory_data,
-					sizeof(memory_data));
-	if (ret < 0)
-		printf("ft_blob_update): cannot set /memory/reg "
-			"property err:%s\n", fdt_strerror(ret));
-	}
-	else {
-		/* memory node is required in dts */
-		printf("ft_blob_update(): cannot find /memory node "
-		"err:%s\n", fdt_strerror(nodeoffset));
-	}
 }
 #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
 
common/cmd_bootm.c +10 -0
index d816349..3381c07 100644
@@ -992,6 +992,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 			do_reset (cmdtp, flag, argc, argv);
 		}
 #endif
+		/*
+		 * Add the "/memory" node if it does not exist, and do a fixup
+		 * of the "reg" property with values detected by U-Boot
+		 * (taken from bd->bi_memstart and bd->bi_memsize).
+		 */
+		if (fdt_memory(of_flat_tree) < 0) {
+			puts ("ERROR: /memory node create failed - "
+				"must RESET the board to recover.\n");
+			do_reset (cmdtp, flag, argc, argv);
+		}
 #ifdef CONFIG_OF_BOARD_SETUP
 		/* Call the board-specific fixup routine */
 		ft_board_setup(of_flat_tree, gd->bd);
common/fdt_support.c +41 -0

45 lines not on this page · raw message

cpu/mpc83xx/cpu.c +0 -17
index e634f0a..51b63e6 100644
@@ -526,7 +526,6 @@ ft_cpu_setup(void *blob, bd_t *bd)
 	int nodeoffset;
 	int err;
 	int j;
-	int tmp[2];
 
 	for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
 		nodeoffset = fdt_find_node_by_path(blob, fixup_props[j].node);
@@ -542,22 +541,6 @@ ft_cpu_setup(void *blob, bd_t *bd)
 			      fixup_props[j].node, fdt_strerror(nodeoffset));
 		}
 	}
-
-	/* update, or add and update /memory node */
-	nodeoffset = fdt_find_node_by_path(blob, "/memory");
-	if (nodeoffset < 0) {
-		nodeoffset = fdt_add_subnode(blob, 0, "memory");
-		if (nodeoffset < 0)
-			debug("failed to add /memory node: %s\n",
-			      fdt_strerror(nodeoffset));
-	}
-	if (nodeoffset >= 0) {
-		fdt_setprop(blob, nodeoffset, "device_type",
-			    "memory", sizeof("memory"));
-		tmp[0] = cpu_to_be32(bd->bi_memstart);
-		tmp[1] = cpu_to_be32(bd->bi_memsize);
-		fdt_setprop(blob, nodeoffset, "reg", tmp, sizeof(tmp));
-	}
 }
 #elif defined(CONFIG_OF_FLAT_TREE)
 void
include/fdt_support.h +1 -0
index 60fa423..eca2186 100644
@@ -29,6 +29,7 @@
 #include <fdt.h>
 
 int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force);
+int fdt_memory(void *fdt);
 
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 int fdt_env(void *fdt);
#1 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 11 lines
common/cmd_bootm.c +3 -0
index d816349..3381c07 100644
@@ -992,6 +992,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 			do_reset (cmdtp, flag, argc, argv);
 		}
 #endif
+		/*
+		 * Add the "/memory" node if it does not exist, and do a fixup
+		 * of the "reg" property with values detected by U-Boot

common/cmd_bootm.c do_bootm_linux (cmd_tbl_t *cmdtp, int flag, · line 1007

Quoted 10 lines
common/cmd_bootm.c +7 -0
+		 * (taken from bd->bi_memstart and bd->bi_memsize).
+		 */
+		if (fdt_memory(of_flat_tree) < 0) {
+			puts ("ERROR: /memory node create failed - "
+				"must RESET the board to recover.\n");
+			do_reset (cmdtp, flag, argc, argv);
+		}
 #ifdef CONFIG_OF_BOARD_SETUP
 		/* Call the board-specific fixup routine */
 		ft_board_setup(of_flat_tree, gd->bd);

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

There are cases in which we don't want fdt_memory() called as it stands.

- k

#2 lore raw

PATCH 1/1 fdt: add common memory fixup function

Hi Kumar,

sorry for the late response. I've been very busy the last days ...

Kumar Gala wrote on Tuesday, November 20, 2007 9:34 PM:

Quoted 24 lines
Quoted 10 lines
common/cmd_bootm.c +2 -0
index d816349..3381c07 100644
@@ -992,6 +992,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 			do_reset (cmdtp, flag, argc, argv);
 		}
 #endif
+		/*
+		 * Add the "/memory" node if it does not exist, and do a fixup

common/cmd_bootm.c do_bootm_linux (cmd_tbl_t *cmdtp, int flag, · line 1006

Quoted 10 lines
common/cmd_bootm.c +7 -0
+		 * of the "reg" property with values detected by U-Boot
+		 * (taken from bd->bi_memstart and bd->bi_memsize). +		 */
+		if (fdt_memory(of_flat_tree) < 0) {
+			puts ("ERROR: /memory node create failed - "
+				"must RESET the board to recover.\n");
+			do_reset (cmdtp, flag, argc, argv);
+		}
 #ifdef CONFIG_OF_BOARD_SETUP
 		/* Call the board-specific fixup routine */
 		ft_board_setup(of_flat_tree, gd->bd);

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

Quoted 4 lines

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

That's funny. My first patch wrapped the fixup in CONFIG_OF_MEMORY_FIXUP and it was you, who suggested to drop this ;-). AFAIR Kim suggested to wrap it in the existing OF_LIBFDT instead - what I did then. But I have no objections, if you put CONFIG_OF_MEMORY_FIXUP in place again.

Best Regards,
Martin Krause

#3 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 10 lines
Quoted 9 lines

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is
wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

Quoted 5 lines

That's funny. My first patch wrapped the fixup in CONFIG_OF_MEMORY_FIXUP
and it was you, who suggested to drop this ;-). AFAIR Kim suggested to wrap it in the existing OF_LIBFDT instead - what I did then. But I have no objections, if you put CONFIG_OF_MEMORY_FIXUP in place again.

Yeah, I know. I realized later that we should leave it to board code to decide what it wants in such cases. The reason for that is if you can envision having multiple device trees in multiprocessor system with each processor running a different OS.

- k

#4 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 16 lines · On Tue, 27 Nov 2007 08:13:07 -0600 Kumar Gala <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is
wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

Quoted 5 lines

That's funny. My first patch wrapped the fixup in CONFIG_OF_MEMORY_FIXUP
and it was you, who suggested to drop this ;-). AFAIR Kim suggested to wrap it in the existing OF_LIBFDT instead - what I did then. But I have no objections, if you put CONFIG_OF_MEMORY_FIXUP in place again.

Quoted 4 lines

Yeah, I know. I realized later that we should leave it to board code to decide what it wants in such cases. The reason for that is if you can envision having multiple device trees in multiprocessor system with each processor running a different OS.

so make it a weak fn then?

Kim

#5 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 21 lines · Kim Phillips
Quoted 18 lines · On Tue, 27 Nov 2007 08:13:07 -0600 Kumar Gala <[email protected]> wrote:
Quoted 17 lines
Quoted 9 lines

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is
wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

That's funny. My first patch wrapped the fixup in CONFIG_OF_MEMORY_FIXUP
and it was you, who suggested to drop this ;-). AFAIR Kim suggested to
wrap it in the existing OF_LIBFDT instead - what I did then. But I have no objections, if you put CONFIG_OF_MEMORY_FIXUP in place again.

Quoted 6 lines
Quoted 4 lines

Yeah, I know. I realized later that we should leave it to board code to decide what it wants in such cases. The reason for that is if you can envision having multiple device trees in multiprocessor system with each processor running a different OS.

so make it a weak fn then?

weak doesn't cover it. I don't want to implement my own version of fdt_memory_fixup(). I want to control how its called.

- k

#6 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 29 lines · On Tue, 27 Nov 2007 11:16:50 -0600 Kumar Gala <[email protected]> wrote:
Quoted 26 lines · Kim Phillips
Quoted 22 lines · On Tue, 27 Nov 2007 08:13:07 -0600 Kumar Gala <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines

Was thinking about this some more and realized I don't like fdt_memory() getting called via bootm w/o the board code have control.

I think Kim suggest we have a CONFIG_OF_MEMORY_FIXUP that this call is
wrapped around. But leave fdt_memory() available. I want it such that the board code/config is in control of what fixups gets called for it.

Quoted 7 lines

That's funny. My first patch wrapped the fixup in CONFIG_OF_MEMORY_FIXUP
and it was you, who suggested to drop this ;-). AFAIR Kim suggested to
wrap it in the existing OF_LIBFDT instead - what I did then. But I have no objections, if you put CONFIG_OF_MEMORY_FIXUP in place again.

Yeah, I know. I realized later that we should leave it to board code to decide what it wants in such cases. The reason for that is if you can envision having multiple device trees in multiprocessor system with each processor running a different OS.

Quoted 4 lines
Quoted 1 line

so make it a weak fn then?

weak doesn't cover it. I don't want to implement my own version of fdt_memory_fixup(). I want to control how its called.

ya, ok. I see this now.

Kim