[RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes

Herve Codina posted 77 patches 3 weeks, 5 days ago
[RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by Herve Codina 3 weeks, 5 days ago
Referencing a sub-node from an orphan node using a path is needed.

Indeed, using the following snippet:
--- 8< ---
/addon/;

&node1 {
	subnode {
		foo-phandle = <&foo_label>;
	};
};

&node2 {
	foo_label: foo {
		prop = <1>;
	};
};
--- 8< ---

Even if node2 is an orphan node, foo is a local node. foo-phandle
references the foo node using a label.

Once converted to a dtb, the label is lost. Only the phandle of the foo
node is used in the foo-phandle property and this property is marked
FDT_REF_LOCAL.

Converting back this dtb to a dts, the marked local phandle should be
translated to a path to the related local node.

The issue is that this local node is not in a root device tree. We need
to identify the orphan node the foo node belongs to.

We cannot use a path starting by '/'. This kind of path identify node in
the root tree.

This new syntax allows to identify the orphan node in a path:
  $<orphan_name>/<path>

This leads to a reference by path in the form &{$<orphan_name>/<path>}.

Using the previous example, those both phandles points to the same node:
  foo-phandle1 = <&foo_label>;    /* Reference by label */
  foo-phandle2 = <&{$node2/foo}>; /* Reference by path */

When the dtb is converted back to a dts, the marked local phandle
involving subnode available from orphan nodes can be translated to a
reference by path thanks to the new syntax.

Add support for this &{$<orphan_name>/<path>} syntax to reference by
path a local node from an orphan node.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 dtc-lexer.l  |  7 +++++++
 dtc-parser.y | 19 +++++++++++++++++++
 dtc.c        | 22 ++++++++++++++++++++--
 livetree.c   | 14 +++++++++++++-
 treesource.c |  3 ++-
 5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index cb616f9..540bfdf 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -239,6 +239,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 			return DT_PATH_REF;
 		}
 
+<*>"&{\$"{LABEL}([/]{PATHCHAR}*)?\}  {	/* orphan path reference */
+			yytext[yyleng-1] = '\0';
+			DPRINT("Ref orphan path: %s\n", yytext+1);
+			yylval.labelref = xstrdup(yytext+2);
+			return DT_ORPHAN_PATH_REF;
+		}
+
 <BYTESTRING>[0-9a-fA-F]{2} {
 			yylval.byte = strtol(yytext, NULL, 16);
 			DPRINT("Byte: %02x\n", (int)yylval.byte);
diff --git a/dtc-parser.y b/dtc-parser.y
index 7f8c294..9d619cd 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -111,6 +111,7 @@ static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanl
 %token <labelref> DT_LABEL
 %token <labelref> DT_LABEL_REF
 %token <labelref> DT_PATH_REF
+%token <labelref> DT_ORPHAN_PATH_REF
 %token DT_INCBIN
 
 %type <data> propdata
@@ -589,6 +590,24 @@ arrayprefix:
 				ERROR(&@2, "References are only allowed in "
 					    "arrays with 32-bit elements.");
 
+			$$.data = data_append_integer($1.data, val, $1.bits);
+		}
+	| arrayprefix DT_ORPHAN_PATH_REF
+		{
+			uint64_t val = ~0ULL >> (64 - $1.bits);
+
+			if ($1.bits == 32) {
+				if (!(last_header_flags & DTSF_ADDON))
+					ERROR(&@2, "Orphan path reference %s supported only in addon", $2);
+
+				$1.data = data_add_marker($1.data,
+							  REF_PHANDLE,
+							  $2);
+			} else {
+				ERROR(&@2, "References are only allowed in "
+					    "arrays with 32-bit elements.");
+			}
+
 			$$.data = data_append_integer($1.data, val, $1.bits);
 		}
 	| arrayprefix DT_LABEL
diff --git a/dtc.c b/dtc.c
index 63725bf..72d85e4 100644
--- a/dtc.c
+++ b/dtc.c
@@ -48,13 +48,31 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 static void dti_fill_fullpaths(struct dt_info *dti)
 {
 	struct node *orphan;
+	struct node *child;
 
 	/* Fill fullpaths for the root node */
 	if (dti->dt)
 		fill_fullpaths(dti->dt, "");
 
-	for_each_orphan(dti->orphanlist, orphan)
-		fill_fullpaths(orphan, "__orphan__/");
+	/* Fill fullpaths for orphan nodes */
+	for_each_orphan(dti->orphanlist, orphan) {
+		if (orphan->name[0] == '\0')
+			die("orphan node has an empty name\n");
+
+		/*
+		 * An orphan node name is set with its reference.
+		 * Its name is in the form "&xxxxxx".
+		 * For its full path, we use "$xxxxx" to make a clear
+		 * distinction between a reference (&xxxx) where a resolution
+		 * could be involved vs a "simple" path where we just need to
+		 * identified the orphan ($xxxx).
+		 */
+		xasprintf(&orphan->fullpath, "$%s", orphan->name + 1);
+		orphan->basenamelen = strlen(orphan->name);
+
+		for_each_child(orphan, child)
+			fill_fullpaths(child, orphan->fullpath);
+	}
 }
 
 /* Usage related data. */
diff --git a/livetree.c b/livetree.c
index 59b912d..263da1f 100644
--- a/livetree.c
+++ b/livetree.c
@@ -804,7 +804,19 @@ static struct node *get_node_by_ref(struct node *tree, const char *ref)
 			path = slash + 1;
 		}
 
-		target = get_node_by_label(tree, label);
+		if (label[0] == '$' && tree->name[0] == '&') {
+			/*
+			 * We search for an orphan and the given tree is an
+			 * orphan. Use the given tree only if it matches the
+			 * expected orphan.
+			 */
+			if (streq(label + 1, tree->name + 1))
+				target = tree;
+			else
+				target = NULL;
+		} else {
+			target = get_node_by_label(tree, label);
+		}
 
 		free(buf);
 
diff --git a/treesource.c b/treesource.c
index 71dbd5f..44de0db 100644
--- a/treesource.c
+++ b/treesource.c
@@ -278,7 +278,8 @@ static void write_propval(FILE *f, struct property *prop)
 					break;
 
 			if (m_phandle) {
-				if (m_phandle->ref[0] == '/')
+				if (m_phandle->ref[0] == '/' /* Root node */ ||
+				    m_phandle->ref[0] == '$' /* Orphan node */)
 					fprintf(f, "&{%s}", m_phandle->ref);
 				else
 					fprintf(f, "&%s", m_phandle->ref);
-- 
2.52.0
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by David Gibson 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 03:19:54PM +0100, Herve Codina wrote:
> Referencing a sub-node from an orphan node using a path is needed.
> 
> Indeed, using the following snippet:
> --- 8< ---
> /addon/;
> 
> &node1 {
> 	subnode {
> 		foo-phandle = <&foo_label>;
> 	};
> };
> 
> &node2 {
> 	foo_label: foo {
> 		prop = <1>;
> 	};
> };
> --- 8< ---
> 
> Even if node2 is an orphan node, foo is a local node. foo-phandle
> references the foo node using a label.

Another option would be to eliminate the idea of local references, and
require a symbol be attached to things that you want to reference by
label.


> 
> Once converted to a dtb, the label is lost. Only the phandle of the foo
> node is used in the foo-phandle property and this property is marked
> FDT_REF_LOCAL.
> 
> Converting back this dtb to a dts, the marked local phandle should be
> translated to a path to the related local node.
> 
> The issue is that this local node is not in a root device tree. We need
> to identify the orphan node the foo node belongs to.
> 
> We cannot use a path starting by '/'. This kind of path identify node in
> the root tree.
> 
> This new syntax allows to identify the orphan node in a path:
>   $<orphan_name>/<path>
> 
> This leads to a reference by path in the form &{$<orphan_name>/<path>}.
> 
> Using the previous example, those both phandles points to the same node:
>   foo-phandle1 = <&foo_label>;    /* Reference by label */
>   foo-phandle2 = <&{$node2/foo}>; /* Reference by path */
> 
> When the dtb is converted back to a dts, the marked local phandle
> involving subnode available from orphan nodes can be translated to a
> reference by path thanks to the new syntax.
> 
> Add support for this &{$<orphan_name>/<path>} syntax to reference by
> path a local node from an orphan node.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  dtc-lexer.l  |  7 +++++++
>  dtc-parser.y | 19 +++++++++++++++++++
>  dtc.c        | 22 ++++++++++++++++++++--
>  livetree.c   | 14 +++++++++++++-
>  treesource.c |  3 ++-
>  5 files changed, 61 insertions(+), 4 deletions(-)
> 
> diff --git a/dtc-lexer.l b/dtc-lexer.l
> index cb616f9..540bfdf 100644
> --- a/dtc-lexer.l
> +++ b/dtc-lexer.l
> @@ -239,6 +239,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
>  			return DT_PATH_REF;
>  		}
>  
> +<*>"&{\$"{LABEL}([/]{PATHCHAR}*)?\}  {	/* orphan path reference */
> +			yytext[yyleng-1] = '\0';
> +			DPRINT("Ref orphan path: %s\n", yytext+1);
> +			yylval.labelref = xstrdup(yytext+2);
> +			return DT_ORPHAN_PATH_REF;
> +		}
> +
>  <BYTESTRING>[0-9a-fA-F]{2} {
>  			yylval.byte = strtol(yytext, NULL, 16);
>  			DPRINT("Byte: %02x\n", (int)yylval.byte);
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 7f8c294..9d619cd 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -111,6 +111,7 @@ static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanl
>  %token <labelref> DT_LABEL
>  %token <labelref> DT_LABEL_REF
>  %token <labelref> DT_PATH_REF
> +%token <labelref> DT_ORPHAN_PATH_REF
>  %token DT_INCBIN
>  
>  %type <data> propdata
> @@ -589,6 +590,24 @@ arrayprefix:
>  				ERROR(&@2, "References are only allowed in "
>  					    "arrays with 32-bit elements.");
>  
> +			$$.data = data_append_integer($1.data, val, $1.bits);
> +		}
> +	| arrayprefix DT_ORPHAN_PATH_REF
> +		{
> +			uint64_t val = ~0ULL >> (64 - $1.bits);
> +
> +			if ($1.bits == 32) {
> +				if (!(last_header_flags & DTSF_ADDON))
> +					ERROR(&@2, "Orphan path reference %s supported only in addon", $2);
> +
> +				$1.data = data_add_marker($1.data,
> +							  REF_PHANDLE,
> +							  $2);
> +			} else {
> +				ERROR(&@2, "References are only allowed in "
> +					    "arrays with 32-bit elements.");
> +			}
> +
>  			$$.data = data_append_integer($1.data, val, $1.bits);
>  		}
>  	| arrayprefix DT_LABEL
> diff --git a/dtc.c b/dtc.c
> index 63725bf..72d85e4 100644
> --- a/dtc.c
> +++ b/dtc.c
> @@ -48,13 +48,31 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
>  static void dti_fill_fullpaths(struct dt_info *dti)
>  {
>  	struct node *orphan;
> +	struct node *child;
>  
>  	/* Fill fullpaths for the root node */
>  	if (dti->dt)
>  		fill_fullpaths(dti->dt, "");
>  
> -	for_each_orphan(dti->orphanlist, orphan)
> -		fill_fullpaths(orphan, "__orphan__/");
> +	/* Fill fullpaths for orphan nodes */
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		if (orphan->name[0] == '\0')
> +			die("orphan node has an empty name\n");
> +
> +		/*
> +		 * An orphan node name is set with its reference.
> +		 * Its name is in the form "&xxxxxx".
> +		 * For its full path, we use "$xxxxx" to make a clear
> +		 * distinction between a reference (&xxxx) where a resolution
> +		 * could be involved vs a "simple" path where we just need to
> +		 * identified the orphan ($xxxx).
> +		 */
> +		xasprintf(&orphan->fullpath, "$%s", orphan->name + 1);
> +		orphan->basenamelen = strlen(orphan->name);
> +
> +		for_each_child(orphan, child)
> +			fill_fullpaths(child, orphan->fullpath);
> +	}
>  }
>  
>  /* Usage related data. */
> diff --git a/livetree.c b/livetree.c
> index 59b912d..263da1f 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -804,7 +804,19 @@ static struct node *get_node_by_ref(struct node *tree, const char *ref)
>  			path = slash + 1;
>  		}
>  
> -		target = get_node_by_label(tree, label);
> +		if (label[0] == '$' && tree->name[0] == '&') {
> +			/*
> +			 * We search for an orphan and the given tree is an
> +			 * orphan. Use the given tree only if it matches the
> +			 * expected orphan.
> +			 */
> +			if (streq(label + 1, tree->name + 1))
> +				target = tree;
> +			else
> +				target = NULL;
> +		} else {
> +			target = get_node_by_label(tree, label);
> +		}
>  
>  		free(buf);
>  
> diff --git a/treesource.c b/treesource.c
> index 71dbd5f..44de0db 100644
> --- a/treesource.c
> +++ b/treesource.c
> @@ -278,7 +278,8 @@ static void write_propval(FILE *f, struct property *prop)
>  					break;
>  
>  			if (m_phandle) {
> -				if (m_phandle->ref[0] == '/')
> +				if (m_phandle->ref[0] == '/' /* Root node */ ||
> +				    m_phandle->ref[0] == '$' /* Orphan node */)
>  					fprintf(f, "&{%s}", m_phandle->ref);
>  				else
>  					fprintf(f, "&%s", m_phandle->ref);
> -- 
> 2.52.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
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by Herve Codina 2 weeks, 5 days ago
On Thu, 15 Jan 2026 18:01:39 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Jan 12, 2026 at 03:19:54PM +0100, Herve Codina wrote:
> > Referencing a sub-node from an orphan node using a path is needed.
> > 
> > Indeed, using the following snippet:
> > --- 8< ---
> > /addon/;
> > 
> > &node1 {
> > 	subnode {
> > 		foo-phandle = <&foo_label>;
> > 	};
> > };
> > 
> > &node2 {
> > 	foo_label: foo {
> > 		prop = <1>;
> > 	};
> > };
> > --- 8< ---
> > 
> > Even if node2 is an orphan node, foo is a local node. foo-phandle
> > references the foo node using a label.  
> 
> Another option would be to eliminate the idea of local references, and
> require a symbol be attached to things that you want to reference by
> label.

Hum, new kind of references.

We have reference by phandle to local nodes. Reference by symbol for
external nodes (i.e. nodes not present in current dtb).

Now new kind of reference for node available in the current dtb but
in a different tree (orphan tree).

For that we need to:
  - Mark the phandle value in the property as a cross-tree phandle
    reference
  - Add the symbol label in the referenced node.

When the addon is applied, this new kind of reference need to be taken
into account in a new way:
  - The phandle value in the referenced node need to be updated in the
    same way as all other phandle value in nodes to avoid collisions.
  - The cross-tree reference needs to be resolved.

This adds an unneeded complexity.

IMHO, we shouldn't eliminate local references.

We need to reference all possible local nodes by path even if cross-tree
due to orphan tree is involved.

Best regards,
Hervé
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by David Gibson 2 weeks, 4 days ago
On Mon, Jan 19, 2026 at 05:38:31PM +0100, Herve Codina wrote:
> On Thu, 15 Jan 2026 18:01:39 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Mon, Jan 12, 2026 at 03:19:54PM +0100, Herve Codina wrote:
> > > Referencing a sub-node from an orphan node using a path is needed.
> > > 
> > > Indeed, using the following snippet:
> > > --- 8< ---
> > > /addon/;
> > > 
> > > &node1 {
> > > 	subnode {
> > > 		foo-phandle = <&foo_label>;
> > > 	};
> > > };
> > > 
> > > &node2 {
> > > 	foo_label: foo {
> > > 		prop = <1>;
> > > 	};
> > > };
> > > --- 8< ---
> > > 
> > > Even if node2 is an orphan node, foo is a local node. foo-phandle
> > > references the foo node using a label.  
> > 
> > Another option would be to eliminate the idea of local references, and
> > require a symbol be attached to things that you want to reference by
> > label.
> 
> Hum, new kind of references.

No, I'm trying to remove a type of reference: I'm suggesting using the
same format as for external references on local references as well.
That might mean things referenced need to be both exported and
imported by the tree creating them.  That might be worth it to reduce
the number of cases.

> We have reference by phandle to local nodes. Reference by symbol for
> external nodes (i.e. nodes not present in current dtb).
> 
> Now new kind of reference for node available in the current dtb but
> in a different tree (orphan tree).
> 
> For that we need to:
>   - Mark the phandle value in the property as a cross-tree phandle
>     reference
>   - Add the symbol label in the referenced node.
> 
> When the addon is applied, this new kind of reference need to be taken
> into account in a new way:
>   - The phandle value in the referenced node need to be updated in the
>     same way as all other phandle value in nodes to avoid collisions.
>   - The cross-tree reference needs to be resolved.
> 
> This adds an unneeded complexity.
> 
> IMHO, we shouldn't eliminate local references.
> 
> We need to reference all possible local nodes by path even if cross-tree
> due to orphan tree is involved.
> 
> Best regards,
> Hervé
> 

-- 
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
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by Herve Codina 2 weeks, 3 days ago
Hi David,

On Wed, 21 Jan 2026 20:06:11 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Jan 19, 2026 at 05:38:31PM +0100, Herve Codina wrote:
> > On Thu, 15 Jan 2026 18:01:39 +1100
> > David Gibson <david@gibson.dropbear.id.au> wrote:
> >   
> > > On Mon, Jan 12, 2026 at 03:19:54PM +0100, Herve Codina wrote:  
> > > > Referencing a sub-node from an orphan node using a path is needed.
> > > > 
> > > > Indeed, using the following snippet:
> > > > --- 8< ---
> > > > /addon/;
> > > > 
> > > > &node1 {
> > > > 	subnode {
> > > > 		foo-phandle = <&foo_label>;
> > > > 	};
> > > > };
> > > > 
> > > > &node2 {
> > > > 	foo_label: foo {
> > > > 		prop = <1>;
> > > > 	};
> > > > };
> > > > --- 8< ---
> > > > 
> > > > Even if node2 is an orphan node, foo is a local node. foo-phandle
> > > > references the foo node using a label.    
> > > 
> > > Another option would be to eliminate the idea of local references, and
> > > require a symbol be attached to things that you want to reference by
> > > label.  
> > 
> > Hum, new kind of references.  
> 
> No, I'm trying to remove a type of reference: I'm suggesting using the
> same format as for external references on local references as well.
> That might mean things referenced need to be both exported and
> imported by the tree creating them.  That might be worth it to reduce
> the number of cases.

Hum, this means a new tags.

local references: ok, phandle to to local node.

external references: phandle to external node.
This has to be resolved based on exports available in the device-tree the
addon is applied to.

Here, the node is not external. It is available in the addon and so it is
a local node.

No import/export mechanism is needed to resolve the phandle. Indeed, this
phandle is already well defined (resolved) in the addon blob.

Having a kind of 'local' import/export to allow local cross-tree references
is going to add an extra complexity where it is not needed.

Look at the related test (patch 65).

In the tests/metadata_addon_references.dts, you can find:
--- 8< ---
&base1 {
	b1_addon: addon-node {
		prop = <2>;
	};
};

&base2 {
	addon-node1 {
		ref-base1-addon-node = <&b1_addon>;
	};
	...
};
--- 8< ---

Converted to dtb and analyzed by fdtdump, this leads to
(tests/metadata_addon_references.dtb.expect):
--- 8< ---
&base1 {
    addon-node {
        prop = <0x00000002>;
        phandle = <0x00000001>;
    };
};
&base2 {
    addon-node1 {
        ref-base1-addon-node = <0x00000001>;
        // [FDT_REF_LOCAL] ref-base1-addon-node[0]
    };
    ...
};
--- 8< ---

This dtb, as all dtbs, can be converted back to a dts.

Having a syntax to reference orphan node by path allows to use this
syntax in the 'ref-base1-addon-node' property. You can find it in
tests/metadata_addon_references.dtb.dts.expect
--- 8< ---
&base1 {

	addon-node {
		prop = <0x02>;
		phandle = <0x01>;
	};
};

&base2 {

	addon-node1 {
		ref-base1-addon-node = <&{$base1/addon-node}>;
	};
	...
};
--- 8< ---

We could only use the phandle value:
   ref-base1-addon-node = <0x01>;

Which is perfectly legit and fully matches what is encoded in the dtb.

But I think it was very interesting, thanks to meta-data, to identify that
this is a phandle and so use a reference instead of a integer (phandle).

No label are stored in the dtb and there is no need to store them. Further
more, a node, in a dts can have several label. Which one to store? The
first one, all, ...

Using export, lead to the node visible to any addon applied. That's not the
expectation.

Using import, means the symbol is external. That's not the case.

A local node exists in the dtb. We should be able to reference it by path.

/ {
    foo {
	bar {
	    ...
	};
    }
};

With the root tree, the 'bar' node, can be referenced by /foo/bar.

Now, with orphan:
&orphan {
    foo {
        bar {
	    ....
        };
    };
};

How to reference 'bar' by path?

We need to identify 'orphan' instead of root ('/') $orphan/foo/bar is the
syntax I propose to do that. Of course, this syntax can be discussed.

IMHO, I thing the feature consisting in referencing by path a node in an
orphan tree is needed and avoid extra complexity.

Best regards,
Hervé

> 
> > We have reference by phandle to local nodes. Reference by symbol for
> > external nodes (i.e. nodes not present in current dtb).
> > 
> > Now new kind of reference for node available in the current dtb but
> > in a different tree (orphan tree).
> > 
> > For that we need to:
> >   - Mark the phandle value in the property as a cross-tree phandle
> >     reference
> >   - Add the symbol label in the referenced node.
> > 
> > When the addon is applied, this new kind of reference need to be taken
> > into account in a new way:
> >   - The phandle value in the referenced node need to be updated in the
> >     same way as all other phandle value in nodes to avoid collisions.
> >   - The cross-tree reference needs to be resolved.
> > 
> > This adds an unneeded complexity.
> > 
> > IMHO, we shouldn't eliminate local references.
> > 
> > We need to reference all possible local nodes by path even if cross-tree
> > due to orphan tree is involved.
> > 
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Posted by David Gibson 1 week, 3 days ago
On Wed, Jan 21, 2026 at 05:30:12PM +0100, Herve Codina wrote:
> Hi David,
> 
> On Wed, 21 Jan 2026 20:06:11 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Mon, Jan 19, 2026 at 05:38:31PM +0100, Herve Codina wrote:
> > > On Thu, 15 Jan 2026 18:01:39 +1100
> > > David Gibson <david@gibson.dropbear.id.au> wrote:
> > >   
> > > > On Mon, Jan 12, 2026 at 03:19:54PM +0100, Herve Codina wrote:  
> > > > > Referencing a sub-node from an orphan node using a path is needed.
> > > > > 
> > > > > Indeed, using the following snippet:
> > > > > --- 8< ---
> > > > > /addon/;
> > > > > 
> > > > > &node1 {
> > > > > 	subnode {
> > > > > 		foo-phandle = <&foo_label>;
> > > > > 	};
> > > > > };
> > > > > 
> > > > > &node2 {
> > > > > 	foo_label: foo {
> > > > > 		prop = <1>;
> > > > > 	};
> > > > > };
> > > > > --- 8< ---
> > > > > 
> > > > > Even if node2 is an orphan node, foo is a local node. foo-phandle
> > > > > references the foo node using a label.    
> > > > 
> > > > Another option would be to eliminate the idea of local references, and
> > > > require a symbol be attached to things that you want to reference by
> > > > label.  
> > > 
> > > Hum, new kind of references.  
> > 
> > No, I'm trying to remove a type of reference: I'm suggesting using the
> > same format as for external references on local references as well.
> > That might mean things referenced need to be both exported and
> > imported by the tree creating them.  That might be worth it to reduce
> > the number of cases.
> 
> Hum, this means a new tags.

Either I'm missing something, or I'm not explaining what I have in
mind well.  My itention here is to *reduce* the number of tags.

The proposal has two ways of adjusting a property referring to a
phandle: a) if the referenced node is within this tree fragment
(local), b) if the referenced node is external.

Clearly we need (b), but I'm wondering if there's any way we can
remove (a), using the method for (b) instead.  i.e. do local
references via label, just like external references.

Here's one possible idea: I've said elsewhere that I'm not convinced
the current proposal adequately handles the case of an addon that
requires several upstream connectors.  The obvious way of addressing
that would mean that imported / referenced symbols aren't global to
the whole addon, but instead are specific to a specified upstream
connector.  So, say each phandle fixup tag contained both a namespace
and a label.  The namespace selects which upstream connector we're
referrring to, the label says what symbol within that connector we're
referring to.

If we went with a scheme like that, we could reserve a special
namespace id to mean "this addon itself".  So, we can use the same
sort of fixup tag for both local and external references, at the cost
of having to explicitly "export" symbols/labels for the locally
referenced nodes.  So, something like

Base tree:
	...
	foo0: foobus@12345 {
		/export/ bridge = &foo0;
	   	/export/ intc = &/path/to/board/intc;
		compatible = "foobus";
		...
	};
	bar0: barbus@abcde {
		/export/ gpio = &/path/to/gpio/mux;
		compatible = "barbus";
		...
	};

Addon:
	/* Declare our upstream connectors */
	/requires/ foo "foobus";
	/requires/ bar "barbus";
	
	&foo.bridge {
		local_intc: local-intc@XXX {
			interrupt-parent = <&foo.intc>;
			...
		};
		widget@YYY {
			compatible = "widget31415", "widget3000";
			interrupt-parent = <&LOCAL.local_intc>;
			interrupts = <...>;
			gpio = <&bar.gpio>;
		}
	}

By the time we compile to dtb, those namespace IDs could likely be
ints, rather than strings.

> local references: ok, phandle to to local node.
> 
> external references: phandle to external node.
> This has to be resolved based on exports available in the device-tree the
> addon is applied to.
> 
> Here, the node is not external. It is available in the addon and so it is
> a local node.
> 
> No import/export mechanism is needed to resolve the phandle. Indeed, this
> phandle is already well defined (resolved) in the addon blob.

> Having a kind of 'local' import/export to allow local cross-tree references
> is going to add an extra complexity where it is not needed.

Does it, though?  We already need the import/export mechanism, so what
prevents us from using it locally?

-- 
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