hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/scripts/dtc/dtc.c
....@@ -1,21 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * (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
194 */
205
216 #include <sys/stat.h>
....@@ -35,6 +20,8 @@
3520 int generate_symbols; /* enable symbols & fixup support */
3621 int generate_fixups; /* suppress generation of fixups on symbol support */
3722 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. */
3825
3926 static int is_power_of_2(int x)
4027 {
....@@ -60,7 +47,7 @@
6047
6148 /* Usage related data. */
6249 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";
6451 static struct option const usage_long_opts[] = {
6552 {"quiet", no_argument, NULL, 'q'},
6653 {"in-format", a_argument, NULL, 'I'},
....@@ -81,6 +68,7 @@
8168 {"error", a_argument, NULL, 'E'},
8269 {"symbols", no_argument, NULL, '@'},
8370 {"auto-alias", no_argument, NULL, 'A'},
71
+ {"annotate", no_argument, NULL, 'T'},
8472 {"help", no_argument, NULL, 'h'},
8573 {"version", no_argument, NULL, 'v'},
8674 {NULL, no_argument, NULL, 0x0},
....@@ -95,6 +83,9 @@
9583 "\n\tOutput formats are:\n"
9684 "\t\tdts - device tree source text\n"
9785 "\t\tdtb - device tree blob\n"
86
+#ifndef NO_YAML
87
+ "\t\tyaml - device tree encoded as YAML\n"
88
+#endif
9889 "\t\tasm - assembler source",
9990 "\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
10091 "\n\tOutput dependency file",
....@@ -114,6 +105,7 @@
114105 "\n\tEnable/disable errors (prefix with \"no-\")",
115106 "\n\tEnable generation of symbols",
116107 "\n\tEnable auto-alias of labels",
108
+ "\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
117109 "\n\tPrint this help and exit",
118110 "\n\tPrint version and exit",
119111 NULL,
....@@ -128,6 +120,8 @@
128120 return fallback;
129121 if (!strcasecmp(s, ".dts"))
130122 return "dts";
123
+ if (!strcasecmp(s, ".yaml"))
124
+ return "yaml";
131125 if (!strcasecmp(s, ".dtb"))
132126 return "dtb";
133127 return fallback;
....@@ -259,6 +253,9 @@
259253 case 'A':
260254 auto_label_aliases = 1;
261255 break;
256
+ case 'T':
257
+ annotate++;
258
+ break;
262259
263260 case 'h':
264261 usage(NULL);
....@@ -297,6 +294,8 @@
297294 outform = "dts";
298295 }
299296 }
297
+ if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
298
+ die("--annotate requires -I dts -O dts\n");
300299 if (streq(inform, "dts"))
301300 dti = dt_from_source(arg);
302301 else if (streq(inform, "fs"))
....@@ -350,6 +349,12 @@
350349
351350 if (streq(outform, "dts")) {
352351 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
353358 } else if (streq(outform, "dtb")) {
354359 dt_to_blob(outf, dti, outversion);
355360 } else if (streq(outform, "asm")) {