hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/scripts/dtc/dtc-parser.y
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
3
- *
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as
7
- * published by the Free Software Foundation; either version 2 of the
8
- * License, or (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18
- * USA
194 */
5
+%locations
6
+
207 %{
218 #include <stdio.h>
229 #include <inttypes.h>
....@@ -31,6 +18,8 @@
3118 srcpos_error((loc), "Error", __VA_ARGS__); \
3219 treesource_error = true; \
3320 } while (0)
21
+
22
+#define YYERROR_CALL(msg) yyerror(msg)
3423
3524 extern struct dt_info *parser_output;
3625 extern bool treesource_error;
....@@ -70,7 +59,8 @@
7059 %token <byte> DT_BYTE
7160 %token <data> DT_STRING
7261 %token <labelref> DT_LABEL
73
-%token <labelref> DT_REF
62
+%token <labelref> DT_LABEL_REF
63
+%token <labelref> DT_PATH_REF
7464 %token DT_INCBIN
7565
7666 %type <data> propdata
....@@ -83,6 +73,7 @@
8373 %type <data> bytestring
8474 %type <prop> propdef
8575 %type <proplist> proplist
76
+%type <labelref> dt_ref
8677
8778 %type <node> devicetree
8879 %type <node> nodedef
....@@ -158,6 +149,8 @@
158149 }
159150 ;
160151
152
+dt_ref: DT_LABEL_REF | DT_PATH_REF;
153
+
161154 devicetree:
162155 '/' nodedef
163156 {
....@@ -167,7 +160,7 @@
167160 {
168161 $$ = merge_nodes($1, $3);
169162 }
170
- | DT_REF nodedef
163
+ | dt_ref nodedef
171164 {
172165 /*
173166 * We rely on the rule being always:
....@@ -176,9 +169,12 @@
176169 */
177170 if (!($<flags>-1 & DTSF_PLUGIN))
178171 ERROR(&@2, "Label or path %s not found", $1);
179
- $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1);
172
+ $$ = add_orphan_node(
173
+ name_node(build_node(NULL, NULL, NULL),
174
+ ""),
175
+ $2, $1);
180176 }
181
- | devicetree DT_LABEL DT_REF nodedef
177
+ | devicetree DT_LABEL dt_ref nodedef
182178 {
183179 struct node *target = get_node_by_ref($1, $3);
184180
....@@ -189,7 +185,7 @@
189185 ERROR(&@3, "Label or path %s not found", $3);
190186 $$ = $1;
191187 }
192
- | devicetree DT_REF nodedef
188
+ | devicetree DT_PATH_REF nodedef
193189 {
194190 /*
195191 * We rely on the rule being always:
....@@ -208,7 +204,26 @@
208204 }
209205 $$ = $1;
210206 }
211
- | devicetree DT_DEL_NODE DT_REF ';'
207
+ | devicetree DT_LABEL_REF nodedef
208
+ {
209
+ struct node *target = get_node_by_ref($1, $2);
210
+
211
+ if (target) {
212
+ merge_nodes(target, $3);
213
+ } else {
214
+ /*
215
+ * We rely on the rule being always:
216
+ * versioninfo plugindecl memreserves devicetree
217
+ * so $-1 is what we want (plugindecl)
218
+ */
219
+ if ($<flags>-1 & DTSF_PLUGIN)
220
+ add_orphan_node($1, $3, $2);
221
+ else
222
+ ERROR(&@2, "Label or path %s not found", $2);
223
+ }
224
+ $$ = $1;
225
+ }
226
+ | devicetree DT_DEL_NODE dt_ref ';'
212227 {
213228 struct node *target = get_node_by_ref($1, $3);
214229
....@@ -220,7 +235,7 @@
220235
221236 $$ = $1;
222237 }
223
- | devicetree DT_OMIT_NO_REF DT_REF ';'
238
+ | devicetree DT_OMIT_NO_REF dt_ref ';'
224239 {
225240 struct node *target = get_node_by_ref($1, $3);
226241
....@@ -237,7 +252,7 @@
237252 nodedef:
238253 '{' proplist subnodes '}' ';'
239254 {
240
- $$ = build_node($2, $3);
255
+ $$ = build_node($2, $3, &@$);
241256 }
242257 ;
243258
....@@ -255,11 +270,11 @@
255270 propdef:
256271 DT_PROPNODENAME '=' propdata ';'
257272 {
258
- $$ = build_property($1, $3);
273
+ $$ = build_property($1, $3, &@$);
259274 }
260275 | DT_PROPNODENAME ';'
261276 {
262
- $$ = build_property($1, empty_data);
277
+ $$ = build_property($1, empty_data, &@$);
263278 }
264279 | DT_DEL_PROP DT_PROPNODENAME ';'
265280 {
....@@ -285,8 +300,9 @@
285300 {
286301 $$ = data_merge($1, $3);
287302 }
288
- | propdataprefix DT_REF
303
+ | propdataprefix dt_ref
289304 {
305
+ $1 = data_add_marker($1, TYPE_STRING, $2);
290306 $$ = data_add_marker($1, REF_PATH, $2);
291307 }
292308 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')'
....@@ -340,22 +356,27 @@
340356 DT_BITS DT_LITERAL '<'
341357 {
342358 unsigned long long bits;
359
+ enum markertype type = TYPE_UINT32;
343360
344361 bits = $2;
345362
346
- if ((bits != 8) && (bits != 16) &&
347
- (bits != 32) && (bits != 64)) {
363
+ switch (bits) {
364
+ case 8: type = TYPE_UINT8; break;
365
+ case 16: type = TYPE_UINT16; break;
366
+ case 32: type = TYPE_UINT32; break;
367
+ case 64: type = TYPE_UINT64; break;
368
+ default:
348369 ERROR(&@2, "Array elements must be"
349370 " 8, 16, 32 or 64-bits");
350371 bits = 32;
351372 }
352373
353
- $$.data = empty_data;
374
+ $$.data = data_add_marker(empty_data, type, NULL);
354375 $$.bits = bits;
355376 }
356377 | '<'
357378 {
358
- $$.data = empty_data;
379
+ $$.data = data_add_marker(empty_data, TYPE_UINT32, NULL);
359380 $$.bits = 32;
360381 }
361382 | arrayprefix integer_prim
....@@ -377,7 +398,7 @@
377398
378399 $$.data = data_append_integer($1.data, $2, $1.bits);
379400 }
380
- | arrayprefix DT_REF
401
+ | arrayprefix dt_ref
381402 {
382403 uint64_t val = ~0ULL >> (64 - $1.bits);
383404
....@@ -455,8 +476,8 @@
455476 ;
456477
457478 integer_shift:
458
- integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }
459
- | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }
479
+ integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; }
480
+ | integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; }
460481 | integer_add
461482 ;
462483
....@@ -499,7 +520,7 @@
499520 bytestring:
500521 /* empty */
501522 {
502
- $$ = empty_data;
523
+ $$ = data_add_marker(empty_data, TYPE_UINT8, NULL);
503524 }
504525 | bytestring DT_BYTE
505526 {
....@@ -534,7 +555,7 @@
534555 }
535556 | DT_DEL_NODE DT_PROPNODENAME ';'
536557 {
537
- $$ = name_node(build_node_delete(), $2);
558
+ $$ = name_node(build_node_delete(&@$), $2);
538559 }
539560 | DT_OMIT_NO_REF subnode
540561 {