2019-06-20 23:19:38 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-06-08 09:18:34 +02:00
|
|
|
/*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
|
|
*/
|
|
|
|
|
2015-07-01 01:31:27 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
#include "dtc.h"
|
2007-03-23 21:18:41 +01:00
|
|
|
#include "srcpos.h"
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2007-04-05 04:04:33 +02:00
|
|
|
/*
|
|
|
|
* Command line options
|
|
|
|
*/
|
|
|
|
int quiet; /* Level of quietness */
|
2021-06-11 19:10:37 +02:00
|
|
|
unsigned int reservenum;/* Number of memory reservation slots */
|
2007-04-05 04:04:33 +02:00
|
|
|
int minsize; /* Minimum blob size */
|
2007-11-28 17:21:12 +01:00
|
|
|
int padsize; /* Additional padding to blob */
|
2016-07-18 09:56:53 +02:00
|
|
|
int alignsize; /* Additional padding to blob accroding to the alignsize */
|
2017-07-13 00:20:30 +02:00
|
|
|
int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties */
|
2016-12-07 13:48:18 +01:00
|
|
|
int generate_symbols; /* enable symbols & fixup support */
|
|
|
|
int generate_fixups; /* suppress generation of fixups on symbol support */
|
|
|
|
int auto_label_aliases; /* auto generate labels -> aliases */
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
int annotate; /* Level of annotation: 1 for input source location
|
|
|
|
>1 for full input source location. */
|
2007-04-05 04:04:33 +02:00
|
|
|
|
2016-07-18 09:56:53 +02:00
|
|
|
static int is_power_of_2(int x)
|
|
|
|
{
|
|
|
|
return (x > 0) && ((x & (x - 1)) == 0);
|
|
|
|
}
|
|
|
|
|
2008-02-29 06:51:28 +01:00
|
|
|
static void fill_fullpaths(struct node *tree, const char *prefix)
|
2005-06-08 09:18:34 +02:00
|
|
|
{
|
|
|
|
struct node *child;
|
2007-12-04 04:26:15 +01:00
|
|
|
const char *unit;
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-24 10:02:35 +02:00
|
|
|
/* Usage related data. */
|
|
|
|
static const char usage_synopsis[] = "dtc [options] <input file>";
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv";
|
2013-05-24 10:02:35 +02:00
|
|
|
static struct option const usage_long_opts[] = {
|
|
|
|
{"quiet", no_argument, NULL, 'q'},
|
|
|
|
{"in-format", a_argument, NULL, 'I'},
|
|
|
|
{"out", a_argument, NULL, 'o'},
|
|
|
|
{"out-format", a_argument, NULL, 'O'},
|
|
|
|
{"out-version", a_argument, NULL, 'V'},
|
|
|
|
{"out-dependency", a_argument, NULL, 'd'},
|
|
|
|
{"reserve", a_argument, NULL, 'R'},
|
|
|
|
{"space", a_argument, NULL, 'S'},
|
|
|
|
{"pad", a_argument, NULL, 'p'},
|
2016-07-18 09:56:53 +02:00
|
|
|
{"align", a_argument, NULL, 'a'},
|
2013-05-24 10:02:35 +02:00
|
|
|
{"boot-cpu", a_argument, NULL, 'b'},
|
|
|
|
{"force", no_argument, NULL, 'f'},
|
|
|
|
{"include", a_argument, NULL, 'i'},
|
|
|
|
{"sort", no_argument, NULL, 's'},
|
|
|
|
{"phandle", a_argument, NULL, 'H'},
|
|
|
|
{"warning", a_argument, NULL, 'W'},
|
|
|
|
{"error", a_argument, NULL, 'E'},
|
2016-12-07 13:48:18 +01:00
|
|
|
{"symbols", no_argument, NULL, '@'},
|
|
|
|
{"auto-alias", no_argument, NULL, 'A'},
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
{"annotate", no_argument, NULL, 'T'},
|
2013-05-24 10:02:35 +02:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'v'},
|
|
|
|
{NULL, no_argument, NULL, 0x0},
|
|
|
|
};
|
|
|
|
static const char * const usage_opts_help[] = {
|
|
|
|
"\n\tQuiet: -q suppress warnings, -qq errors, -qqq all",
|
|
|
|
"\n\tInput formats are:\n"
|
|
|
|
"\t\tdts - device tree source text\n"
|
|
|
|
"\t\tdtb - device tree blob\n"
|
|
|
|
"\t\tfs - /proc/device-tree style directory",
|
|
|
|
"\n\tOutput file",
|
|
|
|
"\n\tOutput formats are:\n"
|
|
|
|
"\t\tdts - device tree source text\n"
|
|
|
|
"\t\tdtb - device tree blob\n"
|
2018-09-11 22:41:31 +02:00
|
|
|
#ifndef NO_YAML
|
|
|
|
"\t\tyaml - device tree encoded as YAML\n"
|
|
|
|
#endif
|
2013-05-24 10:02:35 +02:00
|
|
|
"\t\tasm - assembler source",
|
2017-10-18 07:55:08 +02:00
|
|
|
"\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
|
2013-05-24 10:02:35 +02:00
|
|
|
"\n\tOutput dependency file",
|
2014-09-11 09:16:37 +02:00
|
|
|
"\n\tMake space for <number> reserve map entries (for dtb and asm output)",
|
2013-05-24 10:02:35 +02:00
|
|
|
"\n\tMake the blob at least <bytes> long (extra space)",
|
|
|
|
"\n\tAdd padding to the blob of <bytes> long (extra space)",
|
2016-07-18 09:56:53 +02:00
|
|
|
"\n\tMake the blob align to the <bytes> (extra space)",
|
2013-05-24 10:02:35 +02:00
|
|
|
"\n\tSet the physical boot cpu",
|
|
|
|
"\n\tTry to produce output even if the input tree has errors",
|
|
|
|
"\n\tAdd a path to search for include files",
|
|
|
|
"\n\tSort nodes and properties before outputting (useful for comparing trees)",
|
|
|
|
"\n\tValid phandle formats are:\n"
|
|
|
|
"\t\tlegacy - \"linux,phandle\" properties only\n"
|
|
|
|
"\t\tepapr - \"phandle\" properties only\n"
|
|
|
|
"\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
|
|
|
|
"\n\tEnable/disable warnings (prefix with \"no-\")",
|
|
|
|
"\n\tEnable/disable errors (prefix with \"no-\")",
|
2016-12-07 13:48:18 +01:00
|
|
|
"\n\tEnable generation of symbols",
|
|
|
|
"\n\tEnable auto-alias of labels",
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
|
2013-05-24 10:02:35 +02:00
|
|
|
"\n\tPrint this help and exit",
|
|
|
|
"\n\tPrint version and exit",
|
|
|
|
NULL,
|
|
|
|
};
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2015-07-01 01:31:27 +02:00
|
|
|
static const char *guess_type_by_name(const char *fname, const char *fallback)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
s = strrchr(fname, '.');
|
|
|
|
if (s == NULL)
|
|
|
|
return fallback;
|
|
|
|
if (!strcasecmp(s, ".dts"))
|
|
|
|
return "dts";
|
2018-09-11 22:41:31 +02:00
|
|
|
if (!strcasecmp(s, ".yaml"))
|
|
|
|
return "yaml";
|
2021-01-06 10:56:08 +01:00
|
|
|
if (!strcasecmp(s, ".dtbo"))
|
|
|
|
return "dtb";
|
2015-07-01 01:31:27 +02:00
|
|
|
if (!strcasecmp(s, ".dtb"))
|
|
|
|
return "dtb";
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *guess_input_format(const char *fname, const char *fallback)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
2017-03-06 02:08:53 +01:00
|
|
|
fdt32_t magic;
|
2015-07-01 01:31:27 +02:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
if (stat(fname, &statbuf) != 0)
|
|
|
|
return fallback;
|
|
|
|
|
|
|
|
if (S_ISDIR(statbuf.st_mode))
|
|
|
|
return "fs";
|
|
|
|
|
|
|
|
if (!S_ISREG(statbuf.st_mode))
|
|
|
|
return fallback;
|
|
|
|
|
|
|
|
f = fopen(fname, "r");
|
|
|
|
if (f == NULL)
|
|
|
|
return fallback;
|
|
|
|
if (fread(&magic, 4, 1, f) != 1) {
|
|
|
|
fclose(f);
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
|
2017-03-06 02:08:53 +01:00
|
|
|
if (fdt32_to_cpu(magic) == FDT_MAGIC)
|
2015-07-01 01:31:27 +02:00
|
|
|
return "dtb";
|
|
|
|
|
|
|
|
return guess_type_by_name(fname, fallback);
|
|
|
|
}
|
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-05-31 03:58:42 +02:00
|
|
|
struct dt_info *dti;
|
2015-07-01 01:31:27 +02:00
|
|
|
const char *inform = NULL;
|
2015-07-01 01:31:28 +02:00
|
|
|
const char *outform = NULL;
|
2007-12-04 04:26:15 +01:00
|
|
|
const char *outname = "-";
|
2012-01-12 19:31:00 +01:00
|
|
|
const char *depname = NULL;
|
2013-10-28 11:06:53 +01:00
|
|
|
bool force = false, sort = false;
|
2007-12-04 04:26:15 +01:00
|
|
|
const char *arg;
|
2005-06-08 09:18:34 +02:00
|
|
|
int opt;
|
|
|
|
FILE *outf = NULL;
|
2007-09-26 05:11:05 +02:00
|
|
|
int outversion = DEFAULT_FDT_VERSION;
|
2008-05-16 05:22:57 +02:00
|
|
|
long long cmdline_boot_cpuid = -1;
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2007-04-05 04:04:33 +02:00
|
|
|
quiet = 0;
|
|
|
|
reservenum = 0;
|
|
|
|
minsize = 0;
|
2007-11-28 17:21:12 +01:00
|
|
|
padsize = 0;
|
2016-07-18 09:56:53 +02:00
|
|
|
alignsize = 0;
|
2007-03-18 21:49:24 +01:00
|
|
|
|
2013-05-24 10:02:35 +02:00
|
|
|
while ((opt = util_getopt_long()) != EOF) {
|
2005-06-08 09:18:34 +02:00
|
|
|
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;
|
2012-01-12 19:31:00 +01:00
|
|
|
case 'd':
|
|
|
|
depname = optarg;
|
|
|
|
break;
|
2005-06-08 09:18:34 +02:00
|
|
|
case 'R':
|
2021-06-11 19:10:37 +02:00
|
|
|
reservenum = strtoul(optarg, NULL, 0);
|
2005-06-08 09:18:34 +02:00
|
|
|
break;
|
2007-04-05 04:04:33 +02:00
|
|
|
case 'S':
|
|
|
|
minsize = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
2007-11-28 17:21:12 +01:00
|
|
|
case 'p':
|
|
|
|
padsize = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
2016-07-18 09:56:53 +02:00
|
|
|
case 'a':
|
|
|
|
alignsize = strtol(optarg, NULL, 0);
|
|
|
|
if (!is_power_of_2(alignsize))
|
|
|
|
die("Invalid argument \"%d\" to -a option\n",
|
2017-02-27 00:38:38 +01:00
|
|
|
alignsize);
|
2016-07-18 09:56:53 +02:00
|
|
|
break;
|
2005-06-08 09:18:34 +02:00
|
|
|
case 'f':
|
2013-10-28 11:06:53 +01:00
|
|
|
force = true;
|
2005-06-08 09:18:34 +02:00
|
|
|
break;
|
2007-03-18 21:49:24 +01:00
|
|
|
case 'q':
|
|
|
|
quiet++;
|
|
|
|
break;
|
2006-05-31 00:31:51 +02:00
|
|
|
case 'b':
|
2008-05-16 05:22:57 +02:00
|
|
|
cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
|
2006-05-31 00:31:51 +02:00
|
|
|
break;
|
2012-03-15 04:04:13 +01:00
|
|
|
case 'i':
|
|
|
|
srcfile_add_search_path(optarg);
|
|
|
|
break;
|
2007-07-07 20:52:25 +02:00
|
|
|
case 'v':
|
2013-04-10 20:29:09 +02:00
|
|
|
util_version();
|
Support ePAPR compliant phandle properties
Currently, the Linux kernel, libfdt and dtc, when using flattened
device trees encode a node's phandle into a property named
"linux,phandle". The ePAPR specification, however - aiming as it is
to not be a Linux specific spec - requires that phandles be encoded in
a property named simply "phandle".
This patch adds support for this newer approach to dtc and libfdt.
Specifically:
- fdt_get_phandle() will now return the correct phandle if it
is supplied in either of these properties
- fdt_node_offset_by_phandle() will correctly find a node with
the given phandle encoded in either property.
- By default, when auto-generating phandles, dtc will encode
it into both properties for maximum compatibility. A new -H
option allows either only old-style or only new-style
properties to be generated.
- If phandle properties are explicitly supplied in the dts
file, dtc will not auto-generate ones in the alternate format.
- If both properties are supplied, dtc will check that they
have the same value.
- Some existing testcases are updated to use a mix of old and
new-style phandles, partially testing the changes.
- A new phandle_format test further tests the libfdt support,
and the -H option.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-26 05:37:13 +01:00
|
|
|
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;
|
|
|
|
|
2010-11-09 23:51:09 +01:00
|
|
|
case 's':
|
2013-10-28 11:06:53 +01:00
|
|
|
sort = true;
|
2010-11-09 23:51:09 +01:00
|
|
|
break;
|
|
|
|
|
2012-07-08 15:25:22 +02:00
|
|
|
case 'W':
|
|
|
|
parse_checks_option(true, false, optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
parse_checks_option(false, true, optarg);
|
|
|
|
break;
|
|
|
|
|
2016-12-07 13:48:18 +01:00
|
|
|
case '@':
|
|
|
|
generate_symbols = 1;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
auto_label_aliases = 1;
|
|
|
|
break;
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
case 'T':
|
|
|
|
annotate++;
|
|
|
|
break;
|
2016-12-07 13:48:18 +01:00
|
|
|
|
2007-03-18 21:49:24 +01:00
|
|
|
case 'h':
|
2013-05-24 10:04:43 +02:00
|
|
|
usage(NULL);
|
2005-06-08 09:18:34 +02:00
|
|
|
default:
|
2013-05-24 10:04:43 +02:00
|
|
|
usage("unknown option");
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > (optind+1))
|
2013-05-24 10:04:43 +02:00
|
|
|
usage("missing files");
|
2005-06-08 09:18:34 +02:00
|
|
|
else if (argc < (optind+1))
|
|
|
|
arg = "-";
|
|
|
|
else
|
|
|
|
arg = argv[optind];
|
|
|
|
|
2007-11-28 17:21:12 +01:00
|
|
|
/* minsize and padsize are mutually exclusive */
|
2008-05-16 05:22:35 +02:00
|
|
|
if (minsize && padsize)
|
2007-11-28 17:21:12 +01:00
|
|
|
die("Can't set both -p and -S\n");
|
|
|
|
|
2012-01-12 19:31:00 +01:00
|
|
|
if (depname) {
|
|
|
|
depfile = fopen(depname, "w");
|
|
|
|
if (!depfile)
|
|
|
|
die("Couldn't open dependency file %s: %s\n", depname,
|
|
|
|
strerror(errno));
|
|
|
|
fprintf(depfile, "%s:", outname);
|
|
|
|
}
|
|
|
|
|
2015-07-01 01:31:27 +02:00
|
|
|
if (inform == NULL)
|
|
|
|
inform = guess_input_format(arg, "dts");
|
2015-07-01 01:31:28 +02:00
|
|
|
if (outform == NULL) {
|
|
|
|
outform = guess_type_by_name(outname, NULL);
|
|
|
|
if (outform == NULL) {
|
|
|
|
if (streq(inform, "dts"))
|
|
|
|
outform = "dtb";
|
|
|
|
else
|
|
|
|
outform = "dts";
|
|
|
|
}
|
|
|
|
}
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
|
|
|
|
die("--annotate requires -I dts -O dts\n");
|
2008-05-16 05:22:09 +02:00
|
|
|
if (streq(inform, "dts"))
|
2016-05-31 03:58:42 +02:00
|
|
|
dti = dt_from_source(arg);
|
2008-05-16 05:22:09 +02:00
|
|
|
else if (streq(inform, "fs"))
|
2016-05-31 03:58:42 +02:00
|
|
|
dti = dt_from_fs(arg);
|
2008-05-16 05:22:09 +02:00
|
|
|
else if(streq(inform, "dtb"))
|
2016-05-31 03:58:42 +02:00
|
|
|
dti = dt_from_blob(arg);
|
2008-05-16 05:22:09 +02:00
|
|
|
else
|
2005-06-08 09:18:34 +02:00
|
|
|
die("Unknown input format \"%s\"\n", inform);
|
|
|
|
|
2017-02-03 09:29:39 +01:00
|
|
|
dti->outname = outname;
|
|
|
|
|
2012-01-12 19:31:00 +01:00
|
|
|
if (depfile) {
|
|
|
|
fputc('\n', depfile);
|
|
|
|
fclose(depfile);
|
|
|
|
}
|
|
|
|
|
2008-05-16 05:22:57 +02:00
|
|
|
if (cmdline_boot_cpuid != -1)
|
2016-05-31 03:58:42 +02:00
|
|
|
dti->boot_cpuid_phys = cmdline_boot_cpuid;
|
2008-05-16 05:22:57 +02:00
|
|
|
|
2016-05-31 03:58:42 +02:00
|
|
|
fill_fullpaths(dti->dt, "");
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2016-12-07 13:48:18 +01:00
|
|
|
/* on a plugin, generate by default */
|
2016-05-31 03:58:42 +02:00
|
|
|
if (dti->dtsflags & DTSF_PLUGIN) {
|
2016-12-07 13:48:18 +01:00
|
|
|
generate_fixups = 1;
|
|
|
|
}
|
|
|
|
|
2017-10-24 16:14:18 +02:00
|
|
|
process_checks(force, dti);
|
|
|
|
|
2016-12-07 13:48:18 +01:00
|
|
|
if (auto_label_aliases)
|
2016-05-31 03:58:42 +02:00
|
|
|
generate_label_tree(dti, "aliases", false);
|
2016-12-07 13:48:18 +01:00
|
|
|
|
|
|
|
if (generate_symbols)
|
2016-05-31 03:58:42 +02:00
|
|
|
generate_label_tree(dti, "__symbols__", true);
|
2016-12-07 13:48:18 +01:00
|
|
|
|
|
|
|
if (generate_fixups) {
|
2016-05-31 03:58:42 +02:00
|
|
|
generate_fixups_tree(dti, "__fixups__");
|
|
|
|
generate_local_fixups_tree(dti, "__local_fixups__");
|
2016-12-07 13:48:18 +01:00
|
|
|
}
|
|
|
|
|
2010-11-09 23:51:09 +01:00
|
|
|
if (sort)
|
2016-05-31 03:58:42 +02:00
|
|
|
sort_tree(dti);
|
2008-05-16 05:22:57 +02:00
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
if (streq(outname, "-")) {
|
|
|
|
outf = stdout;
|
|
|
|
} else {
|
2014-06-19 13:12:27 +02:00
|
|
|
outf = fopen(outname, "wb");
|
2005-06-08 09:18:34 +02:00
|
|
|
if (! outf)
|
|
|
|
die("Couldn't open output file %s: %s\n",
|
|
|
|
outname, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (streq(outform, "dts")) {
|
2016-05-31 03:58:42 +02:00
|
|
|
dt_to_source(outf, dti);
|
2018-09-11 22:41:31 +02:00
|
|
|
#ifndef NO_YAML
|
|
|
|
} else if (streq(outform, "yaml")) {
|
|
|
|
if (!streq(inform, "dts"))
|
|
|
|
die("YAML output format requires dts input format\n");
|
|
|
|
dt_to_yaml(outf, dti);
|
|
|
|
#endif
|
2005-06-08 09:18:34 +02:00
|
|
|
} else if (streq(outform, "dtb")) {
|
2016-05-31 03:58:42 +02:00
|
|
|
dt_to_blob(outf, dti, outversion);
|
2005-06-08 09:18:34 +02:00
|
|
|
} else if (streq(outform, "asm")) {
|
2016-05-31 03:58:42 +02:00
|
|
|
dt_to_asm(outf, dti, outversion);
|
2005-06-08 09:18:34 +02:00
|
|
|
} else if (streq(outform, "null")) {
|
|
|
|
/* do nothing */
|
|
|
|
} else {
|
|
|
|
die("Unknown output format \"%s\"\n", outform);
|
|
|
|
}
|
2007-09-18 03:44:04 +02:00
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
exit(0);
|
|
|
|
}
|