Add support for structured tags and v18 dtb version
v4 cover Add support for structured tags and v18 dtb version
Previously, I sent a RFC series related to support for metadata and addon device-trees [1].
During the discussion the concept of structured tags and "unknown" tags emerged as well as the need to have them handled as a prerequisite of support for metadata and addon.
The conclusion was the need for a new dtb version (v18) with support for:
- Structured tags and based on them, "unknown" tags.
Those structured tags allow to have an standardized definition of tags with the capability of skipping a tag and its related data when a "unknown" tag is incountered by a given version of libfdt, dtc and tools. Those "unknown" tags are tags defined in future versions. Even if they exact meaning is unknown for an 'old' version, they structure is understood and the 'old' version can skip them without any errors if allowed.
- Flags in the dtb header (dt_flags).
The goal of this field is to have a placeholder to specify the type of dtb we are dealing with. For instance, addons dtb will set a flag in this placeholder
- A last compatible version for writing purpose.
The goal of the new dtb header field (last_comp_version_w) is to disable globally any modification. It works similarly to last_comp_version but for modification. It can be used to avoid any modification that could be done by an 'old' version and could lead to inconsistencies between the modification itself and some "unknown" tags.
This current series implements those features and leads to the v18 dtb version. Worth noting that during the review of the v3 iteration of the series, the last_comp_version_w dtb header field has been rejected.
Patches 1 to 6 add support (and update tests) for possible FDT_NOP tags at offset 0. Those patches are fixes patches.
Patch 7 to 11 are preparation patches improving the test treegen tool.
Patch 12 introduces the structured tags. The patch gives definitions needed to handle those tags.
Patch 13 is a preparation patch needed by patch 14 which itself adds the generation of all dtbs needed for tests involving "unknown" tags.
Patches 15, 16 and 17 handle "unknown" tags in fdtdump, libfdt and dtc. This is the reading part implementation related to "unknown" tags in tools and lib.
Patch 18 to 20 are preparation commits for patch 21 and patch 21 itself is handling modifications (writing part) when unknown tags are involved.
The last patch (patch 22) bumps the dtb version including changes that cannot be moved out of the version bump without having a v18 without all expected features.
Also, several tests are added as soon as the related feature is supported. Those tests are part of the last commit adding the feature.
As already said, this current series is a prerequisite to the support for metadata and addons. The RFC v2 series related to metadata and addons [2] will be rebased on top of this prerequisite. Please, keep that in mind for the review of this current prerequisite series.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Best regards,
Hervé
Changes:
v3 -> v4
Rebase on top of the last master branch of the dtc repository.
Patch 1 in v3 applied upstream
Patch 1 (patch 2 in v3)
- Return EBADSTRUCTURE instead of ENOTFOUND in fdt_root_offset()
- fdt_next_tag(): Remove unneeded variable initialisation
- Make fdt_check_node_offset_() update its offset parameter
Patch 2 (new patch in v3)
- Add a dedicated test for fdt_root_offset()
Patch 3 (patch 3 in v3)
- Remove the FDT_BEGIN_NODE check from the root_node test
Patch 4 (patch 4 in v3)
- Add 'Reviewed-by: David Gibson'
Patch 5 (new patch in v4)
- Add '--noskip-nop' option in dtbs_equal_ordered. This option is useful to avoid FDT_NOP tags skipped when dtbs are compared in tests looking explicitly at FDT_NOP tags.
Patch 6 (new patch in v4)
- Fix dtc to handle all possible FDT_NOP tags. FDT_NOP tags before the root node and FDT_NOP tags before the FDT_END tag were not handled.
- Add a dtc test involving FDT_NOP tags. Used a nopulated dtb. Indeed, with recent modification done in nopulate, FDT_NOP are added everywhere in the dtb from offset 0 and after all tags up to FDT_END.
Patch 7 (patch 5 in v3)
- Add 'Reviewed-by: David Gibson'
Patch 8 (new patch in v4)
- Introduce harnesses in treegen to allow grouping tree generators
Patch 9 (new patch in v4)
- Fix missing included header in util.h
Patch 10 (new patch in v4)
- Introduce treegen.h an export primitives to generate trees
Patch 11 (new patch in v4)
- Move generated base dtbs from treegen.c to a dedicated file treegen_base.c (split treegen.c file)
Patch 12 (patch 6 in v3)
- Rework "structured" tags definition:
- Remove SKIP_SAFE bit
- Introduce 'Reserved' field
- Resize fields
- Update comments
- Add macro to help in handling tags (get DLEN, test if skippable)
- Remap tests reserved tags to high tag_id value
Patch 13 (new patch in v4)
- Add concat() macro in util.h.
Patch 14 (new patch in v4)
- Generate expected dtbs used for tests with unknwnow tags
Patch 15 (patch 7 in v3)
- Update due to "structured" tags definition rework
- Remove dtbs generation (treegen modification) and use dtbs generated in patch 13.
- Remove '-u' option and update unknown tags display text
- Add get_structured_tag_data()
Patch 16 (patch 9 in v3)
- Update due to "structured" tags definition rework
- Return all tags from fdt_next_tag().
- Add fdt_get_structured_tag_data()
- Check unknown tags in dtbs_equal_ordered. Also add the '-s' option to ignore those tags when dtbs are compared.
- Update tests using dtbs generated in patch 13.
Patch 17 (patch 8 in v3)
- Update due to "structured" tags definition rework
- Add flat_read_structured_tag_data()
- Update the test; use -O dtb instead of -O dts and compare the output (dtbs_equal_ordered) against unknown_tags_removed.dtb generated in patch 13.
Patch 18 (patch 10 in v3)
No changes
Patch 19 (patch 11 in v3)
- Remove fdt_open_into() from tests/get_prop_offset_w.c
- Remove get_poffset() and its usage. Replace it by a direct fdt_for_each_property_offset() usage.
- Checked returned pointers values instead of values pointed by those pointers.
- Move the test from tree1_tests_rw() tests to other write-in-place tests in tree1_tests().
Patch 12 in v3 (libfdt: Introduce fdt_getprop_offset_namelen()) Fully removed in v4
Patch 20 (patch 13 in v3)
No changes
Patch 21 (patch 14 in v3)
- Rework all the patch.
- Update due to "structured" tags definition.
- Implement the new set of rules related to modification when unknown tags are involved.
- Expose internally fdt_get_property_namelen_() and use it to replace the usage of the no more existing fdt_getprop_offset_namelen().
- Introduce fdt_remove_unknown_tags_{at,after}() to handle the logic needed to remove unknown tags. Put those function in the neutral fdt.c file. Use this common function from both wip and rw modification functions.
- Introduce 'eraser' functions passed to fdt_remove_unknown_tags_*() depending on wip or rw modification;
- fdt_erase_nopify() used in wip modification allow to erase unknown tags using FDT_NOP tags.
- fdt_erase_splice() used in rw modification allow to erase unknown tags using splice.
- Unknown tags can be present right after a sub-node. Those tags should not be there but nothing prevent that. When a sub-node is deleted those tags must not be attached to any previous items such as a property, an other sub-node or the parent node. Fix that removing them on sub-node removal.
- In all tests, remove expected text files. Use dtbs generated in patch 13 as expected values and compare modified dtbs against expected ones using dtbs_equal_ordered.
Patch 22 (patch 15 in v3)
- Generate and use the expected dtb matching dtflags_default.dts. Use it to replace the expected text file in tests.
- Remove the last_comp_version_w header field.
v2 -> v3
v2: https://lore.kernel.org/devicetree-compiler/[email protected]/
Rebase on top of the last master branch of the dtc repository.
Even if Frank Li has sent his 'Reviewed-by' tag on all v2 patches, his 'Reviewed-by' tag is not added on patches having substantial modification in this v3.
- Patch 1 (New patch):
Remove open coded loops in fdtget.
- Patch 2 (patch 1 and 2 in v2):
Squash v2 patch 1 and patch 2
Rename fdt_first_node() to fdt_root_offset()
Make fdt_root_offset() accessible from users of libfdt library. Fix libfdt functions that must take care of root node offset vs offset 0 (identified thanks to nopulate update and missed in v2):
- fdt_get_name(),
- fdt_first_property_offset(),
- fdt_supernode_atdepth_offset(),
- fdt_node_depth(),
- fdt_add_property_().
Update commit log
Add 'Reviewed-by: Frank Li'
- Patch 3 (new patch):
Update tests to avoid considering offset 0 as the expected offset for the root node.
- Patch 4 (new patch):
Improve nopulate to add a FDT_NOP tag at offset 0 (i.e. before the root node).
- Patch 5 (patch 3 in v2)
Port modification done on tree.S in v2 to the treegen tool
- Patch 6 (patch 4 in v2)
Force structured tags to be unsigned. This avoids later signed/unsigned mismatch.
Add 'Reviewed-by: Frank Li'
- Patch 7 (patch 5 in v2)
Use treegen tool to generate unknown_tags_can_skip.dtb and unknown_tags_no_skip.dtb.
Slightly modified unknown_tags_can_skip.dtb content. Add 'Reviewed-by: Frank Li'
- Patch 8 (patch 6 in v2)
Update expected dtbs due to slightly modification in unknown_tags_can_skip.dtb
Add 'Reviewed-by: Frank Li'
- Patch 9 (patch 7 in v2)
Rename fdt_is_unknown_tag() to fdt_tag_is_unknown() Add 'Reviewed-by: Frank Li'
- Patch 10 (patch 8 in v2)
Add 'Reviewed-by: Frank Li'
- Patch 11 (New patch)
Introduce fdt_getprop_by_offset_w() and its related test. This new function is needed for later fdt_wip modifications.
- Patch 12 (New patch)
Introduce fdt_getprop_offset_namelen() and its simple variant fdt_getprop_offset(). This new function is needed for later fdt_wip modifications
- Patch 13 (New patch)
Introduce wip_func, a test utility to call wip (write inplace) functions family. This allows to write test with custom scenario when unknown tags are involved.
- Patch 14 (patch 9 in v2)
Handle modification done using inplace functions (fdt_wip.c). Those were missed in previous v2.
Add a test involving wip functions when unknown tags are present. Update expected dtbs due to slightly modification in unknown_tags_can_skip.dtb
- Patch 15 (patch 10 in v2)
Add a test for the dt_flags default value
Update header generation in treegen tool and use treegen tool to generate last_comp_version_w.dtb
Add 'Reviewed-by: Frank Li'
v1 -> v2
v1: https://lore.kernel.org/devicetree-compiler/[email protected]/T/#t
Rebase on top of the last master branch of the dtc repository. Remove the RFC tag.
- Patches 1, 2, 3, 4 and 7 in v1: Removed
Already applied.
- Patch 1 (5 in v1)
Update the commit log.
- Patch 2 (6 in v1)
Fix a typo in the commit log.
Add a comment related to 'offset <= 0' in fdt_next_node().
- Patch 3 (8 in v1)
No change
- Patch 4 (9 in v1)
Fix typos in commit log.
Replace DATA_LNG_ENCODING by DATA_LEN_ENCODING in commit log. Use SKIP_SAFE instead of CAN_SKIP in commit log.
Rename FDT_TAG_DATA_LNG to FDT_TAG_DATA_VARLEN in tags definition. Rename FDT_TEST_LNG_CAN_SKIP to FDT_TEST_VARLEN_CAN_SKIP.
- Patch 5 (10 in v1)
Use FDT_TAG_DATA_VARLEN instead of FDT_TAG_DATA_LNG.
Use FDT_TEST_VARLEN_CAN_SKIP instead of FDT_TEST_LNG_CAN_SKIP. Update values used in the unknown_tags_can_skip dtb test file. Use 'len' instead of 'lng'
Update the '-uu' option help message.
Update the fdtdump test to be stricter (avoid removing some specific comments related to unknown tags in sed command used in the test).
- Patch 6 (11 in v1)
Use FDT_TAG_DATA_VARLEN instead of FDT_TAG_DATA_LNG. Update the dtc test due to unknown_tags_can_skip dtb changes. Add 'Reviewed-by: Luca Ceresoli'
- Patch 7 (12 in v1)
Replace fdt_get_next() by fdt_next_tag() in commit title and log. Fix a typo in commit log.
Use FDT_TAG_DATA_VARLEN instead of FDT_TAG_DATA_LNG. Update the fdtget test due to unknown_tags_can_skip dtb changes. Add 'Reviewed-by: Luca Ceresoli'
- Patch 8 (13 in v1)
Fix commit log.
Add 'Reviewed-by: Luca Ceresoli'
- Patch 9 (14 in v1)
Update the fdtput test due to unknown_tags_can_skip dtb and fdtdump changes.
Add a missing ')' in commit log
Add 'Reviewed-by: Luca Ceresoli'
- Patch 10 (15 in v1)
Fix typos and clarify several parts of the commit log.
Herve Codina (22):
libfdt: Don't assume the root node is available at offset 0
tests: Add a test for fdt_root_offset()
tests: Don't assume the root node is available at offset 0 tests/nopulate: Add an FDT_NOP before the root node
tests: dtbs_equal_ordered: Add --noskip-nop option
dtc: Skip possible FDT_NOP before the root node and before FDT_END tag
tests: treegen: Introduce emit_fdt_header_vers()
tests: treegen: Introduce tree harness
util.h: Add missing <stdio.h>
tests: treegen: Export tree generation primitives
tests: treegen: Move base harness trees to treegen_base.c Introduce structured tag value definition
util.h: Add concat() macro
tests: treegen: Generate dtbs with unknown tags
fdtdump: Handle unknown tags
libfdt: Handle unknown tags in fdt_next_tag()
flattree: Handle unknown tags
libfdt: Introduce fdt_ptr_offset_()
libfdt: Introduce fdt_getprop_by_offset_w()
tests: Add wip_func utility
libfdt: Handle unknown tags on dtb modifications
Introduce v18 dtb version
dtc.h | 2 +- fdtdump.c | 48 +- flattree.c | 93 +- libfdt/fdt.c | 168 ++- libfdt/fdt.h | 80 ++ libfdt/fdt_check.c | 6 +- libfdt/fdt_ro.c | 83 +- libfdt/fdt_rw.c | 195 +++- libfdt/fdt_sw.c | 2 + libfdt/fdt_wip.c | 115 +- libfdt/libfdt.h | 25 +- libfdt/libfdt_internal.h | 26 +- libfdt/version.lds | 1 + pylibfdt/libfdt.i | 9 + tests/.gitignore | 3 + tests/Makefile.tests | 247 ++++- tests/dtbs_equal_ordered.c | 84 +- tests/dtflags_default.dts | 10 + tests/get_prop_offset_w.c | 78 ++ tests/meson.build | 241 ++++- tests/node_offset_by_compatible.c | 4 +- tests/node_offset_by_prop_value.c | 11 +- tests/nopulate.c | 3 + tests/path_offset.c | 13 +- tests/pylibfdt_tests.py | 9 +- tests/root_node.c | 9 +- tests/root_offset.c | 45 + tests/run_tests.sh | 179 ++- tests/testutils.c | 2 +- tests/treegen.c | 617 ++--------- tests/treegen.h | 83 ++ tests/treegen_base.c | 590 ++++++++++ tests/treegen_unknown_tags.c | 1142 ++++++++++++++++++++ tests/unknown_tags_can_skip.fdtdump.expect | 228 ++++ tests/wip_func.c | 127 +++ util.h | 4 + 36 files changed, 3925 insertions(+), 657 deletions(-) create mode 100644 tests/dtflags_default.dts create mode 100644 tests/get_prop_offset_w.c create mode 100644 tests/root_offset.c create mode 100644 tests/treegen.h create mode 100644 tests/treegen_base.c create mode 100644 tests/treegen_unknown_tags.c create mode 100644 tests/unknown_tags_can_skip.fdtdump.expect create mode 100644 tests/wip_func.c
Signature · 1 line
2.56.1
PATCH v4 1/22 libfdt: Don't assume the root node is available at offset 0
In several places, libfdt assumes that the root offset (i.e. the first FDT_BEGIN_NODE tag) is present at offset 0 of the structure block.
This assumption is not correct. An FDT_NOP tag can be present at offset 0 and this is a legitimate case. Indeed, the device-tree specification
[0] defines the FDT_NOP tag as follows:
The FDT_NOP token will be ignored by any program parsing the device tree. This token has no extra data; so it is followed immediately by the next token, which can be any valid token. A property or node definition in the tree can be overwritten with FDT_NOP tokens to remove it from the tree without needing to move other sections of the tree’s representation in the devicetree blob.
Nothing specifies a location for this tag, so it has to be simply ignored. Having this tag at offset 0 doesn't make an exception; the tag has to be ignored.
Introduce fdt_root_offset() in order to get the offset of the root node (first FDT_BEGIN_NODE tag) available in an FDT blob taking care of FDT_NOP tags.
Use this function to get the root node offset instead of looking for this node at offset 0.
--- libfdt/fdt.c | 43 ++++++++++++++++++++++--- libfdt/fdt_ro.c | 69 ++++++++++++++++++++++++++++++---------- libfdt/fdt_rw.c | 8 ++++- libfdt/libfdt.h | 15 ++++++++- libfdt/libfdt_internal.h | 2 +- libfdt/version.lds | 1 + 6 files changed, 113 insertions(+), 25 deletions(-)
libfdt/fdt.c +38 -5
@@ -253,16 +253,49 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)return tag; } -int fdt_check_node_offset_ (const void *fdt,int offset) +int fdt_root_offset (const void *fdt) { +int nextoffset =0 ; +int offset; +uint32_t tag; + +do { + offset = nextoffset; + tag =fdt_next_tag (fdt, offset, &nextoffset); +switch (tag) { +case FDT_END_NODE : +case FDT_PROP : +return -FDT_ERR_BADSTRUCTURE ; + +case FDT_BEGIN_NODE : +return offset; + +default : +break ; + } + }while (tag !=FDT_END ); + +return (nextoffset <0 ) ? nextoffset : -FDT_ERR_BADSTRUCTURE ; +} + +int fdt_check_node_offset_ (const void *fdt,int *offset) +{ +int nextoffset; +if (!can_assume (VALID_INPUT ) - && ((offset <0 ) || (offset %FDT_TAGSIZE ))) + && ((*offset <0 ) || (*offset %FDT_TAGSIZE )))return -FDT_ERR_BADOFFSET ; -if (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE ) +if (*offset ==0 ) { + *offset =fdt_root_offset (fdt); +if (*offset <0 ) +return *offset; + } + +if (fdt_next_tag (fdt, *offset, &nextoffset) !=FDT_BEGIN_NODE )return -FDT_ERR_BADOFFSET ; -return offset; +return nextoffset; }int fdt_check_prop_offset_ (const void *fdt,int offset)
@@ -283,7 +316,7 @@ int fdt_next_node(const void *fdt, int offset, int *depth)uint32_t tag;if (offset >=0 ) -if ((nextoffset =fdt_check_node_offset_ (fdt, offset)) <0 ) +if ((nextoffset =fdt_check_node_offset_ (fdt, &offset)) <0 )return nextoffset; do {
libfdt/fdt_ro.c +52 -17
148 lines not on this page · raw message
libfdt/fdt_rw.c +7 -1
@@ -226,7 +226,7 @@ static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,int err;int allocated; -if ((nextoffset =fdt_check_node_offset_ (fdt, nodeoffset)) <0 ) +if ((nextoffset =fdt_check_node_offset_ (fdt, &nodeoffset)) <0 )return nextoffset; namestroff =fdt_find_add_string_ (fdt, name, namelen, &allocated);
@@ -390,6 +390,12 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,FDT_RW_PROBE (fdt); +if (!parentoffset) { + parentoffset =fdt_root_offset (fdt); +if (parentoffset <0 ) +return parentoffset; + } + offset =fdt_subnode_offset_namelen (fdt, parentoffset, name, namelen);if (offset >=0 )return -FDT_ERR_EXISTS ;
libfdt/libfdt.h +14 -1
@@ -503,6 +503,19 @@ int fdt_num_mem_rsv(const void *fdt);*/ int fdt_get_mem_rsv (const void *fdt,int n,uint64_t *address,uint64_t *size); +/** +* fdt_root_offset - Get the offset of the root node +* @fdt: pointer to the device tree blob +* +* The root node can be located after the offset 0. Indeed FDT_NOP tags can be +* present at offset 0. fdt_root_offset() takes care of those possible FDT_NOP +* tags. +* +* returns: offset of the root node or negative libfdt error value otherwise +*/ +int fdt_root_offset (const void *fdt); + +/** * fdt_subnode_offset_namelen - find a subnode based on substring * @fdt: pointer to the device tree blob
@@ -1025,7 +1038,7 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);* at a specific depth from the root (where the root itself has depth * 0, its immediate subnodes depth 1 and so forth). So * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); -* will always return 0, the offset of the root node. If the node at +* will always return the offset of the root node. If the node at * nodeoffset has depth D, then: * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); * will return nodeoffset itself.
libfdt/libfdt_internal.h +1 -1
@@ -20,7 +20,7 @@ int32_t fdt_ro_probe_(const void *fdt); } \ } -int fdt_check_node_offset_ (const void *fdt,int offset); +int fdt_check_node_offset_ (const void *fdt,int *offset);int fdt_check_prop_offset_ (const void *fdt,int offset); const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
libfdt/version.lds +1 -0
@@ -7,6 +7,7 @@ LIBFDT_1.2 { fdt_string; fdt_num_mem_rsv; fdt_get_mem_rsv; + fdt_root_offset; fdt_subnode_offset_namelen; fdt_subnode_offset; fdt_path_offset_namelen;
Signature · 1 line
2.56.1
PATCH v4 2/22 tests: Add a test for fdt_root_offset()
In reply to Herve CodinaThe fdt_root_offset() function has been recently introduced.
Add a specific test for this function.
--- tests/.gitignore | 1 + tests/Makefile.tests | 4 ++-- tests/meson.build | 2 ++ tests/root_offset.c | 45 +++++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 3 +++ tests/treegen.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tests/root_offset.c
tests/.gitignore +1 -0
@@ -56,6 +56,7 @@ tmp.* /references /relref_merge /root_node +/root_offset /rw_tree1 /rw_oom /set_name
tests/Makefile.tests +2 -2
@@ -1,5 +1,5 @@ LIB_TESTS_L = get_mem_rsv \ - root_node find_property subnode_offset path_offset \ + root_node root_offset find_property subnode_offset path_offset \ get_name getprop get_prop_offset get_phandle \ get_path supernode_atdepth_offset parent_offset \ node_offset_by_prop_value node_offset_by_phandle \
@@ -44,7 +44,7 @@ TESTS = $(LIB_TESTS) $(DL_LIB_TESTS) TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ truncated_string.dtb truncated_memrsv.dtb unterminated_memrsv.dtb \ - two_roots.dtb named_root.dtb bad_proplen.dtb + two_roots.dtb named_root.dtb root_offset_12.dtb bad_proplen.dtb TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%) TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
tests/meson.build +2 -0
@@ -17,6 +17,7 @@ treegen_dtb = custom_target( 'unterminated_memrsv.dtb', 'two_roots.dtb', 'named_root.dtb', + 'root_offset_12.dtb', 'bad_proplen.dtb', ] )
@@ -76,6 +77,7 @@ tests = [ 'references', 'relref_merge', 'root_node', + 'root_offset', 'rw_oom', 'rw_tree1', 'set_name',
tests/root_offset.c new file +45 -0
45 lines not on this page · raw message
tests/run_tests.sh +3 -0
@@ -435,6 +435,9 @@ check_tests () { ALL_LAYOUTS="mts mst tms tsm smt stm" libfdt_tests () { + run_test root_offset 0 test_tree1.dtb + run_test root_offset 12 root_offset_12.dtb + tree1_tests test_tree1.dtb run_dtc_test -I dts -O dtb -o addresses.test.dtb "$SRCDIR/addresses.dts"
tests/treegen.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 3/22 tests: Don't assume the root node is available at offset 0
In reply to Herve CodinaSeveral tests use offset 0 as the offset of the root node. Either to check the offset returned by tested functions or to directly manipulate the root node retrieved using fdt_offset_ptr(fdt, 0, ...).
The root node is not always at offset 0. Indeed, an FDT_NOP tag can be present at offset 0. fdt_root_offset() returns the offset of the root node taking care of possible FDT_NOP tags.
Use fdt_root_offset() to get the offset of the root node and use this value whenever the offset of the root node is expected.
--- tests/node_offset_by_compatible.c | 4 +++- tests/node_offset_by_prop_value.c | 11 +++++++---- tests/path_offset.c | 13 +++++++++---- tests/root_node.c | 9 +++++---- 4 files changed, 24 insertions(+), 13 deletions(-)
tests/node_offset_by_compatible.c +3 -1
@@ -39,12 +39,14 @@ static void check_search(void *fdt, const char *compat, ...)int main (int argc,char *argv[]) {void *fdt; +int root_offset;int subnode1_offset, subnode2_offset;int subsubnode1_offset, subsubnode2_offset;test_init (argc, argv); fdt =load_blob_arg (argc, argv); + root_offset =fdt_root_offset (fdt); subnode1_offset =fdt_path_offset (fdt,"/subnode@1" ); subnode2_offset =fdt_path_offset (fdt,"/subnode@2" ); subsubnode1_offset =fdt_path_offset (fdt,"/subnode@1/subsubnode" );
@@ -54,7 +56,7 @@ int main(int argc, char *argv[]) || (subsubnode1_offset < 0) || (subsubnode2_offset < 0))FAIL ("Can't find required nodes" ); -check_search (fdt,"test_tree1" ,0 , -FDT_ERR_NOTFOUND ); +check_search (fdt,"test_tree1" , root_offset, -FDT_ERR_NOTFOUND );check_search (fdt,"subnode1" , subnode1_offset, -FDT_ERR_NOTFOUND );check_search (fdt,"subsubnode1" , subsubnode1_offset, -FDT_ERR_NOTFOUND );check_search (fdt,"subsubnode2" , subsubnode2_offset, -FDT_ERR_NOTFOUND );
tests/node_offset_by_prop_value.c +7 -4
@@ -64,12 +64,14 @@ static void check_search_str(void *fdt, const char *propname,int main (int argc,char *argv[]) {void *fdt; +int root_offset;int subnode1_offset, subnode2_offset;int subsubnode1_offset, subsubnode2_offset;test_init (argc, argv); fdt =load_blob_arg (argc, argv); + root_offset =fdt_root_offset (fdt); subnode1_offset =fdt_path_offset (fdt,"/subnode@1" ); subnode2_offset =fdt_path_offset (fdt,"/subnode@2" ); subsubnode1_offset =fdt_path_offset (fdt,"/subnode@1/subsubnode" );
@@ -79,19 +81,20 @@ int main(int argc, char *argv[]) || (subsubnode1_offset < 0) || (subsubnode2_offset < 0))FAIL ("Can't find required nodes" ); -check_search_cell (fdt,"prop-int" ,TEST_VALUE_1 ,0 , subnode1_offset, - subsubnode1_offset, -FDT_ERR_NOTFOUND ); +check_search_cell (fdt,"prop-int" ,TEST_VALUE_1 , root_offset, + subnode1_offset, subsubnode1_offset, -FDT_ERR_NOTFOUND );check_search_cell (fdt,"prop-int" ,TEST_VALUE_2 , subnode2_offset, subsubnode2_offset, -FDT_ERR_NOTFOUND ); -check_search_str (fdt,"prop-str" ,TEST_STRING_1 ,0 , -FDT_ERR_NOTFOUND ); +check_search_str (fdt,"prop-str" ,TEST_STRING_1 , root_offset, + -FDT_ERR_NOTFOUND );check_search_str (fdt,"prop-str" ,"no such string" , -FDT_ERR_NOTFOUND );check_search_cell (fdt,"prop-int" ,TEST_VALUE_1 +1 , -FDT_ERR_NOTFOUND ); -check_search (fdt,"no-such-prop" ,NULL ,0 , -FDT_ERR_NOTFOUND ); +check_search (fdt,"no-such-prop" ,NULL , root_offset, -FDT_ERR_NOTFOUND );PASS (); }
tests/path_offset.c +9 -4
@@ -84,11 +84,16 @@ int main(int argc, char *argv[])void *fdt;int subnode1_offset, subnode2_offset;int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2; +int root_offset;test_init (argc, argv); fdt =load_blob_arg (argc, argv); -check_path_offset (fdt,"/" ,0 ); + root_offset =fdt_root_offset (fdt); +if (root_offset <0 ) +FAIL ("fdt_root_offset() failed: %s" ,fdt_strerror (root_offset)); + +check_path_offset (fdt,"/" , root_offset); subnode1_offset =check_subnode (fdt,0 ,"subnode@1" ); subnode2_offset =check_subnode (fdt,0 ,"subnode@2" );
@@ -106,8 +111,8 @@ int main(int argc, char *argv[])/* Test paths with extraneous separators */ check_path_offset (fdt,"" , -FDT_ERR_BADPATH ); -check_path_offset (fdt,"//" ,0 ); -check_path_offset (fdt,"///" ,0 ); +check_path_offset (fdt,"//" , root_offset); +check_path_offset (fdt,"///" , root_offset);check_path_offset (fdt,"//subnode@1" , subnode1_offset);check_path_offset (fdt,"/subnode@1/" , subnode1_offset);check_path_offset (fdt,"//subnode@1///" , subnode1_offset);
@@ -116,7 +121,7 @@ int main(int argc, char *argv[])/* Test fdt_path_offset_namelen() */ check_path_offset_namelen (fdt,"/subnode@1" ,-1 , -FDT_ERR_BADPATH );check_path_offset_namelen (fdt,"/subnode@1" ,0 , -FDT_ERR_BADPATH ); -check_path_offset_namelen (fdt,"/subnode@1" ,1 ,0 ); +check_path_offset_namelen (fdt,"/subnode@1" ,1 , root_offset);check_path_offset_namelen (fdt,"/subnode@1/subsubnode" ,10 , subnode1_offset);check_path_offset_namelen (fdt,"/subnode@1/subsubnode" ,11 , subnode1_offset);check_path_offset_namelen (fdt,"/subnode@2TRAILINGGARBAGE" ,10 , subnode2_offset);
tests/root_node.c +5 -4
@@ -19,18 +19,19 @@ int main(int argc, char *argv[]) {void *fdt;const struct fdt_node_header *nh; +int root_offset;test_init (argc, argv); fdt =load_blob_arg (argc, argv); - nh =fdt_offset_ptr (fdt,0 ,sizeof (*nh)); + root_offset =fdt_root_offset (fdt); +if (root_offset <0 ) +FAIL ("fdt_root_offset() returns %d" , root_offset); + nh =fdt_offset_ptr (fdt, root_offset,sizeof (*nh));if (! nh)FAIL ("NULL retrieving root node" ); -if (fdt32_to_cpu (nh->tag) !=FDT_BEGIN_NODE ) -FAIL ("Wrong tag on root node" ); -if (strlen (nh->name) !=0 )FAIL ("Wrong name for root node, \"%s\" instead of empty" , nh->name);
Signature · 1 line
2.56.1
PATCH v4 4/22 tests/nopulate: Add an FDT_NOP before the root node
In reply to Herve CodinaAn FDT_NOP tag can be present at offset 0 and so before the root node. This is a legitimate case.
The nopulate tool adds an FDT_NOP tag after each tag encountered but it doesn't add an FDT_NOP tag at offset 0.
Improve nopulate to fix this gap and add an FDT_NOP tag at offset 0.
--- tests/nopulate.c | 3 +++ 1 file changed, 3 insertions(+)
tests/nopulate.c +3 -0
@@ -23,7 +23,10 @@ static int nopulate_struct(char *buf, const char *fdt)uint32_t tag;char *p; +/* Add a FDT_NOP before the root node (first node) */ p = buf; + *((fdt32_t *)p) =cpu_to_fdt32 (FDT_NOP ); + p +=FDT_TAGSIZE ; do { offset = nextoffset;
Signature · 1 line
2.56.1
PATCH v4 5/22 tests: dtbs_equal_ordered: Add --noskip-nop option
In reply to Herve Codinadtbs_equal_ordered skips FDT_NOP tags by default when it compares dtbs.
Add an option to override this behavior and take into account FDT_NOP tags in dtbs comparison.
--- tests/dtbs_equal_ordered.c | 42 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-)
tests/dtbs_equal_ordered.c +32 -10
@@ -16,6 +16,7 @@#include "testdata.h" static int notequal;/* = 0 */ +static int ignore_nop =1 ;#define MISMATCH (fmt, ...) \ do { \
@@ -76,11 +77,11 @@ static void compare_structure(const void *fdt1, const void *fdt2)do { offset1 = nextoffset1; tag1 =fdt_next_tag (fdt1, offset1, &nextoffset1); - }while (tag1 ==FDT_NOP ); + }while (ignore_nop && (tag1 ==FDT_NOP ));do { offset2 = nextoffset2; tag2 =fdt_next_tag (fdt2, offset2, &nextoffset2); - }while (tag2 ==FDT_NOP ); + }while (ignore_nop && (tag2 ==FDT_NOP ));if (tag1 != tag2) MISMATCH("Tag mismatch (%d != %d) at (%d, %d)",
@@ -126,26 +127,47 @@ static void compare_structure(const void *fdt1, const void *fdt2) offset1, offset2);break ; +case FDT_NOP : +break ; +case FDT_END :return ; } } } +static void badargs (char **argv) +{ +CONFIG ("Usage: %s [-n] --noskip-nop <dtb file> <dtb file>" , argv[0 ]); +} +int main (int argc,char *argv[]) {void *fdt1, *fdt2;uint32_t cpuid1, cpuid2; +char **args; +int argsleft;test_init (argc, argv); -if ((argc !=3 ) - && ((argc !=4 ) || !streq (argv[1 ],"-n" ))) -CONFIG ("Usage: %s [-n] <dtb file> <dtb file>" , argv[0 ]); -if (argc ==4 ) - notequal =1 ; - - fdt1 =load_blob (argv[argc-2 ]); - fdt2 =load_blob (argv[argc-1 ]); + + args = &argv[1 ]; + argsleft = argc -1 ; + +while (argsleft >2 ) { +if (streq (args[0 ],"-n" )) + notequal =1 ; +else if (streq (args[0 ],"--noskip-nop" )) + ignore_nop =0 ; +else +badargs (argv); + args++; + argsleft--; + } +if (argsleft !=2 ) +badargs (argv); + + fdt1 =load_blob (args[0 ]); + fdt2 =load_blob (args[1 ]);compare_mem_rsv (fdt1, fdt2);compare_structure (fdt1, fdt2);
Signature · 1 line
2.56.1
PATCH v4 6/22 dtc: Skip possible FDT_NOP before the root node and before FDT_END tag
In reply to Herve Codinadtc assumes that the root offset (i.e. the first FDT_BEGIN_NODE tag) is present at offset 0 of the structure block.
This assumption is not correct. FDT_NOP tags can be present at offset 0 and this is a legitimate case.
Also it assumes that the FDT_END tag is present right after the last FDT_END_NODE tag. Here also FDT_NOP tags can be present after the last FDT_END_NODE tag and before the FDT_END tag.
Handle those possible FDT_NOP tags.
--- flattree.c | 11 ++++++++--- tests/run_tests.sh | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-)
flattree.c +8 -3
@@ -909,14 +909,19 @@ struct dt_info *dt_from_blob(const char *fname) reservelist =flat_read_mem_reserve (&memresvbuf); - val =flat_read_word (&dtbuf); - +/* Skip possible FDT_NOP available before the root node */ +do { + val =flat_read_word (&dtbuf); + }while (val ==FDT_NOP );if (val !=FDT_BEGIN_NODE )die ("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\n" , val); tree =unflatten_tree (&dtbuf, &strbuf,"" , flags); - val =flat_read_word (&dtbuf); +/* Skip possible FDT_NOP available before FDT_END */ +do { + val =flat_read_word (&dtbuf); + }while (val ==FDT_NOP );if (val !=FDT_END )die ("Device tree blob doesn't end with FDT_END\n" );
tests/run_tests.sh +5 -0
@@ -597,6 +597,11 @@ dtc_tests () { tree1_tests_rw dtc_tree1.test.dtb run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb + # Check that FDT_NOP are well skipped and not present in the generated dtb + run_test nopulate dtc_tree1.test.dtb + run_dtc_test -I dtb -O dtb -o dtc_out_noppy.dtc_tree1.test.dtb noppy.dtc_tree1.test.dtb + run_test dtbs_equal_ordered --noskip-nop dtc_out_noppy.dtc_tree1.test.dtb dtc_tree1.test.dtb + run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb "$SRCDIR/propname_escapes.dts" run_test propname_escapes dtc_escapes.test.dtb
Signature · 1 line
2.56.1
PATCH v4 7/22 tests: treegen: Introduce emit_fdt_header_vers()
In reply to Herve Codinatreegen is used to generate custom dtbs. It uses emit_fdt_header() to generate the header part.
The current definition of this function doesn't allow setting custom values for the version fields.
In order to easily generate dtbs with custom version values, introduce emit_fdt_header_vers().
The modification doesn't introduce any functional changes.
--- tests/treegen.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tests/treegen.c +9 -3
@@ -105,7 +105,8 @@ static void fill_prop_name(struct buf *b, size_t strs, size_t prop, size_t strof/* FDT structure helpers */ -static size_t emit_fdt_header (struct buf *b) +static size_t emit_fdt_header_vers (struct buf *b,uint32_t version, +uint32_t last_comp_version) {size_t off =emit_u32 (b,FDT_MAGIC );
@@ -113,14 +114,19 @@ static size_t emit_fdt_header(struct buf *b)emit_u32 (b,0 );/* off_dt_struct */ emit_u32 (b,0 );/* off_dt_strings */ emit_u32 (b,0 );/* off_mem_rsvmap */ -emit_u32 (b,0x11 );/* version */ -emit_u32 (b,0x10 );/* last_comp_version */ +emit_u32 (b, version);/* version */ +emit_u32 (b, last_comp_version);/* last_comp_version */ emit_u32 (b,0 );/* boot_cpuid_phys */ emit_u32 (b,0 );/* size_dt_strings */ emit_u32 (b,0 );/* size_dt_struct */ return off; } +static size_t emit_fdt_header (struct buf *b) +{ +return emit_fdt_header_vers (b,0x11 ,0x10 ); +} +static void finish_rsvmap (struct buf *b,size_t hdr,size_t rsvmap) {struct fdt_header *fh = (struct fdt_header *)(b->data + hdr);
Signature · 1 line
2.56.1
PATCH v4 8/22 tests: treegen: Introduce tree harness
In reply to Herve CodinaTree harnesses allow grouping tree generation.
Harnesses and related tree generation can be moved to specific source files exporting only the harness to main().
treegen.c will be split in that direction, and the introduced harness is a needed feature for this split.
Apart from some display in main(), no functional changes.
--- tests/treegen.c | 68 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 19 deletions(-)
tests/treegen.c +49 -19
@@ -789,13 +789,28 @@ static struct buf make_bad_proplen(void)return b; } -/* Tree table and main */ - -static struct { +/* Tree generator */ +struct treegen {struct buf (*generator)(void );const char *filename; -} trees[] = { +};#define TREE (name) { make_##name, #name ".dtb" } + +/* Tree harness */ +struct treeharness { +const char *name; +const struct treegen *tab_treegen; +unsigned int nb_treegen; +}; +#define TREEHARNESS (name_, tab_treegen_) \ + { \ + .name = name_, \ + .tab_treegen = tab_treegen_, \ + .nb_treegen = ARRAY_SIZE(tab_treegen_), \ + } + +/* Tree base generators */ +static const struct treegen treegens[] = {TREE (test_tree1),TREE (bad_node_char),TREE (bad_node_format),TREE (bad_prop_char),TREE (ovf_size_strings),
@@ -808,9 +823,17 @@ static struct { TREE(bad_proplen), }; +/* Tree base harness */ +struct treeharness treeharness_base =TREEHARNESS ("base" , treegens); + +/* Tree harnesses */ +static const struct treeharness *tab_treeharness[] = { + &treeharness_base, +}; +int main (int argc,char *argv[]) { -unsigned int i; +unsigned int i, j;if (argc !=2 ) {fprintf (stderr,"Usage: %s <output-dir>\n" , argv[0 ]);
@@ -822,24 +845,31 @@ int main(int argc, char *argv[])return 1 ; } -for (i =0 ; i <ARRAY_SIZE (trees); i++) { -struct buf b = trees[i].generator (); -const char *filename = trees[i].filename; -int fd; -ssize_t ret; +for (i =0 ; i <ARRAY_SIZE (tab_treeharness); i++) { +const struct treeharness *treeharness = tab_treeharness[i]; + +printf ("Harness \"%s\"\n" , treeharness->name); + +for (j =0 ; j < treeharness->nb_treegen; j++) { +const struct treegen *treegen = &treeharness->tab_treegen[j]; +struct buf b = treegen->generator (); +const char *filename = treegen->filename; +int fd; +ssize_t ret; -printf ("Tree \"%s\", %zu bytes\n" , filename, b.cursor); +printf (" Tree \"%s\", %zu bytes\n" , filename, b.cursor); - fd =open (filename,O_WRONLY |O_CREAT |O_TRUNC ,0666 ); -if (fd <0 ) -perror ("open()" ); + fd =open (filename,O_WRONLY |O_CREAT |O_TRUNC ,0666 ); +if (fd <0 ) +perror ("open()" ); - ret =write (fd, b.data, b.cursor); -if (ret <0 || (size_t )ret != b.cursor) -perror ("write()" ); + ret =write (fd, b.data, b.cursor); +if (ret <0 || (size_t )ret != b.cursor) +perror ("write()" ); -close (fd); -free (b.data); +close (fd); +free (b.data); + } }return 0 ;
Signature · 1 line
2.56.1
PATCH v4 9/22 util.h: Add missing <stdio.h>
In reply to Herve Codinautil.h defines static inline functions which use fprintf() and similar functions.
In order to include util.h without the need to include stdio.h before util.h, add the missing stdio.h directly to util.h.
--- util.h | 1 + 1 file changed, 1 insertion(+)
util.h +1 -0
@@ -6,6 +6,7 @@#include <stdarg.h> #include <stdbool.h> #include <getopt.h> +#include <stdio.h> /* * Copyright 2011 The Chromium Authors, All Rights Reserved.
Signature · 1 line
2.56.1
PATCH v4 10/22 tests: treegen: Export tree generation primitives
In reply to Herve CodinaTree generation primitives are statically defined in treegen.c.
In order to allow harnesses and related tree generation to be grouped in specific source files, export the generation primitives.
No functional changes.
--- tests/treegen.c | 63 +++++++++++++++++-------------------- tests/treegen.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 35 deletions(-) create mode 100644 tests/treegen.h
tests/treegen.c +28 -35
@@ -20,18 +20,11 @@#include "testdata.h" #include "util.h" -/* -* Buffer with write cursor. Emit helpers write at the cursor, advance it, and -* return the offset at which data was written. -*/ -struct buf { -char *data; -size_t size, cursor; -}; +#include "treegen.h" #define CHUNKSIZE 1024 -static struct buf buf_init (void ) +struct buf buf_init (void ) {struct buf b = {NULL ,0 ,0 };
@@ -40,7 +33,7 @@ static struct buf buf_init(void)/* Low-level helpers */ -static size_t emit_bytes (struct buf *b,const void *data,int len) +size_t emit_bytes (struct buf *b,const void *data,int len) {size_t off = b->cursor;
@@ -59,28 +52,28 @@ static size_t emit_bytes(struct buf *b, const void *data, int len)return off; } -static size_t emit_u32 (struct buf *b,uint32_t val) +size_t emit_u32 (struct buf *b,uint32_t val) {fdt32_t beval =cpu_to_fdt32 (val);return emit_bytes (b, &beval,sizeof (beval)); } -static size_t emit_u64 (struct buf *b,uint64_t val) +size_t emit_u64 (struct buf *b,uint64_t val) {fdt64_t beval =cpu_to_fdt64 (val);return emit_bytes (b, &beval,sizeof (beval)); } -static size_t emit_string (struct buf *b,const char *str) +size_t emit_string (struct buf *b,const char *str) {return emit_bytes (b, str,strlen (str) +1 ); }#define MAX_ALIGNMENT 8 -static size_t emit_align (struct buf *b,size_t alignment) +size_t emit_align (struct buf *b,size_t alignment) {size_t pad = ((b->cursor + alignment -1 ) & ~(alignment -1 )) - b->cursor;static const char zeros[MAX_ALIGNMENT ];
@@ -91,12 +84,12 @@ static size_t emit_align(struct buf *b, size_t alignment)return emit_bytes (b, zeros, pad); } -static size_t start_block (struct buf *b) +size_t start_block (struct buf *b) {return b->cursor; } -static void fill_prop_name (struct buf *b,size_t strs,size_t prop,size_t stroff) +void fill_prop_name (struct buf *b,size_t strs,size_t prop,size_t stroff) {struct fdt_property *fp = (struct fdt_property *)(b->data + prop);
@@ -105,8 +98,8 @@ static void fill_prop_name(struct buf *b, size_t strs, size_t prop, size_t strof/* FDT structure helpers */ -static size_t emit_fdt_header_vers (struct buf *b,uint32_t version, -uint32_t last_comp_version) +size_t emit_fdt_header_vers (struct buf *b,uint32_t version, +uint32_t last_comp_version) {size_t off =emit_u32 (b,FDT_MAGIC );
@@ -122,19 +115,19 @@ static size_t emit_fdt_header_vers(struct buf *b, uint32_t version,return off; } -static size_t emit_fdt_header (struct buf *b) +size_t emit_fdt_header (struct buf *b) {return emit_fdt_header_vers (b,0x11 ,0x10 ); } -static void finish_rsvmap (struct buf *b,size_t hdr,size_t rsvmap) +void finish_rsvmap (struct buf *b,size_t hdr,size_t rsvmap) {struct fdt_header *fh = (struct fdt_header *)(b->data + hdr); fh->off_mem_rsvmap =cpu_to_fdt32 (rsvmap - hdr); } -static void finish_struct_block (struct buf *b,size_t hdr,size_t start) +void finish_struct_block (struct buf *b,size_t hdr,size_t start) {struct fdt_header *fh = (struct fdt_header *)(b->data + hdr);
@@ -142,7 +135,7 @@ static void finish_struct_block(struct buf *b, size_t hdr, size_t start) fh->size_dt_struct =cpu_to_fdt32 (b->cursor - start); } -static void finish_strings_block (struct buf *b,size_t hdr,size_t start) +void finish_strings_block (struct buf *b,size_t hdr,size_t start) {struct fdt_header *fh = (struct fdt_header *)(b->data + hdr);
@@ -150,14 +143,14 @@ static void finish_strings_block(struct buf *b, size_t hdr, size_t start) fh->size_dt_strings =cpu_to_fdt32 (b->cursor - start); } -static void finish_totalsize (struct buf *b,size_t hdr) +void finish_totalsize (struct buf *b,size_t hdr) {struct fdt_header *fh = (struct fdt_header *)(b->data + hdr); fh->totalsize =cpu_to_fdt32 (b->cursor - hdr); } -static size_t emit_rsvmap_entry (struct buf *b,uint64_t addr,uint64_t size) +size_t emit_rsvmap_entry (struct buf *b,uint64_t addr,uint64_t size) {size_t off =emit_u64 (b, addr);
@@ -165,12 +158,12 @@ static size_t emit_rsvmap_entry(struct buf *b, uint64_t addr, uint64_t size)return off; } -static size_t emit_rsvmap_term (struct buf *b) +size_t emit_rsvmap_term (struct buf *b) {return emit_rsvmap_entry (b,0 ,0 ); } -static void emit_rsvmap_empty (struct buf *b,size_t hdr) +void emit_rsvmap_empty (struct buf *b,size_t hdr) {size_t rsvmap =start_block (b);
@@ -178,7 +171,7 @@ static void emit_rsvmap_empty(struct buf *b, size_t hdr)finish_rsvmap (b, hdr, rsvmap); } -static size_t emit_begin_node (struct buf *b,const char *name) +size_t emit_begin_node (struct buf *b,const char *name) {size_t off =emit_u32 (b,FDT_BEGIN_NODE );
@@ -187,17 +180,17 @@ static size_t emit_begin_node(struct buf *b, const char *name)return off; } -static size_t emit_end_node (struct buf *b) +size_t emit_end_node (struct buf *b) {return emit_u32 (b,FDT_END_NODE ); } -static size_t emit_fdt_end (struct buf *b) +size_t emit_fdt_end (struct buf *b) {return emit_u32 (b,FDT_END ); } -static size_t emit_prop_header (struct buf *b,int nameoff,int len) +size_t emit_prop_header (struct buf *b,int nameoff,int len) {size_t off =emit_u32 (b,FDT_PROP );
@@ -206,12 +199,12 @@ static size_t emit_prop_header(struct buf *b, int nameoff, int len)return off; } -static size_t emit_prop_nil (struct buf *b,int nameoff) +size_t emit_prop_nil (struct buf *b,int nameoff) {return emit_prop_header (b, nameoff,0 ); } -static size_t emit_prop_u32 (struct buf *b,int nameoff,uint32_t val) +size_t emit_prop_u32 (struct buf *b,int nameoff,uint32_t val) {size_t off =emit_prop_header (b, nameoff,4 );
@@ -219,7 +212,7 @@ static size_t emit_prop_u32(struct buf *b, int nameoff, uint32_t val)return off; } -static size_t emit_prop_u64 (struct buf *b,int nameoff,uint64_t val) +size_t emit_prop_u64 (struct buf *b,int nameoff,uint64_t val) {size_t off =emit_prop_header (b, nameoff,8 );
@@ -227,7 +220,7 @@ static size_t emit_prop_u64(struct buf *b, int nameoff, uint64_t val)return off; } -static size_t emit_prop_str (struct buf *b,int nameoff,const char *str) +size_t emit_prop_str (struct buf *b,int nameoff,const char *str) {int len =strlen (str) +1 ;size_t off =emit_prop_header (b, nameoff, len);
@@ -240,7 +233,7 @@ static size_t emit_prop_str(struct buf *b, int nameoff, const char *str)#define emit_prop_strings (b, nameoff, ...) \ emit_prop_strings_(b, nameoff, __VA_ARGS__, NULL) -static size_t emit_prop_strings_ (struct buf *b,int nameoff, ...) +size_t emit_prop_strings_ (struct buf *b,int nameoff, ...) {size_t off =emit_prop_header (b, nameoff,0 );size_t start = b->cursor;
tests/treegen.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 11/22 tests: treegen: Move base harness trees to treegen_base.c
In reply to Herve CodinaHarnesses have been recently introduced and tree generation primitives are accessible from outside treegen.c.
Simplify treegen.c by moving the base harness trees to their specific
file: treegen_base.c.
No functional changes.
--- tests/Makefile.tests | 6 + tests/meson.build | 5 +- tests/treegen.c | 573 +------------------------------------------ tests/treegen_base.c | 551 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 563 insertions(+), 572 deletions(-) create mode 100644 tests/treegen_base.c
tests/Makefile.tests +6 -0
@@ -71,6 +71,12 @@ $(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_dep) @$(VECHO) LD [libdl] $@ $(LINK.c) -o $@ $^ $(LIBDL) +TREEGEN_OBJS = $(TESTS_PREFIX)treegen.o \ + $(TESTS_PREFIX)treegen_base.o + +$(TESTS_PREFIX)treegen: $(TREEGEN_OBJS) + $(LINK.c) -o $@ $^ + $(TESTS_TREES): $(TESTS_PREFIX)treegen @$(VECHO) TREEGEN cd $(TESTS_PREFIX); ./treegen . >/dev/null
tests/meson.build +4 -1
@@ -1,4 +1,7 @@ -treegen = executable('treegen', files('treegen.c'), +treegen = executable('treegen', + files('treegen.c', + 'treegen_base.c' + ), build_by_default: false, dependencies: [util_dep])
tests/treegen.c +2 -571
593 lines not on this page · raw message
tests/treegen_base.c new file +551 -0
551 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 12/22 Introduce structured tag value definition
In reply to Herve CodinaThe goal of structured tag values is to ease the introduction of new tags in future releases with the capability for an already existing release to ignore those structured tags. In order to do that, the data length related to the unknown tag needs to be identified.
A structured tag value is defined as a 32-bit value as follows:
Bits | 31 | 30 24 | 23 18 | 17 0|
------+----+----------+-----------------------------+--------+
Fields| 1 | Reserved | Data length encoding (DLEN) | TAG_ID |
------+----+-----------+----------------------------+--------+
Bit 31 is always set to 1 to identify a structured tag value.
Bits 30..24 are bits reserved for future use. They must be cleared.
Bits 23..18 (DLEN) encode the length of the data related to the tag. Following values are possible:
0b000000: No data
0b000001: 1 x 32-bit word
0b000010: 2 x 32-bit words
...
0b111101: 61 x 32-bit words
0b111110: 62 x 32-bit words
0b111111: varlen encoding. The length of the data is encoded by a
32-bit word available right after the tag. This word gives
the length of the data in bytes. Padding is present (if
needed) after the data block in order to have the next tag
aligned on a 32-bit word.Bits 17..0 (TAG_ID) form the tag identifier defining a specific tag.
Introduce the structured tag value definition and some specific tags reserved for testing based on this structure definition.
--- libfdt/fdt.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
libfdt/fdt.h +76 -0
@@ -57,6 +57,82 @@ struct fdt_property {#define FDT_NOP 0x4/* nop */ #define FDT_END 0x9 +/* +* Structured tag format: +* - bit 31: set to 1 +* Identify a structured tag. +* +* - bit 30..24: Reserved (7 bits) +* Those bits are reserved for future use. They must be cleared (0 value). +* If any of these bits is set, an error should be reported. +* +* - bit 23..18: Data length encoding (DLEN, 6 bits) +* Encode the length of data attached to the tag. +* 0b000000: No data +* 0b000001: 1 32bit word +* 0b000010: 2 x 32bit word +* ... +* 0b111101: 61 x 32bit words +* 0b111110: 62 x 32bit words +* 0b111111: varlen encoding. The length of data is encode by an 32bit +* word available right after the tag. This word gives the +* length of data in bytes. Padding is present (if needed) +* after the data block in order to have the next tag aligned +* on a 32bit word. +* +* - bit 17..0: Tag identifier (TAG_ID, 18 bits) +* +* The full tag value is used to identify a tag. Two structured tags with the +* same tag identifier field but with different data length encoding (DLEN +* field) should be considered as two different tags. +* +* The exact tag value is completely known when a new tag is defined and its +* data length encoding (DLEN field) must not be determine at runtime when the +* exact length of data is known. +* +* Any tags where the length of the data is not known when the tag is defined +* (i.e. sizeof(data) cannot be determined when the tag is defined) must use the +* varlen encoding value (DLEN field set to 0b111111). Tags with strings or +* arrays where the number of items in the array can vary should use the varlen +* encoding. +* +* Also for tags where the length of data is greater than 62 x 32bit words +* (maximum value without using varlen encoding), the varlen encoding must be +* used even if the length of data is known when the tag is defined. +* +* A structured tag with reserved bits cleared can be safely ignored and simply +* skipped when its TAG_ID value is not a known value (unknown tag). If any of +* the reserved bits are not cleared, the structured tag must not be ignored and +* an error should be reported. +*/ +#define FDT_TAG_STRUCTURED (1U << 31) +#define FDT_TAG_RESERVED (0x7f << 24) +#define FDT_TAG_DLEN_MASK (0x3f << 18) +#define FDT_TAG_DLEN_SET (_n) ((_n) << 18) +#define FDT_TAG_DLEN_GET (_tag) (((_tag) & FDT_TAG_DLEN_MASK) >> 18) +#define FDT_TAG_DLEN_VARLEN 0x3f + +#define FDT_TAG_STRUCTURED_BUILD (_tag_dlen, _tag_id) \ + (FDT_TAG_STRUCTURED | FDT_TAG_DLEN_SET(_tag_dlen) | (_tag_id)) + +#define FDT_TAG_IS_SKIPPABLE (_tag) (((_tag) & FDT_TAG_STRUCTURED) && \ + !((_tag) & FDT_TAG_RESERVED)) + +/* +* Structured tags reserved for tests purpose +* +* Any structured tags with the tag identifier set to 0x3ffff are reserved for +* test purpose. When a parser find this kind of tag, it must consider the tag +* as an unknown tag and so skip it. A generator must never use this kind of +* tags, except, of course, if the generator is used to generate a dtb for test +* purpose. +*/ +#define FDT_TEST_NONE FDT_TAG_STRUCTURED_BUILD(0, 0x3ffff) +#define FDT_TEST_1FDT32 FDT_TAG_STRUCTURED_BUILD(1, 0x3ffff) +#define FDT_TEST_2FDT32 FDT_TAG_STRUCTURED_BUILD(2, 0x3ffff) +#define FDT_TEST_VARLEN FDT_TAG_STRUCTURED_BUILD(FDT_TAG_DLEN_VARLEN, 0x3ffff) + +#define FDT_V1_SIZE (7*sizeof(fdt32_t))#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
Signature · 1 line
2.56.1
PATCH v4 13/22 util.h: Add concat() macro
In reply to Herve Codinautil.h defines the stringify() macro, which forces parameter expansion.
In the same way, define the concat() macro allowing the concatenation of parameters forcing their expansion before the concatenation.
This allows the following:
--- 8< ---
#define bar 2
#define baz 3
#define foo concat(bar, baz) /* foo is set to 23 */ #define other concat(test,baz) /* other is set to test3 */ --- 8< ---
--- util.h | 3 +++ 1 file changed, 3 insertions(+)
util.h +3 -0
@@ -32,6 +32,9 @@#define stringify (s) stringify_(s)#define stringify_ (s) #s +#define concat (a, b) concat_(a, b) +#define concat_ (a, b) a ## b + static inline void NORETURN PRINTF(1, 2) die(const char *str, ...) {va_list ap;
Signature · 1 line
2.56.1
PATCH v4 14/22 tests: treegen: Generate dtbs with unknown tags
In reply to Herve CodinaSeveral dtbs involving unknown structured tags are generated. Among those dtbs, expected dtbs when libfdt functions are used to modify a dtb are generated.
DTB modifications when unknown tags are involved follow specific rules:
| existing prop | existing node (1) | Downgrade
| unknown tag | unknown tag | version (2)
----------------------+---------------+-------------------+-----------
Modify a property | Remove | Keep (3) | Yes
Add a property | NA | Remove | Yes
Delete a property | Remove | Remove | Yes
Add a sub-node | NA | Remove | Yes
Delete a sub-node | NA | Remove | Yes----------------------+---------------+-------------------+-----------
(1) The existing node is the node where the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
(2) The version is always downgraded on any change (modification, addition, deletion of a property or a sub-node) even if no tags are removed.
(3) Removing unknown tags in the node when a property is modified will change the property offset. Avoid this property offset change and so keep node related unknown tags in that case.
Generated dtbs are consistent with those rules.
Also, in order to cover several cases related to unknown tag presence, several nodes are present in each dtb. Those nodes contain three properties and three subnodes allowing several use cases to be tested; modify/remove the first property available in a node, modify/remove a property among other properties, modify/remove the last property of a node. Available subnodes offer the same kind of combination.
The node structure is the following:
{
prop1 = "123456789";
prop2 = "123456789";
prop3 = "123456789";
subnode1 {
prop;
};
subnode2 {
prop;
};
subnode3 {
prop;
};}
Six nodes are available with this structure but differ in unknown tags and/or FDT_NOP presence.
- node1: No unknown tags, no FDT_NOP tags
- node2: Only unknown tags related to properties, no FDT_NOP tags
- node3: Only unknown tags related to node, no FDT_NOP tags
- node4: Both unknown tags related to properties and node, no FDT_NOP tags
- node5: Same as node4 but with unknown tags related to node added in subnodes
- node6: Same as node5 but with FDT_NOP tags added (mixed with unknown tags)
Three additional nodes are present: node7, node8 and node9. They have the same unknown tags and FDT_NOP tags as node6 but:
- node7 is a properties-only node (no subnodes are available in node7),
- node8 is a subnodes-only node (no properties are available in node8),
- node9 is an empty node.
This last node is used only on rw modification when a property or a subnode is added (neither adding a property nor a subnode is supported by write-in-place modifications).
Those additional nodes allow checking that there is no interference between properties and subnodes when modifications are performed.
Expected dtbs are generated depending on the modification done for each of the nine nodes.
--- tests/Makefile.tests | 235 ++++++- tests/meson.build | 233 ++++++- tests/treegen.c | 2 + tests/treegen_unknown_tags.c | 1142 ++++++++++++++++++++++++++++++++++ 4 files changed, 1609 insertions(+), 3 deletions(-) create mode 100644 tests/treegen_unknown_tags.c
tests/Makefile.tests +233 -2
@@ -44,7 +44,237 @@ TESTS = $(LIB_TESTS) $(DL_LIB_TESTS) TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ truncated_string.dtb truncated_memrsv.dtb unterminated_memrsv.dtb \ - two_roots.dtb named_root.dtb root_offset_12.dtb bad_proplen.dtb + two_roots.dtb named_root.dtb root_offset_12.dtb bad_proplen.dtb \ + unknown_tags_can_skip.dtb \ + unknown_tags_removed.dtb \ + unknown_tags_rw_node1_prop1_modified_ab.dtb \ + unknown_tags_rw_node1_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node1_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node1_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node1_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node1_prop2_modified_ab.dtb \ + unknown_tags_rw_node1_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node1_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node1_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node1_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node1_prop3_modified_ab.dtb \ + unknown_tags_rw_node1_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node1_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node1_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node1_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node1_prop1_removed.dtb \ + unknown_tags_rw_node1_prop2_removed.dtb \ + unknown_tags_rw_node1_prop3_removed.dtb \ + unknown_tags_rw_node1_subnode1_removed.dtb \ + unknown_tags_rw_node1_subnode2_removed.dtb \ + unknown_tags_rw_node1_subnode3_removed.dtb \ + unknown_tags_rw_node1_propnew_added.dtb \ + unknown_tags_rw_node1_subnodenew_added.dtb \ + unknown_tags_rw_node2_prop1_modified_ab.dtb \ + unknown_tags_rw_node2_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node2_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node2_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node2_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node2_prop2_modified_ab.dtb \ + unknown_tags_rw_node2_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node2_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node2_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node2_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node2_prop3_modified_ab.dtb \ + unknown_tags_rw_node2_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node2_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node2_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node2_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node2_prop1_removed.dtb \ + unknown_tags_rw_node2_prop2_removed.dtb \ + unknown_tags_rw_node2_prop3_removed.dtb \ + unknown_tags_rw_node2_subnode1_removed.dtb \ + unknown_tags_rw_node2_subnode2_removed.dtb \ + unknown_tags_rw_node2_subnode3_removed.dtb \ + unknown_tags_rw_node2_propnew_added.dtb \ + unknown_tags_rw_node2_subnodenew_added.dtb \ + unknown_tags_rw_node3_prop1_modified_ab.dtb \ + unknown_tags_rw_node3_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node3_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node3_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node3_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node3_prop2_modified_ab.dtb \ + unknown_tags_rw_node3_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node3_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node3_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node3_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node3_prop3_modified_ab.dtb \ + unknown_tags_rw_node3_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node3_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node3_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node3_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node3_prop1_removed.dtb \ + unknown_tags_rw_node3_prop2_removed.dtb \ + unknown_tags_rw_node3_prop3_removed.dtb \ + unknown_tags_rw_node3_subnode1_removed.dtb \ + unknown_tags_rw_node3_subnode2_removed.dtb \ + unknown_tags_rw_node3_subnode3_removed.dtb \ + unknown_tags_rw_node3_propnew_added.dtb \ + unknown_tags_rw_node3_subnodenew_added.dtb \ + unknown_tags_rw_node4_prop1_modified_ab.dtb \ + unknown_tags_rw_node4_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node4_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node4_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node4_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node4_prop2_modified_ab.dtb \ + unknown_tags_rw_node4_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node4_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node4_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node4_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node4_prop3_modified_ab.dtb \ + unknown_tags_rw_node4_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node4_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node4_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node4_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node4_prop1_removed.dtb \ + unknown_tags_rw_node4_prop2_removed.dtb \ + unknown_tags_rw_node4_prop3_removed.dtb \ + unknown_tags_rw_node4_subnode1_removed.dtb \ + unknown_tags_rw_node4_subnode2_removed.dtb \ + unknown_tags_rw_node4_subnode3_removed.dtb \ + unknown_tags_rw_node4_propnew_added.dtb \ + unknown_tags_rw_node4_subnodenew_added.dtb \ + unknown_tags_rw_node5_prop1_modified_ab.dtb \ + unknown_tags_rw_node5_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node5_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node5_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node5_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node5_prop2_modified_ab.dtb \ + unknown_tags_rw_node5_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node5_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node5_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node5_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node5_prop3_modified_ab.dtb \ + unknown_tags_rw_node5_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node5_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node5_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node5_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node5_prop1_removed.dtb \ + unknown_tags_rw_node5_prop2_removed.dtb \ + unknown_tags_rw_node5_prop3_removed.dtb \ + unknown_tags_rw_node5_subnode1_removed.dtb \ + unknown_tags_rw_node5_subnode2_removed.dtb \ + unknown_tags_rw_node5_subnode3_removed.dtb \ + unknown_tags_rw_node5_propnew_added.dtb \ + unknown_tags_rw_node5_subnodenew_added.dtb \ + unknown_tags_rw_node6_prop1_modified_ab.dtb \ + unknown_tags_rw_node6_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node6_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node6_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node6_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node6_prop2_modified_ab.dtb \ + unknown_tags_rw_node6_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node6_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node6_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node6_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node6_prop3_modified_ab.dtb \ + unknown_tags_rw_node6_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node6_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node6_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node6_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node6_prop1_removed.dtb \ + unknown_tags_rw_node6_prop2_removed.dtb \ + unknown_tags_rw_node6_prop3_removed.dtb \ + unknown_tags_rw_node6_subnode1_removed.dtb \ + unknown_tags_rw_node6_subnode2_removed.dtb \ + unknown_tags_rw_node6_subnode3_removed.dtb \ + unknown_tags_rw_node6_propnew_added.dtb \ + unknown_tags_rw_node6_subnodenew_added.dtb \ + unknown_tags_rw_node7_prop1_modified_ab.dtb \ + unknown_tags_rw_node7_prop1_modified_abcdefgh.dtb \ + unknown_tags_rw_node7_prop1_modified_abcdefghi.dtb \ + unknown_tags_rw_node7_prop1_modified_abcdefghij.dtb \ + unknown_tags_rw_node7_prop1_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node7_prop2_modified_ab.dtb \ + unknown_tags_rw_node7_prop2_modified_abcdefgh.dtb \ + unknown_tags_rw_node7_prop2_modified_abcdefghi.dtb \ + unknown_tags_rw_node7_prop2_modified_abcdefghij.dtb \ + unknown_tags_rw_node7_prop2_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node7_prop3_modified_ab.dtb \ + unknown_tags_rw_node7_prop3_modified_abcdefgh.dtb \ + unknown_tags_rw_node7_prop3_modified_abcdefghi.dtb \ + unknown_tags_rw_node7_prop3_modified_abcdefghij.dtb \ + unknown_tags_rw_node7_prop3_modified_abcdefghijklmnop.dtb \ + unknown_tags_rw_node7_prop1_removed.dtb \ + unknown_tags_rw_node7_prop2_removed.dtb \ + unknown_tags_rw_node7_prop3_removed.dtb \ + unknown_tags_rw_node7_propnew_added.dtb \ + unknown_tags_rw_node7_subnodenew_added.dtb \ + unknown_tags_rw_node8_subnode1_removed.dtb \ + unknown_tags_rw_node8_subnode2_removed.dtb \ + unknown_tags_rw_node8_subnode3_removed.dtb \ + unknown_tags_rw_node8_propnew_added.dtb \ + unknown_tags_rw_node8_subnodenew_added.dtb \ + unknown_tags_rw_node9_propnew_added.dtb \ + unknown_tags_rw_node9_subnodenew_added.dtb \ + unknown_tags_wip_node1_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node1_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node1_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node1_prop1_removed.dtb \ + unknown_tags_wip_node1_prop2_removed.dtb \ + unknown_tags_wip_node1_prop3_removed.dtb \ + unknown_tags_wip_node1_subnode1_removed.dtb \ + unknown_tags_wip_node1_subnode2_removed.dtb \ + unknown_tags_wip_node1_subnode3_removed.dtb \ + unknown_tags_wip_node2_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node2_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node2_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node2_prop1_removed.dtb \ + unknown_tags_wip_node2_prop2_removed.dtb \ + unknown_tags_wip_node2_prop3_removed.dtb \ + unknown_tags_wip_node2_subnode1_removed.dtb \ + unknown_tags_wip_node2_subnode2_removed.dtb \ + unknown_tags_wip_node2_subnode3_removed.dtb \ + unknown_tags_wip_node3_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node3_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node3_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node3_prop1_removed.dtb \ + unknown_tags_wip_node3_prop2_removed.dtb \ + unknown_tags_wip_node3_prop3_removed.dtb \ + unknown_tags_wip_node3_subnode1_removed.dtb \ + unknown_tags_wip_node3_subnode2_removed.dtb \ + unknown_tags_wip_node3_subnode3_removed.dtb \ + unknown_tags_wip_node4_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node4_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node4_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node4_prop1_removed.dtb \ + unknown_tags_wip_node4_prop2_removed.dtb \ + unknown_tags_wip_node4_prop3_removed.dtb \ + unknown_tags_wip_node4_subnode1_removed.dtb \ + unknown_tags_wip_node4_subnode2_removed.dtb \ + unknown_tags_wip_node4_subnode3_removed.dtb \ + unknown_tags_wip_node5_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node5_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node5_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node5_prop1_removed.dtb \ + unknown_tags_wip_node5_prop2_removed.dtb \ + unknown_tags_wip_node5_prop3_removed.dtb \ + unknown_tags_wip_node5_subnode1_removed.dtb \ + unknown_tags_wip_node5_subnode2_removed.dtb \ + unknown_tags_wip_node5_subnode3_removed.dtb \ + unknown_tags_wip_node6_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node6_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node6_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node6_prop1_removed.dtb \ + unknown_tags_wip_node6_prop2_removed.dtb \ + unknown_tags_wip_node6_prop3_removed.dtb \ + unknown_tags_wip_node6_subnode1_removed.dtb \ + unknown_tags_wip_node6_subnode2_removed.dtb \ + unknown_tags_wip_node6_subnode3_removed.dtb \ + unknown_tags_wip_node7_prop1_modified_abcdefghi.dtb \ + unknown_tags_wip_node7_prop2_modified_abcdefghi.dtb \ + unknown_tags_wip_node7_prop3_modified_abcdefghi.dtb \ + unknown_tags_wip_node7_prop1_removed.dtb \ + unknown_tags_wip_node7_prop2_removed.dtb \ + unknown_tags_wip_node7_prop3_removed.dtb \ + unknown_tags_wip_node8_subnode1_removed.dtb \ + unknown_tags_wip_node8_subnode2_removed.dtb \ + unknown_tags_wip_node8_subnode3_removed.dtb TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%) TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
@@ -72,7 +302,8 @@ $(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_dep) $(LINK.c) -o $@ $^ $(LIBDL) TREEGEN_OBJS = $(TESTS_PREFIX)treegen.o \ - $(TESTS_PREFIX)treegen_base.o + $(TESTS_PREFIX)treegen_base.o \ + $(TESTS_PREFIX)treegen_unknown_tags.o $(TESTS_PREFIX)treegen: $(TREEGEN_OBJS) $(LINK.c) -o $@ $^
tests/meson.build +232 -1
244 lines not on this page · raw message
tests/treegen.c +2 -0
@@ -249,10 +249,12 @@ size_t emit_prop_strings_(struct buf *b, int nameoff, ...)/* Available harnesses */ extern struct treeharness treeharness_base; +extern struct treeharness treeharness_unknown_tags;/* Tree harnesses */ static const struct treeharness *tab_treeharness[] = { &treeharness_base, + &treeharness_unknown_tags, };int main (int argc,char *argv[])
tests/treegen_unknown_tags.c new file +1142 -0
1,142 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 15/22 fdtdump: Handle unknown tags
In reply to Herve CodinaThe structured tag value definition introduced recently gives the ability to ignore unknown tags without any error when they are read.
Add support for those structured tags in fdtdump.
--- fdtdump.c | 42 ++++ tests/run_tests.sh | 39 ++++ tests/unknown_tags_can_skip.fdtdump.expect | 228 +++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 tests/unknown_tags_can_skip.fdtdump.expect
fdtdump.c +42 -0
@@ -53,6 +53,30 @@ static uint32_t next_cell(const void *blob, uint32_t *off, uint32_t limit)return fdt32_to_cpu (*p); } +static uint32_t get_structured_tag_data (uint32_t tag,const char *blob, +uint32_t off,uint32_t limit, +const char **data,uint32_t *data_size) +{ +uint32_t sz; + + sz =FDT_TAG_DLEN_GET (tag); +if (sz !=FDT_TAG_DLEN_VARLEN ) { + sz *=sizeof (fdt32_t); + }else { +/* Get the length */ + sz =next_cell (blob, &off, limit); + } + +if (off > limit || sz > limit - off) +die ("** End of blob while reading structured tag data\n" ); + + *data_size = sz; + *data = sz ? blob + off :NULL ; + +/* Skip the data bytes */ +return ALIGN (off + sz,4 ); +} +static void dump_blob (void *blob,bool debug) {struct fdt_header *bph = blob;
@@ -178,6 +202,24 @@ static void dump_blob(void *blob, bool debug)continue ; } +if (FDT_TAG_IS_SKIPPABLE (tag)) { +uint32_t sz, index; +const char *d; + + o =get_structured_tag_data (tag, blob, o, totalsize, + &d, &sz); + +printf ("%*s// Tag: 0x%08" PRIx32", data len %" PRIu32, + depth * shift,"" , tag, sz); +if (sz !=0 ) { +printf (" " ); +for (index =0 ; index < sz; index++) +printf ("%02hhx" , *(d + index)); + } +printf ("\n" ); +continue ; + } +die ("** Unknown tag 0x%08" PRIx32"\n" , tag); } }
tests/run_tests.sh +39 -0
@@ -227,6 +227,40 @@ check_align () { ) } +# $1: generated file +# $2: expected file +check_diff () { + printf "check_diff $1 $2: " + local fgen="$1" + local fref="$2" + ( + if diff $fref $fgen >/dev/null; then + PASS + else + if [ -z "$QUIET_TEST" ]; then + echo "DIFF :-:" + diff -u $fref $fgen + fi + FAIL "Results differ from expected" + fi + ) +} + +# $1: dtb file +# $2: out file +wrap_fdtdump () { + printf "wrap_fdtdump $1: " + local dtb="$1" + local out="$2" + ( + if $FDTDUMP ${dtb} 2>/dev/null >${out}; then + PASS + else + FAIL + fi + ) +} + run_dtc_test () { printf "dtc $*: " base_run_test wrap_test $VALGRIND $DTC "$@"
@@ -1125,6 +1159,11 @@ utilfdt_tests () { fdtdump_tests () { run_fdtdump_test "$SRCDIR/fdtdump.dts" + + base_run_test wrap_fdtdump unknown_tags_can_skip.dtb unknown_tags_can_skip.dtb.out + # Remove unneeded comments + sed -i.bak '/^\/\/ [^T]/d' unknown_tags_can_skip.dtb.out + base_run_test check_diff unknown_tags_can_skip.dtb.out "$SRCDIR/unknown_tags_can_skip.fdtdump.expect" } fdtoverlay_tests() {
tests/unknown_tags_can_skip.fdtdump.expect new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 16/22 libfdt: Handle unknown tags in fdt_next_tag()
In reply to Herve CodinaThe structured tag value definition introduced recently gives the ability to ignore unknown tags without any error when they are read.
libfdt uses the low-level function fdt_next_tag() to get a tag.
Make fdt_next_tag() return those unknown tags which can be skipped, and update callers to skip them.
--- libfdt/fdt.c | 46 +++++++++++++++++++++++++++++++++++- libfdt/fdt_check.c | 6 +++-- libfdt/fdt_ro.c | 2 +- tests/dtbs_equal_ordered.c | 48 +++++++++++++++++++++++++++++++++++--- tests/run_tests.sh | 36 +++++++++++++++++++++++++++- 5 files changed, 130 insertions(+), 8 deletions(-)
libfdt/fdt.c +45 -1
@@ -188,6 +188,37 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)return fdt_offset_ptr_limit_ (fdt,fdt_struct_limit_ (fdt), offset, len); } +static int fdt_get_structured_tag_data (uint32_t tag,const void *fdt,int limit, +int offset,uint32_t *data_len) +{ +int data_offset = offset; +uint32_t len =0 ; +const fdt32_t *lenp; + + len =FDT_TAG_DLEN_GET (tag); +if (len !=FDT_TAG_DLEN_VARLEN ) { + len *=sizeof (fdt32_t); + }else { +/* Get the length */ + lenp =fdt_offset_ptr_limit_ (fdt, limit, offset,sizeof (*lenp)); +if (!can_assume (VALID_DTB ) && !lenp) +return -FDT_ERR_BADSTRUCTURE ; + len =fdt32_to_cpu (*lenp); + +/* Skip the cell encoding the length */ + data_offset +=sizeof (*lenp); + } + +if ((data_offset <0 ) || (data_offset > limit) + || (len > (uint32_t )(limit - data_offset))) +return -FDT_ERR_BADSTRUCTURE ; + +if (data_len) + *data_len = len; + +return data_offset; +} +uint32_t fdt_next_tag (const void *fdt,int startoffset,int *nextoffset) {const fdt32_t *tagp, *lenp;
@@ -195,6 +226,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)int limit =fdt_struct_limit_ (fdt);int offset = startoffset;const char *p, *nul; +int data_offset; *nextoffset = -FDT_ERR_TRUNCATED ; tagp =fdt_offset_ptr_limit_ (fdt, limit, offset,FDT_TAGSIZE );
@@ -242,7 +274,18 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)break ;default : -return FDT_END ; +if (!FDT_TAG_IS_SKIPPABLE (tag)) +return FDT_END ; + +/* Retrieve the data block */ + data_offset =fdt_get_structured_tag_data (tag, fdt, limit, + offset, &len); +if (data_offset <0 ) +return FDT_END ;/* premature end */ + +/* Skip the whole data bloc */ + offset = data_offset + len; +break ; } if (!fdt_offset_ptr_limit_(fdt, limit, startoffset,
@@ -326,6 +369,7 @@ int fdt_next_node(const void *fdt, int offset, int *depth)switch (tag) {case FDT_PROP :case FDT_NOP : +default :/* All skippable tags */ break ;case FDT_BEGIN_NODE :
libfdt/fdt_check.c +4 -2
@@ -45,7 +45,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)return nextoffset;/* If we see two root nodes, something is wrong */ -if (expect_end && tag !=FDT_END && tag !=FDT_NOP ) +if (expect_end && tag !=FDT_END && tag !=FDT_NOP && + !FDT_TAG_IS_SKIPPABLE (tag))return -FDT_ERR_BADSTRUCTURE ;switch (tag) {
@@ -92,7 +93,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)break ;default : -return -FDT_ERR_INTERNAL ; +/* Skippable tags -> Skip them */ +break ; } } }
libfdt/fdt_ro.c +1 -1
@@ -229,7 +229,7 @@ static int nextprop_(const void *fdt, int offset)return offset; } offset = nextoffset; - }while (tag ==FDT_NOP ); + }while (tag ==FDT_NOP ||FDT_TAG_IS_SKIPPABLE (tag));return -FDT_ERR_NOTFOUND ; }
tests/dtbs_equal_ordered.c +45 -3
92 lines not on this page · raw message
tests/run_tests.sh +35 -1
@@ -471,6 +471,7 @@ ALL_LAYOUTS="mts mst tms tsm smt stm" libfdt_tests () { run_test root_offset 0 test_tree1.dtb run_test root_offset 12 root_offset_12.dtb + run_test root_offset 8 unknown_tags_can_skip.dtb tree1_tests test_tree1.dtb
@@ -616,13 +617,43 @@ libfdt_tests () { run_test dtbs_equal_ordered cell-overflow.test.dtb cell-overflow-results.test.dtb # check full tests - for good in test_tree1.dtb; do + for good in test_tree1.dtb unknown_tags_can_skip.dtb unknown_tags_removed.dtb; do run_test check_full $good done for bad in truncated_property.dtb truncated_string.dtb \ truncated_memrsv.dtb two_roots.dtb named_root.dtb; do run_test check_full -n $bad done + + for n in "node1" "node2" "node3" "node4" "node5" "node6" "node7" "node8" "node9"; do + # node8 is a subnodes-only node, node9 is an empty node + if [ "$n" != "node8" ] && [ "$n" != "node9" ]; then + for p in "prop1" "prop2" "prop3"; do + run_test check_full unknown_tags_rw_${n}_${p}_modified_ab.dtb + run_test check_full unknown_tags_rw_${n}_${p}_modified_abcdefgh.dtb + run_test check_full unknown_tags_rw_${n}_${p}_modified_abcdefghi.dtb + run_test check_full unknown_tags_rw_${n}_${p}_modified_abcdefghij.dtb + run_test check_full unknown_tags_rw_${n}_${p}_modified_abcdefghijklmnop.dtb + run_test check_full unknown_tags_rw_${n}_${p}_removed.dtb + + #run_test check_full unknown_tags_wip_${n}_${p}_modified_ab.dtb + #run_test check_full unknown_tags_wip_${n}_${p}_modified_abcdefgh.dtb + run_test check_full unknown_tags_wip_${n}_${p}_modified_abcdefghi.dtb + run_test check_full unknown_tags_wip_${n}_${p}_removed.dtb + done + fi + + # node7 is a properties-only node, node9 is an empty node + if [ "$n" != "node7" ] && [ "$n" != "node9" ]; then + for sn in "subnode1" "subnode2" "subnode3"; do + run_test check_full unknown_tags_rw_${n}_${sn}_removed.dtb + run_test check_full unknown_tags_wip_${n}_${sn}_removed.dtb + done + fi + + run_test check_full unknown_tags_rw_${n}_propnew_added.dtb + run_test check_full unknown_tags_rw_${n}_subnodenew_added.dtb + done } dtc_tests () {
@@ -1055,6 +1086,9 @@ fdtget_tests () { run_fdtget_test "<the dead silence>" -tx \ -d "<the dead silence>" $dtb /randomnode doctor-who run_fdtget_test "<blink>" -tx -d "<blink>" $dtb /memory doctor-who + + # test with unknown tags involved + run_fdtget_test "123456789" unknown_tags_can_skip.dtb /node4 prop2 } fdtput_tests () {
Signature · 1 line
2.56.1
PATCH v4 17/22 flattree: Handle unknown tags
In reply to Herve CodinaThe structured tag value definition introduced recently gives the ability to ignore unknown tags without any error when they are read.
Handle those structured tags.
--- flattree.c | 69 +++++++++++++++++++++++++++++++++++++++++++--- tests/run_tests.sh | 4 +++ 2 files changed, 69 insertions(+), 4 deletions(-)
flattree.c +65 -4
@@ -580,7 +580,8 @@ static void flat_read_chunk(struct inbuf *inb, void *p, int len)if ((inb->ptr + len) > inb->limit)die ("Premature end of data parsing flat device tree\n" ); -memcpy (p, inb->ptr, len); +if (p) +memcpy (p, inb->ptr, len); inb->ptr += len; }
@@ -605,6 +606,66 @@ static void flat_realign(struct inbuf *inb, int align)die ("Premature end of data parsing flat device tree\n" ); } +static void flat_read_structured_tag_data (struct inbuf *inb,uint32_t tag, +struct inbuf *databuf) +{ +uint32_t len; + + len =FDT_TAG_DLEN_GET (tag); +if (len !=FDT_TAG_DLEN_VARLEN ) { + len *=sizeof (fdt32_t); + }else { +/* Get the length */ + len =flat_read_word (inb); + } + +/* +* Put the data (len bytes) in databuf if provided. +* No need to check the validity of the inb ptr + len against the inb +* limit. This will be check in the following chunk read. +*/ +if (databuf) +inbuf_init (databuf, inb->ptr, inb->ptr + len); + +/* Skip the following data (len bytes + padding) from inb */ +if (len) { +flat_read_chunk (inb,NULL , len); +flat_realign (inb,sizeof (uint32_t )); + } +} + +static bool flat_skip_unknown_tag (struct inbuf *inb,uint32_t tag) +{ +if (!FDT_TAG_IS_SKIPPABLE (tag)) +return false; + +/* Read tag related data */ +flat_read_structured_tag_data (inb, tag,NULL ); + +return true; +} + +static uint32_t flat_read_tag (struct inbuf *inb) +{ +uint32_t tag; + +do { + tag =flat_read_word (inb); +switch (tag) { +case FDT_BEGIN_NODE : +case FDT_END_NODE : +case FDT_PROP : +case FDT_NOP : +case FDT_END : +return tag; +default : +break ; + } + }while (flat_skip_unknown_tag (inb, tag)); + +die ("Cannot skip unknown tag 0x%08x\n" , tag); +} +static const char *flat_read_string (struct inbuf *inb) {int len =0 ;
@@ -754,7 +815,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,struct property *prop;struct node *child; - val =flat_read_word (dtbuf); + val =flat_read_tag (dtbuf);switch (val) {case FDT_PROP :if (node->children)
@@ -911,7 +972,7 @@ struct dt_info *dt_from_blob(const char *fname)/* Skip possible FDT_NOP available before the root node */ do { - val =flat_read_word (&dtbuf); + val =flat_read_tag (&dtbuf); }while (val ==FDT_NOP );if (val !=FDT_BEGIN_NODE )die ("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\n" , val);
@@ -920,7 +981,7 @@ struct dt_info *dt_from_blob(const char *fname)/* Skip possible FDT_NOP available before FDT_END */ do { - val =flat_read_word (&dtbuf); + val =flat_read_tag (&dtbuf); }while (val ==FDT_NOP );if (val !=FDT_END )die ("Device tree blob doesn't end with FDT_END\n" );
tests/run_tests.sh +4 -0
@@ -1011,6 +1011,10 @@ dtc_tests () { # Tests for overlay/plugin generation dtc_overlay_tests + + # Tests with "unknown tags" + run_dtc_test -I dtb -O dtb -o unknown_tags_can_skip.dtb.dtb unknown_tags_can_skip.dtb + run_test dtbs_equal_ordered --noskip-nop unknown_tags_can_skip.dtb.dtb unknown_tags_removed.dtb } cmp_tests () {
Signature · 1 line
2.56.1
PATCH v4 18/22 libfdt: Introduce fdt_ptr_offset_()
In reply to Herve Codinalibfdt provides internal helpers to convert an offset to a pointer but nothing to perform the reverse operation.
Introduce the fdt_ptr_offset_() internal helper to convert a pointer to an offset.
--- libfdt/libfdt_internal.h | 5 +++++ 1 file changed, 5 insertions(+)
libfdt/libfdt_internal.h +5 -0
@@ -43,6 +43,11 @@ static inline void *fdt_offset_ptr_w_(void *fdt, int offset)return (void *)(uintptr_t )fdt_offset_ptr_ (fdt, offset); } +static inline int fdt_ptr_offset_ (const void *fdt,const void *ptr) +{ +return (const char *)ptr - (const char *)fdt_offset_ptr_ (fdt,0 ); +} +static inline const struct fdt_reserve_entry *fdt_mem_rsv_ (const void *fdt,int n) { const struct fdt_reserve_entry *rsv_table =
Signature · 1 line
2.56.1
PATCH v4 19/22 libfdt: Introduce fdt_getprop_by_offset_w()
In reply to Herve CodinaFuture operations, such as handling unknown tags on dtb modifications, need to modify properties retrieved by their offset.
fdt_getprop_by_offset() already exists to get a property by its offset but the property returned is read-only. A writable returned property is needed.
Fill the gap and introduce fdt_getprop_by_offset_w(), the write enabled variant of fdt_getprop_by_offset().
Also add its related test.
--- libfdt/libfdt.h | 6 +++ tests/.gitignore | 1 + tests/Makefile.tests | 2 +- tests/get_prop_offset_w.c | 78 +++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + tests/run_tests.sh | 1 + 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/get_prop_offset_w.c
libfdt/libfdt.h +6 -0
@@ -856,6 +856,12 @@ static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,#ifndef SWIG /* This function is not useful in Python */ const void *fdt_getprop_by_offset (const void *fdt,int offset,const char **namep,int *lenp); +static inline void *fdt_getprop_by_offset_w (const void *fdt,int offset, +const char **namep,int *lenp) +{ +return (void *)(uintptr_t )fdt_getprop_by_offset (fdt, offset, namep, + lenp); +}#endif /**
tests/.gitignore +1 -0
@@ -30,6 +30,7 @@ tmp.* /get_phandle /getprop /get_prop_offset +/get_prop_offset_w /incbin /integer-expressions /fs_tree1
tests/Makefile.tests +1 -1
@@ -16,7 +16,7 @@ LIB_TESTS_L = get_mem_rsv \ sw_tree1 sw_states \ move_and_save mangle-layout nopulate \ open_pack rw_tree1 rw_oom set_name setprop del_property del_node \ - appendprop1 appendprop2 propname_escapes \ + appendprop1 appendprop2 propname_escapes get_prop_offset_w \ string_escapes references path-references phandle_format \ boot-cpuid incbin relref_merge \ extra-terminating-null \
tests/get_prop_offset_w.c new file +78 -0
78 lines not on this page · raw message
tests/meson.build +1 -0
@@ -284,6 +284,7 @@ tests = [ 'get_path', 'get_phandle', 'get_prop_offset', + 'get_prop_offset_w', 'get_next_tag_invalid_prop_len', 'getprop', 'incbin',
tests/run_tests.sh +1 -0
@@ -445,6 +445,7 @@ tree1_tests () { run_test setprop_inplace $TREE run_test nop_property $TREE run_test nop_node $TREE + run_test get_prop_offset_w $TREE } tree1_tests_rw () {
Signature · 1 line
2.56.1
PATCH v4 20/22 tests: Add wip_func utility
In reply to Herve Codinawip_func is a test utility allowing to wrap the write-in-place functions.
It allows creating tests with a custom write-in-place sequence.
Also, the modified dtb is saved, allowing later checks on it.
--- tests/.gitignore | 1 + tests/Makefile.tests | 3 +- tests/meson.build | 1 + tests/wip_func.c | 127 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/wip_func.c
tests/.gitignore +1 -0
@@ -78,4 +78,5 @@ tmp.* /unterminated_memrsv /utilfdt_test /value-labels +/wip_func /get_next_tag_invalid_prop_len
tests/Makefile.tests +2 -1
@@ -31,7 +31,8 @@ LIB_TESTS_L = get_mem_rsv \ check_path check_header check_full \ fs_tree1 \ truncated_property truncated_string \ - truncated_memrsv unterminated_memrsv + truncated_memrsv unterminated_memrsv \ + wip_func LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) ifneq ($(STATIC_BUILD),1)
tests/meson.build +1 -0
@@ -331,6 +331,7 @@ tests = [ 'truncated_string', 'unterminated_memrsv', 'utilfdt_test', + 'wip_func', ] test_deps = [testutil_dep, util_dep, libfdt_dep]
tests/wip_func.c new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 21/22 libfdt: Handle unknown tags on dtb modifications
In reply to Herve CodinaThe structured tag value definition introduced recently gives the ability to ignore unknown tags without any error.
When the dtb is modified, those unknown tags have to be taken into account.
First, depending on the unknown tag location, the item associated with the tag is identified:
- An unknown tag located just after an FDT_BEGIN_NODE is related to the node.
- An unknown tag located just after an FDT_PROP is related to the property.
- An unknown tag outside any node (i.e. located before the first FDT_BEGIN_NODE or after the last FDT_END_NODE) is a global tag related to the dtb itself.
Then, when we perform modifications in a dtb containing unknown tags, the following rules apply:
| existing prop | existing node (1) | Downgrade
| unknown tag | unknown tag | version (2)
----------------------+---------------+-------------------+-----------
Modify a property (4) | Remove | Keep (3) | Yes
Add a property | NA | Remove | Yes
Delete a property | Remove | Remove | Yes
Add a sub-node | NA | Remove | Yes
Delete a sub-node | NA | Remove | Yes----------------------+---------------+-------------------+-----------
(1) The existing node is the node where the property or sub-node involved is present. Not all nodes, not the parent node but the node directly impacted by the modification.
(2) The version is always downgraded on any change (modification, addition, deletion of a property or a sub-node) even if no tags are removed.
(3) Removing unknown tags in the node when a property is modified will change the property offset. Avoid this property offset change and so keep node related unknown tags in that case.
(4) All property modifications done outside libfdt using the property data pointer directly will not lead to any unknown tag removal. Some libfdt API functions allow getting a pointer to property data. Property data modification using this pointer directly is considered a modification outside libfdt.
Implement those rules when a dtb is modified.
--- libfdt/fdt.c | 73 +++++++++++++++++ libfdt/fdt_ro.c | 12 +-- libfdt/fdt_rw.c | 173 ++++++++++++++++++++++++++++++++++++--- libfdt/fdt_wip.c | 115 +++++++++++++++++++++++--- libfdt/libfdt_internal.h | 19 +++++ tests/run_tests.sh | 86 +++++++++++++++++++ 6 files changed, 451 insertions(+), 27 deletions(-)
libfdt/fdt.c +73 -0
@@ -296,6 +296,21 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)return tag; } +static bool fdt_tag_is_unknown (uint32_t tag) +{ +switch (tag) { +case FDT_BEGIN_NODE : +case FDT_END_NODE : +case FDT_PROP : +case FDT_NOP : +case FDT_END : +return false; +default : +break ; + } +return true; +} +int fdt_root_offset (const void *fdt) {int nextoffset =0 ;
@@ -455,3 +470,61 @@ int fdt_move(const void *fdt, void *buf, int bufsize)memmove (buf, fdt,fdt_totalsize (fdt));return 0 ; } + +void fdt_downgrade_version (void *fdt) +{ +/* +* Don't use can_assume(LATEST) to conditionally perform the operation. +* +* The version must be downgraded if we encounter a future dtb not yet +* known. In that case even if compiled with ASSUME_LATEST, this +* future dtb proves that we are no more the latest version. +*/ +if (fdt_version (fdt) >FDT_LAST_SUPPORTED_VERSION ) +fdt_set_version (fdt,FDT_LAST_SUPPORTED_VERSION ); +} + +int fdt_remove_unknown_tags_at (void *fdt,int start_offset, +int (*eraser)(void *fdt,int offset,int len)) +{ +int nextoffset = start_offset; +uint32_t tag; +int offset; + +/* Look at unknown tags starting at start_offset */ +do { + offset = nextoffset; + tag =fdt_next_tag (fdt, offset, &nextoffset); +if (tag ==FDT_END ) { +/* +* We can remove unknown tags after a node, FDT_END can +* be found. +*/ +return nextoffset <0 ? nextoffset :0 ; + } + +/* Remove unknown tag */ +if (FDT_TAG_IS_SKIPPABLE (tag) &&fdt_tag_is_unknown (tag)) { + nextoffset = (*eraser)(fdt, offset, nextoffset - offset); +if (nextoffset <0 ) +return nextoffset; + } + + }while ((tag !=FDT_PROP ) && (tag !=FDT_BEGIN_NODE ) && + (tag !=FDT_END_NODE )); + +return 0 ; +} + +int fdt_remove_unknown_tags_after (void *fdt,int offset, +int (*eraser)(void *fdt,int offset,int len)) +{ +int nextoffset; +uint32_t tag; + + tag =fdt_next_tag (fdt, offset, &nextoffset); +if (tag ==FDT_END ) +return nextoffset <0 ? nextoffset :0 ; + +return fdt_remove_unknown_tags_at (fdt, nextoffset, eraser); +}
libfdt/fdt_ro.c +6 -6
@@ -415,12 +415,12 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,return fdt_get_property_by_offset_ (fdt, offset, lenp); } -static const struct fdt_property *fdt_get_property_namelen_ (const void *fdt, -int offset, -const char *name, -int namelen, -int *lenp, -int *poffset) +const struct fdt_property *fdt_get_property_namelen_ (const void *fdt, +int offset, +const char *name, +int namelen, +int *lenp, +int *poffset) { for (offset = fdt_first_property_offset(fdt, offset); (offset >= 0);
libfdt/fdt_rw.c +162 -11
283 lines not on this page · raw message
libfdt/fdt_wip.c +105 -10
165 lines not on this page · raw message
libfdt/libfdt_internal.h +19 -0
@@ -23,6 +23,25 @@ int32_t fdt_ro_probe_(const void *fdt);int fdt_check_node_offset_ (const void *fdt,int *offset);int fdt_check_prop_offset_ (const void *fdt,int offset); +const struct fdt_property *fdt_get_property_namelen_ (const void *fdt, +int offset, +const char *name, +int namelen, +int *lenp, +int *poffset); + +/* +* The 'eraser' have to erase the area of length @len starting at the given +* @offset. It must returns the offset pointing right after the area erased. +* or a negative error code value. +*/ +int fdt_remove_unknown_tags_at (void *fdt,int offset, +int (*eraser)(void *fdt,int offset,int len)); +int fdt_remove_unknown_tags_after (void *fdt,int offset, +int (*eraser)(void *fdt,int offset,int len)); + +void fdt_downgrade_version (void *fdt); +const char *fdt_find_string_len_ (const char *strtab,int tabsize,const char *s,int s_len); static inline const char *fdt_find_string_(const char *strtab, int tabsize,
tests/run_tests.sh +86 -0
98 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v4 22/22 Introduce v18 dtb version
In reply to Herve CodinaThis v18 version adds support for
- Structured tags.
Those tag value definitions will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb versions.
libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbs generated with later versions of dtc.
- dt_flags header field.
For now, this flag field is set to 0. It is a placeholder for future dtb versions and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.
--- dtc.h | 2 +- fdtdump.c | 6 +++++- flattree.c | 17 +++++++++++++++-- libfdt/fdt.c | 6 ++++-- libfdt/fdt.h | 4 ++++ libfdt/fdt_rw.c | 14 ++++++++++++-- libfdt/fdt_sw.c | 2 ++ libfdt/libfdt.h | 4 +++- pylibfdt/libfdt.i | 9 +++++++++ tests/Makefile.tests | 1 + tests/dtflags_default.dts | 10 ++++++++++ tests/meson.build | 1 + tests/pylibfdt_tests.py | 9 +++++---- tests/run_tests.sh | 7 ++++++- tests/testutils.c | 2 +- tests/treegen.c | 3 ++- tests/treegen_base.c | 39 +++++++++++++++++++++++++++++++++++++++ 17 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 tests/dtflags_default.dts
dtc.h +1 -1
@@ -25,7 +25,7 @@#define debug (...)#endif -#define DEFAULT_FDT_VERSION 17 +#define DEFAULT_FDT_VERSION 18/* * Command line options
fdtdump.c +5 -1
@@ -17,7 +17,7 @@#include "util.h" #define FDT_MAGIC_SIZE 4 -#define MAX_VERSION 17U +#define MAX_VERSION 18U#define ALIGN (x, a) (((x) + ((a) - 1)) & ~((a) - 1))#define PALIGN (p, a) ((void *)(ALIGN((uintptr_t)(p), (a))))
@@ -114,6 +114,10 @@ static void dump_blob(void *blob, bool debug)if (version >=17 )printf ("// size_dt_struct:\t0x%" PRIx32"\n" ,fdt32_to_cpu (bph->size_dt_struct)); +if (version >=18 ) { +printf ("// dt_flags:\t\t0x%" PRIx32"\n" , +fdt32_to_cpu (bph->dt_flags)); + }printf ("\n" );for (i =0 ; ; i++) {
flattree.c +15 -2
@@ -14,6 +14,7 @@#define FTF_STRTABSIZE 0x10#define FTF_STRUCTSIZE 0x20#define FTF_NOPS 0x40 +#define FTF_DTFLAGS 0x80 static struct version_info { int version;
@@ -31,6 +32,8 @@ static struct version_info { FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS}, {17 ,16 ,FDT_V17_SIZE , FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, + {18, 16, FDT_V18_SIZE, + FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_DTFLAGS}, }; struct emitter {
@@ -315,7 +318,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,static void make_fdt_header (struct fdt_header *fdt,struct version_info *vi,int reservesize,int dtsize,int strsize, -int boot_cpuid_phys) +int boot_cpuid_phys,uint32_t dt_flags) {int reserve_off;
@@ -342,6 +345,8 @@ static void make_fdt_header(struct fdt_header *fdt, fdt->size_dt_strings =cpu_to_fdt32 (strsize);if (vi->flags &FTF_STRUCTSIZE ) fdt->size_dt_struct =cpu_to_fdt32 (dtsize); +if (vi->flags &FTF_DTFLAGS ) + fdt->dt_flags =cpu_to_fdt32 (dt_flags); }void dt_to_blob (FILE *f,struct dt_info *dti,int version)
@@ -369,7 +374,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)/* Make header */ make_fdt_header (&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, - dti->boot_cpuid_phys); + dti->boot_cpuid_phys,0 );/* * If the user asked for more space than is used, adjust the totalsize.
@@ -500,6 +505,11 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version) symprefix, symprefix); } +if (vi->flags &FTF_DTFLAGS ) { +fprintf (f,"\t/* dt_flags */\n" ); +asm_emit_cell (f,0 ); + } +/* * Reserve map entries. * Align the reserve map to a doubleword boundary.
@@ -964,6 +974,9 @@ struct dt_info *dt_from_blob(const char *fname) flags |=FTF_NOPS ; } +if (version >=18 ) + flags |=FTF_DTFLAGS ; +inbuf_init (&memresvbuf, blob + off_mem_rsvmap, blob + totalsize);inbuf_init (&dtbuf, blob + off_dt, blob + totalsize);
libfdt/fdt.c +4 -2
@@ -76,13 +76,15 @@ size_t fdt_header_size_(uint32_t version)return FDT_V3_SIZE ; else if (version <= 16) return FDT_V16_SIZE; - else + else if (version <= 17) return FDT_V17_SIZE; + else + return FDT_V18_SIZE; } size_t fdt_header_size(const void *fdt) { -return can_assume (LATEST ) ?FDT_V17_SIZE : +return can_assume (LATEST ) ?FDT_V18_SIZE :fdt_header_size_ (fdt_version (fdt)); }
libfdt/fdt.h +4 -0
@@ -26,6 +26,9 @@ struct fdt_header {/* version 17 fields below */ fdt32_t size_dt_struct;/* size of the structure block */ + +/* version 18 fields below */ +fdt32_t dt_flags;/* Ored value of FDT_FLAG_XXXX */ };struct fdt_reserve_entry {
@@ -138,5 +141,6 @@ struct fdt_property {#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))#define FDT_V16_SIZE FDT_V3_SIZE#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) +#define FDT_V18_SIZE (FDT_V17_SIZE + sizeof(fdt32_t))#endif /* FDT_H */
libfdt/fdt_rw.c +12 -2
@@ -628,6 +628,7 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)int newsize;const char *fdtstart = fdt;const char *fdtend = fdtstart +fdt_totalsize (fdt); +uint32_t dt_flags;char *tmp;FDT_RO_PROBE (fdt);
@@ -637,6 +638,11 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)return err; mem_rsv_size = (err +1 ) *sizeof (struct fdt_reserve_entry ); +if (can_assume (LATEST ) ||fdt_version (fdt) >=18 ) + dt_flags =fdt_dt_flags (fdt); +else + dt_flags =0 ; +if (can_assume (LATEST ) ||fdt_version (fdt) >=17 ) { struct_size =fdt_size_dt_struct (fdt); }else if (fdt_version (fdt) ==16 ) {
@@ -655,7 +661,10 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize) err =fdt_move (fdt, buf, bufsize);if (err)return err; -fdt_set_version (buf,17 ); +if (can_assume (LATEST ) ||fdt_version (fdt) <18 ) { +fdt_set_version (buf,18 ); +fdt_set_dt_flags (buf, dt_flags); + }fdt_set_size_dt_struct (buf, struct_size);fdt_set_totalsize (buf, bufsize);return 0 ;
@@ -684,8 +693,9 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)fdt_set_magic (buf,FDT_MAGIC );fdt_set_totalsize (buf, bufsize); -fdt_set_version (buf,17 ); +fdt_set_version (buf,18 );fdt_set_last_comp_version (buf,16 ); +fdt_set_dt_flags (buf, dt_flags);fdt_set_boot_cpuid_phys (buf,fdt_boot_cpuid_phys (fdt));return 0 ;
libfdt/fdt_sw.c +2 -0
@@ -137,6 +137,8 @@ int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)fdt_set_off_dt_struct (fdt,fdt_off_mem_rsvmap (fdt));fdt_set_off_dt_strings (fdt,0 ); +fdt_set_dt_flags (fdt,0 ); +return 0 ; }
libfdt/libfdt.h +3 -1
@@ -15,7 +15,7 @@ extern "C" {#define FDT_FIRST_SUPPORTED_VERSION 0x02#define FDT_LAST_COMPATIBLE_VERSION 0x10 -#define FDT_LAST_SUPPORTED_VERSION 0x11 +#define FDT_LAST_SUPPORTED_VERSION 0x12/* Error codes: informative error codes */ #define FDT_ERR_NOTFOUND 1
@@ -284,6 +284,7 @@ int fdt_next_subnode(const void *fdt, int offset);#define fdt_boot_cpuid_phys (fdt) (fdt_get_header(fdt, boot_cpuid_phys))#define fdt_size_dt_strings (fdt) (fdt_get_header(fdt, size_dt_strings))#define fdt_size_dt_struct (fdt) (fdt_get_header(fdt, size_dt_struct)) +#define fdt_dt_flags (fdt) (fdt_get_header(fdt, dt_flags))#define fdt_set_hdr_ (name) \ static inline void fdt_set_##name(void *fdt, uint32_t val) \
@@ -301,6 +302,7 @@ fdt_set_hdr_(last_comp_version) fdt_set_hdr_(boot_cpuid_phys) fdt_set_hdr_(size_dt_strings) fdt_set_hdr_(size_dt_struct) +fdt_set_hdr_(dt_flags)#undef fdt_set_hdr_/**
pylibfdt/libfdt.i +9 -0
@@ -298,6 +298,14 @@ class FdtRo(object): """ return fdt_size_dt_struct(self._fdt) + def dt_flags(self): + """Return flags from the header + + Returns: + flags value from the header + """ + return fdt_dt_flags(self._fdt) + def num_mem_rsv(self, quiet=()): """Return the number of memory reserve-map records
@@ -1411,6 +1419,7 @@ uint32_t fdt_last_comp_version(const void *fdt); uint32_t fdt_boot_cpuid_phys(const void *fdt); uint32_t fdt_size_dt_strings(const void *fdt); uint32_t fdt_size_dt_struct(const void *fdt); +uint32_t fdt_dt_flags(const void *fdt); int fdt_property_string(void *fdt, const char *name, const char *val); int fdt_property_cell(void *fdt, const char *name, uint32_t val);
tests/Makefile.tests +1 -0
@@ -46,6 +46,7 @@ TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ truncated_string.dtb truncated_memrsv.dtb unterminated_memrsv.dtb \ two_roots.dtb named_root.dtb root_offset_12.dtb bad_proplen.dtb \ + dtflags_default.dtb \ unknown_tags_can_skip.dtb \ unknown_tags_removed.dtb \ unknown_tags_rw_node1_prop1_modified_ab.dtb \
tests/dtflags_default.dts new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + prop = <1>; +};
tests/meson.build +1 -0
@@ -23,6 +23,7 @@ treegen_dtb = custom_target( 'named_root.dtb', 'root_offset_12.dtb', 'bad_proplen.dtb', + 'dtflags_default.dtb', 'unknown_tags_can_skip.dtb', 'unknown_tags_removed.dtb', 'unknown_tags_rw_node1_prop1_modified_ab.dtb',
tests/pylibfdt_tests.py +5 -4
@@ -301,10 +301,10 @@ class PyLibfdtBasicTests(unittest.TestCase): """Test that we can access the header values""" self.assertEqual(self.fdt.magic(), 0xd00dfeed) self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt)) - self.assertEqual(self.fdt.off_dt_struct(), 88) - self.assertEqual(self.fdt.off_dt_strings(), 652) - self.assertEqual(self.fdt.off_mem_rsvmap(), 40) - self.assertEqual(self.fdt.version(), 17) + self.assertEqual(self.fdt.off_dt_struct(), 96) + self.assertEqual(self.fdt.off_dt_strings(), 660) + self.assertEqual(self.fdt.off_mem_rsvmap(), 48) + self.assertEqual(self.fdt.version(), 18) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) self.fdt.set_boot_cpuid_phys(0x42)
@@ -312,6 +312,7 @@ class PyLibfdtBasicTests(unittest.TestCase): self.fdt.set_boot_cpuid_phys(0) self.assertEqual(self.fdt.size_dt_strings(), 105) self.assertEqual(self.fdt.size_dt_struct(), 564) + self.assertEqual(self.fdt.dt_flags(), 0) def testPack(self): """Test that we can pack the tree after deleting something"""
tests/run_tests.sh +6 -1
@@ -618,7 +618,8 @@ libfdt_tests () { run_test dtbs_equal_ordered cell-overflow.test.dtb cell-overflow-results.test.dtb # check full tests - for good in test_tree1.dtb unknown_tags_can_skip.dtb unknown_tags_removed.dtb; do + for good in test_tree1.dtb unknown_tags_can_skip.dtb unknown_tags_removed.dtb \ + dtflags_default.dtb; do run_test check_full $good done for bad in truncated_property.dtb truncated_string.dtb \
@@ -1053,6 +1054,10 @@ dtc_tests () { # Tests with "unknown tags" run_dtc_test -I dtb -O dtb -o unknown_tags_can_skip.dtb.dtb unknown_tags_can_skip.dtb run_test dtbs_equal_ordered --noskip-nop unknown_tags_can_skip.dtb.dtb unknown_tags_removed.dtb + + # Tests dt_flags header field (default value) + run_dtc_test -I dts -O dtb -o dtflags_default.dts.dtb "$SRCDIR/dtflags_default.dts" + run_test dtbs_equal_ordered dtflags_default.dts.dtb dtflags_default.dtb } cmp_tests () {
tests/testutils.c +1 -1
@@ -338,7 +338,7 @@ void *open_blob_rw(const void *blob) {int err;void *buf; -int newsize =fdt_totalsize (blob) +8 ; +int newsize =fdt_totalsize (blob) +8 +4 ; buf =xmalloc (newsize); err =fdt_open_into (blob, buf, newsize);
tests/treegen.c +2 -1
@@ -108,12 +108,13 @@ size_t emit_fdt_header_vers(struct buf *b, uint32_t version,emit_u32 (b,0 );/* boot_cpuid_phys */ emit_u32 (b,0 );/* size_dt_strings */ emit_u32 (b,0 );/* size_dt_struct */ +emit_u32 (b,0 );/* dt_flags */ return off; }size_t emit_fdt_header (struct buf *b) { -return emit_fdt_header_vers (b,0x11 ,0x10 ); +return emit_fdt_header_vers (b,0x12 ,0x10 ); }void finish_rsvmap (struct buf *b,size_t hdr,size_t rsvmap)
tests/treegen_base.c +39 -0
@@ -533,6 +533,44 @@ static struct buf make_bad_proplen(void)return b; } +/* Tree matching dtflags_default.dts */ +static struct buf make_dtflags_default (void ) +{ +struct buf b =buf_init (); +size_t hdr; +size_t p; + + hdr =emit_fdt_header (&b); +emit_align (&b,8 ); + +emit_rsvmap_empty (&b, hdr); + + { +size_t ss =start_block (&b); + +emit_begin_node (&b,"" ); + p =emit_prop_u32 (&b,0 ,1 ); +emit_end_node (&b); +emit_fdt_end (&b); + +finish_struct_block (&b, hdr, ss); + } + + { +size_t strs =start_block (&b); +size_t s; + + s =emit_string (&b,"prop" ); +fill_prop_name (&b, strs, p, s); + +finish_strings_block (&b, hdr, strs); + } + +finish_totalsize (&b, hdr); + +return b; +} +/* Tree generators */ static const struct treegen treegens[] = {TREE (test_tree1),
@@ -545,6 +583,7 @@ static const struct treegen treegens[] = {TREE (named_root),TREE (root_offset_12),TREE (bad_proplen), + TREE(dtflags_default), };/* Harness */
Signature · 1 line
2.56.1