30
30
int reservenum; /* Number of memory reservation slots */
31
31
int minsize; /* Minimum blob size */
32
32
int padsize; /* Additional padding to blob */
34
char *join_path(const char *path, const char *name)
36
int lenp = strlen(path);
37
int lenn = strlen(name);
42
len = lenp + lenn + 2;
43
if ((lenp > 0) && (path[lenp-1] == '/')) {
49
memcpy(str, path, lenp);
54
memcpy(str+lenp, name, lenn+1);
58
void fill_fullpaths(struct node *tree, const char *prefix)
33
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
35
static void fill_fullpaths(struct node *tree, const char *prefix)
60
37
struct node *child;
104
81
fprintf(stderr, "\t\tSet the physical boot cpu\n");
105
82
fprintf(stderr, "\t-f\n");
106
83
fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
84
fprintf(stderr, "\t-s\n");
85
fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n");
107
86
fprintf(stderr, "\t-v\n");
108
87
fprintf(stderr, "\t\tPrint DTC version and exit\n");
88
fprintf(stderr, "\t-H <phandle format>\n");
89
fprintf(stderr, "\t\tphandle formats are:\n");
90
fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n");
91
fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n");
92
fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n");
112
96
int main(int argc, char *argv[])
115
99
const char *inform = "dts";
116
100
const char *outform = "dts";
117
101
const char *outname = "-";
118
int force = 0, check = 0;
102
int force = 0, check = 0, sort = 0;
121
struct dtc_file *inf = NULL;
122
105
FILE *outf = NULL;
123
106
int outversion = DEFAULT_FDT_VERSION;
124
int boot_cpuid_phys = 0xfeedbeef;
107
long long cmdline_boot_cpuid = -1;
131
while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:v")) != EOF) {
114
while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:vH:s")) != EOF) {
164
boot_cpuid_phys = strtol(optarg, NULL, 0);
147
cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
167
printf("Version: %s\n", DTC_VERSION);
150
printf("Version: %s\n", DTC_VERSION);
153
if (streq(optarg, "legacy"))
154
phandle_format = PHANDLE_LEGACY;
155
else if (streq(optarg, "epapr"))
156
phandle_format = PHANDLE_EPAPR;
157
else if (streq(optarg, "both"))
158
phandle_format = PHANDLE_BOTH;
160
die("Invalid argument \"%s\" to -H option\n",
180
179
arg = argv[optind];
182
181
/* minsize and padsize are mutually exclusive */
183
if ((minsize) && (padsize)) {
182
if (minsize && padsize)
184
183
die("Can't set both -p and -S\n");
186
fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n");
187
188
fprintf(stderr, "DTC: %s->%s on file \"%s\"\n",
188
189
inform, outform, arg);
190
if (streq(inform, "dts")) {
191
if (streq(inform, "dts"))
191
192
bi = dt_from_source(arg);
192
} else if (streq(inform, "fs")) {
193
else if (streq(inform, "fs"))
193
194
bi = dt_from_fs(arg);
194
} else if(streq(inform, "dtb")) {
195
inf = dtc_open_file(arg, NULL);
197
die("Couldn't open \"%s\": %s\n", arg,
200
bi = dt_from_blob(inf->file);
195
else if(streq(inform, "dtb"))
196
bi = dt_from_blob(arg);
202
198
die("Unknown input format \"%s\"\n", inform);
205
if (inf && inf->file != stdin)
208
if (! bi || ! bi->dt || bi->error)
209
die("Couldn't read input tree\n");
200
if (cmdline_boot_cpuid != -1)
201
bi->boot_cpuid_phys = cmdline_boot_cpuid;
203
fill_fullpaths(bi->dt, "");
211
204
process_checks(force, bi);
213
209
if (streq(outname, "-")) {
222
218
if (streq(outform, "dts")) {
223
219
dt_to_source(outf, bi);
224
220
} else if (streq(outform, "dtb")) {
225
dt_to_blob(outf, bi, outversion, boot_cpuid_phys);
221
dt_to_blob(outf, bi, outversion);
226
222
} else if (streq(outform, "asm")) {
227
dt_to_asm(outf, bi, outversion, boot_cpuid_phys);
223
dt_to_asm(outf, bi, outversion);
228
224
} else if (streq(outform, "null")) {