From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E9AD3C17 for ; Mon, 12 Jan 2026 14:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227627; cv=none; b=T+nWGFZq9wyt2N1uI5bjZhkE5ThJ2GGuoKr03UmcsgO0SJGPhY+m9mZf7vcczKDx9hEFORkTHk9/QDM+3+iz0hkBNAFMe+f1SsB4sA9fKPkXwYSivd0wqmeVcdHYUG2w+WpVLk3n3Kz1AGroWZq7JYwfzXJYbCxi+gCGGXEjxHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227627; c=relaxed/simple; bh=HnzCHq9aLoqzn8azuoQ36GxKVX+LOp2A1A6oGdqgrTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NeYpkv+Isy7CLTRtOvyCxzfYFYHDEkzH7ZUWDnF7NhdUfIpddGwCYn83N/iXSRlM3W0NcFdrGd9fMnVRp+5jRb9q3Bdx8CnVNJakTFTI0gt/JihajIyMk12isYZBsG2dWb5YtGCzLX12PayWaujEfp4bvIdzc+dxEQ+rBBMP77I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=yCRp+iDf; arc=none smtp.client-ip=185.246.84.56 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.b="yCRp+iDf" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 63B051A27E8; Mon, 12 Jan 2026 14:20:24 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3ABE860732; Mon, 12 Jan 2026 14:20:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 253D4103C8CD8; Mon, 12 Jan 2026 15:20:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227623; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=1j23LmyPC4ZZ4R/AQp4I/05eHF1WCAB+ohIqJ2dvH/A=; b=yCRp+iDfT3SkkLMyTtJaenXAzv8XuHvr1g8rR9swTaly6viikF6zHwDzPIEm8CdX1gDYtX lJEkuaBcDusWVA0ZRS+dJ94OWu1fRitI6dR76DY4vl3F1e4iA/zWFovr8XzZny/PzNFB+G CAisq4q86guRPrsZOgxnQ+8o4nnqr/In5zObiYDaK1UKH3F99cXfabhNL7gEWYGfj+iw2j Xsza/9RmLD6ys8YqmxjRm7s83OGFDnAOORJ+oEEoywUsogBSLdBeuwvTHepJoxXru9VP6E hJcd05CfGLBfwPc7YH27udmZ/n2r2S9Vb65tNswaOQCIwwcoRAJJ4Z+BbxJpPQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 01/77] checks: Use consistent type for strspn() returned value Date: Mon, 12 Jan 2026 15:18:51 +0100 Message-ID: <20260112142009.1006236-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" strspn() returns a size_t value. The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict(). Fix the variable type used in check_node_name_chars_strict(). Signed-off-by: Herve Codina Reviewed-by: Ayush Singh --- checks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks.c b/checks.c index 5d09216..041e565 100644 --- a/checks.c +++ b/checks.c @@ -324,7 +324,7 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS= ); static void check_node_name_chars_strict(struct check *c, struct dt_info *= dti, struct node *node) { - int n =3D strspn(node->name, c->data); + size_t n =3D strspn(node->name, c->data); =20 if (n < node->basenamelen) FAIL(c, dti, node, "Character '%c' not recommended in node name", --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B3EB260588; Mon, 12 Jan 2026 14:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227629; cv=none; b=eXlJnh0RgV6Ob0jHk7eeB9j5tJP7mdT0cg8C1bF6bd0YX8krSHvM+J9T6vyxTi1UZNLh8dn6JXeEoZuvurYPawMH1Le0XN6786PV/FaWg7mGbSj41PQITLQS7LB3cxDDS2QNUbXLaW7K97gKf1FCTkk+Gr+GkuvH5bY+San86ME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227629; c=relaxed/simple; bh=Mmcnvo0XQvPuBaHpA8xKSUDM+QmtNvCssITIOUQPOUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EEXqQDAyxNbv0h4rmdMoSzMwEPfkCp38S6nDpxHZ4iRrOBxhh61X5mn/pw7D25AeahlLVIMeQlNoPExO2z20SLdynqPbFdK4kJkxKer/Pkb08h/R0AIYoIjPZG+sqKeaWE8QTerHSh66Ai80ecbf3AeHbOvqU7oHcujm9CuUfDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OPRxTGVe; arc=none smtp.client-ip=185.246.84.56 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.b="OPRxTGVe" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 46EAA1A27ED; Mon, 12 Jan 2026 14:20:26 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1D8566074A; Mon, 12 Jan 2026 14:20:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id AFEEE103C9260; Mon, 12 Jan 2026 15:20:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227624; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lkchoh9jnV9vrtFbWNI6rxkfKR+PqzEYzU7fTeN5IPA=; b=OPRxTGVeRm3nhA2Uh9NnEvPOIsY/IK5i/iv+LF6b7CiD4tMUU0PwBcvx/Pye2/aCFmMWE9 CW3qpvUhuAONPsH5N5uEJ6f3+bm9aDbTLO6cMK6iQV0SsCfKtYbrz+2ezSEOcR/f+7y1TD I1jU2bikrSlRR+sqGwAsDT/YadH29pB9SBNdhSg3WkJq+BDuKJ297uoQ6v2a6pKO6pDUrQ 7GuTVYZSbEwegVgLHup+nJTxy/+AlKLyEnpDtApBHQpmpsxqSxzV74ijkMjBjJKlMzBp99 4Qp/eWc6Z+S8hNEjS8pCwuFL4BhtHL1eXzPYHIPIyBixt2fi1xo7QjdslAFHTg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 02/77] Introduce v18 dtb version Date: Mon, 12 Jan 2026 15:18:52 +0100 Message-ID: <20260112142009.1006236-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" This v18 version will add support for - metadata in device-tree blobs in order to have a better handling of phandles and unresolved references. - Addon device-tree blob (successor of device-tree overlay) - Import and export symbols feature - multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree) Signed-off-by: Herve Codina --- dtc.h | 2 +- fdtdump.c | 2 +- flattree.c | 2 ++ libfdt/fdt.h | 1 + libfdt/fdt_rw.c | 13 +++++++------ libfdt/libfdt.h | 2 +- tests/pylibfdt_tests.py | 2 +- tests/trees.S | 2 +- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dtc.h b/dtc.h index 3a220b9..186caad 100644 --- a/dtc.h +++ b/dtc.h @@ -29,7 +29,7 @@ #define debug(...) #endif =20 -#define DEFAULT_FDT_VERSION 17 +#define DEFAULT_FDT_VERSION 18 =20 /* * Command line options diff --git a/fdtdump.c b/fdtdump.c index d424869..ec25edf 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -18,7 +18,7 @@ #include "util.h" =20 #define FDT_MAGIC_SIZE 4 -#define MAX_VERSION 17U +#define MAX_VERSION 18U =20 #define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1)) #define PALIGN(p, a) ((void *)(ALIGN((uintptr_t)(p), (a)))) diff --git a/flattree.c b/flattree.c index 30e6de2..c3887da 100644 --- a/flattree.c +++ b/flattree.c @@ -30,6 +30,8 @@ static struct version_info { FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS}, {17, 16, FDT_V17_SIZE, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, + {18, 18, FDT_V18_SIZE, + FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, }; =20 struct emitter { diff --git a/libfdt/fdt.h b/libfdt/fdt.h index a07abfc..9372353 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -62,5 +62,6 @@ struct fdt_property { #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t)) #define FDT_V16_SIZE FDT_V3_SIZE #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) +#define FDT_V18_SIZE FDT_V17_SIZE =20 #endif /* FDT_H */ diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c index 7475caf..00e32bb 100644 --- a/libfdt/fdt_rw.c +++ b/libfdt/fdt_rw.c @@ -28,13 +28,13 @@ static int fdt_rw_probe_(void *fdt) return 0; FDT_RO_PROBE(fdt); =20 - if (!can_assume(LATEST) && fdt_version(fdt) < 17) + if (!can_assume(LATEST) && fdt_version(fdt) < 18) return -FDT_ERR_BADVERSION; if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), fdt_size_dt_struct(fdt))) return -FDT_ERR_BADLAYOUT; - if (!can_assume(LATEST) && fdt_version(fdt) > 17) - fdt_set_version(fdt, 17); + if (!can_assume(LATEST) && fdt_version(fdt) > 18) + fdt_set_version(fdt, 18); =20 return 0; } @@ -455,7 +455,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsi= ze) err =3D fdt_move(fdt, buf, bufsize); if (err) return err; - fdt_set_version(buf, 17); + fdt_set_version(buf, 18); + fdt_set_last_comp_version(buf, 18); fdt_set_size_dt_struct(buf, struct_size); fdt_set_totalsize(buf, bufsize); return 0; @@ -484,8 +485,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsi= ze) =20 fdt_set_magic(buf, FDT_MAGIC); fdt_set_totalsize(buf, bufsize); - fdt_set_version(buf, 17); - fdt_set_last_comp_version(buf, 16); + fdt_set_version(buf, 18); + fdt_set_last_comp_version(buf, 18); fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); =20 return 0; diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index 7a10f66..c5cd35d 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -15,7 +15,7 @@ extern "C" { =20 #define FDT_FIRST_SUPPORTED_VERSION 0x02 #define FDT_LAST_COMPATIBLE_VERSION 0x10 -#define FDT_LAST_SUPPORTED_VERSION 0x11 +#define FDT_LAST_SUPPORTED_VERSION 0x12 =20 /* Error codes: informative error codes */ #define FDT_ERR_NOTFOUND 1 diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py index a4f73ed..373e11a 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -288,7 +288,7 @@ class PyLibfdtBasicTests(unittest.TestCase): self.assertEqual(self.fdt.off_dt_struct(), 88) self.assertEqual(self.fdt.off_dt_strings(), 652) self.assertEqual(self.fdt.off_mem_rsvmap(), 40) - self.assertEqual(self.fdt.version(), 17) + self.assertEqual(self.fdt.version(), 18) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) self.assertEqual(self.fdt.size_dt_strings(), 105) diff --git a/tests/trees.S b/tests/trees.S index d69f7f1..ecd43bc 100644 --- a/tests/trees.S +++ b/tests/trees.S @@ -17,7 +17,7 @@ fdtlong (\tree\()_struct - \tree) fdtlong (\tree\()_strings - \tree) fdtlong (\tree\()_rsvmap - \tree) - fdtlong 0x11 + fdtlong 0x12 fdtlong 0x10 fdtlong 0 fdtlong (\tree\()_strings_end - \tree\()_strings) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2699525A642; Mon, 12 Jan 2026 14:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227637; cv=none; b=V5jvWCydvtb/SHTopM7n3cKBOG+LS6i8yiUE5s1+4uM5BmIs04nTS8XNrgIijKb9tgw90nAQu70iZMHLbqONLCB/CPIwUpWg8NDAcoqQD2Vm99R04z2gUB0u1pFkR7z3K0yTgW33qtPSlhk7K2QR+fHWIboZq1tGQNVsvW0SYps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227637; c=relaxed/simple; bh=mvH09V7lrGA/S50DWTiUI7+DX7/+HTFsSeoUZVw3bdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GlhBuMpZX5PxrLcXF412YrhmAOXZbPfIygmXtSISCDx+RbcRbA0lM/mMjLGODuqxKTzrW7phI7fReaqucFQisVZ797I5gfvR4sIsD2va09LqePff1AZgf7PAHGBx7hCvHyMvOdd7gogVUSEchRjlY3yCsHNSgag/c/GfwXsGNFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WMj9umbO; arc=none smtp.client-ip=185.171.202.116 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.b="WMj9umbO" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 8B1EBC2086C; Mon, 12 Jan 2026 14:20:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 765386075A; Mon, 12 Jan 2026 14:20:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4D442103C8C61; Mon, 12 Jan 2026 15:20:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227626; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=jngatU43htu5Ifo+yB7tNhvkj0T5808QtUi5ZKsFCRA=; b=WMj9umbOglb1r4mpLmEV8b9Z6AYSkvZgg9xsV7ooUTkEbkeTTJYlgrXo4+1ZXjuQon4sFU 4qEWoFEcXzj5lXrg0TWFD2XgqPc65itivxIRif9yx1+LAnbJDhMlNFpEpkpmVKvogf2/MU AcVZECoyKg0DoQK0w3+cFCWWM2TdGuTEthu/0zTsbZ7ZnbA51QqmBiCSEAnGm9cyq/Br0b f2GDoCmODwr/nzELFxT4GpcWGpyvlmjKNeetc7Mb2IRPMRNYE+9QW2RF1tJSC3LhDcOt82 ZlyycE8N1nCrzbVFH4iW1e7powy8gOJHC3hmwP+avy7ZDbb5egVLt6AdWKXoGQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 03/77] libfdt: Introduce fdt_next_tag_full() and use it in fdt_next_tag() Date: Mon, 12 Jan 2026 15:18:53 +0100 Message-ID: <20260112142009.1006236-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In v18 dtb new tags are added. Prepare libfdt to handle those new tags. Keep fdt_next_tag() handling only existing tags and introduce fdt_next_tag_full() to handle new tags. fdt_next_tag() uses fdt_next_tag_full() but it will filter out new tags when they are introduced to have those new tags transparent for existing fdt_next_tag() callers. Code that will need to handle those new tags will use explicitly fdt_next_tag_full() to have access to them when they need to. No new tags have been introduced yet and modifications done here prepare their introduction. Signed-off-by: Herve Codina --- libfdt/fdt.c | 35 ++++++++++++++++++++++++++++++++++- libfdt/libfdt.h | 18 ++++++++++++++++++ libfdt/version.lds | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 95f644c..ce051a0 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -159,7 +159,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset,= unsigned int len) return fdt_offset_ptr_(fdt, offset); } =20 -uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) +uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffs= et) { const fdt32_t *tagp, *lenp; uint32_t tag, len, sum; @@ -220,6 +220,39 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset= , int *nextoffset) return tag; } =20 +uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) +{ + uint32_t tag, tmp_tag; + int tmp_offset, tmp_next; + + /* Retrieve next tag */ + tag =3D fdt_next_tag_full(fdt, startoffset, nextoffset); + + /* Look at next one to see what we need to do */ + tmp_next =3D *nextoffset; + do { + tmp_offset =3D tmp_next; + tmp_tag =3D fdt_next_tag_full(fdt, tmp_offset, &tmp_next); + switch (tmp_tag) { + case FDT_BEGIN_NODE: + case FDT_END_NODE: + case FDT_PROP: + case FDT_NOP: + case FDT_END: + /* Next tag is not new tag introduced in v18 -> Ok */ + *nextoffset =3D tmp_offset; + return tag; + + default: + break; + } + } while (1); + + /* We shouldn't reach this code */ + *nextoffset =3D -FDT_ERR_BADSTRUCTURE; + return FDT_END; +} + int fdt_check_node_offset_(const void *fdt, int offset) { if (!can_assume(VALID_INPUT) diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index c5cd35d..d1a9cd5 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -154,6 +154,24 @@ static inline void *fdt_offset_ptr_w(void *fdt, int of= fset, int checklen) */ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); =20 +/** + * fdt_next_tag_full - get next tag in the device tree without any filteri= ng + * @fdt: Pointer to the device tree blob + * @offset: Offset within the blob to start searching + * @nextoffset: Pointer to variable to store the offset of the next tag + * + * fdt_next_tag_full() returns the tag type of the next tag in the device = tree + * blob starting from the given @offset. If @nextoffset is non-NULL, it wi= ll + * be set to the offset immediately following the tag. + * fdt_next_tag() can return only a subset of all possible tags performing= some + * internal filtering. fdt_next_tag_full() doesn't perform this filtering. + * + * returns: + * the tag type (FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END), + * FDT_END, if offset is out of bounds + */ +uint32_t fdt_next_tag_full(const void *fdt, int offset, int *nextoffset); + /* * External helpers to access words from a device tree blob. They're built * to work even with unaligned pointers on platforms (such as ARMv5) that = don't diff --git a/libfdt/version.lds b/libfdt/version.lds index cbfef54..7e2dde2 100644 --- a/libfdt/version.lds +++ b/libfdt/version.lds @@ -52,6 +52,7 @@ LIBFDT_1.2 { fdt_strerror; fdt_offset_ptr; fdt_next_tag; + fdt_next_tag_full; fdt_appendprop; fdt_create_empty_tree; fdt_first_property_offset; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97B3625A2CF; Mon, 12 Jan 2026 14:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227635; cv=none; b=hoiTlNK/XD/5IpN4D3k2cobragH/7IswiwF3s47JPDz3m4eMcrENBgDTDG7x5oZiQvGIHcWv6rg9ZG4EcH8o8A+k+2kyKFnwxY/bIBMPHTQNQalYKYchyHxQbGK0rL6huqJ96H6G1CNql0Y8T05WatYUXvEmc7QcH9XNbnCkgzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227635; c=relaxed/simple; bh=N6vNZnVvxa0cyZoAR2VRThiEj4wnSiGOR31YXUtZkNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ot5V1jTfrtwhzOb9HltO7cYqOimZod4Zc9/U47VVMx3uAxiB1WxelDa6Cjy4X7IeF+JmGy5/xkI+Jr+C7FobPBS89BXfKkehjG/So+i8T3zl92Qr9vTpjdSqRe+yKxwivfVC02xAs1UphU9hy872pBd33/kp9PcILHlylEv8aDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=v1d0eOjB; arc=none smtp.client-ip=185.246.84.56 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.b="v1d0eOjB" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 07BD61A26D2; Mon, 12 Jan 2026 14:20:29 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D12116075E; Mon, 12 Jan 2026 14:20:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E046B103C9261; Mon, 12 Jan 2026 15:20:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227628; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=BvVIGAhOsl/qKFvH3/fIDoLGZ6jnPOuqu4xf6eHm0K4=; b=v1d0eOjBcuWoUxR4Q/hqZzMDFcyIWKdognsVpsxaaS2aVgYVZKsnkfXECT7LUuumtOd9c/ QTLxCXEew7zt+QsArVDpZ1QRD3NvTM1gFOyBcCtjG3dur3bX6PmMEjyxgNv5RBFkhjgUTh 7mhipVEny6MIuq/10pDaN96g8yomS+FHVsCDu7Xx7Asi62MKPf1Dg8fuLEb5uKR0Np8j/Y zQjgSn6/jx2VMDlAiRHOkrlw8pljydN6JGnfNsj0zabEreO3KH/b+bFSsk8xZ9yjZy0Lpg Upj97a2KhYcM2xnbR6Dy1LIHn+/njAduMAS3PoEpXzo8TJ4NwXeQCxnkqnU9bw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 04/77] dtc: Allow to use data_append_markers() out of data.c Date: Mon, 12 Jan 2026 15:18:54 +0100 Message-ID: <20260112142009.1006236-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" With meta-data available in dtb, markers can be set as soon as a dtb is parsed. This will be done in flattree.c using data_append_markers(). Prepare this usage allowing this function to be used out of data.c Signed-off-by: Herve Codina --- data.c | 2 +- dtc.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index 5b25aa0..11b2169 100644 --- a/data.c +++ b/data.c @@ -127,7 +127,7 @@ struct data data_insert_at_marker(struct data d, struct= marker *m, return d; } =20 -static struct data data_append_markers(struct data d, struct marker *m) +struct data data_append_markers(struct data d, struct marker *m) { struct marker **mp =3D &d.markers; =20 diff --git a/dtc.h b/dtc.h index 186caad..3bbd97e 100644 --- a/dtc.h +++ b/dtc.h @@ -187,6 +187,7 @@ struct data data_insert_data(struct data d, struct mark= er *m, struct data old); struct marker *alloc_marker(unsigned int offset, enum markertype type, char *ref); struct data data_add_marker(struct data d, enum markertype type, char *ref= ); +struct data data_append_markers(struct data d, struct marker *m); =20 bool data_is_one_string(struct data d); =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97BDB25A34F for ; Mon, 12 Jan 2026 14:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227635; cv=none; b=uCJf5hCD3n3pvUIUW2gviy2qeYgbGFn7zuI5S/uTsVgo0oKKJsi5UoUZea9zD5CzjxE6y6jzEZ2vqc4NQ7HzN2AoF6/ePw2cGMJT2bfvSjfC5RXuVTIa+VU+RPpkqFL5gJT1/0IxbF96lkgIUx5wlpClSf9+fK/v8xaf96XPyjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227635; c=relaxed/simple; bh=CvLvY8SMr9F9mZwO/2tuWr2whQw14srELqUnn6HBTBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a/INdLRRsvG099EF8FWW9bayru0ix2767aIS0aj6sPALVLCZiNv8AShymzsnaCW4y52fdqelDYd7JF3QqR964j1OiyYTps8m6SHGNnT+1Y06ioECcDw18Wf5JZA3TI7M7yoKP7TZpCz2OT6UijQmZsIaVQEYg6fx6g32/kjWZe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=oqaGkhsI; arc=none smtp.client-ip=185.246.84.56 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.b="oqaGkhsI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id BD7AF1A27ED; Mon, 12 Jan 2026 14:20:30 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 93AA16075F; Mon, 12 Jan 2026 14:20:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5EC3A103C8CD8; Mon, 12 Jan 2026 15:20:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227629; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=IUPvT7nS1D4nXzhnOstmhdejKMlnh6AgZFSDlvQ1CHk=; b=oqaGkhsI+7DtrxzeEiBANcHQo4BF29lj6p8jmQMnXsHi/URq3Tdtp6KbqYfbjvchL/Uty8 I3Z9xJP3BlPJGLIiHPDD5gb5GGSHB7biB4xL7V/LzuOeWTdAtPPNI3MB9LfG9G4ELSLEts 6QXI3EwpkLK6uKzTcDW+16A/1E6CD9RHPwzCjtT3E17/aWjQjjibnvl72Ldnz+4U1MPqli 7LcgSOiga2F14gVCmIhu5zJqxKT8PeT1IrlxSeczfDOf2JZXVWbWMv7h5a0hmaEYtwK2mB tTATXFdY1M/4EqCtascIcRroOkLVcmwkSQ6MrGqj9r0IJ3hWBZE7668l+y3uhA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 05/77] fdtdump: Change FDT_PROP prob handling to ease future addition Date: Mon, 12 Jan 2026 15:18:55 +0100 Message-ID: <20260112142009.1006236-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In order to ease future tags addition, perform operation related to FDT_PROP when the tag is explicitly FDT_PROP instead of relying to a kind of default value case. Handle the FDT_PROP tag exactly in the same way as it is done for other tags. No functional modification. Signed-off-by: Herve Codina Reviewed-by: Ayush Singh --- fdtdump.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fdtdump.c b/fdtdump.c index ec25edf..95a2274 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -129,23 +129,25 @@ static void dump_blob(void *blob, bool debug) continue; } =20 - if (tag !=3D FDT_PROP) { - fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, ""= , tag); - break; + if (tag =3D=3D FDT_PROP) { + sz =3D fdt32_to_cpu(GET_CELL(p)); + s =3D p_strings + fdt32_to_cpu(GET_CELL(p)); + if (version < 16 && sz >=3D 8) + p =3D PALIGN(p, 8); + t =3D p; + + p =3D PALIGN(p + sz, 4); + + dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s); + dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off); + printf("%*s%s", depth * shift, "", s); + utilfdt_print_data(t, sz); + printf(";\n"); + continue; } - sz =3D fdt32_to_cpu(GET_CELL(p)); - s =3D p_strings + fdt32_to_cpu(GET_CELL(p)); - if (version < 16 && sz >=3D 8) - p =3D PALIGN(p, 8); - t =3D p; - - p =3D PALIGN(p + sz, 4); - - dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s); - dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off); - printf("%*s%s", depth * shift, "", s); - utilfdt_print_data(t, sz); - printf(";\n"); + + fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "",= tag); + break; } } =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A97B72BDC2C for ; Mon, 12 Jan 2026 14:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227640; cv=none; b=rfIDpPv1Cyr2wYbMT/XiCFqEigLsd0SvJ3I9qFodZzH7EMU0i+LFPVI+NkxuOe4NtEUg+REiAu7tT+shJFfNp9ho+8yM3Mju4G8esYs+PMvJkjelXrHP2PNdKiwlYeO2NaBg5FGWBwiG/lkHIYKw4Eh2w6SDCU65AmPghD5mkC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227640; c=relaxed/simple; bh=ASMfnfySi7bTxNB9DYI439TvBroyPcIu/bYgWZMO3zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BDnAANF7Zi4+TW5trfvoy0Sdk6Zbs9yKugiw3M8g/4cTk1LQsxp4FHpe0ciQoi/wwlXDMGE5LdsizVfeaUChXVLUFIOq6aB/ZkRtZlQjPBQT8K/M03vX9GMMX6Jv3NoCgwgY9C1yblTqxy1dUPSsFBtvxT5rph7cgcpn5cGbNvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UUzOLoV1; arc=none smtp.client-ip=185.171.202.116 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.b="UUzOLoV1" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 98648C2086F; Mon, 12 Jan 2026 14:20:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 33F1360760; Mon, 12 Jan 2026 14:20:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1C82B103C9262; Mon, 12 Jan 2026 15:20:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227631; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=VMgqV5/5POLzWoizLuLtWMxKI4gxwI+vjmwg1ydT5ME=; b=UUzOLoV1c8ksQuhQ/lO3FvHXP0iRbF9OBoB8XMhkMOLOWPJvu3+unK5Mv2LL82dQJnFXZO ISIyXnPjzCeE2uYsvrZ79t3eLKd6T3oW6aF2aCokx7PWPG8lvEedU2VJyjXSvkAZWBQ/9J JJzYV17N5SCAGrsuqCX1o5eolvzXyDkw2KoO5JcYvFYPLgj5yHJJMVSfv+2SkQ/hr2J6Wu BseJXUp0DJxZ5qwGp2VvCHWMVq+dQNLbgtjrUkGMG8HNR/m93F8mU7LFtNK/5nsw+GIAIz vHeOMKs+Zjr3K9RJxmi/lw+RIKwqUlvnCgUS6VJ0OKM2IGsLKnSst2h9TVIseg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag Date: Mon, 12 Jan 2026 15:18:56 +0100 Message-ID: <20260112142009.1006236-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property. It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob). It is followed by one value: - offset (32bit): Offset in the property data where the phandle is available. Example: FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004 This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb. This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304. If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle. For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present: FDT_PROP 0x00000008 xxxxxxxx FDT_REF_LOCAL 0x00000004 FDT_PROP 0x00000010 xxxxxxxx FDT_REF_LOCAL 0x00000000 FDT_REF_LOCAL 0x00000008 Add support for this new dtb tag. Suggested-by: David Gibson Link: https://lore.kernel.org/all/aL-2fmYsbexEtpNp@zatzit/ Signed-off-by: Herve Codina --- data.c | 1 + dtc.h | 1 + fdtdump.c | 14 +++++++++++++- flattree.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- libfdt/fdt.c | 24 ++++++++++++++++++++++-- libfdt/fdt.h | 1 + 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/data.c b/data.c index 11b2169..9bae704 100644 --- a/data.c +++ b/data.c @@ -288,6 +288,7 @@ struct marker *alloc_marker(unsigned int offset, enum m= arkertype type, m->type =3D type; m->ref =3D ref; m->next =3D NULL; + m->is_local =3D 0; =20 return m; } diff --git a/dtc.h b/dtc.h index 3bbd97e..965321c 100644 --- a/dtc.h +++ b/dtc.h @@ -128,6 +128,7 @@ struct marker { enum markertype type; unsigned int offset; char *ref; + bool is_local; struct marker *next; }; =20 diff --git a/fdtdump.c b/fdtdump.c index 95a2274..dffa9a6 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -57,8 +57,9 @@ static void dump_blob(void *blob, bool debug) const char *p_strings =3D (const char *)blob + off_str; uint32_t version =3D fdt32_to_cpu(bph->version); uint32_t totalsize =3D fdt32_to_cpu(bph->totalsize); - uint32_t tag; + uint32_t tag, offset; const char *p, *s, *t; + const char *last_prop_name =3D NULL; int depth, sz, shift; int i; uint64_t addr, size; @@ -105,6 +106,7 @@ static void dump_blob(void *blob, bool debug) (uintptr_t)p - blob_off - 4, tag, tagname(tag)); =20 if (tag =3D=3D FDT_BEGIN_NODE) { + last_prop_name =3D NULL; s =3D p; p =3D PALIGN(p + strlen(s) + 1, 4); =20 @@ -118,6 +120,7 @@ static void dump_blob(void *blob, bool debug) } =20 if (tag =3D=3D FDT_END_NODE) { + last_prop_name =3D NULL; depth--; =20 printf("%*s};\n", depth * shift, ""); @@ -143,6 +146,15 @@ static void dump_blob(void *blob, bool debug) printf("%*s%s", depth * shift, "", s); utilfdt_print_data(t, sz); printf(";\n"); + last_prop_name =3D s; + continue; + } + + if (tag =3D=3D FDT_REF_LOCAL) { + offset =3D fdt32_to_cpu(GET_CELL(p)); + + printf("%*s// [FDT_REF_LOCAL] %s[%"PRIu32"]\n", depth * shift, "", + last_prop_name, offset); continue; } =20 diff --git a/flattree.c b/flattree.c index c3887da..5c597ad 100644 --- a/flattree.c +++ b/flattree.c @@ -13,6 +13,7 @@ #define FTF_STRTABSIZE 0x10 #define FTF_STRUCTSIZE 0x20 #define FTF_NOPS 0x40 +#define FTF_REF_XXX 0x80 =20 static struct version_info { int version; @@ -31,7 +32,7 @@ static struct version_info { {17, 16, FDT_V17_SIZE, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, {18, 18, FDT_V18_SIZE, - FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, + FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX}, }; =20 struct emitter { @@ -42,6 +43,7 @@ struct emitter { void (*beginnode)(void *, struct label *labels); void (*endnode)(void *, struct label *labels); void (*property)(void *, struct label *labels); + void (*ref_local)(void *); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -91,6 +93,11 @@ static void bin_emit_property(void *e, struct label *lab= els) bin_emit_cell(e, FDT_PROP); } =20 +static void bin_emit_ref_local(void *e) +{ + bin_emit_cell(e, FDT_REF_LOCAL); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -99,6 +106,7 @@ static struct emitter bin_emitter =3D { .beginnode =3D bin_emit_beginnode, .endnode =3D bin_emit_endnode, .property =3D bin_emit_property, + .ref_local =3D bin_emit_ref_local, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -210,6 +218,14 @@ static void asm_emit_property(void *e, struct label *l= abels) asm_emit_cell(e, FDT_PROP); } =20 +static void asm_emit_ref_local(void *e) +{ + FILE *f =3D e; + + fprintf(f, "\t/* FDT_REF_LOCAL */\n"); + asm_emit_cell(e, FDT_REF_LOCAL); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -218,6 +234,7 @@ static struct emitter asm_emitter =3D { .beginnode =3D asm_emit_beginnode, .endnode =3D asm_emit_endnode, .property =3D asm_emit_property, + .ref_local =3D asm_emit_ref_local, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -242,6 +259,7 @@ static void flatten_tree(struct node *tree, struct emit= ter *emit, struct property *prop; struct node *child; bool seen_name_prop =3D false; + struct marker *m; =20 if (tree->deleted) return; @@ -272,6 +290,17 @@ static void flatten_tree(struct node *tree, struct emi= tter *emit, =20 emit->data(etarget, prop->val); emit->align(etarget, sizeof(cell_t)); + + if (vi->flags & FTF_REF_XXX) { + m =3D prop->val.markers; + for_each_marker_of_type(m, REF_PHANDLE) { + if (m->is_local) { + emit->ref_local(etarget); + emit->cell(etarget, m->offset); + continue; + } + } + } } =20 if ((vi->flags & FTF_NAMEPROPS) && !seen_name_prop) { @@ -737,6 +766,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, struct node *node; const char *flatname; uint32_t val; + uint32_t offset; =20 node =3D build_node(NULL, NULL, NULL); =20 @@ -751,6 +781,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, do { struct property *prop; struct node *child; + struct marker *m; =20 val =3D flat_read_word(dtbuf); switch (val) { @@ -782,6 +813,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, /* Ignore */ break; =20 + case FDT_REF_LOCAL: + if (!(flags & FTF_REF_XXX)) + die("REF_LOCAL tag found in flat tree" + " version <18\n"); + + offset =3D flat_read_word(dtbuf); + m =3D alloc_marker(offset, REF_PHANDLE, NULL); + m->is_local =3D true; + prop->val =3D data_append_markers(prop->val, m); + break; + default: die("Invalid opcode word %08x in device tree blob\n", val); @@ -900,6 +942,9 @@ struct dt_info *dt_from_blob(const char *fname) flags |=3D FTF_NOPS; } =20 + if (version >=3D 18) + flags |=3D FTF_REF_XXX; + inbuf_init(&memresvbuf, blob + off_mem_rsvmap, blob + totalsize); inbuf_init(&dtbuf, blob + off_dt, blob + totalsize); diff --git a/libfdt/fdt.c b/libfdt/fdt.c index ce051a0..7268fb6 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -161,7 +161,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset,= unsigned int len) =20 uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffs= et) { - const fdt32_t *tagp, *lenp; + const fdt32_t *tagp, *lenp, *tmp32p; uint32_t tag, len, sum; int offset =3D startoffset; const char *p; @@ -209,6 +209,14 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) case FDT_NOP: break; =20 + case FDT_REF_LOCAL: + /* Skip offset value */ + tmp32p =3D fdt_offset_ptr(fdt, offset, sizeof(*tmp32p)); + if (!can_assume(VALID_DTB) && !tmp32p) + return FDT_END; /* premature end */ + offset +=3D sizeof(fdt32_t); + break; + default: return FDT_END; } @@ -239,10 +247,22 @@ uint32_t fdt_next_tag(const void *fdt, int startoffse= t, int *nextoffset) case FDT_PROP: case FDT_NOP: case FDT_END: - /* Next tag is not new tag introduced in v18 -> Ok */ + /* + * Next tag is not a meta-data tag -> Ok this next tag + * has to be handle by fd_next_tag(). + * Filter out any potential meta-data tag returning + * nextoffset pointing to this current next tag. + */ *nextoffset =3D tmp_offset; return tag; =20 + case FDT_REF_LOCAL: + /* + * Next tag is a meta-data tag present in the middle + * of the structure -> Skip it and look at next one + */ + break; + default: break; } diff --git a/libfdt/fdt.h b/libfdt/fdt.h index 9372353..f8efdf1 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -55,6 +55,7 @@ struct fdt_property { #define FDT_PROP 0x3 /* Property: name off, size, content */ #define FDT_NOP 0x4 /* nop */ +#define FDT_REF_LOCAL 0x5 /* local phandle reference: offset */ #define FDT_END 0x9 =20 #define FDT_V1_SIZE (7*sizeof(fdt32_t)) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BC3F261B9C for ; Mon, 12 Jan 2026 14:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227636; cv=none; b=PaMyz8aC9g2nD40/zmPiVh15VH2lbRmEFuqpTXFuL1mfbvMij3wG6sZ36pBaMbHlBe2PWMBjmBpkERJwPIKRM9gSeTokIGAMdp4avEGgpDAnWJA2O9MgWHw+vXhxWNHCbJb7PNFBu310wSQs1ZEsZvWq99LLWtKfHpBn5rcJrOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227636; c=relaxed/simple; bh=5s4MfuH6bV1kFmHdaAlJjhLcHBaKKPUQ+j0TcMZDzMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LkLzUn+/KA3iiYuFlgln0oC0qFrPtfzot20HdSb3qvTTX0YqpevhJfE+pJcG6HvQYvPz88nS4T/p+Vn8p8kkVKSIdC4fMi5g+UY2MH7Cr6BPDXZ35ejhX8xoVRGhenPq2D0orlyyQF9PQJae63PGBQ4ynXFtqeD+52rRR0IpJO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=1zHUYbzr; arc=none smtp.client-ip=185.246.85.4 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.b="1zHUYbzr" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id D48AF4E42089; Mon, 12 Jan 2026 14:20:33 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A92D8606FA; Mon, 12 Jan 2026 14:20:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8EBB8103C8C61; Mon, 12 Jan 2026 15:20:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227632; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=oKTQDhMRl0VW80WOH8cTeTsgqrNdBUCiZDYFcFk7Fcg=; b=1zHUYbzrT9AfAl2lPr9xVXcmUWw+byCIy28LOsoET0K0pNtqIoL0/rZ7qhiftLKgKBMjfr I1B7j3jgYEueY6YBYtkbwuC80XBSfMLbdi3fNuH4pZN24bFR0m7sP1sB0H1+7mB/e1185J RR1EtT/6fnDmFhwzikuVTPoTuf9rICg33QHoavqZGDp7yRjEpMIlU5avAuOKDUn42Grc9z 11iZvcUBZf2Hgbz4gYDk8DyajNF9WEJtrN4vnckmZEWm4JMywzx/LeSkQZmCrx/AEEFi75 PhpMTiJJkfrwb5nHFiYGH8kQwTyuhfVRLH8b9bN2udQM/XW69V4LsMvT0h178g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 07/77] livetree: Improve get_node_by_phandle() Date: Mon, 12 Jan 2026 15:18:57 +0100 Message-ID: <20260112142009.1006236-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" get_node_by_phandle() allows to get a node based on its phandle value. It checks the phandle value against value available in internal node structure. This internal phandle value is updated during process_check() and so, get_node_by_phandle() cannot give correct results before the process_check() call. Improve get_node_by_phandle() to look at node phandle properties when the internal phandle value is not valid. This allows to return a correct matching node even if process_check() was not called yet. With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed to update internal phandle references before the call to process_check(). Indeed, this tag allows to identify phandles and internal references need to be updated based on the phandle value before the process_check() call. Signed-off-by: Herve Codina --- livetree.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/livetree.c b/livetree.c index f328824..9b67934 100644 --- a/livetree.c +++ b/livetree.c @@ -609,16 +609,35 @@ struct node *get_node_by_label(struct node *tree, con= st char *label) return NULL; } =20 +static cell_t get_node_phandle_existing(struct node *node) +{ + struct property *prop; + + if (phandle_is_valid(node->phandle)) + return node->phandle; + + prop =3D get_property(node, "phandle"); + if (!prop) { + prop =3D get_property(node, "linux,phandle"); + if (!prop) + return 0; + } + + return propval_cell(prop); +} + struct node *get_node_by_phandle(struct node *tree, cell_t phandle) { struct node *child, *node; + cell_t tree_phandle; =20 if (!phandle_is_valid(phandle)) { assert(generate_fixups); return NULL; } =20 - if (tree->phandle =3D=3D phandle) { + tree_phandle =3D get_node_phandle_existing(tree); + if (phandle_is_valid(tree_phandle) && tree_phandle =3D=3D phandle) { if (tree->deleted) return NULL; return tree; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB92B25A33F; Mon, 12 Jan 2026 14:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227638; cv=none; b=FQ6ICimj2Y2sOWzgH44wOE24SX23psyXumeGYEE41ilC/7bwMYhXA0LKMSmOhohgt8eKV8CzSfjPGlKjEsMx9fX5TfAOkp/CAyKGxrY1DDuZG4GtVDphmDoYYJ4wqyvVr2RZCVZr8vJRl7L0BBXBs28SEP1FEYaAaV1YkfExNXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227638; c=relaxed/simple; bh=8icfqPELgBR70xUKNLjUJGX7//gjd6acEmboB01cqzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qM9CBE8bjB36YHEExt5k2rTlYVbEzwHKYGKQdO5tjnOLdMndtM86lqBLFAtu0ZFQgrERHsvqPK7w7N1oUTG2SaoVYqFF33/sK3fq+kxUHxzdFNuwNVuTHrJFKx7Kc+LPVXPtk/Go+o9q6yi7Vf4GXmwa6jSefZisLw/Mcee+9OY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pDR9yfQ4; arc=none smtp.client-ip=185.246.85.4 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.b="pDR9yfQ4" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 5C36B4E4208B; Mon, 12 Jan 2026 14:20:35 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 32167606FA; Mon, 12 Jan 2026 14:20:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4AF9F103C9263; Mon, 12 Jan 2026 15:20:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227634; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=74KBIs7Q6u//Ah9/aNetQalsEtH5TnbY0fwXskVdBvM=; b=pDR9yfQ4glOvotcXQ9NcSlotEd2QQmDUw2jdnV3HFakiYXgDkL+npnwy9prUNznsnzDQ0/ M2ytaVyPsxwTL8az3u72LOukBWOXgxOtWCfhiYvvkGF0dFNr7POJHZFtAveqBQpcK9Xp5q EcjJjKGRAdJfMe/jgVLCjhYlqvJgUfXH+0eeZRfVMHPPefc0Z2yLnYS9FrFYCk74ygebRQ GTuPaLayKLs5q9Y5tsT+L6RmofAvRIpr7McsBSC5HHymYx/Mi517UC/yo4bzROWFtCBuWi zMT8sGrcLgwbWk2biZkDbRaC+JcrEKTfRRGwjJG7hXOulZuZ1aXKc3/V0dRBig== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 08/77] dtc: Introduce update_phandles_ref() Date: Mon, 12 Jan 2026 15:18:58 +0100 Message-ID: <20260112142009.1006236-9-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" With the introduction of FDT_REF_LOCAL dtb tag, a local phandle used by a property is identify when a dtb is parsed. In order to have consistent internal data, the reference related to this phandle usage needs to be updated based on the phandle value. This is done by update_phandles_ref(). Signed-off-by: Herve Codina --- dtc.c | 2 ++ dtc.h | 2 ++ livetree.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/dtc.c b/dtc.c index b3445b7..88f03ff 100644 --- a/dtc.c +++ b/dtc.c @@ -333,6 +333,8 @@ int main(int argc, char *argv[]) generate_fixups =3D 1; } =20 + update_phandles_ref(dti); + process_checks(force, dti); =20 if (auto_label_aliases) diff --git a/dtc.h b/dtc.h index 965321c..351fe41 100644 --- a/dtc.h +++ b/dtc.h @@ -345,6 +345,8 @@ void generate_label_tree(struct dt_info *dti, const cha= r *name, bool allocph); void generate_fixups_tree(struct dt_info *dti, const char *name); void generate_local_fixups_tree(struct dt_info *dti, const char *name); =20 +void update_phandles_ref(struct dt_info *dti); + /* Checks */ =20 void parse_checks_option(bool warn, bool error, const char *arg); diff --git a/livetree.c b/livetree.c index 9b67934..9e30a63 100644 --- a/livetree.c +++ b/livetree.c @@ -1158,3 +1158,41 @@ void generate_local_fixups_tree(struct dt_info *dti,= const char *name) "Warning: Preexisting data in %s malformed, some content could not be a= dded.\n", name); } + +static void update_phandles_ref_internal(struct dt_info *dti, struct node = *node) +{ + struct node *c; + struct property *prop; + struct marker *m; + struct node *refnode; + cell_t phandle; + + for_each_property(node, prop) { + m =3D prop->val.markers; + for_each_marker_of_type(m, REF_PHANDLE) { + if (m->ref) + continue; + + if (m->is_local) { + phandle =3D propval_cell_n(prop, + m->offset / sizeof(cell_t)); + refnode =3D get_node_by_phandle(dti->dt, phandle); + if (!refnode) + die("Node not found for phandle 0x%"PRIx32"\n", phandle); + + m->ref =3D refnode->fullpath; + continue; + } else { + die("Found a non local phandle without a reference\n"); + } + } + } + + for_each_child(node, c) + update_phandles_ref_internal(dti, c); +} + +void update_phandles_ref(struct dt_info *dti) +{ + update_phandles_ref_internal(dti, dti->dt); +} --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2A6025A34F for ; Mon, 12 Jan 2026 14:20:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227641; cv=none; b=c76PbSEqOat87DLGQN+EwV+UIQ37Wd35Q1G8iOyDO6XWHMWfbJDr3AhtEoNjtUSx+ufO5g98HrOooLgHMO4VZdBgPxEbWpMFHeDbMYfTedio3sPqIzZoGPvh9ge6arlt6D40ZQLVIEW6Bm7gIwIZO3MUhVtLMIgyop5+jmCEFWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227641; c=relaxed/simple; bh=Q7d+N+qaxCS1cL3oXzPN5kKvGycb5yJI0kIRov0CX3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=esKNXmus7/pp15R9lrCATY6lqbEL9MVtdD3IPlmtRTJZMs081wuSpRSyF6+VDUpK6jRrdyBDb7lxvju5e5zCXmHuM1iAenaNnsw28NefLIhK/73ruicS7L/i1G9bhvDBssWHMZA0sZvoECm4XcRkGfKSdiL+7L6mJyHK2g3V++g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=TVl3VYYO; arc=none smtp.client-ip=185.246.84.56 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.b="TVl3VYYO" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id E51E31A27F5; Mon, 12 Jan 2026 14:20:36 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id BBA1C606FA; Mon, 12 Jan 2026 14:20:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C0690103C9260; Mon, 12 Jan 2026 15:20:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227635; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=R0j2VCBhRwI5mPHPNv3oVXmquGF1BZdBGvded0qwW+M=; b=TVl3VYYO2PeZfexko6SRu6Nw/Ycm7ksufavfAQTxnxIK42vK0+DO07XgkeIwA0EIVu/Akk i06lXDtoIgdiwd8hiFvmJ6ZZf805Ast6ZgJ5vrhsNuj6aNx/bG+Ja+lfZ2r7JDcsmHI66a BAhSOjzIh4n1Gk0lMhVlmS4o2mlnnbzLjJ9PLhtDOhdmq1UFIIEpcK4dd+gUwxllMt+DUW 3iqBe8RJ2ga1OJrD0FhzLCuDQcmZPssDKXO8rcf2KDd/wFOP+BflkiSVJVEGBnDpdS4TKa oJpaGD3JuDAxPVipah8u/Ay5c0N86RQXvv+GYEP4J1NQ6WireXL7cd2ouCTUxA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 09/77] dtc: Introduce mark_local_phandles() Date: Mon, 12 Jan 2026 15:18:59 +0100 Message-ID: <20260112142009.1006236-10-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference. This is the purpose of mark_local_phandles(). It identifies a phandle reference as a local reference when this reference points to a local node. With that node, the related FDT_REF_LOCAL tag is set in the dtb. Signed-off-by: Herve Codina --- dtc.c | 1 + dtc.h | 1 + livetree.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/dtc.c b/dtc.c index 88f03ff..d0b4de3 100644 --- a/dtc.c +++ b/dtc.c @@ -334,6 +334,7 @@ int main(int argc, char *argv[]) } =20 update_phandles_ref(dti); + mark_local_phandles(dti); =20 process_checks(force, dti); =20 diff --git a/dtc.h b/dtc.h index 351fe41..08c9f07 100644 --- a/dtc.h +++ b/dtc.h @@ -346,6 +346,7 @@ void generate_fixups_tree(struct dt_info *dti, const ch= ar *name); void generate_local_fixups_tree(struct dt_info *dti, const char *name); =20 void update_phandles_ref(struct dt_info *dti); +void mark_local_phandles(struct dt_info *dti); =20 /* Checks */ =20 diff --git a/livetree.c b/livetree.c index 9e30a63..2a0a7ed 100644 --- a/livetree.c +++ b/livetree.c @@ -1196,3 +1196,29 @@ void update_phandles_ref(struct dt_info *dti) { update_phandles_ref_internal(dti, dti->dt); } + +static void mark_local_phandles_internal(struct dt_info *dti, + struct node *node) +{ + struct node *c; + struct property *prop; + struct marker *m; + struct node *refnode; + + for_each_property(node, prop) { + m =3D prop->val.markers; + for_each_marker_of_type(m, REF_PHANDLE) { + refnode =3D get_node_by_ref(dti->dt, m->ref); + if (refnode) + m->is_local =3D true; + } + } + + for_each_child(node, c) + mark_local_phandles_internal(dti, c); +} + +void mark_local_phandles(struct dt_info *dti) +{ + mark_local_phandles_internal(dti, dti->dt); +} --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 915252D3225; Mon, 12 Jan 2026 14:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227641; cv=none; b=Ogn0pi2q1LEKjt6slkI0p8Q2AXFBVMb2CYlOTWl5s39+2sTy9lZ/pRPwNPqGXyH3etxGqS3iq3EwY6kleo9NbqP517RUZ6dmxyombVrHZa3tN5+NgePSXnY2ljZd999iPN+aWXNKWv/aiXgnLnqo65g0walI6RyDgsWQ2uSQiW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227641; c=relaxed/simple; bh=ZXU9XNcj48fjtMAslY9eni60v2cXAHj2Unj3M3PwFZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNjMzrySf329WYeizED1J8fTTs2GYpHZmXMFIC8kiZ49Nyk6kRNY2FxRu8GGxcNCMAl6WwzcV90E+yOLbuN+N/6dlEwT/2pTWZz/ktb1T6SfChjNrj/Xj1v1+H33H5phoYIUtz3OpLoxmVgBOo7ts5VIcFHcz0EgT+gh4W5krR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=tTVs3QV5; arc=none smtp.client-ip=185.246.85.4 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.b="tTVs3QV5" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 5245F4E4208D; Mon, 12 Jan 2026 14:20:38 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 27451606FA; Mon, 12 Jan 2026 14:20:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3ED41103C9264; Mon, 12 Jan 2026 15:20:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227637; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=8uFabX923YEkpFpxXtAznZ2imCbjUvPJlwt8YWDTWN8=; b=tTVs3QV5Y8OiHUr0K8AWV6WiaX8f0TDt/7Vu0Fj4Z5coMYpYYSrhN2RzcmdXc/jPuobbMo LTQk2yUzU0ikk/ymI+CI4l+Oi7sesfB76T8ywTCFyosJQ2GPmmJr7ORg82c65IgbusE5Rq 1J+4zRIjw2mjBof3muqEbDzvOghd9uLUPT6jAR2fuNIgX3pVjn1adTH05r8YnxHr7Z3btx 3167bEOt8r4YbUsUA16CQVRW3d4ffW3ng22Bku7A2OTrXXyrWks822DdaqLHY40HORE/4N eYw0DAztIWWFDSCOtv1DNcOj2f0a0Q69ExCAPhCtEP/GNl7s1K7CdSFaF2k/UQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 10/77] tests: Add basic metadata tests Date: Mon, 12 Jan 2026 15:19:00 +0100 Message-ID: <20260112142009.1006236-11-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" This first test is related to local phandle references (FDT_REF_LOCAL dtb tag). The test pattern used is - Generate a dts (xxx.dts.dts) from an input dts - Check this generated dts against expected contents - Generate a dtb (xxx.dtb) from the same input dts - Check this generated dtb against expected contents - Generate a dts (xxx.dtb.dts) from the generated dtb - Check this generated dts against expected contents - Generate a dtb (xxx.dtb.dts.dtb) from the generated dts - Check this generated dtb, expect the same contents as for xxx.dtb Even if only one meta-data feature is currently tested in this tests introduction, use a loop in order to ease future addition consisting in adding new input dts as soon as new meta-data feature are supported. Signed-off-by: Herve Codina --- tests/meson.build | 3 +- tests/metadata_reflocal.dtb.dts.expect | 23 ++++++++++ tests/metadata_reflocal.dtb.expect | 20 +++++++++ tests/metadata_reflocal.dts | 27 ++++++++++++ tests/metadata_reflocal.dts.dts.expect | 23 ++++++++++ tests/run_tests.sh | 58 +++++++++++++++++++++++++- 6 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 tests/metadata_reflocal.dtb.dts.expect create mode 100644 tests/metadata_reflocal.dtb.expect create mode 100644 tests/metadata_reflocal.dts create mode 100644 tests/metadata_reflocal.dts.dts.expect diff --git a/tests/meson.build b/tests/meson.build index 37bfd47..e81a2e1 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -140,7 +140,8 @@ run_test_types =3D [ 'fdtget', 'fdtput', 'fdtdump', - 'fdtoverlay' + 'fdtoverlay', + 'metadata' ] run_test_deps =3D [ dtc_tools, dumptrees_dtb, tests_exe diff --git a/tests/metadata_reflocal.dtb.dts.expect b/tests/metadata_refloc= al.dtb.dts.expect new file mode 100644 index 0000000..076c17a --- /dev/null +++ b/tests/metadata_reflocal.dtb.dts.expect @@ -0,0 +1,23 @@ +/dts-v1/; + +/ { + + node-a { + + subnode-a { + phandle =3D <0x01>; + }; + }; + + node-b { + phandle =3D <0x02>; + }; + + node-c { + }; + + node-d { + ref-subnode-a =3D <&{/node-a/subnode-a}>; + ref-node-b =3D <0x123 0x456 &{/node-b} 0x789>; + }; +}; diff --git a/tests/metadata_reflocal.dtb.expect b/tests/metadata_reflocal.d= tb.expect new file mode 100644 index 0000000..33b3896 --- /dev/null +++ b/tests/metadata_reflocal.dtb.expect @@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + node-a { + subnode-a { + phandle =3D <0x00000001>; + }; + }; + node-b { + phandle =3D <0x00000002>; + }; + node-c { + }; + node-d { + ref-subnode-a =3D <0x00000001>; + // [FDT_REF_LOCAL] ref-subnode-a[0] + ref-node-b =3D <0x00000123 0x00000456 0x00000002 0x00000789>; + // [FDT_REF_LOCAL] ref-node-b[8] + }; +}; diff --git a/tests/metadata_reflocal.dts b/tests/metadata_reflocal.dts new file mode 100644 index 0000000..f04d24f --- /dev/null +++ b/tests/metadata_reflocal.dts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + node-a { + subnode_a: subnode-a { + }; + }; + + node_b: node-b { + }; + + node-c { + }; + + node_d: node-d { + ref-subnode-a =3D <&subnode_a>; + }; +}; + +&node_d { + ref-node-b =3D <0x123 0x456 &node_b 0x789>; +}; diff --git a/tests/metadata_reflocal.dts.dts.expect b/tests/metadata_refloc= al.dts.dts.expect new file mode 100644 index 0000000..b72b545 --- /dev/null +++ b/tests/metadata_reflocal.dts.dts.expect @@ -0,0 +1,23 @@ +/dts-v1/; + +/ { + + node-a { + + subnode_a: subnode-a { + phandle =3D <0x01>; + }; + }; + + node_b: node-b { + phandle =3D <0x02>; + }; + + node-c { + }; + + node_d: node-d { + ref-subnode-a =3D <&subnode_a>; + ref-node-b =3D <0x123 0x456 &node_b 0x789>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index f07092b..7a8bdbc 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1090,6 +1090,59 @@ fdtoverlay_tests() { run_wrap_test test "$bd" =3D "$pd" } =20 +# $1: f1 file +# $2: f2 file +check_diff () { + printf "diff $1 $2: " + local f1=3D"$1" + local f2=3D"$2" + ( + if diff $f1 $f2 >/dev/null; then + PASS + else + if [ -z "$QUIET_TEST" ]; then + echo "DIFF :-:" + diff -u $f1 $f2 + fi + FAIL "Results differ from expected" + fi + ) +} + +# $1: dtb file +# $2: out file +wrap_fdtdump () { + printf "wrap_fdtdump $1: " + local dtb=3D"$1" + local out=3D"$2" + ( + if $FDTDUMP ${dtb} 2>/dev/null >${out}; then + PASS + else + FAIL + fi + ) +} + +metadata_tests() { + for dt in metadata_reflocal; do + run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" + base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" + run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" + base_run_test wrap_fdtdump $dt.dtb $dt.dtb.out + # Remove unneeded comments + sed -i '/^\/\/ /d' $dt.dtb.out + base_run_test check_diff $dt.dtb.out "$SRCDIR/$dt.dtb.expect" + run_dtc_test -I dtb -O dts -o $dt.dtb.dts $dt.dtb + base_run_test check_diff $dt.dtb.dts "$SRCDIR/$dt.dtb.dts.expect" + run_dtc_test -I dts -O dtb -o $dt.dtb.dts.dtb $dt.dtb.dts + base_run_test wrap_fdtdump $dt.dtb.dts.dtb $dt.dtb.dts.dtb.out + # Remove unneeded comments + sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out + base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect" + done +} + pylibfdt_tests () { run_dtc_test -I dts -O dtb -o test_props.dtb "$SRCDIR/test_props.dts" TMP=3D/tmp/tests.stderr.$$ @@ -1129,7 +1182,7 @@ while getopts "vt:me" ARG ; do done =20 if [ -z "$TESTSETS" ]; then - TESTSETS=3D"libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtove= rlay" + TESTSETS=3D"libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtove= rlay metadata" =20 # Test pylibfdt if the libfdt Python module is available. if ! $no_python; then @@ -1169,6 +1222,9 @@ for set in $TESTSETS; do "fdtoverlay") fdtoverlay_tests ;; + "metadata") + metadata_tests + ;; esac done =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DEFE2DA760; Mon, 12 Jan 2026 14:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227644; cv=none; b=sVT9b3NFwFDnNe/+Vk70YOGs4iPs1p1cDZ5Lfiw2ykcQRifegkdQxpEkNPzwEqayAVA7C8arevbSbtPEMgBBw3AGHQR8tvEuH8nIcDxo10mG5SmBjFnLnbY9qmyDaK/xhOjLDvBscN3SRXsF0eEEEe/PbhUZJfUmNmXnlRpVX70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227644; c=relaxed/simple; bh=qtSYMfEKE7N1RUZ+Et1MCf9TOQxcc6/qt8r1vbidjUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJ/SPESDDzmrqbfUT96JD7DFCu0nC00nVE/dwlQ+Zm0eto2kP11QbS5pY9lWZWeM24ECv+Frd56SMd5uOrk473V4d8zFS6ZIRODG97KrDIk37HJlxg6ptVHgrQM/rHIv/l0NODLUrJ2woEvJoyekjCn33G4X4cf/Napsya9+v1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=zDzGto/i; arc=none smtp.client-ip=185.246.85.4 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.b="zDzGto/i" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id AFDE94E4208E; Mon, 12 Jan 2026 14:20:39 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 86D67606FA; Mon, 12 Jan 2026 14:20:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9450A103C9266; Mon, 12 Jan 2026 15:20:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227638; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=MbYI6yj1uJVvzjpvfvc/MoMnyr+zoT0U56BLtMvMqdk=; b=zDzGto/i7u9rJjqABjQYHXFwCjBZM1I7A0OI/FM/F+n5jCXBgFZRzha8W/cFyApQrxZQuH hFjXeTST7u7Kib8fxgWOO0aEdYHHMKXAvBn3LO1S1g3Wm8bjCZkUHie76ztfh5kOyCMfeQ GzcUt+oGkfP4cmCfuv8KWvGMJYFSOzjK3Eu0rSx1RhGP72fH/IAbCgegnQ8FfkCS+ff0Z9 YLXYZJDRTPrVuA/ishACjl/2/UoUGqEbNyi3cI/DzR23ADc6KMZ0+OzYOTdqQePOBEAAPf XHHgdV91qd7G7uQazHXGzVwZzPRYoi1yJcJtjNFXBCGUrs30ibVZ/grDtD3RAg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 11/77] Add support for FDT_REF_PHANDLE dtb tag Date: Mon, 12 Jan 2026 15:19:01 +0100 Message-ID: <20260112142009.1006236-12-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob. The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property. It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree. It is followed by two values and a possible alignment padding: - offset (32bit): Offset in the property data where the phandle is available. - label (string including \0): The label to use to resolve the phandle value. - padding: Padding (0x00) added to have the next tag aligned on 32bit. Example: FDT_PROP 0x00000008 xxxxxxxx 0x00 0x01 0x02 0x03 0xff 0xff 0xff 0xff FDT_REF_PHANDLE 0x00000004 "foo1" 0x00 0x00 0x00 This means that at the offset 4 of the property data, the value (0xffffffff) is an unresolved phandle value and the related node is the node referenced by "foo1". This is what is encoded in the dtb when the related dts has a property with the value set to <0x00010203 &foo1> with 'foo1' a reference to an non local node. If several non local phandles are used in the property data, several FDT_REF_PHANDLE are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle. For instance, if a first property with 8 bytes of data has a unresolved phandle value at offset 4 referenced by "foo" and a second property with 16 bytes of data has unresolved phandle values at offset 0 and 8 referenced by "bar" and "baz", the following tags sequence is present: FDT_PROP 0x00000008 xxxxxxxx FDT_REF_PHANDLE 0x00000004 "foo" 0x00 0x00 0x00 FDT_PROP 0x00000010 xxxxxxxx FDT_REF_LOCAL 0x00000000 "bar" 0x00 0x00 0x00 FDT_REF_LOCAL 0x00000008 "baz" 0x00 0x00 0x00 Add support for this new dtb tag. Suggested-by: David Gibson Link: https://lore.kernel.org/all/aL-2fmYsbexEtpNp@zatzit/ Signed-off-by: Herve Codina --- dtc.c | 12 ++++++++++++ fdtdump.c | 10 ++++++++++ flattree.c | 37 +++++++++++++++++++++++++++++++++++++ libfdt/fdt.c | 16 ++++++++++++++++ libfdt/fdt.h | 2 ++ 5 files changed, 77 insertions(+) diff --git a/dtc.c b/dtc.c index d0b4de3..fe8e8e4 100644 --- a/dtc.c +++ b/dtc.c @@ -336,6 +336,18 @@ int main(int argc, char *argv[]) update_phandles_ref(dti); mark_local_phandles(dti); =20 + /* + * With FDT_REF_PHANDLE added in dtbs, we need to identified + * if some unresolved phandle references are allowed in the dtb + * we have parsed (needed for process_check() to run properly). + * + * Identify plugin device-trees (overlays) based on specific node + * presence. + */ + if (get_subnode(dti->dt, "__fixups__") || + get_subnode(dti->dt, "__local_fixups__")) + dti->dtsflags |=3D DTSF_PLUGIN; + process_checks(force, dti); =20 if (auto_label_aliases) diff --git a/fdtdump.c b/fdtdump.c index dffa9a6..7300280 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -158,6 +158,16 @@ static void dump_blob(void *blob, bool debug) continue; } =20 + if (tag =3D=3D FDT_REF_PHANDLE) { + offset =3D fdt32_to_cpu(GET_CELL(p)); + s =3D p; + p =3D PALIGN(p + strlen(s) + 1, 4); + + printf("%*s// [FDT_REF_PHANDLE] %s[%"PRIu32"], ref =3D %s\n", + depth * shift, "", last_prop_name, offset, s); + continue; + } + fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "",= tag); break; } diff --git a/flattree.c b/flattree.c index 5c597ad..07f7545 100644 --- a/flattree.c +++ b/flattree.c @@ -44,6 +44,7 @@ struct emitter { void (*endnode)(void *, struct label *labels); void (*property)(void *, struct label *labels); void (*ref_local)(void *); + void (*ref_phandle)(void *); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -98,6 +99,11 @@ static void bin_emit_ref_local(void *e) bin_emit_cell(e, FDT_REF_LOCAL); } =20 +static void bin_emit_ref_phandle(void *e) +{ + bin_emit_cell(e, FDT_REF_PHANDLE); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -107,6 +113,7 @@ static struct emitter bin_emitter =3D { .endnode =3D bin_emit_endnode, .property =3D bin_emit_property, .ref_local =3D bin_emit_ref_local, + .ref_phandle =3D bin_emit_ref_phandle, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -226,6 +233,14 @@ static void asm_emit_ref_local(void *e) asm_emit_cell(e, FDT_REF_LOCAL); } =20 +static void asm_emit_ref_phandle(void *e) +{ + FILE *f =3D e; + + fprintf(f, "\t/* FDT_REF_PHANDLE */\n"); + asm_emit_cell(e, FDT_REF_PHANDLE); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -235,6 +250,7 @@ static struct emitter asm_emitter =3D { .endnode =3D asm_emit_endnode, .property =3D asm_emit_property, .ref_local =3D asm_emit_ref_local, + .ref_phandle =3D asm_emit_ref_phandle, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -299,6 +315,15 @@ static void flatten_tree(struct node *tree, struct emi= tter *emit, emit->cell(etarget, m->offset); continue; } + + if (m->ref[0] =3D=3D '/') + die("Phandle uses a non local reference by path (%s)\n", + m->ref); + + emit->ref_phandle(etarget); + emit->cell(etarget, m->offset); + emit->string(etarget, m->ref, 0); + emit->align(etarget, sizeof(cell_t)); } } } @@ -767,6 +792,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, const char *flatname; uint32_t val; uint32_t offset; + const char *str; =20 node =3D build_node(NULL, NULL, NULL); =20 @@ -824,6 +850,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, prop->val =3D data_append_markers(prop->val, m); break; =20 + case FDT_REF_PHANDLE: + if (!(flags & FTF_REF_XXX)) + die("REF_PHANDLE tag found in flat tree" + " version <18\n"); + + offset =3D flat_read_word(dtbuf); + str =3D flat_read_string(dtbuf); + m =3D alloc_marker(offset, REF_PHANDLE, xstrdup(str)); + prop->val =3D data_append_markers(prop->val, m); + break; + default: die("Invalid opcode word %08x in device tree blob\n", val); diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 7268fb6..8f3c35d 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -217,6 +217,21 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) offset +=3D sizeof(fdt32_t); break; =20 + case FDT_REF_PHANDLE: + /* Skip offset value */ + tmp32p =3D fdt_offset_ptr(fdt, offset, sizeof(*tmp32p)); + if (!can_assume(VALID_DTB) && !tmp32p) + return FDT_END; /* premature end */ + offset +=3D sizeof(fdt32_t); + + /* Skip ref */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + break; + default: return FDT_END; } @@ -257,6 +272,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) return tag; =20 case FDT_REF_LOCAL: + case FDT_REF_PHANDLE: /* * Next tag is a meta-data tag present in the middle * of the structure -> Skip it and look at next one diff --git a/libfdt/fdt.h b/libfdt/fdt.h index f8efdf1..530d2e5 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -56,6 +56,8 @@ struct fdt_property { size, content */ #define FDT_NOP 0x4 /* nop */ #define FDT_REF_LOCAL 0x5 /* local phandle reference: offset */ +#define FDT_REF_PHANDLE 0x6 /* external phandle reference: offset, + external label */ #define FDT_END 0x9 =20 #define FDT_V1_SIZE (7*sizeof(fdt32_t)) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A45D27F72C; Mon, 12 Jan 2026 14:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227646; cv=none; b=J4fq6X4Z+OerkmJJX+vcpvQCQhEUxZNpn6fzTv8jtuB+x4nxp8Htnx9T6ADFlV/0miAM7JpRdX3K4LW56zFQlNSqI5b2QoEQqpGUZs0os8VQBE0HgVhW5JVoKsQaJ606jm44J4DqPxOoDGCToiMr9cpJiIO1wDg52qY8ijZ/wes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227646; c=relaxed/simple; bh=MoQoo9fRri73x9p0C7T9REHSx3MxrPKkzLwacQcp6ss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bu1qwp6nTPJaU3F+XpbFfdP3WcY7bJarDvLXY2CC/APkzcBXD76jK267q6cWA64joJ7CsvJpel9PlsU9/lZmRoqH9XPOL7WpHnVGXHeWdSzkVp2TZPz6JMjkw4PeuvlbOolZFb973ykLt0/v2LVFO21Wld2ldrd0YcgDwlhOnV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=JlZMYo4d; arc=none smtp.client-ip=185.246.84.56 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.b="JlZMYo4d" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 2991D1A27F7; Mon, 12 Jan 2026 14:20:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0028D606FA; Mon, 12 Jan 2026 14:20:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 13776103C9265; Mon, 12 Jan 2026 15:20:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227640; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=28CXldTWxJfeqeWSrkzBjbOfb3UPT1622I/9ZKpFlS0=; b=JlZMYo4dpsnirBrviWPJYU0bl8RDspVQjqg8rtQtRfgIkdtbl3+Q2kw3qWYHQ7InkeMJIv ETxU8b5LnF2vPxvoU345fRe3HTo+A7EshEhZDU8ZUBybEs/OO1/9x0RtuXGoaMUitipfIh pMjcmdTx518/cNgVB09bjxaXKbrnRNYY3POYP2Se9dTkywOXPJwnajvZqsb51tyfmeZN6z lmDIA5Z+2KQFoVE52jTT4b5BGPKn0zOdR9/Lh9efi6EsqOq7ao8vL+d3n0pUm5NHTqbKYW T3mJ3SZll1oaDGXM/SAFqo1UCLRXH1/bb/e7KXRWBtNpga9yRqXQqx+r6sTPRQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 12/77] tests: metadata: Add external phandle reference tests Date: Mon, 12 Jan 2026 15:19:02 +0100 Message-ID: <20260112142009.1006236-13-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add tests related to external phandle references (FDT_REF_PHANDLE dtb tag). Signed-off-by: Herve Codina --- tests/metadata_refphandle.dtb.dts.expect | 17 +++++++++++++++++ tests/metadata_refphandle.dtb.expect | 16 ++++++++++++++++ tests/metadata_refphandle.dts | 11 +++++++++++ tests/metadata_refphandle.dts.dts.expect | 17 +++++++++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_refphandle.dtb.dts.expect create mode 100644 tests/metadata_refphandle.dtb.expect create mode 100644 tests/metadata_refphandle.dts create mode 100644 tests/metadata_refphandle.dts.dts.expect diff --git a/tests/metadata_refphandle.dtb.dts.expect b/tests/metadata_refp= handle.dtb.dts.expect new file mode 100644 index 0000000..c229ec1 --- /dev/null +++ b/tests/metadata_refphandle.dtb.dts.expect @@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + + fragment@0 { + target =3D <&test>; + + __overlay__ { + ref =3D <&node_a>; + }; + }; + + __fixups__ { + test =3D "/fragment@0:target:0"; + node_a =3D "/fragment@0/__overlay__:ref:0"; + }; +}; diff --git a/tests/metadata_refphandle.dtb.expect b/tests/metadata_refphand= le.dtb.expect new file mode 100644 index 0000000..b2f5f95 --- /dev/null +++ b/tests/metadata_refphandle.dtb.expect @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + fragment@0 { + target =3D <0xffffffff>; + // [FDT_REF_PHANDLE] target[0], ref =3D test + __overlay__ { + ref =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref[0], ref =3D node_a + }; + }; + __fixups__ { + test =3D "/fragment@0:target:0"; + node_a =3D "/fragment@0/__overlay__:ref:0"; + }; +}; diff --git a/tests/metadata_refphandle.dts b/tests/metadata_refphandle.dts new file mode 100644 index 0000000..b8aa650 --- /dev/null +++ b/tests/metadata_refphandle.dts @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/plugin/; + +&test { + ref =3D <&node_a>; +}; diff --git a/tests/metadata_refphandle.dts.dts.expect b/tests/metadata_refp= handle.dts.dts.expect new file mode 100644 index 0000000..c229ec1 --- /dev/null +++ b/tests/metadata_refphandle.dts.dts.expect @@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + + fragment@0 { + target =3D <&test>; + + __overlay__ { + ref =3D <&node_a>; + }; + }; + + __fixups__ { + test =3D "/fragment@0:target:0"; + node_a =3D "/fragment@0/__overlay__:ref:0"; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 7a8bdbc..423812e 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1125,7 +1125,7 @@ wrap_fdtdump () { } =20 metadata_tests() { - for dt in metadata_reflocal; do + for dt in metadata_reflocal metadata_refphandle; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1CFD2DECB2 for ; Mon, 12 Jan 2026 14:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227647; cv=none; b=rHhbKoleEf7mgMktVlVuB2wRErSHbI49ZbtUXHrcgZ+H4SVUlO6NH1bv0eMEZu+G+PFBgBZY1ijA5FMdiD4V55SQMOgUGmSLiQUcQKHQGtKwgBI19uhEDnEzhpwlRT+JusH0XMbvRF0TgRrRj7xdcOywp5aJIRoBgwcMHRUnpBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227647; c=relaxed/simple; bh=4Sq/1CVeRzD85KIjpnxfyqvFZlORW4g64otbK0jjiWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JPWnGZXlvFq9p7wi+uLh0SDi2h4FRYHmZxuCuhNwoRnpYSsqIHUsTj9/dtW22uvHoneXKlBIHY0TaBL1JpGxE2GJuzGrJbyt/UAP1mqiie9RRpuFLfpxLoIfUHUrRzVhOH2tEKQqVuIJpG5jt2L8C3phUIxu90pEFH4xIWrYFB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WLsOu/ol; arc=none smtp.client-ip=185.246.84.56 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.b="WLsOu/ol" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B44481A27F8; Mon, 12 Jan 2026 14:20:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8BB4D606FA; Mon, 12 Jan 2026 14:20:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 87B16103C9268; Mon, 12 Jan 2026 15:20:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227641; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=wJikY3Tv3xBu71ohhuSowpW9N3sVjLEUGSxvZacmO+Y=; b=WLsOu/ol/7YG/u7o8QkS2b6QZvUfdGg6ICeirrUKJvnxFf7Yapj/uQ41efx0SYmA9OgX2+ 2JqNtzu4futS8loeLggavBt++yyrb+vLdi1/Be8wbO7TTMlMOB1pj4vl+VboTuJDRMApRO i83kixnVRIlUYZGaV+uc9n6F7xKf5GxXYdAbfY1OPA1UJn/enseW0Iahk7fp3PvYajmVmE tNVFJMjlSSiNvfZz/vwRG10oX49pqON0yaUdPQhf1NYslAM6ZpF9FWwAgFY+pEjHRqNU+g qBUJY2DCdyYAnGExDwZG7wwiigjluqYIEtzll+OCodygDkM5GufMhMZCQgQ05A== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 13/77] Introduce dt_flags field in dtb header Date: Mon, 12 Jan 2026 15:19:03 +0100 Message-ID: <20260112142009.1006236-14-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" There is no simple way to identify a kind of dtb. A dtb can be a "standard" device-tree blob but with the future support for addon dtb, a dtb could be an addon dtb. Whereas, looking at node structures and name, we can identify if a "standard" dtb is a pure base device-tree or an overlay device-tree, this will be no more possible with addons. Indeed, specific node such as __local_fixups__ and/or __fixups__ present in overlays will be no more present in addons. In order to avoid any complex and error prone searches in the dtb structure to identify whether or not a dtb is an addon, encode this information directly in the dtb itself. This is the purpose of the dt_flags field. Prepare the support for 'addon' flag introducing the dt_flags field in the dtb header. Signed-off-by: Herve Codina --- fdtdump.c | 4 ++++ flattree.c | 17 +++++++++++++---- libfdt/fdt.h | 5 ++++- libfdt/fdt_rw.c | 4 ++++ libfdt/libfdt.h | 1 + tests/pylibfdt_tests.py | 6 +++--- tests/testutils.c | 2 +- tests/trees.S | 1 + 8 files changed, 31 insertions(+), 9 deletions(-) diff --git a/fdtdump.c b/fdtdump.c index 7300280..5c78559 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -87,6 +87,10 @@ static void dump_blob(void *blob, bool debug) if (version >=3D 17) printf("// size_dt_struct:\t0x%"PRIx32"\n", fdt32_to_cpu(bph->size_dt_struct)); + if (version >=3D 18) { + printf("// dt_flags:\t\t0x%"PRIx32"\n", + fdt32_to_cpu(bph->dt_flags)); + } printf("\n"); =20 for (i =3D 0; ; i++) { diff --git a/flattree.c b/flattree.c index 07f7545..2e2ffcb 100644 --- a/flattree.c +++ b/flattree.c @@ -14,6 +14,7 @@ #define FTF_STRUCTSIZE 0x20 #define FTF_NOPS 0x40 #define FTF_REF_XXX 0x80 +#define FTF_DTFLAGS 0x100 =20 static struct version_info { int version; @@ -32,7 +33,8 @@ static struct version_info { {17, 16, FDT_V17_SIZE, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, {18, 18, FDT_V18_SIZE, - FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX}, + FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX| + FTF_DTFLAGS}, }; =20 struct emitter { @@ -370,7 +372,7 @@ static struct data flatten_reserve_list(struct reserve_= info *reservelist, static void make_fdt_header(struct fdt_header *fdt, struct version_info *vi, int reservesize, int dtsize, int strsize, - int boot_cpuid_phys) + int boot_cpuid_phys, uint32_t dt_flags) { int reserve_off; =20 @@ -397,6 +399,8 @@ static void make_fdt_header(struct fdt_header *fdt, fdt->size_dt_strings =3D cpu_to_fdt32(strsize); if (vi->flags & FTF_STRUCTSIZE) fdt->size_dt_struct =3D cpu_to_fdt32(dtsize); + if (vi->flags & FTF_DTFLAGS) + fdt->dt_flags =3D cpu_to_fdt32(dt_flags); } =20 void dt_to_blob(FILE *f, struct dt_info *dti, int version) @@ -424,7 +428,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) =20 /* Make header */ make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, - dti->boot_cpuid_phys); + dti->boot_cpuid_phys, 0); =20 /* * If the user asked for more space than is used, adjust the totalsize. @@ -555,6 +559,11 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versi= on) symprefix, symprefix); } =20 + if (vi->flags & FTF_DTFLAGS) { + fprintf(f, "\t/* dt_flags */\n"); + asm_emit_cell(f, 0); + } + /* * Reserve map entries. * Align the reserve map to a doubleword boundary. @@ -980,7 +989,7 @@ struct dt_info *dt_from_blob(const char *fname) } =20 if (version >=3D 18) - flags |=3D FTF_REF_XXX; + flags |=3D FTF_REF_XXX | FTF_DTFLAGS; =20 inbuf_init(&memresvbuf, blob + off_mem_rsvmap, blob + totalsize); diff --git a/libfdt/fdt.h b/libfdt/fdt.h index 530d2e5..128e7bc 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -26,6 +26,9 @@ struct fdt_header { =20 /* version 17 fields below */ fdt32_t size_dt_struct; /* size of the structure block */ + + /* version 18 fields below */ + fdt32_t dt_flags; /* Ored value of FDT_FLAG_XXXX */ }; =20 struct fdt_reserve_entry { @@ -65,6 +68,6 @@ struct fdt_property { #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t)) #define FDT_V16_SIZE FDT_V3_SIZE #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) -#define FDT_V18_SIZE FDT_V17_SIZE +#define FDT_V18_SIZE (FDT_V17_SIZE + sizeof(fdt32_t)) =20 #endif /* FDT_H */ diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c index 00e32bb..1528b33 100644 --- a/libfdt/fdt_rw.c +++ b/libfdt/fdt_rw.c @@ -457,6 +457,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsi= ze) return err; fdt_set_version(buf, 18); fdt_set_last_comp_version(buf, 18); + if (can_assume(LATEST) || fdt_version(fdt) < 18) + fdt_set_dt_flags(buf, 0); fdt_set_size_dt_struct(buf, struct_size); fdt_set_totalsize(buf, bufsize); return 0; @@ -487,6 +489,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsi= ze) fdt_set_totalsize(buf, bufsize); fdt_set_version(buf, 18); fdt_set_last_comp_version(buf, 18); + if (can_assume(LATEST) || fdt_version(fdt) < 18) + fdt_set_dt_flags(buf, 0); fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); =20 return 0; diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index d1a9cd5..9777f32 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -319,6 +319,7 @@ fdt_set_hdr_(last_comp_version) fdt_set_hdr_(boot_cpuid_phys) fdt_set_hdr_(size_dt_strings) fdt_set_hdr_(size_dt_struct) +fdt_set_hdr_(dt_flags) #undef fdt_set_hdr_ =20 /** diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py index 373e11a..7d5ab0b 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -285,9 +285,9 @@ class PyLibfdtBasicTests(unittest.TestCase): """Test that we can access the header values""" self.assertEqual(self.fdt.magic(), 0xd00dfeed) self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt)) - self.assertEqual(self.fdt.off_dt_struct(), 88) - self.assertEqual(self.fdt.off_dt_strings(), 652) - self.assertEqual(self.fdt.off_mem_rsvmap(), 40) + self.assertEqual(self.fdt.off_dt_struct(), 96) + self.assertEqual(self.fdt.off_dt_strings(), 660) + self.assertEqual(self.fdt.off_mem_rsvmap(), 48) self.assertEqual(self.fdt.version(), 18) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) diff --git a/tests/testutils.c b/tests/testutils.c index 54da2e4..2d5cfb3 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -344,7 +344,7 @@ void *open_blob_rw(const void *blob) { int err; void *buf; - int newsize =3D fdt_totalsize(blob) + 8; + int newsize =3D fdt_totalsize(blob) + 8 + 4; =20 buf =3D xmalloc(newsize); err =3D fdt_open_into(blob, buf, newsize); diff --git a/tests/trees.S b/tests/trees.S index ecd43bc..56c1002 100644 --- a/tests/trees.S +++ b/tests/trees.S @@ -22,6 +22,7 @@ fdtlong 0 fdtlong (\tree\()_strings_end - \tree\()_strings) fdtlong (\tree\()_struct_end - \tree\()_struct) + fdtlong 0 .endm =20 .macro rsvmape addrh, addrl, lenh, lenl --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37AEC2C08DB for ; Mon, 12 Jan 2026 14:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227649; cv=none; b=iaMfrLAa/kWPADdAe2EmzAt+fRPi/uilfC3jhlgZuO1vExIxabPwPxEsErcqm3u9W4JY+WxYG8EfHjE+Xtdd/7scnHf1z6MoQHE+e189Yuh+tganKYFsA/TXD6QtvIFNaz4ONYvTOi8K+4ctxNE3PZnYZ23prpwZg5htJTZYRcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227649; c=relaxed/simple; bh=XvLIFqpeEbLFADaL5p0Q+qHRNYTX/5GQLS/+uAVdZa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n+RuG71DebSrLrw44+dPKnRL+I8w6pbmZWLycBfA/YxZe6Z1AAhG1FeR4gBYHT9GSpv0QM3BYRCgn0MYrtNeHLsCgkjXpZ3R/jGMP7lTPyG8wbOS5hMLjZVSKMzbqQJY/Fs0knt3bPYZjn51saDPZi/v7b1SOpxHG8qVoJZQBy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=RkrDBzSL; arc=none smtp.client-ip=185.246.85.4 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.b="RkrDBzSL" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id F3C934E42090; Mon, 12 Jan 2026 14:20:43 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C85D8606FA; Mon, 12 Jan 2026 14:20:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E03A5103C9267; Mon, 12 Jan 2026 15:20:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227643; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=1W7eqtIgrJuKdFP3qxsLYlClLy4pTWcfAqfQQTtlhuw=; b=RkrDBzSLeRIUdNv0q8NELu34XbmtHQFzIlfVsbqH8F+qbBFGMZB6Tg46V/FqFDwr52uLpu u0pMQPxZ4nL1Bfav57Ow2afnuR6P3c7jFD1BrBdaw1q0r/iXe9cSnzXCJ04iB12ryUWp/D ujf9LqtkPAXyQDdGoY5mHWgK1NlGrxx1iFu/Nn1p9XGxpjwm9wK/fUNLmc/Q7oq4khmlwQ fE3vYaBxAPFh+rYSYFVw/b+plra4igT47uKdUfkD8M+vNi+MzY62KR/NXQHiOOzHWLzkcG iItkINEz4ybdCA5uygVJqc/d4VnxYUdIJniNk+ceZU7AOKJhMYWfFUlx0cWLTw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 14/77] tests: metadata: Add a first test related to the dt_flags header field Date: Mon, 12 Jan 2026 15:19:04 +0100 Message-ID: <20260112142009.1006236-15-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" A new field has been recently added to the dtb header: dt_flags. Even if this field is not yet used to encode meaningful information, add a basic test related to this field (presence and its 0 default value). Signed-off-by: Herve Codina --- tests/metadata_dtflags0.dtb.expect | 1 + tests/metadata_dtflags0.dts | 10 ++++++++++ tests/run_tests.sh | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 tests/metadata_dtflags0.dtb.expect create mode 100644 tests/metadata_dtflags0.dts diff --git a/tests/metadata_dtflags0.dtb.expect b/tests/metadata_dtflags0.d= tb.expect new file mode 100644 index 0000000..cefed4d --- /dev/null +++ b/tests/metadata_dtflags0.dtb.expect @@ -0,0 +1 @@ +// dt_flags: 0x0 diff --git a/tests/metadata_dtflags0.dts b/tests/metadata_dtflags0.dts new file mode 100644 index 0000000..3ef867e --- /dev/null +++ b/tests/metadata_dtflags0.dts @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + prop =3D <1>; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 423812e..496fcb9 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1141,6 +1141,12 @@ metadata_tests() { sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect" done + + run_dtc_test -I dts -O dtb -o metadata_dtflags0.dtb "$SRCDIR/metadata_dtf= lags0.dts" + base_run_test wrap_fdtdump metadata_dtflags0.dtb metadata_dtflags0.dtb.out + # Keep only lines containing 'dt_flags' + sed -i '/dt_flags/!d' metadata_dtflags0.dtb.out + base_run_test check_diff metadata_dtflags0.dtb.out "$SRCDIR/metadata_dtfl= ags0.dtb.expect" } =20 pylibfdt_tests () { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABB372BDC2C; Mon, 12 Jan 2026 14:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227648; cv=none; b=RCSV6L/gjc2LogrlPYW+kSBTsfw1fFEVf8SLldHtz23B0rOD45W186WmkQCHgxNI94S3m10UtaaIBAXPkZf+RZKq/k8ofEBWkZhF6PnhsjiF/m6IfaBPB7no6wpWJo9TLaiIg5oSdBPXxjpPZvR7/txKHN8MU2G9SJCRXHdBYK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227648; c=relaxed/simple; bh=CGhVj0rPDjrSgzY9Y2DyIxpIJAgBRyAzL1bzNjUQQ1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h79toinO0rpfBv+OJbKMRplJSzwP95p2XZzbX9eEl4UbFxCh1ANNGxVpC9hri8ceUP0Cl4PpsjBLWddjZ/Xra5MMZ/a+9jqg38INSE6r3/oW9QYSsw2xIq5+RQGRRQ+J5BeA6OiSAC3GB/BJz18aouKUvjW8TMlD6762It/uByI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=zu/p2taW; arc=none smtp.client-ip=185.171.202.116 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.b="zu/p2taW" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C8CA1C2086B; Mon, 12 Jan 2026 14:20:18 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4B681606FA; Mon, 12 Jan 2026 14:20:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5B327103C926D; Mon, 12 Jan 2026 15:20:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227644; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3OKVz8i59SL65e0p8xDL+tkJPTJE7M038p7RDTRf2m0=; b=zu/p2taWdblR8lmPwxKjUVGNgI5FGn3i6SziPhJYE98ezluUZAtsAC5a9SHUit9xvTHqeb VV+yLxuuCDKS9TdUR6+qVCwkuqB3iTWAHTHvLBr9ZTzpbqtd/bf0CZFe1dnTBRzGQyKMFR FTAKp1LHXV4p2ULE34oflvIitpQzT5h1vpGV2lsr1wkL0PKzrlF4hGau/9VPOoYwLQQK7P TWVpHHHgXKQFKLN+U+CKfIwKsVv7JkpIHR4yIEYo6fh23AR44n9Bd8MgGiPSltFbGx2YgD 46i5T4dE0a+aEpoOrzV3LhEsVX91br+mb4mybhbD95z+Gcw1Ht+gpWO8oB8hiQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 15/77] Add support for /addon/ keyword Date: Mon, 12 Jan 2026 15:19:05 +0100 Message-ID: <20260112142009.1006236-16-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The dts /addon/ keyword allows to mark a dts as an addon dts. This is similar to /plugin/ used for overlay dts but specific to addon dts. It is also worth noting that a dts tagged with /addon/ will lead to a dtb with the dt_flags set to FDT_FLAG_ADDON (0x1). This allows to identify without any ambiguity an addon dts and an addon dtb. Signed-off-by: Herve Codina --- checks.c | 26 +++++++++++++------------- dtc-lexer.l | 5 +++++ dtc-parser.y | 5 +++++ dtc.h | 1 + fdtdump.c | 6 +++++- flattree.c | 18 ++++++++++++++---- libfdt/fdt.h | 1 + libfdt/libfdt.h | 1 + treesource.c | 5 ++++- 9 files changed, 49 insertions(+), 19 deletions(-) diff --git a/checks.c b/checks.c index 041e565..2be19c0 100644 --- a/checks.c +++ b/checks.c @@ -616,7 +616,7 @@ static void fixup_phandle_references(struct check *c, s= truct dt_info *dti, =20 refnode =3D get_node_by_ref(dt, m->ref); if (! refnode) { - if (!(dti->dtsflags & DTSF_PLUGIN)) + if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) FAIL(c, dti, node, "Reference to non-existent node or " "label \"%s\"\n", m->ref); else /* mark the entry as unresolved */ @@ -718,8 +718,8 @@ static void check_alias_paths(struct check *c, struct d= t_info *dti, continue; } =20 - /* This check does not work for overlays with external paths */ - if (!(dti->dtsflags & DTSF_PLUGIN) && + /* This check does not work for overlays nor addons with external paths = */ + if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) && (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) { FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s= )", prop->val.val); @@ -1417,8 +1417,8 @@ static void check_property_phandle_args(struct check = *c, * entries when each index position has a specific definition. */ if (!phandle_is_valid(phandle)) { - /* Give up if this is an overlay with external references */ - if (dti->dtsflags & DTSF_PLUGIN) + /* Give up if this is an overlay or addon with external references */ + if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) break; =20 cellsize =3D 0; @@ -1651,8 +1651,8 @@ static void check_interrupt_map(struct check *c, =20 phandle =3D propval_cell_n(irq_map_prop, cell); if (!phandle_is_valid(phandle)) { - /* Give up if this is an overlay with external references */ - if (!(dti->dtsflags & DTSF_PLUGIN)) + /* Give up if this is an overlay or an addon with external references */ + if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) FAIL_PROP(c, dti, node, irq_map_prop, "Cell %zu is not a phandle(%d)", cell, phandle); @@ -1720,9 +1720,9 @@ static void check_interrupts_property(struct check *c, if (prop) { phandle =3D propval_cell(prop); if (!phandle_is_valid(phandle)) { - /* Give up if this is an overlay with + /* Give up if this is an overlay with or an addon * external references */ - if (dti->dtsflags & DTSF_PLUGIN) + if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) return; FAIL_PROP(c, dti, parent, prop, "Invalid phandle"); continue; @@ -1838,8 +1838,8 @@ static void check_graph_port(struct check *c, struct = dt_info *dti, =20 check_graph_reg(c, dti, node); =20 - /* skip checks below for overlays */ - if (dti->dtsflags & DTSF_PLUGIN) + /* skip checks below for overlays or addons */ + if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) return; =20 if (!strprefixeq(node->name, node->basenamelen, "port")) @@ -1880,8 +1880,8 @@ static void check_graph_endpoint(struct check *c, str= uct dt_info *dti, =20 check_graph_reg(c, dti, node); =20 - /* skip checks below for overlays */ - if (dti->dtsflags & DTSF_PLUGIN) + /* skip checks below for overlays or addons */ + if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) return; =20 if (!strprefixeq(node->name, node->basenamelen, "endpoint")) diff --git a/dtc-lexer.l b/dtc-lexer.l index 15d585c..a4a8e0b 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -111,6 +111,11 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_PLUGIN; } =20 +<*>"/addon/" { + DPRINT("Keyword: /addon/\n"); + return DT_ADDON; + } + <*>"/memreserve/" { DPRINT("Keyword: /memreserve/\n"); BEGIN_DEFAULT(); diff --git a/dtc-parser.y b/dtc-parser.y index 4d5eece..d8914d2 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -53,6 +53,7 @@ static bool is_ref_relative(const char *ref) =20 %token DT_V1 %token DT_PLUGIN +%token DT_ADDON %token DT_MEMRESERVE %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR %token DT_BITS @@ -120,6 +121,10 @@ header: { $$ =3D DTSF_V1 | DTSF_PLUGIN; } + | DT_V1 ';' DT_ADDON ';' + { + $$ =3D DTSF_V1 | DTSF_ADDON; + } ; =20 headers: diff --git a/dtc.h b/dtc.h index 08c9f07..c0fffd2 100644 --- a/dtc.h +++ b/dtc.h @@ -336,6 +336,7 @@ struct dt_info { /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ #define DTSF_PLUGIN 0x0002 /* /plugin/ */ +#define DTSF_ADDON 0x0004 /* /addon/ */ =20 struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, diff --git a/fdtdump.c b/fdtdump.c index 5c78559..9b6f41a 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -67,7 +67,6 @@ static void dump_blob(void *blob, bool debug) depth =3D 0; shift =3D 4; =20 - printf("/dts-v1/;\n"); printf("// magic:\t\t0x%"PRIx32"\n", fdt32_to_cpu(bph->magic)); printf("// totalsize:\t\t0x%"PRIx32" (%"PRIu32")\n", totalsize, totalsize); @@ -91,6 +90,11 @@ static void dump_blob(void *blob, bool debug) printf("// dt_flags:\t\t0x%"PRIx32"\n", fdt32_to_cpu(bph->dt_flags)); } + printf("/dts-v1/;\n"); + if (version >=3D 18) { + if (fdt32_to_cpu(bph->dt_flags) & FDT_FLAG_ADDON) + printf("/addon/;\n"); + } printf("\n"); =20 for (i =3D 0; ; i++) { diff --git a/flattree.c b/flattree.c index 2e2ffcb..bedb286 100644 --- a/flattree.c +++ b/flattree.c @@ -412,6 +412,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) struct data dtbuf =3D empty_data; struct data strbuf =3D empty_data; struct fdt_header fdt; + uint32_t dt_flags =3D 0; int padlen =3D 0; =20 for (i =3D 0; i < ARRAY_SIZE(version_table); i++) { @@ -421,6 +422,8 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) if (!vi) die("Unknown device tree blob version %d\n", version); =20 + dt_flags |=3D dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0; + flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi); bin_emit_cell(&dtbuf, FDT_END); =20 @@ -428,7 +431,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) =20 /* Make header */ make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, - dti->boot_cpuid_phys, 0); + dti->boot_cpuid_phys, dt_flags); =20 /* * If the user asked for more space than is used, adjust the totalsize. @@ -511,6 +514,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) struct data strbuf =3D empty_data; struct reserve_info *re; const char *symprefix =3D "dt"; + uint32_t dt_flags =3D 0; =20 for (i =3D 0; i < ARRAY_SIZE(version_table); i++) { if (version_table[i].version =3D=3D version) @@ -519,6 +523,8 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) if (!vi) die("Unknown device tree blob version %d\n", version); =20 + dt_flags |=3D dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0; + fprintf(f, "/* autogenerated by dtc, do not edit */\n\n"); =20 emit_label(f, symprefix, "blob_start"); @@ -561,7 +567,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) =20 if (vi->flags & FTF_DTFLAGS) { fprintf(f, "\t/* dt_flags */\n"); - asm_emit_cell(f, 0); + asm_emit_cell(f, dt_flags); } =20 /* @@ -897,6 +903,7 @@ struct dt_info *dt_from_blob(const char *fname) struct node *tree; uint32_t val; int flags =3D 0; + unsigned int dtsflags =3D 0; =20 f =3D srcfile_relative_open(fname, NULL); =20 @@ -988,8 +995,11 @@ struct dt_info *dt_from_blob(const char *fname) flags |=3D FTF_NOPS; } =20 - if (version >=3D 18) + if (version >=3D 18) { flags |=3D FTF_REF_XXX | FTF_DTFLAGS; + dtsflags |=3D fdt32_to_cpu(fdt->dt_flags) & FDT_FLAG_ADDON ? + DTSF_ADDON : 0; + } =20 inbuf_init(&memresvbuf, blob + off_mem_rsvmap, blob + totalsize); @@ -1012,5 +1022,5 @@ struct dt_info *dt_from_blob(const char *fname) =20 fclose(f); =20 - return build_dt_info(DTSF_V1, reservelist, tree, boot_cpuid_phys); + return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys); } diff --git a/libfdt/fdt.h b/libfdt/fdt.h index 128e7bc..94f65e6 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -51,6 +51,7 @@ struct fdt_property { #endif /* !__ASSEMBLER__ */ =20 #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ +#define FDT_FLAG_ADDON 0x1 #define FDT_TAGSIZE sizeof(fdt32_t) =20 #define FDT_BEGIN_NODE 0x1 /* Start node: full name */ diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index 9777f32..37459a6 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -302,6 +302,7 @@ int fdt_next_subnode(const void *fdt, int offset); #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) +#define fdt_dt_flags(fdt) (fdt_get_header(fdt, dt_flags)) =20 #define fdt_set_hdr_(name) \ static inline void fdt_set_##name(void *fdt, uint32_t val) \ diff --git a/treesource.c b/treesource.c index d25f01f..1db6390 100644 --- a/treesource.c +++ b/treesource.c @@ -369,7 +369,10 @@ void dt_to_source(FILE *f, struct dt_info *dti) { struct reserve_info *re; =20 - fprintf(f, "/dts-v1/;\n\n"); + fprintf(f, "/dts-v1/;\n"); + if (dti->dtsflags & DTSF_ADDON) + fprintf(f, "/addon/;\n"); + fprintf(f, "\n"); =20 for (re =3D dti->reservelist; re; re =3D re->next) { struct label *l; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEB972E2DF3; Mon, 12 Jan 2026 14:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227651; cv=none; b=JSowt2RkE33l9bhk676wBtLAUQ69LZ+MlJJ7bKTC6kt4dIuZvu9PwF065Q6IXAhHPmez8OvXkUt5JwbVTag6POIx7vky8x3msoiBNeXtcX5/fys/l7pfGLQKen9r/YwSwwZ0a7LjRAv1po+p+UpV6Ttrc5WwlpPuLybT1vCDHT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227651; c=relaxed/simple; bh=YO3kQz2fR8DAC3SdoniBXXwcSaVv9biWxGqGAHPUv88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q2QeM8uAxbmp0VWVu6K8cEyX1+4wGxopcz92WEOmpV8GK+ji+TU4PtiT09P7l0wGCaAPRz1j20bBf40HBPvGoS9p7NLc8pUNgYUX/2mPr/aIdQQSNjRunFZKUpjMcHr0hJW1+Apm8qT2CtRerCEczg3Jzn2KHfmr6L3+5pV6/Co= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=D6wtx5al; arc=none smtp.client-ip=185.171.202.116 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.b="D6wtx5al" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 2A487C20869; Mon, 12 Jan 2026 14:20:20 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A252A606FA; Mon, 12 Jan 2026 14:20:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B28B7103C9269; Mon, 12 Jan 2026 15:20:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227645; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=vovB9PJwe7q82dhVvrskUXYb/fGDuEJF62Jmd31jrl0=; b=D6wtx5alwH/bc4Z2IFvnSyvqi9HVyHD6Cr1DvkW8rv+qAcJj275g+fvH0Z5/ySQ9K+CQlb A+suecQV/dd/Mhjx6jNMyMSyFxuEnNOFP0gUfFbCX0Vuh29S9swI4nXxPuf+K7TzVWFxCE MU1Rux5ktyBkbSVytj8lXsIdsZwpYM2eqDdyqa6xTrvBQJMfxXBRjr9AeoQMv+1O/Ft4rh d/iZvHXjflZCvar3fO35LnPoLboAA9y4nfquOUsyo3WAbxzRTTaIOD++1rPYUnGD1ohUs0 4uodWgQ7FO4DzByjHhXALEY0upiJZz8OtL8oN7M3qneybJYXAwzNznUa3VIWnw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 16/77] tests: metadata: Add a test related to addon dt_flags header value Date: Mon, 12 Jan 2026 15:19:06 +0100 Message-ID: <20260112142009.1006236-17-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Addon dtbs leads to the dt_flags header field set to FDT_FLAG_ADDON (0x1). Add a specific test to check this value. Signed-off-by: Herve Codina --- tests/metadata_dtflags1.dtb.expect | 1 + tests/metadata_dtflags1.dts | 11 +++++++++++ tests/run_tests.sh | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/metadata_dtflags1.dtb.expect create mode 100644 tests/metadata_dtflags1.dts diff --git a/tests/metadata_dtflags1.dtb.expect b/tests/metadata_dtflags1.d= tb.expect new file mode 100644 index 0000000..00f98f3 --- /dev/null +++ b/tests/metadata_dtflags1.dtb.expect @@ -0,0 +1 @@ +// dt_flags: 0x1 diff --git a/tests/metadata_dtflags1.dts b/tests/metadata_dtflags1.dts new file mode 100644 index 0000000..d2b2295 --- /dev/null +++ b/tests/metadata_dtflags1.dts @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + prop =3D <1>; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 496fcb9..688d81d 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1147,6 +1147,12 @@ metadata_tests() { # Keep only lines containing 'dt_flags' sed -i '/dt_flags/!d' metadata_dtflags0.dtb.out base_run_test check_diff metadata_dtflags0.dtb.out "$SRCDIR/metadata_dtfl= ags0.dtb.expect" + + run_dtc_test -I dts -O dtb -o metadata_dtflags1.dtb "$SRCDIR/metadata_dtf= lags1.dts" + base_run_test wrap_fdtdump metadata_dtflags1.dtb metadata_dtflags1.dtb.out + # Keep only lines containing 'dt_flags' + sed -i '/dt_flags/!d' metadata_dtflags1.dtb.out + base_run_test check_diff metadata_dtflags1.dtb.out "$SRCDIR/metadata_dtfl= ags1.dtb.expect" } =20 pylibfdt_tests () { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E86F2DA760; Mon, 12 Jan 2026 14:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227651; cv=none; b=SRuDo3wxlfcJCU5QNrwZTZkDzaEZs7IgrYhsdTfyjHtDIci0fi/2CHB17Si8upK/OiNU7BTqZyPKHYruxzCzr/qmhIv13itG2GZTMEMX/8XIQjSRA6mwPUEvI5qS7ti3xxOXfDX2sDhlCxMBusq6e5NWM0PyRtTiy58lkMg3sOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227651; c=relaxed/simple; bh=rAKGpL+MO0wznmSRiK03TBFwuWCatM3EtB022hXSn+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VHg8vS54jjJkxljKmUFK612J0bCPdzvvcEuJ7cRn0m9ncPcirXDEe6JrvaN6TAfnBpiyQzTwyOnKJXO9Eqsn8Vo/RM3BLhb5h3icDVnuHkEvEKp0xKCfjQeQq8BWQWStMJ27ij+pIdYWvqnfQ/sXepYWCh5OakAguoNiBUsTewU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ADn6gJZZ; arc=none smtp.client-ip=185.171.202.116 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.b="ADn6gJZZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id A4BA0C20868; Mon, 12 Jan 2026 14:20:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 282C9606FA; Mon, 12 Jan 2026 14:20:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3315C103C926E; Mon, 12 Jan 2026 15:20:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227647; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=e2wg2ep97sbhvDd+Jf681JB+w9NK5Ex/WMqJnPY+158=; b=ADn6gJZZZuLRAnbD8EnQ3/B4zeJyv4oWU9f0lLpaDLQNS+ahjp7O9hOhZSqK0ZBb5DhdKS dZb8wenRhmt0ImjjvBejrMy+rtZD3bO5TU2VkCDUwHZxDJ6eXwBX+yv5pxniFwXLfI0sm5 TIzoj2d2XaTaZUkYnoK01BlBFa8IaV9vtTtgl5NNZnM9/fmTUhmx+nK/RHD1jRBpfZtpR2 bGrdhRC2rcDVrNLh+5FSFd+Sg3MiW5PJKyRKwaU0D0o2iSJnvzFtCQ7wAXhKpcD/m8DdrX ecMz6zdo1rIm/cK071gfLuxjqeFuKuy9hoLrqbUqvC/t5/erzv/FB3ZXi+ZoUQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 17/77] tests: metadata: Add a basic addon test Date: Mon, 12 Jan 2026 15:19:07 +0100 Message-ID: <20260112142009.1006236-18-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Support for addon dts (/addon/ keyword) and addon dtb (FDT_FLAG_ADDON header flag) have been recently introduced. Even if the FDT_FLAG_ADDON dtb flag itself has its own test already available, add a basic addon test in the metadata 'dts->dts and dts->dtb->dts' test patterns to check that addon dts/dtb are handled correctly. Signed-off-by: Herve Codina --- tests/metadata_addon_base.dtb.dts.expect | 10 ++++++++++ tests/metadata_addon_base.dtb.expect | 10 ++++++++++ tests/metadata_addon_base.dts | 14 ++++++++++++++ tests/metadata_addon_base.dts.dts.expect | 10 ++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_base.dtb.dts.expect create mode 100644 tests/metadata_addon_base.dtb.expect create mode 100644 tests/metadata_addon_base.dts create mode 100644 tests/metadata_addon_base.dts.dts.expect diff --git a/tests/metadata_addon_base.dtb.dts.expect b/tests/metadata_addo= n_base.dtb.dts.expect new file mode 100644 index 0000000..739f9db --- /dev/null +++ b/tests/metadata_addon_base.dtb.dts.expect @@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop =3D <0x01>; + ref-base =3D <&base>; + }; +}; diff --git a/tests/metadata_addon_base.dtb.expect b/tests/metadata_addon_ba= se.dtb.expect new file mode 100644 index 0000000..6c2a89a --- /dev/null +++ b/tests/metadata_addon_base.dtb.expect @@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + +/ { + node-a { + prop =3D <0x00000001>; + ref-base =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref-base[0], ref =3D base + }; +}; diff --git a/tests/metadata_addon_base.dts b/tests/metadata_addon_base.dts new file mode 100644 index 0000000..5e29cef --- /dev/null +++ b/tests/metadata_addon_base.dts @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + node-a { + prop =3D <1>; + ref-base =3D <&base>; + }; +}; diff --git a/tests/metadata_addon_base.dts.dts.expect b/tests/metadata_addo= n_base.dts.dts.expect new file mode 100644 index 0000000..739f9db --- /dev/null +++ b/tests/metadata_addon_base.dts.dts.expect @@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop =3D <0x01>; + ref-base =3D <&base>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 688d81d..def1a7e 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1125,7 +1125,8 @@ wrap_fdtdump () { } =20 metadata_tests() { - for dt in metadata_reflocal metadata_refphandle; do + for dt in metadata_reflocal metadata_refphandle \ + metadata_addon_base; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F7A52E62C0; Mon, 12 Jan 2026 14:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227653; cv=none; b=PQepVdqa9b4b8w72umJj69vkrNM93BL/XAfsWES3OWyFnttMz0MaJ86U1mqN1w+tlCwwPMPkAPS6YCoE5XM0b51EGw4WhlhHP+kWZj70SBNPx8qapwxvlAj8bOpkQzKdyrjhSE7oVuiDKdcOs9sS2trcYVM2VHHmRdbeweh32yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227653; c=relaxed/simple; bh=Kjz3gjhhnUhEGWpZM8tXvNG5FsPtVoun+2NKgHFSZMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q0vHQH6I5uEJpqmsZxSeg5ZEvGZ7UBMwC9RX1399FyK8ScZLnr9FczT/7cMm3qSEeYdLTf34i434b7D4+xyA4oEZQb3+iGIh4yXTctdOD6PvxP4LYgLVuNdzAdkKmX95CfbGIgXKvGmYUSuEQnoXXGZSy2DhrBukNsXo74YAARQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=l0wbZbYf; arc=none smtp.client-ip=185.171.202.116 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.b="l0wbZbYf" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id EAAA7C2086B; Mon, 12 Jan 2026 14:20:22 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 6D91F606FA; Mon, 12 Jan 2026 14:20:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A5E1B103C8C61; Mon, 12 Jan 2026 15:20:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227648; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=YDM7nARSEOyxMicRBpgb4TUpIk9yqVSL2vsEwrm/mwU=; b=l0wbZbYfxtJ777ZbGpZg3Obid8ro7EG5Rcd5qaLTQxFEWOmQLE7/MTat2JkgCjzYShZbDp +l70dkvH/9aqOEeXk6J4GVpIhRVZOfbCKr3rB0iK93K8E9HWlzrgQgXUOwC4i7UKlhuIvJ IWuL4NQNHV9wVcM2IctqaMZIvSnDnZqzkbcrJmiZfXuW4rURbDIZb2g8RkxDSRFt7r1WM5 iOYNCR0kpIPVEU6h2wp0neJfL3BSc1kpsNldh2ALd7T175ny/S0V8bQdNJtvBV1uGTqjwa g7kxCtX//H3aPWQNbT+naK7ISRCcBrmNRXVi4RawnfYkIySzHepxyM43lvzTyg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 18/77] dtc-parser.y: Avoid an empty proplist Date: Mon, 12 Jan 2026 15:19:08 +0100 Message-ID: <20260112142009.1006236-19-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In the dts parser grammar, a nodedef is defined by '{' proplist subnodes '}' ';' with both proplist and subnodes that can be empty lists. Soon a new list will be added in the nodedef related to export symbol list. Having all those lists with support for empty lists will lead to some Bison warnings: warning: 4 shift/reduce conflicts [-Wconflicts-sr] warning: 1 reduce/reduce conflict [-Wconflicts-rr] The simpler way to remove those warning and thus have a robust parsing is to avoid those empty lists. Update the proplist definition and nodedef definition to avoid those multiple empty lists. Instead of allowing a proplist to be an empty list, force the list to be a non empty one and update the nodedef to handle explicitly the absence of the proplist to support the case where no properties are available, i.e. the case of a node composed only of sub-nodes. This doesn't change the functional behavior. Signed-off-by: Herve Codina --- dtc-parser.y | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index d8914d2..2e152b0 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -272,12 +272,16 @@ nodedef: { $$ =3D build_node($2, $3, &@$); } + | '{' subnodes '}' ';' + { + $$ =3D build_node(NULL, $2, &@$); + } ; =20 proplist: - /* empty */ + propdef { - $$ =3D NULL; + $$ =3D chain_property($1, NULL); } | proplist propdef { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39AAB2EBDE9; Mon, 12 Jan 2026 14:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227660; cv=none; b=s8lRhiKZAzlhvCG1jzCHWJXhMeKD7d1xbg/ofiOG7l71ZFsyRWX6HgNroSg+gKu3tXIIjW9+Y7a/J6tsCiUhyqp5dr6d7GP1gy8w7akfreqrv2PvzyoBMWrgUeVsYn1RgUJ1ln4aVDlcQmo+F9QUrJyktuOmCQv7tyWsTucQK4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227660; c=relaxed/simple; bh=qLF2kIyfVul0cJD4gyl/NdCPlfl+XCaJm1dQgoBndY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jr6M5oscfF/Lsg3ux2eBkDM0xJ2Vcbp4e1Tf9Zhic7/VKuTe/PAKb+IrcjX0wLarCuQjU3uuoG3aQT+Zw/m/WHLW3w0gW2V728RriPKz90VlOor90uPOTs9A31tbC/lEsSSgPIl7Xe+MjI6mVrRxwSB36N7IgHOA67gdL/y3uU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=rMXQPsAX; arc=none smtp.client-ip=185.246.85.4 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.b="rMXQPsAX" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 5E9AF4E42091; Mon, 12 Jan 2026 14:20:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2E417606FA; Mon, 12 Jan 2026 14:20:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 08971103C9260; Mon, 12 Jan 2026 15:20:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227650; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=4YJltUWUeDp+5OZdI6WlzDErfO/ft9YRY1mAHR9txhk=; b=rMXQPsAXQHxXoBuqz/fCr1rGV80J9TwFxDkNRmFwhxW0SzPWMlQPQu0DQOA79xSuHxdElT 06QXFVqvXhkdkuJiNMunxqeCu9JM8BV3lpKDj+o0Sbm2nhTAkmXmGWhimecxcNyTFbKHMu XX3TZPlVCwVfjVH67QQO6UTkx9DrcFeMS4O8fxEJIwPAGdhBCjFLT+DctUDFbyHaHMoXry VmJr7CJzmDzzk03yRaaL/QZMzEnaTaFgNH5mvuBHfvi5bmDa3vImRwC3wtMoyF4IiFA7pP hOcz7iwOdEWqQq9lqBMTlFafRo78zY5HrvFlVIha9YEHWj2v8gxuqbFeNg68bw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 19/77] dtc: Introduce export symbols Date: Mon, 12 Jan 2026 15:19:09 +0100 Message-ID: <20260112142009.1006236-20-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols. In order to perform its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols. The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols. Also an exported symbol has a specific name and this name has to used for symbol resolution. Having this specific name allows to: - Have several nodes providing the same exported symbols name but each of them pointing to different nodes. Without looking at the detail of the syntax, node-a and node-b export the same symbol foo but pointing to different node. node-a { /* export foo -> /path/foo1 */ }; node-b { /* export foo -> /path/foo2 */ }; This allow to have the exact same addon referencing 'foo' applied either on node-a or node-b. - Have several board describing a well defined node even if resources needed for exported symbols are not the same. On board A, the 'ctrl' exported symbols points to some ctrl device available on the SoC: node { /* export 'ctrl' -> /soc/ctrl@1000 }; On board B, the ctrl device used is on a i2c bus node { /* export 'ctrl' -> /soc/i2c@5000/ctrl@10 }; The addon can be used on board A and board B without any modification. It uses 'ctrl' exported by the node the it is applied to. Introduce the 'symbol' internal data structure and the export symbol list related to a node. No functional change yet but preparation for the future support for export symbol parsing. Signed-off-by: Herve Codina --- dtc-parser.y | 6 +++--- dtc.h | 13 ++++++++++++- flattree.c | 2 +- fstree.c | 2 +- livetree.c | 7 ++++--- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index 2e152b0..9c93673 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -183,7 +183,7 @@ devicetree: else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); $$ =3D add_orphan_node( - name_node(build_node(NULL, NULL, NULL), + name_node(build_node(NULL, NULL, NULL, NULL), ""), $2, $1); } @@ -270,11 +270,11 @@ devicetree: nodedef: '{' proplist subnodes '}' ';' { - $$ =3D build_node($2, $3, &@$); + $$ =3D build_node($2, $3, NULL, &@$); } | '{' subnodes '}' ';' { - $$ =3D build_node(NULL, $2, &@$); + $$ =3D build_node(NULL, $2, NULL, &@$); } ; =20 diff --git a/dtc.h b/dtc.h index c0fffd2..6508694 100644 --- a/dtc.h +++ b/dtc.h @@ -204,6 +204,16 @@ struct label { struct label *next; }; =20 +struct symbol { + bool is_local; + char *name; + char *ref; + cell_t phandle; + char *fullpath; + struct symbol *next; + struct srcpos *srcpos; +}; + struct bus_type { const char *name; }; @@ -224,6 +234,7 @@ struct node { char *name; struct property *proplist; struct node *children; + struct symbol *exportsymlist; =20 struct node *parent; struct node *next_sibling; @@ -272,7 +283,7 @@ struct property *chain_property(struct property *first,= struct property *list); struct property *reverse_properties(struct property *first); =20 struct node *build_node(struct property *proplist, struct node *children, - struct srcpos *srcpos); + struct symbol *exportsymlist, struct srcpos *srcpos); struct node *build_node_delete(struct srcpos *srcpos); struct node *name_node(struct node *node, const char *name); struct node *omit_node_if_unused(struct node *node); diff --git a/flattree.c b/flattree.c index bedb286..36b795d 100644 --- a/flattree.c +++ b/flattree.c @@ -809,7 +809,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, uint32_t offset; const char *str; =20 - node =3D build_node(NULL, NULL, NULL); + node =3D build_node(NULL, NULL, NULL, NULL); =20 flatname =3D flat_read_string(dtbuf); =20 diff --git a/fstree.c b/fstree.c index 0f9a534..445ae53 100644 --- a/fstree.c +++ b/fstree.c @@ -19,7 +19,7 @@ static struct node *read_fstree(const char *dirname) if (!d) die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); =20 - tree =3D build_node(NULL, NULL, NULL); + tree =3D build_node(NULL, NULL, NULL, NULL); =20 while ((de =3D readdir(d)) !=3D NULL) { char *tmpname; diff --git a/livetree.c b/livetree.c index 2a0a7ed..0050492 100644 --- a/livetree.c +++ b/livetree.c @@ -86,7 +86,7 @@ struct property *reverse_properties(struct property *firs= t) } =20 struct node *build_node(struct property *proplist, struct node *children, - struct srcpos *srcpos) + struct symbol *exportsymlist, struct srcpos *srcpos) { struct node *new =3D xmalloc(sizeof(*new)); struct node *child; @@ -95,6 +95,7 @@ struct node *build_node(struct property *proplist, struct= node *children, =20 new->proplist =3D reverse_properties(proplist); new->children =3D children; + new->exportsymlist =3D exportsymlist; new->srcpos =3D srcpos_copy(srcpos); =20 for_each_child(new, child) { @@ -248,7 +249,7 @@ struct node * add_orphan_node(struct node *dt, struct n= ode *new_node, char *ref) xasprintf(&name, "fragment@%u", next_orphan_fragment++); name_node(new_node, "__overlay__"); - node =3D build_node(p, new_node, NULL); + node =3D build_node(p, new_node, NULL, NULL); name_node(node, name); free(name); =20 @@ -892,7 +893,7 @@ static struct node *build_and_name_child_node(struct no= de *parent, const char *n { struct node *node; =20 - node =3D build_node(NULL, NULL, NULL); + node =3D build_node(NULL, NULL, NULL, NULL); name_node(node, name); add_child(parent, node); =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD4C42EC0A5; Mon, 12 Jan 2026 14:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227662; cv=none; b=qhZ4tKjv2Q0Tgn94PD5+2UgEUS3YyStm1BsVqtoISeJBFt7Tl++B0izjDCAUF50cZOSwwouE8gBKF5Cg8/6GJI0iB5gGX3TLBFZD1F0fOSsX6izKVbagCRKpp6rQQp5X294yS8USZKfruHgx5qmn+oQwA5K74b4SQJCE4OC33gA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227662; c=relaxed/simple; bh=J6bCEsZwMsxttH6QPEEWjkYfZh/WpP7ik2dZx1kzGFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bnqhbM1XdM2QldZzK0J8iV0AuyExJxeBnC4ERsvMEPDsA1Hz7jLfmaJGATjjm7/vAodECXOY2nX08OYIv6Kvb5TMPHavPpjoz7p6n57e4L3/Z6F54EkJQm2D9VRq0O1WCK2gNNS/zZRK2hcWLqZ3rsevnKvdX5TyNO4uf9jPCoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=h0sbFq/1; arc=none smtp.client-ip=185.246.84.56 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.b="h0sbFq/1" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id F07551A27FF; Mon, 12 Jan 2026 14:20:52 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C66FA606FA; Mon, 12 Jan 2026 14:20:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B840D103C9263; Mon, 12 Jan 2026 15:20:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227652; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3BmKNBuRwyGDqMyaOhYLXX0QommV1DD0zaD2Zr2QKNg=; b=h0sbFq/1YaMhabvgGSwzZ9GblOMG8Rj5g7okbRNLNDBB56ZgNgNdMK6fIFnwyS6JPfWoTD L8jFcPHPI/UxM9QqQX3me461bHRYCq8tkJGpqKt+sOOTXt1Hk3yiWPL637zXWixbfLtuex sYRfJl6+a+LwtopJWGnGtL02OBtPLmW/AzuPi+tqgbUdmc5RyXFYhC/FwOHfmC/a0Hi78G YSqpX62BrLAhZorIaaa3qKZsKv5gk+B5KS+kleIQpSRRkZ/f4rUenocETvmQs6XcEB9mkZ hEUs0dMppgMhPpimmyMoYfQ7wlVnFNTPFcLpdEocaAs3rAhClBEYAW4zNyK/tA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 20/77] dtc: Add support for /export/ dts keyword parsing Date: Mon, 12 Jan 2026 15:19:10 +0100 Message-ID: <20260112142009.1006236-21-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The /export/ dts keyword is the keyword used to define an exported symbol at a given node level. This keyword can be present in a node definition (after properties and before subnodes) to export a symbol. If several symbols need to be exported, several /export/ keywords are present. The syntax used is the following: /export/ name: reference; with: name: The name of the exported symbol reference: The reference of a node the symbol is pointing to. For instance: - Reference by label: /export/ foo: &foo1; The exported symbol foo references the node identified by the label foo1. - Reference by path: /export/ foo: &{/path/to/foo@100}; The exported symbol foo references the node at /path/to/foo@100. Add support for /export/ dts keyword. Signed-off-by: Herve Codina --- dtc-lexer.l | 6 ++++ dtc-parser.y | 53 ++++++++++++++++++++++++++++++++++ dtc.h | 8 ++++++ livetree.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) diff --git a/dtc-lexer.l b/dtc-lexer.l index a4a8e0b..90fe70e 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -149,6 +149,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_OMIT_NO_REF; } =20 +<*>"/export/" { + DPRINT("Keyword: /export/\n"); + BEGIN_DEFAULT(); + return DT_EXPORT; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref =3D xstrdup(yytext); diff --git a/dtc-parser.y b/dtc-parser.y index 9c93673..a0d0aef 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -46,6 +46,8 @@ static bool is_ref_relative(const char *ref) struct property *proplist; struct node *node; struct node *nodelist; + struct symbol *symbol; + struct symbol *exportlist; struct reserve_info *re; uint64_t integer; unsigned int flags; @@ -60,6 +62,7 @@ static bool is_ref_relative(const char *ref) %token DT_DEL_PROP %token DT_DEL_NODE %token DT_OMIT_NO_REF +%token DT_EXPORT %token DT_PROPNODENAME %token DT_LITERAL %token DT_CHAR_LITERAL @@ -80,6 +83,8 @@ static bool is_ref_relative(const char *ref) %type bytestring %type propdef %type proplist +%type exportdef +%type exportlist %type dt_ref =20 %type devicetree @@ -276,6 +281,49 @@ nodedef: { $$ =3D build_node(NULL, $2, NULL, &@$); } + | '{' proplist exportlist subnodes '}' ';' + { + /* + * exportlist is created with chain_symbol() and so it + * is created in reverse order. Reverse it now to have + * it in correct order + */ + $$ =3D build_node($2, $4, reverse_symbol($3), &@$); + } + | '{' exportlist subnodes '}' ';' + { + /* + * exportlist is created with chain_symbol() and so it + * is created in reverse order. Reverse it now to have + * it in correct order + */ + $$ =3D build_node(NULL, $3, reverse_symbol($2), &@$); + } + ; + +exportlist: + exportdef + { + $$ =3D chain_symbol($1, NULL); + } + | exportlist exportdef + { + $$ =3D chain_symbol($2, $1); + } + | exportlist propdef + { + ERROR(&@2, "Properties must precede exports"); + YYERROR; + } + ; + +exportdef: + DT_EXPORT DT_LABEL dt_ref ';' + { + $$ =3D build_exportsym($2, $3, 0, &@$); + free($2); + free($3); + } ; =20 proplist: @@ -576,6 +624,11 @@ subnodes: ERROR(&@2, "Properties must precede subnodes"); YYERROR; } + | subnode exportdef + { + ERROR(&@2, "Exports must precede subnodes"); + YYERROR; + } ; =20 subnode: diff --git a/dtc.h b/dtc.h index 6508694..0bf5ba5 100644 --- a/dtc.h +++ b/dtc.h @@ -273,6 +273,9 @@ struct node { for_each_child_withdel(n, c) \ if (!(c)->deleted) =20 +#define for_each_symbol(s0, s) \ + for ((s) =3D (s0); (s); (s) =3D (s)->next) + void add_label(struct label **labels, char *label); void delete_labels(struct label **labels); =20 @@ -282,6 +285,11 @@ struct property *build_property_delete(const char *nam= e); struct property *chain_property(struct property *first, struct property *l= ist); struct property *reverse_properties(struct property *first); =20 +struct symbol *build_exportsym(const char *name, const char *ref, cell_t p= handle, + struct srcpos *srcpos); +struct symbol *chain_symbol(struct symbol *first, struct symbol *list); +struct symbol *reverse_symbol(struct symbol *list); + struct node *build_node(struct property *proplist, struct node *children, struct symbol *exportsymlist, struct srcpos *srcpos); struct node *build_node_delete(struct srcpos *srcpos); diff --git a/livetree.c b/livetree.c index 0050492..4458437 100644 --- a/livetree.c +++ b/livetree.c @@ -36,6 +36,57 @@ void delete_labels(struct label **labels) label->deleted =3D 1; } =20 +struct symbol *build_exportsym(const char *name, const char *ref, cell_t p= handle, + struct srcpos *srcpos) +{ + struct symbol *new =3D xmalloc(sizeof(*new)); + + memset(new, 0, sizeof(*new)); + + new->name =3D xstrdup(name); + new->ref =3D ref ? xstrdup(ref) : NULL; + new->phandle =3D phandle; + new->srcpos =3D srcpos_copy(srcpos); + + return new; +} + +struct symbol *chain_symbol(struct symbol *first, struct symbol *list) +{ + assert(first->next =3D=3D NULL); + + first->next =3D list; + return first; +} + +struct symbol *reverse_symbol(struct symbol *list) +{ + struct symbol *p =3D list; + struct symbol *head =3D NULL; + struct symbol *next; + + while (p) { + next =3D p->next; + p->next =3D head; + head =3D p; + p =3D next; + } + return head; +} + +static void add_symbol(struct symbol **list, struct symbol *new) +{ + struct symbol **s; + + new->next =3D NULL; + + s =3D list; + while (*s) + s =3D &((*s)->next); + + *s =3D new; +} + struct property *build_property(const char *name, struct data val, struct srcpos *srcpos) { @@ -144,6 +195,7 @@ struct node *merge_nodes(struct node *old_node, struct = node *new_node) { struct property *new_prop, *old_prop; struct node *new_child, *old_child; + struct symbol *new_sym, *old_sym; struct label *l; =20 old_node->deleted =3D 0; @@ -217,6 +269,34 @@ struct node *merge_nodes(struct node *old_node, struct= node *new_node) add_child(old_node, new_child); } =20 + /* Merge exported symbols. If there is a collision, keep the new one */ + while (new_node->exportsymlist) { + /* Pop the symbol off the list */ + new_sym =3D new_node->exportsymlist; + new_node->exportsymlist =3D new_sym->next; + new_sym->next =3D NULL; + + /* Look for a collision, set new value if there is */ + for_each_symbol(old_node->exportsymlist, old_sym) { + if (streq(old_sym->name, new_sym->name)) { + old_sym->is_local =3D new_sym->is_local; + free(old_sym->ref); + old_sym->ref =3D new_sym->ref; + old_sym->phandle =3D new_sym->phandle; + old_sym->fullpath =3D new_sym->fullpath; + srcpos_free(old_sym->srcpos); + old_sym->srcpos =3D new_sym->srcpos; + free(new_sym); + new_sym =3D NULL; + break; + } + } + + /* if no collision occurred, add symbol to the old node list. */ + if (new_sym) + add_symbol(&old_node->exportsymlist, new_sym); + } + old_node->srcpos =3D srcpos_extend(old_node->srcpos, new_node->srcpos); =20 /* The new node contents are now merged into the old node. Free --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA4B72E9749; Mon, 12 Jan 2026 14:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227659; cv=none; b=fvU8BZMslTnqp3RfZ9nMqNYnPVeDVQF7yyM6uiIVgQ5f5P9mpEgVFoD5H7VQYaWekv/KAnv6+sAMnlzutQsxT4VbkCp9RWfyp/zzVlTA69TUF0DcFJlzXqsOZUOTqr5vQRh8rJ9H6u7C5LwwBOf9mM1uazJJiUq0O1gbGGh2+RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227659; c=relaxed/simple; bh=onITgzl/j/aTxCmRAXv0CYwm9QPcprVC79srL7J+ERI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KF7BK1vfj7IT7+vZ8A/yv8tAy8680xx1CMDb5WLQqNElTmkJtd5pWRLn4Ir8TdPL9ud7WNi8zM6QYrerN2PpRroRFM/OIysw3liyCVP+22xWwfdgFWastV+wLSeFDm0MQDOaquEEnhxBSCZ6DpfPfCDASgwFRkQwqaYmcVK13g0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=qqyDn8B2; arc=none smtp.client-ip=185.246.85.4 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.b="qqyDn8B2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A80004E4208F; Mon, 12 Jan 2026 14:20:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7C57E606FA; Mon, 12 Jan 2026 14:20:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 77D14103C8CD8; Mon, 12 Jan 2026 15:20:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227653; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=MbcsH2VKS+PWLxCMGjlcJa8WB63hBbUf1OPFHJBaSgU=; b=qqyDn8B2FgG4r6t2KN0YUo+XOGcvyjD3SmeihyXPJ8hMKAGS5DAFTN+a+pDznob4Sr2TL/ r1JyntFgF9bh2a+GdI/teeGcOHkPY0zyIDWtRpQsqpAjqS+phflRzT+KXjZNeMJMd2FWXm SIezYCV6P8JWJPT0nzPmsZy3bGUvwRf5bvVBJCr4TC75QRuxPOscU3M5rh3wr+2FdMz6es o+uP1SvULOg9Kc7Zs8MjL3oL4QNKsX00Uvh2ZuYsag9XFrdTlLXnsw5ZRtTP7Gqtpfx+GH 2YCi6HWIV/8dcRLeGx9rDb6MicVNH56uSFo4kYzR4WP9Zn0nuGOvpRsbSL6D2g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 21/77] checks: Handle export symbols in fixup_phandle_references() Date: Mon, 12 Jan 2026 15:19:11 +0100 Message-ID: <20260112142009.1006236-22-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Export symbols use phandle references. Referenced nodes must have a phandle property set in order to have those references working. fixup_phandle_references() does the needed operation for properties that use a phandle. Extend fixup_phandle_references() to perform exact same operation for export symbols. Signed-off-by: Herve Codina --- checks.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/checks.c b/checks.c index 2be19c0..d1e215e 100644 --- a/checks.c +++ b/checks.c @@ -604,12 +604,13 @@ static void fixup_phandle_references(struct check *c,= struct dt_info *dti, struct node *node) { struct node *dt =3D dti->dt; + struct symbol *exportsym; struct property *prop; + struct node *refnode; + cell_t phandle; =20 for_each_property(node, prop) { struct marker *m =3D prop->val.markers; - struct node *refnode; - cell_t phandle; =20 for_each_marker_of_type(m, REF_PHANDLE) { assert(m->offset + sizeof(cell_t) <=3D prop->val.len); @@ -631,6 +632,25 @@ static void fixup_phandle_references(struct check *c, = struct dt_info *dti, reference_node(refnode); } } + + for_each_symbol(node->exportsymlist, exportsym) { + refnode =3D get_node_by_ref(dt, exportsym->ref); + if (!refnode) { + if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) { + FAIL(c, dti, node, + "Export \"%s\" references to non-existent node or label \"%s\"\n", + exportsym->name, exportsym->ref); + } + exportsym->phandle =3D cpu_to_fdt32(0xffffffff); + continue; + } + + /* Create the phandle property for this referenced node */ + phandle =3D get_node_phandle(dt, refnode); + exportsym->phandle =3D phandle; + + reference_node(refnode); + } } ERROR(phandle_references, fixup_phandle_references, NULL, &duplicate_node_names, &explicit_phandles); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84B1B2D2382; Mon, 12 Jan 2026 14:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227661; cv=none; b=eBmUpSQQ7cjGGytKodNDW2LNGHgZI0o1oONxj3bKtzI59VBABfrgNrUS4jfq8H4c0iVlMN/aM7ihIrFHyTv8RsW4/F9TSLvVuJ7dSvBnrnu6FDC1LxCuRDhYfdNQjLqUn5Mdfm4WYCym6IDkmaBpzA5a7p3RYHC1zECjIfjMU2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227661; c=relaxed/simple; bh=Nj6kJj98DYHwwdjHPdu2+VgWqk7PRTqBXRT9vZd8eeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qr2krR0CkMrhciKgZhW+ZJXUDuYM82Yww8cO78NnsiuABGH6T7CQl4H3E2tmAobvgl+vr8nA98U4eTeQbx0tMQsvLhL0MwHfa+8TVzZHC+upml3fU60ukqKp4SXuDfTQRnpy2uaLmBFfbvvJCRojmSm4rJL0ism4Qn+0fXsHQEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OWk+hX0W; arc=none smtp.client-ip=185.246.85.4 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.b="OWk+hX0W" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 3FAFB4E42092; Mon, 12 Jan 2026 14:20:56 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 13C27606FA; Mon, 12 Jan 2026 14:20:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E7A4A103C9261; Mon, 12 Jan 2026 15:20:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227655; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=0MOeeR6TasGz+3AxpUMPX0Cq21Iksg66J6fcPymVDvA=; b=OWk+hX0Ws5ZSun8uSJ95isB9VmnKshFYFRSaf5ByWplxHtexLxWwE/o1l4qNPsd2IuWBLe 9RHRsx3J7EnFIDbaOcu+5sfFu4RnvawMLNvWUFcHJesBviN12H5RHBtdf1scy25ZAZD5d9 GAZyEsSlyzldVThWYrppjqyCa6ItUqmfyl/8BNaY/JeH0ZzT1SuTfNEmqfeAFMspzbR1Q+ ORUkRDRWyFeemH9l3Erc7bkY7sEOP6qeyLJMTvrPZdx7fYqn6i1mc7y5QuGmgo7VVRCbD5 KGcZRQw/MIuwA/+/z46rbiiy63+TBwfJuOi8oHQyrL/oh+bMz7ll6oGQxMETgw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 22/77] dtc: Add export symbols (/export/ keyword) in generated dts file Date: Mon, 12 Jan 2026 15:19:12 +0100 Message-ID: <20260112142009.1006236-23-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The export symbols (/export/ keyword) parsing from a dts file is supported. Add the support for this keyword in the dts file generation. Signed-off-by: Herve Codina --- treesource.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/treesource.c b/treesource.c index 1db6390..9effe38 100644 --- a/treesource.c +++ b/treesource.c @@ -320,6 +320,7 @@ static void write_propval(FILE *f, struct property *pro= p) =20 static void write_tree_source_node(FILE *f, struct node *tree, int level) { + struct symbol *exportsym; struct property *prop; struct node *child; struct label *l; @@ -349,6 +350,18 @@ static void write_tree_source_node(FILE *f, struct nod= e *tree, int level) fprintf(f, "%s", prop->name); write_propval(f, prop); } + + if (tree->exportsymlist) + fprintf(f, "\n"); + for_each_symbol(tree->exportsymlist, exportsym) { + write_prefix(f, level+1); + fprintf(f, "/export/ %s: ", exportsym->name); + if (exportsym->ref[0] =3D=3D '/') + fprintf(f, "&{%s};\n", exportsym->ref); + else + fprintf(f, "&%s;\n", exportsym->ref); + } + for_each_child(tree, child) { fprintf(f, "\n"); write_tree_source_node(f, child, level+1); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95D0A2EC54A; Mon, 12 Jan 2026 14:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; cv=none; b=UwQbzMAwRK2lhyYijsYtepd5KAaMwTTJFqP2HQU6mpmhqyUxewHZDZpEJYUuHPML54+/w8XYq27OeQqCBlCcpHkSwjqJsWPW5dwu1b2/OZVoBmLLuzuPxLiMtA5+T3z+gtzUx7Bb/VnEXxG7vXv9Ey/RzVmy/pY8rXNFSHmeaeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; c=relaxed/simple; bh=JFhL71ct8SrjrJ//e/l5+RKzOUHWDU5KI0MGy1DmXy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQvOtxOyrgEPY7izL3aXb82SzW3gd5VZzWuGARkbZDd3ZW0UF/MnRNB3mDP1x5HATaB/YWozkpbGrgzNBiGu9Ua53Ck7+2PA2QyYsvZt7uqmjk2k7MgXyQwbU9bMulojNzyzy5+oFUdJ9eOSNWgCoNoNnGaV1zXfFpy3z1mbOrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=yPpHocEr; arc=none smtp.client-ip=185.246.84.56 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.b="yPpHocEr" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 419E11A2803; Mon, 12 Jan 2026 14:20:58 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 17B8F606FA; Mon, 12 Jan 2026 14:20:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 86C5D103C9262; Mon, 12 Jan 2026 15:20:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227656; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=mcrxp0ApOG//BK1b6uSdhxWShcoQ7CdeHdkSNR4OcZk=; b=yPpHocErfgxeG2bCDXSAtRXWFwSpOxsQjGA+qDGXv1k68HeZGO4cEDnFMYIlkeACxqyCsN uBG5NX5QdQjxWfg3vQUmIRUZnf7vgMErqvd4hxuwQFLQtmiba7C8TqP8fJk9Lm+3LFxj+G s2QZOfuBTgqAXuXf0rOxJxK1xfkbiRCQsfLQORc3aaCx+P9hctR3qqWurp5DLKdlAy/Ub6 MgiVl+f38enIwyz9TG6FJJAo9iyHIQJp1ui7t9IvVZJsjOfJReu+9Q44Cg0Per6ALonWSw Vm8Xy0uRtz4R65YZ98QTjyOvrGHjMRTqBLScsp44p+VuY70sSL549dY/SBqe8g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 23/77] dtc: Introduce mark_local_exports() Date: Mon, 12 Jan 2026 15:19:13 +0100 Message-ID: <20260112142009.1006236-24-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In order to have correct tags set in dtb, an export symbol has to be identified as a "local" export symbol when it references a local node. This is done for phandles used by properties in mark_local_phandles(). The same operation is needed for export symbols. This is the purpose of mark_local_exports(). Signed-off-by: Herve Codina --- dtc.c | 2 ++ dtc.h | 2 ++ livetree.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/dtc.c b/dtc.c index fe8e8e4..030bfa2 100644 --- a/dtc.c +++ b/dtc.c @@ -336,6 +336,8 @@ int main(int argc, char *argv[]) update_phandles_ref(dti); mark_local_phandles(dti); =20 + mark_local_exports(dti); + /* * With FDT_REF_PHANDLE added in dtbs, we need to identified * if some unresolved phandle references are allowed in the dtb diff --git a/dtc.h b/dtc.h index 0bf5ba5..ea073c2 100644 --- a/dtc.h +++ b/dtc.h @@ -368,6 +368,8 @@ void generate_local_fixups_tree(struct dt_info *dti, co= nst char *name); void update_phandles_ref(struct dt_info *dti); void mark_local_phandles(struct dt_info *dti); =20 +void mark_local_exports(struct dt_info *dti); + /* Checks */ =20 void parse_checks_option(bool warn, bool error, const char *arg); diff --git a/livetree.c b/livetree.c index 4458437..0e756b8 100644 --- a/livetree.c +++ b/livetree.c @@ -1303,3 +1303,26 @@ void mark_local_phandles(struct dt_info *dti) { mark_local_phandles_internal(dti, dti->dt); } + +static void mark_local_exports_internal(struct dt_info *dti, + struct node *node) +{ + struct node *c; + struct symbol *exportsym; + struct node *refnode; + + for_each_symbol(node->exportsymlist, exportsym) { + refnode =3D get_node_by_ref(dti->dt, exportsym->ref); + if (refnode) + exportsym->is_local =3D true; + } + + for_each_child(node, c) + mark_local_exports_internal(dti, c); +} + +void mark_local_exports(struct dt_info *dti) +{ + mark_local_exports_internal(dti, dti->dt); + +} --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A35112ECD34; Mon, 12 Jan 2026 14:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; cv=none; b=IWhCUqR1rmjY50SvxmVvLctFj9H3jigz1LWHmaCJ/L682b+l8M0ulHjyPz/B69XGW+LvcZKktgP8LVoGW71DXCQ0tQWsUQQZjfTKfBmb7dXVNubUaJjiRGUQwVMr3xgXauYGXTYrJJ8Gj7YrMucLjg4LtrkC+JWmLY9KTWMsm5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; c=relaxed/simple; bh=M6wzRazgjLFhzqVroXSpKrrVzyrsDcHr9GnwSuZiXqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pM1Zcd5KQtefjLw0dXgkZG6XQk3+ckO6Y6fW+fipc8ucglTMRQ9ngvuILUZO2n+rO8RbGbz8rIv/K3goz825duCgkjWcaKSM9vrIcksgUNSLyGD7seOirAfpFVnDi2dqvwkjb4a1iqj/ISEOkeAv/l5hJZDw+HpAATEmMRjtmlE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=SccmcNR1; arc=none smtp.client-ip=185.171.202.116 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.b="SccmcNR1" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id B8C8DC20869; Mon, 12 Jan 2026 14:20:32 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3CBBE606FA; Mon, 12 Jan 2026 14:20:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 476E7103C9264; Mon, 12 Jan 2026 15:20:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227658; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=EIyB/EHU24MdE3qIWWskCx/gYfNdFh0BY/5BKh5Lhr8=; b=SccmcNR1jbQ8AJLjQe1YA5yNhPDH8Dy88QjW+N69YsuExhqCCo5r7cfmeNRe9YqwrVD1TC Tm7dRl+uv5oepmUJNxJChFfHJcj9hOA20GSml/Wf+PmM9MYSp9MvRXIsl1Y+CE2XPexoI3 FAQJ7XSxoYg5d+NNC9on+FicGAzhTxy0cFVZMNU+6G2oeIc6NobDBcezgxfjXn5LKN2EfN nQpdMiqDLDXPtsH4kKmLDSxB9SRLZzCXeRT3mbjvOBUw97/jMppG2Su2KoiT7DGEs0n4E5 59l06emiEoD525N2iQuu3AKe+Fd/mp9hcmL4/jJL8U01By8+92P7F/PFGPenqw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 24/77] dtc: Introduce update_exports_ref() Date: Mon, 12 Jan 2026 15:19:14 +0100 Message-ID: <20260112142009.1006236-25-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In order to have consistent internal data when a export symbol using a local phandle is parsed from a dtb, the reference related to this phandle usage needs to be updated based on the phandle value. This is done for phandles used by properties in update_phandles_ref(). The same operation is needed for export symbols. This is the purpose of update_exports_ref(). Signed-off-by: Herve Codina --- dtc.c | 1 + dtc.h | 1 + livetree.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/dtc.c b/dtc.c index 030bfa2..e0a0b54 100644 --- a/dtc.c +++ b/dtc.c @@ -336,6 +336,7 @@ int main(int argc, char *argv[]) update_phandles_ref(dti); mark_local_phandles(dti); =20 + update_exports_ref(dti); mark_local_exports(dti); =20 /* diff --git a/dtc.h b/dtc.h index ea073c2..024e172 100644 --- a/dtc.h +++ b/dtc.h @@ -368,6 +368,7 @@ void generate_local_fixups_tree(struct dt_info *dti, co= nst char *name); void update_phandles_ref(struct dt_info *dti); void mark_local_phandles(struct dt_info *dti); =20 +void update_exports_ref(struct dt_info *dti); void mark_local_exports(struct dt_info *dti); =20 /* Checks */ diff --git a/livetree.c b/livetree.c index 0e756b8..7cf3ee5 100644 --- a/livetree.c +++ b/livetree.c @@ -1304,6 +1304,36 @@ void mark_local_phandles(struct dt_info *dti) mark_local_phandles_internal(dti, dti->dt); } =20 +static void update_exports_ref_internal(struct dt_info *dti, struct node *= node) +{ + struct node *c; + struct symbol *exportsym; + struct node *refnode; + + for_each_symbol(node->exportsymlist, exportsym) { + if (exportsym->ref) + continue; + + if (exportsym->is_local) { + refnode =3D get_node_by_phandle(dti->dt, exportsym->phandle); + if (!refnode) + die("Node not found for phandle 0x%"PRIx32"\n", exportsym->phandle); + + exportsym->ref =3D refnode->fullpath; + } else { + die("Found a non local phandle without a reference\n"); + } + } + + for_each_child(node, c) + update_exports_ref_internal(dti, c); +} + +void update_exports_ref(struct dt_info *dti) +{ + update_exports_ref_internal(dti, dti->dt); +} + static void mark_local_exports_internal(struct dt_info *dti, struct node *node) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 576F3350A29; Mon, 12 Jan 2026 14:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; cv=none; b=Tz0SLQk3V6ZhG6lQIS94MISDe5cJa+6q8/M5gDGUSe5ZrcQyHhkcTLW3vKtHA/zcatIyWM1CoU+EN7/MID2zZUFZJ/7Bjro0gCaomKd45USNibq2oHCrhRRacR+TKK9tZPVg7Ux2YM4uz+BdtMfNeZ8K1qxWJGShfk/I0SEOetE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227666; c=relaxed/simple; bh=M1jJiNkil1ogha4+E0blrToU5uOsvyRp3h0wli3MwpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5D5ApyDoK2BoC0m1Wv4eVWQ+1LfMP/3EjjiISUrfvcZD0gd7EdcgHGGy64Ns8Z1wMv97S9E2ATAL7Boy8L0oNYmar0ZKSX7eivjX9buMnJl8wSSKMwAe3qVSybrLTiBb7cNAj/uS8yLGwMrbSEd0ME3lgNIf3MMOfzqxwekra4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KXxGBT8q; arc=none smtp.client-ip=185.246.84.56 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.b="KXxGBT8q" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 3CBD21A27FC; Mon, 12 Jan 2026 14:21:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 11D34606FA; Mon, 12 Jan 2026 14:21:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D310E103C9270; Mon, 12 Jan 2026 15:20:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227660; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ioSJXthUvZ+YQtI4bflfnpeu6berBaUGVjc2wmCUJk0=; b=KXxGBT8qSqMmyPXCjIyptIfSxWz3QUtpK4qGseKP2tn1zPs6EZTog0WnA0E0bvM/P+ph54 BANVKru3TxYzwZA88pGnLOcpqhbRQe5m/o9vEKNj3imCw/BkDxrKyRBBi9UkvqAP9q+l/y 7Cu+t/Yhz8HA3xsPd/Ek8dOIfgZ7P3YM4NjZcSAy3nZzHLSdVmqA3zMrgpwAO3cOfCWtrM I5dVifdQEp3koF1EOX8sLlOqA7EAEW70VBsZFkFaHy577DyGUgGZ7IWaXcP9Kq77y83VC0 Vhpnrb3BlZlA9vzp3H9DSn0wy7vBVJqL5CqspC4IM/hlUBvOdd6Z+4yCduOjNA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 25/77] Add support for FDT_EXPORT_SYM dtb tag Date: Mon, 12 Jan 2026 15:19:15 +0100 Message-ID: <20260112142009.1006236-26-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The FDT_EXPORT_SYM dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is a local node and identified by a phandle value. The tag is followed by two values and a possible alignment padding: - name (string including \0) The export symbol name. I.e. the name used to reference this exported symbol. - padding: Padding (0x00) added to have the next value aligned on 32bit. - phandle (32bit) The phandle value identifying the node referenced by this symbol. Example: FDT_EXPORT_SYM 'foo1' 0x00 0x00 0x00 0x00000004 This means that 'foo1' is an exported symbol and the node referenced by this symbol is the node with the phandle value equals 4. This is what is encoded in the dtb when the related dts has the following exported symbol defined: /export/ foo1: &foo; with 'foo' a reference to an existing node where the phandle value is 0x0000004. If several symbols are exported at a given node level, several FDT_EXPORT_SYM are present. Each of them defining one symbol. For instance, exporting 'foo' pointing to phandle 4 and 'bar' pointing to phandle 8 leads to the following sequence: FDT_EXPORT_SYM 'foo' 0x00 0x00 0x00 0x00000004 FDT_EXPORT_SYM 'bar' 0x00 0x00 0x00 0x00000008 Add support for this new dtb tag. Signed-off-by: Herve Codina --- dtc.h | 1 + fdtdump.c | 12 +++++++++- flattree.c | 47 ++++++++++++++++++++++++++++++++++++++-- libfdt/fdt.c | 17 +++++++++++++++ libfdt/fdt.h | 2 ++ libfdt/libfdt_internal.h | 1 + livetree.c | 2 +- 7 files changed, 78 insertions(+), 4 deletions(-) diff --git a/dtc.h b/dtc.h index 024e172..22816ba 100644 --- a/dtc.h +++ b/dtc.h @@ -289,6 +289,7 @@ struct symbol *build_exportsym(const char *name, const = char *ref, cell_t phandle struct srcpos *srcpos); struct symbol *chain_symbol(struct symbol *first, struct symbol *list); struct symbol *reverse_symbol(struct symbol *list); +void add_symbol(struct symbol **list, struct symbol *new); =20 struct node *build_node(struct property *proplist, struct node *children, struct symbol *exportsymlist, struct srcpos *srcpos); diff --git a/fdtdump.c b/fdtdump.c index 9b6f41a..d1af5b6 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -57,7 +57,7 @@ static void dump_blob(void *blob, bool debug) const char *p_strings =3D (const char *)blob + off_str; uint32_t version =3D fdt32_to_cpu(bph->version); uint32_t totalsize =3D fdt32_to_cpu(bph->totalsize); - uint32_t tag, offset; + uint32_t tag, offset, val32; const char *p, *s, *t; const char *last_prop_name =3D NULL; int depth, sz, shift; @@ -176,6 +176,16 @@ static void dump_blob(void *blob, bool debug) continue; } =20 + if (tag =3D=3D FDT_EXPORT_SYM) { + s =3D p; + p =3D PALIGN(p + strlen(s) + 1, 4); + val32 =3D fdt32_to_cpu(GET_CELL(p)); + + printf("%*s// [FDT_EXPORT_SYM] '%s' -> phandle 0x%08"PRIx32"\n", + depth * shift, "", s, val32); + continue; + } + fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "",= tag); break; } diff --git a/flattree.c b/flattree.c index 36b795d..bd52e81 100644 --- a/flattree.c +++ b/flattree.c @@ -15,6 +15,7 @@ #define FTF_NOPS 0x40 #define FTF_REF_XXX 0x80 #define FTF_DTFLAGS 0x100 +#define FTF_EXPORT_IMPORT_SYM 0x200 =20 static struct version_info { int version; @@ -34,7 +35,7 @@ static struct version_info { FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, {18, 18, FDT_V18_SIZE, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX| - FTF_DTFLAGS}, + FTF_DTFLAGS|FTF_EXPORT_IMPORT_SYM}, }; =20 struct emitter { @@ -47,6 +48,7 @@ struct emitter { void (*property)(void *, struct label *labels); void (*ref_local)(void *); void (*ref_phandle)(void *); + void (*export_sym)(void *); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -106,6 +108,11 @@ static void bin_emit_ref_phandle(void *e) bin_emit_cell(e, FDT_REF_PHANDLE); } =20 +static void bin_emit_export_sym(void *e) +{ + bin_emit_cell(e, FDT_EXPORT_SYM); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -116,6 +123,7 @@ static struct emitter bin_emitter =3D { .property =3D bin_emit_property, .ref_local =3D bin_emit_ref_local, .ref_phandle =3D bin_emit_ref_phandle, + .export_sym =3D bin_emit_export_sym, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -243,6 +251,14 @@ static void asm_emit_ref_phandle(void *e) asm_emit_cell(e, FDT_REF_PHANDLE); } =20 +static void asm_emit_export_sym(void *e) +{ + FILE *f =3D e; + + fprintf(f, "\t/* FDT_EXPORT_SYM */\n"); + asm_emit_cell(e, FDT_EXPORT_SYM); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -253,6 +269,7 @@ static struct emitter asm_emitter =3D { .property =3D asm_emit_property, .ref_local =3D asm_emit_ref_local, .ref_phandle =3D asm_emit_ref_phandle, + .export_sym =3D asm_emit_export_sym, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -274,6 +291,7 @@ static void flatten_tree(struct node *tree, struct emit= ter *emit, void *etarget, struct data *strbuf, struct version_info *vi) { + struct symbol *exportsym; struct property *prop; struct node *child; bool seen_name_prop =3D false; @@ -342,6 +360,18 @@ static void flatten_tree(struct node *tree, struct emi= tter *emit, emit->align(etarget, sizeof(cell_t)); } =20 + if (vi->flags & FTF_EXPORT_IMPORT_SYM) { + for_each_symbol(tree->exportsymlist, exportsym) { + if (exportsym->is_local) { + emit->export_sym(etarget); + emit->string(etarget, exportsym->name, 0); + emit->align(etarget, sizeof(cell_t)); + emit->cell(etarget, exportsym->phandle); + continue; + } + } + } + for_each_child(tree, child) { flatten_tree(child, emit, etarget, strbuf, vi); } @@ -820,9 +850,11 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, node->name =3D xstrdup(flatname); =20 do { + struct symbol *exportsym; struct property *prop; struct node *child; struct marker *m; + cell_t phandle; =20 val =3D flat_read_word(dtbuf); switch (val) { @@ -876,6 +908,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, prop->val =3D data_append_markers(prop->val, m); break; =20 + case FDT_EXPORT_SYM: + if (!(flags & FTF_EXPORT_IMPORT_SYM)) + die("FDT_EXPORT_SYM tag found in flat tree" + " version <18\n"); + str =3D flat_read_string(dtbuf); + phandle =3D flat_read_word(dtbuf); + exportsym =3D build_exportsym(str, NULL, phandle, NULL); + exportsym->is_local =3D true; + add_symbol(&node->exportsymlist, exportsym); + break; + default: die("Invalid opcode word %08x in device tree blob\n", val); @@ -996,7 +1039,7 @@ struct dt_info *dt_from_blob(const char *fname) } =20 if (version >=3D 18) { - flags |=3D FTF_REF_XXX | FTF_DTFLAGS; + flags |=3D FTF_REF_XXX | FTF_DTFLAGS | FTF_EXPORT_IMPORT_SYM; dtsflags |=3D fdt32_to_cpu(fdt->dt_flags) & FDT_FLAG_ADDON ? DTSF_ADDON : 0; } diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 8f3c35d..44d7399 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -232,6 +232,22 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) return FDT_END; /* premature end */ break; =20 + case FDT_EXPORT_SYM: + /* Skip name */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + offset =3D FDT_CELLALIGN(offset); + + /* Skip phandle */ + tmp32p =3D fdt_offset_ptr(fdt, offset, sizeof(*tmp32p)); + if (!can_assume(VALID_DTB) && !tmp32p) + return FDT_END; /* premature end */ + offset +=3D sizeof(fdt32_t); + break; + default: return FDT_END; } @@ -273,6 +289,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) =20 case FDT_REF_LOCAL: case FDT_REF_PHANDLE: + case FDT_EXPORT_SYM: /* * Next tag is a meta-data tag present in the middle * of the structure -> Skip it and look at next one diff --git a/libfdt/fdt.h b/libfdt/fdt.h index 94f65e6..e85bc07 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -53,6 +53,7 @@ struct fdt_property { #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ #define FDT_FLAG_ADDON 0x1 #define FDT_TAGSIZE sizeof(fdt32_t) +#define FDT_CELLSIZE sizeof(fdt32_t) =20 #define FDT_BEGIN_NODE 0x1 /* Start node: full name */ #define FDT_END_NODE 0x2 /* End node */ @@ -63,6 +64,7 @@ struct fdt_property { #define FDT_REF_PHANDLE 0x6 /* external phandle reference: offset, external label */ #define FDT_END 0x9 +#define FDT_EXPORT_SYM 0xa /* export symbol: name, phandle value */ =20 #define FDT_V1_SIZE (7*sizeof(fdt32_t)) #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index 0e103ca..d80d218 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -9,6 +9,7 @@ =20 #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) +#define FDT_CELLALIGN(x) (FDT_ALIGN((x), FDT_CELLSIZE)) =20 int32_t fdt_ro_probe_(const void *fdt); #define FDT_RO_PROBE(fdt) \ diff --git a/livetree.c b/livetree.c index 7cf3ee5..7efa1da 100644 --- a/livetree.c +++ b/livetree.c @@ -74,7 +74,7 @@ struct symbol *reverse_symbol(struct symbol *list) return head; } =20 -static void add_symbol(struct symbol **list, struct symbol *new) +void add_symbol(struct symbol **list, struct symbol *new) { struct symbol **s; =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B19582DAFAF; Mon, 12 Jan 2026 14:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227669; cv=none; b=O0OuTaFniherHqu7dN1nS6Sdm1ssXpjKxM+MUhX5og1a7vMuPKi1jVzfKYHQAKBx4qzybpWe18/Azq1Atvj++qOOn+1lQwtyqO+kxPWGZt1aJTmT9JG1T6lg951QklaveqWuQL98e0JTB3xw9EYnmiNvvcCTzDvyNcNivKCSgqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227669; c=relaxed/simple; bh=mhfCVt5rt3GPtwxOIzuJdMwa4TeV6J9WyWsZPDpBhGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t4yYhP55nHOX3nv1boI9ztKTjZ3deYgP9P7Mm5RNqwK5bBYTay1Mm24MFMM9/POpYXTvL3tMPMH21BGHt/2OzPkmr4zxDSoTYajFY2q+EaxAvaak0uB9s4pH/CwfQM9Yi5LauvokXJWiP446Un2Nmp9pPDPoEgrGlbpDa9wMaL4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=d8vZgF/+; arc=none smtp.client-ip=185.246.84.56 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.b="d8vZgF/+" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 934411A2806; Mon, 12 Jan 2026 14:21:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 69973606FA; Mon, 12 Jan 2026 14:21:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8DCD8103C9273; Mon, 12 Jan 2026 15:21:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227661; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=SpFU+MiK+5/rjM23lkiUnkBAKVGmsCcgGfRucPp3BEs=; b=d8vZgF/+/XUSTBhtcMA1b2kwW/RaSqZ59WDsVdugxm25Y74KPJXThvsqI47CZ7CsklmRh/ ClAkUATQ85gRNu5h0n7/HB8qNnU7kQwyxFxtxbGBAnItw9QNgSfjMJEDvUAPxJX/Qb2Qbi eA6FCPY0V+2sr3t8RiJUr9rAEVAxJCZ9iJm42s2PMbA7DnrVft4aew1BDxm+YkWc20MX7/ 7ajQ3jArovba3VLRZSYyIf/bxgeo9BWJ0CbguC446u7UgqbdlcMgWbruJWcCK/wl7cba4K r0RVWB+xjBAsyT1zviDIafNd2l+7P+03qrM4dBm7ygVdL7NcB9/JlXjNvpq6Fw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 26/77] tests: metadata: Add export symbols with local references tests Date: Mon, 12 Jan 2026 15:19:16 +0100 Message-ID: <20260112142009.1006236-27-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add tests related to export symbols using local phandle references (FDT_EXPORT_SYM dtb tag). Signed-off-by: Herve Codina --- .../metadata_exportsyms_local.dtb.dts.expect | 26 +++++++++++++++++ tests/metadata_exportsyms_local.dtb.expect | 20 +++++++++++++ tests/metadata_exportsyms_local.dts | 28 +++++++++++++++++++ .../metadata_exportsyms_local.dts.dts.expect | 26 +++++++++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_exportsyms_local.dtb.dts.expect create mode 100644 tests/metadata_exportsyms_local.dtb.expect create mode 100644 tests/metadata_exportsyms_local.dts create mode 100644 tests/metadata_exportsyms_local.dts.dts.expect diff --git a/tests/metadata_exportsyms_local.dtb.dts.expect b/tests/metadat= a_exportsyms_local.dtb.dts.expect new file mode 100644 index 0000000..ac3d5b3 --- /dev/null +++ b/tests/metadata_exportsyms_local.dtb.dts.expect @@ -0,0 +1,26 @@ +/dts-v1/; + +/ { + + node-a { + }; + + node-b { + phandle =3D <0x03>; + }; + + node-c { + + sub-node { + phandle =3D <0x02>; + }; + }; + + node-d { + phandle =3D <0x01>; + + /export/ node_d: &{/node-d}; + /export/ subnode_c: &{/node-c/sub-node}; + /export/ node_b: &{/node-b}; + }; +}; diff --git a/tests/metadata_exportsyms_local.dtb.expect b/tests/metadata_ex= portsyms_local.dtb.expect new file mode 100644 index 0000000..2002553 --- /dev/null +++ b/tests/metadata_exportsyms_local.dtb.expect @@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + node-a { + }; + node-b { + phandle =3D <0x00000003>; + }; + node-c { + sub-node { + phandle =3D <0x00000002>; + }; + }; + node-d { + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_d' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'subnode_c' -> phandle 0x00000002 + // [FDT_EXPORT_SYM] 'node_b' -> phandle 0x00000003 + }; +}; diff --git a/tests/metadata_exportsyms_local.dts b/tests/metadata_exportsym= s_local.dts new file mode 100644 index 0000000..10e6e47 --- /dev/null +++ b/tests/metadata_exportsyms_local.dts @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + node-a { + }; + + node_b: node-b { + }; + + node-c { + sub_node: sub-node { + }; + }; + + node_d: node-d { + /export/ node_d: &node_d; + /export/ subnode_c: &sub_node; + }; +}; + +&node_d { + /export/ node_b: &node_b; +}; diff --git a/tests/metadata_exportsyms_local.dts.dts.expect b/tests/metadat= a_exportsyms_local.dts.dts.expect new file mode 100644 index 0000000..4723e7e --- /dev/null +++ b/tests/metadata_exportsyms_local.dts.dts.expect @@ -0,0 +1,26 @@ +/dts-v1/; + +/ { + + node-a { + }; + + node_b: node-b { + phandle =3D <0x03>; + }; + + node-c { + + sub_node: sub-node { + phandle =3D <0x02>; + }; + }; + + node_d: node-d { + phandle =3D <0x01>; + + /export/ node_d: &node_d; + /export/ subnode_c: &sub_node; + /export/ node_b: &node_b; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index def1a7e..ed3a240 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1126,7 +1126,7 @@ wrap_fdtdump () { =20 metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ - metadata_addon_base; do + metadata_addon_base metadata_exportsyms_local; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F03B22DE70C; Mon, 12 Jan 2026 14:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227667; cv=none; b=Vap+4z6d90y8fgJTzrFCjgN1fFD91CERoHfqSs+USlkvRLYz2puhVF37mPiHenQkmNwI1rk0pF4xL6kjUXZfP7hSQqUEROBPKJTiZ4SYYjFPn9O9FAzwQA1rxSBk6vIE0rPi/NfEbONWSZzpc7ocQQiT56PdR/ZI/vmoAF3A3iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227667; c=relaxed/simple; bh=nniPvKcWEi4LfAC3oR0MW3FHuw9UeRhJz/7mnfTVxSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zc772qiJPFZ1Ngv4D+xtqxofAzhV4Geh3864IpdgAuZwNjEo9Br6oN9ImhlatoCaQTWIaF/crp2BPfZpBP5nUpH2yLFnKC3DaYZBdD1Rid4ocY7T09ETPpTk4xuG4xfEgkfruvTXl47elSkrgNr5G0KKEvOHeUnZB8R76b+kBg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=FvI1FgiV; arc=none smtp.client-ip=185.171.202.116 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.b="FvI1FgiV" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 3049EC2086B; Mon, 12 Jan 2026 14:20:38 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A8723606FA; Mon, 12 Jan 2026 14:21:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 10082103C9280; Mon, 12 Jan 2026 15:21:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227663; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=iEuhMiG7AJAvgbNC6ER9xCpEGPNZd1hu0Nn4zQ6EPeA=; b=FvI1FgiVlJxeGRt0eclmys0iC3nYIL450BFJer9/TPmSa5a4KmIj8JbXjsIM0kYMvLzy6F mXh0OAXs3R+SlLQwMCWsVePG0n1Bpdbpecs8r8dUdaSBdgbbSE0eP+9d7Bx8sfOoFIkrT3 KgiS1OSIIgctN0IEKOh3tgbKwmcSr2ab6EJD+QB6GdtSIPWvxMaXLPuondmO/p5eC014oL uHtDdp+ANMqvcMGA4P6W8lmzwK5awYPEWEubxMRnRYNjU8o/qA225NGdeJI0TTBDTKEE9e Jtt0pLtvLkNnPfaVRVd3dEjkpcVWFFAi5iyhBFn4lclft7zh7p0UJgaxUSdFnA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 27/77] dtc: Add support for export symbols sorting Date: Mon, 12 Jan 2026 15:19:17 +0100 Message-ID: <20260112142009.1006236-28-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc can sort items when the command line --sort option is set. Add support for export symbols sorting when this option is used. Signed-off-by: Herve Codina --- livetree.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/livetree.c b/livetree.c index 7efa1da..1de5990 100644 --- a/livetree.c +++ b/livetree.c @@ -916,6 +916,42 @@ static void sort_properties(struct node *node) free(tbl); } =20 +static int cmp_symbol(const void *ax, const void *bx) +{ + const struct symbol *a, *b; + + a =3D *((const struct symbol * const *)ax); + b =3D *((const struct symbol * const *)bx); + + return strcmp(a->name, b->name); +} + +static void sort_exportsyms(struct node *node) +{ + int n =3D 0, i =3D 0; + struct symbol *symbol, **tbl; + + for_each_symbol(node->exportsymlist, symbol) + n++; + + if (n =3D=3D 0) + return; + + tbl =3D xmalloc(n * sizeof(*tbl)); + + for_each_symbol(node->exportsymlist, symbol) + tbl[i++] =3D symbol; + + qsort(tbl, n, sizeof(*tbl), cmp_symbol); + + node->exportsymlist =3D tbl[0]; + for (i =3D 0; i < (n-1); i++) + tbl[i]->next =3D tbl[i+1]; + tbl[n-1]->next =3D NULL; + + free(tbl); +} + static int cmp_subnode(const void *ax, const void *bx) { const struct node *a, *b; @@ -957,6 +993,7 @@ static void sort_node(struct node *node) struct node *c; =20 sort_properties(node); + sort_exportsyms(node); sort_subnodes(node); for_each_child_withdel(node, c) sort_node(c); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9C3B35CBAF; Mon, 12 Jan 2026 14:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227672; cv=none; b=leh+0oezB4naAuvmrhwNTgKBoMN0b+ICE+0vuinacpNT9r3HKdDZgIZANJaAYcoBG0GslgPreVwNn2rUzD1cAcWD4vQsrNsrJ1iAUhSIyj+9zu9v5rAIbZFAFZbFgD6IHO1Fhru6hv/klGmlok8anZRv2ui4cDakwQwo8UyYtGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227672; c=relaxed/simple; bh=P/XdXd/bYrHZDkDSuHHmyyBrAIsBa+F365UKC6ogKGc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iY85CNQQ8/xoH69iFdm8gMQeogz7KMFVm5jMIbdW++mD/fDIECEqH64uWyP+s+Ve809Ag0Mc4r+xqVWUGH18WcLtBcLCCJU71JHl0WkqFARC6jZJonnms+XP0KJMdWp2KflDLEo+SoQgBmlqYhnE7ILw3gphyvlbSRyiOPwpyLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=I5dUvqxY; arc=none smtp.client-ip=185.246.84.56 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.b="I5dUvqxY" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 6FB051A280A; Mon, 12 Jan 2026 14:21:06 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 40832606FA; Mon, 12 Jan 2026 14:21:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BF03F103C9281; Mon, 12 Jan 2026 15:21:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227665; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lIzmhSqDNTNqAbKeLro4jdmwBQewOntD3SjbuDJaI24=; b=I5dUvqxY5xJG2c6pwe+N4sFvEgcHpPGPyMCBud3s8zVfSDuIq8eUlxGaTmlZ73Y0rY+YWV 4zbyufJMhvKzlnoWGbva+xs7kaeeNvIlxmQ/b2/kMJbG6l2nCZvPN67M5JeJ6veqDdi3oT K33k/3oYguaQ+q3VPx5OGX5Mk4VHBEAQd1h8ySx3Fv42EnxFiWEHNixwySmlNY1dzXWUk6 5ek2OS5KShqVztkDeXHhPqIBk/CRct2jUqX+OaFD2GwkbHRWmcIajgzU4ah9LbacaBEQCI Dh/qLQ/WiijDrv7Qu/PBCUa9MOmJSIT4JtJfB4nBjT0bERpLBsNwHSmwVRogQQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 28/77] tests: metadata: Add a test for export symbols sorting Date: Mon, 12 Jan 2026 15:19:18 +0100 Message-ID: <20260112142009.1006236-29-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc is able to sort the export symbols list when the --sort option is used. Add a test for this feature. Signed-off-by: Herve Codina --- tests/metadata_sort.dtb.dts.expect | 18 ++++++++++++++++++ tests/metadata_sort.dtb.expect | 15 +++++++++++++++ tests/metadata_sort.dts | 21 +++++++++++++++++++++ tests/run_tests.sh | 8 ++++++++ 4 files changed, 62 insertions(+) create mode 100644 tests/metadata_sort.dtb.dts.expect create mode 100644 tests/metadata_sort.dtb.expect create mode 100644 tests/metadata_sort.dts diff --git a/tests/metadata_sort.dtb.dts.expect b/tests/metadata_sort.dtb.d= ts.expect new file mode 100644 index 0000000..f07a42b --- /dev/null +++ b/tests/metadata_sort.dtb.dts.expect @@ -0,0 +1,18 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop_a =3D <0x1c8>; + prop_b =3D <0x7b>; + + /export/ a: &{/node-b}; + /export/ ba: &{/node-b}; + /export/ bb: &{/node-b}; + }; + + node-b { + phandle =3D <0x01>; + }; +}; diff --git a/tests/metadata_sort.dtb.expect b/tests/metadata_sort.dtb.expect new file mode 100644 index 0000000..7856894 --- /dev/null +++ b/tests/metadata_sort.dtb.expect @@ -0,0 +1,15 @@ +/dts-v1/; +/addon/; + +/ { + node-a { + prop_a =3D <0x000001c8>; + prop_b =3D <0x0000007b>; + // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'ba' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'bb' -> phandle 0x00000001 + }; + node-b { + phandle =3D <0x00000001>; + }; +}; diff --git a/tests/metadata_sort.dts b/tests/metadata_sort.dts new file mode 100644 index 0000000..7d1cca7 --- /dev/null +++ b/tests/metadata_sort.dts @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + node_b: node-b { + }; + + node-a { + prop_b =3D <123>; + prop_a =3D <456>; + + /export/ ba: &node_b; + /export/ bb: &node_b; + /export/ a: &node_b; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index ed3a240..fc270e2 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1154,6 +1154,14 @@ metadata_tests() { # Keep only lines containing 'dt_flags' sed -i '/dt_flags/!d' metadata_dtflags1.dtb.out base_run_test check_diff metadata_dtflags1.dtb.out "$SRCDIR/metadata_dtfl= ags1.dtb.expect" + + run_dtc_test -I dts -O dtb -s -o metadata_sort.dtb "$SRCDIR/metadata_sort= .dts" + base_run_test wrap_fdtdump metadata_sort.dtb metadata_sort.dtb.out + # Remove unneeded comments + sed -i '/^\/\/ /d' metadata_sort.dtb.out + base_run_test check_diff metadata_sort.dtb.out "$SRCDIR/metadata_sort.dtb= .expect" + run_dtc_test -I dtb -O dts -o metadata_sort.dtb.dts metadata_sort.dtb + base_run_test check_diff metadata_sort.dtb.dts "$SRCDIR/metadata_sort.dtb= .dts.expect" } =20 pylibfdt_tests () { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55CF335EDA4; Mon, 12 Jan 2026 14:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227674; cv=none; b=gj8/6GjADSrtc8sstDwIWj391xpqtsUL5Mh28U6DPzFfXtVJSyXFHrN12CfNFkmz6y0aAJ0qfT2m0OPDu0jIDHfzqJInUJ5plL3y9Faj0XRT7NbtQN0yUBtA9w+nVjEUSEI/qLPItPEpGJUsmPAds671epTKdw3q0z3i+h+2mjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227674; c=relaxed/simple; bh=tOVMJYuO8prfhsCsN/Amr9P2xRVZLHjCprcPJLv7o2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gi9M2Qg+wBui/3reZGMO61sY1kF/RpMh33fc53HkEgez/ZrHPLn0zJ06/ZViphw/2pCRkgLz0RF14ixhC8oNSyyDvszBkyGdoVh4REBTPjabz8cDEunRHrjTuS/seQShLHp5rVRb34eAKDEu8Jj4hBKbvwEdQ8D3CsqnyvlQcIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=cpG326GH; arc=none smtp.client-ip=185.246.84.56 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.b="cpG326GH" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id A9DFA1A2803; Mon, 12 Jan 2026 14:21:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 80FF7606FA; Mon, 12 Jan 2026 14:21:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 98E94103C9285; Mon, 12 Jan 2026 15:21:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227666; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=T4jTgWAUMEz0XkU45RA92bUyAxdBYgzEme5177ZYF7Q=; b=cpG326GHbDM1DIau/FH+xERYMtx6EqjsNFxkVbYYe/sP7heY9rq9xZr1jB+Jv+bdwwthUO eZ8o/BVX5hW2Eppiazrt1smzXVNSEmAhYenciIlPsR1e+mGpu2T+7Z5dmRZumv9fwvjqMi KOBiM6BtaU8dtHrurLsJ0deCNVV9b+codfcheWV/L/iIifOArLYTsU2geCcVagCyrabdv0 6NlbOkCxXm60kYQ+IBTIjBhzeMypT9yWGm5+TORGtAn7qE8Z60AC68UjOpEgMrLSRR42Lo QoeexDBTC0wRbZmCHiK2XhdBKKMjP+xl+cbEayc+5U76MABH1kZh1Or96rsoBw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 29/77] Add support for FDT_EXPORT_SYM_REF dtb tag Date: Mon, 12 Jan 2026 15:19:19 +0100 Message-ID: <20260112142009.1006236-30-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The FDT_EXPORT_SYM_REF dtb tag is similar to the FDT_EXPORT_SYM tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob. The FDT_EXPORT_SYM_REF dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is not a local node (i.e. the node is not present in the device-tree blob.). This tag can be available only in overlay or addon device-tree blobs. The symbol has to be resolved when the device-tree blob is applied on top of a base device-tree. It is followed by three values and a possible alignment padding: - name (string including \0) The export symbol name. I.e. the name used to reference this exported symbol. - padding: Padding (0x00) added to have the next value aligned on 32bit. - phandle (32bit) A placeholder for a phandle value. This placeholder can be used during some dtb manipulation to store a temporary phandle value. In terms of FDT_EXPORT_SYM_REF definition, it has no meaningful signification and will be probably set to 0xffffffff, the unresolved phandle value. - label (string including \0): The label to use to resolve this symbol. This label is the reference to the external phandle. - padding: Padding (0x00) added to have the next value aligned on 32bit. Example: FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 0xffffffff 'foo_a' 0x00 0x00 This means that 'foo1' is an exported symbol and the node referenced by this symbol is external to the dtb (unresolved symbol). This external node is referenced by the "foo_a" label. This is what is encoded in the dtb when the related dts has the following exported symbol defined: /export/ foo1: &foo_a; with 'foo_a' a reference to a non local node. If several non local symbols are exported at a given node level, several FDT_EXPORT_SYM_REF are present. Each of them defining one symbol. For instance, exporting 'foo1' pointing the node referenced by 'foo_a' and exporting 'bar1' pointing to the node referenced by 'bar_b' leads to the following sequence: FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 'foo_a' 0x00 0x00 FDT_EXPORT_SYM_REF 'bar1' 0x00 0x00 0x00 'bar_b' 0x00 0x00 Add support for this new dtb tag. Signed-off-by: Herve Codina --- fdtdump.c | 12 ++++++++++++ flattree.c | 40 ++++++++++++++++++++++++++++++++++++++++ libfdt/fdt.c | 24 ++++++++++++++++++++++++ libfdt/fdt.h | 2 ++ 4 files changed, 78 insertions(+) diff --git a/fdtdump.c b/fdtdump.c index d1af5b6..8baadc4 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -186,6 +186,18 @@ static void dump_blob(void *blob, bool debug) continue; } =20 + if (tag =3D=3D FDT_EXPORT_SYM_REF) { + s =3D p; + p =3D PALIGN(p + strlen(s) + 1, 4); + val32 =3D fdt32_to_cpu(GET_CELL(p)); + t =3D p; + p =3D PALIGN(p + strlen(t) + 1, 4); + + printf("%*s// [FDT_EXPORT_SYM_REF] '%s' -> '%s'\n", depth * shift, "", + s, t); + continue; + } + fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "",= tag); break; } diff --git a/flattree.c b/flattree.c index bd52e81..d970259 100644 --- a/flattree.c +++ b/flattree.c @@ -49,6 +49,7 @@ struct emitter { void (*ref_local)(void *); void (*ref_phandle)(void *); void (*export_sym)(void *); + void (*export_sym_ref)(void *); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -113,6 +114,11 @@ static void bin_emit_export_sym(void *e) bin_emit_cell(e, FDT_EXPORT_SYM); } =20 +static void bin_emit_export_sym_ref(void *e) +{ + bin_emit_cell(e, FDT_EXPORT_SYM_REF); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -124,6 +130,7 @@ static struct emitter bin_emitter =3D { .ref_local =3D bin_emit_ref_local, .ref_phandle =3D bin_emit_ref_phandle, .export_sym =3D bin_emit_export_sym, + .export_sym_ref =3D bin_emit_export_sym_ref, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -259,6 +266,14 @@ static void asm_emit_export_sym(void *e) asm_emit_cell(e, FDT_EXPORT_SYM); } =20 +static void asm_emit_export_sym_ref(void *e) +{ + FILE *f =3D e; + + fprintf(f, "\t/* FDT_EXPORT_SYM_REF */\n"); + asm_emit_cell(e, FDT_EXPORT_SYM_REF); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -270,6 +285,7 @@ static struct emitter asm_emitter =3D { .ref_local =3D asm_emit_ref_local, .ref_phandle =3D asm_emit_ref_phandle, .export_sym =3D asm_emit_export_sym, + .export_sym =3D asm_emit_export_sym_ref, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -369,6 +385,18 @@ static void flatten_tree(struct node *tree, struct emi= tter *emit, emit->cell(etarget, exportsym->phandle); continue; } + + if (exportsym->ref[0] =3D=3D '/') + die("Export symbol uses a non local reference by path (%s)\n", + m->ref); + + emit->export_sym_ref(etarget); + emit->string(etarget, exportsym->name, 0); + emit->align(etarget, sizeof(cell_t)); + /* Placeholder for the phandle */ + emit->cell(etarget, exportsym->phandle); + emit->string(etarget, exportsym->ref, 0); + emit->align(etarget, sizeof(cell_t)); } } =20 @@ -838,6 +866,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, uint32_t val; uint32_t offset; const char *str; + const char *str2; =20 node =3D build_node(NULL, NULL, NULL, NULL); =20 @@ -919,6 +948,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, add_symbol(&node->exportsymlist, exportsym); break; =20 + case FDT_EXPORT_SYM_REF: + if (!(flags & FTF_EXPORT_IMPORT_SYM)) + die("FDT_EXPORT_SYM_REF tag found in flat tree" + " version <18\n"); + str =3D flat_read_string(dtbuf); /* Name */ + phandle =3D flat_read_word(dtbuf); /* Phandle */ + str2 =3D flat_read_string(dtbuf); /* Ref */ + exportsym =3D build_exportsym(str, str2, phandle, NULL); + add_symbol(&node->exportsymlist, exportsym); + break; + default: die("Invalid opcode word %08x in device tree blob\n", val); diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 44d7399..febfa71 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -248,6 +248,29 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) offset +=3D sizeof(fdt32_t); break; =20 + case FDT_EXPORT_SYM_REF: + /* Skip name */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + offset =3D FDT_CELLALIGN(offset); + + /* Skip phandle */ + tmp32p =3D fdt_offset_ptr(fdt, offset, sizeof(*tmp32p)); + if (!can_assume(VALID_DTB) && !tmp32p) + return FDT_END; /* premature end */ + offset +=3D sizeof(fdt32_t); + + /* Skip external name */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + break; + default: return FDT_END; } @@ -290,6 +313,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) case FDT_REF_LOCAL: case FDT_REF_PHANDLE: case FDT_EXPORT_SYM: + case FDT_EXPORT_SYM_REF: /* * Next tag is a meta-data tag present in the middle * of the structure -> Skip it and look at next one diff --git a/libfdt/fdt.h b/libfdt/fdt.h index e85bc07..c23723b 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -65,6 +65,8 @@ struct fdt_property { external label */ #define FDT_END 0x9 #define FDT_EXPORT_SYM 0xa /* export symbol: name, phandle value */ +#define FDT_EXPORT_SYM_REF 0xb /* export symbol: name, phandle value (may= be + unresolved), external label */ =20 #define FDT_V1_SIZE (7*sizeof(fdt32_t)) #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1353E279DAF for ; Mon, 12 Jan 2026 14:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; cv=none; b=UlNjTIqielrW+ls0sXZiZHW8txT3onTsZn0o+aj+g45DAvVtEHkHRqdehIiJOgOOH4SRvEpaq8NH9Q9Tt4sK88QItFfycSQHPDxYYrQCD1Sq64oIRyjjrovFrmCW58k7I4XQa7BljYia+OrxJbTou6bhwsWa55UZKJAYgge8FNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; c=relaxed/simple; bh=Fbwc+CPSfjhz85440juvsZ0pX7weWkITVUYz8eTZYfs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rZUU9qEYh6NDYkezvwuCdjM4PO5sDJ+dhP9bxf+R4f87bReweauxFvctE8kOJOcvWkpIGoIq7HI2fURvtelPq3kjFLF8mF+n9U6/EncJNfLsdqiG3cHajoiD+hi0Rejgn5yk84mpM3H1NeXZVZyw2qb4fAd1/jKcMkKphCR5Xnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=rn9eEAn7; arc=none smtp.client-ip=185.171.202.116 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.b="rn9eEAn7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 830B3C20869; Mon, 12 Jan 2026 14:20:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 07055606FA; Mon, 12 Jan 2026 14:21:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EEB0F103C8CD8; Mon, 12 Jan 2026 15:21:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227668; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ac92SjZaWRlxbkMuumtO9ux8bEMj0nelgYnFJXuWnmg=; b=rn9eEAn7bhvN55DNBuIKQQjH6ooCxXAzEWYguAG+riKGzMoQwV/ASiVevxkV72czNFaEXA xwF+7kXBdZi39rFSWuZ42t3OOFhkaTjgOf1TTK+hS6YQT5y5C22vScfxnh4EfJCIgCkZA/ APs6NB9UowNpVWpoEFcihUFehlZfw79pzrhZ0zVqSk+nSRYNu/MewQPZqa5stIiTsekJrm g/qn2gMLamuAO+y7M4SqhtSz0yFoziIK63afvg9fpiq3IM8fO9agDjklrs0lqokXG6dGW9 Yef744q6h2EkDdqtAdK6LZ8zVZbt1pP22mZjCFX4D3SaN6DX2DngJmMelNTONA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 30/77] tests: metadata: Add export symbols with external references tests Date: Mon, 12 Jan 2026 15:19:20 +0100 Message-ID: <20260112142009.1006236-31-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add tests related to export symbols using external references (FDT_EXPORT_SYM_REF dtb tag). Signed-off-by: Herve Codina --- tests/metadata_exportsyms_ref.dtb.dts.expect | 25 +++++++++++++++++++ tests/metadata_exportsyms_ref.dtb.expect | 18 ++++++++++++++ tests/metadata_exportsyms_ref.dts | 26 ++++++++++++++++++++ tests/metadata_exportsyms_ref.dts.dts.expect | 25 +++++++++++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_exportsyms_ref.dtb.dts.expect create mode 100644 tests/metadata_exportsyms_ref.dtb.expect create mode 100644 tests/metadata_exportsyms_ref.dts create mode 100644 tests/metadata_exportsyms_ref.dts.dts.expect diff --git a/tests/metadata_exportsyms_ref.dtb.dts.expect b/tests/metadata_= exportsyms_ref.dtb.dts.expect new file mode 100644 index 0000000..d2c3320 --- /dev/null +++ b/tests/metadata_exportsyms_ref.dtb.dts.expect @@ -0,0 +1,25 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + }; + + node-b { + }; + + node-c { + + sub-node { + + /export/ ref_base_node_a: &base_node_a; + /export/ ref_base_node_b: &base_node_b; + }; + }; + + node-d { + + /export/ ref_base_node_c: &base_node_c; + }; +}; diff --git a/tests/metadata_exportsyms_ref.dtb.expect b/tests/metadata_expo= rtsyms_ref.dtb.expect new file mode 100644 index 0000000..395861b --- /dev/null +++ b/tests/metadata_exportsyms_ref.dtb.expect @@ -0,0 +1,18 @@ +/dts-v1/; +/addon/; + +/ { + node-a { + }; + node-b { + }; + node-c { + sub-node { + // [FDT_EXPORT_SYM_REF] 'ref_base_node_a' -> 'base_node_a' + // [FDT_EXPORT_SYM_REF] 'ref_base_node_b' -> 'base_node_b' + }; + }; + node-d { + // [FDT_EXPORT_SYM_REF] 'ref_base_node_c' -> 'base_node_c' + }; +}; diff --git a/tests/metadata_exportsyms_ref.dts b/tests/metadata_exportsyms_= ref.dts new file mode 100644 index 0000000..c094be1 --- /dev/null +++ b/tests/metadata_exportsyms_ref.dts @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + node-a { + }; + + node-b { + }; + + node-c { + sub_node: sub-node { + /export/ ref_base_node_a: &base_node_a; + /export/ ref_base_node_b: &base_node_b; + }; + }; + + node-d { + /export/ ref_base_node_c: &base_node_c; + }; +}; diff --git a/tests/metadata_exportsyms_ref.dts.dts.expect b/tests/metadata_= exportsyms_ref.dts.dts.expect new file mode 100644 index 0000000..2654df1 --- /dev/null +++ b/tests/metadata_exportsyms_ref.dts.dts.expect @@ -0,0 +1,25 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + }; + + node-b { + }; + + node-c { + + sub_node: sub-node { + + /export/ ref_base_node_a: &base_node_a; + /export/ ref_base_node_b: &base_node_b; + }; + }; + + node-d { + + /export/ ref_base_node_c: &base_node_c; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index fc270e2..1973525 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1126,7 +1126,8 @@ wrap_fdtdump () { =20 metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ - metadata_addon_base metadata_exportsyms_local; do + metadata_addon_base metadata_exportsyms_local \ + metadata_exportsyms_ref; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E329274B30; Mon, 12 Jan 2026 14:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227677; cv=none; b=N6lKK8klh+bHwf/fGqzye5CHW+ZRsVhTGervkxoqJ/QilXKvzkQAExUun9ZzLdh7yme8cx7asn7oWI6ydN9JzV6D6JKqn9r/ZZfhVbzAXFzrhPfcuRK0rFpJ0CitOlUqEbkFtO4nEOBI2+isUjQ1Ma+PCo+gPi9wru9v5wgyEYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227677; c=relaxed/simple; bh=Qupti9JYIx5M1WClAqjvNcU4GtJ8Ej/MuffmAQXKn9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rgzCjy6lyJs3UjPHWQE4xq3xLZlTKZ2PlXMFbCBi6TsuUZ2Ft9iNjGzBoWscuJlcupB4si76nku0YZuF9KlePq3Nu6ecL/oVYaX66ofBNJFxamXiumYVE+fkB0SytnkIOyJ+oAX8rprXrRl1NliWa5RNLtNfQb/6gyRXQE5rM8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=HrELKDXR; arc=none smtp.client-ip=185.246.85.4 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.b="HrELKDXR" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id D8CA54E42097; Mon, 12 Jan 2026 14:21:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AF1E1606FA; Mon, 12 Jan 2026 14:21:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 51B9E103C9260; Mon, 12 Jan 2026 15:21:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227669; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=FemrtMrSgqeOA8KgOvOh4Sq9DDEMgd+SGRC7M4Bg9u8=; b=HrELKDXR36UQl6h4YdJqaifnopf+5Hprs1KWzhJbc+ZD82OGl9my6cySn0ah/wOOTex+lp Ocu9RypEP74l+HXiyllsQ7DksOEQvNRaXYVCQSt3CVmeVSen6TBD1F4r3MwNZwwqVDbTbo C7WL92fsg7x4TgEMHsAs6bnPGP702EezgbOIcx+N5Emwh3N8GV28QB02HvxwL6pit3PLhK AVQLKwyWnA4shqCTysCtePcrHMK9TdU1UNsh1+L5B8g8CJ53wtj4RFwUkmLC5LiRkGBP7C lTk+Wq0y3Lm/iRW+BB4KGcZAUPIgp79m/Wm+O/cGZNNfFwdPHJ218CPacX6kFw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 31/77] dtc: Introduce import symbols Date: Mon, 12 Jan 2026 15:19:21 +0100 Message-ID: <20260112142009.1006236-32-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Import symbols allow to define a list of symbols imported and used by an addon. Those symbols have to be resolved when the addon is applied on a base device-tree and will involved exported symbols provided at the node the addon is applied to. Import symbols are similar in term of feature to __fixups__ available in device-tree overlays. The goal is to identify symbols which are used by an addon but not defined by the addon itself. Those specific symbols are the imported symbols. Introduce the import symbols list related to an addon. No functional change yet but preparation for the future support for import symbol parsing. Signed-off-by: Herve Codina --- dtc-parser.y | 3 ++- dtc.h | 4 +++- flattree.c | 2 +- fstree.c | 2 +- livetree.c | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index a0d0aef..4e46e9d 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -113,7 +113,8 @@ sourcefile: headers memreserves devicetree { parser_output =3D build_dt_info($1, $2, $3, - guess_boot_cpuid($3)); + guess_boot_cpuid($3), + NULL); } ; =20 diff --git a/dtc.h b/dtc.h index 22816ba..796ed51 100644 --- a/dtc.h +++ b/dtc.h @@ -350,6 +350,7 @@ struct dt_info { struct reserve_info *reservelist; uint32_t boot_cpuid_phys; struct node *dt; /* the device tree */ + struct symbol *importsymlist; /* Import symbol list */ const char *outname; /* filename being written to, "-" for stdout */ }; =20 @@ -360,7 +361,8 @@ struct dt_info { =20 struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, - struct node *tree, uint32_t boot_cpuid_phys); + struct node *tree, uint32_t boot_cpuid_phys, + struct symbol *importsymlist); void sort_tree(struct dt_info *dti); void generate_label_tree(struct dt_info *dti, const char *name, bool alloc= ph); void generate_fixups_tree(struct dt_info *dti, const char *name); diff --git a/flattree.c b/flattree.c index d970259..47a289f 100644 --- a/flattree.c +++ b/flattree.c @@ -1105,5 +1105,5 @@ struct dt_info *dt_from_blob(const char *fname) =20 fclose(f); =20 - return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys); + return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, NULL); } diff --git a/fstree.c b/fstree.c index 445ae53..a6aaf1e 100644 --- a/fstree.c +++ b/fstree.c @@ -72,5 +72,5 @@ struct dt_info *dt_from_fs(const char *dirname) tree =3D read_fstree(dirname); tree =3D name_node(tree, ""); =20 - return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree)); + return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL); } diff --git a/livetree.c b/livetree.c index 1de5990..4ec9609 100644 --- a/livetree.c +++ b/livetree.c @@ -531,7 +531,8 @@ struct reserve_info *add_reserve_entry(struct reserve_i= nfo *list, =20 struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, - struct node *tree, uint32_t boot_cpuid_phys) + struct node *tree, uint32_t boot_cpuid_phys, + struct symbol *importsymlist) { struct dt_info *dti; =20 @@ -540,6 +541,7 @@ struct dt_info *build_dt_info(unsigned int dtsflags, dti->reservelist =3D reservelist; dti->dt =3D tree; dti->boot_cpuid_phys =3D boot_cpuid_phys; + dti->importsymlist =3D importsymlist; =20 return dti; } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26E935EDD6 for ; Mon, 12 Jan 2026 14:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; cv=none; b=q1Qv+VLiqIj2No0/PDWxyzjr1CtJn4JiH/iZH42/QeYkm9ac/vWtJLE16UVj3/mqnHLN7rjIioGOgRU23REGeeKz4hFr5x1eYX4JjGANDhH3s+qzsUg/F4JQ4PTPReg0ji+UWTw4BxrDEJISEAqMXikyIAvAfUXM0u6S5GQYXHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; c=relaxed/simple; bh=mxWyWe+6tgliFAK69mK8yOaUcXsCwF4dxGaUJaHzMos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4t4yVc7jf74XX2r9t/bGTi1N7ETN3st7S6f3x/2a2bBWlt1XHwz8jjBLY05LyV+9tA8288QztiKaIxsB7jTjGKNFnAeq8qSPgOsIydFI68T6n0VQ8sdswQ6h+gxJ2xmFeKjpTnxmmrl0Ms7phh2tnCSDkBkLRIThEcon5sJgz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=wx3Zg2C4; arc=none smtp.client-ip=185.246.85.4 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.b="wx3Zg2C4" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id EBEA54E42098; Mon, 12 Jan 2026 14:21:11 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C17EC606FA; Mon, 12 Jan 2026 14:21:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DFDD6103C8C61; Mon, 12 Jan 2026 15:21:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227671; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=27qw+iXgw5tUODAIs2DRLVPxR66zdH5GPz2Pg0sn2oM=; b=wx3Zg2C4KiweI+Knojw+OGPZjGWF9POGhOctyFnzT+3QY8ve4I2MFuOkJcumn94NyXNVqB lftZKZeVEkzrdas/nxs6x3gZ3XDarFBYfYQU8qZyjrCK8wq5B7HyEqSIrZvV4QGxsLbu3x XcUOlHaiJzgtmjqfuc5ahfv7MFoMMRRfK66F1FnYIyK9SSK0MgAVsY/LjQBH2DwvmQkX2h L8om/pNpBLHX4C3qq2k85Z57C1pX70sqSaSOD7VZvifqX32DGnKGhlz9bSxgLjmRuSo4iq xcp1+tPlCSzjFKF1K0LHwe6jbnjsK/Rt2L8NLD7PND96fyX3KNCrmjw9fiY5pQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 32/77] dtc-parser: Introduce last_header_flags Date: Mon, 12 Jan 2026 15:19:22 +0100 Message-ID: <20260112142009.1006236-33-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The parser needs to get header flags value in different places. It relies on the fact that the rule used to parse the dts file is always headers memreserves devicetree With that only rule to parse the file, it uses '$-1' construct to get the flags value. With the future introduction of import symbols parsing, this rule will change and the parser couldn't rely anymore on '$-1' to get flags value. Indeed, import symbols parsing will add a new optional symbol in this rule leading to two possible rules (with and without the new symbol) to parse the source file. Introduce the last_header_flags variable to explicitly keep track of flags while also being agnostic of the rule structure and use this new variable instead of '$-1'. Signed-off-by: Herve Codina --- dtc-parser.y | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index 4e46e9d..48c40e8 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -24,6 +24,8 @@ extern void yyerror(char const *s); extern struct dt_info *parser_output; extern bool treesource_error; =20 +unsigned int last_header_flags; + static bool is_ref_relative(const char *ref) { return ref[0] !=3D '/' && strchr(&ref[1], '/'); @@ -122,14 +124,17 @@ header: DT_V1 ';' { $$ =3D DTSF_V1; + last_header_flags =3D $$; } | DT_V1 ';' DT_PLUGIN ';' { $$ =3D DTSF_V1 | DTSF_PLUGIN; + last_header_flags =3D $$; } | DT_V1 ';' DT_ADDON ';' { $$ =3D DTSF_V1 | DTSF_ADDON; + last_header_flags =3D $$; } ; =20 @@ -179,12 +184,7 @@ devicetree: } | dt_ref nodedef { - /* - * We rely on the rule being always: - * versioninfo plugindecl memreserves devicetree - * so $-1 is what we want (plugindecl) - */ - if (!($-1 & DTSF_PLUGIN)) + if (!(last_header_flags & DTSF_PLUGIN)) ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); @@ -197,7 +197,7 @@ devicetree: { struct node *target =3D get_node_by_ref($1, $3); =20 - if (($-1 & DTSF_PLUGIN) && is_ref_relative($3)) + if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); =20 if (target) { @@ -209,12 +209,7 @@ devicetree: } | devicetree DT_PATH_REF nodedef { - /* - * We rely on the rule being always: - * versioninfo plugindecl memreserves devicetree - * so $-1 is what we want (plugindecl) - */ - if ($-1 & DTSF_PLUGIN) { + if (last_header_flags & DTSF_PLUGIN) { if (is_ref_relative($2)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); add_orphan_node($1, $3, $2); @@ -235,12 +230,7 @@ devicetree: if (target) { merge_nodes(target, $3); } else { - /* - * We rely on the rule being always: - * versioninfo plugindecl memreserves devicetree - * so $-1 is what we want (plugindecl) - */ - if ($-1 & DTSF_PLUGIN) + if (last_header_flags & DTSF_PLUGIN) add_orphan_node($1, $3, $2); else ERROR(&@2, "Label or path %s not found", $2); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F001535EDD5; Mon, 12 Jan 2026 14:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; cv=none; b=kaZ0iaPp+G8MgILjPpMfI3takdAJZhX7d6SIkVeW7o2OPJoJSNqXeM8L0EAo5GmxZztMtKPSK7sQpx6zdESb1NVB+3/DHSIlShz2QsrcFKlQTcwaYGix66RZaHHIr7W5Imk0NsyExA8flnSChblAqWaomzaGcLQ15QicHBnlYoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227679; c=relaxed/simple; bh=Bi2UN6iOcrDb0sdW7NV1HPaSKgyR9IH4udkDYlSAPKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lLVTlUWn01Q6fVrIWSOYZuyv8fz25cdnbYc13sPRhVriu7FQamDlxHn6zr7NDjbnl3CzPUFgVDr6lg/VCWOuho0KpuGoHKOSClNehCwg38Gp2OMVsz6eEuVdwWrEr+ECzbcn28w83m2EiBIXAjaCfUgutCCZ+/gCevUevyIyYO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=DYGix3PY; arc=none smtp.client-ip=185.246.85.4 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.b="DYGix3PY" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 7B3534E42088; Mon, 12 Jan 2026 14:21:13 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 512D1606FA; Mon, 12 Jan 2026 14:21:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 63672103C8CD8; Mon, 12 Jan 2026 15:21:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227672; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Kq9hMaP47pDN1+OYCbbks02Pwt/vwqV+S16LExKnddY=; b=DYGix3PYS2qQ6G4wgkX4iXX7a86RLmfxzzH9fEJzBTTLlBEAqzGPpVT5JBW9CyHis9BelC dRI5SLHGusDa0ul3mqXLe5QPpWICYlWp/PUTwC/b7UXPWNxkBz6NTsMZERcR5KrqehbUw5 QUR73c4d18FoJyB3XoeddPyPBl007xET+DwtZ+tNpUmkgzdZUvTBf2/R5HhV/2wOF8F0f+ CHjGhnXej9i23tprbBjZKF1xxgXBg6G+ZERzAMX+pVtFNPuENO/3vgIpaBSjdVziZinNAU XE1nWovZYMH4oZTBaUA6LA+1f9ieNE4tugeekJYV5t63PgFG5eQC9PmHBWPQVw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 33/77] dtc: Add support for /import/ dts keyword parsing Date: Mon, 12 Jan 2026 15:19:23 +0100 Message-ID: <20260112142009.1006236-34-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The /import/ dts keyword is the keyword used to define an imported symbol used by an addon device-tree. An imported symbol is not related to a specific node and it is global to a whole addon. It can be present after the header definition (and the possible memreserves definition) and before the devicetree nodes definition. If several symbols are imported, several /import/ keyword are present. The syntax used is the following: /import/ name: compatible; with: name: The name of the imported symbol compatible: a string indicating the kind of symbol is expected. This compatible string can be used when the addon is applied in order to help the symbol resolution. For instance: /import/ foo: "bar, foo"; The foo symbol is expected by the addon and should be "bar, foo" compatible. The addon uses this symbol (i.e. it references it) but it doesn't define the symbol itself. From the addon point of view, foo is an unresolved symbol and it will be resolved when the addon is applied. Add support for /import/ dts keyword. Signed-off-by: Herve Codina --- dtc-lexer.l | 6 ++++++ dtc-parser.y | 45 +++++++++++++++++++++++++++++++++++++++++++++ dtc.h | 3 +++ livetree.c | 13 +++++++++++++ 4 files changed, 67 insertions(+) diff --git a/dtc-lexer.l b/dtc-lexer.l index 90fe70e..cb616f9 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -155,6 +155,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_EXPORT; } =20 +<*>"/import/" { + DPRINT("Keyword: /import/\n"); + BEGIN_DEFAULT(); + return DT_IMPORT; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref =3D xstrdup(yytext); diff --git a/dtc-parser.y b/dtc-parser.y index 48c40e8..61ebde2 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -50,6 +50,7 @@ static bool is_ref_relative(const char *ref) struct node *nodelist; struct symbol *symbol; struct symbol *exportlist; + struct symbol *importlist; struct reserve_info *re; uint64_t integer; unsigned int flags; @@ -65,6 +66,7 @@ static bool is_ref_relative(const char *ref) %token DT_DEL_NODE %token DT_OMIT_NO_REF %token DT_EXPORT +%token DT_IMPORT %token DT_PROPNODENAME %token DT_LITERAL %token DT_CHAR_LITERAL @@ -87,6 +89,8 @@ static bool is_ref_relative(const char *ref) %type proplist %type exportdef %type exportlist +%type importdef +%type importlist %type dt_ref =20 %type devicetree @@ -118,6 +122,17 @@ sourcefile: guess_boot_cpuid($3), NULL); } + | headers memreserves importlist devicetree + { + /* + * importlist is created with chain_symbol() and so it + * is created in reverse order. Reverse it now to have + * it in correct order + */ + parser_output =3D build_dt_info($1, $2, $4, + $4 ? guess_boot_cpuid($4) : 0, + reverse_symbol($3)); + } ; =20 header: @@ -171,6 +186,36 @@ memreserve: } ; =20 +importlist: + importdef + { + $$ =3D chain_symbol($1, NULL); + } + | importlist importdef + { + $$ =3D chain_symbol($2, $1); + } + | importlist memreserve + { + ERROR(&@2, "Mem reserve must precede imports"); + YYERROR; + } + ; + +importdef: + DT_IMPORT DT_LABEL DT_STRING ';' + { + struct data d =3D $3; + + if (!(last_header_flags & DTSF_ADDON)) + ERROR(&@2, "Import symbols supported only in addon"); + + $$ =3D build_importsym($2, d.val, &@$); + free($2); + data_free($3); + } + ; + dt_ref: DT_LABEL_REF | DT_PATH_REF; =20 devicetree: diff --git a/dtc.h b/dtc.h index 796ed51..4ebe576 100644 --- a/dtc.h +++ b/dtc.h @@ -207,6 +207,7 @@ struct label { struct symbol { bool is_local; char *name; + char *compatible; char *ref; cell_t phandle; char *fullpath; @@ -287,6 +288,8 @@ struct property *reverse_properties(struct property *fi= rst); =20 struct symbol *build_exportsym(const char *name, const char *ref, cell_t p= handle, struct srcpos *srcpos); +struct symbol *build_importsym(const char *name, const char *compatible, + struct srcpos *srcpos); struct symbol *chain_symbol(struct symbol *first, struct symbol *list); struct symbol *reverse_symbol(struct symbol *list); void add_symbol(struct symbol **list, struct symbol *new); diff --git a/livetree.c b/livetree.c index 4ec9609..dac5359 100644 --- a/livetree.c +++ b/livetree.c @@ -51,6 +51,19 @@ struct symbol *build_exportsym(const char *name, const c= har *ref, cell_t phandle return new; } =20 +struct symbol *build_importsym(const char *name, const char *compatible, s= truct srcpos *srcpos) +{ + struct symbol *new =3D xmalloc(sizeof(*new)); + + memset(new, 0, sizeof(*new)); + + new->name =3D xstrdup(name); + new->compatible =3D xstrdup(compatible); + new->srcpos =3D srcpos_copy(srcpos); + + return new; +} + struct symbol *chain_symbol(struct symbol *first, struct symbol *list) { assert(first->next =3D=3D NULL); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D826735EDDC; Mon, 12 Jan 2026 14:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227678; cv=none; b=CSQQyeRjwMj3lITSgaggAwWX/QH5V4R0o3Xb4pAMgKXD39cvc8EJIhNx+EDZFUqQFja6CMEJhVdnOuFz4SIGRtcAd5rZ81wH9XURcFMQUmArAgzUi+qhvCt1x9gyc6uZ6d+3iqL27lnwCblnuWdkrSejcBipba733Z7SJeY3ilI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227678; c=relaxed/simple; bh=G6ixOon71m3vdzrrCu9liSPXb8xkcl7TAu4sMZzvB1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uRj+GyeVFFHOjTVNZ8kqj15VOHGN6OkHloLopz+aMvuAiygqcZLYxzAB8oRrfwaT22EGqhsxdrAQhll5zEUnxmmSTQip9gBZ4EpHc2GWMiRRxJhUASb3K+ouvNaBt8eRiaun7KSKHXdppbFzGjUO6HE4tR3F6r75t9pag1Pe210= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=zrsTS+Ag; arc=none smtp.client-ip=185.171.202.116 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.b="zrsTS+Ag" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 18394C2086D; Mon, 12 Jan 2026 14:20:48 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8FEF2606FA; Mon, 12 Jan 2026 14:21:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B0068103C9261; Mon, 12 Jan 2026 15:21:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227673; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Zf0RdmR6L6y/T0lQPpa2UuZniR+B2NDmmA3x0g2ZM/g=; b=zrsTS+Agg+7yIv1Qo+wcmWMx3iOIpi+qfAjA7cogl509mvyDVeZuTGv2DfQ6olYuz0RLsg PpMmYTyRAi9x7W7HmSTSR8Jtf762J8djzNchbyAqrRchZeIzmzCbXJ4+/95YfcIdN+H1KT W/zL7Cppf0Pklx5EIO45cHaFoH+6pD/t8lM6D0TUcPkCeYXzz+EMBJ/JrlDUUqClMuSfqr KlCWYgKTnrFmh8Z//LJIRT5rQWNgLuQ0gKWtIERlNooThwSya1H66PjnnX0Y4GVdvuKRnx 5YRzCMZwwoYfPucNsaQ1HyZ7YQFG+RZP4/aDByVO3sJ9tPcYZhk+t/k88roMow== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 34/77] dtc: Add import symbols (/import/ keyword) in generated dts file Date: Mon, 12 Jan 2026 15:19:24 +0100 Message-ID: <20260112142009.1006236-35-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The import symbols (/import/ keyword) parsing from a dts file is supported. Add the support for this keyword in the dts file generation. Signed-off-by: Herve Codina --- treesource.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/treesource.c b/treesource.c index 9effe38..04f65bb 100644 --- a/treesource.c +++ b/treesource.c @@ -381,6 +381,7 @@ static void write_tree_source_node(FILE *f, struct node= *tree, int level) void dt_to_source(FILE *f, struct dt_info *dti) { struct reserve_info *re; + struct symbol *importsym; =20 fprintf(f, "/dts-v1/;\n"); if (dti->dtsflags & DTSF_ADDON) @@ -397,5 +398,14 @@ void dt_to_source(FILE *f, struct dt_info *dti) (unsigned long long)re->size); } =20 + if (dti->importsymlist) { + for_each_symbol(dti->importsymlist, importsym) { + fprintf(f, "/import/ %s: \"%s\";\n", + importsym->name, + importsym->compatible); + } + fprintf(f, "\n"); + } + write_tree_source_node(f, dti->dt, 0); } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7474B2DECC2; Mon, 12 Jan 2026 14:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; cv=none; b=luleG9bCdcLtpirf7OB28GTrTgAu00VPn0ymJ1MRnF+b0UiTYrdB5Xu4X/G0iPEgY8qsSuXnTEO8P9smx50RkTzMydQsCwMuBI8EMZvpy1kVVjznMyKwg7dY0FkLvuX0f1wZUIASiapPm6NDQD5GU2hkJedwhEMVNP3PKNHnMzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; c=relaxed/simple; bh=ZJrs0Z3SKgZFS1A96+FV4YeboNIHPrdwFQ18c6DZA40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RqIu1WrbxBMhLEnR11DQ8/Wd4v8KHalt2sZksysw5jGJBIb+YO96KwE84YoHSnT/k85PjcmwsFmUiTYcIJEK7xFtzUM80QudNFSUqnKqFK13m9H4KnCGikuyVByt13wdIVrwgLkA7w3pGHUVJ56h9HOeY1SxUN9xDqWsXC2E6VE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=lpNYi9Rn; arc=none smtp.client-ip=185.171.202.116 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.b="lpNYi9Rn" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C046AC2086E; Mon, 12 Jan 2026 14:20:49 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 43933606FA; Mon, 12 Jan 2026 14:21:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3AF87103C9262; Mon, 12 Jan 2026 15:21:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227675; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=I6GH7vXbKZIW9LpPDtXPJBa156zcpyu+Pq4lngBAFn4=; b=lpNYi9RnGPtiZfcIigxV6YodWnu2/5400VoE2MacVxlrkwB+/fR67mD/ZpXtKU/Krt2+9O ezv1zFbvNySFxxvDulO5JlT9bfE5W1dUBEA3rnL49AnpoRgS1YcIzHtmKkqPxS4Z9+PHRa pq2SM5WnAK3sHrcuz0SX1oEzENkPKKD3E/qdKad1RS9OmyjL0W1df7cUaLo6kypz/1heCP OHZ6PY2/PgpfFfpzTtLXopjoTAoskgvabi1yyctXlFLRWXpL25yOZcCHF1hpH9QkGCw/FF Ui8AAB+b1pcsQC4UcspZ/TvKqS04udK7kfXR3zcsHPVBnTTL/aaAaCF+UvCUAg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 35/77] Add support for FDT_IMPORT_SYM dtb tag Date: Mon, 12 Jan 2026 15:19:25 +0100 Message-ID: <20260112142009.1006236-36-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The FDT_IMPORT_SYM dtb tag is a meta-data tag defining an imported symbol. It can be present globally in an addon dtb (i.e. outside nodes definition) meaning that this symbol needs to be resolved when the dtb is applied. The tag is followed by two values and possible alignment paddings: - name (string including \0) The import symbol name. I.e. the name used to reference this imported symbol. - padding: Padding (0x00) added to have the next value aligned on 32bit. - compatible (string including \0) The compatible string that can be used for symbol resolution. This string can be an empty string if it is not relevant. - padding: Padding (0x00) added to have the next value aligned on 32bit. Example: FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' This means that 'foo1' is an imported symbol and it is 'bar,foo' compatible. This is what is encoded in the dtb when the related dts has the following imported symbol defined: /import/ foo1: "bar,foo"; If several symbols are imported, several FDT_IMPORT_SYM are present. Each of them defining one imported symbol. For instance, importing 'foo1' ("bar,foo" compatible) and 'baz1' ("bar,baz" compatible) leads to the following sequence: FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' FDT_IMPORT_SYM 'baz1' 0x00 0x00 0x00 'bar,baz' If FDT_IMPORT_SYM tags are present in the dtb, they are present after the root node definition (i.e. after the FDT_END_NODE related to the first FDT_BEGIN_NODE). Add support for this new dtb tag. Signed-off-by: Herve Codina --- fdtdump.c | 11 +++++++++ flattree.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++- libfdt/fdt.c | 28 ++++++++++++++++++++++ libfdt/fdt.h | 1 + 4 files changed, 107 insertions(+), 1 deletion(-) diff --git a/fdtdump.c b/fdtdump.c index 8baadc4..04e6e38 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -198,6 +198,17 @@ static void dump_blob(void *blob, bool debug) continue; } =20 + if (tag =3D=3D FDT_IMPORT_SYM) { + s =3D p; + p =3D PALIGN(p + strlen(s) + 1, 4); + t =3D p; + p =3D PALIGN(p + strlen(t) + 1, 4); + + printf("%*s// [FDT_IMPORT_SYM] '%s' (%s)\n", depth * shift, "", + s, t); + continue; + } + fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "",= tag); break; } diff --git a/flattree.c b/flattree.c index 47a289f..add02f0 100644 --- a/flattree.c +++ b/flattree.c @@ -50,6 +50,7 @@ struct emitter { void (*ref_phandle)(void *); void (*export_sym)(void *); void (*export_sym_ref)(void *); + void (*import_sym)(void *); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -119,6 +120,11 @@ static void bin_emit_export_sym_ref(void *e) bin_emit_cell(e, FDT_EXPORT_SYM_REF); } =20 +static void bin_emit_import_sym(void *e) +{ + bin_emit_cell(e, FDT_IMPORT_SYM); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -131,6 +137,7 @@ static struct emitter bin_emitter =3D { .ref_phandle =3D bin_emit_ref_phandle, .export_sym =3D bin_emit_export_sym, .export_sym_ref =3D bin_emit_export_sym_ref, + .import_sym =3D bin_emit_import_sym, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -274,6 +281,17 @@ static void asm_emit_export_sym_ref(void *e) asm_emit_cell(e, FDT_EXPORT_SYM_REF); } =20 +static void asm_emit_import_sym(void *e) +{ + /* + * Import symbols are an feature introduced for addons. + * Addons device-tree blob have to reason to be in the asm format. + * + * Need to be implemented if really needed. + */ + die("FDT_IMPORT_SYM not supported in asm output\n"); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -286,6 +304,7 @@ static struct emitter asm_emitter =3D { .ref_phandle =3D asm_emit_ref_phandle, .export_sym =3D asm_emit_export_sym, .export_sym =3D asm_emit_export_sym_ref, + .import_sym =3D asm_emit_import_sym, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -461,6 +480,26 @@ static void make_fdt_header(struct fdt_header *fdt, fdt->dt_flags =3D cpu_to_fdt32(dt_flags); } =20 +static void flatten_imports(struct symbol *importsymlist, struct emitter *= emit, + void *etarget, struct version_info *vi, uint32_t dt_flags) +{ + struct symbol *importsym; + + if (!(vi->flags & FTF_EXPORT_IMPORT_SYM)) + return; + + if (!(dt_flags & FDT_FLAG_ADDON) && importsymlist) + die("Only addons can have an import list\n"); + + for_each_symbol(importsymlist, importsym) { + emit->import_sym(etarget); + emit->string(etarget, importsym->name, 0); + emit->align(etarget, sizeof(cell_t)); + emit->string(etarget, importsym->compatible, 0); + emit->align(etarget, sizeof(cell_t)); + } +} + void dt_to_blob(FILE *f, struct dt_info *dti, int version) { struct version_info *vi =3D NULL; @@ -483,6 +522,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) dt_flags |=3D dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0; =20 flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi); + flatten_imports(dti->importsymlist, &bin_emitter, &dtbuf, vi, dt_flags); bin_emit_cell(&dtbuf, FDT_END); =20 reservebuf =3D flatten_reserve_list(dti->reservelist, vi); @@ -574,6 +614,9 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) const char *symprefix =3D "dt"; uint32_t dt_flags =3D 0; =20 + if (dti->importsymlist) + die("Import symbols not supported in asm format\n"); + for (i =3D 0; i < ARRAY_SIZE(version_table); i++) { if (version_table[i].version =3D=3D version) vi =3D &version_table[i]; @@ -810,6 +853,16 @@ static struct property *flat_read_property(struct inbu= f *dtbuf, return build_property(name, val, NULL); } =20 +static struct symbol *flat_read_importsym(struct inbuf *inb) +{ + const char *name; + const char *compatible; + + name =3D flat_read_string(inb); + compatible =3D flat_read_string(inb); + + return build_importsym(name, compatible, NULL); +} =20 static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb) { @@ -984,6 +1037,8 @@ struct dt_info *dt_from_blob(const char *fname) int sizeleft; struct reserve_info *reservelist; struct node *tree; + struct symbol *importsymlist =3D NULL; + struct symbol *importsym; uint32_t val; int flags =3D 0; unsigned int dtsflags =3D 0; @@ -1098,6 +1153,17 @@ struct dt_info *dt_from_blob(const char *fname) tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags); =20 val =3D flat_read_word(&dtbuf); + + if (dtsflags & DTSF_ADDON) { + if (flags & FTF_EXPORT_IMPORT_SYM) { + while (val =3D=3D FDT_IMPORT_SYM) { + importsym =3D flat_read_importsym(&dtbuf); + add_symbol(&importsymlist, importsym); + val =3D flat_read_word(&dtbuf); + } + } + } + if (val !=3D FDT_END) die("Device tree blob doesn't end with FDT_END\n"); =20 @@ -1105,5 +1171,5 @@ struct dt_info *dt_from_blob(const char *fname) =20 fclose(f); =20 - return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, NULL); + return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, importsymlist); } diff --git a/libfdt/fdt.c b/libfdt/fdt.c index febfa71..c169dd9 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -271,6 +271,23 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) return FDT_END; /* premature end */ break; =20 + case FDT_IMPORT_SYM: + /* Skip name */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + offset =3D FDT_CELLALIGN(offset); + + /* Skip compatible */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + break; + default: return FDT_END; } @@ -286,6 +303,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) { uint32_t tag, tmp_tag; int tmp_offset, tmp_next; + int is_skip_to_end =3D 0; =20 /* Retrieve next tag */ tag =3D fdt_next_tag_full(fdt, startoffset, nextoffset); @@ -300,6 +318,9 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) case FDT_END_NODE: case FDT_PROP: case FDT_NOP: + if (is_skip_to_end) + break; + case FDT_END: /* * Next tag is not a meta-data tag -> Ok this next tag @@ -320,6 +341,13 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset= , int *nextoffset) */ break; =20 + case FDT_IMPORT_SYM: + /* Those tags are available at the root level, after the + * root node -> Skip everything until FDT_END + */ + is_skip_to_end =3D 1; + break; + default: break; } diff --git a/libfdt/fdt.h b/libfdt/fdt.h index c23723b..b6c23ef 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -67,6 +67,7 @@ struct fdt_property { #define FDT_EXPORT_SYM 0xa /* export symbol: name, phandle value */ #define FDT_EXPORT_SYM_REF 0xb /* export symbol: name, phandle value (may= be unresolved), external label */ +#define FDT_IMPORT_SYM 0xc /* import symbol: name, compatible */ =20 #define FDT_V1_SIZE (7*sizeof(fdt32_t)) #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F14235F8AA; Mon, 12 Jan 2026 14:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; cv=none; b=A2mSGJUsj24oBK1vAENiP+QGvGHrtzQXkZ2WFGm5vLPxZtO/yB8BKa/NhXctAhs4fi+5QQQjOEcPOm8oAR1qjd4XEoCYlUBsTKKto5Mo1wKHtQ4ei9xKJBfGrYmujdtAyhojUIbdhJKbGBkYz3f2b6+l01WJxiNeMznecxWTjy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; c=relaxed/simple; bh=1onGMMpRznak7CbqW4TktzDUZMDIi2ZM/gqDacla/2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LrdVGh4wQEKOXfeMqn8Nqy2hlmr6UFf7QbSZ8aQAW3fQ1bMruO8NAeLmkJRaeUNGQt1xZEzZlTlwTOfKIX0bsLnAzqqQ794RFMN7IQWv7JDHtYe3ORDbkZR+LEv2cZyE74DcfhveEvxRHQ2azEiJklzQKBPTvGKSdo1sQIHFcrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kJ9xtDLP; arc=none smtp.client-ip=185.171.202.116 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.b="kJ9xtDLP" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id F2556C20868; Mon, 12 Jan 2026 14:20:50 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 735F5606FA; Mon, 12 Jan 2026 14:21:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id AC4A2103C9264; Mon, 12 Jan 2026 15:21:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227676; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ElGWPoey4Ujkb+I3lI6CjrKZLt6O/F285tA0mrtu7lo=; b=kJ9xtDLPgxWtAPzTp/FeyjTAkX/F8M7BkbuwBZaXXQZd/z3j0ZljU7GrEmtMC2w4VXqu8I Ra/6IyJkElX47fiWeZLOnE940AoqOxH2oZD3w/15an/QZYHykT8d9heV3SGgAlnpTc1mDF jigjB31zZC/bwSdcFdT3FaQFaYAfCvw3dHgyVEvpU0i+jqaoWII2i81YSBXfdL/f+PvbWK Wq38Shd4gZVpsWvIBjkQo+EUUqvGJGX0sAIsYppABZO+JCqT9uEJg6P3Pl22TNr7olwfnJ FT65X7Px5LMV4vnBPsvpJQOt3OdrjBQO2WZ5964k9iU7OVv6Z1A4dAI6bmWR9g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 36/77] tests: metadata: Add import symbols tests Date: Mon, 12 Jan 2026 15:19:26 +0100 Message-ID: <20260112142009.1006236-37-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add tests related to import symbols (FDT_IMPORT_SYM dtb tag). Signed-off-by: Herve Codina --- tests/metadata_importsyms.dtb.dts.expect | 9 +++++++++ tests/metadata_importsyms.dtb.expect | 8 ++++++++ tests/metadata_importsyms.dts | 14 ++++++++++++++ tests/metadata_importsyms.dts.dts.expect | 9 +++++++++ tests/run_tests.sh | 10 +++++----- 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 tests/metadata_importsyms.dtb.dts.expect create mode 100644 tests/metadata_importsyms.dtb.expect create mode 100644 tests/metadata_importsyms.dts create mode 100644 tests/metadata_importsyms.dts.dts.expect diff --git a/tests/metadata_importsyms.dtb.dts.expect b/tests/metadata_impo= rtsyms.dtb.dts.expect new file mode 100644 index 0000000..eabf8c7 --- /dev/null +++ b/tests/metadata_importsyms.dtb.dts.expect @@ -0,0 +1,9 @@ +/dts-v1/; +/addon/; + +/import/ base_a: "foo,bar"; +/import/ base_b: "foo,baz"; + +/ { + prop =3D <0x01>; +}; diff --git a/tests/metadata_importsyms.dtb.expect b/tests/metadata_importsy= ms.dtb.expect new file mode 100644 index 0000000..2177026 --- /dev/null +++ b/tests/metadata_importsyms.dtb.expect @@ -0,0 +1,8 @@ +/dts-v1/; +/addon/; + +/ { + prop =3D <0x00000001>; +}; +// [FDT_IMPORT_SYM] 'base_a' (foo,bar) +// [FDT_IMPORT_SYM] 'base_b' (foo,baz) diff --git a/tests/metadata_importsyms.dts b/tests/metadata_importsyms.dts new file mode 100644 index 0000000..671586d --- /dev/null +++ b/tests/metadata_importsyms.dts @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ base_a: "foo,bar"; +/import/ base_b: "foo,baz"; + +/ { + prop =3D <1>; +}; diff --git a/tests/metadata_importsyms.dts.dts.expect b/tests/metadata_impo= rtsyms.dts.dts.expect new file mode 100644 index 0000000..eabf8c7 --- /dev/null +++ b/tests/metadata_importsyms.dts.dts.expect @@ -0,0 +1,9 @@ +/dts-v1/; +/addon/; + +/import/ base_a: "foo,bar"; +/import/ base_b: "foo,baz"; + +/ { + prop =3D <0x01>; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 1973525..5368db9 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1127,20 +1127,20 @@ wrap_fdtdump () { metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ - metadata_exportsyms_ref; do + metadata_exportsyms_ref metadata_importsyms; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" base_run_test wrap_fdtdump $dt.dtb $dt.dtb.out - # Remove unneeded comments - sed -i '/^\/\/ /d' $dt.dtb.out + # Remove unneeded comments, keep comments in the form '// [xxxx' + sed -i '/^\/\/ [^\[]/d' $dt.dtb.out base_run_test check_diff $dt.dtb.out "$SRCDIR/$dt.dtb.expect" run_dtc_test -I dtb -O dts -o $dt.dtb.dts $dt.dtb base_run_test check_diff $dt.dtb.dts "$SRCDIR/$dt.dtb.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb.dts.dtb $dt.dtb.dts base_run_test wrap_fdtdump $dt.dtb.dts.dtb $dt.dtb.dts.dtb.out - # Remove unneeded comments - sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out + # Remove unneeded comments, keep comments in the form '// [xxxx' + sed -i '/^\/\/ [^\[]/d' $dt.dtb.dts.dtb.out base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect" done =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BB7D35F8DC; Mon, 12 Jan 2026 14:21:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; cv=none; b=aGyYsAct9Roqbp7jU/ofkpog9TxAJ8I/RYcXRf4I9jcIl4bWhRP2kn9TqEObzUQUESGabi3QAoIN38MO1H53i6rLgAAkfrKjWlLrdDxhhmvUakoHAz+ttW7zbT4+bao8rorrrVYtDaAj4lYu03ByE/XxCiKsTXmlSvStsQiYwjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227683; c=relaxed/simple; bh=vfKZ808QQM0nIlJRvHraS0GHeykUmrjvoLimiiF68wk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rWDMuOiDXhlgu4bbIcsuTWSc/1LLa30lCt6LJaVGbC51oZtH8KX8boZBGjBOaQn+T3/5U60qNftuVkkotFIT7p8SyMjnc/kZqt9gGbLVDBCQ2PBeEzawqQaBQIEYZWpiTOKpiMYDRgEP+mjy5LRYLW1rtQafTbVSJe4PQ9sEQQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KYCJKoRF; arc=none smtp.client-ip=185.246.84.56 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.b="KYCJKoRF" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 3E2821A2814; Mon, 12 Jan 2026 14:21:19 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 13C42606FA; Mon, 12 Jan 2026 14:21:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0D971103C9263; Mon, 12 Jan 2026 15:21:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227678; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=KEET+tHSWdPNEyFdzi+VJg0Gd+rIpUhql9YgoSlC500=; b=KYCJKoRFCyYJzRRJs7Gen6C/gWVni/dHtvUw6U6erIyS4BmWwi7QHVLkt/8nunG2qkGSvA F6HFGR/ALszt4fJqA/H/RqA1DAIzUpyC0M576VdAPdp4M5kZpqxIr2+rgVAVroJx0XZ/kA ZbqPfumMUHBVkGzzdGBcZx17vIUByRmCvAaPR5zF6INi3bVkgTHSCNLCEkBhlGO0uihZd1 2Xw2XpHLk5BNlpdrFd8GrY050FyCwXPyv1KjDsP1EOXJFxtOI/FB+DLmX4O/BnV9kTQLwb 8rmpen1NsQgx1FLYvkxfk+LzVN5BmuYwgtrO/0oDOLxbkWYhsC2imtmNErifIw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 37/77] dtc: Add support for import symbols sorting Date: Mon, 12 Jan 2026 15:19:27 +0100 Message-ID: <20260112142009.1006236-38-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc can sort items when the command line --sort option is set. Add support for import symbols sorting when this option is used. Signed-off-by: Herve Codina --- livetree.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/livetree.c b/livetree.c index dac5359..285f6e1 100644 --- a/livetree.c +++ b/livetree.c @@ -1014,9 +1014,36 @@ static void sort_node(struct node *node) sort_node(c); } =20 +static void sort_importsyms(struct dt_info *dti) +{ + int n =3D 0, i =3D 0; + struct symbol *symbol, **tbl; + + for_each_symbol(dti->importsymlist, symbol) + n++; + + if (n =3D=3D 0) + return; + + tbl =3D xmalloc(n * sizeof(*tbl)); + + for_each_symbol(dti->importsymlist, symbol) + tbl[i++] =3D symbol; + + qsort(tbl, n, sizeof(*tbl), cmp_symbol); + + dti->importsymlist =3D tbl[0]; + for (i =3D 0; i < (n-1); i++) + tbl[i]->next =3D tbl[i+1]; + tbl[n-1]->next =3D NULL; + + free(tbl); +} + void sort_tree(struct dt_info *dti) { sort_reserve_entries(dti); + sort_importsyms(dti); sort_node(dti->dt); } =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E250F35FF78 for ; Mon, 12 Jan 2026 14:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227689; cv=none; b=fnCSk2mksPhKxiPbjxGKpRW7K3QWK6FlJ0VK+oHpcDOQF7CsS9YzsN4R0bksXZR5JclMoyzdohjxG5iKgBk/hXb6PKLNipUsA80VU2eJ8Ou+cLKVf8gtDwhBw8EEVGUENDxOWHMW6UsX65BHs8LIvzVbhFXTLmYDRWf+6vAHhAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227689; c=relaxed/simple; bh=XK4Qj6dGI5I2sDXHvTeRuRbmQgbqoVznNYSvAZEruGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UlVPBcnO16Ll62owfQ/STT9cy1jSxoplcXytn4AoI9gmg7xH+ZOQ+OlF5tw2nza5Jc/tyF4tG7KEM5K/g0VgmWdmGbNM50BLo6GTIl/hwA4Sjq/4pNwNxcg8FYkwUci13a1N9nIXvZ+3jOYaj1FO+blIMz5JeVAcsOM/eVsZnZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=moT0VZQz; arc=none smtp.client-ip=185.246.85.4 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.b="moT0VZQz" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 705184E42088; Mon, 12 Jan 2026 14:21:20 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4777B606FA; Mon, 12 Jan 2026 14:21:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7F841103C9265; Mon, 12 Jan 2026 15:21:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227679; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=cMv+eZ8iw4zoGhMV/2Bi24IbtrvJT0jIrX504J92XpU=; b=moT0VZQzfgkdFfoX+lfDgOhh5TnP4T4fQBKTfYyzzRvpVlU0f46/BdEuS6Y37jW9ai+1Il Qrz80CDiHS56tdLu6d/XallPpb3EWXKTFrmzfAK6uLhJ4FTZo7YPscL0mW013dfdQ5P+o4 +62PpGXr1tnaY9PbMguOong5cVeRicEpjNOMSnBNNUX48DzDuaV3mZBMt7KbWIcEeUNJkM ht/pKy5L39NabintnXFZvr6SlhFsfKX44rCrxMFXWQ6An52fxRINBun3cJ9ZERA/HP27dr T8WWRWMubHbI9b+TaheBBFq0F4LinfTl0wwNBB3BF/I042LUh2D5uQyhP7qptw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 38/77] tests: metadata: Improve sort test to check for import symbols sorting Date: Mon, 12 Jan 2026 15:19:28 +0100 Message-ID: <20260112142009.1006236-39-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc is able to sort the import symbols list when the --sort option is used. Improve the metadata sort test to perform a check for this feature. Signed-off-by: Herve Codina --- tests/metadata_sort.dtb.dts.expect | 4 ++++ tests/metadata_sort.dtb.expect | 3 +++ tests/metadata_sort.dts | 4 ++++ tests/run_tests.sh | 4 ++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/metadata_sort.dtb.dts.expect b/tests/metadata_sort.dtb.d= ts.expect index f07a42b..270c06d 100644 --- a/tests/metadata_sort.dtb.dts.expect +++ b/tests/metadata_sort.dtb.dts.expect @@ -1,6 +1,10 @@ /dts-v1/; /addon/; =20 +/import/ abc: "foo,bar"; +/import/ de1: "foo,bar"; +/import/ de2: "foo,bar"; + / { =20 node-a { diff --git a/tests/metadata_sort.dtb.expect b/tests/metadata_sort.dtb.expect index 7856894..0dacab7 100644 --- a/tests/metadata_sort.dtb.expect +++ b/tests/metadata_sort.dtb.expect @@ -13,3 +13,6 @@ phandle =3D <0x00000001>; }; }; +// [FDT_IMPORT_SYM] 'abc' (foo,bar) +// [FDT_IMPORT_SYM] 'de1' (foo,bar) +// [FDT_IMPORT_SYM] 'de2' (foo,bar) diff --git a/tests/metadata_sort.dts b/tests/metadata_sort.dts index 7d1cca7..e523e20 100644 --- a/tests/metadata_sort.dts +++ b/tests/metadata_sort.dts @@ -6,6 +6,10 @@ /dts-v1/; /addon/; =20 +/import/ de1: "foo,bar"; +/import/ abc: "foo,bar"; +/import/ de2: "foo,bar"; + / { node_b: node-b { }; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 5368db9..a5e31df 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1158,8 +1158,8 @@ metadata_tests() { =20 run_dtc_test -I dts -O dtb -s -o metadata_sort.dtb "$SRCDIR/metadata_sort= .dts" base_run_test wrap_fdtdump metadata_sort.dtb metadata_sort.dtb.out - # Remove unneeded comments - sed -i '/^\/\/ /d' metadata_sort.dtb.out + # Remove unneeded comments, keep comments in the form '// [xxxx' + sed -i '/^\/\/ [^\[]/d' metadata_sort.dtb.out base_run_test check_diff metadata_sort.dtb.out "$SRCDIR/metadata_sort.dtb= .expect" run_dtc_test -I dtb -O dts -o metadata_sort.dtb.dts metadata_sort.dtb base_run_test check_diff metadata_sort.dtb.dts "$SRCDIR/metadata_sort.dtb= .dts.expect" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A82727F005 for ; Mon, 12 Jan 2026 14:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227691; cv=none; b=aqk+c8mxVTWtGnwmsKshdIRTARz88fHPAfVTJV+pSBQ86pnnEanZm4hVpM6f8faxskN7l0ggbyHy954gb1lgZS1y40Lu40Iq+5nJ/Msvf8KStw112zIggCEVVx02No9+FuCzQqC2+3YHXredRtzFpiqc+i+TApJbcbmSOWVFGoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227691; c=relaxed/simple; bh=IhtcqPPHHR+d8cgYxMu+tvtglQnsOrF4VbtnjuBnTIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t3rizZxMqCZzqzX815IERMmqWiV4476AJEcjKQHN3/Na5k4VrW21ymP3iGH4EO+/6jmvPXxxWf5ZxD2ZOYrVJULDNinsxUaUBtjIrVthmDJv/56nbAw9sZDhtXAeHTG7MKceC58MiY7DDxXIuY/aP62L4UFNjlwUOsAV3kdHKYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=rV3Hjh1S; arc=none smtp.client-ip=185.246.85.4 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.b="rV3Hjh1S" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id D640A4E42094; Mon, 12 Jan 2026 14:21:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id ABECF606FA; Mon, 12 Jan 2026 14:21:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CAD2B103C9266; Mon, 12 Jan 2026 15:21:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227680; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ZJldroz6n2K7wZV9eCfbDZE1cK13dJqn3M2idW1Xvtc=; b=rV3Hjh1S8lOAzi54BVv3DGRRBHQWcsoBK90n+Lfdmp0QeFxPx8Tu89aKmiF5sYe929blaU fJGaOQ7f9sazfylGC8SILYm00CKXGr4g7QN9uOdMbOzAdeRgFEaT8Jh09u1GjnQd0oQBx0 gkBcp76ZlUNlSl1QJzuflWmQIgDr+WAMvxnFTgcPGVdetbRQozpNi2SlWLIZRnPcDkEvMm CEHSZ5sZhsSUWq3ilKH0ZnmruAEjq/5mDNuzZDQd1qLSxBh8zEqdPNUdRhWXvs8/XqoGzo GxrI8EmKXNQSKr2cKh7tS+pTzGjmz0gc44u9mW0sluX5s5d/WZO3kL1nL6DXqg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 39/77] check: Get 'chosen' node using get_subnode() Date: Mon, 12 Jan 2026 15:19:29 +0100 Message-ID: <20260112142009.1006236-40-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" get_node_by_path() is going to be replaced by a more generic function in order to handle orphan node support for addon device-tree. The 'chosen' node is a subnode of the root node and can perfectly be retrieved using get_subnode(). In preparation of the future change related to get_node_by_path(), replace its usage to get the 'chosen' node by call to get_subnode(). The modification doesn't introduce any functional changes. Signed-off-by: Herve Codina --- checks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/checks.c b/checks.c index d1e215e..9744431 100644 --- a/checks.c +++ b/checks.c @@ -1341,8 +1341,7 @@ static void check_obsolete_chosen_interrupt_controlle= r(struct check *c, if (node !=3D dt) return; =20 - - chosen =3D get_node_by_path(dt, "/chosen"); + chosen =3D get_subnode(dt, "chosen"); if (!chosen) return; =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A92035FF4E; Mon, 12 Jan 2026 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227688; cv=none; b=dX+Drkb8/JYVopXX9EBY6MKggfSAVpmm74mXVFl4HqJifXp3OuRDFYNwe6AaQHOeKVJ6bAASUOkf9/BvfmKdMLmmHAUQSIfZEUbGzhEDA+PRNc0y4BQSmGwmhAUnNSheY+TrlcZAfoIisUQNckLYbNqRUkG7tKO2HOwJ3KNRdUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227688; c=relaxed/simple; bh=OoyS4UC/Wzp1sAwL4X8FtdLsOhjxMAp/Hu2r358yXBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rr/q3i/vOaa693nSL60Rnx6VclIx8vsAdFxbIXL4FHmX1vs2Shlual86/SHoMQlIvkyvcLVNqBjza4Rsygrjo4DbFKsH3UAQ+BtNlcVeA4EiCoH8I72SstQepNrNURzVyrbTzbMT6xCpSZ3PbCa/xxg7Y+n4ETop3zAj1hNqPgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ACc/Vk+3; arc=none smtp.client-ip=185.246.85.4 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.b="ACc/Vk+3" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 06BDE4E42099; Mon, 12 Jan 2026 14:21:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D21FF606FA; Mon, 12 Jan 2026 14:21:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 19390103C9267; Mon, 12 Jan 2026 15:21:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227682; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=cN+EDkDZwy4x05AXNz2uJNmRjetYUqQ5KbnRnubDECs=; b=ACc/Vk+3TMt/HHR1566QDs3oS3eWx6uuhbNZwxtLwagqwp2NaqT2baqRAvXGP+flNwLF5z mmETsQn/bmz5n7/ad1zkqP/x4bIjQ8k8hCQ/iAwqeuoNduudwVKzJFK2pMsEB6IC4dtlIE kijPLxhnNvLBNdF9z//Xrk1NTh5CvuBKPKc0Bzx1wrfJr8CGw1vL2PpqLk8TRFu4cwRGFJ I2Tq75kiaMEQBKfvQMfggwfcS2Nik6mlPPM5vzEdy4SrO7kRWKzsqFZjrZ2G29cVtPNjG/ SVjo35vda2YkLSjJNDLoyyg9aj9MpBVz9BWJNm5HMTXgacajH41If23kjdBiAw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path() Date: Mon, 12 Jan 2026 15:19:30 +0100 Message-ID: <20260112142009.1006236-41-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_node_by_path(). dti_get_node_by_path() retrieves a node by its path like get_node_by_path() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 2 +- dtc.h | 3 ++- livetree.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/checks.c b/checks.c index 9744431..b2b1bf7 100644 --- a/checks.c +++ b/checks.c @@ -740,7 +740,7 @@ static void check_alias_paths(struct check *c, struct d= t_info *dti, =20 /* This check does not work for overlays nor addons with external paths = */ if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) && - (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) { + (!prop->val.val || !dti_get_node_by_path(dti, prop->val.val))) { FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s= )", prop->val.val); continue; diff --git a/dtc.h b/dtc.h index 4ebe576..8ba093f 100644 --- a/dtc.h +++ b/dtc.h @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tre= e, const char *label, struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); -struct node *get_node_by_path(struct node *tree, const char *path); struct node *get_node_by_label(struct node *tree, const char *label); struct node *get_node_by_phandle(struct node *tree, cell_t phandle); struct node *get_node_by_ref(struct node *tree, const char *ref); @@ -357,6 +356,8 @@ struct dt_info { const char *outname; /* filename being written to, "-" for stdout */ }; =20 +struct node *dti_get_node_by_path(struct dt_info *dti, const char *path); + /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ #define DTSF_PLUGIN 0x0002 /* /plugin/ */ diff --git a/livetree.c b/livetree.c index 285f6e1..23ba957 100644 --- a/livetree.c +++ b/livetree.c @@ -659,7 +659,7 @@ struct node *get_subnode(struct node *node, const char = *nodename) return NULL; } =20 -struct node *get_node_by_path(struct node *tree, const char *path) +static struct node *get_node_by_path(struct node *tree, const char *path) { const char *p; struct node *child; @@ -785,6 +785,19 @@ struct node *get_node_by_ref(struct node *tree, const = char *ref) return target; } =20 +struct node *dti_get_node_by_path(struct dt_info *dti, const char *path) +{ + struct node *node; + + if (dti->dt) { + node =3D get_node_by_path(dti->dt, path); + if (node) + return node; + } + + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EEB82E06E6; Mon, 12 Jan 2026 14:21:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227691; cv=none; b=XXi/BuUcwF4moL/KDFe7JQeF9Vdr7PQn3UQehg/E43RF8Xy+au0UXSPC4lfjO04C4htWlyAXJLgg6Bt2ZvSVxm2wmJhSrdm4nM25SyBUAp5M+0tMFX0oeRWESLf1QGraeNeoQEyjIPuwo6a1LFyB/BMYxMs7h9cJuiHyeOpXipk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227691; c=relaxed/simple; bh=UJOe9J058M+QPWpZkQ3InJqQgg3Eq3lRdII7sc3pcIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p56HWhcDOTU5QXVp9MA7iyaFC0mMzvg/58Q+NpHGsc8iZRV2HOnIwjoyclcgA0Kqrj5tYRXNwoVsx+fH8OCt8mbn6Z7rimmLrgktcrR0WuPLZTKdpxzKmD4sPisiZKL44ouN6Wwfh7cKtleqDYJ1911YPtDynJg7ksOQjLhcMY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=HgwDg9J0; arc=none smtp.client-ip=185.246.85.4 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.b="HgwDg9J0" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 69F164E42097; Mon, 12 Jan 2026 14:21:24 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 419AB606FA; Mon, 12 Jan 2026 14:21:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 70A06103C9268; Mon, 12 Jan 2026 15:21:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227683; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=CaiWFh7u9sbz5mmN+4mQtbyp1ymuZidFap1qL6WWEwo=; b=HgwDg9J06FLcqogIbabhjc0P0poM7pxIisEAXaTi/xCaWBTenrZgOmgqUWA+pJON97ErIK Fl2lUzn2GDe2Nj+EmbfLvjc5yBKv+nVBf6B6e1Wh/eI8F64X8flQYqGOHG4JxrngRWStmL QMG5x892evpuz0hl6zCefg3+kSdbTO0hvbNqwIMzS7gALj2okqILmfZ8e+bHwtH1Dso9ju 955rQ11u2H13Ek69vGXXDACFPMzRsZOkQGsw3fP79hjWX0m1ftNDflPQApNE6VX4Czd/XX YA0hFwuZNC685y29czQuE7dyyVyeBha+kLDKNO4945a1X+eer/pPvY8wrmDiyg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 41/77] dtc: Introduce dti_get_node_by_label() Date: Mon, 12 Jan 2026 15:19:31 +0100 Message-ID: <20260112142009.1006236-42-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_node_by_label(). dti_get_node_by_label() retrieves a node by its label like get_node_by_label() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 2 +- dtc.h | 2 +- livetree.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/checks.c b/checks.c index b2b1bf7..a76e96a 100644 --- a/checks.c +++ b/checks.c @@ -444,7 +444,7 @@ static void check_duplicate_label(struct check *c, stru= ct dt_info *dti, struct property *otherprop =3D NULL; struct marker *othermark =3D NULL; =20 - othernode =3D get_node_by_label(dt, label); + othernode =3D dti_get_node_by_label(dti, label); =20 if (!othernode) otherprop =3D get_property_by_label(dt, label, &othernode); diff --git a/dtc.h b/dtc.h index 8ba093f..3dce237 100644 --- a/dtc.h +++ b/dtc.h @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tre= e, const char *label, struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); -struct node *get_node_by_label(struct node *tree, const char *label); struct node *get_node_by_phandle(struct node *tree, cell_t phandle); struct node *get_node_by_ref(struct node *tree, const char *ref); cell_t get_node_phandle(struct node *root, struct node *node); @@ -357,6 +356,7 @@ struct dt_info { }; =20 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path); +struct node *dti_get_node_by_label(struct dt_info *dti, const char *label); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index 23ba957..771ff3d 100644 --- a/livetree.c +++ b/livetree.c @@ -685,7 +685,7 @@ static struct node *get_node_by_path(struct node *tree,= const char *path) return NULL; } =20 -struct node *get_node_by_label(struct node *tree, const char *label) +static struct node *get_node_by_label(struct node *tree, const char *label) { struct node *child, *node; struct label *l; @@ -798,6 +798,19 @@ struct node *dti_get_node_by_path(struct dt_info *dti,= const char *path) return NULL; } =20 +struct node *dti_get_node_by_label(struct dt_info *dti, const char *label) +{ + struct node *node; + + if (dti->dt) { + node =3D get_node_by_label(dti->dt, label); + if (node) + return node; + } + + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 972BF361670; Mon, 12 Jan 2026 14:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227695; cv=none; b=d2g19nOUNZwpZkazSZ0oCEXHdNW2MQIDOlWvtPEC989PMTxbXnY3BWCUSRnjKaf5cvHRlaPRSxZmOR9nvOA+ehbzcLDvunudBWA2pSelChrwSOJzwnZuquNpd6E1qIJZDzTUwkYicVzKusEKeXlOSR5A/x58Xva0u8Rqn8ey8xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227695; c=relaxed/simple; bh=rg9z+VpW6LnOy3nEU1gPmfERK+TSCIO/nbOFNd4Ncpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RzgXG98KC9DmbusVUK92z8MGeiqG68yQRLEHGssCoV03FKmkYDxgZJWCBdfQnIWkUnbEjQXrLuvr2OzsHec6UNwBZKqYcy74kd/5NrDvYCImgo0qDZOzdSNIrRcLIxbSngvoZt2k7vWN/oAYk16AWEiTbroerNqsuOMYG+Csuf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=1Rh+7SIi; arc=none smtp.client-ip=185.246.85.4 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.b="1Rh+7SIi" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id ABA054E4209A; Mon, 12 Jan 2026 14:21:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 84044606FA; Mon, 12 Jan 2026 14:21:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C6A09103C9269; Mon, 12 Jan 2026 15:21:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227684; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=mt1ukzE1WdqxEMlqc5egdvChAzbkLpTNQ+GIEG3HFTc=; b=1Rh+7SIiA5A/iRCqcvP95WMTi4N5De//C/qMw1LGN6qtLskbrgd6cArg5WEcGyK3SkNBcY nPMlBNc98PZKbxMuPgRSYAJkLOrHrsNp7n0ORoBg0lZAmAZYGeH+w0FXexqMKoEWaogEfG R1TS2Q71N/efNBVJp/ghUfU9vrb6I8Tpa1jnpZ8eT04M4uB/tvnnlmu4//gXtbsfI3SsnX F93aVKx2ZVmXTT9ggm9fj9wf+v88nVr05UKaXUkEu9/g9XMeuI0d7/hGY4jYI65gJXLZs2 rXoUkNiWgagrVy9g8H7XHT7Y6ZkscU6MOpwJYcYoSdJcau8ek5RJQVeV34b7fA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 42/77] dtc: Introduce dti_get_node_by_phandle() Date: Mon, 12 Jan 2026 15:19:32 +0100 Message-ID: <20260112142009.1006236-43-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_node_by_phandle(). dti_get_node_by_phandle() retrieves a node by its phandle value like get_node_by_phandle() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 14 +++++--------- dtc.h | 2 +- livetree.c | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/checks.c b/checks.c index a76e96a..fd22524 100644 --- a/checks.c +++ b/checks.c @@ -533,7 +533,6 @@ static cell_t check_phandle_prop(struct check *c, struc= t dt_info *dti, static void check_explicit_phandles(struct check *c, struct dt_info *dti, struct node *node) { - struct node *root =3D dti->dt; struct node *other; cell_t phandle, linux_phandle; =20 @@ -555,7 +554,7 @@ static void check_explicit_phandles(struct check *c, st= ruct dt_info *dti, if (linux_phandle && !phandle) phandle =3D linux_phandle; =20 - other =3D get_node_by_phandle(root, phandle); + other =3D dti_get_node_by_phandle(dti, phandle); if (other && (other !=3D node)) { FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)", phandle, other->fullpath); @@ -1414,7 +1413,6 @@ static void check_property_phandle_args(struct check = *c, struct property *prop, const struct provider *provider) { - struct node *root =3D dti->dt; unsigned int cell, cellsize =3D 0; =20 if (!is_multiple_of(prop->val.len, sizeof(cell_t))) { @@ -1457,7 +1455,7 @@ static void check_property_phandle_args(struct check = *c, cell); } =20 - provider_node =3D get_node_by_phandle(root, phandle); + provider_node =3D dti_get_node_by_phandle(dti, phandle); if (!provider_node) { FAIL_PROP(c, dti, node, prop, "Could not get phandle node for (cell %d)", @@ -1624,7 +1622,6 @@ static void check_interrupt_map(struct check *c, struct dt_info *dti, struct node *node) { - struct node *root =3D dti->dt; struct property *prop, *irq_map_prop; size_t cellsize, cell, map_cells; =20 @@ -1678,7 +1675,7 @@ static void check_interrupt_map(struct check *c, break; } =20 - provider_node =3D get_node_by_phandle(root, phandle); + provider_node =3D dti_get_node_by_phandle(dti, phandle); if (!provider_node) { FAIL_PROP(c, dti, node, irq_map_prop, "Could not get phandle(%d) node for (cell %zu)", @@ -1716,7 +1713,6 @@ static void check_interrupts_property(struct check *c, struct dt_info *dti, struct node *node) { - struct node *root =3D dti->dt; struct node *irq_node =3D NULL, *parent =3D node; struct property *irq_prop, *prop =3D NULL; cell_t irq_cells, phandle; @@ -1747,7 +1743,7 @@ static void check_interrupts_property(struct check *c, continue; } =20 - irq_node =3D get_node_by_phandle(root, phandle); + irq_node =3D dti_get_node_by_phandle(dti, phandle); if (!irq_node) { FAIL_PROP(c, dti, parent, prop, "Bad phandle"); return; @@ -1882,7 +1878,7 @@ static struct node *get_remote_endpoint(struct check = *c, struct dt_info *dti, if (!phandle_is_valid(phandle)) return NULL; =20 - node =3D get_node_by_phandle(dti->dt, phandle); + node =3D dti_get_node_by_phandle(dti, phandle); if (!node) FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid"); =20 diff --git a/dtc.h b/dtc.h index 3dce237..7d53fcb 100644 --- a/dtc.h +++ b/dtc.h @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tre= e, const char *label, struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); -struct node *get_node_by_phandle(struct node *tree, cell_t phandle); struct node *get_node_by_ref(struct node *tree, const char *ref); cell_t get_node_phandle(struct node *root, struct node *node); =20 @@ -357,6 +356,7 @@ struct dt_info { =20 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path); struct node *dti_get_node_by_label(struct dt_info *dti, const char *label); +struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index 771ff3d..a551307 100644 --- a/livetree.c +++ b/livetree.c @@ -722,7 +722,7 @@ static cell_t get_node_phandle_existing(struct node *no= de) return propval_cell(prop); } =20 -struct node *get_node_by_phandle(struct node *tree, cell_t phandle) +static struct node *get_node_by_phandle(struct node *tree, cell_t phandle) { struct node *child, *node; cell_t tree_phandle; @@ -811,6 +811,19 @@ struct node *dti_get_node_by_label(struct dt_info *dti= , const char *label) return NULL; } =20 +struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle) +{ + struct node *node; + + if (dti->dt) { + node =3D get_node_by_phandle(dti->dt, phandle); + if (node) + return node; + } + + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { @@ -1362,7 +1375,7 @@ static void update_phandles_ref_internal(struct dt_in= fo *dti, struct node *node) if (m->is_local) { phandle =3D propval_cell_n(prop, m->offset / sizeof(cell_t)); - refnode =3D get_node_by_phandle(dti->dt, phandle); + refnode =3D dti_get_node_by_phandle(dti, phandle); if (!refnode) die("Node not found for phandle 0x%"PRIx32"\n", phandle); =20 @@ -1420,7 +1433,7 @@ static void update_exports_ref_internal(struct dt_inf= o *dti, struct node *node) continue; =20 if (exportsym->is_local) { - refnode =3D get_node_by_phandle(dti->dt, exportsym->phandle); + refnode =3D dti_get_node_by_phandle(dti, exportsym->phandle); if (!refnode) die("Node not found for phandle 0x%"PRIx32"\n", exportsym->phandle); =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4351529BD80; Mon, 12 Jan 2026 14:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227690; cv=none; b=b+oYMtdyfJtAmTWGzyg/NYk7ULBqQgRxIp/ZUvsRzqkpIiLjI7CwxQbT1qhoMNsPT/GSVCyTaqU3jcqnQohHDsp8MRBn4qQJXfP9x6f0Lyvu7qWMhp7QcxrplpxwnHlSjAViK9luOuOm6TnI02/Q4IHJlyhSc7RwqxO/H2edIc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227690; c=relaxed/simple; bh=CEasET10sP+j3Sucb0CuGp5z2ogY06a0y4XR5kPsAtM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XTQPkBT/GZxZ+WImXNSmnQqa3aAf0OHpZXJraBUiaBOnB9inpzw0GypvFixdCOoW8xTYZk5YykSG3hYaxTi0+GzST4sjrrWJMyDJDxJNa3lDYo+57jN7SqUYgGDbTMmcQ0YipoVRstJdUdhtevHJSxIu0cajPemqq9OEGrsS8hE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=qr3IvNPX; arc=none smtp.client-ip=185.171.202.116 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.b="qr3IvNPX" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 921D9C20869; Mon, 12 Jan 2026 14:21:00 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 15FA9606FA; Mon, 12 Jan 2026 14:21:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2748D103C926D; Mon, 12 Jan 2026 15:21:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227686; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=qkuvUEzHxqmCDSzTmLcBGluTI+Rj6lKZ4lPg+PlL+38=; b=qr3IvNPXgRatKHsrHvQ+X7lcNyNwvcsGVOBoR5DapGl4DF8Q2tuz1caG5FfvaFcloD+AoR MttzXn5JLy9z373GCdLreYGYMiqjbvj4MqvFby/3zi44vZKh3vC7V6Rmc2K3pxu6eIcA7U 45kW5PGZVdhOaaXutel8sajWCDnr2c6rvQQuVcTPe9CfmUyyKKicWrjoi7KT07RC7kfGwa ijhke4EmAz5B+eWjycRsGCuah7QnzkB7H4mgiPgemZassXbgrjicycqn5XOetsvyD0WVId De3ef7SxwV4d7qmUNsVSFEghdsmq4LV04xRknPGBhEmgzTmlV93DryXxXFVZPA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 43/77] dtc: Introduce dti_get_node_by_ref() Date: Mon, 12 Jan 2026 15:19:33 +0100 Message-ID: <20260112142009.1006236-44-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_node_by_ref(). dti_get_node_by_ref() retrieves a node by a reference (a label or a path) like get_node_by_ref() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 10 ++++------ dtc-parser.y | 22 +++++++++++++++++----- dtc.h | 2 +- livetree.c | 19 ++++++++++++++++--- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/checks.c b/checks.c index fd22524..a47870d 100644 --- a/checks.c +++ b/checks.c @@ -486,7 +486,6 @@ ERROR(duplicate_label, check_duplicate_label_node, NULL= ); static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, struct node *node, const char *propname) { - struct node *root =3D dti->dt; struct property *prop; struct marker *m; cell_t phandle; @@ -504,7 +503,7 @@ static cell_t check_phandle_prop(struct check *c, struc= t dt_info *dti, m =3D prop->val.markers; for_each_marker_of_type(m, REF_PHANDLE) { assert(m->offset =3D=3D 0); - if (node !=3D get_node_by_ref(root, m->ref)) + if (node !=3D dti_get_node_by_ref(dti, m->ref)) /* "Set this node's phandle equal to some * other node's phandle". That's nonsensical * by construction. */ { @@ -614,7 +613,7 @@ static void fixup_phandle_references(struct check *c, s= truct dt_info *dti, for_each_marker_of_type(m, REF_PHANDLE) { assert(m->offset + sizeof(cell_t) <=3D prop->val.len); =20 - refnode =3D get_node_by_ref(dt, m->ref); + refnode =3D dti_get_node_by_ref(dti, m->ref); if (! refnode) { if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) FAIL(c, dti, node, "Reference to non-existent node or " @@ -633,7 +632,7 @@ static void fixup_phandle_references(struct check *c, s= truct dt_info *dti, } =20 for_each_symbol(node->exportsymlist, exportsym) { - refnode =3D get_node_by_ref(dt, exportsym->ref); + refnode =3D dti_get_node_by_ref(dti, exportsym->ref); if (!refnode) { if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) { FAIL(c, dti, node, @@ -657,7 +656,6 @@ ERROR(phandle_references, fixup_phandle_references, NUL= L, static void fixup_path_references(struct check *c, struct dt_info *dti, struct node *node) { - struct node *dt =3D dti->dt; struct property *prop; =20 for_each_property(node, prop) { @@ -668,7 +666,7 @@ static void fixup_path_references(struct check *c, stru= ct dt_info *dti, for_each_marker_of_type(m, REF_PATH) { assert(m->offset <=3D prop->val.len); =20 - refnode =3D get_node_by_ref(dt, m->ref); + refnode =3D dti_get_node_by_ref(dti, m->ref); if (!refnode) { FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n", m->ref); diff --git a/dtc-parser.y b/dtc-parser.y index 61ebde2..08b3642 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -31,6 +31,18 @@ static bool is_ref_relative(const char *ref) return ref[0] !=3D '/' && strchr(&ref[1], '/'); } =20 +static struct node *parser_get_node_by_ref(struct node *dt, const char *re= f) +{ + /* + * Use a temporary dt_info in order to use dti_get_node_by_ref() + */ + struct dt_info dti =3D {}; + + dti.dt =3D dt; + + return dti_get_node_by_ref(&dti, ref); +} + %} =20 %union { @@ -240,7 +252,7 @@ devicetree: } | devicetree DT_LABEL dt_ref nodedef { - struct node *target =3D get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref($1, $3); =20 if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); @@ -259,7 +271,7 @@ devicetree: ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); add_orphan_node($1, $3, $2); } else { - struct node *target =3D get_node_by_ref($1, $2); + struct node *target =3D parser_get_node_by_ref($1, $2); =20 if (target) merge_nodes(target, $3); @@ -270,7 +282,7 @@ devicetree: } | devicetree DT_LABEL_REF nodedef { - struct node *target =3D get_node_by_ref($1, $2); + struct node *target =3D parser_get_node_by_ref($1, $2); =20 if (target) { merge_nodes(target, $3); @@ -284,7 +296,7 @@ devicetree: } | devicetree DT_DEL_NODE dt_ref ';' { - struct node *target =3D get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref($1, $3); =20 if (target) delete_node(target); @@ -296,7 +308,7 @@ devicetree: } | devicetree DT_OMIT_NO_REF dt_ref ';' { - struct node *target =3D get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref($1, $3); =20 if (target) omit_node_if_unused(target); diff --git a/dtc.h b/dtc.h index 7d53fcb..832265c 100644 --- a/dtc.h +++ b/dtc.h @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tre= e, const char *label, struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); -struct node *get_node_by_ref(struct node *tree, const char *ref); cell_t get_node_phandle(struct node *root, struct node *node); =20 uint32_t guess_boot_cpuid(struct node *tree); @@ -357,6 +356,7 @@ struct dt_info { struct node *dti_get_node_by_path(struct dt_info *dti, const char *path); struct node *dti_get_node_by_label(struct dt_info *dti, const char *label); struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle); +struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index a551307..f1c7e27 100644 --- a/livetree.c +++ b/livetree.c @@ -748,7 +748,7 @@ static struct node *get_node_by_phandle(struct node *tr= ee, cell_t phandle) return NULL; } =20 -struct node *get_node_by_ref(struct node *tree, const char *ref) +static struct node *get_node_by_ref(struct node *tree, const char *ref) { struct node *target =3D tree; const char *label =3D NULL, *path =3D NULL; @@ -824,6 +824,19 @@ struct node *dti_get_node_by_phandle(struct dt_info *d= ti, cell_t phandle) return NULL; } =20 +struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref) +{ + struct node *node; + + if (dti->dt) { + node =3D get_node_by_ref(dti->dt, ref); + if (node) + return node; + } + + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { @@ -1407,7 +1420,7 @@ static void mark_local_phandles_internal(struct dt_in= fo *dti, for_each_property(node, prop) { m =3D prop->val.markers; for_each_marker_of_type(m, REF_PHANDLE) { - refnode =3D get_node_by_ref(dti->dt, m->ref); + refnode =3D dti_get_node_by_ref(dti, m->ref); if (refnode) m->is_local =3D true; } @@ -1460,7 +1473,7 @@ static void mark_local_exports_internal(struct dt_inf= o *dti, struct node *refnode; =20 for_each_symbol(node->exportsymlist, exportsym) { - refnode =3D get_node_by_ref(dti->dt, exportsym->ref); + refnode =3D dti_get_node_by_ref(dti, exportsym->ref); if (refnode) exportsym->is_local =3D true; } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96263350A29; Mon, 12 Jan 2026 14:21:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227694; cv=none; b=jKfAPUZjqUCBTNCKkHi/SCpsmdLl9a0q7Y/M/xmueJXKkXesmngFvXrBkI36IrzTAb2RFjwbAlWr3cn69Lkp0k0fIE9GxsvRCsEoFcoNi8ROceMoBtE5lXjidbFe9v5TIxtgIYfvKohqCXp5G04mlTStXaLokhhr7bPGggQwBy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227694; c=relaxed/simple; bh=LYvYKtSweDD8VHYtaGBPMKOKolrSaO9bVFl/s96npoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DFvQFiFwWgxWOw/I8FhIu6DZR8nNyfnxN8brYshETjVkJvWWIX/aO1wOj7zZJtO0+OW2gdoNBff5fkK8NbFWXvnza/HKwK/QLoF0xXNSKjUSpqBqcETQclTs8wamqOVef+lD97yQym3WQw91Psy3bvam4qQkyJ/2WkHZHuFtYPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Ay232dxN; arc=none smtp.client-ip=185.171.202.116 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.b="Ay232dxN" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id DA1CAC2086B; Mon, 12 Jan 2026 14:21:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5DE6B606FA; Mon, 12 Jan 2026 14:21:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7C4DC103C926E; Mon, 12 Jan 2026 15:21:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227687; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ZmFxIKNmxvZuWpIeOeQbNbEsravESSWH+HLcdBHzG1s=; b=Ay232dxN4+Xa/7nfYNObydLwjV+LiFR1l2HkA0dApIglWlTBFMBZkqnIrEjoypcH+PEU9R 3fTDamSrPn+zIvJcMBFxnn2pKuOd2saS7ddMWUcRqCzgP+PfUxKUWVvgc1FjoOpdM2D2tB ByPvWs2F+7cNwsFrk3GYrcGt8zZtMwi8Bhc/5J34nM7qB/3Zj+3MPzIhNOqNPNz3JZeInf teXFV+CgaCrXGZQ4NPYnRV9ShhJG/7NdF22YA4dpr3V0ccGiJQ1CBqGYBe1D+/OWFGRIfN hhht3CD2ldftBg8pK7D1vpDezTYdkfYA9l2f8LzB4WNlHyBDoQAWAlZ0DyznoQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 44/77] dtc: Introduce dti_get_node_phandle() Date: Mon, 12 Jan 2026 15:19:34 +0100 Message-ID: <20260112142009.1006236-45-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_node_phandle(). dti_get_node_phandle() get the phandle value related to a node and allocate a new value if the node doesn't have yet a phandle value. It behaves in the same way as get_node_phandle() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 5 ++--- dtc.h | 2 +- livetree.c | 7 +++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/checks.c b/checks.c index a47870d..7dd5032 100644 --- a/checks.c +++ b/checks.c @@ -601,7 +601,6 @@ ERROR(name_properties, check_name_properties, NULL, &na= me_is_string); static void fixup_phandle_references(struct check *c, struct dt_info *dti, struct node *node) { - struct node *dt =3D dti->dt; struct symbol *exportsym; struct property *prop; struct node *refnode; @@ -624,7 +623,7 @@ static void fixup_phandle_references(struct check *c, s= truct dt_info *dti, continue; } =20 - phandle =3D get_node_phandle(dt, refnode); + phandle =3D dti_get_node_phandle(dti, refnode); *((fdt32_t *)(prop->val.val + m->offset)) =3D cpu_to_fdt32(phandle); =20 reference_node(refnode); @@ -644,7 +643,7 @@ static void fixup_phandle_references(struct check *c, s= truct dt_info *dti, } =20 /* Create the phandle property for this referenced node */ - phandle =3D get_node_phandle(dt, refnode); + phandle =3D dti_get_node_phandle(dti, refnode); exportsym->phandle =3D phandle; =20 reference_node(refnode); diff --git a/dtc.h b/dtc.h index 832265c..f7b0b23 100644 --- a/dtc.h +++ b/dtc.h @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tre= e, const char *label, struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); -cell_t get_node_phandle(struct node *root, struct node *node); =20 uint32_t guess_boot_cpuid(struct node *tree); =20 @@ -357,6 +356,7 @@ struct node *dti_get_node_by_path(struct dt_info *dti, = const char *path); struct node *dti_get_node_by_label(struct dt_info *dti, const char *label); struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle); struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref); +cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index f1c7e27..a4917d1 100644 --- a/livetree.c +++ b/livetree.c @@ -853,14 +853,14 @@ static void add_phandle_property(struct node *node, add_property(node, build_property(name, d, NULL)); } =20 -cell_t get_node_phandle(struct node *root, struct node *node) +cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node) { static cell_t phandle =3D 1; /* FIXME: ick, static local */ =20 if (phandle_is_valid(node->phandle)) return node->phandle; =20 - while (get_node_by_phandle(root, phandle)) + while (dti_get_node_by_phandle(dti, phandle)) phandle++; =20 node->phandle =3D phandle; @@ -1143,7 +1143,6 @@ static void generate_label_tree_internal(struct dt_in= fo *dti, struct node *an, struct node *node, bool allocph) { - struct node *dt =3D dti->dt; struct node *c; struct property *p; struct label *l; @@ -1173,7 +1172,7 @@ static void generate_label_tree_internal(struct dt_in= fo *dti, =20 /* force allocation of a phandle for this node */ if (allocph) - (void)get_node_phandle(dt, node); + (void)dti_get_node_phandle(dti, node); } =20 for_each_child(node, c) --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35C92361DCC for ; Mon, 12 Jan 2026 14:21:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; cv=none; b=XJ50WXW6SCz5bCQWzBWoezDltiwyBjpvShLFptSzAQy1BJdJtD4A6ff/b5mVMVM+x+gECqb2BKzkrkUFfa90cCS1gMIceYYLD4FH0Fk8/TVPExl0+6n1X+0OlcwW8ZWhesVj9jO8oSNuAoqrlkh57L/J2qn5xSXzFxb2WAY81Ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; c=relaxed/simple; bh=J4OwbzsaGmvStRtfoi4aXlIuTe0bzd/9gdauNOCKTx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SPSEdggEp2oQx+G3Mw/BnJEiSNQ2fuZxizS99QFT805cBfgZwmM3Pf1Ei0vmyfxGfpbYrIBGh9X2TXfKjBZFKqmZZPj3xiB7r509ZQPJ/kY3bo3Y7m+mEb9z8fYnA3XS5fGHuBBjLZGh+IpepzOBErSEmDMu9By940u64F/vQ4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=1yjdFBCB; arc=none smtp.client-ip=185.246.84.56 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.b="1yjdFBCB" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id D87101A281A; Mon, 12 Jan 2026 14:21:29 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AEDDC606FA; Mon, 12 Jan 2026 14:21:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DB427103C926F; Mon, 12 Jan 2026 15:21:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227688; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=dOGFWVUqh1Cd7Jo0lpL3swxRFgTM5DRrEwAInjw1SZY=; b=1yjdFBCBnIotTLCgeD0IVWoZ8VEEtPDSC8TVGnYHPomUhlJXxFk7QTj2hcmyPF5CIAu4yh FnnPquZEp+VveLY2kKTUWBKqlKwr02ak4ZJQgUA9E4/c2fqqAtFTay0lxwkY8vyCrFaY8P 6ynhQTRfpInlSAQNOA0mfTpntzDfcVVBzNvOqVlA9zOhFxkJK92s6mujw/73TT9R2CSLUt S8jybZAvLtxk4+Xv0oQedLwBaVpnlKp7yZf/THRCTto8wTyUYV805vitIq3KNTF4IHJ13m Pu1OzW5heKNmqs8DOnX/hkC9xtgmZijvo5LcRCpp0j9lPipToHr9i8OyaOTgnw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 45/77] dtc: Introduce dti_get_property_by_label() Date: Mon, 12 Jan 2026 15:19:35 +0100 Message-ID: <20260112142009.1006236-46-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_property_by_label(). dti_get_property_by_label() retrieves a property (and the related node) by its label like get_property_by_label() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 2 +- dtc.h | 5 +++-- livetree.c | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/checks.c b/checks.c index 7dd5032..75040c0 100644 --- a/checks.c +++ b/checks.c @@ -447,7 +447,7 @@ static void check_duplicate_label(struct check *c, stru= ct dt_info *dti, othernode =3D dti_get_node_by_label(dti, label); =20 if (!othernode) - otherprop =3D get_property_by_label(dt, label, &othernode); + otherprop =3D dti_get_property_by_label(dti, label, &othernode); if (!othernode) othermark =3D get_marker_label(dt, label, &othernode, &otherprop); diff --git a/dtc.h b/dtc.h index f7b0b23..399e7fa 100644 --- a/dtc.h +++ b/dtc.h @@ -318,8 +318,6 @@ const char *get_unitname(struct node *node); struct property *get_property(struct node *node, const char *propname); cell_t propval_cell(struct property *prop); cell_t propval_cell_n(struct property *prop, unsigned int n); -struct property *get_property_by_label(struct node *tree, const char *labe= l, - struct node **node); struct marker *get_marker_label(struct node *tree, const char *label, struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); @@ -357,6 +355,9 @@ struct node *dti_get_node_by_label(struct dt_info *dti,= const char *label); struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle); struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref); cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node); +struct property *dti_get_property_by_label(struct dt_info *dti, + const char *label, + struct node **node); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index a4917d1..d023075 100644 --- a/livetree.c +++ b/livetree.c @@ -594,7 +594,7 @@ cell_t propval_cell_n(struct property *prop, unsigned i= nt n) return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n)); } =20 -struct property *get_property_by_label(struct node *tree, const char *labe= l, +static struct property *get_property_by_label(struct node *tree, const cha= r *label, struct node **node) { struct property *prop; @@ -837,6 +837,22 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, = const char *ref) return NULL; } =20 +struct property *dti_get_property_by_label(struct dt_info *dti, + const char *label, + struct node **node) +{ + struct property *property; + + if (dti->dt) { + property =3D get_property_by_label(dti->dt, label, node); + if (property) + return property; + } + + *node =3D NULL; + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A613836212E; Mon, 12 Jan 2026 14:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; cv=none; b=mQO+xnW/hELDvRdfEBT0FcLTsKEeNGxwdWuEMk7IvbBl3sCGMu73YUMG08cJCWReA4QFpHH91D7+zMeLvnzMbWVUkHGFCruXtQGzWIqCwiIhOgXUs7hORLaiJacSxumOyZFxyK6rmx51IR40j+DOxdsUKmJkMbAuTYHZNwFUB9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; c=relaxed/simple; bh=Q1Jcf8MoLeMwNAM9YXolzqu1U6JMXXZJYqA8IOX1ZGE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YFwjuh2kiH33OcK/GWYeMg0wWsoLovHea/Xblji2DGIs/jX9FjcJRxHzcgByddfCxluo5YyZ1clbz0Zmp6K7T3AJX8Wi0ZLgZucea3g9lXQAR3KsBbqTw5UOvrbXXqAxHv4Uj+m8wUaTiPPI0T+hqmXmpX5YQPGcO2BLhMdC1BI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=neW6A/ev; arc=none smtp.client-ip=185.246.84.56 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.b="neW6A/ev" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 8B3AF1A2810; Mon, 12 Jan 2026 14:21:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 61BD1606FA; Mon, 12 Jan 2026 14:21:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5211B103C8C61; Mon, 12 Jan 2026 15:21:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227690; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ApNNZkGBMsyCar9fLA5GMRRYXn3l1pTg4D1D7ZaVA8o=; b=neW6A/evWJMpR9n1IFvGrJGVsnfF7CmNz2YrSzPePAJfg1UbHd9qftI7iY+Jgawzla+C3d V8FXweDYZZY2vg8+9gfytEKoSQ62Louei20wu5p2NtXnSpUpLLXWID0Q8hfrB1KaJuHCw0 m3cidEiXwVFxoEcxeXYRiXoKWiUfxhJSsOLBKZsUb6e7hfl9svoe000GMSIMhOTlT5sfOp KM7outFF1ttwvygNrfaofAvmemQnupL2snhDKE78+Dq1QPGUuVoEkDy2YZ/bg68Rjp7Ccl hXDNGdVSFwI1kM2KfSygRSNvcAdmcuXUP4mKwmRdCwR6o5sjG5RaYuM3Qmf/cg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label() Date: Mon, 12 Jan 2026 15:19:36 +0100 Message-ID: <20260112142009.1006236-47-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_get_marker_label(). dti_get_marker_label() retrieves a marker and its related node and property based on the label value. It behaves in the same way as get_marker_label() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- checks.c | 5 ++--- dtc.h | 4 ++-- livetree.c | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/checks.c b/checks.c index 75040c0..0a855f9 100644 --- a/checks.c +++ b/checks.c @@ -439,7 +439,6 @@ static void check_duplicate_label(struct check *c, stru= ct dt_info *dti, const char *label, struct node *node, struct property *prop, struct marker *mark) { - struct node *dt =3D dti->dt; struct node *othernode =3D NULL; struct property *otherprop =3D NULL; struct marker *othermark =3D NULL; @@ -449,8 +448,8 @@ static void check_duplicate_label(struct check *c, stru= ct dt_info *dti, if (!othernode) otherprop =3D dti_get_property_by_label(dti, label, &othernode); if (!othernode) - othermark =3D get_marker_label(dt, label, &othernode, - &otherprop); + othermark =3D dti_get_marker_label(dti, label, &othernode, + &otherprop); =20 if (!othernode) return; diff --git a/dtc.h b/dtc.h index 399e7fa..d45a84c 100644 --- a/dtc.h +++ b/dtc.h @@ -318,8 +318,6 @@ const char *get_unitname(struct node *node); struct property *get_property(struct node *node, const char *propname); cell_t propval_cell(struct property *prop); cell_t propval_cell_n(struct property *prop, unsigned int n); -struct marker *get_marker_label(struct node *tree, const char *label, - struct node **node, struct property **prop); struct node *get_subnode(struct node *node, const char *nodename); =20 uint32_t guess_boot_cpuid(struct node *tree); @@ -358,6 +356,8 @@ cell_t dti_get_node_phandle(struct dt_info *dti, struct= node *node); struct property *dti_get_property_by_label(struct dt_info *dti, const char *label, struct node **node); +struct marker *dti_get_marker_label(struct dt_info *dti, const char *label, + struct node **node, struct property **prop); =20 /* DTS version flags definitions */ #define DTSF_V1 0x0001 /* /dts-v1/ */ diff --git a/livetree.c b/livetree.c index d023075..79f7b55 100644 --- a/livetree.c +++ b/livetree.c @@ -620,7 +620,7 @@ static struct property *get_property_by_label(struct no= de *tree, const char *lab return NULL; } =20 -struct marker *get_marker_label(struct node *tree, const char *label, +static struct marker *get_marker_label(struct node *tree, const char *labe= l, struct node **node, struct property **prop) { struct marker *m; @@ -853,6 +853,22 @@ struct property *dti_get_property_by_label(struct dt_i= nfo *dti, return NULL; } =20 +struct marker *dti_get_marker_label(struct dt_info *dti, const char *label, + struct node **node, struct property **prop) +{ + struct marker *marker; + + if (dti->dt) { + marker =3D get_marker_label(dti->dt, label, node, prop); + if (marker) + return marker; + } + + *prop =3D NULL; + *node =3D NULL; + return NULL; +} + static void add_phandle_property(struct node *node, const char *name, int format) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E0643624AA for ; Mon, 12 Jan 2026 14:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; cv=none; b=qOFf53Wn60e+2CkYhKAIIkRV3MV7nUkEeziQHBzjj4LE72TbIIGttvpMr8TCm0RYGq20Cm3RRnxAx96x6gWQMKnRMErHr8DT2IhdIL0byUID2cMnIE3G+eTOXIdQabVtPvjz+PJMh9ZnHuPmOjRuEvcoSdsaHI7QD4v5/QcOQmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227696; c=relaxed/simple; bh=zA9I0cK5eNnHIPe3u7Byxko5th3j/+EPsblx2R/GH+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gBjL2PGp7KYlge7GSsNDYEu4hmPFofHvEje/oxubYxLxRF+cHJZoBH/nB4u5OPpAHf0yEzQnMRanm5BYJ8GDa/44r32YHVcNVRqCL2oeD7ygzrFoiu/0aj4WzYZ23/V1W4F8Nx1QRQ4ZhLLSATlEWyeJiFNynlXXuTudL/ab/J4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=LgAx6Gh+; arc=none smtp.client-ip=185.246.85.4 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.b="LgAx6Gh+" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 1A0AA4E42094; Mon, 12 Jan 2026 14:21:33 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id E4B91606FA; Mon, 12 Jan 2026 14:21:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E861E103C8CD8; Mon, 12 Jan 2026 15:21:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227692; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=uzCy+w7Ql4bGyUjuL6W7OYetqStlfivDtS8ed9Atdc4=; b=LgAx6Gh+sb8snu+Txj4ablt1MQtpGDgACxQmQ3hHkA1PnYbtPTFYG2cl8NOyNoSnr/SfR5 YG2gkWmJFzknntuZzqvbsRAS2oZlglljBX+gp3/cMfyl94gtT1NsxEqny5ddNmiSliZ+Rg 1h8Iiga7t/l8braGcO92z5QK9hNGHQ0jj37XkVBpjVjJPZioXpgvZhOC6eftTQpvgEIqBD 6fB+DRSP0u/I8fDpSMJqILr+8b99vai0mcfwQDbgQiq5gluCdrjO4QV++rNb0di9Fpa7uc mxMmjQsWqilnGOQG7e6sQF/Xlt4s1vimfTLXYIBRuYv8wuu4gLif4oBvhfPA9Q== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 47/77] dtc: Introduce dti_fill_fullpaths() Date: Mon, 12 Jan 2026 15:19:37 +0100 Message-ID: <20260112142009.1006236-48-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be: - the classical root tree starting at the root node - trees related to orphan nodes Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree. To prepare this change, introduce and use dti_fill_fullpaths(). dti_fill_fullpaths() builds fullpaths of nodes available in a tree like fill_fullpaths() but it works at the struct dt_info level. It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced. This introduction doesn't lead to any functional changes. Signed-off-by: Herve Codina --- dtc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dtc.c b/dtc.c index e0a0b54..59f4d77 100644 --- a/dtc.c +++ b/dtc.c @@ -45,6 +45,13 @@ static void fill_fullpaths(struct node *tree, const char= *prefix) fill_fullpaths(child, tree->fullpath); } =20 +static void dti_fill_fullpaths(struct dt_info *dti) +{ + /* Fill fullpaths for the root node */ + if (dti->dt) + fill_fullpaths(dti->dt, ""); +} + /* Usage related data. */ static const char usage_synopsis[] =3D "dtc [options] "; static const char usage_short_opts[] =3D "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@= LAThv"; @@ -326,7 +333,7 @@ int main(int argc, char *argv[]) if (cmdline_boot_cpuid !=3D -1) dti->boot_cpuid_phys =3D cmdline_boot_cpuid; =20 - fill_fullpaths(dti->dt, ""); + dti_fill_fullpaths(dti); =20 /* on a plugin, generate by default */ if (dti->dtsflags & DTSF_PLUGIN) { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B34B1364040; Mon, 12 Jan 2026 14:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227699; cv=none; b=NNDtaeDuT9HM5Gpzci38bTpHs+WcReKu/wF5OjiPLyk4KWNHx3//qATER7BrUBisOCjcpUOvctLN4G1JlH+oKof4lpnOdGDdFHUiXZPMUdmIsHBrOtCQ4yBEGMmY+TJsLplLWxKiQfxYsZSlSdJ4JvO21QmsOde9E3mS6M31I0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227699; c=relaxed/simple; bh=QfKhIfkPqMqdIskblp9qTUUzND0cPzgSg1a/L3LMy2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MuHyU39ZKTe5tcLU9NV2cj9d7kqmzD9TVky087Wc2A/O1HM5qbCZI69snxWbdcRtJmSpRmi+90SmGPoC3J5KrK8eqdYFxlX07xNmzRtHF9QqOpmML03PjBO4fIyf61EGL2jn3trc6MDDwq26Qm7tlQyZMwaKU9Sir8UUoSgYMLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=mhtDuusA; arc=none smtp.client-ip=185.246.85.4 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.b="mhtDuusA" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 8A4AD4E42097; Mon, 12 Jan 2026 14:21:34 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 59FD7606FA; Mon, 12 Jan 2026 14:21:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 453CC103C9261; Mon, 12 Jan 2026 15:21:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227693; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=a+hqBPUtvnDIK2sOflevWRsdtyg1p/9U7gaK7ZbRQyU=; b=mhtDuusA6uhtrgfpTuU99EYRDEUbACmozZsv88r+Dfz7jMKqhkLm4X+CkqEgHkRwViArGO RHRT0Lvknt+z8Y/JEaxYpMCe3lndK/saI30gAt+sopK+JDZh/AWhggNDSTI2m5BQ57YFMa emNUi2U8RA6V9o0WKc/x9HjxVBm6yMngyZKy6VeW6bRGotEzcHK2REVUo3/25DeJi1B6Nk jBlVYjALlEII5Xqz1OgmoC6Ww91BtIa98edVZHLNgoE+jMX5k+IeAsnyQJNH11RXfFM65c TELnx/0q/X+Pe6Bb3+Q0S9/zINbJeCBle/r6RIFTw9VvUUi0rxQhXbVjbhUzFw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 48/77] dtc: Introduce orphan nodes Date: Mon, 12 Jan 2026 15:19:38 +0100 Message-ID: <20260112142009.1006236-49-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphans nodes can be present in plugin and addon device-trees. Those nodes are nodes without a parent. The root device-tree node is a particular orphan node and is not part of those 'orphan' nodes group. The orphan nodes group is related to nodes identified by a reference in addons or plugins device-trees. For instance, the following node can be described in addons and plugins (overlay) device-trees: --- 8< --- &foo { subnode { prop =3D <1>; }; }; --- 8< --- The foo referenced node described here has no parent. Indeed, it is not a child of the root node. This kind of node is legit in plugins and addons device-tree in order to perform modification on existing node when the plugin or addon dtb is applied. The foo referenced node is an existing node in the base tree an the subnode node is added to the foo referenced node chen the dtb is applied. Even if foo itself doesn't exists in the plugin or addon device-tree, it needs to be referenced and modifications expected need to be described (new sub-node for instance). In plugin dts, when a orphan node is parsed, the dts structure is changed and the orphan node is merged in the /fragment@n/__overlay__ node. The foo referenced node mentioned in the previous snippet is transformed to: --- 8< --- / { fragment@0 { target =3D <&foo>; __overlay__ { subnode { prop =3D <0x01>; }; }; }; __fixups__ { foo =3D "/fragment@0:target:0"; }; }; --- 8< --- With this mechanism, the orphan node itself doesn't exist anymore in resulting plugin dtb but the resulting device-tree contains meta-data mixed with pure 'device-tree' data. Addons have been introduced to avoid this kind of mixing. For addons, instead of changing the device-tree structure to add something similar to fragments and __overlay__ present in plugins, the orphan node will be present as a new dtb block and will be identified as orphan thanks to meta-data added in dtb. Modification done in this commit doesn't add functional changes but just introduce orphan nodes entry points in data structures and functions in order to prepare future changes related to parsing/generating dts and dtb files. Signed-off-by: Herve Codina --- dtc-parser.y | 4 ++-- dtc.h | 7 ++++++- flattree.c | 3 ++- fstree.c | 3 ++- livetree.c | 4 +++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index 08b3642..626a232 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -132,7 +132,7 @@ sourcefile: { parser_output =3D build_dt_info($1, $2, $3, guess_boot_cpuid($3), - NULL); + NULL, NULL); } | headers memreserves importlist devicetree { @@ -143,7 +143,7 @@ sourcefile: */ parser_output =3D build_dt_info($1, $2, $4, $4 ? guess_boot_cpuid($4) : 0, - reverse_symbol($3)); + reverse_symbol($3), NULL); } ; =20 diff --git a/dtc.h b/dtc.h index d45a84c..399beee 100644 --- a/dtc.h +++ b/dtc.h @@ -277,6 +277,9 @@ struct node { #define for_each_symbol(s0, s) \ for ((s) =3D (s0); (s); (s) =3D (s)->next) =20 +#define for_each_orphan(o0, o) \ + for ((o) =3D (o0); (o); (o) =3D (o)->next_sibling) + void add_label(struct label **labels, char *label); void delete_labels(struct label **labels); =20 @@ -345,6 +348,7 @@ struct dt_info { uint32_t boot_cpuid_phys; struct node *dt; /* the device tree */ struct symbol *importsymlist; /* Import symbol list */ + struct node *orphanlist; /* orphan nodes list */ const char *outname; /* filename being written to, "-" for stdout */ }; =20 @@ -367,7 +371,8 @@ struct marker *dti_get_marker_label(struct dt_info *dti= , const char *label, struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, struct node *tree, uint32_t boot_cpuid_phys, - struct symbol *importsymlist); + struct symbol *importsymlist, + struct node *orphanlist); void sort_tree(struct dt_info *dti); void generate_label_tree(struct dt_info *dti, const char *name, bool alloc= ph); void generate_fixups_tree(struct dt_info *dti, const char *name); diff --git a/flattree.c b/flattree.c index add02f0..412c7f8 100644 --- a/flattree.c +++ b/flattree.c @@ -1171,5 +1171,6 @@ struct dt_info *dt_from_blob(const char *fname) =20 fclose(f); =20 - return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, importsymlist); + return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, + importsymlist, NULL); } diff --git a/fstree.c b/fstree.c index a6aaf1e..2be1ffa 100644 --- a/fstree.c +++ b/fstree.c @@ -72,5 +72,6 @@ struct dt_info *dt_from_fs(const char *dirname) tree =3D read_fstree(dirname); tree =3D name_node(tree, ""); =20 - return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL); + return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL, + NULL); } diff --git a/livetree.c b/livetree.c index 79f7b55..057997a 100644 --- a/livetree.c +++ b/livetree.c @@ -545,7 +545,8 @@ struct reserve_info *add_reserve_entry(struct reserve_i= nfo *list, struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, struct node *tree, uint32_t boot_cpuid_phys, - struct symbol *importsymlist) + struct symbol *importsymlist, + struct node *orphanlist) { struct dt_info *dti; =20 @@ -555,6 +556,7 @@ struct dt_info *build_dt_info(unsigned int dtsflags, dti->dt =3D tree; dti->boot_cpuid_phys =3D boot_cpuid_phys; dti->importsymlist =3D importsymlist; + dti->orphanlist =3D orphanlist; =20 return dti; } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CB4E364036; Mon, 12 Jan 2026 14:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227699; cv=none; b=cOEw083xM1hbV/kpXhAaf9hCDiIgE+wwXqRtLDYql49e9Ap6YYMjkzCx4F/AGfjHYSrshSOF5sI+HSE4pZ198xC8Umrb0eToYtHftFAfyrxbxtzS3TZqQhzHigIgCtRBWRKbEAg4ThfxkXEjiBtqFLcr2i+QPNmHvTaRt00F7dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227699; c=relaxed/simple; bh=SpKTLYZw+7+wk09Q6+LPHx3wY4M0iZWECVL3fNbTi2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZyC24bGviF5SL5NTAP15SHuin/Jc4VlTjFyVbfR31orsBgMLj2M0Lu6gjkjNR9q9M+ZXwhhAKKsvEHvhNHInIFYsed+aZgY9Eeer0Efz/AoniYg8MfZiv9Xug8bu1QICJk2BYI0j3sKfeaa87DqNBaCuz1fC1zwkcmdfwCdlvDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=r7M72lOp; arc=none smtp.client-ip=185.171.202.116 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.b="r7M72lOp" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id BDC6BC2086B; Mon, 12 Jan 2026 14:21:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 40B4B606FA; Mon, 12 Jan 2026 14:21:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DB21B103C8C61; Mon, 12 Jan 2026 15:21:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227695; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=OIU7yMsMxh2KeC6oAXfD8LVNFfIHsbZQjQQWSDSKeoM=; b=r7M72lOpHlnFvBidwcX3AjvSXgnAS6UMbbTMRzQTialQ4PmQS989zeQnyo+tK2BlYDJekh 4e5PZ6AjlnvM8LzDi8roFHvy6gNeZsEqeTvfL7JKkVA1jqDfIhHGo1Lu8I5ncdtaVCj4my 8DdVlCOfmhTsBF/LWAxO62MWVtXU5OV7R2Svp5bTytDgniGnhhXtJLAg42eEgaXzW4pnE8 7Hkq/HxOFvxtjZfw54kwhhzHqx9IPHTVctCEeyM6m7lvfhC9N/5Ny3nKAbCGE+oTMgdO7v rIqOJv7NiDNKmpJpeELWAqln6wCpD16K5dW/YxbD1Rw/aUrOPkEDwYA3pl2poQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 49/77] dtc: Handle orphan nodes in dti_get_xxx_by_yyy() Date: Mon, 12 Jan 2026 15:19:39 +0100 Message-ID: <20260112142009.1006236-50-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes have been introduced recently. Retrieving a node, a property and/or a marker from an orphan node tree is perfectly legit. Those retrievals are performed by the dti_get_xxx_by_yyy() functions family. Update them to handle orphan nodes. Signed-off-by: Herve Codina --- livetree.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/livetree.c b/livetree.c index 057997a..fa9daff 100644 --- a/livetree.c +++ b/livetree.c @@ -789,6 +789,7 @@ static struct node *get_node_by_ref(struct node *tree, = const char *ref) =20 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path) { + struct node *orphan; struct node *node; =20 if (dti->dt) { @@ -797,11 +798,18 @@ struct node *dti_get_node_by_path(struct dt_info *dti= , const char *path) return node; } =20 + for_each_orphan(dti->orphanlist, orphan) { + node =3D get_node_by_path(orphan, path); + if (node) + return node; + } + return NULL; } =20 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label) { + struct node *orphan; struct node *node; =20 if (dti->dt) { @@ -810,11 +818,18 @@ struct node *dti_get_node_by_label(struct dt_info *dt= i, const char *label) return node; } =20 + for_each_orphan(dti->orphanlist, orphan) { + node =3D get_node_by_label(orphan, label); + if (node) + return node; + } + return NULL; } =20 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle) { + struct node *orphan; struct node *node; =20 if (dti->dt) { @@ -823,11 +838,18 @@ struct node *dti_get_node_by_phandle(struct dt_info *= dti, cell_t phandle) return node; } =20 + for_each_orphan(dti->orphanlist, orphan) { + node =3D get_node_by_phandle(orphan, phandle); + if (node) + return node; + } + return NULL; } =20 struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref) { + struct node *orphan; struct node *node; =20 if (dti->dt) { @@ -836,6 +858,12 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, = const char *ref) return node; } =20 + for_each_orphan(dti->orphanlist, orphan) { + node =3D get_node_by_ref(orphan, ref); + if (node) + return node; + } + return NULL; } =20 @@ -844,6 +872,7 @@ struct property *dti_get_property_by_label(struct dt_in= fo *dti, struct node **node) { struct property *property; + struct node *orphan; =20 if (dti->dt) { property =3D get_property_by_label(dti->dt, label, node); @@ -851,6 +880,12 @@ struct property *dti_get_property_by_label(struct dt_i= nfo *dti, return property; } =20 + for_each_orphan(dti->orphanlist, orphan) { + property =3D get_property_by_label(orphan, label, node); + if (property) + return property; + } + *node =3D NULL; return NULL; } @@ -859,6 +894,7 @@ struct marker *dti_get_marker_label(struct dt_info *dti= , const char *label, struct node **node, struct property **prop) { struct marker *marker; + struct node *orphan; =20 if (dti->dt) { marker =3D get_marker_label(dti->dt, label, node, prop); @@ -866,6 +902,12 @@ struct marker *dti_get_marker_label(struct dt_info *dt= i, const char *label, return marker; } =20 + for_each_orphan(dti->orphanlist, orphan) { + marker =3D get_marker_label(orphan, label, node, prop); + if (marker) + return marker; + } + *prop =3D NULL; *node =3D NULL; return NULL; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A21B350A29 for ; Mon, 12 Jan 2026 14:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227700; cv=none; b=Duegls77QoYokVkVbHpGu1jxES7yYP+koN4H8vPej8WlcT0OYfKVo3rWMYGWXTj/pudLcV4cAHMvZSE1fwITiezmcEseZEkUh8EuRPJUYQOyIR3B7EHiIBJdtdBb69Bf+2ORRlIR+KXTLKSk3JXQxIFCYBJtmpiZYqEf7W1plqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227700; c=relaxed/simple; bh=xntXbVBtO+nX4Yp2Qnt+pPiYDGBiY9+fP2bcPhSivOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hi8/nPLpzeKIFGJjRJ8Adxdmf5rbTu4WydgsYEYlo9VU41GX2lx+5CJsgoU46yjLslF08pCzpXWXAibR4banbVmMOrcUaLNRS+zLsoImGivaC2UU4pxzaOhG2be5DBa/QD3RPy3oiAuYKlDBdX1RSQDTLANAJhX5mg1ZaeZGjRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=HZxLyH+2; arc=none smtp.client-ip=185.171.202.116 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.b="HZxLyH+2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id CF421C20869; Mon, 12 Jan 2026 14:21:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 52332606FA; Mon, 12 Jan 2026 14:21:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 76E0B103C9260; Mon, 12 Jan 2026 15:21:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227696; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=XGMM8bs5DtdAdz+Pv3kNdr/9N9Lli16DVt2ayg+uReo=; b=HZxLyH+2BWYf5IxKEcDiANcUqFsDEY4nTa5NsjyUjyo1y7R4W5S+bGQKBXKhLf6dkutAtr 4psfZ1Q4AktmfIwvgVJ6tmsBIObV5w4NdR0Lp6UGg97b3rqsWobzpXkeOArTePoLsJXN03 Y3H8e3HOAXm3y61HpaToAwxSBjpjjt6ofVF1cVhDOkdG7dOMj/sQ+MRfP4Oi146wmJ/Tws OxW2sMHdK9Ye5F/+Ogi08eV0GCInYeWulLBql9vZKWHXSMyFOebJBJH+C7LcZl3koHTxBv hGb0EHrZhwr5UVllvuBD/dGl++IPci8kntSeciOXc+TKcDIaf0+7veVMnWSLuQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 50/77] dtc: Handle orphan nodes in mark_local_xxx() and update_xxx_ref() Date: Mon, 12 Jan 2026 15:19:40 +0100 Message-ID: <20260112142009.1006236-51-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes have been introduced recently. mark_local_phandles() and mark_local_exports() mark phandles and export symbols as local when they reference a local node (i.e. a node in the current device-tree). update_phandles_ref() and update_exports_ref() update references pointing to local nodes. Those phandles, export symbols and references can involve orphan trees. Indeed, even if an orphan node itself is not present in the current device-tree, its subnodes are fully described in the current device-tree and so, those subnodes have to be considered as local nodes. Update those functions to handle orphan nodes. Signed-off-by: Herve Codina --- livetree.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/livetree.c b/livetree.c index fa9daff..52c55be 100644 --- a/livetree.c +++ b/livetree.c @@ -1481,7 +1481,12 @@ static void update_phandles_ref_internal(struct dt_i= nfo *dti, struct node *node) =20 void update_phandles_ref(struct dt_info *dti) { + struct node *orphan; + update_phandles_ref_internal(dti, dti->dt); + + for_each_orphan(dti->orphanlist, orphan) + update_phandles_ref_internal(dti, orphan); } =20 static void mark_local_phandles_internal(struct dt_info *dti, @@ -1507,7 +1512,12 @@ static void mark_local_phandles_internal(struct dt_i= nfo *dti, =20 void mark_local_phandles(struct dt_info *dti) { + struct node *orphan; + mark_local_phandles_internal(dti, dti->dt); + + for_each_orphan(dti->orphanlist, orphan) + mark_local_phandles_internal(dti, orphan); } =20 static void update_exports_ref_internal(struct dt_info *dti, struct node *= node) @@ -1537,7 +1547,12 @@ static void update_exports_ref_internal(struct dt_in= fo *dti, struct node *node) =20 void update_exports_ref(struct dt_info *dti) { + struct node *orphan; + update_exports_ref_internal(dti, dti->dt); + + for_each_orphan(dti->orphanlist, orphan) + update_exports_ref_internal(dti, orphan); } =20 static void mark_local_exports_internal(struct dt_info *dti, @@ -1559,6 +1574,10 @@ static void mark_local_exports_internal(struct dt_in= fo *dti, =20 void mark_local_exports(struct dt_info *dti) { + struct node *orphan; + mark_local_exports_internal(dti, dti->dt); =20 + for_each_orphan(dti->orphanlist, orphan) + mark_local_exports_internal(dti, orphan); } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A13CC2E7BCC; Mon, 12 Jan 2026 14:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227704; cv=none; b=pxhzAcP8A7D7ldVYfQw74IXELhLnNY7KtFqwqpTimm6iRFMX4EKqMbOOpBZA2zxkJrzRZGMZuUBQn1dXgVIkCxI0IF+NxQFjBvMNrSJCzc3C/okJmd8lpofHEb/OvhSHnLQaRW+2mM61u2LfJbhCC/r/XARXnrBrZcq2JgnMVFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227704; c=relaxed/simple; bh=emz6BTfiZT39QJRtAInNNGDoqzeKXs1k4yodIzfFbMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lXt7cVTb6bWpQnjvY5gDlwc+I0pNbyoIHaVlbwSe3vCfaSG36ZwgLUNlIaBvEUPOlyPvEumqbtUZqqOufOi88omwhUQnAtSHWc6DDZl01s1UgnU2YztsyIvawNi5LVBxKyH0ql8qcGvekjDq4BBJ4Z9FC6BoXKWl9nTL7Z2HKf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=j2pXUTvN; arc=none smtp.client-ip=185.171.202.116 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.b="j2pXUTvN" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D782FC20868; Mon, 12 Jan 2026 14:21:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5AFBA606FA; Mon, 12 Jan 2026 14:21:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CBF7B103C8CD8; Mon, 12 Jan 2026 15:21:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227698; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=t9eg9xhAykBraJlN9d8iype3cA15Fcc1FzDy86VUk+Y=; b=j2pXUTvNwOWF/XjA0ZsrozI3E54u/80Uvc3Fkr50cdFSzyRcWBX1FH+bD8DRZ03UMGg/RV 3ctqwmb4JKc0RkVDlSWz3SI05o3GDglha87fgN9tjxLZtgH69c56q3udoZJ8sxx8mtNmuI mtVFFRwL4SmQkLvMSBQbwAnoxMbFkkVVa58rVm1gOkZu4Vyx9DF5msJsXR02Bq3yFvuR5B tJlvAkxUGqreQlVXAfbnl5P3//Yh7XPgpgHqdlptuvNC3d6dXEqe2/AEztNSO6bi/C1IvG pUx4+yw/QLzRa7TI8mqW3grLF11mp5QJVDy6F9LenS8DeHmwlzyENG9XV0UF+Q== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees Date: Mon, 12 Jan 2026 15:19:41 +0100 Message-ID: <20260112142009.1006236-52-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes have been introduced recently. The process_checks() function uses fullpath in several places and crashes due NULL pointer dereferences if fullpath is NULL. In order to have process_checks() function running without crashes with orphan trees (i.e. trees based on orphan nodes), the fullpath of node available in those orphan trees must not be NULL. Fullpath values are built by dti_fill_fullpaths(). Update it to handle fullpath in trees based on orphan nodes. Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be distinct from the root node ("/" prefix). It is worth noting that this "__orphan__/" prefix is a temporary prefix and it will be change later when support for reference by path involving nodes in orphan tree is added. Signed-off-by: Herve Codina --- dtc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dtc.c b/dtc.c index 59f4d77..5cf8f31 100644 --- a/dtc.c +++ b/dtc.c @@ -47,9 +47,14 @@ static void fill_fullpaths(struct node *tree, const char= *prefix) =20 static void dti_fill_fullpaths(struct dt_info *dti) { + struct node *orphan; + /* Fill fullpaths for the root node */ if (dti->dt) fill_fullpaths(dti->dt, ""); + + for_each_orphan(dti->orphanlist, orphan) + fill_fullpaths(orphan, "__orphan__/"); } =20 /* Usage related data. */ --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35B75366546; Mon, 12 Jan 2026 14:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227703; cv=none; b=flXeOP5YFpgCzDCoTC9hpd0c0BT8qdM8VI4ZesYHqQ29k4TycwzCStLWcRjqlBzlHKjf7w/g7D8w3PRcA2O6fa+lsQNZd+vEb5QnJNFF/2m47Sn1JPJ4MvHOWhXAQsOm1+vhBs5i4KD/KeprZIZCLR+kCbK/C9Krw59LhsrO0KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227703; c=relaxed/simple; bh=3XmB2u9U/VDfXppclgC3N/shDA+YrQfPSs8p/ZHWy/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ifcoj8tFl2CKZOcGxhQO+M7wayuF6XVpnd3L7FAAH2K5nLW3qG7DUMr62Dn5gINmc1OjdmLnFudzJd9KL5ZymND80oJtPfW110lSoyHMo39d27uSQweY1BJYJb4XeUoWeiFibq7S43165HsgyM0dG1Y6SI6KM9CMSWAfNp1zoVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kFrD/Ruf; arc=none smtp.client-ip=185.246.85.4 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.b="kFrD/Ruf" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id F0D604E42097; Mon, 12 Jan 2026 14:21:40 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C17A2606FA; Mon, 12 Jan 2026 14:21:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A63AB103C9262; Mon, 12 Jan 2026 15:21:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227699; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Y8Z8zQUeievmL1QoaB7RXDFDsCHVVHoepAC6NjzURqA=; b=kFrD/RufScajvf3u54a20+5Q+sljs5ndCGvLbkFJ9X+gGPfD0WauuGYnarPoFkJU19f13r +1D31pb1IjLTJvDpINj1cYtbTXYDG+Ud/uNvfc1e7w7aludPNjanC8Lz6br7fNT6/aGs7G ucygB3gELZWbQL8q4+l2a0W2E1bPESc7vzyrSeV/rYFwt6x5tlY+oxt4VtDN+ddzZ9hdHp eZcVmJGPmAWhvNLYkLVtjiafbMLV5V8E+tNVTmKxD5g/SnjcS1UgwSMYfHqmfJCgepBfVz PFjDHt8C7xey7X6LX/aZQ7ZGyQHyfSTxwr8lJl1QTUpTpDh/Ad+EWOAWWrDtoA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 52/77] checks: Perform checks for orphan nodes Date: Mon, 12 Jan 2026 15:19:42 +0100 Message-ID: <20260112142009.1006236-53-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes have been introduced recently. Those nodes and related trees need to be handled by the check process. Indeed, in addition to performing checks, phandles are allocated and referenced nodes are marked 'referenced' during the check process. Take into account orphan nodes in check process. Signed-off-by: Herve Codina --- checks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/checks.c b/checks.c index 0a855f9..3ed3a0c 100644 --- a/checks.c +++ b/checks.c @@ -155,6 +155,7 @@ static bool is_multiple_of(int multiple, int divisor) static bool run_check(struct check *c, struct dt_info *dti) { struct node *dt =3D dti->dt; + struct node *orphan; bool error =3D false; int i; =20 @@ -180,6 +181,9 @@ static bool run_check(struct check *c, struct dt_info *= dti) =20 check_nodes_props(c, dti, dt); =20 + for_each_orphan(dti->orphanlist, orphan) + check_nodes_props(c, dti, orphan); + if (c->status =3D=3D UNCHECKED) c->status =3D PASSED; =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4D292BDC16; Mon, 12 Jan 2026 14:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227706; cv=none; b=BpZYmsCwRAxOibtxQM4Z318ZAOuDzB1wh9zxHYZFIQ7gUE65TmQuT9QeZWMLqBYd4iTLyMhhP4CIOetUsxVySzPFtY5VA4Sl2YBrU0di6AePpH2VY5MbwZBTjq8LhOBSvb7Wn5bvw3LVtFHsFqoIEFSZ+odk15DkNvrMw0bET3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227706; c=relaxed/simple; bh=IrJPZI6VXCZCzF0YNT1D3PR1MOkanfIcfCm7fDKWAPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JeylnzR8lxolBC/yLLkdlU0Nz2iniazbgENtfbfjah2wuAN4umSAkNQjSnHcGWtCB+JDaGHNhu2dBVtPLFPidf9fanSCjigm69xldC56QVJnxkjwXkw/SNHkm83UFLNz7J8i48+eROE9tY1YrkPNZRcZw+jj6TLPSoBtaamnG/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Xp7VO5A/; arc=none smtp.client-ip=185.246.85.4 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.b="Xp7VO5A/" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 7CD8A4E4209B; Mon, 12 Jan 2026 14:21:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4FF67606FA; Mon, 12 Jan 2026 14:21:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 25DD3103C9260; Mon, 12 Jan 2026 15:21:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227701; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=j3WcZn970eu+twwPT7s+M2+clKeDIgsnBF2MtWzp4oI=; b=Xp7VO5A/3sM7dI3gTUhbrhOa3LNSxwToUVVwkESrmeBCehZ8lc8hCD2k9A5uWmL0jw5bSU d0sYwJ+D4vOpus+eZHwx1HVb1W/yEENXjcw0dhf5cSJ3EOQuWKvgvH8NeIeErvx3CUJ3rx j2CKSwyBZ4486Bm2VEvrqe6rv+O452aFjbvoBQrFEMFF+CMMycLQcSjbwc/vWeTHyW+YGY 7vbfd0OfMgnrwadxUwF/tCm/zCLrkGUhJ2lbSh4EpHwICYvEJVkXPF0J2J7NvuKVvzYeV7 Uc0aZrkWwEowS8zqRl9t85lS6sQ5J+MqAJpp/yqYY1lvhBmIylp/2Eqb9SEeKg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 53/77] dtc: Rename add_orphan_node() to plugin_add_orphan_node() Date: Mon, 12 Jan 2026 15:19:43 +0100 Message-ID: <20260112142009.1006236-54-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" add_orphan_node() is used when a orphan node is parsed in a plugin (overlay) device-tree. This function creates some device-tree nodes (/fragment@n/__overlay__) in order to merge the parsed orphan node. This is specific to plugin device-trees and cannot be used for addon device-trees. In order to clarify that add_orphan_node() is specific to plugin device-trees and to prepare the support for orphan node parsing in the addon context, rename current add_orphan_node() to plugin_add_orphan_node(). Signed-off-by: Herve Codina --- dtc-parser.y | 6 +++--- dtc.h | 3 ++- livetree.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dtc-parser.y b/dtc-parser.y index 626a232..2b5b3c4 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -245,7 +245,7 @@ devicetree: ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ =3D add_orphan_node( + $$ =3D plugin_add_orphan_node( name_node(build_node(NULL, NULL, NULL, NULL), ""), $2, $1); @@ -269,7 +269,7 @@ devicetree: if (last_header_flags & DTSF_PLUGIN) { if (is_ref_relative($2)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); - add_orphan_node($1, $3, $2); + plugin_add_orphan_node($1, $3, $2); } else { struct node *target =3D parser_get_node_by_ref($1, $2); =20 @@ -288,7 +288,7 @@ devicetree: merge_nodes(target, $3); } else { if (last_header_flags & DTSF_PLUGIN) - add_orphan_node($1, $3, $2); + plugin_add_orphan_node($1, $3, $2); else ERROR(&@2, "Label or path %s not found", $2); } diff --git a/dtc.h b/dtc.h index 399beee..e463756 100644 --- a/dtc.h +++ b/dtc.h @@ -305,7 +305,8 @@ struct node *omit_node_if_unused(struct node *node); struct node *reference_node(struct node *node); struct node *chain_node(struct node *first, struct node *list); struct node *merge_nodes(struct node *old_node, struct node *new_node); -struct node *add_orphan_node(struct node *old_node, struct node *new_node,= char *ref); +struct node *plugin_add_orphan_node(struct node *old_node, struct node *ne= w_node, + char *ref); =20 void add_property(struct node *node, struct property *prop); void delete_property_by_name(struct node *node, char *name); diff --git a/livetree.c b/livetree.c index 52c55be..a21dfc1 100644 --- a/livetree.c +++ b/livetree.c @@ -319,7 +319,8 @@ struct node *merge_nodes(struct node *old_node, struct = node *new_node) return old_node; } =20 -struct node * add_orphan_node(struct node *dt, struct node *new_node, char= *ref) +struct node *plugin_add_orphan_node(struct node *dt, struct node *new_node, + char *ref) { static unsigned int next_orphan_fragment =3D 0; struct node *node; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E443366DCE; Mon, 12 Jan 2026 14:21:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227707; cv=none; b=GMuPd0G+nkP9J4WNq2l4OOO/4Qts/PwMY5fJLhYph55lxxrUV6P+YIpLO8XalfsBWrqJvbeYPZKzNF0s6elisoXk6MO9/F9Kv2uYgrcWsN/V7UjbZm1e0AFZPZb/DpMjtLP0ZOKv85SUuKEXlBXDR+4F8Y2uUxRIH6GHvkzdUWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227707; c=relaxed/simple; bh=nOI3rdElJX0OfYxYedOT4ZqGE9M0sPh0mewGaR+LFpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QYW2oII9DYRfPvv084ydcJRBb0WMjO9BLKJcGM7IIefpRLBish5Aq3RIC5JjvVsy3H4jiz3ABAnfbHuR7GY8z4Wsm6l6r0NWouyGM2w5+b0yJx2Mc07vjN+wXy9LyifJ1eeoY4KKAgJYK3yhV60wY6ZGvM4HCp3sw9gzCyqlsVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pEKO2NKK; arc=none smtp.client-ip=185.246.84.56 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.b="pEKO2NKK" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5B73C1A2810; Mon, 12 Jan 2026 14:21:44 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2D360606FA; Mon, 12 Jan 2026 14:21:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D7698103C8C61; Mon, 12 Jan 2026 15:21:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227702; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=rO7WEJHvnMVpskykeIDKwZjuQCeVEhJb3Pw/kq0BWAs=; b=pEKO2NKKfKnhBIym+SWvFIAV68RPhAWEKKlWZY22T7mI5OaQyVzDrIq1Zfn1a0smg+6Oxc q/qrauQ4EPffEAFLuFY67HSws5Ijk5PsyCQ24eZ2FfORZoqASV9tg6ZFiArUl1cj8sqap5 l6VEW3QmCjP52KUVYEvdzaS7zMUO/8VFAWm2N7+S+Ch6HF/BUb92P+HXOnETzmkjUUOtP5 7kPtUQfEhuVdoPmVODht+NXYkitZIJ2++pL5dNWWFDIaMLgn3I4r449OCl34Bn7nOnSBbw 5Tm2EHVZSxfpKoClNjdvwRrm3tXXYEOLy2bRAwd096A+hnA5B48IHYFuHp4cWQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 54/77] dtc: Add basic support for addon orphan nodes dts parsing Date: Mon, 12 Jan 2026 15:19:44 +0100 Message-ID: <20260112142009.1006236-55-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes are nodes without a parent. The root device-tree node is a particular orphan node and is not part of those 'orphan' nodes group. The orphan nodes group is related to nodes identified by a reference in addons or plugins device-trees. For instance, int the following snippet, foo is an orphan node: --- 8< --- /addon/ &foo { subnode { prop =3D <1>; }; }; --- 8< --- The foo referenced node described has no parent. Indeed, it is not a child of the root node. This kind of node is legit in addons device-tree in order to perform modification on existing node when the addon dtb is applied. Add support for addon orphan node in dts parsing. Compared to plugin (overlay) orphan node parsing, the orphan node parsed in the addon context do not lead to any change in the device-tree structure. '/fragment@0/__overlay__' or similar kind of structure is not needed for addons. Signed-off-by: Herve Codina --- checks.c | 14 ++++++++++-- dtc-parser.y | 60 +++++++++++++++++++++++++++++++++++----------------- dtc.h | 4 ++++ livetree.c | 30 ++++++++++++++++++++++++++ treesource.c | 2 ++ 5 files changed, 89 insertions(+), 21 deletions(-) diff --git a/checks.c b/checks.c index 3ed3a0c..83a0f6e 100644 --- a/checks.c +++ b/checks.c @@ -317,7 +317,12 @@ ERROR(duplicate_property_names, check_duplicate_proper= ty_names, NULL); static void check_node_name_chars(struct check *c, struct dt_info *dti, struct node *node) { - size_t n =3D strspn(node->name, c->data); + size_t n; + + if ((dti->dtsflags & DTSF_ADDON) && node->ref) + return; /* Checking name doesn't make sense for an orphan node */ + + n =3D strspn(node->name, c->data); =20 if (n < strlen(node->name)) FAIL(c, dti, node, "Bad character '%c' in node name", @@ -328,7 +333,12 @@ ERROR(node_name_chars, check_node_name_chars, NODECHAR= S); static void check_node_name_chars_strict(struct check *c, struct dt_info *= dti, struct node *node) { - size_t n =3D strspn(node->name, c->data); + size_t n; + + if ((dti->dtsflags & DTSF_ADDON) && node->ref) + return; /* Checking name doesn't make sense for an orphan node */ + + n =3D strspn(node->name, c->data); =20 if (n < node->basenamelen) FAIL(c, dti, node, "Character '%c' not recommended in node name", diff --git a/dtc-parser.y b/dtc-parser.y index 2b5b3c4..10ca6d4 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -23,6 +23,7 @@ extern void yyerror(char const *s); =20 extern struct dt_info *parser_output; extern bool treesource_error; +extern struct node *parser_orphanlist; =20 unsigned int last_header_flags; =20 @@ -31,7 +32,8 @@ static bool is_ref_relative(const char *ref) return ref[0] !=3D '/' && strchr(&ref[1], '/'); } =20 -static struct node *parser_get_node_by_ref(struct node *dt, const char *re= f) +static struct node *parser_get_node_by_ref(struct node *dt, struct node *o= rphanlist, + const char *ref) { /* * Use a temporary dt_info in order to use dti_get_node_by_ref() @@ -39,6 +41,7 @@ static struct node *parser_get_node_by_ref(struct node *d= t, const char *ref) struct dt_info dti =3D {}; =20 dti.dt =3D dt; + dti.orphanlist =3D orphanlist; =20 return dti_get_node_by_ref(&dti, ref); } @@ -132,7 +135,7 @@ sourcefile: { parser_output =3D build_dt_info($1, $2, $3, guess_boot_cpuid($3), - NULL, NULL); + NULL, parser_orphanlist); } | headers memreserves importlist devicetree { @@ -143,7 +146,8 @@ sourcefile: */ parser_output =3D build_dt_info($1, $2, $4, $4 ? guess_boot_cpuid($4) : 0, - reverse_symbol($3), NULL); + reverse_symbol($3), + parser_orphanlist); } ; =20 @@ -241,21 +245,28 @@ devicetree: } | dt_ref nodedef { - if (!(last_header_flags & DTSF_PLUGIN)) + if (!(last_header_flags & (DTSF_PLUGIN | DTSF_ADDON))) ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ =3D plugin_add_orphan_node( - name_node(build_node(NULL, NULL, NULL, NULL), - ""), - $2, $1); + ERROR(&@2, "Label-relative reference %s not supported in plugin nor ad= don", $1); + + if (last_header_flags & DTSF_PLUGIN) { + $$ =3D plugin_add_orphan_node( + name_node(build_node(NULL, NULL, NULL, NULL), + ""), + $2, $1); + } else { + ERROR(&@2, "Orphan node %s without a root node not yet supported", $1); + YYERROR; + } } | devicetree DT_LABEL dt_ref nodedef { - struct node *target =3D parser_get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $3); =20 - if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); + if ((last_header_flags & (DTSF_PLUGIN | DTSF_ADDON)) && is_ref_relative= ($3)) + ERROR(&@2, "Label-relative reference %s not supported in plugin nor ad= don", $3); =20 if (target) { add_label(&target->labels, $2); @@ -266,12 +277,17 @@ devicetree: } | devicetree DT_PATH_REF nodedef { - if (last_header_flags & DTSF_PLUGIN) { + if (last_header_flags & (DTSF_PLUGIN | DTSF_ADDON)) { if (is_ref_relative($2)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); - plugin_add_orphan_node($1, $3, $2); + ERROR(&@2, "Label-relative reference %s not supported in plugin nor a= ddon", $2); + if(last_header_flags & DTSF_PLUGIN) + plugin_add_orphan_node($1, $3, $2); + else + addon_add_orphan_node(&parser_orphanlist, + orphan_node($3, $2)); } else { - struct node *target =3D parser_get_node_by_ref($1, $2); + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $2); =20 if (target) merge_nodes(target, $3); @@ -282,13 +298,17 @@ devicetree: } | devicetree DT_LABEL_REF nodedef { - struct node *target =3D parser_get_node_by_ref($1, $2); + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $2); =20 if (target) { merge_nodes(target, $3); } else { if (last_header_flags & DTSF_PLUGIN) plugin_add_orphan_node($1, $3, $2); + else if (last_header_flags & DTSF_ADDON) + addon_add_orphan_node(&parser_orphanlist, + orphan_node($3, $2)); else ERROR(&@2, "Label or path %s not found", $2); } @@ -296,7 +316,8 @@ devicetree: } | devicetree DT_DEL_NODE dt_ref ';' { - struct node *target =3D parser_get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $3); =20 if (target) delete_node(target); @@ -308,7 +329,8 @@ devicetree: } | devicetree DT_OMIT_NO_REF dt_ref ';' { - struct node *target =3D parser_get_node_by_ref($1, $3); + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $3); =20 if (target) omit_node_if_unused(target); diff --git a/dtc.h b/dtc.h index e463756..a3e29a6 100644 --- a/dtc.h +++ b/dtc.h @@ -250,6 +250,8 @@ struct node { const struct bus_type *bus; struct srcpos *srcpos; =20 + const char *ref; /* Use only for orphan nodes */ + bool omit_if_unused, is_referenced; }; =20 @@ -307,6 +309,8 @@ struct node *chain_node(struct node *first, struct node= *list); struct node *merge_nodes(struct node *old_node, struct node *new_node); struct node *plugin_add_orphan_node(struct node *old_node, struct node *ne= w_node, char *ref); +struct node *orphan_node(struct node *node, const char *ref); +void addon_add_orphan_node(struct node **dt_orphan, struct node *new_orpha= n); =20 void add_property(struct node *node, struct property *prop); void delete_property_by_name(struct node *node, char *name); diff --git a/livetree.c b/livetree.c index a21dfc1..eaface5 100644 --- a/livetree.c +++ b/livetree.c @@ -351,6 +351,36 @@ struct node *plugin_add_orphan_node(struct node *dt, s= truct node *new_node, return dt; } =20 +struct node *orphan_node(struct node *node, const char *ref) +{ + node->ref =3D xstrdup(ref); + + return node; +} + +void addon_add_orphan_node(struct node **dt_orphan, struct node *new_orpha= n) +{ + struct node **last_orphan; + char *name; + + /* + * For addon orphan node, the node name is set to '&reference' + * This ease the dts file generation and the usage of existing code + */ + xasprintf(&name, "&%s", new_orphan->ref); + + name_node(new_orphan, name); + free(name); + + new_orphan->next_sibling =3D NULL; + + last_orphan =3D dt_orphan; + while (*last_orphan) + last_orphan =3D &((*last_orphan)->next_sibling); + + *last_orphan =3D new_orphan; +} + struct node *chain_node(struct node *first, struct node *list) { assert(first->next_sibling =3D=3D NULL); diff --git a/treesource.c b/treesource.c index 04f65bb..77ff4fb 100644 --- a/treesource.c +++ b/treesource.c @@ -12,11 +12,13 @@ extern YYLTYPE yylloc; =20 struct dt_info *parser_output; bool treesource_error; +struct node *parser_orphanlist; =20 struct dt_info *dt_from_source(const char *fname) { parser_output =3D NULL; treesource_error =3D false; + parser_orphanlist =3D NULL; =20 srcfile_push(fname); yyin =3D current_srcfile->f; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 569D9368296; Mon, 12 Jan 2026 14:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227709; cv=none; b=lrTUv/1Vt66kZxH8PhFdoX8lwmAPWdsppUAUF+cb1ee0Z4sAv1xu75avMokDZdygfzw+hSNCNxxMPlucSBfaleONxJdRuE6QVB3myqfInb9kOmiptkdNbxQci8UnTVovhT6k2SnYei9PtoZr/dBQsTO+a22P/qvuVUNW4nNkWys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227709; c=relaxed/simple; bh=lz9hbmhTi1lTJIqpgGtEj0TQNROAWDaLCFz0UGWKBiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MowqKLaJZNmwQ2dZWR04460rvH8UFSPGoyENNWxTsxiMVm+uRSuOnReGpmIvNNGllvc2afBwMTtn2GPjh9gCTGiOYBKezhu5b1vGziv9mRwW7pMZinilaxKlX+NTITOteATTc8Fz6p1qV6RG48I3qztpGvTi98OL2LtmDBYS9QA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=j7LPoSrG; arc=none smtp.client-ip=185.246.85.4 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.b="j7LPoSrG" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 26CBD4E42094; Mon, 12 Jan 2026 14:21:47 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id EF7C0606FA; Mon, 12 Jan 2026 14:21:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 92279103C9262; Mon, 12 Jan 2026 15:21:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227704; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=F9SddU6hLYTguCqwazUzMkRNt8xyd1Alz30DMqQA3Nw=; b=j7LPoSrG+ldgzvU5S5Lr09dBwsM5Gz1uc2x3id1iBNSlkWkLvqpM9/w/Sjrr8HQCNStgFO pQXjoEjz5+twFeUYXb05BA1tQEAsk/E73OM2N7NIDqyF0bq9f+ioLyA7rAiFVZ3jA0LM7u SgMhKbbGQuY9Q/tjLBLPG4v6+a7VHnPJ1BwVEjLswPuwVujHKJJRAfpYlZypdT1eMQ1Xjd nGdOab/CCRhCJ7eAIjfPmHViFYvaJcRKt+pcpSAGaEyld4f4rB8EWbaOD6IohtY8NqK4SE BmLB2q3CvlO33yuJLm/QQywPgqWUmGmnAcVHvbPPPh2d2jOU2DVj+UKn8oHhNg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 55/77] dtc: Add orphan nodes in generated dts file Date: Mon, 12 Jan 2026 15:19:45 +0100 Message-ID: <20260112142009.1006236-56-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes parsing from an addon dts file is supported. Add the support for orphan nodes in the dts file generation. Signed-off-by: Herve Codina --- treesource.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/treesource.c b/treesource.c index 77ff4fb..bc5d847 100644 --- a/treesource.c +++ b/treesource.c @@ -384,6 +384,7 @@ void dt_to_source(FILE *f, struct dt_info *dti) { struct reserve_info *re; struct symbol *importsym; + struct node *orphan; =20 fprintf(f, "/dts-v1/;\n"); if (dti->dtsflags & DTSF_ADDON) @@ -410,4 +411,9 @@ void dt_to_source(FILE *f, struct dt_info *dti) } =20 write_tree_source_node(f, dti->dt, 0); + + for_each_orphan(dti->orphanlist, orphan) { + fprintf(f, "\n"); + write_tree_source_node(f, orphan, 0); + } } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D43136920C; Mon, 12 Jan 2026 14:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227711; cv=none; b=s0LYrU7HzTxy22dK5XhvWCq6VzS00CywD9jZ4ycdwX2GrhoEuZT6AjVEFpF7xiIlGshc3PyG43NvEqFdMEmgfrnAI7hXSQWC62bDLQItmqEjXs2zcUyDABN0jmOGc7qWhKI2SkKNfwYbShA1Al/+3rPDkyonqjzKT9HL/PicxrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227711; c=relaxed/simple; bh=ZBXmcC0Fkyrj5h9xVIfrIcc8lqyti1NkhaU/f3viA7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qk+ULeXbos56Z8GxurFQYa7wIWklgeR4lwsguZC1YY7OtCDqUJsBr0kaxp8U/X93tq321bYTEAryPvBAQHIvNsDhEeg4qyUoSmmyvhQ7pdKaAJsLBRt4AhP7wRMw1Yxpkpsbu++j8APAiAVFJNJibTboLJshyoIXSeJqHIeUSmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=zKJmG5YM; arc=none smtp.client-ip=185.171.202.116 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.b="zKJmG5YM" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 25EA0C2086B; Mon, 12 Jan 2026 14:21:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9C9B4606FA; Mon, 12 Jan 2026 14:21:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E07D0103C9260; Mon, 12 Jan 2026 15:21:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227705; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=nwWkJJw+OXSJ1Qn8+lYWU/RhooacQw/uFer9xhANjtQ=; b=zKJmG5YMdgj4qBPHkImU/5GaFOWJHSOtPBdfECaCw48XwVAEo9LpAGgKUEeRFb6xoyBLhS VGMprxxPmH8aEroBRgMriyfFvDtU+e7XaKFHLsZJsxBQxliG3x41CglHyFilxxilA45yoo HatNSIJcDLhfBGi4hErRKWZfoM9QvMOT6eeSTJnvtLAqmUne7EzgX64+fQipbD19Nk4ARU J2BN+ZavcumD+87b/xnd9EBnTIRHGduH2mEmsZNOylUw49dF43kj7YywTFFQpK9WEBKlbQ xcShli3TtnmuseYkOijiA/s7z6chEToOdECaBENMZfJSqVvOUdn1QH5RhfUd/Q== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 56/77] Add support for FDT_BEGIN_NODE_REF_SYM dtb tag Date: Mon, 12 Jan 2026 15:19:46 +0100 Message-ID: <20260112142009.1006236-57-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The FDT_BEGIN_NODE_REF dtb tag is a meta-data tag defining a referenced node. This kind of nodes can be present in addon dtbs and identifies a node external to the addon dtb but modified by the addon. For instance, if an addon adds a sub-node a node existing in the device-tree the addon is applied to, the existing node needs to be referenced by the addon dtb. This is the purpose of FDT_BEGIN_NODE_REF. This tag typically identifies what we call orphan nodes in dts. The structure of FDT_BEGIN_NODE_REF is identical to the structure of FDT_BEGIN_NODE except that the node name is not present and it is replaced by the node symbol reference needed to reference the node in the base device-tree when the addon device-tree blob is applied. The FDT_BEGIN_NODE_REF block is terminated by a FDT_END_NODE tag. The FDT_BEGIN_NODE_REF tag is followed by: - node symbol name (string including \0) The symbol name used to reference the node in the base device-tree when the addon is applied. - padding: Padding (0x00) added to have the next value aligned on 32bit. - Node structure (see FDT_BEGIN_NODE): Items provided by the addon to be merged in the referenced node when the addon is applied. - FDT_END_NODE tag Example: FDT_BEGIN_NODE_REF 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE This means that the external node referenced by 'foo1' is modified by the addon. Items to merge when the addon is applied are represented by the '...' part. This is what is encoded in the dtb when the related dts has the following orphan node: &foo1 { ... }; If several external nodes are modified by the addon (several orphan nodes described in the addon), several FDT_BEGIN_NODE_REF are present. Each of them related to an external node. For instance, having 'foo1' and 'bar1' as external nodes leads to the following sequence: FDT_BEGIN_NODE_REF 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE FDT_BEGIN_NODE_REF 'bar1' 0x00 0x00 0x00 ... FDT_END_NODE The FDT_BEGIN_NODE_REF can be present only for a top level node. Subnodes are identified by a FDT_BEGIN_NODE tag. If FDT_BEGIN_NODE_REF tags are present in the dtb, they are present after the root node definition (i.e. after the first FDT_BEGIN_NODE / FDT_END_NODE block). Add support for this new dtb tag. Signed-off-by: Herve Codina --- fdtdump.c | 11 ++++++ flattree.c | 103 ++++++++++++++++++++++++++++++++++++++++++--------- libfdt/fdt.c | 10 +++++ libfdt/fdt.h | 2 + 4 files changed, 108 insertions(+), 18 deletions(-) diff --git a/fdtdump.c b/fdtdump.c index 04e6e38..7d58e3d 100644 --- a/fdtdump.c +++ b/fdtdump.c @@ -176,6 +176,17 @@ static void dump_blob(void *blob, bool debug) continue; } =20 + if (tag =3D=3D FDT_BEGIN_NODE_REF) { + last_prop_name =3D NULL; + s =3D p; + p =3D PALIGN(p + strlen(s) + 1, 4); + + printf("%*s&%s {\n", depth * shift, "", s); + + depth++; + continue; + } + if (tag =3D=3D FDT_EXPORT_SYM) { s =3D p; p =3D PALIGN(p + strlen(s) + 1, 4); diff --git a/flattree.c b/flattree.c index 412c7f8..27f7608 100644 --- a/flattree.c +++ b/flattree.c @@ -51,6 +51,7 @@ struct emitter { void (*export_sym)(void *); void (*export_sym_ref)(void *); void (*import_sym)(void *); + void (*beginnode_ref)(void *, struct label *labels); }; =20 static void bin_emit_cell(void *e, cell_t val) @@ -125,6 +126,11 @@ static void bin_emit_import_sym(void *e) bin_emit_cell(e, FDT_IMPORT_SYM); } =20 +static void bin_emit_beginnode_ref(void *e, struct label *labels) +{ + bin_emit_cell(e, FDT_BEGIN_NODE_REF); +} + static struct emitter bin_emitter =3D { .cell =3D bin_emit_cell, .string =3D bin_emit_string, @@ -138,6 +144,7 @@ static struct emitter bin_emitter =3D { .export_sym =3D bin_emit_export_sym, .export_sym_ref =3D bin_emit_export_sym_ref, .import_sym =3D bin_emit_import_sym, + .beginnode_ref =3D bin_emit_beginnode_ref, }; =20 static void emit_label(FILE *f, const char *prefix, const char *label) @@ -292,6 +299,18 @@ static void asm_emit_import_sym(void *e) die("FDT_IMPORT_SYM not supported in asm output\n"); } =20 +static void asm_emit_beginnode_ref(void *e, struct label *labels) +{ + /* + * Orphan nodes (FDT_BEGIN_NODE_REF tags) are an feature + * introduced for addons. + * Addons device-tree blob have to reason to be in the asm format. + * + * Need to be implemented if really needed. + */ + die("FDT_BEGIN_NODE_REF not supported in asm output\n"); +} + static struct emitter asm_emitter =3D { .cell =3D asm_emit_cell, .string =3D asm_emit_string, @@ -305,6 +324,7 @@ static struct emitter asm_emitter =3D { .export_sym =3D asm_emit_export_sym, .export_sym =3D asm_emit_export_sym_ref, .import_sym =3D asm_emit_import_sym, + .beginnode_ref =3D asm_emit_beginnode_ref, }; =20 static int stringtable_insert(struct data *d, const char *str) @@ -335,13 +355,17 @@ static void flatten_tree(struct node *tree, struct em= itter *emit, if (tree->deleted) return; =20 - emit->beginnode(etarget, tree->labels); - - if (vi->flags & FTF_FULLPATH) - emit->string(etarget, tree->fullpath, 0); - else - emit->string(etarget, tree->name, 0); + if ((vi->flags & FTF_REF_XXX) && tree->ref) { + emit->beginnode_ref(etarget, tree->labels); + emit->string(etarget, tree->ref, 0); + } else { + emit->beginnode(etarget, tree->labels); =20 + if (vi->flags & FTF_FULLPATH) + emit->string(etarget, tree->fullpath, 0); + else + emit->string(etarget, tree->name, 0); + } emit->align(etarget, sizeof(cell_t)); =20 for_each_property(tree, prop) { @@ -500,6 +524,22 @@ static void flatten_imports(struct symbol *importsymli= st, struct emitter *emit, } } =20 +static void flatten_orphans(struct node *orphanlist, struct emitter *emit, + void *etarget, struct data *strbuf, + struct version_info *vi, uint32_t dt_flags) +{ + struct node *orphan; + + if (!(vi->flags & FTF_REF_XXX)) + return; + + if (!(dt_flags & FDT_FLAG_ADDON) && orphanlist) + die("Only addons can have orphan nodes\n"); + + for_each_orphan(orphanlist, orphan) + flatten_tree(orphan, emit, etarget, strbuf, vi); +} + void dt_to_blob(FILE *f, struct dt_info *dti, int version) { struct version_info *vi =3D NULL; @@ -523,6 +563,9 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) =20 flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi); flatten_imports(dti->importsymlist, &bin_emitter, &dtbuf, vi, dt_flags); + flatten_orphans(dti->orphanlist, &bin_emitter, &dtbuf, &strbuf, vi, + dt_flags); + bin_emit_cell(&dtbuf, FDT_END); =20 reservebuf =3D flatten_reserve_list(dti->reservelist, vi); @@ -616,6 +659,9 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) =20 if (dti->importsymlist) die("Import symbols not supported in asm format\n"); + if (dti->orphanlist) + die("Orphan nodes not supported in asm format\n"); + =20 for (i =3D 0; i < ARRAY_SIZE(version_table); i++) { if (version_table[i].version =3D=3D version) @@ -912,7 +958,8 @@ static const char *nodename_from_path(const char *ppath= , const char *cpath) =20 static struct node *unflatten_tree(struct inbuf *dtbuf, struct inbuf *strbuf, - const char *parent_flatname, int flags) + const char *parent_flatname, int flags, + bool is_orphan_node) { struct node *node; const char *flatname; @@ -922,14 +969,18 @@ static struct node *unflatten_tree(struct inbuf *dtbu= f, const char *str2; =20 node =3D build_node(NULL, NULL, NULL, NULL); - - flatname =3D flat_read_string(dtbuf); - - if (flags & FTF_FULLPATH) - node->name =3D xstrdup(nodename_from_path(parent_flatname, - flatname)); - else - node->name =3D xstrdup(flatname); + if (is_orphan_node) { + str =3D flat_read_string(dtbuf); + orphan_node(node, str); + flatname =3D ""; + } else { + flatname =3D flat_read_string(dtbuf); + if (flags & FTF_FULLPATH) + node->name =3D xstrdup(nodename_from_path(parent_flatname, + flatname)); + else + node->name =3D xstrdup(flatname); + } =20 do { struct symbol *exportsym; @@ -949,7 +1000,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, break; =20 case FDT_BEGIN_NODE: - child =3D unflatten_tree(dtbuf,strbuf, flatname, flags); + child =3D unflatten_tree(dtbuf, strbuf, flatname, flags, false); add_child(node, child); break; =20 @@ -1012,6 +1063,11 @@ static struct node *unflatten_tree(struct inbuf *dtb= uf, add_symbol(&node->exportsymlist, exportsym); break; =20 + case FDT_BEGIN_NODE_REF: + /* FDT_BEGIN_NODE_REF can only be at the FDT top level. */ + die("Unexpected FDT_BEGIN_NODE_REF tag\n"); + break; + default: die("Invalid opcode word %08x in device tree blob\n", val); @@ -1039,6 +1095,8 @@ struct dt_info *dt_from_blob(const char *fname) struct node *tree; struct symbol *importsymlist =3D NULL; struct symbol *importsym; + struct node *orphanlist =3D NULL; + struct node *orphan; uint32_t val; int flags =3D 0; unsigned int dtsflags =3D 0; @@ -1150,7 +1208,7 @@ struct dt_info *dt_from_blob(const char *fname) if (val !=3D FDT_BEGIN_NODE) die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%= 08x)\n", val); =20 - tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags); + tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags, false); =20 val =3D flat_read_word(&dtbuf); =20 @@ -1162,6 +1220,15 @@ struct dt_info *dt_from_blob(const char *fname) val =3D flat_read_word(&dtbuf); } } + + if (flags & FTF_REF_XXX) { + while (val =3D=3D FDT_BEGIN_NODE_REF) { + orphan =3D unflatten_tree(&dtbuf, &strbuf, "", flags, + true); + addon_add_orphan_node(&orphanlist, orphan); + val =3D flat_read_word(&dtbuf); + } + } } =20 if (val !=3D FDT_END) @@ -1172,5 +1239,5 @@ struct dt_info *dt_from_blob(const char *fname) fclose(f); =20 return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_ph= ys, - importsymlist, NULL); + importsymlist, orphanlist); } diff --git a/libfdt/fdt.c b/libfdt/fdt.c index c169dd9..dc58d2d 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -232,6 +232,15 @@ uint32_t fdt_next_tag_full(const void *fdt, int starto= ffset, int *nextoffset) return FDT_END; /* premature end */ break; =20 + case FDT_BEGIN_NODE_REF: + /* Skip ref */ + do { + p =3D fdt_offset_ptr(fdt, offset++, 1); + } while (p && (*p !=3D '\0')); + if (!can_assume(VALID_DTB) && !p) + return FDT_END; /* premature end */ + break; + case FDT_EXPORT_SYM: /* Skip name */ do { @@ -342,6 +351,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset,= int *nextoffset) break; =20 case FDT_IMPORT_SYM: + case FDT_BEGIN_NODE_REF: /* Those tags are available at the root level, after the * root node -> Skip everything until FDT_END */ diff --git a/libfdt/fdt.h b/libfdt/fdt.h index b6c23ef..8a39458 100644 --- a/libfdt/fdt.h +++ b/libfdt/fdt.h @@ -63,6 +63,8 @@ struct fdt_property { #define FDT_REF_LOCAL 0x5 /* local phandle reference: offset */ #define FDT_REF_PHANDLE 0x6 /* external phandle reference: offset, external label */ +#define FDT_BEGIN_NODE_REF 0x7 /* Same as FDT_BEGIN_NODE but with + reference instead of name */ #define FDT_END 0x9 #define FDT_EXPORT_SYM 0xa /* export symbol: name, phandle value */ #define FDT_EXPORT_SYM_REF 0xb /* export symbol: name, phandle value (may= be --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6C4E36920D; Mon, 12 Jan 2026 14:21:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227711; cv=none; b=a+iAcaMqrXGSy+aFB6s2cMXtt9UqF2bpkHCxLjjl3iqYRXPGZvsyfmeM3oqRUTdsxtEezfEVJH8T7jKC2PrwxigNNHSD/+yszQigoh6OHe9IkbT4jOlrYTEjc1We2qambOEK1pYr21WIy6lSVVR/nmlAlK4bhUZbDHYeyxSLw1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227711; c=relaxed/simple; bh=33CQC7Szuv6vQuD6MYd8I6qLlyhra2an6beTaS4rIdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbO5pPyuM9dkYxobu7pz+ctF1E1yYCfKLxTTw/ZbCERR0mJfcJyL/De7GAL7Z4UX9JSSoqnaNfZi/jylSGqFmeJd9LZih2t6LktwNr0Yb9OMu66RqcWW123nyYdWK62682O7xZT6igRYDyz6tBq9pJiPC+ywO33KCILqgEx7QrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ezbG/TrZ; arc=none smtp.client-ip=185.171.202.116 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.b="ezbG/TrZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 2504CC2086C; Mon, 12 Jan 2026 14:21:22 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9D684606FA; Mon, 12 Jan 2026 14:21:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4980A103C9263; Mon, 12 Jan 2026 15:21:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227707; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=mHHeMqCiMsa26df8ovlDZ1daSTZXRPr5pWsCtMQc3Tc=; b=ezbG/TrZhwV0hPA+c4Dp40+1cDfzL/Vs2lIvQ2ablplCHiVyPrJwPup4JQJKs6hILzTf0N 4uneonI7EyXrmrJF3lxr2h2lEmj3M1XFekxMzmNibbnMdfp3OdCxzUdQSrSBKy30Aq4VfV BWvkRV7kaE2iUZMiVXSfmsP6EQTpkrw2gczvnvqj70SoumgS1TsHAWXiJZEl3X6sGwzjxj AQCHyJpPoCKMQsBW47c1NH6vl0BK6ufKfyZEr7PFO7vA2K9gkC/bxmym6Dyp1jT7RaWKM0 Plvp5AlUnSTEQeQY8J/FNThxydSZ+AMfxEdlONPmIJpQ48YHWBlDx7jfBBaWZw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 57/77] tests: metadata: Add basic test for addon orphan nodes Date: Mon, 12 Jan 2026 15:19:47 +0100 Message-ID: <20260112142009.1006236-58-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add tests related to addon orphan nodes (FDT_BEGIN_NODE_REF dtb tag). Signed-off-by: Herve Codina --- tests/metadata_addon_orphan1.dtb.dts.expect | 16 ++++++++++++++++ tests/metadata_addon_orphan1.dtb.expect | 13 +++++++++++++ tests/metadata_addon_orphan1.dts | 19 +++++++++++++++++++ tests/metadata_addon_orphan1.dts.dts.expect | 16 ++++++++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan1.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan1.dtb.expect create mode 100644 tests/metadata_addon_orphan1.dts create mode 100644 tests/metadata_addon_orphan1.dts.dts.expect diff --git a/tests/metadata_addon_orphan1.dtb.dts.expect b/tests/metadata_a= ddon_orphan1.dtb.dts.expect new file mode 100644 index 0000000..c24a00f --- /dev/null +++ b/tests/metadata_addon_orphan1.dtb.dts.expect @@ -0,0 +1,16 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop =3D <0x01>; + }; +}; + +&base { + + addon-node { + prop =3D <0x02>; + }; +}; diff --git a/tests/metadata_addon_orphan1.dtb.expect b/tests/metadata_addon= _orphan1.dtb.expect new file mode 100644 index 0000000..7058a2e --- /dev/null +++ b/tests/metadata_addon_orphan1.dtb.expect @@ -0,0 +1,13 @@ +/dts-v1/; +/addon/; + +/ { + node-a { + prop =3D <0x00000001>; + }; +}; +&base { + addon-node { + prop =3D <0x00000002>; + }; +}; diff --git a/tests/metadata_addon_orphan1.dts b/tests/metadata_addon_orphan= 1.dts new file mode 100644 index 0000000..f20d179 --- /dev/null +++ b/tests/metadata_addon_orphan1.dts @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + node-a { + prop =3D <1>; + }; +}; + +&base { + addon-node { + prop =3D <2>; + }; +}; diff --git a/tests/metadata_addon_orphan1.dts.dts.expect b/tests/metadata_a= ddon_orphan1.dts.dts.expect new file mode 100644 index 0000000..c24a00f --- /dev/null +++ b/tests/metadata_addon_orphan1.dts.dts.expect @@ -0,0 +1,16 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop =3D <0x01>; + }; +}; + +&base { + + addon-node { + prop =3D <0x02>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index a5e31df..659b42b 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1127,7 +1127,8 @@ wrap_fdtdump () { metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ - metadata_exportsyms_ref metadata_importsyms; do + metadata_exportsyms_ref metadata_importsyms \ + metadata_addon_orphan1; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 935AD369234; Mon, 12 Jan 2026 14:21:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227713; cv=none; b=DItMfgF9kEHB6ooUhr5UV3P8Mbu2PSVjHAC0pziqn68xVLV4ZlE9tweDKClzJDBt9GIpt64X3rEfdtqnoYHZA2Xdk09WQnjXMqFnsQA7MzlHLxXuV55kSJ1dpf71FKSPJJw3pgywq2SPVaj07GslF6RSahLtRMPH3wyjFJQMThQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227713; c=relaxed/simple; bh=G0B++6o2k/AlJDsoZQtscR7WvdTA/3bbuO8/6ZEtB+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mNXyguHVGvx3Apqy+Gn4Fw6La+x7SpPM/1yxT+wSH+f2bm1jWCPBbNv+X8uKD7YJacRHNTRIrIihyiTDKExljFgkBx9V/z4tO1/dD6/wMQCBT1HQvHrfNpcuSxM6o+5kMSThnoP3D/z+aU5KDwmsy8pwWLdJlrrY0D9eZiYSLv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KiH6b5Ez; arc=none smtp.client-ip=185.246.85.4 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.b="KiH6b5Ez" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 39AAE4E4209C; Mon, 12 Jan 2026 14:21:50 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 10CF4606FA; Mon, 12 Jan 2026 14:21:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 075E0103C8CD8; Mon, 12 Jan 2026 15:21:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227709; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=vKpQaKQa5FbyWIJ4mel2ZrzrfeLGkep42cMZy8gu/kk=; b=KiH6b5EzsjbCsVowgcPkFSJBMYkTrUvsAnIGn58LuT+67Lzgb5abq6ayWyT7I6yMzxjqGo AZP9XI79nh2nS7fzzyV5BmxeydICW+HvZwGZw/ls1HzTKEDM/Wubv34HymibFq8m0EUrCW 107Kil8pySAgQ2eqKnYtekStYdLbSRJVUA4lCfLiwMQn936WQT/tT9TtFFrGDWVBTwlrun 70llz0+jNAtwLIciq1+TXDsAQpYt8c5JWPmwB5HDQqkoy28K7y5cNVrRKDnKdAnBS0EQVJ YjAbXJCA+dyNIy6LbuiMNApnalsij9E4E3j/z9l3CX/O+D5Ue5L7+J+NERtPoA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 58/77] dtc: Add support for missing root node in addon device-tree Date: Mon, 12 Jan 2026 15:19:48 +0100 Message-ID: <20260112142009.1006236-59-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Addon can have orphan nodes fully described (dts) and encoded (dtb) without the need for a root device tree. Contrary to plugin (overlay), addon doesn't need any specific root tree structure to described the orphans. Indeed, /fragment@n/__overlay__ doesn't exist for addons. Orphans are encoded in dtb using the FDT_BEGIN_NODE_REF tag without any impact on the root tree. The following snippet is fully legit for addon: --- 8< --- /addon/; &foo { subnode { prop =3D <1>; }; } --- 8< --- This snippet doesn't contains a root device tree, and the related dtb doesn't need any root device tree to encode the snippet. The root device is no more mandatory for addon. Add support for addon without a root device-tree. Signed-off-by: Herve Codina --- checks.c | 28 ++++++++++++++++++++++++++-- dtc-parser.y | 18 ++++++++++++++---- dtc.c | 36 +++++++++++++++++++++++------------- flattree.c | 42 +++++++++++++++++++++++++++++------------- livetree.c | 22 +++++++++++++++++----- treesource.c | 3 ++- 6 files changed, 111 insertions(+), 38 deletions(-) diff --git a/checks.c b/checks.c index 83a0f6e..f98f153 100644 --- a/checks.c +++ b/checks.c @@ -154,7 +154,6 @@ static bool is_multiple_of(int multiple, int divisor) =20 static bool run_check(struct check *c, struct dt_info *dti) { - struct node *dt =3D dti->dt; struct node *orphan; bool error =3D false; int i; @@ -179,7 +178,8 @@ static bool run_check(struct check *c, struct dt_info *= dti) if (c->status !=3D UNCHECKED) goto out; =20 - check_nodes_props(c, dti, dt); + if (dti->dt) + check_nodes_props(c, dti, dti->dt); =20 for_each_orphan(dti->orphanlist, orphan) check_nodes_props(c, dti, orphan); @@ -2079,6 +2079,30 @@ void process_checks(bool force, struct dt_info *dti) unsigned int i; int error =3D 0; =20 + if (!dti->dt) { + /* No root node is only allowed for addons */ + if (dti->dtsflags & DTSF_ADDON) { + if (!dti->orphanlist) { + /* + * but addons without a root node and without + * orphan nodes is really incorrect + */ + fprintf(stderr, + "ERROR: Input tree has no root or orphan nodes, aborting\n"); + exit(2); + } + } else { + fprintf(stderr, "ERROR: Input tree has no root node, aborting\n"); + exit(2); + } + } + if (!(dti->dtsflags & DTSF_ADDON)) { + if (dti->orphanlist) { + fprintf(stderr, "ERROR: Input tree has orphan nodes, aborting\n"); + exit(2); + } + } + for (i =3D 0; i < ARRAY_SIZE(check_table); i++) { struct check *c =3D check_table[i]; =20 diff --git a/dtc-parser.y b/dtc-parser.y index 10ca6d4..cf5447a 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -133,12 +133,18 @@ static struct node *parser_get_node_by_ref(struct nod= e *dt, struct node *orphanl sourcefile: headers memreserves devicetree { + if (!($1 & DTSF_ADDON) && !$3) + ERROR(&@3, "Only addon support missing root node"); + parser_output =3D build_dt_info($1, $2, $3, - guess_boot_cpuid($3), + $3 ? guess_boot_cpuid($3) : 0, NULL, parser_orphanlist); } | headers memreserves importlist devicetree { + if (!($1 & DTSF_ADDON) && !$4) + ERROR(&@4, "Only addon support missing root node"); + /* * importlist is created with chain_symbol() and so it * is created in reverse order. Reverse it now to have @@ -241,7 +247,10 @@ devicetree: } | devicetree '/' nodedef { - $$ =3D merge_nodes($1, $3); + if ($1) + $$ =3D merge_nodes($1, $3); + else + $$ =3D name_node($3, ""); } | dt_ref nodedef { @@ -256,8 +265,9 @@ devicetree: ""), $2, $1); } else { - ERROR(&@2, "Orphan node %s without a root node not yet supported", $1); - YYERROR; + addon_add_orphan_node(&parser_orphanlist, + orphan_node($2, $1)); + $$ =3D NULL; } } | devicetree DT_LABEL dt_ref nodedef diff --git a/dtc.c b/dtc.c index 5cf8f31..63725bf 100644 --- a/dtc.c +++ b/dtc.c @@ -351,27 +351,37 @@ int main(int argc, char *argv[]) update_exports_ref(dti); mark_local_exports(dti); =20 - /* - * With FDT_REF_PHANDLE added in dtbs, we need to identified - * if some unresolved phandle references are allowed in the dtb - * we have parsed (needed for process_check() to run properly). - * - * Identify plugin device-trees (overlays) based on specific node - * presence. - */ - if (get_subnode(dti->dt, "__fixups__") || - get_subnode(dti->dt, "__local_fixups__")) - dti->dtsflags |=3D DTSF_PLUGIN; + if (dti->dt) { + /* + * With FDT_REF_PHANDLE added in dtbs, we need to identified + * if some unresolved phandle references are allowed in the dtb + * we have parsed (needed for process_check() to run properly). + * + * Identify plugin device-trees (overlays) based on specific node + * presence. + */ + if (get_subnode(dti->dt, "__fixups__") || + get_subnode(dti->dt, "__local_fixups__")) + dti->dtsflags |=3D DTSF_PLUGIN; + } =20 process_checks(force, dti); =20 - if (auto_label_aliases) + if (auto_label_aliases) { + if (!dti->dt) + die("auto-alias not supported without a root node\n"); generate_label_tree(dti, "aliases", false); + } =20 - if (generate_symbols) + if (generate_symbols) { + if (!dti->dt) + die("generation of symbols not supported without a root node\n"); generate_label_tree(dti, "__symbols__", true); + } =20 if (generate_fixups) { + if (!dti->dt) + die("generation of fixups not supported without a root node\n"); generate_fixups_tree(dti, "__fixups__"); generate_local_fixups_tree(dti, "__local_fixups__"); } diff --git a/flattree.c b/flattree.c index 27f7608..11447b1 100644 --- a/flattree.c +++ b/flattree.c @@ -561,7 +561,9 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int versi= on) =20 dt_flags |=3D dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0; =20 - flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi); + if (dti->dt) + flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi); + flatten_imports(dti->importsymlist, &bin_emitter, &dtbuf, vi, dt_flags); flatten_orphans(dti->orphanlist, &bin_emitter, &dtbuf, &strbuf, vi, dt_flags); @@ -752,7 +754,9 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int versio= n) fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); =20 emit_label(f, symprefix, "struct_start"); - flatten_tree(dti->dt, &asm_emitter, f, &strbuf, vi); + + if (dti->dt) + flatten_tree(dti->dt, &asm_emitter, f, &strbuf, vi); =20 fprintf(f, "\t/* FDT_END */\n"); asm_emit_cell(f, FDT_END); @@ -1092,7 +1096,7 @@ struct dt_info *dt_from_blob(const char *fname) struct inbuf memresvbuf; int sizeleft; struct reserve_info *reservelist; - struct node *tree; + struct node *tree =3D NULL; struct symbol *importsymlist =3D NULL; struct symbol *importsym; struct node *orphanlist =3D NULL; @@ -1203,16 +1207,24 @@ struct dt_info *dt_from_blob(const char *fname) =20 reservelist =3D flat_read_mem_reserve(&memresvbuf); =20 - val =3D flat_read_word(&dtbuf); - - if (val !=3D FDT_BEGIN_NODE) - die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%= 08x)\n", val); + if (!(dtsflags & DTSF_ADDON)) { + val =3D flat_read_word(&dtbuf); + if (val !=3D FDT_BEGIN_NODE) + die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x= %08x)\n", + val); =20 - tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags, false); + tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags, false); =20 - val =3D flat_read_word(&dtbuf); + val =3D flat_read_word(&dtbuf); + if (val !=3D FDT_END) + die("Device tree blob doesn't end with FDT_END\n"); + } else { + val =3D flat_read_word(&dtbuf); + if (val =3D=3D FDT_BEGIN_NODE) { + tree =3D unflatten_tree(&dtbuf, &strbuf, "", flags, false); + val =3D flat_read_word(&dtbuf); + } =20 - if (dtsflags & DTSF_ADDON) { if (flags & FTF_EXPORT_IMPORT_SYM) { while (val =3D=3D FDT_IMPORT_SYM) { importsym =3D flat_read_importsym(&dtbuf); @@ -1229,10 +1241,14 @@ struct dt_info *dt_from_blob(const char *fname) val =3D flat_read_word(&dtbuf); } } - } =20 - if (val !=3D FDT_END) - die("Device tree blob doesn't end with FDT_END\n"); + if (!tree && !orphanlist) + die("Device tree blob has 0x%08x tag instead of FDT_BEGIN_NODE or FDT_B= EGIN_NODE_REF\n", + val); + + if (val !=3D FDT_END) + die("Device tree blob doesn't end with FDT_END\n"); + } =20 free(blob); =20 diff --git a/livetree.c b/livetree.c index eaface5..00274c5 100644 --- a/livetree.c +++ b/livetree.c @@ -1203,7 +1203,9 @@ void sort_tree(struct dt_info *dti) { sort_reserve_entries(dti); sort_importsyms(dti); - sort_node(dti->dt); + + if (dti->dt) + sort_node(dti->dt); } =20 /* utility helper to avoid code duplication */ @@ -1451,6 +1453,8 @@ static int generate_local_fixups_tree_internal(struct= dt_info *dti, =20 void generate_label_tree(struct dt_info *dti, const char *name, bool alloc= ph) { + assert(dti->dt); + if (!any_label_tree(dti, dti->dt)) return; generate_label_tree_internal(dti, build_root_node(dti->dt, name), @@ -1459,6 +1463,8 @@ void generate_label_tree(struct dt_info *dti, const c= har *name, bool allocph) =20 void generate_fixups_tree(struct dt_info *dti, const char *name) { + assert(dti->dt); + if (!any_fixup_tree(dti, dti->dt)) return; if (generate_fixups_tree_internal(dti, build_root_node(dti->dt, name), dt= i->dt)) @@ -1469,6 +1475,8 @@ void generate_fixups_tree(struct dt_info *dti, const = char *name) =20 void generate_local_fixups_tree(struct dt_info *dti, const char *name) { + assert(dti->dt); + if (!any_local_fixup_tree(dti, dti->dt)) return; if (generate_local_fixups_tree_internal(dti, build_root_node(dti->dt, nam= e), dti->dt)) @@ -1514,7 +1522,8 @@ void update_phandles_ref(struct dt_info *dti) { struct node *orphan; =20 - update_phandles_ref_internal(dti, dti->dt); + if (dti->dt) + update_phandles_ref_internal(dti, dti->dt); =20 for_each_orphan(dti->orphanlist, orphan) update_phandles_ref_internal(dti, orphan); @@ -1545,7 +1554,8 @@ void mark_local_phandles(struct dt_info *dti) { struct node *orphan; =20 - mark_local_phandles_internal(dti, dti->dt); + if (dti->dt) + mark_local_phandles_internal(dti, dti->dt); =20 for_each_orphan(dti->orphanlist, orphan) mark_local_phandles_internal(dti, orphan); @@ -1580,7 +1590,8 @@ void update_exports_ref(struct dt_info *dti) { struct node *orphan; =20 - update_exports_ref_internal(dti, dti->dt); + if (dti->dt) + update_exports_ref_internal(dti, dti->dt); =20 for_each_orphan(dti->orphanlist, orphan) update_exports_ref_internal(dti, orphan); @@ -1607,7 +1618,8 @@ void mark_local_exports(struct dt_info *dti) { struct node *orphan; =20 - mark_local_exports_internal(dti, dti->dt); + if (dti->dt) + mark_local_exports_internal(dti, dti->dt); =20 for_each_orphan(dti->orphanlist, orphan) mark_local_exports_internal(dti, orphan); diff --git a/treesource.c b/treesource.c index bc5d847..71dbd5f 100644 --- a/treesource.c +++ b/treesource.c @@ -410,7 +410,8 @@ void dt_to_source(FILE *f, struct dt_info *dti) fprintf(f, "\n"); } =20 - write_tree_source_node(f, dti->dt, 0); + if (dti->dt) + write_tree_source_node(f, dti->dt, 0); =20 for_each_orphan(dti->orphanlist, orphan) { fprintf(f, "\n"); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE506368296; Mon, 12 Jan 2026 14:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227714; cv=none; b=gtLnBOKTfEiDIRQTU5HYW2OvT8w0pGqfcajaCRCfG4xvkOiSoYA55aWIPgZ596A2FBjrLoGvK5dAubcheWnBRY25HmeNG4O3/ZdlY7McoIXfpZqNZOF5oUj3OYq1VGDcSRSnZxOz5AzbF1EcI/0mLf5Lu/SBAgSQMHR74YdJiAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227714; c=relaxed/simple; bh=wC8+9farHpO7TwHISd+JDQg+88Xnm1DglxtBoZNZQ4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQlm79NvVjG6iAHtCgivhKBna/mqED3bNeR2xZ6tjL8mMO6t0tzbhZJjg1fcze1cej/aMYvdJNjjopaTlNm1bqL6bhIC5wjg2R3TiLANLk0sd8R2WyXaORdIYkqo8VBD8VAfyTW/hnzveJhJnJxGXBHM9JZZtrl9AZXPgR/eUFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=AChO2PuV; arc=none smtp.client-ip=185.171.202.116 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.b="AChO2PuV" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 2DE67C20868; Mon, 12 Jan 2026 14:21:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A53F2606FA; Mon, 12 Jan 2026 14:21:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9730B103C8C61; Mon, 12 Jan 2026 15:21:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227710; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=OkYo61wpmCiei7gTekU+N071yho8X+Jnp5LaOOR8E2g=; b=AChO2PuV2eYCy2/CyiEsEo/M7SMwl3h5wld0TOzXZvoBPez6jo90x9FvMaBISfDWtJb6qO LBh0DsQRcpQXX5wC9ijgHsYk4M9hmdSBFP42u1JOYCseZydfd/CHV8gGRv/rVqoQs38jyU Du4EiJ3uYyuIPIwtGB7AY2HbZ9iv/HogMoAY7ZXGA12PYFKfn4mpB+2HSGjcV6urGjMHze 5qpG7aYG/KWSbZxmmURf5Eg+3n5H4OZqURULyfhQJ0s2SvZpVyKG4U7nw7oJ1+zQfU1iyX fnR4Ut3ZwSNKOKBaD/8zjJZTEn92rjXgiUhaFwDX7fovedb+LHVMJOvxDr1ahA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 59/77] tests: metadata: Add a test for addon without root node Date: Mon, 12 Jan 2026 15:19:49 +0100 Message-ID: <20260112142009.1006236-60-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The root device-tree node is no more mandatory for addons. Indeed, addons can be composed of only orphan nodes without any needs for the root device-tree node presence. Add a test related to addon dts and dtb without root node. Signed-off-by: Herve Codina --- tests/metadata_addon_orphan2.dtb.dts.expect | 10 ++++++++++ tests/metadata_addon_orphan2.dtb.expect | 8 ++++++++ tests/metadata_addon_orphan2.dts | 13 +++++++++++++ tests/metadata_addon_orphan2.dts.dts.expect | 10 ++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan2.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan2.dtb.expect create mode 100644 tests/metadata_addon_orphan2.dts create mode 100644 tests/metadata_addon_orphan2.dts.dts.expect diff --git a/tests/metadata_addon_orphan2.dtb.dts.expect b/tests/metadata_a= ddon_orphan2.dtb.dts.expect new file mode 100644 index 0000000..32c1b1e --- /dev/null +++ b/tests/metadata_addon_orphan2.dtb.dts.expect @@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + + +&base { + + addon-node { + prop =3D <0x02>; + }; +}; diff --git a/tests/metadata_addon_orphan2.dtb.expect b/tests/metadata_addon= _orphan2.dtb.expect new file mode 100644 index 0000000..46e67d0 --- /dev/null +++ b/tests/metadata_addon_orphan2.dtb.expect @@ -0,0 +1,8 @@ +/dts-v1/; +/addon/; + +&base { + addon-node { + prop =3D <0x00000002>; + }; +}; diff --git a/tests/metadata_addon_orphan2.dts b/tests/metadata_addon_orphan= 2.dts new file mode 100644 index 0000000..d4ff42f --- /dev/null +++ b/tests/metadata_addon_orphan2.dts @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +&base { + addon-node { + prop =3D <2>; + }; +}; diff --git a/tests/metadata_addon_orphan2.dts.dts.expect b/tests/metadata_a= ddon_orphan2.dts.dts.expect new file mode 100644 index 0000000..32c1b1e --- /dev/null +++ b/tests/metadata_addon_orphan2.dts.dts.expect @@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + + +&base { + + addon-node { + prop =3D <0x02>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 659b42b..5edc58b 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1128,7 +1128,7 @@ metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ - metadata_addon_orphan1; do + metadata_addon_orphan1 metadata_addon_orphan2; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4988736A007; Mon, 12 Jan 2026 14:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227715; cv=none; b=lbTlbcNkjarJTafDiLcbBMLUhB+9dA25muAPWq1Pn78mPdNV6TJrny6K2QgyTaeMtTFDPGr5Q+CorcStOO0if4L2DWgKIYFSHoHypgTc9uVBNyrFUEU0hI8QSDNU8bLRh8E/MVOqbrNkDMOsy/uwCXHjBv7l93F/30jGdsUKMsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227715; c=relaxed/simple; bh=ibv3HHQTg3l8cK9tjTVarw5d8EPr7Emhbn4fChGR3ck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IkTb+lK7ir0tErpNc/zcEIqK7vXpUjZeGVqkleU/STYiv1rd0Y1fy+ILmeUijBBRJWq+pPV8BblqjmQhig7OTj29ZO1/Pd7OabrqJ5HdtVdkIyRWHdHqS5hxAMBmVZW6jGRhLOX6I1/HDMQ0H//RTggV5/vRExKZ0C/BGF/6pvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OuQBhuG6; arc=none smtp.client-ip=185.171.202.116 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.b="OuQBhuG6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 88CE6C2086B; Mon, 12 Jan 2026 14:21:26 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0BD6B606FA; Mon, 12 Jan 2026 14:21:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 323E3103C9260; Mon, 12 Jan 2026 15:21:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227712; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=rhQymJfoeWjEmMGqd2fwO2nktZgpHgpUm58z5wMqPwA=; b=OuQBhuG6ey3VKxa2AYudHEJHnIBxhHVfN3iASa1rTO5sV81T9UYR+b+Uz8MB0o5EIiFO5e Md6dJjgaxr5KCc+Q3znuYDxJIg/MCnfAf5wk2UwiQtjr9RZK25MvSj1xjhPwHDsZWnzwcE tLFcTcOL5enFZ/C0AGEq9P77KWtltXT+fQOhVLd8/9DZpmnDsNMzi9UdISSXWhXsATOovx /ZBPXqdIi+f3wGVmKAs7ktRdmWw1QrcewcsCju2dZ5oCrVu1M4CCRVzk/rZ4M1AqdCtFYr byTjJdxsuD/0zpU/ZwpU8OexhL43UbrtMKDkig3EOBXrSdm/atElnrR8owJSiA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 60/77] dtc: Allow parser_get_node_by_ref() to return an orphan node for merging purpose Date: Mon, 12 Jan 2026 15:19:50 +0100 Message-ID: <20260112142009.1006236-61-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" When the same orphan node is described multiple times in an addon dts, those multiple descriptions should be merged. For instance, in the following snippet: --- 8< --- /addon/; &foo { prop1 =3D <1>; }; &foo { prop2 =3D <2>; }; --- 8< --- The foo orphan node is described twice and should be merged in only one instance: --- 8< --- &foo { prop1 =3D <1>; prop2 =3D <2>; }; --- 8< --- The current mecanisme used to find a node for merging is based on label. Indeed, without orphan nodes, '&foo' is a reference to a node with the label 'foo'. This node labeled foo is the node found for merging. With addons and orphan nodes, '&foo' is not a reference to an existing node. Indeed, this node is an orphan one because the node referenced by foo is an external node (i.e. not available in the addon itself). The label 'foo' doesn't exist. No node in the addon are defined with a foo label attached. Take this orphan nodes specificity into account in order to find a possible orphan node candidate for merging. Signed-off-by: Herve Codina --- dtc-parser.y | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dtc-parser.y b/dtc-parser.y index cf5447a..7f8c294 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -39,11 +39,32 @@ static struct node *parser_get_node_by_ref(struct node = *dt, struct node *orphanl * Use a temporary dt_info in order to use dti_get_node_by_ref() */ struct dt_info dti =3D {}; + struct node *target; + struct node *orphan; =20 dti.dt =3D dt; dti.orphanlist =3D orphanlist; =20 - return dti_get_node_by_ref(&dti, ref); + target =3D dti_get_node_by_ref(&dti, ref); + if (target) + return target; + + /* + * No node were found by dti_get_node_by_ref(). + * + * parser_get_node_by_ref() is called by the parser only to get a node + * in order to perform a possible merge. + * + * The referenced used can be a label matching an orphan node. In this + * merge context, returning a matching orphan node makes sense even if + * no label are defined for the orphan node. + */ + for_each_orphan(orphanlist, orphan) { + if (streq(orphan->ref, ref)) + return orphan; + } + + return NULL; } =20 %} --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC8F9369990; Mon, 12 Jan 2026 14:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227718; cv=none; b=ZpGFoCPcjfEVfpcYnzdSZCPJGLpqG1zE8eIwnv9IL/AGB4kH5Q8uc9itheXkq3YUt/ZtW41kd/lziPTlmi2wOeP8LK7fWuZM/ApTbVKAbVCYRk4c0x20KJlgtXkuaNY957PacD4Rv8aFgngE0/6RbKq/PpGqkbupn7OSm1bK5UA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227718; c=relaxed/simple; bh=C/i3bZYNU7hFPWeOIO4liAFOiYkaM6HH7t8B6P6dEYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSee1VzTa+bl6LS02UR49gklU2h9fpZGyEDKMBvResOJBDQEhit8lHe1DBp09l629qVxBDZB5dwqSYwXaY/Wb7dI48588ab5sLLWJhlEYZLkz2T00AI35cUtHYt5XI/xeHWN2KloYeJ1mGwZy4ZcvHaT/ia80SXgag3JGNsa8AI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=t9dD7tOu; arc=none smtp.client-ip=185.246.85.4 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.b="t9dD7tOu" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 58B3D4E42094; Mon, 12 Jan 2026 14:21:55 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2E27A606FA; Mon, 12 Jan 2026 14:21:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A880B103C8CD8; Mon, 12 Jan 2026 15:21:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227714; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lBi3nUNq8ZfOvMorW6kQYzmy743beEuX+jiuAg/FG5k=; b=t9dD7tOu0e3cwKdWn+E10MgvT5EDWUfCOi6AjUZDPglZxqaQJHkyIKmDnTgfK++TkvYA5T Pd0lV0B0g2iFkV+DFwMKpXsSjnqAi1kVOnmsa1Xdon0QUvINYrmQfwpcjpBikoeb1gb/aE vfLxAgJeDOZ9mcd29sCT90RB+Jhoqjik2xvd3S7CQgLQyMvu0a/JHkTQQLwcl7XIh4Lfgo QpZdFzi/feFuE+8aIK8NldrFMInEKvvWLZUUYEKR8tuVdP6TpZB3pQ3PTWsQQLRPo74+n8 0VItYbOwEI9O6f4XcEUNrSfsG0XluKGHffX5VIddP8jWJpjqL4QSQgtfF4JEaQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 61/77] tests: metadata: Add a test related to orphan node merging Date: Mon, 12 Jan 2026 15:19:51 +0100 Message-ID: <20260112142009.1006236-62-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Merging orphan node is supported. Add a test for this feature. Signed-off-by: Herve Codina --- tests/metadata_addon_orphan3.dtb.dts.expect | 22 ++++++++++++++++ tests/metadata_addon_orphan3.dtb.expect | 17 +++++++++++++ tests/metadata_addon_orphan3.dts | 28 +++++++++++++++++++++ tests/metadata_addon_orphan3.dts.dts.expect | 22 ++++++++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan3.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan3.dtb.expect create mode 100644 tests/metadata_addon_orphan3.dts create mode 100644 tests/metadata_addon_orphan3.dts.dts.expect diff --git a/tests/metadata_addon_orphan3.dtb.dts.expect b/tests/metadata_a= ddon_orphan3.dtb.dts.expect new file mode 100644 index 0000000..2605e1b --- /dev/null +++ b/tests/metadata_addon_orphan3.dtb.dts.expect @@ -0,0 +1,22 @@ +/dts-v1/; +/addon/; + + +&base1 { + + addon-node1 { + prop1 =3D <0x01>; + prop2 =3D <0x02>; + }; + + addon-node2 { + prop3 =3D <0x03>; + }; +}; + +&base2 { + + addon-node { + prop =3D <0x00>; + }; +}; diff --git a/tests/metadata_addon_orphan3.dtb.expect b/tests/metadata_addon= _orphan3.dtb.expect new file mode 100644 index 0000000..5a65483 --- /dev/null +++ b/tests/metadata_addon_orphan3.dtb.expect @@ -0,0 +1,17 @@ +/dts-v1/; +/addon/; + +&base1 { + addon-node1 { + prop1 =3D <0x00000001>; + prop2 =3D <0x00000002>; + }; + addon-node2 { + prop3 =3D <0x00000003>; + }; +}; +&base2 { + addon-node { + prop =3D <0x00000000>; + }; +}; diff --git a/tests/metadata_addon_orphan3.dts b/tests/metadata_addon_orphan= 3.dts new file mode 100644 index 0000000..0fe52ec --- /dev/null +++ b/tests/metadata_addon_orphan3.dts @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +&base1 { + addon-node1 { + prop1 =3D <1>; + }; +}; + +&base2 { + addon-node { + prop =3D <0>; + }; +}; + +&base1 { + addon-node1 { + prop2 =3D <2>; + }; + addon-node2 { + prop3 =3D <3>; + }; +}; diff --git a/tests/metadata_addon_orphan3.dts.dts.expect b/tests/metadata_a= ddon_orphan3.dts.dts.expect new file mode 100644 index 0000000..2605e1b --- /dev/null +++ b/tests/metadata_addon_orphan3.dts.dts.expect @@ -0,0 +1,22 @@ +/dts-v1/; +/addon/; + + +&base1 { + + addon-node1 { + prop1 =3D <0x01>; + prop2 =3D <0x02>; + }; + + addon-node2 { + prop3 =3D <0x03>; + }; +}; + +&base2 { + + addon-node { + prop =3D <0x00>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 5edc58b..12418bf 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1128,7 +1128,8 @@ metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ - metadata_addon_orphan1 metadata_addon_orphan2; do + metadata_addon_orphan1 metadata_addon_orphan2 \ + metadata_addon_orphan3; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC2CD36AB42; Mon, 12 Jan 2026 14:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227719; cv=none; b=hVrNw7Pd0TNx2XVso5kOBTcwlJuAZniuuijXU1ZvOoOkPWHBX7Abqfo3E4IAfUCHyIF/BVItDz9hQDpVb7y+cm0NCTbUQFI47bv7ej1+ersx57i80/ZxG1d+onoUifVImTQ71qcMdMSIAgO+lbV4hoLK7Te5HuPPUH7yrgyPZeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227719; c=relaxed/simple; bh=W9kOSnvSyaOHcr8JISA2bsDOv382/kuOx0poBtNKiko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JtMYCNX750R34FJcBiC+J9vhcMDz4BbymRF9veMQpBQqEZAS7XJFhvK9uPpmz6MxCu2pm/s8Q5WRkY4KYrmPoI2Or7zDtalNtLHFlwBbnRwXzYnJzG/z23FEkwNLX0CGK6PuIi3lmWX+nF0SwClGgYRhyfT54H8anx/fFbS1LQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=na/lIYFP; arc=none smtp.client-ip=185.171.202.116 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.b="na/lIYFP" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D5FC0C2086C; Mon, 12 Jan 2026 14:21:29 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 590EF606FA; Mon, 12 Jan 2026 14:21:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 84BDC103C9261; Mon, 12 Jan 2026 15:21:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227715; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=0ya4snKKo2ZGVGe7DjnxyyyxuYX4XyD6EcegEFy9kt0=; b=na/lIYFPtHMW1HnzmSMEM5lFhABUOgxLjMDTdDHnAnwSM4ovt2lQAQlMm2N9d1BcAOqeiP wABPm6tC/jiKTpi1glv0R4KgHLiDTwYT7VOt2kcK5q3Shsp0jHdq2gX1oG+zV5vA3s2aR1 4I+L6Rl66IWWMrB6fU5EXDFJEPWebjmHy2cz4C9T4MPXm1brMWgYLlo7nNttzav3+FmLlF UA11E0bsIiXoLY9sgi/M2Niu8iQL+DoeoGGQea2nJf2rKR3auBE6iD81oeG/e5GiDtbSC2 t5bUQOiSmzlTGV60babYozW6UGidrp2fIQc9tHjVXD+NOvYkgjOviNd1gU2X+Q== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 62/77] dtc: Add support for orphan nodes sorting Date: Mon, 12 Jan 2026 15:19:52 +0100 Message-ID: <20260112142009.1006236-63-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc can sort items when the command line --sort option is set. Add support for orphan nodes sorting when this option is used. Signed-off-by: Herve Codina --- livetree.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/livetree.c b/livetree.c index 00274c5..59b912d 100644 --- a/livetree.c +++ b/livetree.c @@ -1199,6 +1199,34 @@ static void sort_importsyms(struct dt_info *dti) free(tbl); } =20 +static void sort_orphans(struct dt_info *dti) +{ + int n =3D 0, i =3D 0; + struct node *orphan, **tbl; + + for_each_orphan(dti->orphanlist, orphan) { + sort_node(orphan); + n++; + } + + if (n =3D=3D 0) + return; + + tbl =3D xmalloc(n * sizeof(*tbl)); + + for_each_orphan(dti->orphanlist, orphan) + tbl[i++] =3D orphan; + + qsort(tbl, n, sizeof(*tbl), cmp_subnode); + + dti->orphanlist =3D tbl[0]; + for (i =3D 0; i < (n-1); i++) + tbl[i]->next_sibling =3D tbl[i+1]; + tbl[n-1]->next_sibling =3D NULL; + + free(tbl); +} + void sort_tree(struct dt_info *dti) { sort_reserve_entries(dti); @@ -1206,6 +1234,8 @@ void sort_tree(struct dt_info *dti) =20 if (dti->dt) sort_node(dti->dt); + + sort_orphans(dti); } =20 /* utility helper to avoid code duplication */ --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA4FD36AB6B; Mon, 12 Jan 2026 14:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227721; cv=none; b=Epj0xO9/nMBupyQLBw32d1s/Zq0iaYjcclO7QTSgHVpzCch51b5r/z3gZdjoGZywDiZAQ1Lseoopnk+IlKHI/mtO3Sqio5mSl1J7GHV2y21vc1EXkQCeDldYsvYXgx0MEV/GjdbtJjqPyAa21FNmxHaloaBI7Dm6EzP4XWU0vPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227721; c=relaxed/simple; bh=ukav0csfGSYhTySJmPXHNDEiPKRwkJZCNFtIAOUkmi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O/SUg4wONE/8gG8DrEI9FWssdr/ODAtnXgrAAlgla64Um9+Pi+W4EB5xWKkvT3czqkWZSkZB1Yl6LryTl3luuZGcIhpTICQbQSayiyGFvph9FPShxQAF6Z41Mx2tpDikf0XpNxoiW6gACR4QPjnhfcJM+uN+wn1iEkrzJnaVVQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=2S9yzatz; arc=none smtp.client-ip=185.246.85.4 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.b="2S9yzatz" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 732EC4E42097; Mon, 12 Jan 2026 14:21:58 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4397A606FA; Mon, 12 Jan 2026 14:21:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D6DED103C9260; Mon, 12 Jan 2026 15:21:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227717; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=SCPDW1Fd99/HH0hpXZlq0g01YveqESOf+XNqKOwlufg=; b=2S9yzatzpGeiD2XvkKJeGBcf+5CxcQf0O24l+LQkIjakRP6k3Kmi+x0HnGB1t+uz+LAkeH uyscI1CWo/2zkRx64RVpX51KSiR16ow/fyG9niu0hT7mDli96o7R3gQSJYbkmYxlyStJ6r lBsu/aRD71aT/z2umqtiK+Bc0x4GqSpjnWgQE4mNX8uFt/0xXF/UjHY/YNWc4xvuBFYuQT ZMMfZthtbrBVTfqowLrLFhv85uB/s9deBUH0jmHEUSAk8EIumJFd5Hx5KOweu3Vkj9zCUR hrhySUBNGwJcta/adetiSyoSmbRHq/x+HVOHm8dmghXLSPLDw3f1o3W4qIp1Yg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 63/77] tests: metadata: Improve sort test to check for orphan nodes sorting Date: Mon, 12 Jan 2026 15:19:53 +0100 Message-ID: <20260112142009.1006236-64-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" dtc is able to sort orphan nodes when the --sort option is used. Improve the metadata sort test to perform a check for this feature. Signed-off-by: Herve Codina --- tests/metadata_sort.dtb.dts.expect | 39 ++++++++++++++++++++++++++++++ tests/metadata_sort.dtb.expect | 30 +++++++++++++++++++++++ tests/metadata_sort.dts | 33 +++++++++++++++++++++++++ 3 files changed, 102 insertions(+) diff --git a/tests/metadata_sort.dtb.dts.expect b/tests/metadata_sort.dtb.d= ts.expect index 270c06d..df3c02b 100644 --- a/tests/metadata_sort.dtb.dts.expect +++ b/tests/metadata_sort.dtb.dts.expect @@ -20,3 +20,42 @@ phandle =3D <0x01>; }; }; + +&abc { + prop-a =3D "a"; + prop-b =3D "b"; + + node-a { + prop =3D <0x01>; + }; + + node-b { + prop =3D <0x02>; + }; + + node-c { + prop =3D <0x03>; + }; +}; + +&de1 { + prop-a =3D "a"; + prop-b =3D "b"; + + node-a { + prop =3D <0x01>; + }; + + node-b { + prop =3D <0x02>; + }; + + node-c { + prop =3D <0x03>; + }; +}; + +&de2 { + prop-a =3D "a"; + prop-b =3D "b"; +}; diff --git a/tests/metadata_sort.dtb.expect b/tests/metadata_sort.dtb.expect index 0dacab7..47002fe 100644 --- a/tests/metadata_sort.dtb.expect +++ b/tests/metadata_sort.dtb.expect @@ -16,3 +16,33 @@ // [FDT_IMPORT_SYM] 'abc' (foo,bar) // [FDT_IMPORT_SYM] 'de1' (foo,bar) // [FDT_IMPORT_SYM] 'de2' (foo,bar) +&abc { + prop-a =3D "a"; + prop-b =3D "b"; + node-a { + prop =3D <0x00000001>; + }; + node-b { + prop =3D <0x00000002>; + }; + node-c { + prop =3D <0x00000003>; + }; +}; +&de1 { + prop-a =3D "a"; + prop-b =3D "b"; + node-a { + prop =3D <0x00000001>; + }; + node-b { + prop =3D <0x00000002>; + }; + node-c { + prop =3D <0x00000003>; + }; +}; +&de2 { + prop-a =3D "a"; + prop-b =3D "b"; +}; diff --git a/tests/metadata_sort.dts b/tests/metadata_sort.dts index e523e20..3b690a5 100644 --- a/tests/metadata_sort.dts +++ b/tests/metadata_sort.dts @@ -23,3 +23,36 @@ /export/ a: &node_b; }; }; + +&de2 { + prop-b =3D "b"; + prop-a =3D "a"; +}; + +&abc { + prop-b =3D "b"; + prop-a =3D "a"; + node-b { + prop =3D <2>; + }; + node-a { + prop =3D <1>; + }; + node-c { + prop =3D <3>; + }; +}; + +&de1 { + prop-b =3D "b"; + prop-a =3D "a"; + node-b { + prop =3D <2>; + }; + node-a { + prop =3D <1>; + }; + node-c { + prop =3D <3>; + }; +}; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C57F2EAB83; Mon, 12 Jan 2026 14:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227722; cv=none; b=QL+8CEuFF08LfoyNwO3UiN66+48FEUBoR7hzoX1HgmJqUqmpNkSe2VXtonY/r3YvZtNAsV9RLJ68XLStTBjOuRsP3aX+zCGU+M+B7UxMq1sMEXhLmYivv6YlhiXpSb79CR4yczeaAIZOUM53xo/yCMD4EKKxeTLZgbjF0j1IupU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227722; c=relaxed/simple; bh=IQAXO5C5Eq1ZdOJzJLzu/hy+A3JAeF8JEfjcPrQjQag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XeZp6B4rqaMxniWetMR9pfySS/a3ZfKw/L8kaev+9t48pPssf1NBFCfAyeRGujMtS+P4PrWTkl9VPDuMisQTiqAynKtolwkGB4nzit8YyhKKeYszM4toSjUYGbE7UOM9nBQ+fuhyggvBb5aKEmo0F1VBbEvDujBXUkGHrTXqcRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=vjcwI++6; arc=none smtp.client-ip=185.171.202.116 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.b="vjcwI++6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D74C1C2086B; Mon, 12 Jan 2026 14:21:32 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 571C8606FA; Mon, 12 Jan 2026 14:21:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 93FE1103C9262; Mon, 12 Jan 2026 15:21:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227718; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=zkrl7KQL2mBWiVPlgvVg1DTApCz/hctc5nPdz+ry7R4=; b=vjcwI++6Kkr2AdtBxraNlVfueJGHciiQ8fq1VLcZtVGY0ZtC+UR9QksinNKoULX7W2d3Ko DTrBKrjU6Ol7+UUm+0uTjSJJa2oBeWkEx2+T4xc6nGO6aWlgZRqGW4F+JgHfFgB0WzwF26 hyrtteDonOX33ELV7creSCLmpg0KXH+wri2xaZ5vSR6qk7dqZJb7V2+YFJgDx/vD9LF6Sd tN216lb0W0rORQ6Z3q6d3BLTNjEemej5RSFngNFsI4KsUU5wJVUL3iLXWvlXhqFqKx4pR+ Csk+5JmKc6KoKArJ5obzcVLjWmVnWY7mja9ZKNE0lOTYZ+msWHyJU4V5mxDESA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes Date: Mon, 12 Jan 2026 15:19:54 +0100 Message-ID: <20260112142009.1006236-65-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Referencing a sub-node from an orphan node using a path is needed. Indeed, using the following snippet: --- 8< --- /addon/; &node1 { subnode { foo-phandle =3D <&foo_label>; }; }; &node2 { foo_label: foo { prop =3D <1>; }; }; --- 8< --- Even if node2 is an orphan node, foo is a local node. foo-phandle references the foo node using a label. Once converted to a dtb, the label is lost. Only the phandle of the foo node is used in the foo-phandle property and this property is marked FDT_REF_LOCAL. Converting back this dtb to a dts, the marked local phandle should be translated to a path to the related local node. The issue is that this local node is not in a root device tree. We need to identify the orphan node the foo node belongs to. We cannot use a path starting by '/'. This kind of path identify node in the root tree. This new syntax allows to identify the orphan node in a path: $/ This leads to a reference by path in the form &{$/}. Using the previous example, those both phandles points to the same node: foo-phandle1 =3D <&foo_label>; /* Reference by label */ foo-phandle2 =3D <&{$node2/foo}>; /* Reference by path */ When the dtb is converted back to a dts, the marked local phandle involving subnode available from orphan nodes can be translated to a reference by path thanks to the new syntax. Add support for this &{$/} syntax to reference by path a local node from an orphan node. Signed-off-by: Herve Codina --- dtc-lexer.l | 7 +++++++ dtc-parser.y | 19 +++++++++++++++++++ dtc.c | 22 ++++++++++++++++++++-- livetree.c | 14 +++++++++++++- treesource.c | 3 ++- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/dtc-lexer.l b/dtc-lexer.l index cb616f9..540bfdf 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -239,6 +239,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_PATH_REF; } =20 +<*>"&{\$"{LABEL}([/]{PATHCHAR}*)?\} { /* orphan path reference */ + yytext[yyleng-1] =3D '\0'; + DPRINT("Ref orphan path: %s\n", yytext+1); + yylval.labelref =3D xstrdup(yytext+2); + return DT_ORPHAN_PATH_REF; + } + [0-9a-fA-F]{2} { yylval.byte =3D strtol(yytext, NULL, 16); DPRINT("Byte: %02x\n", (int)yylval.byte); diff --git a/dtc-parser.y b/dtc-parser.y index 7f8c294..9d619cd 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -111,6 +111,7 @@ static struct node *parser_get_node_by_ref(struct node = *dt, struct node *orphanl %token DT_LABEL %token DT_LABEL_REF %token DT_PATH_REF +%token DT_ORPHAN_PATH_REF %token DT_INCBIN =20 %type propdata @@ -589,6 +590,24 @@ arrayprefix: ERROR(&@2, "References are only allowed in " "arrays with 32-bit elements."); =20 + $$.data =3D data_append_integer($1.data, val, $1.bits); + } + | arrayprefix DT_ORPHAN_PATH_REF + { + uint64_t val =3D ~0ULL >> (64 - $1.bits); + + if ($1.bits =3D=3D 32) { + if (!(last_header_flags & DTSF_ADDON)) + ERROR(&@2, "Orphan path reference %s supported only in addon", $2); + + $1.data =3D data_add_marker($1.data, + REF_PHANDLE, + $2); + } else { + ERROR(&@2, "References are only allowed in " + "arrays with 32-bit elements."); + } + $$.data =3D data_append_integer($1.data, val, $1.bits); } | arrayprefix DT_LABEL diff --git a/dtc.c b/dtc.c index 63725bf..72d85e4 100644 --- a/dtc.c +++ b/dtc.c @@ -48,13 +48,31 @@ static void fill_fullpaths(struct node *tree, const cha= r *prefix) static void dti_fill_fullpaths(struct dt_info *dti) { struct node *orphan; + struct node *child; =20 /* Fill fullpaths for the root node */ if (dti->dt) fill_fullpaths(dti->dt, ""); =20 - for_each_orphan(dti->orphanlist, orphan) - fill_fullpaths(orphan, "__orphan__/"); + /* Fill fullpaths for orphan nodes */ + for_each_orphan(dti->orphanlist, orphan) { + if (orphan->name[0] =3D=3D '\0') + die("orphan node has an empty name\n"); + + /* + * An orphan node name is set with its reference. + * Its name is in the form "&xxxxxx". + * For its full path, we use "$xxxxx" to make a clear + * distinction between a reference (&xxxx) where a resolution + * could be involved vs a "simple" path where we just need to + * identified the orphan ($xxxx). + */ + xasprintf(&orphan->fullpath, "$%s", orphan->name + 1); + orphan->basenamelen =3D strlen(orphan->name); + + for_each_child(orphan, child) + fill_fullpaths(child, orphan->fullpath); + } } =20 /* Usage related data. */ diff --git a/livetree.c b/livetree.c index 59b912d..263da1f 100644 --- a/livetree.c +++ b/livetree.c @@ -804,7 +804,19 @@ static struct node *get_node_by_ref(struct node *tree,= const char *ref) path =3D slash + 1; } =20 - target =3D get_node_by_label(tree, label); + if (label[0] =3D=3D '$' && tree->name[0] =3D=3D '&') { + /* + * We search for an orphan and the given tree is an + * orphan. Use the given tree only if it matches the + * expected orphan. + */ + if (streq(label + 1, tree->name + 1)) + target =3D tree; + else + target =3D NULL; + } else { + target =3D get_node_by_label(tree, label); + } =20 free(buf); =20 diff --git a/treesource.c b/treesource.c index 71dbd5f..44de0db 100644 --- a/treesource.c +++ b/treesource.c @@ -278,7 +278,8 @@ static void write_propval(FILE *f, struct property *pro= p) break; =20 if (m_phandle) { - if (m_phandle->ref[0] =3D=3D '/') + if (m_phandle->ref[0] =3D=3D '/' /* Root node */ || + m_phandle->ref[0] =3D=3D '$' /* Orphan node */) fprintf(f, "&{%s}", m_phandle->ref); else fprintf(f, "&%s", m_phandle->ref); --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50F2236AB42; Mon, 12 Jan 2026 14:22:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227723; cv=none; b=gwdjeDno7o1FuOx9MBqEPvmJEzen1USaN3g0gDBAf+dZOCfEsO5MuR6YRUVQ1JqA5OE0H9R7EjzBYpx4HK1SAVs7Z/GVX9pAqAaWuZCc66T5pjV6mzg4tBCKvUxHdWssxQ3/4UtbtEMLBlqIXYV+Rugc/gKLUZrI0qI3K4B+5j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227723; c=relaxed/simple; bh=rK1ZcaZmBbXCSSt1XxWv9W9a2SVisNF0mjPNBoGR07k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W3pWEmuAj2Sdl0QRadp5iJ3q14zoYzBLUzopxUgB2a4/AbQDlr3dh2zCkt90N7DCoQcGXNs478PLFZXZ1rNIopE5HtiXn24TJ14xO2AOg3pcPJsvvW4arz4fpWh2D7uR4dYI0sxw4wVCh0iJOijwx0v9Js3u1ND34HAgbHEjsco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=EuN5Fakk; arc=none smtp.client-ip=185.246.85.4 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.b="EuN5Fakk" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 2C1CD4E42094; Mon, 12 Jan 2026 14:22:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 030CD606FA; Mon, 12 Jan 2026 14:22:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EBD43103C8CD8; Mon, 12 Jan 2026 15:21:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227720; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=FsyA8Thd/0g5Sni0FrJIXg1W4AOtqLdlEbFPH+WugoE=; b=EuN5FakkGTML/LcGys1WJ57HfNVhKljk/KA6vRS9lcIkWQ0VECJbTik7+k/oDZQvxFhHx4 kKsiu1580QRAizlJmrBMpPAC8hdY/X0wSatSLgL3tAIYwx8whY+WmbZeF/llW6zOS0QgW/ RIY9ioAFgXw5mRTCMBpatfvU7KY04/TJlAvN5dCAb5sUbY3zpPQdu+fBKJCdOwdAe4H0gR JkZ0Pox3eTQ8ZQYgn0EFdTvh7l15n8Q23de2aEumdKpdP2chDImBLT+xlnnSWCEzzKOHMU xvpq3QVHxSjJ5d/xd4G5tmPLG7dIvKvFlw7be7b+Qh3R/XpJpwzuK3vzi/aSbw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 65/77] tests: metadata: Add a test for references by path involving orphan nodes Date: Mon, 12 Jan 2026 15:19:55 +0100 Message-ID: <20260112142009.1006236-66-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The syntax '&{$/}' allows to reference by path a node that belongs to an orphan node. Add a test related to this kind of references. Signed-off-by: Herve Codina --- .../metadata_addon_references.dtb.dts.expect | 48 +++++++++++++++++++ tests/metadata_addon_references.dtb.expect | 48 +++++++++++++++++++ tests/metadata_addon_references.dts | 43 +++++++++++++++++ .../metadata_addon_references.dts.dts.expect | 48 +++++++++++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_references.dtb.dts.expect create mode 100644 tests/metadata_addon_references.dtb.expect create mode 100644 tests/metadata_addon_references.dts create mode 100644 tests/metadata_addon_references.dts.dts.expect diff --git a/tests/metadata_addon_references.dtb.dts.expect b/tests/metadat= a_addon_references.dtb.dts.expect new file mode 100644 index 0000000..267a929 --- /dev/null +++ b/tests/metadata_addon_references.dtb.dts.expect @@ -0,0 +1,48 @@ +/dts-v1/; +/addon/; + +/ { + + sub-node { + ref1-base1 =3D <&base1>; + ref2-base1-addon-node =3D <&{$base1/addon-node}>; + ref3-base1-addon-node =3D <&{$base1/addon-node}>; + ref4-base1-addon-node =3D <&{$base1/addon-node}>; + ref5-base3 =3D <&{$base3}>; + ref6-base3 =3D <&{$base3}>; + ref7-base3-subsubnode =3D <&{$base3/sub-node/sub-subnode}>; + phandle =3D <0x04>; + }; +}; + +&base1 { + + addon-node { + prop =3D <0x02>; + phandle =3D <0x01>; + }; +}; + +&base2 { + + addon-node1 { + ref-base1-addon-node =3D <&{$base1/addon-node}>; + }; + + addon-node2 { + ref-root-sub-node =3D <&{/sub-node}>; + }; +}; + +&base3 { + phandle =3D <0x02>; + + sub-node { + prop =3D <0x03>; + + sub-subnode { + prop =3D <0x04>; + phandle =3D <0x03>; + }; + }; +}; diff --git a/tests/metadata_addon_references.dtb.expect b/tests/metadata_ad= don_references.dtb.expect new file mode 100644 index 0000000..d8db6cb --- /dev/null +++ b/tests/metadata_addon_references.dtb.expect @@ -0,0 +1,48 @@ +/dts-v1/; +/addon/; + +/ { + sub-node { + ref1-base1 =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref1-base1[0], ref =3D base1 + ref2-base1-addon-node =3D <0x00000001>; + // [FDT_REF_LOCAL] ref2-base1-addon-node[0] + ref3-base1-addon-node =3D <0x00000001>; + // [FDT_REF_LOCAL] ref3-base1-addon-node[0] + ref4-base1-addon-node =3D <0x00000001>; + // [FDT_REF_LOCAL] ref4-base1-addon-node[0] + ref5-base3 =3D <0x00000002>; + // [FDT_REF_LOCAL] ref5-base3[0] + ref6-base3 =3D <0x00000002>; + // [FDT_REF_LOCAL] ref6-base3[0] + ref7-base3-subsubnode =3D <0x00000003>; + // [FDT_REF_LOCAL] ref7-base3-subsubnode[0] + phandle =3D <0x00000004>; + }; +}; +&base1 { + addon-node { + prop =3D <0x00000002>; + phandle =3D <0x00000001>; + }; +}; +&base2 { + addon-node1 { + ref-base1-addon-node =3D <0x00000001>; + // [FDT_REF_LOCAL] ref-base1-addon-node[0] + }; + addon-node2 { + ref-root-sub-node =3D <0x00000004>; + // [FDT_REF_LOCAL] ref-root-sub-node[0] + }; +}; +&base3 { + phandle =3D <0x00000002>; + sub-node { + prop =3D <0x00000003>; + sub-subnode { + prop =3D <0x00000004>; + phandle =3D <0x00000003>; + }; + }; +}; diff --git a/tests/metadata_addon_references.dts b/tests/metadata_addon_ref= erences.dts new file mode 100644 index 0000000..239c141 --- /dev/null +++ b/tests/metadata_addon_references.dts @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + sub_node: sub-node { + ref1-base1 =3D <&base1>; + ref2-base1-addon-node =3D <&b1_addon>; + ref3-base1-addon-node =3D <&{$base1/addon-node}>; + ref4-base1-addon-node =3D <&{$base1/addon-node/}>; + ref5-base3 =3D <&{$base3}>; + ref6-base3 =3D <&{$base3/}>; + ref7-base3-subsubnode =3D <&{$base3/sub-node/sub-subnode}>; + }; +}; + +&base1 { + b1_addon: addon-node { + prop =3D <2>; + }; +}; + +&base2 { + addon-node1 { + ref-base1-addon-node =3D <&b1_addon>; + }; + addon-node2 { + ref-root-sub-node =3D <&sub_node>; + }; +}; + +&base3 { + sub-node { + prop =3D <3>; + sub-subnode { + prop =3D <4>; + }; + }; +}; diff --git a/tests/metadata_addon_references.dts.dts.expect b/tests/metadat= a_addon_references.dts.dts.expect new file mode 100644 index 0000000..dff893e --- /dev/null +++ b/tests/metadata_addon_references.dts.dts.expect @@ -0,0 +1,48 @@ +/dts-v1/; +/addon/; + +/ { + + sub_node: sub-node { + ref1-base1 =3D <&base1>; + ref2-base1-addon-node =3D <&b1_addon>; + ref3-base1-addon-node =3D <&{$base1/addon-node}>; + ref4-base1-addon-node =3D <&{$base1/addon-node/}>; + ref5-base3 =3D <&{$base3}>; + ref6-base3 =3D <&{$base3/}>; + ref7-base3-subsubnode =3D <&{$base3/sub-node/sub-subnode}>; + phandle =3D <0x04>; + }; +}; + +&base1 { + + b1_addon: addon-node { + prop =3D <0x02>; + phandle =3D <0x01>; + }; +}; + +&base2 { + + addon-node1 { + ref-base1-addon-node =3D <&b1_addon>; + }; + + addon-node2 { + ref-root-sub-node =3D <&sub_node>; + }; +}; + +&base3 { + phandle =3D <0x02>; + + sub-node { + prop =3D <0x03>; + + sub-subnode { + prop =3D <0x04>; + phandle =3D <0x03>; + }; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 12418bf..a371377 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1129,7 +1129,7 @@ metadata_tests() { metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ metadata_addon_orphan1 metadata_addon_orphan2 \ - metadata_addon_orphan3; do + metadata_addon_orphan3 metadata_addon_references; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 011C836B072; Mon, 12 Jan 2026 14:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227725; cv=none; b=f/FHiEMkVqDl3v12Rhqbm4IH0g8yCt5vFm5ik9iNxhgbP0WnkhSTOaeCFUDHI1xxlsrGOU3GcGzX8s6ozX3eevQwq3EbkBhTIKDGWsX3Q1zDT8geD4JTokkYstU3Zurr4rFYcLHO7LWW7deoqq+ZXDHs5itL4NqfilSe0xobnxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227725; c=relaxed/simple; bh=eXC6KiPRSYiUbdw5x5z03oKynbhr5u+FK7p6Aso0CQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o7Mdc7vOyYbfP3xWS5/fifVTtgNUE58RqtDHYxr9erCxpcwanuZxSLFgvg9Js0xj9RWs/CoyE2dhrh6CTwJl5UbSq1vtSSg0NKHzrsuet+Meno92HPIq8Cb8wcgGiFq18X18wV23PAraK9M4DXrG/qK3PdcaoqaozcpIUtBzBeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=OmVNvFG8; arc=none smtp.client-ip=185.246.85.4 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.b="OmVNvFG8" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id BFD164E42088; Mon, 12 Jan 2026 14:22:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 94A74606FA; Mon, 12 Jan 2026 14:22:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 6A798103C9260; Mon, 12 Jan 2026 15:22:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227721; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=2X1bVWB5ni5ZlaBKphLXnDg0oYmAUpV1QfsFhnR66KE=; b=OmVNvFG8RZytEjMDSF7NwiZDaybBKcH8AzhWWGQGXEjlkLd73zwdJj78k1RA1jNrX4jUxo gcdcZuTlUgF6vihsT3WxBaj2aYhzGkfonifwc6osFlZrzQ2UKS+Dmm6GULYmKS8EHwY4Zk ouTmHHCZ44RQTWDWKQ/HdFKe6uKhCyUWfuvAJu/ZC5xeNq9xrkz5E+8ArpYmqy7CgaHunf S/V4eGAy6sk0anxsVh/M4Vwfv3gWIe5CETm4lbxxeddYOSFBJCt95Kza/ESd5Bf8MSt2hv UrKZwLqZaQY9gP8cPJ6gK+k2mO94EIjx2FwbxY0qYAF+5g48S9792Gq2v4oNYA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 66/77] dtc: Add support for namespace labels references Date: Mon, 12 Jan 2026 15:19:56 +0100 Message-ID: <20260112142009.1006236-67-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Namespace labels references can only be present in addons and involves import/exported symbols. They allow to 'jump' from node to node based on exported symbols defined at each node. When a label reference contains a dot ('.') char, it becomes a namespace labels reference. For instance &foo.bar.baz is a namespace label reference. The resolution of this reference is performed in a recursive way. - Get the node referenced by foo. - From this node get the node referenced by bar in exported symbols from foo. - From this node get the node referenced by baz in exported symbols from bar. - ... The first item (foo) involves import symbols defined in the addon and export symbols defined in the node the addon is applied to. Other items involves only exported symbols in referenced nodes to perform the resolution chain. We leave the addon thanks to the first item and import symbols. Other items allow to perform jumps from node to node in the base device-tree without leaving it. The full resolution can be summarized with the following diagram: (addon DT) &foo.bar.baz | | | | | +--------------------------------------------+ | | | | +-------------------------------+ | | | | | (addon DT) | | +-> /import/ foo: --+ | | | | | | | | addon applied at | | | target node in the | | | base DT | | | | | | | | (base DT) | | | +---> target { v | | /export/ foo: &n1; | | | | | | | | v (base DT) | | n1 { v | /export/ bar: &n2; | | | v (base DT) | n2 { v /export/ baz: &n3; | | v n3 { ... }; '&foo.bar.baz' references, in the end, the n3 node from the base DT. Implement support for namespace references parsing in dtc. The resolution part is out of dtc. Indeed, dtc has no support for applying an addon. Signed-off-by: Herve Codina --- dtc-lexer.l | 13 +++++++++++++ dtc-parser.y | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/dtc-lexer.l b/dtc-lexer.l index 540bfdf..14b5488 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -232,6 +232,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_LABEL_REF; } =20 +<*>\&{LABEL}(\.{LABEL})+ { /* namespace label reference */ + DPRINT("Ref namespace: %s\n", yytext+1); + yylval.labelref =3D xstrdup(yytext+1); + return DT_LABEL_NAMESPACE_REF; + } + <*>"&{"{PATHCHAR}*\} { /* new-style path reference */ yytext[yyleng-1] =3D '\0'; DPRINT("Ref: %s\n", yytext+2); @@ -246,6 +252,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt= , ...); return DT_ORPHAN_PATH_REF; } =20 +<*>"&{\$"{LABEL}(\.{LABEL})+([/]{PATHCHAR}*)?\} { /* orphan path referenc= e */ + yytext[yyleng-1] =3D '\0'; + DPRINT("Ref (namespace) orphan path: %s\n", yytext+1); + yylval.labelref =3D xstrdup(yytext+2); + return DT_ORPHAN_PATH_REF; + } + [0-9a-fA-F]{2} { yylval.byte =3D strtol(yytext, NULL, 16); DPRINT("Byte: %02x\n", (int)yylval.byte); diff --git a/dtc-parser.y b/dtc-parser.y index 9d619cd..8c63e83 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -32,6 +32,11 @@ static bool is_ref_relative(const char *ref) return ref[0] !=3D '/' && strchr(&ref[1], '/'); } =20 +static bool is_ref_namespace(const char *ref) +{ + return strchr(ref, '.'); +} + static struct node *parser_get_node_by_ref(struct node *dt, struct node *o= rphanlist, const char *ref) { @@ -110,6 +115,7 @@ static struct node *parser_get_node_by_ref(struct node = *dt, struct node *orphanl %token DT_STRING %token DT_LABEL %token DT_LABEL_REF +%token DT_LABEL_NAMESPACE_REF %token DT_PATH_REF %token DT_ORPHAN_PATH_REF %token DT_INCBIN @@ -260,7 +266,7 @@ importdef: } ; =20 -dt_ref: DT_LABEL_REF | DT_PATH_REF; +dt_ref: DT_LABEL_REF | DT_PATH_REF | DT_LABEL_NAMESPACE_REF; =20 devicetree: '/' nodedef @@ -281,6 +287,9 @@ devicetree: else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin nor ad= don", $1); =20 + if (!(last_header_flags & DTSF_ADDON) && is_ref_namespace($1)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $1= ); + if (last_header_flags & DTSF_PLUGIN) { $$ =3D plugin_add_orphan_node( name_node(build_node(NULL, NULL, NULL, NULL), @@ -300,6 +309,10 @@ devicetree: if ((last_header_flags & (DTSF_PLUGIN | DTSF_ADDON)) && is_ref_relative= ($3)) ERROR(&@2, "Label-relative reference %s not supported in plugin nor ad= don", $3); =20 + if (!(last_header_flags & DTSF_ADDON) && is_ref_namespace($3)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $3= ); + + if (target) { add_label(&target->labels, $2); merge_nodes(target, $4); @@ -346,6 +359,25 @@ devicetree: } $$ =3D $1; } + | devicetree DT_LABEL_NAMESPACE_REF nodedef + { + struct node *target =3D parser_get_node_by_ref( + $1, parser_orphanlist, $2); + + if (!(last_header_flags & DTSF_ADDON)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $2= ); + + if (target) { + merge_nodes(target, $3); + } else { + if (last_header_flags & DTSF_ADDON) + addon_add_orphan_node(&parser_orphanlist, + orphan_node($3, $2)); + else + ERROR(&@2, "Label or path %s not found", $2); + } + $$ =3D $1; + } | devicetree DT_DEL_NODE dt_ref ';' { struct node *target =3D parser_get_node_by_ref( @@ -422,6 +454,10 @@ exportlist: exportdef: DT_EXPORT DT_LABEL dt_ref ';' { + /* Only an addon can use namespaced labels references */ + if (!(last_header_flags & DTSF_ADDON) && is_ref_namespace($3)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $3= ); + $$ =3D build_exportsym($2, $3, 0, &@$); free($2); free($3); @@ -477,6 +513,9 @@ propdata: } | propdataprefix dt_ref { + if (!(last_header_flags & DTSF_ADDON) && is_ref_namespace($2)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $2= ); + $1 =3D data_add_marker($1, TYPE_STRING, $2); $$ =3D data_add_marker($1, REF_PATH, $2); } @@ -582,13 +621,17 @@ arrayprefix: { uint64_t val =3D ~0ULL >> (64 - $1.bits); =20 - if ($1.bits =3D=3D 32) + if ($1.bits =3D=3D 32) { + if (!(last_header_flags & DTSF_ADDON) && is_ref_namespace($2)) + ERROR(&@2, "Namespaced label reference %s supported only in addon", $= 2); + $1.data =3D data_add_marker($1.data, REF_PHANDLE, $2); - else + } else { ERROR(&@2, "References are only allowed in " "arrays with 32-bit elements."); + } =20 $$.data =3D data_append_integer($1.data, val, $1.bits); } --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A56F336BCCF; Mon, 12 Jan 2026 14:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227727; cv=none; b=TrCO0lXaTh0x3/KAO+v6q15mGET5Gs++Umiq4nnWmJuo5KnnKDMf9J9N6yWDP5yrmERUVm9JqOWNk7hPt0dEX4Z279u8O0eLGO2bY0yYq9JEI48ZzlM1O/5jL92/iSOmF7BPHLBfkF3LqBkAWyK61bh1ZeDlXRAkb3mwTMQeugU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227727; c=relaxed/simple; bh=cgsbGpr650vhAbxQnzhK3YmbGYPL57A3kTQjBjqeecI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SjDTxRzDjmhrRVcPWiC7K/C6ZhI8EHA73RJTKnXcUSey5TJ9KFOlzczJvgVivYxI07vvW2M7cGXiNVebaJQfQnqVXHVeuNLF44KJOFDVljxsFJUuUjNRgjb5SBepjg7xpCFbK/WNHs6vbl/Vlf3X9HUKTfMeilnjKmD6ypjzU88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=p3D5geHJ; arc=none smtp.client-ip=185.246.85.4 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.b="p3D5geHJ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 78CD24E42094; Mon, 12 Jan 2026 14:22:04 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 439AA606FA; Mon, 12 Jan 2026 14:22:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 11454103C8C61; Mon, 12 Jan 2026 15:22:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227723; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Alu/YSztR2sY7lzG9eizkb540piqJA1gU9XBD5NQ508=; b=p3D5geHJNej93Rh8JkHGSWUmKkhprm/N02OR5jKHFJHIkpGWqlWRvGK22oXJLPgwg4UOvP BCJ2c0M431/xLJmx7PFf9bhsUZe/TeUe08upwmt9m4SUehF9kYCN8XkA5mP5by4w9Azrze 5oOBqyXPK/xsAlnsbfodU17JiYimpFD4k3W/mpgO7F6xZpdKyGixmqOtILF5BLtoxzkEvv ShP9uwMDA0kwDFg8ej8LuH1ERvd1J2adgsuHZyrgUfIhhT45sDW4LYMRaY1IZjEHpc9KeB 1WIXgvNmWJWRR5SzyWREpIRpQquJ9jLnVTcv0rJim8AwpdTfcT9+jMPKRXT4eQ== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 67/77] tests: metadata: Add a test for namespace labels references Date: Mon, 12 Jan 2026 15:19:57 +0100 Message-ID: <20260112142009.1006236-68-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Namespace labels references are references in the form '&foo.bar.baz'. Support for namespace labels references has been recently added to dtc. Add a test related to this kind of references. Signed-off-by: Herve Codina --- ...metadata_addon_refnamespace.dtb.dts.expect | 32 ++++++++++++++++ tests/metadata_addon_refnamespace.dtb.expect | 29 ++++++++++++++ tests/metadata_addon_refnamespace.dts | 38 +++++++++++++++++++ ...metadata_addon_refnamespace.dts.dts.expect | 32 ++++++++++++++++ tests/run_tests.sh | 3 +- 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_refnamespace.dtb.dts.expect create mode 100644 tests/metadata_addon_refnamespace.dtb.expect create mode 100644 tests/metadata_addon_refnamespace.dts create mode 100644 tests/metadata_addon_refnamespace.dts.dts.expect diff --git a/tests/metadata_addon_refnamespace.dtb.dts.expect b/tests/metad= ata_addon_refnamespace.dtb.dts.expect new file mode 100644 index 0000000..111a746 --- /dev/null +++ b/tests/metadata_addon_refnamespace.dtb.dts.expect @@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + + addon-node { + ref0 =3D <&foo.x.y>; + ref1 =3D <0x0a &bar.other 0x14>; + ref2 =3D <&{$foo.x.y.z/addon-node}>; + ref3 =3D <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + + addon-node { + prop =3D <0x00>; + phandle =3D <0x01>; + }; +}; + +&foo.x.y { + + node { + prop1 =3D <0x01>; + prop2 =3D <0x02>; + }; +}; diff --git a/tests/metadata_addon_refnamespace.dtb.expect b/tests/metadata_= addon_refnamespace.dtb.expect new file mode 100644 index 0000000..5fceb61 --- /dev/null +++ b/tests/metadata_addon_refnamespace.dtb.expect @@ -0,0 +1,29 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'foo' (abc,foo) +// [FDT_IMPORT_SYM] 'bar' (abc,bar) +&foo.x { + addon-node { + ref0 =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref0[0], ref =3D foo.x.y + ref1 =3D <0x0000000a 0xffffffff 0x00000014>; + // [FDT_REF_PHANDLE] ref1[4], ref =3D bar.other + ref2 =3D <0x00000001>; + // [FDT_REF_LOCAL] ref2[0] + ref3 =3D <0x00000001>; + // [FDT_REF_LOCAL] ref3[0] + }; +}; +&foo.x.y.z { + addon-node { + prop =3D <0x00000000>; + phandle =3D <0x00000001>; + }; +}; +&foo.x.y { + node { + prop1 =3D <0x00000001>; + prop2 =3D <0x00000002>; + }; +}; diff --git a/tests/metadata_addon_refnamespace.dts b/tests/metadata_addon_r= efnamespace.dts new file mode 100644 index 0000000..51a17a9 --- /dev/null +++ b/tests/metadata_addon_refnamespace.dts @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + addon-node { + ref0 =3D <&foo.x.y>; + ref1 =3D <10 &bar.other 20>; + ref2 =3D <&addon_node>; + ref3 =3D <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + addon_node: addon-node { + prop =3D <0>; + }; +}; + +&foo.x.y { + node { + prop1 =3D <1>; + }; +}; + +&foo.x.y { + node { + prop2 =3D <2>; + }; +}; diff --git a/tests/metadata_addon_refnamespace.dts.dts.expect b/tests/metad= ata_addon_refnamespace.dts.dts.expect new file mode 100644 index 0000000..94861c3 --- /dev/null +++ b/tests/metadata_addon_refnamespace.dts.dts.expect @@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + + addon-node { + ref0 =3D <&foo.x.y>; + ref1 =3D <0x0a &bar.other 0x14>; + ref2 =3D <&addon_node>; + ref3 =3D <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + + addon_node: addon-node { + prop =3D <0x00>; + phandle =3D <0x01>; + }; +}; + +&foo.x.y { + + node { + prop1 =3D <0x01>; + prop2 =3D <0x02>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index a371377..4392752 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1129,7 +1129,8 @@ metadata_tests() { metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ metadata_addon_orphan1 metadata_addon_orphan2 \ - metadata_addon_orphan3 metadata_addon_references; do + metadata_addon_orphan3 metadata_addon_references \ + metadata_addon_refnamespace; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts" --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED1F82EB859; Mon, 12 Jan 2026 14:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227728; cv=none; b=HkBQDeEZH3VjF5h+iEF7ilY/6CpZAaJmfWNXa0ilM86tU4CgfMub3ufE5A85c1R4AV5ShtCiy9o2SBIQczzECMdMmLGxuALRGgu4LNAUF24GI92ZFCSj3u4tg6o8gqY2kOk35LAyBwniU9aiOmmL79nbU3nxw63r+Tkf+5JZFf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227728; c=relaxed/simple; bh=EtANzcsF/O/2N5SLag/+pz1k0e53qUoqWM+zsTEUjow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qYVavabPKAnRPs9E0CkepYwKXUOcGuMOcYU2FLiCgnKe2pqKUubv40Rt63gqHHvngUrvJ+2locJBLYWntPokZh3rWG1EtF8Q5+4edHp46cUfGVjEum9l71IoItbIN/luTYVudTmTiUW1YckIWL/cnB8+MkFXPl5Xu1AF1QREhmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=b8PgCqiU; arc=none smtp.client-ip=185.171.202.116 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.b="b8PgCqiU" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 3291CC20868; Mon, 12 Jan 2026 14:21:39 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A9322606FA; Mon, 12 Jan 2026 14:22:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 84BFF103C8CD8; Mon, 12 Jan 2026 15:22:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227724; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=s4b4iORTYC9hNJsnJAA2UlqWslsOWy9woQFtPV4DXtQ=; b=b8PgCqiUSbJRdvrnhV5mLwXdSlnlOmIECE/PC/8W3D9cPuR2Fy3b52oi8VUesswcubVheX RZKleOjfjI0M2jK0yW3sUBAtpSfJNdAqgdKKBjSLwRBiISraqX27xHtSI8GC2honylOFBL jk1ZM2HRIEAh6WNxcSdbCiGzf9rWSyjdmoKsJvEFbWEzeR2cjhE0o30YOTDz4/xc/dgI2B YDoVNcSTO3rDtM7Ouj+uLeh4LXUiO2nfF8uGFIczXjXG7yO3n31av2ClaPatQSnTEw/WoT oCZ4nvrpSpDodPYBEpeJdp1gY/zlmcijnY5nKbWEjhD2FZBP7ZFgRhtPBm5P1g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 68/77] libfdt: Introduce fdt_getprop_by_offset_w() Date: Mon, 12 Jan 2026 15:19:58 +0100 Message-ID: <20260112142009.1006236-69-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future support for applying a addon on a base device-tree needs to modify properties retrieved by their offset. fdt_getprop_by_offset() already exists to get a preperty by its offset but the property returned is read-only. A writable returned property is needed. Fill the lack and introduce fdt_getprop_by_offset_w(), the write enabled variant of fdt_getprop_by_offset(). Signed-off-by: Herve Codina --- libfdt/libfdt.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index 37459a6..0c654b1 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -858,6 +858,12 @@ static inline struct fdt_property *fdt_get_property_w(= void *fdt, int nodeoffset, #ifndef SWIG /* This function is not useful in Python */ const void *fdt_getprop_by_offset(const void *fdt, int offset, const char **namep, int *lenp); +static inline void *fdt_getprop_by_offset_w(const void *fdt, int offset, + const char **namep, int *lenp) +{ + return (void *)(uintptr_t)fdt_getprop_by_offset(fdt, offset, namep, + lenp); +} #endif =20 /** --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D3936C0AB for ; Mon, 12 Jan 2026 14:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227730; cv=none; b=rHA1nSuOyp7Zng8HMBNvfbt5zWv3rR4hOPH8FUEAlrZCsAJ/wA1V7U0/aD7BgDUNUo5SIEzmB+BVmUPND0j0ivWcZUd+zu49lcHNqnUYyyKGKVyPNazF1ICMmKuhNl4KjHoR022ALSp1leORq7T9WmLjBjF1sF2+Nd8oKfrYJi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227730; c=relaxed/simple; bh=BodRR0JLTYY6t0tgi82Yb1qLdxJmPnMZpxveitB/wWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IGPppMpnZNtjDc4DrUwadaraaN3FG/Ws4CnCF5LFHk5eIm9iLaxCcfasDvz528fltW7dsk3V1Yg1jUE1bfq06K982nVxZoBoWb06yMK0w22VUFx2h2Ivni0DIfwDV3A2L0FZs814+B8vhXZO9tJ1pCyhQTYTBjfuQjdDmncgjIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=emZPgjgX; arc=none smtp.client-ip=185.246.85.4 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.b="emZPgjgX" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A33694E42099; Mon, 12 Jan 2026 14:22:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7958D606FA; Mon, 12 Jan 2026 14:22:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 38DA6103C9262; Mon, 12 Jan 2026 15:22:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227726; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=+tpUvICqLTg4ne1424M0U3kZMx9D8QPY+u/h0GqVlU0=; b=emZPgjgXIGvyoBOtXljJb9rbpywSIyF5CBmOwMyrpFxyR2gkcRfzhr9USMNIaYHrH8jwJU aJbze09cRUZe1z1O/j23V6/yvkAfHzxv78HRffOrFkyIMQBHFMA676Ja//EdPd6+AT5+Wu 6QwGj6eOGU+rqiaE47UzdpL+ROalzzo1UqgJdZYP4ljp9mxInlf50jga6x+rCknzAQ5SJH +2tp4i3zkqza4ScZGJfT31Q0hNE72D89N5prCjZsBOjfHmI+du6pNPbH+2auJCR57tdjTP M15imWX7dTlgQJuR9qqjVCUi8UkL2e1bLvGhEcx2zsdcd3WCXFy3zlL+4yS61g== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 69/77] libfdt: Introduce fdt_getprop_offset() Date: Mon, 12 Jan 2026 15:19:59 +0100 Message-ID: <20260112142009.1006236-70-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The future support for applying a addon on a base device-tree needs to get an offset to a property based on the node offset and the property name. Several function exists to get a property but none of them allows to get the property offset. Fill the lack and introduce fdt_getprop_offset() Signed-off-by: Herve Codina --- libfdt/fdt_ro.c | 12 ++++++++++++ libfdt/libfdt_internal.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 63494fb..29692f9 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -508,6 +508,18 @@ const void *fdt_getprop(const void *fdt, int nodeoffse= t, return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); } =20 +int fdt_getprop_offset(const void *fdt, int nodeoffset, const char *name) +{ + const struct fdt_property *prop; + int lenp, offset; + + prop =3D fdt_get_property_namelen_(fdt, nodeoffset, name, strlen(name), + &lenp, &offset); + if (!prop) + return lenp; + return offset; +} + uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) { const fdt32_t *php; diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index d80d218..499e821 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -24,6 +24,8 @@ int32_t fdt_ro_probe_(const void *fdt); int fdt_check_node_offset_(const void *fdt, int offset); int fdt_check_prop_offset_(const void *fdt, int offset); =20 +int fdt_getprop_offset(const void *fdt, int nodeoffset, const char *name); + const char *fdt_find_string_len_(const char *strtab, int tabsize, const ch= ar *s, int s_len); static inline const char *fdt_find_string_(const char *strtab, int tabsize, --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D0482EBDC0 for ; Mon, 12 Jan 2026 14:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227734; cv=none; b=USTPjExOjzrhlxod7wt2X+f/rYOyuxm8hnStIIZcfkVtI9YGIOP7s7kR8A6j5p5c+0tPI4KcFxBK5xRRI6hco3yGok+8AXe+LXdS9qq3+JzXmOwVHPKPfyHCuJYEnTSCcNuPppqJ9zN7J9DoOhkFFGGh75JMSp3ahbVQWgEhmmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227734; c=relaxed/simple; bh=EF/HO95O51FxshzuC7bKLh5QupHvZYGFwAMUFdr5Q/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BQfgvZF7pqIx6t+pdlOCMOaSecmjKRQ3N68crdkogMldg6A215ofw0JWCJSM+AO3rjm9YsNUdcOfYvQEZc82zBPBBBVZQXvr8B2029M6XlnAzXd8FA1U3wmyu+MGT2v/igyG+2O0jFeRvNQel3OQpH8NKpYitDYlftG1c1k2Apk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pjchJxAK; arc=none smtp.client-ip=185.246.85.4 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.b="pjchJxAK" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 4C5684E42088; Mon, 12 Jan 2026 14:22:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 21665606FA; Mon, 12 Jan 2026 14:22:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E7E86103C8C61; Mon, 12 Jan 2026 15:22:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227728; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=8+psExkdoNg6A6QvsLqhc4STepb2gTuLxwmVgvlrCAs=; b=pjchJxAKd69EKIkx7ra324I7UU9jNyunHUv3gkTVY6mCAa8S7nqW/YL3/h/fz4SLmzuHYY d9uZ5BB7hM41D3b9gd2EGcAEcpJn1N/wmTWaF6qreR6Mt95pJw2Z20dJf3Suhd9vXG0CP6 FDeQdqilCzWrqIZ0ebmfyWjpN3Er7q57NqclHh36ShrJnv20rkOD6FsEjBA3MvmISqHj2+ pbf1JP+DGPtrmEuV9zXSX3GAcv475ZcjL5LxWNhU5t6Mov4vGFKqdu5BMz4FADCr3GjvTS z+lKvnN74HWztdFbKNcz0UWJ4V79wS6eRh1NqKK3kkADTvupl0Dk0RzqL7CEng== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 70/77] libfdt: Add support for applying an addon on a base device-tree blob Date: Mon, 12 Jan 2026 15:20:00 +0100 Message-ID: <20260112142009.1006236-71-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Addon dtbs have been recently supported. The missing part is having some support for addon usage. The goal of addons is to extend a base device-tree. This feature is similar to the overlay feature but addons and recent modifications offer metadata and import/export symbol mechanism. This import/export symbol mechanism allow a fine tuning of symbols exported (i.e. symbol seen from the addon). To extend the base device-tree, an addon needs to be applied to this base device-tree at a specific node. The specific node, target node of the addon, is not encoded in the addon dtb. Indeed, addons do not depends on the exact base device tree structure. An addon can be applied on top of any base device tree as soon as the target node matches expectations of the addon. Exported symbols at this target node has to match imported symbols defined in the addon. When the addon is applied three macro operations have to be done: - Avoid phandle conflict avoidance The conflict avoidance consists in fixing local phandle to avoid conflict with already existing phandle available in the base device-tree. This operation involved metadata recently added in dtb format. - Resolve unresolved symbols The symbol resolution consists in replacing unresolved symbol references present in the addon dtb by a reference to an existing node in the base device tree. This operation involved metadata and import/export symbols. - Merge addon nodes into base device-tree This merging consists in adding additional nodes described in the addon into the base device-tree. fdt_addon_apply() allows to apply an addon on a base device-tree and performs internally all the needed operations. Signed-off-by: Herve Codina --- libfdt/Makefile.libfdt | 2 +- libfdt/fdt_addon.c | 1636 ++++++++++++++++++++++++++++++++++++++ libfdt/fdt_rw.c | 85 ++ libfdt/libfdt.h | 32 + libfdt/libfdt_internal.h | 4 + libfdt/meson.build | 1 + libfdt/version.lds | 1 + 7 files changed, 1760 insertions(+), 1 deletion(-) create mode 100644 libfdt/fdt_addon.c diff --git a/libfdt/Makefile.libfdt b/libfdt/Makefile.libfdt index b763b2e..437d5b5 100644 --- a/libfdt/Makefile.libfdt +++ b/libfdt/Makefile.libfdt @@ -10,7 +10,7 @@ LIBFDT_soname =3D libfdt.$(SHAREDLIB_EXT).1 LIBFDT_INCLUDES =3D fdt.h libfdt.h libfdt_env.h LIBFDT_VERSION =3D version.lds LIBFDT_SRCS =3D fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c = fdt_empty_tree.c \ - fdt_addresses.c fdt_overlay.c fdt_check.c + fdt_addresses.c fdt_overlay.c fdt_addon.c fdt_check.c LIBFDT_OBJS =3D $(LIBFDT_SRCS:%.c=3D%.o) LIBFDT_LIB =3D libfdt.$(SHAREDLIB_EXT).$(DTC_VERSION) =20 diff --git a/libfdt/fdt_addon.c b/libfdt/fdt_addon.c new file mode 100644 index 0000000..351d063 --- /dev/null +++ b/libfdt/fdt_addon.c @@ -0,0 +1,1636 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * libfdt - Flat Device Tree manipulation + * Copyright (C) 2025 Bootlin + */ +#include "libfdt_env.h" + +#include +#include + +#include "libfdt_internal.h" + +/** + * fdt_skip_string - Skip a string + * @fdt: device tree blob + * @offset: Offset of the string to skip + * + * fdt_skip_string() returns the offset of the first byte after the skipped + * string. + * + * returns: + * offset of the first byte after the skipped string + */ +static int fdt_skip_string(const void *fdt, int offset) +{ + const char *p; + int next; + + next =3D offset; + do { + p =3D fdt_offset_ptr(fdt, next++, 1); + } while (p && (*p !=3D '\0')); + + return next; +} + +/** + * addon_phandle_add_offset - Increases a phandle by an offset + * @fdta: Addon device tree blob + * @node: Device tree addon blob + * @name: Name of the property to modify (phandle or linux,phandle) + * @delta: offset to apply + * + * addon_phandle_add_offset() increments a node phandle by a given + * offset. + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int addon_phandle_add_offset(void *fdta, int node, const char *name, + uint32_t delta) +{ + fdt32_t *valp, val; + int len; + + valp =3D fdt_getprop_w(fdta, node, name, &len); + if (!valp) + return len; + if (len !=3D sizeof(val)) + return -FDT_ERR_BADPHANDLE; + + val =3D fdt32_ld(valp); + if (val + delta < val || val + delta =3D=3D (uint32_t)-1) + return -FDT_ERR_NOPHANDLES; + fdt32_st(valp, val + delta); + return 0; +} + +/** + * addon_phandle_set_val - Set a phandle value + * @fdt: Addon device tree blob + * @node: Device tree addon blob + * @name: Name of the property to modify (phandle or linux,phandle) + * @val: Value to set + * + * addon_phandle_set_val() set a node phandle to a given offset. + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int addon_phandle_set_val(void *fdta, int node, const char *name, + uint32_t val) +{ + fdt32_t *valp; + int len; + + valp =3D fdt_getprop_w(fdta, node, name, &len); + if (!valp) + return len; + if (len !=3D sizeof(val)) + return -FDT_ERR_BADPHANDLE; + + fdt32_st(valp, val); + return 0; +} + +/** + * addon_property_add_offset - Increases a property value (a phandle refer= ence) + * by an offset + * @fdta: Addon device tree blob + * @prop_offset: Property to update + * @data_offset: Offset in the property data to update + * @delta: Offset to apply + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int addon_property_add_offset(void *fdta, int prop_offset, + int data_offset, uint32_t delta) +{ + char *propval; + uint32_t val; + int proplen; + fdt32_t *p; + + propval =3D fdt_getprop_by_offset_w(fdta, prop_offset, NULL, &proplen); + if (!propval) + return proplen; + if (proplen < data_offset + sizeof(fdt32_t)) + return -FDT_ERR_BADSTRUCTURE; + + /* Get the phandle pointer */ + p =3D (fdt32_t *)(propval + data_offset); + + /* Update the phandle value */ + val =3D fdt32_ld(p); + if (val + delta < val || val + delta =3D=3D (uint32_t)-1) + return -FDT_ERR_NOPHANDLES; + fdt32_st(p, val + delta); + return 0; +} + +/** + * addon_property_set_val - Set a property value (a phandle reference) + * @fdta: Addon device tree blob + * @prop_offset: Property to update + * @data_offset: Offset in the property data to update + * @value: Value to set + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int addon_property_set_val(void *fdta, int prop_offset, int data_of= fset, + uint32_t val) +{ + char *propval; + int proplen; + fdt32_t *p; + + propval =3D fdt_getprop_by_offset_w(fdta, prop_offset, NULL, &proplen); + if (!propval) + return proplen; + if (proplen < data_offset + sizeof(fdt32_t)) + return -FDT_ERR_BADSTRUCTURE; + + /* Get the phandle pointer and update it */ + p =3D (fdt32_t *)(propval + data_offset); + fdt32_st(p, val); + return 0; +} + +/** + * addon_property_replace - Replace a property value (a phandle reference)= if + * the old value matches the current value. + * @fdta: Addon device tree blob + * @prop_offset: Property to update + * @data_offset: Offset in the property data to update + * @old_val: Old value + * @new_val: New value to set if the @old_val matches + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int addon_property_replace(void *fdt, int prop_offset, int data_off= set, + uint32_t old_val, uint32_t new_val) +{ + char *propval; + uint32_t val; + int proplen; + fdt32_t *p; + + propval =3D fdt_getprop_by_offset_w(fdt, prop_offset, NULL, &proplen); + if (!propval) + return proplen; + if (proplen < data_offset + sizeof(fdt32_t)) + return -FDT_ERR_BADSTRUCTURE; + + /* Get the phandle pointer */ + p =3D (fdt32_t *)(propval + data_offset); + + val =3D fdt32_ld(p); + if (val =3D=3D old_val) + fdt32_st(p, new_val); + + return 0; +} + +/** + * addon_adjust_local_phandles - Adjust the local phandles of a whole addo= n blob + * @fdta: Addon device tree blob + * @delta: Offset to shift the phandles of + * + * addon_adjust_local_phandles() adds a constant to all the local phandles= of + * an addon. This is mainly use as part of the addon application process, = when + * we want to update all the local phandles of the addon to not conflict w= ith + * phandles of the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_adjust_local_phandles(void *fdta, uint32_t delta) +{ + int offset, next_offset; + int prop_phandle_offset; + const fdt32_t *pfdt32; + int last_prop_offset; + fdt32_t *pfdt32w; + uint32_t tag; + uint32_t val; + int ret; + + /* + * phandles that need to be updated are: + * - phandles properties in nodes + * - phandles in properties where a FDT_REF_LOCAL tag is available + * - phandles in FDT_EXPORT_SYM tags + */ + + next_offset =3D 0; + do { + offset =3D next_offset; + tag =3D fdt_next_tag_full(fdta, offset, &next_offset); + switch (tag) { + case FDT_BEGIN_NODE: + ret =3D addon_phandle_add_offset(fdta, offset, "phandle", delta); + if (ret && ret !=3D -FDT_ERR_NOTFOUND) + return ret; + + ret =3D addon_phandle_add_offset(fdta, offset, "linux,phandle", delta); + if (ret && ret !=3D -FDT_ERR_NOTFOUND) + return ret; + break; + + case FDT_END_NODE: + break; + + case FDT_PROP: + last_prop_offset =3D offset; + break; + + case FDT_NOP: + break; + + case FDT_REF_LOCAL: + /* + * The property references a phandle. Get the offset + * of this phandle reference in the property data area. + */ + pfdt32 =3D fdt_offset_ptr(fdta, offset + FDT_TAGSIZE, + sizeof(*pfdt32)); + prop_phandle_offset =3D fdt32_to_cpu(*pfdt32); + + /* Update the phandle reference */ + ret =3D addon_property_add_offset(fdta, last_prop_offset, + prop_phandle_offset, + delta); + if (ret) + return ret; + break; + + case FDT_REF_PHANDLE: + break; + + case FDT_BEGIN_NODE_REF: + break; + + case FDT_END: + ret =3D (next_offset < 0) ? next_offset : 0; + break; + + case FDT_EXPORT_SYM: + /* Skip name */ + offset +=3D FDT_TAGSIZE; + offset =3D FDT_CELLALIGN(fdt_skip_string(fdta, offset)); + + /* Get phandle pointer */ + pfdt32w =3D fdt_offset_ptr_w(fdta, offset, sizeof(*pfdt32)); + + /* Update the phandle value */ + val =3D fdt32_ld(pfdt32w); + if (val + delta < val || val + delta =3D=3D (uint32_t)-1) + return -FDT_ERR_NOPHANDLES; + + fdt32_st(pfdt32w, val + delta); + break; + + case FDT_EXPORT_SYM_REF: + break; + case FDT_IMPORT_SYM: + break; + + default: + return -FDT_ERR_BADSTRUCTURE; + } + } while (tag !=3D FDT_END); + + return ret; +} + +static int fdt_check_exportsym_offset(const void *fdt, int offset) +{ + int nextoffset; + uint32_t tag; + + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + if ((tag !=3D FDT_EXPORT_SYM) && (tag !=3D FDT_EXPORT_SYM_REF)) + return -FDT_ERR_BADOFFSET; + return nextoffset; +} + +static int fdt_next_exportsym_nextoffset_(const void *fdt, int nextoffset) +{ + uint32_t tag; + int offset; + + do { + offset =3D nextoffset; + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + switch (tag) { + case FDT_EXPORT_SYM: + return offset; + + case FDT_EXPORT_SYM_REF: + return offset; + + case FDT_BEGIN_NODE: + /* We are going to leave the current node (sub-node) */ + return -FDT_ERR_NOTFOUND; + + case FDT_BEGIN_NODE_REF: + /* We cannot have a node ref inside an other node */ + return -FDT_ERR_BADSTRUCTURE; + + case FDT_END_NODE: + /* We are going to leave the current node (parent node) */ + return -FDT_ERR_NOTFOUND; + + case FDT_END: + if (nextoffset < 0) + return nextoffset; + + return -FDT_ERR_NOTFOUND; + } + } while (tag !=3D FDT_END); + + return offset; +} + +static int fdt_next_exportsym_offset(const void *fdt, int offset) +{ + int nextoffset; + + if (offset < 0) + return offset; + + nextoffset =3D fdt_check_exportsym_offset(fdt, offset); + if (nextoffset < 0) + return nextoffset; + + return fdt_next_exportsym_nextoffset_(fdt, nextoffset); +} + +static int fdt_check_node_offset_full(const void *fdt, int node_offset) +{ + int nextoffset; + + nextoffset =3D fdt_check_node_offset_(fdt, node_offset); + if (nextoffset < 0) + return nextoffset; + + /* + * We need the export symbols meta data. + * fdt_check_node_offset_() uses fdt_next_tag() to check the node. + * fdt_next_tag() skips meta data. + * Get potential meta data using an explicitly call to + * fdt_next_tag_full() + */ + fdt_next_tag_full(fdt, node_offset, &nextoffset); + return nextoffset; +} + +static int fdt_first_exportsym_offset(const void *fdt, int node_offset) +{ + int nextoffset; + + if (node_offset < 0) + return node_offset; + + nextoffset =3D fdt_check_node_offset_full(fdt, node_offset); + if (nextoffset < 0) + return nextoffset; + + return fdt_next_exportsym_nextoffset_(fdt, nextoffset); +} + +static const char *fdt_exportsym_get_name(const void *fdt, int offset) +{ + if (fdt_check_exportsym_offset(fdt, offset) < 0) + return NULL; + + return fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, 1); +} + +static uint32_t fdt_exportsym_get_phandle(const void *fdt, int offset) +{ + const fdt32_t *pfdt32; + + if (fdt_check_exportsym_offset(fdt, offset) < 0) + return 0; + + /* Skip name */ + offset +=3D FDT_TAGSIZE; + offset =3D FDT_CELLALIGN(fdt_skip_string(fdt, offset)); + + pfdt32 =3D fdt_offset_ptr(fdt, offset, sizeof(*pfdt32)); + if (!pfdt32) + return 0; + + return fdt32_ld_(pfdt32); +} + +#define fdt_for_each_exportsym(exportsym, fdt, node) \ + for (exportsym =3D fdt_first_exportsym_offset(fdt, node); \ + exportsym >=3D 0; \ + exportsym =3D fdt_next_exportsym_offset(fdt, exportsym)) + +/** + * fdt_resolve_symbol - Resolve a symbol + * @fdt: base device tree blob + * @target_node: Target node offset in the base device tree blob containing + * the exported symbols used for the resolution. + * @sym_name: Symbol name + * @sym_namelen: Length of the symbol name + * + * fdt_resolve_symbol() searches for a matching export symbol exported by = the + * @target_node. It returns the node offset in @fdt referenced by the matc= hing + * export symbol. + * + * returns: + * offset of the node matching the symbol after the resolution on suc= cess. + * Negative error code on failure + */ +static int fdt_resolve_symbol(const void *fdt, int target_node, + const char *sym_name, int sym_namelen) +{ + const char *exportsym_name; + uint32_t phandle; + int exportsym; + int ref_node; + + /* Look at export available at the target node */ + fdt_for_each_exportsym(exportsym, fdt, target_node) { + exportsym_name =3D fdt_exportsym_get_name(fdt, exportsym); + if (!exportsym_name) + return -FDT_ERR_BADSTRUCTURE; + + phandle =3D fdt_exportsym_get_phandle(fdt, exportsym); + if ((phandle =3D=3D 0) || (phandle =3D=3D ~0U)) + return -FDT_ERR_BADPHANDLE; + + if ((strlen(exportsym_name) !=3D sym_namelen) || + (memcmp(exportsym_name, sym_name, sym_namelen) !=3D 0)) + continue; + + ref_node =3D fdt_node_offset_by_phandle(fdt, phandle); + if (ref_node < 0) + return -FDT_ERR_NOTFOUND; + + return ref_node; + } + + return -FDT_ERR_NOTFOUND; +} + +/** + * fdt_resolve_import - Resolve an imported symbol + * @fdt: base device tree blob + * @target_node: Target node offset in the base device tree blob containing + * the exported symbols used for the resolution. + * @importsym_name: Import symbol name + * @importsym_compatible: Import symbol compatible string + * + * returns: + * offset of the node matching the symbol after the resolution on suc= cess. + * Negative error code on failure. + */ +static int fdt_resolve_import(const void *fdt, int target_node, + const char *importsym_name, + const char *importsym_compatible) +{ + /* + * Do not check the import symbol compatible string against the found + * node. Indeed, the found node can be a node without any compatible + * string and this is perfectly legit. + * + * The purpose of the import symbol compatible string is to give + * information related to the symbol imported. + * + * This can be use by a driver when it wants to dynamically resolve + * imported symbols based on some specific criteria. In that case, the + * compatible string helps the driver to identify the kind of symbol + * expected by the addon. + * + * Here, in libfdt, no driver are available to perform this dynamic + * resolution. Resolve the symbol using only its name. + */ + return fdt_resolve_symbol(fdt, target_node, importsym_name, + strlen(importsym_name)); +} + +static int fdt_check_importsym_offset(const void *fdt, int offset) +{ + int nextoffset; + uint32_t tag; + + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + if (tag !=3D FDT_IMPORT_SYM) + return -FDT_ERR_BADOFFSET; + return nextoffset; +} + +static int fdt_next_importsym_nextoffset_(const void *fdt, int nextoffset) +{ + uint32_t tag; + int offset; + + do { + offset =3D nextoffset; + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + + switch (tag) { + case FDT_IMPORT_SYM: + return offset; + + case FDT_END: + if (nextoffset < 0) + return nextoffset; + + return -FDT_ERR_NOTFOUND; + } + } while (tag !=3D FDT_IMPORT_SYM); + + return offset; +} + +static int fdt_next_importsym_offset(const void *fdt, int offset) +{ + int nextoffset; + + if (offset < 0) + return offset; + + nextoffset =3D fdt_check_importsym_offset(fdt, offset); + if (nextoffset < 0) + return nextoffset; + + return fdt_next_importsym_nextoffset_(fdt, nextoffset); +} + +static int fdt_first_importsym_offset(const void *fdt) +{ + return fdt_next_importsym_nextoffset_(fdt, 0); +} + + +static const char *fdt_importsym_get_name(const void *fdt, int offset) +{ + if (fdt_check_importsym_offset(fdt, offset) < 0) + return NULL; + + return fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, 1); +} + +static const char *fdt_importsym_get_compatible(const void *fdt, int offse= t) +{ + if (fdt_check_importsym_offset(fdt, offset) < 0) + return NULL; + + /* Skip name */ + offset +=3D FDT_TAGSIZE; + offset =3D FDT_CELLALIGN(fdt_skip_string(fdt, offset)); + + return fdt_offset_ptr(fdt, offset, 1); +} + +#define fdt_for_each_importsym(importsym, fdt) \ + for (importsym =3D fdt_first_importsym_offset(fdt); \ + importsym >=3D 0; \ + importsym =3D fdt_next_importsym_offset(fdt, importsym)) + +/** + * addon_resolve_symbol - Resolve a symbol from an addon + * @fdta: Addon device tree blob. + * @fdt: base device tree blob + * @target_node: Target node the addon is applied to. This node, in the ba= se + * device tree blob, must have exported symbols needed for t= he + * resolution. + * @sym_name: Symbol name + * @sym_namelen: Length of the symbol name + * + * addon_resolve_symbol() resolved a symbol used by an addon using the imp= ort + * symbol table available in the addon device tree blob. + * + * returns: + * offset (in the fdt device tree blob) of the node matching the symb= ol + * after the resolution on success. + * Negative error code on failure. + */ +static int addon_resolve_symbol(const void *fdta, const void *fdt, int tar= get_node, + const char *sym_name, int sym_namelen) +{ + const char *importsym_compat; + const char *importsym_name; + int importsym; + + /* Look at imported symbols */ + fdt_for_each_importsym(importsym, fdta) { + importsym_name =3D fdt_importsym_get_name(fdta, importsym); + if (!importsym_name) + return -FDT_ERR_BADSTRUCTURE; + importsym_compat =3D fdt_importsym_get_compatible(fdta, importsym); + if (!importsym_compat) + return -FDT_ERR_BADSTRUCTURE; + + if ((strlen(importsym_name) !=3D sym_namelen) || + (memcmp(importsym_name, sym_name, sym_namelen) !=3D 0)) + continue; + + return fdt_resolve_import(fdt, target_node, importsym_name, + importsym_compat); + } + /* Not found ... */ + return -FDT_ERR_NOTFOUND; +} + +/** + * addon_resolve_ref - Resolve a reference from an addon + * @fdta: Addon device tree blob. + * @fdt: base device tree blob + * @target_node: Target node the addon is applied to. This node, in the ba= se + * device tree blob, must have exported symbols needed for t= he + * resolution. + * @ref: The reference to resolve + * + * addon_resolve_ref() resolves a reference used by an addon. + * A reference can be composed of several symbols separated by a '.' char. + * For instance "foo.bar.baz". To resolve this reference, addon_resolve_re= f() + * resolves the "foo" symbol the based on node retrieve from this resoluti= on, + * it resolves "bar" and so on up to the last symbol available on the refe= rence. + * + * This last symbol resolution leads to the node offset returned by + * addon_resolve_ref(). + * + * returns: + * offset (in the fdt device tree blob) of the node matching the refe= rence + * after the resolution on success. + * Negative error code on failure. + */ +static int addon_resolve_ref(const void *fdta, const void *fdt, int target= _node, + const char *ref) +{ + const char *end =3D ref + strlen(ref); + const char *r =3D ref; + const char *d; + int tmp_node; + + /* + * A reference can be "foo.bar.baz" for instance. + * In that case, we need to resolve foo from the target_node exported + * symbols then bar from exported symbols defined in the node retrieve + * from foo resolution and so on to resolve the given reference. + * + * The first symbol (foo in the previous example reference) need to be + * resolved through import symbols to "jump" from the addon to the base + * device tree. The other ones are "jumps" in the base device tree + * without leaving it and so, import symbols are not involved for them. + */ + tmp_node =3D target_node; + while (r < end) { + d =3D memchr(r, '.', end - r); + if (!d) + d =3D end; + + if (r =3D=3D ref) + tmp_node =3D addon_resolve_symbol(fdta, fdt, tmp_node, r, d-r); + else + tmp_node =3D fdt_resolve_symbol(fdt, tmp_node, r, d-r); + + if (tmp_node < 0) + return tmp_node; + + r =3D d + 1; + } + + return tmp_node; +} + +/** + * addon_resolve_phandles - Resolve addon external references + * @fdta: Addon device tree blob + * @fdt: Device tree blob the addon is going to be applied to + * @target_node: Offset of the node in fdt the addon is going to be applie= d to + * + * addon_resolve_phandles() resolved unresolved phandle symbols available = in + * the addon. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_resolve_phandles(void *fdta, const void *fdt, int target_= node) +{ + int last_prop_offset, prop_phandle_offset; + int offset, next_offset; + const fdt32_t *pfdt32; + uint32_t phandle; + fdt32_t *pfdt32w; + const char *ref; + uint32_t tag; + int ref_node; + int ret; + + /* + * phandles symbols that need to be resolved are: + * - reference in properties where a FDT_REF_PHANDLE tag is available + * - reference in export symbols + */ + + next_offset =3D 0; + do { + offset =3D next_offset; + tag =3D fdt_next_tag_full(fdta, offset, &next_offset); + switch (tag) { + case FDT_BEGIN_NODE: + break; + + case FDT_END_NODE: + break; + + case FDT_PROP: + last_prop_offset =3D offset; + break; + + case FDT_NOP: + break; + + case FDT_REF_LOCAL: + break; + + case FDT_REF_PHANDLE: + /* + * A property references an unresolver phandle. Get + * the offset of this phandle in the property data area + * and the reference of the phandle + */ + offset +=3D FDT_TAGSIZE; + pfdt32 =3D fdt_offset_ptr(fdta, offset, sizeof(*pfdt32)); + prop_phandle_offset =3D fdt32_to_cpu(*pfdt32); + + offset +=3D sizeof(*pfdt32); + ref =3D fdt_offset_ptr(fdta, offset, 1); + + /* Resolve this phandle */ + ref_node =3D addon_resolve_ref(fdta, fdt, target_node, ref); + if (ref_node < 0) + return ref_node; + + phandle =3D fdt_get_phandle(fdt, ref_node); + if ((phandle =3D=3D 0) || (phandle =3D=3D ~0U)) + return -FDT_ERR_BADPHANDLE; + + /* Update property value */ + ret =3D addon_property_set_val(fdta, last_prop_offset, + prop_phandle_offset, + phandle); + if (ret) + return ret; + + break; + + case FDT_BEGIN_NODE_REF: + break; + + case FDT_END: + ret =3D (next_offset < 0) ? next_offset : 0; + break; + + case FDT_EXPORT_SYM: + break; + + case FDT_EXPORT_SYM_REF: + /* + * The export symbol references an unresolver phandle. + * Get the offset of this phandle and the reference of + * the phandle + */ + + /* Skip name */ + offset +=3D FDT_TAGSIZE; + offset =3D FDT_CELLALIGN(fdt_skip_string(fdta, offset)); + + /* Get pointer to the phandle */ + pfdt32w =3D fdt_offset_ptr_w(fdta, offset, sizeof(*pfdt32w)); + offset +=3D sizeof(*pfdt32w); + + /* Get the reference */ + ref =3D fdt_offset_ptr(fdta, offset, 1); + + /* Resolve the phandle */ + ref_node =3D addon_resolve_ref(fdta, fdt, target_node, ref); + if (ref_node < 0) + return ref_node; + + phandle =3D fdt_get_phandle(fdt, ref_node); + if ((phandle =3D=3D 0) || (phandle =3D=3D ~0U)) + return -FDT_ERR_BADPHANDLE; + + /* Update the FDT_EXPORT_SYM_REF phandle value */ + fdt32_st(pfdt32w, phandle); + break; + + case FDT_IMPORT_SYM: + break; + + default: + return -FDT_ERR_BADSTRUCTURE; + } + } while (tag !=3D FDT_END); + + return ret; +} + +/** + * addon_replace_local_phandles - Replace the old value of phandles by a n= ew one + * for a whole addon + * @fdta: Device tree addon blob + * @old_phandle: Old phandle value + * @new_phandle: New phandle value + * + * addon_replace_local_phandles() replaces phandle values only if the + * old_phandle_value matches the current phandle value. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_replace_local_phandles(void *fdta, uint32_t old_phandle, + uint32_t new_phandle) +{ + int last_prop_offset, prop_phandle_offset; + int offset, next_offset; + const fdt32_t *pfdt32; + fdt32_t *pfdt32w; + uint32_t tag; + uint32_t val; + int ret; + + /* + * phandles that need to be updated are: + * - phandles in properties where a FDT_REF_LOCAL tag is available + * - phandles in FDT_EXPORT_SYM tags + * + * phandles properties in nodes are replace by + * addon_prevent_phandle_overwrite_node() + */ + + next_offset =3D 0; + do { + offset =3D next_offset; + tag =3D fdt_next_tag_full(fdta, offset, &next_offset); + switch (tag) { + case FDT_BEGIN_NODE: + /* + * "phandle" and/of "linux,phandle" properties are + * already updated by addon_prevent_phandle_overwrite_node() + * Nothing more to update here. + */ + break; + + case FDT_END_NODE: + break; + + case FDT_PROP: + last_prop_offset =3D offset; + break; + + case FDT_NOP: + break; + + case FDT_REF_LOCAL: + /* + * The property references a phandle. Get the offset + * of this phandle in the property data area. + */ + pfdt32 =3D fdt_offset_ptr(fdta, offset + FDT_TAGSIZE, sizeof(*pfdt32)); + prop_phandle_offset =3D fdt32_to_cpu(*pfdt32); + + /* Update the phandle value */ + ret =3D addon_property_replace(fdta, last_prop_offset, + prop_phandle_offset, + old_phandle, new_phandle); + if (ret) + return ret; + break; + + case FDT_REF_PHANDLE: + break; + + case FDT_BEGIN_NODE_REF: + break; + + case FDT_END: + ret =3D (next_offset < 0) ? next_offset : 0; + break; + + case FDT_EXPORT_SYM: + /* Skip name */ + offset +=3D FDT_TAGSIZE; + offset =3D FDT_CELLALIGN(fdt_skip_string(fdta, offset)); + + /* Get phandle pointer */ + pfdt32w =3D fdt_offset_ptr_w(fdta, offset, sizeof(*pfdt32)); + + /* Update the phandle value */ + val =3D fdt32_ld(pfdt32w); + if (val =3D=3D old_phandle) + fdt32_st(pfdt32w, new_phandle); + break; + + case FDT_EXPORT_SYM_REF: + break; + case FDT_IMPORT_SYM: + break; + + default: + return -FDT_ERR_BADSTRUCTURE; + } + } while (tag !=3D FDT_END); + + return ret; +} + +/** + * addon_prevent_phandle_overwrite_node - Prevents phandle overwrite for a= given + * addon node. + * @fdta: Addon Device tree blob + * @fdta_node: Node in fdta + * @fdt: Base device tree blob + * @fdt_node: Node in fdt that could be overwrite by the fdta_node + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_prevent_phandle_overwrite_node(void *fdta, int fdta_node, + const void *fdt, int fdt_node) +{ + uint32_t fdta_phandle, fdt_phandle; + int fdta_child, fdt_child; + const char *name; + int ret; + + fdta_phandle =3D fdt_get_phandle(fdta, fdta_node); + fdt_phandle =3D fdt_get_phandle(fdt, fdt_node); + + if (fdta_phandle && fdt_phandle) { + ret =3D addon_phandle_set_val(fdta, fdta_node, "phandle", fdt_phandle); + if (ret && ret !=3D -FDT_ERR_NOTFOUND) + return ret; + + ret =3D addon_phandle_set_val(fdta, fdta_node, "linux,phandle", fdt_phan= dle); + if (ret && ret !=3D -FDT_ERR_NOTFOUND) + return ret; + + ret =3D addon_replace_local_phandles(fdta, fdta_phandle, fdt_phandle); + if (ret) + return ret; + } + + fdt_for_each_subnode(fdta_child, fdta, fdta_node) { + name =3D fdt_get_name(fdta, fdta_child, NULL); + if (!name) + return -FDT_ERR_BADSTRUCTURE; + + fdt_child =3D fdt_subnode_offset(fdt, fdt_node, name); + if (fdt_child =3D=3D -FDT_ERR_NOTFOUND) { + /* + * No further overwrites possible here as the addon node + * is new node. + */ + continue; + } + + ret =3D addon_prevent_phandle_overwrite_node(fdta, fdta_child, + fdt, fdt_child); + if (ret) + return ret; + } + + return 0; +} + +static int fdt_check_orphan_offset(const void *fdt, int offset) +{ + int nextoffset; + uint32_t tag; + + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + if (tag !=3D FDT_BEGIN_NODE_REF) + return -FDT_ERR_BADOFFSET; + return nextoffset; +} + +static int fdt_next_orphan_offset(const void *fdt, int offset) +{ + int nextoffset =3D 0; + uint32_t tag; + + if (offset < 0) + return offset; + + if (offset !=3D 0) { + nextoffset =3D fdt_check_orphan_offset(fdt, offset); + if (nextoffset < 0) + return nextoffset; + } + + do { + offset =3D nextoffset; + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + + switch (tag) { + case FDT_BEGIN_NODE_REF: + return offset; + + case FDT_END: + if (nextoffset < 0) + return nextoffset; + + return -FDT_ERR_NOTFOUND; + } + } while (tag !=3D FDT_BEGIN_NODE_REF); + + return offset; +} + +static const char *fdt_orphan_get_ref(const void *fdt, int offset) +{ + if (fdt_check_orphan_offset(fdt, offset) < 0) + return NULL; + + return fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, 1); +} + +#define fdt_for_each_orphan(orphan, fdt) \ + for (orphan =3D fdt_next_orphan_offset(fdt, 0); \ + orphan >=3D 0; \ + orphan =3D fdt_next_orphan_offset(fdt, orphan)) + +static int fdt_set_tag(void *fdt, int offset, uint32_t new_tag, uint32_t *= old_tag) +{ + uint32_t oldtag; + fdt32_t *tagp; + + tagp =3D fdt_offset_ptr_w(fdt, offset, FDT_TAGSIZE); + if (!tagp) { + if (old_tag) + *old_tag =3D FDT_END; + return -FDT_ERR_BADOFFSET; + } + oldtag =3D fdt32_to_cpu(*tagp); + *tagp =3D cpu_to_fdt32(new_tag); + if (old_tag) + *old_tag =3D oldtag; + return 0; +} + +/** + * addon_prevent_phandles_overwrite - Fixes addon phandles to not overwrit= e base + * phandles + * @fdta Addon Device tree blob + * @fdt: Base Device Tree blob + * @target_node: Target node in the base device tree the addon is going to= be + * applied to + * + * Checks recursively if applying fdta overwrites phandle values in the ba= se + * fdt. When such a phandle is found, the fdta is changed to use the fdt's + * phandle value to not break references in the base. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_prevent_phandles_overwrite(void *fdta, const void *fdt, + int target_node) +{ + int fdt_orphan_target; + const char *ref; + uint32_t oldtag; + int fdta_orphan; + int ret; + /* + * addon root node is going to applied at base target_node + * Check phandles overwrite with those nodes + */ + ret =3D addon_prevent_phandle_overwrite_node(fdta, 0, + fdt, target_node); + if (ret < 0) + return ret; + + fdt_for_each_orphan(fdta_orphan, fdta) { + ref =3D fdt_orphan_get_ref(fdta, fdta_orphan); + if (!ref) + return -FDT_ERR_BADSTRUCTURE; + + fdt_orphan_target =3D addon_resolve_ref(fdta, fdt, target_node, ref); + if (fdt_orphan_target < 0) + return fdt_orphan_target; + + /* Force an orphan node to be considered as a standard node */ + ret =3D fdt_set_tag(fdta, fdta_orphan, FDT_BEGIN_NODE, &oldtag); + if (ret) + return ret; + + ret =3D addon_prevent_phandle_overwrite_node(fdta, fdta_orphan, + fdt, fdt_orphan_target); + /* Restore orphan node tag */ + fdt_set_tag(fdta, fdta_orphan, oldtag, NULL); + if (ret < 0) + return ret; + } + + return 0; +} + +static int fdt_check_propmarker_offset(const void *fdt, int offset) +{ + int nextoffset; + uint32_t tag; + + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + if ((tag !=3D FDT_REF_LOCAL) && (tag !=3D FDT_REF_PHANDLE)) + return -FDT_ERR_BADOFFSET; + return nextoffset; +} + +static int fdt_next_propmarker_nextoffset_(const void *fdt, int nextoffset) +{ + uint32_t tag; + int offset; + + do { + offset =3D nextoffset; + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + switch (tag) { + case FDT_EXPORT_SYM: + /* We are going to leave the current property (enter an export symbol) = */ + return -FDT_ERR_NOTFOUND; + + case FDT_EXPORT_SYM_REF: + /* We are going to leave the current property (enter an export symbol) = */ + return -FDT_ERR_NOTFOUND; + + case FDT_BEGIN_NODE: + /* We are going to leave the current property (new sub-node) */ + return -FDT_ERR_NOTFOUND; + + case FDT_BEGIN_NODE_REF: + /* We cannot have a node ref inside an other node */ + return -FDT_ERR_BADSTRUCTURE; + + case FDT_END_NODE: + /* We are going to leave the current node (parent node) */ + return -FDT_ERR_NOTFOUND; + + case FDT_PROP: + /* We are going to leave the current property (enter a new property) */ + return -FDT_ERR_NOTFOUND; + + case FDT_REF_LOCAL: + return offset; + + case FDT_REF_PHANDLE: + return offset; + + case FDT_END: + if (nextoffset < 0) + return nextoffset; + + return -FDT_ERR_NOTFOUND; + } + } while (tag !=3D FDT_END); + + return offset; +} + +static int fdt_next_propmarker_offset(const void *fdt, int offset) +{ + int nextoffset; + + if (offset < 0) + return offset; + + nextoffset =3D fdt_check_propmarker_offset(fdt, offset); + if (nextoffset < 0) + return nextoffset; + + return fdt_next_propmarker_nextoffset_(fdt, nextoffset); +} + +static int fdt_check_prop_offset_full(const void *fdt, int prop_offset) +{ + int nextoffset; + + nextoffset =3D fdt_check_prop_offset_(fdt, prop_offset); + if (nextoffset < 0) + return nextoffset; + + /* + * We need the properties meta data. + * fdt_check_prop_offset_() uses fdt_next_tag() to check the property. + * fdt_next_tag() skipped meta data. + * Get potential meta data using an explicitly call to + * fdt_next_tag_full() + */ + fdt_next_tag_full(fdt, prop_offset, &nextoffset); + return nextoffset; +} + + +static int fdt_first_propmarker_offset(const void *fdt, int prop_offset) +{ + int nextoffset; + + if (prop_offset < 0) + return prop_offset; + + nextoffset =3D fdt_check_prop_offset_full(fdt, prop_offset); + if (nextoffset < 0) + return nextoffset; + + return fdt_next_propmarker_nextoffset_(fdt, nextoffset); + +} + +static int fdt_propmarker_is_ref_marker(const void *fdt, int offset) +{ + int nextoffset; + uint32_t tag; + + /* + * Only property 'reference' marker are currently supported but well + * prevent some issue that would happen if some other markers are + * add in the future. + */ + + /* A propmarker reference has to be propmarker ... */ + if (fdt_check_propmarker_offset(fdt, offset) < 0) + return 0; + + /* ... and a 'reference' */ + tag =3D fdt_next_tag_full(fdt, offset, &nextoffset); + if ((tag !=3D FDT_REF_LOCAL) && (tag !=3D FDT_REF_PHANDLE)) + return 0; + + return 1; +} + +static uint32_t fdt_propmarker_ref_get_propoffset(const void *fdt, int off= set) +{ + const fdt32_t *pfdt32; + + if (fdt_check_propmarker_offset(fdt, offset) < 0) + return ~0U; + + pfdt32 =3D fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, sizeof(*pfdt32)); + if (!pfdt32) + return ~0U; + + return fdt32_ld_(pfdt32); +} + +#define fdt_for_each_propmarker(propmarker, fdt, prop) \ + for (propmarker =3D fdt_first_propmarker_offset(fdt, prop); \ + propmarker >=3D 0; \ + propmarker =3D fdt_next_propmarker_offset(fdt, propmarker)) + +static int fdt_mark_property_ref_local(void *fdt, int fdt_property, + uint32_t propoffset) +{ + int propmarker; + uint32_t tmp; + + fdt_for_each_propmarker(propmarker, fdt, fdt_property) { + tmp =3D fdt_propmarker_ref_get_propoffset(fdt, propmarker); + if (tmp =3D=3D ~0U) + return -FDT_ERR_BADSTRUCTURE; + + if (tmp =3D=3D propoffset) + return -FDT_ERR_EXISTS; + } + + return fdt_mark_property_ref_local_(fdt, fdt_property, propoffset); +} + +static int fdt_add_exportsym(void *fdt, int fdt_node, + const char *exportsym_name, uint32_t phandle) +{ + const char *tmp; + int exportsym; + + fdt_for_each_propmarker(exportsym, fdt, fdt_node) { + tmp =3D fdt_exportsym_get_name(fdt, exportsym); + if (!tmp) + return -FDT_ERR_BADSTRUCTURE; + + if (!strcmp(tmp, exportsym_name)) + return -FDT_ERR_EXISTS; + } + + return fdt_add_exportsym_(fdt, fdt_node, exportsym_name, phandle); +} + +/** + * addon_merge_node_properties - Merges properties available in an addon n= ode + * into the base device tree node + * @fdta: Addon Device Tree blob + * @fdta_node: Addon node whose properties have to be merged + * @fdt: Base Device Tree blob + * @fdt_node: Base node the addon node properties have to be merged into + * @is_existing_node: True if the node was already existing in the base de= vice + * tree blob. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_merge_node_properties(const void *fdta, int fdta_node, + void *fdt, int fdt_node, + bool is_existing_node) +{ + uint32_t propoffset; + int fdta_property; + int fdt_property; + const char *name; + const void *prop; + int propmarker; + int prop_len; + int ret; + + fdt_for_each_property_offset(fdta_property, fdta, fdta_node) { + prop =3D fdt_getprop_by_offset(fdta, fdta_property, &name, + &prop_len); + if (prop_len =3D=3D -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + if (prop_len < 0) + return prop_len; + + if (is_existing_node) { + if (!strcmp(name, "phandle") || + !strcmp(name, "linux,phandle")) { + /* + * phandles available in both addon and base dtb + * have the same values. This is ensured by + * previous operation related to phandle + * resolution done in addon_prevent_phandles_overwrite(). + * Just skip the property merge. + */ + continue; + } + /* + * It is not allowed to add or modify properties in + * existing nodes. + */ + return -FDT_ERR_EXISTS; + } + + ret =3D fdt_setprop(fdt, fdt_node, name, prop, prop_len); + if (ret) + return ret; + + /* Retrieve the newly created fdt property offset */ + fdt_property =3D fdt_getprop_offset(fdt, fdt_node, name); + if (fdt_property < 0) + return -FDT_ERR_INTERNAL; + + fdt_for_each_propmarker(propmarker, fdta, fdta_property) { + if (!fdt_propmarker_is_ref_marker(fdta, propmarker)) + continue; + + propoffset =3D fdt_propmarker_ref_get_propoffset(fdta, propmarker); + /* + * Mark the property as a local phandle reference. + * Either it was already a local phandle reference in + * the addon or it was an external phandle reference in + * the addon and has been resolved. + * In all cases it is local in the merged device tree + * blob. + */ + ret =3D fdt_mark_property_ref_local(fdt, fdt_property, + propoffset); + if (ret) + return ret; + } + } + + return 0; +} + +/** + * addon_merge_node_exports - Merges exported symbols in an addon node + * into the base device tree node + * @fdta: Addon Device Tree blob + * @fdta_node: Addon node whose exported symbols have to be merged + * @fdt: Base Device Tree blob + * @fdt_node: Base node the addon node exported symbols have to be merged = into + * @is_existing_node: True if the node was already existing in the base de= vice + * tree blob. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_merge_node_exports(const void *fdta, int fdta_node, + void *fdt, int fdt_node, + bool is_existing_node) +{ + const char *exportsym_name; + uint32_t phandle; + int exportsym; + int ret; + + fdt_for_each_exportsym(exportsym, fdta, fdta_node) { + exportsym_name =3D fdt_exportsym_get_name(fdta, exportsym); + if (!exportsym_name) + return -FDT_ERR_BADSTRUCTURE; + + phandle =3D fdt_exportsym_get_phandle(fdta, exportsym); + if ((phandle =3D=3D 0) || (phandle =3D=3D ~0U)) + return -FDT_ERR_BADPHANDLE; + + if (is_existing_node) { + /* + * It is not allowed to add or modify export symbols in + * existing nodes. + */ + return -FDT_ERR_EXISTS; + } + + ret =3D fdt_add_exportsym(fdt, fdt_node, exportsym_name, phandle); + if (ret) + return ret; + } + + return 0; +} + + +/** + * addon_merge_node - Merges an addon node and its sub-nodes into the base + * device tree + * @fdta: Addon Device Tree blob + * @fdta_node: Addon node to be merged + * @fdt: Base Device Tree blob + * @fdt_node: Base node the addon node has to be merged into + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int addon_merge_node(const void *fdta, int fdta_node, void *fdt, + int fdt_node, bool is_existing_node) +{ + bool is_existing; + int fdta_subnode; + const char *name; + int fdt_subnode; + int ret; + + ret =3D addon_merge_node_properties(fdta, fdta_node, fdt, fdt_node, + is_existing_node); + if (ret) + return ret; + + ret =3D addon_merge_node_exports(fdta, fdta_node, fdt, fdt_node, + is_existing_node); + if (ret) + return ret; + + fdt_for_each_subnode(fdta_subnode, fdta, fdta_node) { + name =3D fdt_get_name(fdta, fdta_subnode, NULL); + + is_existing =3D false; + fdt_subnode =3D fdt_add_subnode(fdt, fdt_node, name); + if (fdt_subnode =3D=3D -FDT_ERR_EXISTS) { + is_existing =3D true; + fdt_subnode =3D fdt_subnode_offset(fdt, fdt_node, name); + if (fdt_subnode =3D=3D -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + } + + if (fdt_subnode < 0) + return fdt_subnode; + + ret =3D addon_merge_node(fdta, fdta_subnode, fdt, fdt_subnode, is_existi= ng); + if (ret) + return ret; + } + + return 0; +} + +static int addon_merge(void *fdta, void *fdt, const char *target_path) +{ + int fdt_orphan_target; + int fdta_orphan; + const char *ref; + uint32_t oldtag; + int target_node; + int ret; + + /* Get the target node from its path*/ + target_node =3D fdt_path_offset(fdt, target_path); + if (target_node < 0) + return target_node; + + /* Merge the addon root node into the base target_node */ + ret =3D addon_merge_node(fdta, 0, fdt, target_node, true); + if (ret < 0) + return ret; + + fdt_for_each_orphan(fdta_orphan, fdta) { + ref =3D fdt_orphan_get_ref(fdta, fdta_orphan); + if (!ref) + return -FDT_ERR_BADSTRUCTURE; + + fdt_orphan_target =3D addon_resolve_ref(fdta, fdt, target_node, ref); + if (fdt_orphan_target < 0) + return fdt_orphan_target; + + /* Force an orphan node to be considered as a standard node */ + ret =3D fdt_set_tag(fdta, fdta_orphan, FDT_BEGIN_NODE, &oldtag); + if (ret) + return ret; + + ret =3D addon_merge_node(fdta, fdta_orphan, fdt, fdt_orphan_target, true= ); + /* Restore orphan node tag */ + fdt_set_tag(fdta, fdta_orphan, oldtag, NULL); + if (ret < 0) + return ret; + + /* + * An orphan node has been merged. The merged node can be + * anywhere in the fdt. Depending on the location of the merged + * node in the fdt, the target node offset can be no longer + * valid. + * + * Reload the offset from the target path to have a valid value. + */ + target_node =3D fdt_path_offset(fdt, target_path); + if (target_node < 0) + return target_node; + } + + return 0; +} + +int fdt_addon_apply(void *fdt, void *fdta, const char *target) +{ + int target_node; + uint32_t delta; + int ret; + + FDT_RO_PROBE(fdt); + FDT_RO_PROBE(fdta); + + ret =3D fdt_find_max_phandle(fdt, &delta); + if (ret) + goto err; + + /* Increase all phandles in the fdta by delta */ + ret =3D addon_adjust_local_phandles(fdta, delta); + if (ret) + goto err; + + /* Get the target node */ + ret =3D fdt_path_offset(fdt, target); + if (ret < 0) + goto err; + + target_node =3D ret; + + /* Resolve phandles */ + ret =3D addon_resolve_phandles(fdta, fdt, target_node); + if (ret < 0) + goto err; + + /* Don't overwrite phandles in fdt */ + ret =3D addon_prevent_phandles_overwrite(fdta, fdt, target_node); + if (ret < 0) + goto err; + + ret =3D addon_merge(fdta, fdt, target); + if (ret < 0) + goto err; + + /* The addon has been damaged, erase its magic */ + fdt_set_magic(fdta, ~0); + + return 0; + +err: + /* The addon might have been damaged, erase its magic */ + fdt_set_magic(fdta, ~0); + + /* The base device tree might have been damaged, erase its magic */ + fdt_set_magic(fdt, ~0); + + return ret; +} diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c index 1528b33..101faaa 100644 --- a/libfdt/fdt_rw.c +++ b/libfdt/fdt_rw.c @@ -337,6 +337,91 @@ int fdt_delprop(void *fdt, int nodeoffset, const char = *name) return fdt_splice_struct_(fdt, prop, proplen, 0); } =20 +int fdt_mark_property_ref_local_(void *fdt, int fdt_property, + uint32_t propoffset) +{ + fdt32_t *markerp; + int nextoffset; + int err; + + FDT_RW_PROBE(fdt); + + nextoffset =3D fdt_check_prop_offset_(fdt, fdt_property); + if (nextoffset < 0) + return nextoffset; + + /* + * We need the properties meta data. + * fdt_check_prop_offset_() uses fdt_next_tag() to check the property. + * fdt_next_tag() skipped meta data. + * Get the tag right after the property using an explicitly call to + * fdt_next_tag_full() + */ + fdt_next_tag_full(fdt, fdt_property, &nextoffset); + if (nextoffset < 0) + return nextoffset; + + markerp =3D fdt_offset_ptr_w_(fdt, nextoffset); + + /* Insert the propmarker at next_offset */ + err =3D fdt_splice_struct_(fdt, markerp, 0, FDT_TAGSIZE + FDT_CELLSIZE); + if (err) + return err; + + *(markerp++) =3D cpu_to_fdt32(FDT_REF_LOCAL); + *markerp =3D cpu_to_fdt32(propoffset); + + return 0; +} + +int fdt_add_exportsym_(void *fdt, int nodeoffset, const char *name, + uint32_t phandle) +{ + int offset, nextoffset; + int namelen, exportlen; + uint32_t tag; + char *p; + int err; + + FDT_RW_PROBE(fdt); + + nextoffset =3D fdt_check_node_offset_(fdt, nodeoffset); + if (nextoffset < 0) + return nextoffset; + + /* + * Try to place the new export tag after the node's properties (if any) + * get_next_tag() skipped meta data and so already present meta-data + * will be skipped. + * This is ok. The new export tag will be place after potential existing + * meta data. + */ + tag =3D fdt_next_tag(fdt, nodeoffset, &nextoffset); + /* the fdt_check_node_offset_() should ensure this never hits */ + if (!can_assume(LIBFDT_FLAWLESS) && (tag !=3D FDT_BEGIN_NODE)) + return -FDT_ERR_INTERNAL; + do { + offset =3D nextoffset; + tag =3D fdt_next_tag(fdt, offset, &nextoffset); + } while ((tag =3D=3D FDT_PROP) || (tag =3D=3D FDT_NOP)); + + p =3D fdt_offset_ptr_w_(fdt, offset); + namelen =3D strlen(name); + exportlen =3D FDT_TAGSIZE + FDT_CELLALIGN(namelen+1) + FDT_CELLSIZE; + + err =3D fdt_splice_struct_(fdt, p, 0, exportlen); + if (err) + return err; + + *((fdt32_t *)p) =3D cpu_to_fdt32(FDT_EXPORT_SYM); + memset(p + FDT_TAGSIZE, 0, FDT_CELLALIGN(namelen+1)); + memcpy(p + FDT_TAGSIZE, name, namelen); + p +=3D exportlen - FDT_CELLSIZE; + *((fdt32_t *)p) =3D cpu_to_fdt32(phandle); + + return 0; +} + int fdt_add_subnode_namelen(void *fdt, int parentoffset, const char *name, int namelen) { diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index 0c654b1..f278380 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -2543,6 +2543,38 @@ int fdt_overlay_apply(void *fdt, void *fdto); int fdt_overlay_target_offset(const void *fdt, const void *fdto, int fragment_offset, char const **pathp); =20 +/** + * fdt_addon_apply - Applies a DT addon on a base DT + * @fdt: pointer to the base device tree blob + * @fdta: pointer to the device tree addon blob + * @target: target node path + * + * fdt_addon_apply() will apply the given device tree addon on the given t= arget + * node in base device tree. + * + * Expect the base device tree to be modified, even if the function + * returns an error. + * + * returns: + * 0, on success + * -FDT_ERR_NOSPACE, there's not enough space in the base device tree + * -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or + * properties in the base DT + * -FDT_ERR_BADPHANDLE, + * -FDT_ERR_BADOVERLAY, + * -FDT_ERR_NOPHANDLES, + * -FDT_ERR_INTERNAL, + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADOFFSET, + * -FDT_ERR_BADPATH, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_addon_apply(void *fdt, void *fdta, const char *target); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index 499e821..f35b506 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -25,6 +25,10 @@ int fdt_check_node_offset_(const void *fdt, int offset); int fdt_check_prop_offset_(const void *fdt, int offset); =20 int fdt_getprop_offset(const void *fdt, int nodeoffset, const char *name); +int fdt_mark_property_ref_local_(void *fdt, int fdt_property, + uint32_t propoffset); +int fdt_add_exportsym_(void *fdt, int nodeoffset, const char *name, + uint32_t phandle); =20 const char *fdt_find_string_len_(const char *strtab, int tabsize, const ch= ar *s, int s_len); diff --git a/libfdt/meson.build b/libfdt/meson.build index 68d4c1d..a6e875f 100644 --- a/libfdt/meson.build +++ b/libfdt/meson.build @@ -9,6 +9,7 @@ sources =3D files( 'fdt_check.c', 'fdt_empty_tree.c', 'fdt_overlay.c', + 'fdt_addon.c', 'fdt_ro.c', 'fdt_rw.c', 'fdt_strerror.c', diff --git a/libfdt/version.lds b/libfdt/version.lds index 7e2dde2..f83b2f9 100644 --- a/libfdt/version.lds +++ b/libfdt/version.lds @@ -83,6 +83,7 @@ LIBFDT_1.2 { fdt_overlay_target_offset; fdt_get_symbol; fdt_get_symbol_namelen; + fdt_addon_apply; local: *; }; --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA722DA760; Mon, 12 Jan 2026 14:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227735; cv=none; b=LeY3e2RewuklPkC76HQvjs82NJ84IkDaaAxtN91Qfd+QvQXGHbxQB159pPERLqetMxBF3qDWsK6ixGDOw3Z/UWp2i3MK5xWpqKUbSHA+ZTVdtMsnILgI/kuhyvtZRiE265jhFPu4WK9Z7zLtX/zTdB/rJD2Hj0rV1hhptznF71w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227735; c=relaxed/simple; bh=Sucyfoy8+Xz2IsznHku9kGLHK88fT8w0tMw6/VCHFIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3WhrJwRMMPXTAQ3HbN5lwuBamzbPzoluClbL+yOKX7n67m2tw4g2UbXn8P9W9i3ocMe1Fbl74i+BW3KAsWYSMDOnkRL2WJXOG1SlQUJ2jwR3t/cBpWM6Jb1rb8wvp7IpbPKRk/gK9Rjsv6a3TfNRnLvuUETgwTCwO3HBdnx0Ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=hby+yWLM; arc=none smtp.client-ip=185.246.85.4 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.b="hby+yWLM" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 27D714E42094; Mon, 12 Jan 2026 14:22:11 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id F067A606FA; Mon, 12 Jan 2026 14:22:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DAAEC103C8CD8; Mon, 12 Jan 2026 15:22:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227730; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=jy5RTTiCQ7Wx69xXqSkW5jY8TKudtZArBpa46lgNVqQ=; b=hby+yWLMwgNZN73qBjc4reFcDEPQrTpFFGWw7tuOAEO+rqawlUqpqDgZkJ4Z417182JDoi dj3Z5ZwV2O9Fg0S5wS+FqzK27QVWJS/BPGuAP6RoEy7ZqEHkJGBujOs08b5L/TD/s2ipXc ti1vxVQH8IbguCOzjxXD/HrHnGowubT2PsTR4e7tzNVvf9Wu9D22aVp6eLJLfI/EoWp57U O/geVXMH/l3Y9RBaEG9rstY3bkGNc3tNKYVCEv7J5onnW0t3hAUWmE9VWMmSO/6sxN7cTv vdpbfxQX2RHc3W/T2wED832TbJy+kpikAWTjfwnDh+YkdU6oelYBhpDXPIpHgg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 71/77] Add fdtaddon tool to apply an addon Date: Mon, 12 Jan 2026 15:20:01 +0100 Message-ID: <20260112142009.1006236-72-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" libfdt has support for applying an addon on top of a base device-tree. This is provided by the libfdt fdt_addon_apply() function. The fdtaddon tool is command line tool which allows to apply addon dtb file to a base device-tree dtb file. It relies on fdt_addon_apply(). Signed-off-by: Herve Codina --- Makefile | 5 ++ fdtaddon.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 2 +- 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 fdtaddon.c diff --git a/Makefile b/Makefile index 83d8220..1137cee 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,7 @@ BIN +=3D fdtdump BIN +=3D fdtget BIN +=3D fdtput BIN +=3D fdtoverlay +BIN +=3D fdtaddon =20 SCRIPTS =3D dtdiff =20 @@ -172,6 +173,7 @@ ifneq ($(MAKECMDGOALS),libfdt) -include $(FDTGET_OBJS:%.o=3D%.d) -include $(FDTPUT_OBJS:%.o=3D%.d) -include $(FDTOVERLAY_OBJS:%.o=3D%.d) +-include $(FDTADDON_OBJS:%.o=3D%.d) endif endif =20 @@ -255,6 +257,8 @@ fdtput: $(FDTPUT_OBJS) $(LIBFDT_dep) =20 fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_dep) =20 +fdtaddon: $(FDTADDON_OBJS) $(LIBFDT_dep) + dist: git archive --format=3Dtar --prefix=3Ddtc-$(dtc_version)/ HEAD \ > ../dtc-$(dtc_version).tar @@ -295,6 +299,7 @@ TESTS_BIN +=3D fdtput TESTS_BIN +=3D fdtget TESTS_BIN +=3D fdtdump TESTS_BIN +=3D fdtoverlay +TESTS_BIN +=3D fdtaddon =20 ifneq ($(MAKECMDGOALS),libfdt) include tests/Makefile.tests diff --git a/fdtaddon.c b/fdtaddon.c new file mode 100644 index 0000000..c2fefa3 --- /dev/null +++ b/fdtaddon.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Bootlin. All rights reserved. + * + * Author: + * Herve Codina + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "util.h" + +/* Usage related data. */ +static const char usage_synopsis[] =3D + "apply an addon to a base blob\n" + " fdtaddon "; +static const char usage_short_opts[] =3D "i:o:t:v" USAGE_COMMON_SHORT_OPTS; +static const struct option usage_long_opts[] =3D { + { "input", required_argument, NULL, 'i' }, + { "output", required_argument, NULL, 'o' }, + { "target", required_argument, NULL, 't' }, + { "verbose", no_argument, NULL, 'v' }, + USAGE_COMMON_LONG_OPTS, +}; +static const char *const usage_opts_help[] =3D { "Input base DT blob", + "Output DT blob", "Target node", + "Verbose messages", + USAGE_COMMON_OPTS_HELP }; + +int verbose; + +static void *do_apply(void *base, const void *addon, const char *target) +{ + void *tmp_merged; + void *tmp_addon; + size_t max_merged_size; + int ret; + + /* + * We take copies first, because a failed apply can trash + * both the base blob and the overlay. + */ + + /* + * The merged size should not be greater than the sum of the size of + * individual items. + */ + max_merged_size =3D fdt_totalsize(base) + fdt_totalsize(addon); + + tmp_merged =3D xmalloc(max_merged_size); + ret =3D fdt_open_into(base, tmp_merged, max_merged_size); + if (ret) { + fprintf(stderr, + "\nFailed to make temporary copy: %s\n", + fdt_strerror(ret)); + goto fail; + } + + tmp_addon =3D xmalloc(fdt_totalsize(addon)); + memcpy(tmp_addon, addon, fdt_totalsize(addon)); + + if (!(fdt_dt_flags(tmp_addon) & FDT_FLAG_ADDON)) { + fprintf(stderr, + "\nAddon dtb is not an 'addon'\n"); + goto fail; + } + + ret =3D fdt_addon_apply(tmp_merged, tmp_addon, target); + if (ret) { + fprintf(stderr, "\nFailed to apply %s\n", fdt_strerror(ret)); + goto fail; + } + + free(tmp_addon); + return tmp_merged; + +fail: + free(tmp_merged); + free(tmp_addon); + return NULL; +} + +static int do_fdtaddon(const char *input_filename, const char *output_file= name, + const char *addon_filename, const char *target) +{ + void *base_blob =3D NULL; + void *addon_blob =3D NULL; + void *merged_blob =3D NULL; + size_t base_buflen; + size_t addon_buflen; + int ret =3D -1; + + base_blob =3D utilfdt_read(input_filename, &base_buflen); + if (!base_blob) { + fprintf(stderr, "\nFailed to read '%s'\n", input_filename); + goto out_err; + } + if (fdt_totalsize(base_blob) > base_buflen) { + fprintf(stderr, + "\nBase blob is incomplete (%zu / %"PRIu32" bytes read)\n", + base_buflen, fdt_totalsize(base_blob)); + goto out_err; + } + + addon_blob =3D utilfdt_read(addon_filename, &addon_buflen); + if (!addon_blob) { + fprintf(stderr, "\nFailed to read '%s'\n", addon_filename); + goto out_err; + } + if (fdt_totalsize(addon_blob) > addon_buflen) { + fprintf(stderr, + "\nAddon blob is incomplete (%zu / %"PRIu32" bytes read)\n", + addon_buflen, fdt_totalsize(addon_blob)); + goto out_err; + } + + /* apply the addon */ + merged_blob =3D do_apply(base_blob, addon_blob, target); + if (!merged_blob) + goto out_err; + + fdt_pack(merged_blob); + ret =3D utilfdt_write(output_filename, merged_blob); + if (ret) + fprintf(stderr, "\nFailed to write '%s'\n", output_filename); + +out_err: + free(merged_blob); + free(addon_blob); + free(base_blob); + + return ret; +} + +int main(int argc, char *argv[]) +{ + char *input_filename =3D NULL; + char *output_filename =3D NULL; + char *addon_filename =3D NULL; + const char *target =3D NULL; + int opt; + + while ((opt =3D util_getopt_long()) !=3D EOF) { + switch (opt) { + case_USAGE_COMMON_FLAGS + + case 'i': + input_filename =3D optarg; + break; + case 'o': + output_filename =3D optarg; + break; + case 'v': + verbose =3D 1; + break; + case 't': + target =3D optarg; + break; + } + } + + if (!input_filename) + usage("missing input file"); + + if (!output_filename) + usage("missing output file"); + + if (!target) + usage("missing target"); + + argv +=3D optind; + argc -=3D optind; + + if (argc !=3D 1) + usage("missing addon file"); + + addon_filename =3D argv[0]; + + if (verbose) { + printf("input =3D %s\n", input_filename); + printf("output =3D %s\n", output_filename); + printf("addon =3D %s\n", addon_filename); + } + + if (do_fdtaddon(input_filename, output_filename, addon_filename, target)) + return 1; + + return 0; +} diff --git a/meson.build b/meson.build index 66b44e8..c108514 100644 --- a/meson.build +++ b/meson.build @@ -107,7 +107,7 @@ if get_option('tools') and not wheel_only install: true, ) =20 - foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay'] + foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay', 'fdtaddon'] dtc_tools +=3D executable(e, files(e + '.c'), dependencies: util_dep, = install: true) endforeach =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADC2236C587; Mon, 12 Jan 2026 14:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227735; cv=none; b=EzHtfB6J0Cylodn185W650h/8OB3Q9dtN5DfZCRYH/xD1A7MUawjlUAgTxlTaZ4h0NzENhOhkO1JnIIqodGKjpZ1wsuUpu2H9H82hlXtCg88OPOzQF2nPXyfp9bT9+XAcfPTSS+1uWmhlaBlxafL+dffA148Wer/jBzjCVzKR+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227735; c=relaxed/simple; bh=CaV6+LlKGRYvRL9UsbxBUGMeZd6ptcNGilWz6iyk29w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O/olmULVy85nQsnavjNMGEC+H2jEe5aMOzINCcmqemcwn9q0jr2LuIaYo5/OmVBgoQ3Oj9AmRngmY6QX+lx0UjavZqKuwpcMoLBIX8JNcysssqy47pKVjduuvpAsddabGB78SwzsPb7SCvyMCvSLxCDWmgVSC06WOsxeR9vwv5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Rs0m+J5r; arc=none smtp.client-ip=185.246.84.56 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.b="Rs0m+J5r" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 8E87C1A2810; Mon, 12 Jan 2026 14:22:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 63D1E606FA; Mon, 12 Jan 2026 14:22:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7B6B6103C9262; Mon, 12 Jan 2026 15:22:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227731; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Fec2nLC5UB9GciN3RWgleKKuS++nqoMq0WJOh/SpVL4=; b=Rs0m+J5rld3HdosKGDqL1UPFWlTCNJQNjU5HQImLt0SRwcr7GhR3KDEYoKUWNbfxdjXY/S TJm1my84s8ou3pRyw3dFdtYd1dZ0UcADhm+ltEBBHFXruSgBVx+v/TMz45uO3lbZJ31WFE cn3YrJVjlCvionZFCF2B/1GtndKvq62JCsnwa8fuoNnihdZ3poLHN9K6jrlg9JjU2EF3RN +9K2cWzTKdrZ/hUtYJGIDm54BtHsyXhxYvtkXzSa0d2CtIJN178W15wbUh4O52MM5iAN4V 9atYSAmR0iYFe/M5WINnd+mHy9frkchboRMzvCegvMkHPnWWVdzZUFPyLGk4AA== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 72/77] tests: Add a first basic test for fdtaddon Date: Mon, 12 Jan 2026 15:20:02 +0100 Message-ID: <20260112142009.1006236-73-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The fdtaddon tests family goal is to test features related the application of an addon to a base device tree. This first basic test added in fdtaddon tests is related to the application of a simple addon. The terminology used in the test is the following: - dts: A 'full' device tree source. This can be either a base device tree or a merged device tree (i.e. a base device tree where an addon has been applied to). - dtb: A 'full' device tree blob This can be either a dtb generated by dtc from a dts or the output of the fdtaddon command. - dtsa: An addon device tree source A dts with the '/addon/' keyword. - dtba: An addon device tree blob This a device tree blob generated from a dtsa. With this terminology in mind, the test pattern is the following: - Generate the base tree dtb (fdtaddon_base.dtb) - Check this generated dtb against expected contents - Generate a dtba (xxx.dtba) from an input dtsa - Check this generated dtba against expected contents - Apply the dtba to the base tree dtb at node-a1 (xxx-merged1.dtb) - Check this generated dtb against expected contents - Generate a dts (xxx-merged1.dtb.dts) from the generated xxx-merged1.dtb - Check this generated dts against expected contents - Apply the dtba to the base tree dtb at node-a2 (xxx-merged2.dtb) - Check this generated dtb against expected contents - Generate a dts (xxx-merged2.dtb.dts) from the generated xxx-merged2.dtb - Check this generated dts against expected contents Even if only one basic addon dsta is currently provided in this tests introduction, use a loop in order to ease future addition consisting in testing other features based on more complex addon dtsa. Signed-off-by: Herve Codina --- tests/fdtaddon_base.dtb.expect | 24 ++++++++++ tests/fdtaddon_base.dts | 27 +++++++++++ tests/fdtaddon_basics1-merged1.dtb.dts.expect | 35 ++++++++++++++ tests/fdtaddon_basics1-merged1.dtb.expect | 27 +++++++++++ tests/fdtaddon_basics1-merged2.dtb.dts.expect | 35 ++++++++++++++ tests/fdtaddon_basics1-merged2.dtb.expect | 27 +++++++++++ tests/fdtaddon_basics1.dtba.expect | 8 ++++ tests/fdtaddon_basics1.dtsa | 13 ++++++ tests/meson.build | 3 +- tests/run_tests.sh | 46 ++++++++++++++++++- tests/testutils.sh | 1 + 11 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 tests/fdtaddon_base.dtb.expect create mode 100644 tests/fdtaddon_base.dts create mode 100644 tests/fdtaddon_basics1-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics1-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics1-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics1-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics1.dtba.expect create mode 100644 tests/fdtaddon_basics1.dtsa diff --git a/tests/fdtaddon_base.dtb.expect b/tests/fdtaddon_base.dtb.expect new file mode 100644 index 0000000..eb8cd40 --- /dev/null +++ b/tests/fdtaddon_base.dtb.expect @@ -0,0 +1,24 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_base.dts b/tests/fdtaddon_base.dts new file mode 100644 index 0000000..3b00146 --- /dev/null +++ b/tests/fdtaddon_base.dts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + base-node { + other_a: sub-node { + prop =3D <0>; + }; + }; + + somewhere { + node_a1: node-a1 { + compatible =3D "abc,aaa"; + /export/ node_a: &node_a1; + /export/ other: &other_a; + }; + node_a2: node-a2 { + compatible =3D "abc,aaa"; + /export/ node_a: &node_a2; + /export/ other: &other_a; + }; + }; +}; diff --git a/tests/fdtaddon_basics1-merged1.dtb.dts.expect b/tests/fdtaddon= _basics1-merged1.dtb.dts.expect new file mode 100644 index 0000000..927733c --- /dev/null +++ b/tests/fdtaddon_basics1-merged1.dtb.dts.expect @@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop =3D <0x00>; + }; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +}; diff --git a/tests/fdtaddon_basics1-merged1.dtb.expect b/tests/fdtaddon_bas= ics1-merged1.dtb.expect new file mode 100644 index 0000000..bee1397 --- /dev/null +++ b/tests/fdtaddon_basics1-merged1.dtb.expect @@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop =3D <0x00000000>; + }; + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_basics1-merged2.dtb.dts.expect b/tests/fdtaddon= _basics1-merged2.dtb.dts.expect new file mode 100644 index 0000000..d85567b --- /dev/null +++ b/tests/fdtaddon_basics1-merged2.dtb.dts.expect @@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop =3D <0x00>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics1-merged2.dtb.expect b/tests/fdtaddon_bas= ics1-merged2.dtb.expect new file mode 100644 index 0000000..34a4b36 --- /dev/null +++ b/tests/fdtaddon_basics1-merged2.dtb.expect @@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop =3D <0x00000000>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics1.dtba.expect b/tests/fdtaddon_basics1.dt= ba.expect new file mode 100644 index 0000000..1102923 --- /dev/null +++ b/tests/fdtaddon_basics1.dtba.expect @@ -0,0 +1,8 @@ +/dts-v1/; +/addon/; + +/ { + addon-node { + prop =3D <0x00000000>; + }; +}; diff --git a/tests/fdtaddon_basics1.dtsa b/tests/fdtaddon_basics1.dtsa new file mode 100644 index 0000000..84621c9 --- /dev/null +++ b/tests/fdtaddon_basics1.dtsa @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + addon-node { + prop =3D <0>; + }; +}; diff --git a/tests/meson.build b/tests/meson.build index e81a2e1..f0ae98a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -141,7 +141,8 @@ run_test_types =3D [ 'fdtput', 'fdtdump', 'fdtoverlay', - 'metadata' + 'metadata', + 'fdtaddon' ] run_test_deps =3D [ dtc_tools, dumptrees_dtb, tests_exe diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 4392752..32c40cf 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1168,6 +1168,47 @@ metadata_tests() { base_run_test check_diff metadata_sort.dtb.dts "$SRCDIR/metadata_sort.dtb= .dts.expect" } =20 +run_fdtaddon_test () { + printf "fdtaddon $*: " + base_run_test wrap_test $VALGRIND $FDTADDON "$@" +} + +check_dtb () { + local dtb=3D"$1" + base_run_test wrap_fdtdump "$dtb" "$dtb.out" + sed -i '/^\/\/ [^\[]/d' "$dtb.out" + base_run_test check_diff "$dtb.out" "$SRCDIR/$dtb.expect" +} + +check_dts () { + local dts=3D"$1" + base_run_test check_diff "$dts" "$SRCDIR/$dts.expect" +} + +fdtaddon_tests() { + run_dtc_test -I dts -O dtb -o fdtaddon_base.dtb "$SRCDIR/fdtaddon_base.dt= s" + check_dtb fdtaddon_base.dtb + + for dt in fdtaddon_basics1; do + run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" + check_dtb $dt.dtba + + run_fdtaddon_test -i fdtaddon_base.dtb -o $dt-merged1.dtb \ + -t "/somewhere/node-a1" $dt.dtba + check_dtb $dt-merged1.dtb + + run_dtc_test -I dtb -O dts -o $dt-merged1.dtb.dts $dt-merged1.dtb + check_dts $dt-merged1.dtb.dts + + run_fdtaddon_test -i fdtaddon_base.dtb -o $dt-merged2.dtb \ + -t "/somewhere/node-a2" $dt.dtba + check_dtb $dt-merged2.dtb + + run_dtc_test -I dtb -O dts -o $dt-merged2.dtb.dts $dt-merged2.dtb + check_dts $dt-merged2.dtb.dts + done +} + pylibfdt_tests () { run_dtc_test -I dts -O dtb -o test_props.dtb "$SRCDIR/test_props.dts" TMP=3D/tmp/tests.stderr.$$ @@ -1207,7 +1248,7 @@ while getopts "vt:me" ARG ; do done =20 if [ -z "$TESTSETS" ]; then - TESTSETS=3D"libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtove= rlay metadata" + TESTSETS=3D"libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtove= rlay metadata fdtaddon" =20 # Test pylibfdt if the libfdt Python module is available. if ! $no_python; then @@ -1250,6 +1291,9 @@ for set in $TESTSETS; do "metadata") metadata_tests ;; + "fdtaddon") + fdtaddon_tests + ;; esac done =20 diff --git a/tests/testutils.sh b/tests/testutils.sh index 6b2f0d1..b5e121e 100644 --- a/tests/testutils.sh +++ b/tests/testutils.sh @@ -27,6 +27,7 @@ DTGET=3D${TEST_BINDIR}/fdtget DTPUT=3D${TEST_BINDIR}/fdtput FDTDUMP=3D${TEST_BINDIR}/fdtdump FDTOVERLAY=3D${TEST_BINDIR}/fdtoverlay +FDTADDON=3D${TEST_BINDIR}/fdtaddon =20 verbose_run () { if [ -z "$QUIET_TEST" ]; then --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 809AD2EC090 for ; Mon, 12 Jan 2026 14:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227737; cv=none; b=Hs84MN/JFzbwCcUDdGkoToEr8zKcf6h4WUoMCp9ffTPLDKltRGE0E8stcGr342VBSnuR4XTXjLaQmCgPKCe3R5UKkhKfmFF/WsfTXPyi9WD9jBQwAx8o3gVlKbx3r4IRJsaUcdWvFT4qRGNHOzwsF129ADrnXPdSAglnNZpmYpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227737; c=relaxed/simple; bh=lAt4uVZNdRbzX1EozzvSNLuM54ZlS0jx8jx98sUV3F4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ez2U/ZKpe1B7RJA4gw9Kiddgj/KZNmXJeTKdj99Vez5FQQk0xhcRbXPjldweVXzXREq8ktNe0FtieT7SC9v8WGZWCE0uTQEnil/ERVxXUc7dxWIhFhOE73jd+ykC0PdWP3n9ivINGwynSuKvccTh07pd6hY2b1ggsNhKOiblWvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=BUtrPGCm; arc=none smtp.client-ip=185.246.84.56 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.b="BUtrPGCm" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 643671A2815; Mon, 12 Jan 2026 14:22:14 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3A4FC606FA; Mon, 12 Jan 2026 14:22:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F13C7103C8C61; Mon, 12 Jan 2026 15:22:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227733; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=XvULYzm2XFF613WS4sfvw7F/+FRjRGtcYlZTDIIWvCM=; b=BUtrPGCmLltiS2fYsagm5u5TjcZQCyPpZyZUO+0DD3S7C0Be1vO6CmmCYtsAMuJNRCnVDA JuEcaKDZSXwBU0qOemsFuhqdyTAa1CPnfRNV9ZOgtxWfFbAalvDnjtxpz3Aw34VHP10W55 hrE76/FAySVR3FU9X+ZpDGki6XQnl+Lk/n/BAGGSzte3dhCYkYXMOd0dx9ffIk9FQ0EasW PBWwRs6nf51dcvWWKgkqhO3w0nilfqplplkhHe39dkj7ifqTsEPP9Tw4YVLEfJQ8mAayIu rQc89ZXlbKnW7qLHLXMjUKVcLJvbtJF7sauBFg7k581OlA9SO7T5wy2dhOuHTw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 73/77] tests: fdtaddon: Add a basic test for addons using an orphan nodes Date: Mon, 12 Jan 2026 15:20:03 +0100 Message-ID: <20260112142009.1006236-74-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Orphan nodes are available in addons. Add a test checking the application of an addon when orphan nodes are involved. Signed-off-by: Herve Codina --- tests/fdtaddon_basics2-merged1.dtb.dts.expect | 35 +++++++++++++++++++ tests/fdtaddon_basics2-merged1.dtb.expect | 27 ++++++++++++++ tests/fdtaddon_basics2-merged2.dtb.dts.expect | 35 +++++++++++++++++++ tests/fdtaddon_basics2-merged2.dtb.expect | 27 ++++++++++++++ tests/fdtaddon_basics2.dtba.expect | 9 +++++ tests/fdtaddon_basics2.dtsa | 15 ++++++++ tests/run_tests.sh | 2 +- 7 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 tests/fdtaddon_basics2-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics2-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics2-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics2-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics2.dtba.expect create mode 100644 tests/fdtaddon_basics2.dtsa diff --git a/tests/fdtaddon_basics2-merged1.dtb.dts.expect b/tests/fdtaddon= _basics2-merged1.dtb.dts.expect new file mode 100644 index 0000000..927733c --- /dev/null +++ b/tests/fdtaddon_basics2-merged1.dtb.dts.expect @@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop =3D <0x00>; + }; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +}; diff --git a/tests/fdtaddon_basics2-merged1.dtb.expect b/tests/fdtaddon_bas= ics2-merged1.dtb.expect new file mode 100644 index 0000000..bee1397 --- /dev/null +++ b/tests/fdtaddon_basics2-merged1.dtb.expect @@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop =3D <0x00000000>; + }; + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_basics2-merged2.dtb.dts.expect b/tests/fdtaddon= _basics2-merged2.dtb.dts.expect new file mode 100644 index 0000000..d85567b --- /dev/null +++ b/tests/fdtaddon_basics2-merged2.dtb.dts.expect @@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop =3D <0x00>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics2-merged2.dtb.expect b/tests/fdtaddon_bas= ics2-merged2.dtb.expect new file mode 100644 index 0000000..34a4b36 --- /dev/null +++ b/tests/fdtaddon_basics2-merged2.dtb.expect @@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop =3D <0x00000000>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics2.dtba.expect b/tests/fdtaddon_basics2.dt= ba.expect new file mode 100644 index 0000000..ec1582e --- /dev/null +++ b/tests/fdtaddon_basics2.dtba.expect @@ -0,0 +1,9 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +&node_a { + addon-node { + prop =3D <0x00000000>; + }; +}; diff --git a/tests/fdtaddon_basics2.dtsa b/tests/fdtaddon_basics2.dtsa new file mode 100644 index 0000000..0dc70af --- /dev/null +++ b/tests/fdtaddon_basics2.dtsa @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; + +&node_a { + addon-node { + prop =3D <0>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 32c40cf..d62496c 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1189,7 +1189,7 @@ fdtaddon_tests() { run_dtc_test -I dts -O dtb -o fdtaddon_base.dtb "$SRCDIR/fdtaddon_base.dt= s" check_dtb fdtaddon_base.dtb =20 - for dt in fdtaddon_basics1; do + for dt in fdtaddon_basics1 fdtaddon_basics2; do run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" check_dtb $dt.dtba =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7074036C5AA for ; Mon, 12 Jan 2026 14:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227738; cv=none; b=S70ZpmVzspKn68ZkxcaEKbxsHGmGDOqzYOJuZNO0AtI84jgwEUM3/UIfjKXa8XqIHSzeYmg9q05xi3pD00PQ3tHOOH5vXUA23qgha3j824yyOH8r3OnW/1rHzXfUuRiYRWjRbcW11eKaflsEyyVfFwJcuVf+YeqVNYlKjhIQa9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227738; c=relaxed/simple; bh=TL1eFLytySgWLcsIcHKihUk/htI+NzCib3bxDXJHBH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dAgLV/G519LVd0LEdhqUiNuEUZPwebnr6YkyU34J0K4LNsiSxidgNPz60c6xeTS/ZkQuTpidqKnd+7re5+9hQnEVgcCPnVFXjgVVL3Sk1dBFdo3IzRqx6yQ5J/GjCUGXlqTqnP+LBZ4gdlcGxeNmyoE6HFE+Zmrdqut0zw7oyAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YidsICga; arc=none smtp.client-ip=185.171.202.116 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.b="YidsICga" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C4E51C20869; Mon, 12 Jan 2026 14:21:48 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4787E606FA; Mon, 12 Jan 2026 14:22:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 79BF8103C8CD8; Mon, 12 Jan 2026 15:22:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227734; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=SpLwVdqXuJV7fGItvNEE3PRUDiOp+phEPj+Qq/rCeKw=; b=YidsICgaEqk/yNQa1/dXeF0s8bx3XJ+nuHqq1XPQAjkOD6w2H0nusp7LfalhsZtFg/xkC0 2TknGNIIDZgtTJg3r+Dv6B/54jimpvyoW3pSWl1sRN8G4+c1+EOdT3Iri10BD+tXHFayA2 +f8qg/87fZ4mgkhQxVHr5fHi07/kbeNxDx2Fdd6u4vW0fkIuHl6A/2T+NX1J5fXC4GOeku iE/ZqGOvqEYTLImGSJVPGvW8nQPL2IKfJhepoLUZaIOrQuS5c4B75cOCf/YtqN7KwwUX98 tAGi7t6CSpEMhg4ah1nnq3IqAlZbfEuu0wSIWa3d5xToR1ad2C6F7kJCVdWPYg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 74/77] tests: fdtaddon: Add a basic test for addons with unresolved phandle references Date: Mon, 12 Jan 2026 15:20:04 +0100 Message-ID: <20260112142009.1006236-75-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Addons can have unresolved phandle references. Those references are resolved when the addon is applied. Add a basic test for this feature. Signed-off-by: Herve Codina --- tests/fdtaddon_basics3-merged1.dtb.dts.expect | 36 +++++++++++++++++++ tests/fdtaddon_basics3-merged1.dtb.expect | 29 +++++++++++++++ tests/fdtaddon_basics3-merged2.dtb.dts.expect | 36 +++++++++++++++++++ tests/fdtaddon_basics3-merged2.dtb.expect | 29 +++++++++++++++ tests/fdtaddon_basics3.dtba.expect | 12 +++++++ tests/fdtaddon_basics3.dtsa | 17 +++++++++ tests/run_tests.sh | 2 +- 7 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 tests/fdtaddon_basics3-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics3-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics3-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics3-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics3.dtba.expect create mode 100644 tests/fdtaddon_basics3.dtsa diff --git a/tests/fdtaddon_basics3-merged1.dtb.dts.expect b/tests/fdtaddon= _basics3-merged1.dtb.dts.expect new file mode 100644 index 0000000..c1bf3cc --- /dev/null +++ b/tests/fdtaddon_basics3-merged1.dtb.dts.expect @@ -0,0 +1,36 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + ref-other =3D <&{/base-node/sub-node} 0x0a>; + prop =3D <0x00>; + }; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +}; diff --git a/tests/fdtaddon_basics3-merged1.dtb.expect b/tests/fdtaddon_bas= ics3-merged1.dtb.expect new file mode 100644 index 0000000..cb2ab03 --- /dev/null +++ b/tests/fdtaddon_basics3-merged1.dtb.expect @@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + ref-other =3D <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop =3D <0x00000000>; + }; + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_basics3-merged2.dtb.dts.expect b/tests/fdtaddon= _basics3-merged2.dtb.dts.expect new file mode 100644 index 0000000..8dc9fd2 --- /dev/null +++ b/tests/fdtaddon_basics3-merged2.dtb.dts.expect @@ -0,0 +1,36 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + ref-other =3D <&{/base-node/sub-node} 0x0a>; + prop =3D <0x00>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics3-merged2.dtb.expect b/tests/fdtaddon_bas= ics3-merged2.dtb.expect new file mode 100644 index 0000000..0bc106e --- /dev/null +++ b/tests/fdtaddon_basics3-merged2.dtb.expect @@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + ref-other =3D <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop =3D <0x00000000>; + }; + }; + }; +}; diff --git a/tests/fdtaddon_basics3.dtba.expect b/tests/fdtaddon_basics3.dt= ba.expect new file mode 100644 index 0000000..14dad9c --- /dev/null +++ b/tests/fdtaddon_basics3.dtba.expect @@ -0,0 +1,12 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon-node { + prop =3D <0x00000000>; + ref-other =3D <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref =3D other + }; +}; diff --git a/tests/fdtaddon_basics3.dtsa b/tests/fdtaddon_basics3.dtsa new file mode 100644 index 0000000..8658b45 --- /dev/null +++ b/tests/fdtaddon_basics3.dtsa @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; +/import/ other: ""; + +&node_a { + addon-node { + prop =3D <0>; + ref-other =3D <&other 10>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d62496c..65b1abe 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1189,7 +1189,7 @@ fdtaddon_tests() { run_dtc_test -I dts -O dtb -o fdtaddon_base.dtb "$SRCDIR/fdtaddon_base.dt= s" check_dtb fdtaddon_base.dtb =20 - for dt in fdtaddon_basics1 fdtaddon_basics2; do + for dt in fdtaddon_basics1 fdtaddon_basics2 fdtaddon_basics3; do run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" check_dtb $dt.dtba =20 --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6862F2BEFFD; Mon, 12 Jan 2026 14:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227740; cv=none; b=hIQDRu/B7Qv9GDfwpuiYFvUxjxEqu5+5/DmpJvkpC3QP1f2nufsX/XMR6kA0X6tw7XfZNHE3UZweBdn41QQbCScNB11v+yvUM2nuBxjba3SPp+35klEmWGdqAqS1o95+QSyyf/QJLlVpQZfSOwiR4hSJfmfk8OVOkIVSzEpKukk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227740; c=relaxed/simple; bh=5ZIAcw63WtQiQvwWK/rR4xVJc5sTLEfbXhPg9Xdcbcg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UhU+NuEpXCtxcTKR/hY2kRppRwLjMA9NECSEelkxDIeFjfKv83Q8wscPYiUk07Bdo9mf5tddy40EFc7jrOqEd5DCwIU+gdv+QzShw+daYr+1nP8MHX/ctq9FasVrl3inyqnxewhc6hfEbtk2Dv5713PPRUiQ28P/JCfUqexAH3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=li5/YBmg; arc=none smtp.client-ip=185.171.202.116 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.b="li5/YBmg" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id A1F78C2086D; Mon, 12 Jan 2026 14:21:50 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 26306606FA; Mon, 12 Jan 2026 14:22:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E21DE103C9260; Mon, 12 Jan 2026 15:22:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227736; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=OTUh/xyZWCcTuN2OhcptvNCMGXB7wKDCYNquNTS0gLs=; b=li5/YBmgTqARP3FNS8i2gEUSyQ0v4MFmbCR4/u69+SU2t/W2ojHVFuWKd7a7O8DA++ET6G pajUHJG2DvD0EwZpefyDlxwtWUx4miHphgeLnnzwljSoTxbJix8AWtfb+gUw/GUlTMTUQd Z5BDW63g/F/+YEll414Y1xS+tK9GOIMi8MD/nUXl/ElUuOq1moc8o3K7ObmWJ64G+oNKwQ B5GJuB8vceIAxbH2xHzzQkoaIl1j/cz3CQxY6UjHmJ3x8omAzCzn71+RO8KBX/gvpeWMIY 3yBsm8LLDvznmcgnS2oI7ussEW4IlS92JmkcxxUjnw/wjAiZRtrLesmPS9eoug== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 75/77] tests: fdtaddon: Add a test for addons using namespace label references Date: Mon, 12 Jan 2026 15:20:05 +0100 Message-ID: <20260112142009.1006236-76-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Namespace label references are labels in the form &foo.bar.baz Those kind of labels allow to 'jump' from node to node based on exported symbols defined at each nodes. Add a test for this feature. Signed-off-by: Herve Codina --- ...ddon_addon_namespace-merged.dtb.dts.expect | 57 +++++++++++++++++++ ...fdtaddon_addon_namespace-merged.dtb.expect | 49 ++++++++++++++++ tests/fdtaddon_addon_namespace.dtba.expect | 31 ++++++++++ tests/fdtaddon_addon_namespace.dtsa | 34 +++++++++++ tests/fdtaddon_base_namespace.dtb.expect | 29 ++++++++++ tests/fdtaddon_base_namespace.dts | 33 +++++++++++ tests/run_tests.sh | 14 +++++ 7 files changed, 247 insertions(+) create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.expect create mode 100644 tests/fdtaddon_addon_namespace.dtba.expect create mode 100644 tests/fdtaddon_addon_namespace.dtsa create mode 100644 tests/fdtaddon_base_namespace.dtb.expect create mode 100644 tests/fdtaddon_base_namespace.dts diff --git a/tests/fdtaddon_addon_namespace-merged.dtb.dts.expect b/tests/f= dtaddon_addon_namespace-merged.dtb.dts.expect new file mode 100644 index 0000000..ff0e5ff --- /dev/null +++ b/tests/fdtaddon_addon_namespace-merged.dtb.dts.expect @@ -0,0 +1,57 @@ +/dts-v1/; + +/ { + + other_n1 { + prop =3D <0x00>; + phandle =3D <0x05>; + + /export/ a: &{/other-a}; + /export/ b: &{/other-b}; + }; + + other-a { + prop =3D <0x00>; + phandle =3D <0x01>; + + addon-node-1a { + phandle =3D <0x06>; + prop =3D <0x1a>; + }; + }; + + other-b { + prop =3D <0x00>; + phandle =3D <0x02>; + + /export/ x: &{/other-x}; + }; + + other-x { + prop =3D <0x00>; + phandle =3D <0x03>; + + addon-node-1bx { + phandle =3D <0x07>; + prop =3D <0x1b>; + }; + }; + + node { + compatible =3D "abc,aaa"; + phandle =3D <0x04>; + + /export/ node: &{/node}; + /export/ n1: &{/other_n1}; + + addon-node2 { + ref-addon-n1bx =3D <&{/other-x/addon-node-1bx}>; + ref-n1bx =3D <&{/other-x}>; + }; + + addon-node1 { + ref-addon-n1a =3D <&{/other-a/addon-node-1a}>; + ref-n1a =3D <&{/other-a}>; + }; + }; +}; diff --git a/tests/fdtaddon_addon_namespace-merged.dtb.expect b/tests/fdtad= don_addon_namespace-merged.dtb.expect new file mode 100644 index 0000000..947a088 --- /dev/null +++ b/tests/fdtaddon_addon_namespace-merged.dtb.expect @@ -0,0 +1,49 @@ +/dts-v1/; + +/ { + other_n1 { + prop =3D <0x00000000>; + phandle =3D <0x00000005>; + // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'b' -> phandle 0x00000002 + }; + other-a { + prop =3D <0x00000000>; + phandle =3D <0x00000001>; + addon-node-1a { + phandle =3D <0x00000006>; + prop =3D <0x0000001a>; + }; + }; + other-b { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + // [FDT_EXPORT_SYM] 'x' -> phandle 0x00000003 + }; + other-x { + prop =3D <0x00000000>; + phandle =3D <0x00000003>; + addon-node-1bx { + phandle =3D <0x00000007>; + prop =3D <0x0000001b>; + }; + }; + node { + compatible =3D "abc,aaa"; + phandle =3D <0x00000004>; + // [FDT_EXPORT_SYM] 'node' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'n1' -> phandle 0x00000005 + addon-node2 { + ref-addon-n1bx =3D <0x00000007>; + // [FDT_REF_LOCAL] ref-addon-n1bx[0] + ref-n1bx =3D <0x00000003>; + // [FDT_REF_LOCAL] ref-n1bx[0] + }; + addon-node1 { + ref-addon-n1a =3D <0x00000006>; + // [FDT_REF_LOCAL] ref-addon-n1a[0] + ref-n1a =3D <0x00000001>; + // [FDT_REF_LOCAL] ref-n1a[0] + }; + }; +}; diff --git a/tests/fdtaddon_addon_namespace.dtba.expect b/tests/fdtaddon_ad= don_namespace.dtba.expect new file mode 100644 index 0000000..426bfe0 --- /dev/null +++ b/tests/fdtaddon_addon_namespace.dtba.expect @@ -0,0 +1,31 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node' (abc,aaa) +// [FDT_IMPORT_SYM] 'n1' () +&node { + addon-node1 { + ref-n1a =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref-n1a[0], ref =3D n1.a + ref-addon-n1a =3D <0x00000001>; + // [FDT_REF_LOCAL] ref-addon-n1a[0] + }; + addon-node2 { + ref-n1bx =3D <0xffffffff>; + // [FDT_REF_PHANDLE] ref-n1bx[0], ref =3D n1.b.x + ref-addon-n1bx =3D <0x00000002>; + // [FDT_REF_LOCAL] ref-addon-n1bx[0] + }; +}; +&n1.a { + addon-node-1a { + prop =3D <0x0000001a>; + phandle =3D <0x00000001>; + }; +}; +&n1.b.x { + addon-node-1bx { + prop =3D <0x0000001b>; + phandle =3D <0x00000002>; + }; +}; diff --git a/tests/fdtaddon_addon_namespace.dtsa b/tests/fdtaddon_addon_nam= espace.dtsa new file mode 100644 index 0000000..8c25d3d --- /dev/null +++ b/tests/fdtaddon_addon_namespace.dtsa @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node: "abc,aaa"; +/import/ n1: ""; + +&node { + addon-node1 { + ref-n1a =3D <&n1.a>; + ref-addon-n1a =3D <&addon_n1a>; + }; + + addon-node2 { + ref-n1bx =3D <&n1.b.x>; + ref-addon-n1bx =3D <&addon_n1bx>; + }; +}; + +&n1.a { + addon_n1a: addon-node-1a { + prop =3D <0x1a>; + }; +}; + +&n1.b.x { + addon_n1bx: addon-node-1bx { + prop =3D <0x1b>; + }; +}; diff --git a/tests/fdtaddon_base_namespace.dtb.expect b/tests/fdtaddon_base= _namespace.dtb.expect new file mode 100644 index 0000000..8383ab0 --- /dev/null +++ b/tests/fdtaddon_base_namespace.dtb.expect @@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + other_n1 { + prop =3D <0x00000000>; + phandle =3D <0x00000005>; + // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'b' -> phandle 0x00000002 + }; + other-a { + prop =3D <0x00000000>; + phandle =3D <0x00000001>; + }; + other-b { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + // [FDT_EXPORT_SYM] 'x' -> phandle 0x00000003 + }; + other-x { + prop =3D <0x00000000>; + phandle =3D <0x00000003>; + }; + node { + compatible =3D "abc,aaa"; + phandle =3D <0x00000004>; + // [FDT_EXPORT_SYM] 'node' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'n1' -> phandle 0x00000005 + }; +}; diff --git a/tests/fdtaddon_base_namespace.dts b/tests/fdtaddon_base_namesp= ace.dts new file mode 100644 index 0000000..e2bc4f0 --- /dev/null +++ b/tests/fdtaddon_base_namespace.dts @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + n1: other_n1 { + prop =3D <0>; + /export/ a: &other_a; + /export/ b: &other_b; + }; + + other_a: other-a { + prop =3D <0>; + }; + + other_b: other-b { + prop =3D <0>; + /export/ x: &other_x; + }; + + other_x: other-x { + prop =3D <0>; + }; + + node: node { + compatible =3D "abc,aaa"; + /export/ node: &node; + /export/ n1: &n1; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 65b1abe..2cdfd89 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1207,6 +1207,20 @@ fdtaddon_tests() { run_dtc_test -I dtb -O dts -o $dt-merged2.dtb.dts $dt-merged2.dtb check_dts $dt-merged2.dtb.dts done + + # Test namespace label reference + run_dtc_test -I dts -O dtb -o fdtaddon_base_namespace.dtb "$SRCDIR/fdtadd= on_base_namespace.dts" + check_dtb fdtaddon_base_namespace.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_addon_namespace.dtba "$SRCDIR/fdta= ddon_addon_namespace.dtsa" + check_dtb fdtaddon_addon_namespace.dtba + + run_fdtaddon_test -i fdtaddon_base_namespace.dtb -o fdtaddon_addon_namesp= ace-merged.dtb \ + -t "/node" fdtaddon_addon_namespace.dtba + check_dtb fdtaddon_addon_namespace-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_addon_namespace-merged.dtb.dts fdt= addon_addon_namespace-merged.dtb + check_dts fdtaddon_addon_namespace-merged.dtb.dts } =20 pylibfdt_tests () { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE4F36CE11 for ; Mon, 12 Jan 2026 14:22:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227742; cv=none; b=quYUIrI9oo5RcyQ/vJzwnncjVrL3yfUYQinKpFl22fcPxYZRBZtuKiwx+43m25/DYX0PL5m5X9NacSJBjC8aNV56JmCUFS5ONb06ntEYRYAOWu5gL7865bFuZdlISTa/11AwPlEkjqpdnUNP8LJn2NJnr0zz7c+kjs2te5obSBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227742; c=relaxed/simple; bh=0M8XNmBY1yKUUSlRfL8H3pbRWlYo1oD6dG5zGNIxxic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzbzD4dlqKYRuhLkGFfM9KXqXqjqwmF6X48LOx/gclFFCTwTgoYyhWvZZwxH1qrSPJSRxkRSQTRN7aozbNCxIsF9ue5/KSRIAjyIg/Fq5FZ/LTIphZmDP/+dj95sRQ//BvblbJmWYjaTWbfIzRe13v0j8SkXUWk+r9wCs1zxewM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=AX1bYBZu; arc=none smtp.client-ip=185.246.84.56 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.b="AX1bYBZu" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 9D2101A2815; Mon, 12 Jan 2026 14:22:18 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 745A1606FA; Mon, 12 Jan 2026 14:22:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 83CE9103C9261; Mon, 12 Jan 2026 15:22:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227737; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=FTTQodoOY8eHd0/51O2e4714Yyvm5TtIBXzgYmLLMp0=; b=AX1bYBZuTBQzNqTHTgpVadBAqnGF4mC78KYK83qGKO+6vDWrST4+9nIQwsI9l9qB82ZWCI 8pX75z2FY6cwuFXfAS/9ZDTDAkE2go3J9bdhv2fWJsGI4dBZjJHO1LxfnhbGsDjA4C6QJm CMb33igdfvXw9nr2vm9XnRXtA9AVvs1BTx+W5qlNGW78KdKn++8T4IXyytDBE8mK2g2YhA 6G5bTtXqKmYW9c2eHel3gzaJ6o0AR2X4C0qRCXvulNf9YpO85CzBFGvNeb3rgAWWRoYmb8 jXm30BI3V/fpU/iQA0VZwD6ACSY6CiytP1FDa12q48wF0VaPTakhsu/C3pmpfg== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 76/77] tests: fdtaddon: Add a test for using 'stacked' addons Date: Mon, 12 Jan 2026 15:20:06 +0100 Message-ID: <20260112142009.1006236-77-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Addon can be stacked on top of each other. A first addon can be applied. This first addon exports some symbols and those exported symbols can be used by a second addon. Add a test for this feature. Signed-off-by: Herve Codina --- .../fdtaddon_stack_1st-merged.dtb.dts.expect | 51 ++++++++++++++ tests/fdtaddon_stack_1st-merged.dtb.expect | 41 +++++++++++ tests/fdtaddon_stack_1st.dtba.expect | 24 +++++++ tests/fdtaddon_stack_1st.dtsa | 27 +++++++ .../fdtaddon_stack_2nd-merged.dtb.dts.expect | 70 +++++++++++++++++++ tests/fdtaddon_stack_2nd-merged.dtb.expect | 59 ++++++++++++++++ tests/fdtaddon_stack_2nd.dtba.expect | 30 ++++++++ tests/fdtaddon_stack_2nd.dtsa | 35 ++++++++++ tests/run_tests.sh | 21 ++++++ 9 files changed, 358 insertions(+) create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.expect create mode 100644 tests/fdtaddon_stack_1st.dtba.expect create mode 100644 tests/fdtaddon_stack_1st.dtsa create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.expect create mode 100644 tests/fdtaddon_stack_2nd.dtba.expect create mode 100644 tests/fdtaddon_stack_2nd.dtsa diff --git a/tests/fdtaddon_stack_1st-merged.dtb.dts.expect b/tests/fdtaddo= n_stack_1st-merged.dtb.dts.expect new file mode 100644 index 0000000..eb6ee30 --- /dev/null +++ b/tests/fdtaddon_stack_1st-merged.dtb.dts.expect @@ -0,0 +1,51 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon1-node { + ref-other =3D <&{/base-node/sub-node} 0x0a>; + prop =3D <0x00>; + + sub-node-other { + phandle =3D <0x05>; + prop =3D <0x01>; + }; + + sub-node-stack1 { + phandle =3D <0x04>; + prop =3D <0x00>; + compatible =3D "abc,bbb"; + + /export/ stack: &{/somewhere/node-a1/addon1-node/sub-node-stack1}; + /export/ other: &{/somewhere/node-a1/addon1-node/sub-node-other}; + /export/ base_other: &{/base-node/sub-node}; + }; + }; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +}; diff --git a/tests/fdtaddon_stack_1st-merged.dtb.expect b/tests/fdtaddon_st= ack_1st-merged.dtb.expect new file mode 100644 index 0000000..332bb26 --- /dev/null +++ b/tests/fdtaddon_stack_1st-merged.dtb.expect @@ -0,0 +1,41 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon1-node { + ref-other =3D <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop =3D <0x00000000>; + sub-node-other { + phandle =3D <0x00000005>; + prop =3D <0x00000001>; + }; + sub-node-stack1 { + phandle =3D <0x00000004>; + prop =3D <0x00000000>; + compatible =3D "abc,bbb"; + // [FDT_EXPORT_SYM] 'stack' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000005 + // [FDT_EXPORT_SYM] 'base_other' -> phandle 0x00000002 + }; + }; + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_stack_1st.dtba.expect b/tests/fdtaddon_stack_1s= t.dtba.expect new file mode 100644 index 0000000..1e1ce57 --- /dev/null +++ b/tests/fdtaddon_stack_1st.dtba.expect @@ -0,0 +1,24 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon1-node { + prop =3D <0x00000000>; + ref-other =3D <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref =3D other + sub-node-stack1 { + compatible =3D "abc,bbb"; + prop =3D <0x00000000>; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'stack' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + // [FDT_EXPORT_SYM_REF] 'base_other' -> 'other' + }; + sub-node-other { + prop =3D <0x00000001>; + phandle =3D <0x00000002>; + }; + }; +}; diff --git a/tests/fdtaddon_stack_1st.dtsa b/tests/fdtaddon_stack_1st.dtsa new file mode 100644 index 0000000..5529dde --- /dev/null +++ b/tests/fdtaddon_stack_1st.dtsa @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; +/import/ other: ""; + +&node_a { + addon1-node { + prop =3D <0>; + ref-other =3D <&other 10>; + stack1: sub-node-stack1 { + compatible =3D "abc,bbb"; + prop =3D <0>; + /export/ stack: &stack1; + /export/ other: &new_other; + /export/ base_other: &other; + }; + new_other: sub-node-other { + prop =3D <1>; + }; + }; +}; diff --git a/tests/fdtaddon_stack_2nd-merged.dtb.dts.expect b/tests/fdtaddo= n_stack_2nd-merged.dtb.dts.expect new file mode 100644 index 0000000..af31f05 --- /dev/null +++ b/tests/fdtaddon_stack_2nd-merged.dtb.dts.expect @@ -0,0 +1,70 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop =3D <0x00>; + phandle =3D <0x02>; + + addon2-node-base-other { + ref =3D <&{/somewhere/node-a1/addon1-node/sub-node-stack1/addon2-node}= >; + prop =3D <0x01>; + }; + }; + }; + + somewhere { + + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon1-node { + ref-other =3D <&{/base-node/sub-node} 0x0a>; + prop =3D <0x00>; + + sub-node-other { + phandle =3D <0x05>; + prop =3D <0x01>; + + addon2-node-other { + prop =3D <&{/base-node/sub-node}>; + + addon2-subnode { + prop =3D <0x02>; + }; + }; + }; + + sub-node-stack1 { + phandle =3D <0x04>; + prop =3D <0x00>; + compatible =3D "abc,bbb"; + + /export/ stack: &{/somewhere/node-a1/addon1-node/sub-node-stack1}; + /export/ other: &{/somewhere/node-a1/addon1-node/sub-node-other}; + /export/ base_other: &{/base-node/sub-node}; + + addon2-node { + phandle =3D <0x06>; + ref-other =3D <&{/somewhere/node-a1/addon1-node/sub-node-other} 0x0a= >; + prop =3D <0x00>; + }; + }; + }; + }; + + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +}; diff --git a/tests/fdtaddon_stack_2nd-merged.dtb.expect b/tests/fdtaddon_st= ack_2nd-merged.dtb.expect new file mode 100644 index 0000000..ccae793 --- /dev/null +++ b/tests/fdtaddon_stack_2nd-merged.dtb.expect @@ -0,0 +1,59 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop =3D <0x00000000>; + phandle =3D <0x00000002>; + addon2-node-base-other { + ref =3D <0x00000006>; + // [FDT_REF_LOCAL] ref[0] + prop =3D <0x00000001>; + }; + }; + }; + somewhere { + node-a1 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon1-node { + ref-other =3D <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop =3D <0x00000000>; + sub-node-other { + phandle =3D <0x00000005>; + prop =3D <0x00000001>; + addon2-node-other { + prop =3D <0x00000002>; + // [FDT_REF_LOCAL] prop[0] + addon2-subnode { + prop =3D <0x00000002>; + }; + }; + }; + sub-node-stack1 { + phandle =3D <0x00000004>; + prop =3D <0x00000000>; + compatible =3D "abc,bbb"; + // [FDT_EXPORT_SYM] 'stack' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000005 + // [FDT_EXPORT_SYM] 'base_other' -> phandle 0x00000002 + addon2-node { + phandle =3D <0x00000006>; + ref-other =3D <0x00000005 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop =3D <0x00000000>; + }; + }; + }; + }; + node-a2 { + compatible =3D "abc,aaa"; + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +}; diff --git a/tests/fdtaddon_stack_2nd.dtba.expect b/tests/fdtaddon_stack_2n= d.dtba.expect new file mode 100644 index 0000000..dbb8afa --- /dev/null +++ b/tests/fdtaddon_stack_2nd.dtba.expect @@ -0,0 +1,30 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'stack' (abc,bbb) +// [FDT_IMPORT_SYM] 'other' () +// [FDT_IMPORT_SYM] 'base_other' () +&stack { + addon2-node { + prop =3D <0x00000000>; + ref-other =3D <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref =3D other + phandle =3D <0x00000001>; + }; +}; +&other { + addon2-node-other { + prop =3D <0xffffffff>; + // [FDT_REF_PHANDLE] prop[0], ref =3D base_other + addon2-subnode { + prop =3D <0x00000002>; + }; + }; +}; +&base_other { + addon2-node-base-other { + prop =3D <0x00000001>; + ref =3D <0x00000001>; + // [FDT_REF_LOCAL] ref[0] + }; +}; diff --git a/tests/fdtaddon_stack_2nd.dtsa b/tests/fdtaddon_stack_2nd.dtsa new file mode 100644 index 0000000..21d80d2 --- /dev/null +++ b/tests/fdtaddon_stack_2nd.dtsa @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ stack: "abc,bbb"; +/import/ other: ""; +/import/ base_other: ""; + +&stack { + addon2_node: addon2-node { + prop =3D <0>; + ref-other =3D <&other 10>; + }; +}; + +&other { + addon2-node-other { + prop =3D <&base_other>; + + addon2-subnode { + prop =3D <2>; + }; + }; +}; + +&base_other { + addon2-node-base-other { + prop =3D <1>; + ref =3D <&addon2_node>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 2cdfd89..69ca39e 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1221,6 +1221,27 @@ fdtaddon_tests() { =20 run_dtc_test -I dtb -O dts -o fdtaddon_addon_namespace-merged.dtb.dts fdt= addon_addon_namespace-merged.dtb check_dts fdtaddon_addon_namespace-merged.dtb.dts + + # test stacked addons + run_dtc_test -I dts -O dtb -o fdtaddon_stack_1st.dtba "$SRCDIR/fdtaddon_s= tack_1st.dtsa" + check_dtb fdtaddon_stack_1st.dtba + + run_fdtaddon_test -i fdtaddon_base.dtb -o fdtaddon_stack_1st-merged.dtb \ + -t "/somewhere/node-a1" fdtaddon_stack_1st.dtba + check_dtb fdtaddon_stack_1st-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_stack_1st-merged.dtb.dts fdtaddon_= stack_1st-merged.dtb + check_dts fdtaddon_stack_1st-merged.dtb.dts + + run_dtc_test -I dts -O dtb -o fdtaddon_stack_2nd.dtba "$SRCDIR/fdtaddon_s= tack_2nd.dtsa" + check_dtb fdtaddon_stack_2nd.dtba + + run_fdtaddon_test -i fdtaddon_stack_1st-merged.dtb -o fdtaddon_stack_2nd-= merged.dtb \ + -t "/somewhere/node-a1/addon1-node/sub-node-stack1" fdtaddon_stack_2n= d.dtba + check_dtb fdtaddon_stack_2nd-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_stack_2nd-merged.dtb.dts fdtaddon_= stack_2nd-merged.dtb + check_dts fdtaddon_stack_2nd-merged.dtb.dts } =20 pylibfdt_tests () { --=20 2.52.0 From nobody Sat Feb 7 19:41:46 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 964C636D4FC; Mon, 12 Jan 2026 14:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227743; cv=none; b=H8CpXxIEiD3C1P8LedEoODseW6fKa4WkG3VLp/w/Bbe+phnrQWB39eEYhABm/BXM/Ut3wL6jN5TaWQ3jfO+dWX45oucCJ5Tv61247vXyDqnROmYNQ+4rDAvW/9BJ2KT0Tf5hTy10pMCAeM+qqQfA6tTheI0W2l8qncKiZFudSe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768227743; c=relaxed/simple; bh=Isd85+H9Qiys/sKykMZqET59mCJqZdWNoHohNREXU0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oX1Q4tRORxg7020t3G+kJrVmTdtEMT3QU04akB/52AC9Q51D8OmeuAdEM5nexpFj7DLrxin9+uLWpWanqHHTp2rfjDOMUrx6ouncsB4f+muihyqTEioff3SDxVMGf6mLtSJYphUep0QODGQ4t4w0vZU8WGMHmOSCscsgkBKYc+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YEC30wYd; arc=none smtp.client-ip=185.246.84.56 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.b="YEC30wYd" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 767D61A2818; Mon, 12 Jan 2026 14:22:20 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4696C606FA; Mon, 12 Jan 2026 14:22:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3EC36103C8C61; Mon, 12 Jan 2026 15:22:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768227739; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=bKw3147CAfL3GStkkCwGjQbpn30MvLQfo0VEk7yzljo=; b=YEC30wYdXPsi9BCzWc9XaCpxRKU75BSvsxWKSOASJRm9RCw2Ik0tQcqyqzIDXtZvik1NkN df0J13A2qgj5mC1fAA52D7eFh6xcw84/g6HL4D78xn2We9O0VVOg1OqRWlw6WJ6CIdaQIv wuGh1Jpcba37Yqh7WiQkJMa7+R6YdD/IHhLMXRt8fAF8F2x4CO/7V1+8FotkyqWrO5694V HYwYvwTJEvJ883jrPSYgUJe0duDKq8otUBoc8a6zCiPZ0AJysF3Vcn99qvMzxjvD0nG6aU TxTXiD5Txn95IvxQMmCQxXn8NPpZNoRqeHoEw2gtrc2f7Q1PMD+eCG9opnjUTw== From: Herve Codina To: David Gibson , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: 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: [RFC PATCH 77/77] tests: fdtaddon: Add a test using more realistic dts and dtsa Date: Mon, 12 Jan 2026 15:20:07 +0100 Message-ID: <20260112142009.1006236-78-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112142009.1006236-1-herve.codina@bootlin.com> References: <20260112142009.1006236-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The dts and dtsa files used in the fdtaddon tests were centered on specific addon features in order to test those specific features. In term of structure or naming, they are not representative of real use-cases. This new test uses realistic dts and dtsa files with naming and structures tradidionally found in real cases. The dts describes the hardware of the base board. The hardware structure of the base board is the following: +--------------+ | 5V regulator +-------+ +--------------+ | | +----------------------+ | +----------------+ | SOC | | | Connector A | | | | | | | +-----------------+ | +-------+ 5v | | + i2c1 controller +---------------+ i2c bus | | +-----------------+ | +-------+ gpio 0 / irq 0 | | | | +---+ gpio 1 / irq 1 | | +------------------+ | | | +----------------+ | | gpio1 controller | | | | | | gpio #10 +------+ | | +------------------+ | | | | | | +---------------- -+ | | | | gpio2 controller | | | | | gpio #3 +----------+ | +------------------+ | +----------------------+ The connector 'Connector A' is the connector where the pluggable board can be connected to. It is described in the dts and related export symbols are set in order to be usable by the dtsa describing the pluggable board. The hardware structure of the pluggable board is the following: +---------------+ | EEPROM | | i2c addr 0x51 | | + +-------+ i2c | | +---------------+ | | +---------------+ | | Expander IO | +----------------+ | | i2c addr 0x23 | | Connector | | | | | | | +---+ Vcc1 | | 5v +---|---+---+ Vcc2 | | i2c bus +---+-------+ i2c | | gpio 0 / irq 0 +-----------+ irq | | gpio 1 / irq 1 +-----------+ reset | +----------------+ +---------------+ This structure is described in the addon dtsa. This addon dtsa is expected to be applied to the base device tree node describing the connector the pluggable board is connected to. Signed-off-by: Herve Codina --- ...ddon_realistic_addon-merged.dtb.dts.expect | 91 ++++++++++++++++++ ...fdtaddon_realistic_addon-merged.dtb.expect | 93 +++++++++++++++++++ tests/fdtaddon_realistic_addon.dtba.expect | 32 +++++++ tests/fdtaddon_realistic_addon.dtsa | 50 ++++++++++ tests/fdtaddon_realistic_base.dtb.expect | 72 ++++++++++++++ tests/fdtaddon_realistic_base.dts | 74 +++++++++++++++ tests/run_tests.sh | 14 +++ 7 files changed, 426 insertions(+) create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.expect create mode 100644 tests/fdtaddon_realistic_addon.dtba.expect create mode 100644 tests/fdtaddon_realistic_addon.dtsa create mode 100644 tests/fdtaddon_realistic_base.dtb.expect create mode 100644 tests/fdtaddon_realistic_base.dts diff --git a/tests/fdtaddon_realistic_addon-merged.dtb.dts.expect b/tests/f= dtaddon_realistic_addon-merged.dtb.dts.expect new file mode 100644 index 0000000..49aa950 --- /dev/null +++ b/tests/fdtaddon_realistic_addon-merged.dtb.dts.expect @@ -0,0 +1,91 @@ +/dts-v1/; + +/ { + + regulator { + compatible =3D "regulator-fixed"; + regulator-min-microvolt =3D <0x4c4b40>; + regulator-max-microvolt =3D <0x4c4b40>; + gpios =3D <&{/soc/gpio@2000} 0x05 0x00>; + phandle =3D <0x05>; + }; + + soc { + compatible =3D "simple-bus"; + #address-cells =3D <0x01>; + #size-cells =3D <0x01>; + + i2c@1000 { + compatible =3D "xyz,i2c-controller"; + reg =3D <0x1000 0x100>; + #address-cells =3D <0x01>; + #size-cells =3D <0x00>; + phandle =3D <0x06>; + }; + + gpio@2000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x2000 0x100>; + gpio-controller; + #gpio-cells =3D <0x02>; + interrupt-controller; + #interrupt-cells =3D <0x02>; + #address-cells =3D <0x00>; + phandle =3D <0x01>; + }; + + gpio@3000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x3000 0x100>; + gpio-controller; + #gpio-cells =3D <0x02>; + interrupt-controller; + #interrupt-cells =3D <0x02>; + #address-cells =3D <0x00>; + phandle =3D <0x02>; + }; + }; + + connector-a { + compatible =3D "abc,foo-connector"; + #address-cells =3D <0x00>; + #interrupt-cells =3D <0x02>; + interrupt-map =3D <0x00 0x00 &{/soc/gpio@2000} 0x0a 0x00 0x00 0x100 &{/s= oc/gpio@2000} 0x0a 0x100 0x01 0x00 &{/soc/gpio@3000} 0x03 0x00 0x01 0x100 &= {/soc/gpio@3000} 0x03 0x100>; + #gpio-cells =3D <0x02>; + gpio-map-mask =3D <0x0f 0x00>; + gpio-map-pass-thru =3D <0x00 0x0f>; + gpio-map =3D <0x00 0x00 &{/soc/gpio@2000} 0x0a 0x00 0x01 0x00 &{/soc/gpi= o@3000} 0x03 0x00>; + phandle =3D <0x03>; + + /export/ connector: &{/connector-a}; + /export/ conn_i2c: &{/connector-a/conn-i2c}; + /export/ conn_5v: &{/regulator}; + + conn-i2c { + compatible =3D "i2c-bus-extension"; + i2c-parent =3D <&{/soc/i2c@1000}>; + #address-cells =3D <0x01>; + #size-cells =3D <0x00>; + phandle =3D <0x04>; + + eeprom@51 { + reg =3D <0x51>; + compatible =3D "xxx,eeprom"; + }; + + gpio@23 { + reset-gpios =3D <&{/connector-a} 0x01 0x00>; + vcc2-supply =3D <&{/regulator}>; + vcc1-supply =3D <&{/regulator}>; + #interrupt-cells =3D <0x02>; + interrupt-controller; + interrupts =3D <0x00 0x100>; + interrupt-parent =3D <&{/connector-a}>; + #gpio-cells =3D <0x02>; + gpio-controller; + reg =3D <0x23>; + compatible =3D "xxx,expander-io"; + }; + }; + }; +}; diff --git a/tests/fdtaddon_realistic_addon-merged.dtb.expect b/tests/fdtad= don_realistic_addon-merged.dtb.expect new file mode 100644 index 0000000..fbebb4c --- /dev/null +++ b/tests/fdtaddon_realistic_addon-merged.dtb.expect @@ -0,0 +1,93 @@ +/dts-v1/; + +/ { + regulator { + compatible =3D "regulator-fixed"; + regulator-min-microvolt =3D <0x004c4b40>; + regulator-max-microvolt =3D <0x004c4b40>; + gpios =3D <0x00000001 0x00000005 0x00000000>; + // [FDT_REF_LOCAL] gpios[0] + phandle =3D <0x00000005>; + }; + soc { + compatible =3D "simple-bus"; + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000001>; + i2c@1000 { + compatible =3D "xyz,i2c-controller"; + reg =3D <0x00001000 0x00000100>; + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000000>; + phandle =3D <0x00000006>; + }; + gpio@2000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x00002000 0x00000100>; + gpio-controller; + #gpio-cells =3D <0x00000002>; + interrupt-controller; + #interrupt-cells =3D <0x00000002>; + #address-cells =3D <0x00000000>; + phandle =3D <0x00000001>; + }; + gpio@3000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x00003000 0x00000100>; + gpio-controller; + #gpio-cells =3D <0x00000002>; + interrupt-controller; + #interrupt-cells =3D <0x00000002>; + #address-cells =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + connector-a { + compatible =3D "abc,foo-connector"; + #address-cells =3D <0x00000000>; + #interrupt-cells =3D <0x00000002>; + interrupt-map =3D <0x00000000 0x00000000 0x00000001 0x0000000a 0x0= 0000000 0x00000000 0x00000100 0x00000001 0x0000000a 0x00000100 0x00000001 0= x00000000 0x00000002 0x00000003 0x00000000 0x00000001 0x00000100 0x00000002= 0x00000003 0x00000100>; + // [FDT_REF_LOCAL] interrupt-map[8] + // [FDT_REF_LOCAL] interrupt-map[28] + // [FDT_REF_LOCAL] interrupt-map[48] + // [FDT_REF_LOCAL] interrupt-map[68] + #gpio-cells =3D <0x00000002>; + gpio-map-mask =3D <0x0000000f 0x00000000>; + gpio-map-pass-thru =3D <0x00000000 0x0000000f>; + gpio-map =3D <0x00000000 0x00000000 0x00000001 0x0000000a 0x000000= 00 0x00000001 0x00000000 0x00000002 0x00000003 0x00000000>; + // [FDT_REF_LOCAL] gpio-map[8] + // [FDT_REF_LOCAL] gpio-map[28] + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'connector' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'conn_i2c' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'conn_5v' -> phandle 0x00000005 + conn-i2c { + compatible =3D "i2c-bus-extension"; + i2c-parent =3D <0x00000006>; + // [FDT_REF_LOCAL] i2c-parent[0] + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000000>; + phandle =3D <0x00000004>; + eeprom@51 { + reg =3D <0x00000051>; + compatible =3D "xxx,eeprom"; + }; + gpio@23 { + reset-gpios =3D <0x00000003 0x00000001 0x00000000>; + // [FDT_REF_LOCAL] reset-gpios[0] + vcc2-supply =3D <0x00000005>; + // [FDT_REF_LOCAL] vcc2-supply[0] + vcc1-supply =3D <0x00000005>; + // [FDT_REF_LOCAL] vcc1-supply[0] + #interrupt-cells =3D <0x00000002>; + interrupt-controller; + interrupts =3D <0x00000000 0x00000100>; + interrupt-parent =3D <0x00000003>; + // [FDT_REF_LOCAL] interrupt-parent[0] + #gpio-cells =3D <0x00000002>; + gpio-controller; + reg =3D <0x00000023>; + compatible =3D "xxx,expander-io"; + }; + }; + }; +}; diff --git a/tests/fdtaddon_realistic_addon.dtba.expect b/tests/fdtaddon_re= alistic_addon.dtba.expect new file mode 100644 index 0000000..bc2efd4 --- /dev/null +++ b/tests/fdtaddon_realistic_addon.dtba.expect @@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'connector' (abc,foo-connector) +// [FDT_IMPORT_SYM] 'conn_5v' () +&connector { + conn-i2c { + gpio@23 { + compatible =3D "xxx,expander-io"; + reg =3D <0x00000023>; + gpio-controller; + #gpio-cells =3D <0x00000002>; + interrupt-parent =3D <0xffffffff>; + // [FDT_REF_PHANDLE] interrupt-parent[0], ref =3D connector + interrupts =3D <0x00000000 0x00000100>; + interrupt-controller; + #interrupt-cells =3D <0x00000002>; + vcc1-supply =3D <0xffffffff>; + // [FDT_REF_PHANDLE] vcc1-supply[0], ref =3D conn_5v + vcc2-supply =3D <0xffffffff>; + // [FDT_REF_PHANDLE] vcc2-supply[0], ref =3D connector.conn_5v + reset-gpios =3D <0xffffffff 0x00000001 0x00000000>; + // [FDT_REF_PHANDLE] reset-gpios[0], ref =3D connector + }; + }; +}; +&connector.conn_i2c { + eeprom@51 { + compatible =3D "xxx,eeprom"; + reg =3D <0x00000051>; + }; +}; diff --git a/tests/fdtaddon_realistic_addon.dtsa b/tests/fdtaddon_realistic= _addon.dtsa new file mode 100644 index 0000000..255a1ff --- /dev/null +++ b/tests/fdtaddon_realistic_addon.dtsa @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ connector: "abc,foo-connector"; +/import/ conn_5v: ""; + +&connector { + /* + * Add a gpio expander at the conn-i2c node (i2c extension bus) + * available at the connector node + */ + conn-i2c { + gpio@23 { + compatible =3D "xxx,expander-io"; + reg =3D <0x23>; + gpio-controller; + #gpio-cells =3D <2>; + + /* Use the connector interrupt number 0 */ + interrupt-parent =3D <&connector>; + interrupts =3D <0 0x100>; + interrupt-controller; + #interrupt-cells =3D <2>; + + /* Use 5V power-supply wired to the connector */ + vcc1-supply =3D <&conn_5v>; /* Need to be an imported symbol */ + vcc2-supply =3D <&connector.conn_5v>; /* Only connector need to be impo= rted */ + + /* Use the connector gpio number 1 */ + reset-gpios =3D <&connector 1 0>; + }; + }; +}; + +/* + * Use namespace reference to add an EEPROM at i2c bus connected + * to the connector. It can be an i2c extension or the i2c controller itse= lf. + * We don't know and we don't have to know. + */ +&connector.conn_i2c { + eeprom@51 { + compatible =3D "xxx,eeprom"; + reg =3D <0x51>; + }; +}; diff --git a/tests/fdtaddon_realistic_base.dtb.expect b/tests/fdtaddon_real= istic_base.dtb.expect new file mode 100644 index 0000000..9064a7a --- /dev/null +++ b/tests/fdtaddon_realistic_base.dtb.expect @@ -0,0 +1,72 @@ +/dts-v1/; + +/ { + regulator { + compatible =3D "regulator-fixed"; + regulator-min-microvolt =3D <0x004c4b40>; + regulator-max-microvolt =3D <0x004c4b40>; + gpios =3D <0x00000001 0x00000005 0x00000000>; + // [FDT_REF_LOCAL] gpios[0] + phandle =3D <0x00000005>; + }; + soc { + compatible =3D "simple-bus"; + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000001>; + i2c@1000 { + compatible =3D "xyz,i2c-controller"; + reg =3D <0x00001000 0x00000100>; + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000000>; + phandle =3D <0x00000006>; + }; + gpio@2000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x00002000 0x00000100>; + gpio-controller; + #gpio-cells =3D <0x00000002>; + interrupt-controller; + #interrupt-cells =3D <0x00000002>; + #address-cells =3D <0x00000000>; + phandle =3D <0x00000001>; + }; + gpio@3000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x00003000 0x00000100>; + gpio-controller; + #gpio-cells =3D <0x00000002>; + interrupt-controller; + #interrupt-cells =3D <0x00000002>; + #address-cells =3D <0x00000000>; + phandle =3D <0x00000002>; + }; + }; + connector-a { + compatible =3D "abc,foo-connector"; + #address-cells =3D <0x00000000>; + #interrupt-cells =3D <0x00000002>; + interrupt-map =3D <0x00000000 0x00000000 0x00000001 0x0000000a 0x0= 0000000 0x00000000 0x00000100 0x00000001 0x0000000a 0x00000100 0x00000001 0= x00000000 0x00000002 0x00000003 0x00000000 0x00000001 0x00000100 0x00000002= 0x00000003 0x00000100>; + // [FDT_REF_LOCAL] interrupt-map[8] + // [FDT_REF_LOCAL] interrupt-map[28] + // [FDT_REF_LOCAL] interrupt-map[48] + // [FDT_REF_LOCAL] interrupt-map[68] + #gpio-cells =3D <0x00000002>; + gpio-map-mask =3D <0x0000000f 0x00000000>; + gpio-map-pass-thru =3D <0x00000000 0x0000000f>; + gpio-map =3D <0x00000000 0x00000000 0x00000001 0x0000000a 0x000000= 00 0x00000001 0x00000000 0x00000002 0x00000003 0x00000000>; + // [FDT_REF_LOCAL] gpio-map[8] + // [FDT_REF_LOCAL] gpio-map[28] + phandle =3D <0x00000003>; + // [FDT_EXPORT_SYM] 'connector' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'conn_i2c' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'conn_5v' -> phandle 0x00000005 + conn-i2c { + compatible =3D "i2c-bus-extension"; + i2c-parent =3D <0x00000006>; + // [FDT_REF_LOCAL] i2c-parent[0] + #address-cells =3D <0x00000001>; + #size-cells =3D <0x00000000>; + phandle =3D <0x00000004>; + }; + }; +}; diff --git a/tests/fdtaddon_realistic_base.dts b/tests/fdtaddon_realistic_b= ase.dts new file mode 100644 index 0000000..0c13f1a --- /dev/null +++ b/tests/fdtaddon_realistic_base.dts @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + conn_a_5v: regulator { + compatible =3D "regulator-fixed"; + regulator-min-microvolt =3D <5000000>; + regulator-max-microvolt =3D <5000000>; + gpios =3D <&gpio1 5 0>; + }; + + soc { + compatible =3D "simple-bus"; + #address-cells =3D <1>; + #size-cells =3D <1>; + + i2c1: i2c@1000 { + compatible =3D "xyz,i2c-controller"; + reg =3D <0x1000 0x100>; + #address-cells =3D <1>; + #size-cells =3D <0>; + }; + + gpio1: gpio@2000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x2000 0x100>; + gpio-controller; + #gpio-cells =3D <2>; + interrupt-controller; + #interrupt-cells =3D <2>; + #address-cells =3D <0>; /* interrupt-map usage */ + }; + + gpio2: gpio@3000 { + compatible =3D "xyz,gpio-controller"; + reg =3D <0x3000 0x100>; + gpio-controller; + #gpio-cells =3D <2>; + interrupt-controller; + #interrupt-cells =3D <2>; + #address-cells =3D <0>; /* interrupt-map usage */ + }; + }; + + conn_a: connector-a { + compatible =3D "abc,foo-connector"; + #address-cells =3D <0>; + #interrupt-cells =3D <2>; + interrupt-map =3D <0 0 &gpio1 10 0>, + <0 0x100 &gpio1 10 0x100>, + <1 0 &gpio2 3 0>, + <1 0x100 &gpio2 3 0x100>; + #gpio-cells =3D <2>; + gpio-map-mask =3D <0xf 0x0>; + gpio-map-pass-thru =3D <0x0 0xf>; + gpio-map =3D <0 0 &gpio1 10 0>, + <1 0 &gpio2 3 0>; + + /export/ connector: &conn_a; + /export/ conn_i2c: &conn_a_i2c; + /export/ conn_5v: &conn_a_5v; + + conn_a_i2c: conn-i2c { + compatible =3D "i2c-bus-extension"; + i2c-parent =3D <&i2c1>; + #address-cells =3D <1>; + #size-cells =3D <0>; + }; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 69ca39e..a6213ab 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1242,6 +1242,20 @@ fdtaddon_tests() { =20 run_dtc_test -I dtb -O dts -o fdtaddon_stack_2nd-merged.dtb.dts fdtaddon_= stack_2nd-merged.dtb check_dts fdtaddon_stack_2nd-merged.dtb.dts + + # More realistic dts and dtsa input files + run_dtc_test -I dts -O dtb -o fdtaddon_realistic_base.dtb "$SRCDIR/fdtadd= on_realistic_base.dts" + check_dtb fdtaddon_realistic_base.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_realistic_addon.dtba "$SRCDIR/fdta= ddon_realistic_addon.dtsa" + check_dtb fdtaddon_realistic_addon.dtba + + run_fdtaddon_test -i fdtaddon_realistic_base.dtb -o fdtaddon_realistic_ad= don-merged.dtb \ + -t "/connector-a" fdtaddon_realistic_addon.dtba + check_dtb fdtaddon_realistic_addon-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_realistic_addon-merged.dtb.dts fdt= addon_realistic_addon-merged.dtb + check_dts fdtaddon_realistic_addon-merged.dtb.dts } =20 pylibfdt_tests () { --=20 2.52.0