linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH 0/4] New style overlay and /expansion/ support
@ 2017-01-31  0:02 Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core Stephen Boyd
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stephen Boyd @ 2017-01-31  0:02 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler, Frank Rowand, Pantelis Antoniou,
	Rob Herring, Mark Brown, Grant Likely, Mark Rutland, mporter,
	Koen Kooi, Guenter Roeck, marex, Wolfram Sang, devicetree,
	linux-kernel, linux-i2c

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/20161125041124.GB12287@umbus.fritz.box
[2] https://lkml.kernel.org/r/1481114903-8197-7-git-send-email-pantelis.antoniou@konsulko.com
[3] https://lkml.kernel.org/r/20160718142037.GS16769@voom.fritz.box

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

-- 
2.10.0.297.gf6727b0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core
  2017-01-31  0:02 [RFC/PATCH 0/4] New style overlay and /expansion/ support Stephen Boyd
@ 2017-01-31  0:02 ` Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 2/4] dtc: Add syntactic sugar version of overlays Stephen Boyd
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2017-01-31  0:02 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler, Frank Rowand, Pantelis Antoniou,
	Rob Herring, Mark Brown, Grant Likely, Mark Rutland, mporter,
	Koen Kooi, Guenter Roeck, marex, Wolfram Sang, devicetree,
	linux-kernel, linux-i2c

From: David Gibson <david@gibson.dropbear.id.au>

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.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[stephen.boyd@linaro.org: Have resolve_overlays() loop with a
cursor]
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 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(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index ca3f5003427c..3d2ce372c286 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -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);
 		}
 	;
 
diff --git a/dtc.c b/dtc.c
index a4edf4c7aebf..91e4c18b891e 100644
--- a/dtc.c
+++ b/dtc.c
@@ -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 */
diff --git a/dtc.h b/dtc.h
index c6f125c68ba8..c4eb6421eabf 100644
--- a/dtc.h
+++ b/dtc.h
@@ -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);
diff --git a/flattree.c b/flattree.c
index ebac548b3fa8..13e4a4a46b6b 100644
--- a/flattree.c
+++ b/flattree.c
@@ -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);
 }
diff --git a/fstree.c b/fstree.c
index ae7d06c3c492..08ee93d26157 100644
--- a/fstree.c
+++ b/fstree.c
@@ -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));
 }
diff --git a/livetree.c b/livetree.c
index afa2f67b142a..dd51223d1e61 100644
--- a/livetree.c
+++ b/livetree.c
@@ -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;
 }
-- 
2.10.0.297.gf6727b0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC/PATCH 2/4] dtc: Add syntactic sugar version of overlays
  2017-01-31  0:02 [RFC/PATCH 0/4] New style overlay and /expansion/ support Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core Stephen Boyd
@ 2017-01-31  0:02 ` Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 3/4] tests: Add a test for overlays syntactic sugar Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 4/4] dtc: Add /expansion/ support Stephen Boyd
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2017-01-31  0:02 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler, Frank Rowand, Pantelis Antoniou,
	Rob Herring, Mark Brown, Grant Likely, Mark Rutland, mporter,
	Koen Kooi, Guenter Roeck, marex, Wolfram Sang, devicetree,
	linux-kernel, linux-i2c

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

Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 dtc.c      |  2 +-
 dtc.h      |  3 ++-
 livetree.c | 40 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/dtc.c b/dtc.c
index 91e4c18b891e..d52d6c77a8cd 100644
--- a/dtc.c
+++ b/dtc.c
@@ -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;
 	}
 }
diff --git a/dtc.h b/dtc.h
index c4eb6421eabf..be75aac1f185 100644
--- a/dtc.h
+++ b/dtc.h
@@ -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);
diff --git a/livetree.c b/livetree.c
index dd51223d1e61..798a87ed587e 100644
--- a/livetree.c
+++ b/livetree.c
@@ -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);
-- 
2.10.0.297.gf6727b0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC/PATCH 3/4] tests: Add a test for overlays syntactic sugar
  2017-01-31  0:02 [RFC/PATCH 0/4] New style overlay and /expansion/ support Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 2/4] dtc: Add syntactic sugar version of overlays Stephen Boyd
@ 2017-01-31  0:02 ` Stephen Boyd
  2017-01-31  0:02 ` [RFC/PATCH 4/4] dtc: Add /expansion/ support Stephen Boyd
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2017-01-31  0:02 UTC (permalink / raw)
  To: David Gibson
  Cc: Pantelis Antoniou, devicetree-compiler, Frank Rowand,
	Rob Herring, Mark Brown, Grant Likely, Mark Rutland, mporter,
	Koen Kooi, Guenter Roeck, marex, Wolfram Sang, devicetree,
	linux-kernel, linux-i2c

From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

Add a single test making sure the &foo { }; syntax works.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
[stephen.boyd@linaro.org: Update test to add required root node]
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 tests/overlay_overlay_simple.dts | 3 +++
 tests/run_tests.sh               | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/tests/overlay_overlay_simple.dts b/tests/overlay_overlay_simple.dts
index 8657e1e7a15a..ab19cc723210 100644
--- a/tests/overlay_overlay_simple.dts
+++ b/tests/overlay_overlay_simple.dts
@@ -7,6 +7,9 @@
 /dts-v1/;
 /plugin/;
 
+/ {
+};
+
 &test {
 	test-int-property = <43>;
 };
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index ed489dbdd269..e2fb084b4434 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -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 () {
-- 
2.10.0.297.gf6727b0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC/PATCH 4/4] dtc: Add /expansion/ support
  2017-01-31  0:02 [RFC/PATCH 0/4] New style overlay and /expansion/ support Stephen Boyd
                   ` (2 preceding siblings ...)
  2017-01-31  0:02 ` [RFC/PATCH 3/4] tests: Add a test for overlays syntactic sugar Stephen Boyd
@ 2017-01-31  0:02 ` Stephen Boyd
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2017-01-31  0:02 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler, Frank Rowand, Pantelis Antoniou,
	Rob Herring, Mark Brown, Grant Likely, Mark Rutland, mporter,
	Koen Kooi, Guenter Roeck, marex, Wolfram Sang, devicetree,
	linux-kernel, linux-i2c

There'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>;
	};

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 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(-)

diff --git a/checks.c b/checks.c
index 3d18e45374c8..44101def69d5 100644
--- a/checks.c
+++ b/checks.c
@@ -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 */
diff --git a/dtc-lexer.l b/dtc-lexer.l
index c600603044f3..c5683e0197ec 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -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();
diff --git a/dtc-parser.y b/dtc-parser.y
index 3d2ce372c286..28de8f6c1b61 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -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:
diff --git a/dtc.c b/dtc.c
index d52d6c77a8cd..8f0b47b53d8c 100644
--- a/dtc.c
+++ b/dtc.c
@@ -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);
diff --git a/dtc.h b/dtc.h
index be75aac1f185..f751757d63f6 100644
--- a/dtc.h
+++ b/dtc.h
@@ -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,
diff --git a/livetree.c b/livetree.c
index 798a87ed587e..f8abb875be8e 100644
--- a/livetree.c
+++ b/livetree.c
@@ -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",
-- 
2.10.0.297.gf6727b0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-31  0:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-31  0:02 [RFC/PATCH 0/4] New style overlay and /expansion/ support Stephen Boyd
2017-01-31  0:02 ` [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core Stephen Boyd
2017-01-31  0:02 ` [RFC/PATCH 2/4] dtc: Add syntactic sugar version of overlays Stephen Boyd
2017-01-31  0:02 ` [RFC/PATCH 3/4] tests: Add a test for overlays syntactic sugar Stephen Boyd
2017-01-31  0:02 ` [RFC/PATCH 4/4] dtc: Add /expansion/ support Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).