From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 553D61C5CB8; Mon, 9 Dec 2024 15:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757525; cv=none; b=fS1qSsMoqUlRml9+XvYwOi7RB6cRG9pvrZxql07pEeumRMB0AHZRs6J27/QUje+JccnqjJCv8Vig2vIY4LMNDVQ/k3MwiKqp8OrS6a6nMqaXH4MJwfiC7TT6iE1tAdpqBRwNp5kGbKUIhVxgyBSG5PYPbAIuvdPDfVVBAjzcEIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757525; c=relaxed/simple; bh=lEJgCTz30ZkebZS5Flp4H/M53zfwCCmzWj2CKzKMjJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CaswWc5OJT2zcKWcRNAJv8czZe9jjjtjJTRiU4ElQna0Sy9Yo3pEY3pQU2QC4RALn7guDv0vhzR6r3OLq/i0jyJcoGuizF2bfmUhE350+Jv/3s++rr8WnifKmKW/9g23YhN6CwQxZIdDzXiV76bqMEPdYSqklvdPerfF4G5Y72U= 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=pB/LBxMj; arc=none smtp.client-ip=217.70.183.197 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="pB/LBxMj" Received: by mail.gandi.net (Postfix) with ESMTPA id 5304B1C0004; Mon, 9 Dec 2024 15:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x4VBr1zEJa6gUZmX14RHtbHMhhsebpJLB65p0BnHY5c=; b=pB/LBxMjkk8ih+PbQL/MeI4eGtiZlcr1EuDeEfh6sPl/M94DVJrS5qHgRvOtApUNiGcLLG Jba6aULzfgkV/KxnFv0VMNN+5BQY0JOVVn7jmEB0C2Pg+syCUOFWvnJcCYwAwuYZC9N09v TMJeofyRdSEbC2opxNEYsAu058ENKalwsCj1qDwXNcG6DL4jExojHwO3Xm1OVAIPN8Tyrq cTgW/qaXXYlkDBPTUGoruAVIi5poBDtCvaCyrnZFaB0wfGAf4X31KY5FWV7pCqCLGwteC0 tZgCsaFVPW2XTuAl4PohLxKAsUooddgj/fh7fB+2o5ZuNfLzGVAcZ/EacNestA== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 1/7] dt-bindings: Add support for export-symbols node Date: Mon, 9 Dec 2024 16:18:19 +0100 Message-ID: <20241209151830.95723-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" An export-symbols node allows to export symbols for symbols resolution performed when applying a device tree overlay. When a device tree overlay is applied on a node having an export-symbols node, symbols listed in the export-symbols node are used to resolve undefined symbols referenced from the overlay. This allows: - Referencing symbols from an device tree overlay without the need to know the full base board. Only the connector definition is needed. - Using the exact same overlay on several connectors available on a given board. For instance, the following description is supported with the export-symbols node: - Base device tree board A: ... foo_connector: connector1 { export-symbols { connector =3D <&foo_connector>; }; }; bar_connector: connector2 { export-symbols { connector =3D <&bar_connector>; }; }; ... - Base device tree board B: ... front_connector: addon-connector { export-symbols { connector =3D <&front_connector>; }; }; ... - Overlay describing an addon board the can be connected on connectors: ... node { ... connector =3D <&connector>; ... }; ... Thanks to the export-symbols node, the overlay can be applied on connector1 or connector2 available on board A but also on addon-connector available on board B. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- .../devicetree/bindings/export-symbols.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/export-symbols.yaml diff --git a/Documentation/devicetree/bindings/export-symbols.yaml b/Docume= ntation/devicetree/bindings/export-symbols.yaml new file mode 100644 index 000000000000..0e404eff8937 --- /dev/null +++ b/Documentation/devicetree/bindings/export-symbols.yaml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/export-symbols.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Export symbols + +maintainers: + - Herve Codina + +description: | + An export-symbols node allows to export symbols for symbols resolution + performed when applying a device tree overlay. + + When a device tree overlay is applied on a node having an export-symbols + node, symbols listed in the export-symbols node are used to resolve unde= fined + symbols referenced from the overlay. + +properties: + $nodename: + const: export-symbols + +patternProperties: + "^[a-zA-Z_]?[a-zA-Z0-9_]*$": + $ref: /schemas/types.yaml#/definitions/phandle + description: + A symbol exported in the form =3D. + +additionalProperties: false + +examples: + - | + /* + * Allows 'connector' symbol used in a device-tree overlay to be resol= ved to + * connector0 when the device-tree overlay is applied on connector0 no= de. + */ + connector0: connector0 { + export-symbols { + connector =3D <&connector0>; + }; + }; +... --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 553811C5CB4; Mon, 9 Dec 2024 15:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757524; cv=none; b=IBOo9m2rHX9ELJu+BpqW1wwuEUGAqcrmS6LNT/helAoDXTAQYHzjFe19nlwx38/XAaWA7/hiLxcMV1KBccG0gwhbUE/WTxTz64fGSVylrWwSH5+gqLh+9UB/0x6jel90rhv5oQxDU0xOhUAwVKW1cVgP5NaGblonvoxr38RTijI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757524; c=relaxed/simple; bh=xcE1Dp+GtZr4tqDbYM//n9fyWpJ+43fYPFpmfVaOKt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tB2qpXt7AUVBaG8eSWKJl+eaV+AKndFjes1KFOnVrrme/DY2A0O9CbmZsnw5Ead3CcWrtum1p+GTGW1c1auC8UR51XuTL3S7Zs92xELmWz6U8Srt9iVt/0Qeq7fX0jL4cZeH0CjqmsYQWB49KSgPgCx1WpC+rb+oTnXOtT8nGwk= 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=IqYHYxEo; arc=none smtp.client-ip=217.70.183.197 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="IqYHYxEo" Received: by mail.gandi.net (Postfix) with ESMTPA id 180FA1C000D; Mon, 9 Dec 2024 15:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aTiTEyB+NdrrDnoEp3UcmqGVspuxMmOtaQInMG+LjNg=; b=IqYHYxEo4st2YMIrFOpbxOVAr3N9YEBR8aR4Ct15yVy9yRyz7p2nmr8h3GXVji1oXlmGUe +d7gujNRYtahKTE45JRebnGKLpoh0MskccrqbtwlZGaVllENmDTib8sUNBAXLeQN3lkBBW IvK6S4gLcYON7UTuY73lvJMmCxV4OWiFWjmE8SzgkPJ1K/NBPgwRFhX+advwHVyhPLtr51 NFpahxN7uWuz2HqJGgGDsWHvbm7vlIb9NwbUDYpqo0Ke8197zA2T4d+xv1k7vS5w8VHQX9 xSJFzUA/rOBedde4hjFa18HPk0J85qKOEBGIb4bsP5OQeJOXgKeB0tV7qhRTZA== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 2/7] of: resolver: Introduce get_phandle_from_symbols_node() Date: Mon, 9 Dec 2024 16:18:20 +0100 Message-ID: <20241209151830.95723-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" In order to simplify the introduction of the export symbols node handling, group necessary operations done to get a phandle from the __symbols__ node in this dedicated get_phandle_from_symbols_node() function. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/of/resolver.c | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 779db058c42f..2560b33fa750 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -214,6 +214,28 @@ static int adjust_local_phandle_references(const struc= t device_node *local_fixup return 0; } =20 +static int get_phandle_from_symbols_node(const struct device_node *tree_sy= mbols, + const char *symbol_name, + phandle *phandle) +{ + struct device_node *refnode; + const char *refpath; + int err; + + err =3D of_property_read_string(tree_symbols, symbol_name, &refpath); + if (err) + return err; + + refnode =3D of_find_node_by_path(refpath); + if (!refnode) + return -ENOENT; + + *phandle =3D refnode->phandle; + of_node_put(refnode); + + return 0; +} + /** * of_resolve_phandles - Relocate and resolve overlay against live tree * @@ -249,11 +271,10 @@ static int adjust_local_phandle_references(const stru= ct device_node *local_fixup */ int of_resolve_phandles(struct device_node *overlay) { - struct device_node *child, *local_fixups, *refnode; - struct device_node *tree_symbols, *overlay_fixups; - struct property *prop; - const char *refpath; + struct device_node *child, *local_fixups, *overlay_fixups; + struct device_node *tree_symbols; phandle phandle, phandle_delta; + struct property *prop; int err; =20 tree_symbols =3D NULL; @@ -306,23 +327,14 @@ int of_resolve_phandles(struct device_node *overlay) if (!of_prop_cmp(prop->name, "name")) continue; =20 - err =3D of_property_read_string(tree_symbols, - prop->name, &refpath); + err =3D get_phandle_from_symbols_node(tree_symbols, prop->name, + &phandle); if (err) { - pr_err("node label '%s' not found in live devicetree symbols table\n", + pr_err("node label '%s' not found or invalid in live devicetree symbols= table\n", prop->name); goto out; } =20 - refnode =3D of_find_node_by_path(refpath); - if (!refnode) { - err =3D -ENOENT; - goto out; - } - - phandle =3D refnode->phandle; - of_node_put(refnode); - err =3D update_usages_of_a_phandle_reference(overlay, prop, phandle); if (err) break; --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 5531F1C5CB3; Mon, 9 Dec 2024 15:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757524; cv=none; b=ZYCSZ6H/utC0YUg/AmeOUZB7OL8jcvF+8gvwIHziqf37qUHO2VkNvJqWZ28Kgde4/xcyVs1CDRIigoFAPpEf4/lkXdkU+Ibt/vlhUS5yJ/23Y/XQnB72FFma7bJqBuD4+msVH5HkA99s0nw56kTt61eq2wkfY8li/ngM8J27s2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757524; c=relaxed/simple; bh=bddoC57aSA5Z++Q1YV92YnSN11dyWZNLBdBNmMRB1cU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCUEeqm/Qxbpi0FkUCNDbUCj0aKnrsL6vDUM8eZqfR00YROVlB9BuELaDY+AztA53OVcqmanYLaEBqItfkZx6inBAhwVPpA0ERJ0GKGQduujdg6TiesS/wNWozvwOYVb+7QCZHS/XON+IXy7vbLApPsJFevjxAujjnUbNosRiwc= 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=QHNWSd45; arc=none smtp.client-ip=217.70.183.197 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="QHNWSd45" Received: by mail.gandi.net (Postfix) with ESMTPA id DAA881C0002; Mon, 9 Dec 2024 15:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N1lLHg+b2rS2dS5LxXdZG0vEvHnYFFE2HcdcCPiiZsk=; b=QHNWSd45eqNZBZQrCzHQbh53U0NxOH2eN55RAOghTckOBm2h5TDUuF48MnHbVy74aBYCWU YX4nxxnKIFzkFeJM6UtqumbswGzWjAB03U8LFcI4mvqgUTZRjV5MljiwLkaFTekP8mdD2K etlGUgo77DfBgGtnW9tCqrn7dojYevDdpFl9rzPc559TKtMlEB1T7jyHIonZ4HNvTMOMDy SWiElyYWWlyHN8SYQKTl2xViVOvCxBkETTgxX8U4bLMTt2DAESRW/ZQNsg7NFWn7H2lbYO vi8ijZvi0mEVPGgm5IwJQ5l4HeEBqoSSWEtPJ0Wn+uUEsjhdkH06r1UprZaX5Q== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 3/7] of: resolver: Add export_symbols in of_resolve_phandles() parameters Date: Mon, 9 Dec 2024 16:18:21 +0100 Message-ID: <20241209151830.95723-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" In order to prepare the introduction of the export symbols node handling, add a export_symbols parameter in of_resolve_phandles(). The export_symbols is the export symbols device tree node the resolver will use for the overlay symbols resolution. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/of/of_private.h | 2 +- drivers/of/overlay.c | 2 +- drivers/of/resolver.c | 9 +++++++-- drivers/of/unittest.c | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index ea5a0951ec5e..b1bc7b676946 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -94,7 +94,7 @@ static inline void __of_detach_node_sysfs(struct device_n= ode *np) {} #endif =20 #if defined(CONFIG_OF_RESOLVE) -int of_resolve_phandles(struct device_node *tree); +int of_resolve_phandles(struct device_node *tree, const struct device_node= *export_symbols); #endif =20 void __of_phandle_cache_inv_entry(phandle handle); diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 434f6dd6a86c..28aa0a133eea 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -915,7 +915,7 @@ static int of_overlay_apply(struct overlay_changeset *o= vcs, { int ret =3D 0, ret_revert, ret_tmp; =20 - ret =3D of_resolve_phandles(ovcs->overlay_root); + ret =3D of_resolve_phandles(ovcs->overlay_root, NULL); if (ret) goto out; =20 diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 2560b33fa750..f5f6c46231d1 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -239,7 +239,8 @@ static int get_phandle_from_symbols_node(const struct d= evice_node *tree_symbols, /** * of_resolve_phandles - Relocate and resolve overlay against live tree * - * @overlay: Pointer to devicetree overlay to relocate and resolve + * @overlay: Pointer to devicetree overlay to relocate and resolve + * @export_symbols: Pointer to devicetree export symbols node. * * Modify (relocate) values of local phandles in @overlay to a range that * does not conflict with the live expanded devicetree. Update references @@ -259,6 +260,10 @@ static int get_phandle_from_symbols_node(const struct = device_node *tree_symbols, * corresponding to that symbol in the live tree. Update the references in * the overlay with the phandle values in the live tree. * + * @export_symbols can be use in this references update. The resolver tries + * first to find a match in the @export_symbols. If not found, it uses the + * "__symbol__" node in the live tree. + * * @overlay must be detached. * * Resolving and applying @overlay to the live expanded devicetree must be @@ -269,7 +274,7 @@ static int get_phandle_from_symbols_node(const struct d= evice_node *tree_symbols, * * Return: %0 on success or a negative error value on error. */ -int of_resolve_phandles(struct device_node *overlay) +int of_resolve_phandles(struct device_node *overlay, const struct device_n= ode *export_symbols) { struct device_node *child, *local_fixups, *overlay_fixups; struct device_node *tree_symbols; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index daf9a2dddd7e..7b97d4fc0236 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1899,7 +1899,7 @@ static int __init unittest_data_add(void) */ of_overlay_mutex_lock(); =20 - rc =3D of_resolve_phandles(unittest_data_node); + rc =3D of_resolve_phandles(unittest_data_node, NULL); if (rc) { pr_err("%s: Failed to resolve phandles (rc=3D%i)\n", __func__, rc); of_overlay_mutex_unlock(); @@ -3794,7 +3794,7 @@ static __init void of_unittest_overlay_high_level(voi= d) * because kmalloc() was not yet available. */ of_overlay_mutex_lock(); - of_resolve_phandles(overlay_base_root); + of_resolve_phandles(overlay_base_root, NULL); of_overlay_mutex_unlock(); =20 =20 --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 810571C5CC1; Mon, 9 Dec 2024 15:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757525; cv=none; b=JNG1KkmMpAfyYvNGERD0Crs8erBG6WMO5hiJjXv3I9Wip77b4qAMffWor/h+FkP3OeXWv4eyGZIsodADijF/5DrAk79gGTZcu/V/Dq55xhNI75ID+VMYKD2acDE1yxGqGz30g/m2EZWFVqq9DJYX9AdJhsTjV9tJKTXBq0jiUoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757525; c=relaxed/simple; bh=7uYFDC/DD6qGCYtp5pFL4NX/XzVCHwPStn3sfh7zDyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBjqVpS4gzEV6jbaR6TgA1n+Q7K7nX6V9RxOH9IOPtueC16HKtC/O+LWPAAh2dswnhC98i2Ijz3rGezYfIepIq+pb6y27cZOP+mz4wVYHVLlvn5Yo99D+pLOdgnPMk5qu0Gj4U8TzYBkZoWetQ2UtaA61rkYfbp0jhQkTQXUqUQ= 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=L1XcsIzY; arc=none smtp.client-ip=217.70.183.197 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="L1XcsIzY" Received: by mail.gandi.net (Postfix) with ESMTPA id A06561C0010; Mon, 9 Dec 2024 15:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tr7OhDfkg+fL9ioPWrN+UHmbgRARJumuDlQwW8WsOKg=; b=L1XcsIzYKXLsjG4jxuDphCJPUo7uOWpGNXwzuxpeCWfwayTRjC6SpsO/37uNfpuN/NgmOM cTSQ7sRk3Kut3G1sQmQZCnWjzwH08ZbcPqZgxmLh3sIU8ChojoALzueZrOLw/jtDAtiBP8 f708O9aejHqvJ9ckapBKR9VN3UNhRT9MmuoBC+Wyah6+kQnUjU7Oft1Z59w8rlr3lr2Rdc rLu/EDmRni7jCoR5a0BTS0iddaIJ1tn6XL/o3vvm8S/JfyIE6sKgi9O98/9D+KPzAcZHz5 AIbH4tv9kCPavxnOiCQ8ZVEhlP/mfEAtvnh6EhEii/BR3fnNbNePBQmlb8TIbw== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 4/7] of: resolver: Add support for the export symbols node Date: Mon, 9 Dec 2024 16:18:22 +0100 Message-ID: <20241209151830.95723-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" Symbols resolution done when an overlay is applied looks only at the global __symbol__ node to resolve unknown symbols from the overlay (i.e symbols listed in the overlay __fixups__ node). In order to provide flexibilities and allow to define some additional symbols visible only when an overlay is applied to a specific node, introduce the export symbols node. The export symbols node adds some additional symbols that can be used in the symbols resolution. The resolver tries to match unresolved symbols first using the export symbols node and, if a match is not found, it tries to match using the global __symbol__ node. Contrary to symbols available in the global __symbols__ node, symbols listed in the export symbols node can be considered as local symbols. Indeed, they can be changed depending on the node the overlay is going to be applied to and are only visibible from the current recolver call. Handle those additional symbols given by the export symbols node in the symbols resolution. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/of/resolver.c | 33 +++++++++++++++++++++++++++++---- drivers/of/unittest.c | 4 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index f5f6c46231d1..b685c46b20b8 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -222,6 +222,9 @@ static int get_phandle_from_symbols_node(const struct d= evice_node *tree_symbols, const char *refpath; int err; =20 + if (!tree_symbols) + return -ENOENT; + err =3D of_property_read_string(tree_symbols, symbol_name, &refpath); if (err) return err; @@ -236,6 +239,25 @@ static int get_phandle_from_symbols_node(const struct = device_node *tree_symbols, return 0; } =20 +static int get_phandle_from_export_node(const struct device_node *export_s= ymbols, + const char *symbol_name, + phandle *phandle) +{ + struct device_node *refnode; + + if (!export_symbols) + return -ENOENT; + + refnode =3D of_parse_phandle(export_symbols, symbol_name, 0); + if (!refnode) + return -ENOENT; + + *phandle =3D refnode->phandle; + of_node_put(refnode); + + return 0; +} + /** * of_resolve_phandles - Relocate and resolve overlay against live tree * @@ -320,7 +342,7 @@ int of_resolve_phandles(struct device_node *overlay, co= nst struct device_node *e } =20 tree_symbols =3D of_find_node_by_path("/__symbols__"); - if (!tree_symbols) { + if (!tree_symbols && !export_symbols) { pr_err("no symbols in root of device tree.\n"); err =3D -EINVAL; goto out; @@ -332,10 +354,13 @@ int of_resolve_phandles(struct device_node *overlay, = const struct device_node *e if (!of_prop_cmp(prop->name, "name")) continue; =20 - err =3D get_phandle_from_symbols_node(tree_symbols, prop->name, - &phandle); + err =3D get_phandle_from_export_node(export_symbols, prop->name, + &phandle); + if (err) + err =3D get_phandle_from_symbols_node(tree_symbols, prop->name, + &phandle); if (err) { - pr_err("node label '%s' not found or invalid in live devicetree symbols= table\n", + pr_err("node label '%s' not found or invalid in live devicetree symbols= or export tables\n", prop->name); goto out; } diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7b97d4fc0236..e76ac087ea98 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -4025,7 +4025,7 @@ static __init void of_unittest_overlay_high_level(voi= d) /* --- overlay_bad_unresolved --- */ =20 EXPECT_BEGIN(KERN_ERR, - "OF: resolver: node label 'this_label_does_not_exist' not found in = live devicetree symbols table"); + "OF: resolver: node label 'this_label_does_not_exist' not found or = invalid in live devicetree symbols or export tables"); EXPECT_BEGIN(KERN_ERR, "OF: resolver: overlay phandle fixup failed: -22"); =20 @@ -4035,7 +4035,7 @@ static __init void of_unittest_overlay_high_level(voi= d) EXPECT_END(KERN_ERR, "OF: resolver: overlay phandle fixup failed: -22"); EXPECT_END(KERN_ERR, - "OF: resolver: node label 'this_label_does_not_exist' not found in li= ve devicetree symbols table"); + "OF: resolver: node label 'this_label_does_not_exist' not found or in= valid in live devicetree symbols or export tables"); =20 return; =20 --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 E24231F2C5B; Mon, 9 Dec 2024 15:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757527; cv=none; b=QG1NfuIewI01RZ8wdDX+079IDZN8b93FDETD7MfirNpaSAztUTbdAZ4xZsvQSNmszJzfxme+rf1hMCRtPzcVcUK8wLr7xn7rD223qGPYd+U4KNLTGOFDA8qAD5xKx+sJFHcd87CUMdQd1GkHwjI5uQ0eUwkxSwqrZbXIxHJ8H7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757527; c=relaxed/simple; bh=6+eH3SLTliNmk9kDqHOkMbkZbG9HOeX8MFLZTyu4Tu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dSQK1Lq2jcyPOS0DZtJ37bx5ob3Vk6l29B3Ga4b/BmDJi7fnqnYA04+xAuiXDhTxt4pBlzJy2u1Mx+7RJT2PXfMRO027U1jUvk4H/3x5z+NELGPkIZMkokJsJy4IbNFDMVVdF5xuJ0spt/WfmhGBTL1j57VgMgyGoJrA3u33Ujo= 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=LR7efqY2; arc=none smtp.client-ip=217.70.183.197 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="LR7efqY2" Received: by mail.gandi.net (Postfix) with ESMTPA id 7A33E1C0013; Mon, 9 Dec 2024 15:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9X8/hBFexYL9f5Jzi2AlRd6tsI8OkRlzCrrLoPJoMzk=; b=LR7efqY2t9yBqSZdKpUjICJ7hoozQ0wGe0qiM8C7JgJyqZGcaEDtDr5/i6QpVcRY0OitOF 9K2y9KlWA7++OfwdEJrvShhtIcd4NqYa7SXbBUHfiEVmb3r80gztGF/9hYvE5zgq9XwWaC 3cNtBWIVqB9Y8SsEp1Ti6+sxzSj3wHVFVvxUrBGtSA6UDTXnLzo19s0gEcX8s84i0c1xQE Dqq3cYy0wo/8Lcjfg/5lZV0muh6eV47O/OioFD9f2D6bjsln1YhwuhNDXQVcTynMUBxpzq bg3xKfatSjmwtu10b5V1xE2kkjS29+PUlIUoojcuTrWfwYLn2FUztAfeFAUlEg== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 5/7] of: overlay: Add export_symbols_name in of_overlay_fdt_apply() parameters Date: Mon, 9 Dec 2024 16:18:23 +0100 Message-ID: <20241209151830.95723-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" In order to prepare the introduction of the export symbols node handling, add a export_symbols_name parameter in of_overlay_fdt_apply(). The export_symbols_name is the name of the export symbols subnode available in the base node that will be used by the resolver to handle export symbols resolution. Having the name of the subnode in parameters instead of the subnode itself avoid the use of an export symbol node that is not directly related to the base node. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/misc/lan966x_pci.c | 3 ++- drivers/of/of_kunit_helpers.c | 2 +- drivers/of/overlay.c | 7 ++++++- drivers/of/unittest.c | 4 ++-- include/linux/of.h | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/misc/lan966x_pci.c b/drivers/misc/lan966x_pci.c index 9c79b58137e5..f05cb040ec69 100644 --- a/drivers/misc/lan966x_pci.c +++ b/drivers/misc/lan966x_pci.c @@ -128,7 +128,8 @@ static int lan966x_pci_load_overlay(struct lan966x_pci = *data) u32 dtbo_size =3D __dtbo_lan966x_pci_end - __dtbo_lan966x_pci_begin; void *dtbo_start =3D __dtbo_lan966x_pci_begin; =20 - return of_overlay_fdt_apply(dtbo_start, dtbo_size, &data->ovcs_id, dev_of= _node(data->dev)); + return of_overlay_fdt_apply(dtbo_start, dtbo_size, &data->ovcs_id, + dev_of_node(data->dev), NULL); } =20 static void lan966x_pci_unload_overlay(struct lan966x_pci *data) diff --git a/drivers/of/of_kunit_helpers.c b/drivers/of/of_kunit_helpers.c index 7b3ed5a382aa..476b43474168 100644 --- a/drivers/of/of_kunit_helpers.c +++ b/drivers/of/of_kunit_helpers.c @@ -56,7 +56,7 @@ int of_overlay_fdt_apply_kunit(struct kunit *test, void *= overlay_fdt, return -ENOMEM; =20 ret =3D of_overlay_fdt_apply(overlay_fdt, overlay_fdt_size, - ovcs_id, NULL); + ovcs_id, NULL, NULL); if (ret) return ret; =20 diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 28aa0a133eea..9bceeed45c9f 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -964,6 +964,10 @@ static int of_overlay_apply(struct overlay_changeset *= ovcs, * @overlay_fdt_size: number of bytes in @overlay_fdt * @ret_ovcs_id: pointer for returning created changeset id * @base: pointer for the target node to apply overlay + * @export_symbols_name: + * Name of the export symbol subnode of the @base node to + * provide extra symbols. Those extra symbols are used in + * the overlay symbols resolution. * * Creates and applies an overlay changeset. * @@ -979,7 +983,8 @@ static int of_overlay_apply(struct overlay_changeset *o= vcs, */ =20 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ret_ovcs_id, const struct device_node *base) + int *ret_ovcs_id, const struct device_node *base, + const char *export_symbols_name) { void *new_fdt; void *new_fdt_align; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e76ac087ea98..f19e15f8b288 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3737,7 +3737,7 @@ static int __init overlay_data_apply(const char *over= lay_name, int *ovcs_id) pr_err("no overlay data for %s\n", overlay_name); =20 ret =3D of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id, - NULL); + NULL, NULL); if (ovcs_id) *ovcs_id =3D info->ovcs_id; if (ret < 0) @@ -4077,7 +4077,7 @@ static int testdrv_probe(struct pci_dev *pdev, const = struct pci_device_id *id) } =20 size =3D info->dtbo_end - info->dtbo_begin; - ret =3D of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn); + ret =3D of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn, NULL); of_node_put(dn); if (ret) return ret; diff --git a/include/linux/of.h b/include/linux/of.h index f921786cb8ac..2ac09b0161fd 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1747,7 +1747,8 @@ struct of_overlay_notify_data { #ifdef CONFIG_OF_OVERLAY =20 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ovcs_id, const struct device_node *target_base); + int *ovcs_id, const struct device_node *target_base, + const char *export_symbols_name); int of_overlay_remove(int *ovcs_id); int of_overlay_remove_all(void); =20 @@ -1757,7 +1758,8 @@ int of_overlay_notifier_unregister(struct notifier_bl= ock *nb); #else =20 static inline int of_overlay_fdt_apply(const void *overlay_fdt, u32 overla= y_fdt_size, - int *ovcs_id, const struct device_node *target_base) + int *ovcs_id, const struct device_node *target_base, + const char *export_symbols_name) { return -ENOTSUPP; } --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 50805216E27; Mon, 9 Dec 2024 15:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757527; cv=none; b=nw+dJYJTxpbXBq6UatWqQNJw+06qDtKOcLYFDSxC0D2iCxC9/Tm/0MH2fE0h3DF9f2SIeBap4cgnyv8elTcXfPauNsTOZb6XxrLWODvZVtTsuH8rxy3Xu4VNO6s8xnTFTvU8Y/1ZpmxrHeUeQ4f7zCHMTjxwdObmZ251ACi1fAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757527; c=relaxed/simple; bh=ujhvA7+BR+nmPw0JGxSahQU55HLF9c4VmOg6XJE36nE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKGOTa3nUdUqWZRCaclirlD/lVCVo7vpSCvQYVCll9RD8ZsOZRTVKmbfkrP0940MGSukG4+EU9nwEsYL/1cK+82UgOe/FHbPUNfhgXguEW2mn/klKV24liTo2HYo1LmMyjEWtraRSXaK3zcDk21RLoP+skeGALF2a11w5Q1hrFs= 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=XJSysGl7; arc=none smtp.client-ip=217.70.183.197 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="XJSysGl7" Received: by mail.gandi.net (Postfix) with ESMTPA id 565C81C000C; Mon, 9 Dec 2024 15:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eJOxQ8jWT4sQQnymSLHfN5zi4FNkUE+3+rzULzxbc1Y=; b=XJSysGl7krZgHCqcEamL+Uw7b6xn/HuokO14fDt5sVWbcR5PLI8h6xG/sDzTnDSQQ/5DjF pQ5MtTXVHpJuDV1ROkklIAsRS9pW4vjj4DuIH4ncEQZ+nFDTiyZ9VijVXvWLoHW3mA4hAq T8xvoYRz6kRvOiPnwplFbHSJFqElliLIOeC8GmOw+1swSVhwDQTPx18tlvHlP4uBNqt5eS NRDIqA9FyS0LQ4BobNXI0qQ+HdDkQzjluF85+4zFbaokZ5UKLOnqBdusOnIQhxy9Wr7c87 0GNOqvTX1YAw/arRx0tRNhD8eOvT/eJilA900JASLN/MRyNiTK76h3kdpTTXBw== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 6/7] of: overlay: Add support for the export symbols node Date: Mon, 9 Dec 2024 16:18:24 +0100 Message-ID: <20241209151830.95723-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" The resolver already supports the use of the export symbol node. Add support of the export symbol node feature in of_overlay_fdt_apply() simply getting the export node from its name and passing it to the resolver. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/of/overlay.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 9bceeed45c9f..b69245a50746 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -887,6 +887,10 @@ static void free_overlay_changeset(struct overlay_chan= geset *ovcs) * of_overlay_apply() - Create and apply an overlay changeset * @ovcs: overlay changeset * @base: point to the target node to apply overlay + * @export_symbols_name: + * Name of the export symbol subnode of the @base node to + * provide extra symbols. Those extra symbols are used in + * the overlay symbols resolution. * * Creates and applies an overlay changeset. * @@ -911,11 +915,24 @@ static void free_overlay_changeset(struct overlay_cha= ngeset *ovcs) */ =20 static int of_overlay_apply(struct overlay_changeset *ovcs, - const struct device_node *base) + const struct device_node *base, + const char *export_symbols_name) { + struct device_node *export_symbols =3D NULL; int ret =3D 0, ret_revert, ret_tmp; =20 - ret =3D of_resolve_phandles(ovcs->overlay_root, NULL); + if (base && export_symbols_name) { + export_symbols =3D of_get_child_by_name(base, export_symbols_name); + if (!export_symbols) { + pr_err("overlay get export symbols '%s' from %pOF failed\n", + export_symbols_name, base); + ret =3D -EINVAL; + goto out; + } + } + + ret =3D of_resolve_phandles(ovcs->overlay_root, export_symbols); + of_node_put(export_symbols); if (ret) goto out; =20 @@ -1055,7 +1072,7 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32= overlay_fdt_size, } ovcs->overlay_mem =3D overlay_mem; =20 - ret =3D of_overlay_apply(ovcs, base); + ret =3D of_overlay_apply(ovcs, base, export_symbols_name); /* * If of_overlay_apply() error, calling free_overlay_changeset() may * result in a memory leak if the apply partly succeeded, so do NOT --=20 2.47.0 From nobody Wed Dec 17 15:54:34 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 6E7DB1C5CBC; Mon, 9 Dec 2024 15:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757523; cv=none; b=nHH/zdRpagikprM4vV5xNoMLK9d47GWs36B5xjQHcYuGE7D0HiaROTez2L1eCQ11kFOvn4l3GY/ch8Kia5HLhhF4qOGUInMTp+DO7NKI7BKlK4/XtCxpo9pdpgK68EnU4QmdcFXERc6sS8b4H7bqeBaguSW2ixsOXGRHUYvQf4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733757523; c=relaxed/simple; bh=GlHe5MSqIY/qCyPEONQZv5fJdEQl5XjwDqUWxFDiHno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvyhBqg0+8hV6vQEvHe2bMthA+S1OpWUjNZzP34YieirPSTDq7zKBmroCvsfAOckxHITU47HU5DwKn//wWmSgWc+llbLla2XE77qksTKttIAuTjh3ala/NAxkkdfP9mdQjUDn3xxWvNChgbgLQ1rjx7wZDQRi+Nf1zxQAdeO3aQ= 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=A8kJMkpq; arc=none smtp.client-ip=217.70.183.197 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="A8kJMkpq" Received: by mail.gandi.net (Postfix) with ESMTPA id 14EA91C0012; Mon, 9 Dec 2024 15:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733757518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gQVQsO33py92daYEPtx0h2qEmnzEGdMuLYStCbvuyw=; b=A8kJMkpqZMp805S8+u/fx6IcH3WxIZtpP1DMAXAPAjHgflPtc9wPTyeGmgLTZXInhF6VDK NwvckGGEgYJTHvqyA7rwiGVoxee57ggTli5+roj4DBfFvxy9TOsqUdppQzTMUPZZtjr2nc 25ydkHUCXwlKp2JUByiQNMosw/2te4nsocM3vzozBsCzUQjri60VEvk7Y8457Z3mQBg0KK Q81vURZxC7G8SWAnxHJS6MnNZ/HteTP14KdOBeWvKNdfzfrdPklb4kuAHSEoCO/taUvTyI h2ReqMvGbkFm+3M7IT0I/eG9OJ4C/aXQU5DsOjr0bedoWa1Ezt0F9NW6AZDRVg== From: Herve Codina To: Andrew Davis , Ayush Singh , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Herve Codina , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 7/7] of: unittest: Add tests for export symbols Date: Mon, 9 Dec 2024 16:18:25 +0100 Message-ID: <20241209151830.95723-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241209151830.95723-1-herve.codina@bootlin.com> References: <20241209151830.95723-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-GND-Sasl: herve.codina@bootlin.com Content-Type: text/plain; charset="utf-8" The export symbols feature allows to use some additional symbols provided in an export symbols node to resolve overlay symbols. Add tests to exercise the export symbols feature. Signed-off-by: Herve Codina Tested-by: Ayush Singh --- drivers/of/unittest-data/Makefile | 5 ++ .../unittest-data/overlay_export_symbols.dtso | 15 +++++ .../of/unittest-data/testcases_common.dtsi | 1 + .../unittest-data/tests-export-symbols.dtsi | 30 +++++++++ drivers/of/unittest.c | 64 +++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 drivers/of/unittest-data/overlay_export_symbols.dtso create mode 100644 drivers/of/unittest-data/tests-export-symbols.dtsi diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/M= akefile index 01a966e39f23..b51be046749a 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_OF_OVERLAY) +=3D overlay.dtbo.o \ overlay_gpio_04a.dtbo.o \ overlay_gpio_04b.dtbo.o \ overlay_pci_node.dtbo.o \ + overlay_export_symbols.dtbo.o \ overlay_bad_unresolved.dtbo.o =20 # enable creation of __symbols__ node @@ -66,6 +67,10 @@ DTC_FLAGS_testcases +=3D -Wno-interrupts_property \ # overlay_bad_add_dup_prop.dtbo \ # overlay_bad_phandle.dtbo \ # overlay_bad_symbol.dtbo \ +# +# Also overlay_export_symbols_ovl.dtbo is designed to be applied to a spec= ific +# node and cannot be applied statically with fdtoverlay + =20 apply_static_overlay_1 :=3D overlay_0.dtbo \ overlay_1.dtbo \ diff --git a/drivers/of/unittest-data/overlay_export_symbols.dtso b/drivers= /of/unittest-data/overlay_export_symbols.dtso new file mode 100644 index 000000000000..89c9df4ef89b --- /dev/null +++ b/drivers/of/unittest-data/overlay_export_symbols.dtso @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target-path=3D""; + __overlay__ { + ovl_node { + ref-base =3D <&test_export_base>; + ref-node =3D <&test_export_node>; + }; + }; + }; +}; diff --git a/drivers/of/unittest-data/testcases_common.dtsi b/drivers/of/un= ittest-data/testcases_common.dtsi index 1c2cdf353ae3..21ffe0fb03ef 100644 --- a/drivers/of/unittest-data/testcases_common.dtsi +++ b/drivers/of/unittest-data/testcases_common.dtsi @@ -18,4 +18,5 @@ node-remove { #include "tests-address.dtsi" #include "tests-platform.dtsi" #include "tests-overlay.dtsi" +#include "tests-export-symbols.dtsi" #include "tests-lifecycle.dtsi" diff --git a/drivers/of/unittest-data/tests-export-symbols.dtsi b/drivers/o= f/unittest-data/tests-export-symbols.dtsi new file mode 100644 index 000000000000..1650289b34cd --- /dev/null +++ b/drivers/of/unittest-data/tests-export-symbols.dtsi @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 + +/ { + testcase-data { + test-export-symbols { + test_export_symbols_b0: base0 { + test_export_symbols_n0: node { + dummy; + }; + + export-symbols { + test_export_base =3D <&test_export_symbols_b0>; + test_export_node =3D <&test_export_symbols_n0>; + }; + }; + + test_export_symbols_b1: base1 { + + test_export_symbols_n1: node { + dummy; + }; + + export-symbols { + test_export_base =3D <&test_export_symbols_b1>; + test_export_node =3D <&test_export_symbols_n1>; + }; + }; + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index f19e15f8b288..1be4ffb7a4db 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -4043,6 +4043,69 @@ static __init void of_unittest_overlay_high_level(vo= id) mutex_unlock(&of_mutex); } =20 +OVERLAY_INFO_EXTERN(overlay_export_symbols); + +static __init void of_unittest_export_symbols(const char *prefix, + const char *base_full_path) +{ + const struct overlay_info ovl =3D OVERLAY_INFO(overlay_export_symbols, 0,= 0); + struct device_node *ovl_node; + struct device_node *base; + struct device_node *node; + struct device_node *ref; + int ovcs_id; + u32 size; + int ret; + + base =3D of_find_node_by_path(base_full_path); + if (unittest(base, "%s: Get base (%s) failed\n", prefix, base_full_path)) + return; + + node =3D of_get_child_by_name(base, "node"); + if (unittest(base, "%s: Get node from %pOF failed\n", prefix, base)) + goto end_put_base; + + size =3D ovl.dtbo_end - ovl.dtbo_begin; + ret =3D of_overlay_fdt_apply(ovl.dtbo_begin, size, &ovcs_id, base, "expor= t-symbols"); + if (unittest(!ret, "%s: Apply '%s' failed (%d)\n", prefix, ovl.name, ret)) + goto end_put_node; + + ovl_node =3D of_get_child_by_name(base, "ovl_node"); + if (unittest(ovl_node, "%s: Get ovl_node from %pOF failed\n", prefix, bas= e)) + goto end_remove_overlay; + + ref =3D of_parse_phandle(ovl_node, "ref-base", 0); + if (unittest(ref, "%s: Parse 'ref-base' from %pOF failed\n", prefix, ovl_= node)) + goto end_put_ovl_node; + unittest(ref =3D=3D base, + "%s: Node from 'ref-base' phandle mismatches (got %pOF, expected %pOF)\= n", + prefix, ref, base); + of_node_put(ref); + + ref =3D of_parse_phandle(ovl_node, "ref-node", 0); + if (unittest(ref, "%s: Parse 'ref-node' from %pOF failed\n", prefix, ovl_= node)) + goto end_put_ovl_node; + unittest(ref =3D=3D node, + "%s: Node from 'ref-node' phandle mismatches (got %pOF, expected %pOF)\= n", + prefix, ref, node); + of_node_put(ref); + +end_put_ovl_node: + of_node_put(ovl_node); +end_remove_overlay: + of_overlay_remove(&ovcs_id); +end_put_node: + of_node_put(node); +end_put_base: + of_node_put(base); +} + +static __init void of_unittest_overlay_export_symbols(void) +{ + of_unittest_export_symbols("base0", "/testcase-data/test-export-symbols/b= ase0"); + of_unittest_export_symbols("base1", "/testcase-data/test-export-symbols/b= ase1"); +} + static int of_unittest_pci_dev_num; static int of_unittest_pci_child_num; =20 @@ -4281,6 +4344,7 @@ static int __init of_unittest(void) of_unittest_overlay(); of_unittest_lifecycle(); of_unittest_pci_node(); + of_unittest_overlay_export_symbols(); =20 /* Double check linkage after removing testcase data */ of_unittest_check_tree_linkage(); --=20 2.47.0