Introduce fdtgrep for subsetting and hashing FDTs
cover Introduce fdtgrep for subsetting and hashing FDTs
This series adds a new function, fdt_find_regions() which maps FDT parts such as nodes and properties to their regions in the FDT binary. The function is then used to implement a grep utility for FDTs.
The function itself is quite simple and small, but this series adds tests and a grep utility, so quite a bit of code is built on it.
The use for this function is twofold. Firstly it provides a convenient way of performing a structure-aware grep of the tree. For example it is possible to grep for a node and get all the properties associated with that node. Trees can be subsetted easily, by specifying the nodes that are required, and then writing out the regions returned by this function. This is useful for small resource-constrained systems, such as boot loaders, which want to use an FDT but do not need to know about all of it. The full FDT can be grepped to pull out the few things that are needed - this can be automatic and does not require the FDT source code.
This first use makes it easy to implement an FDT grep. Options are provided to search for matching nodes (by name or compatible string), properties and also for any of the above. It is possible to search for non-matches also (useful for excluding a particular property from the FDT, for example). The output is like fdtdump, but only with the regions selected by the grep. Options are also provided to print the string table, memory reservation table, etc. The fdtgrep utility can output valid source, which can be used by dtc, but it can also directly output a new .dtb binary.
Secondly it makes it easy to hash parts of the tree and detect changes. The intent is to get a list of regions which will be invariant provided those parts are invariant. For example, if you request a list of regions for all nodes but exclude the property "data", then you will get the same region contents regardless of any change to "data" properties.
This second use is the subject of a recent series sent to the U-Boot mailing list, to enhance FIT images to support verified boot. Briefly, this works by signing configurations (consisting of particular kernel and FDT combinations) so that the boot loader can verify that these combinations are valid and permitted. Since a FIT image is in fact an FDT, we need to be able to hash particular regions of the FDT for the signing and verification process. This is done by using fdt_find_regions() to select the data that needs to be hashed for a particular configuration.
The fdtgrep utility can fairly easily replace all of the functions of fdtdump, so this series turns fdtdump into a symlink.
Simon Glass (8):
Adjust util_is_printable_string() comment and fix test Move property-printing into util
.gitignore: Add rule for *.patch
Export fdt_stringlist_contains()
libfdt: Add function to find regions in an FDT Add fdtgrep to grep and subset FDTs
Remove fdtdump and use fdtgrep instead
RFC: Check offset in fdt_string()
.gitignore | 2 + Makefile | 9 +- Makefile.utils | 7 + fdtdump.c | 172 ----------- fdtgrep.c | 789 ++++++++++++++++++++++++++++++++++++++++++++++++++ libfdt/fdt_ro.c | 7 +- libfdt/fdt_wip.c | 311 ++++++++++++++++++++ libfdt/libfdt.h | 156 ++++++++++ tests/.gitignore | 1 + tests/Makefile.tests | 3 +- tests/grep.dts | 23 ++ tests/region_tree.c | 324 +++++++++++++++++++++ tests/run_tests.sh | 357 ++++++++++++++++++++++- tests/tests.sh | 1 + util.c | 37 +++ util.h | 22 ++- 16 files changed, 2036 insertions(+), 185 deletions(-) delete mode 100644 fdtdump.c create mode 100644 fdtgrep.c create mode 100644 tests/grep.dts create mode 100644 tests/region_tree.c
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH 1/8 Adjust util_is_printable_string() comment and fix test
This commit which changed the behaviour of this function broke one of the tests. Also the comment should be updated to reflect its new behaviour.
--- tests/run_tests.sh | 4 +--- util.h | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-)
tests/run_tests.sh +1 -3
@@ -498,9 +498,7 @@ fdtget_tests () { # run_fdtget_test <expected-result> [<flags>] <file> <node> <property> run_fdtget_test "MyBoardName" $dtb / model - run_fdtget_test "77 121 66 111 \ -97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \ -108 121 78 97 109 101 0" $dtb / compatible + run_fdtget_test "MyBoardName MyBoardFamilyName" $dtb / compatible run_fdtget_test "MyBoardName MyBoardFamilyName" -t s $dtb / compatible run_fdtget_test 32768 $dtb /cpus/PowerPC,970@1 d-cache-size run_fdtget_test 8000 -tx $dtb /cpus/PowerPC,970@1 d-cache-size
util.h +5 -3
@@ -57,12 +57,14 @@ extern char *xstrdup(const char *s);extern char *join_path (const char *path,const char *name);/** -* Check a string of a given length to see if it is all printable and -* has a valid terminator. +* Check a property of a given length to see if it is all printable and +* has a valid terminator. The property can contain either a single string, +* or multiple strings each of non-zero length. * * @param data The string to check * @param len The string length including terminator -* @return 1 if a valid printable string, 0 if not */ +* @return 1 if a valid printable string, 0 if not +*/ int util_is_printable_string (const void *data,int len);/*
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH 1/8] Adjust util_is_printable_string() comment and fix test
Quoted 5 lines · Simon Glass
This commit which changed the behaviour of this function broke one of the tests. Also the comment should be updated to reflect its new behaviour.
Signed-off-by Simon Glass <[email protected]>
Jon, please apply asap, regardless of what we do with the rest of this series, since it fixes up the ugly test failure we have right now.
Quoted 10 lines
--- tests/run_tests.sh | 4 +--- util.h | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-)tests/run_tests.sh +0
-0
tests/run_tests.sh fdtget_tests () { · line 501
Quoted 7 lines
tests/run_tests.sh +1
-3@@ -498,9 +498,7 @@ fdtget_tests () { # run_fdtget_test <expected-result> [<flags>] <file> <node> <property> run_fdtget_test "MyBoardName" $dtb / model - run_fdtget_test "77 121 66 111 \ -97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \ -108 121 78 97 109 101 0" $dtb / compatible + run_fdtget_test "MyBoardName MyBoardFamilyName" $dtb / compatible
I would also like to see a test of the old-style behaviour still present, by explicitly enabling it with -t bu.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
A message that is not in the archive (sent off-list or not yet received): 20130122053340.GJ23500-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org
Re: [PATCH 1/8] Adjust util_is_printable_string() comment and fix test
Hi David,
Quoted 23 lines · David Gibson
Quoted 5 lines · Simon Glass
This commit which changed the behaviour of this function broke one of the tests. Also the comment should be updated to reflect its new behaviour.
Signed-off-by Simon Glass <[email protected]>Acked-by David Gibson <[email protected]>Jon, please apply asap, regardless of what we do with the rest of this series, since it fixes up the ugly test failure we have right now.
Quoted 11 lines
--- tests/run_tests.sh | 4 +--- util.h | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-)tests/run_tests.sh +0
-0@@ -498,9 +498,7 @@ fdtget_tests () {
Quoted 9 lines
tests/run_tests.sh fdtget_tests () { · line 501
Quoted 6 lines
tests/run_tests.sh +1
-3# run_fdtget_test <expected-result> [<flags>] <file> <node> <property> run_fdtget_test "MyBoardName" $dtb / model - run_fdtget_test "77 121 66 111 \ -97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \ -108 121 78 97 109 101 0" $dtb / compatible + run_fdtget_test "MyBoardName MyBoardFamilyName" $dtb / compatibleI would also like to see a test of the old-style behaviour still present, by explicitly enabling it with -t bu.
OK - I have sent a v2 of this patch.
Regards,
Simon
Quoted 6 lines
--
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_!
PATCH 2/8 Move property-printing into util
In reply to a message not in the archiveThe function that prints a property can be useful to other programs, so move it into util.
--- fdtdump.c | 37 +------------------------------------ util.c | 37 +++++++++++++++++++++++++++++++++++++ util.h | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 36 deletions(-)
fdtdump.c +1 -36
@@ -17,41 +17,6 @@#define PALIGN (p, a) ((void *)(ALIGN((unsigned long)(p), (a))))#define GET_CELL (p) (p += 4, *((const uint32_t *)(p-4))) -static void print_data (const char *data,int len) -{ -int i; -const char *p = data; -const char *s; - -/* no data, don't print */ -if (len ==0 ) -return ; - -if (util_is_printable_string (data, len)) { -printf (" = " ); - - s = data; -do { -printf ("\"%s\"" , s); - s +=strlen (s) +1 ; -if (s < data + len) -printf (", " ); - }while (s < data + len); - - }else if ((len %4 ) ==0 ) { -printf (" = <" ); -for (i =0 ; i < len; i +=4 ) -printf ("0x%08x%s" ,fdt32_to_cpu (GET_CELL (p)), - i < (len -4 ) ?" " :"" ); -printf (">" ); - }else { -printf (" = [" ); -for (i =0 ; i < len; i++) -printf ("%02x%s" , *p++, i < len -1 ?" " :"" ); -printf ("]" ); - } -} -static void dump_blob (void *blob) {struct fdt_header *bph = blob;
@@ -147,7 +112,7 @@ static void dump_blob(void *blob) p =PALIGN (p + sz,4 );printf ("%*s%s" , depth * shift,"" , s); -print_data (t, sz); +utilfdt_print_data (t, sz);printf (";\n" ); } }
util.c +37 -0
@@ -335,3 +335,40 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size)return -1 ;return 0 ; } + +void utilfdt_print_data (const char *data,int len) +{ +int i; +const char *p = data; +const char *s; + +/* no data, don't print */ +if (len ==0 ) +return ; + +if (util_is_printable_string (data, len)) { +printf (" = " ); + + s = data; +do { +printf ("\"%s\"" , s); + s +=strlen (s) +1 ; +if (s < data + len) +printf (", " ); + }while (s < data + len); + + }else if ((len %4 ) ==0 ) { +const uint32_t *cell = (const uint32_t *)data; + +printf (" = <" ); +for (i =0 ; i < len; i +=4 ) +printf ("0x%08x%s" ,fdt32_to_cpu (cell[i]), + i < (len -4 ) ?" " :"" ); +printf (">" ); + }else { +printf (" = [" ); +for (i =0 ; i < len; i++) +printf ("%02x%s" , *p++, i < len -1 ?" " :"" ); +printf ("]" ); + } +}
util.h +14 -0
@@ -152,4 +152,18 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size);"\tOptional modifier prefix:\n" \"\t\thh or b=byte, h=2 byte, l=4 byte (default)\n" ; +/** +* Print property data in a readable format to stdout +* +* Properties that look like strings will be printed as strings. Otherwise +* the data will be displayed either as cells (if len is a multiple of 4 +* bytes) or bytes. +* +* If len is 0 then this function does nothing. +* +* @param data Pointers to property data +* @param len Length of property data +*/ +void utilfdt_print_data (const char *data,int len); +#endif /* _UTIL_H */
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH 2/8] Move property-printing into util
Quoted 4 lines · Simon Glass
The function that prints a property can be useful to other programs, so move it into util.
Signed-off-by Simon Glass <[email protected]>
Straightforward enough.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Jon Loeliger
AppliedRe: [PATCH 2/8] Move property-printing into util
In reply to a message not in the archiveQuoted 4 lines
The function that prints a property can be useful to other programs, so move it into util.
Signed-off-by Simon Glass <[email protected]>
Applied.
Thanks,
jdl
PATCH 3/8 .gitignore: Add rule for *.patch
In reply to a message not in the archiveIgnore any patch files that we find, since these are likely to be used when sending patches upstream.
--- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
.gitignore +1 -0
@@ -1,6 +1,7 @@ *.o *.d *.a +*.patch *.so *~ *.tab.[ch]
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH 3/8] .gitignore: Add rule for *.patch
Quoted 4 lines · Simon Glass
Ignore any patch files that we find, since these are likely to be used when sending patches upstream.
Signed-off-by Simon Glass <[email protected]>
Not really related to this series at all, but I think this is a reasonable addition. Jon, please apply, regardless of the rest of the series.
Quoted 16 lines
--- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-).gitignore +1
-0@@ -1,6 +1,7 @@ *.o *.d *.a +*.patch *.so *~ *.tab.[ch]
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Jon Loeliger
AppliedRe: [PATCH 3/8] .gitignore: Add rule for *.patch
In reply to a message not in the archiveQuoted 4 lines
Ignore any patch files that we find, since these are likely to be used when sending patches upstream.
Signed-off-by Simon Glass <[email protected]>
Applied.
Thanks,
jdl
PATCH 4/8 Export fdt_stringlist_contains()
In reply to a message not in the archiveThis function is useful outside libfdt, so export it.
--- libfdt/fdt_ro.c | 5 ++--- libfdt/libfdt.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
libfdt/fdt_ro.c +2 -3
@@ -515,8 +515,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)return offset;/* error from fdt_next_node() */ } -static int _fdt_stringlist_contains (const char *strlist,int listlen, -const char *str) +int fdt_stringlist_contains (const char *strlist,int listlen,const char *str) {int len =strlen (str);const char *p;
@@ -542,7 +541,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset, prop =fdt_getprop (fdt, nodeoffset,"compatible" , &len);if (!prop)return len; -if (_fdt_stringlist_contains (prop, len, compatible)) +if (fdt_stringlist_contains (prop, len, compatible))return 0 ;else return 1 ;
libfdt/libfdt.h +14 -0
@@ -816,6 +816,20 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,int fdt_node_offset_by_compatible (const void *fdt,int startoffset,const char *compatible); +/** +* fdt_stringlist_contains - check a string list property for a string +* @strlist: Property containing a list of strings to check +* @listlen: Length of property +* @str: String to search for +* +* This is a utility function provided for convenience. The list contains +* one or more strings, each terminated by \0, as is found in a device tree +* "compatible" property. +* +* @return: 1 if the string is found in the list, 0 not found, or invalid list +*/ +int fdt_stringlist_contains (const char *strlist,int listlen,const char *str); +/**********************************************************************/ /* Write-in-place functions */ /**********************************************************************/
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-5-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH 4/8] Export fdt_stringlist_contains()
Quoted 3 lines · Simon Glass
This function is useful outside libfdt, so export it.
Signed-off-by Simon Glass <[email protected]>
I didn't export this initially since the compatible test was the only user I knew of. But exporting it seems like a generally good idea.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Jon Loeliger
AppliedRe: [PATCH 4/8] Export fdt_stringlist_contains()
In reply to a message not in the archiveQuoted 3 lines
This function is useful outside libfdt, so export it.
Signed-off-by Simon Glass <[email protected]>
Applied.
Thanks,
jdl
PATCH 5/8 libfdt: Add function to find regions in an FDT
In reply to a message not in the archiveGiven a set of nodes and properties, find the regions of the device tree which describe those parts.
A test is provided which builds a tree while tracking where the regions should be, then calls fdt_find_regions() to make sure that it agrees.
Further tests will come as part of fdtgrep.
--- libfdt/fdt_wip.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++ libfdt/libfdt.h | 142 ++++++++++++++++++++++ tests/.gitignore | 1 + tests/Makefile.tests | 3 +- tests/region_tree.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 5 + 6 files changed, 785 insertions(+), 1 deletions(-) create mode 100644 tests/region_tree.c
libfdt/fdt_wip.c +311 -0
@@ -116,3 +116,314 @@ int fdt_nop_node(void *fdt, int nodeoffset) endoffset - nodeoffset);return 0 ; } + +/* Maximum depth that we can grep */ +#define FDT_MAX_DEPTH 32 + +/* Decribes what we want to include from the current tag */ +enum want_t { +WANT_NOTHING , +WANT_NODES_ONLY , +WANT_NODES_AND_PROPS , +}; + +/* Keeps track of the state at parent nodes */ +struct fdt_subnode_stack { +int offset;/* Offset of node */ +enum want_t want;/* The 'want' value here */ +int included;/* 1 if we included this node, 0 if not */ +}; + +/* The state of our finding algortihm */ +struct find_reg { +struct fdt_subnode_stack stack[FDT_MAX_DEPTH ];/* node stack */ +struct fdt_region *region;/* Contains list of regions found */ +int count;/* Numnber of regions found */ +const void *fdt;/* FDT blob */ +int max_regions;/* Maximum regions to find */ +int can_merge;/* 1 if we can merge with previous region */ +}; + +/** +* fdt_add_region() - Add a new region to our list +* +* The region is added if there is space, but in any case we increment the +* count. If permitted, and the new region overlaps the last one, we merge +* them. +* +* @info: State information +* @offset: Start offset of region +* @size: Size of region +*/ +static void fdt_add_region (struct find_reg *info,int offset,int size) +{ +struct fdt_region *reg = &info->region[info->count -1 ]; + +if (info->can_merge && info->count && + info->count < info->max_regions && + offset <= reg->offset + reg->size) { + reg->size = offset + size - reg->offset; + }else if (info->count < info->max_regions) { + reg++; + reg->offset = offset; + reg->size = size; + info->count++; + } +} + +/** +* fdt_include_supernodes() - Include supernodes required by this node +* +* When we decided to include a node or property which is not at the top +* level, this function forces the inclusion of higher level nodes. For +* example, given this tree: +* +* / { +* testing { +* } +* } +* +* If we decide to include testing then we need the root node to have a valid +* tree. This function adds those regions. +* +* @info: State information +* @depth: Current stack depth +*/ +static void fdt_include_supernodes (struct find_reg *info,int depth) +{ +int base =fdt_off_dt_struct (info->fdt); +int start, stop_at; +int i; + +/* +* Work down the stack looking for supernodes that we didn't include. +* The algortihm here is actually pretty simple, since we know that +* no previous subnode had to include these nodes, or if it did, we +* marked them as included (on the stack) already. +*/ +for (i =0 ; i <= depth; i++) { +if (!info->stack[i].included) { + start = info->stack[i].offset; + +/* Add the FDT_BEGIN_NODE tag of this supernode */ +fdt_next_tag (info->fdt, start, &stop_at); +fdt_add_region (info, base + start, stop_at - start); + +/* Remember that this supernode is now included */ + info->stack[i].included =1 ; + info->can_merge =1 ; + } + +/* Force (later) generation of the FDT_END_NODE tag */ +if (!info->stack[i].want) + info->stack[i].want =WANT_NODES_ONLY ; + } +} + +int fdt_find_regions (const void *fdt, +int (*h_include)(void *priv,int type,const char *data, +int size), +void *priv, +struct fdt_region region[],int max_regions, +char *path,int path_len,int flags) +{ +int base =fdt_off_dt_struct (fdt); +struct find_reg info; +int nextoffset; +int start =-1 ; +int depth =-1 ; +const char *str; +enum want_t want =WANT_NOTHING ; +uint32_t tag; +char *end; + +/* Set up our state */ + info.fdt = fdt; + info.can_merge =1 ; + info.count =0 ; + info.region = region; + info.max_regions = max_regions; + +/* Add the memory reserve map into its own region */ +if (flags &FDT_REG_ADD_MEM_RSVMAP ) { +fdt_add_region (&info,fdt_off_mem_rsvmap (fdt), +fdt_off_dt_struct (fdt) -fdt_off_mem_rsvmap (fdt)); + info.can_merge =0 ;/* Don't allow merging with this */ + } + + end = path; + *end ='\0' ; + nextoffset =0 ; + +/* +* Work through the tags one by one, deciding whether each needs to +* be included or not. We set the variable 'include' to indicate our +* decision. 'want' is used to track what we want to include - it +* allows us to pick up all the properties (and/or subnode tags) of +* a node. +*/ +do { +const struct fdt_property *prop; +const char *name; +int include =0 ; +int stop_at =0 ; +int offset; +int val; +int len; + +/* +* Find the tag, and the offset of the next one. If we need to +* stop including tags, then by default we stop *after* +* including the current tag +*/ + offset = nextoffset; + tag =fdt_next_tag (fdt, offset, &nextoffset); + stop_at = nextoffset; + +switch (tag) { +case FDT_PROP : + stop_at = offset; + prop =fdt_get_property_by_offset (fdt, offset,NULL ); + str =fdt_string (fdt,fdt32_to_cpu (prop->nameoff)); + val =h_include (priv,FDT_IS_PROP , str, +strlen (str) +1 ); +if (val ==-1 ) { + include = want ==WANT_NODES_AND_PROPS ; + }else { + include = val; +/* +* Make sure we include the } for this block. +* It might be more correct to put this done +* by the call to fdt_include_supernodes() in +* the case where it adds the node we are +* currently in, but this is fairly +* equivalent. +*/ +if ((flags &FDT_REG_SUPERNODES ) && val && + !want) + want =WANT_NODES_ONLY ; + } + +/* Value grepping is not yet supported */ +break ; + +case FDT_NOP : + include = want ==WANT_NODES_AND_PROPS ; + stop_at = offset; +break ; + +case FDT_BEGIN_NODE : + depth++; +if (depth ==FDT_MAX_DEPTH ) +return -FDT_ERR_BADSTRUCTURE ; + name =fdt_get_name (fdt, offset, &len); +if (end - path +2 + len >= path_len) +return -FDT_ERR_NOSPACE ; + +/* Build the full path of this node */ +if (end != path +1 ) + *end++ ='/' ; +strcpy (end, name); + end += len; + info.stack[depth].want = want; + info.stack[depth].offset = offset; + +/* +* If we are not intending to include this node, make +* sure we stop *before* its tag +*/ +if (want ==WANT_NODES_ONLY || + !(flags &FDT_REG_DIRECT_SUBNODES )) { + stop_at = offset; + want =WANT_NOTHING ; + } + val =h_include (priv,FDT_IS_NODE , path, + end - path +1 ); + +/* +* If no information about this, try the compatible +* property. Here we are looking ahead in the tree. +*/ +if (val ==-1 ) { + str =fdt_getprop (fdt, offset, +"compatible" , &len); + val =h_include (priv,FDT_IS_COMPAT , str, + len); + } + +/* Include this if requested */ +if (val) + want =WANT_NODES_AND_PROPS ; + +/* If not requested, decay our 'want' value */ +else if (want) + want--; + +/* Not including this tag, so stop now */ +else + stop_at = offset; + +/* +* Decide whether to include this tag, and update our +* stack with the state for this node +*/ + include = want; + info.stack[depth].included = include; +break ; + +case FDT_END_NODE : + include = want; +if (depth <0 ) +return -FDT_ERR_BADSTRUCTURE ; + +/* +* If we don't want this node, stop right away, unless +* we are including subnodes +*/ +if (!want && !(flags &FDT_REG_DIRECT_SUBNODES )) + stop_at = offset; + want = info.stack[depth].want; + depth--; +while (end > path && *--end !='/' ) + ; + *end ='\0' ; +break ; + +case FDT_END : +/* We always include the end tag */ + include =1 ; +break ; + } + +/* If this tag is to be included, mark it as region start */ +if (include && start ==-1 ) { +/* Include any supernodes required by this one */ +if (flags &FDT_REG_SUPERNODES ) +fdt_include_supernodes (&info, depth); + start = offset; + } + +/* +* If this tag is not to be included, finish up the current +* region +*/ +if (!include && start !=-1 ) { +fdt_add_region (&info, base + start, stop_at - start); + start =-1 ; + info.can_merge =1 ; + } + }while (tag !=FDT_END ); + +if (nextoffset !=fdt_size_dt_struct (fdt)) +return -FDT_ERR_BADLAYOUT ; + +/* Add a region for the END tag and a separate one for string table */ +fdt_add_region (&info, base + start, nextoffset - start); +if (flags &FDT_REG_ADD_STRING_TAB ) { + info.can_merge =0 ; +fdt_add_region (&info,fdt_off_dt_strings (fdt), +fdt_size_dt_strings (fdt)); + } + +return info.count; +}
libfdt/libfdt.h +142 -0
146 lines not on this page · raw message
tests/.gitignore +1 -0
@@ -41,6 +41,7 @@ tmp.* /phandle_format /propname_escapes /references +/region_tree /root_node /rw_tree1 /set_name
tests/Makefile.tests +2 -1
@@ -20,7 +20,8 @@ LIB_TESTS_L = get_mem_rsv \ dtb_reverse dtbs_equal_unordered \ add_subnode_with_nops path_offset_aliases \ utilfdt_test \ - integer-expressions + integer-expressions \ + region_tree LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) LIBTREE_TESTS_L = truncated_property
tests/region_tree.c new file +324 -0
324 lines not on this page · raw message
tests/run_tests.sh +5 -0
@@ -246,6 +246,11 @@ libfdt_tests () { # Specific bug tests run_test add_subnode_with_nops + + # Tests for fdt_find_regions() + for flags in 0 1 2 3 4 5 6 7; do + run_test region_tree ${flags} + done } dtc_tests () {
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-6-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
Re: [PATCH 5/8] libfdt: Add function to find regions in an FDT
Quoted 7 lines · Simon Glass
Given a set of nodes and properties, find the regions of the device tree which describe those parts.
A test is provided which builds a tree while tracking where the regions should be, then calls
fdt_find_regions()to make sure that it agrees.Further tests will come as part of fdtgrep.
Ok, for starters I don't want to include this before the next dtc release. It's a pretty substantial addition.
Second, fdt_wip is definitely the wrong place for this. fdt_wip.c is for the Write-In-Place code (i.e. functions which alter the tree contents, but don't need to move any existing data around). AFAICT this function only reads the tree, which would put it in fdt_ro.c. However, it's such a big addition - and adds several new state structures, I think it should go in an entirely new source file for it. That way people who don't use this piece of the library won't get it included, even if they don't have a compiler which does function sections.
Third, I'm having a bit of trouble wrapping my head around exactly what the search function does, and how the various flags and pieces interact. A block comment with a general overview would be nice.
More specific comments below:
Quoted 26 lines
Signed-off-by Simon Glass <[email protected]>--- libfdt/fdt_wip.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++ libfdt/libfdt.h | 142 ++++++++++++++++++++++ tests/.gitignore | 1 + tests/Makefile.tests | 3 +- tests/region_tree.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 5 + 6 files changed, 785 insertions(+), 1 deletions(-) create mode 100644 tests/region_tree.clibfdt/fdt_wip.c +6
-0@@ -116,3 +116,314 @@ int fdt_nop_node(void *fdt, int nodeoffset) endoffset - nodeoffset);return 0 ; } + +/* Maximum depth that we can grep */ +#define FDT_MAX_DEPTH 32 + +/* Decribes what we want to include from the current tag */ +enum want_t {
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 134
Quoted 10 lines
libfdt/fdt_wip.c +10
-0+WANT_NOTHING , +WANT_NODES_ONLY , + WANT_NODES_AND_PROPS, +}; + +/* Keeps track of the state at parent nodes */ +struct fdt_subnode_stack { +int offset;/* Offset of node */ +enum want_t want;/* The 'want' value here */ +int included;/* 1 if we included this node, 0 if not */
What's the distinction between 'included' and 'want' and how do they interact?
Quoted 19 lines
libfdt/fdt_wip.c +19
-0+}; + +/* The state of our finding algortihm */ +struct find_reg { +struct fdt_subnode_stack stack[FDT_MAX_DEPTH ];/* node stack */ +struct fdt_region *region;/* Contains list of regions found */ +int count;/* Numnber of regions found */ +const void *fdt;/* FDT blob */ +int max_regions;/* Maximum regions to find */ +int can_merge;/* 1 if we can merge with previous region */ +}; + +/** +* fdt_add_region() - Add a new region to our list +* +* The region is added if there is space, but in any case we increment the +* count. If permitted, and the new region overlaps the last one, we merge +* them. +*
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 163
Quoted 10 lines
libfdt/fdt_wip.c +10
-0+* @info: State information +* @offset: Start offset of region +* @size: Size of region +*/ +static void fdt_add_region (struct find_reg *info,int offset,int size) +{ +struct fdt_region *reg = &info->region[info->count -1 ]; + + if (info->can_merge && info->count && + info->count < info->max_regions &&
Shouldn't this be <= for the merge case?
Quoted 55 lines
libfdt/fdt_wip.c +55
-0+ offset <= reg->offset + reg->size) { + reg->size = offset + size - reg->offset; + } else if (info->count < info->max_regions) { + reg++; + reg->offset = offset; + reg->size = size; + info->count++; + } +} + +/** +* fdt_include_supernodes() - Include supernodes required by this node +* +* When we decided to include a node or property which is not at the top +* level, this function forces the inclusion of higher level nodes. For +* example, given this tree: +* +* / { +* testing { +* } +* } +* +* If we decide to include testing then we need the root node to have a valid +* tree. This function adds those regions. +* +* @info: State information +* @depth: Current stack depth +*/ +static void fdt_include_supernodes (struct find_reg *info,int depth) +{ +int base =fdt_off_dt_struct (info->fdt); +int start, stop_at; +int i; + +/* +* Work down the stack looking for supernodes that we didn't include. +* The algortihm here is actually pretty simple, since we know that +* no previous subnode had to include these nodes, or if it did, we +* marked them as included (on the stack) already. +*/ +for (i =0 ; i <= depth; i++) { +if (!info->stack[i].included) { + start = info->stack[i].offset; + +/* Add the FDT_BEGIN_NODE tag of this supernode */ +fdt_next_tag (info->fdt, start, &stop_at); +fdt_add_region (info, base + start, stop_at - start); + +/* Remember that this supernode is now included */ + info->stack[i].included =1 ; + info->can_merge =1 ; + } + +/* Force (later) generation of the FDT_END_NODE tag */ +if (!info->stack[i].want)
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 228
Quoted 10 lines
libfdt/fdt_wip.c +10
-0+ info->stack[i].want =WANT_NODES_ONLY ; + } +} + +int fdt_find_regions (const void *fdt, +int (*h_include)(void *priv,int type,const char *data, +int size), +void *priv, +struct fdt_region region[],int max_regions, +char *path,int path_len,int flags)
So, in general I've tried to avoid having the libfdt interfaces require the caller to buffer significant amounts of information. So, if it's possible (and I don't immediately see a reason for it not to be) I'd prefer to see first_region()/next_region() type functions, rather than requiring the callers to gather the whole region list at once.
Quoted 80 lines
libfdt/fdt_wip.c +80
-0+{ +int base =fdt_off_dt_struct (fdt); +struct find_reg info; +int nextoffset; +int start =-1 ; +int depth =-1 ; +const char *str; +enum want_t want =WANT_NOTHING ; +uint32_t tag; +char *end; + +/* Set up our state */ + info.fdt = fdt; + info.can_merge =1 ; + info.count =0 ; + info.region = region; + info.max_regions = max_regions; + +/* Add the memory reserve map into its own region */ +if (flags &FDT_REG_ADD_MEM_RSVMAP ) { +fdt_add_region (&info,fdt_off_mem_rsvmap (fdt), +fdt_off_dt_struct (fdt) -fdt_off_mem_rsvmap (fdt)); + info.can_merge =0 ;/* Don't allow merging with this */ + } + + end = path; + *end ='\0' ; + nextoffset =0 ; + +/* +* Work through the tags one by one, deciding whether each needs to +* be included or not. We set the variable 'include' to indicate our +* decision. 'want' is used to track what we want to include - it +* allows us to pick up all the properties (and/or subnode tags) of +* a node. +*/ + do { + const struct fdt_property *prop; + const char *name; + int include = 0; + int stop_at = 0; + int offset; + int val; + int len; + + /* + * Find the tag, and the offset of the next one. If we need to + * stop including tags, then by default we stop *after* + * including the current tag + */ + offset = nextoffset; + tag = fdt_next_tag(fdt, offset, &nextoffset); + stop_at = nextoffset; + + switch (tag) { + case FDT_PROP: + stop_at = offset; + prop = fdt_get_property_by_offset(fdt, offset, NULL); + str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); + val = h_include(priv, FDT_IS_PROP, str, + strlen(str) + 1); + if (val == -1) { + include = want == WANT_NODES_AND_PROPS; + } else { + include = val; + /* + * Make sure we include the } for this block. + * It might be more correct to put this done + * by the call to fdt_include_supernodes() in + * the case where it adds the node we are + * currently in, but this is fairly + * equivalent. + */ + if ((flags & FDT_REG_SUPERNODES) && val && + !want) + want = WANT_NODES_ONLY; + } + + /* Value grepping is not yet supported */ + break;
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 318
Quoted 10 lines
libfdt/fdt_wip.c +10
-0+ +case FDT_NOP : + include = want ==WANT_NODES_AND_PROPS ; + stop_at = offset; +break ; + +case FDT_BEGIN_NODE : + depth++; +if (depth ==FDT_MAX_DEPTH ) +return -FDT_ERR_BADSTRUCTURE ;
Hrm. Perhaps we should add a new error code for "too deep". After all the structure of the tree is perfectly fine here, it's just this search function can't cope with its depth.
Quoted 90 lines
libfdt/fdt_wip.c +90
-0+ name =fdt_get_name (fdt, offset, &len); +if (end - path +2 + len >= path_len) +return -FDT_ERR_NOSPACE ; + +/* Build the full path of this node */ +if (end != path +1 ) + *end++ ='/' ; +strcpy (end, name); + end += len; + info.stack[depth].want = want; + info.stack[depth].offset = offset; + +/* +* If we are not intending to include this node, make +* sure we stop *before* its tag +*/ +if (want ==WANT_NODES_ONLY || + !(flags &FDT_REG_DIRECT_SUBNODES )) { + stop_at = offset; + want =WANT_NOTHING ; + } + val =h_include (priv,FDT_IS_NODE , path, + end - path +1 ); + +/* +* If no information about this, try the compatible +* property. Here we are looking ahead in the tree. +*/ +if (val ==-1 ) { + str =fdt_getprop (fdt, offset, +"compatible" , &len); + val =h_include (priv,FDT_IS_COMPAT , str, + len); + } + +/* Include this if requested */ +if (val) + want =WANT_NODES_AND_PROPS ; + +/* If not requested, decay our 'want' value */ +else if (want) + want--; + +/* Not including this tag, so stop now */ +else + stop_at = offset; + +/* +* Decide whether to include this tag, and update our +* stack with the state for this node +*/ + include = want; + info.stack[depth].included = include; +break ; + +case FDT_END_NODE : + include = want; +if (depth <0 ) +return -FDT_ERR_BADSTRUCTURE ; + +/* +* If we don't want this node, stop right away, unless +* we are including subnodes +*/ +if (!want && !(flags &FDT_REG_DIRECT_SUBNODES )) + stop_at = offset; + want = info.stack[depth].want; + depth--; +while (end > path && *--end !='/' ) + ; + *end ='\0' ; +break ; + +case FDT_END : +/* We always include the end tag */ + include =1 ; +break ; + } + +/* If this tag is to be included, mark it as region start */ +if (include && start ==-1 ) { +/* Include any supernodes required by this one */ +if (flags &FDT_REG_SUPERNODES ) +fdt_include_supernodes (&info, depth); + start = offset; + } + +/* +* If this tag is not to be included, finish up the current +* region
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 418
Quoted 10 lines
libfdt/fdt_wip.c +10
-0+*/ +if (!include && start !=-1 ) { +fdt_add_region (&info, base + start, stop_at - start); + start =-1 ; + info.can_merge =1 ; + } + }while (tag !=FDT_END ); + +if (nextoffset !=fdt_size_dt_struct (fdt)) +return -FDT_ERR_BADLAYOUT ;
That should be BADSTRUCTURE, not BADLAYOUT. BADLAYOUT means structure/strings/memreserve blocks are not in the preferred order w.r.t. each other.
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 426
Quoted 8 lines
libfdt/fdt_wip.c +8
-0+ +/* Add a region for the END tag and a separate one for string table */ +fdt_add_region (&info, base + start, nextoffset - start); +if (flags &FDT_REG_ADD_STRING_TAB ) { + info.can_merge =0 ; +fdt_add_region (&info,fdt_off_dt_strings (fdt), +fdt_size_dt_strings (fdt)); + }
You may want to give BADLAYOUT here, though, if the strings block is before the structure block.
Quoted 56 lines
libfdt/fdt_wip.c +3
-0+ +return info.count; +}libfdt/libfdt.h +45
-0@@ -1489,4 +1489,146 @@ int fdt_del_node(void *fdt, int nodeoffset);const char *fdt_strerror (int errval); +struct fdt_region { +int offset; +int size; +}; + +/* +* Flags for fdt_find_regions() +* +* Add a region for the string table (always the last region) +*/ +#define FDT_REG_ADD_STRING_TAB (1 << 0) + +/* Add the FDT_BEGIN_NODE tags of subnodes, including their names */ +#define FDT_REG_DIRECT_SUBNODES (1 << 1) + +/* +* Add all supernodes of a matching node/property, useful for creating a +* valid subset tree +*/ +#define FDT_REG_SUPERNODES (1 << 2) + +/* Add a region for the mem_rsvmap table (always the first region) */ +#define FDT_REG_ADD_MEM_RSVMAP (1 << 3) + +/* Indicates what an fdt part is (node, property, value, compatible) */ +#define FDT_IS_NODE (1 << 0) +#define FDT_IS_PROP (1 << 1) +#define FDT_IS_VALUE (1 << 2)/* not supported */ +#define FDT_IS_COMPAT (1 << 3) + +#define FDT_IS_ANY 15 + +/** +* fdt_find_regions() - find regions in device tree +* +* Given a nodes and properties to include and properties to exclude, find +* the regions of the device tree which describe those included parts. +* +* The use for this function is twofold. Firstly it provides a convenient +* way of performing a structure-aware grep of the tree. For example it is +* possible to grep for a node and get all the properties associated with +* that node. Trees can be subsetted easily, by specifying the nodes that +* are required, and then writing out the regions returned by this function. +* This is useful for small resource-constrained systems, such as boot +* loaders, which want to use an FDT but do not need to know about all of
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1546
Quoted 10 lines
libfdt/libfdt.h +10
-0+* it. +* +* Secondly it makes it easy to hash parts of the tree and detect changes. +* The intent is to get a list of regions which will be invariant provided +* those parts are invariant. For example, if you request a list of regions +* for all nodes but exclude the property "data", then you will get the +* same region contents regardless of any change to "data" properties. +* +* This function can be used to produce a byte-stream to send to a hashing +* function to verify that critical parts of the FDT have not changed.
Note that semantically null changes in order could still cause false hash misses even with this subsetting.
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1554
Quoted 7 lines
libfdt/libfdt.h +7
-0+* The nodes/properties to include/exclude are defined by a function +* provided by the caller. This function is called for each node and +* property, and must return: +* +* 0 - to exclude this part +* 1 - to include this part +* -1 - if no information is available
You don't describe what this function does when told "no information is available". Really the option seems a bit pointless to me, why not just leave the include by default or exclude by default decision to the include function.
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1561
Quoted 7 lines
libfdt/libfdt.h +7
-0+* +* For nodes, the function may be called twice, once with FDT_IS_NODE to check +* the node name. If this returns -1 then the function is immediately called +* again with FDT_IS_COMPAT to check the compatible string. Note that if +* there is no compatible string, then data == NULL and size == 0. This means +* that the inclusion of a node can be controlled either by a node name or +* its compatible string.
This seems awkward to me. Why not supply the fdt pointer and node offset when calling the inclusion function for a node and have h_include get whatever properties it needs to make that decision.
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1564
Quoted 3 lines
libfdt/libfdt.h +3
-0+* +* There is no special handling of unit addresses, so the entire name must +* be given for nodes. Wildcards are not supported.
Given where? The only names given in the interface are in the tree itself. Wildcards could be supported by the h_include function AFAICT.
Quoted 69 lines
libfdt/libfdt.h +68
-0+* As an example, including node "/" means to include the root node and all +* root properties. A flag provides a way of also including supernodes (of +* which there is none for the root node), and another flag includes +* immediate subnodes, so in this case we would get the FDT_BEGIN_NODE and +* FDT_END_NODE of all subnodes of /. +* +* The subnode feature helps in a hashing situation since it prevents the +* root node from changing at all. Any change to non-excluded properties, +* names of subnodes or number of subnodes would be detected. +* +* When used with FITs this provides the ability to hash and sign parts of +* the FIT based on different configurations in the FIT. Then it is +* impossible to change anything about that configuration (include images +* attached to the configuration), but it may be possible to add new +* configurations, new images or new signatures within the existing +* framework. +* +* Adding new properties to a device tree may result in the string table +* being extended (if the new property names are different from those +* already added). This function can optionally include a region for +* the string table so that this can be part of the hash too. This is always +* the last region. +* +* The FDT also has a mem_rsvmap table which can also be included, and is +* always the first region if so. +* +* The device tree header is not included in the region list. Since the +* contents of the FDT are changing (shrinking, often), the caller will need +* to regenerate the header anyway. +* +* @fdt: Device tree to check +* @h_include: Function to call to determine whether to include a part or +* not: +* +* @priv: Private pointer as passed to fdt_find_regions() +* @type: Type of this part, FDT_IS_... +* @data: Pointer to data (node name, property name, compatible +* string, value (not yet supported) +* @size: Size of data, or 0 if none +* @return 0 to exclude, 1 to include, -1 if no information is +* available +* @priv: Private pointer passed to h_include +* @region: Returns list of regions, sorted by offset +* @max_regions: Maximum length of region list +* @path: Pointer to a temporary string for the function to use for +* building path names +* @path_len: Length of path, must be large enough to hold the longest +* path in the tree +* @flags: Various flags that control the region algortihm, see +* FDT_REG_... +* @return number of regions in list. If this is >max_regions then the +* region array was exhausted. You should increase max_regions and try +* the call again. Only the first max_regions elements are available in the +* array. +* +* On error a -ve value is return, which can be: +* +* -FDT_ERR_BADSTRUCTURE (too deep or more END tags than BEGIN tags +* -FDT_ERR_BADLAYOUT +* -FDT_ERR_NOSPACE (path area is too small) +*/ +int fdt_find_regions (const void *fdt, +int (*h_include)(void *priv,int type,const char *data, +int size), +void *priv, +struct fdt_region region[],int max_regions, +char *path,int path_len,int flags); +#endif /* _LIBFDT_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
A message that is not in the archive (sent off-list or not yet received): 20130211024736.GG4948-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org
Re: [PATCH 5/8] libfdt: Add function to find regions in an FDT
Hi David,
Quoted 12 lines · David Gibson
Quoted 7 lines · Simon Glass
Given a set of nodes and properties, find the regions of the device tree which describe those parts.
A test is provided which builds a tree while tracking where the regions should be, then calls
fdt_find_regions()to make sure that it agrees.Further tests will come as part of fdtgrep.
Ok, for starters I don't want to include this before the next dtc release. It's a pretty substantial addition.
Quoted 9 lines
Second,
fdt_wipis definitely the wrong place for this.fdt_wip.cis for the Write-In-Place code (i.e. functions which alter the tree contents, but don't need to move any existing data around). AFAICT this function only reads the tree, which would put it infdt_ro.c. However, it's such a big addition - and adds several new state structures, I think it should go in an entirely new source file for it. That way people who don't use this piece of the library won't get it included, even if they don't have a compiler which does function sections.
OK I misunderstood the name of that file - I will add a new file.
Quoted 38 lines
Third, I'm having a bit of trouble wrapping my head around exactly what the search function does, and how the various flags and pieces interact. A block comment with a general overview would be nice.
More specific comments below:
Quoted 31 lines
Signed-off-by Simon Glass <[email protected]>--- libfdt/fdt_wip.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++ libfdt/libfdt.h | 142 ++++++++++++++++++++++ tests/.gitignore | 1 + tests/Makefile.tests | 3 +- tests/region_tree.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 5 + 6 files changed, 785 insertions(+), 1 deletions(-) create mode 100644 tests/region_tree.clibfdt/fdt_wip.c +11
-0@@ -116,3 +116,314 @@ int fdt_nop_node(void *fdt, int nodeoffset) endoffset - nodeoffset);return 0 ; } + +/* Maximum depth that we can grep */ +#define FDT_MAX_DEPTH 32 + +/* Decribes what we want to include from the current tag */ +enum want_t { +WANT_NOTHING , +WANT_NODES_ONLY , +WANT_NODES_AND_PROPS , +}; +
Quoted 8 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 134
Quoted 5 lines
libfdt/fdt_wip.c +5
-0+/* Keeps track of the state at parent nodes */ +struct fdt_subnode_stack { +int offset;/* Offset of node */ +enum want_t want;/* The 'want' value here */ +int included;/* 1 if we included this node, 0 if not */ What's the distinction between 'included' and 'want' and how do they interact?
I will add a big comment for that.
Quoted 24 lines
Quoted 24 lines
libfdt/fdt_wip.c +23
-0+}; + +/* The state of our finding algortihm */ +struct find_reg { +struct fdt_subnode_stack stack[FDT_MAX_DEPTH ];/* node stack */ +struct fdt_region *region;/* Contains list of regions found */ +int count;/* Numnber of regions found */ +const void *fdt;/* FDT blob */ +int max_regions;/* Maximum regions to find */ +int can_merge;/* 1 if we can merge with previous region */ +}; + +/** +* fdt_add_region() - Add a new region to our list +* +* The region is added if there is space, but in any case we increment the +* count. If permitted, and the new region overlaps the last one, we merge +* them. +* +* @info: State information +* @offset: Start offset of region +* @size: Size of region +*/
Quoted 8 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 163
Quoted 6 lines
libfdt/fdt_wip.c +6
-0+static void fdt_add_region (struct find_reg *info,int offset,int size) +{ +struct fdt_region *reg = &info->region[info->count -1 ]; + + if (info->can_merge && info->count && + info->count < info->max_regions &&Shouldn't this be <= for the merge case?
Yes, thanks.
Quoted 65 lines
Quoted 65 lines
libfdt/fdt_wip.c +64
-0+ offset <= reg->offset + reg->size) { + reg->size = offset + size - reg->offset; + } else if (info->count < info->max_regions) { + reg++; + reg->offset = offset; + reg->size = size; + info->count++; + } +} + +/** +* fdt_include_supernodes() - Include supernodes required by this node +* +* When we decided to include a node or property which is not at the top +* level, this function forces the inclusion of higher level nodes. For +* example, given this tree: +* +* / { +* testing { +* } +* } +* +* If we decide to include testing then we need the root node to have a valid +* tree. This function adds those regions. +* +* @info: State information +* @depth: Current stack depth +*/ +static void fdt_include_supernodes (struct find_reg *info,int depth) +{ +int base =fdt_off_dt_struct (info->fdt); +int start, stop_at; +int i; + +/* +* Work down the stack looking for supernodes that we didn't include. +* The algortihm here is actually pretty simple, since we know that +* no previous subnode had to include these nodes, or if it did, we +* marked them as included (on the stack) already. +*/ +for (i =0 ; i <= depth; i++) { +if (!info->stack[i].included) { + start = info->stack[i].offset; + +/* Add the FDT_BEGIN_NODE tag of this supernode */ +fdt_next_tag (info->fdt, start, &stop_at); +fdt_add_region (info, base + start, stop_at - start); + +/* Remember that this supernode is now included */ + info->stack[i].included =1 ; + info->can_merge =1 ; + } + +/* Force (later) generation of the FDT_END_NODE tag */ +if (!info->stack[i].want) + info->stack[i].want =WANT_NODES_ONLY ; + } +} + +int fdt_find_regions(const void *fdt, + int (*h_include)(void *priv, int type, const char *data, + int size), + void *priv, + struct fdt_region region[], int max_regions,
Quoted 8 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 228
Quoted 1 line
libfdt/fdt_wip.c +1
-0+ char *path, int path_len, int flags)So, in general I've tried to avoid having the libfdt interfaces require the caller to buffer significant amounts of information. So, if it's possible (and I don't immediately see a reason for it not to be) I'd prefer to see first_region()/next_region() type functions, rather than requiring the callers to gather the whole region list at once.
OK I have had a crack at this, although it took several hours and I'm not entirely pleased with the state that I need to keep around. I will send a patch and you can see what you think. It can be improved a little I think, but mainly I would like to avoid adding lots of stuff to libfdt.h.
Quoted 87 lines
Quoted 87 lines
libfdt/fdt_wip.c +86
-0+{ +int base =fdt_off_dt_struct (fdt); +struct find_reg info; +int nextoffset; +int start =-1 ; +int depth =-1 ; +const char *str; +enum want_t want =WANT_NOTHING ; +uint32_t tag; +char *end; + +/* Set up our state */ + info.fdt = fdt; + info.can_merge =1 ; + info.count =0 ; + info.region = region; + info.max_regions = max_regions; + +/* Add the memory reserve map into its own region */ +if (flags &FDT_REG_ADD_MEM_RSVMAP ) { +fdt_add_region (&info,fdt_off_mem_rsvmap (fdt), +fdt_off_dt_struct (fdt) -fdt_off_mem_rsvmap (fdt)); + info.can_merge =0 ;/* Don't allow merging with this */ + } + + end = path; + *end ='\0' ; + nextoffset =0 ; + +/* +* Work through the tags one by one, deciding whether each needs to +* be included or not. We set the variable 'include' to indicate our +* decision. 'want' is used to track what we want to include - it +* allows us to pick up all the properties (and/or subnode tags) of +* a node. +*/ + do { + const struct fdt_property *prop; + const char *name; + int include = 0; + int stop_at = 0; + int offset; + int val; + int len; + + /* + * Find the tag, and the offset of the next one. If we need to + * stop including tags, then by default we stop *after* + * including the current tag + */ + offset = nextoffset; + tag = fdt_next_tag(fdt, offset, &nextoffset); + stop_at = nextoffset; + + switch (tag) { + case FDT_PROP: + stop_at = offset; + prop = fdt_get_property_by_offset(fdt, offset, NULL); + str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); + val = h_include(priv, FDT_IS_PROP, str, + strlen(str) + 1); + if (val == -1) { + include = want == WANT_NODES_AND_PROPS; + } else { + include = val; + /* + * Make sure we include the } for this block. + * It might be more correct to put this done + * by the call to fdt_include_supernodes() in + * the case where it adds the node we are + * currently in, but this is fairly + * equivalent. + */ + if ((flags & FDT_REG_SUPERNODES) && val && + !want) + want = WANT_NODES_ONLY; + } + + /* Value grepping is not yet supported */ + break; + + case FDT_NOP: + include = want == WANT_NODES_AND_PROPS; + stop_at = offset; + break; +
Quoted 8 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 318
Quoted 4 lines
libfdt/fdt_wip.c +4
-0+case FDT_BEGIN_NODE : + depth++; +if (depth ==FDT_MAX_DEPTH ) +return -FDT_ERR_BADSTRUCTURE ;Hrm. Perhaps we should add a new error code for "too deep". After all the structure of the tree is perfectly fine here, it's just this search function can't cope with its depth.
Done
Quoted 97 lines
Quoted 97 lines
libfdt/fdt_wip.c +96
-0+ name =fdt_get_name (fdt, offset, &len); +if (end - path +2 + len >= path_len) +return -FDT_ERR_NOSPACE ; + +/* Build the full path of this node */ +if (end != path +1 ) + *end++ ='/' ; +strcpy (end, name); + end += len; + info.stack[depth].want = want; + info.stack[depth].offset = offset; + +/* +* If we are not intending to include this node, make +* sure we stop *before* its tag +*/ +if (want ==WANT_NODES_ONLY || + !(flags &FDT_REG_DIRECT_SUBNODES )) { + stop_at = offset; + want =WANT_NOTHING ; + } + val =h_include (priv,FDT_IS_NODE , path, + end - path +1 ); + +/* +* If no information about this, try the compatible +* property. Here we are looking ahead in the tree. +*/ +if (val ==-1 ) { + str =fdt_getprop (fdt, offset, +"compatible" , &len); + val =h_include (priv,FDT_IS_COMPAT , str, + len); + } + +/* Include this if requested */ +if (val) + want =WANT_NODES_AND_PROPS ; + +/* If not requested, decay our 'want' value */ +else if (want) + want--; + +/* Not including this tag, so stop now */ +else + stop_at = offset; + +/* +* Decide whether to include this tag, and update our +* stack with the state for this node +*/ + include = want; + info.stack[depth].included = include; +break ; + +case FDT_END_NODE : + include = want; +if (depth <0 ) +return -FDT_ERR_BADSTRUCTURE ; + +/* +* If we don't want this node, stop right away, unless +* we are including subnodes +*/ +if (!want && !(flags &FDT_REG_DIRECT_SUBNODES )) + stop_at = offset; + want = info.stack[depth].want; + depth--; +while (end > path && *--end !='/' ) + ; + *end ='\0' ; +break ; + +case FDT_END : +/* We always include the end tag */ + include =1 ; +break ; + } + +/* If this tag is to be included, mark it as region start */ +if (include && start ==-1 ) { +/* Include any supernodes required by this one */ +if (flags &FDT_REG_SUPERNODES ) +fdt_include_supernodes (&info, depth); + start = offset; + } + +/* +* If this tag is not to be included, finish up the current +* region +*/ +if (!include && start !=-1 ) { +fdt_add_region (&info, base + start, stop_at - start); + start =-1 ; + info.can_merge =1 ; + }
Quoted 8 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 418
Quoted 4 lines
libfdt/fdt_wip.c +4
-0+ }while (tag !=FDT_END ); + +if (nextoffset !=fdt_size_dt_struct (fdt)) +return -FDT_ERR_BADLAYOUT ;That should be BADSTRUCTURE, not BADLAYOUT. BADLAYOUT means structure/strings/memreserve blocks are not in the preferred order w.r.t. each other.
OK, done
Quoted 10 lines
libfdt/fdt_wip.c int fdt_nop_node(void *fdt, int nodeoffset) · line 426
Quoted 9 lines
libfdt/fdt_wip.c +8
-0+ +/* Add a region for the END tag and a separate one for string table */ +fdt_add_region (&info, base + start, nextoffset - start); +if (flags &FDT_REG_ADD_STRING_TAB ) { + info.can_merge =0 ; +fdt_add_region (&info,fdt_off_dt_strings (fdt), +fdt_size_dt_strings (fdt)); + }
Quoted 2 lines
You may want to give BADLAYOUT here, though, if the strings block is before the structure block.
OK, will add this.
Quoted 62 lines
Quoted 62 lines
libfdt/fdt_wip.c +3
-0+ +return info.count; +}libfdt/libfdt.h +50
-0@@ -1489,4 +1489,146 @@ int fdt_del_node(void *fdt, int nodeoffset);const char *fdt_strerror (int errval); +struct fdt_region { +int offset; +int size; +}; + +/* +* Flags for fdt_find_regions() +* +* Add a region for the string table (always the last region) +*/ +#define FDT_REG_ADD_STRING_TAB (1 << 0) + +/* Add the FDT_BEGIN_NODE tags of subnodes, including their names */ +#define FDT_REG_DIRECT_SUBNODES (1 << 1) + +/* +* Add all supernodes of a matching node/property, useful for creating a +* valid subset tree +*/ +#define FDT_REG_SUPERNODES (1 << 2) + +/* Add a region for the mem_rsvmap table (always the first region) */ +#define FDT_REG_ADD_MEM_RSVMAP (1 << 3) + +/* Indicates what an fdt part is (node, property, value, compatible) */ +#define FDT_IS_NODE (1 << 0) +#define FDT_IS_PROP (1 << 1) +#define FDT_IS_VALUE (1 << 2)/* not supported */ +#define FDT_IS_COMPAT (1 << 3) + +#define FDT_IS_ANY 15 + +/** +* fdt_find_regions() - find regions in device tree +* +* Given a nodes and properties to include and properties to exclude, find +* the regions of the device tree which describe those included parts. +* +* The use for this function is twofold. Firstly it provides a convenient +* way of performing a structure-aware grep of the tree. For example it is +* possible to grep for a node and get all the properties associated with +* that node. Trees can be subsetted easily, by specifying the nodes that +* are required, and then writing out the regions returned by this function. +* This is useful for small resource-constrained systems, such as boot +* loaders, which want to use an FDT but do not need to know about all of +* it. +* +* Secondly it makes it easy to hash parts of the tree and detect changes. +* The intent is to get a list of regions which will be invariant provided +* those parts are invariant. For example, if you request a list of regions
Quoted 8 lines
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1546
Quoted 5 lines
libfdt/libfdt.h +5
-0+* for all nodes but exclude the property "data", then you will get the +* same region contents regardless of any change to "data" properties. +* +* This function can be used to produce a byte-stream to send to a hashing +* function to verify that critical parts of the FDT have not changed. Note that semantically null changes in order could still cause false hash misses even with this subsetting.
I will add this comment.
Quoted 9 lines
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1554
Quoted 8 lines
libfdt/libfdt.h +7
-0+* The nodes/properties to include/exclude are defined by a function +* provided by the caller. This function is called for each node and +* property, and must return: +* +* 0 - to exclude this part +* 1 - to include this part +* -1 - if no information is available
Quoted 4 lines
You don't describe what this function does when told "no information is available". Really the option seems a bit pointless to me, why not just leave the include by default or exclude by default decision to the include function.
This is partly used to deal with the conflict between node name and node compatible string which you picked up on later. But it is also used to deal with properties. I will add a more detailed comment.
Quoted 9 lines
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1561
Quoted 8 lines
libfdt/libfdt.h +7
-0+* +* For nodes, the function may be called twice, once with FDT_IS_NODE to check +* the node name. If this returns -1 then the function is immediately called +* again with FDT_IS_COMPAT to check the compatible string. Note that if +* there is no compatible string, then data == NULL and size == 0. This means +* that the inclusion of a node can be controlled either by a node name or +* its compatible string.
Quoted 3 lines
This seems awkward to me. Why not supply the fdt pointer and node offset when calling the inclusion function for a node and have
h_includeget whatever properties it needs to make that decision.
Yes it is awkward, and I have been thinking of how to tidy this up. I think I will just go with what you suggest since the cost of trying to make things simple for the caller (in terms of allowing a simple strcmp() there for example) is much higher than the benefit.
Quoted 7 lines
libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1564
Quoted 4 lines
libfdt/libfdt.h +3
-0+* +* There is no special handling of unit addresses, so the entire name must +* be given for nodes. Wildcards are not supported. Given where? The only names given in the interface are in the tree itself. Wildcards could be supported by the
h_includefunction AFAICT.
This comment refers to an earlier interface that I originally tried (passing node names to the function). I dropped it because it was inflexible. I will drop this comment.
Quoted 72 lines
Quoted 60 lines
libfdt/libfdt.h +59
-0+* As an example, including node "/" means to include the root node and all +* root properties. A flag provides a way of also including supernodes (of +* which there is none for the root node), and another flag includes +* immediate subnodes, so in this case we would get the FDT_BEGIN_NODE and +* FDT_END_NODE of all subnodes of /. +* +* The subnode feature helps in a hashing situation since it prevents the +* root node from changing at all. Any change to non-excluded properties, +* names of subnodes or number of subnodes would be detected. +* +* When used with FITs this provides the ability to hash and sign parts of +* the FIT based on different configurations in the FIT. Then it is +* impossible to change anything about that configuration (include images +* attached to the configuration), but it may be possible to add new +* configurations, new images or new signatures within the existing +* framework. +* +* Adding new properties to a device tree may result in the string table +* being extended (if the new property names are different from those +* already added). This function can optionally include a region for +* the string table so that this can be part of the hash too. This is always +* the last region. +* +* The FDT also has a mem_rsvmap table which can also be included, and is +* always the first region if so. +* +* The device tree header is not included in the region list. Since the +* contents of the FDT are changing (shrinking, often), the caller will need +* to regenerate the header anyway. +* +* @fdt: Device tree to check +* @h_include: Function to call to determine whether to include a part or +* not: +* +* @priv: Private pointer as passed to fdt_find_regions() +* @type: Type of this part, FDT_IS_... +* @data: Pointer to data (node name, property name, compatible +* string, value (not yet supported) +* @size: Size of data, or 0 if none +* @return 0 to exclude, 1 to include, -1 if no information is +* available +* @priv: Private pointer passed to h_include +* @region: Returns list of regions, sorted by offset +* @max_regions: Maximum length of region list +* @path: Pointer to a temporary string for the function to use for +* building path names +* @path_len: Length of path, must be large enough to hold the longest +* path in the tree +* @flags: Various flags that control the region algortihm, see +* FDT_REG_... +* @return number of regions in list. If this is >max_regions then the +* region array was exhausted. You should increase max_regions and try +* the call again. Only the first max_regions elements are available in the +* array. +* +* On error a -ve value is return, which can be: +* +* -FDT_ERR_BADSTRUCTURE (too deep or more END tags than BEGIN tags +* -FDT_ERR_BADLAYOUT libfdt/libfdt.h int fdt_del_node(void *fdt, int nodeoffset); · line 1634
Quoted 10 lines
libfdt/libfdt.h +9
-0+* -FDT_ERR_NOSPACE (path area is too small) +*/ +int fdt_find_regions (const void *fdt, +int (*h_include)(void *priv,int type,const char *data, +int size), +void *priv, +struct fdt_region region[],int max_regions, +char *path,int path_len,int flags); +#endif /* _LIBFDT_H */ --
Quoted 4 lines
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!Regards,
Simon
PATCH 6/8 Add fdtgrep to grep and subset FDTs
In reply to a message not in the archivefdtgrep operates like a grep for device trees, working on binary .dtb files.
fdtgrep can find nodes by name or compatible string. It can find properties by name. Using a list of of nodes/properties/compatible strings to match, fdtgrep creates either .dts text output containing just those matches, or .dtb output. In the .dtb case, the output is a valid FDT which only includes the selected nodes/properties. This is useful in resource-constrained systems where a full FDT is too large to fit in available memory (e.g. U-Boot SPL).
fdtgrep also supports producing raw binary output, without the normal FDT headers. This can be useful for hashing part of an FDT and making sure that that part does not change, even if other parts do. This makes it possible to detect an important change, while ignoring a change that is of no interest.
At its simplest fdtgrep can be used as follows;
fdtgrep /holiday tests/grep.dtb
and it produces just that node (with a skeleton to hold it):
/ {
holiday {
compatible = "ixtapa", "mexico";
weather = "sunny";
status = "okay";
};
};The binary form of this is:
fdtgrep -n /holiday -O dtb tests/grep.dtb
which produces a valid DTB file with just the above nodes.
Various options are provided to search for properties, to ensure that nodes/properties are not present, and to search for nodes by compatible string.
--- .gitignore | 1 + Makefile | 4 + Makefile.utils | 7 + fdtgrep.c | 775 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/grep.dts | 23 ++ tests/run_tests.sh | 348 +++++++++++++++++++++++- tests/tests.sh | 1 + 7 files changed, 1158 insertions(+), 1 deletions(-) create mode 100644 fdtgrep.c create mode 100644 tests/grep.dts
.gitignore +1 -0
@@ -12,6 +12,7 @@ lex.yy.c /convert-dtsv0 /version_gen.h /fdtget +/fdtgrep /fdtput /patches /.pc
Makefile +4 -0
@@ -112,6 +112,7 @@ BIN += dtc BIN += fdtdump BIN += fdtget BIN += fdtput +BIN += fdtgrep SCRIPTS = dtdiff
@@ -124,6 +125,7 @@ ifneq ($(DEPTARGETS),) -include $(FDTDUMP_OBJS:%.o=%.d) -include $(FDTGET_OBJS:%.o=%.d) -include $(FDTPUT_OBJS:%.o=%.d) +-include $(FDTGREP_OBJS:%.o=%.d) endif
@@ -188,6 +190,7 @@ fdtget: $(FDTGET_OBJS) $(LIBFDT_archive) fdtput: $(FDTPUT_OBJS) $(LIBFDT_archive) +fdtgrep: $(FDTGREP_OBJS) $(LIBFDT_archive) # # Testsuite rules
@@ -198,6 +201,7 @@ TESTS_BIN += dtc TESTS_BIN += convert-dtsv0 TESTS_BIN += fdtput TESTS_BIN += fdtget +TESTS_BIN += fdtgrep include tests/Makefile.tests
Makefile.utils +7 -0
@@ -22,3 +22,10 @@ FDTPUT_SRCS = \ util.c FDTPUT_OBJS = $(FDTPUT_SRCS:%.c=%.o) + + +FDTGREP_SRCS = \ + fdtgrep.c \ + util.c + +FDTGREP_OBJS = $(FDTGREP_SRCS:%.c=%.o)
fdtgrep.c new file +775 -0
775 lines not on this page · raw message
tests/grep.dts new file +23 -0
@@ -0,0 +1,23 @@ +/dts-v1/; +/memreserve/ 1 2; +/ { + model = "MyBoardName"; + compatible = "MyBoardName", "MyBoardFamilyName"; + #address-cells = <2>; + #size-cells = <2>; + chosen { + bootargs = "root=/dev/sda2"; + linux,platform = <0x600>; + }; + holiday { + compatible = "ixtapa", "mexico"; + weather = "sunny"; + status = "okay"; + flight@1 { + airline = "alaska"; + }; + flight@2 { + airline = "lan"; + }; + }; +};
tests/run_tests.sh +347 -1
366 lines not on this page · raw message
tests/tests.sh +1 -0
@@ -21,6 +21,7 @@ FAIL_IF_SIGNAL () { DTC=../dtc DTGET=../fdtget DTPUT=../fdtput +DTGREP=../fdtgrep verbose_run () { if [ -z "$QUIET_TEST" ]; then
Signature · 1 line
1.7.7.3
PATCH 7/8 Remove fdtdump and use fdtgrep instead
In reply to a message not in the archiveSince fdtgrep does everything that fdtdump does now, perhaps we should replace it with a symlink.
--- Makefile | 5 +- fdtdump.c | 137 ------------------------------------------------------------- fdtgrep.c | 40 ++++++++++++------ 3 files changed, 30 insertions(+), 152 deletions(-) delete mode 100644 fdtdump.c
Makefile +3 -2
@@ -122,7 +122,6 @@ all: $(BIN) libfdt ifneq ($(DEPTARGETS),) -include $(DTC_OBJS:%.o=%.d) -include $(CONVERT_OBJS:%.o=%.d) --include $(FDTDUMP_OBJS:%.o=%.d) -include $(FDTGET_OBJS:%.o=%.d) -include $(FDTPUT_OBJS:%.o=%.d) -include $(FDTGREP_OBJS:%.o=%.d)
@@ -184,7 +183,9 @@ convert-dtsv0: $(CONVERT_OBJS) @$(VECHO) LD $@ $(LINK.c) -o $@ $^ -fdtdump: $(FDTDUMP_OBJS) +fdtdump: fdtgrep + rm -f $@ + ln -s $< $@ fdtget: $(FDTGET_OBJS) $(LIBFDT_archive)
fdtdump.c deleted +0 -137
137 lines not on this page · raw message
fdtgrep.c +27 -13
@@ -726,28 +726,42 @@ int main(int argc, char *argv[]) {char *filename =NULL ;struct display_info disp; +const char *name;int ret;/* set defaults */ memset (&disp,'\0' ,sizeof (disp)); disp.flags =FDT_REG_SUPERNODES ;/* Default flags */ -scan_args (&disp, argc, argv); +/* For fdtdump, use default args */ + name =strrchr (argv[0 ],'/' ); +if (!strcmp (name ? name +1 : argv[0 ],"fdtdump" )) { + disp.show_dts_version =1 ; + disp.header =1 ; + disp.flags |=FDT_REG_ADD_MEM_RSVMAP ; +if (argc <2 ) { +fprintf (stderr,"supply input filename\n" ); +return 5 ; + } + filename = argv[1 ]; + }else { +scan_args (&disp, argc, argv); -/* Show matched lines in colour if we can */ - disp.colour = disp.all &&isatty (0 ); +/* Show matched lines in colour if we can */ + disp.colour = disp.all &&isatty (0 ); -/* Any additional arguments can match anything, just like -g */ -while (optind < argc -1 ) { -if (value_add (&disp, &disp.value_head,FDT_IS_ANY ,1 , - argv[optind++])) -usage ("Cannot add value" ); - } +/* Any additional arguments can match anything, just like -g */ +while (optind < argc -1 ) { +if (value_add (&disp, &disp.value_head,FDT_IS_ANY ,1 , + argv[optind++])) +usage ("Cannot add value" ); + } -if (optind < argc) - filename = argv[optind++]; -if (!filename) -usage ("Missing filename" ); +if (optind < argc) + filename = argv[optind++]; +if (!filename) +usage ("Missing filename" ); + }/* If a valid .dtb is required, set flags to ensure we get one */ if (disp.output ==OUT_DTB ) {
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1358801962-21707-8-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
Re: [PATCH 7/8] Remove fdtdump and use fdtgrep instead
Quoted 2 lines · Simon Glass
Since fdtgrep does everything that fdtdump does now, perhaps we should replace it with a symlink.
Nack. The point of fdtdump is not simply to be a tool for dumping device trees - dtc -I dtb -O dts will do that already. The point is to be a really simple, independent implementation of dumping the tree, which can be used for analyzing bugs in the more complex tools.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
A message that is not in the archive (sent off-list or not yet received): 20130206071606.GR821-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org
Re: [PATCH 7/8] Remove fdtdump and use fdtgrep instead
Hi David,
Quoted 8 lines · David Gibson
Quoted 2 lines · Simon Glass
Since fdtgrep does everything that fdtdump does now, perhaps we should replace it with a symlink.
Nack. The point of fdtdump is not simply to be a tool for dumping device trees - dtc -I dtb -O dts will do that already. The point is to be a really simple, independent implementation of dumping the tree, which can be used for analyzing bugs in the more complex tools.
Sounds reasonable - I wasn't aware of that. I figured that if I didn't send a patch to implement dump with grep then someone would ask for it... But I agree it is nice to keep the simple code and I have made the output function common anyway.
Regards,
Simon
Quoted 6 lines
--
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_!
PATCH 8/8 RFC: Check offset in fdt_string()
In reply to a message not in the archive(We probably don't want this patch, and certainly can't apply it as is, but I send it in order to find out the intent of fdt_string()).
At present fdt_string() says that returns:
- a pointer to the string, on success
- NULL, if stroffset is out of bounds
However it does not in fact return NULL. Changing it to do so also breaks 15 tests (segfault).
What is the intended behaviour of this function, please?
--- libfdt/fdt_ro.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
libfdt/fdt_ro.c +2 -0
@@ -77,6 +77,8 @@ static int _fdt_nodename_eq(const void *fdt, int offset,const char *fdt_string (const void *fdt,int stroffset) { +if (stroffset <0 || stroffset >=fdt_size_dt_strings (fdt)) +return NULL ;return (const char *)fdt +fdt_off_dt_strings (fdt) + stroffset; }
Signature · 1 line
1.7.7.3