scripts/dtc: Update to upstream version 1.4.1
Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
c1ab1e22c7
commit
12888ae902
|
@ -0,0 +1,18 @@
|
|||
# Makefile.dtc
|
||||
#
|
||||
# This is not a complete Makefile of itself. Instead, it is designed to
|
||||
# be easily embeddable into other systems of Makefiles.
|
||||
#
|
||||
DTC_SRCS = \
|
||||
checks.c \
|
||||
data.c \
|
||||
dtc.c \
|
||||
flattree.c \
|
||||
fstree.c \
|
||||
livetree.c \
|
||||
srcpos.c \
|
||||
treesource.c \
|
||||
util.c
|
||||
|
||||
DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
|
||||
DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
|
|
@ -53,7 +53,7 @@ struct check {
|
|||
void *data;
|
||||
bool warn, error;
|
||||
enum checkstatus status;
|
||||
int inprogress;
|
||||
bool inprogress;
|
||||
int num_prereqs;
|
||||
struct check **prereq;
|
||||
};
|
||||
|
@ -141,9 +141,9 @@ static void check_nodes_props(struct check *c, struct node *dt, struct node *nod
|
|||
check_nodes_props(c, dt, child);
|
||||
}
|
||||
|
||||
static int run_check(struct check *c, struct node *dt)
|
||||
static bool run_check(struct check *c, struct node *dt)
|
||||
{
|
||||
int error = 0;
|
||||
bool error = false;
|
||||
int i;
|
||||
|
||||
assert(!c->inprogress);
|
||||
|
@ -151,11 +151,11 @@ static int run_check(struct check *c, struct node *dt)
|
|||
if (c->status != UNCHECKED)
|
||||
goto out;
|
||||
|
||||
c->inprogress = 1;
|
||||
c->inprogress = true;
|
||||
|
||||
for (i = 0; i < c->num_prereqs; i++) {
|
||||
struct check *prq = c->prereq[i];
|
||||
error |= run_check(prq, dt);
|
||||
error = error || run_check(prq, dt);
|
||||
if (prq->status != PASSED) {
|
||||
c->status = PREREQ;
|
||||
check_msg(c, "Failed prerequisite '%s'",
|
||||
|
@ -177,9 +177,9 @@ static int run_check(struct check *c, struct node *dt)
|
|||
TRACE(c, "\tCompleted, status %d", c->status);
|
||||
|
||||
out:
|
||||
c->inprogress = 0;
|
||||
c->inprogress = false;
|
||||
if ((c->status != PASSED) && (c->error))
|
||||
error = 1;
|
||||
error = true;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -624,11 +624,11 @@ static void check_avoid_default_addr_size(struct check *c, struct node *dt,
|
|||
if (!reg && !ranges)
|
||||
return;
|
||||
|
||||
if ((node->parent->addr_cells == -1))
|
||||
if (node->parent->addr_cells == -1)
|
||||
FAIL(c, "Relying on default #address-cells value for %s",
|
||||
node->fullpath);
|
||||
|
||||
if ((node->parent->size_cells == -1))
|
||||
if (node->parent->size_cells == -1)
|
||||
FAIL(c, "Relying on default #size-cells value for %s",
|
||||
node->fullpath);
|
||||
}
|
||||
|
@ -706,15 +706,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
|
|||
c->error = c->error && !error;
|
||||
}
|
||||
|
||||
void parse_checks_option(bool warn, bool error, const char *optarg)
|
||||
void parse_checks_option(bool warn, bool error, const char *arg)
|
||||
{
|
||||
int i;
|
||||
const char *name = optarg;
|
||||
const char *name = arg;
|
||||
bool enable = true;
|
||||
|
||||
if ((strncmp(optarg, "no-", 3) == 0)
|
||||
|| (strncmp(optarg, "no_", 3) == 0)) {
|
||||
name = optarg + 3;
|
||||
if ((strncmp(arg, "no-", 3) == 0)
|
||||
|| (strncmp(arg, "no_", 3) == 0)) {
|
||||
name = arg + 3;
|
||||
enable = false;
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
|
|||
die("Unrecognized check name \"%s\"\n", name);
|
||||
}
|
||||
|
||||
void process_checks(int force, struct boot_info *bi)
|
||||
void process_checks(bool force, struct boot_info *bi)
|
||||
{
|
||||
struct node *dt = bi->dt;
|
||||
int i;
|
||||
|
|
|
@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len)
|
|||
struct data d;
|
||||
char *q;
|
||||
|
||||
d = data_grow_for(empty_data, strlen(s)+1);
|
||||
d = data_grow_for(empty_data, len + 1);
|
||||
|
||||
q = d.val;
|
||||
while (i < len) {
|
||||
|
@ -250,20 +250,20 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref)
|
|||
return data_append_markers(d, m);
|
||||
}
|
||||
|
||||
int data_is_one_string(struct data d)
|
||||
bool data_is_one_string(struct data d)
|
||||
{
|
||||
int i;
|
||||
int len = d.len;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
for (i = 0; i < len-1; i++)
|
||||
if (d.val[i] == '\0')
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
if (d.val[len-1] != '\0')
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
%option noyywrap nounput noinput never-interactive
|
||||
|
||||
%x INCLUDE
|
||||
%x BYTESTRING
|
||||
%x PROPNODENAME
|
||||
%s V1
|
||||
|
@ -40,6 +39,7 @@ LINECOMMENT "//".*\n
|
|||
#include "dtc-parser.tab.h"
|
||||
|
||||
YYLTYPE yylloc;
|
||||
extern bool treesource_error;
|
||||
|
||||
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
|
||||
#define YY_USER_ACTION \
|
||||
|
@ -61,7 +61,8 @@ static int dts_version = 1;
|
|||
BEGIN(V1); \
|
||||
|
||||
static void push_input_file(const char *filename);
|
||||
static int pop_input_file(void);
|
||||
static bool pop_input_file(void);
|
||||
static void lexical_error(const char *fmt, ...);
|
||||
%}
|
||||
|
||||
%%
|
||||
|
@ -71,15 +72,15 @@ static int pop_input_file(void);
|
|||
push_input_file(name);
|
||||
}
|
||||
|
||||
<*>^"#"(line)?{WS}+[0-9]+{WS}+{STRING}({WS}+[0-9]+)? {
|
||||
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
|
||||
char *line, *tmp, *fn;
|
||||
/* skip text before line # */
|
||||
line = yytext;
|
||||
while (!isdigit(*line))
|
||||
while (!isdigit((unsigned char)*line))
|
||||
line++;
|
||||
/* skip digits in line # */
|
||||
tmp = line;
|
||||
while (!isspace(*tmp))
|
||||
while (!isspace((unsigned char)*tmp))
|
||||
tmp++;
|
||||
/* "NULL"-terminate line # */
|
||||
*tmp = '\0';
|
||||
|
@ -146,15 +147,42 @@ static int pop_input_file(void);
|
|||
}
|
||||
|
||||
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
|
||||
yylval.literal = xstrdup(yytext);
|
||||
DPRINT("Literal: '%s'\n", yylval.literal);
|
||||
char *e;
|
||||
DPRINT("Integer Literal: '%s'\n", yytext);
|
||||
|
||||
errno = 0;
|
||||
yylval.integer = strtoull(yytext, &e, 0);
|
||||
|
||||
assert(!(*e) || !e[strspn(e, "UL")]);
|
||||
|
||||
if (errno == ERANGE)
|
||||
lexical_error("Integer literal '%s' out of range",
|
||||
yytext);
|
||||
else
|
||||
/* ERANGE is the only strtoull error triggerable
|
||||
* by strings matching the pattern */
|
||||
assert(errno == 0);
|
||||
return DT_LITERAL;
|
||||
}
|
||||
|
||||
<*>{CHAR_LITERAL} {
|
||||
yytext[yyleng-1] = '\0';
|
||||
yylval.literal = xstrdup(yytext+1);
|
||||
DPRINT("Character literal: %s\n", yylval.literal);
|
||||
struct data d;
|
||||
DPRINT("Character literal: %s\n", yytext);
|
||||
|
||||
d = data_copy_escape_string(yytext+1, yyleng-2);
|
||||
if (d.len == 1) {
|
||||
lexical_error("Empty character literal");
|
||||
yylval.integer = 0;
|
||||
return DT_CHAR_LITERAL;
|
||||
}
|
||||
|
||||
yylval.integer = (unsigned char)d.val[0];
|
||||
|
||||
if (d.len > 2)
|
||||
lexical_error("Character literal has %d"
|
||||
" characters instead of 1",
|
||||
d.len - 1);
|
||||
|
||||
return DT_CHAR_LITERAL;
|
||||
}
|
||||
|
||||
|
@ -164,7 +192,7 @@ static int pop_input_file(void);
|
|||
return DT_REF;
|
||||
}
|
||||
|
||||
<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
|
||||
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
|
||||
yytext[yyleng-1] = '\0';
|
||||
DPRINT("Ref: %s\n", yytext+2);
|
||||
yylval.labelref = xstrdup(yytext+2);
|
||||
|
@ -238,13 +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)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
yypop_buffer_state();
|
||||
yyin = current_srcfile->f;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void lexical_error(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
treesource_error = true;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,8 @@
|
|||
/* A Bison parser, made by GNU Bison 3.0.2. */
|
||||
|
||||
/* A Bison parser, made by GNU Bison 2.4.1. */
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
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
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -32,51 +30,54 @@
|
|||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
DT_V1 = 258,
|
||||
DT_MEMRESERVE = 259,
|
||||
DT_LSHIFT = 260,
|
||||
DT_RSHIFT = 261,
|
||||
DT_LE = 262,
|
||||
DT_GE = 263,
|
||||
DT_EQ = 264,
|
||||
DT_NE = 265,
|
||||
DT_AND = 266,
|
||||
DT_OR = 267,
|
||||
DT_BITS = 268,
|
||||
DT_DEL_PROP = 269,
|
||||
DT_DEL_NODE = 270,
|
||||
DT_PROPNODENAME = 271,
|
||||
DT_LITERAL = 272,
|
||||
DT_CHAR_LITERAL = 273,
|
||||
DT_BASE = 274,
|
||||
DT_BYTE = 275,
|
||||
DT_STRING = 276,
|
||||
DT_LABEL = 277,
|
||||
DT_REF = 278,
|
||||
DT_INCBIN = 279
|
||||
};
|
||||
#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
|
||||
# define YY_YY_DTC_PARSER_TAB_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 0
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
extern int yydebug;
|
||||
#endif
|
||||
|
||||
/* Token type. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
DT_V1 = 258,
|
||||
DT_MEMRESERVE = 259,
|
||||
DT_LSHIFT = 260,
|
||||
DT_RSHIFT = 261,
|
||||
DT_LE = 262,
|
||||
DT_GE = 263,
|
||||
DT_EQ = 264,
|
||||
DT_NE = 265,
|
||||
DT_AND = 266,
|
||||
DT_OR = 267,
|
||||
DT_BITS = 268,
|
||||
DT_DEL_PROP = 269,
|
||||
DT_DEL_NODE = 270,
|
||||
DT_PROPNODENAME = 271,
|
||||
DT_LITERAL = 272,
|
||||
DT_CHAR_LITERAL = 273,
|
||||
DT_BYTE = 274,
|
||||
DT_STRING = 275,
|
||||
DT_LABEL = 276,
|
||||
DT_REF = 277,
|
||||
DT_INCBIN = 278
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
union YYSTYPE
|
||||
{
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
#line 40 "dtc-parser.y"
|
||||
#line 38 "dtc-parser.y" /* yacc.c:1909 */
|
||||
|
||||
char *propnodename;
|
||||
char *literal;
|
||||
char *labelref;
|
||||
unsigned int cbase;
|
||||
uint8_t byte;
|
||||
struct data data;
|
||||
|
||||
|
@ -92,16 +93,29 @@ typedef union YYSTYPE
|
|||
struct reserve_info *re;
|
||||
uint64_t integer;
|
||||
|
||||
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
#line 99 "dtc-parser.tab.h"
|
||||
} YYSTYPE;
|
||||
#line 97 "dtc-parser.tab.h" /* yacc.c:1909 */
|
||||
};
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
extern YYLTYPE yylloc;
|
||||
int yyparse (void);
|
||||
|
||||
|
||||
#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */
|
||||
|
|
|
@ -17,31 +17,27 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dtc.h"
|
||||
#include "srcpos.h"
|
||||
|
||||
YYLTYPE yylloc;
|
||||
|
||||
extern int yylex(void);
|
||||
extern void print_error(char const *fmt, ...);
|
||||
extern void yyerror(char const *s);
|
||||
#define ERROR(loc, ...) \
|
||||
do { \
|
||||
srcpos_error((loc), "Error", __VA_ARGS__); \
|
||||
treesource_error = true; \
|
||||
} while (0)
|
||||
|
||||
extern struct boot_info *the_boot_info;
|
||||
extern int treesource_error;
|
||||
|
||||
static unsigned long long eval_literal(const char *s, int base, int bits);
|
||||
static unsigned char eval_char_literal(const char *s);
|
||||
extern bool treesource_error;
|
||||
%}
|
||||
|
||||
%union {
|
||||
char *propnodename;
|
||||
char *literal;
|
||||
char *labelref;
|
||||
unsigned int cbase;
|
||||
uint8_t byte;
|
||||
struct data data;
|
||||
|
||||
|
@ -65,9 +61,8 @@ static unsigned char eval_char_literal(const char *s);
|
|||
%token DT_DEL_PROP
|
||||
%token DT_DEL_NODE
|
||||
%token <propnodename> DT_PROPNODENAME
|
||||
%token <literal> DT_LITERAL
|
||||
%token <literal> DT_CHAR_LITERAL
|
||||
%token <cbase> DT_BASE
|
||||
%token <integer> DT_LITERAL
|
||||
%token <integer> DT_CHAR_LITERAL
|
||||
%token <byte> DT_BYTE
|
||||
%token <data> DT_STRING
|
||||
%token <labelref> DT_LABEL
|
||||
|
@ -152,17 +147,18 @@ devicetree:
|
|||
if (target)
|
||||
merge_nodes(target, $3);
|
||||
else
|
||||
print_error("label or path, '%s', not found", $2);
|
||||
ERROR(&@2, "Label or path %s not found", $2);
|
||||
$$ = $1;
|
||||
}
|
||||
| devicetree DT_DEL_NODE DT_REF ';'
|
||||
{
|
||||
struct node *target = get_node_by_ref($1, $3);
|
||||
|
||||
if (!target)
|
||||
print_error("label or path, '%s', not found", $3);
|
||||
else
|
||||
if (target)
|
||||
delete_node(target);
|
||||
else
|
||||
ERROR(&@3, "Label or path %s not found", $3);
|
||||
|
||||
|
||||
$$ = $1;
|
||||
}
|
||||
|
@ -230,10 +226,9 @@ propdata:
|
|||
|
||||
if ($6 != 0)
|
||||
if (fseek(f, $6, SEEK_SET) != 0)
|
||||
print_error("Couldn't seek to offset %llu in \"%s\": %s",
|
||||
(unsigned long long)$6,
|
||||
$4.val,
|
||||
strerror(errno));
|
||||
die("Couldn't seek to offset %llu in \"%s\": %s",
|
||||
(unsigned long long)$6, $4.val,
|
||||
strerror(errno));
|
||||
|
||||
d = data_copy_file(f, $8);
|
||||
|
||||
|
@ -274,18 +269,19 @@ propdataprefix:
|
|||
arrayprefix:
|
||||
DT_BITS DT_LITERAL '<'
|
||||
{
|
||||
$$.data = empty_data;
|
||||
$$.bits = eval_literal($2, 0, 7);
|
||||
unsigned long long bits;
|
||||
|
||||
if (($$.bits != 8) &&
|
||||
($$.bits != 16) &&
|
||||
($$.bits != 32) &&
|
||||
($$.bits != 64))
|
||||
{
|
||||
print_error("Only 8, 16, 32 and 64-bit elements"
|
||||
" are currently supported");
|
||||
$$.bits = 32;
|
||||
bits = $2;
|
||||
|
||||
if ((bits != 8) && (bits != 16) &&
|
||||
(bits != 32) && (bits != 64)) {
|
||||
ERROR(&@2, "Array elements must be"
|
||||
" 8, 16, 32 or 64-bits");
|
||||
bits = 32;
|
||||
}
|
||||
|
||||
$$.data = empty_data;
|
||||
$$.bits = bits;
|
||||
}
|
||||
| '<'
|
||||
{
|
||||
|
@ -305,9 +301,8 @@ arrayprefix:
|
|||
* mask), all bits are one.
|
||||
*/
|
||||
if (($2 > mask) && (($2 | mask) != -1ULL))
|
||||
print_error(
|
||||
"integer value out of range "
|
||||
"%016lx (%d bits)", $1.bits);
|
||||
ERROR(&@2, "Value out of range for"
|
||||
" %d-bit array element", $1.bits);
|
||||
}
|
||||
|
||||
$$.data = data_append_integer($1.data, $2, $1.bits);
|
||||
|
@ -321,7 +316,7 @@ arrayprefix:
|
|||
REF_PHANDLE,
|
||||
$2);
|
||||
else
|
||||
print_error("References are only allowed in "
|
||||
ERROR(&@2, "References are only allowed in "
|
||||
"arrays with 32-bit elements.");
|
||||
|
||||
$$.data = data_append_integer($1.data, val, $1.bits);
|
||||
|
@ -334,13 +329,7 @@ arrayprefix:
|
|||
|
||||
integer_prim:
|
||||
DT_LITERAL
|
||||
{
|
||||
$$ = eval_literal($1, 0, 64);
|
||||
}
|
||||
| DT_CHAR_LITERAL
|
||||
{
|
||||
$$ = eval_char_literal($1);
|
||||
}
|
||||
| '(' integer_expr ')'
|
||||
{
|
||||
$$ = $2;
|
||||
|
@ -447,7 +436,7 @@ subnodes:
|
|||
}
|
||||
| subnode propdef
|
||||
{
|
||||
print_error("syntax error: properties must precede subnodes");
|
||||
ERROR(&@2, "Properties must precede subnodes");
|
||||
YYERROR;
|
||||
}
|
||||
;
|
||||
|
@ -470,63 +459,7 @@ subnode:
|
|||
|
||||
%%
|
||||
|
||||
void print_error(char const *fmt, ...)
|
||||
void yyerror(char const *s)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
srcpos_verror(&yylloc, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
treesource_error = 1;
|
||||
}
|
||||
|
||||
void yyerror(char const *s) {
|
||||
print_error("%s", s);
|
||||
}
|
||||
|
||||
static unsigned long long eval_literal(const char *s, int base, int bits)
|
||||
{
|
||||
unsigned long long val;
|
||||
char *e;
|
||||
|
||||
errno = 0;
|
||||
val = strtoull(s, &e, base);
|
||||
if (*e) {
|
||||
size_t uls = strspn(e, "UL");
|
||||
if (e[uls])
|
||||
print_error("bad characters in literal");
|
||||
}
|
||||
if ((errno == ERANGE)
|
||||
|| ((bits < 64) && (val >= (1ULL << bits))))
|
||||
print_error("literal out of range");
|
||||
else if (errno != 0)
|
||||
print_error("bad literal");
|
||||
return val;
|
||||
}
|
||||
|
||||
static unsigned char eval_char_literal(const char *s)
|
||||
{
|
||||
int i = 1;
|
||||
char c = s[0];
|
||||
|
||||
if (c == '\0')
|
||||
{
|
||||
print_error("empty character literal");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the first character in the character literal is a \ then process
|
||||
* the remaining characters as an escape encoding. If the first
|
||||
* character is neither an escape or a terminator it should be the only
|
||||
* character in the literal and will be returned.
|
||||
*/
|
||||
if (c == '\\')
|
||||
c = get_escape_char(s, &i);
|
||||
|
||||
if (s[i] != '\0')
|
||||
print_error("malformed character literal");
|
||||
|
||||
return c;
|
||||
ERROR(&yylloc, "%s", s);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#include "dtc.h"
|
||||
#include "srcpos.h"
|
||||
|
||||
#include "version_gen.h"
|
||||
|
||||
/*
|
||||
* Command line options
|
||||
*/
|
||||
|
@ -49,55 +47,62 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
|
|||
fill_fullpaths(child, tree->fullpath);
|
||||
}
|
||||
|
||||
static void __attribute__ ((noreturn)) usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, "\tdtc [options] <input file>\n");
|
||||
fprintf(stderr, "\nOptions:\n");
|
||||
fprintf(stderr, "\t-h\n");
|
||||
fprintf(stderr, "\t\tThis help text\n");
|
||||
fprintf(stderr, "\t-q\n");
|
||||
fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all\n");
|
||||
fprintf(stderr, "\t-I <input format>\n");
|
||||
fprintf(stderr, "\t\tInput formats are:\n");
|
||||
fprintf(stderr, "\t\t\tdts - device tree source text\n");
|
||||
fprintf(stderr, "\t\t\tdtb - device tree blob\n");
|
||||
fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory\n");
|
||||
fprintf(stderr, "\t-o <output file>\n");
|
||||
fprintf(stderr, "\t-O <output format>\n");
|
||||
fprintf(stderr, "\t\tOutput formats are:\n");
|
||||
fprintf(stderr, "\t\t\tdts - device tree source text\n");
|
||||
fprintf(stderr, "\t\t\tdtb - device tree blob\n");
|
||||
fprintf(stderr, "\t\t\tasm - assembler source\n");
|
||||
fprintf(stderr, "\t-V <output version>\n");
|
||||
fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION);
|
||||
fprintf(stderr, "\t-d <output dependency file>\n");
|
||||
fprintf(stderr, "\t-R <number>\n");
|
||||
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
|
||||
fprintf(stderr, "\t-S <bytes>\n");
|
||||
fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n");
|
||||
fprintf(stderr, "\t-p <bytes>\n");
|
||||
fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n");
|
||||
fprintf(stderr, "\t-b <number>\n");
|
||||
fprintf(stderr, "\t\tSet the physical boot cpu\n");
|
||||
fprintf(stderr, "\t-f\n");
|
||||
fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
|
||||
fprintf(stderr, "\t-i\n");
|
||||
fprintf(stderr, "\t\tAdd a path to search for include files\n");
|
||||
fprintf(stderr, "\t-s\n");
|
||||
fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
|
||||
fprintf(stderr, "\t-v\n");
|
||||
fprintf(stderr, "\t\tPrint DTC version and exit\n");
|
||||
fprintf(stderr, "\t-H <phandle format>\n");
|
||||
fprintf(stderr, "\t\tphandle formats are:\n");
|
||||
fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
|
||||
fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
|
||||
fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
|
||||
fprintf(stderr, "\t-W [no-]<checkname>\n");
|
||||
fprintf(stderr, "\t-E [no-]<checkname>\n");
|
||||
fprintf(stderr, "\t\t\tenable or disable warnings and errors\n");
|
||||
exit(3);
|
||||
}
|
||||
/* Usage related data. */
|
||||
#define FDT_VERSION(version) _FDT_VERSION(version)
|
||||
#define _FDT_VERSION(version) #version
|
||||
static const char usage_synopsis[] = "dtc [options] <input file>";
|
||||
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"in-format", a_argument, NULL, 'I'},
|
||||
{"out", a_argument, NULL, 'o'},
|
||||
{"out-format", a_argument, NULL, 'O'},
|
||||
{"out-version", a_argument, NULL, 'V'},
|
||||
{"out-dependency", a_argument, NULL, 'd'},
|
||||
{"reserve", a_argument, NULL, 'R'},
|
||||
{"space", a_argument, NULL, 'S'},
|
||||
{"pad", a_argument, NULL, 'p'},
|
||||
{"boot-cpu", a_argument, NULL, 'b'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"include", a_argument, NULL, 'i'},
|
||||
{"sort", no_argument, NULL, 's'},
|
||||
{"phandle", a_argument, NULL, 'H'},
|
||||
{"warning", a_argument, NULL, 'W'},
|
||||
{"error", a_argument, NULL, 'E'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, no_argument, NULL, 0x0},
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"\n\tQuiet: -q suppress warnings, -qq errors, -qqq all",
|
||||
"\n\tInput formats are:\n"
|
||||
"\t\tdts - device tree source text\n"
|
||||
"\t\tdtb - device tree blob\n"
|
||||
"\t\tfs - /proc/device-tree style directory",
|
||||
"\n\tOutput file",
|
||||
"\n\tOutput formats are:\n"
|
||||
"\t\tdts - device tree source text\n"
|
||||
"\t\tdtb - device tree blob\n"
|
||||
"\t\tasm - assembler source",
|
||||
"\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
|
||||
"\n\tOutput dependency file",
|
||||
"\n\tMake space for <number> reserve map entries (for dtb and asm output)",
|
||||
"\n\tMake the blob at least <bytes> long (extra space)",
|
||||
"\n\tAdd padding to the blob of <bytes> long (extra space)",
|
||||
"\n\tSet the physical boot cpu",
|
||||
"\n\tTry to produce output even if the input tree has errors",
|
||||
"\n\tAdd a path to search for include files",
|
||||
"\n\tSort nodes and properties before outputting (useful for comparing trees)",
|
||||
"\n\tValid phandle formats are:\n"
|
||||
"\t\tlegacy - \"linux,phandle\" properties only\n"
|
||||
"\t\tepapr - \"phandle\" properties only\n"
|
||||
"\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
|
||||
"\n\tEnable/disable warnings (prefix with \"no-\")",
|
||||
"\n\tEnable/disable errors (prefix with \"no-\")",
|
||||
"\n\tPrint this help and exit",
|
||||
"\n\tPrint version and exit",
|
||||
NULL,
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -106,7 +111,7 @@ int main(int argc, char *argv[])
|
|||
const char *outform = "dts";
|
||||
const char *outname = "-";
|
||||
const char *depname = NULL;
|
||||
int force = 0, sort = 0;
|
||||
bool force = false, sort = false;
|
||||
const char *arg;
|
||||
int opt;
|
||||
FILE *outf = NULL;
|
||||
|
@ -118,8 +123,7 @@ int main(int argc, char *argv[])
|
|||
minsize = 0;
|
||||
padsize = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fqb:i:vH:sW:E:"))
|
||||
!= EOF) {
|
||||
while ((opt = util_getopt_long()) != EOF) {
|
||||
switch (opt) {
|
||||
case 'I':
|
||||
inform = optarg;
|
||||
|
@ -146,7 +150,7 @@ int main(int argc, char *argv[])
|
|||
padsize = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 'f':
|
||||
force = 1;
|
||||
force = true;
|
||||
break;
|
||||
case 'q':
|
||||
quiet++;
|
||||
|
@ -158,8 +162,7 @@ int main(int argc, char *argv[])
|
|||
srcfile_add_search_path(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
printf("Version: %s\n", DTC_VERSION);
|
||||
exit(0);
|
||||
util_version();
|
||||
case 'H':
|
||||
if (streq(optarg, "legacy"))
|
||||
phandle_format = PHANDLE_LEGACY;
|
||||
|
@ -173,7 +176,7 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 's':
|
||||
sort = 1;
|
||||
sort = true;
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
|
@ -185,13 +188,14 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'h':
|
||||
usage(NULL);
|
||||
default:
|
||||
usage();
|
||||
usage("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > (optind+1))
|
||||
usage();
|
||||
usage("missing files");
|
||||
else if (argc < (optind+1))
|
||||
arg = "-";
|
||||
else
|
||||
|
@ -201,9 +205,6 @@ int main(int argc, char *argv[])
|
|||
if (minsize && padsize)
|
||||
die("Can't set both -p and -S\n");
|
||||
|
||||
if (minsize)
|
||||
fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n");
|
||||
|
||||
if (depname) {
|
||||
depfile = fopen(depname, "w");
|
||||
if (!depfile)
|
||||
|
@ -238,7 +239,7 @@ int main(int argc, char *argv[])
|
|||
if (streq(outname, "-")) {
|
||||
outf = stdout;
|
||||
} else {
|
||||
outf = fopen(outname, "w");
|
||||
outf = fopen(outname, "wb");
|
||||
if (! outf)
|
||||
die("Couldn't open output file %s: %s\n",
|
||||
outname, strerror(errno));
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
#include "util.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define debug(fmt,args...) printf(fmt, ##args)
|
||||
#define debug(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define debug(fmt,args...)
|
||||
#define debug(...)
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -66,7 +66,6 @@ typedef uint32_t cell_t;
|
|||
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
|
||||
|
||||
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/* Data blobs */
|
||||
enum markertype {
|
||||
|
@ -89,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) \
|
||||
for (; (m); (m) = (m)->next)
|
||||
|
@ -119,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);
|
||||
|
||||
int data_is_one_string(struct data d);
|
||||
bool data_is_one_string(struct data d);
|
||||
|
||||
/* DT constraints */
|
||||
|
||||
|
@ -128,13 +127,13 @@ int data_is_one_string(struct data d);
|
|||
|
||||
/* Live trees */
|
||||
struct label {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *label;
|
||||
struct label *next;
|
||||
};
|
||||
|
||||
struct property {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *name;
|
||||
struct data val;
|
||||
|
||||
|
@ -144,7 +143,7 @@ struct property {
|
|||
};
|
||||
|
||||
struct node {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *name;
|
||||
struct property *proplist;
|
||||
struct node *children;
|
||||
|
@ -248,8 +247,8 @@ void sort_tree(struct boot_info *bi);
|
|||
|
||||
/* Checks */
|
||||
|
||||
void parse_checks_option(bool warn, bool error, const char *optarg);
|
||||
void process_checks(int force, struct boot_info *bi);
|
||||
void parse_checks_option(bool warn, bool error, const char *arg);
|
||||
void process_checks(bool force, struct boot_info *bi);
|
||||
|
||||
/* Flattened trees */
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
const uint32_t *tagp, *lenp;
|
||||
const fdt32_t *tagp, *lenp;
|
||||
uint32_t tag;
|
||||
int offset = startoffset;
|
||||
const char *p;
|
||||
|
@ -198,6 +198,34 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
|
|||
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)
|
||||
{
|
||||
int len = strlen(s) + 1;
|
||||
|
|
|
@ -1,48 +1,99 @@
|
|||
#ifndef _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__
|
||||
|
||||
struct fdt_header {
|
||||
uint32_t magic; /* magic word FDT_MAGIC */
|
||||
uint32_t totalsize; /* total size of DT block */
|
||||
uint32_t off_dt_struct; /* offset to structure */
|
||||
uint32_t off_dt_strings; /* offset to strings */
|
||||
uint32_t off_mem_rsvmap; /* offset to memory reserve map */
|
||||
uint32_t version; /* format version */
|
||||
uint32_t last_comp_version; /* last compatible version */
|
||||
fdt32_t magic; /* magic word FDT_MAGIC */
|
||||
fdt32_t totalsize; /* total size of DT block */
|
||||
fdt32_t off_dt_struct; /* offset to structure */
|
||||
fdt32_t off_dt_strings; /* offset to strings */
|
||||
fdt32_t off_mem_rsvmap; /* offset to memory reserve map */
|
||||
fdt32_t version; /* format version */
|
||||
fdt32_t last_comp_version; /* last compatible version */
|
||||
|
||||
/* 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 */
|
||||
/* 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 */
|
||||
uint32_t size_dt_struct; /* size of the structure block */
|
||||
fdt32_t size_dt_struct; /* size of the structure block */
|
||||
};
|
||||
|
||||
struct fdt_reserve_entry {
|
||||
uint64_t address;
|
||||
uint64_t size;
|
||||
fdt64_t address;
|
||||
fdt64_t size;
|
||||
};
|
||||
|
||||
struct fdt_node_header {
|
||||
uint32_t tag;
|
||||
fdt32_t tag;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
struct fdt_property {
|
||||
uint32_t tag;
|
||||
uint32_t len;
|
||||
uint32_t nameoff;
|
||||
fdt32_t tag;
|
||||
fdt32_t len;
|
||||
fdt32_t nameoff;
|
||||
char data[0];
|
||||
};
|
||||
|
||||
#endif /* !__ASSEMBLY */
|
||||
|
||||
#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_END_NODE 0x2 /* End node */
|
||||
|
@ -51,10 +102,10 @@ struct fdt_property {
|
|||
#define FDT_NOP 0x4 /* nop */
|
||||
#define FDT_END 0x9
|
||||
|
||||
#define FDT_V1_SIZE (7*sizeof(uint32_t))
|
||||
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(uint32_t))
|
||||
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(uint32_t))
|
||||
#define FDT_V1_SIZE (7*sizeof(fdt32_t))
|
||||
#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t))
|
||||
#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))
|
||||
#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 */
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
|
||||
*
|
||||
* 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 "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
int fdt_address_cells(const void *fdt, int nodeoffset)
|
||||
{
|
||||
const fdt32_t *ac;
|
||||
int val;
|
||||
int len;
|
||||
|
||||
ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
|
||||
if (!ac)
|
||||
return 2;
|
||||
|
||||
if (len != sizeof(*ac))
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
val = fdt32_to_cpu(*ac);
|
||||
if ((val <= 0) || (val > FDT_MAX_NCELLS))
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int fdt_size_cells(const void *fdt, int nodeoffset)
|
||||
{
|
||||
const fdt32_t *sc;
|
||||
int val;
|
||||
int len;
|
||||
|
||||
sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
|
||||
if (!sc)
|
||||
return 2;
|
||||
|
||||
if (len != sizeof(*sc))
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
val = fdt32_to_cpu(*sc);
|
||||
if ((val < 0) || (val > FDT_MAX_NCELLS))
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
return val;
|
||||
}
|
|
@ -322,7 +322,7 @@ const void *fdt_getprop(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;
|
||||
|
||||
/* FIXME: This is a bit sub-optimal, since we potentially scan
|
||||
|
@ -515,8 +515,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
|
|||
return offset; /* error from fdt_next_node() */
|
||||
}
|
||||
|
||||
static int _fdt_stringlist_contains(const char *strlist, int listlen,
|
||||
const char *str)
|
||||
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
const char *p;
|
||||
|
@ -542,7 +541,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
|
|||
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
|
||||
if (!prop)
|
||||
return len;
|
||||
if (_fdt_stringlist_contains(prop, len, compatible))
|
||||
if (fdt_stringlist_contains(prop, len, compatible))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
|
|
|
@ -84,9 +84,9 @@ static int _fdt_rw_check_header(void *fdt)
|
|||
|
||||
#define FDT_RW_CHECK_HEADER(fdt) \
|
||||
{ \
|
||||
int err; \
|
||||
if ((err = _fdt_rw_check_header(fdt)) != 0) \
|
||||
return err; \
|
||||
int __err; \
|
||||
if ((__err = _fdt_rw_check_header(fdt)) != 0) \
|
||||
return __err; \
|
||||
}
|
||||
|
||||
static inline int _fdt_data_size(void *fdt)
|
||||
|
@ -339,7 +339,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
|||
int nodelen;
|
||||
int err;
|
||||
uint32_t tag;
|
||||
uint32_t *endtag;
|
||||
fdt32_t *endtag;
|
||||
|
||||
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);
|
||||
memset(nh->name, 0, FDT_TAGALIGN(namelen+1));
|
||||
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);
|
||||
|
||||
return offset;
|
||||
|
|
|
@ -107,6 +107,38 @@ int fdt_create(void *buf, int bufsize)
|
|||
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)
|
||||
{
|
||||
struct fdt_reserve_entry *re;
|
||||
|
@ -153,7 +185,7 @@ int fdt_begin_node(void *fdt, const char *name)
|
|||
|
||||
int fdt_end_node(void *fdt)
|
||||
{
|
||||
uint32_t *en;
|
||||
fdt32_t *en;
|
||||
|
||||
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)
|
||||
{
|
||||
char *p = (char *)fdt;
|
||||
uint32_t *end;
|
||||
fdt32_t *end;
|
||||
int oldstroffset, newstroffset;
|
||||
uint32_t tag;
|
||||
int offset, nextoffset;
|
||||
|
|
|
@ -74,7 +74,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
|
|||
|
||||
static void _fdt_nop_region(void *start, int len)
|
||||
{
|
||||
uint32_t *p;
|
||||
fdt32_t *p;
|
||||
|
||||
for (p = start; (char *)p < ((char *)start + len); p++)
|
||||
*p = cpu_to_fdt32(FDT_NOP);
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
* fdtdump.c - Contributed by Pantelis Antoniou <pantelis.antoniou AT gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
#include <libfdt_env.h>
|
||||
#include <fdt.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -17,33 +19,29 @@
|
|||
#define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
|
||||
#define GET_CELL(p) (p += 4, *((const uint32_t *)(p-4)))
|
||||
|
||||
static void print_data(const char *data, int len)
|
||||
static const char *tagname(uint32_t tag)
|
||||
{
|
||||
int i;
|
||||
const char *p = data;
|
||||
|
||||
/* no data, don't print */
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (util_is_printable_string(data, len)) {
|
||||
printf(" = \"%s\"", (const char *)data);
|
||||
} else if ((len % 4) == 0) {
|
||||
printf(" = <");
|
||||
for (i = 0; i < len; i += 4)
|
||||
printf("0x%08x%s", fdt32_to_cpu(GET_CELL(p)),
|
||||
i < (len - 4) ? " " : "");
|
||||
printf(">");
|
||||
} else {
|
||||
printf(" = [");
|
||||
for (i = 0; i < len; i++)
|
||||
printf("%02x%s", *p++, i < len - 1 ? " " : "");
|
||||
printf("]");
|
||||
}
|
||||
static const char * const names[] = {
|
||||
#define TN(t) [t] = #t
|
||||
TN(FDT_BEGIN_NODE),
|
||||
TN(FDT_END_NODE),
|
||||
TN(FDT_PROP),
|
||||
TN(FDT_NOP),
|
||||
TN(FDT_END),
|
||||
#undef TN
|
||||
};
|
||||
if (tag < ARRAY_SIZE(names))
|
||||
if (names[tag])
|
||||
return names[tag];
|
||||
return "FDT_???";
|
||||
}
|
||||
|
||||
static void dump_blob(void *blob)
|
||||
#define dumpf(fmt, args...) \
|
||||
do { if (debug) printf("// " fmt, ## args); } while (0)
|
||||
|
||||
static void dump_blob(void *blob, bool debug)
|
||||
{
|
||||
uintptr_t blob_off = (uintptr_t)blob;
|
||||
struct fdt_header *bph = blob;
|
||||
uint32_t off_mem_rsvmap = fdt32_to_cpu(bph->off_mem_rsvmap);
|
||||
uint32_t off_dt = fdt32_to_cpu(bph->off_dt_struct);
|
||||
|
@ -90,14 +88,15 @@ static void dump_blob(void *blob)
|
|||
if (addr == 0 && size == 0)
|
||||
break;
|
||||
|
||||
printf("/memreserve/ %llx %llx;\n",
|
||||
printf("/memreserve/ %#llx %#llx;\n",
|
||||
(unsigned long long)addr, (unsigned long long)size);
|
||||
}
|
||||
|
||||
p = p_struct;
|
||||
while ((tag = fdt32_to_cpu(GET_CELL(p))) != FDT_END) {
|
||||
|
||||
/* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
|
||||
dumpf("%04zx: tag: 0x%08x (%s)\n",
|
||||
(uintptr_t)p - blob_off - 4, tag, tagname(tag));
|
||||
|
||||
if (tag == FDT_BEGIN_NODE) {
|
||||
s = p;
|
||||
|
@ -136,27 +135,93 @@ static void dump_blob(void *blob)
|
|||
|
||||
p = PALIGN(p + sz, 4);
|
||||
|
||||
dumpf("%04zx: string: %s\n", (uintptr_t)s - blob_off, s);
|
||||
dumpf("%04zx: value\n", (uintptr_t)t - blob_off);
|
||||
printf("%*s%s", depth * shift, "", s);
|
||||
print_data(t, sz);
|
||||
utilfdt_print_data(t, sz);
|
||||
printf(";\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] = "fdtdump [options] <file>";
|
||||
static const char usage_short_opts[] = "ds" USAGE_COMMON_SHORT_OPTS;
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"debug", no_argument, NULL, 'd'},
|
||||
{"scan", no_argument, NULL, 's'},
|
||||
USAGE_COMMON_LONG_OPTS
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"Dump debug information while decoding the file",
|
||||
"Scan for an embedded fdt in file",
|
||||
USAGE_COMMON_OPTS_HELP
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
const char *file;
|
||||
char *buf;
|
||||
bool debug = false;
|
||||
bool scan = false;
|
||||
off_t len;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "supply input filename\n");
|
||||
return 5;
|
||||
while ((opt = util_getopt_long()) != EOF) {
|
||||
switch (opt) {
|
||||
case_USAGE_COMMON_FLAGS
|
||||
|
||||
case 'd':
|
||||
debug = true;
|
||||
break;
|
||||
case 's':
|
||||
scan = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (optind != argc - 1)
|
||||
usage("missing input filename");
|
||||
file = argv[optind];
|
||||
|
||||
buf = utilfdt_read_len(file, &len);
|
||||
if (!buf)
|
||||
die("could not read: %s\n", file);
|
||||
|
||||
/* try and locate an embedded fdt in a bigger blob */
|
||||
if (scan) {
|
||||
unsigned char smagic[4];
|
||||
char *p = buf;
|
||||
char *endp = buf + len;
|
||||
|
||||
fdt_set_magic(smagic, FDT_MAGIC);
|
||||
|
||||
/* poor man's memmem */
|
||||
while (true) {
|
||||
p = memchr(p, smagic[0], endp - p - 4);
|
||||
if (!p)
|
||||
break;
|
||||
if (fdt_magic(p) == FDT_MAGIC) {
|
||||
/* try and validate the main struct */
|
||||
off_t this_len = endp - p;
|
||||
fdt32_t max_version = 17;
|
||||
if (fdt_version(p) <= max_version &&
|
||||
fdt_last_comp_version(p) < max_version &&
|
||||
fdt_totalsize(p) < this_len &&
|
||||
fdt_off_dt_struct(p) < this_len &&
|
||||
fdt_off_dt_strings(p) < this_len)
|
||||
break;
|
||||
if (debug)
|
||||
printf("%s: skipping fdt magic at offset %#zx\n",
|
||||
file, p - buf);
|
||||
}
|
||||
++p;
|
||||
}
|
||||
if (!p)
|
||||
die("%s: could not locate fdt magic\n", file);
|
||||
printf("%s: found fdt at offset %#zx\n", file, p - buf);
|
||||
buf = p;
|
||||
}
|
||||
|
||||
buf = utilfdt_read(argv[1]);
|
||||
if (buf)
|
||||
dump_blob(buf);
|
||||
else
|
||||
return 10;
|
||||
dump_blob(buf, debug);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -277,33 +277,33 @@ static int do_fdtget(struct display_info *disp, const char *filename,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *usage_msg =
|
||||
"fdtget - read values from device tree\n"
|
||||
"\n"
|
||||
"Each value is printed on a new line.\n\n"
|
||||
"Usage:\n"
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] =
|
||||
"read values from device tree\n"
|
||||
" fdtget <options> <dt file> [<node> <property>]...\n"
|
||||
" fdtget -p <options> <dt file> [<node> ]...\n"
|
||||
"Options:\n"
|
||||
"\t-t <type>\tType of data\n"
|
||||
"\t-p\t\tList properties for each node\n"
|
||||
"\t-l\t\tList subnodes for each node\n"
|
||||
"\t-d\t\tDefault value to display when the property is "
|
||||
"missing\n"
|
||||
"\t-h\t\tPrint this help\n\n"
|
||||
"\n"
|
||||
"Each value is printed on a new line.\n"
|
||||
USAGE_TYPE_MSG;
|
||||
|
||||
static void usage(const char *msg)
|
||||
{
|
||||
if (msg)
|
||||
fprintf(stderr, "Error: %s\n\n", msg);
|
||||
|
||||
fprintf(stderr, "%s", usage_msg);
|
||||
exit(2);
|
||||
}
|
||||
static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"type", a_argument, NULL, 't'},
|
||||
{"properties", no_argument, NULL, 'p'},
|
||||
{"list", no_argument, NULL, 'l'},
|
||||
{"default", a_argument, NULL, 'd'},
|
||||
USAGE_COMMON_LONG_OPTS,
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"Type of data",
|
||||
"List properties for each node",
|
||||
"List subnodes for each node",
|
||||
"Default value to display when the property is missing",
|
||||
USAGE_COMMON_OPTS_HELP
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
char *filename = NULL;
|
||||
struct display_info disp;
|
||||
int args_per_step = 2;
|
||||
|
@ -312,20 +312,14 @@ int main(int argc, char *argv[])
|
|||
memset(&disp, '\0', sizeof(disp));
|
||||
disp.size = -1;
|
||||
disp.mode = MODE_SHOW_VALUE;
|
||||
for (;;) {
|
||||
int c = getopt(argc, argv, "d:hlpt:");
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
case '?':
|
||||
usage(NULL);
|
||||
while ((opt = util_getopt_long()) != EOF) {
|
||||
switch (opt) {
|
||||
case_USAGE_COMMON_FLAGS
|
||||
|
||||
case 't':
|
||||
if (utilfdt_decode_type(optarg, &disp.type,
|
||||
&disp.size))
|
||||
usage("Invalid type string");
|
||||
usage("invalid type string");
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
@ -347,7 +341,7 @@ int main(int argc, char *argv[])
|
|||
if (optind < argc)
|
||||
filename = argv[optind++];
|
||||
if (!filename)
|
||||
usage("Missing filename");
|
||||
usage("missing filename");
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
@ -358,7 +352,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Check for node, property arguments */
|
||||
if (args_per_step == 2 && (argc % 2))
|
||||
usage("Must have an even number of arguments");
|
||||
usage("must have an even number of arguments");
|
||||
|
||||
if (do_fdtget(&disp, filename, argv, argc, args_per_step))
|
||||
return 1;
|
||||
|
|
|
@ -96,12 +96,7 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
|
|||
/* enlarge our value buffer by a suitable margin if needed */
|
||||
if (upto + len > value_size) {
|
||||
value_size = (upto + len) + 500;
|
||||
value = realloc(value, value_size);
|
||||
if (!value) {
|
||||
fprintf(stderr, "Out of mmory: cannot alloc "
|
||||
"%d bytes\n", value_size);
|
||||
return -1;
|
||||
}
|
||||
value = xrealloc(value, value_size);
|
||||
}
|
||||
|
||||
ptr = value + upto;
|
||||
|
@ -131,19 +126,59 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int store_key_value(void *blob, const char *node_name,
|
||||
#define ALIGN(x) (((x) + (FDT_TAGSIZE) - 1) & ~((FDT_TAGSIZE) - 1))
|
||||
|
||||
static char *_realloc_fdt(char *fdt, int delta)
|
||||
{
|
||||
int new_sz = fdt_totalsize(fdt) + delta;
|
||||
fdt = xrealloc(fdt, new_sz);
|
||||
fdt_open_into(fdt, fdt, new_sz);
|
||||
return fdt;
|
||||
}
|
||||
|
||||
static char *realloc_node(char *fdt, const char *name)
|
||||
{
|
||||
int delta;
|
||||
/* FDT_BEGIN_NODE, node name in off_struct and FDT_END_NODE */
|
||||
delta = sizeof(struct fdt_node_header) + ALIGN(strlen(name) + 1)
|
||||
+ FDT_TAGSIZE;
|
||||
return _realloc_fdt(fdt, delta);
|
||||
}
|
||||
|
||||
static char *realloc_property(char *fdt, int nodeoffset,
|
||||
const char *name, int newlen)
|
||||
{
|
||||
int delta = 0;
|
||||
int oldlen = 0;
|
||||
|
||||
if (!fdt_get_property(fdt, nodeoffset, name, &oldlen))
|
||||
/* strings + property header */
|
||||
delta = sizeof(struct fdt_property) + strlen(name) + 1;
|
||||
|
||||
if (newlen > oldlen)
|
||||
/* actual value in off_struct */
|
||||
delta += ALIGN(newlen) - ALIGN(oldlen);
|
||||
|
||||
return _realloc_fdt(fdt, delta);
|
||||
}
|
||||
|
||||
static int store_key_value(char **blob, const char *node_name,
|
||||
const char *property, const char *buf, int len)
|
||||
{
|
||||
int node;
|
||||
int err;
|
||||
|
||||
node = fdt_path_offset(blob, node_name);
|
||||
node = fdt_path_offset(*blob, node_name);
|
||||
if (node < 0) {
|
||||
report_error(node_name, -1, node);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = fdt_setprop(blob, node, property, buf, len);
|
||||
err = fdt_setprop(*blob, node, property, buf, len);
|
||||
if (err == -FDT_ERR_NOSPACE) {
|
||||
*blob = realloc_property(*blob, node, property, len);
|
||||
err = fdt_setprop(*blob, node, property, buf, len);
|
||||
}
|
||||
if (err) {
|
||||
report_error(property, -1, err);
|
||||
return -1;
|
||||
|
@ -161,7 +196,7 @@ static int store_key_value(void *blob, const char *node_name,
|
|||
* @param in_path Path to process
|
||||
* @return 0 if ok, -1 on error
|
||||
*/
|
||||
static int create_paths(void *blob, const char *in_path)
|
||||
static int create_paths(char **blob, const char *in_path)
|
||||
{
|
||||
const char *path = in_path;
|
||||
const char *sep;
|
||||
|
@ -177,10 +212,11 @@ static int create_paths(void *blob, const char *in_path)
|
|||
if (!sep)
|
||||
sep = path + strlen(path);
|
||||
|
||||
node = fdt_subnode_offset_namelen(blob, offset, path,
|
||||
node = fdt_subnode_offset_namelen(*blob, offset, path,
|
||||
sep - path);
|
||||
if (node == -FDT_ERR_NOTFOUND) {
|
||||
node = fdt_add_subnode_namelen(blob, offset, path,
|
||||
*blob = realloc_node(*blob, path);
|
||||
node = fdt_add_subnode_namelen(*blob, offset, path,
|
||||
sep - path);
|
||||
}
|
||||
if (node < 0) {
|
||||
|
@ -203,7 +239,7 @@ static int create_paths(void *blob, const char *in_path)
|
|||
* @param node_name Name of node to create
|
||||
* @return new node offset if found, or -1 on failure
|
||||
*/
|
||||
static int create_node(void *blob, const char *node_name)
|
||||
static int create_node(char **blob, const char *node_name)
|
||||
{
|
||||
int node = 0;
|
||||
char *p;
|
||||
|
@ -215,15 +251,17 @@ static int create_node(void *blob, const char *node_name)
|
|||
}
|
||||
*p = '\0';
|
||||
|
||||
*blob = realloc_node(*blob, p + 1);
|
||||
|
||||
if (p > node_name) {
|
||||
node = fdt_path_offset(blob, node_name);
|
||||
node = fdt_path_offset(*blob, node_name);
|
||||
if (node < 0) {
|
||||
report_error(node_name, -1, node);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
node = fdt_add_subnode(blob, node, p + 1);
|
||||
node = fdt_add_subnode(*blob, node, p + 1);
|
||||
if (node < 0) {
|
||||
report_error(p + 1, -1, node);
|
||||
return -1;
|
||||
|
@ -250,66 +288,64 @@ static int do_fdtput(struct display_info *disp, const char *filename,
|
|||
* store them into the property.
|
||||
*/
|
||||
assert(arg_count >= 2);
|
||||
if (disp->auto_path && create_paths(blob, *arg))
|
||||
if (disp->auto_path && create_paths(&blob, *arg))
|
||||
return -1;
|
||||
if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
|
||||
store_key_value(blob, *arg, arg[1], value, len))
|
||||
store_key_value(&blob, *arg, arg[1], value, len))
|
||||
ret = -1;
|
||||
break;
|
||||
case OPER_CREATE_NODE:
|
||||
for (; ret >= 0 && arg_count--; arg++) {
|
||||
if (disp->auto_path)
|
||||
ret = create_paths(blob, *arg);
|
||||
ret = create_paths(&blob, *arg);
|
||||
else
|
||||
ret = create_node(blob, *arg);
|
||||
ret = create_node(&blob, *arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ret >= 0)
|
||||
if (ret >= 0) {
|
||||
fdt_pack(blob);
|
||||
ret = utilfdt_write(filename, blob);
|
||||
}
|
||||
|
||||
free(blob);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *usage_msg =
|
||||
"fdtput - write a property value to a device tree\n"
|
||||
"\n"
|
||||
"The command line arguments are joined together into a single value.\n"
|
||||
"\n"
|
||||
"Usage:\n"
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] =
|
||||
"write a property value to a device tree\n"
|
||||
" fdtput <options> <dt file> <node> <property> [<value>...]\n"
|
||||
" fdtput -c <options> <dt file> [<node>...]\n"
|
||||
"Options:\n"
|
||||
"\t-c\t\tCreate nodes if they don't already exist\n"
|
||||
"\t-p\t\tAutomatically create nodes as needed for the node path\n"
|
||||
"\t-t <type>\tType of data\n"
|
||||
"\t-v\t\tVerbose: display each value decoded from command line\n"
|
||||
"\t-h\t\tPrint this help\n\n"
|
||||
"\n"
|
||||
"The command line arguments are joined together into a single value.\n"
|
||||
USAGE_TYPE_MSG;
|
||||
|
||||
static void usage(const char *msg)
|
||||
{
|
||||
if (msg)
|
||||
fprintf(stderr, "Error: %s\n\n", msg);
|
||||
|
||||
fprintf(stderr, "%s", usage_msg);
|
||||
exit(2);
|
||||
}
|
||||
static const char usage_short_opts[] = "cpt:v" USAGE_COMMON_SHORT_OPTS;
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"create", no_argument, NULL, 'c'},
|
||||
{"auto-path", no_argument, NULL, 'p'},
|
||||
{"type", a_argument, NULL, 't'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
USAGE_COMMON_LONG_OPTS,
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"Create nodes if they don't already exist",
|
||||
"Automatically create nodes as needed for the node path",
|
||||
"Type of data",
|
||||
"Display each value decoded from command line",
|
||||
USAGE_COMMON_OPTS_HELP
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
struct display_info disp;
|
||||
char *filename = NULL;
|
||||
|
||||
memset(&disp, '\0', sizeof(disp));
|
||||
disp.size = -1;
|
||||
disp.oper = OPER_WRITE_PROP;
|
||||
for (;;) {
|
||||
int c = getopt(argc, argv, "chpt:v");
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
while ((opt = util_getopt_long()) != EOF) {
|
||||
/*
|
||||
* TODO: add options to:
|
||||
* - delete property
|
||||
|
@ -317,15 +353,13 @@ int main(int argc, char *argv[])
|
|||
* - rename node
|
||||
* - pack fdt before writing
|
||||
* - set amount of free space when writing
|
||||
* - expand fdt if value doesn't fit
|
||||
*/
|
||||
switch (c) {
|
||||
switch (opt) {
|
||||
case_USAGE_COMMON_FLAGS
|
||||
|
||||
case 'c':
|
||||
disp.oper = OPER_CREATE_NODE;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage(NULL);
|
||||
case 'p':
|
||||
disp.auto_path = 1;
|
||||
break;
|
||||
|
@ -344,16 +378,16 @@ int main(int argc, char *argv[])
|
|||
if (optind < argc)
|
||||
filename = argv[optind++];
|
||||
if (!filename)
|
||||
usage("Missing filename");
|
||||
usage("missing filename");
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (disp.oper == OPER_WRITE_PROP) {
|
||||
if (argc < 1)
|
||||
usage("Missing node");
|
||||
usage("missing node");
|
||||
if (argc < 2)
|
||||
usage("Missing property");
|
||||
usage("missing property");
|
||||
}
|
||||
|
||||
if (do_fdtput(&disp, filename, argv, argc))
|
||||
|
|
|
@ -261,7 +261,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
|||
{
|
||||
struct property *prop;
|
||||
struct node *child;
|
||||
int seen_name_prop = 0;
|
||||
bool seen_name_prop = false;
|
||||
|
||||
if (tree->deleted)
|
||||
return;
|
||||
|
@ -279,7 +279,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
|||
int nameoff;
|
||||
|
||||
if (streq(prop->name, "name"))
|
||||
seen_name_prop = 1;
|
||||
seen_name_prop = true;
|
||||
|
||||
nameoff = stringtable_insert(strbuf, prop->name);
|
||||
|
||||
|
|
|
@ -37,26 +37,26 @@ static struct node *read_fstree(const char *dirname)
|
|||
tree = build_node(NULL, NULL);
|
||||
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
char *tmpnam;
|
||||
char *tmpname;
|
||||
|
||||
if (streq(de->d_name, ".")
|
||||
|| streq(de->d_name, ".."))
|
||||
continue;
|
||||
|
||||
tmpnam = join_path(dirname, de->d_name);
|
||||
tmpname = join_path(dirname, de->d_name);
|
||||
|
||||
if (lstat(tmpnam, &st) < 0)
|
||||
die("stat(%s): %s\n", tmpnam, strerror(errno));
|
||||
if (lstat(tmpname, &st) < 0)
|
||||
die("stat(%s): %s\n", tmpname, strerror(errno));
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
struct property *prop;
|
||||
FILE *pfile;
|
||||
|
||||
pfile = fopen(tmpnam, "r");
|
||||
pfile = fopen(tmpname, "rb");
|
||||
if (! pfile) {
|
||||
fprintf(stderr,
|
||||
"WARNING: Cannot open %s: %s\n",
|
||||
tmpnam, strerror(errno));
|
||||
tmpname, strerror(errno));
|
||||
} else {
|
||||
prop = build_property(xstrdup(de->d_name),
|
||||
data_copy_file(pfile,
|
||||
|
@ -67,12 +67,12 @@ static struct node *read_fstree(const char *dirname)
|
|||
} else if (S_ISDIR(st.st_mode)) {
|
||||
struct node *newchild;
|
||||
|
||||
newchild = read_fstree(tmpnam);
|
||||
newchild = read_fstree(tmpname);
|
||||
newchild = name_node(newchild, xstrdup(de->d_name));
|
||||
add_child(tree, newchild);
|
||||
}
|
||||
|
||||
free(tmpnam);
|
||||
free(tmpname);
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
|
|
|
@ -116,7 +116,12 @@
|
|||
* Should never be returned, if it is, it indicates a bug in
|
||||
* 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) */
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
/**********************************************************************/
|
||||
|
@ -582,7 +609,7 @@ const char *fdt_get_alias_namelen(const void *fdt,
|
|||
* value of the property named 'name' in the node /aliases.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
const char *fdt_get_alias(const void *fdt, const char *name);
|
||||
|
@ -816,6 +843,75 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
|
|||
int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
||||
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 */
|
||||
/**********************************************************************/
|
||||
|
@ -882,8 +978,8 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
|
|||
static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
|
||||
const char *name, uint32_t val)
|
||||
{
|
||||
val = cpu_to_fdt32(val);
|
||||
return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt32_t tmp = cpu_to_fdt32(val);
|
||||
return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -917,8 +1013,8 @@ static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
|
|||
static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
|
||||
const char *name, uint64_t val)
|
||||
{
|
||||
val = cpu_to_fdt64(val);
|
||||
return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt64_t tmp = cpu_to_fdt64(val);
|
||||
return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -987,19 +1083,20 @@ int fdt_nop_node(void *fdt, int nodeoffset);
|
|||
/**********************************************************************/
|
||||
|
||||
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_finish_reservemap(void *fdt);
|
||||
int fdt_begin_node(void *fdt, const char *name);
|
||||
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)
|
||||
{
|
||||
val = cpu_to_fdt32(val);
|
||||
return fdt_property(fdt, name, &val, sizeof(val));
|
||||
fdt32_t tmp = cpu_to_fdt32(val);
|
||||
return fdt_property(fdt, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
|
||||
{
|
||||
val = cpu_to_fdt64(val);
|
||||
return fdt_property(fdt, name, &val, sizeof(val));
|
||||
fdt64_t tmp = cpu_to_fdt64(val);
|
||||
return fdt_property(fdt, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
|
||||
{
|
||||
|
@ -1154,8 +1251,8 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
|||
static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
|
||||
uint32_t val)
|
||||
{
|
||||
val = cpu_to_fdt32(val);
|
||||
return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt32_t tmp = cpu_to_fdt32(val);
|
||||
return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1189,8 +1286,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,
|
||||
uint64_t val)
|
||||
{
|
||||
val = cpu_to_fdt64(val);
|
||||
return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt64_t tmp = cpu_to_fdt64(val);
|
||||
return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1296,8 +1393,8 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
|
|||
static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
|
||||
const char *name, uint32_t val)
|
||||
{
|
||||
val = cpu_to_fdt32(val);
|
||||
return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt32_t tmp = cpu_to_fdt32(val);
|
||||
return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1331,8 +1428,8 @@ static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
|
|||
static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
|
||||
const char *name, uint64_t val)
|
||||
{
|
||||
val = cpu_to_fdt64(val);
|
||||
return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
|
||||
fdt64_t tmp = cpu_to_fdt64(val);
|
||||
return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,29 +1,111 @@
|
|||
#ifndef _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 <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define EXTRACT_BYTE(n) ((unsigned long long)((uint8_t *)&x)[n])
|
||||
static inline uint16_t fdt16_to_cpu(uint16_t x)
|
||||
{
|
||||
return (EXTRACT_BYTE(0) << 8) | EXTRACT_BYTE(1);
|
||||
}
|
||||
#define cpu_to_fdt16(x) fdt16_to_cpu(x)
|
||||
#ifdef __CHECKER__
|
||||
#define __force __attribute__((force))
|
||||
#define __bitwise __attribute__((bitwise))
|
||||
#else
|
||||
#define __force
|
||||
#define __bitwise
|
||||
#endif
|
||||
|
||||
static inline uint32_t fdt32_to_cpu(uint32_t x)
|
||||
{
|
||||
return (EXTRACT_BYTE(0) << 24) | (EXTRACT_BYTE(1) << 16) | (EXTRACT_BYTE(2) << 8) | EXTRACT_BYTE(3);
|
||||
}
|
||||
#define cpu_to_fdt32(x) fdt32_to_cpu(x)
|
||||
typedef uint16_t __bitwise fdt16_t;
|
||||
typedef uint32_t __bitwise fdt32_t;
|
||||
typedef uint64_t __bitwise fdt64_t;
|
||||
|
||||
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)
|
||||
| (EXTRACT_BYTE(4) << 24) | (EXTRACT_BYTE(5) << 16) | (EXTRACT_BYTE(6) << 8) | EXTRACT_BYTE(7);
|
||||
return (__force uint16_t)CPU_TO_FDT16(x);
|
||||
}
|
||||
#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
|
||||
|
||||
#endif /* _LIBFDT_ENV_H */
|
||||
|
|
|
@ -57,9 +57,9 @@
|
|||
|
||||
#define FDT_CHECK_HEADER(fdt) \
|
||||
{ \
|
||||
int err; \
|
||||
if ((err = fdt_check_header(fdt)) != 0) \
|
||||
return err; \
|
||||
int __err; \
|
||||
if ((__err = fdt_check_header(fdt)) != 0) \
|
||||
return __err; \
|
||||
}
|
||||
|
||||
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)
|
|||
|
||||
struct node *get_node_by_ref(struct node *tree, const char *ref)
|
||||
{
|
||||
if (ref[0] == '/')
|
||||
if (streq(ref, "/"))
|
||||
return tree;
|
||||
else if (ref[0] == '/')
|
||||
return get_node_by_path(tree, ref);
|
||||
else
|
||||
return get_node_by_label(tree, ref);
|
||||
|
|
|
@ -34,7 +34,7 @@ struct search_path {
|
|||
static struct search_path *search_path_head, **search_path_tail;
|
||||
|
||||
|
||||
static char *dirname(const char *path)
|
||||
static char *get_dirname(const char *path)
|
||||
{
|
||||
const char *slash = strrchr(path, '/');
|
||||
|
||||
|
@ -77,7 +77,7 @@ static char *try_open(const char *dirname, const char *fname, FILE **fp)
|
|||
else
|
||||
fullname = join_path(dirname, fname);
|
||||
|
||||
*fp = fopen(fullname, "r");
|
||||
*fp = fopen(fullname, "rb");
|
||||
if (!*fp) {
|
||||
free(fullname);
|
||||
fullname = NULL;
|
||||
|
@ -150,7 +150,7 @@ void srcfile_push(const char *fname)
|
|||
srcfile = xmalloc(sizeof(*srcfile));
|
||||
|
||||
srcfile->f = srcfile_relative_open(fname, &srcfile->name);
|
||||
srcfile->dir = dirname(srcfile->name);
|
||||
srcfile->dir = get_dirname(srcfile->name);
|
||||
srcfile->prev = current_srcfile;
|
||||
|
||||
srcfile->lineno = 1;
|
||||
|
@ -159,7 +159,7 @@ void srcfile_push(const char *fname)
|
|||
current_srcfile = srcfile;
|
||||
}
|
||||
|
||||
int srcfile_pop(void)
|
||||
bool srcfile_pop(void)
|
||||
{
|
||||
struct srcfile_state *srcfile = current_srcfile;
|
||||
|
||||
|
@ -177,7 +177,7 @@ int srcfile_pop(void)
|
|||
* fix this we could either allocate all the files from a
|
||||
* table, or use a pool allocator. */
|
||||
|
||||
return current_srcfile ? 1 : 0;
|
||||
return current_srcfile ? true : false;
|
||||
}
|
||||
|
||||
void srcfile_add_search_path(const char *dirname)
|
||||
|
@ -290,42 +290,27 @@ srcpos_string(struct srcpos *pos)
|
|||
return pos_str;
|
||||
}
|
||||
|
||||
void
|
||||
srcpos_verror(struct srcpos *pos, char const *fmt, va_list va)
|
||||
void srcpos_verror(struct srcpos *pos, const char *prefix,
|
||||
const char *fmt, va_list va)
|
||||
{
|
||||
const char *srcstr;
|
||||
|
||||
srcstr = srcpos_string(pos);
|
||||
|
||||
fprintf(stdout, "Error: %s ", srcstr);
|
||||
vfprintf(stdout, fmt, va);
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
srcpos_error(struct srcpos *pos, char const *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
srcpos_verror(pos, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
srcpos_warn(struct srcpos *pos, char const *fmt, ...)
|
||||
{
|
||||
const char *srcstr;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
char *srcstr;
|
||||
|
||||
srcstr = srcpos_string(pos);
|
||||
|
||||
fprintf(stderr, "Warning: %s ", srcstr);
|
||||
fprintf(stderr, "%s: %s ", prefix, srcstr);
|
||||
vfprintf(stderr, fmt, va);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
free(srcstr);
|
||||
}
|
||||
|
||||
void srcpos_error(struct srcpos *pos, const char *prefix,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
srcpos_verror(pos, prefix, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define _SRCPOS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct srcfile_state {
|
||||
FILE *f;
|
||||
|
@ -55,7 +56,7 @@ extern struct srcfile_state *current_srcfile; /* = NULL */
|
|||
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
|
||||
|
||||
void srcfile_push(const char *fname);
|
||||
int srcfile_pop(void);
|
||||
bool srcfile_pop(void);
|
||||
|
||||
/**
|
||||
* Add a new directory to the search path for input files
|
||||
|
@ -106,12 +107,12 @@ extern struct srcpos *srcpos_copy(struct srcpos *pos);
|
|||
extern char *srcpos_string(struct srcpos *pos);
|
||||
extern void srcpos_dump(struct srcpos *pos);
|
||||
|
||||
extern void srcpos_verror(struct srcpos *pos, char const *, va_list va)
|
||||
__attribute__((format(printf, 2, 0)));
|
||||
extern void srcpos_error(struct srcpos *pos, char const *, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
extern void srcpos_verror(struct srcpos *pos, const char *prefix,
|
||||
const char *fmt, va_list va)
|
||||
__attribute__((format(printf, 3, 0)));
|
||||
extern void srcpos_error(struct srcpos *pos, const char *prefix,
|
||||
const char *fmt, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
|
||||
extern void srcpos_set_line(char *f, int l);
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ extern int yyparse(void);
|
|||
extern YYLTYPE yylloc;
|
||||
|
||||
struct boot_info *the_boot_info;
|
||||
int treesource_error;
|
||||
bool treesource_error;
|
||||
|
||||
struct boot_info *dt_from_source(const char *fname)
|
||||
{
|
||||
the_boot_info = NULL;
|
||||
treesource_error = 0;
|
||||
treesource_error = false;
|
||||
|
||||
srcfile_push(fname);
|
||||
yyin = current_srcfile->f;
|
||||
|
@ -54,9 +54,9 @@ static void write_prefix(FILE *f, int level)
|
|||
fputc('\t', f);
|
||||
}
|
||||
|
||||
static int isstring(char c)
|
||||
static bool isstring(char c)
|
||||
{
|
||||
return (isprint(c)
|
||||
return (isprint((unsigned char)c)
|
||||
|| (c == '\0')
|
||||
|| strchr("\a\b\t\n\v\f\r", c));
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ static void write_propval_string(FILE *f, struct data val)
|
|||
break;
|
||||
case '\0':
|
||||
fprintf(f, "\", ");
|
||||
while (m && (m->offset < i)) {
|
||||
while (m && (m->offset <= (i + 1))) {
|
||||
if (m->type == LABEL) {
|
||||
assert(m->offset == (i+1));
|
||||
fprintf(f, "%s: ", m->ref);
|
||||
|
@ -119,7 +119,7 @@ static void write_propval_string(FILE *f, struct data val)
|
|||
fprintf(f, "\"");
|
||||
break;
|
||||
default:
|
||||
if (isprint(c))
|
||||
if (isprint((unsigned char)c))
|
||||
fprintf(f, "%c", c);
|
||||
else
|
||||
fprintf(f, "\\x%02hhx", c);
|
||||
|
@ -178,7 +178,7 @@ static void write_propval_bytes(FILE *f, struct data val)
|
|||
m = m->next;
|
||||
}
|
||||
|
||||
fprintf(f, "%02hhx", *bp++);
|
||||
fprintf(f, "%02hhx", (unsigned char)(*bp++));
|
||||
if ((const void *)bp >= propend)
|
||||
break;
|
||||
fprintf(f, " ");
|
||||
|
|
|
@ -34,15 +34,16 @@
|
|||
|
||||
#include "libfdt.h"
|
||||
#include "util.h"
|
||||
#include "version_gen.h"
|
||||
|
||||
char *xstrdup(const char *s)
|
||||
{
|
||||
int len = strlen(s) + 1;
|
||||
char *dup = xmalloc(len);
|
||||
char *d = xmalloc(len);
|
||||
|
||||
memcpy(dup, s, len);
|
||||
memcpy(d, s, len);
|
||||
|
||||
return dup;
|
||||
return d;
|
||||
}
|
||||
|
||||
char *join_path(const char *path, const char *name)
|
||||
|
@ -69,10 +70,10 @@ char *join_path(const char *path, const char *name)
|
|||
return str;
|
||||
}
|
||||
|
||||
int util_is_printable_string(const void *data, int len)
|
||||
bool util_is_printable_string(const void *data, int len)
|
||||
{
|
||||
const char *s = data;
|
||||
const char *ss;
|
||||
const char *ss, *se;
|
||||
|
||||
/* zero length is not */
|
||||
if (len == 0)
|
||||
|
@ -82,13 +83,19 @@ int util_is_printable_string(const void *data, int len)
|
|||
if (s[len - 1] != '\0')
|
||||
return 0;
|
||||
|
||||
ss = s;
|
||||
while (*s && isprint(*s))
|
||||
s++;
|
||||
se = s + len;
|
||||
|
||||
/* not zero, or not done yet */
|
||||
if (*s != '\0' || (s + 1 - ss) < len)
|
||||
return 0;
|
||||
while (s < se) {
|
||||
ss = s;
|
||||
while (s < se && *s && isprint((unsigned char)*s))
|
||||
s++;
|
||||
|
||||
/* not zero, or not done yet */
|
||||
if (*s != '\0' || s == ss)
|
||||
return 0;
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -191,7 +198,7 @@ char get_escape_char(const char *s, int *i)
|
|||
return val;
|
||||
}
|
||||
|
||||
int utilfdt_read_err(const char *filename, char **buffp)
|
||||
int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
|
||||
{
|
||||
int fd = 0; /* assume stdin */
|
||||
char *buf = NULL;
|
||||
|
@ -206,16 +213,12 @@ int utilfdt_read_err(const char *filename, char **buffp)
|
|||
}
|
||||
|
||||
/* Loop until we have read everything */
|
||||
buf = malloc(bufsize);
|
||||
buf = xmalloc(bufsize);
|
||||
do {
|
||||
/* Expand the buffer to hold the next chunk */
|
||||
if (offset == bufsize) {
|
||||
bufsize *= 2;
|
||||
buf = realloc(buf, bufsize);
|
||||
if (!buf) {
|
||||
ret = ENOMEM;
|
||||
break;
|
||||
}
|
||||
buf = xrealloc(buf, bufsize);
|
||||
}
|
||||
|
||||
ret = read(fd, &buf[offset], bufsize - offset);
|
||||
|
@ -232,13 +235,20 @@ int utilfdt_read_err(const char *filename, char **buffp)
|
|||
free(buf);
|
||||
else
|
||||
*buffp = buf;
|
||||
*len = bufsize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *utilfdt_read(const char *filename)
|
||||
int utilfdt_read_err(const char *filename, char **buffp)
|
||||
{
|
||||
off_t len;
|
||||
return utilfdt_read_err_len(filename, buffp, &len);
|
||||
}
|
||||
|
||||
char *utilfdt_read_len(const char *filename, off_t *len)
|
||||
{
|
||||
char *buff;
|
||||
int ret = utilfdt_read_err(filename, &buff);
|
||||
int ret = utilfdt_read_err_len(filename, &buff, len);
|
||||
|
||||
if (ret) {
|
||||
fprintf(stderr, "Couldn't open blob from '%s': %s\n", filename,
|
||||
|
@ -249,6 +259,12 @@ char *utilfdt_read(const char *filename)
|
|||
return buff;
|
||||
}
|
||||
|
||||
char *utilfdt_read(const char *filename)
|
||||
{
|
||||
off_t len;
|
||||
return utilfdt_read_len(filename, &len);
|
||||
}
|
||||
|
||||
int utilfdt_write_err(const char *filename, const void *blob)
|
||||
{
|
||||
int fd = 1; /* assume stdout */
|
||||
|
@ -329,3 +345,100 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size)
|
|||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void utilfdt_print_data(const char *data, int len)
|
||||
{
|
||||
int i;
|
||||
const char *p = data;
|
||||
const char *s;
|
||||
|
||||
/* no data, don't print */
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (util_is_printable_string(data, len)) {
|
||||
printf(" = ");
|
||||
|
||||
s = data;
|
||||
do {
|
||||
printf("\"%s\"", s);
|
||||
s += strlen(s) + 1;
|
||||
if (s < data + len)
|
||||
printf(", ");
|
||||
} while (s < data + len);
|
||||
|
||||
} else if ((len % 4) == 0) {
|
||||
const uint32_t *cell = (const uint32_t *)data;
|
||||
|
||||
printf(" = <");
|
||||
for (i = 0, len /= 4; i < len; i++)
|
||||
printf("0x%08x%s", fdt32_to_cpu(cell[i]),
|
||||
i < (len - 1) ? " " : "");
|
||||
printf(">");
|
||||
} else {
|
||||
printf(" = [");
|
||||
for (i = 0; i < len; i++)
|
||||
printf("%02x%s", *p++, i < len - 1 ? " " : "");
|
||||
printf("]");
|
||||
}
|
||||
}
|
||||
|
||||
void util_version(void)
|
||||
{
|
||||
printf("Version: %s\n", DTC_VERSION);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void util_usage(const char *errmsg, const char *synopsis,
|
||||
const char *short_opts, struct option const long_opts[],
|
||||
const char * const opts_help[])
|
||||
{
|
||||
FILE *fp = errmsg ? stderr : stdout;
|
||||
const char a_arg[] = "<arg>";
|
||||
size_t a_arg_len = strlen(a_arg) + 1;
|
||||
size_t i;
|
||||
int optlen;
|
||||
|
||||
fprintf(fp,
|
||||
"Usage: %s\n"
|
||||
"\n"
|
||||
"Options: -[%s]\n", synopsis, short_opts);
|
||||
|
||||
/* prescan the --long opt length to auto-align */
|
||||
optlen = 0;
|
||||
for (i = 0; long_opts[i].name; ++i) {
|
||||
/* +1 is for space between --opt and help text */
|
||||
int l = strlen(long_opts[i].name) + 1;
|
||||
if (long_opts[i].has_arg == a_argument)
|
||||
l += a_arg_len;
|
||||
if (optlen < l)
|
||||
optlen = l;
|
||||
}
|
||||
|
||||
for (i = 0; long_opts[i].name; ++i) {
|
||||
/* helps when adding new applets or options */
|
||||
assert(opts_help[i] != NULL);
|
||||
|
||||
/* first output the short flag if it has one */
|
||||
if (long_opts[i].val > '~')
|
||||
fprintf(fp, " ");
|
||||
else
|
||||
fprintf(fp, " -%c, ", long_opts[i].val);
|
||||
|
||||
/* then the long flag */
|
||||
if (long_opts[i].has_arg == no_argument)
|
||||
fprintf(fp, "--%-*s", optlen, long_opts[i].name);
|
||||
else
|
||||
fprintf(fp, "--%s %s%*s", long_opts[i].name, a_arg,
|
||||
(int)(optlen - strlen(long_opts[i].name) - a_arg_len), "");
|
||||
|
||||
/* finally the help text */
|
||||
fprintf(fp, "%s\n", opts_help[i]);
|
||||
}
|
||||
|
||||
if (errmsg) {
|
||||
fprintf(fp, "\nError: %s\n", errmsg);
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define _UTIL_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
|
||||
/*
|
||||
* Copyright 2011 The Chromium Authors, All Rights Reserved.
|
||||
|
@ -23,7 +25,9 @@
|
|||
* USA
|
||||
*/
|
||||
|
||||
static inline void __attribute__((noreturn)) die(char * str, ...)
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static inline void __attribute__((noreturn)) die(const char *str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
@ -57,13 +61,15 @@ extern char *xstrdup(const char *s);
|
|||
extern char *join_path(const char *path, const char *name);
|
||||
|
||||
/**
|
||||
* Check a string of a given length to see if it is all printable and
|
||||
* has a valid terminator.
|
||||
* Check a property of a given length to see if it is all printable and
|
||||
* has a valid terminator. The property can contain either a single string,
|
||||
* or multiple strings each of non-zero length.
|
||||
*
|
||||
* @param data The string to check
|
||||
* @param len The string length including terminator
|
||||
* @return 1 if a valid printable string, 0 if not */
|
||||
int util_is_printable_string(const void *data, int len);
|
||||
* @return 1 if a valid printable string, 0 if not
|
||||
*/
|
||||
bool util_is_printable_string(const void *data, int len);
|
||||
|
||||
/*
|
||||
* Parse an escaped character starting at index i in string s. The resulting
|
||||
|
@ -82,6 +88,13 @@ char get_escape_char(const char *s, int *i);
|
|||
*/
|
||||
char *utilfdt_read(const char *filename);
|
||||
|
||||
/**
|
||||
* Like utilfdt_read(), but also passes back the size of the file read.
|
||||
*
|
||||
* @param len If non-NULL, the amount of data we managed to read
|
||||
*/
|
||||
char *utilfdt_read_len(const char *filename, off_t *len);
|
||||
|
||||
/**
|
||||
* Read a device tree file into a buffer. Does not report errors, but only
|
||||
* returns them. The value returned can be passed to strerror() to obtain
|
||||
|
@ -93,6 +106,12 @@ char *utilfdt_read(const char *filename);
|
|||
*/
|
||||
int utilfdt_read_err(const char *filename, char **buffp);
|
||||
|
||||
/**
|
||||
* Like utilfdt_read_err(), but also passes back the size of the file read.
|
||||
*
|
||||
* @param len If non-NULL, the amount of data we managed to read
|
||||
*/
|
||||
int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len);
|
||||
|
||||
/**
|
||||
* Write a device tree buffer to a file. This will report any errors on
|
||||
|
@ -148,6 +167,85 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size);
|
|||
#define USAGE_TYPE_MSG \
|
||||
"<type>\ts=string, i=int, u=unsigned, x=hex\n" \
|
||||
"\tOptional modifier prefix:\n" \
|
||||
"\t\thh or b=byte, h=2 byte, l=4 byte (default)\n";
|
||||
"\t\thh or b=byte, h=2 byte, l=4 byte (default)";
|
||||
|
||||
/**
|
||||
* Print property data in a readable format to stdout
|
||||
*
|
||||
* Properties that look like strings will be printed as strings. Otherwise
|
||||
* the data will be displayed either as cells (if len is a multiple of 4
|
||||
* bytes) or bytes.
|
||||
*
|
||||
* If len is 0 then this function does nothing.
|
||||
*
|
||||
* @param data Pointers to property data
|
||||
* @param len Length of property data
|
||||
*/
|
||||
void utilfdt_print_data(const char *data, int len);
|
||||
|
||||
/**
|
||||
* Show source version and exit
|
||||
*/
|
||||
void util_version(void) __attribute__((noreturn));
|
||||
|
||||
/**
|
||||
* Show usage and exit
|
||||
*
|
||||
* This helps standardize the output of various utils. You most likely want
|
||||
* to use the usage() helper below rather than call this.
|
||||
*
|
||||
* @param errmsg If non-NULL, an error message to display
|
||||
* @param synopsis The initial example usage text (and possible examples)
|
||||
* @param short_opts The string of short options
|
||||
* @param long_opts The structure of long options
|
||||
* @param opts_help An array of help strings (should align with long_opts)
|
||||
*/
|
||||
void util_usage(const char *errmsg, const char *synopsis,
|
||||
const char *short_opts, struct option const long_opts[],
|
||||
const char * const opts_help[]) __attribute__((noreturn));
|
||||
|
||||
/**
|
||||
* Show usage and exit
|
||||
*
|
||||
* If you name all your usage variables with usage_xxx, then you can call this
|
||||
* help macro rather than expanding all arguments yourself.
|
||||
*
|
||||
* @param errmsg If non-NULL, an error message to display
|
||||
*/
|
||||
#define usage(errmsg) \
|
||||
util_usage(errmsg, usage_synopsis, usage_short_opts, \
|
||||
usage_long_opts, usage_opts_help)
|
||||
|
||||
/**
|
||||
* Call getopt_long() with standard options
|
||||
*
|
||||
* Since all util code runs getopt in the same way, provide a helper.
|
||||
*/
|
||||
#define util_getopt_long() getopt_long(argc, argv, usage_short_opts, \
|
||||
usage_long_opts, NULL)
|
||||
|
||||
/* Helper for aligning long_opts array */
|
||||
#define a_argument required_argument
|
||||
|
||||
/* Helper for usage_short_opts string constant */
|
||||
#define USAGE_COMMON_SHORT_OPTS "hV"
|
||||
|
||||
/* Helper for usage_long_opts option array */
|
||||
#define USAGE_COMMON_LONG_OPTS \
|
||||
{"help", no_argument, NULL, 'h'}, \
|
||||
{"version", no_argument, NULL, 'V'}, \
|
||||
{NULL, no_argument, NULL, 0x0}
|
||||
|
||||
/* Helper for usage_opts_help array */
|
||||
#define USAGE_COMMON_OPTS_HELP \
|
||||
"Print this help and exit", \
|
||||
"Print version and exit", \
|
||||
NULL
|
||||
|
||||
/* Helper for getopt case statements */
|
||||
#define case_USAGE_COMMON_FLAGS \
|
||||
case 'h': usage(NULL); \
|
||||
case 'V': util_version(); \
|
||||
case '?': usage("unknown option");
|
||||
|
||||
#endif /* _UTIL_H */
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define DTC_VERSION "DTC 1.2.0-g37c0b6a0"
|
||||
#define DTC_VERSION "DTC 1.4.1"
|
||||
|
|
Loading…
Reference in New Issue