Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/dtc: Update to upstream version v1.4.0

Update to the latest version of dtc with the following notable
enhancements and bug fixes:

* fdtput: expand fdt if value does not fit
* dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpers
* libfdt: Add fdt_next_subnode() to permit easy subnode iteration
* utilfdt_read: pass back up the length of data read
* util_version: new helper for displaying version info
* die: constify format string arg
* utilfdt_read_err: use xmalloc funcs
* Export fdt_stringlist_contains()
* dtc: Drop the '-S is deprecated' warning
* dtc/libfdt: sparse fixes
* dtc/libfdt: introduce fdt types for annotation by endian checkers
* Fix util_is_printable_string
* dtc: srcpos_verror() should print to stderr
* libfdt: Added missing functions to shared library

Shipped bison/flex generated files were built on an Ubuntu 13.10 system.

Signed-off-by: Grant Likely <grant.likely@linaro.org>

+294 -82
+59 -60
scripts/dtc/dtc.c
··· 21 21 #include "dtc.h" 22 22 #include "srcpos.h" 23 23 24 - #include "version_gen.h" 25 - 26 24 /* 27 25 * Command line options 28 26 */ ··· 47 49 fill_fullpaths(child, tree->fullpath); 48 50 } 49 51 50 - static void __attribute__ ((noreturn)) usage(void) 51 - { 52 - fprintf(stderr, "Usage:\n"); 53 - fprintf(stderr, "\tdtc [options] <input file>\n"); 54 - fprintf(stderr, "\nOptions:\n"); 55 - fprintf(stderr, "\t-h\n"); 56 - fprintf(stderr, "\t\tThis help text\n"); 57 - fprintf(stderr, "\t-q\n"); 58 - fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all\n"); 59 - fprintf(stderr, "\t-I <input format>\n"); 60 - fprintf(stderr, "\t\tInput formats are:\n"); 61 - fprintf(stderr, "\t\t\tdts - device tree source text\n"); 62 - fprintf(stderr, "\t\t\tdtb - device tree blob\n"); 63 - fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory\n"); 64 - fprintf(stderr, "\t-o <output file>\n"); 65 - fprintf(stderr, "\t-O <output format>\n"); 66 - fprintf(stderr, "\t\tOutput formats are:\n"); 67 - fprintf(stderr, "\t\t\tdts - device tree source text\n"); 68 - fprintf(stderr, "\t\t\tdtb - device tree blob\n"); 69 - fprintf(stderr, "\t\t\tasm - assembler source\n"); 70 - fprintf(stderr, "\t-V <output version>\n"); 71 - fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION); 72 - fprintf(stderr, "\t-d <output dependency file>\n"); 73 - fprintf(stderr, "\t-R <number>\n"); 74 - fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n"); 75 - fprintf(stderr, "\t-S <bytes>\n"); 76 - fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n"); 77 - fprintf(stderr, "\t-p <bytes>\n"); 78 - fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n"); 79 - fprintf(stderr, "\t-b <number>\n"); 80 - fprintf(stderr, "\t\tSet the physical boot cpu\n"); 81 - fprintf(stderr, "\t-f\n"); 82 - fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n"); 83 - fprintf(stderr, "\t-i\n"); 84 - fprintf(stderr, "\t\tAdd a path to search for include files\n"); 85 - fprintf(stderr, "\t-s\n"); 86 - fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n"); 87 - fprintf(stderr, "\t-v\n"); 88 - fprintf(stderr, "\t\tPrint DTC version and exit\n"); 89 - fprintf(stderr, "\t-H <phandle format>\n"); 90 - fprintf(stderr, "\t\tphandle formats are:\n"); 91 - fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n"); 92 - fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n"); 93 - fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n"); 94 - fprintf(stderr, "\t-W [no-]<checkname>\n"); 95 - fprintf(stderr, "\t-E [no-]<checkname>\n"); 96 - fprintf(stderr, "\t\t\tenable or disable warnings and errors\n"); 97 - exit(3); 98 - } 52 + /* Usage related data. */ 53 + static const char usage_synopsis[] = "dtc [options] <input file>"; 54 + static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv"; 55 + static struct option const usage_long_opts[] = { 56 + {"quiet", no_argument, NULL, 'q'}, 57 + {"in-format", a_argument, NULL, 'I'}, 58 + {"out", a_argument, NULL, 'o'}, 59 + {"out-format", a_argument, NULL, 'O'}, 60 + {"out-version", a_argument, NULL, 'V'}, 61 + {"out-dependency", a_argument, NULL, 'd'}, 62 + {"reserve", a_argument, NULL, 'R'}, 63 + {"space", a_argument, NULL, 'S'}, 64 + {"pad", a_argument, NULL, 'p'}, 65 + {"boot-cpu", a_argument, NULL, 'b'}, 66 + {"force", no_argument, NULL, 'f'}, 67 + {"include", a_argument, NULL, 'i'}, 68 + {"sort", no_argument, NULL, 's'}, 69 + {"phandle", a_argument, NULL, 'H'}, 70 + {"warning", a_argument, NULL, 'W'}, 71 + {"error", a_argument, NULL, 'E'}, 72 + {"help", no_argument, NULL, 'h'}, 73 + {"version", no_argument, NULL, 'v'}, 74 + {NULL, no_argument, NULL, 0x0}, 75 + }; 76 + static const char * const usage_opts_help[] = { 77 + "\n\tQuiet: -q suppress warnings, -qq errors, -qqq all", 78 + "\n\tInput formats are:\n" 79 + "\t\tdts - device tree source text\n" 80 + "\t\tdtb - device tree blob\n" 81 + "\t\tfs - /proc/device-tree style directory", 82 + "\n\tOutput file", 83 + "\n\tOutput formats are:\n" 84 + "\t\tdts - device tree source text\n" 85 + "\t\tdtb - device tree blob\n" 86 + "\t\tasm - assembler source", 87 + "\n\tBlob version to produce, defaults to %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION); 88 + "\n\tOutput dependency file", 89 + "\n\ttMake space for <number> reserve map entries (for dtb and asm output)", 90 + "\n\tMake the blob at least <bytes> long (extra space)", 91 + "\n\tAdd padding to the blob of <bytes> long (extra space)", 92 + "\n\tSet the physical boot cpu", 93 + "\n\tTry to produce output even if the input tree has errors", 94 + "\n\tAdd a path to search for include files", 95 + "\n\tSort nodes and properties before outputting (useful for comparing trees)", 96 + "\n\tValid phandle formats are:\n" 97 + "\t\tlegacy - \"linux,phandle\" properties only\n" 98 + "\t\tepapr - \"phandle\" properties only\n" 99 + "\t\tboth - Both \"linux,phandle\" and \"phandle\" properties", 100 + "\n\tEnable/disable warnings (prefix with \"no-\")", 101 + "\n\tEnable/disable errors (prefix with \"no-\")", 102 + "\n\tPrint this help and exit", 103 + "\n\tPrint version and exit", 104 + NULL, 105 + }; 99 106 100 107 int main(int argc, char *argv[]) 101 108 { ··· 121 118 minsize = 0; 122 119 padsize = 0; 123 120 124 - while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fqb:i:vH:sW:E:")) 125 - != EOF) { 121 + while ((opt = util_getopt_long()) != EOF) { 126 122 switch (opt) { 127 123 case 'I': 128 124 inform = optarg; ··· 160 158 srcfile_add_search_path(optarg); 161 159 break; 162 160 case 'v': 163 - printf("Version: %s\n", DTC_VERSION); 164 - exit(0); 161 + util_version(); 165 162 case 'H': 166 163 if (streq(optarg, "legacy")) 167 164 phandle_format = PHANDLE_LEGACY; ··· 186 185 break; 187 186 188 187 case 'h': 188 + usage(NULL); 189 189 default: 190 - usage(); 190 + usage("unknown option"); 191 191 } 192 192 } 193 193 194 194 if (argc > (optind+1)) 195 - usage(); 195 + usage("missing files"); 196 196 else if (argc < (optind+1)) 197 197 arg = "-"; 198 198 else ··· 202 200 /* minsize and padsize are mutually exclusive */ 203 201 if (minsize && padsize) 204 202 die("Can't set both -p and -S\n"); 205 - 206 - if (minsize) 207 - fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n"); 208 203 209 204 if (depname) { 210 205 depfile = fopen(depname, "w");
-1
scripts/dtc/dtc.h
··· 66 66 #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) 67 67 68 68 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 69 - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 70 69 71 70 /* Data blobs */ 72 71 enum markertype {
+3 -3
scripts/dtc/srcpos.c
··· 297 297 298 298 srcstr = srcpos_string(pos); 299 299 300 - fprintf(stdout, "Error: %s ", srcstr); 301 - vfprintf(stdout, fmt, va); 302 - fprintf(stdout, "\n"); 300 + fprintf(stderr, "Error: %s ", srcstr); 301 + vfprintf(stderr, fmt, va); 302 + fprintf(stderr, "\n"); 303 303 } 304 304 305 305 void
+129 -12
scripts/dtc/util.c
··· 34 34 35 35 #include "libfdt.h" 36 36 #include "util.h" 37 + #include "version_gen.h" 37 38 38 39 char *xstrdup(const char *s) 39 40 { ··· 73 72 int util_is_printable_string(const void *data, int len) 74 73 { 75 74 const char *s = data; 76 - const char *ss; 75 + const char *ss, *se; 77 76 78 77 /* zero length is not */ 79 78 if (len == 0) ··· 83 82 if (s[len - 1] != '\0') 84 83 return 0; 85 84 86 - ss = s; 87 - while (*s && isprint(*s)) 88 - s++; 85 + se = s + len; 89 86 90 - /* not zero, or not done yet */ 91 - if (*s != '\0' || (s + 1 - ss) < len) 92 - return 0; 87 + while (s < se) { 88 + ss = s; 89 + while (s < se && *s && isprint(*s)) 90 + s++; 91 + 92 + /* not zero, or not done yet */ 93 + if (*s != '\0' || s == ss) 94 + return 0; 95 + 96 + s++; 97 + } 93 98 94 99 return 1; 95 100 } ··· 198 191 return val; 199 192 } 200 193 201 - int utilfdt_read_err(const char *filename, char **buffp) 194 + int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len) 202 195 { 203 196 int fd = 0; /* assume stdin */ 204 197 char *buf = NULL; ··· 213 206 } 214 207 215 208 /* Loop until we have read everything */ 216 - buf = malloc(bufsize); 209 + buf = xmalloc(bufsize); 217 210 do { 218 211 /* Expand the buffer to hold the next chunk */ 219 212 if (offset == bufsize) { 220 213 bufsize *= 2; 221 - buf = realloc(buf, bufsize); 214 + buf = xrealloc(buf, bufsize); 222 215 if (!buf) { 223 216 ret = ENOMEM; 224 217 break; ··· 239 232 free(buf); 240 233 else 241 234 *buffp = buf; 235 + *len = bufsize; 242 236 return ret; 243 237 } 244 238 245 - char *utilfdt_read(const char *filename) 239 + int utilfdt_read_err(const char *filename, char **buffp) 240 + { 241 + off_t len; 242 + return utilfdt_read_err_len(filename, buffp, &len); 243 + } 244 + 245 + char *utilfdt_read_len(const char *filename, off_t *len) 246 246 { 247 247 char *buff; 248 - int ret = utilfdt_read_err(filename, &buff); 248 + int ret = utilfdt_read_err_len(filename, &buff, len); 249 249 250 250 if (ret) { 251 251 fprintf(stderr, "Couldn't open blob from '%s': %s\n", filename, ··· 261 247 } 262 248 /* Successful read */ 263 249 return buff; 250 + } 251 + 252 + char *utilfdt_read(const char *filename) 253 + { 254 + off_t len; 255 + return utilfdt_read_len(filename, &len); 264 256 } 265 257 266 258 int utilfdt_write_err(const char *filename, const void *blob) ··· 348 328 if (*fmt) 349 329 return -1; 350 330 return 0; 331 + } 332 + 333 + void utilfdt_print_data(const char *data, int len) 334 + { 335 + int i; 336 + const char *p = data; 337 + const char *s; 338 + 339 + /* no data, don't print */ 340 + if (len == 0) 341 + return; 342 + 343 + if (util_is_printable_string(data, len)) { 344 + printf(" = "); 345 + 346 + s = data; 347 + do { 348 + printf("\"%s\"", s); 349 + s += strlen(s) + 1; 350 + if (s < data + len) 351 + printf(", "); 352 + } while (s < data + len); 353 + 354 + } else if ((len % 4) == 0) { 355 + const uint32_t *cell = (const uint32_t *)data; 356 + 357 + printf(" = <"); 358 + for (i = 0; i < len; i += 4) 359 + printf("0x%08x%s", fdt32_to_cpu(cell[i]), 360 + i < (len - 4) ? " " : ""); 361 + printf(">"); 362 + } else { 363 + printf(" = ["); 364 + for (i = 0; i < len; i++) 365 + printf("%02x%s", *p++, i < len - 1 ? " " : ""); 366 + printf("]"); 367 + } 368 + } 369 + 370 + void util_version(void) 371 + { 372 + printf("Version: %s\n", DTC_VERSION); 373 + exit(0); 374 + } 375 + 376 + void util_usage(const char *errmsg, const char *synopsis, 377 + const char *short_opts, struct option const long_opts[], 378 + const char * const opts_help[]) 379 + { 380 + FILE *fp = errmsg ? stderr : stdout; 381 + const char a_arg[] = "<arg>"; 382 + size_t a_arg_len = strlen(a_arg) + 1; 383 + size_t i; 384 + int optlen; 385 + 386 + fprintf(fp, 387 + "Usage: %s\n" 388 + "\n" 389 + "Options: -[%s]\n", synopsis, short_opts); 390 + 391 + /* prescan the --long opt length to auto-align */ 392 + optlen = 0; 393 + for (i = 0; long_opts[i].name; ++i) { 394 + /* +1 is for space between --opt and help text */ 395 + int l = strlen(long_opts[i].name) + 1; 396 + if (long_opts[i].has_arg == a_argument) 397 + l += a_arg_len; 398 + if (optlen < l) 399 + optlen = l; 400 + } 401 + 402 + for (i = 0; long_opts[i].name; ++i) { 403 + /* helps when adding new applets or options */ 404 + assert(opts_help[i] != NULL); 405 + 406 + /* first output the short flag if it has one */ 407 + if (long_opts[i].val > '~') 408 + fprintf(fp, " "); 409 + else 410 + fprintf(fp, " -%c, ", long_opts[i].val); 411 + 412 + /* then the long flag */ 413 + if (long_opts[i].has_arg == no_argument) 414 + fprintf(fp, "--%-*s", optlen, long_opts[i].name); 415 + else 416 + fprintf(fp, "--%s %s%*s", long_opts[i].name, a_arg, 417 + (int)(optlen - strlen(long_opts[i].name) - a_arg_len), ""); 418 + 419 + /* finally the help text */ 420 + fprintf(fp, "%s\n", opts_help[i]); 421 + } 422 + 423 + if (errmsg) { 424 + fprintf(fp, "\nError: %s\n", errmsg); 425 + exit(EXIT_FAILURE); 426 + } else 427 + exit(EXIT_SUCCESS); 351 428 }
+102 -5
scripts/dtc/util.h
··· 2 2 #define _UTIL_H 3 3 4 4 #include <stdarg.h> 5 + #include <getopt.h> 5 6 6 7 /* 7 8 * Copyright 2011 The Chromium Authors, All Rights Reserved. ··· 24 23 * USA 25 24 */ 26 25 27 - static inline void __attribute__((noreturn)) die(char * str, ...) 26 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 27 + 28 + static inline void __attribute__((noreturn)) die(const char *str, ...) 28 29 { 29 30 va_list ap; 30 31 ··· 60 57 extern char *join_path(const char *path, const char *name); 61 58 62 59 /** 63 - * Check a string of a given length to see if it is all printable and 64 - * has a valid terminator. 60 + * Check a property of a given length to see if it is all printable and 61 + * has a valid terminator. The property can contain either a single string, 62 + * or multiple strings each of non-zero length. 65 63 * 66 64 * @param data The string to check 67 65 * @param len The string length including terminator 68 - * @return 1 if a valid printable string, 0 if not */ 66 + * @return 1 if a valid printable string, 0 if not 67 + */ 69 68 int util_is_printable_string(const void *data, int len); 70 69 71 70 /* ··· 88 83 char *utilfdt_read(const char *filename); 89 84 90 85 /** 86 + * Like utilfdt_read(), but also passes back the size of the file read. 87 + * 88 + * @param len If non-NULL, the amount of data we managed to read 89 + */ 90 + char *utilfdt_read_len(const char *filename, off_t *len); 91 + 92 + /** 91 93 * Read a device tree file into a buffer. Does not report errors, but only 92 94 * returns them. The value returned can be passed to strerror() to obtain 93 95 * an error message for the user. ··· 105 93 */ 106 94 int utilfdt_read_err(const char *filename, char **buffp); 107 95 96 + /** 97 + * Like utilfdt_read_err(), but also passes back the size of the file read. 98 + * 99 + * @param len If non-NULL, the amount of data we managed to read 100 + */ 101 + int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len); 108 102 109 103 /** 110 104 * Write a device tree buffer to a file. This will report any errors on ··· 166 148 #define USAGE_TYPE_MSG \ 167 149 "<type>\ts=string, i=int, u=unsigned, x=hex\n" \ 168 150 "\tOptional modifier prefix:\n" \ 169 - "\t\thh or b=byte, h=2 byte, l=4 byte (default)\n"; 151 + "\t\thh or b=byte, h=2 byte, l=4 byte (default)"; 152 + 153 + /** 154 + * Print property data in a readable format to stdout 155 + * 156 + * Properties that look like strings will be printed as strings. Otherwise 157 + * the data will be displayed either as cells (if len is a multiple of 4 158 + * bytes) or bytes. 159 + * 160 + * If len is 0 then this function does nothing. 161 + * 162 + * @param data Pointers to property data 163 + * @param len Length of property data 164 + */ 165 + void utilfdt_print_data(const char *data, int len); 166 + 167 + /** 168 + * Show source version and exit 169 + */ 170 + void util_version(void) __attribute__((noreturn)); 171 + 172 + /** 173 + * Show usage and exit 174 + * 175 + * This helps standardize the output of various utils. You most likely want 176 + * to use the usage() helper below rather than call this. 177 + * 178 + * @param errmsg If non-NULL, an error message to display 179 + * @param synopsis The initial example usage text (and possible examples) 180 + * @param short_opts The string of short options 181 + * @param long_opts The structure of long options 182 + * @param opts_help An array of help strings (should align with long_opts) 183 + */ 184 + void util_usage(const char *errmsg, const char *synopsis, 185 + const char *short_opts, struct option const long_opts[], 186 + const char * const opts_help[]) __attribute__((noreturn)); 187 + 188 + /** 189 + * Show usage and exit 190 + * 191 + * If you name all your usage variables with usage_xxx, then you can call this 192 + * help macro rather than expanding all arguments yourself. 193 + * 194 + * @param errmsg If non-NULL, an error message to display 195 + */ 196 + #define usage(errmsg) \ 197 + util_usage(errmsg, usage_synopsis, usage_short_opts, \ 198 + usage_long_opts, usage_opts_help) 199 + 200 + /** 201 + * Call getopt_long() with standard options 202 + * 203 + * Since all util code runs getopt in the same way, provide a helper. 204 + */ 205 + #define util_getopt_long() getopt_long(argc, argv, usage_short_opts, \ 206 + usage_long_opts, NULL) 207 + 208 + /* Helper for aligning long_opts array */ 209 + #define a_argument required_argument 210 + 211 + /* Helper for usage_short_opts string constant */ 212 + #define USAGE_COMMON_SHORT_OPTS "hV" 213 + 214 + /* Helper for usage_long_opts option array */ 215 + #define USAGE_COMMON_LONG_OPTS \ 216 + {"help", no_argument, NULL, 'h'}, \ 217 + {"version", no_argument, NULL, 'V'}, \ 218 + {NULL, no_argument, NULL, 0x0} 219 + 220 + /* Helper for usage_opts_help array */ 221 + #define USAGE_COMMON_OPTS_HELP \ 222 + "Print this help and exit", \ 223 + "Print version and exit", \ 224 + NULL 225 + 226 + /* Helper for getopt case statements */ 227 + #define case_USAGE_COMMON_FLAGS \ 228 + case 'h': usage(NULL); \ 229 + case 'V': util_version(); \ 230 + case '?': usage("unknown option"); 170 231 171 232 #endif /* _UTIL_H */
+1 -1
scripts/dtc/version_gen.h
··· 1 - #define DTC_VERSION "DTC 1.2.0-g37c0b6a0" 1 + #define DTC_VERSION "DTC 1.4.0"