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 v3 16/18] dtc: Add the overlay fragments from merge_fragments()
Date: Mon, 16 Nov 2026 15:12:42 +1100	[thread overview]
Message-ID: <avqCubv6DB--kLeB@gractus.seuss> (raw)
In-Reply-To: <20261106195159.2623314-17-sjg@chromium.org>

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

On Fri, Nov 06, 2026 at 12:51:43PM -0700, Simon Glass wrote:
> In a plugin, merge_first_ref() and merge_ref() call add_orphan_node() to
> turn a fragment which refers to the base tree into an overlay fragment
> (a fragment@N node). The grammar actions have always done this, but it
> mixes converting the plugin to the overlay format into the functions
> which merge each fragment.
> 
> Have merge_fragment() tell its caller when a fragment is for the base
> tree, and call add_orphan_node() from merge_fragments() instead, so that
> none of the merge_*() functions does the conversion. Add a comment for
> add_orphan_node() too.
> 
> This does not change the output.
> 
> Suggested-by: Herve Codina <herve.codina@bootlin.com>
> Link: https://lore.kernel.org/devicetree-compiler/20261105100714.47bf0434@bootlin.com/
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> dtc gives the same output and messages as before for every .dts and
> .dtso file in Linux v7.3-12284-g3799eeb906c9
> 
> Changes in v3:
> - Add new patch to add the overlay fragments from merge_fragments()
> 
>  livetree.c | 47 +++++++++++++++++++++++++++++++----------------
>  1 file changed, 31 insertions(+), 16 deletions(-)
> 
> diff --git a/livetree.c b/livetree.c
> index f2c7703..c5fec49 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -225,6 +225,15 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
>  	return old_node;
>  }
>  
> +/*
> + * Add an overlay fragment (a fragment@N node) to the root of a plugin, for a
> + * node which refers to the base tree. The node becomes the fragment's
> + * __overlay__ subnode and ref gives its target, either a path (target-path)
> + * or a label (target, as a phandle reference). Fragments are numbered in the
> + * order they are added.
> + *
> + * Returns the root node, dt
> + */
>  struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
>  {
>  	static unsigned int next_orphan_fragment = 0;
> @@ -611,9 +620,9 @@ static struct node *lookup_ref(struct node *dt, struct fragment *f)
>  }
>  
>  /*
> - * Make the tree at *dtp from a first fragment which refers to a label or path,
> - * rather than being the root node. This is only valid in a plugin, where the
> - * fragment becomes an overlay fragment.
> + * Make an empty tree at *dtp for a first fragment which refers to a label or
> + * path, rather than being the root node. This is only valid in a plugin, where
> + * the fragment becomes an overlay fragment.
>   *
>   * Returns true on success, false on an error, which has been reported.
>   */
> @@ -628,9 +637,7 @@ static bool merge_first_ref(struct node **dtp, struct fragment *f, bool plugin)
>  			     "Label or path %s not found", f->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), ""),
> -			       f->node, f->ref);
> +	*dtp = name_node(build_node(NULL, NULL, NULL), "");

This seems a bit awkward, since this operation no longer resembles any
kind of merge.  Seems like it would be nicer to unconditionally create
an empty tree in merge_fragments(), then "merge" everything into it,
including root fragments.

>  	return ok;
>  }
> @@ -640,12 +647,14 @@ static bool merge_first_ref(struct node **dtp, struct fragment *f, bool plugin)
>   * adding any label in the fragment to that node.
>   *
>   * 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 fragment becomes an overlay fragment,
> - * unless it adds a label, which needs a node in the plugin itself.
> + * it is not found. In both cases, *for_basep is set to true so that the
> + * fragment becomes an overlay fragment, unless it adds a label, which needs a
> + * node in the plugin itself.
>   *
>   * Returns true on success, false on an error, which has been reported.
>   */
> -static bool merge_ref(struct node *dt, struct fragment *f, bool plugin)
> +static bool merge_ref(struct node *dt, struct fragment *f, bool plugin,
> +		      bool *for_basep)

Might be nicer to return an enum, rather than one bool directly and
another via a parameter.

>  {
>  	struct node *target;
>  	bool ok = true;
> @@ -656,8 +665,7 @@ static bool merge_ref(struct node *dt, struct fragment *f, bool plugin)
>  					f->ref_srcpos);
>  		if (!f->label &&
>  		    (f->ref[0] == '/' || !get_node_by_ref(dt, f->ref))) {
> -			/* Add a fragment@N node for the reference */
> -			add_orphan_node(dt, f->node, f->ref);
> +			*for_basep = true;
>  			return ok;
>  		}
>  	}
> @@ -709,12 +717,13 @@ static bool merge_omit_if_no_ref(struct node *dt, struct fragment *f)
>  
>  /*
>   * Merge a fragment of a dts file into the tree at *dtp, which is NULL for the
> - * first fragment. A reference is looked up in the tree as merged so far.
> + * first fragment. A reference is looked up in the tree as merged so far. If
> + * the fragment is for the base tree, *for_basep is set to true.
>   *
>   * Returns true on success, false on an error, which has been reported.
>   */
>  static bool merge_fragment(struct node **dtp, struct fragment *f,
> -			   bool plugin)
> +			   bool plugin, bool *for_basep)
>  {
>  	struct node *dt = *dtp;
>  
> @@ -724,13 +733,14 @@ static bool merge_fragment(struct node **dtp, struct fragment *f,
>  			*dtp = name_node(f->node, "");
>  			return true;
>  		}
> +		*for_basep = true;
>  		return merge_first_ref(dtp, f, plugin);
>  	}
>  
>  	switch (f->type) {
>  	case FRAGMENT_NODE:
>  		if (f->ref)
> -			return merge_ref(dt, f, plugin);
> +			return merge_ref(dt, f, plugin, for_basep);
>  		*dtp = merge_nodes(dt, f->node);
>  		break;
>  	case FRAGMENT_DELETE_NODE:
> @@ -743,7 +753,8 @@ static bool merge_fragment(struct node **dtp, struct fragment *f,
>  }
>  
>  /*
> - * Merge the fragments of a dts file into a single tree, in source order.
> + * Merge the fragments of a dts file into a single tree, in source order. In a
> + * plugin, each fragment for the base tree becomes an overlay fragment.
>   *
>   * Returns true on success, false on errors, which have been reported.
>   */
> @@ -758,9 +769,13 @@ bool merge_fragments(struct dt_info *dti)
>  		return true;
>  
>  	for (f = dti->fragments; f; f = next) {
> +		bool for_base = false;
> +
>  		next = f->next;
> -		if (!merge_fragment(&dt, f, plugin))
> +		if (!merge_fragment(&dt, f, plugin, &for_base))
>  			ok = false;
> +		if (for_base)
> +			add_orphan_node(dt, f->node, f->ref);
>  		free_fragment(f);
>  	}
>  
> -- 
> 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-16  4:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 19:51 [PATCH v3 00/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-06 19:51 ` [PATCH v3 01/18] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-13  3:20   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 02/18] srcpos: Allow srcpos_string() to accept NULL Simon Glass
2026-11-11  4:56   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 03/18] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-13  3:46   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 04/18] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-13  3:49   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 05/18] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-13  3:50   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 06/18] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-13  3:55   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 07/18] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-13  3:58   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 08/18] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-13  4:01   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 09/18] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-13  4:09   ` David Gibson
2026-11-16 23:49     ` Simon Glass
2026-11-16 23:55       ` David Gibson
2026-11-06 19:51 ` [PATCH v3 10/18] dtc: Move labelled-reference " Simon Glass
2026-11-13  4:13   ` David Gibson
2026-11-16 23:49     ` Simon Glass
2026-11-16 23:57       ` David Gibson
2026-11-06 19:51 ` [PATCH v3 11/18] dtc: Move first-reference " Simon Glass
2026-11-13  4:19   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 12/18] dtc: Add merge_fragment() to merge any fragment Simon Glass
2026-11-13  4:24   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 13/18] dtc: Add helpers for the errors when merging a fragment Simon Glass
2026-11-16  3:49   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 14/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-16  4:04   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 15/18] dtc: Merge the fragments of a dts file in main() Simon Glass
2026-11-16  4:08   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 16/18] dtc: Add the overlay fragments from merge_fragments() Simon Glass
2026-11-16  4:12   ` David Gibson [this message]
2026-11-06 19:51 ` [PATCH v3 17/18] tests: Check references to a generated overlay fragment Simon Glass
2026-11-16  4:15   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 18/18] dtc: Add the overlay fragments after merging a plugin Simon Glass
2026-11-16  4:34   ` David Gibson

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=avqCubv6DB--kLeB@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.