X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libfdt%2Ffdt.c;h=cb08ba0a94630cc20b90955423be04886c4546c6;hb=fe749f0cef7b07f2e701543ac5f78cf21bc5829f;hp=586a36136db215fbffb450cfa475403d6755c311;hpb=9caeaadf508cd0e11ac5dfc56ab0f72e3b89a105;p=platform%2Fkernel%2Fu-boot.git diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 586a361..cb08ba0 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h" +#ifndef USE_HOSTCC #include #include +#else +#include "fdt_host.h" +#endif #include "libfdt_internal.h" @@ -129,6 +133,54 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset) return tag; } +int _fdt_check_node_offset(const void *fdt, int offset) +{ + if ((offset < 0) || (offset % FDT_TAGSIZE) + || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)) + return -FDT_ERR_BADOFFSET; + + return offset; +} + +int fdt_next_node(const void *fdt, int offset, int *depth) +{ + int nextoffset = 0; + uint32_t tag; + + if (offset >= 0) + if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0) + return nextoffset; + + 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; @@ -143,10 +195,7 @@ const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) int fdt_move(const void *fdt, void *buf, int bufsize) { - int err = fdt_check_header(fdt); - - if (err) - return err; + CHECK_HEADER(fdt); if (fdt_totalsize(fdt) > bufsize) return -FDT_ERR_NOSPACE;