diff options
author | Wolfgang Denk <wd@denx.de> | 2008-04-08 00:20:52 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2008-04-08 00:20:52 +0200 |
commit | aeff6d503b6006573d5c6b04fc658a64bebee5fa (patch) | |
tree | a8f27e3fede8e8dc1d78b5f8628ac9294829051b /common | |
parent | a1b215e2a2a013327693f2fb990957b746f26cf5 (diff) | |
parent | c2a545ce33b26d80337f80b533828839249fb1c9 (diff) | |
download | u-boot-imx-aeff6d503b6006573d5c6b04fc658a64bebee5fa.zip u-boot-imx-aeff6d503b6006573d5c6b04fc658a64bebee5fa.tar.gz u-boot-imx-aeff6d503b6006573d5c6b04fc658a64bebee5fa.tar.bz2 |
Merge branch 'master' of git://www.denx.de/git/u-boot-fdt
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_fdt.c | 137 | ||||
-rw-r--r-- | common/ft_build.c | 113 |
2 files changed, 67 insertions, 183 deletions
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index a52284e..7436a95 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -42,8 +42,7 @@ DECLARE_GLOBAL_DATA_PTR; static int fdt_valid(void); -static int fdt_parse_prop(char *pathp, char *prop, char *newval, - char *data, int *len); +static int fdt_parse_prop(char **newval, int count, char *data, int *len); static int fdt_print(const char *pathp, char *prop, int depth); /* @@ -202,7 +201,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) if (argc == 4) { len = 0; } else { - ret = fdt_parse_prop(pathp, prop, argv[4], data, &len); + ret = fdt_parse_prop(&argv[4], argc - 4, data, &len); if (ret != 0) return ret; } @@ -464,69 +463,77 @@ static int fdt_valid(void) /* * Parse the user's input, partially heuristic. Valid formats: - * <00> - hex byte - * <0011> - hex half word (16 bits) - * <00112233> - hex word (32 bits) - * - hex double words (64 bits) are not supported, must use - * a byte stream instead. + * <0x00112233 4 05> - an array of cells. Numbers follow standard + * C conventions. * [00 11 22 .. nn] - byte stream * "string" - If the the value doesn't start with "<" or "[", it is * treated as a string. Note that the quotes are * stripped by the parser before we get the string. + * newval: An array of strings containing the new property as specified + * on the command line + * count: The number of strings in the array + * data: A bytestream to be placed in the property + * len: The length of the resulting bytestream */ -static int fdt_parse_prop(char *pathp, char *prop, char *newval, - char *data, int *len) +static int fdt_parse_prop(char **newval, int count, char *data, int *len) { char *cp; /* temporary char pointer */ + char *newp; /* temporary newval char pointer */ unsigned long tmp; /* holds converted values */ + int stridx = 0; - if (*newval == '<') { - /* - * Bigger values than bytes. - */ - *len = 0; - newval++; - while ((*newval != '>') && (*newval != '\0')) { - cp = newval; - tmp = simple_strtoul(cp, &newval, 16); - if ((newval - cp) <= 2) { - *data = tmp & 0xFF; - data += 1; - *len += 1; - } else if ((newval - cp) <= 4) { - *(uint16_t *)data = __cpu_to_be16(tmp); - data += 2; - *len += 2; - } else if ((newval - cp) <= 8) { - *(uint32_t *)data = __cpu_to_be32(tmp); - data += 4; - *len += 4; - } else { + *len = 0; + newp = newval[0]; + + /* An array of cells */ + if (*newp == '<') { + newp++; + while ((*newp != '>') && (stridx < count)) { + /* + * Keep searching until we find that last ">" + * That way users don't have to escape the spaces + */ + if (*newp == '\0') { + newp = newval[++stridx]; + continue; + } + + cp = newp; + tmp = simple_strtoul(cp, &newp, 0); + *(uint32_t *)data = __cpu_to_be32(tmp); + data += 4; + *len += 4; + + /* If the ptr didn't advance, something went wrong */ + if ((newp - cp) <= 0) { printf("Sorry, I could not convert \"%s\"\n", cp); return 1; } - while (*newval == ' ') - newval++; + + while (*newp == ' ') + newp++; } - if (*newval != '>') { - printf("Unexpected character '%c'\n", *newval); + + if (*newp != '>') { + printf("Unexpected character '%c'\n", *newp); return 1; } - } else if (*newval == '[') { + } else if (*newp == '[') { /* * Byte stream. Convert the values. */ - *len = 0; - newval++; - while ((*newval != ']') && (*newval != '\0')) { - tmp = simple_strtoul(newval, &newval, 16); + newp++; + while ((*newp != ']') && (stridx < count)) { + tmp = simple_strtoul(newp, &newp, 16); *data++ = tmp & 0xFF; *len = *len + 1; - while (*newval == ' ') - newval++; + while (*newp == ' ') + newp++; + if (*newp != '\0') + newp = newval[++stridx]; } - if (*newval != ']') { + if (*newp != ']') { printf("Unexpected character '%c'\n", *newval); return 1; } @@ -535,8 +542,11 @@ static int fdt_parse_prop(char *pathp, char *prop, char *newval, * Assume it is a string. Copy it into our data area for * convenience (including the terminating '\0'). */ - *len = strlen(newval) + 1; - strcpy(data, newval); + while (stridx < count) { + *len = strlen(newp) + 1; + strcpy(data, newp); + newp = newval[++stridx]; + } } return 0; } @@ -593,7 +603,6 @@ static int is_printable_string(const void *data, int len) static void print_data(const void *data, int len) { int j; - const u8 *s; /* no data, don't print */ if (len == 0) @@ -616,32 +625,20 @@ static void print_data(const void *data, int len) return; } - switch (len) { - case 1: /* byte */ - printf("<0x%02x>", (*(u8 *) 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 */ -#if __WORDSIZE == 64 - printf("<0x%016llx>", be64_to_cpu(*(uint64_t *) data)); -#else - printf("<0x%08x ", be32_to_cpu(*(u32 *) data) & 0xffffffffU); - data += 4; - printf("0x%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); -#endif - break; - default: /* anything else... hexdump */ + if ((len %4) == 0) { + const u32 *p; + + printf("<"); + for (j = 0, p = data; j < len/4; j ++) + printf("0x%x%s", p[j], j < (len/4 - 1) ? " " : ""); + printf(">"); + } else { /* anything else... hexdump */ + const u8 *s; + printf("["); for (j = 0, s = data; j < len; j++) printf("%02x%s", s[j], j < len - 1 ? " " : ""); printf("]"); - - break; } } @@ -771,7 +768,7 @@ static int fdt_print(const char *pathp, char *prop, int depth) /********************************************************************/ U_BOOT_CMD( - fdt, 5, 0, do_fdt, + fdt, 255, 0, do_fdt, "fdt - flattened device tree utility commands\n", "addr <addr> [<length>] - Set the fdt location to <addr>\n" #ifdef CONFIG_OF_BOARD_SETUP diff --git a/common/ft_build.c b/common/ft_build.c index 5a0575e..0e5699a 100644 --- a/common/ft_build.c +++ b/common/ft_build.c @@ -399,72 +399,12 @@ void *ft_get_prop(void *bphp, const char *propname, int *szp) /* 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) { @@ -485,30 +425,6 @@ void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end) /* 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"); @@ -529,36 +445,7 @@ void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end) 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) |