2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
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.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #define FTF_FULLPATH 0x1
25 #define FTF_VARALIGN 0x2
26 #define FTF_NAMEPROPS 0x4
27 #define FTF_BOOTCPUID 0x8
28 #define FTF_STRTABSIZE 0x10
29 #define FTF_STRUCTSIZE 0x20
32 static struct version_info {
34 int last_comp_version;
39 FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS},
41 FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID},
43 FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID|FTF_STRTABSIZE},
45 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS},
46 {17, 16, FDT_V17_SIZE,
47 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
51 void (*cell)(void *, cell_t);
52 void (*string)(void *, char *, int);
53 void (*align)(void *, int);
54 void (*data)(void *, struct data);
55 void (*beginnode)(void *, const char *);
56 void (*endnode)(void *, const char *);
57 void (*property)(void *, const char *);
60 static void bin_emit_cell(void *e, cell_t val)
62 struct data *dtbuf = e;
64 *dtbuf = data_append_cell(*dtbuf, val);
67 static void bin_emit_string(void *e, char *str, int len)
69 struct data *dtbuf = e;
74 *dtbuf = data_append_data(*dtbuf, str, len);
75 *dtbuf = data_append_byte(*dtbuf, '\0');
78 static void bin_emit_align(void *e, int a)
80 struct data *dtbuf = e;
82 *dtbuf = data_append_align(*dtbuf, a);
85 static void bin_emit_data(void *e, struct data d)
87 struct data *dtbuf = e;
89 *dtbuf = data_append_data(*dtbuf, d.val, d.len);
92 static void bin_emit_beginnode(void *e, const char *label)
94 bin_emit_cell(e, FDT_BEGIN_NODE);
97 static void bin_emit_endnode(void *e, const char *label)
99 bin_emit_cell(e, FDT_END_NODE);
102 static void bin_emit_property(void *e, const char *label)
104 bin_emit_cell(e, FDT_PROP);
107 static struct emitter bin_emitter = {
108 .cell = bin_emit_cell,
109 .string = bin_emit_string,
110 .align = bin_emit_align,
111 .data = bin_emit_data,
112 .beginnode = bin_emit_beginnode,
113 .endnode = bin_emit_endnode,
114 .property = bin_emit_property,
117 static void emit_label(FILE *f, const char *prefix, const char *label)
119 fprintf(f, "\t.globl\t%s_%s\n", prefix, label);
120 fprintf(f, "%s_%s:\n", prefix, label);
121 fprintf(f, "_%s_%s:\n", prefix, label);
124 static void emit_offset_label(FILE *f, const char *label, int offset)
126 fprintf(f, "\t.globl\t%s\n", label);
127 fprintf(f, "%s\t= . + %d\n", label, offset);
130 #define ASM_EMIT_BELONG(f, fmt, ...) \
132 fprintf((f), "\t.byte\t((" fmt ") >> 24) & 0xff\n", __VA_ARGS__); \
133 fprintf((f), "\t.byte\t((" fmt ") >> 16) & 0xff\n", __VA_ARGS__); \
134 fprintf((f), "\t.byte\t((" fmt ") >> 8) & 0xff\n", __VA_ARGS__); \
135 fprintf((f), "\t.byte\t(" fmt ") & 0xff\n", __VA_ARGS__); \
138 static void asm_emit_cell(void *e, cell_t val)
142 fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n",
143 (val >> 24) & 0xff, (val >> 16) & 0xff,
144 (val >> 8) & 0xff, val & 0xff);
147 static void asm_emit_string(void *e, char *str, int len)
158 fprintf(f, "\t.string\t\"%s\"\n", str);
165 static void asm_emit_align(void *e, int a)
169 fprintf(f, "\t.balign\t%d, 0\n", a);
172 static void asm_emit_data(void *e, struct data d)
176 struct marker *m = d.markers;
178 for_each_marker_of_type(m, LABEL)
179 emit_offset_label(f, m->ref, m->offset);
181 while ((d.len - off) >= sizeof(uint32_t)) {
182 asm_emit_cell(e, fdt32_to_cpu(*((uint32_t *)(d.val+off))));
183 off += sizeof(uint32_t);
186 while ((d.len - off) >= 1) {
187 fprintf(f, "\t.byte\t0x%hhx\n", d.val[off]);
191 assert(off == d.len);
194 static void asm_emit_beginnode(void *e, const char *label)
199 fprintf(f, "\t.globl\t%s\n", label);
200 fprintf(f, "%s:\n", label);
202 fprintf(f, "\t/* FDT_BEGIN_NODE */\n");
203 asm_emit_cell(e, FDT_BEGIN_NODE);
206 static void asm_emit_endnode(void *e, const char *label)
210 fprintf(f, "\t/* FDT_END_NODE */\n");
211 asm_emit_cell(e, FDT_END_NODE);
213 fprintf(f, "\t.globl\t%s_end\n", label);
214 fprintf(f, "%s_end:\n", label);
218 static void asm_emit_property(void *e, const char *label)
223 fprintf(f, "\t.globl\t%s\n", label);
224 fprintf(f, "%s:\n", label);
226 fprintf(f, "\t/* FDT_PROP */\n");
227 asm_emit_cell(e, FDT_PROP);
230 static struct emitter asm_emitter = {
231 .cell = asm_emit_cell,
232 .string = asm_emit_string,
233 .align = asm_emit_align,
234 .data = asm_emit_data,
235 .beginnode = asm_emit_beginnode,
236 .endnode = asm_emit_endnode,
237 .property = asm_emit_property,
240 static int stringtable_insert(struct data *d, const char *str)
244 /* FIXME: do this more efficiently? */
246 for (i = 0; i < d->len; i++) {
247 if (streq(str, d->val + i))
251 *d = data_append_data(*d, str, strlen(str)+1);
255 static void flatten_tree(struct node *tree, struct emitter *emit,
256 void *etarget, struct data *strbuf,
257 struct version_info *vi)
259 struct property *prop;
261 int seen_name_prop = 0;
263 emit->beginnode(etarget, tree->label);
265 if (vi->flags & FTF_FULLPATH)
266 emit->string(etarget, tree->fullpath, 0);
268 emit->string(etarget, tree->name, 0);
270 emit->align(etarget, sizeof(cell_t));
272 for_each_property(tree, prop) {
275 if (streq(prop->name, "name"))
278 nameoff = stringtable_insert(strbuf, prop->name);
280 emit->property(etarget, prop->label);
281 emit->cell(etarget, prop->val.len);
282 emit->cell(etarget, nameoff);
284 if ((vi->flags & FTF_VARALIGN) && (prop->val.len >= 8))
285 emit->align(etarget, 8);
287 emit->data(etarget, prop->val);
288 emit->align(etarget, sizeof(cell_t));
291 if ((vi->flags & FTF_NAMEPROPS) && !seen_name_prop) {
292 emit->property(etarget, NULL);
293 emit->cell(etarget, tree->basenamelen+1);
294 emit->cell(etarget, stringtable_insert(strbuf, "name"));
296 if ((vi->flags & FTF_VARALIGN) && ((tree->basenamelen+1) >= 8))
297 emit->align(etarget, 8);
299 emit->string(etarget, tree->name, tree->basenamelen);
300 emit->align(etarget, sizeof(cell_t));
303 for_each_child(tree, child) {
304 flatten_tree(child, emit, etarget, strbuf, vi);
307 emit->endnode(etarget, tree->label);
310 static struct data flatten_reserve_list(struct reserve_info *reservelist,
311 struct version_info *vi)
313 struct reserve_info *re;
314 struct data d = empty_data;
315 static struct fdt_reserve_entry null_re = {0,0};
318 for (re = reservelist; re; re = re->next) {
319 d = data_append_re(d, &re->re);
322 * Add additional reserved slots if the user asked for them.
324 for (j = 0; j < reservenum; j++) {
325 d = data_append_re(d, &null_re);
331 static void make_fdt_header(struct fdt_header *fdt,
332 struct version_info *vi,
333 int reservesize, int dtsize, int strsize,
338 reservesize += sizeof(struct fdt_reserve_entry);
340 memset(fdt, 0xff, sizeof(*fdt));
342 fdt->magic = cpu_to_fdt32(FDT_MAGIC);
343 fdt->version = cpu_to_fdt32(vi->version);
344 fdt->last_comp_version = cpu_to_fdt32(vi->last_comp_version);
346 /* Reserve map should be doubleword aligned */
347 reserve_off = ALIGN(vi->hdr_size, 8);
349 fdt->off_mem_rsvmap = cpu_to_fdt32(reserve_off);
350 fdt->off_dt_struct = cpu_to_fdt32(reserve_off + reservesize);
351 fdt->off_dt_strings = cpu_to_fdt32(reserve_off + reservesize
353 fdt->totalsize = cpu_to_fdt32(reserve_off + reservesize + dtsize + strsize);
355 if (vi->flags & FTF_BOOTCPUID)
356 fdt->boot_cpuid_phys = cpu_to_fdt32(boot_cpuid_phys);
357 if (vi->flags & FTF_STRTABSIZE)
358 fdt->size_dt_strings = cpu_to_fdt32(strsize);
359 if (vi->flags & FTF_STRUCTSIZE)
360 fdt->size_dt_struct = cpu_to_fdt32(dtsize);
363 void dt_to_blob(FILE *f, struct boot_info *bi, int version)
365 struct version_info *vi = NULL;
367 struct data blob = empty_data;
368 struct data reservebuf = empty_data;
369 struct data dtbuf = empty_data;
370 struct data strbuf = empty_data;
371 struct fdt_header fdt;
374 for (i = 0; i < ARRAY_SIZE(version_table); i++) {
375 if (version_table[i].version == version)
376 vi = &version_table[i];
379 die("Unknown device tree blob version %d\n", version);
381 flatten_tree(bi->dt, &bin_emitter, &dtbuf, &strbuf, vi);
382 bin_emit_cell(&dtbuf, FDT_END);
384 reservebuf = flatten_reserve_list(bi->reservelist, vi);
387 make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
388 bi->boot_cpuid_phys);
391 * If the user asked for more space than is used, adjust the totalsize.
394 padlen = minsize - fdt32_to_cpu(fdt.totalsize);
395 if ((padlen < 0) && (quiet < 1))
397 "Warning: blob size %d >= minimum size %d\n",
398 fdt32_to_cpu(fdt.totalsize), minsize);
405 int tsize = fdt32_to_cpu(fdt.totalsize);
407 fdt.totalsize = cpu_to_fdt32(tsize);
411 * Assemble the blob: start with the header, add with alignment
412 * the reserve buffer, add the reserve map terminating zeroes,
413 * the device tree itself, and finally the strings.
415 blob = data_append_data(blob, &fdt, vi->hdr_size);
416 blob = data_append_align(blob, 8);
417 blob = data_merge(blob, reservebuf);
418 blob = data_append_zeroes(blob, sizeof(struct fdt_reserve_entry));
419 blob = data_merge(blob, dtbuf);
420 blob = data_merge(blob, strbuf);
423 * If the user asked for more space than is used, pad out the blob.
426 blob = data_append_zeroes(blob, padlen);
428 if (fwrite(blob.val, blob.len, 1, f) != 1) {
430 die("Error writing device tree blob: %s\n",
433 die("Short write on device tree blob\n");
437 * data_merge() frees the right-hand element so only the blob
438 * remains to be freed.
443 static void dump_stringtable_asm(FILE *f, struct data strbuf)
450 while (p < (strbuf.val + strbuf.len)) {
452 fprintf(f, "\t.string \"%s\"\n", p);
457 void dt_to_asm(FILE *f, struct boot_info *bi, int version)
459 struct version_info *vi = NULL;
461 struct data strbuf = empty_data;
462 struct reserve_info *re;
463 const char *symprefix = "dt";
465 for (i = 0; i < ARRAY_SIZE(version_table); i++) {
466 if (version_table[i].version == version)
467 vi = &version_table[i];
470 die("Unknown device tree blob version %d\n", version);
472 fprintf(f, "/* autogenerated by dtc, do not edit */\n\n");
474 emit_label(f, symprefix, "blob_start");
475 emit_label(f, symprefix, "header");
476 fprintf(f, "\t/* magic */\n");
477 asm_emit_cell(f, FDT_MAGIC);
478 fprintf(f, "\t/* totalsize */\n");
479 ASM_EMIT_BELONG(f, "_%s_blob_abs_end - _%s_blob_start",
480 symprefix, symprefix);
481 fprintf(f, "\t/* off_dt_struct */\n");
482 ASM_EMIT_BELONG(f, "_%s_struct_start - _%s_blob_start",
483 symprefix, symprefix);
484 fprintf(f, "\t/* off_dt_strings */\n");
485 ASM_EMIT_BELONG(f, "_%s_strings_start - _%s_blob_start",
486 symprefix, symprefix);
487 fprintf(f, "\t/* off_mem_rsvmap */\n");
488 ASM_EMIT_BELONG(f, "_%s_reserve_map - _%s_blob_start",
489 symprefix, symprefix);
490 fprintf(f, "\t/* version */\n");
491 asm_emit_cell(f, vi->version);
492 fprintf(f, "\t/* last_comp_version */\n");
493 asm_emit_cell(f, vi->last_comp_version);
495 if (vi->flags & FTF_BOOTCPUID) {
496 fprintf(f, "\t/* boot_cpuid_phys */\n");
497 asm_emit_cell(f, bi->boot_cpuid_phys);
500 if (vi->flags & FTF_STRTABSIZE) {
501 fprintf(f, "\t/* size_dt_strings */\n");
502 ASM_EMIT_BELONG(f, "_%s_strings_end - _%s_strings_start",
503 symprefix, symprefix);
506 if (vi->flags & FTF_STRUCTSIZE) {
507 fprintf(f, "\t/* size_dt_struct */\n");
508 ASM_EMIT_BELONG(f, "_%s_struct_end - _%s_struct_start",
509 symprefix, symprefix);
513 * Reserve map entries.
514 * Align the reserve map to a doubleword boundary.
515 * Each entry is an (address, size) pair of u64 values.
516 * Always supply a zero-sized temination entry.
518 asm_emit_align(f, 8);
519 emit_label(f, symprefix, "reserve_map");
521 fprintf(f, "/* Memory reserve map from source file */\n");
524 * Use .long on high and low halfs of u64s to avoid .quad
525 * as it appears .quad isn't available in some assemblers.
527 for (re = bi->reservelist; re; re = re->next) {
529 fprintf(f, "\t.globl\t%s\n", re->label);
530 fprintf(f, "%s:\n", re->label);
532 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.address >> 32));
533 ASM_EMIT_BELONG(f, "0x%08x",
534 (unsigned int)(re->re.address & 0xffffffff));
535 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size >> 32));
536 ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size & 0xffffffff));
538 for (i = 0; i < reservenum; i++) {
539 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n");
542 fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n");
544 emit_label(f, symprefix, "struct_start");
545 flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi);
547 fprintf(f, "\t/* FDT_END */\n");
548 asm_emit_cell(f, FDT_END);
549 emit_label(f, symprefix, "struct_end");
551 emit_label(f, symprefix, "strings_start");
552 dump_stringtable_asm(f, strbuf);
553 emit_label(f, symprefix, "strings_end");
555 emit_label(f, symprefix, "blob_end");
558 * If the user asked for more space than is used, pad it out.
561 fprintf(f, "\t.space\t%d - (_%s_blob_end - _%s_blob_start), 0\n",
562 minsize, symprefix, symprefix);
565 fprintf(f, "\t.space\t%d, 0\n", padsize);
567 emit_label(f, symprefix, "blob_abs_end");
573 char *base, *limit, *ptr;
576 static void inbuf_init(struct inbuf *inb, void *base, void *limit)
580 inb->ptr = inb->base;
583 static void flat_read_chunk(struct inbuf *inb, void *p, int len)
585 if ((inb->ptr + len) > inb->limit)
586 die("Premature end of data parsing flat device tree\n");
588 memcpy(p, inb->ptr, len);
593 static uint32_t flat_read_word(struct inbuf *inb)
597 assert(((inb->ptr - inb->base) % sizeof(val)) == 0);
599 flat_read_chunk(inb, &val, sizeof(val));
601 return fdt32_to_cpu(val);
604 static void flat_realign(struct inbuf *inb, int align)
606 int off = inb->ptr - inb->base;
608 inb->ptr = inb->base + ALIGN(off, align);
609 if (inb->ptr > inb->limit)
610 die("Premature end of data parsing flat device tree\n");
613 static char *flat_read_string(struct inbuf *inb)
616 const char *p = inb->ptr;
621 die("Premature end of data parsing flat device tree\n");
623 } while ((*p++) != '\0');
625 str = xstrdup(inb->ptr);
629 flat_realign(inb, sizeof(uint32_t));
634 static struct data flat_read_data(struct inbuf *inb, int len)
636 struct data d = empty_data;
641 d = data_grow_for(d, len);
644 flat_read_chunk(inb, d.val, len);
646 flat_realign(inb, sizeof(uint32_t));
651 static char *flat_read_stringtable(struct inbuf *inb, int offset)
655 p = inb->base + offset;
657 if (p >= inb->limit || p < inb->base)
658 die("String offset %d overruns string table\n",
667 return xstrdup(inb->base + offset);
670 static struct property *flat_read_property(struct inbuf *dtbuf,
671 struct inbuf *strbuf, int flags)
673 uint32_t proplen, stroff;
677 proplen = flat_read_word(dtbuf);
678 stroff = flat_read_word(dtbuf);
680 name = flat_read_stringtable(strbuf, stroff);
682 if ((flags & FTF_VARALIGN) && (proplen >= 8))
683 flat_realign(dtbuf, 8);
685 val = flat_read_data(dtbuf, proplen);
687 return build_property(name, val, NULL);
691 static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
693 struct reserve_info *reservelist = NULL;
694 struct reserve_info *new;
696 struct fdt_reserve_entry re;
699 * Each entry is a pair of u64 (addr, size) values for 4 cell_t's.
700 * List terminates at an entry with size equal to zero.
702 * First pass, count entries.
706 flat_read_chunk(inb, &re, sizeof(re));
707 re.address = fdt64_to_cpu(re.address);
708 re.size = fdt64_to_cpu(re.size);
712 new = build_reserve_entry(re.address, re.size, NULL);
713 reservelist = add_reserve_entry(reservelist, new);
720 static char *nodename_from_path(const char *ppath, const char *cpath)
724 plen = strlen(ppath);
726 if (!strneq(ppath, cpath, plen))
727 die("Path \"%s\" is not valid as a child of \"%s\"\n",
730 /* root node is a special case */
731 if (!streq(ppath, "/"))
734 return xstrdup(cpath + plen);
737 static struct node *unflatten_tree(struct inbuf *dtbuf,
738 struct inbuf *strbuf,
739 const char *parent_flatname, int flags)
745 node = build_node(NULL, NULL);
747 flatname = flat_read_string(dtbuf);
749 if (flags & FTF_FULLPATH)
750 node->name = nodename_from_path(parent_flatname, flatname);
752 node->name = flatname;
755 struct property *prop;
758 val = flat_read_word(dtbuf);
762 fprintf(stderr, "Warning: Flat tree input has "
763 "subnodes preceding a property.\n");
764 prop = flat_read_property(dtbuf, strbuf, flags);
765 add_property(node, prop);
769 child = unflatten_tree(dtbuf,strbuf, flatname, flags);
770 add_child(node, child);
777 die("Premature FDT_END in device tree blob\n");
781 if (!(flags & FTF_NOPS))
782 fprintf(stderr, "Warning: NOP tag found in flat tree"
789 die("Invalid opcode word %08x in device tree blob\n",
792 } while (val != FDT_END_NODE);
798 struct boot_info *dt_from_blob(const char *fname)
800 struct dtc_file *dtcf;
801 uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys;
802 uint32_t off_dt, off_str, off_mem_rsvmap;
805 struct fdt_header *fdt;
807 struct inbuf dtbuf, strbuf;
808 struct inbuf memresvbuf;
810 struct reserve_info *reservelist;
815 dtcf = dtc_open_file(fname, NULL);
817 rc = fread(&magic, sizeof(magic), 1, dtcf->file);
818 if (ferror(dtcf->file))
819 die("Error reading DT blob magic number: %s\n",
822 if (feof(dtcf->file))
823 die("EOF reading DT blob magic number\n");
825 die("Mysterious short read reading magic number\n");
828 magic = fdt32_to_cpu(magic);
829 if (magic != FDT_MAGIC)
830 die("Blob has incorrect magic number\n");
832 rc = fread(&totalsize, sizeof(totalsize), 1, dtcf->file);
833 if (ferror(dtcf->file))
834 die("Error reading DT blob size: %s\n", strerror(errno));
836 if (feof(dtcf->file))
837 die("EOF reading DT blob size\n");
839 die("Mysterious short read reading blob size\n");
842 totalsize = fdt32_to_cpu(totalsize);
843 if (totalsize < FDT_V1_SIZE)
844 die("DT blob size (%d) is too small\n", totalsize);
846 blob = xmalloc(totalsize);
848 fdt = (struct fdt_header *)blob;
849 fdt->magic = cpu_to_fdt32(magic);
850 fdt->totalsize = cpu_to_fdt32(totalsize);
852 sizeleft = totalsize - sizeof(magic) - sizeof(totalsize);
853 p = blob + sizeof(magic) + sizeof(totalsize);
856 if (feof(dtcf->file))
857 die("EOF before reading %d bytes of DT blob\n",
860 rc = fread(p, 1, sizeleft, dtcf->file);
861 if (ferror(dtcf->file))
862 die("Error reading DT blob: %s\n",
869 off_dt = fdt32_to_cpu(fdt->off_dt_struct);
870 off_str = fdt32_to_cpu(fdt->off_dt_strings);
871 off_mem_rsvmap = fdt32_to_cpu(fdt->off_mem_rsvmap);
872 version = fdt32_to_cpu(fdt->version);
873 boot_cpuid_phys = fdt32_to_cpu(fdt->boot_cpuid_phys);
875 if (off_mem_rsvmap >= totalsize)
876 die("Mem Reserve structure offset exceeds total size\n");
878 if (off_dt >= totalsize)
879 die("DT structure offset exceeds total size\n");
881 if (off_str > totalsize)
882 die("String table offset exceeds total size\n");
885 uint32_t size_str = fdt32_to_cpu(fdt->size_dt_strings);
886 if (off_str+size_str > totalsize)
887 die("String table extends past total size\n");
888 inbuf_init(&strbuf, blob + off_str, blob + off_str + size_str);
890 inbuf_init(&strbuf, blob + off_str, blob + totalsize);
894 size_dt = fdt32_to_cpu(fdt->size_dt_struct);
895 if (off_dt+size_dt > totalsize)
896 die("Structure block extends past total size\n");
900 flags |= FTF_FULLPATH | FTF_NAMEPROPS | FTF_VARALIGN;
905 inbuf_init(&memresvbuf,
906 blob + off_mem_rsvmap, blob + totalsize);
907 inbuf_init(&dtbuf, blob + off_dt, blob + totalsize);
909 reservelist = flat_read_mem_reserve(&memresvbuf);
911 val = flat_read_word(&dtbuf);
913 if (val != FDT_BEGIN_NODE)
914 die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\n", val);
916 tree = unflatten_tree(&dtbuf, &strbuf, "", flags);
918 val = flat_read_word(&dtbuf);
920 die("Device tree blob doesn't end with FDT_END\n");
924 dtc_close_file(dtcf);
926 return build_boot_info(reservelist, tree, boot_cpuid_phys);