David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
| 3 | * |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of the |
| 8 | * License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 | * USA |
| 19 | */ |
| 20 | |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 21 | #include <sys/stat.h> |
| 22 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 23 | #include "dtc.h" |
| 24 | #include "srcpos.h" |
| 25 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 26 | /* |
| 27 | * Command line options |
| 28 | */ |
| 29 | int quiet; /* Level of quietness */ |
| 30 | int reservenum; /* Number of memory reservation slots */ |
| 31 | int minsize; /* Minimum blob size */ |
| 32 | int padsize; /* Additional padding to blob */ |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 33 | int alignsize; /* Additional padding to blob accroding to the alignsize */ |
Rob Herring | 4201d05 | 2017-10-03 11:37:04 -0500 | [diff] [blame] | 34 | int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties */ |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 35 | int generate_symbols; /* enable symbols & fixup support */ |
| 36 | int generate_fixups; /* suppress generation of fixups on symbol support */ |
| 37 | int auto_label_aliases; /* auto generate labels -> aliases */ |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 38 | int annotate; /* Level of annotation: 1 for input source location |
| 39 | >1 for full input source location. */ |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 40 | |
| 41 | static int is_power_of_2(int x) |
| 42 | { |
| 43 | return (x > 0) && ((x & (x - 1)) == 0); |
| 44 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 45 | |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 46 | static void fill_fullpaths(struct node *tree, const char *prefix) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 47 | { |
| 48 | struct node *child; |
| 49 | const char *unit; |
| 50 | |
| 51 | tree->fullpath = join_path(prefix, tree->name); |
| 52 | |
| 53 | unit = strchr(tree->name, '@'); |
| 54 | if (unit) |
| 55 | tree->basenamelen = unit - tree->name; |
| 56 | else |
| 57 | tree->basenamelen = strlen(tree->name); |
| 58 | |
| 59 | for_each_child(tree, child) |
| 60 | fill_fullpaths(child, tree->fullpath); |
| 61 | } |
| 62 | |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 63 | /* Usage related data. */ |
| 64 | static const char usage_synopsis[] = "dtc [options] <input file>"; |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 65 | static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv"; |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 66 | static struct option const usage_long_opts[] = { |
| 67 | {"quiet", no_argument, NULL, 'q'}, |
| 68 | {"in-format", a_argument, NULL, 'I'}, |
| 69 | {"out", a_argument, NULL, 'o'}, |
| 70 | {"out-format", a_argument, NULL, 'O'}, |
| 71 | {"out-version", a_argument, NULL, 'V'}, |
| 72 | {"out-dependency", a_argument, NULL, 'd'}, |
| 73 | {"reserve", a_argument, NULL, 'R'}, |
| 74 | {"space", a_argument, NULL, 'S'}, |
| 75 | {"pad", a_argument, NULL, 'p'}, |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 76 | {"align", a_argument, NULL, 'a'}, |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 77 | {"boot-cpu", a_argument, NULL, 'b'}, |
| 78 | {"force", no_argument, NULL, 'f'}, |
| 79 | {"include", a_argument, NULL, 'i'}, |
| 80 | {"sort", no_argument, NULL, 's'}, |
| 81 | {"phandle", a_argument, NULL, 'H'}, |
| 82 | {"warning", a_argument, NULL, 'W'}, |
| 83 | {"error", a_argument, NULL, 'E'}, |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 84 | {"symbols", no_argument, NULL, '@'}, |
| 85 | {"auto-alias", no_argument, NULL, 'A'}, |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 86 | {"annotate", no_argument, NULL, 'T'}, |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 87 | {"help", no_argument, NULL, 'h'}, |
| 88 | {"version", no_argument, NULL, 'v'}, |
| 89 | {NULL, no_argument, NULL, 0x0}, |
| 90 | }; |
| 91 | static const char * const usage_opts_help[] = { |
| 92 | "\n\tQuiet: -q suppress warnings, -qq errors, -qqq all", |
| 93 | "\n\tInput formats are:\n" |
| 94 | "\t\tdts - device tree source text\n" |
| 95 | "\t\tdtb - device tree blob\n" |
| 96 | "\t\tfs - /proc/device-tree style directory", |
| 97 | "\n\tOutput file", |
| 98 | "\n\tOutput formats are:\n" |
| 99 | "\t\tdts - device tree source text\n" |
| 100 | "\t\tdtb - device tree blob\n" |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 101 | #ifndef NO_YAML |
| 102 | "\t\tyaml - device tree encoded as YAML\n" |
| 103 | #endif |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 104 | "\t\tasm - assembler source", |
Rob Herring | 9130ba8 | 2018-02-27 17:40:38 -0600 | [diff] [blame] | 105 | "\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)", |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 106 | "\n\tOutput dependency file", |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 107 | "\n\tMake space for <number> reserve map entries (for dtb and asm output)", |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 108 | "\n\tMake the blob at least <bytes> long (extra space)", |
| 109 | "\n\tAdd padding to the blob of <bytes> long (extra space)", |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 110 | "\n\tMake the blob align to the <bytes> (extra space)", |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 111 | "\n\tSet the physical boot cpu", |
| 112 | "\n\tTry to produce output even if the input tree has errors", |
| 113 | "\n\tAdd a path to search for include files", |
| 114 | "\n\tSort nodes and properties before outputting (useful for comparing trees)", |
| 115 | "\n\tValid phandle formats are:\n" |
| 116 | "\t\tlegacy - \"linux,phandle\" properties only\n" |
| 117 | "\t\tepapr - \"phandle\" properties only\n" |
| 118 | "\t\tboth - Both \"linux,phandle\" and \"phandle\" properties", |
| 119 | "\n\tEnable/disable warnings (prefix with \"no-\")", |
| 120 | "\n\tEnable/disable errors (prefix with \"no-\")", |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 121 | "\n\tEnable generation of symbols", |
| 122 | "\n\tEnable auto-alias of labels", |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 123 | "\n\tAnnotate output .dts with input source file and line (-T -T for more details)", |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 124 | "\n\tPrint this help and exit", |
| 125 | "\n\tPrint version and exit", |
| 126 | NULL, |
| 127 | }; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 128 | |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 129 | static const char *guess_type_by_name(const char *fname, const char *fallback) |
| 130 | { |
| 131 | const char *s; |
| 132 | |
| 133 | s = strrchr(fname, '.'); |
| 134 | if (s == NULL) |
| 135 | return fallback; |
| 136 | if (!strcasecmp(s, ".dts")) |
| 137 | return "dts"; |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 138 | if (!strcasecmp(s, ".yaml")) |
| 139 | return "yaml"; |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 140 | if (!strcasecmp(s, ".dtb")) |
| 141 | return "dtb"; |
| 142 | return fallback; |
| 143 | } |
| 144 | |
| 145 | static const char *guess_input_format(const char *fname, const char *fallback) |
| 146 | { |
| 147 | struct stat statbuf; |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 148 | fdt32_t magic; |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 149 | FILE *f; |
| 150 | |
| 151 | if (stat(fname, &statbuf) != 0) |
| 152 | return fallback; |
| 153 | |
| 154 | if (S_ISDIR(statbuf.st_mode)) |
| 155 | return "fs"; |
| 156 | |
| 157 | if (!S_ISREG(statbuf.st_mode)) |
| 158 | return fallback; |
| 159 | |
| 160 | f = fopen(fname, "r"); |
| 161 | if (f == NULL) |
| 162 | return fallback; |
| 163 | if (fread(&magic, 4, 1, f) != 1) { |
| 164 | fclose(f); |
| 165 | return fallback; |
| 166 | } |
| 167 | fclose(f); |
| 168 | |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 169 | if (fdt32_to_cpu(magic) == FDT_MAGIC) |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 170 | return "dtb"; |
| 171 | |
| 172 | return guess_type_by_name(fname, fallback); |
| 173 | } |
| 174 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 175 | int main(int argc, char *argv[]) |
| 176 | { |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 177 | struct dt_info *dti; |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 178 | const char *inform = NULL; |
| 179 | const char *outform = NULL; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 180 | const char *outname = "-"; |
Stephen Warren | 136ec20 | 2012-01-10 17:27:52 -0700 | [diff] [blame] | 181 | const char *depname = NULL; |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 182 | bool force = false, sort = false; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 183 | const char *arg; |
| 184 | int opt; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 185 | FILE *outf = NULL; |
| 186 | int outversion = DEFAULT_FDT_VERSION; |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 187 | long long cmdline_boot_cpuid = -1; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 188 | |
| 189 | quiet = 0; |
| 190 | reservenum = 0; |
| 191 | minsize = 0; |
| 192 | padsize = 0; |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 193 | alignsize = 0; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 194 | |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 195 | while ((opt = util_getopt_long()) != EOF) { |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 196 | switch (opt) { |
| 197 | case 'I': |
| 198 | inform = optarg; |
| 199 | break; |
| 200 | case 'O': |
| 201 | outform = optarg; |
| 202 | break; |
| 203 | case 'o': |
| 204 | outname = optarg; |
| 205 | break; |
| 206 | case 'V': |
| 207 | outversion = strtol(optarg, NULL, 0); |
| 208 | break; |
Stephen Warren | 136ec20 | 2012-01-10 17:27:52 -0700 | [diff] [blame] | 209 | case 'd': |
| 210 | depname = optarg; |
| 211 | break; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 212 | case 'R': |
| 213 | reservenum = strtol(optarg, NULL, 0); |
| 214 | break; |
| 215 | case 'S': |
| 216 | minsize = strtol(optarg, NULL, 0); |
| 217 | break; |
| 218 | case 'p': |
| 219 | padsize = strtol(optarg, NULL, 0); |
| 220 | break; |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 221 | case 'a': |
| 222 | alignsize = strtol(optarg, NULL, 0); |
| 223 | if (!is_power_of_2(alignsize)) |
| 224 | die("Invalid argument \"%d\" to -a option\n", |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 225 | alignsize); |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 226 | break; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 227 | case 'f': |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 228 | force = true; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 229 | break; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 230 | case 'q': |
| 231 | quiet++; |
| 232 | break; |
| 233 | case 'b': |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 234 | cmdline_boot_cpuid = strtoll(optarg, NULL, 0); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 235 | break; |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 236 | case 'i': |
| 237 | srcfile_add_search_path(optarg); |
| 238 | break; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 239 | case 'v': |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 240 | util_version(); |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 241 | case 'H': |
| 242 | if (streq(optarg, "legacy")) |
| 243 | phandle_format = PHANDLE_LEGACY; |
| 244 | else if (streq(optarg, "epapr")) |
| 245 | phandle_format = PHANDLE_EPAPR; |
| 246 | else if (streq(optarg, "both")) |
| 247 | phandle_format = PHANDLE_BOTH; |
| 248 | else |
| 249 | die("Invalid argument \"%s\" to -H option\n", |
| 250 | optarg); |
| 251 | break; |
| 252 | |
| 253 | case 's': |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 254 | sort = true; |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 255 | break; |
| 256 | |
Stephen Warren | cd29672 | 2012-09-28 21:25:59 +0000 | [diff] [blame] | 257 | case 'W': |
| 258 | parse_checks_option(true, false, optarg); |
| 259 | break; |
| 260 | |
| 261 | case 'E': |
| 262 | parse_checks_option(false, true, optarg); |
| 263 | break; |
| 264 | |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 265 | case '@': |
| 266 | generate_symbols = 1; |
| 267 | break; |
| 268 | case 'A': |
| 269 | auto_label_aliases = 1; |
| 270 | break; |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 271 | case 'T': |
| 272 | annotate++; |
| 273 | break; |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 274 | |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 275 | case 'h': |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 276 | usage(NULL); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 277 | default: |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 278 | usage("unknown option"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | if (argc > (optind+1)) |
Grant Likely | 73ab39b | 2014-01-21 12:54:49 +0000 | [diff] [blame] | 283 | usage("missing files"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 284 | else if (argc < (optind+1)) |
| 285 | arg = "-"; |
| 286 | else |
| 287 | arg = argv[optind]; |
| 288 | |
| 289 | /* minsize and padsize are mutually exclusive */ |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 290 | if (minsize && padsize) |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 291 | die("Can't set both -p and -S\n"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 292 | |
Stephen Warren | 136ec20 | 2012-01-10 17:27:52 -0700 | [diff] [blame] | 293 | if (depname) { |
| 294 | depfile = fopen(depname, "w"); |
| 295 | if (!depfile) |
| 296 | die("Couldn't open dependency file %s: %s\n", depname, |
| 297 | strerror(errno)); |
| 298 | fprintf(depfile, "%s:", outname); |
| 299 | } |
| 300 | |
Rob Herring | 91feabc | 2016-01-26 09:04:11 -0600 | [diff] [blame] | 301 | if (inform == NULL) |
| 302 | inform = guess_input_format(arg, "dts"); |
| 303 | if (outform == NULL) { |
| 304 | outform = guess_type_by_name(outname, NULL); |
| 305 | if (outform == NULL) { |
| 306 | if (streq(inform, "dts")) |
| 307 | outform = "dtb"; |
| 308 | else |
| 309 | outform = "dts"; |
| 310 | } |
| 311 | } |
Rob Herring | c2e7075 | 2018-11-28 18:37:35 -0600 | [diff] [blame] | 312 | if (annotate && (!streq(inform, "dts") || !streq(outform, "dts"))) |
| 313 | die("--annotate requires -I dts -O dts\n"); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 314 | if (streq(inform, "dts")) |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 315 | dti = dt_from_source(arg); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 316 | else if (streq(inform, "fs")) |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 317 | dti = dt_from_fs(arg); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 318 | else if(streq(inform, "dtb")) |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 319 | dti = dt_from_blob(arg); |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 320 | else |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 321 | die("Unknown input format \"%s\"\n", inform); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 322 | |
Rob Herring | 89d1231 | 2017-03-21 09:01:08 -0500 | [diff] [blame] | 323 | dti->outname = outname; |
| 324 | |
Stephen Warren | 136ec20 | 2012-01-10 17:27:52 -0700 | [diff] [blame] | 325 | if (depfile) { |
| 326 | fputc('\n', depfile); |
| 327 | fclose(depfile); |
| 328 | } |
| 329 | |
David Gibson | ed95d74 | 2008-08-07 12:24:17 +1000 | [diff] [blame] | 330 | if (cmdline_boot_cpuid != -1) |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 331 | dti->boot_cpuid_phys = cmdline_boot_cpuid; |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 332 | |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 333 | fill_fullpaths(dti->dt, ""); |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 334 | |
| 335 | /* on a plugin, generate by default */ |
| 336 | if (dti->dtsflags & DTSF_PLUGIN) { |
| 337 | generate_fixups = 1; |
| 338 | } |
| 339 | |
Rob Herring | 9130ba8 | 2018-02-27 17:40:38 -0600 | [diff] [blame] | 340 | process_checks(force, dti); |
| 341 | |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 342 | if (auto_label_aliases) |
| 343 | generate_label_tree(dti, "aliases", false); |
| 344 | |
| 345 | if (generate_symbols) |
| 346 | generate_label_tree(dti, "__symbols__", true); |
| 347 | |
| 348 | if (generate_fixups) { |
| 349 | generate_fixups_tree(dti, "__fixups__"); |
| 350 | generate_local_fixups_tree(dti, "__local_fixups__"); |
| 351 | } |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 352 | |
John Bonesio | 658f29a | 2010-11-17 15:28:20 -0800 | [diff] [blame] | 353 | if (sort) |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 354 | sort_tree(dti); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 355 | |
| 356 | if (streq(outname, "-")) { |
| 357 | outf = stdout; |
| 358 | } else { |
Rob Herring | 4760597 | 2015-04-29 16:00:05 -0500 | [diff] [blame] | 359 | outf = fopen(outname, "wb"); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 360 | if (! outf) |
| 361 | die("Couldn't open output file %s: %s\n", |
| 362 | outname, strerror(errno)); |
| 363 | } |
| 364 | |
| 365 | if (streq(outform, "dts")) { |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 366 | dt_to_source(outf, dti); |
Rob Herring | f858927 | 2018-09-13 08:59:25 -0500 | [diff] [blame] | 367 | #ifndef NO_YAML |
| 368 | } else if (streq(outform, "yaml")) { |
| 369 | if (!streq(inform, "dts")) |
| 370 | die("YAML output format requires dts input format\n"); |
| 371 | dt_to_yaml(outf, dti); |
| 372 | #endif |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 373 | } else if (streq(outform, "dtb")) { |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 374 | dt_to_blob(outf, dti, outversion); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 375 | } else if (streq(outform, "asm")) { |
Rob Herring | 6f05afc | 2017-01-04 10:45:20 -0600 | [diff] [blame] | 376 | dt_to_asm(outf, dti, outversion); |
David Gibson | a4da2e3 | 2007-12-18 15:06:42 +1100 | [diff] [blame] | 377 | } else if (streq(outform, "null")) { |
| 378 | /* do nothing */ |
| 379 | } else { |
| 380 | die("Unknown output format \"%s\"\n", outform); |
| 381 | } |
| 382 | |
| 383 | exit(0); |
| 384 | } |