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/dtc-parser.y | |
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/dtc-parser.y')
-rw-r--r-- | scripts/dtc/dtc-parser.y | 255 |
1 files changed, 221 insertions, 34 deletions
diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y index 5e84a67fc1d2..f412460f94d7 100644 --- a/scripts/dtc/dtc-parser.y +++ b/scripts/dtc/dtc-parser.y | |||
@@ -34,6 +34,7 @@ extern struct boot_info *the_boot_info; | |||
34 | extern int treesource_error; | 34 | extern int treesource_error; |
35 | 35 | ||
36 | static unsigned long long eval_literal(const char *s, int base, int bits); | 36 | static unsigned long long eval_literal(const char *s, int base, int bits); |
37 | static unsigned char eval_char_literal(const char *s); | ||
37 | %} | 38 | %} |
38 | 39 | ||
39 | %union { | 40 | %union { |
@@ -44,19 +45,28 @@ static unsigned long long eval_literal(const char *s, int base, int bits); | |||
44 | uint8_t byte; | 45 | uint8_t byte; |
45 | struct data data; | 46 | struct data data; |
46 | 47 | ||
47 | uint64_t addr; | 48 | struct { |
48 | cell_t cell; | 49 | struct data data; |
50 | int bits; | ||
51 | } array; | ||
52 | |||
49 | struct property *prop; | 53 | struct property *prop; |
50 | struct property *proplist; | 54 | struct property *proplist; |
51 | struct node *node; | 55 | struct node *node; |
52 | struct node *nodelist; | 56 | struct node *nodelist; |
53 | struct reserve_info *re; | 57 | struct reserve_info *re; |
58 | uint64_t integer; | ||
54 | } | 59 | } |
55 | 60 | ||
56 | %token DT_V1 | 61 | %token DT_V1 |
57 | %token DT_MEMRESERVE | 62 | %token DT_MEMRESERVE |
63 | %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR | ||
64 | %token DT_BITS | ||
65 | %token DT_DEL_PROP | ||
66 | %token DT_DEL_NODE | ||
58 | %token <propnodename> DT_PROPNODENAME | 67 | %token <propnodename> DT_PROPNODENAME |
59 | %token <literal> DT_LITERAL | 68 | %token <literal> DT_LITERAL |
69 | %token <literal> DT_CHAR_LITERAL | ||
60 | %token <cbase> DT_BASE | 70 | %token <cbase> DT_BASE |
61 | %token <byte> DT_BYTE | 71 | %token <byte> DT_BYTE |
62 | %token <data> DT_STRING | 72 | %token <data> DT_STRING |
@@ -68,9 +78,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits); | |||
68 | %type <data> propdataprefix | 78 | %type <data> propdataprefix |
69 | %type <re> memreserve | 79 | %type <re> memreserve |
70 | %type <re> memreserves | 80 | %type <re> memreserves |
71 | %type <addr> addr | 81 | %type <array> arrayprefix |
72 | %type <data> celllist | ||
73 | %type <cell> cellval | ||
74 | %type <data> bytestring | 82 | %type <data> bytestring |
75 | %type <prop> propdef | 83 | %type <prop> propdef |
76 | %type <proplist> proplist | 84 | %type <proplist> proplist |
@@ -80,6 +88,21 @@ static unsigned long long eval_literal(const char *s, int base, int bits); | |||
80 | %type <node> subnode | 88 | %type <node> subnode |
81 | %type <nodelist> subnodes | 89 | %type <nodelist> subnodes |
82 | 90 | ||
91 | %type <integer> integer_prim | ||
92 | %type <integer> integer_unary | ||
93 | %type <integer> integer_mul | ||
94 | %type <integer> integer_add | ||
95 | %type <integer> integer_shift | ||
96 | %type <integer> integer_rela | ||
97 | %type <integer> integer_eq | ||
98 | %type <integer> integer_bitand | ||
99 | %type <integer> integer_bitxor | ||
100 | %type <integer> integer_bitor | ||
101 | %type <integer> integer_and | ||
102 | %type <integer> integer_or | ||
103 | %type <integer> integer_trinary | ||
104 | %type <integer> integer_expr | ||
105 | |||
83 | %% | 106 | %% |
84 | 107 | ||
85 | sourcefile: | 108 | sourcefile: |
@@ -102,7 +125,7 @@ memreserves: | |||
102 | ; | 125 | ; |
103 | 126 | ||
104 | memreserve: | 127 | memreserve: |
105 | DT_MEMRESERVE addr addr ';' | 128 | DT_MEMRESERVE integer_prim integer_prim ';' |
106 | { | 129 | { |
107 | $$ = build_reserve_entry($2, $3); | 130 | $$ = build_reserve_entry($2, $3); |
108 | } | 131 | } |
@@ -113,13 +136,6 @@ memreserve: | |||
113 | } | 136 | } |
114 | ; | 137 | ; |
115 | 138 | ||
116 | addr: | ||
117 | DT_LITERAL | ||
118 | { | ||
119 | $$ = eval_literal($1, 0, 64); | ||
120 | } | ||
121 | ; | ||
122 | |||
123 | devicetree: | 139 | devicetree: |
124 | '/' nodedef | 140 | '/' nodedef |
125 | { | 141 | { |
@@ -139,6 +155,17 @@ devicetree: | |||
139 | print_error("label or path, '%s', not found", $2); | 155 | print_error("label or path, '%s', not found", $2); |
140 | $$ = $1; | 156 | $$ = $1; |
141 | } | 157 | } |
158 | | devicetree DT_DEL_NODE DT_REF ';' | ||
159 | { | ||
160 | struct node *target = get_node_by_ref($1, $3); | ||
161 | |||
162 | if (!target) | ||
163 | print_error("label or path, '%s', not found", $3); | ||
164 | else | ||
165 | delete_node(target); | ||
166 | |||
167 | $$ = $1; | ||
168 | } | ||
142 | ; | 169 | ; |
143 | 170 | ||
144 | nodedef: | 171 | nodedef: |
@@ -168,6 +195,10 @@ propdef: | |||
168 | { | 195 | { |
169 | $$ = build_property($1, empty_data); | 196 | $$ = build_property($1, empty_data); |
170 | } | 197 | } |
198 | | DT_DEL_PROP DT_PROPNODENAME ';' | ||
199 | { | ||
200 | $$ = build_property_delete($2); | ||
201 | } | ||
171 | | DT_LABEL propdef | 202 | | DT_LABEL propdef |
172 | { | 203 | { |
173 | add_label(&$2->labels, $1); | 204 | add_label(&$2->labels, $1); |
@@ -180,9 +211,9 @@ propdata: | |||
180 | { | 211 | { |
181 | $$ = data_merge($1, $2); | 212 | $$ = data_merge($1, $2); |
182 | } | 213 | } |
183 | | propdataprefix '<' celllist '>' | 214 | | propdataprefix arrayprefix '>' |
184 | { | 215 | { |
185 | $$ = data_merge($1, $3); | 216 | $$ = data_merge($1, $2.data); |
186 | } | 217 | } |
187 | | propdataprefix '[' bytestring ']' | 218 | | propdataprefix '[' bytestring ']' |
188 | { | 219 | { |
@@ -192,7 +223,7 @@ propdata: | |||
192 | { | 223 | { |
193 | $$ = data_add_marker($1, REF_PATH, $2); | 224 | $$ = data_add_marker($1, REF_PATH, $2); |
194 | } | 225 | } |
195 | | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' | 226 | | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' |
196 | { | 227 | { |
197 | FILE *f = srcfile_relative_open($4.val, NULL); | 228 | FILE *f = srcfile_relative_open($4.val, NULL); |
198 | struct data d; | 229 | struct data d; |
@@ -240,31 +271,154 @@ propdataprefix: | |||
240 | } | 271 | } |
241 | ; | 272 | ; |
242 | 273 | ||
243 | celllist: | 274 | arrayprefix: |
244 | /* empty */ | 275 | DT_BITS DT_LITERAL '<' |
276 | { | ||
277 | $$.data = empty_data; | ||
278 | $$.bits = eval_literal($2, 0, 7); | ||
279 | |||
280 | if (($$.bits != 8) && | ||
281 | ($$.bits != 16) && | ||
282 | ($$.bits != 32) && | ||
283 | ($$.bits != 64)) | ||
284 | { | ||
285 | print_error("Only 8, 16, 32 and 64-bit elements" | ||
286 | " are currently supported"); | ||
287 | $$.bits = 32; | ||
288 | } | ||
289 | } | ||
290 | | '<' | ||
291 | { | ||
292 | $$.data = empty_data; | ||
293 | $$.bits = 32; | ||
294 | } | ||
295 | | arrayprefix integer_prim | ||
296 | { | ||
297 | if ($1.bits < 64) { | ||
298 | uint64_t mask = (1ULL << $1.bits) - 1; | ||
299 | /* | ||
300 | * Bits above mask must either be all zero | ||
301 | * (positive within range of mask) or all one | ||
302 | * (negative and sign-extended). The second | ||
303 | * condition is true if when we set all bits | ||
304 | * within the mask to one (i.e. | in the | ||
305 | * mask), all bits are one. | ||
306 | */ | ||
307 | if (($2 > mask) && (($2 | mask) != -1ULL)) | ||
308 | print_error( | ||
309 | "integer value out of range " | ||
310 | "%016lx (%d bits)", $1.bits); | ||
311 | } | ||
312 | |||
313 | $$.data = data_append_integer($1.data, $2, $1.bits); | ||
314 | } | ||
315 | | arrayprefix DT_REF | ||
316 | { | ||
317 | uint64_t val = ~0ULL >> (64 - $1.bits); | ||
318 | |||
319 | if ($1.bits == 32) | ||
320 | $1.data = data_add_marker($1.data, | ||
321 | REF_PHANDLE, | ||
322 | $2); | ||
323 | else | ||
324 | print_error("References are only allowed in " | ||
325 | "arrays with 32-bit elements."); | ||
326 | |||
327 | $$.data = data_append_integer($1.data, val, $1.bits); | ||
328 | } | ||
329 | | arrayprefix DT_LABEL | ||
245 | { | 330 | { |
246 | $$ = empty_data; | 331 | $$.data = data_add_marker($1.data, LABEL, $2); |
247 | } | 332 | } |
248 | | celllist cellval | 333 | ; |
334 | |||
335 | integer_prim: | ||
336 | DT_LITERAL | ||
249 | { | 337 | { |
250 | $$ = data_append_cell($1, $2); | 338 | $$ = eval_literal($1, 0, 64); |
251 | } | 339 | } |
252 | | celllist DT_REF | 340 | | DT_CHAR_LITERAL |
253 | { | 341 | { |
254 | $$ = data_append_cell(data_add_marker($1, REF_PHANDLE, | 342 | $$ = eval_char_literal($1); |
255 | $2), -1); | ||
256 | } | 343 | } |
257 | | celllist DT_LABEL | 344 | | '(' integer_expr ')' |
258 | { | 345 | { |
259 | $$ = data_add_marker($1, LABEL, $2); | 346 | $$ = $2; |
260 | } | 347 | } |
261 | ; | 348 | ; |
262 | 349 | ||
263 | cellval: | 350 | integer_expr: |
264 | DT_LITERAL | 351 | integer_trinary |
265 | { | 352 | ; |
266 | $$ = eval_literal($1, 0, 32); | 353 | |
267 | } | 354 | integer_trinary: |
355 | integer_or | ||
356 | | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } | ||
357 | ; | ||
358 | |||
359 | integer_or: | ||
360 | integer_and | ||
361 | | integer_or DT_OR integer_and { $$ = $1 || $3; } | ||
362 | ; | ||
363 | |||
364 | integer_and: | ||
365 | integer_bitor | ||
366 | | integer_and DT_AND integer_bitor { $$ = $1 && $3; } | ||
367 | ; | ||
368 | |||
369 | integer_bitor: | ||
370 | integer_bitxor | ||
371 | | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } | ||
372 | ; | ||
373 | |||
374 | integer_bitxor: | ||
375 | integer_bitand | ||
376 | | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } | ||
377 | ; | ||
378 | |||
379 | integer_bitand: | ||
380 | integer_eq | ||
381 | | integer_bitand '&' integer_eq { $$ = $1 & $3; } | ||
382 | ; | ||
383 | |||
384 | integer_eq: | ||
385 | integer_rela | ||
386 | | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } | ||
387 | | integer_eq DT_NE integer_rela { $$ = $1 != $3; } | ||
388 | ; | ||
389 | |||
390 | integer_rela: | ||
391 | integer_shift | ||
392 | | integer_rela '<' integer_shift { $$ = $1 < $3; } | ||
393 | | integer_rela '>' integer_shift { $$ = $1 > $3; } | ||
394 | | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } | ||
395 | | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } | ||
396 | ; | ||
397 | |||
398 | integer_shift: | ||
399 | integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } | ||
400 | | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } | ||
401 | | integer_add | ||
402 | ; | ||
403 | |||
404 | integer_add: | ||
405 | integer_add '+' integer_mul { $$ = $1 + $3; } | ||
406 | | integer_add '-' integer_mul { $$ = $1 - $3; } | ||
407 | | integer_mul | ||
408 | ; | ||
409 | |||
410 | integer_mul: | ||
411 | integer_mul '*' integer_unary { $$ = $1 * $3; } | ||
412 | | integer_mul '/' integer_unary { $$ = $1 / $3; } | ||
413 | | integer_mul '%' integer_unary { $$ = $1 % $3; } | ||
414 | | integer_unary | ||
415 | ; | ||
416 | |||
417 | integer_unary: | ||
418 | integer_prim | ||
419 | | '-' integer_unary { $$ = -$2; } | ||
420 | | '~' integer_unary { $$ = ~$2; } | ||
421 | | '!' integer_unary { $$ = !$2; } | ||
268 | ; | 422 | ; |
269 | 423 | ||
270 | bytestring: | 424 | bytestring: |
@@ -303,6 +457,10 @@ subnode: | |||
303 | { | 457 | { |
304 | $$ = name_node($2, $1); | 458 | $$ = name_node($2, $1); |
305 | } | 459 | } |
460 | | DT_DEL_NODE DT_PROPNODENAME ';' | ||
461 | { | ||
462 | $$ = name_node(build_node_delete(), $2); | ||
463 | } | ||
306 | | DT_LABEL subnode | 464 | | DT_LABEL subnode |
307 | { | 465 | { |
308 | add_label(&$2->labels, $1); | 466 | add_label(&$2->labels, $1); |
@@ -334,12 +492,41 @@ static unsigned long long eval_literal(const char *s, int base, int bits) | |||
334 | 492 | ||
335 | errno = 0; | 493 | errno = 0; |
336 | val = strtoull(s, &e, base); | 494 | val = strtoull(s, &e, base); |
337 | if (*e) | 495 | if (*e) { |
338 | print_error("bad characters in literal"); | 496 | size_t uls = strspn(e, "UL"); |
339 | else if ((errno == ERANGE) | 497 | if (e[uls]) |
498 | print_error("bad characters in literal"); | ||
499 | } | ||
500 | if ((errno == ERANGE) | ||
340 | || ((bits < 64) && (val >= (1ULL << bits)))) | 501 | || ((bits < 64) && (val >= (1ULL << bits)))) |
341 | print_error("literal out of range"); | 502 | print_error("literal out of range"); |
342 | else if (errno != 0) | 503 | else if (errno != 0) |
343 | print_error("bad literal"); | 504 | print_error("bad literal"); |
344 | return val; | 505 | return val; |
345 | } | 506 | } |
507 | |||
508 | static unsigned char eval_char_literal(const char *s) | ||
509 | { | ||
510 | int i = 1; | ||
511 | char c = s[0]; | ||
512 | |||
513 | if (c == '\0') | ||
514 | { | ||
515 | print_error("empty character literal"); | ||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | /* | ||
520 | * If the first character in the character literal is a \ then process | ||
521 | * the remaining characters as an escape encoding. If the first | ||
522 | * character is neither an escape or a terminator it should be the only | ||
523 | * character in the literal and will be returned. | ||
524 | */ | ||
525 | if (c == '\\') | ||
526 | c = get_escape_char(s, &i); | ||
527 | |||
528 | if (s[i] != '\0') | ||
529 | print_error("malformed character literal"); | ||
530 | |||
531 | return c; | ||
532 | } | ||