scripts/dtc: Update to upstream version with overlay patches

This commit is contained in:
Phil Elwell
2015-01-23 14:48:55 +00:00
committed by popcornmix
parent 740e2da8a9
commit 9615583a44
18 changed files with 1714 additions and 1496 deletions

View File

@@ -53,7 +53,7 @@ struct check {
void *data;
bool warn, error;
enum checkstatus status;
int inprogress;
bool inprogress;
int num_prereqs;
struct check **prereq;
};
@@ -113,6 +113,7 @@ static inline void check_msg(struct check *c, const char *fmt, ...)
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}
#define FAIL(c, ...) \
@@ -141,9 +142,9 @@ static void check_nodes_props(struct check *c, struct node *dt, struct node *nod
check_nodes_props(c, dt, child);
}
static int run_check(struct check *c, struct node *dt)
static bool run_check(struct check *c, struct node *dt)
{
int error = 0;
bool error = false;
int i;
assert(!c->inprogress);
@@ -151,11 +152,11 @@ static int run_check(struct check *c, struct node *dt)
if (c->status != UNCHECKED)
goto out;
c->inprogress = 1;
c->inprogress = true;
for (i = 0; i < c->num_prereqs; i++) {
struct check *prq = c->prereq[i];
error |= run_check(prq, dt);
error = error || run_check(prq, dt);
if (prq->status != PASSED) {
c->status = PREREQ;
check_msg(c, "Failed prerequisite '%s'",
@@ -177,9 +178,9 @@ static int run_check(struct check *c, struct node *dt)
TRACE(c, "\tCompleted, status %d", c->status);
out:
c->inprogress = 0;
c->inprogress = false;
if ((c->status != PASSED) && (c->error))
error = 1;
error = true;
return error;
}
@@ -457,22 +458,93 @@ static void fixup_phandle_references(struct check *c, struct node *dt,
struct node *node, struct property *prop)
{
struct marker *m = prop->val.markers;
struct fixup *f, **fp;
struct fixup_entry *fe, **fep;
struct node *refnode;
cell_t phandle;
int has_phandle_refs;
has_phandle_refs = 0;
for_each_marker_of_type(m, REF_PHANDLE) {
has_phandle_refs = 1;
break;
}
if (!has_phandle_refs)
return;
for_each_marker_of_type(m, REF_PHANDLE) {
assert(m->offset + sizeof(cell_t) <= prop->val.len);
refnode = get_node_by_ref(dt, m->ref);
if (! refnode) {
if (!refnode && !symbol_fixup_support) {
FAIL(c, "Reference to non-existent node or label \"%s\"\n",
m->ref);
continue;
}
phandle = get_node_phandle(dt, refnode);
*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
if (!refnode) {
/* allocate fixup entry */
fe = xmalloc(sizeof(*fe));
fe->node = node;
fe->prop = prop;
fe->offset = m->offset;
fe->next = NULL;
/* search for an already existing fixup */
for_each_fixup(dt, f)
if (strcmp(f->ref, m->ref) == 0)
break;
/* no fixup found, add new */
if (f == NULL) {
f = xmalloc(sizeof(*f));
f->ref = m->ref;
f->entries = NULL;
f->next = NULL;
/* add it to the tree */
fp = &dt->fixups;
while (*fp)
fp = &(*fp)->next;
*fp = f;
}
/* and now append fixup entry */
fep = &f->entries;
while (*fep)
fep = &(*fep)->next;
*fep = fe;
/* mark the entry as unresolved */
phandle = 0xdeadbeef;
} else {
phandle = get_node_phandle(dt, refnode);
/* if it's a plugin, we need to record it */
if (symbol_fixup_support && dt->is_plugin) {
/* allocate a new local fixup entry */
fe = xmalloc(sizeof(*fe));
fe->node = node;
fe->prop = prop;
fe->offset = m->offset;
fe->next = NULL;
/* append it to the local fixups */
fep = &dt->local_fixups;
while (*fep)
fep = &(*fep)->next;
*fep = fe;
}
}
*((cell_t *)(prop->val.val + m->offset)) =
cpu_to_fdt32(phandle);
}
}
ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
&duplicate_node_names, &explicit_phandles);
@@ -624,11 +696,11 @@ static void check_avoid_default_addr_size(struct check *c, struct node *dt,
if (!reg && !ranges)
return;
if ((node->parent->addr_cells == -1))
if (node->parent->addr_cells == -1)
FAIL(c, "Relying on default #address-cells value for %s",
node->fullpath);
if ((node->parent->size_cells == -1))
if (node->parent->size_cells == -1)
FAIL(c, "Relying on default #size-cells value for %s",
node->fullpath);
}
@@ -651,6 +723,45 @@ static void check_obsolete_chosen_interrupt_controller(struct check *c,
}
TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
static void check_auto_label_phandles(struct check *c, struct node *dt,
struct node *node)
{
struct label *l;
struct symbol *s, **sp;
int has_label;
if (!symbol_fixup_support)
return;
has_label = 0;
for_each_label(node->labels, l) {
has_label = 1;
break;
}
if (!has_label)
return;
/* force allocation of a phandle for this node */
(void)get_node_phandle(dt, node);
/* add the symbol */
for_each_label(node->labels, l) {
s = xmalloc(sizeof(*s));
s->label = l;
s->node = node;
s->next = NULL;
/* add it to the symbols list */
sp = &dt->symbols;
while (*sp)
sp = &((*sp)->next);
*sp = s;
}
}
NODE_WARNING(auto_label_phandles, NULL);
static struct check *check_table[] = {
&duplicate_node_names, &duplicate_property_names,
&node_name_chars, &node_name_format, &property_name_chars,
@@ -669,6 +780,8 @@ static struct check *check_table[] = {
&avoid_default_addr_size,
&obsolete_chosen_interrupt_controller,
&auto_label_phandles,
&always_fail,
};
@@ -706,15 +819,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
c->error = c->error && !error;
}
void parse_checks_option(bool warn, bool error, const char *optarg)
void parse_checks_option(bool warn, bool error, const char *arg)
{
int i;
const char *name = optarg;
const char *name = arg;
bool enable = true;
if ((strncmp(optarg, "no-", 3) == 0)
|| (strncmp(optarg, "no_", 3) == 0)) {
name = optarg + 3;
if ((strncmp(arg, "no-", 3) == 0)
|| (strncmp(arg, "no_", 3) == 0)) {
name = arg + 3;
enable = false;
}
@@ -733,7 +846,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
die("Unrecognized check name \"%s\"\n", name);
}
void process_checks(int force, struct boot_info *bi)
void process_checks(bool force, struct boot_info *bi)
{
struct node *dt = bi->dt;
int i;

View File

@@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len)
struct data d;
char *q;
d = data_grow_for(empty_data, strlen(s)+1);
d = data_grow_for(empty_data, len + 1);
q = d.val;
while (i < len) {
@@ -250,20 +250,20 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref)
return data_append_markers(d, m);
}
int data_is_one_string(struct data d)
bool data_is_one_string(struct data d)
{
int i;
int len = d.len;
if (len == 0)
return 0;
return false;
for (i = 0; i < len-1; i++)
if (d.val[i] == '\0')
return 0;
return false;
if (d.val[len-1] != '\0')
return 0;
return false;
return 1;
return true;
}

View File

@@ -20,7 +20,6 @@
%option noyywrap nounput noinput never-interactive
%x INCLUDE
%x BYTESTRING
%x PROPNODENAME
%s V1
@@ -40,6 +39,7 @@ LINECOMMENT "//".*\n
#include "dtc-parser.tab.h"
YYLTYPE yylloc;
extern bool treesource_error;
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
#define YY_USER_ACTION \
@@ -61,7 +61,8 @@ static int dts_version = 1;
BEGIN(V1); \
static void push_input_file(const char *filename);
static int pop_input_file(void);
static bool pop_input_file(void);
static void lexical_error(const char *fmt, ...);
%}
%%
@@ -75,11 +76,11 @@ static int pop_input_file(void);
char *line, *tmp, *fn;
/* skip text before line # */
line = yytext;
while (!isdigit(*line))
while (!isdigit((unsigned char)*line))
line++;
/* skip digits in line # */
tmp = line;
while (!isspace(*tmp))
while (!isspace((unsigned char)*tmp))
tmp++;
/* "NULL"-terminate line # */
*tmp = '\0';
@@ -112,6 +113,11 @@ static int pop_input_file(void);
return DT_V1;
}
<*>"/plugin/" {
DPRINT("Keyword: /plugin/\n");
return DT_PLUGIN;
}
<*>"/memreserve/" {
DPRINT("Keyword: /memreserve/\n");
BEGIN_DEFAULT();
@@ -146,15 +152,42 @@ static int pop_input_file(void);
}
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
yylval.literal = xstrdup(yytext);
DPRINT("Literal: '%s'\n", yylval.literal);
char *e;
DPRINT("Integer Literal: '%s'\n", yytext);
errno = 0;
yylval.integer = strtoull(yytext, &e, 0);
assert(!(*e) || !e[strspn(e, "UL")]);
if (errno == ERANGE)
lexical_error("Integer literal '%s' out of range",
yytext);
else
/* ERANGE is the only strtoull error triggerable
* by strings matching the pattern */
assert(errno == 0);
return DT_LITERAL;
}
<*>{CHAR_LITERAL} {
yytext[yyleng-1] = '\0';
yylval.literal = xstrdup(yytext+1);
DPRINT("Character literal: %s\n", yylval.literal);
struct data d;
DPRINT("Character literal: %s\n", yytext);
d = data_copy_escape_string(yytext+1, yyleng-2);
if (d.len == 1) {
lexical_error("Empty character literal");
yylval.integer = 0;
return DT_CHAR_LITERAL;
}
yylval.integer = (unsigned char)d.val[0];
if (d.len > 2)
lexical_error("Character literal has %d"
" characters instead of 1",
d.len - 1);
return DT_CHAR_LITERAL;
}
@@ -164,7 +197,7 @@ static int pop_input_file(void);
return DT_REF;
}
<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2);
yylval.labelref = xstrdup(yytext+2);
@@ -238,13 +271,24 @@ static void push_input_file(const char *filename)
}
static int pop_input_file(void)
static bool pop_input_file(void)
{
if (srcfile_pop() == 0)
return 0;
return false;
yypop_buffer_state();
yyin = current_srcfile->f;
return 1;
return true;
}
static void lexical_error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
va_end(ap);
treesource_error = true;
}

View File

@@ -372,8 +372,8 @@ static void yy_fatal_error (yyconst char msg[] );
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 30
#define YY_END_OF_BUFFER 31
#define YY_NUM_RULES 31
#define YY_END_OF_BUFFER 32
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@@ -381,25 +381,26 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[161] =
static yyconst flex_int16_t yy_accept[166] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31, 29, 18, 18, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 15, 16,
16, 29, 16, 10, 10, 18, 26, 0, 3, 0,
27, 12, 0, 0, 11, 0, 0, 0, 0, 0,
0, 0, 21, 23, 25, 24, 22, 0, 9, 28,
0, 0, 0, 14, 14, 16, 16, 16, 10, 10,
10, 0, 12, 0, 11, 0, 0, 0, 20, 0,
0, 0, 0, 0, 0, 0, 0, 16, 10, 10,
10, 0, 19, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 32, 30,
19, 19, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 16, 17, 17, 30,
17, 11, 11, 19, 27, 0, 3, 0, 28, 13,
0, 0, 12, 0, 0, 0, 0, 0, 0, 0,
0, 22, 24, 26, 25, 23, 0, 10, 29, 0,
0, 0, 15, 15, 17, 17, 17, 11, 11, 11,
0, 13, 0, 12, 0, 0, 0, 21, 0, 0,
0, 0, 0, 0, 0, 0, 0, 17, 11, 11,
11, 0, 14, 20, 0, 0, 0, 0, 0, 0,
0, 0, 16, 13, 0, 0, 0, 0, 0, 0,
0, 0, 0, 16, 6, 0, 0, 0, 0, 0,
0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
4, 17, 0, 0, 2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 5, 8, 0, 0, 0, 0, 7, 0
0, 0, 0, 0, 17, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 17, 7, 0, 0, 0,
0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 4, 18, 0, 0, 5, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 6, 9, 0,
0, 0, 0, 8, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@@ -415,9 +416,9 @@ static yyconst flex_int32_t yy_ec[256] =
22, 22, 22, 22, 24, 22, 22, 25, 22, 22,
1, 26, 27, 1, 22, 1, 21, 28, 29, 30,
31, 21, 22, 22, 32, 22, 22, 33, 34, 35,
36, 37, 22, 38, 39, 40, 41, 42, 22, 25,
43, 22, 44, 45, 46, 1, 1, 1, 1, 1,
31, 21, 32, 22, 33, 22, 22, 34, 35, 36,
37, 38, 22, 39, 40, 41, 42, 43, 22, 25,
44, 22, 45, 46, 47, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -434,163 +435,165 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[47] =
static yyconst flex_int32_t yy_meta[48] =
{ 0,
1, 1, 1, 1, 1, 1, 2, 3, 1, 2,
2, 2, 4, 5, 5, 5, 6, 1, 1, 1,
7, 8, 8, 8, 8, 1, 1, 7, 7, 7,
7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 3, 1, 1
8, 8, 8, 8, 3, 1, 4
} ;
static yyconst flex_int16_t yy_base[175] =
static yyconst flex_int16_t yy_base[180] =
{ 0,
0, 385, 378, 40, 41, 383, 72, 382, 34, 44,
388, 393, 61, 117, 368, 116, 115, 115, 115, 48,
367, 107, 368, 339, 127, 120, 0, 147, 393, 0,
127, 0, 133, 156, 168, 153, 393, 125, 393, 380,
393, 0, 369, 127, 393, 160, 371, 377, 347, 21,
343, 346, 393, 393, 393, 393, 393, 359, 393, 393,
183, 343, 339, 393, 356, 0, 183, 340, 187, 348,
347, 0, 0, 0, 178, 359, 195, 365, 354, 326,
332, 325, 334, 328, 204, 326, 331, 324, 393, 335,
150, 311, 343, 342, 315, 322, 340, 179, 313, 207,
0, 393, 35, 392, 66, 391, 38, 107, 397, 401,
55, 113, 377, 112, 111, 111, 114, 42, 376, 106,
377, 347, 126, 120, 0, 147, 401, 0, 124, 0,
137, 158, 170, 163, 401, 153, 401, 389, 401, 0,
378, 120, 401, 131, 380, 386, 355, 139, 351, 355,
351, 401, 401, 401, 401, 401, 367, 401, 401, 185,
350, 346, 401, 364, 0, 185, 347, 189, 356, 355,
0, 0, 330, 180, 366, 141, 372, 361, 332, 338,
331, 341, 334, 326, 205, 331, 337, 329, 401, 341,
167, 316, 401, 349, 348, 320, 328, 346, 180, 318,
319, 316, 317, 393, 337, 333, 305, 302, 311, 301,
310, 190, 338, 337, 393, 307, 322, 301, 305, 277,
208, 311, 307, 278, 271, 270, 248, 246, 213, 130,
393, 393, 263, 235, 207, 221, 218, 229, 213, 213,
206, 234, 218, 210, 208, 193, 219, 393, 223, 204,
176, 157, 393, 393, 120, 106, 97, 119, 393, 393,
245, 251, 259, 263, 267, 273, 280, 284, 292, 300,
304, 310, 318, 326
324, 209, 324, 320, 322, 342, 338, 309, 306, 315,
305, 315, 312, 192, 342, 341, 401, 293, 306, 282,
268, 252, 255, 203, 285, 282, 272, 268, 252, 233,
232, 239, 208, 107, 401, 401, 238, 211, 401, 211,
212, 208, 228, 203, 215, 207, 233, 222, 212, 211,
203, 227, 401, 237, 225, 204, 185, 401, 401, 149,
128, 88, 42, 401, 401, 253, 259, 267, 271, 275,
281, 288, 292, 300, 308, 312, 318, 326, 334
} ;
static yyconst flex_int16_t yy_def[175] =
static yyconst flex_int16_t yy_def[180] =
{ 0,
160, 1, 1, 1, 1, 5, 160, 7, 1, 1,
160, 160, 160, 160, 160, 161, 162, 163, 160, 160,
160, 160, 164, 160, 160, 160, 165, 164, 160, 166,
167, 166, 166, 160, 160, 160, 160, 161, 160, 161,
160, 168, 160, 163, 160, 163, 169, 170, 160, 160,
160, 160, 160, 160, 160, 160, 160, 164, 160, 160,
160, 160, 160, 160, 164, 166, 167, 166, 160, 160,
160, 171, 168, 172, 163, 169, 169, 170, 160, 160,
160, 160, 160, 160, 160, 160, 160, 166, 160, 160,
171, 172, 160, 160, 160, 160, 160, 160, 160, 160,
165, 1, 1, 3, 165, 5, 1, 1, 165, 165,
165, 165, 165, 166, 167, 168, 165, 165, 165, 165,
169, 165, 165, 165, 170, 169, 165, 171, 172, 171,
171, 165, 165, 165, 165, 166, 165, 166, 165, 173,
165, 168, 165, 168, 174, 175, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 169, 165, 165, 165,
165, 165, 165, 169, 171, 172, 171, 165, 165, 165,
176, 173, 177, 168, 174, 174, 175, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 171, 165, 165,
176, 177, 165, 165, 165, 165, 165, 165, 165, 165,
160, 160, 166, 160, 160, 160, 160, 160, 160, 160,
160, 173, 160, 166, 160, 160, 160, 160, 160, 160,
173, 160, 173, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 174, 160, 160, 160, 174, 160, 174, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 0,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160
165, 165, 165, 165, 171, 165, 165, 165, 165, 165,
165, 165, 165, 178, 165, 171, 165, 165, 165, 165,
165, 165, 165, 178, 165, 178, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 179, 165, 165,
165, 179, 165, 179, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 0, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165
} ;
static yyconst flex_int16_t yy_nxt[440] =
static yyconst flex_int16_t yy_nxt[449] =
{ 0,
12, 13, 14, 13, 15, 16, 12, 17, 18, 12,
12, 12, 19, 12, 12, 12, 12, 20, 21, 22,
23, 23, 23, 23, 23, 12, 12, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 12, 24, 12, 25, 34, 35, 35,
25, 81, 26, 26, 27, 27, 27, 34, 35, 35,
82, 28, 36, 36, 36, 53, 54, 29, 28, 28,
28, 28, 12, 13, 14, 13, 15, 16, 30, 17,
18, 30, 30, 30, 26, 30, 30, 30, 12, 20,
21, 22, 31, 31, 31, 31, 31, 32, 12, 31,
10, 11, 12, 11, 13, 14, 10, 15, 16, 10,
10, 10, 17, 10, 10, 10, 10, 18, 19, 20,
21, 21, 21, 21, 21, 10, 10, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 10, 22, 10, 24, 25, 25,
25, 32, 33, 33, 164, 26, 34, 34, 34, 52,
53, 27, 26, 26, 26, 26, 10, 11, 12, 11,
13, 14, 28, 15, 16, 28, 28, 28, 24, 28,
28, 28, 10, 18, 19, 20, 29, 29, 29, 29,
29, 30, 10, 29, 29, 29, 29, 29, 29, 29,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 12, 24, 12, 36, 36,
36, 39, 41, 45, 47, 56, 57, 48, 61, 47,
39, 159, 48, 66, 61, 45, 66, 66, 66, 158,
46, 40, 49, 59, 50, 157, 51, 49, 52, 50,
40, 63, 46, 52, 36, 36, 36, 156, 43, 62,
65, 65, 65, 59, 136, 68, 137, 65, 75, 69,
69, 69, 70, 71, 65, 65, 65, 65, 70, 71,
72, 69, 69, 69, 61, 46, 45, 155, 154, 66,
70, 71, 66, 66, 66, 122, 85, 85, 85, 59,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
10, 22, 10, 23, 34, 34, 34, 37, 39, 43,
32, 33, 33, 45, 55, 56, 46, 60, 43, 45,
65, 163, 46, 65, 65, 65, 44, 38, 60, 74,
58, 47, 141, 48, 142, 44, 49, 47, 50, 48,
76, 51, 62, 94, 50, 41, 44, 51, 37, 61,
64, 64, 64, 58, 34, 34, 34, 64, 162, 80,
67, 68, 68, 68, 64, 64, 64, 64, 38, 81,
69, 70, 71, 68, 68, 68, 60, 161, 43, 69,
70, 65, 69, 70, 65, 65, 65, 125, 85, 85,
69, 69, 69, 46, 77, 100, 109, 93, 100, 70,
71, 110, 112, 122, 129, 123, 153, 85, 85, 85,
135, 135, 135, 148, 148, 160, 135, 135, 135, 152,
142, 142, 142, 123, 143, 142, 142, 142, 151, 143,
150, 146, 145, 149, 149, 38, 38, 38, 38, 38,
38, 38, 38, 42, 144, 141, 140, 42, 42, 44,
44, 44, 44, 44, 44, 44, 44, 58, 58, 58,
58, 64, 139, 64, 66, 138, 134, 66, 133, 66,
66, 67, 132, 131, 67, 67, 67, 67, 73, 130,
73, 73, 76, 76, 76, 76, 76, 76, 76, 76,
85, 58, 68, 68, 68, 44, 102, 110, 125, 133,
102, 69, 70, 111, 114, 160, 159, 126, 85, 85,
85, 140, 140, 140, 140, 140, 140, 153, 126, 147,
147, 147, 153, 148, 147, 147, 147, 158, 148, 165,
157, 156, 155, 151, 150, 149, 146, 154, 145, 144,
143, 139, 154, 36, 36, 36, 36, 36, 36, 36,
36, 40, 138, 137, 136, 40, 40, 42, 42, 42,
42, 42, 42, 42, 42, 57, 57, 57, 57, 63,
135, 63, 65, 134, 165, 65, 133, 65, 65, 66,
132, 131, 66, 66, 66, 66, 72, 130, 72, 72,
78, 78, 78, 78, 78, 78, 78, 78, 91, 160,
91, 92, 129, 92, 92, 128, 92, 92, 121, 121,
121, 121, 121, 121, 121, 121, 147, 147, 147, 147,
147, 147, 147, 147, 127, 126, 125, 124, 61, 61,
120, 119, 118, 117, 116, 115, 47, 114, 110, 113,
111, 108, 107, 106, 48, 105, 104, 89, 103, 102,
101, 99, 98, 97, 96, 95, 94, 79, 77, 90,
89, 88, 59, 87, 86, 59, 84, 83, 80, 79,
77, 74, 160, 60, 59, 55, 37, 160, 33, 25,
26, 25, 11, 160, 160, 160, 160, 160, 160, 160,
75, 75, 75, 75, 75, 75, 75, 75, 77, 77,
77, 77, 77, 77, 77, 77, 91, 129, 91, 92,
128, 92, 92, 127, 92, 92, 124, 124, 124, 124,
124, 124, 124, 124, 152, 152, 152, 152, 152, 152,
152, 152, 60, 60, 123, 122, 121, 120, 119, 118,
117, 45, 116, 111, 115, 113, 112, 109, 108, 107,
46, 106, 93, 89, 105, 104, 103, 101, 100, 99,
98, 97, 96, 95, 78, 76, 93, 90, 89, 88,
58, 87, 86, 58, 84, 83, 82, 79, 78, 76,
73, 165, 59, 58, 54, 35, 165, 31, 23, 23,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160
9, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165
} ;
static yyconst flex_int16_t yy_chk[440] =
static yyconst flex_int16_t yy_chk[449] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 4, 9, 9, 9,
10, 50, 4, 5, 5, 5, 5, 10, 10, 10,
50, 5, 13, 13, 13, 20, 20, 5, 5, 5,
5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
3, 7, 7, 7, 163, 3, 11, 11, 11, 18,
18, 3, 3, 3, 3, 3, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 14, 14,
14, 16, 17, 18, 19, 22, 22, 19, 25, 26,
38, 158, 26, 31, 33, 44, 31, 31, 31, 157,
18, 16, 19, 31, 19, 156, 19, 26, 19, 26,
38, 26, 44, 26, 36, 36, 36, 155, 17, 25,
28, 28, 28, 28, 130, 33, 130, 28, 46, 34,
34, 34, 91, 91, 28, 28, 28, 28, 34, 34,
34, 35, 35, 35, 61, 46, 75, 152, 151, 67,
35, 35, 67, 67, 67, 112, 61, 61, 61, 67,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 8, 12, 12, 12, 14, 15, 16,
8, 8, 8, 17, 20, 20, 17, 23, 42, 24,
29, 162, 24, 29, 29, 29, 16, 14, 31, 44,
29, 17, 134, 17, 134, 42, 17, 24, 17, 24,
76, 17, 24, 76, 24, 15, 44, 24, 36, 23,
26, 26, 26, 26, 34, 34, 34, 26, 161, 48,
31, 32, 32, 32, 26, 26, 26, 26, 36, 48,
32, 32, 32, 33, 33, 33, 60, 160, 74, 91,
91, 66, 33, 33, 66, 66, 66, 114, 60, 60,
69, 69, 69, 75, 77, 85, 98, 77, 100, 69,
69, 98, 100, 121, 129, 112, 150, 85, 85, 85,
135, 135, 135, 143, 147, 149, 129, 129, 129, 146,
138, 138, 138, 121, 138, 142, 142, 142, 145, 142,
144, 141, 140, 143, 147, 161, 161, 161, 161, 161,
161, 161, 161, 162, 139, 137, 136, 162, 162, 163,
163, 163, 163, 163, 163, 163, 163, 164, 164, 164,
164, 165, 134, 165, 166, 133, 128, 166, 127, 166,
166, 167, 126, 125, 167, 167, 167, 167, 168, 124,
168, 168, 169, 169, 169, 169, 169, 169, 169, 169,
60, 66, 68, 68, 68, 74, 85, 99, 124, 133,
102, 68, 68, 99, 102, 157, 156, 114, 85, 85,
85, 133, 133, 133, 140, 140, 140, 148, 124, 143,
143, 143, 152, 143, 147, 147, 147, 155, 147, 154,
151, 150, 149, 146, 145, 144, 142, 148, 141, 138,
137, 132, 152, 166, 166, 166, 166, 166, 166, 166,
166, 167, 131, 130, 129, 167, 167, 168, 168, 168,
168, 168, 168, 168, 168, 169, 169, 169, 169, 170,
128, 170, 171, 127, 126, 171, 125, 171, 171, 172,
123, 122, 172, 172, 172, 172, 173, 121, 173, 173,
170, 170, 170, 170, 170, 170, 170, 170, 171, 123,
171, 172, 122, 172, 172, 120, 172, 172, 173, 173,
173, 173, 173, 173, 173, 173, 174, 174, 174, 174,
174, 174, 174, 174, 119, 118, 117, 116, 114, 113,
111, 110, 109, 108, 107, 106, 105, 103, 102, 101,
99, 97, 96, 95, 94, 93, 92, 90, 88, 87,
86, 84, 83, 82, 81, 80, 79, 78, 76, 71,
70, 68, 65, 63, 62, 58, 52, 51, 49, 48,
47, 43, 40, 24, 23, 21, 15, 11, 8, 6,
3, 2, 160, 160, 160, 160, 160, 160, 160, 160,
174, 174, 174, 174, 174, 174, 174, 174, 175, 175,
175, 175, 175, 175, 175, 175, 176, 120, 176, 177,
119, 177, 177, 118, 177, 177, 178, 178, 178, 178,
178, 178, 178, 178, 179, 179, 179, 179, 179, 179,
179, 179, 116, 115, 113, 112, 111, 110, 109, 108,
107, 106, 105, 104, 103, 101, 100, 98, 97, 96,
95, 94, 92, 90, 88, 87, 86, 84, 83, 82,
81, 80, 79, 78, 77, 75, 73, 70, 69, 67,
64, 62, 61, 57, 51, 50, 49, 47, 46, 45,
41, 38, 22, 21, 19, 13, 9, 6, 4, 2,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160, 160
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165, 165, 165,
165, 165, 165, 165, 165, 165, 165, 165
} ;
static yy_state_type yy_last_accepting_state;
@@ -631,13 +634,13 @@ char *yytext;
#line 38 "dtc-lexer.l"
#line 37 "dtc-lexer.l"
#include "dtc.h"
#include "srcpos.h"
#include "dtc-parser.tab.h"
YYLTYPE yylloc;
extern bool treesource_error;
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
#define YY_USER_ACTION \
@@ -659,14 +662,14 @@ static int dts_version = 1;
BEGIN(V1); \
static void push_input_file(const char *filename);
static int pop_input_file(void);
#line 664 "dtc-lexer.lex.c"
static bool pop_input_file(void);
static void lexical_error(const char *fmt, ...);
#line 668 "dtc-lexer.lex.c"
#define INITIAL 0
#define INCLUDE 1
#define BYTESTRING 2
#define PROPNODENAME 3
#define V1 4
#define BYTESTRING 1
#define PROPNODENAME 2
#define V1 3
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
@@ -852,9 +855,9 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 67 "dtc-lexer.l"
#line 68 "dtc-lexer.l"
#line 858 "dtc-lexer.lex.c"
#line 861 "dtc-lexer.lex.c"
if ( !(yy_init) )
{
@@ -908,13 +911,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 )
if ( yy_current_state >= 166 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_current_state != 160 );
while ( yy_current_state != 165 );
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
@@ -937,7 +940,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
#line 68 "dtc-lexer.l"
#line 69 "dtc-lexer.l"
{
char *name = strchr(yytext, '\"') + 1;
yytext[yyleng-1] = '\0';
@@ -947,16 +950,16 @@ YY_RULE_SETUP
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 74 "dtc-lexer.l"
#line 75 "dtc-lexer.l"
{
char *line, *tmp, *fn;
/* skip text before line # */
line = yytext;
while (!isdigit(*line))
while (!isdigit((unsigned char)*line))
line++;
/* skip digits in line # */
tmp = line;
while (!isspace(*tmp))
while (!isspace((unsigned char)*tmp))
tmp++;
/* "NULL"-terminate line # */
*tmp = '\0';
@@ -970,11 +973,10 @@ YY_RULE_SETUP
}
YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(INCLUDE):
case YY_STATE_EOF(BYTESTRING):
case YY_STATE_EOF(PROPNODENAME):
case YY_STATE_EOF(V1):
#line 95 "dtc-lexer.l"
#line 96 "dtc-lexer.l"
{
if (!pop_input_file()) {
yyterminate();
@@ -984,7 +986,7 @@ case YY_STATE_EOF(V1):
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
#line 101 "dtc-lexer.l"
#line 102 "dtc-lexer.l"
{
DPRINT("String: %s\n", yytext);
yylval.data = data_copy_escape_string(yytext+1,
@@ -994,7 +996,7 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
#line 108 "dtc-lexer.l"
#line 109 "dtc-lexer.l"
{
DPRINT("Keyword: /dts-v1/\n");
dts_version = 1;
@@ -1004,25 +1006,33 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 115 "dtc-lexer.l"
#line 116 "dtc-lexer.l"
{
DPRINT("Keyword: /memreserve/\n");
BEGIN_DEFAULT();
return DT_MEMRESERVE;
DPRINT("Keyword: /plugin/\n");
return DT_PLUGIN;
}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 121 "dtc-lexer.l"
{
DPRINT("Keyword: /bits/\n");
DPRINT("Keyword: /memreserve/\n");
BEGIN_DEFAULT();
return DT_BITS;
return DT_MEMRESERVE;
}
YY_BREAK
case 7:
YY_RULE_SETUP
#line 127 "dtc-lexer.l"
{
DPRINT("Keyword: /bits/\n");
BEGIN_DEFAULT();
return DT_BITS;
}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 133 "dtc-lexer.l"
{
DPRINT("Keyword: /delete-property/\n");
DPRINT("<PROPNODENAME>\n");
@@ -1030,9 +1040,9 @@ YY_RULE_SETUP
return DT_DEL_PROP;
}
YY_BREAK
case 8:
case 9:
YY_RULE_SETUP
#line 134 "dtc-lexer.l"
#line 140 "dtc-lexer.l"
{
DPRINT("Keyword: /delete-node/\n");
DPRINT("<PROPNODENAME>\n");
@@ -1040,9 +1050,9 @@ YY_RULE_SETUP
return DT_DEL_NODE;
}
YY_BREAK
case 9:
case 10:
YY_RULE_SETUP
#line 141 "dtc-lexer.l"
#line 147 "dtc-lexer.l"
{
DPRINT("Label: %s\n", yytext);
yylval.labelref = xstrdup(yytext);
@@ -1050,38 +1060,65 @@ YY_RULE_SETUP
return DT_LABEL;
}
YY_BREAK
case 10:
YY_RULE_SETUP
#line 148 "dtc-lexer.l"
{
yylval.literal = xstrdup(yytext);
DPRINT("Literal: '%s'\n", yylval.literal);
return DT_LITERAL;
}
YY_BREAK
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
#line 154 "dtc-lexer.l"
{
yytext[yyleng-1] = '\0';
yylval.literal = xstrdup(yytext+1);
DPRINT("Character literal: %s\n", yylval.literal);
return DT_CHAR_LITERAL;
char *e;
DPRINT("Integer Literal: '%s'\n", yytext);
errno = 0;
yylval.integer = strtoull(yytext, &e, 0);
assert(!(*e) || !e[strspn(e, "UL")]);
if (errno == ERANGE)
lexical_error("Integer literal '%s' out of range",
yytext);
else
/* ERANGE is the only strtoull error triggerable
* by strings matching the pattern */
assert(errno == 0);
return DT_LITERAL;
}
YY_BREAK
case 12:
/* rule 12 can match eol */
YY_RULE_SETUP
#line 161 "dtc-lexer.l"
#line 173 "dtc-lexer.l"
{
struct data d;
DPRINT("Character literal: %s\n", yytext);
d = data_copy_escape_string(yytext+1, yyleng-2);
if (d.len == 1) {
lexical_error("Empty character literal");
yylval.integer = 0;
return DT_CHAR_LITERAL;
}
yylval.integer = (unsigned char)d.val[0];
if (d.len > 2)
lexical_error("Character literal has %d"
" characters instead of 1",
d.len - 1);
return DT_CHAR_LITERAL;
}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 194 "dtc-lexer.l"
{ /* label reference */
DPRINT("Ref: %s\n", yytext+1);
yylval.labelref = xstrdup(yytext+1);
return DT_REF;
}
YY_BREAK
case 13:
case 14:
YY_RULE_SETUP
#line 167 "dtc-lexer.l"
#line 200 "dtc-lexer.l"
{ /* new-style path reference */
yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2);
@@ -1089,27 +1126,27 @@ YY_RULE_SETUP
return DT_REF;
}
YY_BREAK
case 14:
case 15:
YY_RULE_SETUP
#line 174 "dtc-lexer.l"
#line 207 "dtc-lexer.l"
{
yylval.byte = strtol(yytext, NULL, 16);
DPRINT("Byte: %02x\n", (int)yylval.byte);
return DT_BYTE;
}
YY_BREAK
case 15:
case 16:
YY_RULE_SETUP
#line 180 "dtc-lexer.l"
#line 213 "dtc-lexer.l"
{
DPRINT("/BYTESTRING\n");
BEGIN_DEFAULT();
return ']';
}
YY_BREAK
case 16:
case 17:
YY_RULE_SETUP
#line 186 "dtc-lexer.l"
#line 219 "dtc-lexer.l"
{
DPRINT("PropNodeName: %s\n", yytext);
yylval.propnodename = xstrdup((yytext[0] == '\\') ?
@@ -1118,75 +1155,75 @@ YY_RULE_SETUP
return DT_PROPNODENAME;
}
YY_BREAK
case 17:
case 18:
YY_RULE_SETUP
#line 194 "dtc-lexer.l"
#line 227 "dtc-lexer.l"
{
DPRINT("Binary Include\n");
return DT_INCBIN;
}
YY_BREAK
case 18:
/* rule 18 can match eol */
YY_RULE_SETUP
#line 199 "dtc-lexer.l"
/* eat whitespace */
YY_BREAK
case 19:
/* rule 19 can match eol */
YY_RULE_SETUP
#line 200 "dtc-lexer.l"
/* eat C-style comments */
#line 232 "dtc-lexer.l"
/* eat whitespace */
YY_BREAK
case 20:
/* rule 20 can match eol */
YY_RULE_SETUP
#line 201 "dtc-lexer.l"
/* eat C++-style comments */
#line 233 "dtc-lexer.l"
/* eat C-style comments */
YY_BREAK
case 21:
/* rule 21 can match eol */
YY_RULE_SETUP
#line 203 "dtc-lexer.l"
{ return DT_LSHIFT; };
#line 234 "dtc-lexer.l"
/* eat C++-style comments */
YY_BREAK
case 22:
YY_RULE_SETUP
#line 204 "dtc-lexer.l"
{ return DT_RSHIFT; };
#line 236 "dtc-lexer.l"
{ return DT_LSHIFT; };
YY_BREAK
case 23:
YY_RULE_SETUP
#line 205 "dtc-lexer.l"
{ return DT_LE; };
#line 237 "dtc-lexer.l"
{ return DT_RSHIFT; };
YY_BREAK
case 24:
YY_RULE_SETUP
#line 206 "dtc-lexer.l"
{ return DT_GE; };
#line 238 "dtc-lexer.l"
{ return DT_LE; };
YY_BREAK
case 25:
YY_RULE_SETUP
#line 207 "dtc-lexer.l"
{ return DT_EQ; };
#line 239 "dtc-lexer.l"
{ return DT_GE; };
YY_BREAK
case 26:
YY_RULE_SETUP
#line 208 "dtc-lexer.l"
{ return DT_NE; };
#line 240 "dtc-lexer.l"
{ return DT_EQ; };
YY_BREAK
case 27:
YY_RULE_SETUP
#line 209 "dtc-lexer.l"
{ return DT_AND; };
#line 241 "dtc-lexer.l"
{ return DT_NE; };
YY_BREAK
case 28:
YY_RULE_SETUP
#line 210 "dtc-lexer.l"
{ return DT_OR; };
#line 242 "dtc-lexer.l"
{ return DT_AND; };
YY_BREAK
case 29:
YY_RULE_SETUP
#line 212 "dtc-lexer.l"
#line 243 "dtc-lexer.l"
{ return DT_OR; };
YY_BREAK
case 30:
YY_RULE_SETUP
#line 245 "dtc-lexer.l"
{
DPRINT("Char: %c (\\x%02x)\n", yytext[0],
(unsigned)yytext[0]);
@@ -1202,12 +1239,12 @@ YY_RULE_SETUP
return yytext[0];
}
YY_BREAK
case 30:
case 31:
YY_RULE_SETUP
#line 227 "dtc-lexer.l"
#line 260 "dtc-lexer.l"
ECHO;
YY_BREAK
#line 1211 "dtc-lexer.lex.c"
#line 1248 "dtc-lexer.lex.c"
case YY_END_OF_BUFFER:
{
@@ -1499,7 +1536,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 )
if ( yy_current_state >= 166 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1527,11 +1564,11 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 )
if ( yy_current_state >= 166 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 160);
yy_is_jam = (yy_current_state == 165);
return yy_is_jam ? 0 : yy_current_state;
}
@@ -2166,7 +2203,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 227 "dtc-lexer.l"
#line 260 "dtc-lexer.l"
@@ -2182,14 +2219,25 @@ static void push_input_file(const char *filename)
}
static int pop_input_file(void)
static bool pop_input_file(void)
{
if (srcfile_pop() == 0)
return 0;
return false;
yypop_buffer_state();
yyin = current_srcfile->f;
return 1;
return true;
}
static void lexical_error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
va_end(ap);
treesource_error = true;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 2.7.12-4996. */
/* A Bison parser, made by GNU Bison 3.0.2. */
/* Bison interface for Yacc-like parsers in C
@@ -32,7 +32,7 @@
#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
# define YY_YY_DTC_PARSER_TAB_H_INCLUDED
/* Enabling traces. */
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
@@ -40,29 +40,28 @@
extern int yydebug;
#endif
/* Tokens. */
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
enum yytokentype
{
DT_V1 = 258,
DT_MEMRESERVE = 259,
DT_LSHIFT = 260,
DT_RSHIFT = 261,
DT_LE = 262,
DT_GE = 263,
DT_EQ = 264,
DT_NE = 265,
DT_AND = 266,
DT_OR = 267,
DT_BITS = 268,
DT_DEL_PROP = 269,
DT_DEL_NODE = 270,
DT_PROPNODENAME = 271,
DT_LITERAL = 272,
DT_CHAR_LITERAL = 273,
DT_BASE = 274,
DT_PLUGIN = 259,
DT_MEMRESERVE = 260,
DT_LSHIFT = 261,
DT_RSHIFT = 262,
DT_LE = 263,
DT_GE = 264,
DT_EQ = 265,
DT_NE = 266,
DT_AND = 267,
DT_OR = 268,
DT_BITS = 269,
DT_DEL_PROP = 270,
DT_DEL_NODE = 271,
DT_PROPNODENAME = 272,
DT_LITERAL = 273,
DT_CHAR_LITERAL = 274,
DT_BYTE = 275,
DT_STRING = 276,
DT_LABEL = 277,
@@ -71,17 +70,15 @@ extern int yydebug;
};
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{
/* Line 2053 of yacc.c */
#line 40 "dtc-parser.y"
#line 39 "dtc-parser.y" /* yacc.c:1909 */
char *propnodename;
char *literal;
char *labelref;
unsigned int cbase;
uint8_t byte;
struct data data;
@@ -96,30 +93,31 @@ typedef union YYSTYPE
struct node *nodelist;
struct reserve_info *re;
uint64_t integer;
int is_plugin;
/* Line 2053 of yacc.c */
#line 103 "dtc-parser.tab.h"
} YYSTYPE;
#line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
};
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
/* Location type. */
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE YYLTYPE;
struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
};
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
extern YYSTYPE yylval;
extern YYLTYPE yylloc;
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */

View File

@@ -17,31 +17,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%{
#include <stdio.h>
#include <inttypes.h>
#include "dtc.h"
#include "srcpos.h"
YYLTYPE yylloc;
extern int yylex(void);
extern void print_error(char const *fmt, ...);
extern void yyerror(char const *s);
#define ERROR(loc, ...) \
do { \
srcpos_error((loc), "Error", __VA_ARGS__); \
treesource_error = true; \
} while (0)
extern struct boot_info *the_boot_info;
extern int treesource_error;
static unsigned long long eval_literal(const char *s, int base, int bits);
static unsigned char eval_char_literal(const char *s);
extern bool treesource_error;
%}
%union {
char *propnodename;
char *literal;
char *labelref;
unsigned int cbase;
uint8_t byte;
struct data data;
@@ -56,18 +53,19 @@ static unsigned char eval_char_literal(const char *s);
struct node *nodelist;
struct reserve_info *re;
uint64_t integer;
int is_plugin;
}
%token DT_V1
%token DT_PLUGIN
%token DT_MEMRESERVE
%token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
%token DT_BITS
%token DT_DEL_PROP
%token DT_DEL_NODE
%token <propnodename> DT_PROPNODENAME
%token <literal> DT_LITERAL
%token <literal> DT_CHAR_LITERAL
%token <cbase> DT_BASE
%token <integer> DT_LITERAL
%token <integer> DT_CHAR_LITERAL
%token <byte> DT_BYTE
%token <data> DT_STRING
%token <labelref> DT_LABEL
@@ -76,6 +74,7 @@ static unsigned char eval_char_literal(const char *s);
%type <data> propdata
%type <data> propdataprefix
%type <is_plugin> plugindecl
%type <re> memreserve
%type <re> memreserves
%type <array> arrayprefix
@@ -106,10 +105,23 @@ static unsigned char eval_char_literal(const char *s);
%%
sourcefile:
DT_V1 ';' memreserves devicetree
DT_V1 ';' plugindecl memreserves devicetree
{
the_boot_info = build_boot_info($3, $4,
guess_boot_cpuid($4));
$5->is_plugin = $3;
$5->is_root = 1;
the_boot_info = build_boot_info($4, $5,
guess_boot_cpuid($5));
}
;
plugindecl:
/* empty */
{
$$ = 0;
}
| DT_PLUGIN ';'
{
$$ = 1;
}
;
@@ -152,17 +164,18 @@ devicetree:
if (target)
merge_nodes(target, $3);
else
print_error("label or path, '%s', not found", $2);
ERROR(&@2, "Label or path %s not found", $2);
$$ = $1;
}
| devicetree DT_DEL_NODE DT_REF ';'
{
struct node *target = get_node_by_ref($1, $3);
if (!target)
print_error("label or path, '%s', not found", $3);
else
if (target)
delete_node(target);
else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
@@ -230,9 +243,8 @@ propdata:
if ($6 != 0)
if (fseek(f, $6, SEEK_SET) != 0)
print_error("Couldn't seek to offset %llu in \"%s\": %s",
(unsigned long long)$6,
$4.val,
die("Couldn't seek to offset %llu in \"%s\": %s",
(unsigned long long)$6, $4.val,
strerror(errno));
d = data_copy_file(f, $8);
@@ -274,18 +286,19 @@ propdataprefix:
arrayprefix:
DT_BITS DT_LITERAL '<'
{
$$.data = empty_data;
$$.bits = eval_literal($2, 0, 7);
unsigned long long bits;
if (($$.bits != 8) &&
($$.bits != 16) &&
($$.bits != 32) &&
($$.bits != 64))
{
print_error("Only 8, 16, 32 and 64-bit elements"
" are currently supported");
$$.bits = 32;
bits = $2;
if ((bits != 8) && (bits != 16) &&
(bits != 32) && (bits != 64)) {
ERROR(&@2, "Array elements must be"
" 8, 16, 32 or 64-bits");
bits = 32;
}
$$.data = empty_data;
$$.bits = bits;
}
| '<'
{
@@ -305,9 +318,8 @@ arrayprefix:
* mask), all bits are one.
*/
if (($2 > mask) && (($2 | mask) != -1ULL))
print_error(
"integer value out of range "
"%016lx (%d bits)", $1.bits);
ERROR(&@2, "Value out of range for"
" %d-bit array element", $1.bits);
}
$$.data = data_append_integer($1.data, $2, $1.bits);
@@ -321,7 +333,7 @@ arrayprefix:
REF_PHANDLE,
$2);
else
print_error("References are only allowed in "
ERROR(&@2, "References are only allowed in "
"arrays with 32-bit elements.");
$$.data = data_append_integer($1.data, val, $1.bits);
@@ -334,13 +346,7 @@ arrayprefix:
integer_prim:
DT_LITERAL
{
$$ = eval_literal($1, 0, 64);
}
| DT_CHAR_LITERAL
{
$$ = eval_char_literal($1);
}
| '(' integer_expr ')'
{
$$ = $2;
@@ -447,7 +453,7 @@ subnodes:
}
| subnode propdef
{
print_error("syntax error: properties must precede subnodes");
ERROR(&@2, "Properties must precede subnodes");
YYERROR;
}
;
@@ -470,63 +476,7 @@ subnode:
%%
void print_error(char const *fmt, ...)
void yyerror(char const *s)
{
va_list va;
va_start(va, fmt);
srcpos_verror(&yylloc, fmt, va);
va_end(va);
treesource_error = 1;
}
void yyerror(char const *s) {
print_error("%s", s);
}
static unsigned long long eval_literal(const char *s, int base, int bits)
{
unsigned long long val;
char *e;
errno = 0;
val = strtoull(s, &e, base);
if (*e) {
size_t uls = strspn(e, "UL");
if (e[uls])
print_error("bad characters in literal");
}
if ((errno == ERANGE)
|| ((bits < 64) && (val >= (1ULL << bits))))
print_error("literal out of range");
else if (errno != 0)
print_error("bad literal");
return val;
}
static unsigned char eval_char_literal(const char *s)
{
int i = 1;
char c = s[0];
if (c == '\0')
{
print_error("empty character literal");
return 0;
}
/*
* If the first character in the character literal is a \ then process
* the remaining characters as an escape encoding. If the first
* character is neither an escape or a terminator it should be the only
* character in the literal and will be returned.
*/
if (c == '\\')
c = get_escape_char(s, &i);
if (s[i] != '\0')
print_error("malformed character literal");
return c;
ERROR(&yylloc, "%s", s);
}

View File

@@ -29,6 +29,7 @@ int reservenum; /* Number of memory reservation slots */
int minsize; /* Minimum blob size */
int padsize; /* Additional padding to blob */
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
int symbol_fixup_support = 0;
static void fill_fullpaths(struct node *tree, const char *prefix)
{
@@ -48,8 +49,10 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
}
/* Usage related data. */
#define FDT_VERSION(version) _FDT_VERSION(version)
#define _FDT_VERSION(version) #version
static const char usage_synopsis[] = "dtc [options] <input file>";
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv@";
static struct option const usage_long_opts[] = {
{"quiet", no_argument, NULL, 'q'},
{"in-format", a_argument, NULL, 'I'},
@@ -67,6 +70,7 @@ static struct option const usage_long_opts[] = {
{"phandle", a_argument, NULL, 'H'},
{"warning", a_argument, NULL, 'W'},
{"error", a_argument, NULL, 'E'},
{"symbols", a_argument, NULL, '@'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{NULL, no_argument, NULL, 0x0},
@@ -82,9 +86,9 @@ static const char * const usage_opts_help[] = {
"\t\tdts - device tree source text\n"
"\t\tdtb - device tree blob\n"
"\t\tasm - assembler source",
"\n\tBlob version to produce, defaults to %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION);
"\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
"\n\tOutput dependency file",
"\n\ttMake space for <number> reserve map entries (for dtb and asm output)",
"\n\tMake space for <number> reserve map entries (for dtb and asm output)",
"\n\tMake the blob at least <bytes> long (extra space)",
"\n\tAdd padding to the blob of <bytes> long (extra space)",
"\n\tSet the physical boot cpu",
@@ -97,6 +101,7 @@ static const char * const usage_opts_help[] = {
"\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
"\n\tEnable/disable warnings (prefix with \"no-\")",
"\n\tEnable/disable errors (prefix with \"no-\")",
"\n\tSymbols and Fixups support",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
NULL,
@@ -109,7 +114,7 @@ int main(int argc, char *argv[])
const char *outform = "dts";
const char *outname = "-";
const char *depname = NULL;
int force = 0, sort = 0;
bool force = false, sort = false;
const char *arg;
int opt;
FILE *outf = NULL;
@@ -148,7 +153,7 @@ int main(int argc, char *argv[])
padsize = strtol(optarg, NULL, 0);
break;
case 'f':
force = 1;
force = true;
break;
case 'q':
quiet++;
@@ -174,7 +179,7 @@ int main(int argc, char *argv[])
break;
case 's':
sort = 1;
sort = true;
break;
case 'W':
@@ -184,7 +189,9 @@ int main(int argc, char *argv[])
case 'E':
parse_checks_option(false, true, optarg);
break;
case '@':
symbol_fixup_support = 1;
break;
case 'h':
usage(NULL);
default:
@@ -237,7 +244,7 @@ int main(int argc, char *argv[])
if (streq(outname, "-")) {
outf = stdout;
} else {
outf = fopen(outname, "w");
outf = fopen(outname, "wb");
if (! outf)
die("Couldn't open output file %s: %s\n",
outname, strerror(errno));

View File

@@ -38,9 +38,9 @@
#include "util.h"
#ifdef DEBUG
#define debug(fmt,args...) printf(fmt, ##args)
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(fmt,args...)
#define debug(...)
#endif
@@ -54,6 +54,7 @@ extern int reservenum; /* Number of memory reservation slots */
extern int minsize; /* Minimum blob size */
extern int padsize; /* Additional padding to blob */
extern int phandle_format; /* Use linux,phandle or phandle properties */
extern int symbol_fixup_support;/* enable symbols & fixup support */
#define PHANDLE_LEGACY 0x1
#define PHANDLE_EPAPR 0x2
@@ -88,7 +89,7 @@ struct data {
};
#define empty_data ((struct data){ /* all .members = 0 or NULL */ })
#define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
#define for_each_marker(m) \
for (; (m); (m) = (m)->next)
@@ -118,7 +119,7 @@ struct data data_append_align(struct data d, int align);
struct data data_add_marker(struct data d, enum markertype type, char *ref);
int data_is_one_string(struct data d);
bool data_is_one_string(struct data d);
/* DT constraints */
@@ -127,13 +128,32 @@ int data_is_one_string(struct data d);
/* Live trees */
struct label {
int deleted;
bool deleted;
char *label;
struct label *next;
};
struct fixup_entry {
int offset;
struct node *node;
struct property *prop;
struct fixup_entry *next;
};
struct fixup {
char *ref;
struct fixup_entry *entries;
struct fixup *next;
};
struct symbol {
struct label *label;
struct node *node;
struct symbol *next;
};
struct property {
int deleted;
bool deleted;
char *name;
struct data val;
@@ -143,7 +163,7 @@ struct property {
};
struct node {
int deleted;
bool deleted;
char *name;
struct property *proplist;
struct node *children;
@@ -158,6 +178,12 @@ struct node {
int addr_cells, size_cells;
struct label *labels;
int is_root;
int is_plugin;
struct fixup *fixups;
struct symbol *symbols;
struct fixup_entry *local_fixups;
};
#define for_each_label_withdel(l0, l) \
@@ -181,6 +207,18 @@ struct node {
for_each_child_withdel(n, c) \
if (!(c)->deleted)
#define for_each_fixup(n, f) \
for ((f) = (n)->fixups; (f); (f) = (f)->next)
#define for_each_fixup_entry(f, fe) \
for ((fe) = (f)->entries; (fe); (fe) = (fe)->next)
#define for_each_symbol(n, s) \
for ((s) = (n)->symbols; (s); (s) = (s)->next)
#define for_each_local_fixup_entry(n, fe) \
for ((fe) = (n)->local_fixups; (fe); (fe) = (fe)->next)
void add_label(struct label **labels, char *label);
void delete_labels(struct label **labels);
@@ -247,8 +285,8 @@ void sort_tree(struct boot_info *bi);
/* Checks */
void parse_checks_option(bool warn, bool error, const char *optarg);
void process_checks(int force, struct boot_info *bi);
void parse_checks_option(bool warn, bool error, const char *arg);
void process_checks(bool force, struct boot_info *bi);
/* Flattened trees */

View File

@@ -261,7 +261,13 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
{
struct property *prop;
struct node *child;
int seen_name_prop = 0;
bool seen_name_prop = false;
struct symbol *sym;
struct fixup *f;
struct fixup_entry *fe;
char *name, *s;
const char *fullpath;
int namesz, nameoff, vallen;
if (tree->deleted)
return;
@@ -276,10 +282,8 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
emit->align(etarget, sizeof(cell_t));
for_each_property(tree, prop) {
int nameoff;
if (streq(prop->name, "name"))
seen_name_prop = 1;
seen_name_prop = true;
nameoff = stringtable_insert(strbuf, prop->name);
@@ -310,6 +314,139 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
flatten_tree(child, emit, etarget, strbuf, vi);
}
if (!symbol_fixup_support)
goto no_symbols;
/* add the symbol nodes (if any) */
if (tree->symbols) {
emit->beginnode(etarget, NULL);
emit->string(etarget, "__symbols__", 0);
emit->align(etarget, sizeof(cell_t));
for_each_symbol(tree, sym) {
vallen = strlen(sym->node->fullpath);
nameoff = stringtable_insert(strbuf, sym->label->label);
emit->property(etarget, NULL);
emit->cell(etarget, vallen + 1);
emit->cell(etarget, nameoff);
if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
emit->align(etarget, 8);
emit->string(etarget, sym->node->fullpath,
strlen(sym->node->fullpath));
emit->align(etarget, sizeof(cell_t));
}
emit->endnode(etarget, NULL);
}
/* add the fixup nodes */
if (tree->fixups) {
/* emit the external fixups */
emit->beginnode(etarget, NULL);
emit->string(etarget, "__fixups__", 0);
emit->align(etarget, sizeof(cell_t));
for_each_fixup(tree, f) {
namesz = 0;
for_each_fixup_entry(f, fe) {
fullpath = fe->node->fullpath;
if (fullpath[0] == '\0')
fullpath = "/";
namesz += strlen(fullpath) + 1;
namesz += strlen(fe->prop->name) + 1;
namesz += 32; /* space for :<number> + '\0' */
}
name = xmalloc(namesz);
s = name;
for_each_fixup_entry(f, fe) {
fullpath = fe->node->fullpath;
if (fullpath[0] == '\0')
fullpath = "/";
snprintf(s, name + namesz - s, "%s:%s:%d",
fullpath,
fe->prop->name, fe->offset);
s += strlen(s) + 1;
}
nameoff = stringtable_insert(strbuf, f->ref);
vallen = s - name - 1;
emit->property(etarget, NULL);
emit->cell(etarget, vallen + 1);
emit->cell(etarget, nameoff);
if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
emit->align(etarget, 8);
emit->string(etarget, name, vallen);
emit->align(etarget, sizeof(cell_t));
free(name);
}
emit->endnode(etarget, tree->labels);
}
/* add the local fixup property */
if (tree->local_fixups) {
/* emit the external fixups */
emit->beginnode(etarget, NULL);
emit->string(etarget, "__local_fixups__", 0);
emit->align(etarget, sizeof(cell_t));
namesz = 0;
for_each_local_fixup_entry(tree, fe) {
fullpath = fe->node->fullpath;
if (fullpath[0] == '\0')
fullpath = "/";
namesz += strlen(fullpath) + 1;
namesz += strlen(fe->prop->name) + 1;
namesz += 32; /* space for :<number> + '\0' */
}
name = xmalloc(namesz);
s = name;
for_each_local_fixup_entry(tree, fe) {
fullpath = fe->node->fullpath;
if (fullpath[0] == '\0')
fullpath = "/";
snprintf(s, name + namesz - s, "%s:%s:%d",
fullpath, fe->prop->name,
fe->offset);
s += strlen(s) + 1;
}
nameoff = stringtable_insert(strbuf, "fixup");
vallen = s - name - 1;
emit->property(etarget, NULL);
emit->cell(etarget, vallen + 1);
emit->cell(etarget, nameoff);
if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
emit->align(etarget, 8);
emit->string(etarget, name, vallen);
emit->align(etarget, sizeof(cell_t));
free(name);
emit->endnode(etarget, tree->labels);
}
no_symbols:
emit->endnode(etarget, tree->labels);
}

View File

@@ -37,26 +37,26 @@ static struct node *read_fstree(const char *dirname)
tree = build_node(NULL, NULL);
while ((de = readdir(d)) != NULL) {
char *tmpnam;
char *tmpname;
if (streq(de->d_name, ".")
|| streq(de->d_name, ".."))
continue;
tmpnam = join_path(dirname, de->d_name);
tmpname = join_path(dirname, de->d_name);
if (lstat(tmpnam, &st) < 0)
die("stat(%s): %s\n", tmpnam, strerror(errno));
if (lstat(tmpname, &st) < 0)
die("stat(%s): %s\n", tmpname, strerror(errno));
if (S_ISREG(st.st_mode)) {
struct property *prop;
FILE *pfile;
pfile = fopen(tmpnam, "r");
pfile = fopen(tmpname, "rb");
if (! pfile) {
fprintf(stderr,
"WARNING: Cannot open %s: %s\n",
tmpnam, strerror(errno));
tmpname, strerror(errno));
} else {
prop = build_property(xstrdup(de->d_name),
data_copy_file(pfile,
@@ -67,12 +67,12 @@ static struct node *read_fstree(const char *dirname)
} else if (S_ISDIR(st.st_mode)) {
struct node *newchild;
newchild = read_fstree(tmpnam);
newchild = read_fstree(tmpname);
newchild = name_node(newchild, xstrdup(de->d_name));
add_child(tree, newchild);
}
free(tmpnam);
free(tmpname);
}
closedir(d);

View File

@@ -511,7 +511,9 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
struct node *get_node_by_ref(struct node *tree, const char *ref)
{
if (ref[0] == '/')
if (streq(ref, "/"))
return tree;
else if (ref[0] == '/')
return get_node_by_path(tree, ref);
else
return get_node_by_label(tree, ref);

View File

@@ -34,7 +34,7 @@ struct search_path {
static struct search_path *search_path_head, **search_path_tail;
static char *dirname(const char *path)
static char *get_dirname(const char *path)
{
const char *slash = strrchr(path, '/');
@@ -77,7 +77,7 @@ static char *try_open(const char *dirname, const char *fname, FILE **fp)
else
fullname = join_path(dirname, fname);
*fp = fopen(fullname, "r");
*fp = fopen(fullname, "rb");
if (!*fp) {
free(fullname);
fullname = NULL;
@@ -150,7 +150,7 @@ void srcfile_push(const char *fname)
srcfile = xmalloc(sizeof(*srcfile));
srcfile->f = srcfile_relative_open(fname, &srcfile->name);
srcfile->dir = dirname(srcfile->name);
srcfile->dir = get_dirname(srcfile->name);
srcfile->prev = current_srcfile;
srcfile->lineno = 1;
@@ -159,7 +159,7 @@ void srcfile_push(const char *fname)
current_srcfile = srcfile;
}
int srcfile_pop(void)
bool srcfile_pop(void)
{
struct srcfile_state *srcfile = current_srcfile;
@@ -177,7 +177,7 @@ int srcfile_pop(void)
* fix this we could either allocate all the files from a
* table, or use a pool allocator. */
return current_srcfile ? 1 : 0;
return current_srcfile ? true : false;
}
void srcfile_add_search_path(const char *dirname)
@@ -290,42 +290,27 @@ srcpos_string(struct srcpos *pos)
return pos_str;
}
void
srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
void srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va)
{
const char *srcstr;
char *srcstr;
srcstr = srcpos_string(pos);
fprintf(stderr, "Error: %s ", srcstr);
fprintf(stderr, "%s: %s ", prefix, srcstr);
vfprintf(stderr, fmt, va);
fprintf(stderr, "\n");
free(srcstr);
}
void
srcpos_error(struct srcpos *pos, char const *fmt, ...)
void srcpos_error(struct srcpos *pos, const char *prefix,
const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
srcpos_verror(pos, fmt, va);
va_end(va);
}
void
srcpos_warn(struct srcpos *pos, char const *fmt, ...)
{
const char *srcstr;
va_list va;
va_start(va, fmt);
srcstr = srcpos_string(pos);
fprintf(stderr, "Warning: %s ", srcstr);
vfprintf(stderr, fmt, va);
fprintf(stderr, "\n");
srcpos_verror(pos, prefix, fmt, va);
va_end(va);
}

View File

@@ -21,6 +21,7 @@
#define _SRCPOS_H_
#include <stdio.h>
#include <stdbool.h>
struct srcfile_state {
FILE *f;
@@ -55,7 +56,7 @@ extern struct srcfile_state *current_srcfile; /* = NULL */
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
void srcfile_push(const char *fname);
int srcfile_pop(void);
bool srcfile_pop(void);
/**
* Add a new directory to the search path for input files
@@ -106,12 +107,12 @@ extern struct srcpos *srcpos_copy(struct srcpos *pos);
extern char *srcpos_string(struct srcpos *pos);
extern void srcpos_dump(struct srcpos *pos);
extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
__attribute__((format(printf, 2, 0)));
extern void srcpos_error(struct srcpos *pos, char const *, ...)
__attribute__((format(printf, 2, 3)));
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
__attribute__((format(printf, 2, 3)));
extern void srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va)
__attribute__((format(printf, 3, 0)));
extern void srcpos_error(struct srcpos *pos, const char *prefix,
const char *fmt, ...)
__attribute__((format(printf, 3, 4)));
extern void srcpos_set_line(char *f, int l);

View File

@@ -26,12 +26,12 @@ extern int yyparse(void);
extern YYLTYPE yylloc;
struct boot_info *the_boot_info;
int treesource_error;
bool treesource_error;
struct boot_info *dt_from_source(const char *fname)
{
the_boot_info = NULL;
treesource_error = 0;
treesource_error = false;
srcfile_push(fname);
yyin = current_srcfile->f;
@@ -54,9 +54,9 @@ static void write_prefix(FILE *f, int level)
fputc('\t', f);
}
static int isstring(char c)
static bool isstring(char c)
{
return (isprint(c)
return (isprint((unsigned char)c)
|| (c == '\0')
|| strchr("\a\b\t\n\v\f\r", c));
}
@@ -109,7 +109,7 @@ static void write_propval_string(FILE *f, struct data val)
break;
case '\0':
fprintf(f, "\", ");
while (m && (m->offset < i)) {
while (m && (m->offset <= (i + 1))) {
if (m->type == LABEL) {
assert(m->offset == (i+1));
fprintf(f, "%s: ", m->ref);
@@ -119,7 +119,7 @@ static void write_propval_string(FILE *f, struct data val)
fprintf(f, "\"");
break;
default:
if (isprint(c))
if (isprint((unsigned char)c))
fprintf(f, "%c", c);
else
fprintf(f, "\\x%02hhx", c);
@@ -178,7 +178,7 @@ static void write_propval_bytes(FILE *f, struct data val)
m = m->next;
}
fprintf(f, "%02hhx", *bp++);
fprintf(f, "%02hhx", (unsigned char)(*bp++));
if ((const void *)bp >= propend)
break;
fprintf(f, " ");

View File

@@ -39,11 +39,11 @@
char *xstrdup(const char *s)
{
int len = strlen(s) + 1;
char *dup = xmalloc(len);
char *d = xmalloc(len);
memcpy(dup, s, len);
memcpy(d, s, len);
return dup;
return d;
}
char *join_path(const char *path, const char *name)
@@ -70,7 +70,7 @@ char *join_path(const char *path, const char *name)
return str;
}
int util_is_printable_string(const void *data, int len)
bool util_is_printable_string(const void *data, int len)
{
const char *s = data;
const char *ss, *se;
@@ -87,7 +87,7 @@ int util_is_printable_string(const void *data, int len)
while (s < se) {
ss = s;
while (s < se && *s && isprint(*s))
while (s < se && *s && isprint((unsigned char)*s))
s++;
/* not zero, or not done yet */
@@ -219,10 +219,6 @@ int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
if (offset == bufsize) {
bufsize *= 2;
buf = xrealloc(buf, bufsize);
if (!buf) {
ret = ENOMEM;
break;
}
}
ret = read(fd, &buf[offset], bufsize - offset);
@@ -375,9 +371,9 @@ void utilfdt_print_data(const char *data, int len)
const uint32_t *cell = (const uint32_t *)data;
printf(" = <");
for (i = 0; i < len; i += 4)
for (i = 0, len /= 4; i < len; i++)
printf("0x%08x%s", fdt32_to_cpu(cell[i]),
i < (len - 4) ? " " : "");
i < (len - 1) ? " " : "");
printf(">");
} else {
printf(" = [");

View File

@@ -2,6 +2,7 @@
#define _UTIL_H
#include <stdarg.h>
#include <stdbool.h>
#include <getopt.h>
/*
@@ -33,6 +34,7 @@ static inline void __attribute__((noreturn)) die(const char *str, ...)
va_start(ap, str);
fprintf(stderr, "FATAL ERROR: ");
vfprintf(stderr, str, ap);
va_end(ap);
exit(1);
}
@@ -68,7 +70,7 @@ extern char *join_path(const char *path, const char *name);
* @param len The string length including terminator
* @return 1 if a valid printable string, 0 if not
*/
int util_is_printable_string(const void *data, int len);
bool util_is_printable_string(const void *data, int len);
/*
* Parse an escaped character starting at index i in string s. The resulting

View File

@@ -1 +1 @@
#define DTC_VERSION "DTC 1.4.0-dirty"
#define DTC_VERSION "DTC 1.4.1-g36c70742"