[U-Boot-Users] [PATCH] fdt: add common memory fixup function

Martin Krause martin.krause at tqs.de
Fri Oct 26 13:47:01 CEST 2007


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.

Signed-off-by: Martin Krause <martin.krause at tqs.de>
---
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(-)

diff --git a/board/cds/common/ft_board.c b/board/cds/common/ft_board.c
index 9d97905..be0e824 100644
--- a/board/cds/common/ft_board.c
+++ b/board/cds/common/ft_board.c
@@ -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
diff --git a/board/cm5200/cm5200.c b/board/cm5200/cm5200.c
index e2ab5b8..b2a64c7 100644
--- a/board/cm5200/cm5200.c
+++ b/board/cm5200/cm5200.c
@@ -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) */
 
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index d816349..3381c07 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -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);
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 175d59e..ee434d6 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -348,4 +348,45 @@ int fdt_bd_t(void *fdt)
 }
 #endif /* ifdef CONFIG_OF_HAS_BD_T */
 
+/********************************************************************/
+
+int fdt_memory(void *fdt)
+{
+	int   nodeoffset;
+	int   err;
+	u32   tmp[2];
+	bd_t *bd = gd->bd;
+
+	err = fdt_check_header(fdt);
+	if (err < 0) {
+		printf("fdt_memory: %s\n", fdt_strerror(err));
+		return err;
+	}
+	/* update, or add and update /memory node */
+	nodeoffset = fdt_find_node_by_path(fdt, "/memory");
+	if (nodeoffset < 0) {
+		nodeoffset = fdt_add_subnode(fdt, 0, "memory");
+		if (nodeoffset < 0)
+			printf("WARNING could not create /memory: %s.\n",
+				fdt_strerror(nodeoffset));
+		return nodeoffset;
+	}
+	err = fdt_setprop(fdt, nodeoffset, "device_type", "memory",
+			  sizeof("memory"));
+	if (err < 0) {
+		printf("WARNING: could not set %s %s.\n",
+		       "device_type", fdt_strerror(err));
+		return err;
+	}
+	tmp[0] = cpu_to_be32(bd->bi_memstart);
+	tmp[1] = cpu_to_be32(bd->bi_memsize);
+	err = fdt_setprop(fdt, nodeoffset, "reg", tmp, sizeof(tmp));
+	if (err < 0) {
+		printf("WARNING: could not set %s %s.\n",
+		       "reg", fdt_strerror(err));
+		return err;
+	}
+	return 0;
+}
+
 #endif /* CONFIG_OF_LIBFDT */
diff --git a/cpu/mpc83xx/cpu.c b/cpu/mpc83xx/cpu.c
index e634f0a..51b63e6 100644
--- a/cpu/mpc83xx/cpu.c
+++ b/cpu/mpc83xx/cpu.c
@@ -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
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 60fa423..eca2186 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -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);





More information about the U-Boot mailing list