All of lore.kernel.org
 help / color / mirror / Atom feed
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 10/10] dtc: Move first-reference handling out of the grammar
Date: Fri, 27 Nov 2026 14:49:57 +1100	[thread overview]
Message-ID: <awj91V_VRaV9Mw6B@gractus.seuss> (raw)
In-Reply-To: <20261126184126.1472738-11-sjg@chromium.org>

[-- Attachment #1: Type: text/plain, Size: 5056 bytes --]

On Thu, Nov 26, 2026 at 11:41:09AM -0700, Simon Glass wrote:
> In a plugin, the first source layer can refer to a label or path instead
> of being the root node. The grammar action for this holds its merge
> logic, which makes an overlay fragment in a new tree.
> 
> Move it into a new merge_first_ref(), passing it a struct source_layer
> for the reference and node. This is the last user of is_ref_relative()
> in the grammar, so make that function static.
> 
> 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>

Though as noted, I don't see this as the final step.

> ---
> 
> Changes in v5:
> - Use the term 'source layer' rather than 'fragment'
> 
> Changes in v4:
> - Free the fragment after merging it
> 
> Changes in v2:
> - Return true on success from merge_first_ref()
> - Use dt_ref instead of fragment_ref
> 
>  dtc-parser.y | 15 +++++++--------
>  dtc.h        |  3 ++-
>  livetree.c   | 31 ++++++++++++++++++++++++++++++-
>  3 files changed, 39 insertions(+), 10 deletions(-)
> 
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 98b68b1..4a6da6d 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -164,19 +164,18 @@ devicetree:
>  		}
>  	| dt_ref nodedef
>  		{
> +			struct source_layer *layer;
> +
> +			layer = build_layer_ref(NULL, $1, &@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))
> -				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);
> -			$$ = add_orphan_node(
> -					name_node(build_node(NULL, NULL, NULL),
> -						  ""),
> -					$2, $1);
> +			if (!merge_first_ref(&$$, layer,
> +					     $<flags>-1 & DTSF_PLUGIN))
> +				treesource_error = true;
> +			free_layer(layer);
>  		}
>  	| devicetree DT_LABEL dt_ref nodedef
>  		{
> diff --git a/dtc.h b/dtc.h
> index eaf247f..97db4dc 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -351,6 +351,8 @@ struct source_layer *build_layer_delete_node(char *ref,
>  struct source_layer *build_layer_omit_if_no_ref(char *ref,
>  						struct srcpos *ref_srcpos);
>  void free_layer(struct source_layer *layer);
> +bool merge_first_ref(struct node **dtp, struct source_layer *layer,
> +		     bool plugin);
>  bool merge_ref(struct node *dt, struct source_layer *layer, bool plugin);
>  bool merge_delete_node(struct node *dt, struct source_layer *layer);
>  bool merge_omit_if_no_ref(struct node *dt, struct source_layer *layer);
> @@ -370,7 +372,6 @@ struct dt_info {
>  struct dt_info *build_dt_info(unsigned int dtsflags,
>  			      struct reserve_info *reservelist,
>  			      struct node *tree, uint32_t boot_cpuid_phys);
> -bool is_ref_relative(const char *ref);
>  void sort_tree(struct dt_info *dti);
>  void generate_labels_from_tree(struct dt_info *dti, const char *name);
>  void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
> diff --git a/livetree.c b/livetree.c
> index a33f021..72552be 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -538,11 +538,40 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
>  }
>  
>  /* Check whether a reference is relative to a label, e.g. &{label/node} */
> -bool is_ref_relative(const char *ref)
> +static bool is_ref_relative(const char *ref)
>  {
>  	return ref[0] != '/' && strchr(&ref[1], '/');
>  }
>  
> +/*
> + * Make the tree at *dtp from a first source layer which refers to a label or
> + * path, rather than being the root node. This is only valid in a plugin, where
> + * the source layer becomes an overlay fragment.
> + *
> + * Returns true on success, false on an error, which has been reported.
> + */
> +bool merge_first_ref(struct node **dtp, struct source_layer *layer,
> +		     bool plugin)
> +{
> +	bool ok = true;
> +
> +	if (!plugin) {
> +		srcpos_error(layer->node->srcpos, "Error",
> +			     "Label or path %s not found", layer->ref);
> +		ok = false;
> +	} else if (is_ref_relative(layer->ref)) {
> +		srcpos_error(layer->node->srcpos, "Error",
> +			     "Label-relative reference %s not supported in plugin",
> +			     layer->ref);
> +		ok = false;
> +	}
> +	/* Make a new, empty tree with a fragment@N node for the reference */
> +	*dtp = add_orphan_node(name_node(build_node(NULL, NULL, NULL), ""),
> +			       layer->node, layer->ref);
> +
> +	return ok;
> +}
> +
>  /*
>   * Merge a source layer which refers to a label or path into the node it refers
>   * to, adding any label in the source layer to that node.
> -- 
> 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 --]

  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
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 [this message]
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=awj91V_VRaV9Mw6B@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.