[U-Boot-Users] [PATCH] Add a oftdump (open firmware flattened tree dump) command.

Grant Likely grant.likely at secretlab.ca
Thu Nov 2 16:46:43 CET 2006


On 10/31/06, Jerry Van Baren <gerald.vanbaren at smiths-aerospace.com> wrote:
> Add a oftdump (open firmware flattened tree dump) command.
>
> Git repository:
> <http://www.cideas.us/cgi-bin/gitweb.cgi?p=u-boot/u-boot-of-cmd.git;a=summary>
>
> Branch: of-cmd
> <http://www.cideas.us/cgi-bin/gitweb.cgi?p=u-boot/u-boot-of-cmd.git;a=shortlog;h=of-cmd>
>
> Signed-off-by: Jerry Van Baren <vanbaren at cideas.com>

Not that I have any authority on this, but I'm going to NAK it (for
right now).  Others may disagree.

The global statics really bother me, and I'll take a look myself if
there is a better way.  Give me a few days.

Cheers,
g.

>
>
> >From 20328071e132c40c662ffb2a07460144841b9e1a Mon Sep 17 00:00:00 2001
> From: Jerry Van Baren <vanbaren at cideas.com>
> Date: Mon, 30 Oct 2006 21:47:02 -0500
> Subject: [PATCH] Add a oftdump (open firmware flattened tree dump) command.
> ---
>  common/Makefile      |    2 +-
>  common/cmd_bootm.c   |    2 --
>  common/cmd_oftdump.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
>  common/ft_build.c    |   65 ++++++++++++++++++++++++++++++++++++++++++--------
>  include/ft_build.h   |    2 +-
>  5 files changed, 114 insertions(+), 15 deletions(-)
>
> diff --git a/common/Makefile b/common/Makefile
> index 07ddc95..477aadb 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -37,7 +37,7 @@ COBJS = main.o ACEX1K.o altera.o bedbug.
>           cmd_i2c.o cmd_ide.o cmd_immap.o cmd_itest.o cmd_jffs2.o \
>           cmd_load.o cmd_log.o \
>           cmd_mem.o cmd_mii.o cmd_misc.o cmd_mmc.o \
> -         cmd_nand.o cmd_net.o cmd_nvedit.o \
> +         cmd_nand.o cmd_net.o cmd_nvedit.o cmd_oftdump.o \
>           cmd_pci.o cmd_pcmcia.o cmd_portio.o \
>           cmd_reginfo.o cmd_reiser.o cmd_scsi.o cmd_spi.o cmd_universe.o \
>           cmd_usb.o cmd_vfd.o \
> diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
> index 3091a58..1797328 100644
> --- a/common/cmd_bootm.c
> +++ b/common/cmd_bootm.c
> @@ -950,7 +950,6 @@ #else       /* CONFIG_OF_FLAT_TREE */
>         }
>
>         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)
>         unlock_ram_in_cache();
> @@ -968,7 +967,6 @@ #endif
>                         cmd_start, cmd_end);
>         else {
>                 ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
> -               /* ft_dump_blob(of_flat_tree); */
>                 (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
>         }
>  #endif /* CONFIG_OF_FLAT_TREE */
> diff --git a/common/cmd_oftdump.c b/common/cmd_oftdump.c
> new file mode 100644
> index 0000000..5cc1995
> --- /dev/null
> +++ b/common/cmd_oftdump.c
> @@ -0,0 +1,58 @@
> +/*
> + * (C) Copyright 2006
> + * Gerald Van Baren, Custom IDEAS, vanbaren at cideas.com.
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * 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
> + */
> +
> +/*
> + * Misc functions
> + */
> +#include <common.h>
> +#include <command.h>
> +#include <ft_build.h>
> +
> +#ifdef CONFIG_OF_FLAT_TREE
> +
> +int do_oftdump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
> +{
> +       void    *p = (void *)simple_strtoul(argv[1], NULL, 16);
> +
> +       if (argc < 2) {
> +               printf ("Usage:\n%s\n", cmdtp->usage);
> +               return 1;
> +       } else if (argc == 2) {
> +               ft_dump_blob(p, "/");
> +       } else {
> +               ft_dump_blob(p, argv[2]);
> +       }
> +
> +       return 0;
> +}
> +
> +
> +U_BOOT_CMD(
> +       oftdump, 3,     0,      do_oftdump,
> +       "oftdump - Open Firmware flattened tree dump\n",
> +       "oftdump <addr>        - Dump the whole OF flattened tree\n"
> +       "oftdump <addr> <prop> - Dump the given OF property\n"
> +);
> +
> +#endif /* CONFIG_OF_FLAT_TREE */
> +
> diff --git a/common/ft_build.c b/common/ft_build.c
> index 980e40f..4fbe34c 100644
> --- a/common/ft_build.c
> +++ b/common/ft_build.c
> @@ -233,10 +233,19 @@ static void print_data(const void *data,
>                 printf(" = <%04x>", be16_to_cpu(*(u16 *) data) & 0xffff);
>                 break;
>         case 4:         /* word */
> -               printf(" = <%x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
> +               printf(" = <%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
>                 break;
>         case 8:         /* double-word */
> -               printf(" = <%qx>", be64_to_cpu(*(uint64_t *) data));
> +               /*
> +                * If 64 bit printing is supported, use it.
> +                */
> +#ifdef CFG_64BIT_VSPRINTF
> +               printf(" = <%016llx>", be64_to_cpu(*(uint64_t *) data));
> +#else
> +               printf(" = <%08x", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
> +               data += sizeof(u32);
> +               printf(" %08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
> +#endif
>                 break;
>         default:                /* anything else... hexdump */
>                 printf(" = [");
> @@ -248,7 +257,12 @@ static void print_data(const void *data,
>         }
>  }
>
> -void ft_dump_blob(const void *bphp)
> +/*
> + * Used by ft_dump_blob() and ft_get_prop() to build up property names
> + */
> +static char path[256], prop[256];
> +
> +void ft_dump_blob(const void *bphp, const char *propname)
>  {
>         const struct boot_param_header *bph = bphp;
>         const uint64_t *p_rsvmap = (const uint64_t *)
> @@ -260,17 +274,22 @@ void ft_dump_blob(const void *bphp)
>         u32 tag;
>         const u32 *p;
>         const char *s, *t;
> +       char *ss;
>         int depth, sz, shift;
> +       int found;
>         int i;
>         uint64_t addr, size;
>
>         if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
>                 /* not valid tree */
> +               printf("Not a valid tree.\n");
>                 return;
>         }
>
>         depth = 0;
>         shift = 4;
> +       found = 0;
> +       strcpy(path, "/");
>
>         for (i = 0;; i++) {
>                 addr = be64_to_cpu(p_rsvmap[i * 2]);
> @@ -290,7 +309,17 @@ void ft_dump_blob(const void *bphp)
>                         s = (const char *)p;
>                         p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4);
>
> -                       printf("%*s%s {\n", depth * shift, "", s);
> +                       strcat(path, s);
> +                       if (found || (strcmp(path, propname) == 0)) {
> +                               found++;
> +                               if (depth == 0)
> +                                       printf("/ {\n");
> +                               else
> +                                       printf("%*s%s {\n", depth * shift, "", s);
> +                       }
> +                       /* The root path is already there as "/" */
> +                       if(depth != 0)
> +                               strcat(path, "/");
>
>                         depth++;
>                         continue;
> @@ -299,7 +328,16 @@ void ft_dump_blob(const void *bphp)
>                 if (tag == OF_DT_END_NODE) {
>                         depth--;
>
> -                       printf("%*s};\n", depth * shift, "");
> +                       path[strlen(path) - 1] = '\0';
> +                       ss = strrchr(path, '/');
> +                       if (ss != NULL)
> +                               ss[1] = '\0';
> +
> +                       if(found) {
> +                               printf("%*s};\n", depth * shift, "");
> +                               if (found-- == 0)
> +                                       return;         /* request done */
> +                       }
>                         continue;
>                 }
>
> @@ -317,9 +355,15 @@ void ft_dump_blob(const void *bphp)
>                 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");
> +
> +               strcpy(prop, path);
> +               strcat(prop, s);
> +
> +               if(found || (strcmp(prop, propname) == 0)) {
> +                       printf("%*s%s", depth * shift, "", s);
> +                       print_data(t, sz);
> +                       printf(";\n");
> +               }
>         }
>  }
>
> @@ -349,7 +393,6 @@ void *ft_get_prop(void *bphp, const char
>         char *s, *t;
>         char *ss;
>         int sz;
> -       static char path[256], prop[256];
>
>         path[0] = '\0';
>
> @@ -478,7 +521,7 @@ #endif
>
>  #ifdef DEBUG
>         printf ("recieved oftree\n");
> -       ft_dump_blob(blob);
> +       ft_dump_blob(blob, "/");
>  #endif
>
>         ft_init_cxt(&cxt, blob);
> @@ -585,7 +628,7 @@ #endif
>
>  #ifdef DEBUG
>         printf("final OF-tree\n");
> -       ft_dump_blob(blob);
> +       ft_dump_blob(blob, "/");
>  #endif
>  }
>  #endif
> diff --git a/include/ft_build.h b/include/ft_build.h
> index 89c689c..5530122 100644
> --- a/include/ft_build.h
> +++ b/include/ft_build.h
> @@ -58,7 +58,7 @@ void ft_add_rsvmap(struct ft_cxt *cxt, u
>
>  void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end);
>
> -void ft_dump_blob(const void *bphp);
> +void ft_dump_blob(const void *bphp, const char *propname);
>  void ft_merge_blob(struct ft_cxt *cxt, void *blob);
>  void *ft_get_prop(void *bphp, const char *propname, int *szp);
>
> --
> 1.4.1.1
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
> _______________________________________________
> U-Boot-Users mailing list
> U-Boot-Users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/u-boot-users
>
>
>


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




More information about the U-Boot mailing list