Skip to contentSkip to conversation

Move to LIBFDT for mpc5xxx platforms

PATCH Superseded Grant Likely 2 participants 6 messages Sep 4, 2007 – Sep 7, 2007

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Move to LIBFDT for mpc5xxx platforms

Wolfgang, et al.

Here is hopefully the final version of migrating all the 5xxx boards to use LIBFDT. It has been tested on lite5200 and an earlier version of the patch was tested on motionpro. I'll wait a day to collect sign off and final comments, then I'll push it to the 5xxx tree.

Cheers,
g.

--
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.

#1 lore raw

PATCH 1/2 libfdt: add convenience function fdt_find_and_setprop()

From: Grant Likely <[email protected]>

Given the path to a node, fdt_find_and_setprop() allows a property value to be set directly.

---

 include/libfdt.h |    2 ++
 libfdt/fdt_rw.c  |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
include/libfdt.h +2 -0
index 340e89d..38c65a9 100644
@@ -140,6 +140,8 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
 	})
 #define fdt_setprop_string(fdt, nodeoffset, name, str) \
 	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
+int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
+			 const void *val, int len, int create);
 int fdt_delprop(void *fdt, int nodeoffset, const char *name);
 int fdt_add_subnode_namelen(void *fdt, int parentoffset,
 			    const char *name, int namelen);
libfdt/fdt_rw.c +26 -0
index 693bfe4..55fcc41 100644
@@ -188,6 +188,32 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
 	return 0;
 }
 
+/**
+ * fdt_find_and_setprop: Find a node and set it's property
+ *
+ * @fdt: ptr to device tree
+ * @node: path of node
+ * @prop: property name
+ * @val: ptr to new value
+ * @len: length of new property value
+ * @create: flag to create the property if it doesn't exist
+ *
+ * Convenience function to directly set a property given the path to the node.
+ */
+int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
+			 const void *val, int len, int create)
+{
+	int nodeoff = fdt_find_node_by_path(fdt, node);
+
+	if (nodeoff < 0)
+		return nodeoff;
+
+	if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL))
+		return 0; /* create flag not set; so exit quietly */
+
+	return fdt_setprop(fdt, nodeoff, prop, val, len);
+}
+
 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
 {
 	struct fdt_property *prop;
#2 lore raw

PATCH 2/2 Migrate 5xxx boards from CONFIG_OF_FLAT_TREE to CONFIG_OF_LIBFDT

In reply to Grant Likely

From: Grant Likely <[email protected]>

Affects boards: icecube (lite5200), jupiter, motionpro, tqm5200

Tested on: lite5200b

---

 board/icecube/icecube.c     |    7 +---
 board/jupiter/jupiter.c     |    8 +----
 board/motionpro/motionpro.c |    8 ++---
 board/tqm5200/tqm5200.c     |    9 ++----
 cpu/mpc5xxx/cpu.c           |   69 +++++++++++++++++++++++++++----------------
 include/configs/IceCube.h   |    2 +
 include/configs/TQM5200.h   |    2 +
 include/configs/jupiter.h   |    2 +
 include/configs/motionpro.h |    2 +
 9 files changed, 58 insertions(+), 51 deletions(-)
board/icecube/icecube.c +2 -5
index c027f6f..07ba245 100644
@@ -28,10 +28,7 @@
 #include <mpc5xxx.h>
 #include <pci.h>
 #include <asm/processor.h>
-
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
-#endif
+#include <libfdt.h>
 
 #if defined(CONFIG_LITE5200B)
 #include "mt46v32m16.h"
@@ -386,7 +383,7 @@ void ide_set_reset (int idereset)
 }
 #endif
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 void
 ft_board_setup(void *blob, bd_t *bd)
 {
board/jupiter/jupiter.c +2 -6
index b227487..efdc333 100644
@@ -28,11 +28,7 @@
 #include <mpc5xxx.h>
 #include <pci.h>
 #include <asm/processor.h>
-
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
-#endif
-
+#include <libfdt.h>
 
 #define SDRAM_DDR	0
 #if 1
@@ -308,7 +304,7 @@ void ide_set_reset (int idereset)
 }
 #endif
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 void
 ft_board_setup(void *blob, bd_t *bd)
 {
board/motionpro/motionpro.c +3 -5
index 6eb5fe9..f83998e 100644
@@ -29,9 +29,7 @@
 #include <common.h>
 #include <mpc5xxx.h>
 #include <miiphy.h>
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
-#endif
+#include <libfdt.h>
 
 #if defined(CONFIG_STATUS_LED)
 #include <status_led.h>
@@ -196,12 +194,12 @@ int checkboard(void)
 }
 
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 void ft_board_setup(void *blob, bd_t *bd)
 {
 	ft_cpu_setup(blob, bd);
 }
-#endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */
+#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
 
 
 #if defined(CONFIG_STATUS_LED)
board/tqm5200/tqm5200.c +3 -6
index 51f4aeb..21f67aa 100644
@@ -31,10 +31,7 @@
 #include <mpc5xxx.h>
 #include <pci.h>
 #include <asm/processor.h>
-
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
-#endif
+#include <libfdt.h>
 
 #ifdef CONFIG_VIDEO_SM501
 #include <sm501.h>
@@ -780,9 +777,9 @@ int board_get_height (void)
 
 #endif /* CONFIG_VIDEO_SM501 */
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 void ft_board_setup(void *blob, bd_t *bd)
 {
 	ft_cpu_setup(blob, bd);
 }
-#endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */
+#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
cpu/mpc5xxx/cpu.c +44 -25

89 lines not on this page · raw message

include/configs/IceCube.h +1 -1
index bdd92ba..4c16d22 100644
@@ -178,7 +178,7 @@
 #endif /* CONFIG_MPC5200 */
 
 /* pass open firmware flat tree */
-#define CONFIG_OF_FLAT_TREE	1
+#define CONFIG_OF_LIBFDT	1
 #define CONFIG_OF_BOARD_SETUP	1
 
 #define OF_CPU			"PowerPC,5200 at 0"
include/configs/TQM5200.h +1 -1
index c08173b..e0c9d81 100644
@@ -701,7 +701,7 @@
  * Open firmware flat tree support
  *-----------------------------------------------------------------------
  */
-#define CONFIG_OF_FLAT_TREE	1
+#define CONFIG_OF_LIBFDT	1
 #define CONFIG_OF_BOARD_SETUP	1
 
 #define OF_CPU			"PowerPC,5200 at 0"
include/configs/jupiter.h +1 -1
index 4070ab9..b7100e9 100644
@@ -145,7 +145,7 @@
 
 #if 0
 /* pass open firmware flat tree */
-#define CONFIG_OF_FLAT_TREE	1
+#define CONFIG_OF_LIBFDT	1
 #define CONFIG_OF_BOARD_SETUP	1
 
 #define OF_CPU			"PowerPC,5200 at 0"
include/configs/motionpro.h +1 -1
index 82827c6..9a21632 100644
@@ -417,7 +417,7 @@ extern void __led_set(led_id_t id, int state);
 #define CFG_RESET_ADDRESS	0xfff00100
 
 /* pass open firmware flat tree */
-#define CONFIG_OF_FLAT_TREE	1
+#define CONFIG_OF_LIBFDT	1
 #define CONFIG_OF_BOARD_SETUP	1
 
 #define OF_CPU			"PowerPC,5200 at 0"
#3 lore raw

PATCH 2/2 Migrate 5xxx boards from CONFIG_OF_FLAT_TREE to CONFIG_OF_LIBFDT

Quoted 8 lines · Grant Likely

From: Grant Likely <[email protected]>

Affects boards: icecube (lite5200), jupiter, motionpro, tqm5200

Tested on: lite5200b

---

Hi Grant,

Thanks for including motionpro changes with this patch; see my comments below.

[...]

cpu/mpc5xxx/cpu.c line 29

Quoted 10 lines
cpu/mpc5xxx/cpu.c +2 -0
index 1eac2bb..e8a928a 100644
@@ -25,14 +25,18 @@
  * CPU specific code for the MPC5xxx CPUs
  */
 
+#undef DEBUG
+

Is this needed?

cpu/mpc5xxx/cpu.c line 39

Quoted 12 lines
cpu/mpc5xxx/cpu.c +4 -2
 #include <common.h>
 #include <watchdog.h>
 #include <command.h>
 #include <mpc5xxx.h>
+#include <asm/io.h>
 #include <asm/processor.h>
 
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
+#if defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
+#include <libfdt_env.h>

Are we using this?

Quoted 24 lines
cpu/mpc5xxx/cpu.c +12 -3
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -109,31 +113,46 @@ unsigned long get_tbclk (void)
 	return (tbclk);
 }
 
+
 /* ------------------------------------------------------------------------- */
 
-#ifdef CONFIG_OF_FLAT_TREE
-void
-ft_cpu_setup(void *blob, bd_t *bd)
+#ifdef CONFIG_OF_LIBFDT
+static void do_fixup(void *fdt, const char *node, const char *prop,
+		     const void *val, int len, int create)
+{
+#if defined(DEBUG)
+	int i;
+	debug("Updating property '%s/%s' = ", node, prop);
+	for (i = 0; i < len; i++)
+		debug(" %.2x", *(u8*)(val+i));
+	debug("\n");
+#endif

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 139

Quoted 10 lines
cpu/mpc5xxx/cpu.c +10 -0
+	int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
+	if (rc)
+		printf("Unable to update property %s:%s, err=%s\n",
+		       node, prop, fdt_strerror(rc));
+}
+
+static void do_fixup_u32(void *fdt, const char *node, const char *prop,
+			 u32 val, int create)
+{
+	val = cpu_to_be32(val);

Shouldn't this be cpu_to_fdt32()? In such a case we need libfdt_env.h of course.

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 141

Quoted 2 lines
cpu/mpc5xxx/cpu.c +2 -0
+	do_fixup(fdt, node, prop, &val, sizeof(val), create);
+}

I don't think do_fixup() and do_fixup_u32() should be in cpu/mpc5xxx/cpu.c - they can and should be used by 83xx (and others) without modification. Is libfdt really out of the question because of printf() calls?

Regards,
Bartlomiej

#4 lore raw

PATCH 2/2 Migrate 5xxx boards from CONFIG_OF_FLAT_TREE to CONFIG_OF_LIBFDT

Quoted 84 lines · Bartlomiej Sieka
Quoted 8 lines · Grant Likely

From: Grant Likely <[email protected]>

Affects boards: icecube (lite5200), jupiter, motionpro, tqm5200

Tested on: lite5200b

---

Hi Grant,

Thanks for including motionpro changes with this patch; see my comments below.

[...]

cpu/mpc5xxx/cpu.c line 29

Quoted 10 lines
cpu/mpc5xxx/cpu.c +2 -0
index 1eac2bb..e8a928a 100644
@@ -25,14 +25,18 @@
  * CPU specific code for the MPC5xxx CPUs
  */
 
+#undef DEBUG
+

Is this needed?

cpu/mpc5xxx/cpu.c line 39

Quoted 12 lines
cpu/mpc5xxx/cpu.c +4 -2
 #include <common.h>
 #include <watchdog.h>
 #include <command.h>
 #include <mpc5xxx.h>
+#include <asm/io.h>
 #include <asm/processor.h>
 
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
+#if defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
+#include <libfdt_env.h>

Are we using this?

Quoted 24 lines
cpu/mpc5xxx/cpu.c +12 -3
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -109,31 +113,46 @@ unsigned long get_tbclk (void)
      return (tbclk);
 }
 
+
 /* ------------------------------------------------------------------------- */
 
-#ifdef CONFIG_OF_FLAT_TREE
-void
-ft_cpu_setup(void *blob, bd_t *bd)
+#ifdef CONFIG_OF_LIBFDT
+static void do_fixup(void *fdt, const char *node, const char *prop,
+                  const void *val, int len, int create)
+{
+#if defined(DEBUG)
+     int i;
+     debug("Updating property '%s/%s' = ", node, prop);
+     for (i = 0; i < len; i++)
+             debug(" %.2x", *(u8*)(val+i));
+     debug("\n");
+#endif

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 139

Quoted 10 lines
cpu/mpc5xxx/cpu.c +10 -0
+     int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
+     if (rc)
+             printf("Unable to update property %s:%s, err=%s\n",
+                    node, prop, fdt_strerror(rc));
+}
+
+static void do_fixup_u32(void *fdt, const char *node, const char *prop,
+                      u32 val, int create)
+{
+     val = cpu_to_be32(val);

Shouldn't this be cpu_to_fdt32()? In such a case we need libfdt_env.h of course.

Quoted 7 lines

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 141

Quoted 2 lines
cpu/mpc5xxx/cpu.c +2 -0
+     do_fixup(fdt, node, prop, &val, sizeof(val), create);
+}

I don't think do_fixup() and do_fixup_u32() should be in cpu/mpc5xxx/cpu.c - they can and should be used by 83xx (and others) without modification. Is libfdt really out of the question because of printf() calls?

I think so. libfdt is *supposed* to be cross platform code that is used by u-boot, dtc, etc. Unfortunately there has already been drift in this regard, :-( I think libfdt functions should provide feedback via the return code, and let callers take care of formating output. The fixup functions in cpu.c is purely shorthand to keep the body of ft_setup_cpu tidy (so it doesn't need the same boilerplate for each function call to check the results), but I do agree that they are useful to more than just 5xxx. So where should they go? And as a secondary question, do we put them there now, or move them in the next merge window?

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195
#5 lore raw

PATCH 2/2 Migrate 5xxx boards from CONFIG_OF_FLAT_TREE to CONFIG_OF_LIBFDT

Quoted 37 lines · Grant Likely
Quoted 28 lines · Bartlomiej Sieka
Quoted 14 lines
cpu/mpc5xxx/cpu.c +11 -3
-#ifdef CONFIG_OF_FLAT_TREE
-void
-ft_cpu_setup(void *blob, bd_t *bd)
+#ifdef CONFIG_OF_LIBFDT
+static void do_fixup(void *fdt, const char *node, const char *prop,
+                  const void *val, int len, int create)
+{
+#if defined(DEBUG)
+     int i;
+     debug("Updating property '%s/%s' = ", node, prop);
+     for (i = 0; i < len; i++)
+             debug(" %.2x", *(u8*)(val+i));
+     debug("\n");
+#endif

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 139

Quoted 10 lines
cpu/mpc5xxx/cpu.c +10 -0
+     int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
+     if (rc)
+             printf("Unable to update property %s:%s, err=%s\n",
+                    node, prop, fdt_strerror(rc));
+}
+
+static void do_fixup_u32(void *fdt, const char *node, const char *prop,
+                      u32 val, int create)
+{
+     val = cpu_to_be32(val);

Shouldn't this be cpu_to_fdt32()? In such a case we need libfdt_env.h of course.

Quoted 7 lines

cpu/mpc5xxx/cpu.c unsigned long get_tbclk (void) · line 141

Quoted 2 lines
cpu/mpc5xxx/cpu.c +2 -0
+     do_fixup(fdt, node, prop, &val, sizeof(val), create);
+}

I don't think do_fixup() and do_fixup_u32() should be in cpu/mpc5xxx/cpu.c - they can and should be used by 83xx (and others) without modification. Is libfdt really out of the question because of printf() calls?

Quoted 10 lines

I think so. libfdt is *supposed* to be cross platform code that is used by u-boot, dtc, etc. Unfortunately there has already been drift in this regard, :-( I think libfdt functions should provide feedback via the return code, and let callers take care of formating output. The fixup functions in cpu.c is purely shorthand to keep the body of ft_setup_cpu tidy (so it doesn't need the same boilerplate for each function call to check the results), but I do agree that they are useful to more than just 5xxx. So where should they go? And as a secondary question, do we put them there now, or move them in the next merge window?

... How about putting them in common/fdt_support.c?

Cheers,
g.

Quoted 10 lines

Cheers,
g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195