devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Series short description
@ 2010-11-02 22:54 John Bonesio
  2010-11-02 22:55 ` [PATCH 1/4] Allow nodes to be refrenced by path at the top level John Bonesio
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: John Bonesio @ 2010-11-02 22:54 UTC (permalink / raw)
  To: glikely-s3s/WqlpOiPyB63q8FvJNQ,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

The following series implements various changes for merging and modifiying
device trees.

The last one is a first stab at making labels from aliases. This way we can
have a consistent syntax for paths from alias and label references:
	&{alias/path/from/alias}
	&{label/path/from/label}

There might be a better approach to implementing this. Once of the constraints
I ended up following was to provide line information when there is an attempt
to re-use a label from a deleted or modified node. This constraint (or
requirement) might not be viewed as important like I think. Removing this might
make the changes easier to implemnt but may make it harder for dts writers to
discover the source of errors.

This last patch doesn't include a test case, though I have tested basic
functionality.

---

John Bonesio (4):
      Allow nodes to be refrenced by path at the top level.
      Implements a new feature for deleting existing device tree nodes.
      Implements a new feature for deleting existing properties in device tree nodes.
      Allow nodes at the root to be specified by path as well as by label.


 Makefile.dtc                    |    1 
 checks.c                        |   20 +++++++
 dtc-lexer.l                     |   38 ++++++++++++-
 dtc-parser.y                    |   86 +++++++++++++++++++++++++++-
 dtc.h                           |   10 +++
 flattree.c                      |    3 +
 livetree.c                      |  118 +++++++++++++++++++++++++++++++++++++--
 tests/dtc-checkfails.sh         |    2 -
 tests/run_tests.sh              |    6 ++
 tests/test_tree1_merge_path.dts |   41 ++++++++++++++
 util.h                          |   10 +++
 11 files changed, 324 insertions(+), 11 deletions(-)
 create mode 100644 tests/test_tree1_merge_path.dts

-- 
Signature

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

* [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
  2010-11-02 22:54 [PATCH 0/4] Series short description John Bonesio
@ 2010-11-02 22:55 ` John Bonesio
  2010-11-04  0:15   ` David Gibson
  2010-11-02 22:55 ` [PATCH 2/4] Implements a new feature for deleting existing device tree nodes John Bonesio
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: John Bonesio @ 2010-11-02 22:55 UTC (permalink / raw)
  To: glikely-s3s/WqlpOiPyB63q8FvJNQ,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

When nodes are modified by merging device trees, nodes to be updated/merged can
be specified by a label. Specifying nodes by full path (instead of label)
doesn't quite work. This patch fixes that.

Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---

 dtc-lexer.l                     |    2 +-
 dtc-parser.y                    |    5 ++---
 tests/run_tests.sh              |    2 ++
 tests/test_tree1_merge_path.dts |   41 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 4 deletions(-)
 create mode 100644 tests/test_tree1_merge_path.dts

diff --git a/dtc-lexer.l b/dtc-lexer.l
index 081e13a..e866ea5 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -115,7 +115,7 @@ static int pop_input_file(void);
 			return DT_REF;
 		}
 
-"&{/"{PATHCHAR}+\}	{	/* new-style path reference */
+<*>"&{/"{PATHCHAR}+\}	{	/* new-style path reference */
 			yytext[yyleng-1] = '\0';
 			DPRINT("Ref: %s\n", yytext+2);
 			yylval.labelref = xstrdup(yytext+2);
diff --git a/dtc-parser.y b/dtc-parser.y
index b58ba8e..5e84a67 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -131,13 +131,12 @@ devicetree:
 		}
 	| devicetree DT_REF nodedef
 		{
-			struct node *target;
+			struct node *target = get_node_by_ref($1, $2);
 
-			target = get_node_by_label($1, $2);
 			if (target)
 				merge_nodes(target, $3);
 			else
-				print_error("label, '%s' not found", $2);
+				print_error("label or path, '%s', not found", $2);
 			$$ = $1;
 		}
 	;
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 77ce80d..a887254 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -305,6 +305,8 @@ dtc_tests () {
     run_dtc_test -I dts -O dtb -o multilabel_merge.test.dtb multilabel_merge.dts
     run_test references multilabel.test.dtb
     run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb
+    run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb test_tree1_merge_path.dts
+    tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
 
     # Check some checks
     check_tests dup-nodename.dts duplicate_node_names
diff --git a/tests/test_tree1_merge_path.dts b/tests/test_tree1_merge_path.dts
new file mode 100644
index 0000000..d68713b
--- /dev/null
+++ b/tests/test_tree1_merge_path.dts
@@ -0,0 +1,41 @@
+/dts-v1/;
+
+/memreserve/ 0xdeadbeef00000000 0x100000;
+/memreserve/ 123456789 010000;
+
+/ {
+	compatible = "test_tree1";
+	prop-int = <0xdeadbeef>;
+	prop-str = "hello world";
+
+	subnode@1 {
+		compatible = "subnode1";
+		prop-int = [deadbeef];
+
+		subsubnode {
+			compatible = "subsubnode1", "subsubnode";
+			prop-int = <0xdeadbeef>;
+		};
+
+		ss1 {
+		};
+	};
+
+	subnode@2 {
+		linux,phandle = <0x2000>;
+		prop-int = <123456789>;
+
+		ssn0: subsubnode@0 {
+			phandle = <0x2001>;
+			prop-int = <0xbad>;
+		};
+
+		ss2 {
+		};
+	};
+};
+
+&{/subnode@2/subsubnode@0} {
+	compatible = "subsubnode2", "subsubnode";
+	prop-int = <0726746425>;
+};

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

* [PATCH 2/4] Implements a new feature for deleting existing device tree nodes.
  2010-11-02 22:54 [PATCH 0/4] Series short description John Bonesio
  2010-11-02 22:55 ` [PATCH 1/4] Allow nodes to be refrenced by path at the top level John Bonesio
@ 2010-11-02 22:55 ` John Bonesio
  2010-11-02 22:55 ` [PATCH 3/4] Implements a new feature for deleting existing properties in " John Bonesio
  2010-11-02 22:55 ` [PATCH 4/4] Allow nodes at the root to be specified by path as well as by label John Bonesio
  3 siblings, 0 replies; 10+ messages in thread
From: John Bonesio @ 2010-11-02 22:55 UTC (permalink / raw)
  To: glikely-s3s/WqlpOiPyB63q8FvJNQ,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

This is interesting when the /include/ "<filename>" feature is used. This way
we can create base device tree source files for a family of systems and modify
the device tree for a specific system.

The current sytem allows an existing node to be extended with new properties
and subnodes.

The new features allow an existing node to be replaced completely by the new
properties and subnodes. The new features also allow an existing node to be
deleted.

Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---

 Makefile.dtc       |    1 +
 checks.c           |   20 ++++++++++++++++++++
 dtc-lexer.l        |    6 ++++++
 dtc-parser.y       |   15 +++++++++++++++
 dtc.h              |    5 +++++
 livetree.c         |   39 +++++++++++++++++++++++++++++++++++++++
 tests/run_tests.sh |    2 ++
 util.h             |   10 ++++++++++
 8 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/Makefile.dtc b/Makefile.dtc
index bece49b..0fe3186 100644
--- a/Makefile.dtc
+++ b/Makefile.dtc
@@ -12,6 +12,7 @@ DTC_SRCS = \
 	livetree.c \
 	srcpos.c \
 	treesource.c \
+	strtbl.c \
 	util.c
 
 DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
diff --git a/checks.c b/checks.c
index a662a00..56e8817 100644
--- a/checks.c
+++ b/checks.c
@@ -19,6 +19,7 @@
  */
 
 #include "dtc.h"
+#include "srcpos.h"
 
 #ifdef TRACE_CHECKS
 #define TRACE(c, ...) \
@@ -292,6 +293,25 @@ static void check_duplicate_label(struct check *c, struct node *dt,
 	struct node *othernode = NULL;
 	struct property *otherprop = NULL;
 	struct marker *othermark = NULL;
+	struct srcpos *pos;
+
+	pos = strtbl_str_data(removed_labels, label);
+
+	if (pos) {
+		/* Then the label did exist, but the node it's in was removed */
+		if (pos->file)
+			FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
+			     " and removed node defined at line %d in file %s",
+			     label, DESCLABEL_ARGS(node, prop, mark),
+			     pos->first_line, pos->file->name);
+		else
+			FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
+			     " and removed node defined at line %d",
+			     label, DESCLABEL_ARGS(node, prop, mark),
+			     pos->first_line);
+	} else {
+		/* Check to see if the label is already in another node */
+	}
 
 	othernode = get_node_by_label(dt, label);
 
diff --git a/dtc-lexer.l b/dtc-lexer.l
index e866ea5..bcabbfe 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -96,6 +96,12 @@ static int pop_input_file(void);
 			return DT_MEMRESERVE;
 		}
 
+<*>"/remove-node/"	{
+			DPRINT("Keyword: /remove-node/\n");
+			BEGIN_DEFAULT();
+			return DT_REMOVENODE;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
diff --git a/dtc-parser.y b/dtc-parser.y
index 5e84a67..4814d34 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -33,6 +33,8 @@ extern void yyerror(char const *s);
 extern struct boot_info *the_boot_info;
 extern int treesource_error;
 
+strtbl label_table = NULL;
+
 static unsigned long long eval_literal(const char *s, int base, int bits);
 %}
 
@@ -55,6 +57,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
 
 %token DT_V1
 %token DT_MEMRESERVE
+%token DT_REMOVENODE
 %token <propnodename> DT_PROPNODENAME
 %token <literal> DT_LITERAL
 %token <cbase> DT_BASE
@@ -108,6 +111,7 @@ memreserve:
 		}
 	| DT_LABEL memreserve
 		{
+			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
 			add_label(&$2->labels, $1);
 			$$ = $2;
 		}
@@ -139,6 +143,15 @@ devicetree:
 				print_error("label or path, '%s', not found", $2);
 			$$ = $1;
 		}
+	| devicetree DT_REMOVENODE DT_REF ';'
+		{
+			struct node *target = get_node_by_ref($1, $3);
+
+			if (target)
+				remove_child(target->parent, target);
+			else
+				print_error("label or path, '%s', not found", $3);
+		}
 	;
 
 nodedef:
@@ -170,6 +183,7 @@ propdef:
 		}
 	| DT_LABEL propdef
 		{
+			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
 			add_label(&$2->labels, $1);
 			$$ = $2;
 		}
@@ -305,6 +319,7 @@ subnode:
 		}
 	| DT_LABEL subnode
 		{
+			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
 			add_label(&$2->labels, $1);
 			$$ = $2;
 		}
diff --git a/dtc.h b/dtc.h
index b36ac5d..95e3bd1 100644
--- a/dtc.h
+++ b/dtc.h
@@ -35,6 +35,7 @@
 #include <fdt.h>
 
 #include "util.h"
+#include "strtbl.h"
 
 #ifdef DEBUG
 #define debug(fmt,args...)	printf(fmt, ##args)
@@ -178,6 +179,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node);
 
 void add_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
+void remove_child(struct node *parent, struct node *child);
 
 const char *get_unitname(struct node *node);
 struct property *get_property(struct node *node, const char *propname);
@@ -221,6 +223,9 @@ struct boot_info {
 struct boot_info *build_boot_info(struct reserve_info *reservelist,
 				  struct node *tree, uint32_t boot_cpuid_phys);
 
+extern strtbl label_table;
+extern strtbl removed_labels;
+
 /* Checks */
 
 void process_checks(int force, struct boot_info *bi);
diff --git a/livetree.c b/livetree.c
index 13c5f10..88de3c3 100644
--- a/livetree.c
+++ b/livetree.c
@@ -20,6 +20,8 @@
 
 #include "dtc.h"
 
+strtbl removed_labels = NULL;
+
 /*
  * Tree building functions
  */
@@ -202,6 +204,43 @@ void add_child(struct node *parent, struct node *child)
 	*p = child;
 }
 
+void remove_child(struct node *parent, struct node *child)
+{
+	struct node **p;
+	struct property *prop;
+	struct label *l;
+	void *data;
+
+	/* Make sure we've got a consistent tree here */
+	assert(child->parent == parent);
+
+	/* Keep track of removed node labels, maintaining the original
+	 * data associated with the label collected by the parser */
+	for_each_label(child->labels, l) {
+		data = strtbl_str_data(label_table, l->label);
+		strtbl_insert(&removed_labels, l->label, data);
+	}
+
+	/* Keep track of removed property labels, maintaining the original
+	 * data associated with the label collected by the parser */
+	for_each_property(child, prop) {
+		for_each_label(prop->labels, l) {
+			data = strtbl_str_data(label_table, l->label);
+			strtbl_insert(&removed_labels, l->label, data);
+		}
+	}
+
+	p = &parent->children;
+	while (*p) {
+		if (*p == child) {
+			*p = (*p)->next_sibling;
+			break;
+		}
+		p = &((*p)->next_sibling);
+	}
+	child->parent = NULL;
+}
+
 struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size)
 {
 	struct reserve_info *new = xmalloc(sizeof(*new));
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index a887254..495e759 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -307,6 +307,8 @@ dtc_tests () {
     run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb
     run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb test_tree1_merge_path.dts
     tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
+    run_dtc_test -I dts -O dtb -o dtc_tree1_merge_remove.test.dtb test_tree1_merge_remove.dts
+    tree1_tests dtc_tree1_merge_remove.test.dtb test_tree1.dtb
 
     # Check some checks
     check_tests dup-nodename.dts duplicate_node_names
diff --git a/util.h b/util.h
index 9cead84..b544cbc 100644
--- a/util.h
+++ b/util.h
@@ -40,6 +40,16 @@ static inline void *xmalloc(size_t len)
 	return new;
 }
 
+static inline void *xcalloc(size_t nmemb, size_t len) {
+	void *new = calloc(nmemb, len);
+
+	if (!new)
+		die("calloc() failed\n");
+
+	return new;
+}
+
+
 static inline void *xrealloc(void *p, size_t len)
 {
 	void *new = realloc(p, len);

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

* [PATCH 3/4] Implements a new feature for deleting existing properties in device tree nodes.
  2010-11-02 22:54 [PATCH 0/4] Series short description John Bonesio
  2010-11-02 22:55 ` [PATCH 1/4] Allow nodes to be refrenced by path at the top level John Bonesio
  2010-11-02 22:55 ` [PATCH 2/4] Implements a new feature for deleting existing device tree nodes John Bonesio
@ 2010-11-02 22:55 ` John Bonesio
  2010-11-02 22:55 ` [PATCH 4/4] Allow nodes at the root to be specified by path as well as by label John Bonesio
  3 siblings, 0 replies; 10+ messages in thread
From: John Bonesio @ 2010-11-02 22:55 UTC (permalink / raw)
  To: glikely-s3s/WqlpOiPyB63q8FvJNQ,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

When updating existing nodes in a device tree merge operation, properties
can be removed by using
	/remove-prop/ <property>;

If a property has been removed, it is treated the same as if it had not been
declared.

Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---

 dtc-lexer.l             |    6 ++++++
 dtc-parser.y            |    6 ++++++
 dtc.h                   |    3 +++
 flattree.c              |    3 +++
 livetree.c              |   31 ++++++++++++++++++++++++++-----
 tests/dtc-checkfails.sh |    2 +-
 tests/run_tests.sh      |    2 ++
 7 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index bcabbfe..4b07236 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -102,6 +102,12 @@ static int pop_input_file(void);
 			return DT_REMOVENODE;
 		}
 
+<*>"/remove-prop/"	{
+			DPRINT("Keyword: /undef-prop/\n");
+			BEGIN(PROPNODENAME);
+			return DT_REMOVEPROP;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
diff --git a/dtc-parser.y b/dtc-parser.y
index 4814d34..2a9736a 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -58,6 +58,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
 %token DT_V1
 %token DT_MEMRESERVE
 %token DT_REMOVENODE
+%token <propnodename> DT_REMOVEPROP
 %token <propnodename> DT_PROPNODENAME
 %token <literal> DT_LITERAL
 %token <cbase> DT_BASE
@@ -181,6 +182,11 @@ propdef:
 		{
 			$$ = build_property($1, empty_data);
 		}
+	| DT_REMOVEPROP propdef
+		{
+			$2->undefined = 1;
+			$$ = $2;
+		}
 	| DT_LABEL propdef
 		{
 			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
diff --git a/dtc.h b/dtc.h
index 95e3bd1..764b3a9 100644
--- a/dtc.h
+++ b/dtc.h
@@ -132,6 +132,8 @@ struct label {
 };
 
 struct property {
+	int undefined;  /* when this feild is set to 1, the property is to be
+	                   treated as undefined */
 	char *name;
 	struct data val;
 
@@ -178,6 +180,7 @@ struct node *chain_node(struct node *first, struct node *list);
 struct node *merge_nodes(struct node *old_node, struct node *new_node);
 
 void add_property(struct node *node, struct property *prop);
+void remove_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
 void remove_child(struct node *parent, struct node *child);
 
diff --git a/flattree.c b/flattree.c
index ead0332..00439e9 100644
--- a/flattree.c
+++ b/flattree.c
@@ -275,6 +275,9 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 	for_each_property(tree, prop) {
 		int nameoff;
 
+		if (prop->undefined)
+			continue;
+
 		if (streq(prop->name, "name"))
 			seen_name_prop = 1;
 
diff --git a/livetree.c b/livetree.c
index 88de3c3..f1b235c 100644
--- a/livetree.c
+++ b/livetree.c
@@ -123,11 +123,15 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
 		/* Look for a collision, set new value if there is */
 		for_each_property(old_node, old_prop) {
 			if (streq(old_prop->name, new_prop->name)) {
-				/* Add new labels to old property */
-				for_each_label(new_prop->labels, l)
-					add_label(&old_prop->labels, l->label);
-
-				old_prop->val = new_prop->val;
+				if (new_prop->undefined) {
+					remove_property(old_node, old_prop);
+				} else {
+					/* Add new labels to old property */
+					for_each_label(new_prop->labels, l)
+						add_label(&old_prop->labels, l->label);
+
+					old_prop->val = new_prop->val;
+				}
 				free(new_prop);
 				new_prop = NULL;
 				break;
@@ -190,6 +194,23 @@ void add_property(struct node *node, struct property *prop)
 	*p = prop;
 }
 
+void remove_property(struct node *node, struct property *prop)
+{
+	struct property **p;
+
+	p = &node->proplist;
+	while (*p) {
+		if (*p == prop) {
+			*p = (*p)->next;
+			return;
+		}
+		p = &((*p)->next);
+	}
+	/* property not in the node? it's probably an error, so flag it. */
+	assert(0);
+}
+
+
 void add_child(struct node *parent, struct node *child)
 {
 	struct node **p;
diff --git a/tests/dtc-checkfails.sh b/tests/dtc-checkfails.sh
index c58694f..a13eb28 100755
--- a/tests/dtc-checkfails.sh
+++ b/tests/dtc-checkfails.sh
@@ -23,7 +23,7 @@ if [ "$ret" -gt 127 ]; then
 fi
 
 for c in $CHECKS; do
-    if ! grep -E "^(ERROR)|(Warning) \($c\):" $LOG > /dev/null; then
+    if ! grep -E "^(ERROR)|(Error)|(Warning) \($c\):" $LOG > /dev/null; then
 	FAIL "Failed to trigger check \"$c\""
     fi
 done
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 495e759..912a19b 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -309,6 +309,8 @@ dtc_tests () {
     tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
     run_dtc_test -I dts -O dtb -o dtc_tree1_merge_remove.test.dtb test_tree1_merge_remove.dts
     tree1_tests dtc_tree1_merge_remove.test.dtb test_tree1.dtb
+    run_dtc_test -I dts -O dtb -o dtc_tree1_merge_remove_prop.test.dtb test_tree1_merge_remove_prop.dts
+    tree1_tests dtc_tree1_merge_remove_prop.test.dtb test_tree1.dtb
 
     # Check some checks
     check_tests dup-nodename.dts duplicate_node_names

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

* [PATCH 4/4] Allow nodes at the root to be specified by path as well as by label.
  2010-11-02 22:54 [PATCH 0/4] Series short description John Bonesio
                   ` (2 preceding siblings ...)
  2010-11-02 22:55 ` [PATCH 3/4] Implements a new feature for deleting existing properties in " John Bonesio
@ 2010-11-02 22:55 ` John Bonesio
  3 siblings, 0 replies; 10+ messages in thread
From: John Bonesio @ 2010-11-02 22:55 UTC (permalink / raw)
  To: glikely-s3s/WqlpOiPyB63q8FvJNQ,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

Changes to allow us to specify a node by it's path. A path can be used in
place of a label.

This is particularly useful when overriding existing nodes.
This way we don't have to label every possible node in a device tree we know
is a base device tree for a class of systems, and we know the tree will be
modified for the specific systems.

Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---

 dtc-lexer.l  |   24 +++++++++++++++++++++++
 dtc-parser.y |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dtc.h        |    2 ++
 livetree.c   |   48 +++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 133 insertions(+), 1 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index 4b07236..087a51f 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -127,6 +127,23 @@ static int pop_input_file(void);
 			return DT_REF;
 		}
 
+<*>"&{"{LABEL}{PATHCHAR}*\} { /* label and/or path refererence with braces */
+			/*
+			 * Possibly this could be parsed by the parser rather
+			 * than as a lexical element.
+			 *
+			 * What is intended here is to support the following
+			 * type of references:
+			 * a) &{/path/to/the/node/reference}
+			 * b) &{label}
+			 * c) &{label/path/from/labeled/node/to/reference}
+			 */
+			yytext[yyleng-1] = '\0';
+			DPRINT("Ref: %s\n", yytext+2);
+			yylval.labelref = xstrdup(yytext+2);
+			return DT_REF;
+		}
+
 <*>"&{/"{PATHCHAR}+\}	{	/* new-style path reference */
 			yytext[yyleng-1] = '\0';
 			DPRINT("Ref: %s\n", yytext+2);
@@ -146,6 +163,13 @@ static int pop_input_file(void);
 			return ']';
 		}
 
+<PROPNODENAME>"aliases" {
+			DPRINT("Aliases: %s\n", yytext);
+			yylval.propnodename = xstrdup(yytext);
+			BEGIN_DEFAULT();
+			return DT_ALIASES;
+		}
+
 <PROPNODENAME>{PROPNODECHAR}+ {
 			DPRINT("PropNodeName: %s\n", yytext);
 			yylval.propnodename = xstrdup(yytext);
diff --git a/dtc-parser.y b/dtc-parser.y
index 2a9736a..8718f07 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -60,6 +60,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
 %token DT_REMOVENODE
 %token <propnodename> DT_REMOVEPROP
 %token <propnodename> DT_PROPNODENAME
+%token <propnodename> DT_ALIASES
 %token <literal> DT_LITERAL
 %token <cbase> DT_BASE
 %token <byte> DT_BYTE
@@ -77,10 +78,13 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
 %type <cell> cellval
 %type <data> bytestring
 %type <prop> propdef
+%type <prop> aliasespropdef
 %type <proplist> proplist
+%type <proplist> aliasesproplist
 
 %type <node> devicetree
 %type <node> nodedef
+%type <node> aliasesnodedef
 %type <node> subnode
 %type <nodelist> subnodes
 
@@ -128,11 +132,33 @@ addr:
 devicetree:
 	  '/' nodedef
 		{
+			/*
+			 * We need to wait until the whole tree is parsed so we
+			 * can assign aliases as labels on forward reference
+			 * nodes.
+			 */
+			struct node *aliases_node = get_node_by_ref($2, "/aliases");
+
+			if (aliases_node) {
+				make_aliases_labels($2, aliases_node);
+			}
+
 			$$ = name_node($2, "");
 		}
 	| devicetree '/' nodedef
 		{
 			$$ = merge_nodes($1, $3);
+
+			/*
+			 * We need to wait until the whole tree is parsed so we
+			 * can assign aliases as labels on forward reference
+			 * nodes.
+			 */
+			struct node *aliases_node = get_node_by_ref($$, "/aliases");
+
+			if (aliases_node) {
+				make_aliases_labels($$, aliases_node);
+			}
 		}
 	| devicetree DT_REF nodedef
 		{
@@ -162,6 +188,13 @@ nodedef:
 		}
 	;
 
+aliasesnodedef:
+	  '{' aliasesproplist '}' ';'
+		{
+			$$ = build_node($2, NULL);
+		}
+	;
+
 proplist:
 	  /* empty */
 		{
@@ -173,6 +206,17 @@ proplist:
 		}
 	;
 
+aliasesproplist:
+	  /* empty */
+		{
+			$$ = NULL;
+		}
+	| aliasesproplist aliasespropdef
+		{
+			$$ = chain_property($2, $1);
+		}
+	;
+
 propdef:
 	  DT_PROPNODENAME '=' propdata ';'
 		{
@@ -195,6 +239,18 @@ propdef:
 		}
 	;
 
+aliasespropdef:
+	  DT_PROPNODENAME '=' DT_REF ';'
+		{
+			struct data d = empty_data;
+
+			d = data_add_marker(d, REF_PATH, $3);
+			$$ = build_property($1, d);
+
+			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
+		}
+	;
+
 propdata:
 	  propdataprefix DT_STRING
 		{
@@ -323,6 +379,10 @@ subnode:
 		{
 			$$ = name_node($2, $1);
 		}
+	| DT_ALIASES aliasesnodedef
+		{
+			$$ = name_node($2, "aliases");
+		}
 	| DT_LABEL subnode
 		{
 			strtbl_insert(&label_table, $1, srcpos_copy(&yylloc));
diff --git a/dtc.h b/dtc.h
index 764b3a9..1c3632c 100644
--- a/dtc.h
+++ b/dtc.h
@@ -179,6 +179,8 @@ 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 make_aliases_labels(struct node *root, struct node *aliases);
+
 void add_property(struct node *node, struct property *prop);
 void remove_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
diff --git a/livetree.c b/livetree.c
index f1b235c..357d762 100644
--- a/livetree.c
+++ b/livetree.c
@@ -473,8 +473,54 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
 {
 	if (ref[0] == '/')
 		return get_node_by_path(tree, ref);
-	else
+	else {
+		/*
+		 * Support finding a node reference that is rooted by
+		 * a label reference.
+		 *
+		 * References rooted by a label have a '/' in them.
+		 */
+		char *ref_cpy = xstrdup(ref);
+		char *p = strchr(ref_cpy, '/');
+		struct node *node;
+
+		if (p) {
+			*p = '\0';
+			node = get_node_by_label(tree, ref_cpy);
+			*p = '/';
+			node = get_node_by_path(node, p+1);
+
+			free(ref_cpy);
+
+			return node;
+		}
+
 		return get_node_by_label(tree, ref);
+	}
+}
+
+void make_aliases_labels(struct node *root, struct node *aliases) {
+	struct property *prop;
+	
+	for_each_property(aliases, prop) {
+		struct marker *m = prop->val.markers;
+		struct node *refnode;
+
+		for_each_marker_of_type(m, REF_PATH) {
+			refnode = get_node_by_ref(root, m->ref);
+			if (refnode)
+				/*
+				 * Right here we might be insertting labels
+				 * with illegal characters, but we won't be
+				 * able to reference them in the dts file
+				 * (sytnax error).
+				 *
+				 * We could possibly check for this and spit
+				 * out a warning.
+				 */
+				add_label(&refnode->labels, prop->name);
+		}
+	}
 }
 
 cell_t get_node_phandle(struct node *root, struct node *node)

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

* Re: [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
  2010-11-02 22:55 ` [PATCH 1/4] Allow nodes to be refrenced by path at the top level John Bonesio
@ 2010-11-04  0:15   ` David Gibson
  2010-11-09 16:33     ` Jon Loeliger
  0 siblings, 1 reply; 10+ messages in thread
From: David Gibson @ 2010-11-04  0:15 UTC (permalink / raw)
  To: John Bonesio
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	glikely-s3s/WqlpOiPyB63q8FvJNQ

On Tue, Nov 02, 2010 at 03:55:04PM -0700, John Bonesio wrote:
> When nodes are modified by merging device trees, nodes to be updated/merged can
> be specified by a label. Specifying nodes by full path (instead of label)
> doesn't quite work. This patch fixes that.
> 
> Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>

If we go where I'm beginning to suspect we want to with deprecating
some existing syntax, this may become moot.  However as long as we're
using reference like syntax for the merging, we should accept all the
references that are valid elsewhere.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

* Re: [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
  2010-11-04  0:15   ` David Gibson
@ 2010-11-09 16:33     ` Jon Loeliger
       [not found]       ` <E1PFr8Q-0003CF-52-CYoMK+44s/E@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Jon Loeliger @ 2010-11-09 16:33 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	glikely-s3s/WqlpOiPyB63q8FvJNQ

> On Tue, Nov 02, 2010 at 03:55:04PM -0700, John Bonesio wrote:
> > When nodes are modified by merging device trees, nodes to be updated/merged
>  can
> > be specified by a label. Specifying nodes by full path (instead of label)
> > doesn't quite work. This patch fixes that.
> > 
> > Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> 
> Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
> 
> If we go where I'm beginning to suspect we want to with deprecating
> some existing syntax, this may become moot.  However as long as we're
> using reference like syntax for the merging, we should accept all the
> references that are valid elsewhere.

Are we read for just this patch, or the series?
I didn't see any more commentary about the remaining 3 patches.

Thanks,
jdl

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

* Re: [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
       [not found]       ` <E1PFr8Q-0003CF-52-CYoMK+44s/E@public.gmane.org>
@ 2010-11-09 16:44         ` Grant Likely
       [not found]           ` <AANLkTim3TopcXUcdJ1kGBwHYTNjL=SdhBaaZgnrWQG-a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Grant Likely @ 2010-11-09 16:44 UTC (permalink / raw)
  To: Jon Loeliger; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On Tue, Nov 9, 2010 at 9:33 AM, Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org> wrote:
>> On Tue, Nov 02, 2010 at 03:55:04PM -0700, John Bonesio wrote:
>> > When nodes are modified by merging device trees, nodes to be updated/merged
>>  can
>> > be specified by a label. Specifying nodes by full path (instead of label)
>> > doesn't quite work. This patch fixes that.
>> >
>> > Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>>
>> Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
>>
>> If we go where I'm beginning to suspect we want to with deprecating
>> some existing syntax, this may become moot.  However as long as we're
>> using reference like syntax for the merging, we should accept all the
>> references that are valid elsewhere.
>
> Are we read for just this patch, or the series?
> I didn't see any more commentary about the remaining 3 patches.

Hold off on the remaining three.  Also, this patch is based on the
commits currently in my tree which have also been acked:

git://git.secretlab.ca/git/dtc.git master

g.

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

* Re: [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
       [not found]           ` <AANLkTim3TopcXUcdJ1kGBwHYTNjL=SdhBaaZgnrWQG-a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-11-09 22:42             ` David Gibson
  2010-11-13 20:49             ` Jon Loeliger
  1 sibling, 0 replies; 10+ messages in thread
From: David Gibson @ 2010-11-09 22:42 UTC (permalink / raw)
  To: Grant Likely; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On Tue, Nov 09, 2010 at 09:44:22AM -0700, Grant Likely wrote:
> On Tue, Nov 9, 2010 at 9:33 AM, Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org> wrote:
> >> On Tue, Nov 02, 2010 at 03:55:04PM -0700, John Bonesio wrote:
> >> > When nodes are modified by merging device trees, nodes to be updated/merged
> >>  can
> >> > be specified by a label. Specifying nodes by full path (instead of label)
> >> > doesn't quite work. This patch fixes that.
> >> >
> >> > Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> >>
> >> Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
> >>
> >> If we go where I'm beginning to suspect we want to with deprecating
> >> some existing syntax, this may become moot.  However as long as we're
> >> using reference like syntax for the merging, we should accept all the
> >> references that are valid elsewhere.
> >
> > Are we read for just this patch, or the series?
> > I didn't see any more commentary about the remaining 3 patches.
> 
> Hold off on the remaining three.  Also, this patch is based on the
> commits currently in my tree which have also been acked:
> 
> git://git.secretlab.ca/git/dtc.git master

Yeah, what Grant said.  I'm happy with patch 1/4, but the others need
more discussion / work.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

* Re: [PATCH 1/4] Allow nodes to be refrenced by path at the top level.
       [not found]           ` <AANLkTim3TopcXUcdJ1kGBwHYTNjL=SdhBaaZgnrWQG-a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2010-11-09 22:42             ` David Gibson
@ 2010-11-13 20:49             ` Jon Loeliger
  1 sibling, 0 replies; 10+ messages in thread
From: Jon Loeliger @ 2010-11-13 20:49 UTC (permalink / raw)
  To: Grant Likely; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

> On Tue, Nov 9, 2010 at 9:33 AM, Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org> wrote:
> >> On Tue, Nov 02, 2010 at 03:55:04PM -0700, John Bonesio wrote:
> >> > When nodes are modified by merging device trees, nodes to be updated/m=
> erged
> >> =A0can
> >> > be specified by a label. Specifying nodes by full path (instead of lab=
> el)
> >> > doesn't quite work. This patch fixes that.
> >> >
> >> > Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> >>
> >> Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
> >>
> >> If we go where I'm beginning to suspect we want to with deprecating
> >> some existing syntax, this may become moot. =A0However as long as we're
> >> using reference like syntax for the merging, we should accept all the
> >> references that are valid elsewhere.
> >
> > Are we read for just this patch, or the series?
> > I didn't see any more commentary about the remaining 3 patches.
> 
> Hold off on the remaining three.  Also, this patch is based on the
> commits currently in my tree which have also been acked:
> 
> git://git.secretlab.ca/git/dtc.git master
> 
> g.

Patch 1/4 in this series applied and pushed out
along with Patch 1/4 from the previous series:
    Create new and use new print_error that uses printf style formatting.

Thanks,
jdl

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

end of thread, other threads:[~2010-11-13 20:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-02 22:54 [PATCH 0/4] Series short description John Bonesio
2010-11-02 22:55 ` [PATCH 1/4] Allow nodes to be refrenced by path at the top level John Bonesio
2010-11-04  0:15   ` David Gibson
2010-11-09 16:33     ` Jon Loeliger
     [not found]       ` <E1PFr8Q-0003CF-52-CYoMK+44s/E@public.gmane.org>
2010-11-09 16:44         ` Grant Likely
     [not found]           ` <AANLkTim3TopcXUcdJ1kGBwHYTNjL=SdhBaaZgnrWQG-a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-11-09 22:42             ` David Gibson
2010-11-13 20:49             ` Jon Loeliger
2010-11-02 22:55 ` [PATCH 2/4] Implements a new feature for deleting existing device tree nodes John Bonesio
2010-11-02 22:55 ` [PATCH 3/4] Implements a new feature for deleting existing properties in " John Bonesio
2010-11-02 22:55 ` [PATCH 4/4] Allow nodes at the root to be specified by path as well as by label John Bonesio

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