New style overlay and /expansion/ support
cover New style overlay and /expansion/ support
This series revives the new style of overlay syntax that never got merged. David said he wanted to handle it outside of the parse phase[1], and he proposed a patch to move overlay application to the livetree phase. I've applied that patch and reworked Pantelis' last two patches for the new style "syntactic sugar" on top[2].
In addition, I've included the new /expansion/ keyword support for overlays that don't reference any labels that are outside of the input file. The new expansion keyword just transforms the unresolved references into strings that go into a new 'target-alias' property instead of the 'target' property. This is in line with what David has proposed on the mailing list a few months ago[3].
RFC part: The current syntax requires a root node or overlays are rejected. Making the root node optional would require some non-trivial rework of the grammar to support it. This means the proposed 'new style' syntax doesn't work without the root node.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] https://lkml.kernel.org/r/[email protected]
David Gibson (1):
Start moving overlay handling from parser into dtc core
Pantelis Antoniou (1):
tests: Add a test for overlays syntactic sugar
Stephen Boyd (2):
dtc: Add syntactic sugar version of overlays
dtc: Add /expansion/ support
checks.c | 2 +- dtc-lexer.l | 6 +++ dtc-parser.y | 68 +++++++++++++++++----------------- dtc.c | 16 +++++++- dtc.h | 20 +++++++++- flattree.c | 2 +- fstree.c | 2 +- livetree.c | 80 +++++++++++++++++++++++++++++++++++++++- tests/overlay_overlay_simple.dts | 3 ++ tests/run_tests.sh | 6 +++ 10 files changed, 163 insertions(+), 42 deletions(-)
Signature · 1 line
2.10.0.297.gf6727b0
PATCH 1/4 Start moving overlay handling from parser into dtc core
From: David Gibson <[email protected]>
To make includes more useful, dtc for some time has allowed "overlays" in dts files, defining the tree in several chunks which are merged together. Recent Linux kernels make use of dynamic DT overlays which have similar mechanics, but are implemented at DT load time with specially formatted dtbs.
In order to provide better support for these dynamic overlays in dtc, we want to explicitly manipulate overlays, rather than just fold them together during the parse phase. This patch is a first step towards this.
[[email protected]: Have resolve_overlays() loop with a cursor]
--- dtc-parser.y | 63 +++++++++++++++++++++++++++++------------------------------- dtc.c | 13 +++++++++++++ dtc.h | 18 +++++++++++++++-- flattree.c | 2 +- fstree.c | 2 +- livetree.c | 40 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 99 insertions(+), 39 deletions(-)
dtc-parser.y +30 -33
@@ -51,6 +51,8 @@ extern bool treesource_error; struct property *proplist; struct node *node; struct node *nodelist; + struct overlay *overlay; + struct overlay *overlaylist; struct reserve_info *re; uint64_t integer; unsigned int flags;
@@ -83,11 +85,14 @@ extern bool treesource_error; %type <prop> propdef %type <proplist> proplist -%type <node> devicetree %type <node> nodedef %type <node> subnode %type <nodelist> subnodes +%type <node> basetree +%type <overlay> overlay +%type <overlaylist> overlays + %type <integer> integer_prim %type <integer> integer_unary %type <integer> integer_mul
@@ -106,9 +111,9 @@ extern bool treesource_error; %% sourcefile: - headers memreserves devicetree + headers memreserves basetree overlays { - parser_output = build_dt_info($1, $2, $3, + parser_output = build_dt_info($1, $2, $3, $4, guess_boot_cpuid($3)); } ;
@@ -157,48 +162,40 @@ memreserve: } ; -devicetree: +basetree: '/' nodedef { $$ = name_node($2, ""); } - | devicetree '/' nodedef + ; + +overlay: basetree { - $$ = merge_nodes($1, $3); + $$ = build_overlay("/", $1); } - - | devicetree DT_LABEL DT_REF nodedef + | DT_REF nodedef { - struct node *target = get_node_by_ref($1, $3); - - if (target) { - add_label(&target->labels, $2); - merge_nodes(target, $4); - } else - ERROR(&@3, "Label or path %s not found", $3); - $$ = $1; + $$ = build_overlay($1, $2); } - | devicetree DT_REF nodedef + | DT_DEL_NODE DT_REF ';' { - struct node *target = get_node_by_ref($1, $2); - - if (target) - merge_nodes(target, $3); - else - ERROR(&@2, "Label or path %s not found", $2); - $$ = $1; + $$ = build_overlay($2, NULL); } - | devicetree DT_DEL_NODE DT_REF ';' + | DT_LABEL overlay { - struct node *target = get_node_by_ref($1, $3); - - if (target) - delete_node(target); - else - ERROR(&@3, "Label or path %s not found", $3); - + add_label(&$2->dt->labels, $1); + $$ = $2; + } + ; - $$ = $1; +overlays: + /* empty */ + { + $$ = NULL; + } + | overlay overlays + { + $$ = chain_overlay($1, $2); } ;
dtc.c +13 -0
@@ -58,6 +58,16 @@ static void fill_fullpaths(struct node *tree, const char *prefix)fill_fullpaths (child, tree->fullpath); } +static void resolve_overlays (struct dt_info *dti) +{ +struct overlay *o = dti->overlays; + +while (o) { +apply_overlay (dti->dt, o); + o = o->next; + } +} +/* Usage related data. */ #define FDT_VERSION (version) _FDT_VERSION(version)#define _FDT_VERSION (version) #version
@@ -317,7 +327,10 @@ int main(int argc, char *argv[])if (cmdline_boot_cpuid !=-1 ) dti->boot_cpuid_phys = cmdline_boot_cpuid; +resolve_overlays (dti); +fill_fullpaths (dti->dt,"" ); +process_checks (force, dti);/* on a plugin, generate by default */
dtc.h +16 -2
@@ -164,6 +164,12 @@ struct node {struct label *labels; }; +struct overlay { +char *target; +struct node *dt; +struct overlay *next; +}; +#define for_each_label_withdel (l0, l) \ for ((l) = (l0); (l); (l) = (l)->next)
@@ -208,6 +214,10 @@ void delete_node(struct node *node);void append_to_property (struct node *node,char *name,const void *data,int len); +struct overlay *build_overlay (char *target,struct node *dt); +struct overlay *chain_overlay (struct overlay *first,struct overlay *list); +void apply_overlay (struct node *base,struct overlay *overlay); +const char *get_unitname (struct node *node);struct property *get_property (struct node *node,const char *propname);cell_t propval_cell (struct property *prop);
@@ -245,7 +255,9 @@ struct dt_info {unsigned int dtsflags;struct reserve_info *reservelist;uint32_t boot_cpuid_phys; -struct node *dt;/* the device tree */ + +struct node *dt; +struct overlay *overlays; };/* DTS version flags definitions */
@@ -254,7 +266,9 @@ struct dt_info {struct dt_info *build_dt_info (unsigned int dtsflags,struct reserve_info *reservelist, -struct node *tree,uint32_t boot_cpuid_phys); +struct node *basetree, +struct overlay *overlays, +uint32_t boot_cpuid_phys);void sort_tree (struct dt_info *dti);void generate_label_tree (struct dt_info *dti,char *name,bool allocph);void generate_fixups_tree (struct dt_info *dti,char *name);
flattree.c +1 -1
@@ -942,5 +942,5 @@ struct dt_info *dt_from_blob(const char *fname)fclose (f); -return build_dt_info (DTSF_V1 , reservelist, tree, boot_cpuid_phys); +return build_dt_info (DTSF_V1 , reservelist, tree,NULL , boot_cpuid_phys); }
fstree.c +1 -1
@@ -86,5 +86,5 @@ struct dt_info *dt_from_fs(const char *dirname) tree =read_fstree (dirname); tree =name_node (tree,"" ); -return build_dt_info (DTSF_V1 ,NULL , tree,guess_boot_cpuid (tree)); +return build_dt_info (DTSF_V1 ,NULL , tree,NULL ,guess_boot_cpuid (tree)); }
livetree.c +38 -2
@@ -313,6 +313,39 @@ void append_to_property(struct node *node, } } +struct overlay *build_overlay (char *target,struct node *dt) +{ +struct overlay *new =xmalloc (sizeof (*new)); + + new->target = target; + new->dt = dt; + new->next =NULL ; +return new; +} + +struct overlay *chain_overlay (struct overlay *first,struct overlay *list) +{ +assert (first->next ==NULL ); + + first->next = list; +return first; +} + +void apply_overlay (struct node *base,struct overlay *overlay) +{ +struct node *target =get_node_by_ref (base, overlay->target); + +if (!target) +die ("Couldn't find label or path %s for overlay\n" , + overlay->target); + +if (!overlay->dt) +/* Deletion */ +delete_node (target); +else +merge_nodes (target, overlay->dt); +} +struct reserve_info *build_reserve_entry (uint64_t address,uint64_t size) {struct reserve_info *new =xmalloc (sizeof (*new));
@@ -354,15 +387,18 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list,struct dt_info *build_dt_info (unsigned int dtsflags,struct reserve_info *reservelist, -struct node *tree,uint32_t boot_cpuid_phys) +struct node *basetree, +struct overlay *overlays, +uint32_t boot_cpuid_phys) {struct dt_info *dti; dti =xmalloc (sizeof (*dti)); dti->dtsflags = dtsflags; dti->reservelist = reservelist; - dti->dt = tree; dti->boot_cpuid_phys = boot_cpuid_phys; + dti->dt = basetree; + dti->overlays = overlays;return dti; }
Signature · 1 line
2.10.0.297.gf6727b0
PATCH 2/4 dtc: Add syntactic sugar version of overlays
In reply to Stephen BoydInstead of writing overlays with the target property and __overlay__ node, i.e.
fragment@0 {
target = <&foo>;
__overlay__ {
bar-property = <0x200>;
};
}support the syntactic sugar version of overlays where this can be written as
&foo {
bar-property = <0x200>;
};and have dtc convert that into a fragment node.
Based on a patch by Pantelis Antoniou.
--- dtc.c | 2 +- dtc.h | 3 ++- livetree.c | 40 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 6 deletions(-)
dtc.c +1 -1
@@ -63,7 +63,7 @@ static void resolve_overlays(struct dt_info *dti)struct overlay *o = dti->overlays;while (o) { -apply_overlay (dti->dt, o); +apply_overlay (dti->dt, o, dti->dtsflags); o = o->next; } }
dtc.h +2 -1
@@ -216,7 +216,8 @@ void append_to_property(struct node *node,struct overlay *build_overlay (char *target,struct node *dt);struct overlay *chain_overlay (struct overlay *first,struct overlay *list); -void apply_overlay (struct node *base,struct overlay *overlay); +void apply_overlay (struct node *base,struct overlay *overlay, +unsigned int dtsflags);const char *get_unitname (struct node *node);struct property *get_property (struct node *node,const char *propname);
livetree.c +36 -4
@@ -331,14 +331,46 @@ struct overlay *chain_overlay(struct overlay *first, struct overlay *list)return first; } -void apply_overlay (struct node *base,struct overlay *overlay) +static void add_fragment (struct node *base,struct overlay *overlay) { -struct node *target =get_node_by_ref (base, overlay->target); +static unsigned int next_fragment =0 ; +struct node *node; +struct property *p; +struct data d = empty_data; +char *name; -if (!target) -die ("Couldn't find label or path %s for overlay\n" , +if (!overlay->dt) +die ("Deletions not supported at runtime for %s\n" , overlay->target); +/* Insert a target = <&phandle> property */ + d =data_add_marker (d,REF_PHANDLE , overlay->target); + d =data_append_integer (d,0xffffffff ,32 ); + + p =build_property ("target" , d); + +xasprintf (&name,"fragment@%u" , next_fragment++); +name_node (overlay->dt,"__overlay__" ); + node =build_node (p, overlay->dt); +name_node (node, name); + +add_child (base, node); +} + +void apply_overlay (struct node *base,struct overlay *overlay, +unsigned int dtsflags) +{ +struct node *target =get_node_by_ref (base, overlay->target); + +if (!target) { +if (dtsflags &DTSF_PLUGIN ) { +add_fragment (base, overlay); +return ; + }else +die ("Couldn't find label or path %s for overlay\n" , + overlay->target); + } +if (!overlay->dt)/* Deletion */ delete_node (target);
Signature · 1 line
2.10.0.297.gf6727b0
PATCH 3/4 tests: Add a test for overlays syntactic sugar
In reply to Stephen BoydFrom: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/[email protected]>
Add a single test making sure the &foo { }; syntax works.
--- tests/overlay_overlay_simple.dts | 3 +++ tests/run_tests.sh | 6 ++++++ 2 files changed, 9 insertions(+)
tests/overlay_overlay_simple.dts +3 -0
@@ -7,6 +7,9 @@ /dts-v1/; /plugin/; +/ { +}; + &test { test-int-property = <43>; };
tests/run_tests.sh +6 -0
@@ -231,6 +231,12 @@ dtc_overlay_tests () { run_test check_path overlay_base_with_aliases.dtb not-exists "/__symbols__" run_test check_path overlay_base_with_aliases.dtb not-exists "/__fixups__" run_test check_path overlay_base_with_aliases.dtb not-exists "/__local_fixups__" + + # Test simplified plugin syntax + run_dtc_test -@ -I dts -O dtb -o overlay_overlay_simple.dtb overlay_overlay_simple.dts + + # Verify non-generation of local fixups + run_test check_path overlay_overlay_simple.dtb not-exists "/__local_fixups__" } tree1_tests () {
Signature · 6 lines
2.10.0.297.gf6727b0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/4 dtc: Add /expansion/ support
In reply to Stephen BoydThere's typically a standard pinout for expansion boards on platforms like raspberry pi, 96boards, C.H.I.P, etc. Introduce a new syntax to describe these types of expansion boards in devicetree.
In general, the resulting dtb format is very similar to the /plugin/ style of overlays, except the 'target' property in the fragment node is replaced with a 'target-alias' property that contains a string instead of a phandle.
fragment@0 {
target-alias = "i2c_1";
};instead of
fragment@0 {
target = <&i2c_1>;
};--- checks.c | 2 +- dtc-lexer.l | 6 ++++++ dtc-parser.y | 5 +++++ dtc.c | 3 +-- dtc.h | 1 + livetree.c | 22 +++++++++++++++------- 6 files changed, 29 insertions(+), 10 deletions(-)
checks.c +1 -1
@@ -487,7 +487,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti, refnode =get_node_by_ref (dt, m->ref);if (! refnode) { -if (!(dti->dtsflags &DTSF_PLUGIN )) +if (!(dti->dtsflags & (DTSF_PLUGIN |DTSF_EXPANSION )))FAIL (c,"Reference to non-existent node or " "label \"%s\"\n" , m->ref);else /* mark the entry as unresolved */
dtc-lexer.l +6 -0
@@ -126,6 +126,12 @@ static void lexical_error(const char *fmt, ...); return DT_PLUGIN; } +<*>"/expansion/" { + DPRINT("Keyword: /expansion/\n"); + return DT_EXPANSION; + } + + <*>"/memreserve/" { DPRINT("Keyword: /memreserve/\n"); BEGIN_DEFAULT();
dtc-parser.y +5 -0
@@ -60,6 +60,7 @@ extern bool treesource_error; %token DT_V1 %token DT_PLUGIN +%token DT_EXPANSION %token DT_MEMRESERVE %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR %token DT_BITS
@@ -127,6 +128,10 @@ header: { $$ = DTSF_V1 | DTSF_PLUGIN; } + | DT_V1 ';' DT_EXPANSION ';' + { + $$ = DTSF_V1 | DTSF_EXPANSION; + } ; headers:
dtc.c +1 -2
@@ -334,9 +334,8 @@ int main(int argc, char *argv[])process_checks (force, dti);/* on a plugin, generate by default */ -if (dti->dtsflags &DTSF_PLUGIN ) { +if (dti->dtsflags & (DTSF_PLUGIN |DTSF_EXPANSION )) generate_fixups =1 ; - }if (auto_label_aliases)generate_label_tree (dti,"aliases" , false);
dtc.h +1 -0
@@ -264,6 +264,7 @@ struct dt_info {/* DTS version flags definitions */ #define DTSF_V1 0x0001/* /dts-v1/ */ #define DTSF_PLUGIN 0x0002/* /plugin/ */ +#define DTSF_EXPANSION 0x0004/* /expansion/ */ struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist,
livetree.c +15 -7
@@ -331,7 +331,8 @@ struct overlay *chain_overlay(struct overlay *first, struct overlay *list)return first; } -static void add_fragment (struct node *base,struct overlay *overlay) +static void add_fragment (struct node *base,struct overlay *overlay, +bool expansion) {static unsigned int next_fragment =0 ;struct node *node;
@@ -343,11 +344,18 @@ static void add_fragment(struct node *base, struct overlay *overlay)die ("Deletions not supported at runtime for %s\n" , overlay->target); -/* Insert a target = <&phandle> property */ - d =data_add_marker (d,REF_PHANDLE , overlay->target); - d =data_append_integer (d,0xffffffff ,32 ); +if (expansion) { +/* Insert a target-alias = "<target>" property */ + p =build_property ("target-alias" , +data_copy_mem (overlay->target, +strlen (overlay->target) +1 )); + }else { +/* Insert a target = <&phandle> property */ + d =data_add_marker (d,REF_PHANDLE , overlay->target); + d =data_append_integer (d,0xffffffff ,32 ); - p =build_property ("target" , d); + p =build_property ("target" , d); + }xasprintf (&name,"fragment@%u" , next_fragment++);name_node (overlay->dt,"__overlay__" );
@@ -363,8 +371,8 @@ void apply_overlay(struct node *base, struct overlay *overlay,struct node *target =get_node_by_ref (base, overlay->target);if (!target) { -if (dtsflags &DTSF_PLUGIN ) { -add_fragment (base, overlay); +if (dtsflags & (DTSF_PLUGIN |DTSF_EXPANSION )) { +add_fragment (base, overlay, dtsflags &DTSF_EXPANSION );return ; }else die("Couldn't find label or path %s for overlay\n",
Signature · 1 line
2.10.0.297.gf6727b0