All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: David Gibson <david@gibson.dropbear.id.au>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Frank Li <Frank.Li@nxp.com>,
	David Lechner <dlechner@baylibre.com>,
	Ayush Singh <ayush@beagleboard.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree-spec@vger.kernel.org,
	Hui Pu <hui.pu@gehealthcare.com>,
	Ian Ray <ian.ray@gehealthcare.com>,
	Luca Ceresoli <luca.ceresoli@bootlin.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Herve Codina <herve.codina@bootlin.com>
Subject: [PATCH v4 15/22] fdtdump: Handle unknown tags
Date: Thu, 26 Nov 2026 12:22:32 +0100	[thread overview]
Message-ID: <20261126112239.636284-16-herve.codina@bootlin.com> (raw)
In-Reply-To: <20261126112239.636284-1-herve.codina@bootlin.com>

The 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.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
 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

diff --git a/fdtdump.c b/fdtdump.c
index 2f219676..91759973 100644
--- a/fdtdump.c
+++ b/fdtdump.c
@@ -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);
 	}
 }
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index a9be92a9..6472c86d 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -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() {
diff --git a/tests/unknown_tags_can_skip.fdtdump.expect b/tests/unknown_tags_can_skip.fdtdump.expect
new file mode 100644
index 00000000..8c5809e1
--- /dev/null
+++ b/tests/unknown_tags_can_skip.fdtdump.expect
@@ -0,0 +1,228 @@
+/dts-v1/;
+
+// Tag: 0x8007ffff, data len 4 00000001
+/ {
+    // Tag: 0x8003ffff, data len 0
+    info = "!! Unknown tags are present here and there !!";
+    // Tag: 0x8007ffff, data len 4 00000002
+    // Tag: 0x800bffff, data len 8 0000000300000003
+    // Tag: 0x80ffffff, data len 3 040404
+    node1 {
+        prop1 = "123456789";
+        prop2 = "123456789";
+        prop3 = "123456789";
+        subnode1 {
+            prop;
+        };
+        subnode2 {
+            prop;
+        };
+        subnode3 {
+            prop;
+        };
+    };
+    node2 {
+        prop1 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop2 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop3 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        subnode1 {
+            prop;
+        };
+        subnode2 {
+            prop;
+        };
+        subnode3 {
+            prop;
+        };
+    };
+    node3 {
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // Tag: 0x8007ffff, data len 4 00000011
+        prop1 = "123456789";
+        prop2 = "123456789";
+        prop3 = "123456789";
+        subnode1 {
+            prop;
+        };
+        subnode2 {
+            prop;
+        };
+        subnode3 {
+            prop;
+        };
+    };
+    node4 {
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // Tag: 0x8007ffff, data len 4 00000011
+        prop1 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop2 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop3 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        subnode1 {
+            prop;
+        };
+        subnode2 {
+            prop;
+        };
+        subnode3 {
+            prop;
+        };
+    };
+    node5 {
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // Tag: 0x8007ffff, data len 4 00000011
+        prop1 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop2 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        prop3 = "123456789";
+        // Tag: 0x8003ffff, data len 0
+        // Tag: 0x80ffffff, data len 3 202020
+        // Tag: 0x8007ffff, data len 4 00000021
+        subnode1 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode2 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode3 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+    };
+    node6 {
+        // [NOP]
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000011
+        // [NOP]
+        prop1 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+        prop2 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+        prop3 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+        subnode1 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode2 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode3 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+    };
+    node7 {
+        // [NOP]
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000011
+        // [NOP]
+        prop1 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+        prop2 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+        prop3 = "123456789";
+        // [NOP]
+        // Tag: 0x8003ffff, data len 0
+        // [NOP]
+        // Tag: 0x80ffffff, data len 3 202020
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000021
+        // [NOP]
+    };
+    node8 {
+        // [NOP]
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000011
+        // [NOP]
+        subnode1 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode2 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+        subnode3 {
+            // Tag: 0x8007ffff, data len 4 00000030
+            prop;
+        };
+        // Tag: 0x800bffff, data len 8 0000004000000040
+    };
+    node9 {
+        // [NOP]
+        // Tag: 0x800bffff, data len 8 0000001000000010
+        // [NOP]
+        // Tag: 0x8007ffff, data len 4 00000011
+        // [NOP]
+    };
+    // Tag: 0x80ffffff, data len 4 05050505
+};
+// Tag: 0x8007ffff, data len 4 00000006
+// Tag: 0x80ffffff, data len 2 0707
-- 
2.56.1


  parent reply	other threads:[~2026-11-26 11:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 11:22 [PATCH v4 00/22] Add support for structured tags and v18 dtb version Herve Codina
2026-11-26 11:22 ` [PATCH v4 01/22] libfdt: Don't assume the root node is available at offset 0 Herve Codina
2026-11-26 11:22 ` [PATCH v4 02/22] tests: Add a test for fdt_root_offset() Herve Codina
2026-11-26 11:22 ` [PATCH v4 03/22] tests: Don't assume the root node is available at offset 0 Herve Codina
2026-11-26 11:22 ` [PATCH v4 04/22] tests/nopulate: Add an FDT_NOP before the root node Herve Codina
2026-11-26 11:22 ` [PATCH v4 05/22] tests: dtbs_equal_ordered: Add --noskip-nop option Herve Codina
2026-11-26 11:22 ` [PATCH v4 06/22] dtc: Skip possible FDT_NOP before the root node and before FDT_END tag Herve Codina
2026-11-26 11:22 ` [PATCH v4 07/22] tests: treegen: Introduce emit_fdt_header_vers() Herve Codina
2026-11-26 11:22 ` [PATCH v4 08/22] tests: treegen: Introduce tree harness Herve Codina
2026-11-26 11:22 ` [PATCH v4 09/22] util.h: Add missing <stdio.h> Herve Codina
2026-11-26 11:22 ` [PATCH v4 10/22] tests: treegen: Export tree generation primitives Herve Codina
2026-11-26 11:22 ` [PATCH v4 11/22] tests: treegen: Move base harness trees to treegen_base.c Herve Codina
2026-11-26 11:22 ` [PATCH v4 12/22] Introduce structured tag value definition Herve Codina
2026-11-26 11:22 ` [PATCH v4 13/22] util.h: Add concat() macro Herve Codina
2026-11-26 11:22 ` [PATCH v4 14/22] tests: treegen: Generate dtbs with unknown tags Herve Codina
2026-11-26 11:22 ` Herve Codina [this message]
2026-11-26 11:22 ` [PATCH v4 16/22] libfdt: Handle unknown tags in fdt_next_tag() Herve Codina
2026-11-26 11:22 ` [PATCH v4 17/22] flattree: Handle unknown tags Herve Codina
2026-11-26 11:22 ` [PATCH v4 18/22] libfdt: Introduce fdt_ptr_offset_() Herve Codina
2026-11-26 11:22 ` [PATCH v4 19/22] libfdt: Introduce fdt_getprop_by_offset_w() Herve Codina
2026-11-26 11:22 ` [PATCH v4 20/22] tests: Add wip_func utility Herve Codina
2026-11-26 11:22 ` [PATCH v4 21/22] libfdt: Handle unknown tags on dtb modifications Herve Codina
2026-11-26 11:22 ` [PATCH v4 22/22] Introduce v18 dtb version Herve Codina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126112239.636284-16-herve.codina@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=Frank.Li@nxp.com \
    --cc=ayush@beagleboard.org \
    --cc=conor+dt@kernel.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=devicetree-spec@vger.kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=geert@linux-m68k.org \
    --cc=hui.pu@gehealthcare.com \
    --cc=ian.ray@gehealthcare.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=krzk@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.