2005-06-08 09:18:34 +02:00
|
|
|
/*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
|
|
*
|
2007-09-18 03:44:04 +02:00
|
|
|
*
|
2005-06-08 09:18:34 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2007-09-18 03:44:04 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
2005-06-08 09:18:34 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-19 08:00:31 +02:00
|
|
|
%locations
|
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
%{
|
|
|
|
#include "dtc.h"
|
2007-03-23 21:18:41 +01:00
|
|
|
#include "srcpos.h"
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2008-03-05 01:47:54 +01:00
|
|
|
extern int yylex(void);
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2005-07-15 09:14:24 +02:00
|
|
|
extern struct boot_info *the_boot_info;
|
2008-01-04 00:43:33 +01:00
|
|
|
extern int treesource_error;
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2008-03-05 01:47:54 +01:00
|
|
|
static unsigned long long eval_literal(const char *s, int base, int bits);
|
2005-06-08 09:18:34 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
2007-11-07 01:16:19 +01:00
|
|
|
char *propnodename;
|
|
|
|
char *literal;
|
|
|
|
char *labelref;
|
2007-02-15 17:59:27 +01:00
|
|
|
unsigned int cbase;
|
2005-07-11 08:49:52 +02:00
|
|
|
u8 byte;
|
2005-06-08 09:18:34 +02:00
|
|
|
struct data data;
|
2007-11-07 01:16:19 +01:00
|
|
|
|
|
|
|
u64 addr;
|
|
|
|
cell_t cell;
|
2005-06-08 09:18:34 +02:00
|
|
|
struct property *prop;
|
|
|
|
struct property *proplist;
|
|
|
|
struct node *node;
|
|
|
|
struct node *nodelist;
|
2005-10-24 10:18:38 +02:00
|
|
|
struct reserve_info *re;
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
|
2007-11-07 01:17:17 +01:00
|
|
|
%token DT_V1
|
2005-07-15 09:14:24 +02:00
|
|
|
%token DT_MEMRESERVE
|
2007-11-07 01:16:19 +01:00
|
|
|
%token <propnodename> DT_PROPNODENAME
|
|
|
|
%token <literal> DT_LITERAL
|
2007-11-07 01:17:17 +01:00
|
|
|
%token <literal> DT_LEGACYLITERAL
|
2007-02-15 17:59:27 +01:00
|
|
|
%token <cbase> DT_BASE
|
2005-06-08 09:18:34 +02:00
|
|
|
%token <byte> DT_BYTE
|
|
|
|
%token <data> DT_STRING
|
2007-11-07 01:16:19 +01:00
|
|
|
%token <labelref> DT_LABEL
|
|
|
|
%token <labelref> DT_REF
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
%type <data> propdata
|
2007-02-07 06:37:50 +01:00
|
|
|
%type <data> propdataprefix
|
2005-07-15 09:14:24 +02:00
|
|
|
%type <re> memreserve
|
2005-10-24 10:18:38 +02:00
|
|
|
%type <re> memreserves
|
2007-11-07 01:17:17 +01:00
|
|
|
%type <re> v0_memreserve
|
|
|
|
%type <re> v0_memreserves
|
2007-11-07 01:16:19 +01:00
|
|
|
%type <addr> addr
|
2005-06-08 09:18:34 +02:00
|
|
|
%type <data> celllist
|
2007-11-07 01:16:19 +01:00
|
|
|
%type <cbase> cellbase
|
|
|
|
%type <cell> cellval
|
2005-06-08 09:18:34 +02:00
|
|
|
%type <data> bytestring
|
|
|
|
%type <prop> propdef
|
|
|
|
%type <proplist> proplist
|
|
|
|
|
2005-07-15 09:14:24 +02:00
|
|
|
%type <node> devicetree
|
2005-06-08 09:18:34 +02:00
|
|
|
%type <node> nodedef
|
|
|
|
%type <node> subnode
|
|
|
|
%type <nodelist> subnodes
|
2007-11-07 01:16:19 +01:00
|
|
|
%type <labelref> label
|
2005-06-16 06:36:37 +02:00
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
%%
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
sourcefile:
|
2007-11-07 01:17:17 +01:00
|
|
|
DT_V1 ';' memreserves devicetree
|
|
|
|
{
|
|
|
|
the_boot_info = build_boot_info($3, $4);
|
|
|
|
}
|
|
|
|
| v0_memreserves devicetree
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2005-07-15 09:14:24 +02:00
|
|
|
the_boot_info = build_boot_info($1, $2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
memreserves:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = NULL;
|
2005-07-15 09:14:24 +02:00
|
|
|
}
|
2007-10-23 16:28:54 +02:00
|
|
|
| memreserve memreserves
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = chain_reserve_entry($1, $2);
|
2005-07-15 09:14:24 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
memreserve:
|
2007-11-07 01:16:19 +01:00
|
|
|
label DT_MEMRESERVE addr addr ';'
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-07-07 08:18:49 +02:00
|
|
|
$$ = build_reserve_entry($3, $4, $1);
|
2005-07-15 09:14:24 +02:00
|
|
|
}
|
2007-11-07 01:17:17 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
v0_memreserves:
|
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| v0_memreserve v0_memreserves
|
|
|
|
{
|
|
|
|
$$ = chain_reserve_entry($1, $2);
|
|
|
|
};
|
|
|
|
;
|
|
|
|
|
|
|
|
v0_memreserve:
|
|
|
|
memreserve
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2007-11-07 01:16:19 +01:00
|
|
|
| label DT_MEMRESERVE addr '-' addr ';'
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-07-07 08:18:49 +02:00
|
|
|
$$ = build_reserve_entry($3, $5 - $3 + 1, $1);
|
2005-07-15 09:14:24 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-11-07 01:16:19 +01:00
|
|
|
addr:
|
|
|
|
DT_LITERAL
|
2007-11-07 01:17:17 +01:00
|
|
|
{
|
|
|
|
$$ = eval_literal($1, 0, 64);
|
|
|
|
}
|
|
|
|
| DT_LEGACYLITERAL
|
2007-11-07 01:16:19 +01:00
|
|
|
{
|
|
|
|
$$ = eval_literal($1, 16, 64);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
devicetree:
|
|
|
|
'/' nodedef
|
|
|
|
{
|
2005-07-15 09:14:24 +02:00
|
|
|
$$ = name_node($2, "", NULL);
|
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
nodedef:
|
|
|
|
'{' proplist subnodes '}' ';'
|
|
|
|
{
|
2005-06-08 09:18:34 +02:00
|
|
|
$$ = build_node($2, $3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
proplist:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = NULL;
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
2007-10-22 23:09:56 +02:00
|
|
|
| proplist propdef
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-22 23:09:56 +02:00
|
|
|
$$ = chain_property($2, $1);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
propdef:
|
2007-11-07 01:16:19 +01:00
|
|
|
label DT_PROPNODENAME '=' propdata ';'
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2005-06-16 06:36:37 +02:00
|
|
|
$$ = build_property($2, $4, $1);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
2007-11-07 01:16:19 +01:00
|
|
|
| label DT_PROPNODENAME ';'
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2005-06-17 06:32:32 +02:00
|
|
|
$$ = build_property($2, empty_data, $1);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
propdata:
|
|
|
|
propdataprefix DT_STRING
|
|
|
|
{
|
|
|
|
$$ = data_merge($1, $2);
|
|
|
|
}
|
|
|
|
| propdataprefix '<' celllist '>'
|
|
|
|
{
|
2007-11-02 06:54:26 +01:00
|
|
|
$$ = data_merge($1, $3);
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
|
|
|
| propdataprefix '[' bytestring ']'
|
|
|
|
{
|
|
|
|
$$ = data_merge($1, $3);
|
|
|
|
}
|
2007-12-05 00:43:50 +01:00
|
|
|
| propdataprefix DT_REF
|
|
|
|
{
|
|
|
|
$$ = data_add_marker($1, REF_PATH, $2);
|
|
|
|
}
|
2007-10-18 16:42:16 +02:00
|
|
|
| propdata DT_LABEL
|
|
|
|
{
|
2007-11-22 04:39:23 +01:00
|
|
|
$$ = data_add_marker($1, LABEL, $2);
|
2007-02-07 06:37:50 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
propdataprefix:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
$$ = empty_data;
|
|
|
|
}
|
|
|
|
| propdata ','
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| propdataprefix DT_LABEL
|
|
|
|
{
|
2007-11-22 04:39:23 +01:00
|
|
|
$$ = data_add_marker($1, LABEL, $2);
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
celllist:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
$$ = empty_data;
|
|
|
|
}
|
2007-11-07 01:16:19 +01:00
|
|
|
| celllist cellval
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-11-07 01:16:19 +01:00
|
|
|
$$ = data_append_cell($1, $2);
|
2007-02-15 17:59:27 +01:00
|
|
|
}
|
2007-10-18 16:42:16 +02:00
|
|
|
| celllist DT_REF
|
|
|
|
{
|
2007-11-22 04:39:23 +01:00
|
|
|
$$ = data_append_cell(data_add_marker($1, REF_PHANDLE,
|
|
|
|
$2), -1);
|
2005-06-16 09:04:00 +02:00
|
|
|
}
|
2007-10-18 16:42:16 +02:00
|
|
|
| celllist DT_LABEL
|
|
|
|
{
|
2007-11-22 04:39:23 +01:00
|
|
|
$$ = data_add_marker($1, LABEL, $2);
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
2007-11-07 01:16:19 +01:00
|
|
|
cellbase:
|
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
$$ = 16;
|
|
|
|
}
|
|
|
|
| DT_BASE
|
|
|
|
;
|
|
|
|
|
|
|
|
cellval:
|
2007-11-07 01:17:17 +01:00
|
|
|
DT_LITERAL
|
|
|
|
{
|
|
|
|
$$ = eval_literal($1, 0, 32);
|
|
|
|
}
|
|
|
|
| cellbase DT_LEGACYLITERAL
|
2007-11-07 01:16:19 +01:00
|
|
|
{
|
|
|
|
$$ = eval_literal($2, $1, 32);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
bytestring:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
$$ = empty_data;
|
|
|
|
}
|
|
|
|
| bytestring DT_BYTE
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
|
|
|
$$ = data_append_byte($1, $2);
|
|
|
|
}
|
|
|
|
| bytestring DT_LABEL
|
|
|
|
{
|
2007-11-22 04:39:23 +01:00
|
|
|
$$ = data_add_marker($1, LABEL, $2);
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
subnodes:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = NULL;
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
2007-10-23 16:28:54 +02:00
|
|
|
| subnode subnodes
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = chain_node($1, $2);
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2007-12-05 00:27:04 +01:00
|
|
|
| subnode propdef
|
|
|
|
{
|
2008-01-04 22:10:47 +01:00
|
|
|
yyerror("syntax error: properties must precede subnodes");
|
2007-12-05 00:27:04 +01:00
|
|
|
YYERROR;
|
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
subnode:
|
2007-11-07 01:16:19 +01:00
|
|
|
label DT_PROPNODENAME nodedef
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
|
|
|
$$ = name_node($3, $2, $1);
|
|
|
|
}
|
2005-06-16 06:36:37 +02:00
|
|
|
;
|
|
|
|
|
2007-10-18 16:42:16 +02:00
|
|
|
label:
|
2007-10-23 16:28:54 +02:00
|
|
|
/* empty */
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = NULL;
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2007-10-23 16:28:54 +02:00
|
|
|
| DT_LABEL
|
2007-10-18 16:42:16 +02:00
|
|
|
{
|
2007-10-23 16:28:54 +02:00
|
|
|
$$ = $1;
|
2007-10-18 16:42:16 +02:00
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2008-01-04 00:43:29 +01:00
|
|
|
void yyerrorf(char const *s, ...)
|
2005-06-08 09:18:34 +02:00
|
|
|
{
|
2008-01-04 00:43:31 +01:00
|
|
|
const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
|
2008-01-04 00:43:29 +01:00
|
|
|
va_list va;
|
|
|
|
va_start(va, s);
|
2007-03-23 21:18:41 +01:00
|
|
|
|
|
|
|
if (strcmp(fname, "-") == 0)
|
|
|
|
fname = "stdin";
|
|
|
|
|
2008-01-04 00:43:29 +01:00
|
|
|
fprintf(stderr, "%s:%d ", fname, yylloc.first_line);
|
|
|
|
vfprintf(stderr, s, va);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
2008-01-04 00:43:33 +01:00
|
|
|
treesource_error = 1;
|
2008-01-04 00:43:29 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
void yyerror (char const *s)
|
|
|
|
{
|
|
|
|
yyerrorf("%s", s);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
2007-02-16 16:33:54 +01:00
|
|
|
|
2008-03-05 01:47:54 +01:00
|
|
|
static unsigned long long eval_literal(const char *s, int base, int bits)
|
2007-02-16 16:33:54 +01:00
|
|
|
{
|
2007-11-07 01:16:19 +01:00
|
|
|
unsigned long long val;
|
2007-07-07 08:18:48 +02:00
|
|
|
char *e;
|
|
|
|
|
2007-11-07 01:16:19 +01:00
|
|
|
errno = 0;
|
|
|
|
val = strtoull(s, &e, base);
|
|
|
|
if (*e)
|
|
|
|
yyerror("bad characters in literal");
|
|
|
|
else if ((errno == ERANGE)
|
|
|
|
|| ((bits < 64) && (val >= (1ULL << bits))))
|
|
|
|
yyerror("literal out of range");
|
|
|
|
else if (errno != 0)
|
|
|
|
yyerror("bad literal");
|
|
|
|
return val;
|
2007-02-16 16:33:54 +01:00
|
|
|
}
|