diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2019-07-04 14:39:02 +1000 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2019-07-04 14:39:02 +1000 |
commit | b99353474850969a1f856d344d273325ddb069c7 (patch) | |
tree | 3acfbf1226303aa6580e5ddbda23ef5e02eb46ab | |
parent | d6de81b81b68f9e559adf42366574233be338fd8 (diff) | |
download | dtc-b99353474850969a1f856d344d273325ddb069c7.zip dtc-b99353474850969a1f856d344d273325ddb069c7.tar.gz dtc-b99353474850969a1f856d344d273325ddb069c7.tar.bz2 |
fdtoverlay: Allow adding labels to __overlay__ nodes in overlays
When applying overlays, we merge symbols from the overlay into the target
tree. At the moment the logic for this assumes all symbols in the overlay
are attached to a node of the form:
/fragment@XXX/__overlay__/relative/path
And will end up applied to the relative/path node under the fragment's
target.
However, this disallows the case of a symbol in the form just:
/fragment@XXX/__overlay__
This does have a pretty obvious sensible meaning: attach the new symbol
directly to the fragment's target, but we don't currently do that.
It's pretty easy to workaround this limitation in one's overlays, but it's
also easy to handle in the overlay applying code, so we might as well
extend it to cover this case.
Reported-by: Christophe Braillon
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | libfdt/fdt_overlay.c | 17 | ||||
-rwxr-xr-x | tests/run_tests.sh | 12 | ||||
-rw-r--r-- | tests/stacked_overlay_addlabel.dts | 13 | ||||
-rw-r--r-- | tests/stacked_overlay_base_nolabel.dts | 6 |
4 files changed, 42 insertions, 6 deletions
diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c index e97f12b..7fbf58c 100644 --- a/libfdt/fdt_overlay.c +++ b/libfdt/fdt_overlay.c @@ -733,8 +733,6 @@ static int overlay_symbol_update(void *fdt, void *fdto) /* keep end marker to avoid strlen() */ e = path + path_len; - /* format: /<fragment-name>/__overlay__/<relative-subnode-path> */ - if (*path != '/') return -FDT_ERR_BADVALUE; @@ -748,11 +746,18 @@ static int overlay_symbol_update(void *fdt, void *fdto) /* verify format; safe since "s" lies in \0 terminated prop */ len = sizeof("/__overlay__/") - 1; - if ((e - s) < len || memcmp(s, "/__overlay__/", len)) + if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) { + /* /<fragment-name>/__overlay__/<relative-subnode-path> */ + rel_path = s + len; + rel_path_len = e - rel_path; + } else if ((e - s) == len + && (memcmp(s, "/__overlay__", len - 1) == 0)) { + /* /<fragment-name>/__overlay__ */ + rel_path = ""; + rel_path_len = 0; + } else { return -FDT_ERR_BADOVERLAY; - - rel_path = s + len; - rel_path_len = e - rel_path; + } /* find the fragment index in which the symbol lies */ ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d368ad5..2620332 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -949,6 +949,18 @@ fdtoverlay_tests() { # test that fdtoverlay manages to apply overlays with long target path run_fdtoverlay_test lpath "/test-node/sub-test-node/sub-test-node-with-very-long-target-path/test-0" "prop" "-ts" ${basedtb} ${target_long_pathdtb} ${overlay_long_pathdtb} + + # test adding a label to the root of a fragment + stacked_base_nolabel=stacked_overlay_base_nolabel.dts + stacked_base_nolabeldtb=stacked_overlay_base_nolabel.test.dtb + stacked_addlabel=stacked_overlay_addlabel.dts + stacked_addlabeldtb=stacked_overlay_addlabel.test.dtb + stacked_addlabel_targetdtb=stacked_overlay_target_nolabel.fdtoverlay.test.dtb + + run_dtc_test -@ -I dts -O dtb -o $stacked_base_nolabeldtb $stacked_base_nolabel + run_dtc_test -@ -I dts -O dtb -o $stacked_addlabeldtb $stacked_addlabel + + run_fdtoverlay_test baz "/foonode/barnode/baznode" "baz-property" "-ts" ${stacked_base_nolabeldtb} ${stacked_addlabel_targetdtb} ${stacked_addlabeldtb} ${stacked_bardtb} ${stacked_bazdtb} } pylibfdt_tests () { diff --git a/tests/stacked_overlay_addlabel.dts b/tests/stacked_overlay_addlabel.dts new file mode 100644 index 0000000..e5c158f --- /dev/null +++ b/tests/stacked_overlay_addlabel.dts @@ -0,0 +1,13 @@ +/dts-v1/; +/plugin/; +/ { + fragment@1 { + target-path = "/foonode"; + foo: __overlay__ { + overlay-1-property; + bar: barnode { + bar-property = "bar"; + }; + }; + }; +}; diff --git a/tests/stacked_overlay_base_nolabel.dts b/tests/stacked_overlay_base_nolabel.dts new file mode 100644 index 0000000..0c47f0d --- /dev/null +++ b/tests/stacked_overlay_base_nolabel.dts @@ -0,0 +1,6 @@ +/dts-v1/; +/ { + foonode { + foo-property = "foo"; + }; +}; |