From: Ian Campbell Subject: Re: [PATCH 4/8] device tree: add device_tree_dump() to print a flat device tree Date: Wed, 14 Mar 2012 10:11:15 +0000 Message-ID: <1331719875.23971.367.camel@zakaz.uk.xensource.com> References: <1330448064-32267-1-git-send-email-david.vrabel@citrix.com> <1330448064-32267-5-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1330448064-32267-5-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Tue, 2012-02-28 at 16:54 +0000, David Vrabel wrote: > From: David Vrabel > > Add a device_tree_dump() function which prints to main structure and > properties names of a flat device tree (but not the properties values > yet). > > This will be useful for debugging problems with the device tree > generated for dom0. > > Signed-off-by: David Vrabel Other than coding style issues (which I'm not going to comment on any more): Acked-by: Ian Campbell > --- > xen/common/device_tree.c | 38 ++++++++++++++++++++++++++++++++++++++ > xen/include/xen/device_tree.h | 1 + > 2 files changed, 39 insertions(+), 0 deletions(-) > > diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c > index e95ff3c..dbc4f61 100644 > --- a/xen/common/device_tree.c > +++ b/xen/common/device_tree.c > @@ -101,6 +101,44 @@ int device_tree_for_each_node(const void *fdt, > return 0; > } > > +static int dump_node(const void *fdt, int node, const char *name, int depth, > + u32 address_cells, u32 size_cells, void *data) > +{ > + char prefix[2*MAX_DEPTH + 1] = ""; > + int i; > + int prop; > + > + for (i = 0; i < depth; i++) > + safe_strcat(prefix, " "); > + > + if (name[0] == '\0') > + name = "/"; > + printk("%s%s:\n", prefix, name); > + > + for (prop = fdt_first_property_offset(fdt, node); > + prop >= 0; > + prop = fdt_next_property_offset(fdt, prop)) > + { > + const struct fdt_property *p; > + > + p = fdt_get_property_by_offset(fdt, prop, NULL); > + > + printk("%s %s\n", prefix, fdt_string(fdt, fdt32_to_cpu(p->nameoff))); > + } > + > + return 0; > +} > + > +/** > + * device_tree_dump - print a text representation of a device tree > + * @fdt: flat device tree to print > + */ > +void device_tree_dump(const void *fdt) > +{ > + device_tree_for_each_node(fdt, dump_node, NULL); > +} > + > + > static void __init process_memory_node(const void *fdt, int node, const char *name, > u32 address_cells, u32 size_cells) > { > diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h > index 505f3e3..b91b39f 100644 > --- a/xen/include/xen/device_tree.h > +++ b/xen/include/xen/device_tree.h > @@ -41,5 +41,6 @@ paddr_t device_tree_get_xen_paddr(void); > > int device_tree_for_each_node(const void *fdt, > device_tree_node_func func, void *data); > +void device_tree_dump(const void *fdt); > > #endif