Skip to content

Commit

Permalink
overlay: Add syntactic sugar version of overlays
Browse files Browse the repository at this point in the history
For simple overlays that use a single target there exists a
simpler syntax version.

&foo { }; generates an overlay with a single target at foo.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
pantoniou authored and dgibson committed Sep 28, 2017
1 parent 497432f commit 737b2df
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
20 changes: 17 additions & 3 deletions dtc-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,19 @@ devicetree:
{
struct node *target = get_node_by_ref($1, $2);

if (target)
if (target) {
merge_nodes(target, $3);
else
ERROR(&@2, "Label or path %s not found", $2);
} else {
/*
* We rely on the rule being always:
* versioninfo plugindecl memreserves devicetree
* so $-1 is what we want (plugindecl)
*/
if ($<flags>-1 & DTSF_PLUGIN)
add_orphan_node($1, $3, $2);
else
ERROR(&@2, "Label or path %s not found", $2);
}
$$ = $1;
}
| devicetree DT_DEL_NODE DT_REF ';'
Expand All @@ -200,6 +209,11 @@ devicetree:

$$ = $1;
}
| /* empty */
{
/* build empty node */
$$ = name_node(build_node(NULL, NULL), "");
}
;

nodedef:
Expand Down
1 change: 1 addition & 0 deletions dtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ struct node *build_node_delete(void);
struct node *name_node(struct node *node, char *name);
struct node *chain_node(struct node *first, struct node *list);
struct node *merge_nodes(struct node *old_node, struct node *new_node);
void 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);
Expand Down
22 changes: 22 additions & 0 deletions livetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
return old_node;
}

void add_orphan_node(struct node *dt, struct node *new_node, char *ref)
{
static unsigned int next_orphan_fragment = 0;
struct node *node;
struct property *p;
struct data d = empty_data;
char *name;

d = data_add_marker(d, REF_PHANDLE, ref);
d = data_append_integer(d, 0xffffffff, 32);

p = build_property("target", d);

xasprintf(&name, "fragment@%u",
next_orphan_fragment++);
name_node(new_node, "__overlay__");
node = build_node(p, new_node);
name_node(node, name);

add_child(dt, node);
}

struct node *chain_node(struct node *first, struct node *list)
{
assert(first->next_sibling == NULL);
Expand Down

0 comments on commit 737b2df

Please sign in to comment.