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

powerpc: Update in-kernel dtc and libfdt to version 1.2.0

Some time ago, a copies of the upstream dtc and libfdt sources were
included in the kernel tree to avoid having these as external
dependencies for building the kernel. Since then development on the
upstream dtc and libfdt has continued. This updates the in-kernel
versions to match the recently released upstream dtc version 1.2.0.
This includes a number of bugfixes, many cleanups and a few new
features.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

David Gibson and committed by
Paul Mackerras
ed95d745 0ec27c04

+1615 -1429
+1 -17
arch/powerpc/boot/dtc-src/Makefile.dtc
··· 5 5 # 6 6 DTC_SRCS = dtc.c flattree.c fstree.c data.c livetree.c treesource.c srcpos.c \ 7 7 checks.c 8 - DTC_EXTRA = dtc.h srcpos.h 9 - DTC_LEXFILES = dtc-lexer.l 10 - DTC_BISONFILES = dtc-parser.y 11 - 12 - DTC_LEX_SRCS = $(DTC_LEXFILES:%.l=%.lex.c) 13 - DTC_BISON_SRCS = $(DTC_BISONFILES:%.y=%.tab.c) 14 - DTC_BISON_INCLUDES = $(DTC_BISONFILES:%.y=%.tab.h) 15 - 16 - DTC_GEN_SRCS = $(DTC_LEX_SRCS) $(DTC_BISON_SRCS) 17 - DTC_GEN_ALL = $(DTC_GEN_SRCS) $(DTC_BISON_INCLUDES) 8 + DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c 18 9 DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o) 19 - 20 - DTC_CLEANFILES = $(DTC_GEN_ALL) 21 - 22 - # We assume the containing Makefile system can do auto-dependencies for most 23 - # things, but we supply the dependencies on generated header files explicitly 24 - 25 - $(addprefix $(DTC_objdir)/,$(DTC_GEN_SRCS:%.c=%.o)): $(addprefix $(DTC_objdir)/,$(DTC_BISON_INCLUDES))
+68 -231
arch/powerpc/boot/dtc-src/checks.c
··· 242 242 } 243 243 NODE_CHECK(duplicate_property_names, NULL, ERROR); 244 244 245 + #define LOWERCASE "abcdefghijklmnopqrstuvwxyz" 246 + #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 247 + #define DIGITS "0123456789" 248 + #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" 249 + 250 + static void check_node_name_chars(struct check *c, struct node *dt, 251 + struct node *node) 252 + { 253 + int n = strspn(node->name, c->data); 254 + 255 + if (n < strlen(node->name)) 256 + FAIL(c, "Bad character '%c' in node %s", 257 + node->name[n], node->fullpath); 258 + } 259 + NODE_CHECK(node_name_chars, PROPNODECHARS "@", ERROR); 260 + 261 + static void check_node_name_format(struct check *c, struct node *dt, 262 + struct node *node) 263 + { 264 + if (strchr(get_unitname(node), '@')) 265 + FAIL(c, "Node %s has multiple '@' characters in name", 266 + node->fullpath); 267 + } 268 + NODE_CHECK(node_name_format, NULL, ERROR, &node_name_chars); 269 + 270 + static void check_property_name_chars(struct check *c, struct node *dt, 271 + struct node *node, struct property *prop) 272 + { 273 + int n = strspn(prop->name, c->data); 274 + 275 + if (n < strlen(prop->name)) 276 + FAIL(c, "Bad character '%c' in property name \"%s\", node %s", 277 + prop->name[n], prop->name, node->fullpath); 278 + } 279 + PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR); 280 + 245 281 static void check_explicit_phandles(struct check *c, struct node *root, 246 282 struct node *node) 247 283 { ··· 316 280 static void check_name_properties(struct check *c, struct node *root, 317 281 struct node *node) 318 282 { 319 - struct property *prop; 283 + struct property **pp, *prop = NULL; 320 284 321 - prop = get_property(node, "name"); 285 + for (pp = &node->proplist; *pp; pp = &((*pp)->next)) 286 + if (streq((*pp)->name, "name")) { 287 + prop = *pp; 288 + break; 289 + } 290 + 322 291 if (!prop) 323 292 return; /* No name property, that's fine */ 324 293 325 294 if ((prop->val.len != node->basenamelen+1) 326 - || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) 295 + || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) { 327 296 FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead" 328 297 " of base node name)", node->fullpath, prop->val.val); 298 + } else { 299 + /* The name property is correct, and therefore redundant. 300 + * Delete it */ 301 + *pp = prop->next; 302 + free(prop->name); 303 + data_free(prop->val); 304 + free(prop); 305 + } 329 306 } 330 307 CHECK_IS_STRING(name_is_string, "name", ERROR); 331 308 NODE_CHECK(name_properties, NULL, ERROR, &name_is_string); ··· 350 301 static void fixup_phandle_references(struct check *c, struct node *dt, 351 302 struct node *node, struct property *prop) 352 303 { 353 - struct marker *m = prop->val.markers; 354 - struct node *refnode; 355 - cell_t phandle; 304 + struct marker *m = prop->val.markers; 305 + struct node *refnode; 306 + cell_t phandle; 356 307 357 - for_each_marker_of_type(m, REF_PHANDLE) { 358 - assert(m->offset + sizeof(cell_t) <= prop->val.len); 308 + for_each_marker_of_type(m, REF_PHANDLE) { 309 + assert(m->offset + sizeof(cell_t) <= prop->val.len); 359 310 360 - refnode = get_node_by_ref(dt, m->ref); 361 - if (! refnode) { 362 - FAIL(c, "Reference to non-existent node or label \"%s\"\n", 363 - m->ref); 364 - continue; 365 - } 311 + refnode = get_node_by_ref(dt, m->ref); 312 + if (! refnode) { 313 + FAIL(c, "Reference to non-existent node or label \"%s\"\n", 314 + m->ref); 315 + continue; 316 + } 366 317 367 - phandle = get_node_phandle(dt, refnode); 368 - *((cell_t *)(prop->val.val + m->offset)) = cpu_to_be32(phandle); 369 - } 318 + phandle = get_node_phandle(dt, refnode); 319 + *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle); 320 + } 370 321 } 371 322 CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR, 372 323 &duplicate_node_names, &explicit_phandles); ··· 547 498 548 499 static struct check *check_table[] = { 549 500 &duplicate_node_names, &duplicate_property_names, 501 + &node_name_chars, &node_name_format, &property_name_chars, 550 502 &name_is_string, &name_properties, 551 503 &explicit_phandles, 552 504 &phandle_references, &path_references, ··· 561 511 &obsolete_chosen_interrupt_controller, 562 512 }; 563 513 564 - int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys); 565 - 566 - void process_checks(int force, struct boot_info *bi, 567 - int checkflag, int outversion, int boot_cpuid_phys) 514 + void process_checks(int force, struct boot_info *bi) 568 515 { 569 516 struct node *dt = bi->dt; 570 517 int i; ··· 584 537 "output forced\n"); 585 538 } 586 539 } 587 - 588 - if (checkflag) { 589 - if (error) { 590 - fprintf(stderr, "Warning: Skipping semantic checks due to structural errors\n"); 591 - } else { 592 - if (!check_semantics(bi->dt, outversion, 593 - boot_cpuid_phys)) 594 - fprintf(stderr, "Warning: Input tree has semantic errors\n"); 595 - } 596 - } 597 - } 598 - 599 - /* 600 - * Semantic check functions 601 - */ 602 - 603 - #define ERRMSG(...) if (quiet < 2) fprintf(stderr, "ERROR: " __VA_ARGS__) 604 - #define WARNMSG(...) if (quiet < 1) fprintf(stderr, "Warning: " __VA_ARGS__) 605 - 606 - #define DO_ERR(...) do {ERRMSG(__VA_ARGS__); ok = 0; } while (0) 607 - 608 - #define CHECK_HAVE(node, propname) \ 609 - do { \ 610 - if (! (prop = get_property((node), (propname)))) \ 611 - DO_ERR("Missing \"%s\" property in %s\n", (propname), \ 612 - (node)->fullpath); \ 613 - } while (0); 614 - 615 - #define CHECK_HAVE_WARN(node, propname) \ 616 - do { \ 617 - if (! (prop = get_property((node), (propname)))) \ 618 - WARNMSG("%s has no \"%s\" property\n", \ 619 - (node)->fullpath, (propname)); \ 620 - } while (0) 621 - 622 - #define CHECK_HAVE_STRING(node, propname) \ 623 - do { \ 624 - CHECK_HAVE((node), (propname)); \ 625 - if (prop && !data_is_one_string(prop->val)) \ 626 - DO_ERR("\"%s\" property in %s is not a string\n", \ 627 - (propname), (node)->fullpath); \ 628 - } while (0) 629 - 630 - #define CHECK_HAVE_STREQ(node, propname, value) \ 631 - do { \ 632 - CHECK_HAVE_STRING((node), (propname)); \ 633 - if (prop && !streq(prop->val.val, (value))) \ 634 - DO_ERR("%s has wrong %s, %s (should be %s\n", \ 635 - (node)->fullpath, (propname), \ 636 - prop->val.val, (value)); \ 637 - } while (0) 638 - 639 - #define CHECK_HAVE_ONECELL(node, propname) \ 640 - do { \ 641 - CHECK_HAVE((node), (propname)); \ 642 - if (prop && (prop->val.len != sizeof(cell_t))) \ 643 - DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \ 644 - } while (0) 645 - 646 - #define CHECK_HAVE_WARN_ONECELL(node, propname) \ 647 - do { \ 648 - CHECK_HAVE_WARN((node), (propname)); \ 649 - if (prop && (prop->val.len != sizeof(cell_t))) \ 650 - DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \ 651 - } while (0) 652 - 653 - #define CHECK_HAVE_WARN_PHANDLE(xnode, propname, root) \ 654 - do { \ 655 - struct node *ref; \ 656 - CHECK_HAVE_WARN_ONECELL((xnode), (propname)); \ 657 - if (prop) {\ 658 - cell_t phandle = propval_cell(prop); \ 659 - if ((phandle == 0) || (phandle == -1)) { \ 660 - DO_ERR("\"%s\" property in %s contains an invalid phandle %x\n", (propname), (xnode)->fullpath, phandle); \ 661 - } else { \ 662 - ref = get_node_by_phandle((root), propval_cell(prop)); \ 663 - if (! ref) \ 664 - DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \ 665 - } \ 666 - } \ 667 - } while (0) 668 - 669 - #define CHECK_HAVE_WARN_STRING(node, propname) \ 670 - do { \ 671 - CHECK_HAVE_WARN((node), (propname)); \ 672 - if (prop && !data_is_one_string(prop->val)) \ 673 - DO_ERR("\"%s\" property in %s is not a string\n", \ 674 - (propname), (node)->fullpath); \ 675 - } while (0) 676 - 677 - static int check_root(struct node *root) 678 - { 679 - struct property *prop; 680 - int ok = 1; 681 - 682 - CHECK_HAVE_STRING(root, "model"); 683 - CHECK_HAVE_WARN(root, "compatible"); 684 - 685 - return ok; 686 - } 687 - 688 - static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys) 689 - { 690 - struct node *cpus, *cpu; 691 - struct property *prop; 692 - struct node *bootcpu = NULL; 693 - int ok = 1; 694 - 695 - cpus = get_subnode(root, "cpus"); 696 - if (! cpus) { 697 - ERRMSG("Missing /cpus node\n"); 698 - return 0; 699 - } 700 - 701 - if (cpus->addr_cells != 1) 702 - DO_ERR("%s has bad #address-cells value %d (should be 1)\n", 703 - cpus->fullpath, cpus->addr_cells); 704 - if (cpus->size_cells != 0) 705 - DO_ERR("%s has bad #size-cells value %d (should be 0)\n", 706 - cpus->fullpath, cpus->size_cells); 707 - 708 - for_each_child(cpus, cpu) { 709 - CHECK_HAVE_STREQ(cpu, "device_type", "cpu"); 710 - 711 - CHECK_HAVE_ONECELL(cpu, "reg"); 712 - if (prop) { 713 - cell_t unitnum; 714 - char *eptr; 715 - 716 - unitnum = strtol(get_unitname(cpu), &eptr, 16); 717 - if (*eptr) { 718 - WARNMSG("%s has bad format unit name %s (should be CPU number\n", 719 - cpu->fullpath, get_unitname(cpu)); 720 - } else if (unitnum != propval_cell(prop)) { 721 - WARNMSG("%s unit name \"%s\" does not match \"reg\" property <%x>\n", 722 - cpu->fullpath, get_unitname(cpu), 723 - propval_cell(prop)); 724 - } 725 - } 726 - 727 - /* CHECK_HAVE_ONECELL(cpu, "d-cache-line-size"); */ 728 - /* CHECK_HAVE_ONECELL(cpu, "i-cache-line-size"); */ 729 - CHECK_HAVE_ONECELL(cpu, "d-cache-size"); 730 - CHECK_HAVE_ONECELL(cpu, "i-cache-size"); 731 - 732 - CHECK_HAVE_WARN_ONECELL(cpu, "clock-frequency"); 733 - CHECK_HAVE_WARN_ONECELL(cpu, "timebase-frequency"); 734 - 735 - prop = get_property(cpu, "linux,boot-cpu"); 736 - if (prop) { 737 - if (prop->val.len) 738 - WARNMSG("\"linux,boot-cpu\" property in %s is non-empty\n", 739 - cpu->fullpath); 740 - if (bootcpu) 741 - DO_ERR("Multiple boot cpus (%s and %s)\n", 742 - bootcpu->fullpath, cpu->fullpath); 743 - else 744 - bootcpu = cpu; 745 - } 746 - } 747 - 748 - if (outversion < 2) { 749 - if (! bootcpu) 750 - WARNMSG("No cpu has \"linux,boot-cpu\" property\n"); 751 - } else { 752 - if (bootcpu) 753 - WARNMSG("\"linux,boot-cpu\" property is deprecated in blob version 2 or higher\n"); 754 - if (boot_cpuid_phys == 0xfeedbeef) 755 - WARNMSG("physical boot CPU not set. Use -b option to set\n"); 756 - } 757 - 758 - return ok; 759 - } 760 - 761 - static int check_memory(struct node *root) 762 - { 763 - struct node *mem; 764 - struct property *prop; 765 - int nnodes = 0; 766 - int ok = 1; 767 - 768 - for_each_child(root, mem) { 769 - if (! strneq(mem->name, "memory", mem->basenamelen)) 770 - continue; 771 - 772 - nnodes++; 773 - 774 - CHECK_HAVE_STREQ(mem, "device_type", "memory"); 775 - CHECK_HAVE(mem, "reg"); 776 - } 777 - 778 - if (nnodes == 0) { 779 - ERRMSG("No memory nodes\n"); 780 - return 0; 781 - } 782 - 783 - return ok; 784 - } 785 - 786 - int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys) 787 - { 788 - int ok = 1; 789 - 790 - ok = ok && check_root(dt); 791 - ok = ok && check_cpus(dt, outversion, boot_cpuid_phys); 792 - ok = ok && check_memory(dt); 793 - if (! ok) 794 - return 0; 795 - 796 - return 1; 797 540 }
+31 -31
arch/powerpc/boot/dtc-src/data.c
··· 32 32 m = nm; 33 33 } 34 34 35 - assert(!d.val || d.asize); 36 - 37 35 if (d.val) 38 36 free(d.val); 39 37 } ··· 40 42 { 41 43 struct data nd; 42 44 int newsize; 43 - 44 - /* we must start with an allocated datum */ 45 - assert(!d.val || d.asize); 46 45 47 46 if (xlen == 0) 48 47 return d; ··· 51 56 while ((d.len + xlen) > newsize) 52 57 newsize *= 2; 53 58 54 - nd.asize = newsize; 55 59 nd.val = xrealloc(d.val, newsize); 56 - 57 - assert(nd.asize >= (d.len + xlen)); 58 60 59 61 return nd; 60 62 } ··· 75 83 long val; 76 84 77 85 x[3] = '\0'; 78 - x[0] = s[(*i)]; 79 - if (x[0]) { 80 - x[1] = s[(*i)+1]; 81 - if (x[1]) 82 - x[2] = s[(*i)+2]; 83 - } 86 + strncpy(x, s + *i, 3); 84 87 85 88 val = strtol(x, &endx, 8); 86 - if ((endx - x) == 0) 87 - fprintf(stderr, "Empty \\nnn escape\n"); 89 + 90 + assert(endx > x); 88 91 89 92 (*i) += endx - x; 90 93 return val; ··· 92 105 long val; 93 106 94 107 x[2] = '\0'; 95 - x[0] = s[(*i)]; 96 - if (x[0]) 97 - x[1] = s[(*i)+1]; 108 + strncpy(x, s + *i, 2); 98 109 99 110 val = strtol(x, &endx, 16); 100 - if ((endx - x) == 0) 101 - fprintf(stderr, "Empty \\x escape\n"); 111 + if (!(endx > x)) 112 + die("\\x used with no following hex digits\n"); 102 113 103 114 (*i) += endx - x; 104 115 return val; ··· 167 182 return d; 168 183 } 169 184 170 - struct data data_copy_file(FILE *f, size_t len) 185 + struct data data_copy_file(FILE *f, size_t maxlen) 171 186 { 172 - struct data d; 187 + struct data d = empty_data; 173 188 174 - d = data_grow_for(empty_data, len); 189 + while (!feof(f) && (d.len < maxlen)) { 190 + size_t chunksize, ret; 175 191 176 - d.len = len; 177 - fread(d.val, len, 1, f); 192 + if (maxlen == -1) 193 + chunksize = 4096; 194 + else 195 + chunksize = maxlen - d.len; 196 + 197 + d = data_grow_for(d, chunksize); 198 + ret = fread(d.val + d.len, 1, chunksize, f); 199 + 200 + if (ferror(f)) 201 + die("Error reading file into data: %s", strerror(errno)); 202 + 203 + if (d.len + ret < d.len) 204 + die("Overflow reading file into data\n"); 205 + 206 + d.len += ret; 207 + } 178 208 179 209 return d; 180 210 } ··· 247 247 248 248 struct data data_append_cell(struct data d, cell_t word) 249 249 { 250 - cell_t beword = cpu_to_be32(word); 250 + cell_t beword = cpu_to_fdt32(word); 251 251 252 252 return data_append_data(d, &beword, sizeof(beword)); 253 253 } ··· 256 256 { 257 257 struct fdt_reserve_entry bere; 258 258 259 - bere.address = cpu_to_be64(re->address); 260 - bere.size = cpu_to_be64(re->size); 259 + bere.address = cpu_to_fdt64(re->address); 260 + bere.size = cpu_to_fdt64(re->size); 261 261 262 262 return data_append_data(d, &bere, sizeof(bere)); 263 263 } 264 264 265 - struct data data_append_addr(struct data d, u64 addr) 265 + struct data data_append_addr(struct data d, uint64_t addr) 266 266 { 267 - u64 beaddr = cpu_to_be64(addr); 267 + uint64_t beaddr = cpu_to_fdt64(addr); 268 268 269 269 return data_append_data(d, &beaddr, sizeof(beaddr)); 270 270 }
+57 -65
arch/powerpc/boot/dtc-src/dtc-lexer.l
··· 28 28 PROPNODECHAR [a-zA-Z0-9,._+*#?@-] 29 29 PATHCHAR ({PROPNODECHAR}|[/]) 30 30 LABEL [a-zA-Z_][a-zA-Z0-9_]* 31 + STRING \"([^\\"]|\\.)*\" 32 + WS [[:space:]] 33 + COMMENT "/*"([^*]|\*+[^*/])*\*+"/" 34 + LINECOMMENT "//".*\n 31 35 32 36 %{ 33 37 #include "dtc.h" ··· 56 52 DPRINT("<V1>\n"); \ 57 53 BEGIN(V1); \ 58 54 } 55 + 56 + static void push_input_file(const char *filename); 57 + static int pop_input_file(void); 59 58 %} 60 59 61 60 %% 62 - <*>"/include/" BEGIN(INCLUDE); 63 - 64 - <INCLUDE>\"[^"\n]*\" { 65 - yytext[strlen(yytext) - 1] = 0; 66 - if (!push_input_file(yytext + 1)) { 67 - /* Some unrecoverable error.*/ 68 - exit(1); 69 - } 70 - BEGIN_DEFAULT(); 61 + <*>"/include/"{WS}*{STRING} { 62 + char *name = strchr(yytext, '\"') + 1; 63 + yytext[yyleng-1] = '\0'; 64 + push_input_file(name); 71 65 } 72 - 73 66 74 67 <*><<EOF>> { 75 68 if (!pop_input_file()) { ··· 74 73 } 75 74 } 76 75 77 - <*>\"([^\\"]|\\.)*\" { 78 - yylloc.filenum = srcpos_filenum; 76 + <*>{STRING} { 77 + yylloc.file = srcpos_file; 79 78 yylloc.first_line = yylineno; 80 79 DPRINT("String: %s\n", yytext); 81 80 yylval.data = data_copy_escape_string(yytext+1, ··· 85 84 } 86 85 87 86 <*>"/dts-v1/" { 88 - yylloc.filenum = srcpos_filenum; 87 + yylloc.file = srcpos_file; 89 88 yylloc.first_line = yylineno; 90 89 DPRINT("Keyword: /dts-v1/\n"); 91 90 dts_version = 1; ··· 94 93 } 95 94 96 95 <*>"/memreserve/" { 97 - yylloc.filenum = srcpos_filenum; 96 + yylloc.file = srcpos_file; 98 97 yylloc.first_line = yylineno; 99 98 DPRINT("Keyword: /memreserve/\n"); 100 99 BEGIN_DEFAULT(); ··· 102 101 } 103 102 104 103 <*>{LABEL}: { 105 - yylloc.filenum = srcpos_filenum; 104 + yylloc.file = srcpos_file; 106 105 yylloc.first_line = yylineno; 107 106 DPRINT("Label: %s\n", yytext); 108 107 yylval.labelref = strdup(yytext); ··· 111 110 } 112 111 113 112 <INITIAL>[bodh]# { 114 - yylloc.filenum = srcpos_filenum; 113 + yylloc.file = srcpos_file; 115 114 yylloc.first_line = yylineno; 116 115 if (*yytext == 'b') 117 116 yylval.cbase = 2; ··· 126 125 } 127 126 128 127 <INITIAL>[0-9a-fA-F]+ { 129 - yylloc.filenum = srcpos_filenum; 128 + yylloc.file = srcpos_file; 130 129 yylloc.first_line = yylineno; 131 130 yylval.literal = strdup(yytext); 132 131 DPRINT("Literal: '%s'\n", yylval.literal); ··· 134 133 } 135 134 136 135 <V1>[0-9]+|0[xX][0-9a-fA-F]+ { 137 - yylloc.filenum = srcpos_filenum; 136 + yylloc.file = srcpos_file; 138 137 yylloc.first_line = yylineno; 139 138 yylval.literal = strdup(yytext); 140 139 DPRINT("Literal: '%s'\n", yylval.literal); ··· 142 141 } 143 142 144 143 \&{LABEL} { /* label reference */ 145 - yylloc.filenum = srcpos_filenum; 144 + yylloc.file = srcpos_file; 146 145 yylloc.first_line = yylineno; 147 146 DPRINT("Ref: %s\n", yytext+1); 148 147 yylval.labelref = strdup(yytext+1); ··· 150 149 } 151 150 152 151 "&{/"{PATHCHAR}+\} { /* new-style path reference */ 153 - yylloc.filenum = srcpos_filenum; 152 + yylloc.file = srcpos_file; 154 153 yylloc.first_line = yylineno; 155 154 yytext[yyleng-1] = '\0'; 156 155 DPRINT("Ref: %s\n", yytext+2); ··· 159 158 } 160 159 161 160 <INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */ 162 - yylloc.filenum = srcpos_filenum; 161 + yylloc.file = srcpos_file; 163 162 yylloc.first_line = yylineno; 164 163 DPRINT("Ref: %s\n", yytext+1); 165 164 yylval.labelref = strdup(yytext+1); ··· 167 166 } 168 167 169 168 <BYTESTRING>[0-9a-fA-F]{2} { 170 - yylloc.filenum = srcpos_filenum; 169 + yylloc.file = srcpos_file; 171 170 yylloc.first_line = yylineno; 172 171 yylval.byte = strtol(yytext, NULL, 16); 173 172 DPRINT("Byte: %02x\n", (int)yylval.byte); ··· 175 174 } 176 175 177 176 <BYTESTRING>"]" { 178 - yylloc.filenum = srcpos_filenum; 177 + yylloc.file = srcpos_file; 179 178 yylloc.first_line = yylineno; 180 179 DPRINT("/BYTESTRING\n"); 181 180 BEGIN_DEFAULT(); ··· 183 182 } 184 183 185 184 <PROPNODENAME>{PROPNODECHAR}+ { 186 - yylloc.filenum = srcpos_filenum; 185 + yylloc.file = srcpos_file; 187 186 yylloc.first_line = yylineno; 188 187 DPRINT("PropNodeName: %s\n", yytext); 189 188 yylval.propnodename = strdup(yytext); ··· 191 190 return DT_PROPNODENAME; 192 191 } 193 192 194 - 195 - <*>[[:space:]]+ /* eat whitespace */ 196 - 197 - <*>"/*"([^*]|\*+[^*/])*\*+"/" { 198 - yylloc.filenum = srcpos_filenum; 193 + "/incbin/" { 194 + yylloc.file = srcpos_file; 199 195 yylloc.first_line = yylineno; 200 - DPRINT("Comment: %s\n", yytext); 201 - /* eat comments */ 196 + DPRINT("Binary Include\n"); 197 + return DT_INCBIN; 202 198 } 203 199 204 - <*>"//".*\n /* eat line comments */ 200 + <*>{WS}+ /* eat whitespace */ 201 + <*>{COMMENT}+ /* eat C-style comments */ 202 + <*>{LINECOMMENT}+ /* eat C++-style comments */ 205 203 206 204 <*>. { 207 - yylloc.filenum = srcpos_filenum; 205 + yylloc.file = srcpos_file; 208 206 yylloc.first_line = yylineno; 209 207 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 210 208 (unsigned)yytext[0]); ··· 227 227 */ 228 228 229 229 struct incl_file { 230 - int filenum; 231 - FILE *file; 230 + struct dtc_file *file; 232 231 YY_BUFFER_STATE yy_prev_buf; 233 232 int yy_prev_lineno; 234 233 struct incl_file *prev; 235 234 }; 236 235 237 - struct incl_file *incl_file_stack; 236 + static struct incl_file *incl_file_stack; 238 237 239 238 240 239 /* ··· 244 245 static int incl_depth = 0; 245 246 246 247 247 - int push_input_file(const char *filename) 248 + static void push_input_file(const char *filename) 248 249 { 249 - FILE *f; 250 250 struct incl_file *incl_file; 251 + struct dtc_file *newfile; 252 + struct search_path search, *searchptr = NULL; 251 253 252 - if (!filename) { 253 - yyerror("No include file name given."); 254 - return 0; 254 + assert(filename); 255 + 256 + if (incl_depth++ >= MAX_INCLUDE_DEPTH) 257 + die("Includes nested too deeply"); 258 + 259 + if (srcpos_file) { 260 + search.dir = srcpos_file->dir; 261 + search.next = NULL; 262 + search.prev = NULL; 263 + searchptr = &search; 255 264 } 256 265 257 - if (incl_depth++ >= MAX_INCLUDE_DEPTH) { 258 - yyerror("Includes nested too deeply"); 259 - return 0; 260 - } 266 + newfile = dtc_open_file(filename, searchptr); 261 267 262 - f = dtc_open_file(filename); 263 - 264 - incl_file = malloc(sizeof(struct incl_file)); 265 - if (!incl_file) { 266 - yyerror("Can not allocate include file space."); 267 - return 0; 268 - } 268 + incl_file = xmalloc(sizeof(struct incl_file)); 269 269 270 270 /* 271 271 * Save current context. 272 272 */ 273 273 incl_file->yy_prev_buf = YY_CURRENT_BUFFER; 274 274 incl_file->yy_prev_lineno = yylineno; 275 - incl_file->filenum = srcpos_filenum; 276 - incl_file->file = yyin; 275 + incl_file->file = srcpos_file; 277 276 incl_file->prev = incl_file_stack; 278 277 279 278 incl_file_stack = incl_file; ··· 279 282 /* 280 283 * Establish new context. 281 284 */ 282 - srcpos_filenum = lookup_file_name(filename, 0); 285 + srcpos_file = newfile; 283 286 yylineno = 1; 284 - yyin = f; 287 + yyin = newfile->file; 285 288 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); 286 - 287 - return 1; 288 289 } 289 290 290 291 291 - int pop_input_file(void) 292 + static int pop_input_file(void) 292 293 { 293 294 struct incl_file *incl_file; 294 295 295 296 if (incl_file_stack == 0) 296 297 return 0; 297 298 298 - fclose(yyin); 299 + dtc_close_file(srcpos_file); 299 300 300 301 /* 301 302 * Pop. ··· 308 313 yy_delete_buffer(YY_CURRENT_BUFFER); 309 314 yy_switch_to_buffer(incl_file->yy_prev_buf); 310 315 yylineno = incl_file->yy_prev_lineno; 311 - srcpos_filenum = incl_file->filenum; 312 - yyin = incl_file->file; 316 + srcpos_file = incl_file->file; 317 + yyin = incl_file->file ? incl_file->file->file : NULL; 313 318 314 319 /* 315 320 * Free old state. 316 321 */ 317 322 free(incl_file); 318 - 319 - if (YY_CURRENT_BUFFER == 0) 320 - return 0; 321 323 322 324 return 1; 323 325 }
+222 -209
arch/powerpc/boot/dtc-src/dtc-lexer.lex.c_shipped
··· 9 9 #define FLEX_SCANNER 10 10 #define YY_FLEX_MAJOR_VERSION 2 11 11 #define YY_FLEX_MINOR_VERSION 5 12 - #define YY_FLEX_SUBMINOR_VERSION 33 12 + #define YY_FLEX_SUBMINOR_VERSION 34 13 13 #if YY_FLEX_SUBMINOR_VERSION > 0 14 14 #define FLEX_BETA 15 15 #endif ··· 31 31 32 32 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ 33 33 34 - #if __STDC_VERSION__ >= 199901L 34 + #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 35 35 36 36 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, 37 37 * if you want the limit (max/min) macros for int types. ··· 94 94 95 95 #else /* ! __cplusplus */ 96 96 97 - #if __STDC__ 97 + /* C99 requires __STDC__ to be defined as 1. */ 98 + #if defined (__STDC__) 98 99 99 100 #define YY_USE_CONST 100 101 101 - #endif /* __STDC__ */ 102 + #endif /* defined (__STDC__) */ 102 103 #endif /* ! __cplusplus */ 103 104 104 105 #ifdef YY_USE_CONST ··· 195 194 /* The following is because we cannot portably get our hands on size_t 196 195 * (without autoconf's help, which isn't available because we want 197 196 * flex-generated scanners to compile on their own). 197 + * Given that the standard has decreed that size_t exists since 1989, 198 + * I guess we can afford to depend on it. Manoj. 198 199 */ 199 200 200 201 #ifndef YY_TYPEDEF_YY_SIZE_T 201 202 #define YY_TYPEDEF_YY_SIZE_T 202 - typedef unsigned int yy_size_t; 203 + typedef size_t yy_size_t; 203 204 #endif 204 205 205 206 #ifndef YY_STRUCT_YY_BUFFER_STATE ··· 352 349 353 350 /* Begin user sect3 */ 354 351 355 - #define yywrap() 1 352 + #define yywrap(n) 1 356 353 #define YY_SKIP_YYWRAP 357 354 358 355 typedef unsigned char YY_CHAR; ··· 392 389 flex_int32_t yy_verify; 393 390 flex_int32_t yy_nxt; 394 391 }; 395 - static yyconst flex_int16_t yy_accept[94] = 392 + static yyconst flex_int16_t yy_accept[104] = 396 393 { 0, 397 394 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 398 - 21, 19, 16, 16, 19, 19, 19, 8, 8, 19, 399 - 8, 19, 19, 19, 19, 14, 15, 15, 19, 9, 400 - 9, 16, 0, 3, 0, 0, 10, 0, 0, 0, 401 - 0, 0, 0, 8, 8, 6, 0, 7, 0, 2, 402 - 0, 13, 13, 15, 15, 9, 0, 12, 10, 0, 403 - 0, 0, 0, 18, 0, 0, 0, 2, 9, 0, 404 - 17, 0, 0, 0, 11, 0, 0, 0, 0, 0, 405 - 0, 0, 0, 0, 4, 0, 0, 1, 0, 0, 406 - 0, 5, 0 395 + 21, 19, 16, 16, 19, 19, 19, 7, 7, 19, 396 + 7, 19, 19, 19, 19, 13, 14, 14, 19, 8, 397 + 8, 16, 0, 2, 0, 0, 9, 0, 0, 0, 398 + 0, 0, 0, 7, 7, 5, 0, 6, 0, 12, 399 + 12, 14, 14, 8, 0, 11, 9, 0, 0, 0, 400 + 0, 18, 0, 0, 0, 0, 8, 0, 17, 0, 401 + 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 402 + 0, 0, 0, 0, 0, 0, 0, 0, 3, 15, 403 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 407 404 405 + 0, 4, 0 408 406 } ; 409 407 410 408 static yyconst flex_int32_t yy_ec[256] = ··· 448 444 7, 7, 7, 8, 1 449 445 } ; 450 446 451 - static yyconst flex_int16_t yy_base[107] = 447 + static yyconst flex_int16_t yy_base[117] = 452 448 { 0, 453 - 0, 0, 32, 0, 53, 0, 76, 0, 108, 111, 454 - 280, 288, 37, 39, 33, 36, 106, 0, 123, 146, 455 - 255, 251, 45, 0, 159, 288, 0, 53, 108, 172, 456 - 114, 127, 158, 288, 245, 0, 0, 234, 235, 236, 457 - 197, 195, 199, 0, 0, 288, 0, 288, 160, 288, 458 - 183, 288, 0, 0, 183, 182, 0, 0, 0, 0, 459 - 204, 189, 207, 288, 179, 187, 180, 194, 0, 171, 460 - 288, 196, 178, 174, 288, 169, 169, 177, 165, 153, 461 - 143, 155, 137, 118, 288, 122, 42, 288, 36, 36, 462 - 40, 288, 288, 212, 218, 223, 229, 234, 239, 245, 449 + 0, 0, 30, 0, 44, 0, 67, 0, 97, 105, 450 + 302, 303, 35, 44, 40, 94, 112, 0, 129, 152, 451 + 296, 295, 159, 0, 176, 303, 0, 116, 95, 165, 452 + 49, 46, 102, 303, 296, 0, 0, 288, 290, 293, 453 + 264, 266, 270, 0, 0, 303, 0, 303, 264, 303, 454 + 0, 0, 195, 101, 0, 0, 0, 0, 284, 125, 455 + 277, 265, 225, 230, 216, 218, 0, 202, 224, 221, 456 + 217, 107, 196, 188, 303, 206, 179, 186, 178, 185, 457 + 183, 162, 161, 150, 169, 160, 145, 125, 303, 303, 458 + 137, 109, 190, 103, 203, 167, 108, 197, 303, 123, 463 459 464 - 251, 255, 262, 270, 275, 280 460 + 29, 303, 303, 215, 221, 226, 229, 234, 240, 246, 461 + 250, 257, 265, 270, 275, 282 465 462 } ; 466 463 467 - static yyconst flex_int16_t yy_def[107] = 464 + static yyconst flex_int16_t yy_def[117] = 468 465 { 0, 469 - 93, 1, 1, 3, 3, 5, 93, 7, 3, 3, 470 - 93, 93, 93, 93, 94, 95, 93, 96, 93, 19, 471 - 19, 20, 97, 98, 20, 93, 99, 100, 95, 93, 472 - 93, 93, 94, 93, 94, 101, 102, 93, 103, 104, 473 - 93, 93, 93, 96, 19, 93, 20, 93, 97, 93, 474 - 97, 93, 20, 99, 100, 93, 105, 101, 102, 106, 475 - 103, 103, 104, 93, 93, 93, 93, 94, 105, 106, 476 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 477 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 478 - 93, 93, 0, 93, 93, 93, 93, 93, 93, 93, 466 + 103, 1, 1, 3, 3, 5, 103, 7, 3, 3, 467 + 103, 103, 103, 103, 104, 105, 103, 106, 103, 19, 468 + 19, 20, 103, 107, 20, 103, 108, 109, 105, 103, 469 + 103, 103, 104, 103, 104, 110, 111, 103, 112, 113, 470 + 103, 103, 103, 106, 19, 103, 20, 103, 103, 103, 471 + 20, 108, 109, 103, 114, 110, 111, 115, 112, 112, 472 + 113, 103, 103, 103, 103, 103, 114, 115, 103, 103, 473 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 474 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 475 + 103, 103, 103, 103, 103, 116, 103, 116, 103, 116, 479 476 480 - 93, 93, 93, 93, 93, 93 477 + 103, 103, 0, 103, 103, 103, 103, 103, 103, 103, 478 + 103, 103, 103, 103, 103, 103 481 479 } ; 482 480 483 - static yyconst flex_int16_t yy_nxt[324] = 481 + static yyconst flex_int16_t yy_nxt[339] = 484 482 { 0, 485 483 12, 13, 14, 15, 12, 16, 12, 12, 12, 17, 486 484 18, 18, 18, 12, 19, 20, 20, 12, 12, 21, 487 485 19, 21, 19, 22, 20, 20, 20, 20, 20, 20, 488 - 20, 20, 20, 12, 12, 23, 34, 12, 32, 32, 489 - 32, 32, 12, 12, 12, 36, 20, 33, 50, 92, 490 - 35, 20, 20, 20, 20, 20, 15, 54, 91, 54, 491 - 54, 54, 51, 24, 24, 24, 46, 25, 90, 38, 492 - 89, 26, 25, 25, 25, 25, 12, 13, 14, 15, 493 - 27, 12, 27, 27, 27, 17, 27, 27, 27, 12, 494 - 28, 28, 28, 12, 12, 28, 28, 28, 28, 28, 486 + 20, 20, 20, 12, 12, 12, 32, 32, 102, 23, 487 + 12, 12, 12, 34, 20, 32, 32, 32, 32, 20, 488 + 20, 20, 20, 20, 24, 24, 24, 35, 25, 54, 489 + 54, 54, 26, 25, 25, 25, 25, 12, 13, 14, 490 + 15, 27, 12, 27, 27, 27, 23, 27, 27, 27, 491 + 12, 28, 28, 28, 12, 12, 28, 28, 28, 28, 492 + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 495 493 496 - 28, 28, 28, 28, 28, 28, 28, 28, 28, 12, 497 - 12, 15, 39, 29, 15, 40, 29, 93, 30, 31, 498 - 31, 30, 31, 31, 56, 56, 56, 41, 32, 32, 499 - 42, 88, 43, 45, 45, 45, 46, 45, 47, 47, 500 - 87, 38, 45, 45, 45, 45, 47, 47, 47, 47, 501 - 47, 47, 47, 47, 47, 47, 47, 47, 47, 86, 502 - 47, 34, 33, 50, 85, 47, 47, 47, 47, 53, 503 - 53, 53, 84, 53, 83, 35, 82, 51, 53, 53, 504 - 53, 53, 56, 56, 56, 93, 68, 54, 57, 54, 505 - 54, 54, 56, 56, 56, 62, 46, 34, 71, 81, 494 + 12, 12, 29, 36, 103, 34, 17, 30, 31, 31, 495 + 29, 54, 54, 54, 17, 30, 31, 31, 39, 35, 496 + 52, 40, 52, 52, 52, 103, 78, 38, 38, 46, 497 + 101, 60, 79, 41, 69, 97, 42, 94, 43, 45, 498 + 45, 45, 46, 45, 47, 47, 93, 92, 45, 45, 499 + 45, 45, 47, 47, 47, 47, 47, 47, 47, 47, 500 + 47, 47, 47, 47, 47, 39, 47, 91, 40, 90, 501 + 99, 47, 47, 47, 47, 54, 54, 54, 89, 88, 502 + 41, 55, 87, 49, 100, 43, 51, 51, 51, 86, 503 + 51, 95, 95, 96, 85, 51, 51, 51, 51, 52, 506 504 507 - 80, 79, 78, 77, 76, 75, 74, 73, 72, 64, 508 - 62, 35, 33, 33, 33, 33, 33, 33, 33, 33, 509 - 37, 67, 66, 37, 37, 37, 44, 65, 44, 49, 510 - 49, 49, 49, 49, 49, 49, 49, 52, 64, 52, 511 - 54, 62, 54, 60, 54, 54, 55, 93, 55, 55, 512 - 55, 55, 58, 58, 58, 48, 58, 58, 59, 48, 513 - 59, 59, 61, 61, 61, 61, 61, 61, 61, 61, 514 - 63, 63, 63, 63, 63, 63, 63, 63, 69, 93, 515 - 69, 70, 70, 70, 93, 70, 70, 11, 93, 93, 516 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 505 + 99, 52, 52, 52, 95, 95, 96, 84, 46, 83, 506 + 82, 81, 39, 79, 100, 33, 33, 33, 33, 33, 507 + 33, 33, 33, 37, 80, 77, 37, 37, 37, 44, 508 + 40, 44, 50, 76, 50, 52, 75, 52, 74, 52, 509 + 52, 53, 73, 53, 53, 53, 53, 56, 56, 56, 510 + 72, 56, 56, 57, 71, 57, 57, 59, 59, 59, 511 + 59, 59, 59, 59, 59, 61, 61, 61, 61, 61, 512 + 61, 61, 61, 67, 70, 67, 68, 68, 68, 62, 513 + 68, 68, 98, 98, 98, 98, 98, 98, 98, 98, 514 + 60, 66, 65, 64, 63, 62, 60, 58, 103, 48, 517 515 518 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 519 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 520 - 93, 93, 93 516 + 48, 103, 11, 103, 103, 103, 103, 103, 103, 103, 517 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 518 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 519 + 103, 103, 103, 103, 103, 103, 103, 103 521 520 } ; 522 521 523 - static yyconst flex_int16_t yy_chk[324] = 522 + static yyconst flex_int16_t yy_chk[339] = 524 523 { 0, 525 524 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 526 525 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 527 526 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 528 - 1, 1, 1, 1, 1, 3, 15, 3, 13, 13, 529 - 14, 14, 3, 3, 3, 16, 3, 23, 23, 91, 530 - 15, 3, 3, 3, 3, 3, 5, 28, 90, 28, 531 - 28, 28, 23, 5, 5, 5, 28, 5, 89, 16, 532 - 87, 5, 5, 5, 5, 5, 7, 7, 7, 7, 527 + 1, 1, 1, 1, 1, 3, 13, 13, 101, 3, 528 + 3, 3, 3, 15, 3, 14, 14, 32, 32, 3, 529 + 3, 3, 3, 3, 5, 5, 5, 15, 5, 31, 530 + 31, 31, 5, 5, 5, 5, 5, 7, 7, 7, 531 + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 533 532 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 534 533 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 535 534 536 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 537 - 7, 9, 17, 9, 10, 17, 10, 29, 9, 9, 538 - 9, 10, 10, 10, 31, 31, 31, 17, 32, 32, 539 - 17, 86, 17, 19, 19, 19, 19, 19, 19, 19, 540 - 84, 29, 19, 19, 19, 19, 19, 19, 19, 19, 541 - 19, 19, 19, 19, 19, 19, 20, 20, 20, 83, 542 - 20, 33, 49, 49, 82, 20, 20, 20, 20, 25, 543 - 25, 25, 81, 25, 80, 33, 79, 49, 25, 25, 544 - 25, 25, 30, 30, 30, 51, 51, 55, 30, 55, 545 - 55, 55, 56, 56, 56, 62, 55, 68, 62, 78, 535 + 7, 7, 9, 16, 29, 33, 9, 9, 9, 9, 536 + 10, 54, 54, 54, 10, 10, 10, 10, 17, 33, 537 + 28, 17, 28, 28, 28, 100, 72, 16, 29, 28, 538 + 97, 60, 72, 17, 60, 94, 17, 92, 17, 19, 539 + 19, 19, 19, 19, 19, 19, 91, 88, 19, 19, 540 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 541 + 19, 19, 20, 20, 20, 23, 20, 87, 23, 86, 542 + 96, 20, 20, 20, 20, 30, 30, 30, 85, 84, 543 + 23, 30, 83, 23, 96, 23, 25, 25, 25, 82, 544 + 25, 93, 93, 93, 81, 25, 25, 25, 25, 53, 546 545 547 - 77, 76, 74, 73, 72, 70, 67, 66, 65, 63, 548 - 61, 68, 94, 94, 94, 94, 94, 94, 94, 94, 549 - 95, 43, 42, 95, 95, 95, 96, 41, 96, 97, 550 - 97, 97, 97, 97, 97, 97, 97, 98, 40, 98, 551 - 99, 39, 99, 38, 99, 99, 100, 35, 100, 100, 552 - 100, 100, 101, 101, 101, 22, 101, 101, 102, 21, 553 - 102, 102, 103, 103, 103, 103, 103, 103, 103, 103, 554 - 104, 104, 104, 104, 104, 104, 104, 104, 105, 11, 555 - 105, 106, 106, 106, 0, 106, 106, 93, 93, 93, 556 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 546 + 98, 53, 53, 53, 95, 95, 95, 80, 53, 79, 547 + 78, 77, 76, 74, 98, 104, 104, 104, 104, 104, 548 + 104, 104, 104, 105, 73, 71, 105, 105, 105, 106, 549 + 70, 106, 107, 69, 107, 108, 68, 108, 66, 108, 550 + 108, 109, 65, 109, 109, 109, 109, 110, 110, 110, 551 + 64, 110, 110, 111, 63, 111, 111, 112, 112, 112, 552 + 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 553 + 113, 113, 113, 114, 62, 114, 115, 115, 115, 61, 554 + 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 555 + 59, 49, 43, 42, 41, 40, 39, 38, 35, 22, 557 556 558 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 559 - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 560 - 93, 93, 93 557 + 21, 11, 103, 103, 103, 103, 103, 103, 103, 103, 558 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 559 + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 560 + 103, 103, 103, 103, 103, 103, 103, 103 561 561 } ; 562 562 563 563 /* Table of booleans, true if rule could match eol. */ 564 564 static yyconst flex_int32_t yy_rule_can_match_eol[21] = 565 565 { 0, 566 - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 566 + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 567 567 0, }; 568 568 569 569 static yy_state_type yy_last_accepting_state; ··· 608 600 609 601 610 602 611 - #line 33 "dtc-lexer.l" 603 + #line 37 "dtc-lexer.l" 612 604 #include "dtc.h" 613 605 #include "srcpos.h" 614 606 #include "dtc-parser.tab.h" ··· 631 623 DPRINT("<V1>\n"); \ 632 624 BEGIN(V1); \ 633 625 } 634 - #line 627 "dtc-lexer.lex.c" 626 + 627 + static void push_input_file(const char *filename); 628 + static int pop_input_file(void); 629 + #line 638 "dtc-lexer.lex.c" 635 630 636 631 #define INITIAL 0 637 632 #define INCLUDE 1 ··· 696 685 /* This used to be an fputs(), but since the string might contain NUL's, 697 686 * we now use fwrite(). 698 687 */ 699 - #define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) 688 + #define ECHO fwrite( yytext, yyleng, 1, yyout ) 700 689 #endif 701 690 702 691 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, ··· 707 696 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ 708 697 { \ 709 698 int c = '*'; \ 710 - size_t n; \ 699 + int n; \ 711 700 for ( n = 0; n < max_size && \ 712 701 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ 713 702 buf[n] = (char) c; \ ··· 789 778 register char *yy_cp, *yy_bp; 790 779 register int yy_act; 791 780 792 - #line 57 "dtc-lexer.l" 781 + #line 64 "dtc-lexer.l" 793 782 794 - #line 784 "dtc-lexer.lex.c" 783 + #line 795 "dtc-lexer.lex.c" 795 784 796 785 if ( !(yy_init) ) 797 786 { ··· 844 833 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 845 834 { 846 835 yy_current_state = (int) yy_def[yy_current_state]; 847 - if ( yy_current_state >= 94 ) 836 + if ( yy_current_state >= 104 ) 848 837 yy_c = yy_meta[(unsigned int) yy_c]; 849 838 } 850 839 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 851 840 ++yy_cp; 852 841 } 853 - while ( yy_base[yy_current_state] != 288 ); 842 + while ( yy_base[yy_current_state] != 303 ); 854 843 855 844 yy_find_action: 856 845 yy_act = yy_accept[yy_current_state]; ··· 885 874 goto yy_find_action; 886 875 887 876 case 1: 877 + /* rule 1 can match eol */ 888 878 YY_RULE_SETUP 889 - #line 58 "dtc-lexer.l" 890 - BEGIN(INCLUDE); 891 - YY_BREAK 892 - case 2: 893 - YY_RULE_SETUP 894 - #line 60 "dtc-lexer.l" 879 + #line 65 "dtc-lexer.l" 895 880 { 896 - yytext[strlen(yytext) - 1] = 0; 897 - if (!push_input_file(yytext + 1)) { 898 - /* Some unrecoverable error.*/ 899 - exit(1); 900 - } 901 - BEGIN_DEFAULT(); 881 + char *name = strchr(yytext, '\"') + 1; 882 + yytext[yyleng-1] = '\0'; 883 + push_input_file(name); 902 884 } 903 885 YY_BREAK 904 886 case YY_STATE_EOF(INITIAL): ··· 899 895 case YY_STATE_EOF(BYTESTRING): 900 896 case YY_STATE_EOF(PROPNODENAME): 901 897 case YY_STATE_EOF(V1): 902 - #line 70 "dtc-lexer.l" 898 + #line 71 "dtc-lexer.l" 903 899 { 904 900 if (!pop_input_file()) { 905 901 yyterminate(); 906 902 } 907 903 } 908 904 YY_BREAK 909 - case 3: 910 - /* rule 3 can match eol */ 905 + case 2: 906 + /* rule 2 can match eol */ 911 907 YY_RULE_SETUP 912 - #line 76 "dtc-lexer.l" 908 + #line 77 "dtc-lexer.l" 913 909 { 914 - yylloc.filenum = srcpos_filenum; 910 + yylloc.file = srcpos_file; 915 911 yylloc.first_line = yylineno; 916 912 DPRINT("String: %s\n", yytext); 917 913 yylval.data = data_copy_escape_string(yytext+1, ··· 920 916 return DT_STRING; 921 917 } 922 918 YY_BREAK 923 - case 4: 919 + case 3: 924 920 YY_RULE_SETUP 925 - #line 86 "dtc-lexer.l" 921 + #line 87 "dtc-lexer.l" 926 922 { 927 - yylloc.filenum = srcpos_filenum; 923 + yylloc.file = srcpos_file; 928 924 yylloc.first_line = yylineno; 929 925 DPRINT("Keyword: /dts-v1/\n"); 930 926 dts_version = 1; ··· 932 928 return DT_V1; 933 929 } 934 930 YY_BREAK 935 - case 5: 931 + case 4: 936 932 YY_RULE_SETUP 937 - #line 95 "dtc-lexer.l" 933 + #line 96 "dtc-lexer.l" 938 934 { 939 - yylloc.filenum = srcpos_filenum; 935 + yylloc.file = srcpos_file; 940 936 yylloc.first_line = yylineno; 941 937 DPRINT("Keyword: /memreserve/\n"); 942 938 BEGIN_DEFAULT(); 943 939 return DT_MEMRESERVE; 944 940 } 945 941 YY_BREAK 946 - case 6: 942 + case 5: 947 943 YY_RULE_SETUP 948 - #line 103 "dtc-lexer.l" 944 + #line 104 "dtc-lexer.l" 949 945 { 950 - yylloc.filenum = srcpos_filenum; 946 + yylloc.file = srcpos_file; 951 947 yylloc.first_line = yylineno; 952 948 DPRINT("Label: %s\n", yytext); 953 949 yylval.labelref = strdup(yytext); ··· 955 951 return DT_LABEL; 956 952 } 957 953 YY_BREAK 958 - case 7: 954 + case 6: 959 955 YY_RULE_SETUP 960 - #line 112 "dtc-lexer.l" 956 + #line 113 "dtc-lexer.l" 961 957 { 962 - yylloc.filenum = srcpos_filenum; 958 + yylloc.file = srcpos_file; 963 959 yylloc.first_line = yylineno; 964 960 if (*yytext == 'b') 965 961 yylval.cbase = 2; ··· 973 969 return DT_BASE; 974 970 } 975 971 YY_BREAK 976 - case 8: 972 + case 7: 977 973 YY_RULE_SETUP 978 - #line 127 "dtc-lexer.l" 974 + #line 128 "dtc-lexer.l" 979 975 { 980 - yylloc.filenum = srcpos_filenum; 976 + yylloc.file = srcpos_file; 981 977 yylloc.first_line = yylineno; 982 978 yylval.literal = strdup(yytext); 983 979 DPRINT("Literal: '%s'\n", yylval.literal); 984 980 return DT_LEGACYLITERAL; 985 981 } 986 982 YY_BREAK 987 - case 9: 983 + case 8: 988 984 YY_RULE_SETUP 989 - #line 135 "dtc-lexer.l" 985 + #line 136 "dtc-lexer.l" 990 986 { 991 - yylloc.filenum = srcpos_filenum; 987 + yylloc.file = srcpos_file; 992 988 yylloc.first_line = yylineno; 993 989 yylval.literal = strdup(yytext); 994 990 DPRINT("Literal: '%s'\n", yylval.literal); 995 991 return DT_LITERAL; 996 992 } 997 993 YY_BREAK 998 - case 10: 994 + case 9: 999 995 YY_RULE_SETUP 1000 - #line 143 "dtc-lexer.l" 996 + #line 144 "dtc-lexer.l" 1001 997 { /* label reference */ 1002 - yylloc.filenum = srcpos_filenum; 998 + yylloc.file = srcpos_file; 1003 999 yylloc.first_line = yylineno; 1004 1000 DPRINT("Ref: %s\n", yytext+1); 1005 1001 yylval.labelref = strdup(yytext+1); 1006 1002 return DT_REF; 1007 1003 } 1008 1004 YY_BREAK 1009 - case 11: 1005 + case 10: 1010 1006 YY_RULE_SETUP 1011 - #line 151 "dtc-lexer.l" 1007 + #line 152 "dtc-lexer.l" 1012 1008 { /* new-style path reference */ 1013 - yylloc.filenum = srcpos_filenum; 1009 + yylloc.file = srcpos_file; 1014 1010 yylloc.first_line = yylineno; 1015 1011 yytext[yyleng-1] = '\0'; 1016 1012 DPRINT("Ref: %s\n", yytext+2); ··· 1018 1014 return DT_REF; 1019 1015 } 1020 1016 YY_BREAK 1021 - case 12: 1017 + case 11: 1022 1018 YY_RULE_SETUP 1023 - #line 160 "dtc-lexer.l" 1019 + #line 161 "dtc-lexer.l" 1024 1020 { /* old-style path reference */ 1025 - yylloc.filenum = srcpos_filenum; 1021 + yylloc.file = srcpos_file; 1026 1022 yylloc.first_line = yylineno; 1027 1023 DPRINT("Ref: %s\n", yytext+1); 1028 1024 yylval.labelref = strdup(yytext+1); 1029 1025 return DT_REF; 1030 1026 } 1031 1027 YY_BREAK 1032 - case 13: 1028 + case 12: 1033 1029 YY_RULE_SETUP 1034 - #line 168 "dtc-lexer.l" 1030 + #line 169 "dtc-lexer.l" 1035 1031 { 1036 - yylloc.filenum = srcpos_filenum; 1032 + yylloc.file = srcpos_file; 1037 1033 yylloc.first_line = yylineno; 1038 1034 yylval.byte = strtol(yytext, NULL, 16); 1039 1035 DPRINT("Byte: %02x\n", (int)yylval.byte); 1040 1036 return DT_BYTE; 1041 1037 } 1042 1038 YY_BREAK 1043 - case 14: 1039 + case 13: 1044 1040 YY_RULE_SETUP 1045 - #line 176 "dtc-lexer.l" 1041 + #line 177 "dtc-lexer.l" 1046 1042 { 1047 - yylloc.filenum = srcpos_filenum; 1043 + yylloc.file = srcpos_file; 1048 1044 yylloc.first_line = yylineno; 1049 1045 DPRINT("/BYTESTRING\n"); 1050 1046 BEGIN_DEFAULT(); 1051 1047 return ']'; 1052 1048 } 1053 1049 YY_BREAK 1054 - case 15: 1050 + case 14: 1055 1051 YY_RULE_SETUP 1056 - #line 184 "dtc-lexer.l" 1052 + #line 185 "dtc-lexer.l" 1057 1053 { 1058 - yylloc.filenum = srcpos_filenum; 1054 + yylloc.file = srcpos_file; 1059 1055 yylloc.first_line = yylineno; 1060 1056 DPRINT("PropNodeName: %s\n", yytext); 1061 1057 yylval.propnodename = strdup(yytext); ··· 1063 1059 return DT_PROPNODENAME; 1064 1060 } 1065 1061 YY_BREAK 1062 + case 15: 1063 + YY_RULE_SETUP 1064 + #line 194 "dtc-lexer.l" 1065 + { 1066 + yylloc.file = srcpos_file; 1067 + yylloc.first_line = yylineno; 1068 + DPRINT("Binary Include\n"); 1069 + return DT_INCBIN; 1070 + } 1071 + YY_BREAK 1066 1072 case 16: 1067 1073 /* rule 16 can match eol */ 1068 1074 YY_RULE_SETUP 1069 - #line 194 "dtc-lexer.l" 1075 + #line 201 "dtc-lexer.l" 1070 1076 /* eat whitespace */ 1071 1077 YY_BREAK 1072 1078 case 17: 1073 1079 /* rule 17 can match eol */ 1074 1080 YY_RULE_SETUP 1075 - #line 196 "dtc-lexer.l" 1076 - { 1077 - yylloc.filenum = srcpos_filenum; 1078 - yylloc.first_line = yylineno; 1079 - DPRINT("Comment: %s\n", yytext); 1080 - /* eat comments */ 1081 - } 1081 + #line 202 "dtc-lexer.l" 1082 + /* eat C-style comments */ 1082 1083 YY_BREAK 1083 1084 case 18: 1084 1085 /* rule 18 can match eol */ 1085 1086 YY_RULE_SETUP 1086 1087 #line 203 "dtc-lexer.l" 1087 - /* eat line comments */ 1088 + /* eat C++-style comments */ 1088 1089 YY_BREAK 1089 1090 case 19: 1090 1091 YY_RULE_SETUP 1091 1092 #line 205 "dtc-lexer.l" 1092 1093 { 1093 - yylloc.filenum = srcpos_filenum; 1094 + yylloc.file = srcpos_file; 1094 1095 yylloc.first_line = yylineno; 1095 1096 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 1096 1097 (unsigned)yytext[0]); ··· 1116 1107 #line 222 "dtc-lexer.l" 1117 1108 ECHO; 1118 1109 YY_BREAK 1119 - #line 1111 "dtc-lexer.lex.c" 1110 + #line 1120 "dtc-lexer.lex.c" 1120 1111 1121 1112 case YY_END_OF_BUFFER: 1122 1113 { ··· 1369 1360 else 1370 1361 ret_val = EOB_ACT_CONTINUE_SCAN; 1371 1362 1363 + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { 1364 + /* Extend the array by 50%, plus the number we really need. */ 1365 + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); 1366 + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); 1367 + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) 1368 + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); 1369 + } 1370 + 1372 1371 (yy_n_chars) += number_to_move; 1373 1372 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; 1374 1373 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; ··· 1406 1389 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1407 1390 { 1408 1391 yy_current_state = (int) yy_def[yy_current_state]; 1409 - if ( yy_current_state >= 94 ) 1392 + if ( yy_current_state >= 104 ) 1410 1393 yy_c = yy_meta[(unsigned int) yy_c]; 1411 1394 } 1412 1395 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ··· 1434 1417 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1435 1418 { 1436 1419 yy_current_state = (int) yy_def[yy_current_state]; 1437 - if ( yy_current_state >= 94 ) 1420 + if ( yy_current_state >= 104 ) 1438 1421 yy_c = yy_meta[(unsigned int) yy_c]; 1439 1422 } 1440 1423 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; 1441 - yy_is_jam = (yy_current_state == 93); 1424 + yy_is_jam = (yy_current_state == 103); 1442 1425 1443 1426 return yy_is_jam ? 0 : yy_current_state; 1444 1427 } ··· 1760 1743 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc 1761 1744 (num_to_alloc * sizeof(struct yy_buffer_state*) 1762 1745 ); 1763 - 1746 + if ( ! (yy_buffer_stack) ) 1747 + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); 1748 + 1764 1749 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); 1765 1750 1766 1751 (yy_buffer_stack_max) = num_to_alloc; ··· 1780 1761 ((yy_buffer_stack), 1781 1762 num_to_alloc * sizeof(struct yy_buffer_state*) 1782 1763 ); 1764 + if ( ! (yy_buffer_stack) ) 1765 + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); 1783 1766 1784 1767 /* zero only the new slots.*/ 1785 1768 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); ··· 2093 2072 */ 2094 2073 2095 2074 struct incl_file { 2096 - int filenum; 2097 - FILE *file; 2075 + struct dtc_file *file; 2098 2076 YY_BUFFER_STATE yy_prev_buf; 2099 2077 int yy_prev_lineno; 2100 2078 struct incl_file *prev; 2101 2079 }; 2102 2080 2103 - struct incl_file *incl_file_stack; 2081 + static struct incl_file *incl_file_stack; 2104 2082 2105 2083 2106 2084 /* ··· 2110 2090 static int incl_depth = 0; 2111 2091 2112 2092 2113 - int push_input_file(const char *filename) 2093 + static void push_input_file(const char *filename) 2114 2094 { 2115 - FILE *f; 2116 2095 struct incl_file *incl_file; 2096 + struct dtc_file *newfile; 2097 + struct search_path search, *searchptr = NULL; 2117 2098 2118 - if (!filename) { 2119 - yyerror("No include file name given."); 2120 - return 0; 2099 + assert(filename); 2100 + 2101 + if (incl_depth++ >= MAX_INCLUDE_DEPTH) 2102 + die("Includes nested too deeply"); 2103 + 2104 + if (srcpos_file) { 2105 + search.dir = srcpos_file->dir; 2106 + search.next = NULL; 2107 + search.prev = NULL; 2108 + searchptr = &search; 2121 2109 } 2122 2110 2123 - if (incl_depth++ >= MAX_INCLUDE_DEPTH) { 2124 - yyerror("Includes nested too deeply"); 2125 - return 0; 2126 - } 2111 + newfile = dtc_open_file(filename, searchptr); 2127 2112 2128 - f = dtc_open_file(filename); 2129 - 2130 - incl_file = malloc(sizeof(struct incl_file)); 2131 - if (!incl_file) { 2132 - yyerror("Can not allocate include file space."); 2133 - return 0; 2134 - } 2113 + incl_file = xmalloc(sizeof(struct incl_file)); 2135 2114 2136 2115 /* 2137 2116 * Save current context. 2138 2117 */ 2139 2118 incl_file->yy_prev_buf = YY_CURRENT_BUFFER; 2140 2119 incl_file->yy_prev_lineno = yylineno; 2141 - incl_file->filenum = srcpos_filenum; 2142 - incl_file->file = yyin; 2120 + incl_file->file = srcpos_file; 2143 2121 incl_file->prev = incl_file_stack; 2144 2122 2145 2123 incl_file_stack = incl_file; ··· 2145 2127 /* 2146 2128 * Establish new context. 2147 2129 */ 2148 - srcpos_filenum = lookup_file_name(filename, 0); 2130 + srcpos_file = newfile; 2149 2131 yylineno = 1; 2150 - yyin = f; 2132 + yyin = newfile->file; 2151 2133 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); 2152 - 2153 - return 1; 2154 2134 } 2155 2135 2156 2136 2157 - int pop_input_file(void) 2137 + static int pop_input_file(void) 2158 2138 { 2159 2139 struct incl_file *incl_file; 2160 2140 2161 2141 if (incl_file_stack == 0) 2162 2142 return 0; 2163 2143 2164 - fclose(yyin); 2144 + dtc_close_file(srcpos_file); 2165 2145 2166 2146 /* 2167 2147 * Pop. ··· 2174 2158 yy_delete_buffer(YY_CURRENT_BUFFER); 2175 2159 yy_switch_to_buffer(incl_file->yy_prev_buf); 2176 2160 yylineno = incl_file->yy_prev_lineno; 2177 - srcpos_filenum = incl_file->filenum; 2178 - yyin = incl_file->file; 2161 + srcpos_file = incl_file->file; 2162 + yyin = incl_file->file ? incl_file->file->file : NULL; 2179 2163 2180 2164 /* 2181 2165 * Free old state. 2182 2166 */ 2183 2167 free(incl_file); 2184 - 2185 - if (YY_CURRENT_BUFFER == 0) 2186 - return 0; 2187 2168 2188 2169 return 1; 2189 2170 }
+227 -170
arch/powerpc/boot/dtc-src/dtc-parser.tab.c_shipped
··· 75 75 DT_BYTE = 264, 76 76 DT_STRING = 265, 77 77 DT_LABEL = 266, 78 - DT_REF = 267 78 + DT_REF = 267, 79 + DT_INCBIN = 268 79 80 }; 80 81 #endif 81 82 /* Tokens. */ ··· 90 89 #define DT_STRING 265 91 90 #define DT_LABEL 266 92 91 #define DT_REF 267 92 + #define DT_INCBIN 268 93 93 94 94 95 95 ··· 98 96 /* Copy the first part of user declarations. */ 99 97 #line 23 "dtc-parser.y" 100 98 99 + #include <stdio.h> 100 + 101 101 #include "dtc.h" 102 102 #include "srcpos.h" 103 103 104 - int yylex(void); 105 - unsigned long long eval_literal(const char *s, int base, int bits); 104 + extern int yylex(void); 106 105 107 106 extern struct boot_info *the_boot_info; 107 + extern int treesource_error; 108 108 109 + static unsigned long long eval_literal(const char *s, int base, int bits); 109 110 110 111 111 112 /* Enabling traces. */ ··· 131 126 132 127 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 133 128 typedef union YYSTYPE 134 - #line 34 "dtc-parser.y" 129 + #line 37 "dtc-parser.y" 135 130 { 136 131 char *propnodename; 137 132 char *literal; 138 133 char *labelref; 139 134 unsigned int cbase; 140 - u8 byte; 135 + uint8_t byte; 141 136 struct data data; 142 137 143 - u64 addr; 138 + uint64_t addr; 144 139 cell_t cell; 145 140 struct property *prop; 146 141 struct property *proplist; ··· 149 144 struct reserve_info *re; 150 145 } 151 146 /* Line 187 of yacc.c. */ 152 - #line 148 "dtc-parser.tab.c" 147 + #line 153 "dtc-parser.tab.c" 153 148 YYSTYPE; 154 149 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 155 150 # define YYSTYPE_IS_DECLARED 1 ··· 174 169 175 170 176 171 /* Line 216 of yacc.c. */ 177 - #line 173 "dtc-parser.tab.c" 172 + #line 178 "dtc-parser.tab.c" 178 173 179 174 #ifdef short 180 175 # undef short ··· 391 386 /* YYFINAL -- State number of the termination state. */ 392 387 #define YYFINAL 9 393 388 /* YYLAST -- Last index in YYTABLE. */ 394 - #define YYLAST 60 389 + #define YYLAST 73 395 390 396 391 /* YYNTOKENS -- Number of terminals. */ 397 - #define YYNTOKENS 24 392 + #define YYNTOKENS 27 398 393 /* YYNNTS -- Number of nonterminals. */ 399 394 #define YYNNTS 20 400 395 /* YYNRULES -- Number of rules. */ 401 - #define YYNRULES 43 396 + #define YYNRULES 45 402 397 /* YYNRULES -- Number of states. */ 403 - #define YYNSTATES 67 398 + #define YYNSTATES 76 404 399 405 400 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 406 401 #define YYUNDEFTOK 2 407 - #define YYMAXUTOK 267 402 + #define YYMAXUTOK 268 408 403 409 404 #define YYTRANSLATE(YYX) \ 410 405 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) ··· 416 411 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 417 412 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 418 413 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 419 - 2, 2, 2, 2, 23, 14, 2, 15, 2, 2, 420 - 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, 421 - 19, 18, 20, 2, 2, 2, 2, 2, 2, 2, 414 + 24, 26, 2, 2, 25, 15, 2, 16, 2, 2, 415 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 416 + 20, 19, 21, 2, 2, 2, 2, 2, 2, 2, 422 417 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 423 418 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 424 - 2, 21, 2, 22, 2, 2, 2, 2, 2, 2, 419 + 2, 22, 2, 23, 2, 2, 2, 2, 2, 2, 425 420 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 426 421 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 427 - 2, 2, 2, 16, 2, 17, 2, 2, 2, 2, 422 + 2, 2, 2, 17, 2, 18, 2, 2, 2, 2, 428 423 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 429 424 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 430 425 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ··· 438 433 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 439 434 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 440 435 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 441 - 5, 6, 7, 8, 9, 10, 11, 12 436 + 5, 6, 7, 8, 9, 10, 11, 12, 13 442 437 }; 443 438 444 439 #if YYDEBUG ··· 448 443 { 449 444 0, 0, 3, 8, 11, 12, 15, 21, 22, 25, 450 445 27, 34, 36, 38, 41, 47, 48, 51, 57, 61, 451 - 64, 69, 74, 77, 80, 81, 84, 87, 88, 91, 452 - 94, 97, 98, 100, 102, 105, 106, 109, 112, 113, 453 - 116, 119, 123, 124 446 + 64, 69, 74, 77, 87, 93, 96, 97, 100, 103, 447 + 104, 107, 110, 113, 114, 116, 118, 121, 122, 125, 448 + 128, 129, 132, 135, 139, 140 454 449 }; 455 450 456 451 /* YYRHS -- A `-1'-separated list of the rules' RHS. */ 457 452 static const yytype_int8 yyrhs[] = 458 453 { 459 - 25, 0, -1, 3, 13, 26, 31, -1, 28, 31, 460 - -1, -1, 27, 26, -1, 43, 4, 30, 30, 13, 461 - -1, -1, 29, 28, -1, 27, -1, 43, 4, 30, 462 - 14, 30, 13, -1, 6, -1, 7, -1, 15, 32, 463 - -1, 16, 33, 41, 17, 13, -1, -1, 33, 34, 464 - -1, 43, 5, 18, 35, 13, -1, 43, 5, 13, 465 - -1, 36, 10, -1, 36, 19, 37, 20, -1, 36, 466 - 21, 40, 22, -1, 36, 12, -1, 35, 11, -1, 467 - -1, 35, 23, -1, 36, 11, -1, -1, 37, 39, 468 - -1, 37, 12, -1, 37, 11, -1, -1, 8, -1, 469 - 6, -1, 38, 7, -1, -1, 40, 9, -1, 40, 470 - 11, -1, -1, 42, 41, -1, 42, 34, -1, 43, 471 - 5, 32, -1, -1, 11, -1 454 + 28, 0, -1, 3, 14, 29, 34, -1, 31, 34, 455 + -1, -1, 30, 29, -1, 46, 4, 33, 33, 14, 456 + -1, -1, 32, 31, -1, 30, -1, 46, 4, 33, 457 + 15, 33, 14, -1, 6, -1, 7, -1, 16, 35, 458 + -1, 17, 36, 44, 18, 14, -1, -1, 36, 37, 459 + -1, 46, 5, 19, 38, 14, -1, 46, 5, 14, 460 + -1, 39, 10, -1, 39, 20, 40, 21, -1, 39, 461 + 22, 43, 23, -1, 39, 12, -1, 39, 13, 24, 462 + 10, 25, 33, 25, 33, 26, -1, 39, 13, 24, 463 + 10, 26, -1, 38, 11, -1, -1, 38, 25, -1, 464 + 39, 11, -1, -1, 40, 42, -1, 40, 12, -1, 465 + 40, 11, -1, -1, 8, -1, 6, -1, 41, 7, 466 + -1, -1, 43, 9, -1, 43, 11, -1, -1, 45, 467 + 44, -1, 45, 37, -1, 46, 5, 35, -1, -1, 468 + 11, -1 472 469 }; 473 470 474 471 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 475 472 static const yytype_uint16 yyrline[] = 476 473 { 477 - 0, 85, 85, 89, 97, 100, 107, 115, 118, 125, 478 - 129, 136, 140, 147, 154, 162, 165, 172, 176, 183, 479 - 187, 191, 195, 199, 207, 210, 214, 222, 225, 229, 480 - 234, 242, 245, 249, 253, 261, 264, 268, 276, 279, 481 - 283, 291, 299, 302 474 + 0, 89, 89, 93, 101, 104, 111, 119, 122, 129, 475 + 133, 140, 144, 151, 158, 166, 169, 176, 180, 187, 476 + 191, 195, 199, 203, 220, 231, 239, 242, 246, 254, 477 + 257, 261, 266, 274, 277, 281, 285, 293, 296, 300, 478 + 308, 311, 315, 323, 331, 334 482 479 }; 483 480 #endif 484 481 ··· 491 484 { 492 485 "$end", "error", "$undefined", "DT_V1", "DT_MEMRESERVE", 493 486 "DT_PROPNODENAME", "DT_LITERAL", "DT_LEGACYLITERAL", "DT_BASE", 494 - "DT_BYTE", "DT_STRING", "DT_LABEL", "DT_REF", "';'", "'-'", "'/'", "'{'", 495 - "'}'", "'='", "'<'", "'>'", "'['", "']'", "','", "$accept", "sourcefile", 496 - "memreserves", "memreserve", "v0_memreserves", "v0_memreserve", "addr", 497 - "devicetree", "nodedef", "proplist", "propdef", "propdata", 498 - "propdataprefix", "celllist", "cellbase", "cellval", "bytestring", 499 - "subnodes", "subnode", "label", 0 487 + "DT_BYTE", "DT_STRING", "DT_LABEL", "DT_REF", "DT_INCBIN", "';'", "'-'", 488 + "'/'", "'{'", "'}'", "'='", "'<'", "'>'", "'['", "']'", "'('", "','", 489 + "')'", "$accept", "sourcefile", "memreserves", "memreserve", 490 + "v0_memreserves", "v0_memreserve", "addr", "devicetree", "nodedef", 491 + "proplist", "propdef", "propdata", "propdataprefix", "celllist", 492 + "cellbase", "cellval", "bytestring", "subnodes", "subnode", "label", 0 500 493 }; 501 494 #endif 502 495 ··· 506 499 static const yytype_uint16 yytoknum[] = 507 500 { 508 501 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 509 - 265, 266, 267, 59, 45, 47, 123, 125, 61, 60, 510 - 62, 91, 93, 44 502 + 265, 266, 267, 268, 59, 45, 47, 123, 125, 61, 503 + 60, 62, 91, 93, 40, 44, 41 511 504 }; 512 505 # endif 513 506 514 507 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 515 508 static const yytype_uint8 yyr1[] = 516 509 { 517 - 0, 24, 25, 25, 26, 26, 27, 28, 28, 29, 518 - 29, 30, 30, 31, 32, 33, 33, 34, 34, 35, 519 - 35, 35, 35, 35, 36, 36, 36, 37, 37, 37, 520 - 37, 38, 38, 39, 39, 40, 40, 40, 41, 41, 521 - 41, 42, 43, 43 510 + 0, 27, 28, 28, 29, 29, 30, 31, 31, 32, 511 + 32, 33, 33, 34, 35, 36, 36, 37, 37, 38, 512 + 38, 38, 38, 38, 38, 38, 39, 39, 39, 40, 513 + 40, 40, 40, 41, 41, 42, 42, 43, 43, 43, 514 + 44, 44, 44, 45, 46, 46 522 515 }; 523 516 524 517 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ ··· 526 519 { 527 520 0, 2, 4, 2, 0, 2, 5, 0, 2, 1, 528 521 6, 1, 1, 2, 5, 0, 2, 5, 3, 2, 529 - 4, 4, 2, 2, 0, 2, 2, 0, 2, 2, 530 - 2, 0, 1, 1, 2, 0, 2, 2, 0, 2, 531 - 2, 3, 0, 1 522 + 4, 4, 2, 9, 5, 2, 0, 2, 2, 0, 523 + 2, 2, 2, 0, 1, 1, 2, 0, 2, 2, 524 + 0, 2, 2, 3, 0, 1 532 525 }; 533 526 534 527 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state ··· 536 529 means the default is an error. */ 537 530 static const yytype_uint8 yydefact[] = 538 531 { 539 - 7, 0, 43, 0, 9, 0, 7, 0, 4, 1, 532 + 7, 0, 45, 0, 9, 0, 7, 0, 4, 1, 540 533 0, 3, 8, 0, 0, 4, 0, 15, 13, 11, 541 - 12, 0, 2, 5, 0, 38, 0, 0, 0, 16, 542 - 0, 38, 0, 0, 6, 0, 40, 39, 0, 10, 543 - 14, 18, 24, 41, 0, 0, 23, 17, 25, 19, 544 - 26, 22, 27, 35, 31, 0, 33, 32, 30, 29, 545 - 20, 0, 28, 36, 37, 21, 34 534 + 12, 0, 2, 5, 0, 40, 0, 0, 0, 16, 535 + 0, 40, 0, 0, 6, 0, 42, 41, 0, 10, 536 + 14, 18, 26, 43, 0, 0, 25, 17, 27, 19, 537 + 28, 22, 0, 29, 37, 0, 33, 0, 0, 35, 538 + 34, 32, 31, 20, 0, 30, 38, 39, 21, 0, 539 + 24, 36, 0, 0, 0, 23 546 540 }; 547 541 548 542 /* YYDEFGOTO[NTERM-NUM]. */ 549 543 static const yytype_int8 yydefgoto[] = 550 544 { 551 545 -1, 3, 14, 4, 5, 6, 27, 11, 18, 25, 552 - 29, 44, 45, 54, 61, 62, 55, 30, 31, 7 546 + 29, 44, 45, 56, 64, 65, 57, 30, 31, 7 553 547 }; 554 548 555 549 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 556 550 STATE-NUM. */ 557 - #define YYPACT_NINF -13 551 + #define YYPACT_NINF -14 558 552 static const yytype_int8 yypact[] = 559 553 { 560 - 23, 11, -13, 37, -13, -4, 18, 39, 18, -13, 561 - 28, -13, -13, 34, -4, 18, 41, -13, -13, -13, 562 - -13, 25, -13, -13, 34, -3, 34, 33, 34, -13, 563 - 30, -3, 43, 36, -13, 38, -13, -13, 20, -13, 564 - -13, -13, -13, -13, 2, 9, -13, -13, -13, -13, 565 - -13, -13, -13, -13, -2, -6, -13, -13, -13, -13, 566 - -13, 45, -13, -13, -13, -13, -13 554 + 30, -11, -14, 7, -14, -1, 27, 13, 27, -14, 555 + 8, -14, -14, 40, -1, 27, 35, -14, -14, -14, 556 + -14, 21, -14, -14, 40, 24, 40, 28, 40, -14, 557 + 32, 24, 46, 38, -14, 39, -14, -14, 26, -14, 558 + -14, -14, -14, -14, -9, 10, -14, -14, -14, -14, 559 + -14, -14, 31, -14, -14, 44, -2, 3, 23, -14, 560 + -14, -14, -14, -14, 50, -14, -14, -14, -14, 40, 561 + -14, -14, 33, 40, 36, -14 567 562 }; 568 563 569 564 /* YYPGOTO[NTERM-NUM]. */ 570 565 static const yytype_int8 yypgoto[] = 571 566 { 572 - -13, -13, 35, 27, 47, -13, -12, 40, 17, -13, 573 - 26, -13, -13, -13, -13, -13, -13, 29, -13, -8 567 + -14, -14, 48, 29, 53, -14, -13, 47, 34, -14, 568 + 37, -14, -14, -14, -14, -14, -14, 42, -14, -7 574 569 }; 575 570 576 571 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 577 572 positive, shift that token. If negative, reduce the rule which 578 573 number is the opposite. If zero, do what YYDEFACT says. 579 574 If YYTABLE_NINF, syntax error. */ 580 - #define YYTABLE_NINF -43 575 + #define YYTABLE_NINF -45 581 576 static const yytype_int8 yytable[] = 582 577 { 583 - 16, 21, -42, 63, 56, 64, 57, 16, 2, 58, 584 - 59, 10, 28, 46, 33, 47, 65, 32, 60, 49, 585 - 50, 51, -42, 32, 8, 48, 1, -42, 52, 2, 586 - 53, 19, 20, 41, 2, 15, 17, 9, 42, 26, 587 - 19, 20, 15, 13, 17, 24, 34, 35, 38, 39, 588 - 23, 40, 66, 12, 22, 43, 0, 36, 0, 0, 589 - 37 578 + 21, 16, 46, 8, 59, 47, 60, 9, 16, 61, 579 + 62, 28, 66, 33, 67, 10, 48, 13, 32, 63, 580 + 49, 50, 51, 52, 32, 17, 68, 19, 20, -44, 581 + 53, -44, 54, 1, -44, 2, 26, 15, 2, 24, 582 + 41, 2, 34, 17, 15, 42, 19, 20, 69, 70, 583 + 35, 38, 39, 40, 58, 55, 72, 71, 73, 12, 584 + 74, 22, 75, 23, 0, 0, 0, 0, 36, 0, 585 + 0, 0, 43, 37 590 586 }; 591 587 592 588 static const yytype_int8 yycheck[] = 593 589 { 594 - 8, 13, 5, 9, 6, 11, 8, 15, 11, 11, 595 - 12, 15, 24, 11, 26, 13, 22, 25, 20, 10, 596 - 11, 12, 4, 31, 13, 23, 3, 4, 19, 11, 597 - 21, 6, 7, 13, 11, 8, 16, 0, 18, 14, 598 - 6, 7, 15, 4, 16, 4, 13, 17, 5, 13, 599 - 15, 13, 7, 6, 14, 38, -1, 31, -1, -1, 600 - 31 590 + 13, 8, 11, 14, 6, 14, 8, 0, 15, 11, 591 + 12, 24, 9, 26, 11, 16, 25, 4, 25, 21, 592 + 10, 11, 12, 13, 31, 17, 23, 6, 7, 5, 593 + 20, 4, 22, 3, 4, 11, 15, 8, 11, 4, 594 + 14, 11, 14, 17, 15, 19, 6, 7, 25, 26, 595 + 18, 5, 14, 14, 10, 24, 69, 7, 25, 6, 596 + 73, 14, 26, 15, -1, -1, -1, -1, 31, -1, 597 + -1, -1, 38, 31 601 598 }; 602 599 603 600 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 604 601 symbol of state STATE-NUM. */ 605 602 static const yytype_uint8 yystos[] = 606 603 { 607 - 0, 3, 11, 25, 27, 28, 29, 43, 13, 0, 608 - 15, 31, 28, 4, 26, 27, 43, 16, 32, 6, 609 - 7, 30, 31, 26, 4, 33, 14, 30, 30, 34, 610 - 41, 42, 43, 30, 13, 17, 34, 41, 5, 13, 611 - 13, 13, 18, 32, 35, 36, 11, 13, 23, 10, 612 - 11, 12, 19, 21, 37, 40, 6, 8, 11, 12, 613 - 20, 38, 39, 9, 11, 22, 7 604 + 0, 3, 11, 28, 30, 31, 32, 46, 14, 0, 605 + 16, 34, 31, 4, 29, 30, 46, 17, 35, 6, 606 + 7, 33, 34, 29, 4, 36, 15, 33, 33, 37, 607 + 44, 45, 46, 33, 14, 18, 37, 44, 5, 14, 608 + 14, 14, 19, 35, 38, 39, 11, 14, 25, 10, 609 + 11, 12, 13, 20, 22, 24, 40, 43, 10, 6, 610 + 8, 11, 12, 21, 41, 42, 9, 11, 23, 25, 611 + 26, 7, 33, 25, 33, 26 614 612 }; 615 613 616 614 #define yyerrok (yyerrstatus = 0) ··· 1452 1440 switch (yyn) 1453 1441 { 1454 1442 case 2: 1455 - #line 86 "dtc-parser.y" 1443 + #line 90 "dtc-parser.y" 1456 1444 { 1457 - the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node)); 1445 + the_boot_info = build_boot_info((yyvsp[(3) - (4)].re), (yyvsp[(4) - (4)].node), 0); 1458 1446 ;} 1459 1447 break; 1460 1448 1461 1449 case 3: 1462 - #line 90 "dtc-parser.y" 1450 + #line 94 "dtc-parser.y" 1463 1451 { 1464 - the_boot_info = build_boot_info((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].node)); 1452 + the_boot_info = build_boot_info((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].node), 0); 1465 1453 ;} 1466 1454 break; 1467 1455 1468 1456 case 4: 1469 - #line 97 "dtc-parser.y" 1457 + #line 101 "dtc-parser.y" 1470 1458 { 1471 1459 (yyval.re) = NULL; 1472 1460 ;} 1473 1461 break; 1474 1462 1475 1463 case 5: 1476 - #line 101 "dtc-parser.y" 1464 + #line 105 "dtc-parser.y" 1477 1465 { 1478 1466 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1479 1467 ;} 1480 1468 break; 1481 1469 1482 1470 case 6: 1483 - #line 108 "dtc-parser.y" 1471 + #line 112 "dtc-parser.y" 1484 1472 { 1485 1473 (yyval.re) = build_reserve_entry((yyvsp[(3) - (5)].addr), (yyvsp[(4) - (5)].addr), (yyvsp[(1) - (5)].labelref)); 1486 1474 ;} 1487 1475 break; 1488 1476 1489 1477 case 7: 1490 - #line 115 "dtc-parser.y" 1478 + #line 119 "dtc-parser.y" 1491 1479 { 1492 1480 (yyval.re) = NULL; 1493 1481 ;} 1494 1482 break; 1495 1483 1496 1484 case 8: 1497 - #line 119 "dtc-parser.y" 1485 + #line 123 "dtc-parser.y" 1498 1486 { 1499 1487 (yyval.re) = chain_reserve_entry((yyvsp[(1) - (2)].re), (yyvsp[(2) - (2)].re)); 1500 1488 ;} 1501 1489 break; 1502 1490 1503 1491 case 9: 1504 - #line 126 "dtc-parser.y" 1492 + #line 130 "dtc-parser.y" 1505 1493 { 1506 1494 (yyval.re) = (yyvsp[(1) - (1)].re); 1507 1495 ;} 1508 1496 break; 1509 1497 1510 1498 case 10: 1511 - #line 130 "dtc-parser.y" 1499 + #line 134 "dtc-parser.y" 1512 1500 { 1513 1501 (yyval.re) = build_reserve_entry((yyvsp[(3) - (6)].addr), (yyvsp[(5) - (6)].addr) - (yyvsp[(3) - (6)].addr) + 1, (yyvsp[(1) - (6)].labelref)); 1514 1502 ;} 1515 1503 break; 1516 1504 1517 1505 case 11: 1518 - #line 137 "dtc-parser.y" 1506 + #line 141 "dtc-parser.y" 1519 1507 { 1520 1508 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 0, 64); 1521 1509 ;} 1522 1510 break; 1523 1511 1524 1512 case 12: 1525 - #line 141 "dtc-parser.y" 1513 + #line 145 "dtc-parser.y" 1526 1514 { 1527 1515 (yyval.addr) = eval_literal((yyvsp[(1) - (1)].literal), 16, 64); 1528 1516 ;} 1529 1517 break; 1530 1518 1531 1519 case 13: 1532 - #line 148 "dtc-parser.y" 1520 + #line 152 "dtc-parser.y" 1533 1521 { 1534 1522 (yyval.node) = name_node((yyvsp[(2) - (2)].node), "", NULL); 1535 1523 ;} 1536 1524 break; 1537 1525 1538 1526 case 14: 1539 - #line 155 "dtc-parser.y" 1527 + #line 159 "dtc-parser.y" 1540 1528 { 1541 1529 (yyval.node) = build_node((yyvsp[(2) - (5)].proplist), (yyvsp[(3) - (5)].nodelist)); 1542 1530 ;} 1543 1531 break; 1544 1532 1545 1533 case 15: 1546 - #line 162 "dtc-parser.y" 1534 + #line 166 "dtc-parser.y" 1547 1535 { 1548 1536 (yyval.proplist) = NULL; 1549 1537 ;} 1550 1538 break; 1551 1539 1552 1540 case 16: 1553 - #line 166 "dtc-parser.y" 1541 + #line 170 "dtc-parser.y" 1554 1542 { 1555 1543 (yyval.proplist) = chain_property((yyvsp[(2) - (2)].prop), (yyvsp[(1) - (2)].proplist)); 1556 1544 ;} 1557 1545 break; 1558 1546 1559 1547 case 17: 1560 - #line 173 "dtc-parser.y" 1548 + #line 177 "dtc-parser.y" 1561 1549 { 1562 1550 (yyval.prop) = build_property((yyvsp[(2) - (5)].propnodename), (yyvsp[(4) - (5)].data), (yyvsp[(1) - (5)].labelref)); 1563 1551 ;} 1564 1552 break; 1565 1553 1566 1554 case 18: 1567 - #line 177 "dtc-parser.y" 1555 + #line 181 "dtc-parser.y" 1568 1556 { 1569 1557 (yyval.prop) = build_property((yyvsp[(2) - (3)].propnodename), empty_data, (yyvsp[(1) - (3)].labelref)); 1570 1558 ;} 1571 1559 break; 1572 1560 1573 1561 case 19: 1574 - #line 184 "dtc-parser.y" 1562 + #line 188 "dtc-parser.y" 1575 1563 { 1576 1564 (yyval.data) = data_merge((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].data)); 1577 1565 ;} 1578 1566 break; 1579 1567 1580 1568 case 20: 1581 - #line 188 "dtc-parser.y" 1582 - { 1583 - (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data)); 1584 - ;} 1585 - break; 1586 - 1587 - case 21: 1588 1569 #line 192 "dtc-parser.y" 1589 1570 { 1590 1571 (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data)); 1591 1572 ;} 1592 1573 break; 1593 1574 1594 - case 22: 1575 + case 21: 1595 1576 #line 196 "dtc-parser.y" 1577 + { 1578 + (yyval.data) = data_merge((yyvsp[(1) - (4)].data), (yyvsp[(3) - (4)].data)); 1579 + ;} 1580 + break; 1581 + 1582 + case 22: 1583 + #line 200 "dtc-parser.y" 1596 1584 { 1597 1585 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), REF_PATH, (yyvsp[(2) - (2)].labelref)); 1598 1586 ;} 1599 1587 break; 1600 1588 1601 1589 case 23: 1602 - #line 200 "dtc-parser.y" 1590 + #line 204 "dtc-parser.y" 1591 + { 1592 + struct search_path path = { srcpos_file->dir, NULL, NULL }; 1593 + struct dtc_file *file = dtc_open_file((yyvsp[(4) - (9)].data).val, &path); 1594 + struct data d = empty_data; 1595 + 1596 + if ((yyvsp[(6) - (9)].addr) != 0) 1597 + if (fseek(file->file, (yyvsp[(6) - (9)].addr), SEEK_SET) != 0) 1598 + yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 1599 + (unsigned long long)(yyvsp[(6) - (9)].addr), 1600 + (yyvsp[(4) - (9)].data).val, strerror(errno)); 1601 + 1602 + d = data_copy_file(file->file, (yyvsp[(8) - (9)].addr)); 1603 + 1604 + (yyval.data) = data_merge((yyvsp[(1) - (9)].data), d); 1605 + dtc_close_file(file); 1606 + ;} 1607 + break; 1608 + 1609 + case 24: 1610 + #line 221 "dtc-parser.y" 1611 + { 1612 + struct search_path path = { srcpos_file->dir, NULL, NULL }; 1613 + struct dtc_file *file = dtc_open_file((yyvsp[(4) - (5)].data).val, &path); 1614 + struct data d = empty_data; 1615 + 1616 + d = data_copy_file(file->file, -1); 1617 + 1618 + (yyval.data) = data_merge((yyvsp[(1) - (5)].data), d); 1619 + dtc_close_file(file); 1620 + ;} 1621 + break; 1622 + 1623 + case 25: 1624 + #line 232 "dtc-parser.y" 1603 1625 { 1604 1626 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1605 1627 ;} 1606 1628 break; 1607 1629 1608 - case 24: 1609 - #line 207 "dtc-parser.y" 1630 + case 26: 1631 + #line 239 "dtc-parser.y" 1610 1632 { 1611 1633 (yyval.data) = empty_data; 1612 1634 ;} 1613 1635 break; 1614 1636 1615 - case 25: 1616 - #line 211 "dtc-parser.y" 1637 + case 27: 1638 + #line 243 "dtc-parser.y" 1617 1639 { 1618 1640 (yyval.data) = (yyvsp[(1) - (2)].data); 1619 1641 ;} 1620 1642 break; 1621 1643 1622 - case 26: 1623 - #line 215 "dtc-parser.y" 1644 + case 28: 1645 + #line 247 "dtc-parser.y" 1624 1646 { 1625 1647 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1626 1648 ;} 1627 1649 break; 1628 1650 1629 - case 27: 1630 - #line 222 "dtc-parser.y" 1651 + case 29: 1652 + #line 254 "dtc-parser.y" 1631 1653 { 1632 1654 (yyval.data) = empty_data; 1633 1655 ;} 1634 1656 break; 1635 1657 1636 - case 28: 1637 - #line 226 "dtc-parser.y" 1658 + case 30: 1659 + #line 258 "dtc-parser.y" 1638 1660 { 1639 1661 (yyval.data) = data_append_cell((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].cell)); 1640 1662 ;} 1641 1663 break; 1642 1664 1643 - case 29: 1644 - #line 230 "dtc-parser.y" 1665 + case 31: 1666 + #line 262 "dtc-parser.y" 1645 1667 { 1646 1668 (yyval.data) = data_append_cell(data_add_marker((yyvsp[(1) - (2)].data), REF_PHANDLE, 1647 1669 (yyvsp[(2) - (2)].labelref)), -1); 1648 1670 ;} 1649 1671 break; 1650 1672 1651 - case 30: 1652 - #line 235 "dtc-parser.y" 1673 + case 32: 1674 + #line 267 "dtc-parser.y" 1653 1675 { 1654 1676 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1655 1677 ;} 1656 1678 break; 1657 1679 1658 - case 31: 1659 - #line 242 "dtc-parser.y" 1680 + case 33: 1681 + #line 274 "dtc-parser.y" 1660 1682 { 1661 1683 (yyval.cbase) = 16; 1662 1684 ;} 1663 1685 break; 1664 1686 1665 - case 33: 1666 - #line 250 "dtc-parser.y" 1687 + case 35: 1688 + #line 282 "dtc-parser.y" 1667 1689 { 1668 1690 (yyval.cell) = eval_literal((yyvsp[(1) - (1)].literal), 0, 32); 1669 1691 ;} 1670 1692 break; 1671 1693 1672 - case 34: 1673 - #line 254 "dtc-parser.y" 1694 + case 36: 1695 + #line 286 "dtc-parser.y" 1674 1696 { 1675 1697 (yyval.cell) = eval_literal((yyvsp[(2) - (2)].literal), (yyvsp[(1) - (2)].cbase), 32); 1676 1698 ;} 1677 1699 break; 1678 1700 1679 - case 35: 1680 - #line 261 "dtc-parser.y" 1701 + case 37: 1702 + #line 293 "dtc-parser.y" 1681 1703 { 1682 1704 (yyval.data) = empty_data; 1683 1705 ;} 1684 1706 break; 1685 1707 1686 - case 36: 1687 - #line 265 "dtc-parser.y" 1708 + case 38: 1709 + #line 297 "dtc-parser.y" 1688 1710 { 1689 1711 (yyval.data) = data_append_byte((yyvsp[(1) - (2)].data), (yyvsp[(2) - (2)].byte)); 1690 1712 ;} 1691 1713 break; 1692 1714 1693 - case 37: 1694 - #line 269 "dtc-parser.y" 1715 + case 39: 1716 + #line 301 "dtc-parser.y" 1695 1717 { 1696 1718 (yyval.data) = data_add_marker((yyvsp[(1) - (2)].data), LABEL, (yyvsp[(2) - (2)].labelref)); 1697 1719 ;} 1698 1720 break; 1699 1721 1700 - case 38: 1701 - #line 276 "dtc-parser.y" 1722 + case 40: 1723 + #line 308 "dtc-parser.y" 1702 1724 { 1703 1725 (yyval.nodelist) = NULL; 1704 1726 ;} 1705 1727 break; 1706 1728 1707 - case 39: 1708 - #line 280 "dtc-parser.y" 1729 + case 41: 1730 + #line 312 "dtc-parser.y" 1709 1731 { 1710 1732 (yyval.nodelist) = chain_node((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].nodelist)); 1711 1733 ;} 1712 1734 break; 1713 1735 1714 - case 40: 1715 - #line 284 "dtc-parser.y" 1736 + case 42: 1737 + #line 316 "dtc-parser.y" 1716 1738 { 1717 - yyerror("syntax error: properties must precede subnodes\n"); 1739 + yyerror("syntax error: properties must precede subnodes"); 1718 1740 YYERROR; 1719 1741 ;} 1720 1742 break; 1721 1743 1722 - case 41: 1723 - #line 292 "dtc-parser.y" 1744 + case 43: 1745 + #line 324 "dtc-parser.y" 1724 1746 { 1725 1747 (yyval.node) = name_node((yyvsp[(3) - (3)].node), (yyvsp[(2) - (3)].propnodename), (yyvsp[(1) - (3)].labelref)); 1726 1748 ;} 1727 1749 break; 1728 1750 1729 - case 42: 1730 - #line 299 "dtc-parser.y" 1751 + case 44: 1752 + #line 331 "dtc-parser.y" 1731 1753 { 1732 1754 (yyval.labelref) = NULL; 1733 1755 ;} 1734 1756 break; 1735 1757 1736 - case 43: 1737 - #line 303 "dtc-parser.y" 1758 + case 45: 1759 + #line 335 "dtc-parser.y" 1738 1760 { 1739 1761 (yyval.labelref) = (yyvsp[(1) - (1)].labelref); 1740 1762 ;} ··· 1776 1730 1777 1731 1778 1732 /* Line 1267 of yacc.c. */ 1779 - #line 1734 "dtc-parser.tab.c" 1733 + #line 1780 "dtc-parser.tab.c" 1780 1734 default: break; 1781 1735 } 1782 1736 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); ··· 1996 1950 } 1997 1951 1998 1952 1999 - #line 308 "dtc-parser.y" 1953 + #line 340 "dtc-parser.y" 2000 1954 2001 1955 2002 - void yyerror (char const *s) 1956 + void yyerrorf(char const *s, ...) 2003 1957 { 2004 - const char *fname = srcpos_filename_for_num(yylloc.filenum); 1958 + const char *fname = srcpos_file ? srcpos_file->name : "<no-file>"; 1959 + va_list va; 1960 + va_start(va, s); 2005 1961 2006 1962 if (strcmp(fname, "-") == 0) 2007 1963 fname = "stdin"; 2008 1964 2009 - fprintf(stderr, "%s:%d %s\n", 2010 - fname, yylloc.first_line, s); 1965 + fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 1966 + vfprintf(stderr, s, va); 1967 + fprintf(stderr, "\n"); 1968 + 1969 + treesource_error = 1; 1970 + va_end(va); 2011 1971 } 2012 1972 2013 - unsigned long long eval_literal(const char *s, int base, int bits) 1973 + void yyerror (char const *s) 1974 + { 1975 + yyerrorf("%s", s); 1976 + } 1977 + 1978 + static unsigned long long eval_literal(const char *s, int base, int bits) 2014 1979 { 2015 1980 unsigned long long val; 2016 1981 char *e;
+7 -5
arch/powerpc/boot/dtc-src/dtc-parser.tab.h_shipped
··· 48 48 DT_BYTE = 264, 49 49 DT_STRING = 265, 50 50 DT_LABEL = 266, 51 - DT_REF = 267 51 + DT_REF = 267, 52 + DT_INCBIN = 268 52 53 }; 53 54 #endif 54 55 /* Tokens. */ ··· 63 62 #define DT_STRING 265 64 63 #define DT_LABEL 266 65 64 #define DT_REF 267 65 + #define DT_INCBIN 268 66 66 67 67 68 68 69 69 70 70 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 71 71 typedef union YYSTYPE 72 - #line 34 "dtc-parser.y" 72 + #line 37 "dtc-parser.y" 73 73 { 74 74 char *propnodename; 75 75 char *literal; 76 76 char *labelref; 77 77 unsigned int cbase; 78 - u8 byte; 78 + uint8_t byte; 79 79 struct data data; 80 80 81 - u64 addr; 81 + uint64_t addr; 82 82 cell_t cell; 83 83 struct property *prop; 84 84 struct property *proplist; ··· 88 86 struct reserve_info *re; 89 87 } 90 88 /* Line 1489 of yacc.c. */ 91 - #line 90 "dtc-parser.tab.h" 89 + #line 92 "dtc-parser.tab.h" 92 90 YYSTYPE; 93 91 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 94 92 # define YYSTYPE_IS_DECLARED 1
+55 -12
arch/powerpc/boot/dtc-src/dtc-parser.y
··· 21 21 %locations 22 22 23 23 %{ 24 + #include <stdio.h> 25 + 24 26 #include "dtc.h" 25 27 #include "srcpos.h" 26 28 27 - int yylex(void); 28 - unsigned long long eval_literal(const char *s, int base, int bits); 29 + extern int yylex(void); 29 30 30 31 extern struct boot_info *the_boot_info; 32 + extern int treesource_error; 31 33 34 + static unsigned long long eval_literal(const char *s, int base, int bits); 32 35 %} 33 36 34 37 %union { ··· 39 36 char *literal; 40 37 char *labelref; 41 38 unsigned int cbase; 42 - u8 byte; 39 + uint8_t byte; 43 40 struct data data; 44 41 45 - u64 addr; 42 + uint64_t addr; 46 43 cell_t cell; 47 44 struct property *prop; 48 45 struct property *proplist; ··· 61 58 %token <data> DT_STRING 62 59 %token <labelref> DT_LABEL 63 60 %token <labelref> DT_REF 61 + %token DT_INCBIN 64 62 65 63 %type <data> propdata 66 64 %type <data> propdataprefix ··· 88 84 sourcefile: 89 85 DT_V1 ';' memreserves devicetree 90 86 { 91 - the_boot_info = build_boot_info($3, $4); 87 + the_boot_info = build_boot_info($3, $4, 0); 92 88 } 93 89 | v0_memreserves devicetree 94 90 { 95 - the_boot_info = build_boot_info($1, $2); 91 + the_boot_info = build_boot_info($1, $2, 0); 96 92 } 97 93 ; 98 94 ··· 200 196 { 201 197 $$ = data_add_marker($1, REF_PATH, $2); 202 198 } 199 + | propdataprefix DT_INCBIN '(' DT_STRING ',' addr ',' addr ')' 200 + { 201 + struct search_path path = { srcpos_file->dir, NULL, NULL }; 202 + struct dtc_file *file = dtc_open_file($4.val, &path); 203 + struct data d = empty_data; 204 + 205 + if ($6 != 0) 206 + if (fseek(file->file, $6, SEEK_SET) != 0) 207 + yyerrorf("Couldn't seek to offset %llu in \"%s\": %s", 208 + (unsigned long long)$6, 209 + $4.val, strerror(errno)); 210 + 211 + d = data_copy_file(file->file, $8); 212 + 213 + $$ = data_merge($1, d); 214 + dtc_close_file(file); 215 + } 216 + | propdataprefix DT_INCBIN '(' DT_STRING ')' 217 + { 218 + struct search_path path = { srcpos_file->dir, NULL, NULL }; 219 + struct dtc_file *file = dtc_open_file($4.val, &path); 220 + struct data d = empty_data; 221 + 222 + d = data_copy_file(file->file, -1); 223 + 224 + $$ = data_merge($1, d); 225 + dtc_close_file(file); 226 + } 203 227 | propdata DT_LABEL 204 228 { 205 229 $$ = data_add_marker($1, LABEL, $2); ··· 314 282 } 315 283 | subnode propdef 316 284 { 317 - yyerror("syntax error: properties must precede subnodes\n"); 285 + yyerror("syntax error: properties must precede subnodes"); 318 286 YYERROR; 319 287 } 320 288 ; ··· 339 307 340 308 %% 341 309 342 - void yyerror (char const *s) 310 + void yyerrorf(char const *s, ...) 343 311 { 344 - const char *fname = srcpos_filename_for_num(yylloc.filenum); 312 + const char *fname = srcpos_file ? srcpos_file->name : "<no-file>"; 313 + va_list va; 314 + va_start(va, s); 345 315 346 316 if (strcmp(fname, "-") == 0) 347 317 fname = "stdin"; 348 318 349 - fprintf(stderr, "%s:%d %s\n", 350 - fname, yylloc.first_line, s); 319 + fprintf(stderr, "%s:%d ", fname, yylloc.first_line); 320 + vfprintf(stderr, s, va); 321 + fprintf(stderr, "\n"); 322 + 323 + treesource_error = 1; 324 + va_end(va); 351 325 } 352 326 353 - unsigned long long eval_literal(const char *s, int base, int bits) 327 + void yyerror (char const *s) 328 + { 329 + yyerrorf("%s", s); 330 + } 331 + 332 + static unsigned long long eval_literal(const char *s, int base, int bits) 354 333 { 355 334 unsigned long long val; 356 335 char *e;
+18 -23
arch/powerpc/boot/dtc-src/dtc.c
··· 55 55 return str; 56 56 } 57 57 58 - void fill_fullpaths(struct node *tree, const char *prefix) 58 + static void fill_fullpaths(struct node *tree, const char *prefix) 59 59 { 60 60 struct node *child; 61 61 const char *unit; ··· 106 106 fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n"); 107 107 fprintf(stderr, "\t-v\n"); 108 108 fprintf(stderr, "\t\tPrint DTC version and exit\n"); 109 - exit(2); 109 + exit(3); 110 110 } 111 111 112 112 int main(int argc, char *argv[]) ··· 118 118 int force = 0, check = 0; 119 119 const char *arg; 120 120 int opt; 121 - FILE *inf = NULL; 122 121 FILE *outf = NULL; 123 122 int outversion = DEFAULT_FDT_VERSION; 124 - int boot_cpuid_phys = 0xfeedbeef; 123 + long long cmdline_boot_cpuid = -1; 125 124 126 125 quiet = 0; 127 126 reservenum = 0; ··· 160 161 quiet++; 161 162 break; 162 163 case 'b': 163 - boot_cpuid_phys = strtol(optarg, NULL, 0); 164 + cmdline_boot_cpuid = strtoll(optarg, NULL, 0); 164 165 break; 165 166 case 'v': 166 - printf("Version: %s\n", DTC_VERSION); 167 - exit(0); 167 + printf("Version: %s\n", DTC_VERSION); 168 + exit(0); 168 169 case 'h': 169 170 default: 170 171 usage(); ··· 179 180 arg = argv[optind]; 180 181 181 182 /* minsize and padsize are mutually exclusive */ 182 - if ((minsize) && (padsize)) { 183 + if (minsize && padsize) 183 184 die("Can't set both -p and -S\n"); 184 - } 185 185 186 186 fprintf(stderr, "DTC: %s->%s on file \"%s\"\n", 187 187 inform, outform, arg); 188 188 189 - if (streq(inform, "dts")) { 189 + if (streq(inform, "dts")) 190 190 bi = dt_from_source(arg); 191 - } else if (streq(inform, "fs")) { 191 + else if (streq(inform, "fs")) 192 192 bi = dt_from_fs(arg); 193 - } else if(streq(inform, "dtb")) { 194 - inf = dtc_open_file(arg); 195 - bi = dt_from_blob(inf); 196 - } else { 193 + else if(streq(inform, "dtb")) 194 + bi = dt_from_blob(arg); 195 + else 197 196 die("Unknown input format \"%s\"\n", inform); 198 - } 199 197 200 - if (inf && (inf != stdin)) 201 - fclose(inf); 198 + if (cmdline_boot_cpuid != -1) 199 + bi->boot_cpuid_phys = cmdline_boot_cpuid; 202 200 203 - if (! bi || ! bi->dt) 204 - die("Couldn't read input tree\n"); 201 + fill_fullpaths(bi->dt, ""); 202 + process_checks(force, bi); 205 203 206 - process_checks(force, bi, check, outversion, boot_cpuid_phys); 207 204 208 205 if (streq(outname, "-")) { 209 206 outf = stdout; ··· 213 218 if (streq(outform, "dts")) { 214 219 dt_to_source(outf, bi); 215 220 } else if (streq(outform, "dtb")) { 216 - dt_to_blob(outf, bi, outversion, boot_cpuid_phys); 221 + dt_to_blob(outf, bi, outversion); 217 222 } else if (streq(outform, "asm")) { 218 - dt_to_asm(outf, bi, outversion, boot_cpuid_phys); 223 + dt_to_asm(outf, bi, outversion); 219 224 } else if (streq(outform, "null")) { 220 225 /* do nothing */ 221 226 } else {
+10 -33
arch/powerpc/boot/dtc-src/dtc.h
··· 30 30 #include <ctype.h> 31 31 #include <errno.h> 32 32 #include <unistd.h> 33 - #include <netinet/in.h> 34 - #include <endian.h> 35 - #include <byteswap.h> 36 33 34 + #include <libfdt_env.h> 37 35 #include <fdt.h> 38 36 39 37 #define DEFAULT_FDT_VERSION 17 ··· 73 75 return new; 74 76 } 75 77 76 - typedef uint8_t u8; 77 - typedef uint16_t u16; 78 - typedef uint32_t u32; 79 - typedef uint64_t u64; 80 - typedef u32 cell_t; 78 + typedef uint32_t cell_t; 81 79 82 - #define cpu_to_be16(x) htons(x) 83 - #define be16_to_cpu(x) ntohs(x) 84 - 85 - #define cpu_to_be32(x) htonl(x) 86 - #define be32_to_cpu(x) ntohl(x) 87 - 88 - #if __BYTE_ORDER == __BIG_ENDIAN 89 - #define cpu_to_be64(x) (x) 90 - #define be64_to_cpu(x) (x) 91 - #else 92 - #define cpu_to_be64(x) bswap_64(x) 93 - #define be64_to_cpu(x) bswap_64(x) 94 - #endif 95 80 96 81 #define streq(a, b) (strcmp((a), (b)) == 0) 97 82 #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) ··· 99 118 struct data { 100 119 int len; 101 120 char *val; 102 - int asize; 103 121 struct marker *markers; 104 122 }; 105 123 ··· 125 145 struct data data_merge(struct data d1, struct data d2); 126 146 struct data data_append_cell(struct data d, cell_t word); 127 147 struct data data_append_re(struct data d, const struct fdt_reserve_entry *re); 128 - struct data data_append_addr(struct data d, u64 addr); 148 + struct data data_append_addr(struct data d, uint64_t addr); 129 149 struct data data_append_byte(struct data d, uint8_t byte); 130 150 struct data data_append_zeroes(struct data d, int len); 131 151 struct data data_append_align(struct data d, int align); ··· 203 223 char *label; 204 224 }; 205 225 206 - struct reserve_info *build_reserve_entry(u64 start, u64 len, char *label); 226 + struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len, char *label); 207 227 struct reserve_info *chain_reserve_entry(struct reserve_info *first, 208 228 struct reserve_info *list); 209 229 struct reserve_info *add_reserve_entry(struct reserve_info *list, ··· 213 233 struct boot_info { 214 234 struct reserve_info *reservelist; 215 235 struct node *dt; /* the device tree */ 236 + uint32_t boot_cpuid_phys; 216 237 }; 217 238 218 239 struct boot_info *build_boot_info(struct reserve_info *reservelist, 219 - struct node *tree); 240 + struct node *tree, uint32_t boot_cpuid_phys); 220 241 221 242 /* Checks */ 222 243 223 - void process_checks(int force, struct boot_info *bi, 224 - int checkflag, int outversion, int boot_cpuid_phys); 244 + void process_checks(int force, struct boot_info *bi); 225 245 226 246 /* Flattened trees */ 227 247 228 - void dt_to_blob(FILE *f, struct boot_info *bi, int version, 229 - int boot_cpuid_phys); 230 - void dt_to_asm(FILE *f, struct boot_info *bi, int version, 231 - int boot_cpuid_phys); 248 + void dt_to_blob(FILE *f, struct boot_info *bi, int version); 249 + void dt_to_asm(FILE *f, struct boot_info *bi, int version); 232 250 233 - struct boot_info *dt_from_blob(FILE *f); 251 + struct boot_info *dt_from_blob(const char *fname); 234 252 235 253 /* Tree source */ 236 254 ··· 242 264 /* misc */ 243 265 244 266 char *join_path(const char *path, const char *name); 245 - void fill_fullpaths(struct node *tree, const char *prefix); 246 267 247 268 #endif /* _DTC_H */
+85 -147
arch/powerpc/boot/dtc-src/flattree.c
··· 19 19 */ 20 20 21 21 #include "dtc.h" 22 + #include "srcpos.h" 22 23 23 24 #define FTF_FULLPATH 0x1 24 25 #define FTF_VARALIGN 0x2 ··· 163 162 { 164 163 FILE *f = e; 165 164 int off = 0; 166 - struct marker *m; 165 + struct marker *m = d.markers; 167 166 168 - m = d.markers; 169 - while (m) { 170 - if (m->type == LABEL) 171 - emit_offset_label(f, m->ref, m->offset); 172 - m = m->next; 173 - } 167 + for_each_marker_of_type(m, LABEL) 168 + emit_offset_label(f, m->ref, m->offset); 174 169 175 - while ((d.len - off) >= sizeof(u32)) { 170 + while ((d.len - off) >= sizeof(uint32_t)) { 176 171 fprintf(f, "\t.long\t0x%x\n", 177 - be32_to_cpu(*((u32 *)(d.val+off)))); 178 - off += sizeof(u32); 172 + fdt32_to_cpu(*((uint32_t *)(d.val+off)))); 173 + off += sizeof(uint32_t); 179 174 } 180 175 181 - if ((d.len - off) >= sizeof(u16)) { 182 - fprintf(f, "\t.short\t0x%hx\n", 183 - be16_to_cpu(*((u16 *)(d.val+off)))); 184 - off += sizeof(u16); 185 - } 186 - 187 - if ((d.len - off) >= 1) { 176 + while ((d.len - off) >= 1) { 188 177 fprintf(f, "\t.byte\t0x%hhx\n", d.val[off]); 189 178 off += 1; 190 179 } ··· 327 336 328 337 memset(fdt, 0xff, sizeof(*fdt)); 329 338 330 - fdt->magic = cpu_to_be32(FDT_MAGIC); 331 - fdt->version = cpu_to_be32(vi->version); 332 - fdt->last_comp_version = cpu_to_be32(vi->last_comp_version); 339 + fdt->magic = cpu_to_fdt32(FDT_MAGIC); 340 + fdt->version = cpu_to_fdt32(vi->version); 341 + fdt->last_comp_version = cpu_to_fdt32(vi->last_comp_version); 333 342 334 343 /* Reserve map should be doubleword aligned */ 335 344 reserve_off = ALIGN(vi->hdr_size, 8); 336 345 337 - fdt->off_mem_rsvmap = cpu_to_be32(reserve_off); 338 - fdt->off_dt_struct = cpu_to_be32(reserve_off + reservesize); 339 - fdt->off_dt_strings = cpu_to_be32(reserve_off + reservesize 346 + fdt->off_mem_rsvmap = cpu_to_fdt32(reserve_off); 347 + fdt->off_dt_struct = cpu_to_fdt32(reserve_off + reservesize); 348 + fdt->off_dt_strings = cpu_to_fdt32(reserve_off + reservesize 340 349 + dtsize); 341 - fdt->totalsize = cpu_to_be32(reserve_off + reservesize + dtsize + strsize); 350 + fdt->totalsize = cpu_to_fdt32(reserve_off + reservesize + dtsize + strsize); 342 351 343 352 if (vi->flags & FTF_BOOTCPUID) 344 - fdt->boot_cpuid_phys = cpu_to_be32(boot_cpuid_phys); 353 + fdt->boot_cpuid_phys = cpu_to_fdt32(boot_cpuid_phys); 345 354 if (vi->flags & FTF_STRTABSIZE) 346 - fdt->size_dt_strings = cpu_to_be32(strsize); 355 + fdt->size_dt_strings = cpu_to_fdt32(strsize); 347 356 if (vi->flags & FTF_STRUCTSIZE) 348 - fdt->size_dt_struct = cpu_to_be32(dtsize); 357 + fdt->size_dt_struct = cpu_to_fdt32(dtsize); 349 358 } 350 359 351 - void dt_to_blob(FILE *f, struct boot_info *bi, int version, 352 - int boot_cpuid_phys) 360 + void dt_to_blob(FILE *f, struct boot_info *bi, int version) 353 361 { 354 362 struct version_info *vi = NULL; 355 363 int i; ··· 373 383 374 384 /* Make header */ 375 385 make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, 376 - boot_cpuid_phys); 386 + bi->boot_cpuid_phys); 377 387 378 388 /* 379 389 * If the user asked for more space than is used, adjust the totalsize. 380 390 */ 381 391 if (minsize > 0) { 382 - padlen = minsize - be32_to_cpu(fdt.totalsize); 392 + padlen = minsize - fdt32_to_cpu(fdt.totalsize); 383 393 if ((padlen < 0) && (quiet < 1)) 384 394 fprintf(stderr, 385 395 "Warning: blob size %d >= minimum size %d\n", 386 - be32_to_cpu(fdt.totalsize), minsize); 396 + fdt32_to_cpu(fdt.totalsize), minsize); 387 397 } 388 398 389 399 if (padsize > 0) 390 400 padlen = padsize; 391 401 392 402 if (padlen > 0) { 393 - int tsize = be32_to_cpu(fdt.totalsize); 403 + int tsize = fdt32_to_cpu(fdt.totalsize); 394 404 tsize += padlen; 395 - fdt.totalsize = cpu_to_be32(tsize); 405 + fdt.totalsize = cpu_to_fdt32(tsize); 396 406 } 397 407 398 408 /* ··· 400 410 * the reserve buffer, add the reserve map terminating zeroes, 401 411 * the device tree itself, and finally the strings. 402 412 */ 403 - blob = data_append_data(blob, &fdt, sizeof(fdt)); 413 + blob = data_append_data(blob, &fdt, vi->hdr_size); 404 414 blob = data_append_align(blob, 8); 405 415 blob = data_merge(blob, reservebuf); 406 416 blob = data_append_zeroes(blob, sizeof(struct fdt_reserve_entry)); ··· 439 449 } 440 450 } 441 451 442 - void dt_to_asm(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys) 452 + void dt_to_asm(FILE *f, struct boot_info *bi, int version) 443 453 { 444 454 struct version_info *vi = NULL; 445 455 int i; ··· 479 489 480 490 if (vi->flags & FTF_BOOTCPUID) 481 491 fprintf(f, "\t.long\t%i\t\t\t\t\t/* boot_cpuid_phys */\n", 482 - boot_cpuid_phys); 492 + bi->boot_cpuid_phys); 483 493 484 494 if (vi->flags & FTF_STRTABSIZE) 485 495 fprintf(f, "\t.long\t_%s_strings_end - _%s_strings_start\t/* size_dt_strings */\n", ··· 569 579 inb->ptr += len; 570 580 } 571 581 572 - static u32 flat_read_word(struct inbuf *inb) 582 + static uint32_t flat_read_word(struct inbuf *inb) 573 583 { 574 - u32 val; 584 + uint32_t val; 575 585 576 586 assert(((inb->ptr - inb->base) % sizeof(val)) == 0); 577 587 578 588 flat_read_chunk(inb, &val, sizeof(val)); 579 589 580 - return be32_to_cpu(val); 590 + return fdt32_to_cpu(val); 581 591 } 582 592 583 593 static void flat_realign(struct inbuf *inb, int align) ··· 605 615 606 616 inb->ptr += len; 607 617 608 - flat_realign(inb, sizeof(u32)); 618 + flat_realign(inb, sizeof(uint32_t)); 609 619 610 620 return str; 611 621 } ··· 622 632 623 633 flat_read_chunk(inb, d.val, len); 624 634 625 - flat_realign(inb, sizeof(u32)); 635 + flat_realign(inb, sizeof(uint32_t)); 626 636 627 637 return d; 628 638 } ··· 649 659 static struct property *flat_read_property(struct inbuf *dtbuf, 650 660 struct inbuf *strbuf, int flags) 651 661 { 652 - u32 proplen, stroff; 662 + uint32_t proplen, stroff; 653 663 char *name; 654 664 struct data val; 655 665 ··· 683 693 p = inb->ptr; 684 694 while (1) { 685 695 flat_read_chunk(inb, &re, sizeof(re)); 686 - re.address = be64_to_cpu(re.address); 687 - re.size = be64_to_cpu(re.size); 696 + re.address = fdt64_to_cpu(re.address); 697 + re.size = fdt64_to_cpu(re.size); 688 698 if (re.size == 0) 689 699 break; 690 700 ··· 698 708 699 709 static char *nodename_from_path(const char *ppath, const char *cpath) 700 710 { 701 - const char *lslash; 702 711 int plen; 703 712 704 - lslash = strrchr(cpath, '/'); 705 - if (! lslash) 706 - return NULL; 713 + plen = strlen(ppath); 707 714 708 - plen = lslash - cpath; 715 + if (!strneq(ppath, cpath, plen)) 716 + die("Path \"%s\" is not valid as a child of \"%s\"\n", 717 + cpath, ppath); 709 718 710 - if (streq(cpath, "/") && streq(ppath, "")) 711 - return ""; 719 + /* root node is a special case */ 720 + if (!streq(ppath, "/")) 721 + plen++; 712 722 713 - if ((plen == 0) && streq(ppath, "/")) 714 - return strdup(lslash+1); 715 - 716 - if (! strneq(ppath, cpath, plen)) 717 - return NULL; 718 - 719 - return strdup(lslash+1); 720 - } 721 - 722 - static const char PROPCHAR[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,._+*#?-"; 723 - static const char UNITCHAR[] = "0123456789abcdef,"; 724 - 725 - static int check_node_name(const char *name) 726 - { 727 - const char *atpos; 728 - int basenamelen; 729 - 730 - atpos = strrchr(name, '@'); 731 - 732 - if (atpos) 733 - basenamelen = atpos - name; 734 - else 735 - basenamelen = strlen(name); 736 - 737 - if (strspn(name, PROPCHAR) < basenamelen) 738 - return -1; 739 - 740 - if (atpos 741 - && ((basenamelen + 1 + strspn(atpos+1, UNITCHAR)) < strlen(name))) 742 - return -1; 743 - 744 - return basenamelen; 723 + return strdup(cpath + plen); 745 724 } 746 725 747 726 static struct node *unflatten_tree(struct inbuf *dtbuf, 748 727 struct inbuf *strbuf, 749 - const char *parent_path, int flags) 728 + const char *parent_flatname, int flags) 750 729 { 751 730 struct node *node; 752 - u32 val; 731 + char *flatname; 732 + uint32_t val; 753 733 754 734 node = build_node(NULL, NULL); 755 735 756 - if (flags & FTF_FULLPATH) { 757 - node->fullpath = flat_read_string(dtbuf); 758 - node->name = nodename_from_path(parent_path, node->fullpath); 736 + flatname = flat_read_string(dtbuf); 759 737 760 - if (! node->name) 761 - die("Path \"%s\" is not valid as a child of \"%s\"\n", 762 - node->fullpath, parent_path); 763 - } else { 764 - node->name = flat_read_string(dtbuf); 765 - node->fullpath = join_path(parent_path, node->name); 766 - } 767 - 768 - node->basenamelen = check_node_name(node->name); 769 - if (node->basenamelen < 0) { 770 - fprintf(stderr, "Warning \"%s\" has incorrect format\n", node->name); 771 - } 738 + if (flags & FTF_FULLPATH) 739 + node->name = nodename_from_path(parent_flatname, flatname); 740 + else 741 + node->name = flatname; 772 742 773 743 do { 774 744 struct property *prop; ··· 745 795 break; 746 796 747 797 case FDT_BEGIN_NODE: 748 - child = unflatten_tree(dtbuf,strbuf, node->fullpath, 749 - flags); 798 + child = unflatten_tree(dtbuf,strbuf, flatname, flags); 750 799 add_child(node, child); 751 800 break; 752 801 ··· 774 825 } 775 826 776 827 777 - struct boot_info *dt_from_blob(FILE *f) 828 + struct boot_info *dt_from_blob(const char *fname) 778 829 { 779 - u32 magic, totalsize, version, size_str, size_dt; 780 - u32 off_dt, off_str, off_mem_rsvmap; 830 + struct dtc_file *dtcf; 831 + uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys; 832 + uint32_t off_dt, off_str, off_mem_rsvmap; 781 833 int rc; 782 834 char *blob; 783 835 struct fdt_header *fdt; ··· 788 838 int sizeleft; 789 839 struct reserve_info *reservelist; 790 840 struct node *tree; 791 - u32 val; 841 + uint32_t val; 792 842 int flags = 0; 793 843 794 - rc = fread(&magic, sizeof(magic), 1, f); 795 - if (ferror(f)) 844 + dtcf = dtc_open_file(fname, NULL); 845 + 846 + rc = fread(&magic, sizeof(magic), 1, dtcf->file); 847 + if (ferror(dtcf->file)) 796 848 die("Error reading DT blob magic number: %s\n", 797 849 strerror(errno)); 798 850 if (rc < 1) { 799 - if (feof(f)) 851 + if (feof(dtcf->file)) 800 852 die("EOF reading DT blob magic number\n"); 801 853 else 802 854 die("Mysterious short read reading magic number\n"); 803 855 } 804 856 805 - magic = be32_to_cpu(magic); 857 + magic = fdt32_to_cpu(magic); 806 858 if (magic != FDT_MAGIC) 807 859 die("Blob has incorrect magic number\n"); 808 860 809 - rc = fread(&totalsize, sizeof(totalsize), 1, f); 810 - if (ferror(f)) 861 + rc = fread(&totalsize, sizeof(totalsize), 1, dtcf->file); 862 + if (ferror(dtcf->file)) 811 863 die("Error reading DT blob size: %s\n", strerror(errno)); 812 864 if (rc < 1) { 813 - if (feof(f)) 865 + if (feof(dtcf->file)) 814 866 die("EOF reading DT blob size\n"); 815 867 else 816 868 die("Mysterious short read reading blob size\n"); 817 869 } 818 870 819 - totalsize = be32_to_cpu(totalsize); 871 + totalsize = fdt32_to_cpu(totalsize); 820 872 if (totalsize < FDT_V1_SIZE) 821 873 die("DT blob size (%d) is too small\n", totalsize); 822 874 823 875 blob = xmalloc(totalsize); 824 876 825 877 fdt = (struct fdt_header *)blob; 826 - fdt->magic = cpu_to_be32(magic); 827 - fdt->totalsize = cpu_to_be32(totalsize); 878 + fdt->magic = cpu_to_fdt32(magic); 879 + fdt->totalsize = cpu_to_fdt32(totalsize); 828 880 829 881 sizeleft = totalsize - sizeof(magic) - sizeof(totalsize); 830 882 p = blob + sizeof(magic) + sizeof(totalsize); 831 883 832 884 while (sizeleft) { 833 - if (feof(f)) 885 + if (feof(dtcf->file)) 834 886 die("EOF before reading %d bytes of DT blob\n", 835 887 totalsize); 836 888 837 - rc = fread(p, 1, sizeleft, f); 838 - if (ferror(f)) 889 + rc = fread(p, 1, sizeleft, dtcf->file); 890 + if (ferror(dtcf->file)) 839 891 die("Error reading DT blob: %s\n", 840 892 strerror(errno)); 841 893 ··· 845 893 p += rc; 846 894 } 847 895 848 - off_dt = be32_to_cpu(fdt->off_dt_struct); 849 - off_str = be32_to_cpu(fdt->off_dt_strings); 850 - off_mem_rsvmap = be32_to_cpu(fdt->off_mem_rsvmap); 851 - version = be32_to_cpu(fdt->version); 852 - 853 - fprintf(stderr, "\tmagic:\t\t\t0x%x\n", magic); 854 - fprintf(stderr, "\ttotalsize:\t\t%d\n", totalsize); 855 - fprintf(stderr, "\toff_dt_struct:\t\t0x%x\n", off_dt); 856 - fprintf(stderr, "\toff_dt_strings:\t\t0x%x\n", off_str); 857 - fprintf(stderr, "\toff_mem_rsvmap:\t\t0x%x\n", off_mem_rsvmap); 858 - fprintf(stderr, "\tversion:\t\t0x%x\n", version ); 859 - fprintf(stderr, "\tlast_comp_version:\t0x%x\n", 860 - be32_to_cpu(fdt->last_comp_version)); 896 + off_dt = fdt32_to_cpu(fdt->off_dt_struct); 897 + off_str = fdt32_to_cpu(fdt->off_dt_strings); 898 + off_mem_rsvmap = fdt32_to_cpu(fdt->off_mem_rsvmap); 899 + version = fdt32_to_cpu(fdt->version); 900 + boot_cpuid_phys = fdt32_to_cpu(fdt->boot_cpuid_phys); 861 901 862 902 if (off_mem_rsvmap >= totalsize) 863 903 die("Mem Reserve structure offset exceeds total size\n"); ··· 860 916 if (off_str > totalsize) 861 917 die("String table offset exceeds total size\n"); 862 918 863 - if (version >= 2) 864 - fprintf(stderr, "\tboot_cpuid_phys:\t0x%x\n", 865 - be32_to_cpu(fdt->boot_cpuid_phys)); 866 - 867 - size_str = -1; 868 919 if (version >= 3) { 869 - size_str = be32_to_cpu(fdt->size_dt_strings); 870 - fprintf(stderr, "\tsize_dt_strings:\t%d\n", size_str); 920 + uint32_t size_str = fdt32_to_cpu(fdt->size_dt_strings); 871 921 if (off_str+size_str > totalsize) 872 922 die("String table extends past total size\n"); 923 + inbuf_init(&strbuf, blob + off_str, blob + off_str + size_str); 924 + } else { 925 + inbuf_init(&strbuf, blob + off_str, blob + totalsize); 873 926 } 874 927 875 928 if (version >= 17) { 876 - size_dt = be32_to_cpu(fdt->size_dt_struct); 877 - fprintf(stderr, "\tsize_dt_struct:\t\t%d\n", size_dt); 929 + size_dt = fdt32_to_cpu(fdt->size_dt_struct); 878 930 if (off_dt+size_dt > totalsize) 879 931 die("Structure block extends past total size\n"); 880 932 } ··· 884 944 inbuf_init(&memresvbuf, 885 945 blob + off_mem_rsvmap, blob + totalsize); 886 946 inbuf_init(&dtbuf, blob + off_dt, blob + totalsize); 887 - if (size_str >= 0) 888 - inbuf_init(&strbuf, blob + off_str, blob + off_str + size_str); 889 - else 890 - inbuf_init(&strbuf, blob + off_str, blob + totalsize); 891 947 892 948 reservelist = flat_read_mem_reserve(&memresvbuf); 893 949 ··· 900 964 901 965 free(blob); 902 966 903 - return build_boot_info(reservelist, tree); 967 + dtc_close_file(dtcf); 968 + 969 + return build_boot_info(reservelist, tree, boot_cpuid_phys); 904 970 }
+3 -5
arch/powerpc/boot/dtc-src/fstree.c
··· 31 31 struct node *tree; 32 32 33 33 d = opendir(dirname); 34 - if (! d) 35 - die("opendir(): %s\n", strerror(errno)); 34 + if (!d) 35 + die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); 36 36 37 37 tree = build_node(NULL, NULL); 38 38 ··· 87 87 tree = read_fstree(dirname); 88 88 tree = name_node(tree, "", NULL); 89 89 90 - fill_fullpaths(tree, ""); 91 - 92 - return build_boot_info(NULL, tree); 90 + return build_boot_info(NULL, tree, 0); 93 91 } 94 92
+23
arch/powerpc/boot/dtc-src/libfdt_env.h
··· 1 + #ifndef _LIBFDT_ENV_H 2 + #define _LIBFDT_ENV_H 3 + 4 + #include <stddef.h> 5 + #include <stdint.h> 6 + #include <string.h> 7 + 8 + #define _B(n) ((unsigned long long)((uint8_t *)&x)[n]) 9 + static inline uint32_t fdt32_to_cpu(uint32_t x) 10 + { 11 + return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3); 12 + } 13 + #define cpu_to_fdt32(x) fdt32_to_cpu(x) 14 + 15 + static inline uint64_t fdt64_to_cpu(uint64_t x) 16 + { 17 + return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32) 18 + | (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7); 19 + } 20 + #define cpu_to_fdt64(x) fdt64_to_cpu(x) 21 + #undef _B 22 + 23 + #endif /* _LIBFDT_ENV_H */
+6 -3
arch/powerpc/boot/dtc-src/livetree.c
··· 115 115 struct node **p; 116 116 117 117 child->next_sibling = NULL; 118 + child->parent = parent; 118 119 119 120 p = &parent->children; 120 121 while (*p) ··· 124 123 *p = child; 125 124 } 126 125 127 - struct reserve_info *build_reserve_entry(u64 address, u64 size, char *label) 126 + struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size, 127 + char *label) 128 128 { 129 129 struct reserve_info *new = xmalloc(sizeof(*new)); 130 130 ··· 167 165 } 168 166 169 167 struct boot_info *build_boot_info(struct reserve_info *reservelist, 170 - struct node *tree) 168 + struct node *tree, uint32_t boot_cpuid_phys) 171 169 { 172 170 struct boot_info *bi; 173 171 174 172 bi = xmalloc(sizeof(*bi)); 175 173 bi->reservelist = reservelist; 176 174 bi->dt = tree; 175 + bi->boot_cpuid_phys = boot_cpuid_phys; 177 176 178 177 return bi; 179 178 } ··· 205 202 cell_t propval_cell(struct property *prop) 206 203 { 207 204 assert(prop->val.len == sizeof(cell_t)); 208 - return be32_to_cpu(*((cell_t *)prop->val.val)); 205 + return fdt32_to_cpu(*((cell_t *)prop->val.val)); 209 206 } 210 207 211 208 struct node *get_subnode(struct node *node, const char *nodename)
+70 -59
arch/powerpc/boot/dtc-src/srcpos.c
··· 20 20 #include "dtc.h" 21 21 #include "srcpos.h" 22 22 23 - 24 - /* 25 - * Record the complete unique set of opened file names. 26 - * Primarily used to cache source position file names. 27 - */ 28 - #define MAX_N_FILE_NAMES (100) 29 - 30 - const char *file_names[MAX_N_FILE_NAMES]; 31 - static int n_file_names = 0; 32 - 33 23 /* 34 24 * Like yylineno, this is the current open file pos. 35 25 */ 36 26 37 - int srcpos_filenum = -1; 27 + struct dtc_file *srcpos_file; 38 28 39 - 40 - 41 - FILE *dtc_open_file(const char *fname) 29 + static int dtc_open_one(struct dtc_file *file, 30 + const char *search, 31 + const char *fname) 42 32 { 43 - FILE *f; 33 + char *fullname; 44 34 45 - if (lookup_file_name(fname, 1) < 0) 46 - die("Too many files opened\n"); 35 + if (search) { 36 + fullname = xmalloc(strlen(search) + strlen(fname) + 2); 47 37 48 - if (streq(fname, "-")) 49 - f = stdin; 50 - else 51 - f = fopen(fname, "r"); 38 + strcpy(fullname, search); 39 + strcat(fullname, "/"); 40 + strcat(fullname, fname); 41 + } else { 42 + fullname = strdup(fname); 43 + } 52 44 53 - if (! f) 54 - die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); 45 + file->file = fopen(fullname, "r"); 46 + if (!file->file) { 47 + free(fullname); 48 + return 0; 49 + } 55 50 56 - return f; 51 + file->name = fullname; 52 + return 1; 57 53 } 58 54 59 55 60 - 61 - /* 62 - * Locate and optionally add filename fname in the file_names[] array. 63 - * 64 - * If the filename is currently not in the array and the boolean 65 - * add_it is non-zero, an attempt to add the filename will be made. 66 - * 67 - * Returns; 68 - * Index [0..MAX_N_FILE_NAMES) where the filename is kept 69 - * -1 if the name can not be recorded 70 - */ 71 - 72 - int lookup_file_name(const char *fname, int add_it) 56 + struct dtc_file *dtc_open_file(const char *fname, 57 + const struct search_path *search) 73 58 { 74 - int i; 59 + static const struct search_path default_search = { NULL, NULL, NULL }; 75 60 76 - for (i = 0; i < n_file_names; i++) { 77 - if (strcmp(file_names[i], fname) == 0) 78 - return i; 61 + struct dtc_file *file; 62 + const char *slash; 63 + 64 + file = xmalloc(sizeof(struct dtc_file)); 65 + 66 + slash = strrchr(fname, '/'); 67 + if (slash) { 68 + char *dir = xmalloc(slash - fname + 1); 69 + 70 + memcpy(dir, fname, slash - fname); 71 + dir[slash - fname] = 0; 72 + file->dir = dir; 73 + } else { 74 + file->dir = NULL; 79 75 } 80 76 81 - if (add_it) { 82 - if (n_file_names < MAX_N_FILE_NAMES) { 83 - file_names[n_file_names] = strdup(fname); 84 - return n_file_names++; 85 - } 77 + if (streq(fname, "-")) { 78 + file->name = "stdin"; 79 + file->file = stdin; 80 + return file; 86 81 } 87 82 88 - return -1; 83 + if (fname[0] == '/') { 84 + file->file = fopen(fname, "r"); 85 + if (!file->file) 86 + goto fail; 87 + 88 + file->name = strdup(fname); 89 + return file; 90 + } 91 + 92 + if (!search) 93 + search = &default_search; 94 + 95 + while (search) { 96 + if (dtc_open_one(file, search->dir, fname)) 97 + return file; 98 + 99 + if (errno != ENOENT) 100 + goto fail; 101 + 102 + search = search->next; 103 + } 104 + 105 + fail: 106 + die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); 89 107 } 90 108 91 - 92 - const char *srcpos_filename_for_num(int filenum) 109 + void dtc_close_file(struct dtc_file *file) 93 110 { 94 - if (0 <= filenum && filenum < n_file_names) { 95 - return file_names[filenum]; 96 - } 111 + if (fclose(file->file)) 112 + die("Error closing \"%s\": %s\n", file->name, strerror(errno)); 97 113 98 - return 0; 99 - } 100 - 101 - 102 - const char *srcpos_get_filename(void) 103 - { 104 - return srcpos_filename_for_num(srcpos_filenum); 114 + free(file->dir); 115 + free(file); 105 116 }
+20 -10
arch/powerpc/boot/dtc-src/srcpos.h
··· 22 22 * array of all opened filenames. 23 23 */ 24 24 25 + #include <stdio.h> 26 + 27 + struct dtc_file { 28 + char *dir; 29 + const char *name; 30 + FILE *file; 31 + }; 32 + 25 33 #if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED) 26 34 typedef struct YYLTYPE { 27 35 int first_line; 28 36 int first_column; 29 37 int last_line; 30 38 int last_column; 31 - int filenum; 39 + struct dtc_file *file; 32 40 } YYLTYPE; 33 41 34 42 #define YYLTYPE_IS_DECLARED 1 ··· 56 48 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 57 49 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 58 50 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 59 - (Current).filenum = YYRHSLOC (Rhs, N).filenum; \ 51 + (Current).file = YYRHSLOC (Rhs, N).file; \ 60 52 } \ 61 53 else \ 62 54 { \ ··· 64 56 YYRHSLOC (Rhs, 0).last_line; \ 65 57 (Current).first_column = (Current).last_column = \ 66 58 YYRHSLOC (Rhs, 0).last_column; \ 67 - (Current).filenum = YYRHSLOC (Rhs, 0).filenum; \ 59 + (Current).file = YYRHSLOC (Rhs, 0).file; \ 68 60 } \ 69 61 while (YYID (0)) 70 62 71 63 72 64 73 65 extern void yyerror(char const *); 66 + extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2))); 74 67 75 - extern int srcpos_filenum; 68 + extern struct dtc_file *srcpos_file; 76 69 77 - extern int push_input_file(const char *filename); 78 - extern int pop_input_file(void); 70 + struct search_path { 71 + const char *dir; /* NULL for current directory */ 72 + struct search_path *prev, *next; 73 + }; 79 74 80 - extern FILE *dtc_open_file(const char *fname); 81 - extern int lookup_file_name(const char *fname, int add_it); 82 - extern const char *srcpos_filename_for_num(int filenum); 83 - const char *srcpos_get_filename(void); 75 + extern struct dtc_file *dtc_open_file(const char *fname, 76 + const struct search_path *search); 77 + extern void dtc_close_file(struct dtc_file *file);
+9 -6
arch/powerpc/boot/dtc-src/treesource.c
··· 23 23 24 24 extern FILE *yyin; 25 25 extern int yyparse(void); 26 - extern void yyerror(char const *); 27 26 28 27 struct boot_info *the_boot_info; 28 + int treesource_error; 29 29 30 30 struct boot_info *dt_from_source(const char *fname) 31 31 { 32 32 the_boot_info = NULL; 33 + treesource_error = 0; 33 34 34 - push_input_file(fname); 35 + srcpos_file = dtc_open_file(fname, NULL); 36 + yyin = srcpos_file->file; 35 37 36 38 if (yyparse() != 0) 37 - return NULL; 39 + die("Unable to parse input tree\n"); 38 40 39 - fill_fullpaths(the_boot_info->dt, ""); 41 + if (treesource_error) 42 + die("Syntax error parsing input tree\n"); 40 43 41 44 return the_boot_info; 42 45 } ··· 147 144 m = m->next; 148 145 } 149 146 150 - fprintf(f, "0x%x", be32_to_cpu(*cp++)); 147 + fprintf(f, "0x%x", fdt32_to_cpu(*cp++)); 151 148 if ((void *)cp >= propend) 152 149 break; 153 150 fprintf(f, " "); ··· 176 173 } 177 174 178 175 fprintf(f, "%02hhx", *bp++); 179 - if ((void *)bp >= propend) 176 + if ((const void *)bp >= propend) 180 177 break; 181 178 fprintf(f, " "); 182 179 }
+1 -1
arch/powerpc/boot/dtc-src/version_gen.h
··· 1 - #define DTC_VERSION "DTC 1.0.0-gd6f9b62f" 1 + #define DTC_VERSION "DTC 1.2.0"
+1 -7
arch/powerpc/boot/libfdt/Makefile.libfdt
··· 3 3 # This is not a complete Makefile of itself. Instead, it is designed to 4 4 # be easily embeddable into other systems of Makefiles. 5 5 # 6 - LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 7 6 LIBFDT_INCLUDES = fdt.h libfdt.h 8 - LIBFDT_EXTRA = libfdt_internal.h 9 - LIBFDT_LIB = libfdt/libfdt.a 10 - 7 + LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c 11 8 LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 12 - 13 - $(LIBFDT_objdir)/$(LIBFDT_LIB): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 14 -
+53 -8
arch/powerpc/boot/libfdt/fdt.c
··· 63 63 return -FDT_ERR_BADVERSION; 64 64 if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) 65 65 return -FDT_ERR_BADVERSION; 66 - } else if (fdt_magic(fdt) == SW_MAGIC) { 66 + } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { 67 67 /* Unfinished sequential-write blob */ 68 68 if (fdt_size_dt_struct(fdt) == 0) 69 69 return -FDT_ERR_BADSTATE; ··· 76 76 77 77 const void *fdt_offset_ptr(const void *fdt, int offset, int len) 78 78 { 79 - const void *p; 79 + const char *p; 80 80 81 81 if (fdt_version(fdt) >= 0x11) 82 82 if (((offset + len) < offset) ··· 124 124 } 125 125 126 126 if (nextoffset) 127 - *nextoffset = ALIGN(offset, FDT_TAGSIZE); 127 + *nextoffset = FDT_TAGALIGN(offset); 128 128 129 129 return tag; 130 + } 131 + 132 + int _fdt_check_node_offset(const void *fdt, int offset) 133 + { 134 + if ((offset < 0) || (offset % FDT_TAGSIZE) 135 + || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)) 136 + return -FDT_ERR_BADOFFSET; 137 + 138 + return offset; 139 + } 140 + 141 + int fdt_next_node(const void *fdt, int offset, int *depth) 142 + { 143 + int nextoffset = 0; 144 + uint32_t tag; 145 + 146 + if (offset >= 0) 147 + if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0) 148 + return nextoffset; 149 + 150 + do { 151 + offset = nextoffset; 152 + tag = fdt_next_tag(fdt, offset, &nextoffset); 153 + 154 + switch (tag) { 155 + case FDT_PROP: 156 + case FDT_NOP: 157 + break; 158 + 159 + case FDT_BEGIN_NODE: 160 + if (depth) 161 + (*depth)++; 162 + break; 163 + 164 + case FDT_END_NODE: 165 + if (depth) 166 + (*depth)--; 167 + break; 168 + 169 + case FDT_END: 170 + return -FDT_ERR_NOTFOUND; 171 + 172 + default: 173 + return -FDT_ERR_BADSTRUCTURE; 174 + } 175 + } while (tag != FDT_BEGIN_NODE); 176 + 177 + return offset; 130 178 } 131 179 132 180 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) ··· 184 136 const char *p; 185 137 186 138 for (p = strtab; p <= last; p++) 187 - if (memeq(p, s, len)) 139 + if (memcmp(p, s, len) == 0) 188 140 return p; 189 141 return NULL; 190 142 } 191 143 192 144 int fdt_move(const void *fdt, void *buf, int bufsize) 193 145 { 194 - int err = fdt_check_header(fdt); 195 - 196 - if (err) 197 - return err; 146 + FDT_CHECK_HEADER(fdt); 198 147 199 148 if (fdt_totalsize(fdt) > bufsize) 200 149 return -FDT_ERR_NOSPACE;
+106 -223
arch/powerpc/boot/libfdt/fdt_ro.c
··· 55 55 56 56 #include "libfdt_internal.h" 57 57 58 - #define CHECK_HEADER(fdt) \ 59 - { \ 60 - int err; \ 61 - if ((err = fdt_check_header(fdt)) != 0) \ 62 - return err; \ 63 - } 64 - 65 - static int nodename_eq(const void *fdt, int offset, 66 - const char *s, int len) 58 + static int _fdt_nodename_eq(const void *fdt, int offset, 59 + const char *s, int len) 67 60 { 68 - const char *p = fdt_offset_ptr(fdt, offset, len+1); 61 + const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1); 69 62 70 63 if (! p) 71 64 /* short match */ ··· 77 84 78 85 const char *fdt_string(const void *fdt, int stroffset) 79 86 { 80 - return (char *)fdt + fdt_off_dt_strings(fdt) + stroffset; 87 + return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset; 81 88 } 82 89 83 90 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) 84 91 { 85 - CHECK_HEADER(fdt); 92 + FDT_CHECK_HEADER(fdt); 86 93 *address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address); 87 94 *size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size); 88 95 return 0; ··· 97 104 return i; 98 105 } 99 106 100 - int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, 107 + int fdt_subnode_offset_namelen(const void *fdt, int offset, 101 108 const char *name, int namelen) 102 109 { 103 - int level = 0; 104 - uint32_t tag; 105 - int offset, nextoffset; 110 + int depth; 106 111 107 - CHECK_HEADER(fdt); 112 + FDT_CHECK_HEADER(fdt); 108 113 109 - tag = fdt_next_tag(fdt, parentoffset, &nextoffset); 110 - if (tag != FDT_BEGIN_NODE) 111 - return -FDT_ERR_BADOFFSET; 114 + for (depth = 0; 115 + offset >= 0; 116 + offset = fdt_next_node(fdt, offset, &depth)) { 117 + if (depth < 0) 118 + return -FDT_ERR_NOTFOUND; 119 + else if ((depth == 1) 120 + && _fdt_nodename_eq(fdt, offset, name, namelen)) 121 + return offset; 122 + } 112 123 113 - do { 114 - offset = nextoffset; 115 - tag = fdt_next_tag(fdt, offset, &nextoffset); 116 - 117 - switch (tag) { 118 - case FDT_END: 119 - return -FDT_ERR_TRUNCATED; 120 - 121 - case FDT_BEGIN_NODE: 122 - level++; 123 - if (level != 1) 124 - continue; 125 - if (nodename_eq(fdt, offset+FDT_TAGSIZE, name, namelen)) 126 - /* Found it! */ 127 - return offset; 128 - break; 129 - 130 - case FDT_END_NODE: 131 - level--; 132 - break; 133 - 134 - case FDT_PROP: 135 - case FDT_NOP: 136 - break; 137 - 138 - default: 139 - return -FDT_ERR_BADSTRUCTURE; 140 - } 141 - } while (level >= 0); 142 - 143 - return -FDT_ERR_NOTFOUND; 124 + return offset; /* error */ 144 125 } 145 126 146 127 int fdt_subnode_offset(const void *fdt, int parentoffset, ··· 129 162 const char *p = path; 130 163 int offset = 0; 131 164 132 - CHECK_HEADER(fdt); 165 + FDT_CHECK_HEADER(fdt); 133 166 134 167 if (*path != '/') 135 168 return -FDT_ERR_BADPATH; ··· 157 190 158 191 const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) 159 192 { 160 - const struct fdt_node_header *nh; 193 + const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); 161 194 int err; 162 195 163 - if ((err = fdt_check_header(fdt)) != 0) 164 - goto fail; 165 - 166 - err = -FDT_ERR_BADOFFSET; 167 - nh = fdt_offset_ptr(fdt, nodeoffset, sizeof(*nh)); 168 - if (!nh || (fdt32_to_cpu(nh->tag) != FDT_BEGIN_NODE)) 169 - goto fail; 196 + if (((err = fdt_check_header(fdt)) != 0) 197 + || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) 198 + goto fail; 170 199 171 200 if (len) 172 201 *len = strlen(nh->name); ··· 185 222 int offset, nextoffset; 186 223 int err; 187 224 188 - if ((err = fdt_check_header(fdt)) != 0) 189 - goto fail; 225 + if (((err = fdt_check_header(fdt)) != 0) 226 + || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) 227 + goto fail; 190 228 191 - err = -FDT_ERR_BADOFFSET; 192 - if (nodeoffset % FDT_TAGSIZE) 193 - goto fail; 194 - 195 - tag = fdt_next_tag(fdt, nodeoffset, &nextoffset); 196 - if (tag != FDT_BEGIN_NODE) 197 - goto fail; 198 - 229 + nextoffset = err; 199 230 do { 200 231 offset = nextoffset; 201 232 ··· 210 253 if (! prop) 211 254 goto fail; 212 255 namestroff = fdt32_to_cpu(prop->nameoff); 213 - if (streq(fdt_string(fdt, namestroff), name)) { 256 + if (strcmp(fdt_string(fdt, namestroff), name) == 0) { 214 257 /* Found it! */ 215 258 int len = fdt32_to_cpu(prop->len); 216 259 prop = fdt_offset_ptr(fdt, offset, ··· 264 307 265 308 int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) 266 309 { 267 - uint32_t tag; 268 - int p = 0, overflow = 0; 269 - int offset, nextoffset, namelen; 310 + int pdepth = 0, p = 0; 311 + int offset, depth, namelen; 270 312 const char *name; 271 313 272 - CHECK_HEADER(fdt); 273 - 274 - tag = fdt_next_tag(fdt, 0, &nextoffset); 275 - if (tag != FDT_BEGIN_NODE) 276 - return -FDT_ERR_BADSTRUCTURE; 314 + FDT_CHECK_HEADER(fdt); 277 315 278 316 if (buflen < 2) 279 317 return -FDT_ERR_NOSPACE; 280 - buf[0] = '/'; 281 - p = 1; 282 318 283 - while (nextoffset <= nodeoffset) { 284 - offset = nextoffset; 285 - tag = fdt_next_tag(fdt, offset, &nextoffset); 286 - switch (tag) { 287 - case FDT_END: 288 - return -FDT_ERR_BADOFFSET; 319 + for (offset = 0, depth = 0; 320 + (offset >= 0) && (offset <= nodeoffset); 321 + offset = fdt_next_node(fdt, offset, &depth)) { 322 + if (pdepth < depth) 323 + continue; /* overflowed buffer */ 289 324 290 - case FDT_BEGIN_NODE: 291 - name = fdt_get_name(fdt, offset, &namelen); 292 - if (!name) 293 - return namelen; 294 - if (overflow || ((p + namelen + 1) > buflen)) { 295 - overflow++; 296 - break; 297 - } 325 + while (pdepth > depth) { 326 + do { 327 + p--; 328 + } while (buf[p-1] != '/'); 329 + pdepth--; 330 + } 331 + 332 + name = fdt_get_name(fdt, offset, &namelen); 333 + if (!name) 334 + return namelen; 335 + if ((p + namelen + 1) <= buflen) { 298 336 memcpy(buf + p, name, namelen); 299 337 p += namelen; 300 338 buf[p++] = '/'; 301 - break; 339 + pdepth++; 340 + } 302 341 303 - case FDT_END_NODE: 304 - if (overflow) { 305 - overflow--; 306 - break; 307 - } 308 - do { 342 + if (offset == nodeoffset) { 343 + if (pdepth < (depth + 1)) 344 + return -FDT_ERR_NOSPACE; 345 + 346 + if (p > 1) /* special case so that root path is "/", not "" */ 309 347 p--; 310 - } while (buf[p-1] != '/'); 311 - break; 312 - 313 - case FDT_PROP: 314 - case FDT_NOP: 315 - break; 316 - 317 - default: 318 - return -FDT_ERR_BADSTRUCTURE; 348 + buf[p] = '\0'; 349 + return p; 319 350 } 320 351 } 321 352 322 - if (overflow) 323 - return -FDT_ERR_NOSPACE; 353 + if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) 354 + return -FDT_ERR_BADOFFSET; 355 + else if (offset == -FDT_ERR_BADOFFSET) 356 + return -FDT_ERR_BADSTRUCTURE; 324 357 325 - if (p > 1) /* special case so that root path is "/", not "" */ 326 - p--; 327 - buf[p] = '\0'; 328 - return p; 358 + return offset; /* error from fdt_next_node() */ 329 359 } 330 360 331 361 int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, 332 362 int supernodedepth, int *nodedepth) 333 363 { 334 - int level = -1; 335 - uint32_t tag; 336 - int offset, nextoffset = 0; 364 + int offset, depth; 337 365 int supernodeoffset = -FDT_ERR_INTERNAL; 338 366 339 - CHECK_HEADER(fdt); 367 + FDT_CHECK_HEADER(fdt); 340 368 341 369 if (supernodedepth < 0) 342 370 return -FDT_ERR_NOTFOUND; 343 371 344 - do { 345 - offset = nextoffset; 346 - tag = fdt_next_tag(fdt, offset, &nextoffset); 347 - switch (tag) { 348 - case FDT_END: 349 - return -FDT_ERR_BADOFFSET; 372 + for (offset = 0, depth = 0; 373 + (offset >= 0) && (offset <= nodeoffset); 374 + offset = fdt_next_node(fdt, offset, &depth)) { 375 + if (depth == supernodedepth) 376 + supernodeoffset = offset; 350 377 351 - case FDT_BEGIN_NODE: 352 - level++; 353 - if (level == supernodedepth) 354 - supernodeoffset = offset; 355 - break; 378 + if (offset == nodeoffset) { 379 + if (nodedepth) 380 + *nodedepth = depth; 356 381 357 - case FDT_END_NODE: 358 - level--; 359 - break; 360 - 361 - case FDT_PROP: 362 - case FDT_NOP: 363 - break; 364 - 365 - default: 366 - return -FDT_ERR_BADSTRUCTURE; 382 + if (supernodedepth > depth) 383 + return -FDT_ERR_NOTFOUND; 384 + else 385 + return supernodeoffset; 367 386 } 368 - } while (offset < nodeoffset); 387 + } 369 388 370 - if (nodedepth) 371 - *nodedepth = level; 389 + if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) 390 + return -FDT_ERR_BADOFFSET; 391 + else if (offset == -FDT_ERR_BADOFFSET) 392 + return -FDT_ERR_BADSTRUCTURE; 372 393 373 - if (supernodedepth > level) 374 - return -FDT_ERR_NOTFOUND; 375 - return supernodeoffset; 394 + return offset; /* error from fdt_next_node() */ 376 395 } 377 396 378 397 int fdt_node_depth(const void *fdt, int nodeoffset) ··· 376 443 const char *propname, 377 444 const void *propval, int proplen) 378 445 { 379 - uint32_t tag; 380 - int offset, nextoffset; 446 + int offset; 381 447 const void *val; 382 448 int len; 383 449 384 - CHECK_HEADER(fdt); 385 - 386 - if (startoffset >= 0) { 387 - tag = fdt_next_tag(fdt, startoffset, &nextoffset); 388 - if (tag != FDT_BEGIN_NODE) 389 - return -FDT_ERR_BADOFFSET; 390 - } else { 391 - nextoffset = 0; 392 - } 450 + FDT_CHECK_HEADER(fdt); 393 451 394 452 /* FIXME: The algorithm here is pretty horrible: we scan each 395 453 * property of a node in fdt_getprop(), then if that didn't 396 454 * find what we want, we scan over them again making our way 397 455 * to the next node. Still it's the easiest to implement 398 456 * approach; performance can come later. */ 399 - do { 400 - offset = nextoffset; 401 - tag = fdt_next_tag(fdt, offset, &nextoffset); 457 + for (offset = fdt_next_node(fdt, startoffset, NULL); 458 + offset >= 0; 459 + offset = fdt_next_node(fdt, offset, NULL)) { 460 + val = fdt_getprop(fdt, offset, propname, &len); 461 + if (val && (len == proplen) 462 + && (memcmp(val, propval, len) == 0)) 463 + return offset; 464 + } 402 465 403 - switch (tag) { 404 - case FDT_BEGIN_NODE: 405 - val = fdt_getprop(fdt, offset, propname, &len); 406 - if (val 407 - && (len == proplen) 408 - && (memcmp(val, propval, len) == 0)) 409 - return offset; 410 - break; 411 - 412 - case FDT_PROP: 413 - case FDT_END: 414 - case FDT_END_NODE: 415 - case FDT_NOP: 416 - break; 417 - 418 - default: 419 - return -FDT_ERR_BADSTRUCTURE; 420 - } 421 - } while (tag != FDT_END); 422 - 423 - return -FDT_ERR_NOTFOUND; 466 + return offset; /* error from fdt_next_node() */ 424 467 } 425 468 426 469 int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) ··· 408 499 &phandle, sizeof(phandle)); 409 500 } 410 501 411 - int _stringlist_contains(const void *strlist, int listlen, const char *str) 502 + int _stringlist_contains(const char *strlist, int listlen, const char *str) 412 503 { 413 504 int len = strlen(str); 414 - const void *p; 505 + const char *p; 415 506 416 507 while (listlen >= len) { 417 508 if (memcmp(str, strlist, len+1) == 0) ··· 443 534 int fdt_node_offset_by_compatible(const void *fdt, int startoffset, 444 535 const char *compatible) 445 536 { 446 - uint32_t tag; 447 - int offset, nextoffset; 448 - int err; 537 + int offset, err; 449 538 450 - CHECK_HEADER(fdt); 451 - 452 - if (startoffset >= 0) { 453 - tag = fdt_next_tag(fdt, startoffset, &nextoffset); 454 - if (tag != FDT_BEGIN_NODE) 455 - return -FDT_ERR_BADOFFSET; 456 - } else { 457 - nextoffset = 0; 458 - } 539 + FDT_CHECK_HEADER(fdt); 459 540 460 541 /* FIXME: The algorithm here is pretty horrible: we scan each 461 542 * property of a node in fdt_node_check_compatible(), then if 462 543 * that didn't find what we want, we scan over them again 463 544 * making our way to the next node. Still it's the easiest to 464 545 * implement approach; performance can come later. */ 465 - do { 466 - offset = nextoffset; 467 - tag = fdt_next_tag(fdt, offset, &nextoffset); 546 + for (offset = fdt_next_node(fdt, startoffset, NULL); 547 + offset >= 0; 548 + offset = fdt_next_node(fdt, offset, NULL)) { 549 + err = fdt_node_check_compatible(fdt, offset, compatible); 550 + if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) 551 + return err; 552 + else if (err == 0) 553 + return offset; 554 + } 468 555 469 - switch (tag) { 470 - case FDT_BEGIN_NODE: 471 - err = fdt_node_check_compatible(fdt, offset, 472 - compatible); 473 - if ((err < 0) 474 - && (err != -FDT_ERR_NOTFOUND)) 475 - return err; 476 - else if (err == 0) 477 - return offset; 478 - break; 479 - 480 - case FDT_PROP: 481 - case FDT_END: 482 - case FDT_END_NODE: 483 - case FDT_NOP: 484 - break; 485 - 486 - default: 487 - return -FDT_ERR_BADSTRUCTURE; 488 - } 489 - } while (tag != FDT_END); 490 - 491 - return -FDT_ERR_NOTFOUND; 556 + return offset; /* error from fdt_next_node() */ 492 557 }
+108 -92
arch/powerpc/boot/libfdt/fdt_rw.c
··· 55 55 56 56 #include "libfdt_internal.h" 57 57 58 - static int _blocks_misordered(const void *fdt, 58 + static int _fdt_blocks_misordered(const void *fdt, 59 59 int mem_rsv_size, int struct_size) 60 60 { 61 - return (fdt_off_mem_rsvmap(fdt) < ALIGN(sizeof(struct fdt_header), 8)) 61 + return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) 62 62 || (fdt_off_dt_struct(fdt) < 63 63 (fdt_off_mem_rsvmap(fdt) + mem_rsv_size)) 64 64 || (fdt_off_dt_strings(fdt) < ··· 67 67 (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); 68 68 } 69 69 70 - static int rw_check_header(void *fdt) 70 + static int _fdt_rw_check_header(void *fdt) 71 71 { 72 - int err; 72 + FDT_CHECK_HEADER(fdt); 73 73 74 - if ((err = fdt_check_header(fdt))) 75 - return err; 76 74 if (fdt_version(fdt) < 17) 77 75 return -FDT_ERR_BADVERSION; 78 - if (_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), 79 - fdt_size_dt_struct(fdt))) 76 + if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), 77 + fdt_size_dt_struct(fdt))) 80 78 return -FDT_ERR_BADLAYOUT; 81 79 if (fdt_version(fdt) > 17) 82 80 fdt_set_version(fdt, 17); ··· 82 84 return 0; 83 85 } 84 86 85 - #define RW_CHECK_HEADER(fdt) \ 87 + #define FDT_RW_CHECK_HEADER(fdt) \ 86 88 { \ 87 89 int err; \ 88 - if ((err = rw_check_header(fdt)) != 0) \ 90 + if ((err = _fdt_rw_check_header(fdt)) != 0) \ 89 91 return err; \ 90 92 } 91 93 92 - static inline int _blob_data_size(void *fdt) 94 + static inline int _fdt_data_size(void *fdt) 93 95 { 94 96 return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); 95 97 } 96 98 97 - static int _blob_splice(void *fdt, void *p, int oldlen, int newlen) 99 + static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) 98 100 { 99 - void *end = fdt + _blob_data_size(fdt); 101 + char *p = splicepoint; 102 + char *end = (char *)fdt + _fdt_data_size(fdt); 100 103 101 104 if (((p + oldlen) < p) || ((p + oldlen) > end)) 102 105 return -FDT_ERR_BADOFFSET; 103 - if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt))) 106 + if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) 104 107 return -FDT_ERR_NOSPACE; 105 108 memmove(p + newlen, p + oldlen, end - p - oldlen); 106 109 return 0; 107 110 } 108 111 109 - static int _blob_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, 110 - int oldn, int newn) 112 + static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, 113 + int oldn, int newn) 111 114 { 112 115 int delta = (newn - oldn) * sizeof(*p); 113 116 int err; 114 - err = _blob_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); 117 + err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); 115 118 if (err) 116 119 return err; 117 120 fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); ··· 120 121 return 0; 121 122 } 122 123 123 - static int _blob_splice_struct(void *fdt, void *p, 124 - int oldlen, int newlen) 124 + static int _fdt_splice_struct(void *fdt, void *p, 125 + int oldlen, int newlen) 125 126 { 126 127 int delta = newlen - oldlen; 127 128 int err; 128 129 129 - if ((err = _blob_splice(fdt, p, oldlen, newlen))) 130 + if ((err = _fdt_splice(fdt, p, oldlen, newlen))) 130 131 return err; 131 132 132 133 fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); ··· 134 135 return 0; 135 136 } 136 137 137 - static int _blob_splice_string(void *fdt, int newlen) 138 + static int _fdt_splice_string(void *fdt, int newlen) 138 139 { 139 - void *p = fdt + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); 140 + void *p = (char *)fdt 141 + + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); 140 142 int err; 141 143 142 - if ((err = _blob_splice(fdt, p, 0, newlen))) 144 + if ((err = _fdt_splice(fdt, p, 0, newlen))) 143 145 return err; 144 146 145 147 fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); 146 148 return 0; 147 149 } 148 150 149 - static int _find_add_string(void *fdt, const char *s) 151 + static int _fdt_find_add_string(void *fdt, const char *s) 150 152 { 151 153 char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); 152 154 const char *p; ··· 161 161 return (p - strtab); 162 162 163 163 new = strtab + fdt_size_dt_strings(fdt); 164 - err = _blob_splice_string(fdt, len); 164 + err = _fdt_splice_string(fdt, len); 165 165 if (err) 166 166 return err; 167 167 ··· 174 174 struct fdt_reserve_entry *re; 175 175 int err; 176 176 177 - if ((err = rw_check_header(fdt))) 178 - return err; 177 + FDT_RW_CHECK_HEADER(fdt); 179 178 180 179 re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt)); 181 - err = _blob_splice_mem_rsv(fdt, re, 0, 1); 180 + err = _fdt_splice_mem_rsv(fdt, re, 0, 1); 182 181 if (err) 183 182 return err; 184 183 ··· 191 192 struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n); 192 193 int err; 193 194 194 - if ((err = rw_check_header(fdt))) 195 - return err; 195 + FDT_RW_CHECK_HEADER(fdt); 196 + 196 197 if (n >= fdt_num_mem_rsv(fdt)) 197 198 return -FDT_ERR_NOTFOUND; 198 199 199 - err = _blob_splice_mem_rsv(fdt, re, 1, 0); 200 + err = _fdt_splice_mem_rsv(fdt, re, 1, 0); 200 201 if (err) 201 202 return err; 202 203 return 0; 203 204 } 204 205 205 - static int _resize_property(void *fdt, int nodeoffset, const char *name, int len, 206 - struct fdt_property **prop) 206 + static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, 207 + int len, struct fdt_property **prop) 207 208 { 208 209 int oldlen; 209 210 int err; ··· 212 213 if (! (*prop)) 213 214 return oldlen; 214 215 215 - if ((err = _blob_splice_struct(fdt, (*prop)->data, 216 - ALIGN(oldlen, FDT_TAGSIZE), 217 - ALIGN(len, FDT_TAGSIZE)))) 216 + if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), 217 + FDT_TAGALIGN(len)))) 218 218 return err; 219 219 220 220 (*prop)->len = cpu_to_fdt32(len); 221 221 return 0; 222 222 } 223 223 224 - static int _add_property(void *fdt, int nodeoffset, const char *name, int len, 225 - struct fdt_property **prop) 224 + static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, 225 + int len, struct fdt_property **prop) 226 226 { 227 - uint32_t tag; 228 227 int proplen; 229 228 int nextoffset; 230 229 int namestroff; 231 230 int err; 232 231 233 - tag = fdt_next_tag(fdt, nodeoffset, &nextoffset); 234 - if (tag != FDT_BEGIN_NODE) 235 - return -FDT_ERR_BADOFFSET; 232 + if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) 233 + return nextoffset; 236 234 237 - namestroff = _find_add_string(fdt, name); 235 + namestroff = _fdt_find_add_string(fdt, name); 238 236 if (namestroff < 0) 239 237 return namestroff; 240 238 241 239 *prop = _fdt_offset_ptr_w(fdt, nextoffset); 242 - proplen = sizeof(**prop) + ALIGN(len, FDT_TAGSIZE); 240 + proplen = sizeof(**prop) + FDT_TAGALIGN(len); 243 241 244 - err = _blob_splice_struct(fdt, *prop, 0, proplen); 242 + err = _fdt_splice_struct(fdt, *prop, 0, proplen); 245 243 if (err) 246 244 return err; 247 245 ··· 248 252 return 0; 249 253 } 250 254 255 + int fdt_set_name(void *fdt, int nodeoffset, const char *name) 256 + { 257 + char *namep; 258 + int oldlen, newlen; 259 + int err; 260 + 261 + FDT_RW_CHECK_HEADER(fdt); 262 + 263 + namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); 264 + if (!namep) 265 + return oldlen; 266 + 267 + newlen = strlen(name); 268 + 269 + err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1), 270 + FDT_TAGALIGN(newlen+1)); 271 + if (err) 272 + return err; 273 + 274 + memcpy(namep, name, newlen+1); 275 + return 0; 276 + } 277 + 251 278 int fdt_setprop(void *fdt, int nodeoffset, const char *name, 252 279 const void *val, int len) 253 280 { 254 281 struct fdt_property *prop; 255 282 int err; 256 283 257 - if ((err = rw_check_header(fdt))) 258 - return err; 284 + FDT_RW_CHECK_HEADER(fdt); 259 285 260 - err = _resize_property(fdt, nodeoffset, name, len, &prop); 286 + err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop); 261 287 if (err == -FDT_ERR_NOTFOUND) 262 - err = _add_property(fdt, nodeoffset, name, len, &prop); 288 + err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); 263 289 if (err) 264 290 return err; 265 291 ··· 294 276 struct fdt_property *prop; 295 277 int len, proplen; 296 278 297 - RW_CHECK_HEADER(fdt); 279 + FDT_RW_CHECK_HEADER(fdt); 298 280 299 281 prop = fdt_get_property_w(fdt, nodeoffset, name, &len); 300 282 if (! prop) 301 283 return len; 302 284 303 - proplen = sizeof(*prop) + ALIGN(len, FDT_TAGSIZE); 304 - return _blob_splice_struct(fdt, prop, proplen, 0); 285 + proplen = sizeof(*prop) + FDT_TAGALIGN(len); 286 + return _fdt_splice_struct(fdt, prop, proplen, 0); 305 287 } 306 288 307 289 int fdt_add_subnode_namelen(void *fdt, int parentoffset, ··· 314 296 uint32_t tag; 315 297 uint32_t *endtag; 316 298 317 - RW_CHECK_HEADER(fdt); 299 + FDT_RW_CHECK_HEADER(fdt); 318 300 319 301 offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); 320 302 if (offset >= 0) ··· 327 309 do { 328 310 offset = nextoffset; 329 311 tag = fdt_next_tag(fdt, offset, &nextoffset); 330 - } while (tag == FDT_PROP); 312 + } while ((tag == FDT_PROP) || (tag == FDT_NOP)); 331 313 332 314 nh = _fdt_offset_ptr_w(fdt, offset); 333 - nodelen = sizeof(*nh) + ALIGN(namelen+1, FDT_TAGSIZE) + FDT_TAGSIZE; 315 + nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE; 334 316 335 - err = _blob_splice_struct(fdt, nh, 0, nodelen); 317 + err = _fdt_splice_struct(fdt, nh, 0, nodelen); 336 318 if (err) 337 319 return err; 338 320 339 321 nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); 340 - memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE)); 322 + memset(nh->name, 0, FDT_TAGALIGN(namelen+1)); 341 323 memcpy(nh->name, name, namelen); 342 - endtag = (uint32_t *)((void *)nh + nodelen - FDT_TAGSIZE); 324 + endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE); 343 325 *endtag = cpu_to_fdt32(FDT_END_NODE); 344 326 345 327 return offset; ··· 354 336 { 355 337 int endoffset; 356 338 357 - RW_CHECK_HEADER(fdt); 339 + FDT_RW_CHECK_HEADER(fdt); 358 340 359 341 endoffset = _fdt_node_end_offset(fdt, nodeoffset); 360 342 if (endoffset < 0) 361 343 return endoffset; 362 344 363 - return _blob_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset), 364 - endoffset - nodeoffset, 0); 345 + return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset), 346 + endoffset - nodeoffset, 0); 365 347 } 366 348 367 - static void _packblocks(const void *fdt, void *buf, 368 - int mem_rsv_size, int struct_size) 349 + static void _fdt_packblocks(const char *old, char *new, 350 + int mem_rsv_size, int struct_size) 369 351 { 370 352 int mem_rsv_off, struct_off, strings_off; 371 353 372 - mem_rsv_off = ALIGN(sizeof(struct fdt_header), 8); 354 + mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8); 373 355 struct_off = mem_rsv_off + mem_rsv_size; 374 356 strings_off = struct_off + struct_size; 375 357 376 - memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size); 377 - fdt_set_off_mem_rsvmap(buf, mem_rsv_off); 358 + memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size); 359 + fdt_set_off_mem_rsvmap(new, mem_rsv_off); 378 360 379 - memmove(buf + struct_off, fdt + fdt_off_dt_struct(fdt), struct_size); 380 - fdt_set_off_dt_struct(buf, struct_off); 381 - fdt_set_size_dt_struct(buf, struct_size); 361 + memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size); 362 + fdt_set_off_dt_struct(new, struct_off); 363 + fdt_set_size_dt_struct(new, struct_size); 382 364 383 - memmove(buf + strings_off, fdt + fdt_off_dt_strings(fdt), 384 - fdt_size_dt_strings(fdt)); 385 - fdt_set_off_dt_strings(buf, strings_off); 386 - fdt_set_size_dt_strings(buf, fdt_size_dt_strings(fdt)); 365 + memmove(new + strings_off, old + fdt_off_dt_strings(old), 366 + fdt_size_dt_strings(old)); 367 + fdt_set_off_dt_strings(new, strings_off); 368 + fdt_set_size_dt_strings(new, fdt_size_dt_strings(old)); 387 369 } 388 370 389 371 int fdt_open_into(const void *fdt, void *buf, int bufsize) ··· 391 373 int err; 392 374 int mem_rsv_size, struct_size; 393 375 int newsize; 394 - void *tmp; 376 + const char *fdtstart = fdt; 377 + const char *fdtend = fdtstart + fdt_totalsize(fdt); 378 + char *tmp; 395 379 396 - err = fdt_check_header(fdt); 397 - if (err) 398 - return err; 380 + FDT_CHECK_HEADER(fdt); 399 381 400 382 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) 401 383 * sizeof(struct fdt_reserve_entry); ··· 408 390 ; 409 391 } 410 392 411 - if (!_blocks_misordered(fdt, mem_rsv_size, struct_size)) { 393 + if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) { 412 394 /* no further work necessary */ 413 395 err = fdt_move(fdt, buf, bufsize); 414 396 if (err) ··· 420 402 } 421 403 422 404 /* Need to reorder */ 423 - newsize = ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size 405 + newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size 424 406 + struct_size + fdt_size_dt_strings(fdt); 425 407 426 408 if (bufsize < newsize) 427 409 return -FDT_ERR_NOSPACE; 428 410 429 - if (((buf + newsize) <= fdt) 430 - || (buf >= (fdt + fdt_totalsize(fdt)))) { 431 - tmp = buf; 432 - } else { 433 - tmp = (void *)fdt + fdt_totalsize(fdt); 434 - if ((tmp + newsize) > (buf + bufsize)) 411 + /* First attempt to build converted tree at beginning of buffer */ 412 + tmp = buf; 413 + /* But if that overlaps with the old tree... */ 414 + if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) { 415 + /* Try right after the old tree instead */ 416 + tmp = (char *)(uintptr_t)fdtend; 417 + if ((tmp + newsize) > ((char *)buf + bufsize)) 435 418 return -FDT_ERR_NOSPACE; 436 419 } 437 420 438 - _packblocks(fdt, tmp, mem_rsv_size, struct_size); 421 + _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size); 439 422 memmove(buf, tmp, newsize); 440 423 441 424 fdt_set_magic(buf, FDT_MAGIC); ··· 451 432 int fdt_pack(void *fdt) 452 433 { 453 434 int mem_rsv_size; 454 - int err; 455 435 456 - err = rw_check_header(fdt); 457 - if (err) 458 - return err; 436 + FDT_RW_CHECK_HEADER(fdt); 459 437 460 438 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) 461 439 * sizeof(struct fdt_reserve_entry); 462 - _packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); 463 - fdt_set_totalsize(fdt, _blob_data_size(fdt)); 440 + _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); 441 + fdt_set_totalsize(fdt, _fdt_data_size(fdt)); 464 442 465 443 return 0; 466 444 }
+17 -17
arch/powerpc/boot/libfdt/fdt_strerror.c
··· 55 55 56 56 #include "libfdt_internal.h" 57 57 58 - struct errtabent { 58 + struct fdt_errtabent { 59 59 const char *str; 60 60 }; 61 61 62 - #define ERRTABENT(val) \ 62 + #define FDT_ERRTABENT(val) \ 63 63 [(val)] = { .str = #val, } 64 64 65 - static struct errtabent errtable[] = { 66 - ERRTABENT(FDT_ERR_NOTFOUND), 67 - ERRTABENT(FDT_ERR_EXISTS), 68 - ERRTABENT(FDT_ERR_NOSPACE), 65 + static struct fdt_errtabent fdt_errtable[] = { 66 + FDT_ERRTABENT(FDT_ERR_NOTFOUND), 67 + FDT_ERRTABENT(FDT_ERR_EXISTS), 68 + FDT_ERRTABENT(FDT_ERR_NOSPACE), 69 69 70 - ERRTABENT(FDT_ERR_BADOFFSET), 71 - ERRTABENT(FDT_ERR_BADPATH), 72 - ERRTABENT(FDT_ERR_BADSTATE), 70 + FDT_ERRTABENT(FDT_ERR_BADOFFSET), 71 + FDT_ERRTABENT(FDT_ERR_BADPATH), 72 + FDT_ERRTABENT(FDT_ERR_BADSTATE), 73 73 74 - ERRTABENT(FDT_ERR_TRUNCATED), 75 - ERRTABENT(FDT_ERR_BADMAGIC), 76 - ERRTABENT(FDT_ERR_BADVERSION), 77 - ERRTABENT(FDT_ERR_BADSTRUCTURE), 78 - ERRTABENT(FDT_ERR_BADLAYOUT), 74 + FDT_ERRTABENT(FDT_ERR_TRUNCATED), 75 + FDT_ERRTABENT(FDT_ERR_BADMAGIC), 76 + FDT_ERRTABENT(FDT_ERR_BADVERSION), 77 + FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 78 + FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 79 79 }; 80 - #define ERRTABSIZE (sizeof(errtable) / sizeof(errtable[0])) 80 + #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 81 81 82 82 const char *fdt_strerror(int errval) 83 83 { ··· 85 85 return "<valid offset/length>"; 86 86 else if (errval == 0) 87 87 return "<no error>"; 88 - else if (errval > -ERRTABSIZE) { 89 - const char *s = errtable[-errval].str; 88 + else if (errval > -FDT_ERRTABSIZE) { 89 + const char *s = fdt_errtable[-errval].str; 90 90 91 91 if (s) 92 92 return s;
+27 -28
arch/powerpc/boot/libfdt/fdt_sw.c
··· 55 55 56 56 #include "libfdt_internal.h" 57 57 58 - static int check_header_sw(void *fdt) 58 + static int _fdt_sw_check_header(void *fdt) 59 59 { 60 - if (fdt_magic(fdt) != SW_MAGIC) 60 + if (fdt_magic(fdt) != FDT_SW_MAGIC) 61 61 return -FDT_ERR_BADMAGIC; 62 + /* FIXME: should check more details about the header state */ 62 63 return 0; 63 64 } 64 65 65 - static void *grab_space(void *fdt, int len) 66 + #define FDT_SW_CHECK_HEADER(fdt) \ 67 + { \ 68 + int err; \ 69 + if ((err = _fdt_sw_check_header(fdt)) != 0) \ 70 + return err; \ 71 + } 72 + 73 + static void *_fdt_grab_space(void *fdt, int len) 66 74 { 67 75 int offset = fdt_size_dt_struct(fdt); 68 76 int spaceleft; ··· 94 86 95 87 memset(buf, 0, bufsize); 96 88 97 - fdt_set_magic(fdt, SW_MAGIC); 89 + fdt_set_magic(fdt, FDT_SW_MAGIC); 98 90 fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); 99 91 fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION); 100 92 fdt_set_totalsize(fdt, bufsize); 101 93 102 - fdt_set_off_mem_rsvmap(fdt, ALIGN(sizeof(struct fdt_header), 103 - sizeof(struct fdt_reserve_entry))); 94 + fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header), 95 + sizeof(struct fdt_reserve_entry))); 104 96 fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); 105 97 fdt_set_off_dt_strings(fdt, bufsize); 106 98 ··· 110 102 int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) 111 103 { 112 104 struct fdt_reserve_entry *re; 113 - int err = check_header_sw(fdt); 114 105 int offset; 115 106 116 - if (err) 117 - return err; 107 + FDT_SW_CHECK_HEADER(fdt); 108 + 118 109 if (fdt_size_dt_struct(fdt)) 119 110 return -FDT_ERR_BADSTATE; 120 111 ··· 121 114 if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) 122 115 return -FDT_ERR_NOSPACE; 123 116 124 - re = (struct fdt_reserve_entry *)(fdt + offset); 117 + re = (struct fdt_reserve_entry *)((char *)fdt + offset); 125 118 re->address = cpu_to_fdt64(addr); 126 119 re->size = cpu_to_fdt64(size); 127 120 ··· 138 131 int fdt_begin_node(void *fdt, const char *name) 139 132 { 140 133 struct fdt_node_header *nh; 141 - int err = check_header_sw(fdt); 142 134 int namelen = strlen(name) + 1; 143 135 144 - if (err) 145 - return err; 136 + FDT_SW_CHECK_HEADER(fdt); 146 137 147 - nh = grab_space(fdt, sizeof(*nh) + ALIGN(namelen, FDT_TAGSIZE)); 138 + nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); 148 139 if (! nh) 149 140 return -FDT_ERR_NOSPACE; 150 141 ··· 154 149 int fdt_end_node(void *fdt) 155 150 { 156 151 uint32_t *en; 157 - int err = check_header_sw(fdt); 158 152 159 - if (err) 160 - return err; 153 + FDT_SW_CHECK_HEADER(fdt); 161 154 162 - en = grab_space(fdt, FDT_TAGSIZE); 155 + en = _fdt_grab_space(fdt, FDT_TAGSIZE); 163 156 if (! en) 164 157 return -FDT_ERR_NOSPACE; 165 158 ··· 165 162 return 0; 166 163 } 167 164 168 - static int find_add_string(void *fdt, const char *s) 165 + static int _fdt_find_add_string(void *fdt, const char *s) 169 166 { 170 167 char *strtab = (char *)fdt + fdt_totalsize(fdt); 171 168 const char *p; ··· 191 188 int fdt_property(void *fdt, const char *name, const void *val, int len) 192 189 { 193 190 struct fdt_property *prop; 194 - int err = check_header_sw(fdt); 195 191 int nameoff; 196 192 197 - if (err) 198 - return err; 193 + FDT_SW_CHECK_HEADER(fdt); 199 194 200 - nameoff = find_add_string(fdt, name); 195 + nameoff = _fdt_find_add_string(fdt, name); 201 196 if (nameoff == 0) 202 197 return -FDT_ERR_NOSPACE; 203 198 204 - prop = grab_space(fdt, sizeof(*prop) + ALIGN(len, FDT_TAGSIZE)); 199 + prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); 205 200 if (! prop) 206 201 return -FDT_ERR_NOSPACE; 207 202 ··· 212 211 213 212 int fdt_finish(void *fdt) 214 213 { 215 - int err = check_header_sw(fdt); 216 214 char *p = (char *)fdt; 217 215 uint32_t *end; 218 216 int oldstroffset, newstroffset; 219 217 uint32_t tag; 220 218 int offset, nextoffset; 221 219 222 - if (err) 223 - return err; 220 + FDT_SW_CHECK_HEADER(fdt); 224 221 225 222 /* Add terminator */ 226 - end = grab_space(fdt, sizeof(*end)); 223 + end = _fdt_grab_space(fdt, sizeof(*end)); 227 224 if (! end) 228 225 return -FDT_ERR_NOSPACE; 229 226 *end = cpu_to_fdt32(FDT_END);
+5 -4
arch/powerpc/boot/libfdt/fdt_wip.c
··· 72 72 return 0; 73 73 } 74 74 75 - static void nop_region(void *start, int len) 75 + static void _fdt_nop_region(void *start, int len) 76 76 { 77 77 uint32_t *p; 78 78 79 - for (p = start; (void *)p < (start + len); p++) 79 + for (p = start; (char *)p < ((char *)start + len); p++) 80 80 *p = cpu_to_fdt32(FDT_NOP); 81 81 } 82 82 ··· 89 89 if (! prop) 90 90 return len; 91 91 92 - nop_region(prop, len + sizeof(*prop)); 92 + _fdt_nop_region(prop, len + sizeof(*prop)); 93 93 94 94 return 0; 95 95 } ··· 139 139 if (endoffset < 0) 140 140 return endoffset; 141 141 142 - nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0), endoffset - nodeoffset); 142 + _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0), 143 + endoffset - nodeoffset); 143 144 return 0; 144 145 }
+369 -14
arch/powerpc/boot/libfdt/libfdt.h
··· 125 125 const void *fdt_offset_ptr(const void *fdt, int offset, int checklen); 126 126 static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) 127 127 { 128 - return (void *)fdt_offset_ptr(fdt, offset, checklen); 128 + return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); 129 129 } 130 130 131 131 uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); 132 + 133 + /**********************************************************************/ 134 + /* Traversal functions */ 135 + /**********************************************************************/ 136 + 137 + int fdt_next_node(const void *fdt, int offset, int *depth); 132 138 133 139 /**********************************************************************/ 134 140 /* General functions */ ··· 213 207 /**********************************************************************/ 214 208 215 209 /** 216 - * fdt_string - retreive a string from the strings block of a device tree 210 + * fdt_string - retrieve a string from the strings block of a device tree 217 211 * @fdt: pointer to the device tree blob 218 212 * @stroffset: offset of the string within the strings block (native endian) 219 213 * ··· 227 221 const char *fdt_string(const void *fdt, int stroffset); 228 222 229 223 /** 230 - * fdt_num_mem_rsv - retreive the number of memory reserve map entries 224 + * fdt_num_mem_rsv - retrieve the number of memory reserve map entries 231 225 * @fdt: pointer to the device tree blob 232 226 * 233 227 * Returns the number of entries in the device tree blob's memory ··· 240 234 int fdt_num_mem_rsv(const void *fdt); 241 235 242 236 /** 243 - * fdt_get_mem_rsv - retreive one memory reserve map entry 237 + * fdt_get_mem_rsv - retrieve one memory reserve map entry 244 238 * @fdt: pointer to the device tree blob 245 239 * @address, @size: pointers to 64-bit variables 246 240 * ··· 320 314 int fdt_path_offset(const void *fdt, const char *path); 321 315 322 316 /** 323 - * fdt_get_name - retreive the name of a given node 317 + * fdt_get_name - retrieve the name of a given node 324 318 * @fdt: pointer to the device tree blob 325 319 * @nodeoffset: structure block offset of the starting node 326 320 * @lenp: pointer to an integer variable (will be overwritten) or NULL ··· 352 346 * fdt_get_property() retrieves a pointer to the fdt_property 353 347 * structure within the device tree blob corresponding to the property 354 348 * named 'name' of the node at offset nodeoffset. If lenp is 355 - * non-NULL, the length of the property value also returned, in the 349 + * non-NULL, the length of the property value is also returned, in the 356 350 * integer pointed to by lenp. 357 351 * 358 352 * returns: ··· 375 369 const char *name, 376 370 int *lenp) 377 371 { 378 - return (struct fdt_property *)fdt_get_property(fdt, nodeoffset, 379 - name, lenp); 372 + return (struct fdt_property *)(uintptr_t) 373 + fdt_get_property(fdt, nodeoffset, name, lenp); 380 374 } 381 375 382 376 /** ··· 389 383 * fdt_getprop() retrieves a pointer to the value of the property 390 384 * named 'name' of the node at offset nodeoffset (this will be a 391 385 * pointer to within the device blob itself, not a copy of the value). 392 - * If lenp is non-NULL, the length of the property value also 386 + * If lenp is non-NULL, the length of the property value is also 393 387 * returned, in the integer pointed to by lenp. 394 388 * 395 389 * returns: ··· 411 405 static inline void *fdt_getprop_w(void *fdt, int nodeoffset, 412 406 const char *name, int *lenp) 413 407 { 414 - return (void *)fdt_getprop(fdt, nodeoffset, name, lenp); 408 + return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); 415 409 } 416 410 417 411 /** 418 - * fdt_get_phandle - retreive the phandle of a given node 412 + * fdt_get_phandle - retrieve the phandle of a given node 419 413 * @fdt: pointer to the device tree blob 420 414 * @nodeoffset: structure block offset of the node 421 415 * ··· 423 417 * structure block offset nodeoffset. 424 418 * 425 419 * returns: 426 - * the phandle of the node at nodeoffset, on succes (!= 0, != -1) 420 + * the phandle of the node at nodeoffset, on success (!= 0, != -1) 427 421 * 0, if the node has no phandle, or another error occurs 428 422 */ 429 423 uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); ··· 522 516 * structure from the start to nodeoffset, *twice*. 523 517 * 524 518 * returns: 525 - * stucture block offset of the parent of the node at nodeoffset 519 + * structure block offset of the parent of the node at nodeoffset 526 520 * (>=0), on success 527 521 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 528 522 * -FDT_ERR_BADMAGIC, ··· 579 573 * @fdt: pointer to the device tree blob 580 574 * @phandle: phandle value 581 575 * 582 - * fdt_node_offset_by_prop_value() returns the offset of the node 576 + * fdt_node_offset_by_phandle() returns the offset of the node 583 577 * which has the given phandle value. If there is more than one node 584 578 * in the tree with the given phandle (an invalid tree), results are 585 579 * undefined. ··· 661 655 /* Write-in-place functions */ 662 656 /**********************************************************************/ 663 657 658 + /** 659 + * fdt_setprop_inplace - change a property's value, but not its size 660 + * @fdt: pointer to the device tree blob 661 + * @nodeoffset: offset of the node whose property to change 662 + * @name: name of the property to change 663 + * @val: pointer to data to replace the property value with 664 + * @len: length of the property value 665 + * 666 + * fdt_setprop_inplace() replaces the value of a given property with 667 + * the data in val, of length len. This function cannot change the 668 + * size of a property, and so will only work if len is equal to the 669 + * current length of the property. 670 + * 671 + * This function will alter only the bytes in the blob which contain 672 + * the given property value, and will not alter or move any other part 673 + * of the tree. 674 + * 675 + * returns: 676 + * 0, on success 677 + * -FDT_ERR_NOSPACE, if len is not equal to the property's current length 678 + * -FDT_ERR_NOTFOUND, node does not have the named property 679 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 680 + * -FDT_ERR_BADMAGIC, 681 + * -FDT_ERR_BADVERSION, 682 + * -FDT_ERR_BADSTATE, 683 + * -FDT_ERR_BADSTRUCTURE, 684 + * -FDT_ERR_TRUNCATED, standard meanings 685 + */ 664 686 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 665 687 const void *val, int len); 688 + 689 + /** 690 + * fdt_setprop_inplace_cell - change the value of a single-cell property 691 + * @fdt: pointer to the device tree blob 692 + * @nodeoffset: offset of the node whose property to change 693 + * @name: name of the property to change 694 + * @val: cell (32-bit integer) value to replace the property with 695 + * 696 + * fdt_setprop_inplace_cell() replaces the value of a given property 697 + * with the 32-bit integer cell value in val, converting val to 698 + * big-endian if necessary. This function cannot change the size of a 699 + * property, and so will only work if the property already exists and 700 + * has length 4. 701 + * 702 + * This function will alter only the bytes in the blob which contain 703 + * the given property value, and will not alter or move any other part 704 + * of the tree. 705 + * 706 + * returns: 707 + * 0, on success 708 + * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 709 + * -FDT_ERR_NOTFOUND, node does not have the named property 710 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 711 + * -FDT_ERR_BADMAGIC, 712 + * -FDT_ERR_BADVERSION, 713 + * -FDT_ERR_BADSTATE, 714 + * -FDT_ERR_BADSTRUCTURE, 715 + * -FDT_ERR_TRUNCATED, standard meanings 716 + */ 666 717 static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, 667 718 const char *name, uint32_t val) 668 719 { ··· 727 664 return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val)); 728 665 } 729 666 667 + /** 668 + * fdt_nop_property - replace a property with nop tags 669 + * @fdt: pointer to the device tree blob 670 + * @nodeoffset: offset of the node whose property to nop 671 + * @name: name of the property to nop 672 + * 673 + * fdt_nop_property() will replace a given property's representation 674 + * in the blob with FDT_NOP tags, effectively removing it from the 675 + * tree. 676 + * 677 + * This function will alter only the bytes in the blob which contain 678 + * the property, and will not alter or move any other part of the 679 + * tree. 680 + * 681 + * returns: 682 + * 0, on success 683 + * -FDT_ERR_NOTFOUND, node does not have the named property 684 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 685 + * -FDT_ERR_BADMAGIC, 686 + * -FDT_ERR_BADVERSION, 687 + * -FDT_ERR_BADSTATE, 688 + * -FDT_ERR_BADSTRUCTURE, 689 + * -FDT_ERR_TRUNCATED, standard meanings 690 + */ 730 691 int fdt_nop_property(void *fdt, int nodeoffset, const char *name); 692 + 693 + /** 694 + * fdt_nop_node - replace a node (subtree) with nop tags 695 + * @fdt: pointer to the device tree blob 696 + * @nodeoffset: offset of the node to nop 697 + * 698 + * fdt_nop_node() will replace a given node's representation in the 699 + * blob, including all its subnodes, if any, with FDT_NOP tags, 700 + * effectively removing it from the tree. 701 + * 702 + * This function will alter only the bytes in the blob which contain 703 + * the node and its properties and subnodes, and will not alter or 704 + * move any other part of the tree. 705 + * 706 + * returns: 707 + * 0, on success 708 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 709 + * -FDT_ERR_BADMAGIC, 710 + * -FDT_ERR_BADVERSION, 711 + * -FDT_ERR_BADSTATE, 712 + * -FDT_ERR_BADSTRUCTURE, 713 + * -FDT_ERR_TRUNCATED, standard meanings 714 + */ 731 715 int fdt_nop_node(void *fdt, int nodeoffset); 732 716 733 717 /**********************************************************************/ ··· 803 693 int fdt_open_into(const void *fdt, void *buf, int bufsize); 804 694 int fdt_pack(void *fdt); 805 695 696 + /** 697 + * fdt_add_mem_rsv - add one memory reserve map entry 698 + * @fdt: pointer to the device tree blob 699 + * @address, @size: 64-bit values (native endian) 700 + * 701 + * Adds a reserve map entry to the given blob reserving a region at 702 + * address address of length size. 703 + * 704 + * This function will insert data into the reserve map and will 705 + * therefore change the indexes of some entries in the table. 706 + * 707 + * returns: 708 + * 0, on success 709 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 710 + * contain the new reservation entry 711 + * -FDT_ERR_BADMAGIC, 712 + * -FDT_ERR_BADVERSION, 713 + * -FDT_ERR_BADSTATE, 714 + * -FDT_ERR_BADSTRUCTURE, 715 + * -FDT_ERR_BADLAYOUT, 716 + * -FDT_ERR_TRUNCATED, standard meanings 717 + */ 806 718 int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); 719 + 720 + /** 721 + * fdt_del_mem_rsv - remove a memory reserve map entry 722 + * @fdt: pointer to the device tree blob 723 + * @n: entry to remove 724 + * 725 + * fdt_del_mem_rsv() removes the n-th memory reserve map entry from 726 + * the blob. 727 + * 728 + * This function will delete data from the reservation table and will 729 + * therefore change the indexes of some entries in the table. 730 + * 731 + * returns: 732 + * 0, on success 733 + * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there 734 + * are less than n+1 reserve map entries) 735 + * -FDT_ERR_BADMAGIC, 736 + * -FDT_ERR_BADVERSION, 737 + * -FDT_ERR_BADSTATE, 738 + * -FDT_ERR_BADSTRUCTURE, 739 + * -FDT_ERR_BADLAYOUT, 740 + * -FDT_ERR_TRUNCATED, standard meanings 741 + */ 807 742 int fdt_del_mem_rsv(void *fdt, int n); 808 743 744 + /** 745 + * fdt_set_name - change the name of a given node 746 + * @fdt: pointer to the device tree blob 747 + * @nodeoffset: structure block offset of a node 748 + * @name: name to give the node 749 + * 750 + * fdt_set_name() replaces the name (including unit address, if any) 751 + * of the given node with the given string. NOTE: this function can't 752 + * efficiently check if the new name is unique amongst the given 753 + * node's siblings; results are undefined if this function is invoked 754 + * with a name equal to one of the given node's siblings. 755 + * 756 + * This function may insert or delete data from the blob, and will 757 + * therefore change the offsets of some existing nodes. 758 + * 759 + * returns: 760 + * 0, on success 761 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob 762 + * to contain the new name 763 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 764 + * -FDT_ERR_BADMAGIC, 765 + * -FDT_ERR_BADVERSION, 766 + * -FDT_ERR_BADSTATE, standard meanings 767 + */ 768 + int fdt_set_name(void *fdt, int nodeoffset, const char *name); 769 + 770 + /** 771 + * fdt_setprop - create or change a property 772 + * @fdt: pointer to the device tree blob 773 + * @nodeoffset: offset of the node whose property to change 774 + * @name: name of the property to change 775 + * @val: pointer to data to set the property value to 776 + * @len: length of the property value 777 + * 778 + * fdt_setprop() sets the value of the named property in the given 779 + * node to the given value and length, creating the property if it 780 + * does not already exist. 781 + * 782 + * This function may insert or delete data from the blob, and will 783 + * therefore change the offsets of some existing nodes. 784 + * 785 + * returns: 786 + * 0, on success 787 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 788 + * contain the new property value 789 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 790 + * -FDT_ERR_BADLAYOUT, 791 + * -FDT_ERR_BADMAGIC, 792 + * -FDT_ERR_BADVERSION, 793 + * -FDT_ERR_BADSTATE, 794 + * -FDT_ERR_BADSTRUCTURE, 795 + * -FDT_ERR_BADLAYOUT, 796 + * -FDT_ERR_TRUNCATED, standard meanings 797 + */ 809 798 int fdt_setprop(void *fdt, int nodeoffset, const char *name, 810 799 const void *val, int len); 800 + 801 + /** 802 + * fdt_setprop_cell - set a property to a single cell value 803 + * @fdt: pointer to the device tree blob 804 + * @nodeoffset: offset of the node whose property to change 805 + * @name: name of the property to change 806 + * @val: 32-bit integer value for the property (native endian) 807 + * 808 + * fdt_setprop_cell() sets the value of the named property in the 809 + * given node to the given cell value (converting to big-endian if 810 + * necessary), or creates a new property with that value if it does 811 + * not already exist. 812 + * 813 + * This function may insert or delete data from the blob, and will 814 + * therefore change the offsets of some existing nodes. 815 + * 816 + * returns: 817 + * 0, on success 818 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 819 + * contain the new property value 820 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 821 + * -FDT_ERR_BADLAYOUT, 822 + * -FDT_ERR_BADMAGIC, 823 + * -FDT_ERR_BADVERSION, 824 + * -FDT_ERR_BADSTATE, 825 + * -FDT_ERR_BADSTRUCTURE, 826 + * -FDT_ERR_BADLAYOUT, 827 + * -FDT_ERR_TRUNCATED, standard meanings 828 + */ 811 829 static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, 812 830 uint32_t val) 813 831 { 814 832 val = cpu_to_fdt32(val); 815 833 return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val)); 816 834 } 835 + 836 + /** 837 + * fdt_setprop_string - set a property to a string value 838 + * @fdt: pointer to the device tree blob 839 + * @nodeoffset: offset of the node whose property to change 840 + * @name: name of the property to change 841 + * @str: string value for the property 842 + * 843 + * fdt_setprop_string() sets the value of the named property in the 844 + * given node to the given string value (using the length of the 845 + * string to determine the new length of the property), or creates a 846 + * new property with that value if it does not already exist. 847 + * 848 + * This function may insert or delete data from the blob, and will 849 + * therefore change the offsets of some existing nodes. 850 + * 851 + * returns: 852 + * 0, on success 853 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 854 + * contain the new property value 855 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 856 + * -FDT_ERR_BADLAYOUT, 857 + * -FDT_ERR_BADMAGIC, 858 + * -FDT_ERR_BADVERSION, 859 + * -FDT_ERR_BADSTATE, 860 + * -FDT_ERR_BADSTRUCTURE, 861 + * -FDT_ERR_BADLAYOUT, 862 + * -FDT_ERR_TRUNCATED, standard meanings 863 + */ 817 864 #define fdt_setprop_string(fdt, nodeoffset, name, str) \ 818 865 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 866 + 867 + /** 868 + * fdt_delprop - delete a property 869 + * @fdt: pointer to the device tree blob 870 + * @nodeoffset: offset of the node whose property to nop 871 + * @name: name of the property to nop 872 + * 873 + * fdt_del_property() will delete the given property. 874 + * 875 + * This function will delete data from the blob, and will therefore 876 + * change the offsets of some existing nodes. 877 + * 878 + * returns: 879 + * 0, on success 880 + * -FDT_ERR_NOTFOUND, node does not have the named property 881 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 882 + * -FDT_ERR_BADLAYOUT, 883 + * -FDT_ERR_BADMAGIC, 884 + * -FDT_ERR_BADVERSION, 885 + * -FDT_ERR_BADSTATE, 886 + * -FDT_ERR_BADSTRUCTURE, 887 + * -FDT_ERR_TRUNCATED, standard meanings 888 + */ 819 889 int fdt_delprop(void *fdt, int nodeoffset, const char *name); 890 + 891 + /** 892 + * fdt_add_subnode_namelen - creates a new node based on substring 893 + * @fdt: pointer to the device tree blob 894 + * @parentoffset: structure block offset of a node 895 + * @name: name of the subnode to locate 896 + * @namelen: number of characters of name to consider 897 + * 898 + * Identical to fdt_add_subnode(), but use only the first namelen 899 + * characters of name as the name of the new node. This is useful for 900 + * creating subnodes based on a portion of a larger string, such as a 901 + * full path. 902 + */ 820 903 int fdt_add_subnode_namelen(void *fdt, int parentoffset, 821 904 const char *name, int namelen); 905 + 906 + /** 907 + * fdt_add_subnode - creates a new node 908 + * @fdt: pointer to the device tree blob 909 + * @parentoffset: structure block offset of a node 910 + * @name: name of the subnode to locate 911 + * 912 + * fdt_add_subnode() creates a new node as a subnode of the node at 913 + * structure block offset parentoffset, with the given name (which 914 + * should include the unit address, if any). 915 + * 916 + * This function will insert data into the blob, and will therefore 917 + * change the offsets of some existing nodes. 918 + 919 + * returns: 920 + * structure block offset of the created nodeequested subnode (>=0), on success 921 + * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 922 + * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag 923 + * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of 924 + * the given name 925 + * -FDT_ERR_NOSPACE, if there is insufficient free space in the 926 + * blob to contain the new node 927 + * -FDT_ERR_NOSPACE 928 + * -FDT_ERR_BADLAYOUT 929 + * -FDT_ERR_BADMAGIC, 930 + * -FDT_ERR_BADVERSION, 931 + * -FDT_ERR_BADSTATE, 932 + * -FDT_ERR_BADSTRUCTURE, 933 + * -FDT_ERR_TRUNCATED, standard meanings. 934 + */ 822 935 int fdt_add_subnode(void *fdt, int parentoffset, const char *name); 936 + 937 + /** 938 + * fdt_del_node - delete a node (subtree) 939 + * @fdt: pointer to the device tree blob 940 + * @nodeoffset: offset of the node to nop 941 + * 942 + * fdt_del_node() will remove the given node, including all its 943 + * subnodes if any, from the blob. 944 + * 945 + * This function will delete data from the blob, and will therefore 946 + * change the offsets of some existing nodes. 947 + * 948 + * returns: 949 + * 0, on success 950 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 951 + * -FDT_ERR_BADLAYOUT, 952 + * -FDT_ERR_BADMAGIC, 953 + * -FDT_ERR_BADVERSION, 954 + * -FDT_ERR_BADSTATE, 955 + * -FDT_ERR_BADSTRUCTURE, 956 + * -FDT_ERR_TRUNCATED, standard meanings 957 + */ 823 958 int fdt_del_node(void *fdt, int nodeoffset); 824 959 825 960 /**********************************************************************/
+15 -9
arch/powerpc/boot/libfdt/libfdt_internal.h
··· 52 52 */ 53 53 #include <fdt.h> 54 54 55 - #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 56 - #define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a))) 55 + #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 56 + #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) 57 57 58 - #define memeq(p, q, n) (memcmp((p), (q), (n)) == 0) 59 - #define streq(p, q) (strcmp((p), (q)) == 0) 58 + #define FDT_CHECK_HEADER(fdt) \ 59 + { \ 60 + int err; \ 61 + if ((err = fdt_check_header(fdt)) != 0) \ 62 + return err; \ 63 + } 60 64 61 65 uint32_t _fdt_next_tag(const void *fdt, int startoffset, int *nextoffset); 66 + int _fdt_check_node_offset(const void *fdt, int offset); 62 67 const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); 63 68 int _fdt_node_end_offset(void *fdt, int nodeoffset); 64 69 65 70 static inline const void *_fdt_offset_ptr(const void *fdt, int offset) 66 71 { 67 - return fdt + fdt_off_dt_struct(fdt) + offset; 72 + return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; 68 73 } 69 74 70 75 static inline void *_fdt_offset_ptr_w(void *fdt, int offset) 71 76 { 72 - return (void *)_fdt_offset_ptr(fdt, offset); 77 + return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); 73 78 } 74 79 75 80 static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) 76 81 { 77 82 const struct fdt_reserve_entry *rsv_table = 78 - fdt + fdt_off_mem_rsvmap(fdt); 83 + (const struct fdt_reserve_entry *) 84 + ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); 79 85 80 86 return rsv_table + n; 81 87 } 82 88 static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) 83 89 { 84 - return (void *)_fdt_mem_rsv(fdt, n); 90 + return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); 85 91 } 86 92 87 - #define SW_MAGIC (~FDT_MAGIC) 93 + #define FDT_SW_MAGIC (~FDT_MAGIC) 88 94 89 95 #endif /* _LIBFDT_INTERNAL_H */
+1
arch/powerpc/boot/libfdt_env.h
··· 6 6 7 7 typedef u32 uint32_t; 8 8 typedef u64 uint64_t; 9 + typedef unsigned long uintptr_t; 9 10 10 11 #define fdt16_to_cpu(x) (x) 11 12 #define cpu_to_fdt16(x) (x)