From: David Gibson <david@gibson.dropbear.id.au>
To: Simon Glass <sjg@chromium.org>
Cc: Devicetree Compiler <devicetree-compiler@vger.kernel.org>,
Herve Codina <herve.codina@bootlin.com>
Subject: Re: [PATCH v5 08/10] dtc: Move path-reference handling out of the grammar
Date: Fri, 27 Nov 2026 14:34:47 +1100 [thread overview]
Message-ID: <awj6SSdzpGKqFKCU@gractus.seuss> (raw)
In-Reply-To: <20261126184126.1472738-9-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 4198 bytes --]
On Thu, Nov 26, 2026 at 11:41:07AM -0700, Simon Glass wrote:
> The grammar action for a top-level &{/path} { ... } holds its merge
> logic, including making an overlay fragment in a plugin.
>
> Move it into merge_ref(), which can tell a path from a label by looking
> at the reference, and use a single rule for both kinds of reference.
>
> The output does not change.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Patches 3..8 merged.
> ---
>
> Changes in v5:
> - Use the term 'source layer' rather than 'fragment'
>
> Changes in v4:
> - Look up the reference once, at the top of merge_ref()
>
> Changes in v2:
> - Combine merge_path_ref() into merge_ref()
> - Combine the rules for label and path references, using dt_ref
>
> dtc-parser.y | 27 +--------------------------
> livetree.c | 31 ++++++++++++++++++++++---------
> 2 files changed, 23 insertions(+), 35 deletions(-)
>
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 8e67182..993eb7b 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -192,32 +192,7 @@ devicetree:
> ERROR(&@3, "Label or path %s not found", $3);
> $$ = $1;
> }
> - | devicetree DT_PATH_REF nodedef
> - {
> - struct node *target = get_node_by_ref($1, $2);
> -
> - /*
> - * We rely on the rule being always:
> - * versioninfo plugindecl memreserves devicetree
> - * so $-1 is what we want (plugindecl)
> - */
> - if ($<flags>-1 & DTSF_PLUGIN) {
> - if (is_ref_relative($2))
> - ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
> - /* A path is in the base tree and a label may be */
> - if ($2[0] == '/' || !target)
> - add_orphan_node($1, $3, $2);
> - else
> - merge_nodes(target, $3);
> - } else {
> - if (target)
> - merge_nodes(target, $3);
> - else
> - ERROR(&@2, "Label or path %s not found", $2);
> - }
> - $$ = $1;
> - }
> - | devicetree DT_LABEL_REF nodedef
> + | devicetree dt_ref nodedef
> {
> struct source_layer *layer;
>
> diff --git a/livetree.c b/livetree.c
> index 18ac4ab..0be2da2 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -544,29 +544,42 @@ bool is_ref_relative(const char *ref)
> }
>
> /*
> - * Merge a source layer which refers to a label into the node with that label.
> - * In a plugin, a label which is not found becomes an overlay fragment.
> + * Merge a source layer which refers to a label or path into the node it refers
> + * to.
> + *
> + * In a plugin, a path always refers to the base tree and a label may do so, if
> + * it is not found. In both cases, the source layer becomes an overlay fragment.
> *
> * Returns true on success, false on an error, which has been reported.
> */
> bool merge_ref(struct node *dt, struct source_layer *layer, bool plugin)
> {
> struct node *target = get_node_by_ref(dt, layer->ref);
> + bool ok = true;
>
> assert(layer->type == LAYER_NODE);
> - if (target) {
> - merge_nodes(target, layer->node);
> - return true;
> + if (plugin) {
> + if (is_ref_relative(layer->ref)) {
> + srcpos_error(layer->ref_srcpos, "Error",
> + "Label-relative reference %s not supported in plugin",
> + layer->ref);
> + ok = false;
> + }
> + if (layer->ref[0] == '/' || !target) {
> + /* Add a fragment@N node for the reference */
> + add_orphan_node(dt, layer->node, layer->ref);
> + return ok;
> + }
> }
> - if (!plugin) {
> +
> + if (!target) {
> srcpos_error(layer->ref_srcpos, "Error",
> "Label or path %s not found", layer->ref);
> return false;
> }
> - /* The label may be in the base tree, so add a fragment@N node for it */
> - add_orphan_node(dt, layer->node, layer->ref);
> + merge_nodes(target, layer->node);
>
> - return true;
> + return ok;
> }
>
> /*
> --
> 2.43.0
>
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-11-27 3:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 18:40 [PATCH v5 00/10] dtc: Move the merging of source layers out of the grammar Simon Glass
2026-11-26 18:41 ` [PATCH v5 01/10] tests: Note that &{/} in a plugin is existing behaviour Simon Glass
2026-11-26 18:41 ` [PATCH v5 02/10] tests: Check a label on a node which is not in a plugin Simon Glass
2026-11-27 2:50 ` David Gibson
2026-11-26 18:41 ` [PATCH v5 03/10] dtc: Add a struct for the source layers of a dts file Simon Glass
2026-11-26 20:42 ` Herve Codina
2026-11-27 18:40 ` Simon Glass
2026-11-26 18:41 ` [PATCH v5 04/10] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-26 18:41 ` [PATCH v5 05/10] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-26 18:41 ` [PATCH v5 06/10] dtc: Move label-reference " Simon Glass
2026-11-26 18:41 ` [PATCH v5 07/10] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-26 18:41 ` [PATCH v5 08/10] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-27 3:34 ` David Gibson [this message]
2026-11-26 18:41 ` [PATCH v5 09/10] dtc: Move labelled-reference " Simon Glass
2026-11-27 3:43 ` David Gibson
2026-11-27 18:44 ` Simon Glass
2026-11-26 18:41 ` [PATCH v5 10/10] dtc: Move first-reference " Simon Glass
2026-11-27 3:49 ` David Gibson
2026-11-27 18:46 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awj6SSdzpGKqFKCU@gractus.seuss \
--to=david@gibson.dropbear.id.au \
--cc=devicetree-compiler@vger.kernel.org \
--cc=herve.codina@bootlin.com \
--cc=sjg@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.