| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * (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 | 4 | */ |
|---|
| 20 | 5 | |
|---|
| 21 | 6 | #include <sys/stat.h> |
|---|
| .. | .. |
|---|
| 35 | 20 | int generate_symbols; /* enable symbols & fixup support */ |
|---|
| 36 | 21 | int generate_fixups; /* suppress generation of fixups on symbol support */ |
|---|
| 37 | 22 | int auto_label_aliases; /* auto generate labels -> aliases */ |
|---|
| 23 | +int annotate; /* Level of annotation: 1 for input source location |
|---|
| 24 | + >1 for full input source location. */ |
|---|
| 38 | 25 | |
|---|
| 39 | 26 | static int is_power_of_2(int x) |
|---|
| 40 | 27 | { |
|---|
| .. | .. |
|---|
| 60 | 47 | |
|---|
| 61 | 48 | /* Usage related data. */ |
|---|
| 62 | 49 | static const char usage_synopsis[] = "dtc [options] <input file>"; |
|---|
| 63 | | -static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv"; |
|---|
| 50 | +static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv"; |
|---|
| 64 | 51 | static struct option const usage_long_opts[] = { |
|---|
| 65 | 52 | {"quiet", no_argument, NULL, 'q'}, |
|---|
| 66 | 53 | {"in-format", a_argument, NULL, 'I'}, |
|---|
| .. | .. |
|---|
| 81 | 68 | {"error", a_argument, NULL, 'E'}, |
|---|
| 82 | 69 | {"symbols", no_argument, NULL, '@'}, |
|---|
| 83 | 70 | {"auto-alias", no_argument, NULL, 'A'}, |
|---|
| 71 | + {"annotate", no_argument, NULL, 'T'}, |
|---|
| 84 | 72 | {"help", no_argument, NULL, 'h'}, |
|---|
| 85 | 73 | {"version", no_argument, NULL, 'v'}, |
|---|
| 86 | 74 | {NULL, no_argument, NULL, 0x0}, |
|---|
| .. | .. |
|---|
| 95 | 83 | "\n\tOutput formats are:\n" |
|---|
| 96 | 84 | "\t\tdts - device tree source text\n" |
|---|
| 97 | 85 | "\t\tdtb - device tree blob\n" |
|---|
| 86 | +#ifndef NO_YAML |
|---|
| 87 | + "\t\tyaml - device tree encoded as YAML\n" |
|---|
| 88 | +#endif |
|---|
| 98 | 89 | "\t\tasm - assembler source", |
|---|
| 99 | 90 | "\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)", |
|---|
| 100 | 91 | "\n\tOutput dependency file", |
|---|
| .. | .. |
|---|
| 114 | 105 | "\n\tEnable/disable errors (prefix with \"no-\")", |
|---|
| 115 | 106 | "\n\tEnable generation of symbols", |
|---|
| 116 | 107 | "\n\tEnable auto-alias of labels", |
|---|
| 108 | + "\n\tAnnotate output .dts with input source file and line (-T -T for more details)", |
|---|
| 117 | 109 | "\n\tPrint this help and exit", |
|---|
| 118 | 110 | "\n\tPrint version and exit", |
|---|
| 119 | 111 | NULL, |
|---|
| .. | .. |
|---|
| 128 | 120 | return fallback; |
|---|
| 129 | 121 | if (!strcasecmp(s, ".dts")) |
|---|
| 130 | 122 | return "dts"; |
|---|
| 123 | + if (!strcasecmp(s, ".yaml")) |
|---|
| 124 | + return "yaml"; |
|---|
| 131 | 125 | if (!strcasecmp(s, ".dtb")) |
|---|
| 132 | 126 | return "dtb"; |
|---|
| 133 | 127 | return fallback; |
|---|
| .. | .. |
|---|
| 259 | 253 | case 'A': |
|---|
| 260 | 254 | auto_label_aliases = 1; |
|---|
| 261 | 255 | break; |
|---|
| 256 | + case 'T': |
|---|
| 257 | + annotate++; |
|---|
| 258 | + break; |
|---|
| 262 | 259 | |
|---|
| 263 | 260 | case 'h': |
|---|
| 264 | 261 | usage(NULL); |
|---|
| .. | .. |
|---|
| 297 | 294 | outform = "dts"; |
|---|
| 298 | 295 | } |
|---|
| 299 | 296 | } |
|---|
| 297 | + if (annotate && (!streq(inform, "dts") || !streq(outform, "dts"))) |
|---|
| 298 | + die("--annotate requires -I dts -O dts\n"); |
|---|
| 300 | 299 | if (streq(inform, "dts")) |
|---|
| 301 | 300 | dti = dt_from_source(arg); |
|---|
| 302 | 301 | else if (streq(inform, "fs")) |
|---|
| .. | .. |
|---|
| 350 | 349 | |
|---|
| 351 | 350 | if (streq(outform, "dts")) { |
|---|
| 352 | 351 | dt_to_source(outf, dti); |
|---|
| 352 | +#ifndef NO_YAML |
|---|
| 353 | + } else if (streq(outform, "yaml")) { |
|---|
| 354 | + if (!streq(inform, "dts")) |
|---|
| 355 | + die("YAML output format requires dts input format\n"); |
|---|
| 356 | + dt_to_yaml(outf, dti); |
|---|
| 357 | +#endif |
|---|
| 353 | 358 | } else if (streq(outform, "dtb")) { |
|---|
| 354 | 359 | dt_to_blob(outf, dti, outversion); |
|---|
| 355 | 360 | } else if (streq(outform, "asm")) { |
|---|