From: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Subject: [PATCH 4/4] Create a new property value that means 'undefined'.
Date: Wed, 20 Oct 2010 14:45:22 -0700 [thread overview]
Message-ID: <20101020214522.2985.97224.stgit@riker> (raw)
In-Reply-To: <20101020214419.2985.51068.stgit@riker>
When updating existing nodes in a device tree merge operation, properties
can be removed by setting the value to /undef-prop/.
if /undef-prop/ is assigned to a property that doesn't exist, the property
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 | 14 ++++++++++----
dtc-parser.y | 6 ++++++
dtc.h | 7 +++++++
flattree.c | 3 +++
livetree.c | 38 +++++++++++++++++++++++++++++++++-----
5 files changed, 59 insertions(+), 9 deletions(-)
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 216a3d2..efa89b4 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -102,6 +102,12 @@ static int pop_input_file(void);
return DT_REMOVENODE;
}
+<*>"/undef-prop/" {
+ DPRINT("Keyword: /undef-prop/\n");
+ BEGIN_DEFAULT();
+ return DT_UNDEFINED;
+ }
+
<*>{LABEL}: {
DPRINT("Label: %s\n", yytext);
yylval.labelref = xstrdup(yytext);
@@ -116,10 +122,10 @@ static int pop_input_file(void);
}
-<*>\&{LABEL} { /* label reference without the braces*/
- DPRINT("Ref: %s\n", yytext+1);
- yylval.labelref = xstrdup(yytext+1);
- return DT_REF;
+<*>\&{LABEL} { /* label reference without the braces*/
+ DPRINT("Ref: %s\n", yytext+1);
+ yylval.labelref = xstrdup(yytext+1);
+ return DT_REF;
}
<*>"&{"{LABEL}{PATHCHAR}*\} { /* label and/or path refererence with braces */
diff --git a/dtc-parser.y b/dtc-parser.y
index 0a74c86..ac9cfd7 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -56,6 +56,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits);
%token DT_V1
%token DT_MEMRESERVE
%token DT_REMOVENODE
+%token DT_UNDEFINED
%token <propnodename> DT_PROPNODENAME
%token <literal> DT_LITERAL
%token <cbase> DT_BASE
@@ -178,6 +179,11 @@ propdef:
{
$$ = build_property($1, empty_data);
}
+ | DT_PROPNODENAME '=' DT_UNDEFINED ';'
+ {
+ $$ = build_property($1, empty_data);
+ undefine_property($$)
+ }
| DT_LABEL propdef
{
add_label(&$2->labels, $1);
diff --git a/dtc.h b/dtc.h
index a7f3667..b3fca6e 100644
--- a/dtc.h
+++ b/dtc.h
@@ -130,7 +130,12 @@ struct label {
struct label *next;
};
+#define PROP_DEFINED (0)
+#define PROP_UNDEFINED (1)
+
struct property {
+ int undefined; /* if the property is set to undefined, this feild is
+ set to PROP_UNDEFINED */
char *name;
struct data val;
@@ -170,6 +175,7 @@ void add_label(struct label **labels, char *label);
struct property *build_property(char *name, struct data val);
struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);
+void undefine_property(struct property *prop);
struct node *build_node(struct property *proplist, struct node *children);
struct node *name_node(struct node *node, char *name);
@@ -177,6 +183,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 bf8796b..2ef734d 100644
--- a/livetree.c
+++ b/livetree.c
@@ -51,6 +51,11 @@ struct property *build_property(char *name, struct data val)
return new;
}
+void undefine_property(struct property *prop)
+{
+ prop->undefined = 1;
+}
+
struct property *chain_property(struct property *first, struct property *list)
{
assert(first->next == NULL);
@@ -121,11 +126,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;
@@ -188,6 +197,25 @@ void add_property(struct node *node, struct property *prop)
*p = prop;
}
+void remove_property(struct node *node, struct property *prop)
+{
+ struct property **p;
+ int found = 0;
+
+ p = &node->proplist;
+ while (*p) {
+ if (*p == prop) {
+ *p = (*p)->next;
+ found = 1;
+ break;
+ }
+ p = &((*p)->next);
+ }
+ /* property not in the node? it's probably an error, so flag it. */
+ assert(found);
+}
+
+
void add_child(struct node *parent, struct node *child)
{
struct node **p;
next prev parent reply other threads:[~2010-10-20 21:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-20 21:44 [PATCH 0/4] Series short description John Bonesio
2010-10-20 21:44 ` [PATCH 1/4] Create new and use new print_error that uses printf style formatting John Bonesio
2010-10-21 4:44 ` Grant Likely
[not found] ` <20101021044410.GD13335-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2010-11-13 20:40 ` Jon Loeliger
2010-10-20 21:45 ` [PATCH 2/4] Implements new features for updating existing device tree nodes John Bonesio
2010-10-21 4:47 ` Grant Likely
2010-10-21 5:58 ` David Gibson
2010-10-20 21:45 ` [PATCH 3/4] Allow nodes at the root to be specified by path as well as by label John Bonesio
2010-10-21 4:36 ` Grant Likely
2010-10-21 6:03 ` David Gibson
2010-10-20 21:45 ` John Bonesio [this message]
2010-10-21 5:20 ` [PATCH 4/4] Create a new property value that means 'undefined' Grant Likely
[not found] ` <20101021052053.GF13335-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2010-10-21 6:19 ` David Gibson
2010-10-21 15:20 ` John Bonesio
2010-10-22 0:38 ` David Gibson
2010-10-22 19:42 ` John Bonesio
2010-10-21 6:14 ` David Gibson
2010-10-22 19:50 ` John Bonesio
2010-10-25 0:44 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101020214522.2985.97224.stgit@riker \
--to=bones-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.