struct boot_info *dt_from_source(const char *fname) { the_boot_info = NULL; push_input_file(fname); if (yyparse() != 0) return NULL; fill_fullpaths(the_boot_info->dt, ""); return the_boot_info; }
static void fill_fullpaths(struct node *tree, const char *prefix) { struct node *child; const char *unit; tree->fullpath = join_path(prefix, tree->name); unit = strchr(tree->name, '@'); if (unit) tree->basenamelen = unit - tree->name; else tree->basenamelen = strlen(tree->name); for_each_child(tree, child) fill_fullpaths(child, tree->fullpath); }
int main(int argc, char *argv[]) { struct boot_info *bi; const char *inform = "dts"; const char *outform = "dts"; const char *outname = "-"; const char *depname = NULL; int force = 0, sort = 0; const char *arg; int opt; FILE *outf = NULL; int outversion = DEFAULT_FDT_VERSION; long long cmdline_boot_cpuid = -1; quiet = 0; reservenum = 0; minsize = 0; padsize = 0; while ((opt = util_getopt_long()) != EOF) { switch (opt) { case 'I': inform = optarg; break; case 'O': outform = optarg; break; case 'o': outname = optarg; break; case 'V': outversion = strtol(optarg, NULL, 0); break; case 'd': depname = optarg; break; case 'R': reservenum = strtol(optarg, NULL, 0); break; case 'S': minsize = strtol(optarg, NULL, 0); break; case 'p': padsize = strtol(optarg, NULL, 0); break; case 'f': force = 1; break; case 'q': quiet++; break; case 'b': cmdline_boot_cpuid = strtoll(optarg, NULL, 0); break; case 'i': srcfile_add_search_path(optarg); break; case 'v': util_version(); case 'H': if (streq(optarg, "legacy")) phandle_format = PHANDLE_LEGACY; else if (streq(optarg, "epapr")) phandle_format = PHANDLE_EPAPR; else if (streq(optarg, "both")) phandle_format = PHANDLE_BOTH; else die("Invalid argument \"%s\" to -H option\n", optarg); break; case 's': sort = 1; break; case 'W': parse_checks_option(true, false, optarg); break; case 'E': parse_checks_option(false, true, optarg); break; case '@': symbol_fixup_support = 1; break; case 'h': usage(NULL); default: usage("unknown option"); } } if (argc > (optind+1)) usage("missing files"); else if (argc < (optind+1)) arg = "-"; else arg = argv[optind]; /* minsize and padsize are mutually exclusive */ if (minsize && padsize) die("Can't set both -p and -S\n"); if (depname) { depfile = fopen(depname, "w"); if (!depfile) die("Couldn't open dependency file %s: %s\n", depname, strerror(errno)); fprintf(depfile, "%s:", outname); } if (streq(inform, "dts")) bi = dt_from_source(arg); else if (streq(inform, "fs")) bi = dt_from_fs(arg); else if(streq(inform, "dtb")) bi = dt_from_blob(arg); else die("Unknown input format \"%s\"\n", inform); if (depfile) { fputc('\n', depfile); fclose(depfile); } if (cmdline_boot_cpuid != -1) bi->boot_cpuid_phys = cmdline_boot_cpuid; fill_fullpaths(bi->dt, ""); process_checks(force, bi); if (sort) sort_tree(bi); if (streq(outname, "-")) { outf = stdout; } else { outf = fopen(outname, "w"); if (! outf) die("Couldn't open output file %s: %s\n", outname, strerror(errno)); } if (streq(outform, "dts")) { dt_to_source(outf, bi); } else if (streq(outform, "dtb")) { dt_to_blob(outf, bi, outversion); } else if (streq(outform, "asm")) { dt_to_asm(outf, bi, outversion); } else if (streq(outform, "null")) { /* do nothing */ } else { die("Unknown output format \"%s\"\n", outform); } exit(0); }
int main(int argc, char *argv[]) { struct dt_info *dti; const char *inform = NULL; const char *outform = NULL; const char *outname = "-"; const char *depname = NULL; bool force = false, sort = false; const char *arg; int opt; FILE *outf = NULL; int outversion = DEFAULT_FDT_VERSION; long long cmdline_boot_cpuid = -1; quiet = 0; reservenum = 0; minsize = 0; padsize = 0; alignsize = 0; while ((opt = util_getopt_long()) != EOF) { switch (opt) { case 'I': inform = optarg; break; case 'O': outform = optarg; break; case 'o': outname = optarg; break; case 'V': outversion = strtol(optarg, NULL, 0); break; case 'd': depname = optarg; break; case 'R': reservenum = strtol(optarg, NULL, 0); break; case 'S': minsize = strtol(optarg, NULL, 0); break; case 'p': padsize = strtol(optarg, NULL, 0); break; case 'a': alignsize = strtol(optarg, NULL, 0); if (!is_power_of_2(alignsize)) die("Invalid argument \"%d\" to -a option\n", alignsize); break; case 'f': force = true; break; case 'q': quiet++; break; case 'b': cmdline_boot_cpuid = strtoll(optarg, NULL, 0); break; case 'i': srcfile_add_search_path(optarg); break; case 'v': util_version(); case 'H': if (streq(optarg, "legacy")) phandle_format = PHANDLE_LEGACY; else if (streq(optarg, "epapr")) phandle_format = PHANDLE_EPAPR; else if (streq(optarg, "both")) phandle_format = PHANDLE_BOTH; else die("Invalid argument \"%s\" to -H option\n", optarg); break; case 's': sort = true; break; case 'W': parse_checks_option(true, false, optarg); break; case 'E': parse_checks_option(false, true, optarg); break; case '@': generate_symbols = 1; break; case 'A': auto_label_aliases = 1; break; case 'h': usage(NULL); default: usage("unknown option"); } } if (argc > (optind+1)) usage("missing files"); else if (argc < (optind+1)) arg = "-"; else arg = argv[optind]; /* minsize and padsize are mutually exclusive */ if (minsize && padsize) die("Can't set both -p and -S\n"); if (depname) { depfile = fopen(depname, "w"); if (!depfile) die("Couldn't open dependency file %s: %s\n", depname, strerror(errno)); fprintf(depfile, "%s:", outname); } if (inform == NULL) inform = guess_input_format(arg, "dts"); if (outform == NULL) { outform = guess_type_by_name(outname, NULL); if (outform == NULL) { if (streq(inform, "dts")) outform = "dtb"; else outform = "dts"; } } if (streq(inform, "dts")) dti = dt_from_source(arg); else if (streq(inform, "fs")) dti = dt_from_fs(arg); else if(streq(inform, "dtb")) dti = dt_from_blob(arg); else die("Unknown input format \"%s\"\n", inform); dti->outname = outname; if (depfile) { fputc('\n', depfile); fclose(depfile); } if (cmdline_boot_cpuid != -1) dti->boot_cpuid_phys = cmdline_boot_cpuid; fill_fullpaths(dti->dt, ""); process_checks(force, dti); /* on a plugin, generate by default */ if (dti->dtsflags & DTSF_PLUGIN) { generate_fixups = 1; } if (auto_label_aliases) generate_label_tree(dti, "aliases", false); if (generate_symbols) generate_label_tree(dti, "__symbols__", true); if (generate_fixups) { generate_fixups_tree(dti, "__fixups__"); generate_local_fixups_tree(dti, "__local_fixups__"); } if (sort) sort_tree(dti); if (streq(outname, "-")) { outf = stdout; } else { outf = fopen(outname, "wb"); if (! outf) die("Couldn't open output file %s: %s\n", outname, strerror(errno)); } if (streq(outform, "dts")) { dt_to_source(outf, dti); } else if (streq(outform, "dtb")) { dt_to_blob(outf, dti, outversion); } else if (streq(outform, "asm")) { dt_to_asm(outf, dti, outversion); } else if (streq(outform, "null")) { /* do nothing */ } else { die("Unknown output format \"%s\"\n", outform); } exit(0); }
int main(int argc, char *argv[]) { struct boot_info *bi; const char *inform = "dts"; const char *outform = "dts"; const char *outname = "-"; const char *depname = NULL; int force = 0, sort = 0; const char *arg; int opt; FILE *outf = NULL; int outversion = DEFAULT_FDT_VERSION; long long cmdline_boot_cpuid = -1; quiet = 0; reservenum = 0; minsize = 0; padsize = 0; while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fcqb:vH:s")) != EOF) { switch (opt) { case 'I': inform = optarg; break; case 'O': outform = optarg; break; case 'o': outname = optarg; break; case 'V': outversion = strtol(optarg, NULL, 0); break; case 'd': depname = optarg; break; case 'R': reservenum = strtol(optarg, NULL, 0); break; case 'S': minsize = strtol(optarg, NULL, 0); break; case 'p': padsize = strtol(optarg, NULL, 0); break; case 'f': force = 1; break; case 'q': quiet++; break; case 'b': cmdline_boot_cpuid = strtoll(optarg, NULL, 0); break; case 'v': printf("Version: %s\n", DTC_VERSION); exit(0); case 'H': if (streq(optarg, "legacy")) phandle_format = PHANDLE_LEGACY; else if (streq(optarg, "epapr")) phandle_format = PHANDLE_EPAPR; else if (streq(optarg, "both")) phandle_format = PHANDLE_BOTH; else die("Invalid argument \"%s\" to -H option\n", optarg); break; case 's': sort = 1; break; case 'h': default: usage(); } } if (argc > (optind+1)) usage(); else if (argc < (optind+1)) arg = "-"; else arg = argv[optind]; if (minsize && padsize) die("Can't set both -p and -S\n"); if (minsize) fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n"); fprintf(stderr, "DTC: %s->%s on file \"%s\"\n", inform, outform, arg); if (depname) { depfile = fopen(depname, "w"); if (!depfile) die("Couldn't open dependency file %s: %s\n", depname, strerror(errno)); fprintf(depfile, "%s:", outname); } if (streq(inform, "dts")) bi = dt_from_source(arg); else if (streq(inform, "fs")) bi = dt_from_fs(arg); else if(streq(inform, "dtb")) bi = dt_from_blob(arg); else die("Unknown input format \"%s\"\n", inform); if (depfile) { fputc('\n', depfile); fclose(depfile); } if (cmdline_boot_cpuid != -1) bi->boot_cpuid_phys = cmdline_boot_cpuid; fill_fullpaths(bi->dt, ""); process_checks(force, bi); if (sort) sort_tree(bi); if (streq(outname, "-")) { outf = stdout; } else { outf = fopen(outname, "w"); if (! outf) die("Couldn't open output file %s: %s\n", outname, strerror(errno)); } if (streq(outform, "dts")) { dt_to_source(outf, bi); } else if (streq(outform, "dtb")) { dt_to_blob(outf, bi, outversion); } else if (streq(outform, "asm")) { dt_to_asm(outf, bi, outversion); } else if (streq(outform, "null")) { } else { die("Unknown output format \"%s\"\n", outform); } exit(0); }
int main(int argc, char *argv[]) { struct boot_info *bi; const char *endianstr = "be"; const char *inform = "dts"; const char *outform = "dts"; const char *outname = "-"; int force = 0, check = 0; const char *arg; int opt; FILE *outf = NULL; int outversion = DEFAULT_FDT_VERSION; long long cmdline_boot_cpuid = -1; quiet = 0; reservenum = 0; minsize = 0; padsize = 0; while ((opt = getopt(argc, argv, "hE:I:O:o:V:R:S:p:fcqb:v")) != EOF) { switch (opt) { case 'E': endianstr = optarg; break; case 'I': inform = optarg; break; case 'O': outform = optarg; break; case 'o': outname = optarg; break; case 'V': outversion = strtol(optarg, NULL, 0); break; case 'R': reservenum = strtol(optarg, NULL, 0); break; case 'S': minsize = strtol(optarg, NULL, 0); break; case 'p': padsize = strtol(optarg, NULL, 0); break; case 'f': force = 1; break; case 'c': check = 1; break; case 'q': quiet++; break; case 'b': cmdline_boot_cpuid = strtoll(optarg, NULL, 0); break; case 'v': printf("Version: %s\n", DTC_VERSION); exit(0); case 'h': default: usage(); } } if (argc > (optind+1)) usage(); else if (argc < (optind+1)) arg = "-"; else arg = argv[optind]; if (streq(endianstr, "le")) little_endian = 1; else little_endian = 0; /* minsize and padsize are mutually exclusive */ if (minsize && padsize) die("Can't set both -p and -S\n"); fprintf(stderr, "DTC: %s->%s on file \"%s\"\n", inform, outform, arg); if (streq(inform, "dts")) bi = dt_from_source(arg); else if (streq(inform, "fs")) bi = dt_from_fs(arg); else if(streq(inform, "dtb")) bi = dt_from_blob(arg); else die("Unknown input format \"%s\"\n", inform); if (cmdline_boot_cpuid != -1) bi->boot_cpuid_phys = cmdline_boot_cpuid; fill_fullpaths(bi->dt, ""); process_checks(force, bi); if (streq(outname, "-")) { outf = stdout; } else { outf = fopen(outname, "w"); if (! outf) die("Couldn't open output file %s: %s\n", outname, strerror(errno)); } if (streq(outform, "dts")) { dt_to_source(outf, bi); } else if (streq(outform, "dtb")) { dt_to_blob(outf, bi, outversion); } else if (streq(outform, "asm")) { dt_to_asm(outf, bi, outversion); } else if (streq(outform, "null")) { /* do nothing */ } else { die("Unknown output format \"%s\"\n", outform); } exit(0); }