summaryrefslogtreecommitdiff
path: root/libfdt/fdt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2008-02-12 11:58:31 +1100
committerGerald Van Baren <vanbaren@cideas.com>2008-03-18 21:03:45 -0400
commitae0b5908de3b9855f8931bc9b32c9fc4962df5a9 (patch)
tree95f9df10a186b5c4c62d311f8df8d0830b06e7d4 /libfdt/fdt.c
parent9eaeb07a7185d852c7aa10735ecd4e9edf24fb5d (diff)
downloadu-boot-ae0b5908de3b9855f8931bc9b32c9fc4962df5a9.tar.gz
u-boot-ae0b5908de3b9855f8931bc9b32c9fc4962df5a9.tar.bz2
u-boot-ae0b5908de3b9855f8931bc9b32c9fc4962df5a9.zip
libfdt: Add and use a node iteration helper function.
This patch adds an fdt_next_node() function which can be used to iterate through nodes of the tree while keeping track of depth. This function is used to simplify the iteration code in a lot of other functions, and is also exported for use by library users. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt/fdt.c')
-rw-r--r--libfdt/fdt.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 586a36136d..c61fb531b3 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -129,6 +129,47 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset)
return tag;
}
+int fdt_next_node(const void *fdt, int offset, int *depth)
+{
+ int nextoffset = 0;
+ uint32_t tag;
+
+ if (offset >= 0) {
+ tag = fdt_next_tag(fdt, offset, &nextoffset);
+ if (tag != FDT_BEGIN_NODE)
+ return -FDT_ERR_BADOFFSET;
+ }
+
+ do {
+ offset = nextoffset;
+ tag = fdt_next_tag(fdt, offset, &nextoffset);
+
+ switch (tag) {
+ case FDT_PROP:
+ case FDT_NOP:
+ break;
+
+ case FDT_BEGIN_NODE:
+ if (depth)
+ (*depth)++;
+ break;
+
+ case FDT_END_NODE:
+ if (depth)
+ (*depth)--;
+ break;
+
+ case FDT_END:
+ return -FDT_ERR_NOTFOUND;
+
+ default:
+ return -FDT_ERR_BADSTRUCTURE;
+ }
+ } while (tag != FDT_BEGIN_NODE);
+
+ return offset;
+}
+
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
{
int len = strlen(s) + 1;