From: Grant Likely Date: Thu, 30 Aug 2007 12:20:14 -0600 Subject: [U-Boot-Users] [PATCH/RFC] mpc5200: switch to CONFIG_OF_LIBFDT Message-ID: <20070830173340.24697.19740.stgit@trillian.cg.shawcable.net> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Grant Likely Here is a patch which converts the icecube* and tqm5200 boards from using OF_FLAT_TREE to OF_LIBFDT. It also fixes the compile of cm5200. It's been tested on the lite5200. Still to be resolved: is there a better place to put the helper functions. Signed-off-by: Grant Likely --- board/icecube/icecube.c | 10 ++++--- board/tqm5200/tqm5200.c | 12 +++++--- cpu/mpc5xxx/cpu.c | 67 ++++++++++++++++++++++++++++----------------- include/configs/IceCube.h | 2 + include/configs/TQM5200.h | 2 + 5 files changed, 57 insertions(+), 36 deletions(-) diff --git a/board/icecube/icecube.c b/board/icecube/icecube.c index c027f6f..6a2a77a 100644 --- a/board/icecube/icecube.c +++ b/board/icecube/icecube.c @@ -29,9 +29,11 @@ #include #include -#if defined(CONFIG_OF_FLAT_TREE) -#include -#endif +#ifdef CONFIG_OF_LIBFDT +#include +#include +#include +#endif /* CONFIG_OF_LIBFDT */ #if defined(CONFIG_LITE5200B) #include "mt46v32m16.h" @@ -386,7 +388,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) { diff --git a/board/tqm5200/tqm5200.c b/board/tqm5200/tqm5200.c index 51f4aeb..09f1709 100644 --- a/board/tqm5200/tqm5200.c +++ b/board/tqm5200/tqm5200.c @@ -32,9 +32,11 @@ #include #include -#if defined(CONFIG_OF_FLAT_TREE) -#include -#endif +#ifdef CONFIG_OF_LIBFDT +#include +#include +#include +#endif /* CONFIG_OF_LIBFDT */ #ifdef CONFIG_VIDEO_SM501 #include @@ -780,9 +782,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) */ diff --git a/cpu/mpc5xxx/cpu.c b/cpu/mpc5xxx/cpu.c index 1eac2bb..bb3ad49 100644 --- a/cpu/mpc5xxx/cpu.c +++ b/cpu/mpc5xxx/cpu.c @@ -31,8 +31,9 @@ #include #include -#if defined(CONFIG_OF_FLAT_TREE) -#include +#if defined(CONFIG_OF_LIBFDT) +#include +#include #endif DECLARE_GLOBAL_DATA_PTR; @@ -111,29 +112,45 @@ unsigned long get_tbclk (void) /* ------------------------------------------------------------------------- */ -#ifdef CONFIG_OF_FLAT_TREE -void -ft_cpu_setup(void *blob, bd_t *bd) +#ifdef CONFIG_OF_LIBFDT +static void fixup_prop(void *fdt, char *node, char *prop, void *val, int size, + int create) { - u32 *p; - int len; - - /* Core XLB bus frequency */ - p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); - if (p != NULL) - *p = cpu_to_be32(bd->bi_busfreq); - - /* SOC peripherals use the IPB bus frequency */ - p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len); - if (p != NULL) - *p = cpu_to_be32(bd->bi_ipbfreq); - - p = ft_get_prop(blob, "/" OF_SOC "/ethernet at 3000/mac-address", &len); - if (p != NULL) - memcpy(p, bd->bi_enetaddr, 6); - - p = ft_get_prop(blob, "/" OF_SOC "/ethernet at 3000/local-mac-address", &len); - if (p != NULL) - memcpy(p, bd->bi_enetaddr, 6); + int nodeoff; + int rc; + + nodeoff = fdt_find_node_by_path(fdt, node); + if (nodeoff < 0) { + printf("Couldn't find %s:%s\n", node, fdt_strerror(nodeoff)); + return; + } + + if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL)) + return; + + rc = fdt_setprop(fdt, nodeoff, prop, val, size); + if (rc) + printf("Problem setting %s = %s: %s\n", + node, prop, fdt_strerror(rc)); +} + +static void fixup_int_prop(void *fdt, char *node, char *prop, u32 val, + int create) +{ + val = cpu_to_be32(val); + fixup_prop(fdt, node, prop, &val, sizeof(val), create); +} + +void ft_cpu_setup(void *blob, bd_t *bd) +{ + char * cpu_path = "/cpus/" OF_CPU; + char * eth_path = "/" OF_SOC "/ethernet@3000"; + + fixup_int_prop(blob, cpu_path, "timebase-frequency", OF_TBCLK, 1); + fixup_int_prop(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1); + fixup_int_prop(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1); + fixup_int_prop(blob, "/" OF_SOC, "bus-frequency", bd->bi_ipbfreq, 1); + fixup_prop(blob, eth_path, "mac-address", bd->bi_enetaddr, 6, 0); + fixup_prop(blob, eth_path, "local-mac-address", bd->bi_enetaddr, 6, 0); } #endif diff --git a/include/configs/IceCube.h b/include/configs/IceCube.h index bdd92ba..4c16d22 100644 --- a/include/configs/IceCube.h +++ b/include/configs/IceCube.h @@ -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" diff --git a/include/configs/TQM5200.h b/include/configs/TQM5200.h index c08173b..e0c9d81 100644 --- a/include/configs/TQM5200.h +++ b/include/configs/TQM5200.h @@ -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"