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
29 extern
int yylex(void);
31 extern
struct boot_info
*the_boot_info
;
32 extern
int treesource_error
;
34 static unsigned long long eval_literal
(const char *s
, int base
, int bits
);
47 struct property
*prop
;
48 struct property
*proplist
;
50 struct node
*nodelist
;
51 struct reserve_info
*re
;
56 %token
<propnodename
> DT_PROPNODENAME
57 %token
<literal
> DT_LITERAL
58 %token
<literal
> DT_LEGACYLITERAL
59 %token
<cbase
> DT_BASE
61 %token
<data
> DT_STRING
62 %token
<labelref
> DT_LABEL
63 %token
<labelref
> DT_REF
67 %type
<data
> propdataprefix
69 %type
<re
> memreserves
70 %type
<re
> v0_memreserve
71 %type
<re
> v0_memreserves
74 %type
<cbase
> cellbase
76 %type
<data
> bytestring
78 %type
<proplist
> proplist
80 %type
<node
> devicetree
83 %type
<nodelist
> subnodes
84 %type
<labelref
> label
89 DT_V1
';' memreserves devicetree
91 the_boot_info
= build_boot_info
($3, $4, 0);
93 | v0_memreserves devicetree
95 the_boot_info
= build_boot_info
($1, $2, 0);
104 | memreserve memreserves
106 $$
= chain_reserve_entry
($1, $2);
111 label DT_MEMRESERVE addr addr
';'
113 $$
= build_reserve_entry
($3, $4, $1);
122 | v0_memreserve v0_memreserves
124 $$
= chain_reserve_entry
($1, $2);
133 | label DT_MEMRESERVE addr
'-' addr
';'
135 $$
= build_reserve_entry
($3, $5 - $3 + 1, $1);
142 $$
= eval_literal
($1, 0, 64);
146 $$
= eval_literal
($1, 16, 64);
153 $$
= name_node
($2, "", NULL
);
158 '{' proplist subnodes
'}' ';'
160 $$
= build_node
($2, $3);
171 $$
= chain_property
($2, $1);
176 label DT_PROPNODENAME
'=' propdata
';'
178 $$
= build_property
($2, $4, $1);
180 | label DT_PROPNODENAME
';'
182 $$
= build_property
($2, empty_data
, $1);
187 propdataprefix DT_STRING
189 $$
= data_merge
($1, $2);
191 | propdataprefix
'<' celllist
'>'
193 $$
= data_merge
($1, $3);
195 | propdataprefix
'[' bytestring
']'
197 $$
= data_merge
($1, $3);
199 | propdataprefix DT_REF
201 $$
= data_add_marker
($1, REF_PATH
, $2);
203 | propdataprefix DT_INCBIN
'(' DT_STRING
',' addr
',' addr
')'
205 struct search_path path
= { srcpos_file
->dir
, NULL
, NULL
};
206 struct dtc_file
*file
= dtc_open_file
($4.val
, &path
);
207 struct data d
= empty_data
;
210 if
(fseek
(file
->file
, $6, SEEK_SET
) != 0)
211 yyerrorf
("Couldn't seek to offset %llu in \"%s\": %s",
212 (unsigned long long)$6,
213 $4.val
, strerror
(errno
));
215 d
= data_copy_file
(file
->file
, $8);
217 $$
= data_merge
($1, d
);
218 dtc_close_file
(file
);
220 | propdataprefix DT_INCBIN
'(' DT_STRING
')'
222 struct search_path path
= { srcpos_file
->dir
, NULL
, NULL
};
223 struct dtc_file
*file
= dtc_open_file
($4.val
, &path
);
224 struct data d
= empty_data
;
226 d
= data_copy_file
(file
->file
, -1);
228 $$
= data_merge
($1, d
);
229 dtc_close_file
(file
);
233 $$
= data_add_marker
($1, LABEL
, $2);
246 | propdataprefix DT_LABEL
248 $$
= data_add_marker
($1, LABEL
, $2);
259 $$
= data_append_cell
($1, $2);
263 $$
= data_append_cell
(data_add_marker
($1, REF_PHANDLE
,
268 $$
= data_add_marker
($1, LABEL
, $2);
283 $$
= eval_literal
($1, 0, 32);
285 | cellbase DT_LEGACYLITERAL
287 $$
= eval_literal
($2, $1, 32);
298 $$
= data_append_byte
($1, $2);
300 | bytestring DT_LABEL
302 $$
= data_add_marker
($1, LABEL
, $2);
313 $$
= chain_node
($1, $2);
317 yyerror("syntax error: properties must precede subnodes");
323 label DT_PROPNODENAME nodedef
325 $$
= name_node
($3, $2, $1);
342 void yyerrorf
(char const *s
, ...
)
344 const char *fname
= srcpos_file ? srcpos_file
->name
: "<no-file>";
348 if
(strcmp
(fname
, "-") == 0)
351 fprintf
(stderr
, "%s:%d ", fname
, yylloc.first_line
);
352 vfprintf
(stderr
, s
, va
);
353 fprintf
(stderr
, "\n");
355 treesource_error
= 1;
359 void yyerror (char const *s
)
364 static unsigned long long eval_literal
(const char *s
, int base
, int bits
)
366 unsigned long long val
;
370 val
= strtoull
(s
, &e
, base
);
372 yyerror("bad characters in literal");
373 else if
((errno
== ERANGE
)
374 ||
((bits
< 64) && (val
>= (1ULL << bits
))))
375 yyerror("literal out of range");
377 yyerror("bad literal");