Commit 999a78d5cf00dfb8cd8342454933ea492e955377

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent 0d82161823

scripts/dtc: Update to upstream version v1.4.5-3-gb1a60033c110

This adds the following commits from upstream:

b1a6003 tests: Add a test for overlays syntactic sugar
737b2df overlay: Add syntactic sugar version of overlays
497432f checks: Use proper format modifier for size_t
22a65c5 dtc: Bump version to v1.4.5
c575d80 Add fdtoverlay to .gitignore
b6a6f94 fdtoverlay: Sanity check blob size
8c1eb15 pylibfdt: Use Python2 explicitly
ee3d26f checks: add interrupts property check
c1e7738 checks: add gpio binding properties check
b3bbac0 checks: add phandle with arg property checks

[ sync with Linux commit: 4201d057ea91c3d6efd2db65219bc91fae413bc2 ]

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Showing 10 changed files with 1642 additions and 335 deletions Side-by-side Diff

scripts/dtc/checks.c
... ... @@ -956,6 +956,265 @@
956 956 WARNING(obsolete_chosen_interrupt_controller,
957 957 check_obsolete_chosen_interrupt_controller, NULL);
958 958  
  959 +struct provider {
  960 + const char *prop_name;
  961 + const char *cell_name;
  962 + bool optional;
  963 +};
  964 +
  965 +static void check_property_phandle_args(struct check *c,
  966 + struct dt_info *dti,
  967 + struct node *node,
  968 + struct property *prop,
  969 + const struct provider *provider)
  970 +{
  971 + struct node *root = dti->dt;
  972 + int cell, cellsize = 0;
  973 +
  974 + if (prop->val.len % sizeof(cell_t)) {
  975 + FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s",
  976 + prop->name, prop->val.len, sizeof(cell_t), node->fullpath);
  977 + return;
  978 + }
  979 +
  980 + for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
  981 + struct node *provider_node;
  982 + struct property *cellprop;
  983 + int phandle;
  984 +
  985 + phandle = propval_cell_n(prop, cell);
  986 + /*
  987 + * Some bindings use a cell value 0 or -1 to skip over optional
  988 + * entries when each index position has a specific definition.
  989 + */
  990 + if (phandle == 0 || phandle == -1) {
  991 + cellsize = 0;
  992 + continue;
  993 + }
  994 +
  995 + /* If we have markers, verify the current cell is a phandle */
  996 + if (prop->val.markers) {
  997 + struct marker *m = prop->val.markers;
  998 + for_each_marker_of_type(m, REF_PHANDLE) {
  999 + if (m->offset == (cell * sizeof(cell_t)))
  1000 + break;
  1001 + }
  1002 + if (!m)
  1003 + FAIL(c, dti, "Property '%s', cell %d is not a phandle reference in %s",
  1004 + prop->name, cell, node->fullpath);
  1005 + }
  1006 +
  1007 + provider_node = get_node_by_phandle(root, phandle);
  1008 + if (!provider_node) {
  1009 + FAIL(c, dti, "Could not get phandle node for %s:%s(cell %d)",
  1010 + node->fullpath, prop->name, cell);
  1011 + break;
  1012 + }
  1013 +
  1014 + cellprop = get_property(provider_node, provider->cell_name);
  1015 + if (cellprop) {
  1016 + cellsize = propval_cell(cellprop);
  1017 + } else if (provider->optional) {
  1018 + cellsize = 0;
  1019 + } else {
  1020 + FAIL(c, dti, "Missing property '%s' in node %s or bad phandle (referred from %s:%s[%d])",
  1021 + provider->cell_name,
  1022 + provider_node->fullpath,
  1023 + node->fullpath, prop->name, cell);
  1024 + break;
  1025 + }
  1026 +
  1027 + if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) {
  1028 + FAIL(c, dti, "%s property size (%d) too small for cell size %d in %s",
  1029 + prop->name, prop->val.len, cellsize, node->fullpath);
  1030 + }
  1031 + }
  1032 +}
  1033 +
  1034 +static void check_provider_cells_property(struct check *c,
  1035 + struct dt_info *dti,
  1036 + struct node *node)
  1037 +{
  1038 + struct provider *provider = c->data;
  1039 + struct property *prop;
  1040 +
  1041 + prop = get_property(node, provider->prop_name);
  1042 + if (!prop)
  1043 + return;
  1044 +
  1045 + check_property_phandle_args(c, dti, node, prop, provider);
  1046 +}
  1047 +#define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
  1048 + static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
  1049 + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);
  1050 +
  1051 +WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
  1052 +WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
  1053 +WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells");
  1054 +WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells");
  1055 +WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells");
  1056 +WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells");
  1057 +WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells");
  1058 +WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells");
  1059 +WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true);
  1060 +WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells");
  1061 +WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells");
  1062 +WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells");
  1063 +WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells");
  1064 +WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
  1065 +WARNING_PROPERTY_PHANDLE_CELLS(sound_dais, "sound-dais", "#sound-dai-cells");
  1066 +WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");
  1067 +
  1068 +static bool prop_is_gpio(struct property *prop)
  1069 +{
  1070 + char *str;
  1071 +
  1072 + /*
  1073 + * *-gpios and *-gpio can appear in property names,
  1074 + * so skip over any false matches (only one known ATM)
  1075 + */
  1076 + if (strstr(prop->name, "nr-gpio"))
  1077 + return false;
  1078 +
  1079 + str = strrchr(prop->name, '-');
  1080 + if (str)
  1081 + str++;
  1082 + else
  1083 + str = prop->name;
  1084 + if (!(streq(str, "gpios") || streq(str, "gpio")))
  1085 + return false;
  1086 +
  1087 + return true;
  1088 +}
  1089 +
  1090 +static void check_gpios_property(struct check *c,
  1091 + struct dt_info *dti,
  1092 + struct node *node)
  1093 +{
  1094 + struct property *prop;
  1095 +
  1096 + /* Skip GPIO hog nodes which have 'gpios' property */
  1097 + if (get_property(node, "gpio-hog"))
  1098 + return;
  1099 +
  1100 + for_each_property(node, prop) {
  1101 + struct provider provider;
  1102 +
  1103 + if (!prop_is_gpio(prop))
  1104 + continue;
  1105 +
  1106 + provider.prop_name = prop->name;
  1107 + provider.cell_name = "#gpio-cells";
  1108 + provider.optional = false;
  1109 + check_property_phandle_args(c, dti, node, prop, &provider);
  1110 + }
  1111 +
  1112 +}
  1113 +WARNING(gpios_property, check_gpios_property, NULL, &phandle_references);
  1114 +
  1115 +static void check_deprecated_gpio_property(struct check *c,
  1116 + struct dt_info *dti,
  1117 + struct node *node)
  1118 +{
  1119 + struct property *prop;
  1120 +
  1121 + for_each_property(node, prop) {
  1122 + char *str;
  1123 +
  1124 + if (!prop_is_gpio(prop))
  1125 + continue;
  1126 +
  1127 + str = strstr(prop->name, "gpio");
  1128 + if (!streq(str, "gpio"))
  1129 + continue;
  1130 +
  1131 + FAIL(c, dti, "'[*-]gpio' is deprecated, use '[*-]gpios' instead for %s:%s",
  1132 + node->fullpath, prop->name);
  1133 + }
  1134 +
  1135 +}
  1136 +CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL);
  1137 +
  1138 +static bool node_is_interrupt_provider(struct node *node)
  1139 +{
  1140 + struct property *prop;
  1141 +
  1142 + prop = get_property(node, "interrupt-controller");
  1143 + if (prop)
  1144 + return true;
  1145 +
  1146 + prop = get_property(node, "interrupt-map");
  1147 + if (prop)
  1148 + return true;
  1149 +
  1150 + return false;
  1151 +}
  1152 +static void check_interrupts_property(struct check *c,
  1153 + struct dt_info *dti,
  1154 + struct node *node)
  1155 +{
  1156 + struct node *root = dti->dt;
  1157 + struct node *irq_node = NULL, *parent = node;
  1158 + struct property *irq_prop, *prop = NULL;
  1159 + int irq_cells, phandle;
  1160 +
  1161 + irq_prop = get_property(node, "interrupts");
  1162 + if (!irq_prop)
  1163 + return;
  1164 +
  1165 + if (irq_prop->val.len % sizeof(cell_t))
  1166 + FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s",
  1167 + irq_prop->name, irq_prop->val.len, sizeof(cell_t),
  1168 + node->fullpath);
  1169 +
  1170 + while (parent && !prop) {
  1171 + if (parent != node && node_is_interrupt_provider(parent)) {
  1172 + irq_node = parent;
  1173 + break;
  1174 + }
  1175 +
  1176 + prop = get_property(parent, "interrupt-parent");
  1177 + if (prop) {
  1178 + phandle = propval_cell(prop);
  1179 + irq_node = get_node_by_phandle(root, phandle);
  1180 + if (!irq_node) {
  1181 + FAIL(c, dti, "Bad interrupt-parent phandle for %s",
  1182 + node->fullpath);
  1183 + return;
  1184 + }
  1185 + if (!node_is_interrupt_provider(irq_node))
  1186 + FAIL(c, dti,
  1187 + "Missing interrupt-controller or interrupt-map property in %s",
  1188 + irq_node->fullpath);
  1189 +
  1190 + break;
  1191 + }
  1192 +
  1193 + parent = parent->parent;
  1194 + }
  1195 +
  1196 + if (!irq_node) {
  1197 + FAIL(c, dti, "Missing interrupt-parent for %s", node->fullpath);
  1198 + return;
  1199 + }
  1200 +
  1201 + prop = get_property(irq_node, "#interrupt-cells");
  1202 + if (!prop) {
  1203 + FAIL(c, dti, "Missing #interrupt-cells in interrupt-parent %s",
  1204 + irq_node->fullpath);
  1205 + return;
  1206 + }
  1207 +
  1208 + irq_cells = propval_cell(prop);
  1209 + if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) {
  1210 + FAIL(c, dti,
  1211 + "interrupts size is (%d), expected multiple of %d in %s",
  1212 + irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)),
  1213 + node->fullpath);
  1214 + }
  1215 +}
  1216 +WARNING(interrupts_property, check_interrupts_property, &phandle_references);
  1217 +
959 1218 static struct check *check_table[] = {
960 1219 &duplicate_node_names, &duplicate_property_names,
961 1220 &node_name_chars, &node_name_format, &property_name_chars,
... ... @@ -986,6 +1245,27 @@
986 1245  
987 1246 &avoid_default_addr_size,
988 1247 &obsolete_chosen_interrupt_controller,
  1248 +
  1249 + &clocks_property,
  1250 + &cooling_device_property,
  1251 + &dmas_property,
  1252 + &hwlocks_property,
  1253 + &interrupts_extended_property,
  1254 + &io_channels_property,
  1255 + &iommus_property,
  1256 + &mboxes_property,
  1257 + &msi_parent_property,
  1258 + &mux_controls_property,
  1259 + &phys_property,
  1260 + &power_domains_property,
  1261 + &pwms_property,
  1262 + &resets_property,
  1263 + &sound_dais_property,
  1264 + &thermal_sensors_property,
  1265 +
  1266 + &deprecated_gpio_property,
  1267 + &gpios_property,
  1268 + &interrupts_property,
989 1269  
990 1270 &always_fail,
991 1271 };
scripts/dtc/dtc-lexer.lex.c_shipped
... ... @@ -8,8 +8,8 @@
8 8  
9 9 #define FLEX_SCANNER
10 10 #define YY_FLEX_MAJOR_VERSION 2
11   -#define YY_FLEX_MINOR_VERSION 5
12   -#define YY_FLEX_SUBMINOR_VERSION 35
  11 +#define YY_FLEX_MINOR_VERSION 6
  12 +#define YY_FLEX_SUBMINOR_VERSION 1
13 13 #if YY_FLEX_SUBMINOR_VERSION > 0
14 14 #define FLEX_BETA
15 15 #endif
16 16  
17 17  
... ... @@ -88,25 +88,13 @@
88 88  
89 89 #endif /* ! FLEXINT_H */
90 90  
91   -#ifdef __cplusplus
92   -
93   -/* The "const" storage-class-modifier is valid. */
94   -#define YY_USE_CONST
95   -
96   -#else /* ! __cplusplus */
97   -
98   -/* C99 requires __STDC__ to be defined as 1. */
99   -#if defined (__STDC__)
100   -
101   -#define YY_USE_CONST
102   -
103   -#endif /* defined (__STDC__) */
104   -#endif /* ! __cplusplus */
105   -
106   -#ifdef YY_USE_CONST
  91 +/* TODO: this is always defined, so inline it */
107 92 #define yyconst const
  93 +
  94 +#if defined(__GNUC__) && __GNUC__ >= 3
  95 +#define yynoreturn __attribute__((__noreturn__))
108 96 #else
109   -#define yyconst
  97 +#define yynoreturn
110 98 #endif
111 99  
112 100 /* Returned upon end-of-file. */
... ... @@ -162,6 +150,11 @@
162 150 typedef struct yy_buffer_state *YY_BUFFER_STATE;
163 151 #endif
164 152  
  153 +#ifndef YY_TYPEDEF_YY_SIZE_T
  154 +#define YY_TYPEDEF_YY_SIZE_T
  155 +typedef size_t yy_size_t;
  156 +#endif
  157 +
165 158 extern int yyleng;
166 159  
167 160 extern FILE *yyin, *yyout;
... ... @@ -171,6 +164,7 @@
171 164 #define EOB_ACT_LAST_MATCH 2
172 165  
173 166 #define YY_LESS_LINENO(n)
  167 + #define YY_LINENO_REWIND_TO(ptr)
174 168  
175 169 /* Return all but the first "n" matched characters back to the input stream. */
176 170 #define yyless(n) \
... ... @@ -188,11 +182,6 @@
188 182  
189 183 #define unput(c) yyunput( c, (yytext_ptr) )
190 184  
191   -#ifndef YY_TYPEDEF_YY_SIZE_T
192   -#define YY_TYPEDEF_YY_SIZE_T
193   -typedef size_t yy_size_t;
194   -#endif
195   -
196 185 #ifndef YY_STRUCT_YY_BUFFER_STATE
197 186 #define YY_STRUCT_YY_BUFFER_STATE
198 187 struct yy_buffer_state
... ... @@ -205,7 +194,7 @@
205 194 /* Size of input buffer in bytes, not including room for EOB
206 195 * characters.
207 196 */
208   - yy_size_t yy_buf_size;
  197 + int yy_buf_size;
209 198  
210 199 /* Number of characters read into yy_ch_buf, not including EOB
211 200 * characters.
... ... @@ -233,7 +222,7 @@
233 222  
234 223 int yy_bs_lineno; /**< The line count. */
235 224 int yy_bs_column; /**< The column count. */
236   -
  225 +
237 226 /* Whether to try to fill the input buffer when we reach the
238 227 * end of it.
239 228 */
... ... @@ -261,7 +250,7 @@
261 250 /* Stack of input buffers. */
262 251 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
263 252 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
264   -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
  253 +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
265 254  
266 255 /* We provide macros for accessing buffer states in case in the
267 256 * future we want to put the buffer states in a more general
... ... @@ -284,7 +273,7 @@
284 273 int yyleng;
285 274  
286 275 /* Points to current character in buffer. */
287   -static char *yy_c_buf_p = (char *) 0;
  276 +static char *yy_c_buf_p = NULL;
288 277 static int yy_init = 0; /* whether we need to initialize */
289 278 static int yy_start = 0; /* start state number */
290 279  
291 280  
... ... @@ -341,12 +330,12 @@
341 330  
342 331 /* Begin user sect3 */
343 332  
344   -#define yywrap(n) 1
  333 +#define yywrap() (/*CONSTCOND*/1)
345 334 #define YY_SKIP_YYWRAP
346 335  
347 336 typedef unsigned char YY_CHAR;
348 337  
349   -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
  338 +FILE *yyin = NULL, *yyout = NULL;
350 339  
351 340 typedef int yy_state_type;
352 341  
353 342  
354 343  
... ... @@ -355,19 +344,22 @@
355 344 int yylineno = 1;
356 345  
357 346 extern char *yytext;
  347 +#ifdef yytext_ptr
  348 +#undef yytext_ptr
  349 +#endif
358 350 #define yytext_ptr yytext
359 351  
360 352 static yy_state_type yy_get_previous_state (void );
361 353 static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
362 354 static int yy_get_next_buffer (void );
363   -static void yy_fatal_error (yyconst char msg[] );
  355 +static void yynoreturn yy_fatal_error (yyconst char* msg );
364 356  
365 357 /* Done after the current pattern has been matched and before the
366 358 * corresponding action - sets up yytext.
367 359 */
368 360 #define YY_DO_BEFORE_ACTION \
369 361 (yytext_ptr) = yy_bp; \
370   - yyleng = (size_t) (yy_cp - yy_bp); \
  362 + yyleng = (int) (yy_cp - yy_bp); \
371 363 (yy_hold_char) = *yy_cp; \
372 364 *yy_cp = '\0'; \
373 365 (yy_c_buf_p) = yy_cp;
... ... @@ -403,7 +395,7 @@
403 395 0, 0, 0, 8, 0
404 396 } ;
405 397  
406   -static yyconst flex_int32_t yy_ec[256] =
  398 +static yyconst YY_CHAR yy_ec[256] =
407 399 { 0,
408 400 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
409 401 4, 4, 4, 1, 1, 1, 1, 1, 1, 1,
... ... @@ -435,7 +427,7 @@
435 427 1, 1, 1, 1, 1
436 428 } ;
437 429  
438   -static yyconst flex_int32_t yy_meta[48] =
  430 +static yyconst YY_CHAR yy_meta[48] =
439 431 { 0,
440 432 1, 1, 1, 1, 1, 1, 2, 3, 1, 2,
441 433 2, 2, 4, 5, 5, 5, 6, 1, 1, 1,
... ... @@ -444,7 +436,7 @@
444 436 8, 8, 8, 8, 3, 1, 4
445 437 } ;
446 438  
447   -static yyconst flex_int16_t yy_base[180] =
  439 +static yyconst flex_uint16_t yy_base[180] =
448 440 { 0,
449 441 0, 393, 35, 392, 66, 391, 38, 107, 397, 401,
450 442 55, 113, 377, 112, 111, 111, 114, 42, 376, 106,
... ... @@ -490,7 +482,7 @@
490 482 165, 165, 165, 165, 165, 165, 165, 165, 165
491 483 } ;
492 484  
493   -static yyconst flex_int16_t yy_nxt[449] =
  485 +static yyconst flex_uint16_t yy_nxt[449] =
494 486 { 0,
495 487 10, 11, 12, 11, 13, 14, 10, 15, 16, 10,
496 488 10, 10, 17, 10, 10, 10, 10, 18, 19, 20,
... ... @@ -665,7 +657,7 @@
665 657 static bool pop_input_file(void);
666 658 static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
667 659  
668   -#line 669 "dtc-lexer.lex.c"
  660 +#line 661 "dtc-lexer.lex.c"
669 661  
670 662 #define INITIAL 0
671 663 #define BYTESTRING 1
672 664  
673 665  
674 666  
... ... @@ -701,19 +693,19 @@
701 693  
702 694 FILE *yyget_in (void );
703 695  
704   -void yyset_in (FILE * in_str );
  696 +void yyset_in (FILE * _in_str );
705 697  
706 698 FILE *yyget_out (void );
707 699  
708   -void yyset_out (FILE * out_str );
  700 +void yyset_out (FILE * _out_str );
709 701  
710   -int yyget_leng (void );
  702 + int yyget_leng (void );
711 703  
712 704 char *yyget_text (void );
713 705  
714 706 int yyget_lineno (void );
715 707  
716   -void yyset_lineno (int line_number );
  708 +void yyset_lineno (int _line_number );
717 709  
718 710 /* Macros after this point can all be overridden by user definitions in
719 711 * section 1.
... ... @@ -727,6 +719,10 @@
727 719 #endif
728 720 #endif
729 721  
  722 +#ifndef YY_NO_UNPUT
  723 +
  724 +#endif
  725 +
730 726 #ifndef yytext_ptr
731 727 static void yy_flex_strncpy (char *,yyconst char *,int );
732 728 #endif
... ... @@ -760,7 +756,7 @@
760 756 /* This used to be an fputs(), but since the string might contain NUL's,
761 757 * we now use fwrite().
762 758 */
763   -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
  759 +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
764 760 #endif
765 761  
766 762 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
... ... @@ -784,7 +780,7 @@
784 780 else \
785 781 { \
786 782 errno=0; \
787   - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
  783 + while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
788 784 { \
789 785 if( errno != EINTR) \
790 786 { \
... ... @@ -839,7 +835,7 @@
839 835  
840 836 /* Code executed at the end of each rule. */
841 837 #ifndef YY_BREAK
842   -#define YY_BREAK break;
  838 +#define YY_BREAK /*LINTED*/break;
843 839 #endif
844 840  
845 841 #define YY_RULE_SETUP \
846 842  
... ... @@ -852,14 +848,10 @@
852 848 */
853 849 YY_DECL
854 850 {
855   - register yy_state_type yy_current_state;
856   - register char *yy_cp, *yy_bp;
857   - register int yy_act;
  851 + yy_state_type yy_current_state;
  852 + char *yy_cp, *yy_bp;
  853 + int yy_act;
858 854  
859   -#line 69 "dtc-lexer.l"
860   -
861   -#line 862 "dtc-lexer.lex.c"
862   -
863 855 if ( !(yy_init) )
864 856 {
865 857 (yy_init) = 1;
... ... @@ -886,7 +878,12 @@
886 878 yy_load_buffer_state( );
887 879 }
888 880  
889   - while ( 1 ) /* loops until end-of-file is reached */
  881 + {
  882 +#line 69 "dtc-lexer.l"
  883 +
  884 +#line 885 "dtc-lexer.lex.c"
  885 +
  886 + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
890 887 {
891 888 yy_cp = (yy_c_buf_p);
892 889  
... ... @@ -903,7 +900,7 @@
903 900 yy_match:
904 901 do
905 902 {
906   - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
  903 + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
907 904 if ( yy_accept[yy_current_state] )
908 905 {
909 906 (yy_last_accepting_state) = yy_current_state;
... ... @@ -915,7 +912,7 @@
915 912 if ( yy_current_state >= 166 )
916 913 yy_c = yy_meta[(unsigned int) yy_c];
917 914 }
918   - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  915 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
919 916 ++yy_cp;
920 917 }
921 918 while ( yy_current_state != 165 );
... ... @@ -1256,7 +1253,7 @@
1256 1253 #line 272 "dtc-lexer.l"
1257 1254 ECHO;
1258 1255 YY_BREAK
1259   -#line 1260 "dtc-lexer.lex.c"
  1256 +#line 1257 "dtc-lexer.lex.c"
1260 1257  
1261 1258 case YY_END_OF_BUFFER:
1262 1259 {
... ... @@ -1386,6 +1383,7 @@
1386 1383 "fatal flex scanner internal error--no action found" );
1387 1384 } /* end of action switch */
1388 1385 } /* end of scanning one token */
  1386 + } /* end of user's declarations */
1389 1387 } /* end of yylex */
1390 1388  
1391 1389 /* yy_get_next_buffer - try to read in a new buffer
... ... @@ -1397,9 +1395,9 @@
1397 1395 */
1398 1396 static int yy_get_next_buffer (void)
1399 1397 {
1400   - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1401   - register char *source = (yytext_ptr);
1402   - register int number_to_move, i;
  1398 + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
  1399 + char *source = (yytext_ptr);
  1400 + int number_to_move, i;
1403 1401 int ret_val;
1404 1402  
1405 1403 if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
... ... @@ -1428,7 +1426,7 @@
1428 1426 /* Try to read more data. */
1429 1427  
1430 1428 /* First move last chars to start of buffer. */
1431   - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
  1429 + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1432 1430  
1433 1431 for ( i = 0; i < number_to_move; ++i )
1434 1432 *(dest++) = *(source++);
... ... @@ -1448,7 +1446,7 @@
1448 1446 { /* Not enough room in the buffer - grow it. */
1449 1447  
1450 1448 /* just a shorter name for the current buffer */
1451   - YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
  1449 + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1452 1450  
1453 1451 int yy_c_buf_p_offset =
1454 1452 (int) ((yy_c_buf_p) - b->yy_ch_buf);
... ... @@ -1468,7 +1466,7 @@
1468 1466 }
1469 1467 else
1470 1468 /* Can't grow it, we don't own it. */
1471   - b->yy_ch_buf = 0;
  1469 + b->yy_ch_buf = NULL;
1472 1470  
1473 1471 if ( ! b->yy_ch_buf )
1474 1472 YY_FATAL_ERROR(
... ... @@ -1486,7 +1484,7 @@
1486 1484  
1487 1485 /* Read in more data. */
1488 1486 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1489   - (yy_n_chars), (size_t) num_to_read );
  1487 + (yy_n_chars), num_to_read );
1490 1488  
1491 1489 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1492 1490 }
1493 1491  
... ... @@ -1510,9 +1508,9 @@
1510 1508 else
1511 1509 ret_val = EOB_ACT_CONTINUE_SCAN;
1512 1510  
1513   - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
  1511 + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1514 1512 /* Extend the array by 50%, plus the number we really need. */
1515   - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
  1513 + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1516 1514 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
1517 1515 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1518 1516 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1519 1517  
... ... @@ -1531,15 +1529,15 @@
1531 1529  
1532 1530 static yy_state_type yy_get_previous_state (void)
1533 1531 {
1534   - register yy_state_type yy_current_state;
1535   - register char *yy_cp;
  1532 + yy_state_type yy_current_state;
  1533 + char *yy_cp;
1536 1534  
1537 1535 yy_current_state = (yy_start);
1538 1536 yy_current_state += YY_AT_BOL();
1539 1537  
1540 1538 for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1541 1539 {
1542   - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
  1540 + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1543 1541 if ( yy_accept[yy_current_state] )
1544 1542 {
1545 1543 (yy_last_accepting_state) = yy_current_state;
... ... @@ -1551,7 +1549,7 @@
1551 1549 if ( yy_current_state >= 166 )
1552 1550 yy_c = yy_meta[(unsigned int) yy_c];
1553 1551 }
1554   - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  1552 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1555 1553 }
1556 1554  
1557 1555 return yy_current_state;
1558 1556  
... ... @@ -1564,10 +1562,10 @@
1564 1562 */
1565 1563 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
1566 1564 {
1567   - register int yy_is_jam;
1568   - register char *yy_cp = (yy_c_buf_p);
  1565 + int yy_is_jam;
  1566 + char *yy_cp = (yy_c_buf_p);
1569 1567  
1570   - register YY_CHAR yy_c = 1;
  1568 + YY_CHAR yy_c = 1;
1571 1569 if ( yy_accept[yy_current_state] )
1572 1570 {
1573 1571 (yy_last_accepting_state) = yy_current_state;
1574 1572  
1575 1573  
... ... @@ -1579,12 +1577,16 @@
1579 1577 if ( yy_current_state >= 166 )
1580 1578 yy_c = yy_meta[(unsigned int) yy_c];
1581 1579 }
1582   - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  1580 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1583 1581 yy_is_jam = (yy_current_state == 165);
1584 1582  
1585   - return yy_is_jam ? 0 : yy_current_state;
  1583 + return yy_is_jam ? 0 : yy_current_state;
1586 1584 }
1587 1585  
  1586 +#ifndef YY_NO_UNPUT
  1587 +
  1588 +#endif
  1589 +
1588 1590 #ifndef YY_NO_INPUT
1589 1591 #ifdef __cplusplus
1590 1592 static int yyinput (void)
... ... @@ -1633,7 +1635,7 @@
1633 1635 case EOB_ACT_END_OF_FILE:
1634 1636 {
1635 1637 if ( yywrap( ) )
1636   - return EOF;
  1638 + return 0;
1637 1639  
1638 1640 if ( ! (yy_did_buffer_switch_on_eof) )
1639 1641 YY_NEW_FILE;
... ... @@ -1736,7 +1738,7 @@
1736 1738 if ( ! b )
1737 1739 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1738 1740  
1739   - b->yy_buf_size = size;
  1741 + b->yy_buf_size = (yy_size_t)size;
1740 1742  
1741 1743 /* yy_ch_buf has to be 2 characters longer than the size given because
1742 1744 * we need to put in 2 end-of-buffer characters.
1743 1745  
1744 1746  
... ... @@ -1891,15 +1893,15 @@
1891 1893 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1892 1894 * immediate realloc on the next call.
1893 1895 */
1894   - num_to_alloc = 1;
  1896 + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1895 1897 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1896 1898 (num_to_alloc * sizeof(struct yy_buffer_state*)
1897 1899 );
1898 1900 if ( ! (yy_buffer_stack) )
1899 1901 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1900   -
  1902 +
1901 1903 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1902   -
  1904 +
1903 1905 (yy_buffer_stack_max) = num_to_alloc;
1904 1906 (yy_buffer_stack_top) = 0;
1905 1907 return;
... ... @@ -1908,7 +1910,7 @@
1908 1910 if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1909 1911  
1910 1912 /* Increase the buffer to prepare for a possible push. */
1911   - int grow_size = 8 /* arbitrary grow size */;
  1913 + yy_size_t grow_size = 8 /* arbitrary grow size */;
1912 1914  
1913 1915 num_to_alloc = (yy_buffer_stack_max) + grow_size;
1914 1916 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
... ... @@ -1928,7 +1930,7 @@
1928 1930 * @param base the character buffer
1929 1931 * @param size the size in bytes of the character buffer
1930 1932 *
1931   - * @return the newly allocated buffer state object.
  1933 + * @return the newly allocated buffer state object.
1932 1934 */
1933 1935 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
1934 1936 {
... ... @@ -1938,7 +1940,7 @@
1938 1940 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1939 1941 base[size-1] != YY_END_OF_BUFFER_CHAR )
1940 1942 /* They forgot to leave room for the EOB's. */
1941   - return 0;
  1943 + return NULL;
1942 1944  
1943 1945 b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1944 1946 if ( ! b )
... ... @@ -1947,7 +1949,7 @@
1947 1949 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1948 1950 b->yy_buf_pos = b->yy_ch_buf = base;
1949 1951 b->yy_is_our_buffer = 0;
1950   - b->yy_input_file = 0;
  1952 + b->yy_input_file = NULL;
1951 1953 b->yy_n_chars = b->yy_buf_size;
1952 1954 b->yy_is_interactive = 0;
1953 1955 b->yy_at_bol = 1;
... ... @@ -1970,7 +1972,7 @@
1970 1972 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1971 1973 {
1972 1974  
1973   - return yy_scan_bytes(yystr,strlen(yystr) );
  1975 + return yy_scan_bytes(yystr,(int) strlen(yystr) );
1974 1976 }
1975 1977  
1976 1978 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
... ... @@ -1988,7 +1990,7 @@
1988 1990 int i;
1989 1991  
1990 1992 /* Get memory for full buffer, including space for trailing EOB's. */
1991   - n = _yybytes_len + 2;
  1993 + n = (yy_size_t) (_yybytes_len + 2);
1992 1994 buf = (char *) yyalloc(n );
1993 1995 if ( ! buf )
1994 1996 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1995 1997  
... ... @@ -2014,9 +2016,9 @@
2014 2016 #define YY_EXIT_FAILURE 2
2015 2017 #endif
2016 2018  
2017   -static void yy_fatal_error (yyconst char* msg )
  2019 +static void yynoreturn yy_fatal_error (yyconst char* msg )
2018 2020 {
2019   - (void) fprintf( stderr, "%s\n", msg );
  2021 + (void) fprintf( stderr, "%s\n", msg );
2020 2022 exit( YY_EXIT_FAILURE );
2021 2023 }
2022 2024  
... ... @@ -2044,7 +2046,7 @@
2044 2046 */
2045 2047 int yyget_lineno (void)
2046 2048 {
2047   -
  2049 +
2048 2050 return yylineno;
2049 2051 }
2050 2052  
2051 2053  
2052 2054  
2053 2055  
2054 2056  
2055 2057  
2056 2058  
2057 2059  
... ... @@ -2082,29 +2084,29 @@
2082 2084 }
2083 2085  
2084 2086 /** Set the current line number.
2085   - * @param line_number
  2087 + * @param _line_number line number
2086 2088 *
2087 2089 */
2088   -void yyset_lineno (int line_number )
  2090 +void yyset_lineno (int _line_number )
2089 2091 {
2090 2092  
2091   - yylineno = line_number;
  2093 + yylineno = _line_number;
2092 2094 }
2093 2095  
2094 2096 /** Set the input stream. This does not discard the current
2095 2097 * input buffer.
2096   - * @param in_str A readable stream.
  2098 + * @param _in_str A readable stream.
2097 2099 *
2098 2100 * @see yy_switch_to_buffer
2099 2101 */
2100   -void yyset_in (FILE * in_str )
  2102 +void yyset_in (FILE * _in_str )
2101 2103 {
2102   - yyin = in_str ;
  2104 + yyin = _in_str ;
2103 2105 }
2104 2106  
2105   -void yyset_out (FILE * out_str )
  2107 +void yyset_out (FILE * _out_str )
2106 2108 {
2107   - yyout = out_str ;
  2109 + yyout = _out_str ;
2108 2110 }
2109 2111  
2110 2112 int yyget_debug (void)
2111 2113  
... ... @@ -2112,9 +2114,9 @@
2112 2114 return yy_flex_debug;
2113 2115 }
2114 2116  
2115   -void yyset_debug (int bdebug )
  2117 +void yyset_debug (int _bdebug )
2116 2118 {
2117   - yy_flex_debug = bdebug ;
  2119 + yy_flex_debug = _bdebug ;
2118 2120 }
2119 2121  
2120 2122 static int yy_init_globals (void)
2121 2123  
... ... @@ -2123,10 +2125,10 @@
2123 2125 * This function is called from yylex_destroy(), so don't allocate here.
2124 2126 */
2125 2127  
2126   - (yy_buffer_stack) = 0;
  2128 + (yy_buffer_stack) = NULL;
2127 2129 (yy_buffer_stack_top) = 0;
2128 2130 (yy_buffer_stack_max) = 0;
2129   - (yy_c_buf_p) = (char *) 0;
  2131 + (yy_c_buf_p) = NULL;
2130 2132 (yy_init) = 0;
2131 2133 (yy_start) = 0;
2132 2134  
... ... @@ -2135,8 +2137,8 @@
2135 2137 yyin = stdin;
2136 2138 yyout = stdout;
2137 2139 #else
2138   - yyin = (FILE *) 0;
2139   - yyout = (FILE *) 0;
  2140 + yyin = NULL;
  2141 + yyout = NULL;
2140 2142 #endif
2141 2143  
2142 2144 /* For future reference: Set errno on error, since we are called by
... ... @@ -2174,7 +2176,8 @@
2174 2176 #ifndef yytext_ptr
2175 2177 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
2176 2178 {
2177   - register int i;
  2179 +
  2180 + int i;
2178 2181 for ( i = 0; i < n; ++i )
2179 2182 s1[i] = s2[i];
2180 2183 }
... ... @@ -2183,7 +2186,7 @@
2183 2186 #ifdef YY_NEED_STRLEN
2184 2187 static int yy_flex_strlen (yyconst char * s )
2185 2188 {
2186   - register int n;
  2189 + int n;
2187 2190 for ( n = 0; s[n]; ++n )
2188 2191 ;
2189 2192  
2190 2193  
... ... @@ -2193,11 +2196,12 @@
2193 2196  
2194 2197 void *yyalloc (yy_size_t size )
2195 2198 {
2196   - return (void *) malloc( size );
  2199 + return malloc(size);
2197 2200 }
2198 2201  
2199 2202 void *yyrealloc (void * ptr, yy_size_t size )
2200 2203 {
  2204 +
2201 2205 /* The cast to (char *) in the following accommodates both
2202 2206 * implementations that use char* generic pointers, and those
2203 2207 * that use void* generic pointers. It works with the latter
2204 2208  
... ... @@ -2205,12 +2209,12 @@
2205 2209 * any pointer type to void*, and deal with argument conversions
2206 2210 * as though doing an assignment.
2207 2211 */
2208   - return (void *) realloc( (char *) ptr, size );
  2212 + return realloc(ptr, size);
2209 2213 }
2210 2214  
2211 2215 void yyfree (void * ptr )
2212 2216 {
2213   - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
  2217 + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2214 2218 }
2215 2219  
2216 2220 #define YYTABLES_NAME "yytables"
scripts/dtc/dtc-parser.tab.c_shipped
Changes suppressed. Click to show
1   -/* A Bison parser, made by GNU Bison 3.0.2. */
  1 +/* A Bison parser, made by GNU Bison 3.0.4. */
2 2  
3 3 /* Bison implementation for Yacc-like parsers in C
4 4  
5   - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  5 + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 6  
7 7 This program is free software: you can redistribute it and/or modify
8 8 it under the terms of the GNU General Public License as published by
... ... @@ -44,7 +44,7 @@
44 44 #define YYBISON 1
45 45  
46 46 /* Bison version. */
47   -#define YYBISON_VERSION "3.0.2"
  47 +#define YYBISON_VERSION "3.0.4"
48 48  
49 49 /* Skeleton name. */
50 50 #define YYSKELETON_NAME "yacc.c"
... ... @@ -143,7 +143,7 @@
143 143  
144 144 /* Value type. */
145 145 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
146   -typedef union YYSTYPE YYSTYPE;
  146 +
147 147 union YYSTYPE
148 148 {
149 149 #line 39 "dtc-parser.y" /* yacc.c:355 */
... ... @@ -168,6 +168,8 @@
168 168  
169 169 #line 170 "dtc-parser.tab.c" /* yacc.c:355 */
170 170 };
  171 +
  172 +typedef union YYSTYPE YYSTYPE;
171 173 # define YYSTYPE_IS_TRIVIAL 1
172 174 # define YYSTYPE_IS_DECLARED 1
173 175 #endif
... ... @@ -195,7 +197,7 @@
195 197  
196 198 /* Copy the second part of user declarations. */
197 199  
198   -#line 199 "dtc-parser.tab.c" /* yacc.c:358 */
  200 +#line 201 "dtc-parser.tab.c" /* yacc.c:358 */
199 201  
200 202 #ifdef short
201 203 # undef short
... ... @@ -446,7 +448,7 @@
446 448 /* YYNNTS -- Number of nonterminals. */
447 449 #define YYNNTS 30
448 450 /* YYNRULES -- Number of rules. */
449   -#define YYNRULES 84
  451 +#define YYNRULES 85
450 452 /* YYNSTATES -- Number of states. */
451 453 #define YYNSTATES 149
452 454  
... ... @@ -497,14 +499,14 @@
497 499 static const yytype_uint16 yyrline[] =
498 500 {
499 501 0, 109, 109, 117, 121, 128, 129, 139, 142, 149,
500   - 153, 161, 165, 170, 181, 191, 206, 214, 217, 224,
501   - 228, 232, 236, 244, 248, 252, 256, 260, 276, 286,
502   - 294, 297, 301, 308, 324, 329, 348, 362, 369, 370,
503   - 371, 378, 382, 383, 387, 388, 392, 393, 397, 398,
504   - 402, 403, 407, 408, 412, 413, 414, 418, 419, 420,
505   - 421, 422, 426, 427, 428, 432, 433, 434, 438, 439,
506   - 448, 457, 461, 462, 463, 464, 469, 472, 476, 484,
507   - 487, 491, 499, 503, 507
  502 + 153, 161, 165, 170, 181, 200, 213, 220, 228, 231,
  503 + 238, 242, 246, 250, 258, 262, 266, 270, 274, 290,
  504 + 300, 308, 311, 315, 322, 338, 343, 362, 376, 383,
  505 + 384, 385, 392, 396, 397, 401, 402, 406, 407, 411,
  506 + 412, 416, 417, 421, 422, 426, 427, 428, 432, 433,
  507 + 434, 435, 436, 440, 441, 442, 446, 447, 448, 452,
  508 + 453, 462, 471, 475, 476, 477, 478, 483, 486, 490,
  509 + 498, 501, 505, 513, 517, 521
508 510 };
509 511 #endif
510 512  
511 513  
... ... @@ -580,20 +582,20 @@
580 582 static const yytype_uint8 yydefact[] =
581 583 {
582 584 0, 0, 0, 5, 7, 3, 1, 6, 0, 0,
583   - 0, 7, 0, 38, 39, 0, 0, 10, 0, 2,
584   - 8, 4, 0, 0, 0, 72, 0, 41, 42, 44,
585   - 46, 48, 50, 52, 54, 57, 64, 67, 71, 0,
586   - 17, 11, 0, 0, 0, 0, 73, 74, 75, 40,
  585 + 16, 7, 0, 39, 40, 0, 0, 10, 0, 2,
  586 + 8, 4, 0, 0, 0, 73, 0, 42, 43, 45,
  587 + 47, 49, 51, 53, 55, 58, 65, 68, 72, 0,
  588 + 18, 11, 0, 0, 0, 0, 74, 75, 76, 41,
587 589 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
588 590 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
589   - 79, 0, 0, 14, 12, 45, 0, 47, 49, 51,
590   - 53, 55, 56, 60, 61, 59, 58, 62, 63, 65,
591   - 66, 69, 68, 70, 0, 0, 0, 0, 18, 0,
592   - 79, 15, 13, 0, 0, 0, 20, 30, 82, 22,
593   - 84, 0, 81, 80, 43, 21, 83, 0, 0, 16,
594   - 29, 19, 31, 0, 23, 32, 26, 0, 76, 34,
595   - 0, 0, 0, 0, 37, 36, 24, 35, 33, 0,
596   - 77, 78, 25, 0, 28, 0, 0, 0, 27
  591 + 80, 0, 0, 14, 12, 46, 0, 48, 50, 52,
  592 + 54, 56, 57, 61, 62, 60, 59, 63, 64, 66,
  593 + 67, 70, 69, 71, 0, 0, 0, 0, 19, 0,
  594 + 80, 15, 13, 0, 0, 0, 21, 31, 83, 23,
  595 + 85, 0, 82, 81, 44, 22, 84, 0, 0, 17,
  596 + 30, 20, 32, 0, 24, 33, 27, 0, 77, 35,
  597 + 0, 0, 0, 0, 38, 37, 25, 36, 34, 0,
  598 + 78, 79, 26, 0, 29, 0, 0, 0, 28
597 599 };
598 600  
599 601 /* YYPGOTO[NTERM-NUM]. */
600 602  
... ... @@ -676,28 +678,28 @@
676 678 static const yytype_uint8 yyr1[] =
677 679 {
678 680 0, 48, 49, 50, 50, 51, 51, 52, 52, 53,
679   - 53, 54, 54, 54, 54, 54, 55, 56, 56, 57,
680   - 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
681   - 59, 59, 59, 60, 60, 60, 60, 60, 61, 61,
682   - 61, 62, 63, 63, 64, 64, 65, 65, 66, 66,
683   - 67, 67, 68, 68, 69, 69, 69, 70, 70, 70,
684   - 70, 70, 71, 71, 71, 72, 72, 72, 73, 73,
685   - 73, 73, 74, 74, 74, 74, 75, 75, 75, 76,
686   - 76, 76, 77, 77, 77
  681 + 53, 54, 54, 54, 54, 54, 54, 55, 56, 56,
  682 + 57, 57, 57, 57, 58, 58, 58, 58, 58, 58,
  683 + 58, 59, 59, 59, 60, 60, 60, 60, 60, 61,
  684 + 61, 61, 62, 63, 63, 64, 64, 65, 65, 66,
  685 + 66, 67, 67, 68, 68, 69, 69, 69, 70, 70,
  686 + 70, 70, 70, 71, 71, 71, 72, 72, 72, 73,
  687 + 73, 73, 73, 74, 74, 74, 74, 75, 75, 75,
  688 + 76, 76, 76, 77, 77, 77
687 689 };
688 690  
689 691 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
690 692 static const yytype_uint8 yyr2[] =
691 693 {
692 694 0, 2, 3, 2, 4, 1, 2, 0, 2, 4,
693   - 2, 2, 3, 4, 3, 4, 5, 0, 2, 4,
694   - 2, 3, 2, 2, 3, 4, 2, 9, 5, 2,
695   - 0, 2, 2, 3, 1, 2, 2, 2, 1, 1,
696   - 3, 1, 1, 5, 1, 3, 1, 3, 1, 3,
697   - 1, 3, 1, 3, 1, 3, 3, 1, 3, 3,
698   - 3, 3, 3, 3, 1, 3, 3, 1, 3, 3,
699   - 3, 1, 1, 2, 2, 2, 0, 2, 2, 0,
700   - 2, 2, 2, 3, 2
  695 + 2, 2, 3, 4, 3, 4, 0, 5, 0, 2,
  696 + 4, 2, 3, 2, 2, 3, 4, 2, 9, 5,
  697 + 2, 0, 2, 2, 3, 1, 2, 2, 2, 1,
  698 + 1, 3, 1, 1, 5, 1, 3, 1, 3, 1,
  699 + 3, 1, 3, 1, 3, 1, 3, 3, 1, 3,
  700 + 3, 3, 3, 3, 3, 1, 3, 3, 1, 3,
  701 + 3, 3, 1, 1, 2, 2, 2, 0, 2, 2,
  702 + 0, 2, 2, 2, 3, 2
701 703 };
702 704  
703 705  
... ... @@ -1472,7 +1474,7 @@
1472 1474 parser_output = build_dt_info((yyvsp[-2].flags), (yyvsp[-1].re), (yyvsp[0].node),
1473 1475 guess_boot_cpuid((yyvsp[0].node)));
1474 1476 }
1475   -#line 1476 "dtc-parser.tab.c" /* yacc.c:1646 */
  1477 +#line 1478 "dtc-parser.tab.c" /* yacc.c:1646 */
1476 1478 break;
1477 1479  
1478 1480 case 3:
... ... @@ -1480,7 +1482,7 @@
1480 1482 {
1481 1483 (yyval.flags) = DTSF_V1;
1482 1484 }
1483   -#line 1484 "dtc-parser.tab.c" /* yacc.c:1646 */
  1485 +#line 1486 "dtc-parser.tab.c" /* yacc.c:1646 */
1484 1486 break;
1485 1487  
1486 1488 case 4:
... ... @@ -1488,7 +1490,7 @@
1488 1490 {
1489 1491 (yyval.flags) = DTSF_V1 | DTSF_PLUGIN;
1490 1492 }
1491   -#line 1492 "dtc-parser.tab.c" /* yacc.c:1646 */
  1493 +#line 1494 "dtc-parser.tab.c" /* yacc.c:1646 */
1492 1494 break;
1493 1495  
1494 1496 case 6:
... ... @@ -1498,7 +1500,7 @@
1498 1500 ERROR(&(yylsp[0]), "Header flags don't match earlier ones");
1499 1501 (yyval.flags) = (yyvsp[-1].flags);
1500 1502 }
1501   -#line 1502 "dtc-parser.tab.c" /* yacc.c:1646 */
  1503 +#line 1504 "dtc-parser.tab.c" /* yacc.c:1646 */
1502 1504 break;
1503 1505  
1504 1506 case 7:
... ... @@ -1506,7 +1508,7 @@
1506 1508 {
1507 1509 (yyval.re) = NULL;
1508 1510 }
1509   -#line 1510 "dtc-parser.tab.c" /* yacc.c:1646 */
  1511 +#line 1512 "dtc-parser.tab.c" /* yacc.c:1646 */
1510 1512 break;
1511 1513  
1512 1514 case 8:
... ... @@ -1514,7 +1516,7 @@
1514 1516 {
1515 1517 (yyval.re) = chain_reserve_entry((yyvsp[-1].re), (yyvsp[0].re));
1516 1518 }
1517   -#line 1518 "dtc-parser.tab.c" /* yacc.c:1646 */
  1519 +#line 1520 "dtc-parser.tab.c" /* yacc.c:1646 */
1518 1520 break;
1519 1521  
1520 1522 case 9:
... ... @@ -1522,7 +1524,7 @@
1522 1524 {
1523 1525 (yyval.re) = build_reserve_entry((yyvsp[-2].integer), (yyvsp[-1].integer));
1524 1526 }
1525   -#line 1526 "dtc-parser.tab.c" /* yacc.c:1646 */
  1527 +#line 1528 "dtc-parser.tab.c" /* yacc.c:1646 */
1526 1528 break;
1527 1529  
1528 1530 case 10:
... ... @@ -1531,7 +1533,7 @@
1531 1533 add_label(&(yyvsp[0].re)->labels, (yyvsp[-1].labelref));
1532 1534 (yyval.re) = (yyvsp[0].re);
1533 1535 }
1534   -#line 1535 "dtc-parser.tab.c" /* yacc.c:1646 */
  1536 +#line 1537 "dtc-parser.tab.c" /* yacc.c:1646 */
1535 1537 break;
1536 1538  
1537 1539 case 11:
... ... @@ -1539,7 +1541,7 @@
1539 1541 {
1540 1542 (yyval.node) = name_node((yyvsp[0].node), "");
1541 1543 }
1542   -#line 1543 "dtc-parser.tab.c" /* yacc.c:1646 */
  1544 +#line 1545 "dtc-parser.tab.c" /* yacc.c:1646 */
1543 1545 break;
1544 1546  
1545 1547 case 12:
... ... @@ -1547,7 +1549,7 @@
1547 1549 {
1548 1550 (yyval.node) = merge_nodes((yyvsp[-2].node), (yyvsp[0].node));
1549 1551 }
1550   -#line 1551 "dtc-parser.tab.c" /* yacc.c:1646 */
  1552 +#line 1553 "dtc-parser.tab.c" /* yacc.c:1646 */
1551 1553 break;
1552 1554  
1553 1555 case 13:
... ... @@ -1562,7 +1564,7 @@
1562 1564 ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
1563 1565 (yyval.node) = (yyvsp[-3].node);
1564 1566 }
1565   -#line 1566 "dtc-parser.tab.c" /* yacc.c:1646 */
  1567 +#line 1568 "dtc-parser.tab.c" /* yacc.c:1646 */
1566 1568 break;
1567 1569  
1568 1570 case 14:
1569 1571  
1570 1572  
1571 1573  
... ... @@ -1570,17 +1572,26 @@
1570 1572 {
1571 1573 struct node *target = get_node_by_ref((yyvsp[-2].node), (yyvsp[-1].labelref));
1572 1574  
1573   - if (target)
  1575 + if (target) {
1574 1576 merge_nodes(target, (yyvsp[0].node));
1575   - else
1576   - ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  1577 + } else {
  1578 + /*
  1579 + * We rely on the rule being always:
  1580 + * versioninfo plugindecl memreserves devicetree
  1581 + * so $-1 is what we want (plugindecl)
  1582 + */
  1583 + if ((yyvsp[(-1) - (3)].flags) & DTSF_PLUGIN)
  1584 + add_orphan_node((yyvsp[-2].node), (yyvsp[0].node), (yyvsp[-1].labelref));
  1585 + else
  1586 + ERROR(&(yylsp[-1]), "Label or path %s not found", (yyvsp[-1].labelref));
  1587 + }
1577 1588 (yyval.node) = (yyvsp[-2].node);
1578 1589 }
1579   -#line 1580 "dtc-parser.tab.c" /* yacc.c:1646 */
  1590 +#line 1591 "dtc-parser.tab.c" /* yacc.c:1646 */
1580 1591 break;
1581 1592  
1582 1593 case 15:
1583   -#line 192 "dtc-parser.y" /* yacc.c:1646 */
  1594 +#line 201 "dtc-parser.y" /* yacc.c:1646 */
1584 1595 {
1585 1596 struct node *target = get_node_by_ref((yyvsp[-3].node), (yyvsp[-1].labelref));
1586 1597  
1587 1598  
1588 1599  
1589 1600  
1590 1601  
1591 1602  
1592 1603  
1593 1604  
1594 1605  
1595 1606  
1596 1607  
1597 1608  
1598 1609  
1599 1610  
1600 1611  
1601 1612  
1602 1613  
1603 1614  
1604 1615  
1605 1616  
1606 1617  
1607 1618  
1608 1619  
1609 1620  
1610 1621  
1611 1622  
1612 1623  
1613 1624  
1614 1625  
1615 1626  
1616 1627  
... ... @@ -1592,100 +1603,109 @@
1592 1603  
1593 1604 (yyval.node) = (yyvsp[-3].node);
1594 1605 }
1595   -#line 1596 "dtc-parser.tab.c" /* yacc.c:1646 */
  1606 +#line 1607 "dtc-parser.tab.c" /* yacc.c:1646 */
1596 1607 break;
1597 1608  
1598 1609 case 16:
1599   -#line 207 "dtc-parser.y" /* yacc.c:1646 */
  1610 +#line 213 "dtc-parser.y" /* yacc.c:1646 */
1600 1611 {
1601   - (yyval.node) = build_node((yyvsp[-3].proplist), (yyvsp[-2].nodelist));
  1612 + /* build empty node */
  1613 + (yyval.node) = name_node(build_node(NULL, NULL), "");
1602 1614 }
1603   -#line 1604 "dtc-parser.tab.c" /* yacc.c:1646 */
  1615 +#line 1616 "dtc-parser.tab.c" /* yacc.c:1646 */
1604 1616 break;
1605 1617  
1606 1618 case 17:
1607   -#line 214 "dtc-parser.y" /* yacc.c:1646 */
  1619 +#line 221 "dtc-parser.y" /* yacc.c:1646 */
1608 1620 {
1609   - (yyval.proplist) = NULL;
  1621 + (yyval.node) = build_node((yyvsp[-3].proplist), (yyvsp[-2].nodelist));
1610 1622 }
1611   -#line 1612 "dtc-parser.tab.c" /* yacc.c:1646 */
  1623 +#line 1624 "dtc-parser.tab.c" /* yacc.c:1646 */
1612 1624 break;
1613 1625  
1614 1626 case 18:
1615   -#line 218 "dtc-parser.y" /* yacc.c:1646 */
  1627 +#line 228 "dtc-parser.y" /* yacc.c:1646 */
1616 1628 {
1617   - (yyval.proplist) = chain_property((yyvsp[0].prop), (yyvsp[-1].proplist));
  1629 + (yyval.proplist) = NULL;
1618 1630 }
1619   -#line 1620 "dtc-parser.tab.c" /* yacc.c:1646 */
  1631 +#line 1632 "dtc-parser.tab.c" /* yacc.c:1646 */
1620 1632 break;
1621 1633  
1622 1634 case 19:
1623   -#line 225 "dtc-parser.y" /* yacc.c:1646 */
  1635 +#line 232 "dtc-parser.y" /* yacc.c:1646 */
1624 1636 {
1625   - (yyval.prop) = build_property((yyvsp[-3].propnodename), (yyvsp[-1].data));
  1637 + (yyval.proplist) = chain_property((yyvsp[0].prop), (yyvsp[-1].proplist));
1626 1638 }
1627   -#line 1628 "dtc-parser.tab.c" /* yacc.c:1646 */
  1639 +#line 1640 "dtc-parser.tab.c" /* yacc.c:1646 */
1628 1640 break;
1629 1641  
1630 1642 case 20:
1631   -#line 229 "dtc-parser.y" /* yacc.c:1646 */
  1643 +#line 239 "dtc-parser.y" /* yacc.c:1646 */
1632 1644 {
1633   - (yyval.prop) = build_property((yyvsp[-1].propnodename), empty_data);
  1645 + (yyval.prop) = build_property((yyvsp[-3].propnodename), (yyvsp[-1].data));
1634 1646 }
1635   -#line 1636 "dtc-parser.tab.c" /* yacc.c:1646 */
  1647 +#line 1648 "dtc-parser.tab.c" /* yacc.c:1646 */
1636 1648 break;
1637 1649  
1638 1650 case 21:
1639   -#line 233 "dtc-parser.y" /* yacc.c:1646 */
  1651 +#line 243 "dtc-parser.y" /* yacc.c:1646 */
1640 1652 {
1641   - (yyval.prop) = build_property_delete((yyvsp[-1].propnodename));
  1653 + (yyval.prop) = build_property((yyvsp[-1].propnodename), empty_data);
1642 1654 }
1643   -#line 1644 "dtc-parser.tab.c" /* yacc.c:1646 */
  1655 +#line 1656 "dtc-parser.tab.c" /* yacc.c:1646 */
1644 1656 break;
1645 1657  
1646 1658 case 22:
1647   -#line 237 "dtc-parser.y" /* yacc.c:1646 */
  1659 +#line 247 "dtc-parser.y" /* yacc.c:1646 */
1648 1660 {
  1661 + (yyval.prop) = build_property_delete((yyvsp[-1].propnodename));
  1662 + }
  1663 +#line 1664 "dtc-parser.tab.c" /* yacc.c:1646 */
  1664 + break;
  1665 +
  1666 + case 23:
  1667 +#line 251 "dtc-parser.y" /* yacc.c:1646 */
  1668 + {
1649 1669 add_label(&(yyvsp[0].prop)->labels, (yyvsp[-1].labelref));
1650 1670 (yyval.prop) = (yyvsp[0].prop);
1651 1671 }
1652   -#line 1653 "dtc-parser.tab.c" /* yacc.c:1646 */
  1672 +#line 1673 "dtc-parser.tab.c" /* yacc.c:1646 */
1653 1673 break;
1654 1674  
1655   - case 23:
1656   -#line 245 "dtc-parser.y" /* yacc.c:1646 */
  1675 + case 24:
  1676 +#line 259 "dtc-parser.y" /* yacc.c:1646 */
1657 1677 {
1658 1678 (yyval.data) = data_merge((yyvsp[-1].data), (yyvsp[0].data));
1659 1679 }
1660   -#line 1661 "dtc-parser.tab.c" /* yacc.c:1646 */
  1680 +#line 1681 "dtc-parser.tab.c" /* yacc.c:1646 */
1661 1681 break;
1662 1682  
1663   - case 24:
1664   -#line 249 "dtc-parser.y" /* yacc.c:1646 */
  1683 + case 25:
  1684 +#line 263 "dtc-parser.y" /* yacc.c:1646 */
1665 1685 {
1666 1686 (yyval.data) = data_merge((yyvsp[-2].data), (yyvsp[-1].array).data);
1667 1687 }
1668   -#line 1669 "dtc-parser.tab.c" /* yacc.c:1646 */
  1688 +#line 1689 "dtc-parser.tab.c" /* yacc.c:1646 */
1669 1689 break;
1670 1690  
1671   - case 25:
1672   -#line 253 "dtc-parser.y" /* yacc.c:1646 */
  1691 + case 26:
  1692 +#line 267 "dtc-parser.y" /* yacc.c:1646 */
1673 1693 {
1674 1694 (yyval.data) = data_merge((yyvsp[-3].data), (yyvsp[-1].data));
1675 1695 }
1676   -#line 1677 "dtc-parser.tab.c" /* yacc.c:1646 */
  1696 +#line 1697 "dtc-parser.tab.c" /* yacc.c:1646 */
1677 1697 break;
1678 1698  
1679   - case 26:
1680   -#line 257 "dtc-parser.y" /* yacc.c:1646 */
  1699 + case 27:
  1700 +#line 271 "dtc-parser.y" /* yacc.c:1646 */
1681 1701 {
1682 1702 (yyval.data) = data_add_marker((yyvsp[-1].data), REF_PATH, (yyvsp[0].labelref));
1683 1703 }
1684   -#line 1685 "dtc-parser.tab.c" /* yacc.c:1646 */
  1704 +#line 1705 "dtc-parser.tab.c" /* yacc.c:1646 */
1685 1705 break;
1686 1706  
1687   - case 27:
1688   -#line 261 "dtc-parser.y" /* yacc.c:1646 */
  1707 + case 28:
  1708 +#line 275 "dtc-parser.y" /* yacc.c:1646 */
1689 1709 {
1690 1710 FILE *f = srcfile_relative_open((yyvsp[-5].data).val, NULL);
1691 1711 struct data d;
1692 1712  
... ... @@ -1701,11 +1721,11 @@
1701 1721 (yyval.data) = data_merge((yyvsp[-8].data), d);
1702 1722 fclose(f);
1703 1723 }
1704   -#line 1705 "dtc-parser.tab.c" /* yacc.c:1646 */
  1724 +#line 1725 "dtc-parser.tab.c" /* yacc.c:1646 */
1705 1725 break;
1706 1726  
1707   - case 28:
1708   -#line 277 "dtc-parser.y" /* yacc.c:1646 */
  1727 + case 29:
  1728 +#line 291 "dtc-parser.y" /* yacc.c:1646 */
1709 1729 {
1710 1730 FILE *f = srcfile_relative_open((yyvsp[-1].data).val, NULL);
1711 1731 struct data d = empty_data;
1712 1732  
1713 1733  
1714 1734  
1715 1735  
1716 1736  
1717 1737  
1718 1738  
1719 1739  
1720 1740  
... ... @@ -1715,43 +1735,43 @@
1715 1735 (yyval.data) = data_merge((yyvsp[-4].data), d);
1716 1736 fclose(f);
1717 1737 }
1718   -#line 1719 "dtc-parser.tab.c" /* yacc.c:1646 */
  1738 +#line 1739 "dtc-parser.tab.c" /* yacc.c:1646 */
1719 1739 break;
1720 1740  
1721   - case 29:
1722   -#line 287 "dtc-parser.y" /* yacc.c:1646 */
  1741 + case 30:
  1742 +#line 301 "dtc-parser.y" /* yacc.c:1646 */
1723 1743 {
1724 1744 (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
1725 1745 }
1726   -#line 1727 "dtc-parser.tab.c" /* yacc.c:1646 */
  1746 +#line 1747 "dtc-parser.tab.c" /* yacc.c:1646 */
1727 1747 break;
1728 1748  
1729   - case 30:
1730   -#line 294 "dtc-parser.y" /* yacc.c:1646 */
  1749 + case 31:
  1750 +#line 308 "dtc-parser.y" /* yacc.c:1646 */
1731 1751 {
1732 1752 (yyval.data) = empty_data;
1733 1753 }
1734   -#line 1735 "dtc-parser.tab.c" /* yacc.c:1646 */
  1754 +#line 1755 "dtc-parser.tab.c" /* yacc.c:1646 */
1735 1755 break;
1736 1756  
1737   - case 31:
1738   -#line 298 "dtc-parser.y" /* yacc.c:1646 */
  1757 + case 32:
  1758 +#line 312 "dtc-parser.y" /* yacc.c:1646 */
1739 1759 {
1740 1760 (yyval.data) = (yyvsp[-1].data);
1741 1761 }
1742   -#line 1743 "dtc-parser.tab.c" /* yacc.c:1646 */
  1762 +#line 1763 "dtc-parser.tab.c" /* yacc.c:1646 */
1743 1763 break;
1744 1764  
1745   - case 32:
1746   -#line 302 "dtc-parser.y" /* yacc.c:1646 */
  1765 + case 33:
  1766 +#line 316 "dtc-parser.y" /* yacc.c:1646 */
1747 1767 {
1748 1768 (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
1749 1769 }
1750   -#line 1751 "dtc-parser.tab.c" /* yacc.c:1646 */
  1770 +#line 1771 "dtc-parser.tab.c" /* yacc.c:1646 */
1751 1771 break;
1752 1772  
1753   - case 33:
1754   -#line 309 "dtc-parser.y" /* yacc.c:1646 */
  1773 + case 34:
  1774 +#line 323 "dtc-parser.y" /* yacc.c:1646 */
1755 1775 {
1756 1776 unsigned long long bits;
1757 1777  
1758 1778  
1759 1779  
1760 1780  
... ... @@ -1767,20 +1787,20 @@
1767 1787 (yyval.array).data = empty_data;
1768 1788 (yyval.array).bits = bits;
1769 1789 }
1770   -#line 1771 "dtc-parser.tab.c" /* yacc.c:1646 */
  1790 +#line 1791 "dtc-parser.tab.c" /* yacc.c:1646 */
1771 1791 break;
1772 1792  
1773   - case 34:
1774   -#line 325 "dtc-parser.y" /* yacc.c:1646 */
  1793 + case 35:
  1794 +#line 339 "dtc-parser.y" /* yacc.c:1646 */
1775 1795 {
1776 1796 (yyval.array).data = empty_data;
1777 1797 (yyval.array).bits = 32;
1778 1798 }
1779   -#line 1780 "dtc-parser.tab.c" /* yacc.c:1646 */
  1799 +#line 1800 "dtc-parser.tab.c" /* yacc.c:1646 */
1780 1800 break;
1781 1801  
1782   - case 35:
1783   -#line 330 "dtc-parser.y" /* yacc.c:1646 */
  1802 + case 36:
  1803 +#line 344 "dtc-parser.y" /* yacc.c:1646 */
1784 1804 {
1785 1805 if ((yyvsp[-1].array).bits < 64) {
1786 1806 uint64_t mask = (1ULL << (yyvsp[-1].array).bits) - 1;
1787 1807  
... ... @@ -1799,11 +1819,11 @@
1799 1819  
1800 1820 (yyval.array).data = data_append_integer((yyvsp[-1].array).data, (yyvsp[0].integer), (yyvsp[-1].array).bits);
1801 1821 }
1802   -#line 1803 "dtc-parser.tab.c" /* yacc.c:1646 */
  1822 +#line 1823 "dtc-parser.tab.c" /* yacc.c:1646 */
1803 1823 break;
1804 1824  
1805   - case 36:
1806   -#line 349 "dtc-parser.y" /* yacc.c:1646 */
  1825 + case 37:
  1826 +#line 363 "dtc-parser.y" /* yacc.c:1646 */
1807 1827 {
1808 1828 uint64_t val = ~0ULL >> (64 - (yyvsp[-1].array).bits);
1809 1829  
1810 1830  
1811 1831  
1812 1832  
1813 1833  
1814 1834  
1815 1835  
1816 1836  
1817 1837  
1818 1838  
1819 1839  
1820 1840  
1821 1841  
1822 1842  
1823 1843  
1824 1844  
1825 1845  
1826 1846  
1827 1847  
1828 1848  
1829 1849  
1830 1850  
1831 1851  
1832 1852  
1833 1853  
1834 1854  
1835 1855  
1836 1856  
1837 1857  
1838 1858  
1839 1859  
1840 1860  
1841 1861  
1842 1862  
1843 1863  
1844 1864  
1845 1865  
1846 1866  
1847 1867  
1848 1868  
... ... @@ -1817,129 +1837,129 @@
1817 1837  
1818 1838 (yyval.array).data = data_append_integer((yyvsp[-1].array).data, val, (yyvsp[-1].array).bits);
1819 1839 }
1820   -#line 1821 "dtc-parser.tab.c" /* yacc.c:1646 */
  1840 +#line 1841 "dtc-parser.tab.c" /* yacc.c:1646 */
1821 1841 break;
1822 1842  
1823   - case 37:
1824   -#line 363 "dtc-parser.y" /* yacc.c:1646 */
  1843 + case 38:
  1844 +#line 377 "dtc-parser.y" /* yacc.c:1646 */
1825 1845 {
1826 1846 (yyval.array).data = data_add_marker((yyvsp[-1].array).data, LABEL, (yyvsp[0].labelref));
1827 1847 }
1828   -#line 1829 "dtc-parser.tab.c" /* yacc.c:1646 */
  1848 +#line 1849 "dtc-parser.tab.c" /* yacc.c:1646 */
1829 1849 break;
1830 1850  
1831   - case 40:
1832   -#line 372 "dtc-parser.y" /* yacc.c:1646 */
  1851 + case 41:
  1852 +#line 386 "dtc-parser.y" /* yacc.c:1646 */
1833 1853 {
1834 1854 (yyval.integer) = (yyvsp[-1].integer);
1835 1855 }
1836   -#line 1837 "dtc-parser.tab.c" /* yacc.c:1646 */
  1856 +#line 1857 "dtc-parser.tab.c" /* yacc.c:1646 */
1837 1857 break;
1838 1858  
1839   - case 43:
1840   -#line 383 "dtc-parser.y" /* yacc.c:1646 */
  1859 + case 44:
  1860 +#line 397 "dtc-parser.y" /* yacc.c:1646 */
1841 1861 { (yyval.integer) = (yyvsp[-4].integer) ? (yyvsp[-2].integer) : (yyvsp[0].integer); }
1842   -#line 1843 "dtc-parser.tab.c" /* yacc.c:1646 */
  1862 +#line 1863 "dtc-parser.tab.c" /* yacc.c:1646 */
1843 1863 break;
1844 1864  
1845   - case 45:
1846   -#line 388 "dtc-parser.y" /* yacc.c:1646 */
  1865 + case 46:
  1866 +#line 402 "dtc-parser.y" /* yacc.c:1646 */
1847 1867 { (yyval.integer) = (yyvsp[-2].integer) || (yyvsp[0].integer); }
1848   -#line 1849 "dtc-parser.tab.c" /* yacc.c:1646 */
  1868 +#line 1869 "dtc-parser.tab.c" /* yacc.c:1646 */
1849 1869 break;
1850 1870  
1851   - case 47:
1852   -#line 393 "dtc-parser.y" /* yacc.c:1646 */
  1871 + case 48:
  1872 +#line 407 "dtc-parser.y" /* yacc.c:1646 */
1853 1873 { (yyval.integer) = (yyvsp[-2].integer) && (yyvsp[0].integer); }
1854   -#line 1855 "dtc-parser.tab.c" /* yacc.c:1646 */
  1874 +#line 1875 "dtc-parser.tab.c" /* yacc.c:1646 */
1855 1875 break;
1856 1876  
1857   - case 49:
1858   -#line 398 "dtc-parser.y" /* yacc.c:1646 */
  1877 + case 50:
  1878 +#line 412 "dtc-parser.y" /* yacc.c:1646 */
1859 1879 { (yyval.integer) = (yyvsp[-2].integer) | (yyvsp[0].integer); }
1860   -#line 1861 "dtc-parser.tab.c" /* yacc.c:1646 */
  1880 +#line 1881 "dtc-parser.tab.c" /* yacc.c:1646 */
1861 1881 break;
1862 1882  
1863   - case 51:
1864   -#line 403 "dtc-parser.y" /* yacc.c:1646 */
  1883 + case 52:
  1884 +#line 417 "dtc-parser.y" /* yacc.c:1646 */
1865 1885 { (yyval.integer) = (yyvsp[-2].integer) ^ (yyvsp[0].integer); }
1866   -#line 1867 "dtc-parser.tab.c" /* yacc.c:1646 */
  1886 +#line 1887 "dtc-parser.tab.c" /* yacc.c:1646 */
1867 1887 break;
1868 1888  
1869   - case 53:
1870   -#line 408 "dtc-parser.y" /* yacc.c:1646 */
  1889 + case 54:
  1890 +#line 422 "dtc-parser.y" /* yacc.c:1646 */
1871 1891 { (yyval.integer) = (yyvsp[-2].integer) & (yyvsp[0].integer); }
1872   -#line 1873 "dtc-parser.tab.c" /* yacc.c:1646 */
  1892 +#line 1893 "dtc-parser.tab.c" /* yacc.c:1646 */
1873 1893 break;
1874 1894  
1875   - case 55:
1876   -#line 413 "dtc-parser.y" /* yacc.c:1646 */
  1895 + case 56:
  1896 +#line 427 "dtc-parser.y" /* yacc.c:1646 */
1877 1897 { (yyval.integer) = (yyvsp[-2].integer) == (yyvsp[0].integer); }
1878   -#line 1879 "dtc-parser.tab.c" /* yacc.c:1646 */
  1898 +#line 1899 "dtc-parser.tab.c" /* yacc.c:1646 */
1879 1899 break;
1880 1900  
1881   - case 56:
1882   -#line 414 "dtc-parser.y" /* yacc.c:1646 */
  1901 + case 57:
  1902 +#line 428 "dtc-parser.y" /* yacc.c:1646 */
1883 1903 { (yyval.integer) = (yyvsp[-2].integer) != (yyvsp[0].integer); }
1884   -#line 1885 "dtc-parser.tab.c" /* yacc.c:1646 */
  1904 +#line 1905 "dtc-parser.tab.c" /* yacc.c:1646 */
1885 1905 break;
1886 1906  
1887   - case 58:
1888   -#line 419 "dtc-parser.y" /* yacc.c:1646 */
  1907 + case 59:
  1908 +#line 433 "dtc-parser.y" /* yacc.c:1646 */
1889 1909 { (yyval.integer) = (yyvsp[-2].integer) < (yyvsp[0].integer); }
1890   -#line 1891 "dtc-parser.tab.c" /* yacc.c:1646 */
  1910 +#line 1911 "dtc-parser.tab.c" /* yacc.c:1646 */
1891 1911 break;
1892 1912  
1893   - case 59:
1894   -#line 420 "dtc-parser.y" /* yacc.c:1646 */
  1913 + case 60:
  1914 +#line 434 "dtc-parser.y" /* yacc.c:1646 */
1895 1915 { (yyval.integer) = (yyvsp[-2].integer) > (yyvsp[0].integer); }
1896   -#line 1897 "dtc-parser.tab.c" /* yacc.c:1646 */
  1916 +#line 1917 "dtc-parser.tab.c" /* yacc.c:1646 */
1897 1917 break;
1898 1918  
1899   - case 60:
1900   -#line 421 "dtc-parser.y" /* yacc.c:1646 */
  1919 + case 61:
  1920 +#line 435 "dtc-parser.y" /* yacc.c:1646 */
1901 1921 { (yyval.integer) = (yyvsp[-2].integer) <= (yyvsp[0].integer); }
1902   -#line 1903 "dtc-parser.tab.c" /* yacc.c:1646 */
  1922 +#line 1923 "dtc-parser.tab.c" /* yacc.c:1646 */
1903 1923 break;
1904 1924  
1905   - case 61:
1906   -#line 422 "dtc-parser.y" /* yacc.c:1646 */
  1925 + case 62:
  1926 +#line 436 "dtc-parser.y" /* yacc.c:1646 */
1907 1927 { (yyval.integer) = (yyvsp[-2].integer) >= (yyvsp[0].integer); }
1908   -#line 1909 "dtc-parser.tab.c" /* yacc.c:1646 */
  1928 +#line 1929 "dtc-parser.tab.c" /* yacc.c:1646 */
1909 1929 break;
1910 1930  
1911   - case 62:
1912   -#line 426 "dtc-parser.y" /* yacc.c:1646 */
  1931 + case 63:
  1932 +#line 440 "dtc-parser.y" /* yacc.c:1646 */
1913 1933 { (yyval.integer) = (yyvsp[-2].integer) << (yyvsp[0].integer); }
1914   -#line 1915 "dtc-parser.tab.c" /* yacc.c:1646 */
  1934 +#line 1935 "dtc-parser.tab.c" /* yacc.c:1646 */
1915 1935 break;
1916 1936  
1917   - case 63:
1918   -#line 427 "dtc-parser.y" /* yacc.c:1646 */
  1937 + case 64:
  1938 +#line 441 "dtc-parser.y" /* yacc.c:1646 */
1919 1939 { (yyval.integer) = (yyvsp[-2].integer) >> (yyvsp[0].integer); }
1920   -#line 1921 "dtc-parser.tab.c" /* yacc.c:1646 */
  1940 +#line 1941 "dtc-parser.tab.c" /* yacc.c:1646 */
1921 1941 break;
1922 1942  
1923   - case 65:
1924   -#line 432 "dtc-parser.y" /* yacc.c:1646 */
  1943 + case 66:
  1944 +#line 446 "dtc-parser.y" /* yacc.c:1646 */
1925 1945 { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }
1926   -#line 1927 "dtc-parser.tab.c" /* yacc.c:1646 */
  1946 +#line 1947 "dtc-parser.tab.c" /* yacc.c:1646 */
1927 1947 break;
1928 1948  
1929   - case 66:
1930   -#line 433 "dtc-parser.y" /* yacc.c:1646 */
  1949 + case 67:
  1950 +#line 447 "dtc-parser.y" /* yacc.c:1646 */
1931 1951 { (yyval.integer) = (yyvsp[-2].integer) - (yyvsp[0].integer); }
1932   -#line 1933 "dtc-parser.tab.c" /* yacc.c:1646 */
  1952 +#line 1953 "dtc-parser.tab.c" /* yacc.c:1646 */
1933 1953 break;
1934 1954  
1935   - case 68:
1936   -#line 438 "dtc-parser.y" /* yacc.c:1646 */
  1955 + case 69:
  1956 +#line 452 "dtc-parser.y" /* yacc.c:1646 */
1937 1957 { (yyval.integer) = (yyvsp[-2].integer) * (yyvsp[0].integer); }
1938   -#line 1939 "dtc-parser.tab.c" /* yacc.c:1646 */
  1958 +#line 1959 "dtc-parser.tab.c" /* yacc.c:1646 */
1939 1959 break;
1940 1960  
1941   - case 69:
1942   -#line 440 "dtc-parser.y" /* yacc.c:1646 */
  1961 + case 70:
  1962 +#line 454 "dtc-parser.y" /* yacc.c:1646 */
1943 1963 {
1944 1964 if ((yyvsp[0].integer) != 0) {
1945 1965 (yyval.integer) = (yyvsp[-2].integer) / (yyvsp[0].integer);
1946 1966  
... ... @@ -1948,11 +1968,11 @@
1948 1968 (yyval.integer) = 0;
1949 1969 }
1950 1970 }
1951   -#line 1952 "dtc-parser.tab.c" /* yacc.c:1646 */
  1971 +#line 1972 "dtc-parser.tab.c" /* yacc.c:1646 */
1952 1972 break;
1953 1973  
1954   - case 70:
1955   -#line 449 "dtc-parser.y" /* yacc.c:1646 */
  1974 + case 71:
  1975 +#line 463 "dtc-parser.y" /* yacc.c:1646 */
1956 1976 {
1957 1977 if ((yyvsp[0].integer) != 0) {
1958 1978 (yyval.integer) = (yyvsp[-2].integer) % (yyvsp[0].integer);
1959 1979  
1960 1980  
1961 1981  
1962 1982  
1963 1983  
1964 1984  
1965 1985  
1966 1986  
1967 1987  
1968 1988  
1969 1989  
1970 1990  
1971 1991  
1972 1992  
1973 1993  
1974 1994  
1975 1995  
1976 1996  
1977 1997  
1978 1998  
1979 1999  
1980 2000  
1981 2001  
1982 2002  
1983 2003  
... ... @@ -1961,103 +1981,103 @@
1961 1981 (yyval.integer) = 0;
1962 1982 }
1963 1983 }
1964   -#line 1965 "dtc-parser.tab.c" /* yacc.c:1646 */
  1984 +#line 1985 "dtc-parser.tab.c" /* yacc.c:1646 */
1965 1985 break;
1966 1986  
1967   - case 73:
1968   -#line 462 "dtc-parser.y" /* yacc.c:1646 */
  1987 + case 74:
  1988 +#line 476 "dtc-parser.y" /* yacc.c:1646 */
1969 1989 { (yyval.integer) = -(yyvsp[0].integer); }
1970   -#line 1971 "dtc-parser.tab.c" /* yacc.c:1646 */
  1990 +#line 1991 "dtc-parser.tab.c" /* yacc.c:1646 */
1971 1991 break;
1972 1992  
1973   - case 74:
1974   -#line 463 "dtc-parser.y" /* yacc.c:1646 */
  1993 + case 75:
  1994 +#line 477 "dtc-parser.y" /* yacc.c:1646 */
1975 1995 { (yyval.integer) = ~(yyvsp[0].integer); }
1976   -#line 1977 "dtc-parser.tab.c" /* yacc.c:1646 */
  1996 +#line 1997 "dtc-parser.tab.c" /* yacc.c:1646 */
1977 1997 break;
1978 1998  
1979   - case 75:
1980   -#line 464 "dtc-parser.y" /* yacc.c:1646 */
  1999 + case 76:
  2000 +#line 478 "dtc-parser.y" /* yacc.c:1646 */
1981 2001 { (yyval.integer) = !(yyvsp[0].integer); }
1982   -#line 1983 "dtc-parser.tab.c" /* yacc.c:1646 */
  2002 +#line 2003 "dtc-parser.tab.c" /* yacc.c:1646 */
1983 2003 break;
1984 2004  
1985   - case 76:
1986   -#line 469 "dtc-parser.y" /* yacc.c:1646 */
  2005 + case 77:
  2006 +#line 483 "dtc-parser.y" /* yacc.c:1646 */
1987 2007 {
1988 2008 (yyval.data) = empty_data;
1989 2009 }
1990   -#line 1991 "dtc-parser.tab.c" /* yacc.c:1646 */
  2010 +#line 2011 "dtc-parser.tab.c" /* yacc.c:1646 */
1991 2011 break;
1992 2012  
1993   - case 77:
1994   -#line 473 "dtc-parser.y" /* yacc.c:1646 */
  2013 + case 78:
  2014 +#line 487 "dtc-parser.y" /* yacc.c:1646 */
1995 2015 {
1996 2016 (yyval.data) = data_append_byte((yyvsp[-1].data), (yyvsp[0].byte));
1997 2017 }
1998   -#line 1999 "dtc-parser.tab.c" /* yacc.c:1646 */
  2018 +#line 2019 "dtc-parser.tab.c" /* yacc.c:1646 */
1999 2019 break;
2000 2020  
2001   - case 78:
2002   -#line 477 "dtc-parser.y" /* yacc.c:1646 */
  2021 + case 79:
  2022 +#line 491 "dtc-parser.y" /* yacc.c:1646 */
2003 2023 {
2004 2024 (yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));
2005 2025 }
2006   -#line 2007 "dtc-parser.tab.c" /* yacc.c:1646 */
  2026 +#line 2027 "dtc-parser.tab.c" /* yacc.c:1646 */
2007 2027 break;
2008 2028  
2009   - case 79:
2010   -#line 484 "dtc-parser.y" /* yacc.c:1646 */
  2029 + case 80:
  2030 +#line 498 "dtc-parser.y" /* yacc.c:1646 */
2011 2031 {
2012 2032 (yyval.nodelist) = NULL;
2013 2033 }
2014   -#line 2015 "dtc-parser.tab.c" /* yacc.c:1646 */
  2034 +#line 2035 "dtc-parser.tab.c" /* yacc.c:1646 */
2015 2035 break;
2016 2036  
2017   - case 80:
2018   -#line 488 "dtc-parser.y" /* yacc.c:1646 */
  2037 + case 81:
  2038 +#line 502 "dtc-parser.y" /* yacc.c:1646 */
2019 2039 {
2020 2040 (yyval.nodelist) = chain_node((yyvsp[-1].node), (yyvsp[0].nodelist));
2021 2041 }
2022   -#line 2023 "dtc-parser.tab.c" /* yacc.c:1646 */
  2042 +#line 2043 "dtc-parser.tab.c" /* yacc.c:1646 */
2023 2043 break;
2024 2044  
2025   - case 81:
2026   -#line 492 "dtc-parser.y" /* yacc.c:1646 */
  2045 + case 82:
  2046 +#line 506 "dtc-parser.y" /* yacc.c:1646 */
2027 2047 {
2028 2048 ERROR(&(yylsp[0]), "Properties must precede subnodes");
2029 2049 YYERROR;
2030 2050 }
2031   -#line 2032 "dtc-parser.tab.c" /* yacc.c:1646 */
  2051 +#line 2052 "dtc-parser.tab.c" /* yacc.c:1646 */
2032 2052 break;
2033 2053  
2034   - case 82:
2035   -#line 500 "dtc-parser.y" /* yacc.c:1646 */
  2054 + case 83:
  2055 +#line 514 "dtc-parser.y" /* yacc.c:1646 */
2036 2056 {
2037 2057 (yyval.node) = name_node((yyvsp[0].node), (yyvsp[-1].propnodename));
2038 2058 }
2039   -#line 2040 "dtc-parser.tab.c" /* yacc.c:1646 */
  2059 +#line 2060 "dtc-parser.tab.c" /* yacc.c:1646 */
2040 2060 break;
2041 2061  
2042   - case 83:
2043   -#line 504 "dtc-parser.y" /* yacc.c:1646 */
  2062 + case 84:
  2063 +#line 518 "dtc-parser.y" /* yacc.c:1646 */
2044 2064 {
2045 2065 (yyval.node) = name_node(build_node_delete(), (yyvsp[-1].propnodename));
2046 2066 }
2047   -#line 2048 "dtc-parser.tab.c" /* yacc.c:1646 */
  2067 +#line 2068 "dtc-parser.tab.c" /* yacc.c:1646 */
2048 2068 break;
2049 2069  
2050   - case 84:
2051   -#line 508 "dtc-parser.y" /* yacc.c:1646 */
  2070 + case 85:
  2071 +#line 522 "dtc-parser.y" /* yacc.c:1646 */
2052 2072 {
2053 2073 add_label(&(yyvsp[0].node)->labels, (yyvsp[-1].labelref));
2054 2074 (yyval.node) = (yyvsp[0].node);
2055 2075 }
2056   -#line 2057 "dtc-parser.tab.c" /* yacc.c:1646 */
  2076 +#line 2077 "dtc-parser.tab.c" /* yacc.c:1646 */
2057 2077 break;
2058 2078  
2059 2079  
2060   -#line 2061 "dtc-parser.tab.c" /* yacc.c:1646 */
  2080 +#line 2081 "dtc-parser.tab.c" /* yacc.c:1646 */
2061 2081 default: break;
2062 2082 }
2063 2083 /* User semantic actions sometimes alter yychar, and that requires
... ... @@ -2292,7 +2312,7 @@
2292 2312 #endif
2293 2313 return yyresult;
2294 2314 }
2295   -#line 514 "dtc-parser.y" /* yacc.c:1906 */
  2315 +#line 528 "dtc-parser.y" /* yacc.c:1906 */
2296 2316  
2297 2317  
2298 2318 void yyerror(char const *s)
scripts/dtc/dtc-parser.tab.h_shipped
1   -/* A Bison parser, made by GNU Bison 3.0.2. */
  1 +/* A Bison parser, made by GNU Bison 3.0.4. */
2 2  
3 3 /* Bison interface for Yacc-like parsers in C
4 4  
5   - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
  5 + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 6  
7 7 This program is free software: you can redistribute it and/or modify
8 8 it under the terms of the GNU General Public License as published by
... ... @@ -72,7 +72,7 @@
72 72  
73 73 /* Value type. */
74 74 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
75   -typedef union YYSTYPE YYSTYPE;
  75 +
76 76 union YYSTYPE
77 77 {
78 78 #line 39 "dtc-parser.y" /* yacc.c:1909 */
... ... @@ -97,6 +97,8 @@
97 97  
98 98 #line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
99 99 };
  100 +
  101 +typedef union YYSTYPE YYSTYPE;
100 102 # define YYSTYPE_IS_TRIVIAL 1
101 103 # define YYSTYPE_IS_DECLARED 1
102 104 #endif
scripts/dtc/dtc-parser.y
... ... @@ -182,10 +182,19 @@
182 182 {
183 183 struct node *target = get_node_by_ref($1, $2);
184 184  
185   - if (target)
  185 + if (target) {
186 186 merge_nodes(target, $3);
187   - else
188   - ERROR(&@2, "Label or path %s not found", $2);
  187 + } else {
  188 + /*
  189 + * We rely on the rule being always:
  190 + * versioninfo plugindecl memreserves devicetree
  191 + * so $-1 is what we want (plugindecl)
  192 + */
  193 + if ($<flags>-1 & DTSF_PLUGIN)
  194 + add_orphan_node($1, $3, $2);
  195 + else
  196 + ERROR(&@2, "Label or path %s not found", $2);
  197 + }
189 198 $$ = $1;
190 199 }
191 200 | devicetree DT_DEL_NODE DT_REF ';'
... ... @@ -199,6 +208,11 @@
199 208  
200 209  
201 210 $$ = $1;
  211 + }
  212 + | /* empty */
  213 + {
  214 + /* build empty node */
  215 + $$ = name_node(build_node(NULL, NULL), "");
202 216 }
203 217 ;
204 218  
... ... @@ -203,6 +203,7 @@
203 203 struct node *name_node(struct node *node, char *name);
204 204 struct node *chain_node(struct node *first, struct node *list);
205 205 struct node *merge_nodes(struct node *old_node, struct node *new_node);
  206 +void add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
206 207  
207 208 void add_property(struct node *node, struct property *prop);
208 209 void delete_property_by_name(struct node *node, char *name);
... ... @@ -216,6 +217,7 @@
216 217 const char *get_unitname(struct node *node);
217 218 struct property *get_property(struct node *node, const char *propname);
218 219 cell_t propval_cell(struct property *prop);
  220 +cell_t propval_cell_n(struct property *prop, int n);
219 221 struct property *get_property_by_label(struct node *tree, const char *label,
220 222 struct node **node);
221 223 struct marker *get_marker_label(struct node *tree, const char *label,
scripts/dtc/libfdt/fdt_addresses.c
  1 +/*
  2 + * libfdt - Flat Device Tree manipulation
  3 + * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
  4 + *
  5 + * libfdt is dual licensed: you can use it either under the terms of
  6 + * the GPL, or the BSD license, at your option.
  7 + *
  8 + * a) This library is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of the
  11 + * License, or (at your option) any later version.
  12 + *
  13 + * This library is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public
  19 + * License along with this library; if not, write to the Free
  20 + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  21 + * MA 02110-1301 USA
  22 + *
  23 + * Alternatively,
  24 + *
  25 + * b) Redistribution and use in source and binary forms, with or
  26 + * without modification, are permitted provided that the following
  27 + * conditions are met:
  28 + *
  29 + * 1. Redistributions of source code must retain the above
  30 + * copyright notice, this list of conditions and the following
  31 + * disclaimer.
  32 + * 2. Redistributions in binary form must reproduce the above
  33 + * copyright notice, this list of conditions and the following
  34 + * disclaimer in the documentation and/or other materials
  35 + * provided with the distribution.
  36 + *
  37 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  38 + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  39 + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  40 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  41 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  44 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  46 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  47 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  48 + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  49 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50 + */
  51 +#include "libfdt_env.h"
  52 +
  53 +#include <fdt.h>
  54 +#include <libfdt.h>
  55 +
  56 +#include "libfdt_internal.h"
  57 +
  58 +int fdt_address_cells(const void *fdt, int nodeoffset)
  59 +{
  60 + const fdt32_t *ac;
  61 + int val;
  62 + int len;
  63 +
  64 + ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
  65 + if (!ac)
  66 + return 2;
  67 +
  68 + if (len != sizeof(*ac))
  69 + return -FDT_ERR_BADNCELLS;
  70 +
  71 + val = fdt32_to_cpu(*ac);
  72 + if ((val <= 0) || (val > FDT_MAX_NCELLS))
  73 + return -FDT_ERR_BADNCELLS;
  74 +
  75 + return val;
  76 +}
  77 +
  78 +int fdt_size_cells(const void *fdt, int nodeoffset)
  79 +{
  80 + const fdt32_t *sc;
  81 + int val;
  82 + int len;
  83 +
  84 + sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
  85 + if (!sc)
  86 + return 2;
  87 +
  88 + if (len != sizeof(*sc))
  89 + return -FDT_ERR_BADNCELLS;
  90 +
  91 + val = fdt32_to_cpu(*sc);
  92 + if ((val < 0) || (val > FDT_MAX_NCELLS))
  93 + return -FDT_ERR_BADNCELLS;
  94 +
  95 + return val;
  96 +}
scripts/dtc/libfdt/fdt_overlay.c
  1 +#include "libfdt_env.h"
  2 +
  3 +#include <fdt.h>
  4 +#include <libfdt.h>
  5 +
  6 +#include "libfdt_internal.h"
  7 +
  8 +/**
  9 + * overlay_get_target_phandle - retrieves the target phandle of a fragment
  10 + * @fdto: pointer to the device tree overlay blob
  11 + * @fragment: node offset of the fragment in the overlay
  12 + *
  13 + * overlay_get_target_phandle() retrieves the target phandle of an
  14 + * overlay fragment when that fragment uses a phandle (target
  15 + * property) instead of a path (target-path property).
  16 + *
  17 + * returns:
  18 + * the phandle pointed by the target property
  19 + * 0, if the phandle was not found
  20 + * -1, if the phandle was malformed
  21 + */
  22 +static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
  23 +{
  24 + const fdt32_t *val;
  25 + int len;
  26 +
  27 + val = fdt_getprop(fdto, fragment, "target", &len);
  28 + if (!val)
  29 + return 0;
  30 +
  31 + if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1))
  32 + return (uint32_t)-1;
  33 +
  34 + return fdt32_to_cpu(*val);
  35 +}
  36 +
  37 +/**
  38 + * overlay_get_target - retrieves the offset of a fragment's target
  39 + * @fdt: Base device tree blob
  40 + * @fdto: Device tree overlay blob
  41 + * @fragment: node offset of the fragment in the overlay
  42 + * @pathp: pointer which receives the path of the target (or NULL)
  43 + *
  44 + * overlay_get_target() retrieves the target offset in the base
  45 + * device tree of a fragment, no matter how the actual targetting is
  46 + * done (through a phandle or a path)
  47 + *
  48 + * returns:
  49 + * the targetted node offset in the base device tree
  50 + * Negative error code on error
  51 + */
  52 +static int overlay_get_target(const void *fdt, const void *fdto,
  53 + int fragment, char const **pathp)
  54 +{
  55 + uint32_t phandle;
  56 + const char *path = NULL;
  57 + int path_len = 0, ret;
  58 +
  59 + /* Try first to do a phandle based lookup */
  60 + phandle = overlay_get_target_phandle(fdto, fragment);
  61 + if (phandle == (uint32_t)-1)
  62 + return -FDT_ERR_BADPHANDLE;
  63 +
  64 + /* no phandle, try path */
  65 + if (!phandle) {
  66 + /* And then a path based lookup */
  67 + path = fdt_getprop(fdto, fragment, "target-path", &path_len);
  68 + if (path)
  69 + ret = fdt_path_offset(fdt, path);
  70 + else
  71 + ret = path_len;
  72 + } else
  73 + ret = fdt_node_offset_by_phandle(fdt, phandle);
  74 +
  75 + /*
  76 + * If we haven't found either a target or a
  77 + * target-path property in a node that contains a
  78 + * __overlay__ subnode (we wouldn't be called
  79 + * otherwise), consider it a improperly written
  80 + * overlay
  81 + */
  82 + if (ret < 0 && path_len == -FDT_ERR_NOTFOUND)
  83 + ret = -FDT_ERR_BADOVERLAY;
  84 +
  85 + /* return on error */
  86 + if (ret < 0)
  87 + return ret;
  88 +
  89 + /* return pointer to path (if available) */
  90 + if (pathp)
  91 + *pathp = path ? path : NULL;
  92 +
  93 + return ret;
  94 +}
  95 +
  96 +/**
  97 + * overlay_phandle_add_offset - Increases a phandle by an offset
  98 + * @fdt: Base device tree blob
  99 + * @node: Device tree overlay blob
  100 + * @name: Name of the property to modify (phandle or linux,phandle)
  101 + * @delta: offset to apply
  102 + *
  103 + * overlay_phandle_add_offset() increments a node phandle by a given
  104 + * offset.
  105 + *
  106 + * returns:
  107 + * 0 on success.
  108 + * Negative error code on error
  109 + */
  110 +static int overlay_phandle_add_offset(void *fdt, int node,
  111 + const char *name, uint32_t delta)
  112 +{
  113 + const fdt32_t *val;
  114 + uint32_t adj_val;
  115 + int len;
  116 +
  117 + val = fdt_getprop(fdt, node, name, &len);
  118 + if (!val)
  119 + return len;
  120 +
  121 + if (len != sizeof(*val))
  122 + return -FDT_ERR_BADPHANDLE;
  123 +
  124 + adj_val = fdt32_to_cpu(*val);
  125 + if ((adj_val + delta) < adj_val)
  126 + return -FDT_ERR_NOPHANDLES;
  127 +
  128 + adj_val += delta;
  129 + if (adj_val == (uint32_t)-1)
  130 + return -FDT_ERR_NOPHANDLES;
  131 +
  132 + return fdt_setprop_inplace_u32(fdt, node, name, adj_val);
  133 +}
  134 +
  135 +/**
  136 + * overlay_adjust_node_phandles - Offsets the phandles of a node
  137 + * @fdto: Device tree overlay blob
  138 + * @node: Offset of the node we want to adjust
  139 + * @delta: Offset to shift the phandles of
  140 + *
  141 + * overlay_adjust_node_phandles() adds a constant to all the phandles
  142 + * of a given node. This is mainly use as part of the overlay
  143 + * application process, when we want to update all the overlay
  144 + * phandles to not conflict with the overlays of the base device tree.
  145 + *
  146 + * returns:
  147 + * 0 on success
  148 + * Negative error code on failure
  149 + */
  150 +static int overlay_adjust_node_phandles(void *fdto, int node,
  151 + uint32_t delta)
  152 +{
  153 + int child;
  154 + int ret;
  155 +
  156 + ret = overlay_phandle_add_offset(fdto, node, "phandle", delta);
  157 + if (ret && ret != -FDT_ERR_NOTFOUND)
  158 + return ret;
  159 +
  160 + ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta);
  161 + if (ret && ret != -FDT_ERR_NOTFOUND)
  162 + return ret;
  163 +
  164 + fdt_for_each_subnode(child, fdto, node) {
  165 + ret = overlay_adjust_node_phandles(fdto, child, delta);
  166 + if (ret)
  167 + return ret;
  168 + }
  169 +
  170 + return 0;
  171 +}
  172 +
  173 +/**
  174 + * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay
  175 + * @fdto: Device tree overlay blob
  176 + * @delta: Offset to shift the phandles of
  177 + *
  178 + * overlay_adjust_local_phandles() adds a constant to all the
  179 + * phandles of an overlay. This is mainly use as part of the overlay
  180 + * application process, when we want to update all the overlay
  181 + * phandles to not conflict with the overlays of the base device tree.
  182 + *
  183 + * returns:
  184 + * 0 on success
  185 + * Negative error code on failure
  186 + */
  187 +static int overlay_adjust_local_phandles(void *fdto, uint32_t delta)
  188 +{
  189 + /*
  190 + * Start adjusting the phandles from the overlay root
  191 + */
  192 + return overlay_adjust_node_phandles(fdto, 0, delta);
  193 +}
  194 +
  195 +/**
  196 + * overlay_update_local_node_references - Adjust the overlay references
  197 + * @fdto: Device tree overlay blob
  198 + * @tree_node: Node offset of the node to operate on
  199 + * @fixup_node: Node offset of the matching local fixups node
  200 + * @delta: Offset to shift the phandles of
  201 + *
  202 + * overlay_update_local_nodes_references() update the phandles
  203 + * pointing to a node within the device tree overlay by adding a
  204 + * constant delta.
  205 + *
  206 + * This is mainly used as part of a device tree application process,
  207 + * where you want the device tree overlays phandles to not conflict
  208 + * with the ones from the base device tree before merging them.
  209 + *
  210 + * returns:
  211 + * 0 on success
  212 + * Negative error code on failure
  213 + */
  214 +static int overlay_update_local_node_references(void *fdto,
  215 + int tree_node,
  216 + int fixup_node,
  217 + uint32_t delta)
  218 +{
  219 + int fixup_prop;
  220 + int fixup_child;
  221 + int ret;
  222 +
  223 + fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
  224 + const fdt32_t *fixup_val;
  225 + const char *tree_val;
  226 + const char *name;
  227 + int fixup_len;
  228 + int tree_len;
  229 + int i;
  230 +
  231 + fixup_val = fdt_getprop_by_offset(fdto, fixup_prop,
  232 + &name, &fixup_len);
  233 + if (!fixup_val)
  234 + return fixup_len;
  235 +
  236 + if (fixup_len % sizeof(uint32_t))
  237 + return -FDT_ERR_BADOVERLAY;
  238 +
  239 + tree_val = fdt_getprop(fdto, tree_node, name, &tree_len);
  240 + if (!tree_val) {
  241 + if (tree_len == -FDT_ERR_NOTFOUND)
  242 + return -FDT_ERR_BADOVERLAY;
  243 +
  244 + return tree_len;
  245 + }
  246 +
  247 + for (i = 0; i < (fixup_len / sizeof(uint32_t)); i++) {
  248 + fdt32_t adj_val;
  249 + uint32_t poffset;
  250 +
  251 + poffset = fdt32_to_cpu(fixup_val[i]);
  252 +
  253 + /*
  254 + * phandles to fixup can be unaligned.
  255 + *
  256 + * Use a memcpy for the architectures that do
  257 + * not support unaligned accesses.
  258 + */
  259 + memcpy(&adj_val, tree_val + poffset, sizeof(adj_val));
  260 +
  261 + adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta);
  262 +
  263 + ret = fdt_setprop_inplace_namelen_partial(fdto,
  264 + tree_node,
  265 + name,
  266 + strlen(name),
  267 + poffset,
  268 + &adj_val,
  269 + sizeof(adj_val));
  270 + if (ret == -FDT_ERR_NOSPACE)
  271 + return -FDT_ERR_BADOVERLAY;
  272 +
  273 + if (ret)
  274 + return ret;
  275 + }
  276 + }
  277 +
  278 + fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
  279 + const char *fixup_child_name = fdt_get_name(fdto, fixup_child,
  280 + NULL);
  281 + int tree_child;
  282 +
  283 + tree_child = fdt_subnode_offset(fdto, tree_node,
  284 + fixup_child_name);
  285 + if (tree_child == -FDT_ERR_NOTFOUND)
  286 + return -FDT_ERR_BADOVERLAY;
  287 + if (tree_child < 0)
  288 + return tree_child;
  289 +
  290 + ret = overlay_update_local_node_references(fdto,
  291 + tree_child,
  292 + fixup_child,
  293 + delta);
  294 + if (ret)
  295 + return ret;
  296 + }
  297 +
  298 + return 0;
  299 +}
  300 +
  301 +/**
  302 + * overlay_update_local_references - Adjust the overlay references
  303 + * @fdto: Device tree overlay blob
  304 + * @delta: Offset to shift the phandles of
  305 + *
  306 + * overlay_update_local_references() update all the phandles pointing
  307 + * to a node within the device tree overlay by adding a constant
  308 + * delta to not conflict with the base overlay.
  309 + *
  310 + * This is mainly used as part of a device tree application process,
  311 + * where you want the device tree overlays phandles to not conflict
  312 + * with the ones from the base device tree before merging them.
  313 + *
  314 + * returns:
  315 + * 0 on success
  316 + * Negative error code on failure
  317 + */
  318 +static int overlay_update_local_references(void *fdto, uint32_t delta)
  319 +{
  320 + int fixups;
  321 +
  322 + fixups = fdt_path_offset(fdto, "/__local_fixups__");
  323 + if (fixups < 0) {
  324 + /* There's no local phandles to adjust, bail out */
  325 + if (fixups == -FDT_ERR_NOTFOUND)
  326 + return 0;
  327 +
  328 + return fixups;
  329 + }
  330 +
  331 + /*
  332 + * Update our local references from the root of the tree
  333 + */
  334 + return overlay_update_local_node_references(fdto, 0, fixups,
  335 + delta);
  336 +}
  337 +
  338 +/**
  339 + * overlay_fixup_one_phandle - Set an overlay phandle to the base one
  340 + * @fdt: Base Device Tree blob
  341 + * @fdto: Device tree overlay blob
  342 + * @symbols_off: Node offset of the symbols node in the base device tree
  343 + * @path: Path to a node holding a phandle in the overlay
  344 + * @path_len: number of path characters to consider
  345 + * @name: Name of the property holding the phandle reference in the overlay
  346 + * @name_len: number of name characters to consider
  347 + * @poffset: Offset within the overlay property where the phandle is stored
  348 + * @label: Label of the node referenced by the phandle
  349 + *
  350 + * overlay_fixup_one_phandle() resolves an overlay phandle pointing to
  351 + * a node in the base device tree.
  352 + *
  353 + * This is part of the device tree overlay application process, when
  354 + * you want all the phandles in the overlay to point to the actual
  355 + * base dt nodes.
  356 + *
  357 + * returns:
  358 + * 0 on success
  359 + * Negative error code on failure
  360 + */
  361 +static int overlay_fixup_one_phandle(void *fdt, void *fdto,
  362 + int symbols_off,
  363 + const char *path, uint32_t path_len,
  364 + const char *name, uint32_t name_len,
  365 + int poffset, const char *label)
  366 +{
  367 + const char *symbol_path;
  368 + uint32_t phandle;
  369 + fdt32_t phandle_prop;
  370 + int symbol_off, fixup_off;
  371 + int prop_len;
  372 +
  373 + if (symbols_off < 0)
  374 + return symbols_off;
  375 +
  376 + symbol_path = fdt_getprop(fdt, symbols_off, label,
  377 + &prop_len);
  378 + if (!symbol_path)
  379 + return prop_len;
  380 +
  381 + symbol_off = fdt_path_offset(fdt, symbol_path);
  382 + if (symbol_off < 0)
  383 + return symbol_off;
  384 +
  385 + phandle = fdt_get_phandle(fdt, symbol_off);
  386 + if (!phandle)
  387 + return -FDT_ERR_NOTFOUND;
  388 +
  389 + fixup_off = fdt_path_offset_namelen(fdto, path, path_len);
  390 + if (fixup_off == -FDT_ERR_NOTFOUND)
  391 + return -FDT_ERR_BADOVERLAY;
  392 + if (fixup_off < 0)
  393 + return fixup_off;
  394 +
  395 + phandle_prop = cpu_to_fdt32(phandle);
  396 + return fdt_setprop_inplace_namelen_partial(fdto, fixup_off,
  397 + name, name_len, poffset,
  398 + &phandle_prop,
  399 + sizeof(phandle_prop));
  400 +};
  401 +
  402 +/**
  403 + * overlay_fixup_phandle - Set an overlay phandle to the base one
  404 + * @fdt: Base Device Tree blob
  405 + * @fdto: Device tree overlay blob
  406 + * @symbols_off: Node offset of the symbols node in the base device tree
  407 + * @property: Property offset in the overlay holding the list of fixups
  408 + *
  409 + * overlay_fixup_phandle() resolves all the overlay phandles pointed
  410 + * to in a __fixups__ property, and updates them to match the phandles
  411 + * in use in the base device tree.
  412 + *
  413 + * This is part of the device tree overlay application process, when
  414 + * you want all the phandles in the overlay to point to the actual
  415 + * base dt nodes.
  416 + *
  417 + * returns:
  418 + * 0 on success
  419 + * Negative error code on failure
  420 + */
  421 +static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
  422 + int property)
  423 +{
  424 + const char *value;
  425 + const char *label;
  426 + int len;
  427 +
  428 + value = fdt_getprop_by_offset(fdto, property,
  429 + &label, &len);
  430 + if (!value) {
  431 + if (len == -FDT_ERR_NOTFOUND)
  432 + return -FDT_ERR_INTERNAL;
  433 +
  434 + return len;
  435 + }
  436 +
  437 + do {
  438 + const char *path, *name, *fixup_end;
  439 + const char *fixup_str = value;
  440 + uint32_t path_len, name_len;
  441 + uint32_t fixup_len;
  442 + char *sep, *endptr;
  443 + int poffset, ret;
  444 +
  445 + fixup_end = memchr(value, '\0', len);
  446 + if (!fixup_end)
  447 + return -FDT_ERR_BADOVERLAY;
  448 + fixup_len = fixup_end - fixup_str;
  449 +
  450 + len -= fixup_len + 1;
  451 + value += fixup_len + 1;
  452 +
  453 + path = fixup_str;
  454 + sep = memchr(fixup_str, ':', fixup_len);
  455 + if (!sep || *sep != ':')
  456 + return -FDT_ERR_BADOVERLAY;
  457 +
  458 + path_len = sep - path;
  459 + if (path_len == (fixup_len - 1))
  460 + return -FDT_ERR_BADOVERLAY;
  461 +
  462 + fixup_len -= path_len + 1;
  463 + name = sep + 1;
  464 + sep = memchr(name, ':', fixup_len);
  465 + if (!sep || *sep != ':')
  466 + return -FDT_ERR_BADOVERLAY;
  467 +
  468 + name_len = sep - name;
  469 + if (!name_len)
  470 + return -FDT_ERR_BADOVERLAY;
  471 +
  472 + poffset = strtoul(sep + 1, &endptr, 10);
  473 + if ((*endptr != '\0') || (endptr <= (sep + 1)))
  474 + return -FDT_ERR_BADOVERLAY;
  475 +
  476 + ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off,
  477 + path, path_len, name, name_len,
  478 + poffset, label);
  479 + if (ret)
  480 + return ret;
  481 + } while (len > 0);
  482 +
  483 + return 0;
  484 +}
  485 +
  486 +/**
  487 + * overlay_fixup_phandles - Resolve the overlay phandles to the base
  488 + * device tree
  489 + * @fdt: Base Device Tree blob
  490 + * @fdto: Device tree overlay blob
  491 + *
  492 + * overlay_fixup_phandles() resolves all the overlay phandles pointing
  493 + * to nodes in the base device tree.
  494 + *
  495 + * This is one of the steps of the device tree overlay application
  496 + * process, when you want all the phandles in the overlay to point to
  497 + * the actual base dt nodes.
  498 + *
  499 + * returns:
  500 + * 0 on success
  501 + * Negative error code on failure
  502 + */
  503 +static int overlay_fixup_phandles(void *fdt, void *fdto)
  504 +{
  505 + int fixups_off, symbols_off;
  506 + int property;
  507 +
  508 + /* We can have overlays without any fixups */
  509 + fixups_off = fdt_path_offset(fdto, "/__fixups__");
  510 + if (fixups_off == -FDT_ERR_NOTFOUND)
  511 + return 0; /* nothing to do */
  512 + if (fixups_off < 0)
  513 + return fixups_off;
  514 +
  515 + /* And base DTs without symbols */
  516 + symbols_off = fdt_path_offset(fdt, "/__symbols__");
  517 + if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND)))
  518 + return symbols_off;
  519 +
  520 + fdt_for_each_property_offset(property, fdto, fixups_off) {
  521 + int ret;
  522 +
  523 + ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property);
  524 + if (ret)
  525 + return ret;
  526 + }
  527 +
  528 + return 0;
  529 +}
  530 +
  531 +/**
  532 + * overlay_apply_node - Merges a node into the base device tree
  533 + * @fdt: Base Device Tree blob
  534 + * @target: Node offset in the base device tree to apply the fragment to
  535 + * @fdto: Device tree overlay blob
  536 + * @node: Node offset in the overlay holding the changes to merge
  537 + *
  538 + * overlay_apply_node() merges a node into a target base device tree
  539 + * node pointed.
  540 + *
  541 + * This is part of the final step in the device tree overlay
  542 + * application process, when all the phandles have been adjusted and
  543 + * resolved and you just have to merge overlay into the base device
  544 + * tree.
  545 + *
  546 + * returns:
  547 + * 0 on success
  548 + * Negative error code on failure
  549 + */
  550 +static int overlay_apply_node(void *fdt, int target,
  551 + void *fdto, int node)
  552 +{
  553 + int property;
  554 + int subnode;
  555 +
  556 + fdt_for_each_property_offset(property, fdto, node) {
  557 + const char *name;
  558 + const void *prop;
  559 + int prop_len;
  560 + int ret;
  561 +
  562 + prop = fdt_getprop_by_offset(fdto, property, &name,
  563 + &prop_len);
  564 + if (prop_len == -FDT_ERR_NOTFOUND)
  565 + return -FDT_ERR_INTERNAL;
  566 + if (prop_len < 0)
  567 + return prop_len;
  568 +
  569 + ret = fdt_setprop(fdt, target, name, prop, prop_len);
  570 + if (ret)
  571 + return ret;
  572 + }
  573 +
  574 + fdt_for_each_subnode(subnode, fdto, node) {
  575 + const char *name = fdt_get_name(fdto, subnode, NULL);
  576 + int nnode;
  577 + int ret;
  578 +
  579 + nnode = fdt_add_subnode(fdt, target, name);
  580 + if (nnode == -FDT_ERR_EXISTS) {
  581 + nnode = fdt_subnode_offset(fdt, target, name);
  582 + if (nnode == -FDT_ERR_NOTFOUND)
  583 + return -FDT_ERR_INTERNAL;
  584 + }
  585 +
  586 + if (nnode < 0)
  587 + return nnode;
  588 +
  589 + ret = overlay_apply_node(fdt, nnode, fdto, subnode);
  590 + if (ret)
  591 + return ret;
  592 + }
  593 +
  594 + return 0;
  595 +}
  596 +
  597 +/**
  598 + * overlay_merge - Merge an overlay into its base device tree
  599 + * @fdt: Base Device Tree blob
  600 + * @fdto: Device tree overlay blob
  601 + *
  602 + * overlay_merge() merges an overlay into its base device tree.
  603 + *
  604 + * This is the next to last step in the device tree overlay application
  605 + * process, when all the phandles have been adjusted and resolved and
  606 + * you just have to merge overlay into the base device tree.
  607 + *
  608 + * returns:
  609 + * 0 on success
  610 + * Negative error code on failure
  611 + */
  612 +static int overlay_merge(void *fdt, void *fdto)
  613 +{
  614 + int fragment;
  615 +
  616 + fdt_for_each_subnode(fragment, fdto, 0) {
  617 + int overlay;
  618 + int target;
  619 + int ret;
  620 +
  621 + /*
  622 + * Each fragments will have an __overlay__ node. If
  623 + * they don't, it's not supposed to be merged
  624 + */
  625 + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
  626 + if (overlay == -FDT_ERR_NOTFOUND)
  627 + continue;
  628 +
  629 + if (overlay < 0)
  630 + return overlay;
  631 +
  632 + target = overlay_get_target(fdt, fdto, fragment, NULL);
  633 + if (target < 0)
  634 + return target;
  635 +
  636 + ret = overlay_apply_node(fdt, target, fdto, overlay);
  637 + if (ret)
  638 + return ret;
  639 + }
  640 +
  641 + return 0;
  642 +}
  643 +
  644 +static int get_path_len(const void *fdt, int nodeoffset)
  645 +{
  646 + int len = 0, namelen;
  647 + const char *name;
  648 +
  649 + FDT_CHECK_HEADER(fdt);
  650 +
  651 + for (;;) {
  652 + name = fdt_get_name(fdt, nodeoffset, &namelen);
  653 + if (!name)
  654 + return namelen;
  655 +
  656 + /* root? we're done */
  657 + if (namelen == 0)
  658 + break;
  659 +
  660 + nodeoffset = fdt_parent_offset(fdt, nodeoffset);
  661 + if (nodeoffset < 0)
  662 + return nodeoffset;
  663 + len += namelen + 1;
  664 + }
  665 +
  666 + /* in case of root pretend it's "/" */
  667 + if (len == 0)
  668 + len++;
  669 + return len;
  670 +}
  671 +
  672 +/**
  673 + * overlay_symbol_update - Update the symbols of base tree after a merge
  674 + * @fdt: Base Device Tree blob
  675 + * @fdto: Device tree overlay blob
  676 + *
  677 + * overlay_symbol_update() updates the symbols of the base tree with the
  678 + * symbols of the applied overlay
  679 + *
  680 + * This is the last step in the device tree overlay application
  681 + * process, allowing the reference of overlay symbols by subsequent
  682 + * overlay operations.
  683 + *
  684 + * returns:
  685 + * 0 on success
  686 + * Negative error code on failure
  687 + */
  688 +static int overlay_symbol_update(void *fdt, void *fdto)
  689 +{
  690 + int root_sym, ov_sym, prop, path_len, fragment, target;
  691 + int len, frag_name_len, ret, rel_path_len;
  692 + const char *s, *e;
  693 + const char *path;
  694 + const char *name;
  695 + const char *frag_name;
  696 + const char *rel_path;
  697 + const char *target_path;
  698 + char *buf;
  699 + void *p;
  700 +
  701 + ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
  702 +
  703 + /* if no overlay symbols exist no problem */
  704 + if (ov_sym < 0)
  705 + return 0;
  706 +
  707 + root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
  708 +
  709 + /* it no root symbols exist we should create them */
  710 + if (root_sym == -FDT_ERR_NOTFOUND)
  711 + root_sym = fdt_add_subnode(fdt, 0, "__symbols__");
  712 +
  713 + /* any error is fatal now */
  714 + if (root_sym < 0)
  715 + return root_sym;
  716 +
  717 + /* iterate over each overlay symbol */
  718 + fdt_for_each_property_offset(prop, fdto, ov_sym) {
  719 + path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
  720 + if (!path)
  721 + return path_len;
  722 +
  723 + /* verify it's a string property (terminated by a single \0) */
  724 + if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1])
  725 + return -FDT_ERR_BADVALUE;
  726 +
  727 + /* keep end marker to avoid strlen() */
  728 + e = path + path_len;
  729 +
  730 + /* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
  731 +
  732 + if (*path != '/')
  733 + return -FDT_ERR_BADVALUE;
  734 +
  735 + /* get fragment name first */
  736 + s = strchr(path + 1, '/');
  737 + if (!s)
  738 + return -FDT_ERR_BADOVERLAY;
  739 +
  740 + frag_name = path + 1;
  741 + frag_name_len = s - path - 1;
  742 +
  743 + /* verify format; safe since "s" lies in \0 terminated prop */
  744 + len = sizeof("/__overlay__/") - 1;
  745 + if ((e - s) < len || memcmp(s, "/__overlay__/", len))
  746 + return -FDT_ERR_BADOVERLAY;
  747 +
  748 + rel_path = s + len;
  749 + rel_path_len = e - rel_path;
  750 +
  751 + /* find the fragment index in which the symbol lies */
  752 + ret = fdt_subnode_offset_namelen(fdto, 0, frag_name,
  753 + frag_name_len);
  754 + /* not found? */
  755 + if (ret < 0)
  756 + return -FDT_ERR_BADOVERLAY;
  757 + fragment = ret;
  758 +
  759 + /* an __overlay__ subnode must exist */
  760 + ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
  761 + if (ret < 0)
  762 + return -FDT_ERR_BADOVERLAY;
  763 +
  764 + /* get the target of the fragment */
  765 + ret = overlay_get_target(fdt, fdto, fragment, &target_path);
  766 + if (ret < 0)
  767 + return ret;
  768 + target = ret;
  769 +
  770 + /* if we have a target path use */
  771 + if (!target_path) {
  772 + ret = get_path_len(fdt, target);
  773 + if (ret < 0)
  774 + return ret;
  775 + len = ret;
  776 + } else {
  777 + len = strlen(target_path);
  778 + }
  779 +
  780 + ret = fdt_setprop_placeholder(fdt, root_sym, name,
  781 + len + (len > 1) + rel_path_len + 1, &p);
  782 + if (ret < 0)
  783 + return ret;
  784 +
  785 + if (!target_path) {
  786 + /* again in case setprop_placeholder changed it */
  787 + ret = overlay_get_target(fdt, fdto, fragment, &target_path);
  788 + if (ret < 0)
  789 + return ret;
  790 + target = ret;
  791 + }
  792 +
  793 + buf = p;
  794 + if (len > 1) { /* target is not root */
  795 + if (!target_path) {
  796 + ret = fdt_get_path(fdt, target, buf, len + 1);
  797 + if (ret < 0)
  798 + return ret;
  799 + } else
  800 + memcpy(buf, target_path, len + 1);
  801 +
  802 + } else
  803 + len--;
  804 +
  805 + buf[len] = '/';
  806 + memcpy(buf + len + 1, rel_path, rel_path_len);
  807 + buf[len + 1 + rel_path_len] = '\0';
  808 + }
  809 +
  810 + return 0;
  811 +}
  812 +
  813 +int fdt_overlay_apply(void *fdt, void *fdto)
  814 +{
  815 + uint32_t delta = fdt_get_max_phandle(fdt);
  816 + int ret;
  817 +
  818 + FDT_CHECK_HEADER(fdt);
  819 + FDT_CHECK_HEADER(fdto);
  820 +
  821 + ret = overlay_adjust_local_phandles(fdto, delta);
  822 + if (ret)
  823 + goto err;
  824 +
  825 + ret = overlay_update_local_references(fdto, delta);
  826 + if (ret)
  827 + goto err;
  828 +
  829 + ret = overlay_fixup_phandles(fdt, fdto);
  830 + if (ret)
  831 + goto err;
  832 +
  833 + ret = overlay_merge(fdt, fdto);
  834 + if (ret)
  835 + goto err;
  836 +
  837 + ret = overlay_symbol_update(fdt, fdto);
  838 + if (ret)
  839 + goto err;
  840 +
  841 + /*
  842 + * The overlay has been damaged, erase its magic.
  843 + */
  844 + fdt_set_magic(fdto, ~0);
  845 +
  846 + return 0;
  847 +
  848 +err:
  849 + /*
  850 + * The overlay might have been damaged, erase its magic.
  851 + */
  852 + fdt_set_magic(fdto, ~0);
  853 +
  854 + /*
  855 + * The base device tree might have been damaged, erase its
  856 + * magic.
  857 + */
  858 + fdt_set_magic(fdt, ~0);
  859 +
  860 + return ret;
  861 +}
scripts/dtc/livetree.c
... ... @@ -216,6 +216,28 @@
216 216 return old_node;
217 217 }
218 218  
  219 +void add_orphan_node(struct node *dt, struct node *new_node, char *ref)
  220 +{
  221 + static unsigned int next_orphan_fragment = 0;
  222 + struct node *node;
  223 + struct property *p;
  224 + struct data d = empty_data;
  225 + char *name;
  226 +
  227 + d = data_add_marker(d, REF_PHANDLE, ref);
  228 + d = data_append_integer(d, 0xffffffff, 32);
  229 +
  230 + p = build_property("target", d);
  231 +
  232 + xasprintf(&name, "fragment@%u",
  233 + next_orphan_fragment++);
  234 + name_node(new_node, "__overlay__");
  235 + node = build_node(p, new_node);
  236 + name_node(node, name);
  237 +
  238 + add_child(dt, node);
  239 +}
  240 +
219 241 struct node *chain_node(struct node *first, struct node *list)
220 242 {
221 243 assert(first->next_sibling == NULL);
... ... @@ -394,6 +416,12 @@
394 416 {
395 417 assert(prop->val.len == sizeof(cell_t));
396 418 return fdt32_to_cpu(*((fdt32_t *)prop->val.val));
  419 +}
  420 +
  421 +cell_t propval_cell_n(struct property *prop, int n)
  422 +{
  423 + assert(prop->val.len / sizeof(cell_t) >= n);
  424 + return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n));
397 425 }
398 426  
399 427 struct property *get_property_by_label(struct node *tree, const char *label,
scripts/dtc/version_gen.h
1   -#define DTC_VERSION "DTC 1.4.4-gfe50bd1e"
  1 +#define DTC_VERSION "DTC 1.4.5-gb1a60033"