* [PATCH 4/5] ppc: switch to libfdt based oftree implementation
2011-12-14 12:43 ppc work Sascha Hauer
` (2 preceding siblings ...)
2011-12-14 12:43 ` [PATCH 3/5] ppc pcm030: Move memory registration to mem_initcall Sascha Hauer
@ 2011-12-14 12:43 ` Sascha Hauer
2011-12-14 15:10 ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-14 12:43 ` [PATCH 5/5] remove old ft_build support Sascha Hauer
4 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2011-12-14 12:43 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/ppc/lib/ppclinux.c | 231 +-----------------------------------------
arch/ppc/mach-mpc5xxx/cpu.c | 42 ++++-----
commands/bootm.c | 5 +
include/boot.h | 2 +-
4 files changed, 31 insertions(+), 249 deletions(-)
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 471b303..f7d3950 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -16,231 +16,15 @@
#endif
extern bd_t *bd;
-static int do_bootm_linux(struct image_data *idata)
+static int do_bootm_linux(struct image_data *data)
{
- ulong sp;
- ulong initrd_end = 0;
- ulong cmd_start, cmd_end;
- ulong initrd_high;
- int initrd_copy_to_ram = 1;
- char *cmdline;
- const char *c;
- bd_t *kbd;
- void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
-#ifdef CONFIG_OF_FLAT_TREE
- char *of_flat_tree = NULL;
-#endif
- image_header_t *os_header = &idata->os->header;
- image_header_t *initrd_header = NULL;
- void *os_data = NULL;
- void *initrd_data = NULL;
- void *of_data = NULL;
- struct image_handle *oftree_handle;
- unsigned long os_len, initrd_len;
-
- if (idata->initrd)
- initrd_header = &idata->initrd->header;
-
- printf("entering %s: os_header: %p initrd_header: %p oftree: %s\n",
- __FUNCTION__, os_header, initrd_header, idata->oftree);
-
- if (image_get_type(os_header) == IH_TYPE_MULTI) {
- unsigned long *data = (unsigned long *)(idata->os->data);
- unsigned long len1 = 0, len2 = 0;
-
- if (!*data) {
- printf("multifile image with 0 entries???\n");
- return -1;
- }
- os_len = ntohl(*data); /* first one is the kernel */
- data++;
-
- if (*data) {
- len1 = ntohl(*data); /* could be initrd or oftree */
- data++;
- }
-
- if (*data) {
- len2 = ntohl(*data); /* could be oftree */
- data++;
- }
-
- while (*data) /* skip all remaining files */
- data++;
-
- data++; /* skip terminating zero */
-
- os_data = (void *)ntohl(data);
-
- if (len2) {
- initrd_data = (void *)
- ((unsigned long)data + ((os_len + 3) & ~3));
- initrd_len = len1;
- of_data = (void *)
- ((unsigned long)initrd_data + ((initrd_len + 3) & ~3));
- } else if (len1) {
- /* We could check here if this is a multifile image
- * with only a kernel and an oftree. Original barebox
- * did not do this, so leave it out for now.
- */
- initrd_data = (void *)((unsigned long)data + ((os_len + 3) & ~3));
- initrd_len = len1;
- }
- } else {
- os_data = idata->os->data;
- printf("set os_data to %p\n", os_data);
- }
-
- if (idata->initrd)
- initrd_data = idata->initrd->data;
+ void (*kernel)(void *, void *, unsigned long,
+ unsigned long, unsigned long);
+ struct image_header *os_header = &data->os->header;
-#ifdef CONFIG_OF_FLAT_TREE
- if (idata->oftree) {
- /* The oftree can be given either as an barebox image or as a
- * binary blob. First try to read it as an image.
- */
- oftree_handle = map_image(idata->oftree, 1);
- if (oftree_handle) {
- of_data = oftree_handle->data;
- } else {
- of_data = read_file(idata->oftree, 0);
- if (!of_data) {
- printf("could not read %s: %s\n", idata->oftree, errno_str());
- return -1;
- }
- }
- /* FIXME: check if this is really an oftree */
- }
-#endif
- printf("loading kernel.\n");
-
- if ((c = getenv ("initrd_high")) != NULL) {
- /* a value of "no" or a similar string will act like 0,
- * turning the "load high" feature off. This is intentional.
- */
- initrd_high = simple_strtoul(c, NULL, 16);
- if (initrd_high == ~0)
- initrd_copy_to_ram = 0;
- } else { /* not set, no restrictions to load high */
- initrd_high = ~0;
- }
-
-#ifdef CONFIG_LOGBUFFER
- kbd=gd->bd;
- /* Prevent initrd from overwriting logbuffer */
- if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
- initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
- debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
-#endif
+ kernel = (void *)image_get_ep(os_header);
/*
- * Booting a (Linux) kernel image
- *
- * Allocate space for command line and board info - the
- * address should be as high as possible within the reach of
- * the kernel (see CFG_BOOTMAPSZ settings), but in unused
- * memory, which means far enough below the current stack
- * pointer.
- */
-
- asm( "mr %0,1": "=r"(sp) : );
-
- debug ("## Current stack ends at 0x%08lX ", sp);
-
- sp -= 2048; /* just to be sure */
- if (sp > CFG_BOOTMAPSZ)
- sp = CFG_BOOTMAPSZ;
- sp &= ~0xF;
-
- debug ("=> set upper limit to 0x%08lX\n", sp);
-
- cmdline = (char *)((sp - CONFIG_CBSIZE) & ~0xF);
- kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
-
- printf("cmdline: %p kbd: %p\n", cmdline, kbd);
-
- if ((c = getenv("bootargs")) == NULL)
- c = "";
-
- strcpy (cmdline, c);
-
- cmd_start = (ulong)cmdline;
- cmd_end = cmd_start + strlen(cmdline);
-
- init_board_data(kbd);
-
-#ifdef DEBUG
- printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
-
-// do_bdinfo (NULL, 0, 0, NULL);
-#endif
-
- if ((c = getenv ("clocks_in_mhz")) != NULL) {
- /* convert all clock information to MHz */
- kbd->bi_intfreq /= 1000000L;
- kbd->bi_busfreq /= 1000000L;
-#if defined(CONFIG_MPC8220)
- kbd->bi_inpfreq /= 1000000L;
- kbd->bi_pcifreq /= 1000000L;
- kbd->bi_pevfreq /= 1000000L;
- kbd->bi_flbfreq /= 1000000L;
- kbd->bi_vcofreq /= 1000000L;
-#endif
-#if defined(CONFIG_CPM2)
- kbd->bi_cpmfreq /= 1000000L;
- kbd->bi_brgfreq /= 1000000L;
- kbd->bi_sccfreq /= 1000000L;
- kbd->bi_vco /= 1000000L;
-#endif
-#if defined(CONFIG_MPC5xxx)
- kbd->bi_ipbfreq /= 1000000L;
- kbd->bi_pcifreq /= 1000000L;
-#endif /* CONFIG_MPC5xxx */
- }
-
- kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep(os_header); /* FIXME */
-
-#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
- unlock_ram_in_cache();
-#endif
-
-#ifdef CONFIG_OF_FLAT_TREE
- /* move of_flat_tree if needed */
- if (of_data) {
- ulong of_start, of_len;
- of_len = ((struct boot_param_header *)of_data)->totalsize;
- /* provide extra 8k pad */
- if (initrd_data)
- of_start = (unsigned long)initrd_data - of_len - 8192;
- else
- of_start = (ulong)kbd - of_len - 8192;
- of_start &= ~(4096 - 1); /* align on page */
- debug ("## device tree at 0x%p ... 0x%p (len=%ld=0x%lX)\n",
- of_data, of_data + of_len - 1, of_len, of_len);
-
- of_flat_tree = (char *)of_start;
- printf (" Loading Device Tree to %08lx, end %08lx ... ",
- of_start, of_start + of_len - 1);
- memmove ((void *)of_start, (void *)of_data, of_len);
- }
-#endif
-
- /*
- * Linux Kernel Parameters (passing board info data):
- * r3: ptr to board info data
- * r4: initrd_start or 0 if no initrd
- * r5: initrd_end - unused if r4 is 0
- * r6: Start of command line string
- * r7: End of command line string
- */
-#ifdef CONFIG_OF_FLAT_TREE
- if (!of_flat_tree) /* no device tree; boot old style */
-#endif
- (*kernel) (kbd, (ulong)initrd_data, initrd_end, cmd_start, cmd_end);
- /* does not return */
-
-#ifdef CONFIG_OF_FLAT_TREE
- /*
* Linux Kernel Parameters (passing device tree):
* r3: ptr to OF flat tree, followed by the board info data
* r4: physical pointer to the kernel itself
@@ -248,11 +32,8 @@ static int do_bootm_linux(struct image_data *idata)
* r6: NULL
* r7: NULL
*/
- ft_setup(of_flat_tree, kbd, (long)initrd_data, initrd_end);
- ft_cpu_setup(of_flat_tree, kbd);
+ kernel(data->oftree, kernel, 0, 0, 0);
- (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
-#endif
reset_cpu(0);
/* not reached */
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index d695b9b..62ddb1f 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -34,12 +34,9 @@
#include <init.h>
#include <types.h>
#include <errno.h>
+#include <of.h>
#include <mach/clocks.h>
-#if defined(CONFIG_OF_FLAT_TREE)
-#include <ft_build.h>
-#endif
-
int checkcpu (void)
{
ulong clock = get_cpu_clock();
@@ -83,27 +80,26 @@ void __noreturn reset_cpu (unsigned long addr)
/* ------------------------------------------------------------------------- */
-#ifdef CONFIG_OF_FLAT_TREE
-void
-ft_cpu_setup(void *blob, bd_t *bd)
+#ifdef CONFIG_OFTREE
+static int of_mpc5200_fixup(struct fdt_header *fdt)
+{
+ char *cpu_path = "/cpus/PowerPC,5200@0";
+ int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
+
+ do_fixup_by_path_u32(fdt, cpu_path, "timebase-frequency", get_timebase_clock(), 1);
+ do_fixup_by_path_u32(fdt, cpu_path, "bus-frequency", get_bus_clock(), 1);
+ do_fixup_by_path_u32(fdt, cpu_path, "clock-frequency", get_cpu_clock(), 1);
+ do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "bus-frequency", get_ipb_clock(), 1);
+ do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "system-frequency",
+ get_bus_clock() * div, 1);
+ return 0;
+}
+
+static int of_register_mpc5200_fixup(void)
{
- 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(get_bus_clock());
-
- /* SOC peripherals use the IPB bus frequency */
- p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
- if (p != NULL)
- *p = cpu_to_be32(get_ipb_clock());
-
- p = ft_get_prop(blob, "/" OF_SOC "/ethernet@3000/mac-address", &len);
- if (p != NULL)
- memcpy(p, bd->bi_enetaddr, 6);
+ return of_register_fixup(of_mpc5200_fixup);
}
+late_initcall(of_register_mpc5200_fixup);
#endif
int cpu_init_board_data(bd_t *bd)
diff --git a/commands/bootm.c b/commands/bootm.c
index f97a842..265ad46 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -38,6 +38,7 @@
#include <fs.h>
#include <errno.h>
#include <boot.h>
+#include <of.h>
#include <rtc.h>
#include <init.h>
#include <magicvar.h>
@@ -144,6 +145,10 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
}
}
+#ifdef CONFIG_OFTREE
+ data.oftree = of_get_fixed_tree();
+#endif
+
if (optind == argc) {
ret = COMMAND_ERROR_USAGE;
goto err_out;
diff --git a/include/boot.h b/include/boot.h
index b67e034..297b944 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -7,7 +7,7 @@
struct image_data {
struct image_handle *os;
struct image_handle *initrd;
- const char *oftree;
+ void *oftree;
int verify;
unsigned long initrd_address;
unsigned long initrd_size;
--
1.7.7.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] remove old ft_build support
2011-12-14 12:43 ppc work Sascha Hauer
` (3 preceding siblings ...)
2011-12-14 12:43 ` [PATCH 4/5] ppc: switch to libfdt based oftree implementation Sascha Hauer
@ 2011-12-14 12:43 ` Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2011-12-14 12:43 UTC (permalink / raw)
To: barebox
This is unused now as its only user (ppc) is switched to
libfdt based oftree support"
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/ppc/boards/pcm030/pcm030.c | 9 -
common/Kconfig | 4 -
common/Makefile | 1 -
common/ft_build.c | 620 ---------------------------------------
include/ft_build.h | 69 -----
5 files changed, 0 insertions(+), 703 deletions(-)
delete mode 100644 common/ft_build.c
delete mode 100644 include/ft_build.h
diff --git a/arch/ppc/boards/pcm030/pcm030.c b/arch/ppc/boards/pcm030/pcm030.c
index 9c6ccb7..80f1cbe 100644
--- a/arch/ppc/boards/pcm030/pcm030.c
+++ b/arch/ppc/boards/pcm030/pcm030.c
@@ -191,12 +191,3 @@ void initdram (int board_type)
}
}
}
-
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
-{
- ft_cpu_setup(blob, bd);
-}
-#endif
-
diff --git a/common/Kconfig b/common/Kconfig
index 27464d1..1c9e398 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -398,10 +398,6 @@ config CONSOLE_ACTIVATE_ALL
Enabling this options activates all consoles on startup, so
you will get output and a prompt on all consoles simultaneously.
-config OF_FLAT_TREE
- bool
- prompt "Open Firmware flat device tree support"
-
config PARTITION
bool
prompt "Enable Partitions"
diff --git a/common/Makefile b/common/Makefile
index 9bce479..237c6b0 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -1,7 +1,6 @@
obj-$(CONFIG_SHELL_HUSH) += hush.o
obj-$(CONFIG_SHELL_SIMPLE) += parser.o
obj-$(CONFIG_GREGORIAN_CALENDER) += date.o
-obj-$(CONFIG_OF_FLAT_TREE) += ft_build.o
obj-$(CONFIG_KALLSYMS) += kallsyms.o
obj-$(CONFIG_ENV_HANDLING) += environment.o
obj-$(CONFIG_AUTO_COMPLETE) += complete.o
diff --git a/common/ft_build.c b/common/ft_build.c
deleted file mode 100644
index 9042f13..0000000
--- a/common/ft_build.c
+++ /dev/null
@@ -1,620 +0,0 @@
-/*
- * OF flat tree builder
- * Written by: Pantelis Antoniou <pantelis.antoniou@gmail.com>
- * Updated by: Matthew McClintock <msm@freescale.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <boot.h>
-#include <init.h>
-#include <malloc.h>
-#include <environment.h>
-#include <asm/byteorder.h>
-#include <stdio.h>
-
-#include <errno.h>
-#include <stddef.h>
-
-#include <ft_build.h>
-
-#undef DEBUG
-
-/* align addr on a size boundary - adjust address up if needed -- Cort */
-#define _ALIGN(addr,size) (((addr)+(size)-1)&(~((size)-1)))
-#ifndef CONFIG_OF_BOOT_CPU
-#define CONFIG_OF_BOOT_CPU 0
-#endif
-#define SIZE_OF_RSVMAP_ENTRY (2*sizeof(u64))
-
-static void ft_put_word(struct ft_cxt *cxt, u32 v)
-{
- memmove(cxt->p + sizeof(u32), cxt->p, cxt->p_end - cxt->p);
-
- *(u32 *) cxt->p = cpu_to_be32(v);
- cxt->p += sizeof(u32);
- cxt->p_end += sizeof(u32);
-}
-
-static inline void ft_put_bin(struct ft_cxt *cxt, const void *data, int sz)
-{
- int aligned_size = ((u8 *)_ALIGN((unsigned long)cxt->p + sz,
- sizeof(u32))) - cxt->p;
-
- memmove(cxt->p + aligned_size, cxt->p, cxt->p_end - cxt->p);
-
- /* make sure the last bytes are zeroed */
- memset(cxt->p + aligned_size - (aligned_size % sizeof(u32)), 0,
- (aligned_size % sizeof(u32)));
-
- memcpy(cxt->p, data, sz);
-
- cxt->p += aligned_size;
- cxt->p_end += aligned_size;
-}
-
-void ft_begin_node(struct ft_cxt *cxt, const char *name)
-{
- ft_put_word(cxt, OF_DT_BEGIN_NODE);
- ft_put_bin(cxt, name, strlen(name) + 1);
-}
-
-void ft_end_node(struct ft_cxt *cxt)
-{
- ft_put_word(cxt, OF_DT_END_NODE);
-}
-
-void ft_nop(struct ft_cxt *cxt)
-{
- ft_put_word(cxt, OF_DT_NOP);
-}
-
-static int lookup_string(struct ft_cxt *cxt, const char *name)
-{
- u8 *p;
-
- p = cxt->p;
- while (p < cxt->p_end) {
- if (strcmp((char *)p, name) == 0)
- return p - cxt->p;
- p += strlen((char *)p) + 1;
- }
-
- return -1;
-}
-
-void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz)
-{
- int off = 0;
-
- off = lookup_string(cxt, name);
- if (off == -1) {
- memcpy(cxt->p_end, name, strlen(name) + 1);
- off = cxt->p_end - cxt->p;
- cxt->p_end += strlen(name) + 1;
- }
-
- /* now put offset from beginning of *STRUCTURE* */
- /* will be fixed up at the end */
- ft_put_word(cxt, OF_DT_PROP);
- ft_put_word(cxt, sz);
- ft_put_word(cxt, off);
- ft_put_bin(cxt, data, sz);
-}
-
-void ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str)
-{
- ft_prop(cxt, name, str, strlen(str) + 1);
-}
-
-void ft_prop_int(struct ft_cxt *cxt, const char *name, int val)
-{
- u32 v = cpu_to_be32((u32) val);
-
- ft_prop(cxt, name, &v, sizeof(u32));
-}
-
-/* pick up and start working on a tree in place */
-void ft_init_cxt(struct ft_cxt *cxt, void *blob)
-{
- struct boot_param_header *bph = blob;
-
- memset(cxt, 0, sizeof(*cxt));
-
- cxt->bph = bph;
- bph->boot_cpuid_phys = CONFIG_OF_BOOT_CPU;
-
- /* find beginning and end of reserve map table (zeros in last entry) */
- cxt->p_rsvmap = (u8 *)bph + bph->off_mem_rsvmap;
- while ( ((uint64_t *)cxt->p_rsvmap)[0] != 0 &&
- ((uint64_t *)cxt->p_rsvmap)[1] != 0 ) {
- cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
- }
-
- cxt->p_start = (u8 *)bph + bph->off_dt_struct;
- cxt->p_end = (u8 *)bph + bph->totalsize;
- cxt->p = (u8 *)bph + bph->off_dt_strings;
-}
-
-/* add a reserver physical area to the rsvmap */
-void ft_add_rsvmap(struct ft_cxt *cxt, u64 physstart, u64 physend)
-{
- memmove(cxt->p_rsvmap + SIZE_OF_RSVMAP_ENTRY, cxt->p_rsvmap,
- cxt->p_end - cxt->p_rsvmap);
-
- ((u64 *)cxt->p_rsvmap)[0] = cpu_to_be64(physstart);
- ((u64 *)cxt->p_rsvmap)[1] = cpu_to_be64(physend);
- ((u64 *)cxt->p_rsvmap)[2] = 0;
- ((u64 *)cxt->p_rsvmap)[3] = 0;
-
- cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
- cxt->p_start += SIZE_OF_RSVMAP_ENTRY;
- cxt->p += SIZE_OF_RSVMAP_ENTRY;
- cxt->p_end += SIZE_OF_RSVMAP_ENTRY;
-}
-
-void ft_end_tree(struct ft_cxt *cxt)
-{
- ft_put_word(cxt, OF_DT_END);
-}
-
-/* update the boot param header with correct values */
-void ft_finalize_tree(struct ft_cxt *cxt) {
- struct boot_param_header *bph = cxt->bph;
-
- bph->totalsize = cxt->p_end - (u8 *)bph;
- bph->off_dt_struct = cxt->p_start - (u8 *)bph;
- bph->off_dt_strings = cxt->p - (u8 *)bph;
- bph->dt_strings_size = cxt->p_end - cxt->p;
-}
-
-static inline int isprint(int c)
-{
- return c >= 0x20 && c <= 0x7e;
-}
-
-static int is_printable_string(const void *data, int len)
-{
- const char *s = data;
- const char *ss;
-
- /* zero length is not */
- if (len == 0)
- return 0;
-
- /* must terminate with zero */
- if (s[len - 1] != '\0')
- return 0;
-
- ss = s;
- while (*s && isprint(*s))
- s++;
-
- /* not zero, or not done yet */
- if (*s != '\0' || (s + 1 - ss) < len)
- return 0;
-
- return 1;
-}
-
-static void print_data(const void *data, int len)
-{
- int i;
- const u8 *s;
-
- /* no data, don't print */
- if (len == 0)
- return;
-
- if (is_printable_string(data, len)) {
- puts(" = \"");
- puts(data);
- puts("\"");
- return;
- }
-
- switch (len) {
- case 1: /* byte */
- printf(" = <%02x>", (*(u8 *) data) & 0xff);
- break;
- case 2: /* half-word */
- printf(" = <%04x>", be16_to_cpu(*(u16 *) data) & 0xffff);
- break;
- case 4: /* word */
- printf(" = <%x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
- break;
- case 8: /* double-word */
- printf(" = <%qx>", be64_to_cpu(*(uint64_t *) data));
- break;
- default: /* anything else... hexdump */
- printf(" = [");
- for (i = 0, s = data; i < len; i++)
- printf("%02x%s", s[i], i < len - 1 ? " " : "");
- printf("]");
-
- break;
- }
-}
-
-void ft_dump_blob(const void *bphp)
-{
- const struct boot_param_header *bph = bphp;
- const uint64_t *p_rsvmap = (const uint64_t *)
- ((const char *)bph + be32_to_cpu(bph->off_mem_rsvmap));
- const u32 *p_struct = (const u32 *)
- ((const char *)bph + be32_to_cpu(bph->off_dt_struct));
- const u32 *p_strings = (const u32 *)
- ((const char *)bph + be32_to_cpu(bph->off_dt_strings));
- u32 tag;
- const u32 *p;
- const char *s, *t;
- int depth, sz, shift;
- int i;
- uint64_t addr, size;
-
- if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
- /* not valid tree */
- return;
- }
-
- depth = 0;
- shift = 4;
-
- for (i = 0;; i++) {
- addr = be64_to_cpu(p_rsvmap[i * 2]);
- size = be64_to_cpu(p_rsvmap[i * 2 + 1]);
- if (addr == 0 && size == 0)
- break;
-
- printf("/memreserve/ %qx %qx;\n", addr, size);
- }
-
- p = p_struct;
- while ((tag = be32_to_cpu(*p++)) != OF_DT_END) {
-
- /* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
-
- if (tag == OF_DT_BEGIN_NODE) {
- s = (const char *)p;
- p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4);
-
- printf("%*s%s {\n", depth * shift, "", s);
-
- depth++;
- continue;
- }
-
- if (tag == OF_DT_END_NODE) {
- depth--;
-
- printf("%*s};\n", depth * shift, "");
- continue;
- }
-
- if (tag == OF_DT_NOP) {
- printf("%*s[NOP]\n", depth * shift, "");
- continue;
- }
-
- if (tag != OF_DT_PROP) {
- fprintf(stderr, "%*s ** Unknown tag 0x%08x at 0x%p\n",
- depth * shift, "", tag, --p);
- break;
- }
- sz = be32_to_cpu(*p++);
- s = (const char *)p_strings + be32_to_cpu(*p++);
- t = (const char *)p;
- p = (const u32 *)_ALIGN((unsigned long)p + sz, 4);
- printf("%*s%s", depth * shift, "", s);
- print_data(t, sz);
- printf(";\n");
- }
-}
-
-void ft_backtrack_node(struct ft_cxt *cxt)
-{
- int i = 4;
-
- while (be32_to_cpu(*(u32 *) (cxt->p - i)) != OF_DT_END_NODE)
- i += 4;
-
- memmove (cxt->p - i, cxt->p, cxt->p_end - cxt->p);
-
- cxt->p_end -= i;
- cxt->p -= i;
-}
-
-void *ft_get_prop(void *bphp, const char *propname, int *szp)
-{
- struct boot_param_header *bph = bphp;
- uint32_t *p_struct =
- (uint32_t *) ((char *)bph + be32_to_cpu(bph->off_dt_struct));
- uint32_t *p_strings =
- (uint32_t *) ((char *)bph + be32_to_cpu(bph->off_dt_strings));
- uint32_t version = be32_to_cpu(bph->version);
- uint32_t tag;
- uint32_t *p;
- char *s, *t;
- char *ss;
- int sz;
- static char path[256], prop[256];
-
- path[0] = '\0';
-
- p = p_struct;
- while ((tag = be32_to_cpu(*p++)) != OF_DT_END) {
-
- if (tag == OF_DT_BEGIN_NODE) {
- s = (char *)p;
- p = (uint32_t *) _ALIGN((unsigned long)p + strlen(s) +
- 1, 4);
- strcat(path, s);
- strcat(path, "/");
- continue;
- }
-
- if (tag == OF_DT_END_NODE) {
- path[strlen(path) - 1] = '\0';
- ss = strrchr(path, '/');
- if (ss != NULL)
- ss[1] = '\0';
- continue;
- }
-
- if (tag == OF_DT_NOP)
- continue;
-
- if (tag != OF_DT_PROP)
- break;
-
- sz = be32_to_cpu(*p++);
- s = (char *)p_strings + be32_to_cpu(*p++);
- if (version < 0x10 && sz >= 8)
- p = (uint32_t *) _ALIGN((unsigned long)p, 8);
- t = (char *)p;
- p = (uint32_t *) _ALIGN((unsigned long)p + sz, 4);
-
- strcpy(prop, path);
- strcat(prop, s);
-
- if (strcmp(prop, propname) == 0) {
- *szp = sz;
- return t;
- }
- }
-
- return NULL;
-}
-
-/********************************************************************/
-
-/* Function that returns a character from the environment */
-extern uchar(*env_get_char) (int);
-
-#define BDM(x) { .name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
-
-#ifdef CONFIG_OF_HAS_BD_T
-static const struct {
- const char *name;
- int offset;
-} bd_map[] = {
- BDM(memstart),
- BDM(memsize),
- BDM(flashstart),
- BDM(flashsize),
- BDM(flashoffset),
- BDM(sramstart),
- BDM(sramsize),
-#if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) \
- || defined(CONFIG_E500)
- BDM(immr_base),
-#endif
-#if defined(CONFIG_MPC5xxx)
- BDM(mbar_base),
-#endif
-#if defined(CONFIG_MPC83XX)
- BDM(immrbar),
-#endif
-#if defined(CONFIG_MPC8220)
- BDM(mbar_base),
- BDM(inpfreq),
- BDM(pcifreq),
- BDM(pevfreq),
- BDM(flbfreq),
- BDM(vcofreq),
-#endif
- BDM(bootflags),
- BDM(ip_addr),
- BDM(intfreq),
- BDM(busfreq),
-#ifdef CONFIG_CPM2
- BDM(cpmfreq),
- BDM(brgfreq),
- BDM(sccfreq),
- BDM(vco),
-#endif
-#if defined(CONFIG_MPC5xxx)
- BDM(ipbfreq),
- BDM(pcifreq),
-#endif
- BDM(baudrate),
-};
-#endif
-
-void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end)
-{
- u32 *p;
- int len;
- struct ft_cxt cxt;
- ulong clock;
-#if defined(CONFIG_OF_HAS_BAREBOX_ENV)
- int k, nxt;
-#endif
-#if defined(CONFIG_OF_HAS_BD_T)
- u8 *end;
-#endif
-#if defined(CONFIG_OF_HAS_BAREBOX_ENV) || defined(CONFIG_OF_HAS_BD_T)
- int i;
- static char tmpenv[256];
-#endif
-
- /* disable OF tree; booting old kernel */
- if (getenv("disable_of") != NULL) {
- memcpy(blob, bd, sizeof(*bd));
- return;
- }
-
-#ifdef DEBUG
- printf ("recieved oftree\n");
- ft_dump_blob(blob);
-#endif
-
- ft_init_cxt(&cxt, blob);
-
- if (initrd_start && initrd_end)
- ft_add_rsvmap(&cxt, initrd_start, initrd_end - initrd_start + 1);
-
- /* back into root */
- ft_backtrack_node(&cxt);
-
-#ifdef CONFIG_OF_HAS_BAREBOX_ENV
- ft_begin_node(&cxt, "barebox-env");
-
- for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
- char *s, *lval, *rval;
-
- for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) ;
- s = tmpenv;
- for (k = i; k < nxt && s < &tmpenv[sizeof(tmpenv) - 1]; ++k)
- *s++ = env_get_char(k);
- *s++ = '\0';
- lval = tmpenv;
- s = strchr(tmpenv, '=');
- if (s != NULL) {
- *s++ = '\0';
- rval = s;
- } else
- continue;
- ft_prop_str(&cxt, lval, rval);
- }
-
- ft_end_node(&cxt);
-#endif
-
- ft_begin_node(&cxt, "chosen");
- ft_prop_str(&cxt, "name", "chosen");
-
- ft_prop_str(&cxt, "bootargs", getenv("bootargs"));
- ft_prop_int(&cxt, "linux,platform", 0x600); /* what is this? */
- if (initrd_start && initrd_end) {
- ft_prop_int(&cxt, "linux,initrd-start", initrd_start);
- ft_prop_int(&cxt, "linux,initrd-end", initrd_end);
- }
-#ifdef OF_STDOUT_PATH
- ft_prop_str(&cxt, "linux,stdout-path", OF_STDOUT_PATH);
-#endif
-
- ft_end_node(&cxt);
-
- ft_end_node(&cxt); /* end root */
-
- ft_end_tree(&cxt);
- ft_finalize_tree(&cxt);
-
-#ifdef CONFIG_OF_HAS_BD_T
- /* paste the bd_t at the end of the flat tree */
- end = (char *)blob +
- be32_to_cpu(((struct boot_param_header *)blob)->totalsize);
- memcpy(end, bd, sizeof(*bd));
-#endif
-
-#ifdef CONFIG_PPC
-
-#ifdef CONFIG_OF_HAS_BD_T
- for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) {
- uint32_t v;
-
- sprintf(tmpenv, "/bd_t/%s", bd_map[i].name);
- v = *(uint32_t *)((char *)bd + bd_map[i].offset);
-
- p = ft_get_prop(blob, tmpenv, &len);
- if (p != NULL)
- *p = cpu_to_be32(v);
- }
-
- p = ft_get_prop(blob, "/bd_t/enetaddr", &len);
- if (p != NULL)
- memcpy(p, bd->bi_enetaddr, 6);
-
- p = ft_get_prop(blob, "/bd_t/ethspeed", &len);
- if (p != NULL)
- *p = cpu_to_be32((uint32_t) bd->bi_ethspeed);
-#endif
-
- clock = bd->bi_intfreq;
- p = ft_get_prop(blob, "/cpus/" OF_CPU "/clock-frequency", &len);
- if (p != NULL)
- *p = cpu_to_be32(clock);
-
-#ifdef OF_TBCLK
- clock = OF_TBCLK;
- p = ft_get_prop(blob, "/cpus/" OF_CPU "/timebase-frequency", &len);
- if (p != NULL)
- *p = cpu_to_be32(clock);
-#endif
-#endif /* __powerpc__ */
-
-#ifdef CONFIG_OF_BOARD_SETUP
- ft_board_setup(blob, bd);
-#endif
-
- /* in case the size changed in the platform code */
- ft_finalize_tree(&cxt);
-
-#ifdef DEBUG
- printf("final OF-tree\n");
- ft_dump_blob(blob);
-#endif
-}
-
-#if 0
-static int oftree_handler_cmdline_parse(struct image_data *data, int opt,
- char *optarg)
-{
- switch(opt) {
- case 'o':
- printf("using oftree %s\n", optarg);
- data->oftree = optarg;
- return 0;
- default:
- return 1;
- }
-}
-
-static struct image_handler of_handler = {
- .cmdline_options = "o:",
- .cmdline_parse = oftree_handler_cmdline_parse,
- .help_string = " -o <oftree> use oftree",
-};
-
-static int oftree_register_image_handler(void)
-{
- return register_image_handler(&of_handler);
-}
-
-late_initcall(oftree_register_image_handler);
-#endif
diff --git a/include/ft_build.h b/include/ft_build.h
deleted file mode 100644
index 1fb6b4d..0000000
--- a/include/ft_build.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * OF Flat tree builder
- *
- */
-
-#ifndef FT_BUILD_H
-#define FT_BUILD_H
-
-#include <linux/types.h>
-#include <asm/barebox.h>
-
-/* Definitions used by the flattened device tree */
-#define OF_DT_HEADER 0xd00dfeed /* marker */
-#define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */
-#define OF_DT_END_NODE 0x2 /* End node */
-#define OF_DT_PROP 0x3 /* Property: name off, size,
- * content */
-#define OF_DT_NOP 0x4 /* nop */
-#define OF_DT_END 0x9
-
-#define OF_DT_VERSION 0x10
-
-struct boot_param_header {
- u32 magic; /* magic word OF_DT_HEADER */
- u32 totalsize; /* total size of DT block */
- u32 off_dt_struct; /* offset to structure */
- u32 off_dt_strings; /* offset to strings */
- u32 off_mem_rsvmap; /* offset to memory reserve map */
- u32 version; /* format version */
- u32 last_comp_version; /* last compatible version */
- /* version 2 fields below */
- u32 boot_cpuid_phys; /* Physical CPU id we're booting on */
- /* version 3 fields below */
- u32 dt_strings_size; /* size of the DT strings block */
-};
-
-struct ft_cxt {
- struct boot_param_header *bph;
- u8 *p_rsvmap;
- u8 *p_start; /* pointer to beginning of dt_struct */
- u8 *p_end; /* pointer to end of dt_strings */
- u8 *p; /* pointer to end of dt_struct and beginning of dt_strings */
-};
-
-void ft_begin_node(struct ft_cxt *cxt, const char *name);
-void ft_init_cxt(struct ft_cxt *cxt, void *blob);
-void ft_end_node(struct ft_cxt *cxt);
-
-void ft_end_tree(struct ft_cxt *cxt);
-void ft_finalize_tree(struct ft_cxt *cxt);
-
-void ft_nop(struct ft_cxt *cxt);
-void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz);
-void ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str);
-void ft_prop_int(struct ft_cxt *cxt, const char *name, int val);
-void ft_begin(struct ft_cxt *cxt, void *blob, int max_size);
-void ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size);
-
-void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end);
-
-void ft_dump_blob(const void *bphp);
-void ft_merge_blob(struct ft_cxt *cxt, void *blob);
-void *ft_get_prop(void *bphp, const char *propname, int *szp);
-
-void ft_board_setup(void *blob, bd_t *bd);
-void ft_cpu_setup(void *blob, bd_t *bd);
-void ft_pci_setup(void *blob, bd_t *bd);
-
-#endif
--
1.7.7.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread