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

Martin Krause martin.krause at tqs.de
Thu Oct 25 15:43:27 CEST 2007


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

To activate this feature CONFIG_OF_MEMORY_FIXUP has to be defined
in the board config file.

Signed-off-by: Martin Krause <martin.krause at tqs.de>
---
The patch was tested on the TQM5200 board. Any comments are welcome!

Best Regards,
Martin Krause

 common/cmd_bootm.c        |    7 +++++++
 common/fdt_support.c      |   44 ++++++++++++++++++++++++++++++++++++++++++++
 include/configs/TQM5200.h |    1 +
 include/fdt_support.h     |    4 ++++
 4 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index d816349..fe9f9bc 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -992,6 +992,13 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 			do_reset (cmdtp, flag, argc, argv);
 		}
 #endif
+#ifdef CONFIG_OF_MEMORY_FIXUP
+		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);
+		}
+#endif
 #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..86f22e0 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -348,4 +348,48 @@ int fdt_bd_t(void *fdt)
 }
 #endif /* ifdef CONFIG_OF_HAS_BD_T */
 
+/********************************************************************/
+
+#ifdef CONFIG_OF_MEMORY_FIXUP
+
+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_MEMORY_FIXUP */
+
 #endif /* CONFIG_OF_LIBFDT */
diff --git a/include/configs/TQM5200.h b/include/configs/TQM5200.h
index 8076e70..59b8cff 100644
--- a/include/configs/TQM5200.h
+++ b/include/configs/TQM5200.h
@@ -727,6 +727,7 @@
  */
 #define CONFIG_OF_LIBFDT	1
 #define CONFIG_OF_BOARD_SETUP	1
+#define CONFIG_OF_MEMORY_FIXUP	1
 
 #define OF_CPU			"PowerPC,5200 at 0"
 #define OF_SOC			"soc5200 at f0000000"
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 60fa423..92766f3 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -38,6 +38,10 @@ int fdt_env(void *fdt);
 int fdt_bd_t(void *fdt);
 #endif
 
+#ifdef CONFIG_OF_MEMORY_FIXUP
+int fdt_memory(void *fdt);
+#endif
+
 #ifdef CONFIG_OF_BOARD_SETUP
 void ft_board_setup(void *blob, bd_t *bd);
 void ft_cpu_setup(void *blob, bd_t *bd);





More information about the U-Boot mailing list