2005-06-08 09:18:34 +02:00
|
|
|
/*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
|
|
*
|
2007-09-18 03:44:04 +02:00
|
|
|
*
|
2005-06-08 09:18:34 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2007-09-18 03:44:04 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
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 */
|
|
|
|
int reservenum; /* Number of memory reservation slots */
|
|
|
|
int minsize; /* Minimum blob size */
|
2007-11-28 17:21:12 +01:00
|
|
|
int padsize; /* Additional padding to blob */
|
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
|
|
|
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
|
2007-04-05 04:04:33 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-08-31 08:21:23 +02:00
|
|
|
static void __attribute__ ((noreturn)) usage(void)
|
2005-06-08 09:18:34 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage:\n");
|
|
|
|
fprintf(stderr, "\tdtc [options] <input file>\n");
|
|
|
|
fprintf(stderr, "\nOptions:\n");
|
2007-03-18 21:49:24 +01:00
|
|
|
fprintf(stderr, "\t-h\n");
|
|
|
|
fprintf(stderr, "\t\tThis help text\n");
|
|
|
|
fprintf(stderr, "\t-q\n");
|
|
|
|
fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all\n");
|
2005-06-08 09:18:34 +02:00
|
|
|
fprintf(stderr, "\t-I <input format>\n");
|
|
|
|
fprintf(stderr, "\t\tInput formats are:\n");
|
|
|
|
fprintf(stderr, "\t\t\tdts - device tree source text\n");
|
|
|
|
fprintf(stderr, "\t\t\tdtb - device tree blob\n");
|
|
|
|
fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory\n");
|
2007-04-15 00:16:47 +02:00
|
|
|
fprintf(stderr, "\t-o <output file>\n");
|
2005-06-08 09:18:34 +02:00
|
|
|
fprintf(stderr, "\t-O <output format>\n");
|
|
|
|
fprintf(stderr, "\t\tOutput formats are:\n");
|
|
|
|
fprintf(stderr, "\t\t\tdts - device tree source text\n");
|
|
|
|
fprintf(stderr, "\t\t\tdtb - device tree blob\n");
|
|
|
|
fprintf(stderr, "\t\t\tasm - assembler source\n");
|
|
|
|
fprintf(stderr, "\t-V <output version>\n");
|
2007-09-26 05:11:05 +02:00
|
|
|
fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION);
|
2012-01-12 19:31:00 +01:00
|
|
|
fprintf(stderr, "\t-d <output dependency file>\n");
|
2005-06-08 09:18:34 +02:00
|
|
|
fprintf(stderr, "\t-R <number>\n");
|
|
|
|
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
|
2007-04-05 04:04:33 +02:00
|
|
|
fprintf(stderr, "\t-S <bytes>\n");
|
|
|
|
fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n");
|
2007-11-28 17:21:12 +01:00
|
|
|
fprintf(stderr, "\t-p <bytes>\n");
|
|
|
|
fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n");
|
2006-05-31 00:31:51 +02:00
|
|
|
fprintf(stderr, "\t-b <number>\n");
|
|
|
|
fprintf(stderr, "\t\tSet the physical boot cpu\n");
|
2005-06-08 09:18:34 +02:00
|
|
|
fprintf(stderr, "\t-f\n");
|
|
|
|
fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
|
2012-03-15 04:04:13 +01:00
|
|
|
fprintf(stderr, "\t-i\n");
|
|
|
|
fprintf(stderr, "\t\tAdd a path to search for include files\n");
|
2010-11-09 23:51:09 +01:00
|
|
|
fprintf(stderr, "\t-s\n");
|
|
|
|
fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
|
2007-07-07 20:52:25 +02:00
|
|
|
fprintf(stderr, "\t-v\n");
|
|
|
|
fprintf(stderr, "\t\tPrint DTC version and exit\n");
|
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
|
|
|
fprintf(stderr, "\t-H <phandle format>\n");
|
|
|
|
fprintf(stderr, "\t\tphandle formats are:\n");
|
|
|
|
fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
|
|
|
|
fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
|
|
|
|
fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
|
2012-07-08 15:25:22 +02:00
|
|
|
fprintf(stderr, "\t-W [no-]<checkname>\n");
|
|
|
|
fprintf(stderr, "\t-E [no-]<checkname>\n");
|
|
|
|
fprintf(stderr, "\t\t\tenable or disable warnings and errors\n");
|
2008-03-18 04:04:19 +01:00
|
|
|
exit(3);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2005-07-15 09:14:24 +02:00
|
|
|
struct boot_info *bi;
|
2007-12-04 04:26:15 +01:00
|
|
|
const char *inform = "dts";
|
|
|
|
const char *outform = "dts";
|
|
|
|
const char *outname = "-";
|
2012-01-12 19:31:00 +01:00
|
|
|
const char *depname = NULL;
|
2011-06-28 14:47:09 +02:00
|
|
|
int force = 0, sort = 0;
|
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;
|
2007-03-18 21:49:24 +01:00
|
|
|
|
2012-07-08 15:25:22 +02:00
|
|
|
while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fqb:i:vH:sW:E:"))
|
2012-03-15 04:04:13 +01:00
|
|
|
!= 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':
|
|
|
|
reservenum = strtol(optarg, NULL, 0);
|
|
|
|
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;
|
2005-06-08 09:18:34 +02:00
|
|
|
case 'f':
|
|
|
|
force = 1;
|
|
|
|
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':
|
|
|
|
sort = 1;
|
|
|
|
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;
|
|
|
|
|
2007-03-18 21:49:24 +01:00
|
|
|
case 'h':
|
2005-06-08 09:18:34 +02:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > (optind+1))
|
|
|
|
usage();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-05-16 05:22:09 +02:00
|
|
|
if (streq(inform, "dts"))
|
2007-03-23 21:18:41 +01:00
|
|
|
bi = dt_from_source(arg);
|
2008-05-16 05:22:09 +02:00
|
|
|
else if (streq(inform, "fs"))
|
2005-07-15 09:14:24 +02:00
|
|
|
bi = dt_from_fs(arg);
|
2008-05-16 05:22:09 +02:00
|
|
|
else if(streq(inform, "dtb"))
|
|
|
|
bi = dt_from_blob(arg);
|
|
|
|
else
|
2005-06-08 09:18:34 +02:00
|
|
|
die("Unknown input format \"%s\"\n", inform);
|
|
|
|
|
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)
|
|
|
|
bi->boot_cpuid_phys = cmdline_boot_cpuid;
|
|
|
|
|
2008-02-29 06:51:28 +01:00
|
|
|
fill_fullpaths(bi->dt, "");
|
2007-12-18 04:54:38 +01:00
|
|
|
process_checks(force, bi);
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2010-11-09 23:51:09 +01:00
|
|
|
if (sort)
|
|
|
|
sort_tree(bi);
|
2008-05-16 05:22:57 +02:00
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
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")) {
|
2005-10-26 08:56:26 +02:00
|
|
|
dt_to_source(outf, bi);
|
2005-06-08 09:18:34 +02:00
|
|
|
} else if (streq(outform, "dtb")) {
|
2008-05-16 05:22:57 +02:00
|
|
|
dt_to_blob(outf, bi, outversion);
|
2005-06-08 09:18:34 +02:00
|
|
|
} else if (streq(outform, "asm")) {
|
2008-05-16 05:22:57 +02:00
|
|
|
dt_to_asm(outf, bi, 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);
|
|
|
|
}
|