Add support for dtb metadata and addon device-trees
Subsystems (2)
RFC PATCH v2 49/74 dtc: Rename add_orphan_node() to plugin_add_orphan_node()
In reply to Herve Codinaadd_orphan_node() is used when a orphan node is parsed in a plugin (overlay) device-tree.
This function creates some device-tree nodes (/fragment@n/__overlay__) in order to merge the parsed orphan node.
This is specific to plugin device-trees and cannot be used for addon device-trees.
In order to clarify that add_orphan_node() is specific to plugin device-trees and to prepare the support for orphan node parsing in the addon context, rename current add_orphan_node() to plugin_add_orphan_node().
--- dtc-parser.y | 6 +++--- dtc.h | 3 ++- livetree.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-)
dtc-parser.y +3 -3
@@ -245,7 +245,7 @@ devicetree: ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ = add_orphan_node( + $$ = plugin_add_orphan_node( name_node(build_node(NULL, NULL, NULL, NULL), ""), $2, $1);
@@ -269,7 +269,7 @@ devicetree: if (last_header_flags & DTSF_PLUGIN) { if (is_ref_relative($2)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); - add_orphan_node($1, $3, $2); + plugin_add_orphan_node($1, $3, $2); } else { struct node *target = parser_get_node_by_ref($1, $2);
@@ -288,7 +288,7 @@ devicetree: merge_nodes(target, $3); } else { if (last_header_flags & DTSF_PLUGIN) - add_orphan_node($1, $3, $2); + plugin_add_orphan_node($1, $3, $2); else ERROR(&@2, "Label or path %s not found", $2); }
dtc.h +2 -1
@@ -307,7 +307,8 @@ struct node *omit_node_if_unused(struct node *node);struct node *reference_node (struct node *node);struct node *chain_node (struct node *first,struct node *list);struct node *merge_nodes (struct node *old_node,struct node *new_node); -struct node *add_orphan_node (struct node *old_node,struct node *new_node,char *ref); +struct node *plugin_add_orphan_node (struct node *old_node,struct node *new_node, +char *ref);void add_property (struct node *node,struct property *prop);void delete_property_by_name (struct node *node,char *name);
livetree.c +2 -1
@@ -319,7 +319,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)return old_node; } -struct node *add_orphan_node (struct node *dt,struct node *new_node,char *ref) +struct node *plugin_add_orphan_node (struct node *dt,struct node *new_node, +char *ref) {static unsigned int next_orphan_fragment =0 ;struct node *node;
Signature · 1 line
2.55.0
RFC PATCH v2 50/74 dtc: Add basic support for addon orphan nodes in dts
In reply to Herve CodinaOrphan nodes are nodes without a parent. The root device-tree node is a particular orphan node and is not part of those 'orphan' nodes group.
The orphan nodes group is related to nodes identified by a reference in addons or plugins device-trees. For instance, int the following snippet, foo is an orphan node:
--- 8< ---
/addon/
&foo {
subnode {
prop = <1>;
};
};
--- 8< ---The foo referenced node described has no parent. Indeed, it is not a child of the root node.
This kind of node is legit in addons device-tree in order to perform modification on existing node when the addon dtb is applied.
Add support for addon orphan node in dts.
Compared to plugin (overlay) orphan node parsing, the orphan node parsed in the addon context does not lead to any change in the device-tree structure. '/fragment@0/__overlay__' or similar kind of structure is not needed for addons.
--- dtc-parser.y | 60 +++++++++++++++++++++++++++++++++++----------------- dtc.h | 2 ++ livetree.c | 30 ++++++++++++++++++++++++++ treesource.c | 8 +++++++ 4 files changed, 81 insertions(+), 19 deletions(-)
dtc-parser.y +41 -19
@@ -23,6 +23,7 @@ extern void yyerror(char const *s); extern struct dt_info *parser_output; extern bool treesource_error; +extern struct node *parser_orphanlist; unsigned int last_header_flags;
@@ -31,7 +32,8 @@ static bool is_ref_relative(const char *ref) return ref[0] != '/' && strchr(&ref[1], '/'); } -static struct node *parser_get_node_by_ref(struct node *dt, const char *ref) +static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanlist, + const char *ref) { /* * Use a temporary dt_info in order to use dti_get_node_by_ref()
@@ -39,6 +41,7 @@ static struct node *parser_get_node_by_ref(struct node *dt, const char *ref) struct dt_info dti = {}; dti.dt = dt; + dti.orphanlist = orphanlist; return get_node_by_ref(&dti, ref); }
@@ -132,7 +135,7 @@ sourcefile: { parser_output = build_dt_info($1, $2, $3, guess_boot_cpuid($3), - NULL, NULL); + NULL, parser_orphanlist); } | headers memreserves importlist devicetree {
@@ -143,7 +146,8 @@ sourcefile: */ parser_output = build_dt_info($1, $2, $4, $4 ? guess_boot_cpuid($4) : 0, - reverse_symbol($3), NULL); + reverse_symbol($3), + parser_orphanlist); } ;
@@ -241,21 +245,28 @@ devicetree: } | dt_ref nodedef { - if (!(last_header_flags & DTSF_PLUGIN)) + if (!(last_header_flags & (DTSF_PLUGIN | DTSF_ADDON))) ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ = plugin_add_orphan_node( - name_node(build_node(NULL, NULL, NULL, NULL), - ""), - $2, $1); + ERROR(&@2, "Label-relative reference %s not supported in plugin nor addon", $1); + + if (last_header_flags & DTSF_PLUGIN) { + $$ = plugin_add_orphan_node( + name_node(build_node(NULL, NULL, NULL, NULL), + ""), + $2, $1); + } else { + ERROR(&@2, "Orphan node %s without a root node not yet supported", $1); + YYERROR; + } } | devicetree DT_LABEL dt_ref nodedef { - struct node *target = parser_get_node_by_ref($1, $3); + struct node *target = parser_get_node_by_ref( + $1, parser_orphanlist, $3); - if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); + if ((last_header_flags & (DTSF_PLUGIN | DTSF_ADDON)) && is_ref_relative($3)) + ERROR(&@2, "Label-relative reference %s not supported in plugin nor addon", $3); if (target) { add_label(&target->labels, $2);
@@ -266,12 +277,17 @@ devicetree: } | devicetree DT_PATH_REF nodedef { - if (last_header_flags & DTSF_PLUGIN) { + if (last_header_flags & (DTSF_PLUGIN | DTSF_ADDON)) { if (is_ref_relative($2)) - ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); - plugin_add_orphan_node($1, $3, $2); + ERROR(&@2, "Label-relative reference %s not supported in plugin nor addon", $2); + if(last_header_flags & DTSF_PLUGIN) + plugin_add_orphan_node($1, $3, $2); + else + addon_add_orphan_node(&parser_orphanlist, + orphan_node($3, $2)); } else { - struct node *target = parser_get_node_by_ref($1, $2); + struct node *target = parser_get_node_by_ref( + $1, parser_orphanlist, $2); if (target) merge_nodes(target, $3);
@@ -282,13 +298,17 @@ devicetree: } | devicetree DT_LABEL_REF nodedef { - struct node *target = parser_get_node_by_ref($1, $2); + struct node *target = parser_get_node_by_ref( + $1, parser_orphanlist, $2); if (target) { merge_nodes(target, $3); } else { if (last_header_flags & DTSF_PLUGIN) plugin_add_orphan_node($1, $3, $2); + else if (last_header_flags & DTSF_ADDON) + addon_add_orphan_node(&parser_orphanlist, + orphan_node($3, $2)); else ERROR(&@2, "Label or path %s not found", $2); }
@@ -296,7 +316,8 @@ devicetree: } | devicetree DT_DEL_NODE dt_ref ';' { - struct node *target = parser_get_node_by_ref($1, $3); + struct node *target = parser_get_node_by_ref( + $1, parser_orphanlist, $3); if (target) delete_node(target);
@@ -308,7 +329,8 @@ devicetree: } | devicetree DT_OMIT_NO_REF dt_ref ';' { - struct node *target = parser_get_node_by_ref($1, $3); + struct node *target = parser_get_node_by_ref( + $1, parser_orphanlist, $3); if (target) omit_node_if_unused(target);
dtc.h +2 -0
@@ -309,6 +309,8 @@ struct node *chain_node(struct node *first, struct node *list);struct node *merge_nodes (struct node *old_node,struct node *new_node);struct node *plugin_add_orphan_node (struct node *old_node,struct node *new_node,char *ref); +struct node *orphan_node (struct node *node,const char *ref); +void addon_add_orphan_node (struct node **dt_orphan,struct node *new_orphan);void add_property (struct node *node,struct property *prop);void delete_property_by_name (struct node *node,char *name);
livetree.c +30 -0
@@ -351,6 +351,36 @@ struct node *plugin_add_orphan_node(struct node *dt, struct node *new_node,return dt; } +struct node *orphan_node (struct node *node,const char *ref) +{ + node->ref =xstrdup (ref); + +return node; +} + +void addon_add_orphan_node (struct node **dt_orphan,struct node *new_orphan) +{ +struct node **last_orphan; +char *name; + +/* +* For addon orphan node, the node name is set to '&reference' +* This ease the dts file generation and the usage of existing code +*/ +xasprintf (&name,"&%s" , new_orphan->ref); + +name_node (new_orphan, name); +free (name); + + new_orphan->next_sibling =NULL ; + + last_orphan = dt_orphan; +while (*last_orphan) + last_orphan = &((*last_orphan)->next_sibling); + + *last_orphan = new_orphan; +} +struct node *chain_node (struct node *first,struct node *list) {assert (first->next_sibling ==NULL );
treesource.c +8 -0
@@ -12,11 +12,13 @@ extern YYLTYPE yylloc;struct dt_info *parser_output;bool treesource_error; +struct node *parser_orphanlist;struct dt_info *dt_from_source (const char *fname) { parser_output =NULL ; treesource_error = false; + parser_orphanlist =NULL ;srcfile_push (fname); yyin = current_srcfile->f;
@@ -432,6 +434,7 @@ void dt_to_source(FILE *f, struct dt_info *dti) {struct reserve_info *re;struct symbol *importsym; +struct node *orphan;fprintf (f,"/dts-v1/;\n" );/*
@@ -464,4 +467,9 @@ void dt_to_source(FILE *f, struct dt_info *dti) }write_tree_source_node (f, dti->dt,0 ); + +for_each_orphan (dti->orphanlist, orphan) { +fprintf (f,"\n" ); +write_tree_source_node (f, orphan,0 ); + } }
Signature · 1 line
2.55.0
RFC PATCH v2 51/74 Add support for FDT_BEGIN_NODE_REF dtb tag
In reply to Herve CodinaThe FDT_BEGIN_NODE_REF dtb tag is a tag defining a referenced node.
This kind of nodes can be present in addon dtbs and identifies a node external to the addon dtb but modified by the addon.
For instance, if an addon adds a sub-node to a node existing in the device-tree the addon is applied to, the existing node needs to be referenced by the addon dtb. This is the purpose of FDT_BEGIN_NODE_REF.
This tag typically identifies what we call orphan nodes in dts.
The structure of FDT_BEGIN_NODE_REF is identical to the structure of FDT_BEGIN_NODE except that the node name is not present and it is replaced by the node symbol reference needed to reference the node in the base device-tree when the addon device-tree blob is applied.
The FDT_BEGIN_NODE_REF block is terminated by a FDT_END_NODE tag.
The FDT_BEGIN_NODE_REF tag is followed by the length of the data part (structured tag), the node symbol name, a possible alignment padding and then the node structure. The FDT_BEGIN_NODE_REF block is terminated by a FDT_END_NODE tag:
- data part length (32bit): strlen(node symbol name) + 1
- node symbol name (string including \0)
The symbol name used to reference the node in the base device-tree when the addon is applied.
- padding:
Padding (0x00) added to have the next value aligned on 32bit.
- Node structure (see FDT_BEGIN_NODE):
Items provided by the addon to be merged in the referenced node when the addon is applied.
- FDT_END_NODE tag
Example:
FDT_BEGIN_NODE_REF 5 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE
This means that the external node referenced by 'foo1' is modified by the addon. Items to merge when the addon is applied are represented by the '...' part.
This is what is encoded in the dtb when the related dts has the
following orphan node:
&foo1 {
...
};If several external nodes are modified by the addon (several orphan nodes described in the addon), several FDT_BEGIN_NODE_REF are present. Each of them related to an external node. For instance, having 'foo1' and 'bar10' as external nodes leads to the following sequence:
FDT_BEGIN_NODE_REF 5 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE FDT_BEGIN_NODE_REF 6 'bar10' 0x00 0x00 ... FDT_END_NODE
The FDT_BEGIN_NODE_REF can be present only for a top level node. Subnodes are identified by a FDT_BEGIN_NODE tag.
If FDT_BEGIN_NODE_REF tags are present in the dtb, they are present after the root node definition (i.e. after the first FDT_BEGIN_NODE / FDT_END_NODE block).
Add support for this new dtb tag.
--- fdtdump.c | 12 +++++ flattree.c | 114 ++++++++++++++++++++++++++++++++------- libfdt/fdt.c | 95 +++++++++++++++++++++++++++++++- libfdt/fdt.h | 18 +++++++ libfdt/fdt_check.c | 47 +++++++++++++++- libfdt/fdt_ro.c | 46 +++++++++++++++- libfdt/libfdt_internal.h | 10 ++++ 7 files changed, 317 insertions(+), 25 deletions(-)
fdtdump.c +12 -0
@@ -206,6 +206,18 @@ static void dump_blob(void *blob, bool debug, int dump_unknown)continue ; } +if (tag ==FDT_BEGIN_NODE_REF ) { + last_prop_name =NULL ; + + p =get_structured_tag_data (tag, p, &d, &sz); + s = d; + +printf ("%*s&%s {\n" , depth * shift,"" , s); + + depth++; +continue ; + } +if (tag ==FDT_EXPORT_SYM ) { p =get_structured_tag_data (tag, p, &d, &sz); val32 =fdt32_to_cpu (GET_CELL (d));
flattree.c +94 -20
239 lines not on this page · raw message
libfdt/fdt.c +94 -1
141 lines not on this page · raw message
libfdt/fdt.h +18 -0
@@ -154,6 +154,24 @@ struct fdt_property {*/ #define FDT_IMPORT_SYM FDT_TAG_CAN_SKIP(FDT_TAG_DATA_VARLEN, 0x2100) +/* +* Node reference tag. varlen: node symbol name +* +* It defines a node external to the dtb but modified by the dtb. It can be +* present in an addon dtb. +* +* For instance, if an addon adds a sub-node to a node existing in the +* device-tree the addon is applied to, the existing node needs to be +* referenced by the addon dtb. This is the purpose of FDT_BEGIN_NODE_REF. +* +* node symbol name: The symbol name used to reference the node in the base +* device-tree when the addon is applied. +* +* Following the tag and its related node symbol name, the node structure is +* present. After the node structure, the FTD_END_NODE tag is present. +*/ +#define FDT_BEGIN_NODE_REF FDT_TAG_NO_SKIP(FDT_TAG_DATA_VARLEN, 0x2200) +#define FDT_V1_SIZE (7*sizeof(fdt32_t))#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
libfdt/fdt_check.c +45 -2
83 lines not on this page · raw message
libfdt/fdt_ro.c +44 -2
76 lines not on this page · raw message
libfdt/libfdt_internal.h +10 -0
@@ -61,6 +61,16 @@ static inline const char *fdt_find_string_(const char *strtab, int tabsize,int fdt_node_end_offset_ (void *fdt,int nodeoffset); +int fdt_check_orphan_offset (const void *fdt,int offset,int *data_offset); +int fdt_next_orphan_offset (const void *fdt,int offset); + +#define fdt_for_each_orphan (orphan, fdt) \ + for (orphan = fdt_next_orphan_offset(fdt, 0); \ + orphan >= 0; \ + orphan = fdt_next_orphan_offset(fdt, orphan)) + +int fdta_node_offset_by_phandle (const void *fdta,uint32_t phandle); +static inline const void *fdt_offset_ptr_ (const void *fdt,int offset) {return (const char *)fdt +fdt_off_dt_struct (fdt) + offset;
Signature · 1 line
2.55.0
RFC PATCH v2 52/74 tests: metadata: Add basic test for addon orphan nodes
In reply to Herve CodinaAdd tests related to addon orphan nodes (FDT_BEGIN_NODE_REF dtb tag).
--- tests/metadata_addon_orphan1.dtb.dts.expect | 16 ++++++++++++++++ tests/metadata_addon_orphan1.dtb.expect | 13 +++++++++++++ tests/metadata_addon_orphan1.dts | 19 +++++++++++++++++++ tests/metadata_addon_orphan1.dts.dts.expect | 16 ++++++++++++++++ tests/run_tests.sh | 3 ++- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/metadata_addon_orphan1.dtb.dts.expect create mode 100644 tests/metadata_addon_orphan1.dtb.expect create mode 100644 tests/metadata_addon_orphan1.dts create mode 100644 tests/metadata_addon_orphan1.dts.dts.expect
tests/metadata_addon_orphan1.dtb.dts.expect new file +16 -0
@@ -0,0 +1,16 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop = <0x01>; + }; +}; + +&base { + + addon-node { + prop = <0x02>; + }; +};
tests/metadata_addon_orphan1.dtb.expect new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; +/addon/; + +/ { + node-a { + prop = <0x00000001>; + }; +}; +&base { + addon-node { + prop = <0x00000002>; + }; +};
tests/metadata_addon_orphan1.dts new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/ { + node-a { + prop = <1>; + }; +}; + +&base { + addon-node { + prop = <2>; + }; +};
tests/metadata_addon_orphan1.dts.dts.expect new file +16 -0
@@ -0,0 +1,16 @@ +/dts-v1/; +/addon/; + +/ { + + node-a { + prop = <0x01>; + }; +}; + +&base { + + addon-node { + prop = <0x02>; + }; +};
tests/run_tests.sh +2 -1
@@ -1250,7 +1250,8 @@ fdtoverlay_tests() { metadata_tests() { for dt in metadata_propdata_phandle_local metadata_propdata_phandle_ref \ metadata_addon_base metadata_exportsyms_local \ - metadata_exportsyms_ref metadata_importsyms; do + metadata_exportsyms_ref metadata_importsyms \ + metadata_addon_orphan1; 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.55.0
RFC PATCH v2 53/74 dtc: Add support for missing root node in addon device-tree
In reply to Herve CodinaAddon can have orphan nodes fully described (dts) and encoded (dtb) without the need for a root device tree.
Contrary to plugin (overlay), addon doesn't need any specific root tree structure to described the orphans. Indeed, /fragment@n/__overlay__ doesn't exist for addons. Orphans are encoded in dtb using the FDT_BEGIN_NODE_REF tag without any impact on the root tree.
The following snippet is fully legit for addon:
--- 8< ---
/addon/;
&foo {
subnode {
prop = <1>;
};
}
--- 8< ---This snippet doesn't contains a root device tree, and the related dtb doesn't need any root device tree to encode the snippet.
The root device is no more mandatory for addon.
Add support for addon without a root device-tree.
--- checks.c | 29 +++++++++++++++++++++++++++-- dtc-parser.y | 18 ++++++++++++++---- dtc.c | 21 ++++++++++++++++----- flattree.c | 43 ++++++++++++++++++++++++++++++------------- livetree.c | 13 +++++++++++-- treesource.c | 3 ++- 6 files changed, 100 insertions(+), 27 deletions(-)
checks.c +27 -2
@@ -154,7 +154,6 @@ static bool is_multiple_of(int multiple, int divisor)static bool run_check (struct check *c,struct dt_info *dti) { -struct node *dt = dti->dt;struct node *orphan;bool error = false;int i;
@@ -179,7 +178,8 @@ static bool run_check(struct check *c, struct dt_info *dti)if (c->status !=UNCHECKED ) goto out; -check_nodes_props (c, dti, dt); +if (dti->dt) +check_nodes_props (c, dti, dti->dt);for_each_orphan (dti->orphanlist, orphan)check_nodes_props (c, dti, orphan);
@@ -2105,6 +2105,31 @@ void process_checks(bool force, struct dt_info *dti)exit (2 ); } +if (!dti->dt) { +/* No root node is only allowed for addons */ +if (dti->dtsflags &DTSF_ADDON ) { +if (!dti->orphanlist) { +/* +* but addons without a root node and without +* orphan nodes is really incorrect +*/ +fprintf (stderr, +"ERROR: Input tree has no root or orphan nodes, aborting\n" ); +exit (2 ); + } + }else { +fprintf (stderr,"ERROR: Input tree has no root node, aborting\n" ); +exit (2 ); + } + } + +if (!(dti->dtsflags &DTSF_ADDON )) { +if (dti->orphanlist) { +fprintf (stderr,"ERROR: Input tree has orphan nodes, aborting\n" ); +exit (2 ); + } + } +for (i =0 ; i <ARRAY_SIZE (check_table); i++) {struct check *c = check_table[i];
dtc-parser.y +14 -4
@@ -133,12 +133,18 @@ static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanl sourcefile: headers memreserves devicetree { + if (!($1 & DTSF_ADDON) && !$3) + ERROR(&@3, "Only addon support missing root node"); + parser_output = build_dt_info($1, $2, $3, - guess_boot_cpuid($3), + $3 ? guess_boot_cpuid($3) : 0, NULL, parser_orphanlist); } | headers memreserves importlist devicetree { + if (!($1 & DTSF_ADDON) && !$4) + ERROR(&@4, "Only addon support missing root node"); + /* * importlist is created with chain_symbol() and so it * is created in reverse order. Reverse it now to have
@@ -241,7 +247,10 @@ devicetree: } | devicetree '/' nodedef { - $$ = merge_nodes($1, $3); + if ($1) + $$ = merge_nodes($1, $3); + else + $$ = name_node($3, ""); } | dt_ref nodedef {
@@ -256,8 +265,9 @@ devicetree: ""), $2, $1); } else { - ERROR(&@2, "Orphan node %s without a root node not yet supported", $1); - YYERROR; + addon_add_orphan_node(&parser_orphanlist, + orphan_node($2, $1)); + $$ = NULL; } } | devicetree DT_LABEL dt_ref nodedef
dtc.c +16 -5
@@ -316,18 +316,29 @@ int main(int argc, char *argv[])process_checks (force, dti); -if (auto_label_aliases) +if (auto_label_aliases) { +if (!dti->dt) +die ("auto-alias not supported without a root node\n" );generate_label_tree (dti,"aliases" , false); + } -generate_labels_from_tree (dti,"__symbols__" ); +if (dti->dt) +generate_labels_from_tree (dti,"__symbols__" ); -if (generate_symbols) +if (generate_symbols) { +if (!dti->dt) +die ("generation of symbols not supported without a root node\n" );generate_label_tree (dti,"__symbols__" , true); + } -fixup_phandles (dti,"__fixups__" ); -local_fixup_phandles (dti,"__local_fixups__" ); +if (dti->dt) { +fixup_phandles (dti,"__fixups__" ); +local_fixup_phandles (dti,"__local_fixups__" ); + }if (generate_fixups) { +if (!dti->dt) +die ("generation of fixups not supported without a root node\n" );generate_fixups_tree (dti,"__fixups__" );generate_local_fixups_tree (dti,"__local_fixups__" ); }
flattree.c +30 -13
82 lines not on this page · raw message
livetree.c +11 -2
@@ -692,7 +692,8 @@ static void complete_references(struct dt_info *dti) {struct node *orphan; -complete_references_internal (dti, dti->dt); +if (dti->dt) +complete_references_internal (dti, dti->dt);for_each_orphan (dti->orphanlist, orphan)complete_references_internal (dti, orphan);
@@ -1336,7 +1337,9 @@ void sort_tree(struct dt_info *dti) {sort_reserve_entries (dti);sort_importsyms (dti); -sort_node (dti->dt); + +if (dti->dt) +sort_node (dti->dt); }/* utility helper to avoid code duplication */
@@ -1605,6 +1608,8 @@ void generate_labels_from_tree(struct dt_info *dti, const char *name)void generate_label_tree (struct dt_info *dti,const char *name,bool allocph) { +assert (dti->dt); +if (!any_label_tree (dti, dti->dt))return ; generate_label_tree_internal(dti, build_root_node(dti->dt, name),
@@ -1613,6 +1618,8 @@ void generate_label_tree(struct dt_info *dti, const char *name, bool allocph)void generate_fixups_tree (struct dt_info *dti,const char *name) { +assert (dti->dt); +if (!any_fixup_tree (dti, dti->dt))return ;if (generate_fixups_tree_internal (dti,build_root_node (dti->dt, name), dti->dt))
@@ -1719,6 +1726,8 @@ void fixup_phandles(struct dt_info *dti, const char *name)void generate_local_fixups_tree (struct dt_info *dti,const char *name) { +assert (dti->dt); +if (!any_local_fixup_tree (dti, dti->dt))return ;if (generate_local_fixups_tree_internal (dti,build_root_node (dti->dt, name), dti->dt))
treesource.c +2 -1
@@ -466,7 +466,8 @@ void dt_to_source(FILE *f, struct dt_info *dti)fprintf (f,"\n" ); } -write_tree_source_node (f, dti->dt,0 ); +if (dti->dt) +write_tree_source_node (f, dti->dt,0 );for_each_orphan (dti->orphanlist, orphan) {fprintf (f,"\n" );
Signature · 1 line
2.55.0
RFC PATCH v2 54/74 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
@@ -1251,7 +1251,7 @@ metadata_tests() { for dt in metadata_propdata_phandle_local metadata_propdata_phandle_ref \ 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.55.0
RFC PATCH v2 55/74 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 get_node_by_ref(&dti, ref); + target = get_node_by_ref(&dti, ref); + if (target) + return target; + + /* + * No node were found by 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.55.0
RFC PATCH v2 56/74 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
@@ -1251,7 +1251,8 @@ metadata_tests() { for dt in metadata_propdata_phandle_local metadata_propdata_phandle_ref \ 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.55.0
RFC PATCH v2 57/74 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
@@ -1333,6 +1333,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);
@@ -1340,6 +1368,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.55.0
RFC PATCH v2 58/74 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.55.0
RFC PATCH v2 59/74 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_PROPDATA_PHANDLE.
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 the 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 a 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 ++++++++++++++++ livetree.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++----- treesource.c | 3 ++- 4 files changed, 85 insertions(+), 7 deletions(-)
dtc-lexer.l +7 -0
@@ -236,6 +236,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
livetree.c +57 -6
97 lines not on this page · raw message
treesource.c +2 -1
@@ -328,7 +328,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.55.0
RFC PATCH v2 60/74 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 | 47 +++++++++++++++++++ tests/metadata_addon_references.dtb.expect | 47 +++++++++++++++++++ tests/metadata_addon_references.dts | 43 +++++++++++++++++ .../metadata_addon_references.dts.dts.expect | 47 +++++++++++++++++++ tests/run_tests.sh | 2 +- 5 files changed, 185 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 +47 -0
@@ -0,0 +1,47 @@ +/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 = <0x03>; + }; +}; + +&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 { + + sub-node { + prop = <0x03>; + + sub-subnode { + prop = <0x04>; + phandle = <0x02>; + }; + }; +};
tests/metadata_addon_references.dtb.expect new file +47 -0
47 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 +47 -0
47 lines not on this page · raw message
tests/run_tests.sh +1 -1
@@ -1252,7 +1252,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.55.0
RFC PATCH v2 61/74 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
@@ -229,6 +229,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);
@@ -243,6 +249,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.55.0
RFC PATCH v2 62/74 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_PROPDATA_PHANDLE_REF] ref0[0], ref = foo.x.y + ref1 = <0x0000000a 0xffffffff 0x00000014>; + // [FDT_PROPDATA_PHANDLE_REF] ref1[4], ref = bar.other + ref2 = <0x00000001>; + // [FDT_PROPDATA_PHANDLE] ref2[0] + ref3 = <0x00000001>; + // [FDT_PROPDATA_PHANDLE] 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
@@ -1252,7 +1252,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.55.0
RFC PATCH v2 63/74 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
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 | 1741 ++++++++++++++++++++++++++++++++++++++ libfdt/fdt_rw.c | 69 ++ libfdt/libfdt.h | 32 + libfdt/libfdt_internal.h | 5 + libfdt/meson.build | 1 + libfdt/version.lds | 1 + 7 files changed, 1850 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 +1741 -0
1,741 lines not on this page · raw message
libfdt/fdt_rw.c +69 -0
75 lines not on this page · raw message
libfdt/libfdt.h +32 -0
@@ -2538,6 +2538,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 +5 -0
@@ -51,6 +51,11 @@ static inline int fdt_getprop_offset(const void *fdt, int nodeoffset,return fdt_getprop_offset_namelen (fdt, nodeoffset, name,strlen (name)); } +int fdt_mark_property_phandle_ (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); static inline const char *fdt_find_string_(const char *strtab, int tabsize,
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.55.0
RFC PATCH v2 64/74 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 ++ Makefile.utils | 6 ++ fdtaddon.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 2 +- 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 fdtaddon.c
Makefile +5 -0
@@ -164,6 +164,7 @@ BIN += fdtdump BIN += fdtget BIN += fdtput BIN += fdtoverlay +BIN += fdtaddon SCRIPTS = dtdiff
@@ -177,6 +178,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
@@ -260,6 +262,8 @@ fdtput: $(FDTPUT_OBJS) $(LIBFDT_dep) fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_dep) +fdtaddon: $(FDTADDON_OBJS) $(LIBFDT_dep) + tags: FORCE rm -f tags find . \( -name tests -type d -prune \) -o \
@@ -277,6 +281,7 @@ TESTS_BIN += fdtput TESTS_BIN += fdtget TESTS_BIN += fdtdump TESTS_BIN += fdtoverlay +TESTS_BIN += fdtaddon ifneq ($(MAKECMDGOALS),libfdt) include tests/Makefile.tests
Makefile.utils +6 -0
@@ -29,3 +29,9 @@ FDTOVERLAY_SRCS = \ util.c FDTOVERLAY_OBJS = $(FDTOVERLAY_SRCS:%.c=%.o) + +FDTADDON_SRCS = \ + fdtaddon.c \ + util.c + +FDTADDON_OBJS = $(FDTADDON_SRCS:%.c=%.o)
fdtaddon.c new file +197 -0
197 lines not on this page · raw message
meson.build +1 -1
@@ -108,7 +108,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.55.0
RFC PATCH v2 65/74 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 | 1 + tests/run_tests.sh | 47 ++++++++++++++++++- tests/testutils.sh | 1 + 11 files changed, 244 insertions(+), 1 deletion(-) 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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + }; + }; +};
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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + addon-node { + prop = <0x00000000>; + }; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + }; + }; +};
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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + 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 +1 -0
@@ -144,6 +144,7 @@ run_test_types = [ 'fdtdump', 'fdtoverlay', 'metadata', + 'fdtaddon', ] run_test_deps = [ dtc_tools, treegen_dtb, tests_exe,
tests/run_tests.sh +46 -1
65 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.55.0
RFC PATCH v2 66/74 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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + addon-node { + prop = <0x00000000>; + }; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + }; + }; +};
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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + 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
@@ -1303,7 +1303,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.55.0
RFC PATCH v2 67/74 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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + addon-node { + ref-other = <0x00000002 0x0000000a>; + // [FDT_PROPDATA_PHANDLE] ref-other[0] + prop = <0x00000000>; + }; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + }; + }; +};
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 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + addon-node { + ref-other = <0x00000002 0x0000000a>; + // [FDT_PROPDATA_PHANDLE] 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_PROPDATA_PHANDLE_REF] 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
@@ -1303,7 +1303,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.55.0
RFC PATCH v2 68/74 tests: fdtaddon: Add a basic test for addons with references by path to orphan nodes
In reply to Herve CodinaAddons can use references by path to reference by path to reference an orphan node or sub-nodes of an orphan node.
Those references are converted to either local or external references and have to be handled when the addon is applied.
Add a basic test for this feature.
--- tests/fdtaddon_basics4-merged1.dtb.dts.expect | 43 +++++++++++++++++++ tests/fdtaddon_basics4-merged1.dtb.expect | 37 ++++++++++++++++ tests/fdtaddon_basics4-merged2.dtb.dts.expect | 43 +++++++++++++++++++ tests/fdtaddon_basics4-merged2.dtb.expect | 37 ++++++++++++++++ tests/fdtaddon_basics4.dtba.expect | 22 ++++++++++ tests/fdtaddon_basics4.dtsa | 25 +++++++++++ tests/run_tests.sh | 3 +- 7 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 tests/fdtaddon_basics4-merged1.dtb.dts.expect create mode 100644 tests/fdtaddon_basics4-merged1.dtb.expect create mode 100644 tests/fdtaddon_basics4-merged2.dtb.dts.expect create mode 100644 tests/fdtaddon_basics4-merged2.dtb.expect create mode 100644 tests/fdtaddon_basics4.dtba.expect create mode 100644 tests/fdtaddon_basics4.dtsa
tests/fdtaddon_basics4-merged1.dtb.dts.expect new file +43 -0
@@ -0,0 +1,43 @@ +/dts-v1/; + +/ { + + base-node { + + sub-node { + prop = <0x00>; + phandle = <0x02>; + + sub-node { + phandle = <0x04>; + prop = <0x01>; + }; + }; + }; + + somewhere { + + node-a1 { + compatible = "abc,aaa"; + phandle = <0x01>; + + /export/ node_a: &{/somewhere/node-a1}; + /export/ other: &{/base-node/sub-node}; + + addon-node { + ref-other-subnode = <&{/base-node/sub-node/sub-node}>; + ref-other2 = <&{/base-node/sub-node}>; + ref-other1 = <&{/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_basics4-merged1.dtb.expect new file +37 -0
@@ -0,0 +1,37 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + sub-node { + phandle = <0x00000004>; + prop = <0x00000001>; + }; + }; + }; + somewhere { + node-a1 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + addon-node { + ref-other-subnode = <0x00000004>; + // [FDT_PROPDATA_PHANDLE] ref-other-subnode[0] + ref-other2 = <0x00000002>; + // [FDT_PROPDATA_PHANDLE] ref-other2[0] + ref-other1 = <0x00000002 0x0000000a>; + // [FDT_PROPDATA_PHANDLE] ref-other1[0] + prop = <0x00000000>; + }; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + }; + }; +};
tests/fdtaddon_basics4-merged2.dtb.dts.expect new file +43 -0
43 lines not on this page · raw message
tests/fdtaddon_basics4-merged2.dtb.expect new file +37 -0
@@ -0,0 +1,37 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000002>; + sub-node { + phandle = <0x00000004>; + prop = <0x00000001>; + }; + }; + }; + somewhere { + node-a1 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + // [FDT_EXPORT_SYM] 'node_a' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,aaa"; + phandle = <0x00000003>; + addon-node { + ref-other-subnode = <0x00000004>; + // [FDT_PROPDATA_PHANDLE] ref-other-subnode[0] + ref-other2 = <0x00000002>; + // [FDT_PROPDATA_PHANDLE] ref-other2[0] + ref-other1 = <0x00000002 0x0000000a>; + // [FDT_PROPDATA_PHANDLE] ref-other1[0] + prop = <0x00000000>; + }; + }; + }; +};
tests/fdtaddon_basics4.dtba.expect new file +22 -0
@@ -0,0 +1,22 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon-node { + prop = <0x00000000>; + ref-other1 = <0xffffffff 0x0000000a>; + // [FDT_PROPDATA_PHANDLE_REF] ref-other1[0], ref = other + ref-other2 = <0xffffffff>; + // [FDT_PROPDATA_PHANDLE_REF] ref-other2[0], ref = other + ref-other-subnode = <0x00000001>; + // [FDT_PROPDATA_PHANDLE] ref-other-subnode[0] + }; +}; +&other { + sub-node { + prop = <0x00000001>; + phandle = <0x00000001>; + }; +};
tests/fdtaddon_basics4.dtsa new file +25 -0
@@ -0,0 +1,25 @@ +// 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-other1 = <&other 10>; + ref-other2 = <&{$other}>; + ref-other-subnode = <&{$other/sub-node}>; + }; +}; + +&other { + sub-node { + prop = <1>; + }; +};
tests/run_tests.sh +2 -1
@@ -1303,7 +1303,8 @@ 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 fdtaddon_basics3; do + for dt in fdtaddon_basics1 fdtaddon_basics2 fdtaddon_basics3 \ + fdtaddon_basics4; do run_dtc_test -I dts -O dtb -o $dt.dtba "$SRCDIR/$dt.dtsa" check_dtb $dt.dtba
Signature · 1 line
2.55.0
RFC PATCH v2 69/74 tests: fdtaddon: Add a test for addons with properties identical to existing ones
In reply to Herve CodinaAn addon cannot modify or add a property in a existing node.
If an addon has a property with the exact same value as an existing one, applying the addon doesn't lead to a property modification.
Indeed, because both properties (the addon one and the existing one) are equal, the existing one is not modified.
Add a test for this feature.
--- ...n_addon_prop_existing_ok-merged.dtb.expect | 20 +++++++++++++++ ...dtaddon_addon_prop_existing_ok.dtba.expect | 17 +++++++++++++ tests/fdtaddon_addon_prop_existing_ok.dtsa | 25 +++++++++++++++++++ tests/fdtaddon_base_prop_existing.dtb.expect | 17 +++++++++++++ tests/fdtaddon_base_prop_existing.dts | 22 ++++++++++++++++ tests/run_tests.sh | 12 +++++++++ 6 files changed, 113 insertions(+) create mode 100644 tests/fdtaddon_addon_prop_existing_ok-merged.dtb.expect create mode 100644 tests/fdtaddon_addon_prop_existing_ok.dtba.expect create mode 100644 tests/fdtaddon_addon_prop_existing_ok.dtsa create mode 100644 tests/fdtaddon_base_prop_existing.dtb.expect create mode 100644 tests/fdtaddon_base_prop_existing.dts
tests/fdtaddon_addon_prop_existing_ok-merged.dtb.expect new file +20 -0
@@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + base-node { + // [FDT_EXPORT_SYM] 'base' -> phandle 0x00000001 + compatible = "abc,base"; + exist_bool; + exist_int = <0x0000007b>; + exist_string = "abcdef"; + phandle = <0x00000001>; + sub-node { + sub_exist_bool; + sub_exist_int = <0x000001c8>; + sub_exist_string = "ghi"; + addon-node { + prop; + }; + }; + }; +};
tests/fdtaddon_addon_prop_existing_ok.dtba.expect new file +17 -0
@@ -0,0 +1,17 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'base' (abc,base) +&base { + exist_bool; + exist_int = <0x0000007b>; + exist_string = "abcdef"; + sub-node { + sub_exist_bool; + sub_exist_int = <0x000001c8>; + sub_exist_string = "ghi"; + addon-node { + prop; + }; + }; +};
tests/fdtaddon_addon_prop_existing_ok.dtsa new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; +/addon/; + +/import/ base: "abc,base"; + +&base { + exist_bool; + exist_int = <123>; + exist_string = "abcdef"; + + sub-node { + sub_exist_bool; + sub_exist_int = <456>; + sub_exist_string = "ghi"; + + addon-node { + prop; + }; + }; +};
tests/fdtaddon_base_prop_existing.dtb.expect new file +17 -0
@@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + base-node { + // [FDT_EXPORT_SYM] 'base' -> phandle 0x00000001 + compatible = "abc,base"; + exist_bool; + exist_int = <0x0000007b>; + exist_string = "abcdef"; + phandle = <0x00000001>; + sub-node { + sub_exist_bool; + sub_exist_int = <0x000001c8>; + sub_exist_string = "ghi"; + }; + }; +};
tests/fdtaddon_base_prop_existing.dts new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + base_node: base-node { + compatible = "abc,base"; + exist_bool; + exist_int = <123>; + exist_string = "abcdef"; + /export/ base: &base_node; + + sub-node { + sub_exist_bool; + sub_exist_int = <456>; + sub_exist_string = "ghi"; + }; + }; +};
tests/run_tests.sh +12 -0
@@ -1322,6 +1322,18 @@ 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 addon with exact same properties as ones available in the base tree + run_dtc_test -I dts -O dtb -o fdtaddon_base_prop_existing.dtb "$SRCDIR/fdtaddon_base_prop_existing.dts" + check_dtb fdtaddon_base_prop_existing.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_addon_prop_existing_ok.dtba "$SRCDIR/fdtaddon_addon_prop_existing_ok.dtsa" + check_dtb fdtaddon_addon_prop_existing_ok.dtba + + run_fdtaddon_test -i fdtaddon_base_prop_existing.dtb -o fdtaddon_addon_prop_existing_ok-merged.dtb \ + -t "/base-node" fdtaddon_addon_prop_existing_ok.dtba + check_dtb fdtaddon_addon_prop_existing_ok-merged.dtb + } pylibfdt_tests () {
Signature · 1 line
2.55.0
RFC PATCH v2 70/74 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 | 13 +++++ 7 files changed, 246 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_PROPDATA_PHANDLE_REF] ref-n1a[0], ref = n1.a + ref-addon-n1a = <0x00000001>; + // [FDT_PROPDATA_PHANDLE] ref-addon-n1a[0] + }; + addon-node2 { + ref-n1bx = <0xffffffff>; + // [FDT_PROPDATA_PHANDLE_REF] ref-n1bx[0], ref = n1.b.x + ref-addon-n1bx = <0x00000002>; + // [FDT_PROPDATA_PHANDLE] 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 { + // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'b' -> phandle 0x00000002 + prop = <0x00000000>; + phandle = <0x00000005>; + }; + other-a { + prop = <0x00000000>; + phandle = <0x00000001>; + }; + other-b { + // [FDT_EXPORT_SYM] 'x' -> phandle 0x00000003 + prop = <0x00000000>; + phandle = <0x00000002>; + }; + other-x { + prop = <0x00000000>; + phandle = <0x00000003>; + }; + node { + // [FDT_EXPORT_SYM] 'node' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'n1' -> phandle 0x00000005 + compatible = "abc,aaa"; + phandle = <0x00000004>; + }; +};
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 +13 -0
@@ -1334,6 +1334,19 @@ fdtaddon_tests() { -t "/base-node" fdtaddon_addon_prop_existing_ok.dtba check_dtb fdtaddon_addon_prop_existing_ok-merged.dtb + # 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.55.0
RFC PATCH v2 71/74 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 | 28 ++++++++ .../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, 359 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/ base_other: &{/base-node/sub-node}; + /export/ other: &{/somewhere/node-a1/addon1-node/sub-node-other}; + }; + }; + }; + + 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_PROPDATA_PHANDLE_REF] ref-other[0], ref = other + sub-node-stack1 { + // [FDT_EXPORT_SYM] 'stack' -> phandle 0x00000001 + // [FDT_EXPORT_SYM_REF] 'base_other' -> 'other' + // [FDT_EXPORT_SYM] 'other' -> phandle 0x00000002 + compatible = "abc,bbb"; + prop = <0x00000000>; + phandle = <0x00000001>; + }; + sub-node-other { + prop = <0x00000001>; + phandle = <0x00000002>; + }; + }; +};
tests/fdtaddon_stack_1st.dtsa 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/; + +/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/ base_other: &other; + /export/ other: &new_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_PROPDATA_PHANDLE_REF] ref-other[0], ref = other + phandle = <0x00000001>; + }; +}; +&other { + addon2-node-other { + prop = <0xffffffff>; + // [FDT_PROPDATA_PHANDLE_REF] prop[0], ref = base_other + addon2-subnode { + prop = <0x00000002>; + }; + }; +}; +&base_other { + addon2-node-base-other { + prop = <0x00000001>; + ref = <0x00000001>; + // [FDT_PROPDATA_PHANDLE] 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
@@ -1347,6 +1347,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.55.0
RFC PATCH v2 72/74 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_PROPDATA_PHANDLE_REF] interrupt-parent[0], ref = connector + interrupts = <0x00000000 0x00000100>; + interrupt-controller; + #interrupt-cells = <0x00000002>; + vcc1-supply = <0xffffffff>; + // [FDT_PROPDATA_PHANDLE_REF] vcc1-supply[0], ref = conn_5v + vcc2-supply = <0xffffffff>; + // [FDT_PROPDATA_PHANDLE_REF] vcc2-supply[0], ref = connector.conn_5v + reset-gpios = <0xffffffff 0x00000001 0x00000000>; + // [FDT_PROPDATA_PHANDLE_REF] 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
@@ -1368,6 +1368,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.55.0
RFC PATCH v2 73/74 libfdt/fdt_addon.c: Add support for an external resolver
In reply to Herve Codinafdt_addon.c uses its own default resolver to resolve import symbols.
It expects a matching between the name of the import symbol to resolve and the name of export symbols available in the addon target node (node in the base dtb).
In some cases, it makes sense to have a resolver that could choose the right export symbol to match based on some other criteria.
The external resolver allows the user of libfdt to provide its own resolver and so match an import symbol based on its own criteria.
--- libfdt/fdt_addon.c | 138 +++++++++++++++++++++++++++++++++------------ libfdt/libfdt.h | 98 +++++++++++++++++++++++++++++++- libfdt/version.lds | 2 + 3 files changed, 200 insertions(+), 38 deletions(-)
libfdt/fdt_addon.c +101 -37
@@ -10,6 +10,11 @@#include "libfdt_internal.h" +struct fdt_addon_resolver { +const struct fdt_addon_resolver_ops *ops; +void *priv; +}; +/** * fdt_skip_string - Skip a string * @fdt: device tree blob
@@ -568,21 +573,9 @@ static int fdt_resolve_symbol(const void *fdt, int target_node,return -FDT_ERR_NOTFOUND ; } -/** -* fdt_resolve_import - Resolve an imported symbol -* @fdt: base device tree blob -* @target_node: Target node offset in the base device tree blob containing -* the exported symbols used for the resolution. -* @importsym_name: Import symbol name -* @importsym_compatible: Import symbol compatible string -* -* returns: -* offset of the node matching the symbol after the resolution on success. -* Negative error code on failure. -*/ -static int fdt_resolve_import (const void *fdt,int target_node, -const char *importsym_name, -const char *importsym_compatible) +int fdt_addon_resolve_default (const void *fdt,int target_node, +const char *importsym_name, +const char *importsym_compatible) {/* * Do not check the import symbol compatible string against the found
@@ -604,6 +597,33 @@ static int fdt_resolve_import(const void *fdt, int target_node, strlen(importsym_name)); } +/** +* fdt_resolve_import - Resolve an imported symbol +* @fdt: base device tree blob +* @target_node: Target node offset in the base device tree blob containing +* the exported symbols used for the resolution. +* @importsym_name: Import symbol name +* @importsym_compatible: Import symbol compatible string +* @resolver: Custom resolver. If NULL, the default resolver is used. +* +* returns: +* offset of the node matching the symbol after the resolution on success. +* Negative error code on failure. +*/ +static int fdt_resolve_import (const void *fdt,int target_node, +const char *importsym_name, +const char *importsym_compatible, +const struct fdt_addon_resolver *resolver) +{ +if (resolver) +return resolver->ops->resolve (resolver->priv, fdt, target_node, + importsym_name, + importsym_compatible); + +return fdt_addon_resolve_default (fdt, target_node, importsym_name, + importsym_compatible); +} +static int fdt_check_importsym_offset (const void *fdt,int offset,int *data_offset) {int nextoffset, d;
@@ -709,6 +729,7 @@ static const char *fdt_importsym_get_compatible(const void *fdt, int offset)* resolution. * @sym_name: Symbol name * @sym_namelen: Length of the symbol name +* @resolver: Custom resolver, NULL to use the default resolver. * * addon_resolve_symbol() resolved a symbol used by an addon using the import * symbol table available in the addon device tree blob.
@@ -719,7 +740,8 @@ static const char *fdt_importsym_get_compatible(const void *fdt, int offset)* Negative error code on failure. */ static int addon_resolve_symbol (const void *fdta,const void *fdt,int target_node, -const char *sym_name,size_t sym_namelen) +const char *sym_name,size_t sym_namelen, +const struct fdt_addon_resolver *resolver) {const char *importsym_compat;const char *importsym_name;
@@ -739,7 +761,7 @@ static int addon_resolve_symbol(const void *fdta, const void *fdt, int target_nocontinue ;return fdt_resolve_import (fdt, target_node, importsym_name, - importsym_compat); + importsym_compat, resolver); }/* Not found ... */ return -FDT_ERR_NOTFOUND ;
@@ -753,6 +775,7 @@ static int addon_resolve_symbol(const void *fdta, const void *fdt, int target_no* device tree blob, must have exported symbols needed for the * resolution. * @ref: The reference to resolve +* @resolver: Custom resolver, NULL to use the default resolver * * addon_resolve_ref() resolves a reference used by an addon. * A reference can be composed of several symbols separated by a '.' char.
@@ -769,7 +792,8 @@ static int addon_resolve_symbol(const void *fdta, const void *fdt, int target_no* Negative error code on failure. */ static int addon_resolve_ref (const void *fdta,const void *fdt,int target_node, -const char *ref) +const char *ref, +const struct fdt_addon_resolver *resolver) {const char *end = ref +strlen (ref);const char *r = ref;
@@ -794,7 +818,8 @@ static int addon_resolve_ref(const void *fdta, const void *fdt, int target_node, d = end;if (r == ref) - tmp_node =addon_resolve_symbol (fdta, fdt, tmp_node, r, d-r); + tmp_node =addon_resolve_symbol (fdta, fdt, tmp_node, r, d-r, + resolver);else tmp_node =fdt_resolve_symbol (fdt, tmp_node, r, d-r);
@@ -812,6 +837,7 @@ static int addon_resolve_ref(const void *fdta, const void *fdt, int target_node,* @fdta: Addon device tree blob * @fdt: Device tree blob the addon is going to be applied to * @target_node: Offset of the node in fdt the addon is going to be applied to +* @resolver: Custom resolver. NULL to use the default resolver * * addon_resolve_phandles() resolved unresolved phandle symbols available in * the addon.
@@ -820,7 +846,8 @@ static int addon_resolve_ref(const void *fdta, const void *fdt, int target_node,* 0 on success * Negative error code on failure */ -static int addon_resolve_phandles (void *fdta,const void *fdt,int target_node) +static int addon_resolve_phandles (void *fdta,const void *fdt,int target_node, +const struct fdt_addon_resolver *resolver) {int offset, next_offset, d;int last_prop_offset =-1 ;
@@ -880,7 +907,8 @@ static int addon_resolve_phandles(void *fdta, const void *fdt, int target_node) ref =fdt_offset_ptr (fdta, d,1 );/* Resolve this phandle */ - ref_node =addon_resolve_ref (fdta, fdt, target_node, ref); + ref_node =addon_resolve_ref (fdta, fdt, target_node, ref, + resolver);if (ref_node <0 )return ref_node;
@@ -931,7 +959,8 @@ static int addon_resolve_phandles(void *fdta, const void *fdt, int target_node) ref =fdt_offset_ptr (fdta, d,1 );/* Resolve the phandle */ - ref_node =addon_resolve_ref (fdta, fdt, target_node, ref); + ref_node =addon_resolve_ref (fdta, fdt, target_node, + ref, resolver);if (ref_node <0 )return ref_node;
@@ -1153,6 +1182,7 @@ static const char *fdt_orphan_get_ref(const void *fdt, int offset)* @fdt: Base Device Tree blob * @target_node: Target node in the base device tree the addon is going to be * applied to +* @resolver: Custom resolver, NULL to use the default resolver * * Checks recursively if applying fdta overwrites phandle values in the base * fdt. When such a phandle is found, the fdta is changed to use the fdt's
@@ -1163,7 +1193,8 @@ static const char *fdt_orphan_get_ref(const void *fdt, int offset)* Negative error code on failure */ static int addon_prevent_phandles_overwrite (void *fdta,const void *fdt, -int target_node) +int target_node, +const struct fdt_addon_resolver *resolver) {int fdt_orphan_target;int addon_root_node;
@@ -1187,7 +1218,8 @@ static int addon_prevent_phandles_overwrite(void *fdta, const void *fdt,if (!ref)return -FDT_ERR_BADSTRUCTURE ; - fdt_orphan_target =addon_resolve_ref (fdta, fdt, target_node, ref); + fdt_orphan_target =addon_resolve_ref (fdta, fdt, target_node, + ref, resolver);if (fdt_orphan_target <0 )return fdt_orphan_target;
@@ -1505,6 +1537,7 @@ static int addon_merge_node_properties(const void *fdta, int fdta_node,* @target_path: Path in the base Device Tree to the node where the addon is * applied to. This is the node where export symbols used for symbol * resolution are present. +* @resolver: Custom resolver. NULL to use the default resolver. * * returns: * 0 on success
@@ -1512,7 +1545,8 @@ static int addon_merge_node_properties(const void *fdta, int fdta_node,*/ static int addon_merge_node_exports (const void *fdta,int fdta_node,void *fdt,int fdt_node, -bool is_existing_node,const char *target_path) +bool is_existing_node,const char *target_path, +const struct fdt_addon_resolver *resolver) {const char *exportsym_name;const char *exportsym_ref;
@@ -1554,7 +1588,8 @@ static int addon_merge_node_exports(const void *fdta, int fdta_node,return target_node;/* Resolve the reference */ - ref_node =addon_resolve_ref (fdta, fdt, target_node, exportsym_ref); + ref_node =addon_resolve_ref (fdta, fdt, target_node, + exportsym_ref, resolver);if (ref_node <0 )return ref_node;
@@ -1591,6 +1626,7 @@ static int addon_merge_node_exports(const void *fdta, int fdta_node,* @target_path: Path in the base Device Tree to the node where the addon is * applied to. This is the node where export symbols used for symbol * resolution are present. +* @resolver: Custom resolver, NULL to use the default resolver. * * returns: * 0 on success
@@ -1598,7 +1634,8 @@ static int addon_merge_node_exports(const void *fdta, int fdta_node,*/ static int addon_merge_node (const void *fdta,int fdta_node,void *fdt,int fdt_node,bool is_existing_node, -const char *target_path) +const char *target_path, +const struct fdt_addon_resolver *resolver) {bool is_existing;int fdta_subnode;
@@ -1607,7 +1644,8 @@ static int addon_merge_node(const void *fdta, int fdta_node, void *fdt,int ret; ret =addon_merge_node_exports (fdta, fdta_node, fdt, fdt_node, - is_existing_node, target_path); + is_existing_node, target_path, + resolver);if (ret)return ret;
@@ -1632,7 +1670,7 @@ static int addon_merge_node(const void *fdta, int fdta_node, void *fdt,return fdt_subnode; ret =addon_merge_node (fdta, fdta_subnode, fdt, fdt_subnode, - is_existing, target_path); + is_existing, target_path, resolver);if (ret)return ret; }
@@ -1640,7 +1678,8 @@ static int addon_merge_node(const void *fdta, int fdta_node, void *fdt,return 0 ; } -static int addon_merge (void *fdta,void *fdt,const char *target_path) +static int addon_merge (void *fdta,void *fdt,const char *target_path, +const struct fdt_addon_resolver *resolver) {int fdt_orphan_target;int fdta_orphan;
@@ -1654,7 +1693,8 @@ static int addon_merge(void *fdta, void *fdt, const char *target_path)return target_node;/* Merge the addon root node into the base target_node */ - ret =addon_merge_node (fdta,0 , fdt, target_node, true, target_path); + ret =addon_merge_node (fdta,0 , fdt, target_node, true, target_path, + resolver);if (ret <0 )return ret;
@@ -1663,12 +1703,13 @@ static int addon_merge(void *fdta, void *fdt, const char *target_path)if (!ref)return -FDT_ERR_BADSTRUCTURE ; - fdt_orphan_target =addon_resolve_ref (fdta, fdt, target_node, ref); + fdt_orphan_target =addon_resolve_ref (fdta, fdt, target_node, + ref, resolver);if (fdt_orphan_target <0 )return fdt_orphan_target; ret =addon_merge_node (fdta, fdta_orphan, fdt, fdt_orphan_target, - true, target_path); + true, target_path, resolver);if (ret <0 )return ret;
@@ -1688,8 +1729,12 @@ static int addon_merge(void *fdta, void *fdt, const char *target_path)return 0 ; } -int fdt_addon_apply (void *fdt,void *fdta,const char *target) +int fdt_addon_apply_resolver (void *fdt,void *fdta,const char *target, +const struct fdt_addon_resolver_ops *resolver_ops, +void *resolver_priv) { +struct fdt_addon_resolver *resolver =NULL ; +struct fdt_addon_resolver custom_resolver;int target_node;uint32_t delta;int ret;
@@ -1697,11 +1742,25 @@ int fdt_addon_apply(void *fdt, void *fdta, const char *target)FDT_RO_PROBE (fdt);FDT_RO_PROBE (fdta); +if (resolver_ops) { +/* Initialize the custom resolver */ + custom_resolver.ops = resolver_ops; + custom_resolver.priv = resolver_priv; +/* This custom resolver is the resolver used */ + resolver = &custom_resolver; + } +/* Get the target node */ target_node =fdt_path_offset (fdt, target);if (target_node <0 )return target_node; +if (resolver && resolver->ops->validate) { + ret = resolver->ops->validate (resolver->priv, fdt, target_node); +if (ret <0 ) +return ret; + } + ret =fdt_find_max_phandle (fdt, &delta);if (ret)return ret;
@@ -1712,16 +1771,16 @@ int fdt_addon_apply(void *fdt, void *fdta, const char *target) goto err;/* Resolve phandles */ - ret =addon_resolve_phandles (fdta, fdt, target_node); + ret =addon_resolve_phandles (fdta, fdt, target_node, resolver);if (ret <0 ) goto err;/* Don't overwrite phandles in fdt */ - ret =addon_prevent_phandles_overwrite (fdta, fdt, target_node); + ret =addon_prevent_phandles_overwrite (fdta, fdt, target_node, resolver);if (ret <0 ) goto err; - ret =addon_merge (fdta, fdt, target); + ret =addon_merge (fdta, fdt, target, resolver);if (ret <0 ) goto err;
@@ -1739,3 +1798,8 @@ err:return ret; } + +int fdt_addon_apply (void *fdt,void *fdta,const char *target) +{ +return fdt_addon_apply_resolver (fdt, fdta, target,NULL ,NULL ); +}
libfdt/libfdt.h +97 -1
110 lines not on this page · raw message
libfdt/version.lds +2 -0
@@ -84,6 +84,8 @@ LIBFDT_1.2 { fdt_get_symbol; fdt_get_symbol_namelen; fdt_addon_apply; + fdt_addon_apply_resolver; + fdt_addon_resolve_default; local: *; };
Signature · 1 line
2.55.0
RFC PATCH v2 74/74 fdtaddon: Add a simple external resolver
In reply to Herve Codinalibfdt allows to use an external resolver to resolve import symbols when an addon is applied.
Add a simple external resolver in fdtaddon based on export symbols given on the tool command line (-e or --export). Those export symbols are used to mach import symbols (match by names) in order to resolved them.
Two syntaxes are available for the -e or --export option:
- Export by symbol (--export '<name>=&<symbol>')
The export symbol <name> is created an reference the node identified by <symbol>. This <symbol> has to be an exported symbol available at the node the addon is applied to. For instance, assuming this base device-tree fragment in the base device-tree:
target {
/export/ bar: &{/somewhere/bar-node};
}
The '--target "/target" --export "foo=&bar"' will export foo as an exported symbol pointing to /somewhere/bar-node. An addon can import the foo symbol an it will be resolved to /somewhere/bar-node.
- Export by path (--export '<name>=&{<path>}')
The export symbol <name> is created and reference the node available at the given <path>. This path must be an absolute path. The '--target "/target" --export "foo=&{/somewhere/baz-node}"' export the symbol 'foo' referencing the node at /somewhere/baz-node. Here again, an addon importing the foo symbol will see this foo symbol resolved to /somewhere/baz-node.
It is worth noting that /somewhere/baz-node may not be referenced in the base device-tree. Indeed, /export/ could not be present to reference this node. If the node is not referenced, dtc will not create its phandle value and the resolution will failed. For this reason having a /export/ keyword at the target node pointing to the /somewhere/baz-node node is still recommended. This will ensure that dtc will create the needed phandle.
--- fdtaddon.c | 232 +++++++++++++++++- ...n_custom_resolver_node_a-merged.dtb.expect | 39 +++ ...n_addon_custom_resolver_node_a.dtba.expect | 15 ++ ...fdtaddon_addon_custom_resolver_node_a.dtsa | 22 ++ ..._custom_resolver_node_ab-merged.dtb.expect | 42 ++++ ..._addon_custom_resolver_node_ab.dtba.expect | 21 ++ ...dtaddon_addon_custom_resolver_node_ab.dtsa | 29 +++ .../fdtaddon_base_custom_resolver.dtb.expect | 33 +++ tests/fdtaddon_base_custom_resolver.dts | 52 ++++ tests/run_tests.sh | 25 ++ 10 files changed, 503 insertions(+), 7 deletions(-) create mode 100644 tests/fdtaddon_addon_custom_resolver_node_a-merged.dtb.expect create mode 100644 tests/fdtaddon_addon_custom_resolver_node_a.dtba.expect create mode 100644 tests/fdtaddon_addon_custom_resolver_node_a.dtsa create mode 100644 tests/fdtaddon_addon_custom_resolver_node_ab-merged.dtb.expect create mode 100644 tests/fdtaddon_addon_custom_resolver_node_ab.dtba.expect create mode 100644 tests/fdtaddon_addon_custom_resolver_node_ab.dtsa create mode 100644 tests/fdtaddon_base_custom_resolver.dtb.expect create mode 100644 tests/fdtaddon_base_custom_resolver.dts
fdtaddon.c +225 -7
@@ -22,20 +22,215 @@static const char usage_synopsis[] ="apply an addon to a base blob\n" " fdtaddon <options> <addon.dtba>" ; -static const char usage_short_opts[] ="i:o:t:v" USAGE_COMMON_SHORT_OPTS ; +static const char usage_short_opts[] ="i:o:t:e:v" USAGE_COMMON_SHORT_OPTS ;static const struct option usage_long_opts[] = { {"input" , required_argument,NULL ,'i' }, {"output" , required_argument,NULL ,'o' }, {"target" , required_argument,NULL ,'t' }, + {"export" , required_argument,NULL ,'e' }, {"verbose" , no_argument,NULL ,'v' },USAGE_COMMON_LONG_OPTS , };static const char *const usage_opts_help[] = {"Input base DT blob" , -"Output DT blob" ,"Target node" , +"Output DT blob" , +"Target node" , +"Custom export symbol" +"\n\tMultiple --export or -e can be present in order to export multiple symbols." +"\n\tThe following syntaxes are supported:" +"\n\t - Defines a export symbol pointing to a node using its symbol" +"\n\t --export '<export_name>=&<symbol>'" +"\n\t - Defines a export symbol pointing to a node by path" +"\n\t --export '<export_name>=&{path_to_node}'" ,"Verbose messages" ,USAGE_COMMON_OPTS_HELP }; -static void *do_apply (void *base,const void *addon,const char *target) +struct export_symbol { +char *name; +char *ref; +struct export_symbol *next; +}; + +struct resolver { +struct export_symbol *export_list; +int verbose; +}; + +static void resolver_init (struct resolver *resolver) +{ +memset (resolver,0 ,sizeof (*resolver)); +} + +static void resolver_exit (struct resolver *resolver) +{ +struct export_symbol *e, *next; + + e = resolver->export_list; +while (e) { +free (e->name); +free (e->ref); + next = e->next; +free (e); + e = next; + } +} + +static char *str_strip_spaces (char *str) +{ +char *strip, *tmp; + + tmp = str; + strip = str; +while (*tmp !='\0' ) { +if (*tmp !=' ' && *tmp !='\t' ) + *(strip++) = *tmp; + tmp++; + } + *strip = *tmp; +return str; +} + +static char *str_split (char *str,char token,char **remaining) +{ +char *tmp; + + tmp =strchr (str, token); +if (!tmp) +return NULL ; + *(tmp++) ='\0' ;/* Split the string at token char */ + + *remaining = tmp; +return str; +} + +static int resolver_parse_export (struct resolver *resolver,const char *arg) +{ +struct export_symbol *export_symbol; +const char *name, *ref; +char *tmp, *strip; + + strip =xstrdup (arg); + strip =str_strip_spaces (strip); + + tmp = strip; + + name =str_split (tmp,'=' , &tmp); +if (!name || !strlen (name)) + goto fail; + +if (*(tmp++) !='&' ) + goto fail; +if (*tmp =='\0' ) + goto fail; + +if (*tmp =='{' ) { +/* ref by path : &{/xxxx/yyyy} */ + tmp++; +if (*(tmp) !='/' ) + goto fail; + + ref =str_split (tmp,'}' , &tmp); +if (!ref || !strlen (ref)) + goto fail; +if (*tmp !='\0' ) + goto fail; + }else { +/* ref by symbol : &xxxx */ + ref = tmp; +if (!strlen (ref)) + goto fail; + } + + export_symbol =xmalloc (sizeof (*export_symbol)); + export_symbol->name =xstrdup (name); + export_symbol->ref =xstrdup (ref); +free (strip); + + export_symbol->next = resolver->export_list; + resolver->export_list = export_symbol; +return 0 ; +fail: +free (strip); +return -1 ; +} + +static int resolver_resolve (void *priv,const void *fdt,int target_node, +const char *importsym_name, +const char *importsym_compatible) +{ +struct resolver *resolver = priv; +int node = -FDT_ERR_NOTFOUND ; +struct export_symbol *e; + + e = resolver->export_list; +while (e) { +if (strcmp (importsym_name, e->name)) { + e = e->next; +continue ; + } + +if (e->ref[0 ] =='/' ) + node =fdt_path_offset (fdt, e->ref); +else + node =fdt_addon_resolve_default (fdt, target_node, e->ref, +NULL ); + +return node; + } +return -FDT_ERR_NOTFOUND ; +} + +static int resolver_validate (void *priv,const void *fdt,int target_node) +{ +struct resolver *resolver = priv; +struct export_symbol *e; +uint32_t phandle; +int node; + +/* +* Check the export_symbol list. The related node must exist in the fdt +* blob and must have a valid phandle value. +* +* Simply revolve all export symbols available in the list to validate +* that they can be resolved. +*/ + + e = resolver->export_list; +while (e) { + node =resolver_resolve (resolver, fdt, target_node, e->name, +NULL ); +if (node <0 ) { +fprintf (stderr, +"\nExport symbol '%s': Cannot find reference '%s'\n" , + e->name, e->ref); +return node; + } + + phandle =fdt_get_phandle (fdt, node); +if ((phandle ==0 ) || (phandle == ~0U )) { +fprintf (stderr, +"\nExport symbol '%s', reference '%s': Invalid phandle\n" , + e->name, e->ref); +return -FDT_ERR_BADPHANDLE ; + } + +if (resolver->verbose) { +printf ("Export symbol '%s', ref '%s' -> node at 0x%x, phandle 0x%" PRIx32"\n" , + e->name, e->ref, node, phandle); + } + + e = e->next; + } +return 0 ; +} + +static const struct fdt_addon_resolver_ops resolver_ops = { + .validate = resolver_validate, + .resolve = resolver_resolve, +}; + + +static void *do_apply (void *base,const void *addon,const char *target, +struct resolver *resolver) {void *tmp_merged;void *tmp_addon;
@@ -72,7 +267,12 @@ static void *do_apply(void *base, const void *addon, const char *target) goto fail; } - ret =fdt_addon_apply (tmp_merged, tmp_addon, target); +if (resolver) + ret =fdt_addon_apply_resolver (tmp_merged, tmp_addon, target, + &resolver_ops, resolver); +else + ret =fdt_addon_apply (tmp_merged, tmp_addon, target); +if (ret) {fprintf (stderr,"\nFailed to apply %s\n" ,fdt_strerror (ret)); goto fail;
@@ -88,7 +288,8 @@ fail: }static int do_fdtaddon (const char *input_filename,const char *output_filename, -const char *addon_filename,const char *target) +const char *addon_filename,const char *target, +struct resolver *resolver) {void *base_blob =NULL ;void *addon_blob =NULL ;
@@ -122,7 +323,7 @@ static int do_fdtaddon(const char *input_filename, const char *output_filename, }/* apply the addon */ - merged_blob =do_apply (base_blob, addon_blob, target); + merged_blob =do_apply (base_blob, addon_blob, target, resolver);if (!merged_blob) goto out_err;
@@ -146,7 +347,12 @@ int main(int argc, char *argv[])char *addon_filename =NULL ;const char *target =NULL ;int verbose; +bool use_resolver = false; +struct resolver resolver;int opt; +int ret; + +resolver_init (&resolver);while ((opt =util_getopt_long ()) !=EOF ) {switch (opt) {
@@ -164,6 +370,13 @@ int main(int argc, char *argv[])case 't' : target = optarg;break ; +case 'e' : +if (resolver_parse_export (&resolver, optarg) <0 ) { +resolver_exit (&resolver); +return 1 ; + } + use_resolver = true; +break ; } }
@@ -190,7 +403,12 @@ int main(int argc, char *argv[])printf ("addon = %s\n" , addon_filename); } -if (do_fdtaddon (input_filename, output_filename, addon_filename, target)) + resolver.verbose = verbose; + + ret =do_fdtaddon (input_filename, output_filename, addon_filename, target, + use_resolver ? &resolver :NULL ); +resolver_exit (&resolver); +if (ret)return 1 ;return 0 ;
tests/fdtaddon_addon_custom_resolver_node_a-merged.dtb.expect new file +39 -0
@@ -0,0 +1,39 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000003>; + addon-node { + prop = "other"; + }; + }; + }; + somewhere { + // [FDT_EXPORT_SYM] 'node_a1' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'node_a2' -> phandle 0x00000002 + // [FDT_EXPORT_SYM] 'sub_node' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'node_b1' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'node_b2' -> phandle 0x00000005 + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + addon-node { + prop = "node_a"; + }; + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000002>; + }; + node-b1 { + compatible = "abc,bbb"; + phandle = <0x00000004>; + }; + node-b2 { + compatible = "abc,bbb"; + phandle = <0x00000005>; + }; + }; +};
tests/fdtaddon_addon_custom_resolver_node_a.dtba.expect new file +15 -0
@@ -0,0 +1,15 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon-node { + prop = "node_a"; + }; +}; +&other { + addon-node { + prop = "other"; + }; +};
tests/fdtaddon_addon_custom_resolver_node_a.dtsa new file +22 -0
@@ -0,0 +1,22 @@ +// 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 = "node_a"; + }; +}; + +&other { + addon-node { + prop = "other"; + }; +};
tests/fdtaddon_addon_custom_resolver_node_ab-merged.dtb.expect new file +42 -0
42 lines not on this page · raw message
tests/fdtaddon_addon_custom_resolver_node_ab.dtba.expect new file +21 -0
@@ -0,0 +1,21 @@ +/dts-v1/; +/addon/; + +// [FDT_IMPORT_SYM] 'node_a' (abc,aaa) +// [FDT_IMPORT_SYM] 'node_b' (abc,bbb) +// [FDT_IMPORT_SYM] 'other' () +&node_a { + addon-node { + prop = "node_a"; + }; +}; +&node_b { + addon-node { + prop = "node_b"; + }; +}; +&other { + addon-node { + prop = "other"; + }; +};
tests/fdtaddon_addon_custom_resolver_node_ab.dtsa new file +29 -0
@@ -0,0 +1,29 @@ +// 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/ node_b: "abc,bbb"; +/import/ other: ""; + +&node_a { + addon-node { + prop = "node_a"; + }; +}; + +&node_b { + addon-node { + prop = "node_b"; + }; +}; + +&other { + addon-node { + prop = "other"; + }; +};
tests/fdtaddon_base_custom_resolver.dtb.expect new file +33 -0
@@ -0,0 +1,33 @@ +/dts-v1/; + +/ { + base-node { + sub-node { + prop = <0x00000000>; + phandle = <0x00000003>; + }; + }; + somewhere { + // [FDT_EXPORT_SYM] 'node_a1' -> phandle 0x00000001 + // [FDT_EXPORT_SYM] 'node_a2' -> phandle 0x00000002 + // [FDT_EXPORT_SYM] 'sub_node' -> phandle 0x00000003 + // [FDT_EXPORT_SYM] 'node_b1' -> phandle 0x00000004 + // [FDT_EXPORT_SYM] 'node_b2' -> phandle 0x00000005 + node-a1 { + compatible = "abc,aaa"; + phandle = <0x00000001>; + }; + node-a2 { + compatible = "abc,aaa"; + phandle = <0x00000002>; + }; + node-b1 { + compatible = "abc,bbb"; + phandle = <0x00000004>; + }; + node-b2 { + compatible = "abc,bbb"; + phandle = <0x00000005>; + }; + }; +};
tests/fdtaddon_base_custom_resolver.dts new file +52 -0
52 lines not on this page · raw message
tests/run_tests.sh +25 -0
@@ -1369,6 +1369,31 @@ 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 + # Custom resolver + run_dtc_test -I dts -O dtb -o fdtaddon_base_custom_resolver.dtb "$SRCDIR/fdtaddon_base_custom_resolver.dts" + check_dtb fdtaddon_base_custom_resolver.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_addon_custom_resolver_node_a.dtba "$SRCDIR/fdtaddon_addon_custom_resolver_node_a.dtsa" + check_dtb fdtaddon_addon_custom_resolver_node_a.dtba + + run_fdtaddon_test -i fdtaddon_base_custom_resolver.dtb -o fdtaddon_addon_custom_resolver_node_a-merged.dtb \ + -t "/somewhere" \ + -e "node_a=&node_a1" \ + -e "other=&{/base-node/sub-node}" \ + fdtaddon_addon_custom_resolver_node_a.dtba + check_dtb fdtaddon_addon_custom_resolver_node_a-merged.dtb + + run_dtc_test -I dts -O dtb -o fdtaddon_addon_custom_resolver_node_ab.dtba "$SRCDIR/fdtaddon_addon_custom_resolver_node_ab.dtsa" + check_dtb fdtaddon_addon_custom_resolver_node_ab.dtba + + run_fdtaddon_test -i fdtaddon_base_custom_resolver.dtb -o fdtaddon_addon_custom_resolver_node_ab-merged.dtb \ + -t "/somewhere" \ + -e "node_a=&{/somewhere/node-a2}" \ + -e "node_b=&node_b1" \ + -e "other=&sub_node" \ + fdtaddon_addon_custom_resolver_node_ab.dtba + check_dtb fdtaddon_addon_custom_resolver_node_ab-merged.dtb + # 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
Signature · 1 line
2.55.0