[PATCH v4 06/22] dtc: Skip possible FDT_NOP before the root node and before FDT_END tag
From: Herve Codina
Date: Thu Nov 26 2026 - 06:25:17 EST
dtc 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.
Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
---
flattree.c | 11 ++++++++---
tests/run_tests.sh | 5 +++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/flattree.c b/flattree.c
index 14546f96..b7d81d60 100644
--- a/flattree.c
+++ b/flattree.c
@@ -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");
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 65ea5894..a9be92a9 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -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
--
2.56.1