Blame view

scripts/dtc/dtc.c 6.83 KB
a4da2e3ec   David Gibson   [POWERPC] Merge d...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  /*
   * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
   *
   *
   * 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.
   *
   *  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
   */
  
  #include "dtc.h"
  #include "srcpos.h"
  
  #include "version_gen.h"
  
  /*
   * Command line options
   */
  int quiet;		/* Level of quietness */
  int reservenum;		/* Number of memory reservation slots */
  int minsize;		/* Minimum blob size */
  int padsize;		/* Additional padding to blob */
658f29a51   John Bonesio   of/flattree: Upda...
33
  int phandle_format = PHANDLE_BOTH;	/* Use linux,phandle or phandle properties */
a4da2e3ec   David Gibson   [POWERPC] Merge d...
34

ed95d7450   David Gibson   powerpc: Update i...
35
  static void fill_fullpaths(struct node *tree, const char *prefix)
a4da2e3ec   David Gibson   [POWERPC] Merge d...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  {
  	struct node *child;
  	const char *unit;
  
  	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);
  }
  
  static void  __attribute__ ((noreturn)) usage(void)
  {
  	fprintf(stderr, "Usage:
  ");
  	fprintf(stderr, "\tdtc [options] <input file>
  ");
  	fprintf(stderr, "
  Options:
  ");
  	fprintf(stderr, "\t-h
  ");
  	fprintf(stderr, "\t\tThis help text
  ");
  	fprintf(stderr, "\t-q
  ");
  	fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all
  ");
  	fprintf(stderr, "\t-I <input format>
  ");
  	fprintf(stderr, "\t\tInput formats are:
  ");
  	fprintf(stderr, "\t\t\tdts - device tree source text
  ");
  	fprintf(stderr, "\t\t\tdtb - device tree blob
  ");
  	fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory
  ");
  	fprintf(stderr, "\t-o <output file>
  ");
  	fprintf(stderr, "\t-O <output format>
  ");
  	fprintf(stderr, "\t\tOutput formats are:
  ");
  	fprintf(stderr, "\t\t\tdts - device tree source text
  ");
  	fprintf(stderr, "\t\t\tdtb - device tree blob
  ");
  	fprintf(stderr, "\t\t\tasm - assembler source
  ");
  	fprintf(stderr, "\t-V <output version>
  ");
  	fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb
  \t\tand asm output only)
  ", DEFAULT_FDT_VERSION);
136ec2049   Stephen Warren   dtc: Implement -d...
96
97
  	fprintf(stderr, "\t-d <output dependency file>
  ");
a4da2e3ec   David Gibson   [POWERPC] Merge d...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  	fprintf(stderr, "\t-R <number>
  ");
  	fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for 
  \t\tdtb and asm output only)
  ");
  	fprintf(stderr, "\t-S <bytes>
  ");
  	fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)
  ");
  	fprintf(stderr, "\t-p <bytes>
  ");
  	fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)
  ");
  	fprintf(stderr, "\t-b <number>
  ");
  	fprintf(stderr, "\t\tSet the physical boot cpu
  ");
  	fprintf(stderr, "\t-f
  ");
  	fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors
  ");
658f29a51   John Bonesio   of/flattree: Upda...
119
120
121
122
123
  	fprintf(stderr, "\t-s
  ");
  	fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for
  \t\tcomparing trees)
  ");
a4da2e3ec   David Gibson   [POWERPC] Merge d...
124
125
126
127
  	fprintf(stderr, "\t-v
  ");
  	fprintf(stderr, "\t\tPrint DTC version and exit
  ");
658f29a51   John Bonesio   of/flattree: Upda...
128
129
130
131
132
133
134
135
136
137
  	fprintf(stderr, "\t-H <phandle format>
  ");
  	fprintf(stderr, "\t\tphandle formats are:
  ");
  	fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only
  ");
  	fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only
  ");
  	fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties
  ");
ed95d7450   David Gibson   powerpc: Update i...
138
  	exit(3);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
139
140
141
142
143
144
145
146
  }
  
  int main(int argc, char *argv[])
  {
  	struct boot_info *bi;
  	const char *inform = "dts";
  	const char *outform = "dts";
  	const char *outname = "-";
136ec2049   Stephen Warren   dtc: Implement -d...
147
  	const char *depname = NULL;
658f29a51   John Bonesio   of/flattree: Upda...
148
  	int force = 0, check = 0, sort = 0;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
149
150
  	const char *arg;
  	int opt;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
151
152
  	FILE *outf = NULL;
  	int outversion = DEFAULT_FDT_VERSION;
ed95d7450   David Gibson   powerpc: Update i...
153
  	long long cmdline_boot_cpuid = -1;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
154
155
156
157
158
  
  	quiet      = 0;
  	reservenum = 0;
  	minsize    = 0;
  	padsize    = 0;
136ec2049   Stephen Warren   dtc: Implement -d...
159
160
  	while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fcqb:vH:s"))
  			!= EOF) {
a4da2e3ec   David Gibson   [POWERPC] Merge d...
161
162
163
164
165
166
167
168
169
170
171
172
173
  		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;
136ec2049   Stephen Warren   dtc: Implement -d...
174
175
176
  		case 'd':
  			depname = optarg;
  			break;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  		case 'R':
  			reservenum = strtol(optarg, NULL, 0);
  			break;
  		case 'S':
  			minsize = strtol(optarg, NULL, 0);
  			break;
  		case 'p':
  			padsize = strtol(optarg, NULL, 0);
  			break;
  		case 'f':
  			force = 1;
  			break;
  		case 'c':
  			check = 1;
  			break;
  		case 'q':
  			quiet++;
  			break;
  		case 'b':
ed95d7450   David Gibson   powerpc: Update i...
196
  			cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
197
198
  			break;
  		case 'v':
ed95d7450   David Gibson   powerpc: Update i...
199
200
201
  			printf("Version: %s
  ", DTC_VERSION);
  			exit(0);
658f29a51   John Bonesio   of/flattree: Upda...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  		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
  ",
  				    optarg);
  			break;
  
  		case 's':
  			sort = 1;
  			break;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  		case 'h':
  		default:
  			usage();
  		}
  	}
  
  	if (argc > (optind+1))
  		usage();
  	else if (argc < (optind+1))
  		arg = "-";
  	else
  		arg = argv[optind];
  
  	/* minsize and padsize are mutually exclusive */
ed95d7450   David Gibson   powerpc: Update i...
232
  	if (minsize && padsize)
a4da2e3ec   David Gibson   [POWERPC] Merge d...
233
234
  		die("Can't set both -p and -S
  ");
a4da2e3ec   David Gibson   [POWERPC] Merge d...
235

658f29a51   John Bonesio   of/flattree: Upda...
236
237
238
  	if (minsize)
  		fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead
  ");
a4da2e3ec   David Gibson   [POWERPC] Merge d...
239
240
241
  	fprintf(stderr, "DTC: %s->%s  on file \"%s\"
  ",
  		inform, outform, arg);
136ec2049   Stephen Warren   dtc: Implement -d...
242
243
244
245
246
247
248
249
  	if (depname) {
  		depfile = fopen(depname, "w");
  		if (!depfile)
  			die("Couldn't open dependency file %s: %s
  ", depname,
  			    strerror(errno));
  		fprintf(depfile, "%s:", outname);
  	}
ed95d7450   David Gibson   powerpc: Update i...
250
  	if (streq(inform, "dts"))
a4da2e3ec   David Gibson   [POWERPC] Merge d...
251
  		bi = dt_from_source(arg);
ed95d7450   David Gibson   powerpc: Update i...
252
  	else if (streq(inform, "fs"))
a4da2e3ec   David Gibson   [POWERPC] Merge d...
253
  		bi = dt_from_fs(arg);
ed95d7450   David Gibson   powerpc: Update i...
254
255
256
  	else if(streq(inform, "dtb"))
  		bi = dt_from_blob(arg);
  	else
a4da2e3ec   David Gibson   [POWERPC] Merge d...
257
258
  		die("Unknown input format \"%s\"
  ", inform);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
259

136ec2049   Stephen Warren   dtc: Implement -d...
260
261
262
263
264
  	if (depfile) {
  		fputc('
  ', depfile);
  		fclose(depfile);
  	}
ed95d7450   David Gibson   powerpc: Update i...
265
266
  	if (cmdline_boot_cpuid != -1)
  		bi->boot_cpuid_phys = cmdline_boot_cpuid;
a4da2e3ec   David Gibson   [POWERPC] Merge d...
267

ed95d7450   David Gibson   powerpc: Update i...
268
269
  	fill_fullpaths(bi->dt, "");
  	process_checks(force, bi);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
270

658f29a51   John Bonesio   of/flattree: Upda...
271
272
  	if (sort)
  		sort_tree(bi);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  
  	if (streq(outname, "-")) {
  		outf = stdout;
  	} else {
  		outf = fopen(outname, "w");
  		if (! outf)
  			die("Couldn't open output file %s: %s
  ",
  			    outname, strerror(errno));
  	}
  
  	if (streq(outform, "dts")) {
  		dt_to_source(outf, bi);
  	} else if (streq(outform, "dtb")) {
ed95d7450   David Gibson   powerpc: Update i...
287
  		dt_to_blob(outf, bi, outversion);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
288
  	} else if (streq(outform, "asm")) {
ed95d7450   David Gibson   powerpc: Update i...
289
  		dt_to_asm(outf, bi, outversion);
a4da2e3ec   David Gibson   [POWERPC] Merge d...
290
291
292
293
294
295
296
297
298
  	} else if (streq(outform, "null")) {
  		/* do nothing */
  	} else {
  		die("Unknown output format \"%s\"
  ", outform);
  	}
  
  	exit(0);
  }