* [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree @ 2006-07-19 23:05 Mark A. Greer 2006-08-02 16:10 ` Tom Rini ` (2 more replies) 0 siblings, 3 replies; 17+ messages in thread From: Mark A. Greer @ 2006-07-19 23:05 UTC (permalink / raw) To: linuxppc-dev This patch adds the device tree operations (dt_ops) for a flattened device tree (fdt). Signed-off-by: Mark A. Greer <mgreer@mvista.com> -- Makefile | 2 fdt.c | 525 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 526 insertions(+), 1 deletion(-) -- diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index c2bb541..3e767e5 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile @@ -36,7 +36,7 @@ zliblinuxheader := zlib.h zconf.h zutil. $(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) #$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h) -src-boot := crt0.S string.S stdio.c main.c div64.S +src-boot := crt0.S string.S stdio.c main.c div64.S fdt.c ifeq ($(CONFIG_PPC_MULTIPLATFORM),y) src-boot += of.c endif diff --git a/arch/powerpc/boot/fdt.c b/arch/powerpc/boot/fdt.c new file mode 100644 index 0000000..ad7e7d5 --- /dev/null +++ b/arch/powerpc/boot/fdt.c @@ -0,0 +1,525 @@ +/* + * Simple dtb (binary flattened device tree) search/manipulation routines. + * + * Author: Mark A. Greer <mgreer@mvista.com> + * - The code for strrchr() was copied from lib/string.c and is + * copyrighted by Linus Torvalds. + * - The smarts for fdt_finddevice() were copied with the author's + * permission from u-boot:common/ft_build.c which was written by + * Pantelis Antoniou <pantelis@embeddedalley.com>. + * - Many of the routines related to fdt_translate_addr() came + * from arch/powerpc/kernel/prom_parse.c which has no author or + * copyright notice. + * + * 2006 (c) MontaVista, Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ + +/* Supports dtb version 0x10 only */ + +#include <stdarg.h> +#include <stddef.h> +#include "types.h" +#include "page.h" +#include "string.h" +#include "stdio.h" +#include "ops.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 */ +}; + +static void *dtb_start; +static void *dtb_end; + +#define MAX_ADDR_CELLS 4 +#define BAD_ADDR ((u64)-1) + +struct fdt_bus { + u64 (*map)(u32 *addr, u32 *range, int na, int ns, int pna); + int (*translate)(u32 *addr, u64 offset, int na); +}; + +static inline struct boot_param_header * +fdt_get_bph(void *dt_blob) +{ + return (struct boot_param_header *)dt_blob; +} + +static char * +fdt_strrchr(const char *s, int c) +{ + const char *p = s + strlen(s); + + do { + if (*p == (char)c) + return (char *)p; + } while (--p >= s); + return NULL; +} + +/* 'path' is modified */ +static void +fdt_parentize(char *path, u8 leave_slash) +{ + char *s = &path[strlen(path) - 1]; + + if (*s == '/') + *s = '\0'; + s = fdt_strrchr(path, '/'); + if (s != NULL) { + if (leave_slash) + s[1] = '\0'; + else if (s[0] == '/') + s[0] = '\0'; + } +} + +static inline u32 * +fdt_next(u32 *dp, u32 **tagpp, char **namepp, char **datapp, u32 **sizepp) +{ + static char *str_region; + + *namepp = NULL; + *datapp = NULL; + *sizepp = NULL; + + if (dp == NULL) { /* first time */ + struct boot_param_header *bph = fdt_get_bph(dtb_start); + + if (bph->magic != OF_DT_HEADER) { + *tagpp = NULL; + return NULL; + } + dp = (u32 *)((u32)dtb_start + bph->off_dt_struct); + str_region = (char *)((u32)dtb_start + bph->off_dt_strings); + } + + *tagpp = dp; + + switch (*dp++) { /* Tag */ + case OF_DT_PROP: + *sizepp = dp++; + *namepp = str_region + *dp++; + *datapp = (char *)dp; + dp = (u32 *)_ALIGN_UP((unsigned long)dp + **sizepp, 4); + break; + case OF_DT_BEGIN_NODE: + *namepp = (char *)dp; + dp = (u32 *)_ALIGN_UP((u32)dp + strlen((char *)dp) + 1, 4); + break; + case OF_DT_END_NODE: + case OF_DT_NOP: + break; + case OF_DT_END: + default: + dp = NULL; + break; + } + + return dp; +} + +static void * +fdt_finddevice(const char *name) +{ + u32 *dp, *tagp, *sizep; + char *namep, *datap; + static char path[MAX_PATH_LEN]; + + path[0] = '\0'; + dp = NULL; + + while ((dp = fdt_next(dp, &tagp, &namep, &datap, &sizep)) != NULL) + switch (*tagp) { + case OF_DT_BEGIN_NODE: + strcat(path, namep); + if (!strcmp(path, name)) + return tagp; + strcat(path, "/"); + break; + case OF_DT_END_NODE: + fdt_parentize(path, 1); + break; + } + return NULL; +} + +static int +fdt_getprop(void *node, const char *name, void *buf, int buflen) +{ + u32 *dp, *tagp, *sizep, size; + char *namep, *datap; + int level; + + level = 0; + dp = node; + + while ((dp = fdt_next(dp, &tagp, &namep, &datap, &sizep)) != NULL) + switch (*tagp) { + case OF_DT_PROP: + if ((level == 1) && !strcmp(namep, name)) { + size = min(*sizep, (u32)buflen); + memcpy(buf, datap, size); + return size; + } + break; + case OF_DT_BEGIN_NODE: + level++; + break; + case OF_DT_END_NODE: + if (--level <= 0) + return -1; + break; + } + return -1; +} + +static void +fdt_modify_prop(u32 *dp, char *datap, u32 *old_prop_sizep, char *buf, + int buflen) +{ + u32 old_prop_data_len, new_prop_data_len; + + old_prop_data_len = _ALIGN_UP(*old_prop_sizep, 4); + new_prop_data_len = _ALIGN_UP(buflen, 4); + + /* Check if new prop data fits in old prop data area */ + if (new_prop_data_len == old_prop_data_len) { + memcpy(datap, buf, buflen); + *old_prop_sizep = buflen; + } + else { /* Need to alloc new area to put larger or smaller fdt */ + struct boot_param_header *old_bph, *new_bph; + u32 *old_tailp, *new_tailp, *new_datap; + u32 old_total_size, new_total_size, head_len, tail_len, diff; + void *new_dtb_start, *new_dtb_end; + + old_bph = fdt_get_bph(dtb_start), + old_total_size = old_bph->totalsize; + head_len = (u32)datap - (u32)dtb_start; + tail_len = old_total_size - (head_len + old_prop_data_len); + old_tailp = (u32 *)((u32)dtb_end - tail_len); + new_total_size = head_len + new_prop_data_len + tail_len; + + if (!(new_dtb_start = malloc(new_total_size))) { + printf("Can't alloc space for new fdt\n\r"); + exit(); + } + + new_dtb_end = (void *)((u32)new_dtb_start + new_total_size); + new_datap = (u32 *)((u32)new_dtb_start + head_len); + new_tailp = (u32 *)((u32)new_dtb_end - tail_len); + + memcpy(new_dtb_start, dtb_start, head_len); + memcpy(new_datap, buf, buflen); + memcpy(new_tailp, old_tailp, tail_len); + *(new_datap - 2) = buflen; + + new_bph = fdt_get_bph(new_dtb_start), + new_bph->totalsize = new_total_size; + + diff = new_prop_data_len - old_prop_data_len; + + /* Adjust offsets of other sections, if necessary */ + if (new_bph->off_dt_strings > new_bph->off_dt_struct) + new_bph->off_dt_strings += diff; + + if (new_bph->off_mem_rsvmap > new_bph->off_dt_struct) + new_bph->off_mem_rsvmap += diff; + + free(dtb_start, old_total_size); + + dtb_start = new_dtb_start; + dtb_end = new_dtb_end; + } +} + +/* Only modifies existing properties */ +static int +fdt_setprop(void *node, const char *name, void *buf, int buflen) +{ + u32 *dp, *tagp, *sizep; + char *namep, *datap; + int level; + + level = 0; + dp = node; + + while ((dp = fdt_next(dp, &tagp, &namep, &datap, &sizep)) != NULL) + switch (*tagp) { + case OF_DT_PROP: + if ((level == 1) && !strcmp(namep, name)) { + fdt_modify_prop(tagp, datap, sizep, buf,buflen); + return *sizep; + } + break; + case OF_DT_BEGIN_NODE: + level++; + break; + case OF_DT_END_NODE: + if (--level <= 0) + return -1; + break; + } + return -1; +} + +static u32 +fdt_find_cells(char *path, char *prop) +{ + void *devp; + u32 num; + char p[MAX_PATH_LEN]; + + strcpy(p, path); + do { + if ((devp = finddevice(p)) + && (getprop(devp, prop, &num, sizeof(num)) > 0)) + return num; + fdt_parentize(p, 0); + } while (strlen(p) > 0); + return 1; /* default of 1 */ +} + +static u64 +fdt_read_addr(u32 *cell, int size) +{ + u64 r = 0; + while (size--) + r = (r << 32) | *(cell++); + return r; +} + +static u64 +fdt_bus_default_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + cp = fdt_read_addr(range, na); + s = fdt_read_addr(range + na + pna, ns); + da = fdt_read_addr(addr, na); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int +fdt_bus_default_translate(u32 *addr, u64 offset, int na) +{ + u64 a = fdt_read_addr(addr, na); + memset(addr, 0, na * 4); + a += offset; + if (na > 1) + addr[na - 2] = a >> 32; + addr[na - 1] = a & 0xffffffffu; + + return 0; +} + +static u64 +fdt_bus_pci_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + /* Check address type match */ + if ((addr[0] ^ range[0]) & 0x03000000) + return BAD_ADDR; + + /* Read address values, skipping high cell */ + cp = fdt_read_addr(range + 1, na - 1); + s = fdt_read_addr(range + na + pna, ns); + da = fdt_read_addr(addr + 1, na - 1); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int +fdt_bus_pci_translate(u32 *addr, u64 offset, int na) +{ + return fdt_bus_default_translate(addr + 1, offset, na - 1); +} + +static u64 +fdt_bus_isa_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + /* Check address type match */ + if ((addr[0] ^ range[0]) & 0x00000001) + return BAD_ADDR; + + /* Read address values, skipping high cell */ + cp = fdt_read_addr(range + 1, na - 1); + s = fdt_read_addr(range + na + pna, ns); + da = fdt_read_addr(addr + 1, na - 1); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int +fdt_bus_isa_translate(u32 *addr, u64 offset, int na) +{ + return fdt_bus_default_translate(addr + 1, offset, na - 1); +} + +static void +fdt_match_bus(char *path, struct fdt_bus *bus) +{ + void *devp; + char dtype[128]; /* XXXX */ + + if ((devp = finddevice(path)) && (getprop(devp, "device_type", dtype, + sizeof(dtype)) > 0)) { + if (!strcmp(dtype, "isa")) { + bus->map = fdt_bus_isa_map; + bus->translate = fdt_bus_isa_translate; + } else if (!strcmp(dtype, "pci")) { + bus->map = fdt_bus_pci_map; + bus->translate = fdt_bus_pci_translate; + } else { + bus->map = fdt_bus_default_map; + bus->translate = fdt_bus_default_translate; + } + } +} + +static int +fdt_translate_one(char *path, struct fdt_bus *bus, struct fdt_bus *pbus, + u32 *addr, u32 na, u32 ns, u32 pna) +{ + void *devp; + u32 ranges[10 * (na + pna + ns)]; /* XXXX */ + u32 *rp; + unsigned int rlen; + int rone; + u64 offset = BAD_ADDR; + + if (!(devp = finddevice(path)) + || ((rlen = getprop(devp, "ranges", ranges, + sizeof(ranges))) < 0) + || (rlen == 0)) { + offset = fdt_read_addr(addr, na); + memset(addr, 0, pna * 4); + goto finish; + } + + rlen /= 4; + rone = na + pna + ns; + rp = ranges; + for (; rlen >= rone; rlen -= rone, rp += rone) { + offset = bus->map(addr, rp, na, ns, pna); + if (offset != BAD_ADDR) + break; + } + if (offset == BAD_ADDR) + return 1; + memcpy(addr, rp + na, 4 * pna); + +finish: + /* Translate it into parent bus space */ + return pbus->translate(addr, offset, pna); +} + +/* 'addr' is modified */ +static u64 +fdt_translate_addr(char *p, u32 *in_addr, u32 addr_len) +{ + struct fdt_bus bus, pbus; + int na, ns, pna, pns; + u32 addr[MAX_ADDR_CELLS]; + char path[MAX_PATH_LEN], ppath[MAX_PATH_LEN]; + + strcpy(ppath, p); + fdt_parentize(ppath, 0); + fdt_match_bus(ppath, &bus); + na = fdt_find_cells(ppath, "#address-cells"); + ns = fdt_find_cells(ppath, "#size-cells"); + memcpy(addr, in_addr, na * 4); + + for (;;) { + strcpy(path, ppath); + fdt_parentize(ppath, 0); + + if (strlen(ppath) == 0) + return fdt_read_addr(addr, na); + + fdt_match_bus(ppath, &pbus); + pna = fdt_find_cells(ppath, "#address-cells"); + pns = fdt_find_cells(ppath, "#size-cells"); + + if (fdt_translate_one(path, &bus, &pbus, addr, na, ns, pna)) + exit(); + + na = pna; + ns = pns; + memcpy(&bus, &pbus, sizeof(struct fdt_bus)); + } +} + +static void +fdt_call_kernel(void *entry_addr, unsigned long a1, unsigned long a2, + void *promptr, void *sp) +{ + void (*kernel_entry)(void *dt_blob, void *start_addr, + void *must_be_null); + +#ifdef DEBUG + printf("kernel:\n\r" + " entry addr = 0x%lx\n\r" + " flattened dt = 0x%lx\n\r", + (unsigned long)entry_addr, dtb_start); +#endif + + kernel_entry = entry_addr; + kernel_entry(dtb_start, entry_addr, NULL); +} + +static struct dt_ops fdt_dt_ops; + +struct dt_ops * +fdt_init(void *dt_blob) +{ + struct boot_param_header *bph; + + fdt_dt_ops.finddevice = fdt_finddevice; + fdt_dt_ops.getprop = fdt_getprop; + fdt_dt_ops.setprop = fdt_setprop; + fdt_dt_ops.translate_addr = fdt_translate_addr; + fdt_dt_ops.call_kernel = fdt_call_kernel; + + dtb_start = dt_blob; + bph = fdt_get_bph(dtb_start); + dtb_end = (void *)((u32)dtb_start + bph->totalsize); + + return &fdt_dt_ops; +} ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree 2006-07-19 23:05 [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer @ 2006-08-02 16:10 ` Tom Rini 2006-08-02 17:05 ` Mark A. Greer 2006-08-07 0:38 ` Hollis Blanchard 2006-09-08 3:38 ` [PATCH 3/6] bootwrapper: Add flat device tree ops glue code Mark A. Greer 2 siblings, 1 reply; 17+ messages in thread From: Tom Rini @ 2006-08-02 16:10 UTC (permalink / raw) To: Mark A. Greer; +Cc: linuxppc-dev On Wed, Jul 19, 2006 at 04:05:44PM -0700, Mark A. Greer wrote: > This patch adds the device tree operations (dt_ops) for a flattened > device tree (fdt). [snip] > +/* Definitions used by the flattened device tree */ [snip] ... > +struct fdt_bus { > + u64 (*map)(u32 *addr, u32 *range, int na, int ns, int pna); > + int (*translate)(u32 *addr, u64 offset, int na); > +}; All of that should live in an fdt.h. > + > +static inline struct boot_param_header * > +fdt_get_bph(void *dt_blob) > +{ > + return (struct boot_param_header *)dt_blob; > +} Er, can't we just do this in the few places directly? > + if (!(new_dtb_start = malloc(new_total_size))) { > + printf("Can't alloc space for new fdt\n\r"); > + exit(); > + } Wasn't there a panic("Message") or so, for bootwrapper stuff? If not, maybe there should be.. -- Tom Rini ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree 2006-08-02 16:10 ` Tom Rini @ 2006-08-02 17:05 ` Mark A. Greer 2006-08-02 17:23 ` Tom Rini 0 siblings, 1 reply; 17+ messages in thread From: Mark A. Greer @ 2006-08-02 17:05 UTC (permalink / raw) To: Tom Rini; +Cc: linuxppc-dev On Wed, Aug 02, 2006 at 09:10:54AM -0700, Tom Rini wrote: > On Wed, Jul 19, 2006 at 04:05:44PM -0700, Mark A. Greer wrote: > > > This patch adds the device tree operations (dt_ops) for a flattened > > device tree (fdt). > [snip] > > +/* Definitions used by the flattened device tree */ > [snip] > ... > > +struct fdt_bus { > > + u64 (*map)(u32 *addr, u32 *range, int na, int ns, int pna); > > + int (*translate)(u32 *addr, u64 offset, int na); > > +}; > > All of that should live in an fdt.h. Why? Its never used outside of fdt.c and therefore should not be in fdt.h. > > + > > +static inline struct boot_param_header * > > +fdt_get_bph(void *dt_blob) > > +{ > > + return (struct boot_param_header *)dt_blob; > > +} > > Er, can't we just do this in the few places directly? Sure. > > + if (!(new_dtb_start = malloc(new_total_size))) { > > + printf("Can't alloc space for new fdt\n\r"); > > + exit(); > > + } > > Wasn't there a panic("Message") or so, for bootwrapper stuff? If not, > maybe there should be.. There isn't now. Easy enough to add unless someone else objects. Mark ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree 2006-08-02 17:05 ` Mark A. Greer @ 2006-08-02 17:23 ` Tom Rini 0 siblings, 0 replies; 17+ messages in thread From: Tom Rini @ 2006-08-02 17:23 UTC (permalink / raw) To: Mark A. Greer; +Cc: linuxppc-dev On Wed, Aug 02, 2006 at 10:05:14AM -0700, Mark A. Greer wrote: > On Wed, Aug 02, 2006 at 09:10:54AM -0700, Tom Rini wrote: > > On Wed, Jul 19, 2006 at 04:05:44PM -0700, Mark A. Greer wrote: > > > > > This patch adds the device tree operations (dt_ops) for a flattened > > > device tree (fdt). > > [snip] > > > +/* Definitions used by the flattened device tree */ > > [snip] > > ... > > > +struct fdt_bus { > > > + u64 (*map)(u32 *addr, u32 *range, int na, int ns, int pna); > > > + int (*translate)(u32 *addr, u64 offset, int na); > > > +}; > > > > All of that should live in an fdt.h. > > Why? Its never used outside of fdt.c and therefore should not be in > fdt.h. Meh, I'll drop it then.. -- Tom Rini ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree 2006-07-19 23:05 [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 2006-08-02 16:10 ` Tom Rini @ 2006-08-07 0:38 ` Hollis Blanchard 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard 2006-08-08 0:30 ` [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 2006-09-08 3:38 ` [PATCH 3/6] bootwrapper: Add flat device tree ops glue code Mark A. Greer 2 siblings, 2 replies; 17+ messages in thread From: Hollis Blanchard @ 2006-08-07 0:38 UTC (permalink / raw) To: Mark A. Greer; +Cc: linuxppc-dev, xen-ppc-devel@lists.xensource.com On Wed, 2006-07-19 at 16:05 -0700, an unknown sender wrote: > --- /dev/null > +++ b/arch/powerpc/boot/fdt.c > @@ -0,0 +1,525 @@ > +/* > + * Simple dtb (binary flattened device tree) search/manipulation routines. > + * > + * Author: Mark A. Greer <mgreer at mvista.com> > + * - The code for strrchr() was copied from lib/string.c and is > + * copyrighted by Linus Torvalds. > + * - The smarts for fdt_finddevice() were copied with the author's > + * permission from u-boot:common/ft_build.c which was written by > + * Pantelis Antoniou <pantelis at embeddedalley.com>. Hmm, so we'll have at least three copies of this code: uboot, kernel, and Xen. Would it make sense to put this stuff into a libdt.a? Technically, dtc has a "libdt" already, but it's absurdly incomplete (I don't even know why it's there), so we could just replace it. Xen needs all the finddevice and setprop functionality here, which looks like it's about 2/3rds of this code. > +static void *dtb_start; > +static void *dtb_end; I'd like to avoid the use of globals here. I know it's fine when you're running in early boot, but as I mentioned I'd like to copy this code elsewhere. Could these be moved into a structure that's passed as a function parameter? > +static void > +fdt_modify_prop(u32 *dp, char *datap, u32 *old_prop_sizep, char *buf, > + int buflen) > +{ > + u32 old_prop_data_len, new_prop_data_len; > + > + old_prop_data_len = _ALIGN_UP(*old_prop_sizep, 4); > + new_prop_data_len = _ALIGN_UP(buflen, 4); > + > + /* Check if new prop data fits in old prop data area */ > + if (new_prop_data_len == old_prop_data_len) { > + memcpy(datap, buf, buflen); > + *old_prop_sizep = buflen; > + } > + else { /* Need to alloc new area to put larger or smaller fdt */ > + struct boot_param_header *old_bph, *new_bph; > + u32 *old_tailp, *new_tailp, *new_datap; > + u32 old_total_size, new_total_size, head_len, tail_len, diff; > + void *new_dtb_start, *new_dtb_end; > + > + old_bph = fdt_get_bph(dtb_start), > + old_total_size = old_bph->totalsize; > + head_len = (u32)datap - (u32)dtb_start; > + tail_len = old_total_size - (head_len + old_prop_data_len); > + old_tailp = (u32 *)((u32)dtb_end - tail_len); > + new_total_size = head_len + new_prop_data_len + tail_len; > + > + if (!(new_dtb_start = malloc(new_total_size))) { > + printf("Can't alloc space for new fdt\n\r"); > + exit(); > + } > + > + new_dtb_end = (void *)((u32)new_dtb_start + new_total_size); > + new_datap = (u32 *)((u32)new_dtb_start + head_len); > + new_tailp = (u32 *)((u32)new_dtb_end - tail_len); > + > + memcpy(new_dtb_start, dtb_start, head_len); > + memcpy(new_datap, buf, buflen); > + memcpy(new_tailp, old_tailp, tail_len); > + *(new_datap - 2) = buflen; > + > + new_bph = fdt_get_bph(new_dtb_start), > + new_bph->totalsize = new_total_size; > + > + diff = new_prop_data_len - old_prop_data_len; > + > + /* Adjust offsets of other sections, if necessary */ > + if (new_bph->off_dt_strings > new_bph->off_dt_struct) > + new_bph->off_dt_strings += diff; > + > + if (new_bph->off_mem_rsvmap > new_bph->off_dt_struct) > + new_bph->off_mem_rsvmap += diff; > + > + free(dtb_start, old_total_size); > + > + dtb_start = new_dtb_start; > + dtb_end = new_dtb_end; > + } > +} I didn't realize the boot wrapper had a full malloc() to work with. I was actually planning to only allow overwriting properties with values of the same size, since for the most part I just need to modify some small fixed-size data. Do you need more? I guess if the code already works... -- Hollis Blanchard IBM Linux Technology Center ^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC] consolidated libdt proposal 2006-08-07 0:38 ` Hollis Blanchard @ 2006-08-07 21:58 ` Hollis Blanchard 2006-08-08 5:37 ` Haren Myneni ` (2 more replies) 2006-08-08 0:30 ` [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 1 sibling, 3 replies; 17+ messages in thread From: Hollis Blanchard @ 2006-08-07 21:58 UTC (permalink / raw) To: Mark A. Greer Cc: Pantelis Antoniou, xen-ppc-devel@lists.xensource.com, linuxppc-dev, linuxppc-embedded [-- Attachment #1: Type: text/plain, Size: 1206 bytes --] On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: > > Hmm, so we'll have at least three copies of this code: uboot, kernel, > and Xen. Would it make sense to put this stuff into a libdt.a? > Technically, dtc has a "libdt" already, but it's absurdly incomplete > (I don't even know why it's there), so we could just replace it. Mark, I had a look at the code Pantelis wrote for u-boot, and it was pretty easy to adapt to meet Xen's (userspace-based) needs. I've attached my version below (and see ft_setup() at the bottom of the file). Does it meet your requirements for the kernel bootwrapper? One limitation of the attached code is that it doesn't support changing the *size* of properties, though I don't think that would be too difficult to add if needed. Haren, what about using this in kexec-tools? If everybody can use this (I expect small modifications would be needed), I think we should turn it into a library in the dtc source tree. The various projects using it could then include snapshots (to avoid dependencies). In general I'd like to avoid everybody writing and maintaining their own version of this stuff (myself included). -- Hollis Blanchard IBM Linux Technology Center [-- Attachment #2: ft_build.c --] [-- Type: text/x-csrc, Size: 14053 bytes --] /* * 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <stddef.h> #include <string.h> #include <stdio.h> #include <asm/errno.h> #include "ft_build.h" #define _ALIGN(addr,size) (((addr)+(size)-1)&(~((size)-1))) static void ft_put_word(struct ft_cxt *cxt, u32 v) { if (cxt->overflow) /* do nothing */ return; /* check for overflow */ if (cxt->p + 4 > cxt->pstr) { cxt->overflow = 1; return; } *(u32 *) cxt->p = cpu_to_be32(v); cxt->p += 4; } static inline void ft_put_bin(struct ft_cxt *cxt, const void *data, int sz) { char *p; if (cxt->overflow) /* do nothing */ return; /* next pointer pos */ p = (char *) _ALIGN((unsigned long)cxt->p + sz, 4); /* check for overflow */ if (p > cxt->pstr) { cxt->overflow = 1; return; } memcpy(cxt->p, data, sz); if ((sz & 3) != 0) memset(cxt->p + sz, 0, 4 - (sz & 3)); cxt->p = p; } 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) { char *p; p = cxt->pstr; while (p < cxt->pstr_begin) { if (strcmp(p, (char *)name) == 0) return p - cxt->p_begin; p += strlen(p) + 1; } return -1; } void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz) { int len, off; if (cxt->overflow) return; len = strlen(name) + 1; off = lookup_string(cxt, name); if (off == -1) { /* check if we have space */ if (cxt->p + 12 + sz + len > cxt->pstr) { cxt->overflow = 1; return; } cxt->pstr -= len; memcpy(cxt->pstr, name, len); off = cxt->pstr - cxt->p_begin; } /* 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, 4); } /* start construction of the flat OF tree */ void ft_begin(struct ft_cxt *cxt, void *blob, int max_size) { struct boot_param_header *bph = blob; u32 off; /* clear the cxt */ memset(cxt, 0, sizeof(*cxt)); cxt->bph = bph; cxt->max_size = max_size; /* zero everything in the header area */ memset(bph, 0, sizeof(*bph)); bph->magic = cpu_to_be32(OF_DT_HEADER); bph->version = cpu_to_be32(0x10); bph->last_comp_version = cpu_to_be32(0x10); /* start pointers */ cxt->pres_begin = (char *) _ALIGN((unsigned long)(bph + 1), 8); cxt->pres = cxt->pres_begin; off = (unsigned long)cxt->pres_begin - (unsigned long)bph; bph->off_mem_rsvmap = cpu_to_be32(off); ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */ ((u64 *) cxt->pres)[1] = 0; cxt->p_anchor = cxt->pres + 16; /* over the terminator */ } /* add a reserver physical area to the rsvmap */ void ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size) { ((u64 *) cxt->pres)[0] = cpu_to_be64(physaddr); /* phys = 0, size = 0, terminate */ ((u64 *) cxt->pres)[1] = cpu_to_be64(size); cxt->pres += 18; /* advance */ ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */ ((u64 *) cxt->pres)[1] = 0; /* keep track of size */ cxt->res_size = cxt->pres + 16 - cxt->pres_begin; cxt->p_anchor = cxt->pres + 16; /* over the terminator */ } void ft_begin_tree(struct ft_cxt *cxt) { cxt->p_begin = cxt->p_anchor; cxt->pstr_begin = (char *)cxt->bph + cxt->max_size; /* point at the end */ cxt->p = cxt->p_begin; cxt->pstr = cxt->pstr_begin; } int ft_end_tree(struct ft_cxt *cxt) { struct boot_param_header *bph = cxt->bph; int off, sz, sz1; u32 tag, v; char *p; ft_put_word(cxt, OF_DT_END); if (cxt->overflow) return -ENOMEM; /* size of the areas */ cxt->struct_size = cxt->p - cxt->p_begin; cxt->strings_size = cxt->pstr_begin - cxt->pstr; /* the offset we must move */ off = (cxt->pstr_begin - cxt->p_begin) - cxt->strings_size; /* the new strings start */ cxt->pstr_begin = cxt->p_begin + cxt->struct_size; /* move the whole string area */ memmove(cxt->pstr_begin, cxt->pstr, cxt->strings_size); /* now perform the fixup of the strings */ p = cxt->p_begin; while ((tag = be32_to_cpu(*(u32 *) p)) != OF_DT_END) { p += 4; if (tag == OF_DT_BEGIN_NODE) { p = (char *) _ALIGN((unsigned long)p + strlen(p) + 1, 4); continue; } if (tag == OF_DT_END_NODE || tag == OF_DT_NOP) continue; if (tag != OF_DT_PROP) return -EINVAL; sz = be32_to_cpu(*(u32 *) p); p += 4; v = be32_to_cpu(*(u32 *) p); v -= off; *(u32 *) p = cpu_to_be32(v); /* move down */ p += 4; p = (char *) _ALIGN((unsigned long)p + sz, 4); } /* fix sizes */ p = (char *)cxt->bph; sz = (cxt->pstr_begin + cxt->strings_size) - p; sz1 = _ALIGN(sz, 16); /* align at 16 bytes */ if (sz != sz1) memset(p + sz, 0, sz1 - sz); bph->totalsize = cpu_to_be32(sz1); bph->off_dt_struct = cpu_to_be32(cxt->p_begin - p); bph->off_dt_strings = cpu_to_be32(cxt->pstr_begin - p); /* the new strings start */ cxt->pstr_begin = cxt->p_begin + cxt->struct_size; cxt->pstr = cxt->pstr_begin + cxt->strings_size; return 0; } /**********************************************************************/ 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 char *s; /* no data, don't print */ if (len == 0) return; if (is_printable_string(data, len)) { printf(" = \"%s\"", (char *)data); return; } switch (len) { case 1: /* byte */ printf(" = <0x%02x>", (*(char *) data) & 0xff); break; case 2: /* half-word */ printf(" = <0x%04x>", be16_to_cpu(*(u16 *) data) & 0xffff); break; case 4: /* word */ printf(" = <0x%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); break; case 8: /* double-word */ printf(" = <0x%16llx>", be64_to_cpu(*(u64 *) 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 u64 *p_rsvmap = (const u64 *) ((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; u64 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/ 0x%llx 0x%llx;\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\n", depth * shift, "", tag); 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) { if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE) return; /* XXX only for node */ cxt->p -= 4; } /* note that the root node of the blob is "peeled" off */ void ft_merge_blob(struct ft_cxt *cxt, void *blob) { struct boot_param_header *bph = (struct boot_param_header *)blob; u32 *p_struct = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_struct)); u32 *p_strings = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_strings)); u32 tag, *p; char *s, *t; int depth, sz; if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE) return; /* XXX only for node */ cxt->p -= 4; depth = 0; p = p_struct; while ((tag = be32_to_cpu(*p++)) != OF_DT_END) { /* printf("tag: 0x%08x (%d) - %d\n", tag, p - p_struct, depth); */ if (tag == OF_DT_BEGIN_NODE) { s = (char *)p; p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4); if (depth++ > 0) ft_begin_node(cxt, s); continue; } if (tag == OF_DT_END_NODE) { ft_end_node(cxt); if (--depth == 0) break; 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++); t = (char *)p; p = (u32 *) _ALIGN((unsigned long)p + sz, 4); ft_prop(cxt, s, t, sz); } } void *ft_get_prop(void *bphp, const char *propname, int *szp) { struct boot_param_header *bph = bphp; u32 *p_struct = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_struct)); u32 *p_strings = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_strings)); u32 version = be32_to_cpu(bph->version); u32 tag; u32 *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 = (u32 *) _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 = (u32 *) _ALIGN((unsigned long)p, 8); t = (char *)p; p = (u32 *) _ALIGN((unsigned long)p + sz, 4); strcpy(prop, path); strcat(prop, s); if (strcmp(prop, propname) == 0) { *szp = sz; return t; } } return NULL; } /********************************************************************/ #if 0 extern unsigned char oftree_dtb[]; extern unsigned int oftree_dtb_len; void ft_setup(void *blob, int size, bd_t * bd) { DECLARE_GLOBAL_DATA_PTR; char *end; u32 *p; int len; struct ft_cxt cxt; int i, k, nxt; static char tmpenv[256]; char *s, *lval, *rval; ulong clock; u32 v; /* disable OF tree; booting old kernel */ if (getenv("disable_of") != NULL) { memcpy(blob, bd, sizeof(*bd)); return; } ft_begin(&cxt, blob, size); /* fs_add_rsvmap not used */ ft_begin_tree(&cxt); ft_begin_node(&cxt, ""); ft_end_node(&cxt); /* copy RO tree */ ft_merge_blob(&cxt, oftree_dtb); /* back into root */ ft_backtrack_node(&cxt); ft_begin_node(&cxt, "u-boot-env"); for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { 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); 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? */ ft_end_node(&cxt); ft_end_node(&cxt); /* end root */ ft_end_tree(&cxt); /* printf("merged OF-tree\n"); ft_dump_blob(blob); */ /* 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)); #ifdef CONFIG_PPC for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) { sprintf(tmpenv, "/bd_t/%s", bd_map[i].name); v = *(u32 *)((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((u32) bd->bi_ethspeed); 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(OF_TBCLK); #endif #endif /* __powerpc__ */ /* printf("final OF-tree\n"); ft_dump_blob(blob); */ } #endif [-- Attachment #3: ft_build.h --] [-- Type: text/x-chdr, Size: 4308 bytes --] /* * 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FT_BUILD_H #define FT_BUILD_H #include <endian.h> typedef unsigned short u16; typedef unsigned int u32; typedef unsigned long long u64; static inline u16 swab16(u16 x) { return (((u16)(x) & (u16)0x00ffU) << 8) | (((u16)(x) & (u16)0xff00U) >> 8); } static inline u32 swab32(u32 x) { return (((u32)(x) & (u32)0x000000ffUL) << 24) | (((u32)(x) & (u32)0x0000ff00UL) << 8) | (((u32)(x) & (u32)0x00ff0000UL) >> 8) | (((u32)(x) & (u32)0xff000000UL) >> 24); } static inline u64 swab64(u64 x) { return (u64)(((u64)(x) & (u64)0x00000000000000ffULL) << 56) | (u64)(((u64)(x) & (u64)0x000000000000ff00ULL) << 40) | (u64)(((u64)(x) & (u64)0x0000000000ff0000ULL) << 24) | (u64)(((u64)(x) & (u64)0x00000000ff000000ULL) << 8) | (u64)(((u64)(x) & (u64)0x000000ff00000000ULL) >> 8) | (u64)(((u64)(x) & (u64)0x0000ff0000000000ULL) >> 24) | (u64)(((u64)(x) & (u64)0x00ff000000000000ULL) >> 40) | (u64)(((u64)(x) & (u64)0xff00000000000000ULL) >> 56); } #if __BYTE_ORDER == __LITTLE_ENDIAN #define cpu_to_be16(x) swab16(x) #define be16_to_cpu(x) swab16(x) #define cpu_to_be32(x) swab32(x) #define be32_to_cpu(x) swab32(x) #define cpu_to_be64(x) swab64(x) #define be64_to_cpu(x) swab64(x) #else #define cpu_to_be16(x) (x) #define be16_to_cpu(x) (x) #define cpu_to_be32(x) (x) #define be32_to_cpu(x) (x) #define cpu_to_be64(x) (x) #define be64_to_cpu(x) (x) #endif /* 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; int max_size; /* maximum size of tree */ int overflow; /* set when this happens */ char *p, *pstr, *pres; /* running pointers */ char *p_begin, *pstr_begin, *pres_begin; /* starting pointers */ char *p_anchor; /* start of constructed area */ int struct_size, strings_size, res_size; }; void ft_begin_node(struct ft_cxt *cxt, const char *name); void ft_end_node(struct ft_cxt *cxt); void ft_begin_tree(struct ft_cxt *cxt); int ft_end_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_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_set_prop(void *bphp, const char *propname, void *val, int len); #endif ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard @ 2006-08-08 5:37 ` Haren Myneni 2006-08-08 9:34 ` Pantelis Antoniou 2006-08-08 18:04 ` Mark A. Greer 2006-08-08 18:46 ` Matthew McClintock 2 siblings, 1 reply; 17+ messages in thread From: Haren Myneni @ 2006-08-08 5:37 UTC (permalink / raw) To: Hollis Blanchard Cc: Pantelis Antoniou, xen-ppc-devel@lists.xensource.com, Milton Miller, linuxppc-dev, Sachin P. Sant, linuxppc-embedded Hollis Blanchard wrote: >On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: > > >>Hmm, so we'll have at least three copies of this code: uboot, kernel, >>and Xen. Would it make sense to put this stuff into a libdt.a? >>Technically, dtc has a "libdt" already, but it's absurdly incomplete >>(I don't even know why it's there), so we could just replace it. >> >> > >Mark, I had a look at the code Pantelis wrote for u-boot, and it was >pretty easy to adapt to meet Xen's (userspace-based) needs. I've >attached my version below (and see ft_setup() at the bottom of the >file). Does it meet your requirements for the kernel bootwrapper? > >One limitation of the attached code is that it doesn't support changing >the *size* of properties, though I don't think that would be too >difficult to add if needed. > >Haren, what about using this in kexec-tools? > Hollis, Good idea to have this lib. Based on brief look, some of these funcs are also useful for kexec-tools. Yes, as you mentioned, changing the size of properties is important for kexec/kdump. Present flattened device-tree process in kexec-tools: - Kexec-tool reads the /proc/device-tree and sort these entries since we get the different order than the first kernel uses. - creates linux,usable-memory property under /proc/device-tree/memory@* as appropriate. (for kdump) - Modify the reserve map for RTAS, initrd, TCE and (0- crashkernel-start) - Create initrd properties if not exist in the first kernel as needed - Modify bootargs property Thanks Haren >If everybody can use this (I expect small modifications would be >needed), I think we should turn it into a library in the dtc source >tree. The various projects using it could then include snapshots (to >avoid dependencies). In general I'd like to avoid everybody writing and >maintaining their own version of this stuff (myself included). > > > >------------------------------------------------------------------------ > >/ > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 5:37 ` Haren Myneni @ 2006-08-08 9:34 ` Pantelis Antoniou 2006-08-09 3:19 ` Haren Myneni 0 siblings, 1 reply; 17+ messages in thread From: Pantelis Antoniou @ 2006-08-08 9:34 UTC (permalink / raw) To: Haren Myneni Cc: Hollis Blanchard, xen-ppc-devel@lists.xensource.com, Milton Miller, linuxppc-dev, Sachin P. Sant, linuxppc-embedded On 08 =CE=91=CF=85=CE=B3 2006, at 8:37 =CE=A0=CE=9C, Haren Myneni wrote: > Hollis Blanchard wrote: > >> On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: >> >>> Hmm, so we'll have at least three copies of this code: uboot, =20 >>> kernel, >>> and Xen. Would it make sense to put this stuff into a libdt.a? >>> Technically, dtc has a "libdt" already, but it's absurdly incomplete >>> (I don't even know why it's there), so we could just replace it. >> >> Mark, I had a look at the code Pantelis wrote for u-boot, and it was >> pretty easy to adapt to meet Xen's (userspace-based) needs. I've >> attached my version below (and see ft_setup() at the bottom of the >> file). Does it meet your requirements for the kernel bootwrapper? >> >> One limitation of the attached code is that it doesn't support =20 >> changing >> the *size* of properties, though I don't think that would be too >> difficult to add if needed. >> >> Haren, what about using this in kexec-tools? >> > > Hollis, > Good idea to have this lib. Based on brief look, some of these =20 > funcs are also useful for kexec-tools. Yes, as you mentioned, =20 > changing the size of properties is important for kexec/kdump. > > Present flattened device-tree process in kexec-tools: > > - Kexec-tool reads the /proc/device-tree and sort these entries =20 > since we get the different order than the first kernel uses. > - creates linux,usable-memory property under /proc/device-tree/=20 > memory@* as appropriate. (for kdump) > - Modify the reserve map for RTAS, initrd, TCE and (0- crashkernel-=20 > start) > - Create initrd properties if not exist in the first kernel as needed > - Modify bootargs property > > Thanks > Haren > Hi Haren, Mind writing down what your requirements are? Just modifying the size =20= of the properties? Note that my functions work in a two phases. In the first phase the tree is build with the string table being put =20 at the end of the allocated memory area in a downward motion. When the tree is finalized the string table is memmov'ed to be =20 adjacent to the structure proper. Could you use this two phased approach for you uses? I.e. first work =20 with maximum sized properties and perform a move & fixup stage when finalizing? Regards Pantelis >> If everybody can use this (I expect small modifications would be >> needed), I think we should turn it into a library in the dtc source >> tree. The various projects using it could then include snapshots (to >> avoid dependencies). In general I'd like to avoid everybody =20 >> writing and >> maintaining their own version of this stuff (myself included). >> >> >> ---------------------------------------------------------------------=20= >> --- >> >> / >> > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 9:34 ` Pantelis Antoniou @ 2006-08-09 3:19 ` Haren Myneni 0 siblings, 0 replies; 17+ messages in thread From: Haren Myneni @ 2006-08-09 3:19 UTC (permalink / raw) To: Pantelis Antoniou Cc: Hollis Blanchard, xen-ppc-devel@lists.xensource.com, Milton Miller, linuxppc-dev, Sachin P. Sant, linuxppc-embedded Pantelis Antoniou wrote: > > On 08 Αυγ 2006, at 8:37 ΠΜ, Haren Myneni wrote: > >> Hollis Blanchard wrote: >> >>> On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: >>> >>>> Hmm, so we'll have at least three copies of this code: uboot, kernel, >>>> and Xen. Would it make sense to put this stuff into a libdt.a? >>>> Technically, dtc has a "libdt" already, but it's absurdly incomplete >>>> (I don't even know why it's there), so we could just replace it. >>> >>> >>> Mark, I had a look at the code Pantelis wrote for u-boot, and it was >>> pretty easy to adapt to meet Xen's (userspace-based) needs. I've >>> attached my version below (and see ft_setup() at the bottom of the >>> file). Does it meet your requirements for the kernel bootwrapper? >>> >>> One limitation of the attached code is that it doesn't support changing >>> the *size* of properties, though I don't think that would be too >>> difficult to add if needed. >>> >>> Haren, what about using this in kexec-tools? >>> >> >> Hollis, >> Good idea to have this lib. Based on brief look, some of these funcs >> are also useful for kexec-tools. Yes, as you mentioned, changing the >> size of properties is important for kexec/kdump. >> >> Present flattened device-tree process in kexec-tools: >> >> - Kexec-tool reads the /proc/device-tree and sort these entries since >> we get the different order than the first kernel uses. >> - creates linux,usable-memory property under /proc/device-tree/ >> memory@* as appropriate. (for kdump) >> - Modify the reserve map for RTAS, initrd, TCE and (0- crashkernel- >> start) >> - Create initrd properties if not exist in the first kernel as needed >> - Modify bootargs property >> >> Thanks >> Haren >> > > Hi Haren, > > Mind writing down what your requirements are? Just modifying the size > of the properties? Pantelis, Yes, kexec-tool can use the proposed interfaces. kexec-tool requirements: creating the flattened device-tree from scratch based on the first kernel /proc/device-tree While doing this process, should be able to - add new properties (Ex: linux,usable-memory property under /proc/device-tree/memory@*) - Modify properties: size and the value of the property could be changed(Ex: bootargs, not an issue since creating new anyway) Thanks Haren > > Note that my functions work in a two phases. > In the first phase the tree is build with the string table being put > at the end > of the allocated memory area in a downward motion. > When the tree is finalized the string table is memmov'ed to be > adjacent to the structure > proper. > > Could you use this two phased approach for you uses? I.e. first work > with maximum sized > properties and perform a move & fixup stage when finalizing? > > Regards > > Pantelis > >>> If everybody can use this (I expect small modifications would be >>> needed), I think we should turn it into a library in the dtc source >>> tree. The various projects using it could then include snapshots (to >>> avoid dependencies). In general I'd like to avoid everybody writing and >>> maintaining their own version of this stuff (myself included). >>> >>> >>> --------------------------------------------------------------------- >>> --- >>> >>> / >>> >> > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard 2006-08-08 5:37 ` Haren Myneni @ 2006-08-08 18:04 ` Mark A. Greer 2006-08-08 18:25 ` Hollis Blanchard 2006-08-08 18:46 ` Matthew McClintock 2 siblings, 1 reply; 17+ messages in thread From: Mark A. Greer @ 2006-08-08 18:04 UTC (permalink / raw) To: Hollis Blanchard Cc: Pantelis Antoniou, xen-ppc-devel@lists.xensource.com, linuxppc-dev, linuxppc-embedded Hi Hollis, On Mon, Aug 07, 2006 at 04:58:41PM -0500, Hollis Blanchard wrote: > On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: > > > > Hmm, so we'll have at least three copies of this code: uboot, kernel, > > and Xen. Would it make sense to put this stuff into a libdt.a? > > Technically, dtc has a "libdt" already, but it's absurdly incomplete > > (I don't even know why it's there), so we could just replace it. > > Mark, I had a look at the code Pantelis wrote for u-boot, and it was > pretty easy to adapt to meet Xen's (userspace-based) needs. I've > attached my version below (and see ft_setup() at the bottom of the > file). Does it meet your requirements for the kernel bootwrapper? [Disclaimer: I did a fairly quick scan of your patch so I may have misread or missed something.] Except for not being able to extend a property (see below), I think it does meet my needs (at least as I know them today). However, I was hoping to keep the interfaces in the bootwrapper similar to the ones used in the kernel. To that end, I had a routine to find a device node and other routines to find and modify a property within that node. I didn't notice a "finddevice" type of function to find a device node. Would you have a problem adding one? > One limitation of the attached code is that it doesn't support changing > the *size* of properties, though I don't think that would be too > difficult to add if needed. If we're going to allow cmdline editing in the bootwrapper, we would need to extend the size of a property. We've never really talked about cmdline editing in the powerpc branch but I assume that its a good thing(tm). I know I would like to have it so, IMHO, I think we should add it (and therefore require extending a property). Mark ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 18:04 ` Mark A. Greer @ 2006-08-08 18:25 ` Hollis Blanchard 2006-08-08 18:51 ` Mark A. Greer 0 siblings, 1 reply; 17+ messages in thread From: Hollis Blanchard @ 2006-08-08 18:25 UTC (permalink / raw) To: Mark A. Greer Cc: linuxppc-dev, Pantelis Antoniou, linuxppc-embedded, xen-ppc-devel@lists.xensource.com On Tue, 2006-08-08 at 11:04 -0700, Mark A. Greer wrote: > > Except for not being able to extend a property (see below), > I think it does meet my needs (at least as I know them today). Great. > However, I was hoping to keep the interfaces in the bootwrapper > similar to the ones used in the kernel. To that end, I had a > routine to find a device node and other routines to find and modify > a property within that node. I didn't notice a "finddevice" type of > function to find a device node. Would you have a problem adding one? The way property modification works now is this: p = ft_get_prop(tree, "/xen/console/interrupts", &len); if ((NULL == p) || (len != foolen)) return; *p = cpu_to_be32(foo); (That does need to be hidden in a yet-to-be-written ft_set_prop().) If necessary, it looks like it would be possible to modify ft_get_prop() to return a pointer to the beginning of the node structure, but is it really necessary? Do you have code that would be difficult to convert to using ft_set_prop(tree, "/node/prop", buf, buflen); ? > > One limitation of the attached code is that it doesn't support changing > > the *size* of properties, though I don't think that would be too > > difficult to add if needed. > > If we're going to allow cmdline editing in the bootwrapper, we would > need to extend the size of a property. We've never really talked about > cmdline editing in the powerpc branch but I assume that its a good > thing(tm). I know I would like to have it so, IMHO, I think we should > add it (and therefore require extending a property). I agree, and it shouldn't be too much work. I'll take a look later this week, if nobody else has. -- Hollis Blanchard IBM Linux Technology Center ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 18:25 ` Hollis Blanchard @ 2006-08-08 18:51 ` Mark A. Greer 0 siblings, 0 replies; 17+ messages in thread From: Mark A. Greer @ 2006-08-08 18:51 UTC (permalink / raw) To: Hollis Blanchard Cc: linuxppc-dev, Pantelis Antoniou, linuxppc-embedded, xen-ppc-devel@lists.xensource.com On Tue, Aug 08, 2006 at 01:25:10PM -0500, Hollis Blanchard wrote: > On Tue, 2006-08-08 at 11:04 -0700, Mark A. Greer wrote: > > > > Except for not being able to extend a property (see below), > > I think it does meet my needs (at least as I know them today). > > Great. > > > However, I was hoping to keep the interfaces in the bootwrapper > > similar to the ones used in the kernel. To that end, I had a > > routine to find a device node and other routines to find and modify > > a property within that node. I didn't notice a "finddevice" type of > > function to find a device node. Would you have a problem adding one? > > The way property modification works now is this: > p = ft_get_prop(tree, "/xen/console/interrupts", &len); > if ((NULL == p) || (len != foolen)) > return; > *p = cpu_to_be32(foo); > (That does need to be hidden in a yet-to-be-written ft_set_prop().) > > If necessary, it looks like it would be possible to modify ft_get_prop() > to return a pointer to the beginning of the node structure, but is it > really necessary? No, its just a preference to have it look similar to kernel code. > Do you have code that would be difficult to convert to > using > ft_set_prop(tree, "/node/prop", buf, buflen); > ? No. > > > One limitation of the attached code is that it doesn't support changing > > > the *size* of properties, though I don't think that would be too > > > difficult to add if needed. > > > > If we're going to allow cmdline editing in the bootwrapper, we would > > need to extend the size of a property. We've never really talked about > > cmdline editing in the powerpc branch but I assume that its a good > > thing(tm). I know I would like to have it so, IMHO, I think we should > > add it (and therefore require extending a property). > > I agree, and it shouldn't be too much work. I'll take a look later this > week, if nobody else has. OK. Mark ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard 2006-08-08 5:37 ` Haren Myneni 2006-08-08 18:04 ` Mark A. Greer @ 2006-08-08 18:46 ` Matthew McClintock 2006-08-08 19:12 ` Matthew McClintock 2 siblings, 1 reply; 17+ messages in thread From: Matthew McClintock @ 2006-08-08 18:46 UTC (permalink / raw) To: Hollis Blanchard Cc: linuxppc-dev, Pantelis Antoniou, linuxppc-embedded, xen-ppc-devel@lists.xensource.com [-- Attachment #1: Type: text/plain, Size: 1515 bytes --] Hi Hollis, Attached is a modified version of ft_build.c and ft_build.h from u-boot. -Matthew On Mon, 2006-08-07 at 16:58 -0500, Hollis Blanchard wrote: > On Sun, 2006-08-06 at 19:38 -0500, Hollis Blanchard wrote: > > > > Hmm, so we'll have at least three copies of this code: uboot, kernel, > > and Xen. Would it make sense to put this stuff into a libdt.a? > > Technically, dtc has a "libdt" already, but it's absurdly incomplete > > (I don't even know why it's there), so we could just replace it. > > Mark, I had a look at the code Pantelis wrote for u-boot, and it was > pretty easy to adapt to meet Xen's (userspace-based) needs. I've > attached my version below (and see ft_setup() at the bottom of the > file). Does it meet your requirements for the kernel bootwrapper? > > One limitation of the attached code is that it doesn't support changing > the *size* of properties, though I don't think that would be too > difficult to add if needed. > > Haren, what about using this in kexec-tools? > > If everybody can use this (I expect small modifications would be > needed), I think we should turn it into a library in the dtc source > tree. The various projects using it could then include snapshots (to > avoid dependencies). In general I'd like to avoid everybody writing and > maintaining their own version of this stuff (myself included). > > _______________________________________________ > Linuxppc-dev mailing list > Linuxppc-dev@ozlabs.org > https://ozlabs.org/mailman/listinfo/linuxppc-dev [-- Attachment #2: ft_build.c --] [-- Type: text/x-csrc, Size: 13140 bytes --] /* * 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 <malloc.h> #include <environment.h> #ifdef CONFIG_OF_FLAT_TREE #include <asm/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(p, name) == 0) return p - cxt->p; p += strlen(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) + 2; } /* 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 = (char*)bph + bph->off_dt_struct; cxt->p_end = (char *)bph + bph->totalsize; cxt->p = (char *)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)) { printf(" = \"%s\"", (char *)data); 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%x\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_UBOOT_ENV) int k, nxt; #endif #if defined(CONFIG_OF_HAS_BD_T) u8 *end; #endif #if defined(CONFIG_OF_HAS_UBOOT_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_UBOOT_ENV ft_begin_node(&cxt, "u-boot-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 } #endif [-- Attachment #3: ft_build.h --] [-- Type: text/x-chdr, Size: 2178 bytes --] /* * OF Flat tree builder * */ #ifndef FT_BUILD_H #define FT_BUILD_H #include <linux/types.h> #include <asm/u-boot.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); #ifdef CONFIG_OF_BOARD_SETUP void ft_board_setup(void *blob, bd_t *bd); #endif #endif ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 18:46 ` Matthew McClintock @ 2006-08-08 19:12 ` Matthew McClintock 2006-08-11 19:33 ` Jon Loeliger 0 siblings, 1 reply; 17+ messages in thread From: Matthew McClintock @ 2006-08-08 19:12 UTC (permalink / raw) To: Hollis Blanchard Cc: linuxppc-dev, Pantelis Antoniou, xen-ppc-devel@lists.xensource.com, linuxppc-embedded This is a patch to u-boot with the changes. * Patch to modify ft_build.c to update flat device trees in place Patch by Matthew McClintock 26-June-2006 Signed-off-by: Matthew McClintock <msm@freescale.com> --- common/cmd_bootm.c | 2 common/ft_build.c | 341 ++++++++++++++++------------------------------------ include/ft_build.h | 19 ++- 3 files changed, 115 insertions(+), 247 deletions(-) diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index a472a1d..f1c0eb4 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -836,7 +836,7 @@ #endif (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); #else - ft_setup(of_flat_tree, OF_FLAT_TREE_MAX_SIZE, kbd, initrd_start, initrd_end); + ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); /* ft_dump_blob(of_flat_tree); */ #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) diff --git a/common/ft_build.c b/common/ft_build.c index 9e9c906..b5a997c 100644 --- a/common/ft_build.c +++ b/common/ft_build.c @@ -1,5 +1,22 @@ /* * 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> @@ -13,44 +30,39 @@ #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) { - if (cxt->overflow) /* do nothing */ - return; - - /* check for overflow */ - if (cxt->p + 4 > cxt->pstr) { - cxt->overflow = 1; - return; - } + memmove(cxt->p + sizeof(u32), cxt->p, cxt->p_end - cxt->p); *(u32 *) cxt->p = cpu_to_be32(v); - cxt->p += 4; + cxt->p += sizeof(u32); + cxt->p_end += sizeof(u32); } static inline void ft_put_bin(struct ft_cxt *cxt, const void *data, int sz) { - u8 *p; + int aligned_size = ((u8 *)_ALIGN((unsigned long)cxt->p + sz, + sizeof(u32))) - cxt->p; - if (cxt->overflow) /* do nothing */ - return; - - /* next pointer pos */ - p = (u8 *) _ALIGN((unsigned long)cxt->p + sz, 4); + memmove(cxt->p + aligned_size, cxt->p, cxt->p_end - cxt->p); - /* check for overflow */ - if (p > cxt->pstr) { - cxt->overflow = 1; - return; - } + /* 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); - if ((sz & 3) != 0) - memset(cxt->p + sz, 0, 4 - (sz & 3)); - cxt->p = p; + + cxt->p += aligned_size; + cxt->p_end += aligned_size; } void ft_begin_node(struct ft_cxt *cxt, const char *name) @@ -73,10 +85,10 @@ static int lookup_string(struct ft_cxt * { u8 *p; - p = cxt->pstr; - while (p < cxt->pstr_begin) { + p = cxt->p; + while (p < cxt->p_end) { if (strcmp(p, name) == 0) - return p - cxt->p_begin; + return p - cxt->p; p += strlen(p) + 1; } @@ -85,24 +97,13 @@ static int lookup_string(struct ft_cxt * void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz) { - int len, off; - - if (cxt->overflow) - return; - - len = strlen(name) + 1; + int off = 0; off = lookup_string(cxt, name); if (off == -1) { - /* check if we have space */ - if (cxt->p + 12 + sz + len > cxt->pstr) { - cxt->overflow = 1; - return; - } - - cxt->pstr -= len; - memcpy(cxt->pstr, name, len); - off = cxt->pstr - cxt->p_begin; + memcpy(cxt->p_end, name, strlen(name) + 1); + off = cxt->p_end - cxt->p; + cxt->p_end += strlen(name) + 2; } /* now put offset from beginning of *STRUCTURE* */ @@ -122,138 +123,63 @@ void ft_prop_int(struct ft_cxt *cxt, con { u32 v = cpu_to_be32((u32) val); - ft_prop(cxt, name, &v, 4); + ft_prop(cxt, name, &v, sizeof(u32)); } -/* start construction of the flat OF tree */ -void ft_begin(struct ft_cxt *cxt, void *blob, int max_size) +/* 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; - u32 off; - /* clear the cxt */ memset(cxt, 0, sizeof(*cxt)); cxt->bph = bph; - cxt->max_size = max_size; - - /* zero everything in the header area */ - memset(bph, 0, sizeof(*bph)); - - bph->magic = cpu_to_be32(OF_DT_HEADER); - bph->version = cpu_to_be32(0x10); - bph->last_comp_version = cpu_to_be32(0x10); + bph->boot_cpuid_phys = CONFIG_OF_BOOT_CPU; - /* start pointers */ - cxt->pres_begin = (u8 *) _ALIGN((unsigned long)(bph + 1), 8); - cxt->pres = cxt->pres_begin; - - off = (unsigned long)cxt->pres_begin - (unsigned long)bph; - bph->off_mem_rsvmap = cpu_to_be32(off); - - ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */ - ((u64 *) cxt->pres)[1] = 0; + /* 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_anchor = cxt->pres + 16; /* over the terminator */ + cxt->p_start = (char*)bph + bph->off_dt_struct; + cxt->p_end = (char *)bph + bph->totalsize; + cxt->p = (char *)bph + bph->off_dt_strings; } /* add a reserver physical area to the rsvmap */ -void ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size) +void ft_add_rsvmap(struct ft_cxt *cxt, u64 physstart, u64 physend) { - ((u64 *) cxt->pres)[0] = cpu_to_be64(physaddr); /* phys = 0, size = 0, terminate */ - ((u64 *) cxt->pres)[1] = cpu_to_be64(size); - - cxt->pres += 16; /* advance */ - - ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */ - ((u64 *) cxt->pres)[1] = 0; - - /* keep track of size */ - cxt->res_size = cxt->pres + 16 - cxt->pres_begin; - - cxt->p_anchor = cxt->pres + 16; /* over the terminator */ + 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_begin_tree(struct ft_cxt *cxt) +void ft_end_tree(struct ft_cxt *cxt) { - cxt->p_begin = cxt->p_anchor; - cxt->pstr_begin = (char *)cxt->bph + cxt->max_size; /* point at the end */ - - cxt->p = cxt->p_begin; - cxt->pstr = cxt->pstr_begin; + ft_put_word(cxt, OF_DT_END); } -int ft_end_tree(struct ft_cxt *cxt) -{ +/* update the boot param header with correct values */ +void ft_finalize_tree(struct ft_cxt *cxt) { struct boot_param_header *bph = cxt->bph; - int off, sz, sz1; - u32 tag, v; - u8 *p; - - ft_put_word(cxt, OF_DT_END); - - if (cxt->overflow) - return -ENOMEM; - - /* size of the areas */ - cxt->struct_size = cxt->p - cxt->p_begin; - cxt->strings_size = cxt->pstr_begin - cxt->pstr; - - /* the offset we must move */ - off = (cxt->pstr_begin - cxt->p_begin) - cxt->strings_size; - - /* the new strings start */ - cxt->pstr_begin = cxt->p_begin + cxt->struct_size; - - /* move the whole string area */ - memmove(cxt->pstr_begin, cxt->pstr, cxt->strings_size); - /* now perform the fixup of the strings */ - p = cxt->p_begin; - while ((tag = be32_to_cpu(*(u32 *) p)) != OF_DT_END) { - p += 4; - - if (tag == OF_DT_BEGIN_NODE) { - p = (u8 *) _ALIGN((unsigned long)p + strlen(p) + 1, 4); - continue; - } - - if (tag == OF_DT_END_NODE || tag == OF_DT_NOP) - continue; - - if (tag != OF_DT_PROP) - return -EINVAL; - - sz = be32_to_cpu(*(u32 *) p); - p += 4; - - v = be32_to_cpu(*(u32 *) p); - v -= off; - *(u32 *) p = cpu_to_be32(v); /* move down */ - p += 4; - - p = (u8 *) _ALIGN((unsigned long)p + sz, 4); - } - - /* fix sizes */ - p = (char *)cxt->bph; - sz = (cxt->pstr_begin + cxt->strings_size) - p; - sz1 = _ALIGN(sz, 16); /* align at 16 bytes */ - if (sz != sz1) - memset(p + sz, 0, sz1 - sz); - bph->totalsize = cpu_to_be32(sz1); - bph->off_dt_struct = cpu_to_be32(cxt->p_begin - p); - bph->off_dt_strings = cpu_to_be32(cxt->pstr_begin - p); - - /* the new strings start */ - cxt->pstr_begin = cxt->p_begin + cxt->struct_size; - cxt->pstr = cxt->pstr_begin + cxt->strings_size; - - return 0; + 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; @@ -299,16 +225,16 @@ static void print_data(const void *data, switch (len) { case 1: /* byte */ - printf(" = <0x%02x>", (*(u8 *) data) & 0xff); + printf(" = <%02x>", (*(u8 *) data) & 0xff); break; case 2: /* half-word */ - printf(" = <0x%04x>", be16_to_cpu(*(u16 *) data) & 0xffff); + printf(" = <%04x>", be16_to_cpu(*(u16 *) data) & 0xffff); break; case 4: /* word */ - printf(" = <0x%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); + printf(" = <%x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); break; case 8: /* double-word */ - printf(" = <0x%16llx>", be64_to_cpu(*(uint64_t *) data)); + printf(" = <%qx>", be64_to_cpu(*(uint64_t *) data)); break; default: /* anything else... hexdump */ printf(" = ["); @@ -350,7 +276,7 @@ void ft_dump_blob(const void *bphp) if (addr == 0 && size == 0) break; - printf("/memreserve/ 0x%llx 0x%llx;\n", addr, size); + printf("/memreserve/ %qx %qx;\n", addr, size); } p = p_struct; @@ -381,8 +307,8 @@ void ft_dump_blob(const void *bphp) } if (tag != OF_DT_PROP) { - fprintf(stderr, "%*s ** Unknown tag 0x%08x\n", - depth * shift, "", tag); + fprintf(stderr, "%*s ** Unknown tag 0x%08x at 0x%x\n", + depth * shift, "", tag, --p); break; } sz = be32_to_cpu(*p++); @@ -397,64 +323,15 @@ void ft_dump_blob(const void *bphp) void ft_backtrack_node(struct ft_cxt *cxt) { - if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE) - return; /* XXX only for node */ - - cxt->p -= 4; -} - -/* note that the root node of the blob is "peeled" off */ -void ft_merge_blob(struct ft_cxt *cxt, void *blob) -{ - struct boot_param_header *bph = (struct boot_param_header *)blob; - u32 *p_struct = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_struct)); - u32 *p_strings = - (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_strings)); - u32 tag, *p; - char *s, *t; - int depth, sz; - - if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE) - return; /* XXX only for node */ - - cxt->p -= 4; - - depth = 0; - p = p_struct; - while ((tag = be32_to_cpu(*p++)) != OF_DT_END) { - - /* printf("tag: 0x%08x (%d) - %d\n", tag, p - p_struct, depth); */ - - if (tag == OF_DT_BEGIN_NODE) { - s = (char *)p; - p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4); - - if (depth++ > 0) - ft_begin_node(cxt, s); - - continue; - } - - if (tag == OF_DT_END_NODE) { - ft_end_node(cxt); - if (--depth == 0) - break; - continue; - } - - if (tag == OF_DT_NOP) - continue; + int i = 4; - if (tag != OF_DT_PROP) - break; + while (be32_to_cpu(*(u32 *) (cxt->p - i)) != OF_DT_END_NODE) + i += 4; - sz = be32_to_cpu(*p++); - s = (char *)p_strings + be32_to_cpu(*p++); - t = (char *)p; - p = (u32 *) _ALIGN((unsigned long)p + sz, 4); + memmove (cxt->p - i, cxt->p, cxt->p_end - cxt->p); - ft_prop(cxt, s, t, sz); - } + cxt->p_end -= i; + cxt->p -= i; } void *ft_get_prop(void *bphp, const char *propname, int *szp) @@ -521,9 +398,6 @@ void *ft_get_prop(void *bphp, const char /********************************************************************/ -extern unsigned char oftree_dtb[]; -extern unsigned int oftree_dtb_len; - /* Function that returns a character from the environment */ extern uchar(*env_get_char) (int); @@ -577,7 +451,7 @@ #endif }; #endif -void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_end) +void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end) { u32 *p; int len; @@ -600,20 +474,16 @@ #endif return; } - ft_begin(&cxt, blob, size); +#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); - ft_begin_tree(&cxt); - - ft_begin_node(&cxt, ""); - - ft_end_node(&cxt); - - /* copy RO tree */ - ft_merge_blob(&cxt, oftree_dtb); - /* back into root */ ft_backtrack_node(&cxt); @@ -642,8 +512,8 @@ #ifdef CONFIG_OF_HAS_UBOOT_ENV #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) { @@ -659,11 +529,7 @@ #endif ft_end_node(&cxt); /* end root */ ft_end_tree(&cxt); - - /* - printf("merged OF-tree\n"); - ft_dump_blob(blob); - */ + ft_finalize_tree(&cxt); #ifdef CONFIG_OF_HAS_BD_T /* paste the bd_t at the end of the flat tree */ @@ -712,11 +578,12 @@ #ifdef CONFIG_OF_BOARD_SETUP ft_board_setup(blob, bd); #endif - /* - printf("final OF-tree\n"); - ft_dump_blob(blob); - */ + /* 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 } - #endif diff --git a/include/ft_build.h b/include/ft_build.h index 47ca575..f515687 100644 --- a/include/ft_build.h +++ b/include/ft_build.h @@ -36,19 +36,18 @@ struct boot_param_header { struct ft_cxt { struct boot_param_header *bph; - int max_size; /* maximum size of tree */ - int overflow; /* set when this happens */ - u8 *p, *pstr, *pres; /* running pointers */ - u8 *p_begin, *pstr_begin, *pres_begin; /* starting pointers */ - u8 *p_anchor; /* start of constructed area */ - int struct_size, strings_size, res_size; + 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_begin_tree(struct ft_cxt *cxt); -int ft_end_tree(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); @@ -57,12 +56,14 @@ void ft_prop_int(struct ft_cxt *cxt, con 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, int size, bd_t * bd, ulong initrd_start, ulong initrd_end); +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); +#ifdef CONFIG_OF_BOARD_SETUP void ft_board_setup(void *blob, bd_t *bd); +#endif #endif -- 2006_06_07.01.gittree_pull-dirty ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC] consolidated libdt proposal 2006-08-08 19:12 ` Matthew McClintock @ 2006-08-11 19:33 ` Jon Loeliger 0 siblings, 0 replies; 17+ messages in thread From: Jon Loeliger @ 2006-08-11 19:33 UTC (permalink / raw) To: linuxppc-dev@ozlabs.org Cc: linuxppc-embedded, xen-ppc-devel@lists.xensource.com On Tue, 2006-08-08 at 14:12, Matthew McClintock wrote: > This is a patch to u-boot with the changes. > > * Patch to modify ft_build.c to update flat device trees in place > Patch by Matthew McClintock 26-June-2006 > > Signed-off-by: Matthew McClintock <msm@freescale.com> Also FYI, I have assembled all Matt's 85xx related U-Boot patches, along with the corresponding 86xx updates, into the u-boot-86xx.git tree on: http://jdl.com/git_repos/ This U-Boot separates out the DTS files, but allows the DTB to be downloaded. It can then update it and hand it off to either an 85xx or 86xx linux kernel. I use these commands, roughly: # build U-boot and Linux as usual $ dtc -f -V 0x10 -I dts -O dtb \ linux-2.6-86xx/arch/powerpc/boot/dts/mpc8641_hpcn.dts \ mpc8641_hpcn.dtb In U-boot now: > tftp 1000000 loeliger/uImage.8641 > tftp 900000 loeliger/mpc8641_hpcn.dtb > bootm 1000000 - 900000 Enjoy, jdl ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree 2006-08-07 0:38 ` Hollis Blanchard 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard @ 2006-08-08 0:30 ` Mark A. Greer 1 sibling, 0 replies; 17+ messages in thread From: Mark A. Greer @ 2006-08-08 0:30 UTC (permalink / raw) To: Hollis Blanchard; +Cc: linuxppc-dev, xen-ppc-devel@lists.xensource.com On Sun, Aug 06, 2006 at 07:38:02PM -0500, Hollis Blanchard wrote: > On Wed, 2006-07-19 at 16:05 -0700, an unknown sender wrote: > > --- /dev/null > > +++ b/arch/powerpc/boot/fdt.c > > @@ -0,0 +1,525 @@ > > +/* > > + * Simple dtb (binary flattened device tree) search/manipulation routines. > > + * > > + * Author: Mark A. Greer <mgreer at mvista.com> > > + * - The code for strrchr() was copied from lib/string.c and is > > + * copyrighted by Linus Torvalds. > > + * - The smarts for fdt_finddevice() were copied with the author's > > + * permission from u-boot:common/ft_build.c which was written by > > + * Pantelis Antoniou <pantelis at embeddedalley.com>. > > Hmm, so we'll have at least three copies of this code: uboot, kernel, > and Xen. Would it make sense to put this stuff into a libdt.a? Yes, it would. > Technically, dtc has a "libdt" already, but it's absurdly incomplete (I > don't even know why it's there), so we could just replace it. Sounds like a plan! > Xen needs all the finddevice and setprop functionality here, which looks > like it's about 2/3rds of this code. Yeah, pretty much. > > +static void *dtb_start; > > +static void *dtb_end; > > I'd like to avoid the use of globals here. I know it's fine when you're > running in early boot, but as I mentioned I'd like to copy this code > elsewhere. Could these be moved into a structure that's passed as a > function parameter? Sure. > > +static void > > +fdt_modify_prop(u32 *dp, char *datap, u32 *old_prop_sizep, char *buf, > > + int buflen) > > +{ > > + u32 old_prop_data_len, new_prop_data_len; > > + > > + old_prop_data_len = _ALIGN_UP(*old_prop_sizep, 4); > > + new_prop_data_len = _ALIGN_UP(buflen, 4); > > + > > + /* Check if new prop data fits in old prop data area */ > > + if (new_prop_data_len == old_prop_data_len) { > > + memcpy(datap, buf, buflen); > > + *old_prop_sizep = buflen; > > + } > > + else { /* Need to alloc new area to put larger or smaller fdt */ > > + struct boot_param_header *old_bph, *new_bph; > > + u32 *old_tailp, *new_tailp, *new_datap; > > + u32 old_total_size, new_total_size, head_len, tail_len, diff; > > + void *new_dtb_start, *new_dtb_end; > > + > > + old_bph = fdt_get_bph(dtb_start), > > + old_total_size = old_bph->totalsize; > > + head_len = (u32)datap - (u32)dtb_start; > > + tail_len = old_total_size - (head_len + old_prop_data_len); > > + old_tailp = (u32 *)((u32)dtb_end - tail_len); > > + new_total_size = head_len + new_prop_data_len + tail_len; > > + > > + if (!(new_dtb_start = malloc(new_total_size))) { > > + printf("Can't alloc space for new fdt\n\r"); > > + exit(); > > + } > > + > > + new_dtb_end = (void *)((u32)new_dtb_start + new_total_size); > > + new_datap = (u32 *)((u32)new_dtb_start + head_len); > > + new_tailp = (u32 *)((u32)new_dtb_end - tail_len); > > + > > + memcpy(new_dtb_start, dtb_start, head_len); > > + memcpy(new_datap, buf, buflen); > > + memcpy(new_tailp, old_tailp, tail_len); > > + *(new_datap - 2) = buflen; > > + > > + new_bph = fdt_get_bph(new_dtb_start), > > + new_bph->totalsize = new_total_size; > > + > > + diff = new_prop_data_len - old_prop_data_len; > > + > > + /* Adjust offsets of other sections, if necessary */ > > + if (new_bph->off_dt_strings > new_bph->off_dt_struct) > > + new_bph->off_dt_strings += diff; > > + > > + if (new_bph->off_mem_rsvmap > new_bph->off_dt_struct) > > + new_bph->off_mem_rsvmap += diff; > > + > > + free(dtb_start, old_total_size); > > + > > + dtb_start = new_dtb_start; > > + dtb_end = new_dtb_end; > > + } > > +} > > I didn't realize the boot wrapper had a full malloc() to work with. It doesn't (really). I made a standard interface to what may someday be a real memory allocator. If you look in dink.c, you'll see I just have a hack malloc() and no free() at all. Its one of those things that I was hoping someone would chip in and help with. IIRC, Matt McClintock was looking at that but I'm not sure how far he got. > I > was actually planning to only allow overwriting properties with values > of the same size, since for the most part I just need to modify some > small fixed-size data. Do you need more? I guess if the code already > works... I know that we need to extend the size of a property because /chosen/bootargs can be edited and potentially extended. Mark ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] bootwrapper: Add flat device tree ops glue code 2006-07-19 23:05 [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 2006-08-02 16:10 ` Tom Rini 2006-08-07 0:38 ` Hollis Blanchard @ 2006-09-08 3:38 ` Mark A. Greer 2 siblings, 0 replies; 17+ messages in thread From: Mark A. Greer @ 2006-09-08 3:38 UTC (permalink / raw) To: linuxppc-dev This patch adds the "glue" files that interface between the bootwrapper code and the shared code that is in flatdevtree.[ch]. Signed-off-by: Mark A. Greer <mgreer@mvista.com> -- Makefile | 2 flatdevtree_env.h | 34 ++++++ flatdevtree_misc.c | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) -- diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index c2bb541..f1877ac 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile @@ -39,6 +39,8 @@ #$(addprefix $(obj)/,main.o): $(addprefi src-boot := crt0.S string.S stdio.c main.c div64.S ifeq ($(CONFIG_PPC_MULTIPLATFORM),y) src-boot += of.c +else +src-boot += flatdevtree_misc.c endif src-boot += $(zlib) src-boot := $(addprefix $(obj)/, $(src-boot)) diff --git a/arch/powerpc/boot/flatdevtree_env.h b/arch/powerpc/boot/flatdevtree_env.h new file mode 100644 index 0000000..90e723b --- /dev/null +++ b/arch/powerpc/boot/flatdevtree_env.h @@ -0,0 +1,34 @@ +/* + * This file adds the header file glue so that the shared files + * flatdevicetree.[ch] can compile and work in the powerpc bootwrapper. + * + * Author: Mark A. Greer <mgreer@mvista.com> + * + * 2006 (c) MontaVista Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ +#ifndef _PPC_BOOT_FLATDEVTREE_ENV_H_ +#define _PPC_BOOT_FLATDEVTREE_ENV_H_ + +#include <stdarg.h> +#include <stddef.h> +#include "types.h" +#include "page.h" +#include "string.h" +#include "stdio.h" +#include "ops.h" + +#define be16_to_cpu(x) (x) +#define cpu_to_be16(x) (x) +#define be32_to_cpu(x) (x) +#define cpu_to_be32(x) (x) +#define be64_to_cpu(x) (x) +#define cpu_to_be64(x) (x) + +#define ft_malloc(s) malloc(s) +#define ft_free(p,s) free(p,s) +#define ft_exit(x) exit() + +#endif /* _PPC_BOOT_FLATDEVTREE_ENV_H_ */ diff --git a/arch/powerpc/boot/flatdevtree_misc.c b/arch/powerpc/boot/flatdevtree_misc.c new file mode 100644 index 0000000..603d89d --- /dev/null +++ b/arch/powerpc/boot/flatdevtree_misc.c @@ -0,0 +1,259 @@ +/* + * This file does the necessary interface mapping between the bootwrapper + * device tree operations and the interface provided by shared source + * files flatdevicetree.[ch]. It also provides the bootwrapper-required + * functionality that is not provided by flatdevicetree.c + * + * Author: Mark A. Greer <mgreer@mvista.com> + * ft_translate_addr() and related routines came from + * <file:arch/powerpc/kernel/prom_parse.c> which has no author or + * copyright notice. + * + * 2006 (c) MontaVista Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ +#include "flatdevtree.h" + +#define MAX_ADDR_CELLS 4 +#define BAD_ADDR ((u64)-1) + +struct ft_bus { + u64 (*map)(u32 *addr, u32 *range, int na, int ns, int pna); + int (*translate)(u32 *addr, u64 offset, int na); +}; + +static u32 ft_find_cells(char *path, char *prop) +{ + void *devp; + u32 num; + char p[MAX_PATH_LEN]; + + strcpy(p, path); + do { + if ((devp = finddevice(p)) + && (getprop(devp, prop, &num, sizeof(num)) > 0)) + return num; + ft_parentize(p, 0); + } while (strlen(p) > 0); + return 1; /* default of 1 */ +} + +static u64 ft_read_addr(u32 *cell, int size) +{ + u64 r = 0; + while (size--) + r = (r << 32) | *(cell++); + return r; +} + +static u64 ft_bus_default_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + cp = ft_read_addr(range, na); + s = ft_read_addr(range + na + pna, ns); + da = ft_read_addr(addr, na); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int ft_bus_default_translate(u32 *addr, u64 offset, int na) +{ + u64 a = ft_read_addr(addr, na); + memset(addr, 0, na * 4); + a += offset; + if (na > 1) + addr[na - 2] = a >> 32; + addr[na - 1] = a & 0xffffffffu; + + return 0; +} + +static u64 ft_bus_pci_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + /* Check address type match */ + if ((addr[0] ^ range[0]) & 0x03000000) + return BAD_ADDR; + + /* Read address values, skipping high cell */ + cp = ft_read_addr(range + 1, na - 1); + s = ft_read_addr(range + na + pna, ns); + da = ft_read_addr(addr + 1, na - 1); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int ft_bus_pci_translate(u32 *addr, u64 offset, int na) +{ + return ft_bus_default_translate(addr + 1, offset, na - 1); +} + +static u64 ft_bus_isa_map(u32 *addr, u32 *range, int na, int ns, int pna) +{ + u64 cp, s, da; + + /* Check address type match */ + if ((addr[0] ^ range[0]) & 0x00000001) + return BAD_ADDR; + + /* Read address values, skipping high cell */ + cp = ft_read_addr(range + 1, na - 1); + s = ft_read_addr(range + na + pna, ns); + da = ft_read_addr(addr + 1, na - 1); + + if (da < cp || da >= (cp + s)) + return BAD_ADDR; + return da - cp; +} + +static int ft_bus_isa_translate(u32 *addr, u64 offset, int na) +{ + return ft_bus_default_translate(addr + 1, offset, na - 1); +} + +static void ft_match_bus(char *path, struct ft_bus *bus) +{ + void *devp; + char dtype[128]; /* XXXX */ + + if ((devp = finddevice(path)) && (getprop(devp, "device_type", dtype, + sizeof(dtype)) > 0)) { + if (!strcmp(dtype, "isa")) { + bus->map = ft_bus_isa_map; + bus->translate = ft_bus_isa_translate; + } else if (!strcmp(dtype, "pci")) { + bus->map = ft_bus_pci_map; + bus->translate = ft_bus_pci_translate; + } else { + bus->map = ft_bus_default_map; + bus->translate = ft_bus_default_translate; + } + } +} + +static int ft_translate_one(char *path, struct ft_bus *bus, struct ft_bus *pbus, + u32 *addr, u32 na, u32 ns, u32 pna) +{ + void *devp; + u32 ranges[10 * (na + pna + ns)]; /* XXXX */ + u32 *rp; + unsigned int rlen; + int rone; + u64 offset = BAD_ADDR; + + if (!(devp = finddevice(path)) + || ((rlen = getprop(devp, "ranges", ranges, + sizeof(ranges))) < 0) + || (rlen == 0)) { + offset = ft_read_addr(addr, na); + memset(addr, 0, pna * 4); + goto finish; + } + + rlen /= 4; + rone = na + pna + ns; + rp = ranges; + for (; rlen >= rone; rlen -= rone, rp += rone) { + offset = bus->map(addr, rp, na, ns, pna); + if (offset != BAD_ADDR) + break; + } + if (offset == BAD_ADDR) + return 1; + memcpy(addr, rp + na, 4 * pna); + +finish: + /* Translate it into parent bus space */ + return pbus->translate(addr, offset, pna); +} + +/* 'addr' is modified */ +static u64 ft_translate_addr(const char *p, const u32 *in_addr, + const u32 addr_len) +{ + struct ft_bus bus, pbus; + int na, ns, pna, pns; + u32 addr[MAX_ADDR_CELLS]; + char path[MAX_PATH_LEN], ppath[MAX_PATH_LEN]; + + strcpy(ppath, p); + ft_parentize(ppath, 0); + ft_match_bus(ppath, &bus); + na = ft_find_cells(ppath, "#address-cells"); + ns = ft_find_cells(ppath, "#size-cells"); + memcpy(addr, in_addr, na * 4); + + for (;;) { + strcpy(path, ppath); + ft_parentize(ppath, 0); + + if (strlen(ppath) == 0) + return ft_read_addr(addr, na); + + ft_match_bus(ppath, &pbus); + pna = ft_find_cells(ppath, "#address-cells"); + pns = ft_find_cells(ppath, "#size-cells"); + + if (ft_translate_one(path, &bus, &pbus, addr, na, ns, pna)) + exit(); + + na = pna; + ns = pns; + memcpy(&bus, &pbus, sizeof(struct ft_bus)); + } +} + +static void *dtb; + +static void *ft_finddevice(const char *name) +{ + return ft_find_node(dtb, name); +} + +static int ft_getprop(const void *node, const char *propname, void *buf, + const int buflen) +{ + return ft_get_prop(dtb, node, propname, buf, buflen); +} + +static int ft_setprop(const void *node, const char *propname, const void *buf, + const int buflen) +{ + return ft_set_prop(&dtb, node, propname, buf, buflen); +} + +static void ft_call_kernel(void *entry_addr, unsigned long a1, unsigned long a2, + void *promptr, void *sp) +{ + void (*kernel_entry)(void *dt_blob, void *start_addr, + void *must_be_null); + +#ifdef DEBUG + printf("kernel:\n\r" + " entry addr = 0x%lx\n\r" + " flattened dt = 0x%lx\n\r", + (unsigned long)entry_addr, dtb); +#endif + + kernel_entry = entry_addr; + kernel_entry(dtb, entry_addr, NULL); +} + +void ft_init(void *dt_blob) +{ + dt_ops.finddevice = ft_finddevice; + dt_ops.getprop = ft_getprop; + dt_ops.setprop = ft_setprop; + dt_ops.translate_addr = ft_translate_addr; + dt_ops.call_kernel = ft_call_kernel; + + dtb = dt_blob; +} ^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2006-09-08 3:38 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-07-19 23:05 [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 2006-08-02 16:10 ` Tom Rini 2006-08-02 17:05 ` Mark A. Greer 2006-08-02 17:23 ` Tom Rini 2006-08-07 0:38 ` Hollis Blanchard 2006-08-07 21:58 ` [RFC] consolidated libdt proposal Hollis Blanchard 2006-08-08 5:37 ` Haren Myneni 2006-08-08 9:34 ` Pantelis Antoniou 2006-08-09 3:19 ` Haren Myneni 2006-08-08 18:04 ` Mark A. Greer 2006-08-08 18:25 ` Hollis Blanchard 2006-08-08 18:51 ` Mark A. Greer 2006-08-08 18:46 ` Matthew McClintock 2006-08-08 19:12 ` Matthew McClintock 2006-08-11 19:33 ` Jon Loeliger 2006-08-08 0:30 ` [PATCH 3/6] bootwrapper: Add device tree ops for flattened device tree Mark A. Greer 2006-09-08 3:38 ` [PATCH 3/6] bootwrapper: Add flat device tree ops glue code Mark A. Greer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).