Deleted Added
full compact
treesource.c (204488) treesource.c (238742)
1/*
2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
3 *
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.

--- 9 unchanged lines hidden (view full) ---

18 * USA
19 */
20
21#include "dtc.h"
22#include "srcpos.h"
23
24extern FILE *yyin;
25extern int yyparse(void);
1/*
2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
3 *
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.

--- 9 unchanged lines hidden (view full) ---

18 * USA
19 */
20
21#include "dtc.h"
22#include "srcpos.h"
23
24extern FILE *yyin;
25extern int yyparse(void);
26extern YYLTYPE yylloc;
26
27struct boot_info *the_boot_info;
28int treesource_error;
29
30struct boot_info *dt_from_source(const char *fname)
31{
32 the_boot_info = NULL;
33 treesource_error = 0;
34
27
28struct boot_info *the_boot_info;
29int treesource_error;
30
31struct boot_info *dt_from_source(const char *fname)
32{
33 the_boot_info = NULL;
34 treesource_error = 0;
35
35 srcpos_file = dtc_open_file(fname, NULL);
36 yyin = srcpos_file->file;
36 srcfile_push(fname);
37 yyin = current_srcfile->f;
38 yylloc.file = current_srcfile;
37
38 if (yyparse() != 0)
39 die("Unable to parse input tree\n");
40
41 if (treesource_error)
42 die("Syntax error parsing input tree\n");
43
44 return the_boot_info;

--- 185 unchanged lines hidden (view full) ---

230
231 fprintf(f, ";\n");
232}
233
234static void write_tree_source_node(FILE *f, struct node *tree, int level)
235{
236 struct property *prop;
237 struct node *child;
39
40 if (yyparse() != 0)
41 die("Unable to parse input tree\n");
42
43 if (treesource_error)
44 die("Syntax error parsing input tree\n");
45
46 return the_boot_info;

--- 185 unchanged lines hidden (view full) ---

232
233 fprintf(f, ";\n");
234}
235
236static void write_tree_source_node(FILE *f, struct node *tree, int level)
237{
238 struct property *prop;
239 struct node *child;
240 struct label *l;
238
239 write_prefix(f, level);
241
242 write_prefix(f, level);
240 if (tree->label)
241 fprintf(f, "%s: ", tree->label);
243 for_each_label(tree->labels, l)
244 fprintf(f, "%s: ", l->label);
242 if (tree->name && (*tree->name))
243 fprintf(f, "%s {\n", tree->name);
244 else
245 fprintf(f, "/ {\n");
246
247 for_each_property(tree, prop) {
248 write_prefix(f, level+1);
245 if (tree->name && (*tree->name))
246 fprintf(f, "%s {\n", tree->name);
247 else
248 fprintf(f, "/ {\n");
249
250 for_each_property(tree, prop) {
251 write_prefix(f, level+1);
249 if (prop->label)
250 fprintf(f, "%s: ", prop->label);
252 for_each_label(prop->labels, l)
253 fprintf(f, "%s: ", l->label);
251 fprintf(f, "%s", prop->name);
252 write_propval(f, prop);
253 }
254 for_each_child(tree, child) {
255 fprintf(f, "\n");
256 write_tree_source_node(f, child, level+1);
257 }
258 write_prefix(f, level);
259 fprintf(f, "};\n");
260}
261
262
263void dt_to_source(FILE *f, struct boot_info *bi)
264{
265 struct reserve_info *re;
266
267 fprintf(f, "/dts-v1/;\n\n");
268
269 for (re = bi->reservelist; re; re = re->next) {
254 fprintf(f, "%s", prop->name);
255 write_propval(f, prop);
256 }
257 for_each_child(tree, child) {
258 fprintf(f, "\n");
259 write_tree_source_node(f, child, level+1);
260 }
261 write_prefix(f, level);
262 fprintf(f, "};\n");
263}
264
265
266void dt_to_source(FILE *f, struct boot_info *bi)
267{
268 struct reserve_info *re;
269
270 fprintf(f, "/dts-v1/;\n\n");
271
272 for (re = bi->reservelist; re; re = re->next) {
270 if (re->label)
271 fprintf(f, "%s: ", re->label);
273 struct label *l;
274
275 for_each_label(re->labels, l)
276 fprintf(f, "%s: ", l->label);
272 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n",
273 (unsigned long long)re->re.address,
274 (unsigned long long)re->re.size);
275 }
276
277 write_tree_source_node(f, bi->dt, 0);
278}
279
277 fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n",
278 (unsigned long long)re->re.address,
279 (unsigned long long)re->re.size);
280 }
281
282 write_tree_source_node(f, bi->dt, 0);
283}
284