Skip to contentSkip to conversation

fdt: add common memory fixup function

PATCH New Martin Krause 3 participants 6 messages Oct 26, 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.

---
Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

 board/cds/common/ft_board.c     |    9 ---------
 board/cm5200/cm5200.c           |   22 ++-------------------
 board/mpc7448hpc2/mpc7448hpc2.c |    9 ---------
 board/mpc8540ads/mpc8540ads.c   |    9 ---------
 board/mpc8568mds/ft_board.c     |    7 -------
 board/sbc8349/sbc8349.c         |    9 ---------
 board/sbc8641d/sbc8641d.c       |    9 ---------
 common/cmd_bootm.c              |   10 ++++++++++
 common/fdt_support.c            |   41 +++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h           |    1 +
 10 files changed, 54 insertions(+), 72 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) */
 
board/mpc7448hpc2/mpc7448hpc2.c +0 -9
index 81846eb..68b2222 100644
@@ -93,15 +93,6 @@ long int initdram (int board_type)
 void
 ft_board_setup (void *blob, bd_t *bd)
 {
-	u32 *p;
-	int len;
-
 	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);
-	}
 }
 #endif
board/mpc8540ads/mpc8540ads.c +0 -9
index 914e51a..1171e14 100644
@@ -335,18 +335,9 @@ pci_init_board(void)
 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);
-	}
 }
 #endif
board/mpc8568mds/ft_board.c +0 -7
index 36815cc..1f79b22 100644
@@ -30,16 +30,9 @@ extern void ft_cpu_setup(void *blob, bd_t *bd);
 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);
-	}
 }
 #endif /* CONFIG_OF_FLAT_TREE && CONFIG_OF_BOARD_SETUP */
board/sbc8349/sbc8349.c +0 -9
index 86166ea..ec9c15d 100644
@@ -565,18 +565,9 @@ U_BOOT_CMD(
 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);
-	}
 }
 #endif
board/sbc8641d/sbc8641d.c +0 -9
index 7adc42f..3f8b008 100644
@@ -344,16 +344,7 @@ void pci_init_board(void)
 #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
 void ft_board_setup (void *blob, bd_t * bd)
 {
-	u32 *p;
-	int len;
-
 	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);
-	}
 }
 #endif
 
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

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 20 lines · Martin Krause

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.

---
Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

Quoted 12 lines
 board/cds/common/ft_board.c     |    9 ---------
 board/cm5200/cm5200.c           |   22 ++-------------------
 board/mpc7448hpc2/mpc7448hpc2.c |    9 ---------
 board/mpc8540ads/mpc8540ads.c   |    9 ---------
 board/mpc8568mds/ft_board.c     |    7 -------
 board/sbc8349/sbc8349.c         |    9 ---------
 board/sbc8641d/sbc8641d.c       |    9 ---------
 common/cmd_bootm.c              |   10 ++++++++++
 common/fdt_support.c            |   41 ++++++++++++++++++++++++++++ 
+++++++++++
 include/fdt_support.h           |    1 +
 10 files changed, 54 insertions(+), 72 deletions(-)

Not all the boards you touched used libfdt today (mpc7448hpc2, mpc8540ads, sbc8349, sbc8641d)

- k

#2 lore raw

PATCH 1/1 fdt: add common memory fixup function

Kumar Gala wrote on Friday, October 26, 2007 11:55 AM:

Quoted 32 lines · Martin Krause
Quoted 28 lines

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.

Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

 board/cds/common/ft_board.c     |    9 ---------
 board/cm5200/cm5200.c           |   22 ++-------------------
 board/mpc7448hpc2/mpc7448hpc2.c |    9 ---------
 board/mpc8540ads/mpc8540ads.c   |    9 ---------
 board/mpc8568mds/ft_board.c     |    7 -------
 board/sbc8349/sbc8349.c         |    9 ---------
 board/sbc8641d/sbc8641d.c       |    9 ---------
 common/cmd_bootm.c              |   10 ++++++++++
 common/fdt_support.c            |   41
Quoted 2 lines

++++++++++++++++++++++++++++ +++++++++++ include/fdt_support.h
| 1 + 10 files changed, 54 insertions(+), 72 deletions(-)

Quoted 2 lines

Not all the boards you touched used libfdt today (mpc7448hpc2, mpc8540ads, sbc8349, sbc8641d)

Ups, you are right! The flow of patching carried me away ... I'll redo the patch. Sorry for the noise!

Best Regards,
Martin Krause

#3 lore raw

PATCH 1/1 fdt: add common memory fixup function

In reply to Martin Krause
Quoted 11 lines · Martin Krause

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.

Quoted 6 lines

---
Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

Thanks, into the "in" basket it goes...

gvb

#4 lore raw

PATCH 1/1 fdt: add common memory fixup function

Jerry Van Baren wrote on Friday, October 26, 2007 1:14 PM:

Quoted 13 lines
Quoted 12 lines · Martin Krause

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.

Quoted 7 lines
Quoted 5 lines

Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

Thanks, into the "in" basket it goes...

Ah, please wait, I'm working on an update. I missed some boards already doing a board specific fixup (and instead cought some boards not using libfdt yet ...).

Best Regards,
Martin Krause

#5 lore raw

PATCH 1/1 fdt: add common memory fixup function

Quoted 19 lines · Martin Krause

Jerry Van Baren wrote on Friday, October 26, 2007 1:14 PM:

Quoted 18 lines
Quoted 17 lines · Martin Krause

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.

Since no one raised his hand - here is the patch :)

Best Regards,
Martin Krause

Quoted 8 lines
Quoted 1 line

Thanks, into the "in" basket it goes...

Ah, please wait, I'm working on an update. I missed some boards already doing a board specific fixup (and instead cought some boards not using libfdt yet ...).

Best Regards,
Martin Krause

Yeah, I fell into the "ack before reading the whole thread" trap. ;-)

gvb