41 die(
"Unable to parse input tree\n");
44 die(
"Syntax error parsing input tree\n");
49 static void write_prefix(FILE *
f,
int level)
53 for (i = 0; i <
level; i++)
57 static int isstring(
char c)
61 ||
strchr(
"\a\b\t\n\v\f\r", c));
64 static void write_propval_string(FILE *f,
struct data val)
72 while (m && (m->
offset == 0)) {
79 for (i = 0; i < (val.
len-1); i++) {
112 while (m && (m->
offset < i)) {
137 static void write_propval_cells(FILE *f,
struct data val)
139 void *propend = val.
val + val.
len;
145 while (m && (m->
offset <= ((
char *)cp - val.
val))) {
154 if ((
void *)cp >= propend)
167 static void write_propval_bytes(FILE *f,
struct data val)
169 void *propend = val.
val + val.
len;
170 const char *bp = val.
val;
175 while (m && (m->
offset == (bp-val.
val))) {
182 if ((
const void *)bp >= propend)
195 static void write_propval(FILE *f,
struct property *prop)
198 const char *
p = prop->
val.val;
200 int nnotstring = 0, nnul = 0;
201 int nnotstringlbl = 0, nnotcelllbl = 0;
209 for (i = 0; i < len; i++) {
210 if (! isstring(p[i]))
224 if ((p[len-1] ==
'\0') && (nnotstring == 0) && (nnul < (len-nnul))
225 && (nnotstringlbl == 0)) {
226 write_propval_string(f, prop->
val);
227 }
else if (((len %
sizeof(
cell_t)) == 0) && (nnotcelllbl == 0)) {
228 write_propval_cells(f, prop->
val);
230 write_propval_bytes(f, prop->
val);
236 static void write_tree_source_node(FILE *f,
struct node *
tree,
int level)
242 write_prefix(f, level);
246 fprintf(f, "%s {\n
", tree->name);
250 for_each_property(tree, prop) {
251 write_prefix(f, level+1);
252 for_each_label(prop->labels, l)
253 fprintf(f, "%s:
", l->label);
254 fprintf(f, "%s
", prop->name);
255 write_propval(f, prop);
257 for_each_child(tree, child) {
259 write_tree_source_node(f, child, level+1);
261 write_prefix(f, level);
266 void dt_to_source(FILE *f, struct boot_info *bi)
268 struct reserve_info *re;
270 fprintf(f, "/dts-
v1/;\n\n
");
272 for (re = bi->reservelist; re; re = re->next) {
275 for_each_label(re->labels, l)
276 fprintf(f, "%s:
", l->label);
277 fprintf(f, "/memreserve/\t0x%016llx 0
x%016llx;\n
",
278 (unsigned long long)re->re.address,
279 (unsigned long long)re->re.size);
282 write_tree_source_node(f, bi->dt, 0);