From owner-svn-src-stable@FreeBSD.ORG Thu May 15 14:37:55 2014 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DEF4C236; Thu, 15 May 2014 14:37:54 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BFB822E8C; Thu, 15 May 2014 14:37:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4FEbsq0023588; Thu, 15 May 2014 14:37:54 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4FEbqVs023572; Thu, 15 May 2014 14:37:52 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201405151437.s4FEbqVs023572@svn.freebsd.org> From: Ian Lepore Date: Thu, 15 May 2014 14:37:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r266130 - in stable/10: contrib/dtc contrib/dtc/Documentation contrib/dtc/libfdt usr.bin X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 May 2014 14:37:55 -0000 Author: ian Date: Thu May 15 14:37:52 2014 New Revision: 266130 URL: http://svnweb.freebsd.org/changeset/base/266130 Log: MFC r261215, r261257 Merge from vendor branch importing dtc git rev 6a15eb2350426d285130e4c9d84c0bdb6575547a Don't build BSDL dtc if the GPL dtc is enabled. Modified: stable/10/contrib/dtc/Documentation/manual.txt stable/10/contrib/dtc/Makefile stable/10/contrib/dtc/checks.c stable/10/contrib/dtc/data.c stable/10/contrib/dtc/dtc-lexer.l stable/10/contrib/dtc/dtc-parser.y stable/10/contrib/dtc/dtc.c stable/10/contrib/dtc/dtc.h stable/10/contrib/dtc/fdtdump.c stable/10/contrib/dtc/fdtget.c stable/10/contrib/dtc/fdtput.c stable/10/contrib/dtc/flattree.c stable/10/contrib/dtc/libfdt/Makefile.libfdt stable/10/contrib/dtc/libfdt/fdt.c stable/10/contrib/dtc/libfdt/fdt.h stable/10/contrib/dtc/libfdt/fdt_ro.c stable/10/contrib/dtc/libfdt/fdt_rw.c stable/10/contrib/dtc/libfdt/fdt_sw.c stable/10/contrib/dtc/libfdt/fdt_wip.c stable/10/contrib/dtc/libfdt/libfdt.h stable/10/contrib/dtc/libfdt/libfdt_env.h stable/10/contrib/dtc/libfdt/version.lds stable/10/contrib/dtc/livetree.c stable/10/contrib/dtc/srcpos.c stable/10/contrib/dtc/srcpos.h stable/10/contrib/dtc/treesource.c stable/10/contrib/dtc/util.c stable/10/contrib/dtc/util.h stable/10/usr.bin/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/dtc/Documentation/manual.txt ============================================================================== --- stable/10/contrib/dtc/Documentation/manual.txt Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/Documentation/manual.txt Thu May 15 14:37:52 2014 (r266130) @@ -3,6 +3,7 @@ Device Tree Compiler Manual I - "dtc", the device tree compiler 1) Obtaining Sources + 1.1) Submitting Patches 2) Description 3) Command Line 4) Source File @@ -44,6 +45,10 @@ Tarballs of the 1.0.0 and latest release http://www.jdl.com/software/dtc-v1.2.0.tgz http://www.jdl.com/software/dtc-latest.tgz +1.1) Submitting Patches + +Patches should be sent to jdl@jdl.com, and CC'ed to +devicetree-discuss@lists.ozlabs.org. 2) Description Modified: stable/10/contrib/dtc/Makefile ============================================================================== --- stable/10/contrib/dtc/Makefile Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/Makefile Thu May 15 14:37:52 2014 (r266130) @@ -9,7 +9,7 @@ # CONFIG_LOCALVERSION from some future config system. # VERSION = 1 -PATCHLEVEL = 3 +PATCHLEVEL = 4 SUBLEVEL = 0 EXTRAVERSION = LOCAL_VERSION = @@ -160,18 +160,26 @@ endif # intermediate target and building them again "for real" .SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS) -install: all $(SCRIPTS) - @$(VECHO) INSTALL +install-bin: all $(SCRIPTS) + @$(VECHO) INSTALL-BIN $(INSTALL) -d $(DESTDIR)$(BINDIR) $(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR) + +install-lib: all + @$(VECHO) INSTALL-LIB $(INSTALL) -d $(DESTDIR)$(LIBDIR) $(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR) ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname) ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT) $(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR) + +install-includes: + @$(VECHO) INSTALL-INC $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR) $(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR) +install: install-bin install-lib install-includes + $(VERSION_FILE): Makefile FORCE $(call filechk,version) Modified: stable/10/contrib/dtc/checks.c ============================================================================== --- stable/10/contrib/dtc/checks.c Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/checks.c Thu May 15 14:37:52 2014 (r266130) @@ -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 che 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, st 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, st 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; } @@ -256,11 +256,15 @@ static void check_duplicate_property_nam { struct property *prop, *prop2; - for_each_property(node, prop) - for (prop2 = prop->next; prop2; prop2 = prop2->next) + for_each_property(node, prop) { + for (prop2 = prop->next; prop2; prop2 = prop2->next) { + if (prop2->deleted) + continue; if (streq(prop->name, prop2->name)) FAIL(c, "Duplicate property name %s in %s", prop->name, node->fullpath); + } + } } NODE_ERROR(duplicate_property_names, NULL); @@ -729,7 +733,7 @@ void parse_checks_option(bool warn, bool 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; Modified: stable/10/contrib/dtc/data.c ============================================================================== --- stable/10/contrib/dtc/data.c Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/data.c Thu May 15 14:37:52 2014 (r266130) @@ -250,20 +250,20 @@ struct data data_add_marker(struct data 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; } Modified: stable/10/contrib/dtc/dtc-lexer.l ============================================================================== --- stable/10/contrib/dtc/dtc-lexer.l Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/dtc-lexer.l Thu May 15 14:37:52 2014 (r266130) @@ -44,6 +44,7 @@ YY_BUFFER_STATE include_stack[MAX_INCLUD int include_stack_pointer = 0; YYLTYPE yylloc; +extern bool treesource_error; /* CAUTION: this will stop working if we ever use yyless() or yyunput() */ #define YY_USER_ACTION \ @@ -65,7 +66,8 @@ static int dts_version = 1; BEGIN(V1); \ static void push_input_file(const char *filename); -static int pop_input_file(void); +static bool pop_input_file(void); +static void lexical_error(const char *fmt, ...); %} %% @@ -75,6 +77,27 @@ static int pop_input_file(void); push_input_file(name); } +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { + char *line, *tmp, *fn; + /* skip text before line # */ + line = yytext; + while (!isdigit((unsigned char)*line)) + line++; + /* skip digits in line # */ + tmp = line; + while (!isspace((unsigned char)*tmp)) + tmp++; + /* "NULL"-terminate line # */ + *tmp = '\0'; + /* start of filename */ + fn = strchr(tmp + 1, '"') + 1; + /* strip trailing " from filename */ + tmp = strchr(fn, '"'); + *tmp = 0; + /* -1 since #line is the number of the next line */ + srcpos_set_line(xstrdup(fn), atoi(line) - 1); + } + <*><> { if (!pop_input_file()) { yyterminate(); @@ -107,6 +130,20 @@ static int pop_input_file(void); return DT_BITS; } +<*>"/delete-property/" { + DPRINT("Keyword: /delete-property/\n"); + DPRINT("\n"); + BEGIN(PROPNODENAME); + return DT_DEL_PROP; + } + +<*>"/delete-node/" { + DPRINT("Keyword: /delete-node/\n"); + DPRINT("\n"); + BEGIN(PROPNODENAME); + return DT_DEL_NODE; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref = xstrdup(yytext); @@ -115,15 +152,42 @@ static int pop_input_file(void); } ([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; } @@ -152,9 +216,10 @@ static int pop_input_file(void); return ']'; } -{PROPNODECHAR}+ { +\\?{PROPNODECHAR}+ { DPRINT("PropNodeName: %s\n", yytext); - yylval.propnodename = xstrdup(yytext); + yylval.propnodename = xstrdup((yytext[0] == '\\') ? + yytext + 1 : yytext); BEGIN_DEFAULT(); return DT_PROPNODENAME; } @@ -210,10 +275,10 @@ static void push_input_file(const char * } -static int pop_input_file(void) +static bool pop_input_file(void) { if (srcfile_pop() == 0) - return 0; + return false; assert(include_stack_pointer > 0); @@ -223,5 +288,16 @@ static int pop_input_file(void) 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; } Modified: stable/10/contrib/dtc/dtc-parser.y ============================================================================== --- stable/10/contrib/dtc/dtc-parser.y Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/dtc-parser.y Thu May 15 14:37:52 2014 (r266130) @@ -31,15 +31,11 @@ extern void print_error(char const *fmt, extern void yyerror(char const *s); 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; @@ -62,9 +58,11 @@ static unsigned char eval_char_literal(c %token DT_MEMRESERVE %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR %token DT_BITS +%token DT_DEL_PROP +%token DT_DEL_NODE %token DT_PROPNODENAME -%token DT_LITERAL -%token DT_CHAR_LITERAL +%token DT_LITERAL +%token DT_CHAR_LITERAL %token DT_BASE %token DT_BYTE %token DT_STRING @@ -153,6 +151,17 @@ devicetree: print_error("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 + delete_node(target); + + $$ = $1; + } ; nodedef: @@ -182,6 +191,10 @@ propdef: { $$ = build_property($1, empty_data); } + | DT_DEL_PROP DT_PROPNODENAME ';' + { + $$ = build_property_delete($2); + } | DT_LABEL propdef { add_label(&$2->labels, $1); @@ -213,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); @@ -257,18 +269,20 @@ 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)) + bits = $2; + + 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 = 32; } + + $$.data = empty_data; + $$.bits = bits; } | '<' { @@ -317,13 +331,7 @@ arrayprefix: integer_prim: DT_LITERAL - { - $$ = eval_literal($1, 0, 64); - } | DT_CHAR_LITERAL - { - $$ = eval_char_literal($1); - } | '(' integer_expr ')' { $$ = $2; @@ -440,6 +448,10 @@ subnode: { $$ = name_node($2, $1); } + | DT_DEL_NODE DT_PROPNODENAME ';' + { + $$ = name_node(build_node_delete(), $2); + } | DT_LABEL subnode { add_label(&$2->labels, $1); @@ -454,58 +466,12 @@ void print_error(char const *fmt, ...) va_list va; va_start(va, fmt); - srcpos_verror(&yylloc, fmt, va); + srcpos_verror(&yylloc, "Error", fmt, va); va_end(va); - treesource_error = 1; + treesource_error = true; } 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; -} Modified: stable/10/contrib/dtc/dtc.c ============================================================================== --- stable/10/contrib/dtc/dtc.c Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/dtc.c Thu May 15 14:37:52 2014 (r266130) @@ -21,8 +21,6 @@ #include "dtc.h" #include "srcpos.h" -#include "version_gen.h" - /* * Command line options */ @@ -49,55 +47,60 @@ static void fill_fullpaths(struct node * fill_fullpaths(child, tree->fullpath); } -static void __attribute__ ((noreturn)) usage(void) -{ - fprintf(stderr, "Usage:\n"); - fprintf(stderr, "\tdtc [options] \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 \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 \n"); - fprintf(stderr, "\t-O \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 \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 \n"); - fprintf(stderr, "\t-R \n"); - fprintf(stderr, "\t\tMake space for reserve map entries (relevant for \n\t\tdtb and asm output only)\n"); - fprintf(stderr, "\t-S \n"); - fprintf(stderr, "\t\tMake the blob at least long (extra space)\n"); - fprintf(stderr, "\t-p \n"); - fprintf(stderr, "\t\tAdd padding to the blob of long (extra space)\n"); - fprintf(stderr, "\t-b \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 \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-]\n"); - fprintf(stderr, "\t-E [no-]\n"); - fprintf(stderr, "\t\t\tenable or disable warnings and errors\n"); - exit(3); -} +/* Usage related data. */ +static const char usage_synopsis[] = "dtc [options] "; +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 %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION); + "\n\tOutput dependency file", + "\n\ttMake space for reserve map entries (for dtb and asm output)", + "\n\tMake the blob at least long (extra space)", + "\n\tAdd padding to the blob of 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 +109,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 +121,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 +148,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 +160,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 +174,7 @@ int main(int argc, char *argv[]) break; case 's': - sort = 1; + sort = true; break; case 'W': @@ -185,13 +186,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 +203,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) Modified: stable/10/contrib/dtc/dtc.h ============================================================================== --- stable/10/contrib/dtc/dtc.h Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/dtc.h Thu May 15 14:37:52 2014 (r266130) @@ -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 { @@ -119,7 +118,7 @@ struct data data_append_align(struct dat 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,11 +127,13 @@ int data_is_one_string(struct data d); /* Live trees */ struct label { + bool deleted; char *label; struct label *next; }; struct property { + bool deleted; char *name; struct data val; @@ -142,6 +143,7 @@ struct property { }; struct node { + bool deleted; char *name; struct property *proplist; struct node *children; @@ -158,28 +160,47 @@ struct node { struct label *labels; }; -#define for_each_label(l0, l) \ +#define for_each_label_withdel(l0, l) \ for ((l) = (l0); (l); (l) = (l)->next) -#define for_each_property(n, p) \ +#define for_each_label(l0, l) \ + for_each_label_withdel(l0, l) \ + if (!(l)->deleted) + +#define for_each_property_withdel(n, p) \ for ((p) = (n)->proplist; (p); (p) = (p)->next) -#define for_each_child(n, c) \ +#define for_each_property(n, p) \ + for_each_property_withdel(n, p) \ + if (!(p)->deleted) + +#define for_each_child_withdel(n, c) \ for ((c) = (n)->children; (c); (c) = (c)->next_sibling) +#define for_each_child(n, c) \ + for_each_child_withdel(n, c) \ + if (!(c)->deleted) + void add_label(struct label **labels, char *label); +void delete_labels(struct label **labels); struct property *build_property(char *name, struct data val); +struct property *build_property_delete(char *name); struct property *chain_property(struct property *first, struct property *list); struct property *reverse_properties(struct property *first); struct node *build_node(struct property *proplist, struct node *children); +struct node *build_node_delete(void); struct node *name_node(struct node *node, char *name); struct node *chain_node(struct node *first, struct node *list); struct node *merge_nodes(struct node *old_node, struct node *new_node); void add_property(struct node *node, struct property *prop); +void delete_property_by_name(struct node *node, char *name); +void delete_property(struct property *prop); void add_child(struct node *parent, struct node *child); +void delete_node_by_name(struct node *parent, char *name); +void delete_node(struct node *node); const char *get_unitname(struct node *node); struct property *get_property(struct node *node, const char *propname); @@ -227,7 +248,7 @@ 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 process_checks(bool force, struct boot_info *bi); /* Flattened trees */ Modified: stable/10/contrib/dtc/fdtdump.c ============================================================================== --- stable/10/contrib/dtc/fdtdump.c Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/fdtdump.c Thu May 15 14:37:52 2014 (r266130) @@ -2,14 +2,16 @@ * fdtdump.c - Contributed by Pantelis Antoniou */ +#include #include #include #include #include #include -#include +#include #include +#include #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); @@ -97,7 +95,8 @@ static void dump_blob(void *blob) 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] "; +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; + + while ((opt = util_getopt_long()) != EOF) { + switch (opt) { + case_USAGE_COMMON_FLAGS - if (argc < 2) { - fprintf(stderr, "supply input filename\n"); - return 5; + 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; } Modified: stable/10/contrib/dtc/fdtget.c ============================================================================== --- stable/10/contrib/dtc/fdtget.c Thu May 15 14:37:35 2014 (r266129) +++ stable/10/contrib/dtc/fdtget.c Thu May 15 14:37:52 2014 (r266130) *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***