dtc: Rework handling of boot_cpuid_phys

Currently, dtc will put the nonsense value 0xfeedbeef into the
boot_cpuid_phys field of an output blob, unless explicitly given
another value with the -b command line option.  As well as being a
totally unuseful default value, this also means that dtc won't
properly preserve the boot_cpuid_phys field in -I dtb -O dtb mode.

This patch reworks things to improve the boot_cpuid handling.  The new
semantics are that the output's boot_cpuid_phys value is:
	the value given on the command line if -b is used
otherwise
	the value from the input, if in -I dtb mode
otherwise
	0

Implementation-wise we do the following:
	- boot_cpuid_phys is added to struct boot_info, so that
structure now contains all of the blob's semantic information.
	- dt_to_blob() and dt_to_asm() output the cpuid given in
boot_info
	- dt_from_blob() fills in boot_info based on the input blob
	- The other dt_from_*() functions just record 0, but we can
change this easily if e.g. we invent a way of specifying the boot cpu
in the source format.
	- main() overrides the cpuid in the boot_info between input
and output if -b is given

We add some testcases to check this new behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2008-05-16 13:22:57 +10:00 committed by Jon Loeliger
parent a742aade6a
commit 548767f42e
10 changed files with 88 additions and 21 deletions

View file

@ -354,8 +354,7 @@ static void make_fdt_header(struct fdt_header *fdt,
fdt->size_dt_struct = cpu_to_be32(dtsize);
}
void dt_to_blob(FILE *f, struct boot_info *bi, int version,
int boot_cpuid_phys)
void dt_to_blob(FILE *f, struct boot_info *bi, int version)
{
struct version_info *vi = NULL;
int i;
@ -380,7 +379,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version,
/* Make header */
make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
boot_cpuid_phys);
bi->boot_cpuid_phys);
/*
* If the user asked for more space than is used, adjust the totalsize.
@ -446,7 +445,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)
}
}
void dt_to_asm(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys)
void dt_to_asm(FILE *f, struct boot_info *bi, int version)
{
struct version_info *vi = NULL;
int i;
@ -486,7 +485,7 @@ void dt_to_asm(FILE *f, struct boot_info *bi, int version, int boot_cpuid_phys)
if (vi->flags & FTF_BOOTCPUID)
fprintf(f, "\t.long\t%i\t\t\t\t\t/* boot_cpuid_phys */\n",
boot_cpuid_phys);
bi->boot_cpuid_phys);
if (vi->flags & FTF_STRTABSIZE)
fprintf(f, "\t.long\t_%s_strings_end - _%s_strings_start\t/* size_dt_strings */\n",
@ -784,7 +783,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
struct boot_info *dt_from_blob(const char *fname)
{
struct dtc_file *dtcf;
u32 magic, totalsize, version, size_dt;
u32 magic, totalsize, version, size_dt, boot_cpuid_phys;
u32 off_dt, off_str, off_mem_rsvmap;
int rc;
char *blob;
@ -856,6 +855,7 @@ struct boot_info *dt_from_blob(const char *fname)
off_str = be32_to_cpu(fdt->off_dt_strings);
off_mem_rsvmap = be32_to_cpu(fdt->off_mem_rsvmap);
version = be32_to_cpu(fdt->version);
boot_cpuid_phys = be32_to_cpu(fdt->boot_cpuid_phys);
if (off_mem_rsvmap >= totalsize)
die("Mem Reserve structure offset exceeds total size\n");
@ -908,5 +908,5 @@ struct boot_info *dt_from_blob(const char *fname)
dtc_close_file(dtcf);
return build_boot_info(reservelist, tree);
return build_boot_info(reservelist, tree, boot_cpuid_phys);
}