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 v4 02/10] dtc: Add a struct for the top-level fragments of a dts file
Date: Wed, 25 Nov 2026 11:44:05 +1100 [thread overview]
Message-ID: <awYvRAeiVSO9f0ls@gractus.seuss> (raw)
In-Reply-To: <20261116235813.935070-3-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 5769 bytes --]
On Mon, Nov 16, 2026 at 04:57:56PM -0700, Simon Glass wrote:
> A dts file is made up of top-level fragments: the root node, later
> definitions of a node by label or path, and /delete-node/ or
> /omit-if-no-ref/ with a reference. We would like to deal with each
> fragment on its own before it is merged, for example to apply deletes
> consistently or to run some checks on each one, but that requires
> keeping the fragments apart. At present the parser merges each one into
> the tree as soon as it is parsed.
>
> Add a struct fragment to hold one which refers to a node, with a
> function to build each kind and one to free it.
>
> These are not used yet.
After consideration of our previous discussions, I'm leaning towards
using the term "source layer" for these top level components (thanks
for the "layer" suggestion). It's more verbose than I'd like, but I
think disambiguating from dtb level "fragments" is worth it.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
Apart from the suggested name change,
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>
> Changes in v4:
> - Drop build_fragment_root(), append_fragment() and the next pointer
> - Drop label_srcpos, since the position of the reference is enough
> - Shorten the comment on struct fragment
> - Use 0 rather than '\0' in memset()
>
> Changes in v2:
> - Add a constructor for each kind of fragment, taking all its fields
> - Add the list to struct dt_info later, when it is first used
> - Change the subject from 'Add a list' to 'Add a struct'
> - Drop path_ref in favour of checking the ref for a leading '/'
> - Replace FRAGMENT_ROOT and FRAGMENT_REF with FRAGMENT_NODE
> - Use a NULL ref for the root node
>
> dtc.h | 33 +++++++++++++++++++++++++++++++++
> livetree.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 85 insertions(+)
>
> diff --git a/dtc.h b/dtc.h
> index 791f815..ac18616 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -318,6 +318,39 @@ struct reserve_info *chain_reserve_entry(struct reserve_info *first,
> struct reserve_info *add_reserve_entry(struct reserve_info *list,
> struct reserve_info *new);
>
> +/*
> + * A fragment is one top-level part of a dts file, after the header and any
> + * memory reservations, which refers to a node by label or path: a later
> + * definition of the node, or a /delete-node/ or /omit-if-no-ref/. The root
> + * node, / { ... };, is not held as a fragment.
> + *
> + * This is not the same as an overlay fragment (a fragment@N node), although
> + * in a plugin a fragment may become one when it is merged.
> + */
> +
> +enum fragment_type {
> + FRAGMENT_NODE, /* [label:] &ref { ... }; */
> + FRAGMENT_DELETE_NODE, /* /delete-node/ &ref; */
> + FRAGMENT_OMIT_IF_NO_REF, /* /omit-if-no-ref/ &ref; */
> +};
> +
> +/* The label and node are NULL if the fragment does not have them */
> +struct fragment {
> + enum fragment_type type;
> + char *ref; /* label or path referred to */
> + struct srcpos *ref_srcpos; /* position of ref */
> + char *label; /* label to add to the target */
> + struct node *node; /* the node definition */
> +};
> +
> +struct fragment *build_fragment_ref(char *label, char *ref,
> + struct srcpos *ref_srcpos,
> + struct node *node);
> +struct fragment *build_fragment_delete_node(char *ref,
> + struct srcpos *ref_srcpos);
> +struct fragment *build_fragment_omit_if_no_ref(char *ref,
> + struct srcpos *ref_srcpos);
> +void free_fragment(struct fragment *f);
>
> struct dt_info {
> unsigned int dtsflags;
> diff --git a/livetree.c b/livetree.c
> index abe73de..4231c64 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -448,6 +448,58 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list,
> return list;
> }
>
> +/* Create a fragment of the given type, with its other fields NULL */
> +static struct fragment *new_fragment(enum fragment_type type, char *ref,
> + struct srcpos *ref_srcpos)
> +{
> + struct fragment *new = xmalloc(sizeof(*new));
> +
> + memset(new, 0, sizeof(*new));
> +
> + new->type = type;
> + new->ref = ref;
> + new->ref_srcpos = srcpos_copy(ref_srcpos);
> +
> + return new;
> +}
> +
> +/* Create a fragment for [label:] &ref { ... }; where label is NULL if absent */
> +struct fragment *build_fragment_ref(char *label, char *ref,
> + struct srcpos *ref_srcpos,
> + struct node *node)
> +{
> + struct fragment *new = new_fragment(FRAGMENT_NODE, ref, ref_srcpos);
> +
> + new->label = label;
> + new->node = node;
> +
> + return new;
> +}
> +
> +/* Create a fragment for /delete-node/ &ref; */
> +struct fragment *build_fragment_delete_node(char *ref,
> + struct srcpos *ref_srcpos)
> +{
> + return new_fragment(FRAGMENT_DELETE_NODE, ref, ref_srcpos);
> +}
> +
> +/* Create a fragment for /omit-if-no-ref/ &ref; */
> +struct fragment *build_fragment_omit_if_no_ref(char *ref,
> + struct srcpos *ref_srcpos)
> +{
> + return new_fragment(FRAGMENT_OMIT_IF_NO_REF, ref, ref_srcpos);
> +}
> +
> +/*
> + * Free a fragment, but not its node, reference or label, since the tree may
> + * still use these
> + */
> +void free_fragment(struct fragment *f)
> +{
> + srcpos_free(f->ref_srcpos);
> + free(f);
> +}
> +
> static void fill_fullpaths(struct node *tree, const char *prefix)
> {
> struct node *child;
> --
> 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-25 1:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 23:57 [PATCH v4 00/10] dtc: Move the merging of fragments out of the grammar Simon Glass
2026-11-16 23:57 ` [PATCH v4 01/10] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-25 0:34 ` David Gibson
2026-11-25 6:42 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 02/10] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-25 0:44 ` David Gibson [this message]
2026-11-16 23:57 ` [PATCH v4 03/10] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-25 0:48 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 04/10] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-25 1:15 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 05/10] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-25 1:16 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 06/10] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-25 6:12 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 07/10] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-25 6:16 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 08/10] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-25 6:18 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 09/10] dtc: Move labelled-reference " Simon Glass
2026-11-25 6:21 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 10/10] dtc: Move first-reference " Simon Glass
2026-11-25 6:24 ` 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=awYvRAeiVSO9f0ls@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox