scripts/dtc: Update to upstream version 9d3649bd3be245c9

Sync dtc with upstream as of commit 9d3649bd3be2 (Add testcases for
fdt_path_offset_namelen()).

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: devicetree@vger.kernel.org
This commit is contained in:
Rob Herring 2015-04-29 16:00:05 -05:00
parent f1ec718716
commit 4760597116
29 changed files with 1756 additions and 1546 deletions

View File

@ -53,7 +53,7 @@ struct check {
void *data; void *data;
bool warn, error; bool warn, error;
enum checkstatus status; enum checkstatus status;
int inprogress; bool inprogress;
int num_prereqs; int num_prereqs;
struct check **prereq; struct check **prereq;
}; };
@ -113,6 +113,7 @@ static inline void check_msg(struct check *c, const char *fmt, ...)
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
va_end(ap);
} }
#define FAIL(c, ...) \ #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); 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; int i;
assert(!c->inprogress); assert(!c->inprogress);
@ -151,11 +152,11 @@ static int run_check(struct check *c, struct node *dt)
if (c->status != UNCHECKED) if (c->status != UNCHECKED)
goto out; goto out;
c->inprogress = 1; c->inprogress = true;
for (i = 0; i < c->num_prereqs; i++) { for (i = 0; i < c->num_prereqs; i++) {
struct check *prq = c->prereq[i]; struct check *prq = c->prereq[i];
error |= run_check(prq, dt); error = error || run_check(prq, dt);
if (prq->status != PASSED) { if (prq->status != PASSED) {
c->status = PREREQ; c->status = PREREQ;
check_msg(c, "Failed prerequisite '%s'", 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); TRACE(c, "\tCompleted, status %d", c->status);
out: out:
c->inprogress = 0; c->inprogress = false;
if ((c->status != PASSED) && (c->error)) if ((c->status != PASSED) && (c->error))
error = 1; error = true;
return error; return error;
} }
@ -624,11 +625,11 @@ static void check_avoid_default_addr_size(struct check *c, struct node *dt,
if (!reg && !ranges) if (!reg && !ranges)
return; return;
if ((node->parent->addr_cells == -1)) if (node->parent->addr_cells == -1)
FAIL(c, "Relying on default #address-cells value for %s", FAIL(c, "Relying on default #address-cells value for %s",
node->fullpath); node->fullpath);
if ((node->parent->size_cells == -1)) if (node->parent->size_cells == -1)
FAIL(c, "Relying on default #size-cells value for %s", FAIL(c, "Relying on default #size-cells value for %s",
node->fullpath); node->fullpath);
} }
@ -706,15 +707,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
c->error = c->error && !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; int i;
const char *name = optarg; const char *name = arg;
bool enable = true; bool enable = true;
if ((strncmp(optarg, "no-", 3) == 0) if ((strncmp(arg, "no-", 3) == 0)
|| (strncmp(optarg, "no_", 3) == 0)) { || (strncmp(arg, "no_", 3) == 0)) {
name = optarg + 3; name = arg + 3;
enable = false; enable = false;
} }
@ -733,7 +734,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
die("Unrecognized check name \"%s\"\n", name); 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; struct node *dt = bi->dt;
int i; int i;

View File

@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len)
struct data d; struct data d;
char *q; char *q;
d = data_grow_for(empty_data, strlen(s)+1); d = data_grow_for(empty_data, len + 1);
q = d.val; q = d.val;
while (i < len) { 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); 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 i;
int len = d.len; int len = d.len;
if (len == 0) if (len == 0)
return 0; return false;
for (i = 0; i < len-1; i++) for (i = 0; i < len-1; i++)
if (d.val[i] == '\0') if (d.val[i] == '\0')
return 0; return false;
if (d.val[len-1] != '\0') 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 %option noyywrap nounput noinput never-interactive
%x INCLUDE
%x BYTESTRING %x BYTESTRING
%x PROPNODENAME %x PROPNODENAME
%s V1 %s V1
@ -40,6 +39,7 @@ LINECOMMENT "//".*\n
#include "dtc-parser.tab.h" #include "dtc-parser.tab.h"
YYLTYPE yylloc; YYLTYPE yylloc;
extern bool treesource_error;
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */ /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
#define YY_USER_ACTION \ #define YY_USER_ACTION \
@ -61,7 +61,8 @@ static int dts_version = 1;
BEGIN(V1); \ BEGIN(V1); \
static void push_input_file(const char *filename); 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; char *line, *tmp, *fn;
/* skip text before line # */ /* skip text before line # */
line = yytext; line = yytext;
while (!isdigit(*line)) while (!isdigit((unsigned char)*line))
line++; line++;
/* skip digits in line # */ /* skip digits in line # */
tmp = line; tmp = line;
while (!isspace(*tmp)) while (!isspace((unsigned char)*tmp))
tmp++; tmp++;
/* "NULL"-terminate line # */ /* "NULL"-terminate line # */
*tmp = '\0'; *tmp = '\0';
@ -146,15 +147,42 @@ static int pop_input_file(void);
} }
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
yylval.literal = xstrdup(yytext); char *e;
DPRINT("Literal: '%s'\n", yylval.literal); 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; return DT_LITERAL;
} }
<*>{CHAR_LITERAL} { <*>{CHAR_LITERAL} {
yytext[yyleng-1] = '\0'; struct data d;
yylval.literal = xstrdup(yytext+1); DPRINT("Character literal: %s\n", yytext);
DPRINT("Character literal: %s\n", yylval.literal);
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; return DT_CHAR_LITERAL;
} }
@ -164,7 +192,7 @@ static int pop_input_file(void);
return DT_REF; return DT_REF;
} }
<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */ <*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
yytext[yyleng-1] = '\0'; yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2); DPRINT("Ref: %s\n", yytext+2);
yylval.labelref = xstrdup(yytext+2); yylval.labelref = xstrdup(yytext+2);
@ -238,13 +266,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) if (srcfile_pop() == 0)
return 0; return false;
yypop_buffer_state(); yypop_buffer_state();
yyin = current_srcfile->f; 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

@ -9,7 +9,7 @@
#define FLEX_SCANNER #define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5 #define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35 #define YY_FLEX_SUBMINOR_VERSION 39
#if YY_FLEX_SUBMINOR_VERSION > 0 #if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA #define FLEX_BETA
#endif #endif
@ -162,7 +162,12 @@ typedef unsigned int flex_uint32_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif #endif
extern int yyleng; #ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
extern yy_size_t yyleng;
extern FILE *yyin, *yyout; extern FILE *yyin, *yyout;
@ -171,6 +176,7 @@ extern FILE *yyin, *yyout;
#define EOB_ACT_LAST_MATCH 2 #define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n) #define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */ /* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \ #define yyless(n) \
@ -188,11 +194,6 @@ extern FILE *yyin, *yyout;
#define unput(c) yyunput( c, (yytext_ptr) ) #define unput(c) yyunput( c, (yytext_ptr) )
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#ifndef YY_STRUCT_YY_BUFFER_STATE #ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state struct yy_buffer_state
@ -210,7 +211,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB /* Number of characters read into yy_ch_buf, not including EOB
* characters. * characters.
*/ */
int yy_n_chars; yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it, /* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to * and can realloc() it to grow it, and should free() it to
@ -280,8 +281,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
/* yy_hold_char holds the character lost when yytext is formed. */ /* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char; static char yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */ static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
int yyleng; yy_size_t yyleng;
/* Points to current character in buffer. */ /* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0; static char *yy_c_buf_p = (char *) 0;
@ -309,7 +310,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len );
void *yyalloc (yy_size_t ); void *yyalloc (yy_size_t );
void *yyrealloc (void *,yy_size_t ); void *yyrealloc (void *,yy_size_t );
@ -341,7 +342,7 @@ void yyfree (void * );
/* Begin user sect3 */ /* Begin user sect3 */
#define yywrap(n) 1 #define yywrap() 1
#define YY_SKIP_YYWRAP #define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR; typedef unsigned char YY_CHAR;
@ -381,25 +382,25 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; flex_int32_t yy_nxt;
}; };
static yyconst flex_int16_t yy_accept[161] = static yyconst flex_int16_t yy_accept[159] =
{ 0, { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 29,
31, 29, 18, 18, 29, 29, 29, 29, 29, 29, 18, 18, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 15, 16, 29, 29, 29, 29, 29, 29, 15, 16, 16, 29,
16, 29, 16, 10, 10, 18, 26, 0, 3, 0, 16, 10, 10, 18, 26, 0, 3, 0, 27, 12,
27, 12, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0,
0, 0, 21, 23, 25, 24, 22, 0, 9, 28, 21, 23, 25, 24, 22, 0, 9, 28, 0, 0,
0, 0, 0, 14, 14, 16, 16, 16, 10, 10, 0, 14, 14, 16, 16, 16, 10, 10, 10, 0,
10, 0, 12, 0, 11, 0, 0, 0, 20, 0, 12, 0, 11, 0, 0, 0, 20, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 16, 10, 10, 0, 0, 0, 0, 0, 16, 10, 10, 10, 0,
10, 0, 19, 0, 0, 0, 0, 0, 0, 0, 13, 19, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 16, 13, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 16, 6, 0, 0, 0, 0, 0, 0, 16, 6, 0, 0, 0, 0, 0, 0, 2,
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 17,
4, 17, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 5, 8, 0, 0, 0, 0, 7, 0 5, 8, 0, 0, 0, 0, 7, 0
} ; } ;
static yyconst flex_int32_t yy_ec[256] = static yyconst flex_int32_t yy_ec[256] =
@ -440,157 +441,157 @@ static yyconst flex_int32_t yy_meta[47] =
2, 2, 4, 5, 5, 5, 6, 1, 1, 1, 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, 1, 1, 7, 7, 7,
7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 3, 1, 1 8, 8, 8, 3, 1, 4
} ; } ;
static yyconst flex_int16_t yy_base[175] = static yyconst flex_int16_t yy_base[173] =
{ 0, { 0,
0, 385, 378, 40, 41, 383, 72, 382, 34, 44, 0, 383, 34, 382, 65, 381, 37, 105, 387, 391,
388, 393, 61, 117, 368, 116, 115, 115, 115, 48, 54, 111, 367, 110, 109, 109, 112, 41, 366, 104,
367, 107, 368, 339, 127, 120, 0, 147, 393, 0, 367, 338, 124, 117, 0, 144, 391, 0, 121, 0,
127, 0, 133, 156, 168, 153, 393, 125, 393, 380, 135, 155, 140, 179, 391, 160, 391, 379, 391, 0,
393, 0, 369, 127, 393, 160, 371, 377, 347, 21, 368, 141, 391, 167, 370, 376, 346, 103, 342, 345,
343, 346, 393, 393, 393, 393, 393, 359, 393, 393, 391, 391, 391, 391, 391, 358, 391, 391, 175, 342,
183, 343, 339, 393, 356, 0, 183, 340, 187, 348, 338, 391, 355, 0, 185, 339, 184, 347, 346, 0,
347, 0, 0, 0, 178, 359, 195, 365, 354, 326, 0, 322, 175, 357, 175, 363, 352, 324, 330, 323,
332, 325, 334, 328, 204, 326, 331, 324, 393, 335, 332, 326, 201, 324, 329, 322, 391, 333, 181, 309,
150, 311, 343, 342, 315, 322, 340, 179, 313, 207, 391, 341, 340, 313, 320, 338, 178, 311, 146, 317,
319, 316, 317, 393, 337, 333, 305, 302, 311, 301, 314, 315, 335, 331, 303, 300, 309, 299, 308, 188,
310, 190, 338, 337, 393, 307, 322, 301, 305, 277, 336, 335, 391, 305, 320, 281, 283, 271, 203, 288,
208, 311, 307, 278, 271, 270, 248, 246, 213, 130, 281, 271, 266, 264, 245, 242, 208, 104, 391, 391,
393, 393, 263, 235, 207, 221, 218, 229, 213, 213, 244, 218, 204, 219, 206, 224, 201, 212, 204, 229,
206, 234, 218, 210, 208, 193, 219, 393, 223, 204, 215, 208, 207, 200, 219, 391, 233, 221, 200, 181,
176, 157, 393, 393, 120, 106, 97, 119, 393, 393, 391, 391, 149, 122, 86, 41, 391, 391, 245, 251,
245, 251, 259, 263, 267, 273, 280, 284, 292, 300, 259, 263, 267, 273, 280, 284, 292, 300, 304, 310,
304, 310, 318, 326 318, 326
} ; } ;
static yyconst flex_int16_t yy_def[175] = static yyconst flex_int16_t yy_def[173] =
{ 0, { 0,
160, 1, 1, 1, 1, 5, 160, 7, 1, 1, 158, 1, 1, 3, 158, 5, 1, 1, 158, 158,
160, 160, 160, 160, 160, 161, 162, 163, 160, 160, 158, 158, 158, 159, 160, 161, 158, 158, 158, 158,
160, 160, 164, 160, 160, 160, 165, 164, 160, 166, 162, 158, 158, 158, 163, 162, 158, 164, 165, 164,
167, 166, 166, 160, 160, 160, 160, 161, 160, 161, 164, 158, 158, 158, 158, 159, 158, 159, 158, 166,
160, 168, 160, 163, 160, 163, 169, 170, 160, 160, 158, 161, 158, 161, 167, 168, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 164, 160, 160, 158, 158, 158, 158, 158, 162, 158, 158, 158, 158,
160, 160, 160, 160, 164, 166, 167, 166, 160, 160, 158, 158, 162, 164, 165, 164, 158, 158, 158, 169,
160, 171, 168, 172, 163, 169, 169, 170, 160, 160, 166, 170, 161, 167, 167, 168, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 166, 160, 160, 158, 158, 158, 158, 158, 164, 158, 158, 169, 170,
171, 172, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 166, 160, 160, 160, 160, 160, 160, 160, 158, 164, 158, 158, 158, 158, 158, 158, 158, 171,
160, 173, 160, 166, 160, 160, 160, 160, 160, 160, 158, 164, 158, 158, 158, 158, 158, 158, 171, 158,
173, 160, 173, 160, 160, 160, 160, 160, 160, 160, 171, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 174, 160, 160, 160, 174, 160, 174, 160, 172, 158, 158, 158, 172, 158, 172, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 0, 158, 158, 158, 158, 158, 158, 158, 0, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160 158, 158
} ; } ;
static yyconst flex_int16_t yy_nxt[440] = static yyconst flex_int16_t yy_nxt[438] =
{ 0, { 0,
12, 13, 14, 13, 15, 16, 12, 17, 18, 12, 10, 11, 12, 11, 13, 14, 10, 15, 16, 10,
12, 12, 19, 12, 12, 12, 12, 20, 21, 22, 10, 10, 17, 10, 10, 10, 10, 18, 19, 20,
23, 23, 23, 23, 23, 12, 12, 23, 23, 23, 21, 21, 21, 21, 21, 10, 10, 21, 21, 21,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
23, 23, 23, 12, 24, 12, 25, 34, 35, 35, 21, 21, 21, 10, 22, 10, 24, 25, 25, 25,
25, 81, 26, 26, 27, 27, 27, 34, 35, 35, 32, 33, 33, 157, 26, 34, 34, 34, 51, 52,
82, 28, 36, 36, 36, 53, 54, 29, 28, 28, 27, 26, 26, 26, 26, 10, 11, 12, 11, 13,
28, 28, 12, 13, 14, 13, 15, 16, 30, 17, 14, 28, 15, 16, 28, 28, 28, 24, 28, 28,
18, 30, 30, 30, 26, 30, 30, 30, 12, 20, 28, 10, 18, 19, 20, 29, 29, 29, 29, 29,
21, 22, 31, 31, 31, 31, 31, 32, 12, 31, 30, 10, 29, 29, 29, 29, 29, 29, 29, 29,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 29, 29, 29, 29, 29, 29, 29, 29, 10, 22,
31, 31, 31, 31, 31, 12, 24, 12, 36, 36, 10, 23, 34, 34, 34, 37, 39, 43, 32, 33,
36, 39, 41, 45, 47, 56, 57, 48, 61, 47, 33, 45, 54, 55, 46, 59, 45, 64, 156, 46,
39, 159, 48, 66, 61, 45, 66, 66, 66, 158, 64, 64, 64, 79, 44, 38, 59, 57, 134, 47,
46, 40, 49, 59, 50, 157, 51, 49, 52, 50, 135, 48, 80, 49, 47, 50, 48, 99, 61, 43,
40, 63, 46, 52, 36, 36, 36, 156, 43, 62, 50, 110, 41, 67, 67, 67, 60, 63, 63, 63,
65, 65, 65, 59, 136, 68, 137, 65, 75, 69, 57, 155, 68, 69, 63, 37, 44, 66, 67, 67,
69, 69, 70, 71, 65, 65, 65, 65, 70, 71, 67, 63, 63, 63, 63, 73, 59, 68, 69, 70,
72, 69, 69, 69, 61, 46, 45, 155, 154, 66, 34, 34, 34, 43, 75, 38, 154, 92, 83, 83,
70, 71, 66, 66, 66, 122, 85, 85, 85, 59, 83, 64, 44, 120, 64, 64, 64, 67, 67, 67,
69, 69, 69, 46, 77, 100, 109, 93, 100, 70, 44, 57, 99, 68, 69, 107, 68, 69, 120, 127,
71, 110, 112, 122, 129, 123, 153, 85, 85, 85, 108, 153, 152, 121, 83, 83, 83, 133, 133, 133,
135, 135, 135, 148, 148, 160, 135, 135, 135, 152, 146, 133, 133, 133, 146, 140, 140, 140, 121, 141,
142, 142, 142, 123, 143, 142, 142, 142, 151, 143, 140, 140, 140, 151, 141, 158, 150, 149, 148, 144,
150, 146, 145, 149, 149, 38, 38, 38, 38, 38, 147, 143, 142, 139, 147, 36, 36, 36, 36, 36,
38, 38, 38, 42, 144, 141, 140, 42, 42, 44, 36, 36, 36, 40, 138, 137, 136, 40, 40, 42,
44, 44, 44, 44, 44, 44, 44, 58, 58, 58, 42, 42, 42, 42, 42, 42, 42, 56, 56, 56,
58, 64, 139, 64, 66, 138, 134, 66, 133, 66, 56, 62, 132, 62, 64, 131, 130, 64, 129, 64,
66, 67, 132, 131, 67, 67, 67, 67, 73, 130, 64, 65, 128, 158, 65, 65, 65, 65, 71, 127,
73, 73, 76, 76, 76, 76, 76, 76, 76, 76, 71, 71, 74, 74, 74, 74, 74, 74, 74, 74,
78, 78, 78, 78, 78, 78, 78, 78, 91, 160, 76, 76, 76, 76, 76, 76, 76, 76, 89, 126,
91, 92, 129, 92, 92, 128, 92, 92, 121, 121, 89, 90, 125, 90, 90, 124, 90, 90, 119, 119,
121, 121, 121, 121, 121, 121, 147, 147, 147, 147, 119, 119, 119, 119, 119, 119, 145, 145, 145, 145,
147, 147, 147, 147, 127, 126, 125, 124, 61, 61, 145, 145, 145, 145, 123, 122, 59, 59, 118, 117,
120, 119, 118, 117, 116, 115, 47, 114, 110, 113, 116, 115, 114, 113, 45, 112, 108, 111, 109, 106,
111, 108, 107, 106, 48, 105, 104, 89, 103, 102, 105, 104, 46, 103, 91, 87, 102, 101, 100, 98,
101, 99, 98, 97, 96, 95, 94, 79, 77, 90, 97, 96, 95, 94, 93, 77, 75, 91, 88, 87,
89, 88, 59, 87, 86, 59, 84, 83, 80, 79, 86, 57, 85, 84, 57, 82, 81, 78, 77, 75,
77, 74, 160, 60, 59, 55, 37, 160, 33, 25, 72, 158, 58, 57, 53, 35, 158, 31, 23, 23,
26, 25, 11, 160, 160, 160, 160, 160, 160, 160, 9, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160 158, 158, 158, 158, 158, 158, 158
} ; } ;
static yyconst flex_int16_t yy_chk[440] = static yyconst flex_int16_t yy_chk[438] =
{ 0, { 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, 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, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3,
10, 50, 4, 5, 5, 5, 5, 10, 10, 10, 7, 7, 7, 156, 3, 11, 11, 11, 18, 18,
50, 5, 13, 13, 13, 20, 20, 5, 5, 5, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5,
5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
7, 7, 7, 7, 7, 7, 7, 7, 14, 14, 5, 8, 12, 12, 12, 14, 15, 16, 8, 8,
14, 16, 17, 18, 19, 22, 22, 19, 25, 26, 8, 17, 20, 20, 17, 23, 24, 29, 155, 24,
38, 158, 26, 31, 33, 44, 31, 31, 31, 157, 29, 29, 29, 48, 16, 14, 31, 29, 128, 17,
18, 16, 19, 31, 19, 156, 19, 26, 19, 26, 128, 17, 48, 17, 24, 17, 24, 99, 24, 42,
38, 26, 44, 26, 36, 36, 36, 155, 17, 25, 24, 99, 15, 33, 33, 33, 23, 26, 26, 26,
28, 28, 28, 28, 130, 33, 130, 28, 46, 34, 26, 154, 33, 33, 26, 36, 42, 31, 32, 32,
34, 34, 91, 91, 28, 28, 28, 28, 34, 34, 32, 26, 26, 26, 26, 44, 59, 32, 32, 32,
34, 35, 35, 35, 61, 46, 75, 152, 151, 67, 34, 34, 34, 73, 75, 36, 153, 75, 59, 59,
35, 35, 67, 67, 67, 112, 61, 61, 61, 67, 59, 65, 44, 110, 65, 65, 65, 67, 67, 67,
69, 69, 69, 75, 77, 85, 98, 77, 100, 69, 73, 65, 83, 89, 89, 97, 67, 67, 119, 127,
69, 98, 100, 121, 129, 112, 150, 85, 85, 85, 97, 150, 149, 110, 83, 83, 83, 133, 133, 133,
135, 135, 135, 143, 147, 149, 129, 129, 129, 146, 141, 127, 127, 127, 145, 136, 136, 136, 119, 136,
138, 138, 138, 121, 138, 142, 142, 142, 145, 142, 140, 140, 140, 148, 140, 147, 144, 143, 142, 139,
144, 141, 140, 143, 147, 161, 161, 161, 161, 161, 141, 138, 137, 135, 145, 159, 159, 159, 159, 159,
161, 161, 161, 162, 139, 137, 136, 162, 162, 163, 159, 159, 159, 160, 134, 132, 131, 160, 160, 161,
163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 161, 161, 161, 161, 161, 161, 161, 162, 162, 162,
164, 165, 134, 165, 166, 133, 128, 166, 127, 166, 162, 163, 126, 163, 164, 125, 124, 164, 123, 164,
166, 167, 126, 125, 167, 167, 167, 167, 168, 124, 164, 165, 122, 121, 165, 165, 165, 165, 166, 120,
168, 168, 169, 169, 169, 169, 169, 169, 169, 169, 166, 166, 167, 167, 167, 167, 167, 167, 167, 167,
170, 170, 170, 170, 170, 170, 170, 170, 171, 123, 168, 168, 168, 168, 168, 168, 168, 168, 169, 118,
171, 172, 122, 172, 172, 120, 172, 172, 173, 173, 169, 170, 117, 170, 170, 116, 170, 170, 171, 171,
173, 173, 173, 173, 173, 173, 174, 174, 174, 174, 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
174, 174, 174, 174, 119, 118, 117, 116, 114, 113, 172, 172, 172, 172, 115, 114, 112, 111, 109, 108,
111, 110, 109, 108, 107, 106, 105, 103, 102, 101, 107, 106, 105, 104, 103, 102, 101, 100, 98, 96,
99, 97, 96, 95, 94, 93, 92, 90, 88, 87, 95, 94, 93, 92, 90, 88, 86, 85, 84, 82,
86, 84, 83, 82, 81, 80, 79, 78, 76, 71, 81, 80, 79, 78, 77, 76, 74, 72, 69, 68,
70, 68, 65, 63, 62, 58, 52, 51, 49, 48, 66, 63, 61, 60, 56, 50, 49, 47, 46, 45,
47, 43, 40, 24, 23, 21, 15, 11, 8, 6, 41, 38, 22, 21, 19, 13, 9, 6, 4, 2,
3, 2, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158,
160, 160, 160, 160, 160, 160, 160, 160, 160 158, 158, 158, 158, 158, 158, 158
} ; } ;
static yy_state_type yy_last_accepting_state; static yy_state_type yy_last_accepting_state;
@ -631,13 +632,13 @@ char *yytext;
#line 37 "dtc-lexer.l"
#line 38 "dtc-lexer.l"
#include "dtc.h" #include "dtc.h"
#include "srcpos.h" #include "srcpos.h"
#include "dtc-parser.tab.h" #include "dtc-parser.tab.h"
YYLTYPE yylloc; YYLTYPE yylloc;
extern bool treesource_error;
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */ /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
#define YY_USER_ACTION \ #define YY_USER_ACTION \
@ -659,14 +660,14 @@ static int dts_version = 1;
BEGIN(V1); \ BEGIN(V1); \
static void push_input_file(const char *filename); static void push_input_file(const char *filename);
static int pop_input_file(void); static bool pop_input_file(void);
#line 664 "dtc-lexer.lex.c" static void lexical_error(const char *fmt, ...);
#line 666 "dtc-lexer.lex.c"
#define INITIAL 0 #define INITIAL 0
#define INCLUDE 1 #define BYTESTRING 1
#define BYTESTRING 2 #define PROPNODENAME 2
#define PROPNODENAME 3 #define V1 3
#define V1 4
#ifndef YY_NO_UNISTD_H #ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way /* Special case for "unistd.h", since it is non-ANSI. We include it way
@ -703,7 +704,7 @@ FILE *yyget_out (void );
void yyset_out (FILE * out_str ); void yyset_out (FILE * out_str );
int yyget_leng (void ); yy_size_t yyget_leng (void );
char *yyget_text (void ); char *yyget_text (void );
@ -852,10 +853,6 @@ YY_DECL
register char *yy_cp, *yy_bp; register char *yy_cp, *yy_bp;
register int yy_act; register int yy_act;
#line 67 "dtc-lexer.l"
#line 858 "dtc-lexer.lex.c"
if ( !(yy_init) ) if ( !(yy_init) )
{ {
(yy_init) = 1; (yy_init) = 1;
@ -882,6 +879,11 @@ YY_DECL
yy_load_buffer_state( ); yy_load_buffer_state( );
} }
{
#line 68 "dtc-lexer.l"
#line 886 "dtc-lexer.lex.c"
while ( 1 ) /* loops until end-of-file is reached */ while ( 1 ) /* loops until end-of-file is reached */
{ {
yy_cp = (yy_c_buf_p); yy_cp = (yy_c_buf_p);
@ -899,7 +901,7 @@ YY_DECL
yy_match: yy_match:
do do
{ {
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
if ( yy_accept[yy_current_state] ) if ( yy_accept[yy_current_state] )
{ {
(yy_last_accepting_state) = yy_current_state; (yy_last_accepting_state) = yy_current_state;
@ -908,13 +910,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 ) if ( yy_current_state >= 159 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_current_state != 160 ); while ( yy_current_state != 158 );
yy_cp = (yy_last_accepting_cpos); yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state); yy_current_state = (yy_last_accepting_state);
@ -937,7 +939,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
/* rule 1 can match eol */ /* rule 1 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 68 "dtc-lexer.l" #line 69 "dtc-lexer.l"
{ {
char *name = strchr(yytext, '\"') + 1; char *name = strchr(yytext, '\"') + 1;
yytext[yyleng-1] = '\0'; yytext[yyleng-1] = '\0';
@ -947,16 +949,16 @@ YY_RULE_SETUP
case 2: case 2:
/* rule 2 can match eol */ /* rule 2 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 74 "dtc-lexer.l" #line 75 "dtc-lexer.l"
{ {
char *line, *tmp, *fn; char *line, *tmp, *fn;
/* skip text before line # */ /* skip text before line # */
line = yytext; line = yytext;
while (!isdigit(*line)) while (!isdigit((unsigned char)*line))
line++; line++;
/* skip digits in line # */ /* skip digits in line # */
tmp = line; tmp = line;
while (!isspace(*tmp)) while (!isspace((unsigned char)*tmp))
tmp++; tmp++;
/* "NULL"-terminate line # */ /* "NULL"-terminate line # */
*tmp = '\0'; *tmp = '\0';
@ -970,11 +972,10 @@ YY_RULE_SETUP
} }
YY_BREAK YY_BREAK
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(INCLUDE):
case YY_STATE_EOF(BYTESTRING): case YY_STATE_EOF(BYTESTRING):
case YY_STATE_EOF(PROPNODENAME): case YY_STATE_EOF(PROPNODENAME):
case YY_STATE_EOF(V1): case YY_STATE_EOF(V1):
#line 95 "dtc-lexer.l" #line 96 "dtc-lexer.l"
{ {
if (!pop_input_file()) { if (!pop_input_file()) {
yyterminate(); yyterminate();
@ -984,7 +985,7 @@ case YY_STATE_EOF(V1):
case 3: case 3:
/* rule 3 can match eol */ /* rule 3 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 101 "dtc-lexer.l" #line 102 "dtc-lexer.l"
{ {
DPRINT("String: %s\n", yytext); DPRINT("String: %s\n", yytext);
yylval.data = data_copy_escape_string(yytext+1, yylval.data = data_copy_escape_string(yytext+1,
@ -994,7 +995,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 108 "dtc-lexer.l" #line 109 "dtc-lexer.l"
{ {
DPRINT("Keyword: /dts-v1/\n"); DPRINT("Keyword: /dts-v1/\n");
dts_version = 1; dts_version = 1;
@ -1004,7 +1005,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 115 "dtc-lexer.l" #line 116 "dtc-lexer.l"
{ {
DPRINT("Keyword: /memreserve/\n"); DPRINT("Keyword: /memreserve/\n");
BEGIN_DEFAULT(); BEGIN_DEFAULT();
@ -1013,7 +1014,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 121 "dtc-lexer.l" #line 122 "dtc-lexer.l"
{ {
DPRINT("Keyword: /bits/\n"); DPRINT("Keyword: /bits/\n");
BEGIN_DEFAULT(); BEGIN_DEFAULT();
@ -1022,7 +1023,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 127 "dtc-lexer.l" #line 128 "dtc-lexer.l"
{ {
DPRINT("Keyword: /delete-property/\n"); DPRINT("Keyword: /delete-property/\n");
DPRINT("<PROPNODENAME>\n"); DPRINT("<PROPNODENAME>\n");
@ -1032,7 +1033,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 134 "dtc-lexer.l" #line 135 "dtc-lexer.l"
{ {
DPRINT("Keyword: /delete-node/\n"); DPRINT("Keyword: /delete-node/\n");
DPRINT("<PROPNODENAME>\n"); DPRINT("<PROPNODENAME>\n");
@ -1042,7 +1043,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 141 "dtc-lexer.l" #line 142 "dtc-lexer.l"
{ {
DPRINT("Label: %s\n", yytext); DPRINT("Label: %s\n", yytext);
yylval.labelref = xstrdup(yytext); yylval.labelref = xstrdup(yytext);
@ -1052,27 +1053,54 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 148 "dtc-lexer.l" #line 149 "dtc-lexer.l"
{ {
yylval.literal = xstrdup(yytext); char *e;
DPRINT("Literal: '%s'\n", yylval.literal); 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; return DT_LITERAL;
} }
YY_BREAK YY_BREAK
case 11: case 11:
/* rule 11 can match eol */ /* rule 11 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 154 "dtc-lexer.l" #line 168 "dtc-lexer.l"
{ {
yytext[yyleng-1] = '\0'; struct data d;
yylval.literal = xstrdup(yytext+1); DPRINT("Character literal: %s\n", yytext);
DPRINT("Character literal: %s\n", yylval.literal);
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; return DT_CHAR_LITERAL;
} }
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 161 "dtc-lexer.l" #line 189 "dtc-lexer.l"
{ /* label reference */ { /* label reference */
DPRINT("Ref: %s\n", yytext+1); DPRINT("Ref: %s\n", yytext+1);
yylval.labelref = xstrdup(yytext+1); yylval.labelref = xstrdup(yytext+1);
@ -1081,7 +1109,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 167 "dtc-lexer.l" #line 195 "dtc-lexer.l"
{ /* new-style path reference */ { /* new-style path reference */
yytext[yyleng-1] = '\0'; yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2); DPRINT("Ref: %s\n", yytext+2);
@ -1091,7 +1119,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 174 "dtc-lexer.l" #line 202 "dtc-lexer.l"
{ {
yylval.byte = strtol(yytext, NULL, 16); yylval.byte = strtol(yytext, NULL, 16);
DPRINT("Byte: %02x\n", (int)yylval.byte); DPRINT("Byte: %02x\n", (int)yylval.byte);
@ -1100,7 +1128,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 180 "dtc-lexer.l" #line 208 "dtc-lexer.l"
{ {
DPRINT("/BYTESTRING\n"); DPRINT("/BYTESTRING\n");
BEGIN_DEFAULT(); BEGIN_DEFAULT();
@ -1109,7 +1137,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 186 "dtc-lexer.l" #line 214 "dtc-lexer.l"
{ {
DPRINT("PropNodeName: %s\n", yytext); DPRINT("PropNodeName: %s\n", yytext);
yylval.propnodename = xstrdup((yytext[0] == '\\') ? yylval.propnodename = xstrdup((yytext[0] == '\\') ?
@ -1120,7 +1148,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 194 "dtc-lexer.l" #line 222 "dtc-lexer.l"
{ {
DPRINT("Binary Include\n"); DPRINT("Binary Include\n");
return DT_INCBIN; return DT_INCBIN;
@ -1129,64 +1157,64 @@ YY_RULE_SETUP
case 18: case 18:
/* rule 18 can match eol */ /* rule 18 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 199 "dtc-lexer.l" #line 227 "dtc-lexer.l"
/* eat whitespace */ /* eat whitespace */
YY_BREAK YY_BREAK
case 19: case 19:
/* rule 19 can match eol */ /* rule 19 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 200 "dtc-lexer.l" #line 228 "dtc-lexer.l"
/* eat C-style comments */ /* eat C-style comments */
YY_BREAK YY_BREAK
case 20: case 20:
/* rule 20 can match eol */ /* rule 20 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 201 "dtc-lexer.l" #line 229 "dtc-lexer.l"
/* eat C++-style comments */ /* eat C++-style comments */
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 203 "dtc-lexer.l" #line 231 "dtc-lexer.l"
{ return DT_LSHIFT; }; { return DT_LSHIFT; };
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 204 "dtc-lexer.l" #line 232 "dtc-lexer.l"
{ return DT_RSHIFT; }; { return DT_RSHIFT; };
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 205 "dtc-lexer.l" #line 233 "dtc-lexer.l"
{ return DT_LE; }; { return DT_LE; };
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 206 "dtc-lexer.l" #line 234 "dtc-lexer.l"
{ return DT_GE; }; { return DT_GE; };
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 207 "dtc-lexer.l" #line 235 "dtc-lexer.l"
{ return DT_EQ; }; { return DT_EQ; };
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 208 "dtc-lexer.l" #line 236 "dtc-lexer.l"
{ return DT_NE; }; { return DT_NE; };
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 209 "dtc-lexer.l" #line 237 "dtc-lexer.l"
{ return DT_AND; }; { return DT_AND; };
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
#line 210 "dtc-lexer.l" #line 238 "dtc-lexer.l"
{ return DT_OR; }; { return DT_OR; };
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
#line 212 "dtc-lexer.l" #line 240 "dtc-lexer.l"
{ {
DPRINT("Char: %c (\\x%02x)\n", yytext[0], DPRINT("Char: %c (\\x%02x)\n", yytext[0],
(unsigned)yytext[0]); (unsigned)yytext[0]);
@ -1204,10 +1232,10 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
#line 227 "dtc-lexer.l" #line 255 "dtc-lexer.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 1211 "dtc-lexer.lex.c" #line 1239 "dtc-lexer.lex.c"
case YY_END_OF_BUFFER: case YY_END_OF_BUFFER:
{ {
@ -1337,6 +1365,7 @@ ECHO;
"fatal flex scanner internal error--no action found" ); "fatal flex scanner internal error--no action found" );
} /* end of action switch */ } /* end of action switch */
} /* end of scanning one token */ } /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */ } /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer /* yy_get_next_buffer - try to read in a new buffer
@ -1392,21 +1421,21 @@ static int yy_get_next_buffer (void)
else else
{ {
int num_to_read = yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 ) while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */ { /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */ /* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER; YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset = int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf); (int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer ) if ( b->yy_is_our_buffer )
{ {
int new_size = b->yy_buf_size * 2; yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 ) if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8; b->yy_buf_size += b->yy_buf_size / 8;
@ -1437,7 +1466,7 @@ static int yy_get_next_buffer (void)
/* Read in more data. */ /* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
(yy_n_chars), (size_t) num_to_read ); (yy_n_chars), num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
} }
@ -1499,7 +1528,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 ) if ( yy_current_state >= 159 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1527,11 +1556,11 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 161 ) if ( yy_current_state >= 159 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (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 == 158);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
@ -1560,7 +1589,7 @@ static int yy_get_next_buffer (void)
else else
{ /* need more input */ { /* need more input */
int offset = (yy_c_buf_p) - (yytext_ptr); yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p); ++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) ) switch ( yy_get_next_buffer( ) )
@ -1834,7 +1863,7 @@ void yypop_buffer_state (void)
*/ */
static void yyensure_buffer_stack (void) static void yyensure_buffer_stack (void)
{ {
int num_to_alloc; yy_size_t num_to_alloc;
if (!(yy_buffer_stack)) { if (!(yy_buffer_stack)) {
@ -1931,12 +1960,12 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
* *
* @return the newly allocated buffer state object. * @return the newly allocated buffer state object.
*/ */
YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
{ {
YY_BUFFER_STATE b; YY_BUFFER_STATE b;
char *buf; char *buf;
yy_size_t n; yy_size_t n;
int i; yy_size_t i;
/* Get memory for full buffer, including space for trailing EOB's. */ /* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2; n = _yybytes_len + 2;
@ -2018,7 +2047,7 @@ FILE *yyget_out (void)
/** Get the length of the current token. /** Get the length of the current token.
* *
*/ */
int yyget_leng (void) yy_size_t yyget_leng (void)
{ {
return yyleng; return yyleng;
} }
@ -2166,7 +2195,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 227 "dtc-lexer.l" #line 254 "dtc-lexer.l"
@ -2182,14 +2211,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) if (srcfile_pop() == 0)
return 0; return false;
yypop_buffer_state(); yypop_buffer_state();
yyin = current_srcfile->f; 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 /* Bison interface for Yacc-like parsers in C
@ -32,7 +32,7 @@
#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED #ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
# define YY_YY_DTC_PARSER_TAB_H_INCLUDED # define YY_YY_DTC_PARSER_TAB_H_INCLUDED
/* Enabling traces. */ /* Debug traces. */
#ifndef YYDEBUG #ifndef YYDEBUG
# define YYDEBUG 0 # define YYDEBUG 0
#endif #endif
@ -40,12 +40,11 @@
extern int yydebug; extern int yydebug;
#endif #endif
/* Tokens. */ /* Token type. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers enum yytokentype
know about them. */ {
enum yytokentype {
DT_V1 = 258, DT_V1 = 258,
DT_MEMRESERVE = 259, DT_MEMRESERVE = 259,
DT_LSHIFT = 260, DT_LSHIFT = 260,
@ -62,26 +61,23 @@ extern int yydebug;
DT_PROPNODENAME = 271, DT_PROPNODENAME = 271,
DT_LITERAL = 272, DT_LITERAL = 272,
DT_CHAR_LITERAL = 273, DT_CHAR_LITERAL = 273,
DT_BASE = 274, DT_BYTE = 274,
DT_BYTE = 275, DT_STRING = 275,
DT_STRING = 276, DT_LABEL = 276,
DT_LABEL = 277, DT_REF = 277,
DT_REF = 278, DT_INCBIN = 278
DT_INCBIN = 279
}; };
#endif #endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{ {
/* Line 2053 of yacc.c */ #line 38 "dtc-parser.y" /* yacc.c:1909 */
#line 40 "dtc-parser.y"
char *propnodename; char *propnodename;
char *literal;
char *labelref; char *labelref;
unsigned int cbase;
uint8_t byte; uint8_t byte;
struct data data; struct data data;
@ -97,29 +93,29 @@ typedef union YYSTYPE
struct reserve_info *re; struct reserve_info *re;
uint64_t integer; uint64_t integer;
#line 97 "dtc-parser.tab.h" /* yacc.c:1909 */
/* Line 2053 of yacc.c */ };
#line 103 "dtc-parser.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
#endif #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 extern YYSTYPE yylval;
int yyparse (void *YYPARSE_PARAM); extern YYLTYPE yylloc;
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (void); int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */ #endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */

View File

@ -17,31 +17,27 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA * USA
*/ */
%{ %{
#include <stdio.h> #include <stdio.h>
#include "dtc.h" #include "dtc.h"
#include "srcpos.h" #include "srcpos.h"
YYLTYPE yylloc;
extern int yylex(void); extern int yylex(void);
extern void print_error(char const *fmt, ...);
extern void yyerror(char const *s); 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 struct boot_info *the_boot_info;
extern int treesource_error; extern bool treesource_error;
static unsigned long long eval_literal(const char *s, int base, int bits);
static unsigned char eval_char_literal(const char *s);
%} %}
%union { %union {
char *propnodename; char *propnodename;
char *literal;
char *labelref; char *labelref;
unsigned int cbase;
uint8_t byte; uint8_t byte;
struct data data; struct data data;
@ -65,9 +61,8 @@ static unsigned char eval_char_literal(const char *s);
%token DT_DEL_PROP %token DT_DEL_PROP
%token DT_DEL_NODE %token DT_DEL_NODE
%token <propnodename> DT_PROPNODENAME %token <propnodename> DT_PROPNODENAME
%token <literal> DT_LITERAL %token <integer> DT_LITERAL
%token <literal> DT_CHAR_LITERAL %token <integer> DT_CHAR_LITERAL
%token <cbase> DT_BASE
%token <byte> DT_BYTE %token <byte> DT_BYTE
%token <data> DT_STRING %token <data> DT_STRING
%token <labelref> DT_LABEL %token <labelref> DT_LABEL
@ -145,6 +140,18 @@ devicetree:
{ {
$$ = merge_nodes($1, $3); $$ = merge_nodes($1, $3);
} }
| devicetree DT_LABEL DT_REF nodedef
{
struct node *target = get_node_by_ref($1, $3);
add_label(&target->labels, $2);
if (target)
merge_nodes(target, $4);
else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
| devicetree DT_REF nodedef | devicetree DT_REF nodedef
{ {
struct node *target = get_node_by_ref($1, $2); struct node *target = get_node_by_ref($1, $2);
@ -152,17 +159,18 @@ devicetree:
if (target) if (target)
merge_nodes(target, $3); merge_nodes(target, $3);
else else
print_error("label or path, '%s', not found", $2); ERROR(&@2, "Label or path %s not found", $2);
$$ = $1; $$ = $1;
} }
| devicetree DT_DEL_NODE DT_REF ';' | devicetree DT_DEL_NODE DT_REF ';'
{ {
struct node *target = get_node_by_ref($1, $3); struct node *target = get_node_by_ref($1, $3);
if (!target) if (target)
print_error("label or path, '%s', not found", $3);
else
delete_node(target); delete_node(target);
else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1; $$ = $1;
} }
@ -230,9 +238,8 @@ propdata:
if ($6 != 0) if ($6 != 0)
if (fseek(f, $6, SEEK_SET) != 0) if (fseek(f, $6, SEEK_SET) != 0)
print_error("Couldn't seek to offset %llu in \"%s\": %s", die("Couldn't seek to offset %llu in \"%s\": %s",
(unsigned long long)$6, (unsigned long long)$6, $4.val,
$4.val,
strerror(errno)); strerror(errno));
d = data_copy_file(f, $8); d = data_copy_file(f, $8);
@ -274,18 +281,19 @@ propdataprefix:
arrayprefix: arrayprefix:
DT_BITS DT_LITERAL '<' DT_BITS DT_LITERAL '<'
{ {
$$.data = empty_data; unsigned long long bits;
$$.bits = eval_literal($2, 0, 7);
if (($$.bits != 8) && bits = $2;
($$.bits != 16) &&
($$.bits != 32) && if ((bits != 8) && (bits != 16) &&
($$.bits != 64)) (bits != 32) && (bits != 64)) {
{ ERROR(&@2, "Array elements must be"
print_error("Only 8, 16, 32 and 64-bit elements" " 8, 16, 32 or 64-bits");
" are currently supported"); bits = 32;
$$.bits = 32;
} }
$$.data = empty_data;
$$.bits = bits;
} }
| '<' | '<'
{ {
@ -305,9 +313,8 @@ arrayprefix:
* mask), all bits are one. * mask), all bits are one.
*/ */
if (($2 > mask) && (($2 | mask) != -1ULL)) if (($2 > mask) && (($2 | mask) != -1ULL))
print_error( ERROR(&@2, "Value out of range for"
"integer value out of range " " %d-bit array element", $1.bits);
"%016lx (%d bits)", $1.bits);
} }
$$.data = data_append_integer($1.data, $2, $1.bits); $$.data = data_append_integer($1.data, $2, $1.bits);
@ -321,7 +328,7 @@ arrayprefix:
REF_PHANDLE, REF_PHANDLE,
$2); $2);
else else
print_error("References are only allowed in " ERROR(&@2, "References are only allowed in "
"arrays with 32-bit elements."); "arrays with 32-bit elements.");
$$.data = data_append_integer($1.data, val, $1.bits); $$.data = data_append_integer($1.data, val, $1.bits);
@ -334,13 +341,7 @@ arrayprefix:
integer_prim: integer_prim:
DT_LITERAL DT_LITERAL
{
$$ = eval_literal($1, 0, 64);
}
| DT_CHAR_LITERAL | DT_CHAR_LITERAL
{
$$ = eval_char_literal($1);
}
| '(' integer_expr ')' | '(' integer_expr ')'
{ {
$$ = $2; $$ = $2;
@ -447,7 +448,7 @@ subnodes:
} }
| subnode propdef | subnode propdef
{ {
print_error("syntax error: properties must precede subnodes"); ERROR(&@2, "Properties must precede subnodes");
YYERROR; YYERROR;
} }
; ;
@ -470,63 +471,7 @@ subnode:
%% %%
void print_error(char const *fmt, ...) void yyerror(char const *s)
{ {
va_list va; ERROR(&yylloc, "%s", s);
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;
} }

View File

@ -48,6 +48,8 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
} }
/* Usage related data. */ /* 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_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[] = { static struct option const usage_long_opts[] = {
@ -82,9 +84,9 @@ static const char * const usage_opts_help[] = {
"\t\tdts - device tree source text\n" "\t\tdts - device tree source text\n"
"\t\tdtb - device tree blob\n" "\t\tdtb - device tree blob\n"
"\t\tasm - assembler source", "\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\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\tMake the blob at least <bytes> long (extra space)",
"\n\tAdd padding to the blob of <bytes> long (extra space)", "\n\tAdd padding to the blob of <bytes> long (extra space)",
"\n\tSet the physical boot cpu", "\n\tSet the physical boot cpu",
@ -109,7 +111,7 @@ int main(int argc, char *argv[])
const char *outform = "dts"; const char *outform = "dts";
const char *outname = "-"; const char *outname = "-";
const char *depname = NULL; const char *depname = NULL;
int force = 0, sort = 0; bool force = false, sort = false;
const char *arg; const char *arg;
int opt; int opt;
FILE *outf = NULL; FILE *outf = NULL;
@ -148,7 +150,7 @@ int main(int argc, char *argv[])
padsize = strtol(optarg, NULL, 0); padsize = strtol(optarg, NULL, 0);
break; break;
case 'f': case 'f':
force = 1; force = true;
break; break;
case 'q': case 'q':
quiet++; quiet++;
@ -174,7 +176,7 @@ int main(int argc, char *argv[])
break; break;
case 's': case 's':
sort = 1; sort = true;
break; break;
case 'W': case 'W':
@ -237,7 +239,7 @@ int main(int argc, char *argv[])
if (streq(outname, "-")) { if (streq(outname, "-")) {
outf = stdout; outf = stdout;
} else { } else {
outf = fopen(outname, "w"); outf = fopen(outname, "wb");
if (! outf) if (! outf)
die("Couldn't open output file %s: %s\n", die("Couldn't open output file %s: %s\n",
outname, strerror(errno)); outname, strerror(errno));

View File

@ -38,9 +38,9 @@
#include "util.h" #include "util.h"
#ifdef DEBUG #ifdef DEBUG
#define debug(fmt,args...) printf(fmt, ##args) #define debug(...) printf(__VA_ARGS__)
#else #else
#define debug(fmt,args...) #define debug(...)
#endif #endif
@ -88,7 +88,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) \ #define for_each_marker(m) \
for (; (m); (m) = (m)->next) for (; (m); (m) = (m)->next)
@ -118,7 +118,7 @@ struct data data_append_align(struct data d, int align);
struct data data_add_marker(struct data d, enum markertype type, char *ref); 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 */ /* DT constraints */
@ -127,13 +127,13 @@ int data_is_one_string(struct data d);
/* Live trees */ /* Live trees */
struct label { struct label {
int deleted; bool deleted;
char *label; char *label;
struct label *next; struct label *next;
}; };
struct property { struct property {
int deleted; bool deleted;
char *name; char *name;
struct data val; struct data val;
@ -143,7 +143,7 @@ struct property {
}; };
struct node { struct node {
int deleted; bool deleted;
char *name; char *name;
struct property *proplist; struct property *proplist;
struct node *children; struct node *children;
@ -247,8 +247,8 @@ void sort_tree(struct boot_info *bi);
/* Checks */ /* Checks */
void parse_checks_option(bool warn, bool error, const char *optarg); void parse_checks_option(bool warn, bool error, const char *arg);
void process_checks(int force, struct boot_info *bi); void process_checks(bool force, struct boot_info *bi);
/* Flattened trees */ /* Flattened trees */

View File

@ -261,7 +261,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
{ {
struct property *prop; struct property *prop;
struct node *child; struct node *child;
int seen_name_prop = 0; bool seen_name_prop = false;
if (tree->deleted) if (tree->deleted)
return; return;
@ -279,7 +279,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
int nameoff; int nameoff;
if (streq(prop->name, "name")) if (streq(prop->name, "name"))
seen_name_prop = 1; seen_name_prop = true;
nameoff = stringtable_insert(strbuf, prop->name); nameoff = stringtable_insert(strbuf, prop->name);

View File

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

View File

@ -6,5 +6,6 @@
LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
LIBFDT_VERSION = version.lds LIBFDT_VERSION = version.lds
LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
fdt_addresses.c
LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)

View File

@ -92,7 +92,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
{ {
const uint32_t *tagp, *lenp; const fdt32_t *tagp, *lenp;
uint32_t tag; uint32_t tag;
int offset = startoffset; int offset = startoffset;
const char *p; const char *p;
@ -198,6 +198,34 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
return offset; return offset;
} }
int fdt_first_subnode(const void *fdt, int offset)
{
int depth = 0;
offset = fdt_next_node(fdt, offset, &depth);
if (offset < 0 || depth != 1)
return -FDT_ERR_NOTFOUND;
return offset;
}
int fdt_next_subnode(const void *fdt, int offset)
{
int depth = 1;
/*
* With respect to the parent, the depth of the next subnode will be
* the same as the last.
*/
do {
offset = fdt_next_node(fdt, offset, &depth);
if (offset < 0 || depth < 1)
return -FDT_ERR_NOTFOUND;
} while (depth > 1);
return offset;
}
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
{ {
int len = strlen(s) + 1; int len = strlen(s) + 1;

View File

@ -1,48 +1,99 @@
#ifndef _FDT_H #ifndef _FDT_H
#define _FDT_H #define _FDT_H
/*
* libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation.
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
*
* libfdt is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
*
* a) This library 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 library 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.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* Alternatively,
*
* b) Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
struct fdt_header { struct fdt_header {
uint32_t magic; /* magic word FDT_MAGIC */ fdt32_t magic; /* magic word FDT_MAGIC */
uint32_t totalsize; /* total size of DT block */ fdt32_t totalsize; /* total size of DT block */
uint32_t off_dt_struct; /* offset to structure */ fdt32_t off_dt_struct; /* offset to structure */
uint32_t off_dt_strings; /* offset to strings */ fdt32_t off_dt_strings; /* offset to strings */
uint32_t off_mem_rsvmap; /* offset to memory reserve map */ fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
uint32_t version; /* format version */ fdt32_t version; /* format version */
uint32_t last_comp_version; /* last compatible version */ fdt32_t last_comp_version; /* last compatible version */
/* version 2 fields below */ /* version 2 fields below */
uint32_t boot_cpuid_phys; /* Which physical CPU id we're fdt32_t boot_cpuid_phys; /* Which physical CPU id we're
booting on */ booting on */
/* version 3 fields below */ /* version 3 fields below */
uint32_t size_dt_strings; /* size of the strings block */ fdt32_t size_dt_strings; /* size of the strings block */
/* version 17 fields below */ /* version 17 fields below */
uint32_t size_dt_struct; /* size of the structure block */ fdt32_t size_dt_struct; /* size of the structure block */
}; };
struct fdt_reserve_entry { struct fdt_reserve_entry {
uint64_t address; fdt64_t address;
uint64_t size; fdt64_t size;
}; };
struct fdt_node_header { struct fdt_node_header {
uint32_t tag; fdt32_t tag;
char name[0]; char name[0];
}; };
struct fdt_property { struct fdt_property {
uint32_t tag; fdt32_t tag;
uint32_t len; fdt32_t len;
uint32_t nameoff; fdt32_t nameoff;
char data[0]; char data[0];
}; };
#endif /* !__ASSEMBLY */ #endif /* !__ASSEMBLY */
#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
#define FDT_TAGSIZE sizeof(uint32_t) #define FDT_TAGSIZE sizeof(fdt32_t)
#define FDT_BEGIN_NODE 0x1 /* Start node: full name */ #define FDT_BEGIN_NODE 0x1 /* Start node: full name */
#define FDT_END_NODE 0x2 /* End node */ #define FDT_END_NODE 0x2 /* End node */
@ -51,10 +102,10 @@ struct fdt_property {
#define FDT_NOP 0x4 /* nop */ #define FDT_NOP 0x4 /* nop */
#define FDT_END 0x9 #define FDT_END 0x9
#define FDT_V1_SIZE (7*sizeof(uint32_t)) #define FDT_V1_SIZE (7*sizeof(fdt32_t))
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(uint32_t)) #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(uint32_t)) #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
#define FDT_V16_SIZE FDT_V3_SIZE #define FDT_V16_SIZE FDT_V3_SIZE
#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(uint32_t)) #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t))
#endif /* _FDT_H */ #endif /* _FDT_H */

View File

@ -81,3 +81,4 @@ int fdt_create_empty_tree(void *buf, int bufsize)
return fdt_open_into(buf, buf, bufsize); return fdt_open_into(buf, buf, bufsize);
} }

View File

@ -154,9 +154,9 @@ int fdt_subnode_offset(const void *fdt, int parentoffset,
return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
} }
int fdt_path_offset(const void *fdt, const char *path) int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
{ {
const char *end = path + strlen(path); const char *end = path + namelen;
const char *p = path; const char *p = path;
int offset = 0; int offset = 0;
@ -164,7 +164,7 @@ int fdt_path_offset(const void *fdt, const char *path)
/* see if we have an alias */ /* see if we have an alias */
if (*path != '/') { if (*path != '/') {
const char *q = strchr(path, '/'); const char *q = memchr(path, '/', end - p);
if (!q) if (!q)
q = end; q = end;
@ -177,14 +177,15 @@ int fdt_path_offset(const void *fdt, const char *path)
p = q; p = q;
} }
while (*p) { while (p < end) {
const char *q; const char *q;
while (*p == '/') while (*p == '/') {
p++; p++;
if (! *p) if (p == end)
return offset; return offset;
q = strchr(p, '/'); }
q = memchr(p, '/', end - p);
if (! q) if (! q)
q = end; q = end;
@ -198,6 +199,11 @@ int fdt_path_offset(const void *fdt, const char *path)
return offset; return offset;
} }
int fdt_path_offset(const void *fdt, const char *path)
{
return fdt_path_offset_namelen(fdt, path, strlen(path));
}
const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
{ {
const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);
@ -322,7 +328,7 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,
uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
{ {
const uint32_t *php; const fdt32_t *php;
int len; int len;
/* FIXME: This is a bit sub-optimal, since we potentially scan /* FIXME: This is a bit sub-optimal, since we potentially scan
@ -515,8 +521,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }
static int _fdt_stringlist_contains(const char *strlist, int listlen, int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
const char *str)
{ {
int len = strlen(str); int len = strlen(str);
const char *p; const char *p;
@ -542,7 +547,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len); prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
if (!prop) if (!prop)
return len; return len;
if (_fdt_stringlist_contains(prop, len, compatible)) if (fdt_stringlist_contains(prop, len, compatible))
return 0; return 0;
else else
return 1; return 1;

View File

@ -84,9 +84,9 @@ static int _fdt_rw_check_header(void *fdt)
#define FDT_RW_CHECK_HEADER(fdt) \ #define FDT_RW_CHECK_HEADER(fdt) \
{ \ { \
int err; \ int __err; \
if ((err = _fdt_rw_check_header(fdt)) != 0) \ if ((__err = _fdt_rw_check_header(fdt)) != 0) \
return err; \ return __err; \
} }
static inline int _fdt_data_size(void *fdt) static inline int _fdt_data_size(void *fdt)
@ -339,7 +339,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
int nodelen; int nodelen;
int err; int err;
uint32_t tag; uint32_t tag;
uint32_t *endtag; fdt32_t *endtag;
FDT_RW_CHECK_HEADER(fdt); FDT_RW_CHECK_HEADER(fdt);
@ -366,7 +366,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
memset(nh->name, 0, FDT_TAGALIGN(namelen+1)); memset(nh->name, 0, FDT_TAGALIGN(namelen+1));
memcpy(nh->name, name, namelen); memcpy(nh->name, name, namelen);
endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE); endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
*endtag = cpu_to_fdt32(FDT_END_NODE); *endtag = cpu_to_fdt32(FDT_END_NODE);
return offset; return offset;

View File

@ -107,6 +107,38 @@ int fdt_create(void *buf, int bufsize)
return 0; return 0;
} }
int fdt_resize(void *fdt, void *buf, int bufsize)
{
size_t headsize, tailsize;
char *oldtail, *newtail;
FDT_SW_CHECK_HEADER(fdt);
headsize = fdt_off_dt_struct(fdt);
tailsize = fdt_size_dt_strings(fdt);
if ((headsize + tailsize) > bufsize)
return -FDT_ERR_NOSPACE;
oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
newtail = (char *)buf + bufsize - tailsize;
/* Two cases to avoid clobbering data if the old and new
* buffers partially overlap */
if (buf <= fdt) {
memmove(buf, fdt, headsize);
memmove(newtail, oldtail, tailsize);
} else {
memmove(newtail, oldtail, tailsize);
memmove(buf, fdt, headsize);
}
fdt_set_off_dt_strings(buf, bufsize);
fdt_set_totalsize(buf, bufsize);
return 0;
}
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
{ {
struct fdt_reserve_entry *re; struct fdt_reserve_entry *re;
@ -153,7 +185,7 @@ int fdt_begin_node(void *fdt, const char *name)
int fdt_end_node(void *fdt) int fdt_end_node(void *fdt)
{ {
uint32_t *en; fdt32_t *en;
FDT_SW_CHECK_HEADER(fdt); FDT_SW_CHECK_HEADER(fdt);
@ -213,7 +245,7 @@ int fdt_property(void *fdt, const char *name, const void *val, int len)
int fdt_finish(void *fdt) int fdt_finish(void *fdt)
{ {
char *p = (char *)fdt; char *p = (char *)fdt;
uint32_t *end; fdt32_t *end;
int oldstroffset, newstroffset; int oldstroffset, newstroffset;
uint32_t tag; uint32_t tag;
int offset, nextoffset; int offset, nextoffset;

View File

@ -74,7 +74,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
static void _fdt_nop_region(void *start, int len) static void _fdt_nop_region(void *start, int len)
{ {
uint32_t *p; fdt32_t *p;
for (p = start; (char *)p < ((char *)start + len); p++) for (p = start; (char *)p < ((char *)start + len); p++)
*p = cpu_to_fdt32(FDT_NOP); *p = cpu_to_fdt32(FDT_NOP);

View File

@ -51,8 +51,8 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <libfdt_env.h> #include "libfdt_env.h"
#include <fdt.h> #include "fdt.h"
#define FDT_FIRST_SUPPORTED_VERSION 0x10 #define FDT_FIRST_SUPPORTED_VERSION 0x10
#define FDT_LAST_SUPPORTED_VERSION 0x11 #define FDT_LAST_SUPPORTED_VERSION 0x11
@ -116,7 +116,12 @@
* Should never be returned, if it is, it indicates a bug in * Should never be returned, if it is, it indicates a bug in
* libfdt itself. */ * libfdt itself. */
#define FDT_ERR_MAX 13 /* Errors in device tree content */
#define FDT_ERR_BADNCELLS 14
/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
* or similar property with a bad format or value */
#define FDT_ERR_MAX 14
/**********************************************************************/ /**********************************************************************/
/* Low-level functions (you probably don't need these) */ /* Low-level functions (you probably don't need these) */
@ -136,6 +141,28 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
int fdt_next_node(const void *fdt, int offset, int *depth); int fdt_next_node(const void *fdt, int offset, int *depth);
/**
* fdt_first_subnode() - get offset of first direct subnode
*
* @fdt: FDT blob
* @offset: Offset of node to check
* @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
*/
int fdt_first_subnode(const void *fdt, int offset);
/**
* fdt_next_subnode() - get offset of next direct subnode
*
* After first calling fdt_first_subnode(), call this function repeatedly to
* get direct subnodes of a parent node.
*
* @fdt: FDT blob
* @offset: Offset of previous subnode
* @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
* subnodes
*/
int fdt_next_subnode(const void *fdt, int offset);
/**********************************************************************/ /**********************************************************************/
/* General functions */ /* General functions */
/**********************************************************************/ /**********************************************************************/
@ -295,6 +322,17 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
*/ */
int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
/**
* fdt_path_offset_namelen - find a tree node by its full path
* @fdt: pointer to the device tree blob
* @path: full path of the node to locate
* @namelen: number of characters of path to consider
*
* Identical to fdt_path_offset(), but only consider the first namelen
* characters of path as the path name.
*/
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
/** /**
* fdt_path_offset - find a tree node by its full path * fdt_path_offset - find a tree node by its full path
* @fdt: pointer to the device tree blob * @fdt: pointer to the device tree blob
@ -582,7 +620,7 @@ const char *fdt_get_alias_namelen(const void *fdt,
* value of the property named 'name' in the node /aliases. * value of the property named 'name' in the node /aliases.
* *
* returns: * returns:
* a pointer to the expansion of the alias named 'name', of it exists * a pointer to the expansion of the alias named 'name', if it exists
* NULL, if the given alias or the /aliases node does not exist * NULL, if the given alias or the /aliases node does not exist
*/ */
const char *fdt_get_alias(const void *fdt, const char *name); const char *fdt_get_alias(const void *fdt, const char *name);
@ -816,6 +854,75 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
int fdt_node_offset_by_compatible(const void *fdt, int startoffset, int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
const char *compatible); const char *compatible);
/**
* fdt_stringlist_contains - check a string list property for a string
* @strlist: Property containing a list of strings to check
* @listlen: Length of property
* @str: String to search for
*
* This is a utility function provided for convenience. The list contains
* one or more strings, each terminated by \0, as is found in a device tree
* "compatible" property.
*
* @return: 1 if the string is found in the list, 0 not found, or invalid list
*/
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
/**********************************************************************/
/* Read-only functions (addressing related) */
/**********************************************************************/
/**
* FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
*
* This is the maximum value for #address-cells, #size-cells and
* similar properties that will be processed by libfdt. IEE1275
* requires that OF implementations handle values up to 4.
* Implementations may support larger values, but in practice higher
* values aren't used.
*/
#define FDT_MAX_NCELLS 4
/**
* fdt_address_cells - retrieve address size for a bus represented in the tree
* @fdt: pointer to the device tree blob
* @nodeoffset: offset of the node to find the address size for
*
* When the node has a valid #address-cells property, returns its value.
*
* returns:
* 0 <= n < FDT_MAX_NCELLS, on success
* 2, if the node has no #address-cells property
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #address-cells property
* -FDT_ERR_BADMAGIC,
* -FDT_ERR_BADVERSION,
* -FDT_ERR_BADSTATE,
* -FDT_ERR_BADSTRUCTURE,
* -FDT_ERR_TRUNCATED, standard meanings
*/
int fdt_address_cells(const void *fdt, int nodeoffset);
/**
* fdt_size_cells - retrieve address range size for a bus represented in the
* tree
* @fdt: pointer to the device tree blob
* @nodeoffset: offset of the node to find the address range size for
*
* When the node has a valid #size-cells property, returns its value.
*
* returns:
* 0 <= n < FDT_MAX_NCELLS, on success
* 2, if the node has no #address-cells property
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid #size-cells property
* -FDT_ERR_BADMAGIC,
* -FDT_ERR_BADVERSION,
* -FDT_ERR_BADSTATE,
* -FDT_ERR_BADSTRUCTURE,
* -FDT_ERR_TRUNCATED, standard meanings
*/
int fdt_size_cells(const void *fdt, int nodeoffset);
/**********************************************************************/ /**********************************************************************/
/* Write-in-place functions */ /* Write-in-place functions */
/**********************************************************************/ /**********************************************************************/
@ -882,8 +989,8 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
const char *name, uint32_t val) const char *name, uint32_t val)
{ {
val = cpu_to_fdt32(val); fdt32_t tmp = cpu_to_fdt32(val);
return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**
@ -917,8 +1024,8 @@ static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
const char *name, uint64_t val) const char *name, uint64_t val)
{ {
val = cpu_to_fdt64(val); fdt64_t tmp = cpu_to_fdt64(val);
return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**
@ -987,19 +1094,20 @@ int fdt_nop_node(void *fdt, int nodeoffset);
/**********************************************************************/ /**********************************************************************/
int fdt_create(void *buf, int bufsize); int fdt_create(void *buf, int bufsize);
int fdt_resize(void *fdt, void *buf, int bufsize);
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
int fdt_finish_reservemap(void *fdt); int fdt_finish_reservemap(void *fdt);
int fdt_begin_node(void *fdt, const char *name); int fdt_begin_node(void *fdt, const char *name);
int fdt_property(void *fdt, const char *name, const void *val, int len); int fdt_property(void *fdt, const char *name, const void *val, int len);
static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
{ {
val = cpu_to_fdt32(val); fdt32_t tmp = cpu_to_fdt32(val);
return fdt_property(fdt, name, &val, sizeof(val)); return fdt_property(fdt, name, &tmp, sizeof(tmp));
} }
static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
{ {
val = cpu_to_fdt64(val); fdt64_t tmp = cpu_to_fdt64(val);
return fdt_property(fdt, name, &val, sizeof(val)); return fdt_property(fdt, name, &tmp, sizeof(tmp));
} }
static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
{ {
@ -1154,8 +1262,8 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
uint32_t val) uint32_t val)
{ {
val = cpu_to_fdt32(val); fdt32_t tmp = cpu_to_fdt32(val);
return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**
@ -1189,8 +1297,8 @@ static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
uint64_t val) uint64_t val)
{ {
val = cpu_to_fdt64(val); fdt64_t tmp = cpu_to_fdt64(val);
return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**
@ -1296,8 +1404,8 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
static inline int fdt_appendprop_u32(void *fdt, int nodeoffset, static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
const char *name, uint32_t val) const char *name, uint32_t val)
{ {
val = cpu_to_fdt32(val); fdt32_t tmp = cpu_to_fdt32(val);
return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**
@ -1331,8 +1439,8 @@ static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
static inline int fdt_appendprop_u64(void *fdt, int nodeoffset, static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
const char *name, uint64_t val) const char *name, uint64_t val)
{ {
val = cpu_to_fdt64(val); fdt64_t tmp = cpu_to_fdt64(val);
return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val)); return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
} }
/** /**

View File

@ -1,29 +1,111 @@
#ifndef _LIBFDT_ENV_H #ifndef _LIBFDT_ENV_H
#define _LIBFDT_ENV_H #define _LIBFDT_ENV_H
/*
* libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation.
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
*
* libfdt is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
*
* a) This library 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 library 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.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* Alternatively,
*
* b) Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n]) #ifdef __CHECKER__
static inline uint16_t fdt16_to_cpu(uint16_t x) #define __force __attribute__((force))
{ #define __bitwise __attribute__((bitwise))
return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1); #else
} #define __force
#define cpu_to_fdt16(x) fdt16_to_cpu(x) #define __bitwise
#endif
static inline uint32_t fdt32_to_cpu(uint32_t x) typedef uint16_t __bitwise fdt16_t;
{ typedef uint32_t __bitwise fdt32_t;
return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | (EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3); typedef uint64_t __bitwise fdt64_t;
}
#define cpu_to_fdt32(x) fdt32_to_cpu(x)
static inline uint64_t fdt64_to_cpu(uint64_t x) #define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
(EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
(EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
(EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
(EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
static inline uint16_t fdt16_to_cpu(fdt16_t x)
{ {
return (EXTRACT_BYTE(0) << 56) | (EXTRACT_BYTE(1) << 48) | (EXTRACT_BYTE(2) << 40) | (EXTRACT_BYTE(3) << 32) return (__force uint16_t)CPU_TO_FDT16(x);
| (EXTRACT_BYTE(4) << 24) | (EXTRACT_BYTE(5) << 16) | (EXTRACT_BYTE(6) << 8) | EXTRACT_BYTE(7);
} }
#define cpu_to_fdt64(x) fdt64_to_cpu(x) static inline fdt16_t cpu_to_fdt16(uint16_t x)
{
return (__force fdt16_t)CPU_TO_FDT16(x);
}
static inline uint32_t fdt32_to_cpu(fdt32_t x)
{
return (__force uint32_t)CPU_TO_FDT32(x);
}
static inline fdt32_t cpu_to_fdt32(uint32_t x)
{
return (__force fdt32_t)CPU_TO_FDT32(x);
}
static inline uint64_t fdt64_to_cpu(fdt64_t x)
{
return (__force uint64_t)CPU_TO_FDT64(x);
}
static inline fdt64_t cpu_to_fdt64(uint64_t x)
{
return (__force fdt64_t)CPU_TO_FDT64(x);
}
#undef CPU_TO_FDT64
#undef CPU_TO_FDT32
#undef CPU_TO_FDT16
#undef EXTRACT_BYTE #undef EXTRACT_BYTE
#endif /* _LIBFDT_ENV_H */ #endif /* _LIBFDT_ENV_H */

View File

@ -57,9 +57,9 @@
#define FDT_CHECK_HEADER(fdt) \ #define FDT_CHECK_HEADER(fdt) \
{ \ { \
int err; \ int __err; \
if ((err = fdt_check_header(fdt)) != 0) \ if ((__err = fdt_check_header(fdt)) != 0) \
return err; \ return __err; \
} }
int _fdt_check_node_offset(const void *fdt, int offset); int _fdt_check_node_offset(const void *fdt, int offset);

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

View File

@ -21,6 +21,7 @@
#define _SRCPOS_H_ #define _SRCPOS_H_
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
struct srcfile_state { struct srcfile_state {
FILE *f; FILE *f;
@ -55,7 +56,7 @@ extern struct srcfile_state *current_srcfile; /* = NULL */
FILE *srcfile_relative_open(const char *fname, char **fullnamep); FILE *srcfile_relative_open(const char *fname, char **fullnamep);
void srcfile_push(const char *fname); 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 * 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 char *srcpos_string(struct srcpos *pos);
extern void srcpos_dump(struct srcpos *pos); extern void srcpos_dump(struct srcpos *pos);
extern void srcpos_verror(struct srcpos *pos, char const *, va_list va) extern void srcpos_verror(struct srcpos *pos, const char *prefix,
__attribute__((format(printf, 2, 0))); const char *fmt, va_list va)
extern void srcpos_error(struct srcpos *pos, char const *, ...) __attribute__((format(printf, 3, 0)));
__attribute__((format(printf, 2, 3))); extern void srcpos_error(struct srcpos *pos, const char *prefix,
extern void srcpos_warn(struct srcpos *pos, char const *, ...) const char *fmt, ...)
__attribute__((format(printf, 2, 3))); __attribute__((format(printf, 3, 4)));
extern void srcpos_set_line(char *f, int l); extern void srcpos_set_line(char *f, int l);

View File

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

View File

@ -39,11 +39,11 @@
char *xstrdup(const char *s) char *xstrdup(const char *s)
{ {
int len = strlen(s) + 1; 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) char *join_path(const char *path, const char *name)
@ -70,7 +70,7 @@ char *join_path(const char *path, const char *name)
return str; 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 *s = data;
const char *ss, *se; const char *ss, *se;
@ -87,7 +87,7 @@ int util_is_printable_string(const void *data, int len)
while (s < se) { while (s < se) {
ss = s; ss = s;
while (s < se && *s && isprint(*s)) while (s < se && *s && isprint((unsigned char)*s))
s++; s++;
/* not zero, or not done yet */ /* 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) { if (offset == bufsize) {
bufsize *= 2; bufsize *= 2;
buf = xrealloc(buf, bufsize); buf = xrealloc(buf, bufsize);
if (!buf) {
ret = ENOMEM;
break;
}
} }
ret = read(fd, &buf[offset], bufsize - offset); 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; const uint32_t *cell = (const uint32_t *)data;
printf(" = <"); 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]), printf("0x%08x%s", fdt32_to_cpu(cell[i]),
i < (len - 4) ? " " : ""); i < (len - 1) ? " " : "");
printf(">"); printf(">");
} else { } else {
printf(" = ["); printf(" = [");

View File

@ -2,6 +2,7 @@
#define _UTIL_H #define _UTIL_H
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <getopt.h> #include <getopt.h>
/* /*
@ -33,6 +34,7 @@ static inline void __attribute__((noreturn)) die(const char *str, ...)
va_start(ap, str); va_start(ap, str);
fprintf(stderr, "FATAL ERROR: "); fprintf(stderr, "FATAL ERROR: ");
vfprintf(stderr, str, ap); vfprintf(stderr, str, ap);
va_end(ap);
exit(1); exit(1);
} }
@ -68,7 +70,7 @@ extern char *join_path(const char *path, const char *name);
* @param len The string length including terminator * @param len The string length including terminator
* @return 1 if a valid printable string, 0 if not * @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 * 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-g9d3649bd"