~ubuntu-branches/debian/stretch/device-tree-compiler/stretch

« back to all changes in this revision

Viewing changes to dtc.c

  • Committer: Package Import Robot
  • Author(s): Hector Oron
  • Date: 2011-11-22 12:23:38 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111122122338-ljbxy6a31fqztakc
Tags: 1.3.0-1
* New upstream release. (Closes: #572945)
* New maintainer. (Closes: #649290)
* New VCS repository.
* Update homepage stanza (Closes: #497605)
* Update standards version.
* Compile with -fPIC. Fixes ftbfs on amd64.
* Use dpkg 1.0 format.
* Backport upstream fixes as patches until 2011-10-26.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
int reservenum;         /* Number of memory reservation slots */
31
31
int minsize;            /* Minimum blob size */
32
32
int padsize;            /* Additional padding to blob */
33
 
 
34
 
char *join_path(const char *path, const char *name)
35
 
{
36
 
        int lenp = strlen(path);
37
 
        int lenn = strlen(name);
38
 
        int len;
39
 
        int needslash = 1;
40
 
        char *str;
41
 
 
42
 
        len = lenp + lenn + 2;
43
 
        if ((lenp > 0) && (path[lenp-1] == '/')) {
44
 
                needslash = 0;
45
 
                len--;
46
 
        }
47
 
 
48
 
        str = xmalloc(len);
49
 
        memcpy(str, path, lenp);
50
 
        if (needslash) {
51
 
                str[lenp] = '/';
52
 
                lenp++;
53
 
        }
54
 
        memcpy(str+lenp, name, lenn+1);
55
 
        return str;
56
 
}
57
 
 
58
 
void fill_fullpaths(struct node *tree, const char *prefix)
 
33
int phandle_format = PHANDLE_BOTH;      /* Use linux,phandle or phandle properties */
 
34
 
 
35
static void fill_fullpaths(struct node *tree, const char *prefix)
59
36
{
60
37
        struct node *child;
61
38
        const char *unit;
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");
109
 
        exit(2);
 
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");
 
93
        exit(3);
110
94
}
111
95
 
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;
119
103
        const char *arg;
120
104
        int opt;
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;
125
108
 
126
109
        quiet      = 0;
127
110
        reservenum = 0;
128
111
        minsize    = 0;
129
112
        padsize    = 0;
130
113
 
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) {
132
115
                switch (opt) {
133
116
                case 'I':
134
117
                        inform = optarg;
161
144
                        quiet++;
162
145
                        break;
163
146
                case 'b':
164
 
                        boot_cpuid_phys = strtol(optarg, NULL, 0);
 
147
                        cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
165
148
                        break;
166
149
                case 'v':
167
 
                    printf("Version: %s\n", DTC_VERSION);
168
 
                    exit(0);
 
150
                        printf("Version: %s\n", DTC_VERSION);
 
151
                        exit(0);
 
152
                case 'H':
 
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;
 
159
                        else
 
160
                                die("Invalid argument \"%s\" to -H option\n",
 
161
                                    optarg);
 
162
                        break;
 
163
 
 
164
                case 's':
 
165
                        sort = 1;
 
166
                        break;
 
167
 
169
168
                case 'h':
170
169
                default:
171
170
                        usage();
180
179
                arg = argv[optind];
181
180
 
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");
185
 
        }
 
184
 
 
185
        if (minsize)
 
186
                fprintf(stderr, "DTC: Use of \"-S\" is deprecated; it will be removed soon, use \"-p\" instead\n");
186
187
 
187
188
        fprintf(stderr, "DTC: %s->%s  on file \"%s\"\n",
188
189
                inform, outform, arg);
189
190
 
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);
196
 
                if (!inf)
197
 
                        die("Couldn't open \"%s\": %s\n", arg,
198
 
                            strerror(errno));
199
 
 
200
 
                bi = dt_from_blob(inf->file);
201
 
        } else {
 
195
        else if(streq(inform, "dtb"))
 
196
                bi = dt_from_blob(arg);
 
197
        else
202
198
                die("Unknown input format \"%s\"\n", inform);
203
 
        }
204
 
 
205
 
        if (inf && inf->file != stdin)
206
 
                fclose(inf->file);
207
 
 
208
 
        if (! bi || ! bi->dt || bi->error)
209
 
                die("Couldn't read input tree\n");
210
 
 
 
199
 
 
200
        if (cmdline_boot_cpuid != -1)
 
201
                bi->boot_cpuid_phys = cmdline_boot_cpuid;
 
202
 
 
203
        fill_fullpaths(bi->dt, "");
211
204
        process_checks(force, bi);
212
205
 
 
206
        if (sort)
 
207
                sort_tree(bi);
 
208
 
213
209
        if (streq(outname, "-")) {
214
210
                outf = stdout;
215
211
        } else {
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")) {
229
225
                /* do nothing */
230
226
        } else {