From b99353474850969a1f856d344d273325ddb069c7 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 4 Jul 2019 14:39:02 +1000 Subject: [PATCH] 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 --- libfdt/fdt_overlay.c | 17 +++++++++++------ tests/run_tests.sh | 12 ++++++++++++ tests/stacked_overlay_addlabel.dts | 13 +++++++++++++ tests/stacked_overlay_base_nolabel.dts | 6 ++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/stacked_overlay_addlabel.dts create mode 100644 tests/stacked_overlay_base_nolabel.dts 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: //__overlay__/ */ - 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)) { + /* //__overlay__/ */ + rel_path = s + len; + rel_path_len = e - rel_path; + } else if ((e - s) == len + && (memcmp(s, "/__overlay__", len - 1) == 0)) { + /* //__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"; + }; +};