dtc: Use libfdt/fdt.h instead of flat_dt.h

In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and
constants relating to the flattened device tree format derived from
asm-powerpc/prom.h in the kernel.  The former is used in dtc, the
latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that
throughout, removing flat_dt.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2007-09-26 13:11:05 +10:00 committed by Jon Loeliger
parent 63dc9c7113
commit fb7c7acf5a
6 changed files with 89 additions and 140 deletions

4
data.c
View file

@ -246,9 +246,9 @@ struct data data_append_cell(struct data d, cell_t word)
return data_append_data(d, &beword, sizeof(beword)); return data_append_data(d, &beword, sizeof(beword));
} }
struct data data_append_re(struct data d, struct reserve_entry *re) struct data data_append_re(struct data d, struct fdt_reserve_entry *re)
{ {
struct reserve_entry bere; struct fdt_reserve_entry bere;
bere.address = cpu_to_be64(re->address); bere.address = cpu_to_be64(re->address);
bere.size = cpu_to_be64(re->size); bere.size = cpu_to_be64(re->size);

4
dtc.c
View file

@ -92,7 +92,7 @@ static void __attribute__ ((noreturn)) usage(void)
fprintf(stderr, "\t\t\tdtb - device tree blob\n"); fprintf(stderr, "\t\t\tdtb - device tree blob\n");
fprintf(stderr, "\t\t\tasm - assembler source\n"); fprintf(stderr, "\t\t\tasm - assembler source\n");
fprintf(stderr, "\t-V <output version>\n"); fprintf(stderr, "\t-V <output version>\n");
fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", OF_DEFAULT_VERSION); fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION);
fprintf(stderr, "\t-R <number>\n"); fprintf(stderr, "\t-R <number>\n");
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n"); fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
fprintf(stderr, "\t-S <bytes>\n"); fprintf(stderr, "\t-S <bytes>\n");
@ -117,7 +117,7 @@ int main(int argc, char *argv[])
int opt; int opt;
FILE *inf = NULL; FILE *inf = NULL;
FILE *outf = NULL; FILE *outf = NULL;
int outversion = OF_DEFAULT_VERSION; int outversion = DEFAULT_FDT_VERSION;
int boot_cpuid_phys = 0xfeedbeef; int boot_cpuid_phys = 0xfeedbeef;
quiet = 0; quiet = 0;

7
dtc.h
View file

@ -34,8 +34,9 @@
#include <endian.h> #include <endian.h>
#include <byteswap.h> #include <byteswap.h>
#include "flat_dt.h" #include <fdt.h>
#define DEFAULT_FDT_VERSION 17
/* /*
* Command line options * Command line options
*/ */
@ -128,7 +129,7 @@ struct data data_copy_file(FILE *f, size_t len);
struct data data_append_data(struct data d, void *p, int len); struct data data_append_data(struct data d, void *p, int len);
struct data data_merge(struct data d1, struct data d2); struct data data_merge(struct data d1, struct data d2);
struct data data_append_cell(struct data d, cell_t word); struct data data_append_cell(struct data d, cell_t word);
struct data data_append_re(struct data d, struct reserve_entry *re); struct data data_append_re(struct data d, struct fdt_reserve_entry *re);
struct data data_append_addr(struct data d, u64 addr); struct data data_append_addr(struct data d, u64 addr);
struct data data_append_byte(struct data d, uint8_t byte); struct data data_append_byte(struct data d, uint8_t byte);
struct data data_append_zeroes(struct data d, int len); struct data data_append_zeroes(struct data d, int len);
@ -192,7 +193,7 @@ int check_device_tree(struct node *dt, int outversion, int boot_cpuid_phys);
/* Boot info (tree plus memreserve information */ /* Boot info (tree plus memreserve information */
struct reserve_info { struct reserve_info {
struct reserve_entry re; struct fdt_reserve_entry re;
struct reserve_info *next; struct reserve_info *next;

View file

@ -1,51 +0,0 @@
#ifndef _FLAT_DT_H_
#define _FLAT_DT_H_
#define OF_DEFAULT_VERSION 17
#define OF_DT_HEADER 0xd00dfeed /* 4: version, 4: total size */
#define OF_DT_BEGIN_NODE 0x1 /* Start node: full name */
#define OF_DT_END_NODE 0x2 /* End node */
#define OF_DT_PROP 0x3 /* Property: name off,
size, content */
#define OF_DT_NOP 0x4 /* nop */
#define OF_DT_END 0x9
struct boot_param_header {
uint32_t magic; /* magic word OF_DT_HEADER */
uint32_t totalsize; /* total size of DT block */
uint32_t off_dt_struct; /* offset to structure */
uint32_t off_dt_strings; /* offset to strings */
uint32_t off_mem_rsvmap; /* offset to memory reserve map */
uint32_t version; /* format version */
uint32_t last_comp_version; /* last compatible version */
/* version 2 fields below */
uint32_t boot_cpuid_phys; /* Which physical CPU id we're
booting on */
/* version 3 fields below */
uint32_t size_dt_strings; /* size of the strings block */
/* version 17 fields below */
uint32_t size_dt_struct; /* size of the DT structure block */
};
#define BPH_V1_SIZE (7*sizeof(uint32_t))
#define BPH_V2_SIZE (BPH_V1_SIZE + sizeof(uint32_t))
#define BPH_V3_SIZE (BPH_V2_SIZE + sizeof(uint32_t))
#define BPH_V17_SIZE (BPH_V3_SIZE + sizeof(uint32_t))
struct reserve_entry {
uint64_t address;
uint64_t size;
};
struct flat_dt_property {
uint32_t len;
uint32_t nameoff;
char data[0];
};
#endif /* _FLAT_DT_H_ */

View file

@ -19,7 +19,6 @@
*/ */
#include "dtc.h" #include "dtc.h"
#include "flat_dt.h"
#define FTF_FULLPATH 0x1 #define FTF_FULLPATH 0x1
#define FTF_VARALIGN 0x2 #define FTF_VARALIGN 0x2
@ -35,15 +34,15 @@ static struct version_info {
int hdr_size; int hdr_size;
int flags; int flags;
} version_table[] = { } version_table[] = {
{1, 1, BPH_V1_SIZE, {1, 1, FDT_V1_SIZE,
FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS}, FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS},
{2, 1, BPH_V2_SIZE, {2, 1, FDT_V2_SIZE,
FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID}, FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID},
{3, 1, BPH_V3_SIZE, {3, 1, FDT_V3_SIZE,
FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID|FTF_STRTABSIZE}, FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID|FTF_STRTABSIZE},
{16, 16, BPH_V3_SIZE, {16, 16, FDT_V3_SIZE,
FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS}, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS},
{17, 16, BPH_V17_SIZE, {17, 16, FDT_V17_SIZE,
FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
}; };
@ -91,17 +90,17 @@ static void bin_emit_data(void *e, struct data d)
static void bin_emit_beginnode(void *e, char *label) static void bin_emit_beginnode(void *e, char *label)
{ {
bin_emit_cell(e, OF_DT_BEGIN_NODE); bin_emit_cell(e, FDT_BEGIN_NODE);
} }
static void bin_emit_endnode(void *e, char *label) static void bin_emit_endnode(void *e, char *label)
{ {
bin_emit_cell(e, OF_DT_END_NODE); bin_emit_cell(e, FDT_END_NODE);
} }
static void bin_emit_property(void *e, char *label) static void bin_emit_property(void *e, char *label)
{ {
bin_emit_cell(e, OF_DT_PROP); bin_emit_cell(e, FDT_PROP);
} }
static struct emitter bin_emitter = { static struct emitter bin_emitter = {
@ -199,14 +198,14 @@ static void asm_emit_beginnode(void *e, char *label)
fprintf(f, "\t.globl\t%s\n", label); fprintf(f, "\t.globl\t%s\n", label);
fprintf(f, "%s:\n", label); fprintf(f, "%s:\n", label);
} }
fprintf(f, "\t.long\tOF_DT_BEGIN_NODE\n"); fprintf(f, "\t.long\tFDT_BEGIN_NODE\n");
} }
static void asm_emit_endnode(void *e, char *label) static void asm_emit_endnode(void *e, char *label)
{ {
FILE *f = e; FILE *f = e;
fprintf(f, "\t.long\tOF_DT_END_NODE\n"); fprintf(f, "\t.long\tFDT_END_NODE\n");
if (label) { if (label) {
fprintf(f, "\t.globl\t%s_end\n", label); fprintf(f, "\t.globl\t%s_end\n", label);
fprintf(f, "%s_end:\n", label); fprintf(f, "%s_end:\n", label);
@ -221,7 +220,7 @@ static void asm_emit_property(void *e, char *label)
fprintf(f, "\t.globl\t%s\n", label); fprintf(f, "\t.globl\t%s\n", label);
fprintf(f, "%s:\n", label); fprintf(f, "%s:\n", label);
} }
fprintf(f, "\t.long\tOF_DT_PROP\n"); fprintf(f, "\t.long\tFDT_PROP\n");
} }
static struct emitter asm_emitter = { static struct emitter asm_emitter = {
@ -309,7 +308,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,
{ {
struct reserve_info *re; struct reserve_info *re;
struct data d = empty_data; struct data d = empty_data;
static struct reserve_entry null_re = {0,0}; static struct fdt_reserve_entry null_re = {0,0};
int j; int j;
for (re = reservelist; re; re = re->next) { for (re = reservelist; re; re = re->next) {
@ -325,36 +324,36 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,
return d; return d;
} }
static void make_bph(struct boot_param_header *bph, static void make_fdt_header(struct fdt_header *fdt,
struct version_info *vi, struct version_info *vi,
int reservesize, int dtsize, int strsize, int reservesize, int dtsize, int strsize,
int boot_cpuid_phys) int boot_cpuid_phys)
{ {
int reserve_off; int reserve_off;
reservesize += sizeof(struct reserve_entry); reservesize += sizeof(struct fdt_reserve_entry);
memset(bph, 0xff, sizeof(*bph)); memset(fdt, 0xff, sizeof(*fdt));
bph->magic = cpu_to_be32(OF_DT_HEADER); fdt->magic = cpu_to_be32(FDT_MAGIC);
bph->version = cpu_to_be32(vi->version); fdt->version = cpu_to_be32(vi->version);
bph->last_comp_version = cpu_to_be32(vi->last_comp_version); fdt->last_comp_version = cpu_to_be32(vi->last_comp_version);
/* Reserve map should be doubleword aligned */ /* Reserve map should be doubleword aligned */
reserve_off = ALIGN(vi->hdr_size, 8); reserve_off = ALIGN(vi->hdr_size, 8);
bph->off_mem_rsvmap = cpu_to_be32(reserve_off); fdt->off_mem_rsvmap = cpu_to_be32(reserve_off);
bph->off_dt_struct = cpu_to_be32(reserve_off + reservesize); fdt->off_dt_struct = cpu_to_be32(reserve_off + reservesize);
bph->off_dt_strings = cpu_to_be32(reserve_off + reservesize fdt->off_dt_strings = cpu_to_be32(reserve_off + reservesize
+ dtsize); + dtsize);
bph->totalsize = cpu_to_be32(reserve_off + reservesize + dtsize + strsize); fdt->totalsize = cpu_to_be32(reserve_off + reservesize + dtsize + strsize);
if (vi->flags & FTF_BOOTCPUID) if (vi->flags & FTF_BOOTCPUID)
bph->boot_cpuid_phys = cpu_to_be32(boot_cpuid_phys); fdt->boot_cpuid_phys = cpu_to_be32(boot_cpuid_phys);
if (vi->flags & FTF_STRTABSIZE) if (vi->flags & FTF_STRTABSIZE)
bph->size_dt_strings = cpu_to_be32(strsize); fdt->size_dt_strings = cpu_to_be32(strsize);
if (vi->flags & FTF_STRUCTSIZE) if (vi->flags & FTF_STRUCTSIZE)
bph->size_dt_struct = cpu_to_be32(dtsize); fdt->size_dt_struct = cpu_to_be32(dtsize);
} }
void dt_to_blob(FILE *f, struct boot_info *bi, int version, void dt_to_blob(FILE *f, struct boot_info *bi, int version,
@ -366,7 +365,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version,
struct data reservebuf = empty_data; struct data reservebuf = empty_data;
struct data dtbuf = empty_data; struct data dtbuf = empty_data;
struct data strbuf = empty_data; struct data strbuf = empty_data;
struct boot_param_header bph; struct fdt_header fdt;
int padlen; int padlen;
for (i = 0; i < ARRAY_SIZE(version_table); i++) { for (i = 0; i < ARRAY_SIZE(version_table); i++) {
@ -377,25 +376,25 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version,
die("Unknown device tree blob version %d\n", version); die("Unknown device tree blob version %d\n", version);
flatten_tree(bi->dt, &bin_emitter, &dtbuf, &strbuf, vi); flatten_tree(bi->dt, &bin_emitter, &dtbuf, &strbuf, vi);
bin_emit_cell(&dtbuf, OF_DT_END); bin_emit_cell(&dtbuf, FDT_END);
reservebuf = flatten_reserve_list(bi->reservelist, vi); reservebuf = flatten_reserve_list(bi->reservelist, vi);
/* Make header */ /* Make header */
make_bph(&bph, vi, reservebuf.len, dtbuf.len, strbuf.len, make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
boot_cpuid_phys); boot_cpuid_phys);
/* /*
* If the user asked for more space than is used, adjust the totalsize. * If the user asked for more space than is used, adjust the totalsize.
*/ */
padlen = minsize - be32_to_cpu(bph.totalsize); padlen = minsize - be32_to_cpu(fdt.totalsize);
if (padlen > 0) { if (padlen > 0) {
bph.totalsize = cpu_to_be32(minsize); fdt.totalsize = cpu_to_be32(minsize);
} else { } else {
if ((minsize > 0) && (quiet < 1)) if ((minsize > 0) && (quiet < 1))
fprintf(stderr, fprintf(stderr,
"Warning: blob size %d >= minimum size %d\n", "Warning: blob size %d >= minimum size %d\n",
be32_to_cpu(bph.totalsize), minsize); be32_to_cpu(fdt.totalsize), minsize);
} }
/* /*
@ -403,10 +402,10 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version,
* the reserve buffer, add the reserve map terminating zeroes, * the reserve buffer, add the reserve map terminating zeroes,
* the device tree itself, and finally the strings. * the device tree itself, and finally the strings.
*/ */
blob = data_append_data(blob, &bph, sizeof(bph)); blob = data_append_data(blob, &fdt, sizeof(fdt));
blob = data_append_align(blob, 8); blob = data_append_align(blob, 8);
blob = data_merge(blob, reservebuf); blob = data_merge(blob, reservebuf);
blob = data_append_zeroes(blob, sizeof(struct reserve_entry)); blob = data_append_zeroes(blob, sizeof(struct fdt_reserve_entry));
blob = data_merge(blob, dtbuf); blob = data_merge(blob, dtbuf);
blob = data_merge(blob, strbuf); blob = data_merge(blob, strbuf);
@ -415,7 +414,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version,
*/ */
if (padlen > 0) { if (padlen > 0) {
blob = data_append_zeroes(blob, padlen); blob = data_append_zeroes(blob, padlen);
bph.totalsize = cpu_to_be32(minsize); fdt.totalsize = cpu_to_be32(minsize);
} }
fwrite(blob.val, blob.len, 1, f); fwrite(blob.val, blob.len, 1, f);
@ -460,16 +459,16 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys)
die("Unknown device tree blob version %d\n", version); die("Unknown device tree blob version %d\n", version);
fprintf(f, "/* autogenerated by dtc, do not edit */\n\n"); fprintf(f, "/* autogenerated by dtc, do not edit */\n\n");
fprintf(f, "#define OF_DT_HEADER 0x%x\n", OF_DT_HEADER); fprintf(f, "#define FDT_MAGIC 0x%x\n", FDT_MAGIC);
fprintf(f, "#define OF_DT_BEGIN_NODE 0x%x\n", OF_DT_BEGIN_NODE); fprintf(f, "#define FDT_BEGIN_NODE 0x%x\n", FDT_BEGIN_NODE);
fprintf(f, "#define OF_DT_END_NODE 0x%x\n", OF_DT_END_NODE); fprintf(f, "#define FDT_END_NODE 0x%x\n", FDT_END_NODE);
fprintf(f, "#define OF_DT_PROP 0x%x\n", OF_DT_PROP); fprintf(f, "#define FDT_PROP 0x%x\n", FDT_PROP);
fprintf(f, "#define OF_DT_END 0x%x\n", OF_DT_END); fprintf(f, "#define FDT_END 0x%x\n", FDT_END);
fprintf(f, "\n"); fprintf(f, "\n");
emit_label(f, symprefix, "blob_start"); emit_label(f, symprefix, "blob_start");
emit_label(f, symprefix, "header"); emit_label(f, symprefix, "header");
fprintf(f, "\t.long\tOF_DT_HEADER\t\t\t\t/* magic */\n"); fprintf(f, "\t.long\tFDT_MAGIC\t\t\t\t/* magic */\n");
fprintf(f, "\t.long\t_%s_blob_abs_end - _%s_blob_start\t/* totalsize */\n", fprintf(f, "\t.long\t_%s_blob_abs_end - _%s_blob_start\t/* totalsize */\n",
symprefix, symprefix); symprefix, symprefix);
fprintf(f, "\t.long\t_%s_struct_start - _%s_blob_start\t/* off_dt_struct */\n", fprintf(f, "\t.long\t_%s_struct_start - _%s_blob_start\t/* off_dt_struct */\n",
@ -529,7 +528,7 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys)
emit_label(f, symprefix, "struct_start"); emit_label(f, symprefix, "struct_start");
flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi); flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi);
fprintf(f, "\t.long\tOF_DT_END\n"); fprintf(f, "\t.long\tFDT_END\n");
emit_label(f, symprefix, "struct_end"); emit_label(f, symprefix, "struct_end");
emit_label(f, symprefix, "strings_start"); emit_label(f, symprefix, "strings_start");
@ -674,7 +673,7 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
struct reserve_info *reservelist = NULL; struct reserve_info *reservelist = NULL;
struct reserve_info *new; struct reserve_info *new;
char *p; char *p;
struct reserve_entry re; struct fdt_reserve_entry re;
/* /*
* Each entry is a pair of u64 (addr, size) values for 4 cell_t's. * Each entry is a pair of u64 (addr, size) values for 4 cell_t's.
@ -778,7 +777,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
val = flat_read_word(dtbuf); val = flat_read_word(dtbuf);
switch (val) { switch (val) {
case OF_DT_PROP: case FDT_PROP:
if (node->children) if (node->children)
fprintf(stderr, "Warning: Flat tree input has " fprintf(stderr, "Warning: Flat tree input has "
"subnodes preceding a property.\n"); "subnodes preceding a property.\n");
@ -786,20 +785,20 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
add_property(node, prop); add_property(node, prop);
break; break;
case OF_DT_BEGIN_NODE: case FDT_BEGIN_NODE:
child = unflatten_tree(dtbuf,strbuf, node->fullpath, child = unflatten_tree(dtbuf,strbuf, node->fullpath,
flags); flags);
add_child(node, child); add_child(node, child);
break; break;
case OF_DT_END_NODE: case FDT_END_NODE:
break; break;
case OF_DT_END: case FDT_END:
die("Premature OF_DT_END in device tree blob\n"); die("Premature FDT_END in device tree blob\n");
break; break;
case OF_DT_NOP: case FDT_NOP:
if (!(flags & FTF_NOPS)) if (!(flags & FTF_NOPS))
fprintf(stderr, "Warning: NOP tag found in flat tree" fprintf(stderr, "Warning: NOP tag found in flat tree"
" version <16\n"); " version <16\n");
@ -811,7 +810,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
die("Invalid opcode word %08x in device tree blob\n", die("Invalid opcode word %08x in device tree blob\n",
val); val);
} }
} while (val != OF_DT_END_NODE); } while (val != FDT_END_NODE);
return node; return node;
} }
@ -823,7 +822,7 @@ struct boot_info *dt_from_blob(FILE *f)
u32 off_dt, off_str, off_mem_rsvmap; u32 off_dt, off_str, off_mem_rsvmap;
int rc; int rc;
char *blob; char *blob;
struct boot_param_header *bph; struct fdt_header *fdt;
char *p; char *p;
struct inbuf dtbuf, strbuf; struct inbuf dtbuf, strbuf;
struct inbuf memresvbuf; struct inbuf memresvbuf;
@ -845,7 +844,7 @@ struct boot_info *dt_from_blob(FILE *f)
} }
magic = be32_to_cpu(magic); magic = be32_to_cpu(magic);
if (magic != OF_DT_HEADER) if (magic != FDT_MAGIC)
die("Blob has incorrect magic number\n"); die("Blob has incorrect magic number\n");
rc = fread(&totalsize, sizeof(totalsize), 1, f); rc = fread(&totalsize, sizeof(totalsize), 1, f);
@ -859,14 +858,14 @@ struct boot_info *dt_from_blob(FILE *f)
} }
totalsize = be32_to_cpu(totalsize); totalsize = be32_to_cpu(totalsize);
if (totalsize < BPH_V1_SIZE) if (totalsize < FDT_V1_SIZE)
die("DT blob size (%d) is too small\n", totalsize); die("DT blob size (%d) is too small\n", totalsize);
blob = xmalloc(totalsize); blob = xmalloc(totalsize);
bph = (struct boot_param_header *)blob; fdt = (struct fdt_header *)blob;
bph->magic = cpu_to_be32(magic); fdt->magic = cpu_to_be32(magic);
bph->totalsize = cpu_to_be32(totalsize); fdt->totalsize = cpu_to_be32(totalsize);
sizeleft = totalsize - sizeof(magic) - sizeof(totalsize); sizeleft = totalsize - sizeof(magic) - sizeof(totalsize);
p = blob + sizeof(magic) + sizeof(totalsize); p = blob + sizeof(magic) + sizeof(totalsize);
@ -885,10 +884,10 @@ struct boot_info *dt_from_blob(FILE *f)
p += rc; p += rc;
} }
off_dt = be32_to_cpu(bph->off_dt_struct); off_dt = be32_to_cpu(fdt->off_dt_struct);
off_str = be32_to_cpu(bph->off_dt_strings); off_str = be32_to_cpu(fdt->off_dt_strings);
off_mem_rsvmap = be32_to_cpu(bph->off_mem_rsvmap); off_mem_rsvmap = be32_to_cpu(fdt->off_mem_rsvmap);
version = be32_to_cpu(bph->version); version = be32_to_cpu(fdt->version);
fprintf(stderr, "\tmagic:\t\t\t0x%x\n", magic); fprintf(stderr, "\tmagic:\t\t\t0x%x\n", magic);
fprintf(stderr, "\ttotalsize:\t\t%d\n", totalsize); fprintf(stderr, "\ttotalsize:\t\t%d\n", totalsize);
@ -897,7 +896,7 @@ struct boot_info *dt_from_blob(FILE *f)
fprintf(stderr, "\toff_mem_rsvmap:\t\t0x%x\n", off_mem_rsvmap); fprintf(stderr, "\toff_mem_rsvmap:\t\t0x%x\n", off_mem_rsvmap);
fprintf(stderr, "\tversion:\t\t0x%x\n", version ); fprintf(stderr, "\tversion:\t\t0x%x\n", version );
fprintf(stderr, "\tlast_comp_version:\t0x%x\n", fprintf(stderr, "\tlast_comp_version:\t0x%x\n",
be32_to_cpu(bph->last_comp_version)); be32_to_cpu(fdt->last_comp_version));
if (off_mem_rsvmap >= totalsize) if (off_mem_rsvmap >= totalsize)
die("Mem Reserve structure offset exceeds total size\n"); die("Mem Reserve structure offset exceeds total size\n");
@ -910,18 +909,18 @@ struct boot_info *dt_from_blob(FILE *f)
if (version >= 2) if (version >= 2)
fprintf(stderr, "\tboot_cpuid_phys:\t0x%x\n", fprintf(stderr, "\tboot_cpuid_phys:\t0x%x\n",
be32_to_cpu(bph->boot_cpuid_phys)); be32_to_cpu(fdt->boot_cpuid_phys));
size_str = -1; size_str = -1;
if (version >= 3) { if (version >= 3) {
size_str = be32_to_cpu(bph->size_dt_strings); size_str = be32_to_cpu(fdt->size_dt_strings);
fprintf(stderr, "\tsize_dt_strings:\t%d\n", size_str); fprintf(stderr, "\tsize_dt_strings:\t%d\n", size_str);
if (off_str+size_str > totalsize) if (off_str+size_str > totalsize)
die("String table extends past total size\n"); die("String table extends past total size\n");
} }
if (version >= 17) { if (version >= 17) {
size_dt = be32_to_cpu(bph->size_dt_struct); size_dt = be32_to_cpu(fdt->size_dt_struct);
fprintf(stderr, "\tsize_dt_struct:\t\t%d\n", size_dt); fprintf(stderr, "\tsize_dt_struct:\t\t%d\n", size_dt);
if (off_dt+size_dt > totalsize) if (off_dt+size_dt > totalsize)
die("Structure block extends past total size\n"); die("Structure block extends past total size\n");
@ -945,14 +944,14 @@ struct boot_info *dt_from_blob(FILE *f)
val = flat_read_word(&dtbuf); val = flat_read_word(&dtbuf);
if (val != OF_DT_BEGIN_NODE) if (val != FDT_BEGIN_NODE)
die("Device tree blob doesn't begin with OF_DT_BEGIN_NODE (begins with 0x%08x)\n", val); die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\n", val);
tree = unflatten_tree(&dtbuf, &strbuf, "", flags); tree = unflatten_tree(&dtbuf, &strbuf, "", flags);
val = flat_read_word(&dtbuf); val = flat_read_word(&dtbuf);
if (val != OF_DT_END) if (val != FDT_END)
die("Device tree blob doesn't end with OF_DT_END\n"); die("Device tree blob doesn't end with FDT_END\n");
free(blob); free(blob);

View file

@ -9,7 +9,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <byteswap.h> #include <byteswap.h>
#include "flat_dt.h" #include <fdt.h>
#define cpu_to_be16(x) htons(x) #define cpu_to_be16(x) htons(x)
#define be16_to_cpu(x) ntohs(x) #define be16_to_cpu(x) ntohs(x)
@ -80,9 +80,9 @@ static void print_data(const void *data, int len)
static void dump_blob(void *blob) static void dump_blob(void *blob)
{ {
struct boot_param_header *bph = blob; struct fdt_header *bph = blob;
struct reserve_entry *p_rsvmap = struct fdt_reserve_entry *p_rsvmap =
(struct reserve_entry *)(blob (struct fdt_reserve_entry *)(blob
+ be32_to_cpu(bph->off_mem_rsvmap)); + be32_to_cpu(bph->off_mem_rsvmap));
char *p_struct = blob + be32_to_cpu(bph->off_dt_struct); char *p_struct = blob + be32_to_cpu(bph->off_dt_struct);
char *p_strings = blob + be32_to_cpu(bph->off_dt_strings); char *p_strings = blob + be32_to_cpu(bph->off_dt_strings);
@ -109,11 +109,11 @@ static void dump_blob(void *blob)
} }
p = p_struct; p = p_struct;
while ((tag = be32_to_cpu(GET_CELL(p))) != OF_DT_END) { while ((tag = be32_to_cpu(GET_CELL(p))) != FDT_END) {
/* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */ /* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
if (tag == OF_DT_BEGIN_NODE) { if (tag == FDT_BEGIN_NODE) {
s = p; s = p;
p = PALIGN(p + strlen(s) + 1, 4); p = PALIGN(p + strlen(s) + 1, 4);
@ -126,19 +126,19 @@ static void dump_blob(void *blob)
continue; continue;
} }
if (tag == OF_DT_END_NODE) { if (tag == FDT_END_NODE) {
depth--; depth--;
printf("%*s};\n", depth * shift, ""); printf("%*s};\n", depth * shift, "");
continue; continue;
} }
if (tag == OF_DT_NOP) { if (tag == FDT_NOP) {
printf("%*s// [NOP]\n", depth * shift, ""); printf("%*s// [NOP]\n", depth * shift, "");
continue; continue;
} }
if (tag != OF_DT_PROP) { if (tag != FDT_PROP) {
fprintf(stderr, "%*s ** Unknown tag 0x%08x\n", depth * shift, "", tag); fprintf(stderr, "%*s ** Unknown tag 0x%08x\n", depth * shift, "", tag);
break; break;
} }