2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 extern int yylex(void);
31 extern void yyerror(char const *s);
33 extern struct boot_info *the_boot_info;
34 extern int treesource_error;
36 static unsigned long long eval_literal(const char *s, int base, int bits);
49 struct property *prop;
50 struct property *proplist;
52 struct node *nodelist;
53 struct reserve_info *re;
58 %token <propnodename> DT_PROPNODENAME
59 %token <literal> DT_LITERAL
60 %token <cbase> DT_BASE
62 %token <data> DT_STRING
63 %token <labelref> DT_LABEL
64 %token <labelref> DT_REF
68 %type <data> propdataprefix
70 %type <re> memreserves
74 %type <data> bytestring
76 %type <proplist> proplist
78 %type <node> devicetree
81 %type <nodelist> subnodes
82 %type <labelref> label
87 DT_V1 ';' memreserves devicetree
89 the_boot_info = build_boot_info($3, $4, 0);
98 | memreserve memreserves
100 $$ = chain_reserve_entry($1, $2);
105 label DT_MEMRESERVE addr addr ';'
107 $$ = build_reserve_entry($3, $4, $1);
114 $$ = eval_literal($1, 0, 64);
121 $$ = name_node($2, "", NULL);
126 '{' proplist subnodes '}' ';'
128 $$ = build_node($2, $3);
139 $$ = chain_property($2, $1);
144 label DT_PROPNODENAME '=' propdata ';'
146 $$ = build_property($2, $4, $1);
148 | label DT_PROPNODENAME ';'
150 $$ = build_property($2, empty_data, $1);
155 propdataprefix DT_STRING
157 $$ = data_merge($1, $2);
159 | propdataprefix '<' celllist '>'
161 $$ = data_merge($1, $3);
163 | propdataprefix '[' bytestring ']'
165 $$ = data_merge($1, $3);
167 | propdataprefix DT_REF
169 $$ = data_add_marker($1, REF_PATH, $2);
171 | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')'
173 struct search_path path = { srcpos_file->dir, NULL, NULL };
174 struct dtc_file *file = dtc_open_file($4.val, &path);
175 struct data d = empty_data;
178 if (fseek(file->file, $6, SEEK_SET) != 0)
179 srcpos_error(&yylloc,
180 "Couldn't seek to offset %llu in \"%s\": %s",
181 (unsigned long long)$6,
185 d = data_copy_file(file->file, $8);
187 $$ = data_merge($1, d);
188 dtc_close_file(file);
190 | propdataprefix DT_INCBIN '(' DT_STRING ')'
192 struct search_path path = { srcpos_file->dir, NULL, NULL };
193 struct dtc_file *file = dtc_open_file($4.val, &path);
194 struct data d = empty_data;
196 d = data_copy_file(file->file, -1);
198 $$ = data_merge($1, d);
199 dtc_close_file(file);
203 $$ = data_add_marker($1, LABEL, $2);
216 | propdataprefix DT_LABEL
218 $$ = data_add_marker($1, LABEL, $2);
229 $$ = data_append_cell($1, $2);
233 $$ = data_append_cell(data_add_marker($1, REF_PHANDLE,
238 $$ = data_add_marker($1, LABEL, $2);
245 $$ = eval_literal($1, 0, 32);
256 $$ = data_append_byte($1, $2);
258 | bytestring DT_LABEL
260 $$ = data_add_marker($1, LABEL, $2);
271 $$ = chain_node($1, $2);
275 yyerror("syntax error: properties must precede subnodes");
281 label DT_PROPNODENAME nodedef
283 $$ = name_node($3, $2, $1);
300 void yyerror(char const *s)
302 srcpos_error(&yylloc, "%s", s);
303 treesource_error = 1;
306 static unsigned long long eval_literal(const char *s, int base, int bits)
308 unsigned long long val;
312 val = strtoull(s, &e, base);
314 yyerror("bad characters in literal");
315 else if ((errno == ERANGE)
316 || ((bits < 64) && (val >= (1ULL << bits))))
317 yyerror("literal out of range");
319 yyerror("bad literal");