Commit 47605971 authored by Rob Herring's avatar Rob Herring

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: default avatarRob Herring <robh@kernel.org>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: devicetree@vger.kernel.org
parent f1ec7187
...@@ -53,7 +53,7 @@ struct check { ...@@ -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, ...) ...@@ -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 ...@@ -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) ...@@ -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) ...@@ -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, ...@@ -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) ...@@ -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) ...@@ -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;
......
...@@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len) ...@@ -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) ...@@ -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;
} }
...@@ -20,7 +20,6 @@ ...@@ -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 ...@@ -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; ...@@ -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); ...@@ -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); ...@@ -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); ...@@ -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) ...@@ -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;
} }
This diff is collapsed.
This diff is collapsed.
/* 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
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
special exception, which will cause the skeleton and the resulting special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public Bison output files to be licensed under the GNU General Public
License without this special exception. License without this special exception.
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
#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,48 +40,44 @@ ...@@ -40,48 +40,44 @@
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, DT_RSHIFT = 261,
DT_RSHIFT = 261, DT_LE = 262,
DT_LE = 262, DT_GE = 263,
DT_GE = 263, DT_EQ = 264,
DT_EQ = 264, DT_NE = 265,
DT_NE = 265, DT_AND = 266,
DT_AND = 266, DT_OR = 267,
DT_OR = 267, DT_BITS = 268,
DT_BITS = 268, DT_DEL_PROP = 269,
DT_DEL_PROP = 269, DT_DEL_NODE = 270,
DT_DEL_NODE = 270, DT_PROPNODENAME = 271,
DT_PROPNODENAME = 271, DT_LITERAL = 272,
DT_LITERAL = 272, DT_CHAR_LITERAL = 273,
DT_CHAR_LITERAL = 273, DT_BYTE = 274,
DT_BASE = 274, DT_STRING = 275,
DT_BYTE = 275, DT_LABEL = 276,
DT_STRING = 276, DT_REF = 277,
DT_LABEL = 277, DT_INCBIN = 278
DT_REF = 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 ...@@ -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
#ifdef YYPARSE_PARAM typedef struct YYLTYPE YYLTYPE;
#if defined __STDC__ || defined __cplusplus struct YYLTYPE
int yyparse (void *YYPARSE_PARAM); {
#else int first_line;
int yyparse (); int first_column;
int last_line;
int last_column;
};
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif #endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
extern YYSTYPE yylval;
extern YYLTYPE yylloc;
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 */
...@@ -17,31 +17,27 @@ ...@@ -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); ...@@ -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: ...@@ -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: ...@@ -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,10 +238,9 @@ propdata: ...@@ -230,10 +238,9 @@ 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: ...@@ -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);
bits = $2;
if (($$.bits != 8) &&
($$.bits != 16) && if ((bits != 8) && (bits != 16) &&
($$.bits != 32) && (bits != 32) && (bits != 64)) {
($$.bits != 64)) ERROR(&@2, "Array elements must be"
{ " 8, 16, 32 or 64-bits");
print_error("Only 8, 16, 32 and 64-bit elements" bits = 32;
" are currently supported");
$$.bits = 32;
} }
$$.data = empty_data;
$$.bits = bits;
} }
| '<' | '<'
{ {
...@@ -305,9 +313,8 @@ arrayprefix: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -470,63 +471,7 @@ subnode:
%% %%
void print_error(char const *fmt, ...) void yyerror(char const *s)
{
va_list va;
va_start(va, fmt);
srcpos_verror(&yylloc, fmt, va);
va_end(va);
treesource_error = 1;
}
void yyerror(char const *s) {
print_error("%s", s);
}
static unsigned long long eval_literal(const char *s, int base, int bits)
{
unsigned long long val;
char *e;
errno = 0;
val = strtoull(s, &e, base);
if (*e) {
size_t uls = strspn(e, "UL");
if (e[uls])
print_error("bad characters in literal");
}
if ((errno == ERANGE)
|| ((bits < 64) && (val >= (1ULL << bits))))
print_error("literal out of range");
else if (errno != 0)
print_error("bad literal");
return val;
}
static unsigned char eval_char_literal(const char *s)
{ {
int i = 1; ERROR(&yylloc, "%s", s);
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;
} }
...@@ -48,6 +48,8 @@ static void fill_fullpaths(struct node *tree, const char *prefix) ...@@ -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[] = { ...@@ -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[]) ...@@ -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[]) ...@@ -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[]) ...@@ -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[]) ...@@ -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));
......
...@@ -38,9 +38,9 @@ ...@@ -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 { ...@@ -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); ...@@ -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); ...@@ -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 { ...@@ -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); ...@@ -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 */
......
...@@ -261,7 +261,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit, ...@@ -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, ...@@ -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);
......
...@@ -37,26 +37,26 @@ static struct node *read_fstree(const char *dirname) ...@@ -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) ...@@ -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) ...@@ -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));
} }
...@@ -6,5 +6,6 @@ ...@@ -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)
...@@ -92,7 +92,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) ...@@ -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) ...@@ -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;
......
#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 { ...@@ -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 */
...@@ -81,3 +81,4 @@ int fdt_create_empty_tree(void *buf, int bufsize) ...@@ -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);
} }
...@@ -154,9 +154,9 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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, ...@@ -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) ...@@ -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, ...@@ -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;
......
...@@ -84,9 +84,9 @@ static int _fdt_rw_check_header(void *fdt) ...@@ -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, ...@@ -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, ...@@ -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;
......
...@@ -107,6 +107,38 @@ int fdt_create(void *buf, int bufsize) ...@@ -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) ...@@ -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) ...@@ -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;
......
...@@ -74,7 +74,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, ...@@ -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);
......
...@@ -51,8 +51,8 @@ ...@@ -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 @@ ...@@ -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); ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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); ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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));
} }
/** /**
......
This diff is collapsed.
...@@ -57,9 +57,9 @@ ...@@ -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);
......
...@@ -511,7 +511,9 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle) ...@@ -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);
......
This diff is collapsed.
...@@ -21,6 +21,7 @@ ...@@ -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 */ ...@@ -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); ...@@ -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);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment