From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.85.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795692219; b=oPztFlmIeMlxH6bnvXidHnbNzI/t+orkzJKT8d+u/g8SnICQXI1S0k9MXqbeoq5a93Vp QSlbKE8Nm6p/fLp/l6e7bL3ZB+mWiPn1YArIhjDSuceONFrJZCbIcEiNWdVHOKNYhQdQj guXD50LX4NZHQctz8woOfGfcznOiReE6loPKNkrqCXz1ajnpAfHriiRoXWRl4lkiCgGtk 0PCBFcsd6Dive8nzQ4EFNaFp73TkkN7UvdnPj9tCXCeIB9ocfyzpaot5OQEIgv+7Q+rzS aB9hUX2h4izD8SewZH1v4mfUlkehckhDzZmwA5bHHxel8ddg8dDuPn1O23Gn/TX0F0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795692219; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=lL+MhpygV/AydnxeUSShOtnbHS5X/LG0roQREDIX3nU=; b=dImzxAMFM5HVtpsIyMWD2Uto/TEVAhyojeRmnDgEdxyYjEw6eccCHn8Bzqv3yyjXZoRh Tx3dXp2bQxGiSsTs1195KT5xdgW5K05c98l2Uh89cJsHVKnNeYSGTF8xGVaV6hl+QNffM h6PUjZ0KXRiY8CH9xqVia8/vgTOPjTzBbMXJnDT0Hx6xYXNEI9hXNTf22RdbphLqC+S0I dbXDt4Rhlq3rWTJAAxPPweB05ZiXZ3LeI+Vdscoq0fOK+Dv/m5r2zOOoAfZJJzMZy3D2J ANtu9HbyuiN85+OD/QpjSomCrB0k7EPartFw1t+kypGfsHGoF55WzRbKbTVuUyWaPAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=zNuiyw3E; arc=none smtp.remote-ip=185.246.85.4 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7F34606A31E for ; Thu, 26 Nov 2026 11:23:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D7F34606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=zNuiyw3E Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 9C4614E41798 for ; Thu, 26 Nov 2026 11:23:37 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 6FA6260237; Thu, 26 Nov 2026 11:23:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DF94911E6B367; Thu, 26 Nov 2026 12:23:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1795692212; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lL+MhpygV/AydnxeUSShOtnbHS5X/LG0roQREDIX3nU=; b=zNuiyw3EAelwbPFH3lGcsUhGebQF9yu3cZKviLQ+7T2YdqwWDPPGBMJgqk1wkyq49BOP+C uhAYiH2K9wqPi7v0SWIUw8Tp1VRJaZf45Q1r7ApjcmOZyzBHP1geYnpS+JMKR5QC+ObXmA miDavW8JTD6vSQz3vByfJ+Ft1HG5JsgkgHNTxEcsffCNfH/6MjnR1GCJEWvQJK5X3NdWaf ZKdkF1P3IhhhjFrENG4rAvvSsTN4/95A0cF1IvHp4+ibPeYcRhv1tpRyliRBQTTvlSUmdT pSqddo5njTX5u7J0VthLg4amGD44VVjiOQCY4f6V5XS6j83d05/MjndpT+k6RA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Laurent Pinchart , Kieran Bingham , Frank Li , David Lechner , Ayush Singh , Geert Uytterhoeven , devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree-spec@vger.kernel.org, Hui Pu , Ian Ray , Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v4 06/22] dtc: Skip possible FDT_NOP before the root node and before FDT_END tag Date: Thu, 26 Nov 2026 12:22:23 +0100 Message-ID: <20261126112239.636284-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126112239.636284-1-herve.codina@bootlin.com> References: <20261126112239.636284-1-herve.codina@bootlin.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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 --- 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