diff options
author | Stephen Warren <swarren@nvidia.com> | 2012-09-28 17:25:59 -0400 |
---|---|---|
committer | Rob Herring <rob.herring@calxeda.com> | 2012-10-01 12:11:35 -0400 |
commit | cd296721a9645f9f28800a072490fa15458d1fb7 (patch) | |
tree | 492b9a268a48af07844fbbd39519f95676ee73fe /scripts/dtc/livetree.c | |
parent | acc2097934b5403b97f95763fe99fc115b818061 (diff) |
dtc: import latest upstream dtc
This updates scripts/dtc to commit 317a5d9 "dtc: zero out new label
objects" from git://git.jdl.com/software/dtc.git.
This adds features such as:
* /bits/ syntax for cell data.
* Math expressions within cell data.
* The ability to delete properties or nodes.
* Support for #line directives in the input file, which allows the use of
cpp on *.dts.
* -i command-line option (/include/ path)
* -W/-E command-line options for error/warning control.
* Removal of spew to STDOUT containing the filename being compiled.
* Many additions to the libfdt API.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Jon Loeliger <jdl@jdl.com>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Diffstat (limited to 'scripts/dtc/livetree.c')
-rw-r--r-- | scripts/dtc/livetree.c | 128 |
1 files changed, 114 insertions, 14 deletions
diff --git a/scripts/dtc/livetree.c b/scripts/dtc/livetree.c index 26d0e1e60c0c..b61465fb2f33 100644 --- a/scripts/dtc/livetree.c +++ b/scripts/dtc/livetree.c | |||
@@ -29,16 +29,27 @@ void add_label(struct label **labels, char *label) | |||
29 | struct label *new; | 29 | struct label *new; |
30 | 30 | ||
31 | /* Make sure the label isn't already there */ | 31 | /* Make sure the label isn't already there */ |
32 | for_each_label(*labels, new) | 32 | for_each_label_withdel(*labels, new) |
33 | if (streq(new->label, label)) | 33 | if (streq(new->label, label)) { |
34 | new->deleted = 0; | ||
34 | return; | 35 | return; |
36 | } | ||
35 | 37 | ||
36 | new = xmalloc(sizeof(*new)); | 38 | new = xmalloc(sizeof(*new)); |
39 | memset(new, 0, sizeof(*new)); | ||
37 | new->label = label; | 40 | new->label = label; |
38 | new->next = *labels; | 41 | new->next = *labels; |
39 | *labels = new; | 42 | *labels = new; |
40 | } | 43 | } |
41 | 44 | ||
45 | void delete_labels(struct label **labels) | ||
46 | { | ||
47 | struct label *label; | ||
48 | |||
49 | for_each_label(*labels, label) | ||
50 | label->deleted = 1; | ||
51 | } | ||
52 | |||
42 | struct property *build_property(char *name, struct data val) | 53 | struct property *build_property(char *name, struct data val) |
43 | { | 54 | { |
44 | struct property *new = xmalloc(sizeof(*new)); | 55 | struct property *new = xmalloc(sizeof(*new)); |
@@ -51,6 +62,18 @@ struct property *build_property(char *name, struct data val) | |||
51 | return new; | 62 | return new; |
52 | } | 63 | } |
53 | 64 | ||
65 | struct property *build_property_delete(char *name) | ||
66 | { | ||
67 | struct property *new = xmalloc(sizeof(*new)); | ||
68 | |||
69 | memset(new, 0, sizeof(*new)); | ||
70 | |||
71 | new->name = name; | ||
72 | new->deleted = 1; | ||
73 | |||
74 | return new; | ||
75 | } | ||
76 | |||
54 | struct property *chain_property(struct property *first, struct property *list) | 77 | struct property *chain_property(struct property *first, struct property *list) |
55 | { | 78 | { |
56 | assert(first->next == NULL); | 79 | assert(first->next == NULL); |
@@ -91,6 +114,17 @@ struct node *build_node(struct property *proplist, struct node *children) | |||
91 | return new; | 114 | return new; |
92 | } | 115 | } |
93 | 116 | ||
117 | struct node *build_node_delete(void) | ||
118 | { | ||
119 | struct node *new = xmalloc(sizeof(*new)); | ||
120 | |||
121 | memset(new, 0, sizeof(*new)); | ||
122 | |||
123 | new->deleted = 1; | ||
124 | |||
125 | return new; | ||
126 | } | ||
127 | |||
94 | struct node *name_node(struct node *node, char *name) | 128 | struct node *name_node(struct node *node, char *name) |
95 | { | 129 | { |
96 | assert(node->name == NULL); | 130 | assert(node->name == NULL); |
@@ -106,8 +140,10 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node) | |||
106 | struct node *new_child, *old_child; | 140 | struct node *new_child, *old_child; |
107 | struct label *l; | 141 | struct label *l; |
108 | 142 | ||
143 | old_node->deleted = 0; | ||
144 | |||
109 | /* Add new node labels to old node */ | 145 | /* Add new node labels to old node */ |
110 | for_each_label(new_node->labels, l) | 146 | for_each_label_withdel(new_node->labels, l) |
111 | add_label(&old_node->labels, l->label); | 147 | add_label(&old_node->labels, l->label); |
112 | 148 | ||
113 | /* Move properties from the new node to the old node. If there | 149 | /* Move properties from the new node to the old node. If there |
@@ -118,14 +154,21 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node) | |||
118 | new_node->proplist = new_prop->next; | 154 | new_node->proplist = new_prop->next; |
119 | new_prop->next = NULL; | 155 | new_prop->next = NULL; |
120 | 156 | ||
157 | if (new_prop->deleted) { | ||
158 | delete_property_by_name(old_node, new_prop->name); | ||
159 | free(new_prop); | ||
160 | continue; | ||
161 | } | ||
162 | |||
121 | /* Look for a collision, set new value if there is */ | 163 | /* Look for a collision, set new value if there is */ |
122 | for_each_property(old_node, old_prop) { | 164 | for_each_property_withdel(old_node, old_prop) { |
123 | if (streq(old_prop->name, new_prop->name)) { | 165 | if (streq(old_prop->name, new_prop->name)) { |
124 | /* Add new labels to old property */ | 166 | /* Add new labels to old property */ |
125 | for_each_label(new_prop->labels, l) | 167 | for_each_label_withdel(new_prop->labels, l) |
126 | add_label(&old_prop->labels, l->label); | 168 | add_label(&old_prop->labels, l->label); |
127 | 169 | ||
128 | old_prop->val = new_prop->val; | 170 | old_prop->val = new_prop->val; |
171 | old_prop->deleted = 0; | ||
129 | free(new_prop); | 172 | free(new_prop); |
130 | new_prop = NULL; | 173 | new_prop = NULL; |
131 | break; | 174 | break; |
@@ -146,8 +189,14 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node) | |||
146 | new_child->parent = NULL; | 189 | new_child->parent = NULL; |
147 | new_child->next_sibling = NULL; | 190 | new_child->next_sibling = NULL; |
148 | 191 | ||
192 | if (new_child->deleted) { | ||
193 | delete_node_by_name(old_node, new_child->name); | ||
194 | free(new_child); | ||
195 | continue; | ||
196 | } | ||
197 | |||
149 | /* Search for a collision. Merge if there is */ | 198 | /* Search for a collision. Merge if there is */ |
150 | for_each_child(old_node, old_child) { | 199 | for_each_child_withdel(old_node, old_child) { |
151 | if (streq(old_child->name, new_child->name)) { | 200 | if (streq(old_child->name, new_child->name)) { |
152 | merge_nodes(old_child, new_child); | 201 | merge_nodes(old_child, new_child); |
153 | new_child = NULL; | 202 | new_child = NULL; |
@@ -155,7 +204,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node) | |||
155 | } | 204 | } |
156 | } | 205 | } |
157 | 206 | ||
158 | /* if no collision occurred, add child to the old node. */ | 207 | /* if no collision occured, add child to the old node. */ |
159 | if (new_child) | 208 | if (new_child) |
160 | add_child(old_node, new_child); | 209 | add_child(old_node, new_child); |
161 | } | 210 | } |
@@ -188,6 +237,25 @@ void add_property(struct node *node, struct property *prop) | |||
188 | *p = prop; | 237 | *p = prop; |
189 | } | 238 | } |
190 | 239 | ||
240 | void delete_property_by_name(struct node *node, char *name) | ||
241 | { | ||
242 | struct property *prop = node->proplist; | ||
243 | |||
244 | while (prop) { | ||
245 | if (!strcmp(prop->name, name)) { | ||
246 | delete_property(prop); | ||
247 | return; | ||
248 | } | ||
249 | prop = prop->next; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | void delete_property(struct property *prop) | ||
254 | { | ||
255 | prop->deleted = 1; | ||
256 | delete_labels(&prop->labels); | ||
257 | } | ||
258 | |||
191 | void add_child(struct node *parent, struct node *child) | 259 | void add_child(struct node *parent, struct node *child) |
192 | { | 260 | { |
193 | struct node **p; | 261 | struct node **p; |
@@ -202,6 +270,32 @@ void add_child(struct node *parent, struct node *child) | |||
202 | *p = child; | 270 | *p = child; |
203 | } | 271 | } |
204 | 272 | ||
273 | void delete_node_by_name(struct node *parent, char *name) | ||
274 | { | ||
275 | struct node *node = parent->children; | ||
276 | |||
277 | while (node) { | ||
278 | if (!strcmp(node->name, name)) { | ||
279 | delete_node(node); | ||
280 | return; | ||
281 | } | ||
282 | node = node->next_sibling; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | void delete_node(struct node *node) | ||
287 | { | ||
288 | struct property *prop; | ||
289 | struct node *child; | ||
290 | |||
291 | node->deleted = 1; | ||
292 | for_each_child(node, child) | ||
293 | delete_node(child); | ||
294 | for_each_property(node, prop) | ||
295 | delete_property(prop); | ||
296 | delete_labels(&node->labels); | ||
297 | } | ||
298 | |||
205 | struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size) | 299 | struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size) |
206 | { | 300 | { |
207 | struct reserve_info *new = xmalloc(sizeof(*new)); | 301 | struct reserve_info *new = xmalloc(sizeof(*new)); |
@@ -353,8 +447,11 @@ struct node *get_node_by_path(struct node *tree, const char *path) | |||
353 | const char *p; | 447 | const char *p; |
354 | struct node *child; | 448 | struct node *child; |
355 | 449 | ||
356 | if (!path || ! (*path)) | 450 | if (!path || ! (*path)) { |
451 | if (tree->deleted) | ||
452 | return NULL; | ||
357 | return tree; | 453 | return tree; |
454 | } | ||
358 | 455 | ||
359 | while (path[0] == '/') | 456 | while (path[0] == '/') |
360 | path++; | 457 | path++; |
@@ -397,8 +494,11 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle) | |||
397 | 494 | ||
398 | assert((phandle != 0) && (phandle != -1)); | 495 | assert((phandle != 0) && (phandle != -1)); |
399 | 496 | ||
400 | if (tree->phandle == phandle) | 497 | if (tree->phandle == phandle) { |
498 | if (tree->deleted) | ||
499 | return NULL; | ||
401 | return tree; | 500 | return tree; |
501 | } | ||
402 | 502 | ||
403 | for_each_child(tree, child) { | 503 | for_each_child(tree, child) { |
404 | node = get_node_by_phandle(child, phandle); | 504 | node = get_node_by_phandle(child, phandle); |
@@ -535,7 +635,7 @@ static void sort_properties(struct node *node) | |||
535 | int n = 0, i = 0; | 635 | int n = 0, i = 0; |
536 | struct property *prop, **tbl; | 636 | struct property *prop, **tbl; |
537 | 637 | ||
538 | for_each_property(node, prop) | 638 | for_each_property_withdel(node, prop) |
539 | n++; | 639 | n++; |
540 | 640 | ||
541 | if (n == 0) | 641 | if (n == 0) |
@@ -543,7 +643,7 @@ static void sort_properties(struct node *node) | |||
543 | 643 | ||
544 | tbl = xmalloc(n * sizeof(*tbl)); | 644 | tbl = xmalloc(n * sizeof(*tbl)); |
545 | 645 | ||
546 | for_each_property(node, prop) | 646 | for_each_property_withdel(node, prop) |
547 | tbl[i++] = prop; | 647 | tbl[i++] = prop; |
548 | 648 | ||
549 | qsort(tbl, n, sizeof(*tbl), cmp_prop); | 649 | qsort(tbl, n, sizeof(*tbl), cmp_prop); |
@@ -571,7 +671,7 @@ static void sort_subnodes(struct node *node) | |||
571 | int n = 0, i = 0; | 671 | int n = 0, i = 0; |
572 | struct node *subnode, **tbl; | 672 | struct node *subnode, **tbl; |
573 | 673 | ||
574 | for_each_child(node, subnode) | 674 | for_each_child_withdel(node, subnode) |
575 | n++; | 675 | n++; |
576 | 676 | ||
577 | if (n == 0) | 677 | if (n == 0) |
@@ -579,7 +679,7 @@ static void sort_subnodes(struct node *node) | |||
579 | 679 | ||
580 | tbl = xmalloc(n * sizeof(*tbl)); | 680 | tbl = xmalloc(n * sizeof(*tbl)); |
581 | 681 | ||
582 | for_each_child(node, subnode) | 682 | for_each_child_withdel(node, subnode) |
583 | tbl[i++] = subnode; | 683 | tbl[i++] = subnode; |
584 | 684 | ||
585 | qsort(tbl, n, sizeof(*tbl), cmp_subnode); | 685 | qsort(tbl, n, sizeof(*tbl), cmp_subnode); |
@@ -598,7 +698,7 @@ static void sort_node(struct node *node) | |||
598 | 698 | ||
599 | sort_properties(node); | 699 | sort_properties(node); |
600 | sort_subnodes(node); | 700 | sort_subnodes(node); |
601 | for_each_child(node, c) | 701 | for_each_child_withdel(node, c) |
602 | sort_node(c); | 702 | sort_node(c); |
603 | } | 703 | } |
604 | 704 | ||