Add support for dtb metadata and addon device-trees
Subsystems (2)
RFC PATCH 59/77 tests: metadata: Add a test for addon without root node
In reply to Herve CodinaThe root device-tree node is no more mandatory for addons.
Indeed, addons can be composed of only orphan nodes without any needs for the root device-tree node presence.
Add a test related to addon dts and dtb without root node.
--- tests/metadata_addon_orphan2.dtb.dts.expect | 10 ++++++++++ tests/metadata_addon_orphan2.dtb.expect | 8 ++++++++ tests/metadata_addon_orphan2.dts | 13 +++++++++++++ tests/metadata_addon_orphan2.dts.dts.expect | 10 ++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan2.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan2.dtb.expect create mode 100644 tests/metadata_addon_orphan2.dts create mode 100644 tests/metadata_addon_orphan2.dts.dts.expect
tests/metadata_addon_orphan2.dtb.dts.expect new file +10 -0
@@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + + +&base { + + addon-node { + prop = <0x02>; + }; +};
tests/metadata_addon_orphan2.dtb.expect new file +8 -0
@@ -0,0 +1,8 @@ +/dts-v1/; +/addon/; + +&base { + addon-node { + prop = <0x00000002>; + }; +};
tests/metadata_addon_orphan2.dts new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +&base { + addon-node { + prop = <2>; + }; +};
tests/metadata_addon_orphan2.dts.dts.expect new file +10 -0
@@ -0,0 +1,10 @@ +/dts-v1/; +/addon/; + + +&base { + + addon-node { + prop = <0x02>; + }; +};
tests/run_tests.sh +1 -1
@@ -1128,7 +1128,7 @@ metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ - metadata_addon_orphan1; do + metadata_addon_orphan1 metadata_addon_orphan2; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
RFC PATCH 60/77 dtc: Allow parser_get_node_by_ref() to return an orphan node for merging purpose
In reply to Herve CodinaWhen the same orphan node is described multiple times in an addon dts, those multiple descriptions should be merged.
For instance, in the following snippet:
--- 8< ---
/addon/;
&foo {
prop1 = <1>;
};
&foo {
prop2 = <2>;
};
--- 8< ---The foo orphan node is described twice and should be merged in only one instance:
--- 8< ---
&foo {
prop1 = <1>;
prop2 = <2>;
};
--- 8< ---The current mecanisme used to find a node for merging is based on label. Indeed, without orphan nodes, '&foo' is a reference to a node with the label 'foo'. This node labeled foo is the node found for merging.
With addons and orphan nodes, '&foo' is not a reference to an existing node. Indeed, this node is an orphan one because the node referenced by foo is an external node (i.e. not available in the addon itself).
The label 'foo' doesn't exist. No node in the addon are defined with a foo label attached.
Take this orphan nodes specificity into account in order to find a possible orphan node candidate for merging.
--- dtc-parser.y | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
dtc-parser.y +22 -1
@@ -39,11 +39,32 @@ static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanl * Use a temporary dt_info in order to use dti_get_node_by_ref() */ struct dt_info dti = {}; + struct node *target; + struct node *orphan; dti.dt = dt; dti.orphanlist = orphanlist; - return dti_get_node_by_ref(&dti, ref); + target = dti_get_node_by_ref(&dti, ref); + if (target) + return target; + + /* + * No node were found by dti_get_node_by_ref(). + * + * parser_get_node_by_ref() is called by the parser only to get a node + * in order to perform a possible merge. + * + * The referenced used can be a label matching an orphan node. In this + * merge context, returning a matching orphan node makes sense even if + * no label are defined for the orphan node. + */ + for_each_orphan(orphanlist, orphan) { + if (streq(orphan->ref, ref)) + return orphan; + } + + return NULL; } %}
Signature · 1 line
2.52.0
RFC PATCH 61/77 tests: metadata: Add a test related to orphan node merging
In reply to Herve CodinaMerging orphan node is supported.
Add a test for this feature.
--- tests/metadata_addon_orphan3.dtb.dts.expect | 22 ++++++++++++++++ tests/metadata_addon_orphan3.dtb.expect | 17 +++++++++++++ tests/metadata_addon_orphan3.dts | 28 +++++++++++++++++++++ tests/metadata_addon_orphan3.dts.dts.expect | 22 ++++++++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan3.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan3.dtb.expect create mode 100644 tests/metadata_addon_orphan3.dts create mode 100644 tests/metadata_addon_orphan3.dts.dts.expect
tests/metadata_addon_orphan3.dtb.dts.expect new file +22 -0
@@ -0,0 +1,22 @@ +/dts-v1/; +/addon/; + + +&base1 { + + addon-node1 { + prop1 = <0x01>; + prop2 = <0x02>; + }; + + addon-node2 { + prop3 = <0x03>; + }; +}; + +&base2 { + + addon-node { + prop = <0x00>; + }; +};
tests/metadata_addon_orphan3.dtb.expect new file +17 -0
@@ -0,0 +1,17 @@ +/dts-v1/; +/addon/; + +&base1 { + addon-node1 { + prop1 = <0x00000001>; + prop2 = <0x00000002>; + }; + addon-node2 { + prop3 = <0x00000003>; + }; +}; +&base2 { + addon-node { + prop = <0x00000000>; + }; +};
tests/metadata_addon_orphan3.dts new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +&base1 { + addon-node1 { + prop1 = <1>; + }; +}; + +&base2 { + addon-node { + prop = <0>; + }; +}; + +&base1 { + addon-node1 { + prop2 = <2>; + }; + addon-node2 { + prop3 = <3>; + }; +};
tests/metadata_addon_orphan3.dts.dts.expect new file +22 -0
@@ -0,0 +1,22 @@ +/dts-v1/; +/addon/; + + +&base1 { + + addon-node1 { + prop1 = <0x01>; + prop2 = <0x02>; + }; + + addon-node2 { + prop3 = <0x03>; + }; +}; + +&base2 { + + addon-node { + prop = <0x00>; + }; +};
tests/run_tests.sh +2 -1
@@ -1128,7 +1128,8 @@ metadata_tests() { for dt in metadata_reflocal metadata_refphandle \ metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ - metadata_addon_orphan1 metadata_addon_orphan2; do + metadata_addon_orphan1 metadata_addon_orphan2 \ + metadata_addon_orphan3; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
RFC PATCH 62/77 dtc: Add support for orphan nodes sorting
In reply to Herve Codinadtc can sort items when the command line --sort option is set.
Add support for orphan nodes sorting when this option is used.
--- livetree.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
livetree.c +30 -0
@@ -1199,6 +1199,34 @@ static void sort_importsyms(struct dt_info *dti)free (tbl); } +static void sort_orphans (struct dt_info *dti) +{ +int n =0 , i =0 ; +struct node *orphan, **tbl; + +for_each_orphan (dti->orphanlist, orphan) { +sort_node (orphan); + n++; + } + +if (n ==0 ) +return ; + + tbl =xmalloc (n *sizeof (*tbl)); + +for_each_orphan (dti->orphanlist, orphan) + tbl[i++] = orphan; + +qsort (tbl, n,sizeof (*tbl), cmp_subnode); + + dti->orphanlist = tbl[0 ]; +for (i =0 ; i < (n-1 ); i++) + tbl[i]->next_sibling = tbl[i+1 ]; + tbl[n-1 ]->next_sibling =NULL ; + +free (tbl); +} +void sort_tree (struct dt_info *dti) {sort_reserve_entries (dti);
@@ -1206,6 +1234,8 @@ void sort_tree(struct dt_info *dti)if (dti->dt)sort_node (dti->dt); + +sort_orphans (dti); }/* utility helper to avoid code duplication */
Signature · 1 line
2.52.0
RFC PATCH 63/77 tests: metadata: Improve sort test to check for orphan nodes sorting
In reply to Herve Codinadtc is able to sort orphan nodes when the --sort option is used.
Improve the metadata sort test to perform a check for this feature.
--- tests/metadata_sort.dtb.dts.expect | 39 ++++++++++++++++++++++++++++++ tests/metadata_sort.dtb.expect | 30 +++++++++++++++++++++++ tests/metadata_sort.dts | 33 +++++++++++++++++++++++++ 3 files changed, 102 insertions(+)
tests/metadata_sort.dtb.dts.expect +39 -0
@@ -20,3 +20,42 @@ phandle = <0x01>; }; }; + +&abc { + prop-a = "a"; + prop-b = "b"; + + node-a { + prop = <0x01>; + }; + + node-b { + prop = <0x02>; + }; + + node-c { + prop = <0x03>; + }; +}; + +&de1 { + prop-a = "a"; + prop-b = "b"; + + node-a { + prop = <0x01>; + }; + + node-b { + prop = <0x02>; + }; + + node-c { + prop = <0x03>; + }; +}; + +&de2 { + prop-a = "a"; + prop-b = "b"; +};
tests/metadata_sort.dtb.expect +30 -0
@@ -16,3 +16,33 @@ // [FDT_IMPORT_SYM] 'abc' (foo,bar) // [FDT_IMPORT_SYM] 'de1' (foo,bar) // [FDT_IMPORT_SYM] 'de2' (foo,bar) +&abc { + prop-a = "a"; + prop-b = "b"; + node-a { + prop = <0x00000001>; + }; + node-b { + prop = <0x00000002>; + }; + node-c { + prop = <0x00000003>; + }; +}; +&de1 { + prop-a = "a"; + prop-b = "b"; + node-a { + prop = <0x00000001>; + }; + node-b { + prop = <0x00000002>; + }; + node-c { + prop = <0x00000003>; + }; +}; +&de2 { + prop-a = "a"; + prop-b = "b"; +};
tests/metadata_sort.dts +33 -0
@@ -23,3 +23,36 @@ /export/ a: &node_b; }; }; + +&de2 { + prop-b = "b"; + prop-a = "a"; +}; + +&abc { + prop-b = "b"; + prop-a = "a"; + node-b { + prop = <2>; + }; + node-a { + prop = <1>; + }; + node-c { + prop = <3>; + }; +}; + +&de1 { + prop-b = "b"; + prop-a = "a"; + node-b { + prop = <2>; + }; + node-a { + prop = <1>; + }; + node-c { + prop = <3>; + }; +};
Signature · 1 line
2.52.0
RFC PATCH 64/77 dtc: Add support for references by path involving orphan nodes
In reply to Herve CodinaReferencing 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.
--- dtc-lexer.l | 7 +++++++ dtc-parser.y | 19 +++++++++++++++++++ dtc.c | 22 ++++++++++++++++++++-- livetree.c | 14 +++++++++++++- treesource.c | 3 ++- 5 files changed, 61 insertions(+), 4 deletions(-)
dtc-lexer.l +7 -0
@@ -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);
dtc-parser.y +19 -0
@@ -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
dtc.c +20 -2
@@ -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. */
livetree.c +13 -1
@@ -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);
treesource.c +2 -1
@@ -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);
Signature · 1 line
2.52.0
Re: [RFC PATCH 64/77] dtc: Add support for references by path involving orphan nodes
Quoted 17 lines · Herve Codina
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>; }; };
Quoted 4 lines
--- 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.
Quoted 175 lines
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 <[email protected]>--- dtc-lexer.l | 7 +++++++ dtc-parser.y | 19 +++++++++++++++++++ dtc.c | 22 ++++++++++++++++++++-- livetree.c | 14 +++++++++++++- treesource.c | 3 ++- 5 files changed, 61 insertions(+), 4 deletions(-)dtc-lexer.l +7
-0@@ -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);dtc-parser.y +19
-0@@ -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_LABELdtc.c +20
-2@@ -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. */ livetree.c +13
-1@@ -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);treesource.c +2
-1@@ -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);Signature · 1 line
2.52.0
Signature · 4 lines
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
Quoted 20 lines · On Thu, 15 Jan 2026 18:01:39 +1100 David Gibson <[email protected]>…
Quoted 19 lines · Herve Codina
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< ---
Quoted 6 lines
Quoted 2 lines
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
Quoted 23 lines · Herve Codina
Quoted 20 lines · On Thu, 15 Jan 2026 18:01:39 +1100 David Gibson <[email protected]>…
Quoted 19 lines · Herve Codina
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< ---
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
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.
Quoted 27 lines
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é
Signature · 4 lines
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
Hi David,
Quoted 31 lines · On Wed, 21 Jan 2026 20:06:11 +1100 David Gibson <[email protected]>…
Quoted 30 lines · Herve Codina
Quoted 26 lines · On Thu, 15 Jan 2026 18:01:39 +1100 David Gibson <[email protected]>…
Quoted 17 lines · Herve Codina
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>; }; };Quoted 4 lines
--- 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.
Quoted 7 lines
Quoted 1 line
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é
Quoted 25 lines
Quoted 25 lines
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
Quoted 38 lines · Herve Codina
Hi David,
Quoted 33 lines · On Wed, 21 Jan 2026 20:06:11 +1100 David Gibson <[email protected]>…
Quoted 31 lines · Herve Codina
Quoted 20 lines · On Thu, 15 Jan 2026 18:01:39 +1100 David Gibson <[email protected]>…
Quoted 19 lines · Herve Codina
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< ---
Quoted 6 lines
Quoted 2 lines
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.
Quoted 7 lines
Quoted 5 lines
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.
Quoted 6 lines
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.
Quoted 8 lines
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?
Signature · 4 lines
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
RFC PATCH 65/77 tests: metadata: Add a test for references by path involving orphan nodes
In reply to Herve CodinaThe syntax '&{$<orphan_name>/<path>}' allows to reference by path a node that belongs to an orphan node.
Add a test related to this kind of references.
--- .../metadata_addon_references.dtb.dts.expect | 48 +++++++++++++++++++ tests/metadata_addon_references.dtb.expect | 48 +++++++++++++++++++ tests/metadata_addon_references.dts | 43 +++++++++++++++++ .../metadata_addon_references.dts.dts.expect | 48 +++++++++++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_references.dtb.dts.expect create mode 100644 tests/metadata_addon_references.dtb.expect create mode 100644 tests/metadata_addon_references.dts create mode 100644 tests/metadata_addon_references.dts.dts.expect
tests/metadata_addon_references.dtb.dts.expect new file +48 -0
@@ -0,0 +1,48 @@ +/dts-v1/; +/addon/; + +/ { + + sub-node { + ref1-base1 = <&base1>; + ref2-base1-addon-node = <&{$base1/addon-node}>; + ref3-base1-addon-node = <&{$base1/addon-node}>; + ref4-base1-addon-node = <&{$base1/addon-node}>; + ref5-base3 = <&{$base3}>; + ref6-base3 = <&{$base3}>; + ref7-base3-subsubnode = <&{$base3/sub-node/sub-subnode}>; + phandle = <0x04>; + }; +}; + +&base1 { + + addon-node { + prop = <0x02>; + phandle = <0x01>; + }; +}; + +&base2 { + + addon-node1 { + ref-base1-addon-node = <&{$base1/addon-node}>; + }; + + addon-node2 { + ref-root-sub-node = <&{/sub-node}>; + }; +}; + +&base3 { + phandle = <0x02>; + + sub-node { + prop = <0x03>; + + sub-subnode { + prop = <0x04>; + phandle = <0x03>; + }; + }; +};
tests/metadata_addon_references.dtb.expect new file +48 -0
48 lines not on this page · raw message
tests/metadata_addon_references.dts new file +43 -0
43 lines not on this page · raw message
tests/metadata_addon_references.dts.dts.expect new file +48 -0
48 lines not on this page · raw message
tests/run_tests.sh +1 -1
@@ -1129,7 +1129,7 @@ metadata_tests() { metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ metadata_addon_orphan1 metadata_addon_orphan2 \ - metadata_addon_orphan3; do + metadata_addon_orphan3 metadata_addon_references; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
RFC PATCH 66/77 dtc: Add support for namespace labels references
In reply to Herve CodinaNamespace labels references can only be present in addons and involves import/exported symbols.
They allow to 'jump' from node to node based on exported symbols defined at each node.
When a label reference contains a dot ('.') char, it becomes a namespace labels reference.
For instance &foo.bar.baz is a namespace label reference. The resolution of this reference is performed in a recursive way.
- Get the node referenced by foo.
- From this node get the node referenced by bar in exported symbols from foo.
- From this node get the node referenced by baz in exported symbols from bar.
- ...
The first item (foo) involves import symbols defined in the addon and export symbols defined in the node the addon is applied to.
Other items involves only exported symbols in referenced nodes to perform the resolution chain.
We leave the addon thanks to the first item and import symbols. Other items allow to perform jumps from node to node in the base device-tree without leaving it.
The full resolution can be summarized with the following diagram:
(addon DT)
&foo.bar.baz
| | |
| | +--------------------------------------------+
| | |
| +-------------------------------+ |
| | |
| (addon DT) | |
+-> /import/ foo: --+ | |
| | |
| | |
addon applied at | | |
target node in the | | |
base DT | | |
| | | |
| (base DT) | | |
+---> target { v | |
/export/ foo: &n1; | |
| | |
| | |
v (base DT) | |
n1 { v |
/export/ bar: &n2; |
| |
v (base DT) |
n2 { v
/export/ baz: &n3;
|
|
v
n3 { ... };'&foo.bar.baz' references, in the end, the n3 node from the base DT.
Implement support for namespace references parsing in dtc.
The resolution part is out of dtc. Indeed, dtc has no support for applying an addon.
--- dtc-lexer.l | 13 +++++++++++++ dtc-parser.y | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 3 deletions(-)
dtc-lexer.l +13 -0
@@ -232,6 +232,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_LABEL_REF; } +<*>\&{LABEL}(\.{LABEL})+ { /* namespace label reference */ + DPRINT("Ref namespace: %s\n", yytext+1); + yylval.labelref = xstrdup(yytext+1); + return DT_LABEL_NAMESPACE_REF; + } + <*>"&{"{PATHCHAR}*\} { /* new-style path reference */ yytext[yyleng-1] = '\0'; DPRINT("Ref: %s\n", yytext+2);
@@ -246,6 +252,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_ORPHAN_PATH_REF; } +<*>"&{\$"{LABEL}(\.{LABEL})+([/]{PATHCHAR}*)?\} { /* orphan path reference */ + yytext[yyleng-1] = '\0'; + DPRINT("Ref (namespace) 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);
dtc-parser.y +46 -3
108 lines not on this page · raw message
Signature · 1 line
2.52.0
RFC PATCH 67/77 tests: metadata: Add a test for namespace labels references
In reply to Herve CodinaNamespace labels references are references in the form '&foo.bar.baz'.
Support for namespace labels references has been recently added to dtc.
Add a test related to this kind of references.
--- ...metadata_addon_refnamespace.dtb.dts.expect | 32 ++++++++++++++++ tests/metadata_addon_refnamespace.dtb.expect | 29 ++++++++++++++ tests/metadata_addon_refnamespace.dts | 38 +++++++++++++++++++ ...metadata_addon_refnamespace.dts.dts.expect | 32 ++++++++++++++++ tests/run_tests.sh | 3 +- 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_refnamespace.dtb.dts.expect create mode 100644 tests/metadata_addon_refnamespace.dtb.expect create mode 100644 tests/metadata_addon_refnamespace.dts create mode 100644 tests/metadata_addon_refnamespace.dts.dts.expect
tests/metadata_addon_refnamespace.dtb.dts.expect new file +32 -0
@@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + + addon-node { + ref0 = <&foo.x.y>; + ref1 = <0x0a &bar.other 0x14>; + ref2 = <&{$foo.x.y.z/addon-node}>; + ref3 = <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + + addon-node { + prop = <0x00>; + phandle = <0x01>; + }; +}; + +&foo.x.y { + + node { + prop1 = <0x01>; + prop2 = <0x02>; + }; +};
tests/metadata_addon_refnamespace.dtb.expect new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'foo' (abc,foo) +// [FDT_IMPORT_SYM] 'bar' (abc,bar) +&foo.x { + addon-node { + ref0 = <0xffffffff>; + // [FDT_REF_PHANDLE] ref0[0], ref = foo.x.y + ref1 = <0x0000000a 0xffffffff 0x00000014>; + // [FDT_REF_PHANDLE] ref1[4], ref = bar.other + ref2 = <0x00000001>; + // [FDT_REF_LOCAL] ref2[0] + ref3 = <0x00000001>; + // [FDT_REF_LOCAL] ref3[0] + }; +}; +&foo.x.y.z { + addon-node { + prop = <0x00000000>; + phandle = <0x00000001>; + }; +}; +&foo.x.y { + node { + prop1 = <0x00000001>; + prop2 = <0x00000002>; + }; +};
tests/metadata_addon_refnamespace.dts new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + addon-node { + ref0 = <&foo.x.y>; + ref1 = <10 &bar.other 20>; + ref2 = <&addon_node>; + ref3 = <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + addon_node: addon-node { + prop = <0>; + }; +}; + +&foo.x.y { + node { + prop1 = <1>; + }; +}; + +&foo.x.y { + node { + prop2 = <2>; + }; +};
tests/metadata_addon_refnamespace.dts.dts.expect new file +32 -0
@@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +/import/ foo: "abc,foo"; +/import/ bar: "abc,bar"; + + +&foo.x { + + addon-node { + ref0 = <&foo.x.y>; + ref1 = <0x0a &bar.other 0x14>; + ref2 = <&addon_node>; + ref3 = <&{$foo.x.y.z/addon-node}>; + }; +}; + +&foo.x.y.z { + + addon_node: addon-node { + prop = <0x00>; + phandle = <0x01>; + }; +}; + +&foo.x.y { + + node { + prop1 = <0x01>; + prop2 = <0x02>; + }; +};
tests/run_tests.sh +2 -1
@@ -1129,7 +1129,8 @@ metadata_tests() { metadata_addon_base metadata_exportsyms_local \ metadata_exportsyms_ref metadata_importsyms \ metadata_addon_orphan1 metadata_addon_orphan2 \ - metadata_addon_orphan3 metadata_addon_references; do + metadata_addon_orphan3 metadata_addon_references \ + metadata_addon_refnamespace; do run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts" base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect" run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
RFC PATCH 68/77 libfdt: Introduce fdt_getprop_by_offset_w()
In reply to Herve CodinaThe future support for applying a addon on a base device-tree needs to modify properties retrieved by their offset.
fdt_getprop_by_offset() already exists to get a preperty by its offset but the property returned is read-only. A writable returned property is needed.
Fill the lack and introduce fdt_getprop_by_offset_w(), the write enabled variant of fdt_getprop_by_offset().
--- libfdt/libfdt.h | 6 ++++++ 1 file changed, 6 insertions(+)
libfdt/libfdt.h +6 -0
@@ -858,6 +858,12 @@ static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,#ifndef SWIG /* This function is not useful in Python */ const void *fdt_getprop_by_offset (const void *fdt,int offset,const char **namep,int *lenp); +static inline void *fdt_getprop_by_offset_w (const void *fdt,int offset, +const char **namep,int *lenp) +{ +return (void *)(uintptr_t )fdt_getprop_by_offset (fdt, offset, namep, + lenp); +}#endif /**
Signature · 1 line
2.52.0
Re: [RFC PATCH 68/77] libfdt: Introduce fdt_getprop_by_offset_w()
Quoted 11 lines · Herve Codina
The future support for applying a addon on a base device-tree needs to modify properties retrieved by their offset.
fdt_getprop_by_offset()already exists to get a preperty by its offset but the property returned is read-only. A writable returned property is needed.Fill the lack and introduce
fdt_getprop_by_offset_w(), the write enabled variant offdt_getprop_by_offset().Signed-off-by Herve Codina <[email protected]>
Add a testcase, and this could be merged regardless of the rest of the series.
Quoted 25 lines
--- libfdt/libfdt.h | 6 ++++++ 1 file changed, 6 insertions(+)libfdt/libfdt.h +6
-0@@ -858,6 +858,12 @@ static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,#ifndef SWIG /* This function is not useful in Python */ const void *fdt_getprop_by_offset (const void *fdt,int offset,const char **namep,int *lenp); +static inline void *fdt_getprop_by_offset_w (const void *fdt,int offset, +const char **namep,int *lenp) +{ +return (void *)(uintptr_t )fdt_getprop_by_offset (fdt, offset, namep, + lenp); +}#endif /** Signature · 1 line
2.52.0
Signature · 4 lines
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
RFC PATCH 69/77 libfdt: Introduce fdt_getprop_offset()
In reply to Herve CodinaThe future support for applying a addon on a base device-tree needs to get an offset to a property based on the node offset and the property name.
Several function exists to get a property but none of them allows to get the property offset.
Fill the lack and introduce fdt_getprop_offset()
--- libfdt/fdt_ro.c | 12 ++++++++++++ libfdt/libfdt_internal.h | 2 ++ 2 files changed, 14 insertions(+)
libfdt/fdt_ro.c +12 -0
@@ -508,6 +508,18 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,return fdt_getprop_namelen (fdt, nodeoffset, name,strlen (name), lenp); } +int fdt_getprop_offset (const void *fdt,int nodeoffset,const char *name) +{ +const struct fdt_property *prop; +int lenp, offset; + + prop =fdt_get_property_namelen_ (fdt, nodeoffset, name,strlen (name), + &lenp, &offset); +if (!prop) +return lenp; +return offset; +} +uint32_t fdt_get_phandle (const void *fdt,int nodeoffset) {const fdt32_t *php;
libfdt/libfdt_internal.h +2 -0
@@ -24,6 +24,8 @@ int32_t fdt_ro_probe_(const void *fdt);int fdt_check_node_offset_ (const void *fdt,int offset);int fdt_check_prop_offset_ (const void *fdt,int offset); +int fdt_getprop_offset (const void *fdt,int nodeoffset,const char *name); +const char *fdt_find_string_len_ (const char *strtab,int tabsize,const char *s,int s_len); static inline const char *fdt_find_string_(const char *strtab, int tabsize,
Signature · 1 line
2.52.0
RFC PATCH 70/77 libfdt: Add support for applying an addon on a base device-tree blob
In reply to Herve CodinaAddon dtbs have been recently supported. The missing part is having some support for addon usage.
The goal of addons is to extend a base device-tree. This feature is similar to the overlay feature but addons and recent modifications offer metadata and import/export symbol mechanism.
This import/export symbol mechanism allow a fine tuning of symbols exported (i.e. symbol seen from the addon).
To extend the base device-tree, an addon needs to be applied to this base device-tree at a specific node. The specific node, target node of the addon, is not encoded in the addon dtb.
Indeed, addons do not depends on the exact base device tree structure. An addon can be applied on top of any base device tree as soon as the target node matches expectations of the addon. Exported symbols at this target node has to match imported symbols defined in the addon.
When the addon is applied three macro operations have to be done:
- Avoid phandle conflict avoidance
The conflict avoidance consists in fixing local phandle to avoid conflict with already existing phandle available in the base device-tree. This operation involved metadata recently added in dtb format.
- Resolve unresolved symbols
The symbol resolution consists in replacing unresolved symbol references present in the addon dtb by a reference to an existing node in the base device tree. This operation involved metadata and import/export symbols.
- Merge addon nodes into base device-tree
This merging consists in adding additional nodes described in the addon into the base device-tree.
fdt_addon_apply() allows to apply an addon on a base device-tree and performs internally all the needed operations.
--- libfdt/Makefile.libfdt | 2 +- libfdt/fdt_addon.c | 1636 ++++++++++++++++++++++++++++++++++++++ libfdt/fdt_rw.c | 85 ++ libfdt/libfdt.h | 32 + libfdt/libfdt_internal.h | 4 + libfdt/meson.build | 1 + libfdt/version.lds | 1 + 7 files changed, 1760 insertions(+), 1 deletion(-) create mode 100644 libfdt/fdt_addon.c
libfdt/Makefile.libfdt +1 -1
@@ -10,7 +10,7 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h LIBFDT_VERSION = version.lds LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ - fdt_addresses.c fdt_overlay.c fdt_check.c + fdt_addresses.c fdt_overlay.c fdt_addon.c fdt_check.c LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) LIBFDT_LIB = libfdt.$(SHAREDLIB_EXT).$(DTC_VERSION)
libfdt/fdt_addon.c new file +1636 -0
1,636 lines not on this page · raw message
libfdt/fdt_rw.c +85 -0
91 lines not on this page · raw message
libfdt/libfdt.h +32 -0
@@ -2543,6 +2543,38 @@ int fdt_overlay_apply(void *fdt, void *fdto);int fdt_overlay_target_offset (const void *fdt,const void *fdto,int fragment_offset,char const **pathp); +/** +* fdt_addon_apply - Applies a DT addon on a base DT +* @fdt: pointer to the base device tree blob +* @fdta: pointer to the device tree addon blob +* @target: target node path +* +* fdt_addon_apply() will apply the given device tree addon on the given target +* node in base device tree. +* +* Expect the base device tree to be modified, even if the function +* returns an error. +* +* returns: +* 0, on success +* -FDT_ERR_NOSPACE, there's not enough space in the base device tree +* -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or +* properties in the base DT +* -FDT_ERR_BADPHANDLE, +* -FDT_ERR_BADOVERLAY, +* -FDT_ERR_NOPHANDLES, +* -FDT_ERR_INTERNAL, +* -FDT_ERR_BADLAYOUT, +* -FDT_ERR_BADMAGIC, +* -FDT_ERR_BADOFFSET, +* -FDT_ERR_BADPATH, +* -FDT_ERR_BADVERSION, +* -FDT_ERR_BADSTRUCTURE, +* -FDT_ERR_BADSTATE, +* -FDT_ERR_TRUNCATED, standard meanings +*/ +int fdt_addon_apply (void *fdt,void *fdta,const char *target); +/**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/
libfdt/libfdt_internal.h +4 -0
@@ -25,6 +25,10 @@ int fdt_check_node_offset_(const void *fdt, int offset);int fdt_check_prop_offset_ (const void *fdt,int offset);int fdt_getprop_offset (const void *fdt,int nodeoffset,const char *name); +int fdt_mark_property_ref_local_ (void *fdt,int fdt_property, +uint32_t propoffset); +int fdt_add_exportsym_ (void *fdt,int nodeoffset,const char *name, +uint32_t phandle);const char *fdt_find_string_len_ (const char *strtab,int tabsize,const char *s,int s_len);
libfdt/meson.build +1 -0
@@ -9,6 +9,7 @@ sources = files( 'fdt_check.c', 'fdt_empty_tree.c', 'fdt_overlay.c', + 'fdt_addon.c', 'fdt_ro.c', 'fdt_rw.c', 'fdt_strerror.c',
libfdt/version.lds +1 -0
@@ -83,6 +83,7 @@ LIBFDT_1.2 { fdt_overlay_target_offset; fdt_get_symbol; fdt_get_symbol_namelen; + fdt_addon_apply; local: *; };
Signature · 1 line
2.52.0
RFC PATCH 71/77 Add fdtaddon tool to apply an addon
In reply to Herve Codinalibfdt has support for applying an addon on top of a base device-tree. This is provided by the libfdt fdt_addon_apply() function.
The fdtaddon tool is command line tool which allows to apply addon dtb file to a base device-tree dtb file. It relies on fdt_addon_apply().
--- Makefile | 5 ++ fdtaddon.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 2 +- 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 fdtaddon.c
Makefile +5 -0
@@ -159,6 +159,7 @@ BIN += fdtdump BIN += fdtget BIN += fdtput BIN += fdtoverlay +BIN += fdtaddon SCRIPTS = dtdiff
@@ -172,6 +173,7 @@ ifneq ($(MAKECMDGOALS),libfdt) -include $(FDTGET_OBJS:%.o=%.d) -include $(FDTPUT_OBJS:%.o=%.d) -include $(FDTOVERLAY_OBJS:%.o=%.d) +-include $(FDTADDON_OBJS:%.o=%.d) endif endif
@@ -255,6 +257,8 @@ fdtput: $(FDTPUT_OBJS) $(LIBFDT_dep) fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_dep) +fdtaddon: $(FDTADDON_OBJS) $(LIBFDT_dep) + dist: git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \ > ../dtc-$(dtc_version).tar
@@ -295,6 +299,7 @@ TESTS_BIN += fdtput TESTS_BIN += fdtget TESTS_BIN += fdtdump TESTS_BIN += fdtoverlay +TESTS_BIN += fdtaddon ifneq ($(MAKECMDGOALS),libfdt) include tests/Makefile.tests
fdtaddon.c new file +197 -0
197 lines not on this page · raw message
meson.build +1 -1
@@ -107,7 +107,7 @@ if get_option('tools') and not wheel_only install: true, ) - foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay'] + foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay', 'fdtaddon'] dtc_tools += executable(e, files(e + '.c'), dependencies: util_dep, install: true) endforeach
Signature · 1 line
2.52.0
RFC PATCH 72/77 tests: Add a first basic test for fdtaddon
In reply to Herve CodinaThe fdtaddon tests family goal is to test features related the application of an addon to a base device tree.
This first basic test added in fdtaddon tests is related to the application of a simple addon.
The terminology used in the test is the following:
- dts: A 'full' device tree source.
This can be either a base device tree or a merged device tree (i.e. a base device tree where an addon has been applied to).
- dtb: A 'full' device tree blob
This can be either a dtb generated by dtc from a dts or the output of the fdtaddon command.
- dtsa: An addon device tree source
A dts with the '/addon/' keyword.
- dtba: An addon device tree blob
This a device tree blob generated from a dtsa.
With this terminology in mind, the test pattern is the following:
- Generate the base tree dtb (fdtaddon_base.dtb)
- Check this generated dtb against expected contents
- Generate a dtba (xxx.dtba) from an input dtsa
- Check this generated dtba against expected contents
- Apply the dtba to the base tree dtb at node-a1 (xxx-merged1.dtb)
- Check this generated dtb against expected contents
- Generate a dts (xxx-merged1.dtb.dts) from the generated xxx-merged1.dtb
- Check this generated dts against expected contents
- Apply the dtba to the base tree dtb at node-a2 (xxx-merged2.dtb)
- Check this generated dtb against expected contents
- Generate a dts (xxx-merged2.dtb.dts) from the generated xxx-merged2.dtb
- Check this generated dts against expected contents
Even if only one basic addon dsta is currently provided in this tests introduction, use a loop in order to ease future addition consisting in testing other features based on more complex addon dtsa.
--- tests/fdtaddon_base.dtb.expect | 24 ++++++++++ tests/fdtaddon_base.dts | 27 +++++++++++ tests/fdtaddon_basics1-merged1.dtb.dts.expect | 35 ++++++++++++++ tests/fdtaddon_basics1-merged1.dtb.expect | 27 +++++++++++ tests/fdtaddon_basics1-merged2.dtb.dts.expect | 35 ++++++++++++++ tests/fdtaddon_basics1-merged2.dtb.expect | 27 +++++++++++ tests/fdtaddon_basics1.dtba.expect | 8 ++++ tests/fdtaddon_basics1.dtsa | 13 ++++++ tests/meson.build | 3 +- tests/run_tests.sh | 46 ++++++++++++++++++- tests/testutils.sh | 1 + 11 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 tests/fdtaddon_base.dtb.expect create mode 100644 tests/fdtaddon_base.dts create mode 100644 tests/fdtaddon_basics1-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics1-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics1-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics1-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics1.dtba.expect create mode 100644 tests/fdtaddon_basics1.dtsa
tests/fdtaddon_base.dtb.expect new file +24 -0
@@ -0,0 +1,24 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +};
tests/fdtaddon_base.dts new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + base-node { + other_a: sub-node { + prop = <0>; + }; + }; + + somewhere { + node_a1: node-a1 { + compatible = "abc,aaa"; + /export/ node_a: &node_a1; + /export/ other: &other_a; + }; + node_a2: node-a2 { + compatible = "abc,aaa"; + /export/ node_a: &node_a2; + /export/ other: &other_a; + }; + }; +};
tests/fdtaddon_basics1-merged1.dtb.dts.expect new file +35 -0
@@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop = <0x00>; + }; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +};
tests/fdtaddon_basics1-merged1.dtb.expect new file +27 -0
@@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop = <0x00000000>; + }; + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +};
tests/fdtaddon_basics1-merged2.dtb.dts.expect new file +35 -0
@@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop = <0x00>; + }; + }; + }; +};
tests/fdtaddon_basics1-merged2.dtb.expect new file +27 -0
@@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop = <0x00000000>; + }; + }; + }; +};
tests/fdtaddon_basics1.dtba.expect new file +8 -0
@@ -0,0 +1,8 @@ +/dts-v1/; +/addon/; + +/ { + addon-node { + prop = <0x00000000>; + }; +};
tests/fdtaddon_basics1.dtsa new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + addon-node { + prop = <0>; + }; +};
tests/meson.build +2 -1
@@ -141,7 +141,8 @@ run_test_types = [ 'fdtput', 'fdtdump', 'fdtoverlay', - 'metadata' + 'metadata', + 'fdtaddon' ] run_test_deps = [ dtc_tools, dumptrees_dtb, tests_exe
tests/run_tests.sh +45 -1
64 lines not on this page · raw message
tests/testutils.sh +1 -0
@@ -27,6 +27,7 @@ DTGET=${TEST_BINDIR}/fdtget DTPUT=${TEST_BINDIR}/fdtput FDTDUMP=${TEST_BINDIR}/fdtdump FDTOVERLAY=${TEST_BINDIR}/fdtoverlay +FDTADDON=${TEST_BINDIR}/fdtaddon verbose_run () { if [ -z "$QUIET_TEST" ]; then
Signature · 1 line
2.52.0
RFC PATCH 73/77 tests: fdtaddon: Add a basic test for addons using an orphan nodes
In reply to Herve CodinaOrphan nodes are available in addons.
Add a test checking the application of an addon when orphan nodes are involved.
--- tests/fdtaddon_basics2-merged1.dtb.dts.expect | 35 +++++++++++++++++++ tests/fdtaddon_basics2-merged1.dtb.expect | 27 ++++++++++++++ tests/fdtaddon_basics2-merged2.dtb.dts.expect | 35 +++++++++++++++++++ tests/fdtaddon_basics2-merged2.dtb.expect | 27 ++++++++++++++ tests/fdtaddon_basics2.dtba.expect | 9 +++++ tests/fdtaddon_basics2.dtsa | 15 ++++++++ tests/run_tests.sh | 2 +- 7 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 tests/fdtaddon_basics2-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics2-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics2-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics2-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics2.dtba.expect create mode 100644 tests/fdtaddon_basics2.dtsa
tests/fdtaddon_basics2-merged1.dtb.dts.expect new file +35 -0
@@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop = <0x00>; + }; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +};
tests/fdtaddon_basics2-merged1.dtb.expect new file +27 -0
@@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop = <0x00000000>; + }; + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +};
tests/fdtaddon_basics2-merged2.dtb.dts.expect new file +35 -0
@@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + prop = <0x00>; + }; + }; + }; +};
tests/fdtaddon_basics2-merged2.dtb.expect new file +27 -0
@@ -0,0 +1,27 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + prop = <0x00000000>; + }; + }; + }; +};
tests/fdtaddon_basics2.dtba.expect new file +9 -0
@@ -0,0 +1,9 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +&node_a { + addon-node { + prop = <0x00000000>; + }; +};
tests/fdtaddon_basics2.dtsa new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; + +&node_a { + addon-node { + prop = <0>; + }; +};
tests/run_tests.sh +1 -1
@@ -1189,7 +1189,7 @@ fdtaddon_tests() { run_dtc_test -I dts -O dtb -o fdtaddon_base.dtb "$SRCDIR/fdtaddon_base.dts" check_dtb fdtaddon_base.dtb - for dt in fdtaddon_basics1; do + for dt in fdtaddon_basics1 fdtaddon_basics2; do run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" check_dtb $dt.dtba
Signature · 1 line
2.52.0
RFC PATCH 74/77 tests: fdtaddon: Add a basic test for addons with unresolved phandle references
In reply to Herve CodinaAddons can have unresolved phandle references. Those references are resolved when the addon is applied.
Add a basic test for this feature.
--- tests/fdtaddon_basics3-merged1.dtb.dts.expect | 36 +++++++++++++++++++ tests/fdtaddon_basics3-merged1.dtb.expect | 29 +++++++++++++++ tests/fdtaddon_basics3-merged2.dtb.dts.expect | 36 +++++++++++++++++++ tests/fdtaddon_basics3-merged2.dtb.expect | 29 +++++++++++++++ tests/fdtaddon_basics3.dtba.expect | 12 +++++++ tests/fdtaddon_basics3.dtsa | 17 +++++++++ tests/run_tests.sh | 2 +- 7 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 tests/fdtaddon_basics3-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics3-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics3-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics3-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics3.dtba.expect create mode 100644 tests/fdtaddon_basics3.dtsa
tests/fdtaddon_basics3-merged1.dtb.dts.expect new file +36 -0
@@ -0,0 +1,36 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + ref-other = <&{/base-node/sub-node} 0x0a>; + prop = <0x00>; + }; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +};
tests/fdtaddon_basics3-merged1.dtb.expect new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + ref-other = <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop = <0x00000000>; + }; + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + }; +};
tests/fdtaddon_basics3-merged2.dtb.dts.expect new file +36 -0
@@ -0,0 +1,36 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + ref-other = <&{/base-node/sub-node} 0x0a>; + prop = <0x00>; + }; + }; + }; +};
tests/fdtaddon_basics3-merged2.dtb.expect new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + }; + }; + somewhere { + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000003>; + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + addon-node { + ref-other = <0x00000002 0x0000000a>; + // [FDT_REF_LOCAL] ref-other[0] + prop = <0x00000000>; + }; + }; + }; +};
tests/fdtaddon_basics3.dtba.expect new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon-node { + prop = <0x00000000>; + ref-other = <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref = other + }; +};
tests/fdtaddon_basics3.dtsa new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; +/import/ other: ""; + +&node_a { + addon-node { + prop = <0>; + ref-other = <&other 10>; + }; +};
tests/run_tests.sh +1 -1
@@ -1189,7 +1189,7 @@ fdtaddon_tests() { run_dtc_test -I dts -O dtb -o fdtaddon_base.dtb "$SRCDIR/fdtaddon_base.dts" check_dtb fdtaddon_base.dtb - for dt in fdtaddon_basics1 fdtaddon_basics2; do + for dt in fdtaddon_basics1 fdtaddon_basics2 fdtaddon_basics3; do run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" check_dtb $dt.dtba
Signature · 1 line
2.52.0
RFC PATCH 75/77 tests: fdtaddon: Add a test for addons using namespace label references
In reply to Herve CodinaNamespace label references are labels in the form &foo.bar.baz
Those kind of labels allow to 'jump' from node to node based on exported symbols defined at each nodes.
Add a test for this feature.
--- ...ddon_addon_namespace-merged.dtb.dts.expect | 57 +++++++++++++++++++ ...fdtaddon_addon_namespace-merged.dtb.expect | 49 ++++++++++++++++ tests/fdtaddon_addon_namespace.dtba.expect | 31 ++++++++++ tests/fdtaddon_addon_namespace.dtsa | 34 +++++++++++ tests/fdtaddon_base_namespace.dtb.expect | 29 ++++++++++ tests/fdtaddon_base_namespace.dts | 33 +++++++++++ tests/run_tests.sh | 14 +++++ 7 files changed, 247 insertions(+) create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.expect create mode 100644 tests/fdtaddon_addon_namespace.dtba.expect create mode 100644 tests/fdtaddon_addon_namespace.dtsa create mode 100644 tests/fdtaddon_base_namespace.dtb.expect create mode 100644 tests/fdtaddon_base_namespace.dts
tests/fdtaddon_addon_namespace-merged.dtb.dts.expect new file +57 -0
@@ -0,0 +1,57 @@ +/dts-v1/; + +/ { + + other_n1 { + prop = <0x00>; + phandle = <0x05>; + + /export/ a: &{/other-a}; + /export/ b: &{/other-b}; + }; + + other-a { + prop = <0x00>; + phandle = <0x01>; + + addon-node-1a { + phandle = <0x06>; + prop = <0x1a>; + }; + }; + + other-b { + prop = <0x00>; + phandle = <0x02>; + + /export/ x: &{/other-x}; + }; + + other-x { + prop = <0x00>; + phandle = <0x03>; + + addon-node-1bx { + phandle = <0x07>; + prop = <0x1b>; + }; + }; + + node { + compatible = "abc,aaa"; + phandle = <0x04>; + + /export/ node: &{/node}; + /export/ n1: &{/other_n1}; + + addon-node2 { + ref-addon-n1bx = <&{/other-x/addon-node-1bx}>; + ref-n1bx = <&{/other-x}>; + }; + + addon-node1 { + ref-addon-n1a = <&{/other-a/addon-node-1a}>; + ref-n1a = <&{/other-a}>; + }; + }; +};
tests/fdtaddon_addon_namespace-merged.dtb.expect new file +49 -0
49 lines not on this page · raw message
tests/fdtaddon_addon_namespace.dtba.expect new file +31 -0
@@ -0,0 +1,31 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node' (abc,aaa) +// [FDT_IMPORT_SYM] 'n1' () +&node { + addon-node1 { + ref-n1a = <0xffffffff>; + // [FDT_REF_PHANDLE] ref-n1a[0], ref = n1.a + ref-addon-n1a = <0x00000001>; + // [FDT_REF_LOCAL] ref-addon-n1a[0] + }; + addon-node2 { + ref-n1bx = <0xffffffff>; + // [FDT_REF_PHANDLE] ref-n1bx[0], ref = n1.b.x + ref-addon-n1bx = <0x00000002>; + // [FDT_REF_LOCAL] ref-addon-n1bx[0] + }; +}; +&n1.a { + addon-node-1a { + prop = <0x0000001a>; + phandle = <0x00000001>; + }; +}; +&n1.b.x { + addon-node-1bx { + prop = <0x0000001b>; + phandle = <0x00000002>; + }; +};
tests/fdtaddon_addon_namespace.dtsa new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node: "abc,aaa"; +/import/ n1: ""; + +&node { + addon-node1 { + ref-n1a = <&n1.a>; + ref-addon-n1a = <&addon_n1a>; + }; + + addon-node2 { + ref-n1bx = <&n1.b.x>; + ref-addon-n1bx = <&addon_n1bx>; + }; +}; + +&n1.a { + addon_n1a: addon-node-1a { + prop = <0x1a>; + }; +}; + +&n1.b.x { + addon_n1bx: addon-node-1bx { + prop = <0x1b>; + }; +};
tests/fdtaddon_base_namespace.dtb.expect new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + other_n1 { + prop = <0x00000000>; + phandle = <0x00000005>; + // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'b' -> phandle 0x00000002 + }; + other-a { + prop = <0x00000000>; + phandle = <0x00000001>; + }; + other-b { + prop = <0x00000000>; + phandle = <0x00000002>; + // [FDT_EXPORT_SYM] 'x' -> phandle 0x00000003 + }; + other-x { + prop = <0x00000000>; + phandle = <0x00000003>; + }; + node { + compatible = "abc,aaa"; + phandle = <0x00000004>; + // [FDT_EXPORT_SYM] 'node' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'n1' -> phandle 0x00000005 + }; +};
tests/fdtaddon_base_namespace.dts new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + n1: other_n1 { + prop = <0>; + /export/ a: &other_a; + /export/ b: &other_b; + }; + + other_a: other-a { + prop = <0>; + }; + + other_b: other-b { + prop = <0>; + /export/ x: &other_x; + }; + + other_x: other-x { + prop = <0>; + }; + + node: node { + compatible = "abc,aaa"; + /export/ node: &node; + /export/ n1: &n1; + }; +};
tests/run_tests.sh +14 -0
@@ -1207,6 +1207,20 @@ fdtaddon_tests() { run_dtc_test -I dtb -O dts -o $dt-merged2.dtb.dts $dt-merged2.dtb check_dts $dt-merged2.dtb.dts done + + # Test namespace label reference + run_dtc_test -I dts -O dtb -o fdtaddon_base_namespace.dtb "$SRCDIR/fdtaddon_base_namespace.dts" + check_dtb fdtaddon_base_namespace.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_addon_namespace.dtba "$SRCDIR/fdtaddon_addon_namespace.dtsa" + check_dtb fdtaddon_addon_namespace.dtba + + run_fdtaddon_test -i fdtaddon_base_namespace.dtb -o fdtaddon_addon_namespace-merged.dtb \ + -t "/node" fdtaddon_addon_namespace.dtba + check_dtb fdtaddon_addon_namespace-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_addon_namespace-merged.dtb.dts fdtaddon_addon_namespace-merged.dtb + check_dts fdtaddon_addon_namespace-merged.dtb.dts } pylibfdt_tests () {
Signature · 1 line
2.52.0
RFC PATCH 76/77 tests: fdtaddon: Add a test for using 'stacked' addons
In reply to Herve CodinaAddon can be stacked on top of each other.
A first addon can be applied. This first addon exports some symbols and those exported symbols can be used by a second addon.
Add a test for this feature.
--- .../fdtaddon_stack_1st-merged.dtb.dts.expect | 51 ++++++++++++++ tests/fdtaddon_stack_1st-merged.dtb.expect | 41 +++++++++++ tests/fdtaddon_stack_1st.dtba.expect | 24 +++++++ tests/fdtaddon_stack_1st.dtsa | 27 +++++++ .../fdtaddon_stack_2nd-merged.dtb.dts.expect | 70 +++++++++++++++++++ tests/fdtaddon_stack_2nd-merged.dtb.expect | 59 ++++++++++++++++ tests/fdtaddon_stack_2nd.dtba.expect | 30 ++++++++ tests/fdtaddon_stack_2nd.dtsa | 35 ++++++++++ tests/run_tests.sh | 21 ++++++ 9 files changed, 358 insertions(+) create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.expect create mode 100644 tests/fdtaddon_stack_1st.dtba.expect create mode 100644 tests/fdtaddon_stack_1st.dtsa create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.expect create mode 100644 tests/fdtaddon_stack_2nd.dtba.expect create mode 100644 tests/fdtaddon_stack_2nd.dtsa
tests/fdtaddon_stack_1st-merged.dtb.dts.expect new file +51 -0
@@ -0,0 +1,51 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon1-node { + ref-other = <&{/base-node/sub-node} 0x0a>; + prop = <0x00>; + + sub-node-other { + phandle = <0x05>; + prop = <0x01>; + }; + + sub-node-stack1 { + phandle = <0x04>; + prop = <0x00>; + compatible = "abc,bbb"; + + /export/ stack: &{/somewhere/node-a1/addon1-node/sub-node-stack1}; + /export/ other: &{/somewhere/node-a1/addon1-node/sub-node-other}; + /export/ base_other: &{/base-node/sub-node}; + }; + }; + }; + + node-a2 { + compatible = "abc,aaa"; + phandle = <0x03>; + + /export/ node_a: &{/somewhere/node-a2}; + /export/ other: &{/base-node/sub-node}; + }; + }; +};
tests/fdtaddon_stack_1st-merged.dtb.expect new file +41 -0
41 lines not on this page · raw message
tests/fdtaddon_stack_1st.dtba.expect new file +24 -0
@@ -0,0 +1,24 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon1-node { + prop = <0x00000000>; + ref-other = <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref = other + sub-node-stack1 { + compatible = "abc,bbb"; + prop = <0x00000000>; + phandle = <0x00000001>; + // [FDT_EXPORT_SYM] 'stack' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + // [FDT_EXPORT_SYM_REF] 'base_other' -> 'other' + }; + sub-node-other { + prop = <0x00000001>; + phandle = <0x00000002>; + }; + }; +};
tests/fdtaddon_stack_1st.dtsa new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ node_a: "abc,aaa"; +/import/ other: ""; + +&node_a { + addon1-node { + prop = <0>; + ref-other = <&other 10>; + stack1: sub-node-stack1 { + compatible = "abc,bbb"; + prop = <0>; + /export/ stack: &stack1; + /export/ other: &new_other; + /export/ base_other: &other; + }; + new_other: sub-node-other { + prop = <1>; + }; + }; +};
tests/fdtaddon_stack_2nd-merged.dtb.dts.expect new file +70 -0
70 lines not on this page · raw message
tests/fdtaddon_stack_2nd-merged.dtb.expect new file +59 -0
59 lines not on this page · raw message
tests/fdtaddon_stack_2nd.dtba.expect new file +30 -0
@@ -0,0 +1,30 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'stack' (abc,bbb) +// [FDT_IMPORT_SYM] 'other' () +// [FDT_IMPORT_SYM] 'base_other' () +&stack { + addon2-node { + prop = <0x00000000>; + ref-other = <0xffffffff 0x0000000a>; + // [FDT_REF_PHANDLE] ref-other[0], ref = other + phandle = <0x00000001>; + }; +}; +&other { + addon2-node-other { + prop = <0xffffffff>; + // [FDT_REF_PHANDLE] prop[0], ref = base_other + addon2-subnode { + prop = <0x00000002>; + }; + }; +}; +&base_other { + addon2-node-base-other { + prop = <0x00000001>; + ref = <0x00000001>; + // [FDT_REF_LOCAL] ref[0] + }; +};
tests/fdtaddon_stack_2nd.dtsa new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ stack: "abc,bbb"; +/import/ other: ""; +/import/ base_other: ""; + +&stack { + addon2_node: addon2-node { + prop = <0>; + ref-other = <&other 10>; + }; +}; + +&other { + addon2-node-other { + prop = <&base_other>; + + addon2-subnode { + prop = <2>; + }; + }; +}; + +&base_other { + addon2-node-base-other { + prop = <1>; + ref = <&addon2_node>; + }; +};
tests/run_tests.sh +21 -0
@@ -1221,6 +1221,27 @@ fdtaddon_tests() { run_dtc_test -I dtb -O dts -o fdtaddon_addon_namespace-merged.dtb.dts fdtaddon_addon_namespace-merged.dtb check_dts fdtaddon_addon_namespace-merged.dtb.dts + + # test stacked addons + run_dtc_test -I dts -O dtb -o fdtaddon_stack_1st.dtba "$SRCDIR/fdtaddon_stack_1st.dtsa" + check_dtb fdtaddon_stack_1st.dtba + + run_fdtaddon_test -i fdtaddon_base.dtb -o fdtaddon_stack_1st-merged.dtb \ + -t "/somewhere/node-a1" fdtaddon_stack_1st.dtba + check_dtb fdtaddon_stack_1st-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_stack_1st-merged.dtb.dts fdtaddon_stack_1st-merged.dtb + check_dts fdtaddon_stack_1st-merged.dtb.dts + + run_dtc_test -I dts -O dtb -o fdtaddon_stack_2nd.dtba "$SRCDIR/fdtaddon_stack_2nd.dtsa" + check_dtb fdtaddon_stack_2nd.dtba + + run_fdtaddon_test -i fdtaddon_stack_1st-merged.dtb -o fdtaddon_stack_2nd-merged.dtb \ + -t "/somewhere/node-a1/addon1-node/sub-node-stack1" fdtaddon_stack_2nd.dtba + check_dtb fdtaddon_stack_2nd-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_stack_2nd-merged.dtb.dts fdtaddon_stack_2nd-merged.dtb + check_dts fdtaddon_stack_2nd-merged.dtb.dts } pylibfdt_tests () {
Signature · 1 line
2.52.0
RFC PATCH 77/77 tests: fdtaddon: Add a test using more realistic dts and dtsa
In reply to Herve CodinaThe dts and dtsa files used in the fdtaddon tests were centered on specific addon features in order to test those specific features.
In term of structure or naming, they are not representative of real use-cases.
This new test uses realistic dts and dtsa files with naming and structures tradidionally found in real cases.
The dts describes the hardware of the base board.
The hardware structure of the base board is the following:
+--------------+
| 5V regulator +-------+
+--------------+ |
|
+----------------------+ | +----------------+
| SOC | | | Connector A |
| | | | |
| +-----------------+ | +-------+ 5v |
| + i2c1 controller +---------------+ i2c bus |
| +-----------------+ | +-------+ gpio 0 / irq 0 |
| | | +---+ gpio 1 / irq 1 |
| +------------------+ | | | +----------------+
| | gpio1 controller | | | |
| | gpio #10 +------+ |
| +------------------+ | |
| | |
| +---------------- -+ | |
| | gpio2 controller | | |
| | gpio #3 +----------+
| +------------------+ |
+----------------------+The connector 'Connector A' is the connector where the pluggable board can be connected to. It is described in the dts and related export symbols are set in order to be usable by the dtsa describing the pluggable board.
The hardware structure of the pluggable board is the following:
+---------------+
| EEPROM |
| i2c addr 0x51 |
| +
+-------+ i2c |
| +---------------+
|
| +---------------+
| | Expander IO |
+----------------+ | | i2c addr 0x23 |
| Connector | | | |
| | | +---+ Vcc1 |
| 5v +---|---+---+ Vcc2 |
| i2c bus +---+-------+ i2c |
| gpio 0 / irq 0 +-----------+ irq |
| gpio 1 / irq 1 +-----------+ reset |
+----------------+ +---------------+This structure is described in the addon dtsa. This addon dtsa is expected to be applied to the base device tree node describing the connector the pluggable board is connected to.
--- ...ddon_realistic_addon-merged.dtb.dts.expect | 91 ++++++++++++++++++ ...fdtaddon_realistic_addon-merged.dtb.expect | 93 +++++++++++++++++++ tests/fdtaddon_realistic_addon.dtba.expect | 32 +++++++ tests/fdtaddon_realistic_addon.dtsa | 50 ++++++++++ tests/fdtaddon_realistic_base.dtb.expect | 72 ++++++++++++++ tests/fdtaddon_realistic_base.dts | 74 +++++++++++++++ tests/run_tests.sh | 14 +++ 7 files changed, 426 insertions(+) create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.dts.expect create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.expect create mode 100644 tests/fdtaddon_realistic_addon.dtba.expect create mode 100644 tests/fdtaddon_realistic_addon.dtsa create mode 100644 tests/fdtaddon_realistic_base.dtb.expect create mode 100644 tests/fdtaddon_realistic_base.dts
tests/fdtaddon_realistic_addon-merged.dtb.dts.expect new file +91 -0
@@ -0,0 +1,91 @@ +/dts-v1/; + +/ { + + regulator { + compatible = "regulator-fixed"; + regulator-min-microvolt = <0x4c4b40>; + regulator-max-microvolt = <0x4c4b40>; + gpios = <&{/soc/gpio@2000} 0x05 0x00>; + phandle = <0x05>; + }; + + soc { + compatible = "simple-bus"; + #address-cells = <0x01>; + #size-cells = <0x01>; + + i2c@1000 { + compatible = "xyz,i2c-controller"; + reg = <0x1000 0x100>; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x06>; + }; + + gpio@2000 { + compatible = "xyz,gpio-controller"; + reg = <0x2000 0x100>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + #address-cells = <0x00>; + phandle = <0x01>; + }; + + gpio@3000 { + compatible = "xyz,gpio-controller"; + reg = <0x3000 0x100>; + gpio-controller; + #gpio-cells = <0x02>; + interrupt-controller; + #interrupt-cells = <0x02>; + #address-cells = <0x00>; + phandle = <0x02>; + }; + }; + + connector-a { + compatible = "abc,foo-connector"; + #address-cells = <0x00>; + #interrupt-cells = <0x02>; + interrupt-map = <0x00 0x00 &{/soc/gpio@2000} 0x0a 0x00 0x00 0x100 &{/soc/gpio@2000} 0x0a 0x100 0x01 0x00 &{/soc/gpio@3000} 0x03 0x00 0x01 0x100 &{/soc/gpio@3000} 0x03 0x100>; + #gpio-cells = <0x02>; + gpio-map-mask = <0x0f 0x00>; + gpio-map-pass-thru = <0x00 0x0f>; + gpio-map = <0x00 0x00 &{/soc/gpio@2000} 0x0a 0x00 0x01 0x00 &{/soc/gpio@3000} 0x03 0x00>; + phandle = <0x03>; + + /export/ connector: &{/connector-a}; + /export/ conn_i2c: &{/connector-a/conn-i2c}; + /export/ conn_5v: &{/regulator}; + + conn-i2c { + compatible = "i2c-bus-extension"; + i2c-parent = <&{/soc/i2c@1000}>; + #address-cells = <0x01>; + #size-cells = <0x00>; + phandle = <0x04>; + + eeprom@51 { + reg = <0x51>; + compatible = "xxx,eeprom"; + }; + + gpio@23 { + reset-gpios = <&{/connector-a} 0x01 0x00>; + vcc2-supply = <&{/regulator}>; + vcc1-supply = <&{/regulator}>; + #interrupt-cells = <0x02>; + interrupt-controller; + interrupts = <0x00 0x100>; + interrupt-parent = <&{/connector-a}>; + #gpio-cells = <0x02>; + gpio-controller; + reg = <0x23>; + compatible = "xxx,expander-io"; + }; + }; + }; +};
tests/fdtaddon_realistic_addon-merged.dtb.expect new file +93 -0
93 lines not on this page · raw message
tests/fdtaddon_realistic_addon.dtba.expect new file +32 -0
@@ -0,0 +1,32 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'connector' (abc,foo-connector) +// [FDT_IMPORT_SYM] 'conn_5v' () +&connector { + conn-i2c { + gpio@23 { + compatible = "xxx,expander-io"; + reg = <0x00000023>; + gpio-controller; + #gpio-cells = <0x00000002>; + interrupt-parent = <0xffffffff>; + // [FDT_REF_PHANDLE] interrupt-parent[0], ref = connector + interrupts = <0x00000000 0x00000100>; + interrupt-controller; + #interrupt-cells = <0x00000002>; + vcc1-supply = <0xffffffff>; + // [FDT_REF_PHANDLE] vcc1-supply[0], ref = conn_5v + vcc2-supply = <0xffffffff>; + // [FDT_REF_PHANDLE] vcc2-supply[0], ref = connector.conn_5v + reset-gpios = <0xffffffff 0x00000001 0x00000000>; + // [FDT_REF_PHANDLE] reset-gpios[0], ref = connector + }; + }; +}; +&connector.conn_i2c { + eeprom@51 { + compatible = "xxx,eeprom"; + reg = <0x00000051>; + }; +};
tests/fdtaddon_realistic_addon.dtsa new file +50 -0
50 lines not on this page · raw message
tests/fdtaddon_realistic_base.dtb.expect new file +72 -0
72 lines not on this page · raw message
tests/fdtaddon_realistic_base.dts new file +74 -0
74 lines not on this page · raw message
tests/run_tests.sh +14 -0
@@ -1242,6 +1242,20 @@ fdtaddon_tests() { run_dtc_test -I dtb -O dts -o fdtaddon_stack_2nd-merged.dtb.dts fdtaddon_stack_2nd-merged.dtb check_dts fdtaddon_stack_2nd-merged.dtb.dts + + # More realistic dts and dtsa input files + run_dtc_test -I dts -O dtb -o fdtaddon_realistic_base.dtb "$SRCDIR/fdtaddon_realistic_base.dts" + check_dtb fdtaddon_realistic_base.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_realistic_addon.dtba "$SRCDIR/fdtaddon_realistic_addon.dtsa" + check_dtb fdtaddon_realistic_addon.dtba + + run_fdtaddon_test -i fdtaddon_realistic_base.dtb -o fdtaddon_realistic_addon-merged.dtb \ + -t "/connector-a" fdtaddon_realistic_addon.dtba + check_dtb fdtaddon_realistic_addon-merged.dtb + + run_dtc_test -I dtb -O dts -o fdtaddon_realistic_addon-merged.dtb.dts fdtaddon_realistic_addon-merged.dtb + check_dts fdtaddon_realistic_addon-merged.dtb.dts } pylibfdt_tests () {
Signature · 1 line
2.52.0
Quoted 184 lines · Herve Codina
This big picture series adds support for dtb metadata and addon device-trees.
Before giving details about the series content, let me give a little bit of context.
The use-case is to support additional boards that can be hot-plugged to a connector available in a base board. This connector is standardized in terms of resources available on each pin. Any additional boards compatible with the connector should be able to be connected to base board and all base boards where this connector is implemented should support any additional boards.
TLDR: The last patch, patch 77, gives an example of dts and dtsa (new
addon device-tree) handling this use-case. It provides an example of a realistic base board description (dts) and an realistic additional board description (dtsa).Each base board is described by its own device-tree and the real resource connected to the connector depends on each board. For instance an i2c bus on the connector can come from the i2c1 controller from base board A and i2c5 controller from base board B. This is obviously the case for all resources wired to the connector.
On the other hand, the device-tree describing the additional board has no reason to be changed based on the base board the additional board is going to be connected. Indeed this device-tree describes the additional board hardware and this hardware doesn't change if the additional board is connected to the base board A or the base board B.
In order to extend a device-tree at runtime, a device-tree overlay can be used. The drawback of current overlay implementation is that an overlay is tightly coupled with the base device-tree it is applied to.
If a symbol of the base device-tree has to be used by the overlay, all symbols available in the base device-tree need to be visible by the overlay and the overlay can use only those symbol without any kind of name translation.
With current overlay implementation, a overlay depends on the base board. Indeed, if an overlay wants to add an I2C device on the I2C bus available on the base board A connector, it needs to reference the i2c1 bus whereas it needs to reference the i2c5 bus if it used with the base board B.
In order to fix the issue, the 'export symbol' concept has been proposed. This concept allows some specific node to 'export' symbols in order to be seen by an overlay applied to this node.
The use-case and the export symbol proposal have been detailed during a talk at ELCE 2025. Have a look at the slides [1] and/or the video [2] to have a clear view of the topic
[1] https://bootlin.com/pub/conferences/2025/elce/ceresoli-hotplug-status.pdf
[2] https://www.youtube.com/watch?v=C8dEQ4OzMncThe export symbol proposal based on an export-symbol node in the device-tree have been rejected by device-tree and dtc maintainers.
A discussion about the topic has been started on the mailing-list [3]. This discussions led to:
- The addition of meta-data in dtb instead of having
__fixup__,__local__fixup__, an similar nodes in the device-tree used by overlays- A new kind of device-tree, an addon device-tree, in order to replace the usage of the overlay device-tree in this 'hot-plugging additional board' use-case.
[3] https://lore.kernel.org/all/20250902105710.00512c6d@booty/
This current RFC is the implementation of features discussed on the mailing-list. A lot of things are new in dtb format (new tags) and dts format (new keyword, new kind of references) and not yet mentioned in the standard.
The purpose of this big picture RFC is to move forward on this topic based on code and some concrete dts / dtb example. Indeed, this RFC also adds tests for each feature introduced. Those tests are performed using dts files and the content of those dts files can also help in the discussion.
The first patch is just a simple fix and can probably be merged out of this meta-data and addon discussion.
- Patches 2..12: Introduce new meta-data dtb tags based on markers
Those new tags are
FDT_REF_LOCALandFDT_REF_PHANDLE.
FDT_REF_LOCAL(details in patch 6) is used to tag property using a phandle and this phandle points to a local node (i.e. a node existing in the dtb).
FDT_REF_PHANDLE(details in patch 11) is used to tag a property using a phandle but this phandle points to a non local node (i.e. the node doesn't exist in the dtb). The reference to the node is present with the tag and the phandle value has to be fixed when the dtb is applied. This tag can only be present in plugins (overlays) and addons dtb.- Patches 13..17: Introduce addons device-tree
This part introduce the new /addon/ dts keyword
- Patches 18..30: Introduce /export/ keyword and related dtb tags
This part introduces the new /export/ dts keyword (details in patch
20) and the relatedFDT_EXPORT_SYMandFDT_EXPORT_SYM_REFdtb tags.
FDT_EXPORT_SYM(details in patch 25) is used when the exported symbol involved is a local node andFDT_EXPORT_SYM_REF(details in patch 29) is used when the node involved is a non local node.- Patches 31..38: Introduce /import/ keyword and related dtb tags
This part introduces the new /import/ dts keyword (details in patch
33) and the relatedFDT_IMPORT_SYMdtb tag (details in patch 35).- Patches 39..63: Introduce orphan nodes
Even if the orphan nodes concept was already present in overlays, the final encoding of those nodes in addon dtbs is different compared to overlays dtbs.
In overlays, orphan nodes are transformed to a /fragment@n/__overlay__ node. This is not the way used in addons.
Indeed, in addons, orphan nodes are not transformed to fit in something like /fragment@n/__overlay__. They are encoded in the dtb using a specific tag.
This part, after some preparation, introduces orphan nodes (details in patch 48) and the related
FDT_BEGIN_NODE_REF_SYMdtb tag (details in patch 56).It also adds support for addons dts/dtb without a 'root' (details in patch 58).
This part ended with the support for merging orphan node described in dts when relevant (details patch 60).
- Patches 64..65: Reference orphan nodes and its sub-nodes by path
A new syntax is needed to be able to reference a an orphan node and its sub-nodes by path.
This new syntax is '${$<orphan_name>/<path>}' (details in patch #60)
- Patches 66..67: Namespace labels references
Add Namespace labels references with the new syntax '&foo.bar.baz'.
This new syntax, only allowed in addons, allows to 'jump' from node to node based on exported symbols defined at each node (details in patch 66).
- Patches 68..71: Support for applying an addon
First, add
fdt_addon_apply()in libfdt (details in patch 70) and then the fdtaddon command line tool (details in patch 71).- Patches 72..76: fdtaddon test
Several tests related to addon application
- Patch 77: A more Realistic test
A last test based on use-case we want to handle.
This last patch (and its dts and dtsa files) shows the kind of usage is expected for addons.
Also it proves that metadata and addons features handles our use-case.
I know this series is a huge series but I would like to give the big picture in this RFC (I hope this was a good idea). Of course, this series can be split for the upstreaming step and handled by parts by parts. Let me know.
Tests are provided for each feature. In addition to be used for testing, tests input source files and expected output files can be used to see the expected behavior related to each feature.
Quoted 5 lines
I hope also that this first RFC will help in moving forward regarding this 'handling an additional board described by a device-tree' topic.
Best regards,
Hervé
Hello Herve,
I was just in the process of typing out a reply in the old thread for the topic regarding restarting discussion and how we should move towards extending DT. So imagine my surprise when this lands in my mailbox. Thanks for all this work.
I will go through this series and check things in reference with my connector + addon baord setups.
Best Regards,
Ayush Singh
Quoted 14 lines · Herve Codina
This big picture series adds support for dtb metadata and addon device-trees.
Before giving details about the series content, let me give a little bit of context.
The use-case is to support additional boards that can be hot-plugged to a connector available in a base board. This connector is standardized in terms of resources available on each pin. Any additional boards compatible with the connector should be able to be connected to base board and all base boards where this connector is implemented should support any additional boards.
Quoted 4 lines
TLDR: The last patch, patch 77, gives an example of dts and dtsa (new
addon device-tree) handling this use-case. It provides an example of a realistic base board description (dts) and an realistic additional board description (dtsa).
From a quick scan, that seems reasonable looking to me. The main thing that got my attention was the namespace labels thing which I'll need to study more.
Quoted 44 lines
Each base board is described by its own device-tree and the real resource connected to the connector depends on each board. For instance an i2c bus on the connector can come from the i2c1 controller from base board A and i2c5 controller from base board B. This is obviously the case for all resources wired to the connector.
On the other hand, the device-tree describing the additional board has no reason to be changed based on the base board the additional board is going to be connected. Indeed this device-tree describes the additional board hardware and this hardware doesn't change if the additional board is connected to the base board A or the base board B.
In order to extend a device-tree at runtime, a device-tree overlay can be used. The drawback of current overlay implementation is that an overlay is tightly coupled with the base device-tree it is applied to.
If a symbol of the base device-tree has to be used by the overlay, all symbols available in the base device-tree need to be visible by the overlay and the overlay can use only those symbol without any kind of name translation.
With current overlay implementation, a overlay depends on the base board. Indeed, if an overlay wants to add an I2C device on the I2C bus available on the base board A connector, it needs to reference the i2c1 bus whereas it needs to reference the i2c5 bus if it used with the base board B.
In order to fix the issue, the 'export symbol' concept has been proposed. This concept allows some specific node to 'export' symbols in order to be seen by an overlay applied to this node.
The use-case and the export symbol proposal have been detailed during a talk at ELCE 2025. Have a look at the slides [1] and/or the video [2] to have a clear view of the topic
[1] https://bootlin.com/pub/conferences/2025/elce/ceresoli-hotplug-status.pdf
[2] https://www.youtube.com/watch?v=C8dEQ4OzMncThe export symbol proposal based on an export-symbol node in the device-tree have been rejected by device-tree and dtc maintainers.
A discussion about the topic has been started on the mailing-list [3]. This discussions led to:
Quoted 6 lines
- The addition of meta-data in dtb instead of having
__fixup__,__local__fixup__, an similar nodes in the device-tree used by overlays- A new kind of device-tree, an addon device-tree, in order to replace the usage of the overlay device-tree in this 'hot-plugging additional board' use-case.
I guess "addons" is overlays 2.0. Do you envision any use for overlays 1.0 after this? I wouldn't think so other than compatibility for existing overlays.
Maybe a conversion tool and/or function would be useful (not asking for that now).
Quoted 6 lines
[3] https://lore.kernel.org/all/20250902105710.00512c6d@booty/
This current RFC is the implementation of features discussed on the mailing-list. A lot of things are new in dtb format (new tags) and dts format (new keyword, new kind of references) and not yet mentioned in the standard.
spec follows code. :)
Quoted 17 lines
The purpose of this big picture RFC is to move forward on this topic based on code and some concrete dts / dtb example. Indeed, this RFC also adds tests for each feature introduced. Those tests are performed using dts files and the content of those dts files can also help in the discussion.
The first patch is just a simple fix and can probably be merged out of this meta-data and addon discussion.
- Patches 2..12: Introduce new meta-data dtb tags based on markers
Those new tags are
FDT_REF_LOCALandFDT_REF_PHANDLE.
FDT_REF_LOCAL(details in patch 6) is used to tag property using a phandle and this phandle points to a local node (i.e. a node existing in the dtb).
Quoted 6 lines
FDT_REF_PHANDLE(details in patch 11) is used to tag a property using a phandle but this phandle points to a non local node (i.e. the node doesn't exist in the dtb). The reference to the node is present with the tag and the phandle value has to be fixed when the dtb is applied. This tag can only be present in plugins (overlays) and addons dtb.
This is very much aligned with what I would like to see. We've discussed new DTB formats in the past and it becomes a laundry list of changes likely resulting in something entirely different. I think that's never going to move forward (it's only been discussed for 10+ years). I think doing something like this is much easier to define and deploy.
I think the first step is just allowing the FDT format to have additional tags with metadata that's not yet defined. Ideally that would be just "allow unknown tags" instead of giving a parsing error. However, I think we have to at least know the length of data for unknown tags, so maybe we define a range of tag values which are followed by a length. Either way, that should be a pretty small change and easily deployed everywhere (that uses libfdt). After that, then we can start to define the specific tags and meta-data we want. I would like to see not just phandle info, but all type information for example.
The addition of phandle info is also useful for fw_devlink (which is the kernel's device dependency tracking), and I've been talking with Saravana some about an approach like this.
Quoted 4 lines
- Patches 13..17: Introduce addons device-tree
This part introduce the new /addon/ dts keyword
Quoted 8 lines
- Patches 18..30: Introduce /export/ keyword and related dtb tags
This part introduces the new /export/ dts keyword (details in patch
20) and the relatedFDT_EXPORT_SYMandFDT_EXPORT_SYM_REFdtb tags.
FDT_EXPORT_SYM(details in patch 25) is used when the exported symbol involved is a local node andFDT_EXPORT_SYM_REF(details in patch 29) is used when the node involved is a non local node.
More generally, would these just be "node metadata" tags?
Rob
Hi Rob,
Quoted 1 line · On Tue, 13 Jan 2026 12:44:07 -0600 Rob Herring <[email protected]> wrote:
On Mon, Jan 12, 2026 at 8:20 AM Herve Codina <[email protected]> wrote:
...
Quoted 8 lines
Quoted 4 lines
- A new kind of device-tree, an addon device-tree, in order to replace the usage of the overlay device-tree in this 'hot-plugging additional board' use-case.
I guess "addons" is overlays 2.0. Do you envision any use for overlays 1.0 after this? I wouldn't think so other than compatibility for existing overlays.
On my side, with use cases I know about, I plan to switch to addons.
Of course, our connector use case which was the use case that leads to series will use addons.
Also, I plan to move the overlay used in the LAN966x PCI use case (overlay on top of PCI devices) to addons. I will do that when all needed support for this feature will be available in the Linux kernel.
Quoted 3 lines
Maybe a conversion tool and/or function would be useful (not asking for that now).
Indeed, this kind of tool could be a nice to have.
Quoted 62 lines
Quoted 7 lines
[3] https://lore.kernel.org/all/20250902105710.00512c6d@booty/
This current RFC is the implementation of features discussed on the mailing-list. A lot of things are new in dtb format (new tags) and dts format (new keyword, new kind of references) and not yet mentioned in the standard.
spec follows code. :)
Quoted 17 lines
The purpose of this big picture RFC is to move forward on this topic based on code and some concrete dts / dtb example. Indeed, this RFC also adds tests for each feature introduced. Those tests are performed using dts files and the content of those dts files can also help in the discussion.
The first patch is just a simple fix and can probably be merged out of this meta-data and addon discussion.
- Patches 2..12: Introduce new meta-data dtb tags based on markers
Those new tags are
FDT_REF_LOCALandFDT_REF_PHANDLE.
FDT_REF_LOCAL(details in patch 6) is used to tag property using a phandle and this phandle points to a local node (i.e. a node existing in the dtb).Quoted 6 lines
FDT_REF_PHANDLE(details in patch 11) is used to tag a property using a phandle but this phandle points to a non local node (i.e. the node doesn't exist in the dtb). The reference to the node is present with the tag and the phandle value has to be fixed when the dtb is applied. This tag can only be present in plugins (overlays) and addons dtb.This is very much aligned with what I would like to see. We've discussed new DTB formats in the past and it becomes a laundry list of changes likely resulting in something entirely different. I think that's never going to move forward (it's only been discussed for 10+ years). I think doing something like this is much easier to define and deploy.
I think the first step is just allowing the FDT format to have additional tags with metadata that's not yet defined. Ideally that would be just "allow unknown tags" instead of giving a parsing error. However, I think we have to at least know the length of data for unknown tags, so maybe we define a range of tag values which are followed by a length. Either way, that should be a pretty small change and easily deployed everywhere (that uses libfdt). After that, then we can start to define the specific tags and meta-data we want. I would like to see not just phandle info, but all type information for example.
The addition of phandle info is also useful for
fw_devlink(which is the kernel's device dependency tracking), and I've been talking with Saravana some about an approach like this.Quoted 6 lines
- Patches 13..17: Introduce addons device-tree
This part introduce the new /addon/ dts keyword
- Patches 18..30: Introduce /export/ keyword and related dtb tags
Quoted 9 lines
Quoted 6 lines
This part introduces the new /export/ dts keyword (details in patch
20) and the relatedFDT_EXPORT_SYMandFDT_EXPORT_SYM_REFdtb tags.
FDT_EXPORT_SYM(details in patch 25) is used when the exported symbol involved is a local node andFDT_EXPORT_SYM_REF(details in patch 29) is used when the node involved is a non local node.More generally, would these just be "node metadata" tags?
I think we can have metadata at 3 differents levels:
- Property
- Node
- Global dtb
With the suggestion you did on patch 6 related to FDT_REF_LOCAL and if I understood correctly, you expect to have a kind of "container" tag to group metadata on each level.
Also you expect to have the ability to handle all 'for now unknown' tag smoothly and so, I agree, the length of the data related to a tag are needed to be present with the tag itself. I see to kind of tag, some with the length of data available in the u32 following the tag and other without the length encoded.
Tags without length encoded are followed by one u32 field containing data related to the tag. This allow to avoid a lot of 'TAG_XXX 0x04 u32_data' Indeed, I have the feeling that quite a lot of tags will have only one u32 field as data part and so, having 0x04 encoded (cell aligned) each time.
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this categorie
- 1: New kind of tag adopting this definition
- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag
0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.
- bit 27..0
tag specific identifier
With that definition, the following tags can be defined:
- FDT_INFO_PROPERTY (new tag, length encoding): 0xf0000001 This tag is available after a property.
It is followed by a cell for the length of data, the data part is a sequence of tags (and related data) giving information related to the last property available before the tag.
- FDT_REF_LOCAL (new tag, 1 cell data): 0x90000002:
The cell after this tag is the offset in the property where a local phandle is available
- FDT_REF_PHANDLE (new tag, length encoding): 0xf0000003 Cf. patch 11 for definition
It is followed by a cell for the length of data. The data part is composed of:
- offset (u32)
- label (string including \0)
- padding if needed to have next item aligned on 32bits
With that defined, supposing the following dts example:
--- 8< ---
/* 'foo' is a reference to local node,
* 'bar' is a reference to an external node */
prop = <1 2 &foo &bar1>;
--- 8< ---
The dtb will see the following structure:FDT_PROP ...FDT_INFO_PROPERTY (0xf0000001)
28 (length = (4+4)+(4+4+12) bytes)
FDT_REF_LOCAL (0x90000002)
0x8 <--- offset of &foo
FDT_REF_PHANDLE (0xf0000003)
12 (length = 4+4+1+3 bytes)
0xc <--- offset of &bar
"bar1" + its \0 <-- reference to resolve
0x00 0x00 0x00 <-- 3 bytes paddingAdding FDT_TYPE_U32 later will consist in defining its value, probably a 0x9 family (1 cell after the tag for the offset value)
At any point, only looking at the higher part of the tag (i.e. 0xN.......), we can skip the tag and its data if don't know about the tag.
- 0x0: Old tag format
-> Error if unknown
- 0x8 to 0xe: New format followed by 0 (0x8) to 6 cells of data
-> Ignore if unknown and skip the N cells of data to look at the next
- 0xf: New format followed by 1 cell giving the size of following data. -> Ignore if unknown and read the length available in the cell after the tag, skip length byte of data to look at the next.
If the length read is not a multiple of 4: Error, invalid tag.
For this series we need the container tags:
- FDT_INFO_PROPERTY for information related to a property Among known tags defined in this series, only FDT_REF_LOCAL and FDT_REF_PHANDLE can be grouped into a FDT_INFO_PROPERTY.
- FDT_INFO_NODE for information related to a node
Among known tags defined in this series, only FDT_EXPORT_SYM_LOCAL and FDT_EXPORT_SYM_REF can be grouped into a FDT_INFO_NODE.
- FDT_INFO_DTB for information related to the dtb
Among known tags defined in this series, only FDT_IMPORT_SYM can be present into a FDT_INFO_DTB.
IMHO, the new tag FDT_BEGIN_NODE_REF related to orphan nodes doesn't have to be in one of those containers. Indeed, FDT_BEGIN_NODE_REF is more a node definition than a metadata.
Rob, does this could fit with what you expect?
If it does, is it relevant to keep the length cell available in 0xf family to be in bytes. It should be a multiple of 4 in all cases and so it can be given in the number of 32bit words instead of bytes.
Best regards,
Hervé
Quoted 6 lines · Herve Codina
Hi Rob,
Quoted 1 line · On Tue, 13 Jan 2026 12:44:07 -0600 Rob Herring <[email protected]> wrote:
On Mon, Jan 12, 2026 at 8:20 AM Herve Codina <[email protected]> wrote:
[snip]
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
- Patches 13..17: Introduce addons device-tree
This part introduce the new /addon/ dts keyword
- Patches 18..30: Introduce /export/ keyword and related dtb tags
This part introduces the new /export/ dts keyword (details in patch
20) and the relatedFDT_EXPORT_SYMandFDT_EXPORT_SYM_REFdtb tags.
FDT_EXPORT_SYM(details in patch 25) is used when the exported symbol involved is a local node andFDT_EXPORT_SYM_REF(details in patch 29) is used when the node involved is a non local node.
Quoted 7 lines
Quoted 2 lines
More generally, would these just be "node metadata" tags?
I think we can have metadata at 3 differents levels:
- Property
- Node
- Global dtb
This is a really minor point, but I don't especially like the term "metadata" for the symbol / fixup information. Although it's technically accurate that it's metadata for the property bytestrings, in most contexts "metadata" makes me think only of tree global metadata. By analogy, symbols and fixup information in a .so or .a could be seen as metadata to the raw code / data bytes, but I wouldn't normally use that term for it (whereas I might for, say, the soname or certain .note sections).
Quoted 36 lines
With the suggestion you did on patch 6 related to
FDT_REF_LOCALand if I understood correctly, you expect to have a kind of "container" tag to group metadata on each level.Also you expect to have the ability to handle all 'for now unknown' tag smoothly and so, I agree, the length of the data related to a tag are needed to be present with the tag itself. I see to kind of tag, some with the length of data available in the u32 following the tag and other without the length encoded.
Tags without length encoded are followed by one u32 field containing data related to the tag. This allow to avoid a lot of '
TAG_XXX0x04u32_data' Indeed, I have the feeling that quite a lot of tags will have only one u32 field as data part and so, having0x04encoded (cell aligned) each time.A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this categorie
- 1: New kind of tag adopting this definition- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag
0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.
Quoted 2 lines
- bit 27..0
tag specific identifier
As noted elsewhere, I'm not necessarily opposed to having a general length encoding. However, for each new tag I think we need to think carefully about whether it really is safe for older software that doesn't understand it to just skip it.
Quoted 6 lines
With that definition, the following tags can be defined:
-FDT_INFO_PROPERTY(new tag, length encoding):0xf0000001This tag is available after a property.
It is followed by a cell for the length of data, the data part is a sequence of tags (and related data) giving information related to the last property available before the tag.
I'd prefer to avoid an additional layer of nesting here - I'd rather just have multiple top level tags.
Quoted 60 lines
-
FDT_REF_LOCAL(new tag, 1 cell data):0x90000002:
The cell after this tag is the offset in the property where a local phandle is available-
FDT_REF_PHANDLE(new tag, length encoding):0xf0000003Cf. patch 11 for definition
It is followed by a cell for the length of data. The data part is composed of:
- offset (u32)
- label (string including \0)
- padding if needed to have next item aligned on 32bitsWith that defined, supposing the following dts example:
--- 8< ---
/* 'foo' is a reference to local node,
* 'bar' is a reference to an external node */
prop = <1 2 &foo &bar1>;
--- 8< ---The dtb will see the following structure:
FDT_PROP...FDT_INFO_PROPERTY(0xf0000001)
28 (length = (4+4)+(4+4+12) bytes)
FDT_REF_LOCAL(0x90000002)0x8 <--- offset of &foo FDT_REF_PHANDLE (0xf0000003) 12 (length = 4+4+1+3 bytes) 0xc <--- offset of &bar "bar1" + its \0 <-- reference to resolve 0x00 0x00 0x00 <-- 3 bytes paddingAdding
FDT_TYPE_U32later will consist in defining its value, probably a0x9family (1 cell after the tag for the offset value)At any point, only looking at the higher part of the tag (i.e. 0xN.......), we can skip the tag and its data if don't know about the tag.
-0x0: Old tag format-> Error if unknown-
0x8to0xe: New format followed by 0 (0x8) to 6 cells of data-> Ignore if unknown and skip the N cells of data to look at the next-
0xf: New format followed by 1 cell giving the size of following data. -> Ignore if unknown and read the length available in the cell after the tag, skip length byte of data to look at the next.
If the length read is not a multiple of 4: Error, invalid tag.For this series we need the container tags:
-FDT_INFO_PROPERTYfor information related to a property Among known tags defined in this series, onlyFDT_REF_LOCALandFDT_REF_PHANDLEcan be grouped into aFDT_INFO_PROPERTY.-
FDT_INFO_NODEfor information related to a node
Among known tags defined in this series, onlyFDT_EXPORT_SYM_LOCALandFDT_EXPORT_SYM_REFcan be grouped into aFDT_INFO_NODE.
Quoted 7 lines
-
FDT_INFO_DTBfor information related to the dtb
Among known tags defined in this series, onlyFDT_IMPORT_SYMcan be present into aFDT_INFO_DTB.IMHO, the new tag
FDT_BEGIN_NODE_REFrelated to orphan nodes doesn't have to be in one of those containers. Indeed,FDT_BEGIN_NODE_REFis more a node definition than a metadata.
That's a perfect example of a new tag that absolutely cannot be just skipped if not understood. Software *must* hard error if they encounter this and don't understand it.
Quoted 10 lines
Rob, does this could fit with what you expect?
If it does, is it relevant to keep the length cell available in
0xffamily to be in bytes. It should be a multiple of 4 in all cases and so it can be given in the number of 32bit words instead of bytes.Best regards,
Hervé
Signature · 4 lines
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
Hi Rob, David,
On Mon, 19 Jan 2026 17:00:44 +1100
David Gibson <[email protected]> wrote:
...
Quoted 133 lines
Quoted 5 lines
I think we can have metadata at 3 differents levels:
- Property
- Node
- Global dtbThis is a really minor point, but I don't especially like the term "metadata" for the symbol / fixup information. Although it's technically accurate that it's metadata for the property bytestrings, in most contexts "metadata" makes me think only of tree global metadata. By analogy, symbols and fixup information in a .so or .a could be seen as metadata to the raw code / data bytes, but I wouldn't normally use that term for it (whereas I might for, say, the soname or certain .note sections).
Quoted 36 lines
With the suggestion you did on patch 6 related to
FDT_REF_LOCALand if I understood correctly, you expect to have a kind of "container" tag to group metadata on each level.Also you expect to have the ability to handle all 'for now unknown' tag smoothly and so, I agree, the length of the data related to a tag are needed to be present with the tag itself. I see to kind of tag, some with the length of data available in the u32 following the tag and other without the length encoded.
Tags without length encoded are followed by one u32 field containing data related to the tag. This allow to avoid a lot of '
TAG_XXX0x04u32_data' Indeed, I have the feeling that quite a lot of tags will have only one u32 field as data part and so, having0x04encoded (cell aligned) each time.A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this categorie
- 1: New kind of tag adopting this definition- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag
0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.Quoted 2 lines
- bit 27..0
tag specific identifierAs noted elsewhere, I'm not necessarily opposed to having a general length encoding. However, for each new tag I think we need to think carefully about whether it really is safe for older software that doesn't understand it to just skip it.
Quoted 6 lines
With that definition, the following tags can be defined:
-FDT_INFO_PROPERTY(new tag, length encoding):0xf0000001This tag is available after a property.
It is followed by a cell for the length of data, the data part is a sequence of tags (and related data) giving information related to the last property available before the tag.I'd prefer to avoid an additional layer of nesting here - I'd rather just have multiple top level tags.
Quoted 64 lines
-
FDT_REF_LOCAL(new tag, 1 cell data):0x90000002:
The cell after this tag is the offset in the property where a local phandle is available-
FDT_REF_PHANDLE(new tag, length encoding):0xf0000003Cf. patch 11 for definition
It is followed by a cell for the length of data. The data part is composed of:
- offset (u32)
- label (string including \0)
- padding if needed to have next item aligned on 32bitsWith that defined, supposing the following dts example:
--- 8< ---
/* 'foo' is a reference to local node,
* 'bar' is a reference to an external node */
prop = <1 2 &foo &bar1>;
--- 8< ---The dtb will see the following structure:
FDT_PROP...FDT_INFO_PROPERTY(0xf0000001)
28 (length = (4+4)+(4+4+12) bytes)
FDT_REF_LOCAL(0x90000002)0x8 <--- offset of &foo FDT_REF_PHANDLE (0xf0000003) 12 (length = 4+4+1+3 bytes) 0xc <--- offset of &bar "bar1" + its \0 <-- reference to resolve 0x00 0x00 0x00 <-- 3 bytes paddingAdding
FDT_TYPE_U32later will consist in defining its value, probably a0x9family (1 cell after the tag for the offset value)At any point, only looking at the higher part of the tag (i.e. 0xN.......), we can skip the tag and its data if don't know about the tag.
-0x0: Old tag format-> Error if unknown-
0x8to0xe: New format followed by 0 (0x8) to 6 cells of data-> Ignore if unknown and skip the N cells of data to look at the next-
0xf: New format followed by 1 cell giving the size of following data. -> Ignore if unknown and read the length available in the cell after the tag, skip length byte of data to look at the next.
If the length read is not a multiple of 4: Error, invalid tag.For this series we need the container tags:
-FDT_INFO_PROPERTYfor information related to a property Among known tags defined in this series, onlyFDT_REF_LOCALandFDT_REF_PHANDLEcan be grouped into aFDT_INFO_PROPERTY.-
FDT_INFO_NODEfor information related to a node
Among known tags defined in this series, onlyFDT_EXPORT_SYM_LOCALandFDT_EXPORT_SYM_REFcan be grouped into aFDT_INFO_NODE.-
FDT_INFO_DTBfor information related to the dtb
Among known tags defined in this series, onlyFDT_IMPORT_SYMcan be present into aFDT_INFO_DTB.
Quoted 8 lines
Quoted 3 lines
IMHO, the new tag
FDT_BEGIN_NODE_REFrelated to orphan nodes doesn't have to be in one of those containers. Indeed,FDT_BEGIN_NODE_REFis more a node definition than a metadata.That's a perfect example of a new tag that absolutely cannot be just skipped if not understood. Software *must* hard error if they encounter this and don't understand it.
I have started to implement this "unknown tag" feature based on the tag values definition presented here and with complementary feature (bit allowing to skip an unknown tag) as presented in patch 2 discussion [1].
I didn't introduce any FDT_INFO_xxx tags. They introduce nesting tags and David seems not agree with that.
I use simple test tags to have some "unknown tags" in dtb and looked at the way to handle them.
When we read a dtb, no problem, we just skip "unknown tags" if we are allowed to (flag in tag value).
The issue comes when we modify a dtb.
libftd allows to modify a dtb. It allows to add/modify/remove properties and nodes. Bootloaders for instance use this capability to update a dtb before passing it to the kernel.
How should we handle unknown tags in this context?
We don't knwow about the meaning of those tags (unknown tags) and so, we don't know if those tags are still consistent with modifications done?
A property can be followed by an unknown tags related to this property. Also a property can be followed by an unknown tag related to the node. We simply don't know.
Any modification can impact unknown tags and make them inconsistent. Here again, we simply don't know.
Should we avoid any modification when a dtb contains unknown tags? Should we simply remove all unknown tags when a modification is done?
Bootloaders need to modify the dtb. Avoiding modification is a no-go. Removing "unknown tags" when a modification is done will lead to removing all unknown tags at bootloader stage.
Rob, David, any opinion related to this specific issue and the strategy we should follow when modification are involved?
[1] https://lore.kernel.org/all/[email protected]/
Best regards,
Hervé
Quoted 164 lines · Herve Codina
Hi Rob, David,
On Mon, 19 Jan 2026 17:00:44 +1100
David Gibson <[email protected]> wrote:...
Quoted 133 lines
Quoted 5 lines
I think we can have metadata at 3 differents levels:
- Property
- Node
- Global dtbThis is a really minor point, but I don't especially like the term "metadata" for the symbol / fixup information. Although it's technically accurate that it's metadata for the property bytestrings, in most contexts "metadata" makes me think only of tree global metadata. By analogy, symbols and fixup information in a .so or .a could be seen as metadata to the raw code / data bytes, but I wouldn't normally use that term for it (whereas I might for, say, the soname or certain .note sections).
Quoted 36 lines
With the suggestion you did on patch 6 related to
FDT_REF_LOCALand if I understood correctly, you expect to have a kind of "container" tag to group metadata on each level.Also you expect to have the ability to handle all 'for now unknown' tag smoothly and so, I agree, the length of the data related to a tag are needed to be present with the tag itself. I see to kind of tag, some with the length of data available in the u32 following the tag and other without the length encoded.
Tags without length encoded are followed by one u32 field containing data related to the tag. This allow to avoid a lot of '
TAG_XXX0x04u32_data' Indeed, I have the feeling that quite a lot of tags will have only one u32 field as data part and so, having0x04encoded (cell aligned) each time.A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this categorie
- 1: New kind of tag adopting this definition- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a
multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.Quoted 2 lines
- bit 27..0
tag specific identifierAs noted elsewhere, I'm not necessarily opposed to having a general length encoding. However, for each new tag I think we need to think carefully about whether it really is safe for older software that doesn't understand it to just skip it.
Quoted 6 lines
With that definition, the following tags can be defined:
-FDT_INFO_PROPERTY(new tag, length encoding):0xf0000001This tag is available after a property.
It is followed by a cell for the length of data, the data part is a sequence of tags (and related data) giving information related to the last property available before the tag.I'd prefer to avoid an additional layer of nesting here - I'd rather just have multiple top level tags.
Quoted 64 lines
-
FDT_REF_LOCAL(new tag, 1 cell data):0x90000002:
The cell after this tag is the offset in the property where a local phandle is available-
FDT_REF_PHANDLE(new tag, length encoding):0xf0000003Cf. patch 11 for definition
It is followed by a cell for the length of data. The data part is composed of:
- offset (u32)
- label (string including \0)
- padding if needed to have next item aligned on 32bitsWith that defined, supposing the following dts example:
--- 8< ---
/* 'foo' is a reference to local node,
* 'bar' is a reference to an external node */
prop = <1 2 &foo &bar1>;
--- 8< ---The dtb will see the following structure:
FDT_PROP...FDT_INFO_PROPERTY(0xf0000001)
28 (length = (4+4)+(4+4+12) bytes)
FDT_REF_LOCAL(0x90000002)0x8 <--- offset of &foo FDT_REF_PHANDLE (0xf0000003) 12 (length = 4+4+1+3 bytes) 0xc <--- offset of &bar "bar1" + its \0 <-- reference to resolve 0x00 0x00 0x00 <-- 3 bytes paddingAdding
FDT_TYPE_U32later will consist in defining its value, probably a0x9family (1 cell after the tag for the offset value)At any point, only looking at the higher part of the tag (i.e. 0xN.......), we can skip the tag and its data if don't know about the tag.
-0x0: Old tag format-> Error if unknown-
0x8to0xe: New format followed by 0 (0x8) to 6 cells of data-> Ignore if unknown and skip the N cells of data to look at the next-
0xf: New format followed by 1 cell giving the size of following data. -> Ignore if unknown and read the length available in the cell after the tag, skip length byte of data to look at the next.
If the length read is not a multiple of 4: Error, invalid tag.For this series we need the container tags:
-FDT_INFO_PROPERTYfor information related to a property Among known tags defined in this series, onlyFDT_REF_LOCALandFDT_REF_PHANDLEcan be grouped into aFDT_INFO_PROPERTY.-
FDT_INFO_NODEfor information related to a node
Among known tags defined in this series, onlyFDT_EXPORT_SYM_LOCALandFDT_EXPORT_SYM_REFcan be grouped into aFDT_INFO_NODE.-
FDT_INFO_DTBfor information related to the dtb
Among known tags defined in this series, onlyFDT_IMPORT_SYMcan be present into aFDT_INFO_DTB.Quoted 8 lines
Quoted 3 lines
IMHO, the new tag
FDT_BEGIN_NODE_REFrelated to orphan nodes doesn't have to be in one of those containers. Indeed,FDT_BEGIN_NODE_REFis more a node definition than a metadata.That's a perfect example of a new tag that absolutely cannot be just skipped if not understood. Software *must* hard error if they encounter this and don't understand it.
I have started to implement this "unknown tag" feature based on the tag values definition presented here and with complementary feature (bit allowing to skip an unknown tag) as presented in patch 2 discussion [1].
I didn't introduce any
FDT_INFO_xxxtags. They introduce nesting tags and David seems not agree with that.I use simple test tags to have some "unknown tags" in dtb and looked at the way to handle them.
When we read a dtb, no problem, we just skip "unknown tags" if we are allowed to (flag in tag value).
The issue comes when we modify a dtb.
Quoted 8 lines
libftd allows to modify a dtb. It allows to add/modify/remove properties and nodes. Bootloaders for instance use this capability to update a dtb before passing it to the kernel.
How should we handle unknown tags in this context?
We don't knwow about the meaning of those tags (unknown tags) and so, we don't know if those tags are still consistent with modifications done?
I don't think we have any choice, but to remove the tags.
Quoted 3 lines
A property can be followed by an unknown tags related to this property. Also a property can be followed by an unknown tag related to the node. We simply don't know.
We should be able to distinguish between node and property tags at least. Either by value or location. IOW, node tags must follow a BEGIN_NODE tag and property tags must follow a property.
Quoted 4 lines
Any modification can impact unknown tags and make them inconsistent. Here again, we simply don't know.
Should we avoid any modification when a dtb contains unknown tags?
You answered that below. :)
Quoted 1 line
Should we simply remove all unknown tags when a modification is done?
For that node or property, yes. For the whole DTB, no. Though does modifying a property constitute modifying a node?
Quoted 7 lines
Bootloaders need to modify the dtb. Avoiding modification is a no-go. Removing "unknown tags" when a modification is done will lead to removing all unknown tags at bootloader stage.
Rob, David, any opinion related to this specific issue and the strategy we should follow when modification are involved?
Perhaps we should separate the 'version we can read' and the 'version we can write'. Let's say it is v18 that allows unknown tags, but v19 that actually adds any specific tags (or adds tags that are not safe to ignore). Then a DTB with last_compat_version=v18 and version=v19 can be read by libfdt supporting v18+, but requires v19 libfdt to write it. We'd still have to allow writing a v19 DTB with v18 libfdt, but we'd have to downgrade the version to v18 (or downgrade if we had to drop some tags).
The DT and bootloader/firmware are typically bundled together and in that case there shouldn't be an issue of different versions. You can have a newer DTB instead of the firmware one, but that doesn't need to have the new tags (if the OS does require them, then it broke compatibility).
Even with this series, I think everything can be ignored if you are only looking for compatibility with what we have now. It's only if you want to support the addons, then you need v?? which defines the set of tags for addons. So I'm not certain a tag bit is the right way to say safe to ignore or not. I think if we have a new tag that every client has to understand and handle, then that's a major version change. I think the original intent with the versions was 0x10 (aka 16) was a new major version, 0x13(v18) would be another minor rev, and 0x20 would be the next major version.
Rob
Quoted 150 lines · Rob Herring
Quoted 149 lines · Herve Codina
Hi Rob, David,
On Mon, 19 Jan 2026 17:00:44 +1100
David Gibson <[email protected]> wrote:...
Quoted 141 lines
Quoted 5 lines
I think we can have metadata at 3 differents levels:
- Property
- Node
- Global dtbThis is a really minor point, but I don't especially like the term "metadata" for the symbol / fixup information. Although it's technically accurate that it's metadata for the property bytestrings, in most contexts "metadata" makes me think only of tree global metadata. By analogy, symbols and fixup information in a .so or .a could be seen as metadata to the raw code / data bytes, but I wouldn't normally use that term for it (whereas I might for, say, the soname or certain .note sections).
Quoted 36 lines
With the suggestion you did on patch 6 related to
FDT_REF_LOCALand if I understood correctly, you expect to have a kind of "container" tag to group metadata on each level.Also you expect to have the ability to handle all 'for now unknown' tag smoothly and so, I agree, the length of the data related to a tag are needed to be present with the tag itself. I see to kind of tag, some with the length of data available in the u32 following the tag and other without the length encoded.
Tags without length encoded are followed by one u32 field containing data related to the tag. This allow to avoid a lot of '
TAG_XXX0x04u32_data' Indeed, I have the feeling that quite a lot of tags will have only one u32 field as data part and so, having0x04encoded (cell aligned) each time.A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this categorie
- 1: New kind of tag adopting this definition- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a
multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.Quoted 2 lines
- bit 27..0
tag specific identifierAs noted elsewhere, I'm not necessarily opposed to having a general length encoding. However, for each new tag I think we need to think carefully about whether it really is safe for older software that doesn't understand it to just skip it.
Quoted 6 lines
With that definition, the following tags can be defined:
-FDT_INFO_PROPERTY(new tag, length encoding):0xf0000001This tag is available after a property.
It is followed by a cell for the length of data, the data part is a sequence of tags (and related data) giving information related to the last property available before the tag.I'd prefer to avoid an additional layer of nesting here - I'd rather just have multiple top level tags.
Quoted 60 lines
-
FDT_REF_LOCAL(new tag, 1 cell data):0x90000002:
The cell after this tag is the offset in the property where a local phandle is available-
FDT_REF_PHANDLE(new tag, length encoding):0xf0000003Cf. patch 11 for definition
It is followed by a cell for the length of data. The data part is composed of:
- offset (u32)
- label (string including \0)
- padding if needed to have next item aligned on 32bitsWith that defined, supposing the following dts example:
--- 8< ---
/* 'foo' is a reference to local node,
* 'bar' is a reference to an external node */
prop = <1 2 &foo &bar1>;
--- 8< ---The dtb will see the following structure:
FDT_PROP...FDT_INFO_PROPERTY(0xf0000001)
28 (length = (4+4)+(4+4+12) bytes)
FDT_REF_LOCAL(0x90000002)0x8 <--- offset of &foo FDT_REF_PHANDLE (0xf0000003) 12 (length = 4+4+1+3 bytes) 0xc <--- offset of &bar "bar1" + its \0 <-- reference to resolve 0x00 0x00 0x00 <-- 3 bytes paddingAdding
FDT_TYPE_U32later will consist in defining its value, probably a0x9family (1 cell after the tag for the offset value)At any point, only looking at the higher part of the tag (i.e. 0xN.......), we can skip the tag and its data if don't know about the tag.
-0x0: Old tag format-> Error if unknown-
0x8to0xe: New format followed by 0 (0x8) to 6 cells of data-> Ignore if unknown and skip the N cells of data to look at the next-
0xf: New format followed by 1 cell giving the size of following data. -> Ignore if unknown and read the length available in the cell after the tag, skip length byte of data to look at the next.
If the length read is not a multiple of 4: Error, invalid tag.For this series we need the container tags:
-FDT_INFO_PROPERTYfor information related to a property Among known tags defined in this series, onlyFDT_REF_LOCALandFDT_REF_PHANDLEcan be grouped into aFDT_INFO_PROPERTY.-
FDT_INFO_NODEfor information related to a node
Among known tags defined in this series, onlyFDT_EXPORT_SYM_LOCALandFDT_EXPORT_SYM_REFcan be grouped into aFDT_INFO_NODE.Quoted 7 lines
-
FDT_INFO_DTBfor information related to the dtb
Among known tags defined in this series, onlyFDT_IMPORT_SYMcan be present into aFDT_INFO_DTB.IMHO, the new tag
FDT_BEGIN_NODE_REFrelated to orphan nodes doesn't have to be in one of those containers. Indeed,FDT_BEGIN_NODE_REFis more a node definition than a metadata.That's a perfect example of a new tag that absolutely cannot be just skipped if not understood. Software *must* hard error if they encounter this and don't understand it.
Quoted 6 lines
Quoted 6 lines
I have started to implement this "unknown tag" feature based on the tag values definition presented here and with complementary feature (bit allowing to skip an unknown tag) as presented in patch 2 discussion [1].
I didn't introduce any
FDT_INFO_xxxtags. They introduce nesting tags and David seems not agree with that.
Right. I don't see that they provide any advantage, so it's just extra complexity. I'm open to persuasion if it turns out there's a concrete reason for it.
Quoted 12 lines
Quoted 12 lines
I use simple test tags to have some "unknown tags" in dtb and looked at the way to handle them.
When we read a dtb, no problem, we just skip "unknown tags" if we are allowed to (flag in tag value).
The issue comes when we modify a dtb.
libftd allows to modify a dtb. It allows to add/modify/remove properties and nodes. Bootloaders for instance use this capability to update a dtb before passing it to the kernel.
Quoted 6 lines
Quoted 4 lines
How should we handle unknown tags in this context?
We don't knwow about the meaning of those tags (unknown tags) and so, we don't know if those tags are still consistent with modifications done?
I don't think we have any choice, but to remove the tags.
Agreed.
Quoted 7 lines
Quoted 3 lines
A property can be followed by an unknown tags related to this property. Also a property can be followed by an unknown tag related to the node. We simply don't know.
We should be able to distinguish between node and property tags at least. Either by value or location. IOW, node tags must follow a
BEGIN_NODEtag and property tags must follow a property.
This seems reasonable to me. The fact that these properties are considered tied to a specific node or property should be stated explicitly in the general description of "ignorable" tags, though. As Herve pointed out, we still have the option of adding more "old style" tags if we need something that doesn't fit the new constraints.
Quoted 29 lines
Quoted 4 lines
Any modification can impact unknown tags and make them inconsistent. Here again, we simply don't know.
Should we avoid any modification when a dtb contains unknown tags?
You answered that below. :)
Quoted 1 line
Should we simply remove all unknown tags when a modification is done?
For that node or property, yes. For the whole DTB, no. Though does modifying a property constitute modifying a node?
Quoted 7 lines
Bootloaders need to modify the dtb. Avoiding modification is a no-go. Removing "unknown tags" when a modification is done will lead to removing all unknown tags at bootloader stage.
Rob, David, any opinion related to this specific issue and the strategy we should follow when modification are involved?
Perhaps we should separate the 'version we can read' and the 'version we can write'. Let's say it is v18 that allows unknown tags, but v19 that actually adds any specific tags (or adds tags that are not safe to ignore). Then a DTB with last_compat_version=v18 and version=v19 can be read by libfdt supporting v18+, but requires v19 libfdt to write it. We'd still have to allow writing a v19 DTB with v18 libfdt, but we'd have to downgrade the version to v18 (or downgrade if we had to drop some tags).
Quoted 8 lines
The DT and bootloader/firmware are typically bundled together and in that case there shouldn't be an issue of different versions. You can have a newer DTB instead of the firmware one, but that doesn't need to have the new tags (if the OS does require them, then it broke compatibility).
Even with this series, I think everything can be ignored if you are only looking for compatibility with what we have now.
Not if you rely on reading phandle values.
Quoted 8 lines
It's only if you
want to support the addons, then you need v?? which defines the set of tags for addons. So I'm not certain a tag bit is the right way to say safe to ignore or not. I think if we have a new tag that every client has to understand and handle, then that's a major version change. I think the original intent with the versions was0x10(aka 16) was a new major version, 0x13(v18) would be another minor rev, and0x20would be the next major version.
I don't think it was thought out in that much detail at the time, but that seems a reasonable approach to me.
Signature · 4 lines
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
Quoted 2 lines · Herve Codina
This big picture series adds support for dtb metadata and addon device-trees.
Oof. So, I lobbied for (at least aspects of) this approach, I think it's a better idea than more ad-hoc extensions to overlays.
Now I'm reaping what I sowed: reviewing 77 patches for dtc/libfdt is going to be a real challenge - I've been struggling to find time to review a 6 patch series for months. Well, I guess we'll see what we can do.
Signature · 4 lines
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
Quoted 11 lines · David Gibson
Quoted 2 lines · Herve Codina
This big picture series adds support for dtb metadata and addon device-trees.
Oof. So, I lobbied for (at least aspects of) this approach, I think it's a better idea than more ad-hoc extensions to overlays.
Now I'm reaping what I sowed: reviewing 77 patches for dtc/libfdt is going to be a real challenge - I've been struggling to find time to review a 6 patch series for months. Well, I guess we'll see what we can do.
Jsyk
In line with the above, the review I've done so far is, deliberately, a shallow, first-pass approach. I'm looking primarily at the commit messages rather than code, and I'm focussing on generalities and reviewability, rather than details.
Signature · 4 lines
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