Browse Source

dtc: Don't abuse struct fdt_reserve_entry

struct fdt_reserve_entry is defined in fdt.h to exactly mirror the
in-memory layout of a reserve entry in the flattened tree.  Since that is
always big-endian, it uses fdt64_t elements, which have sparse annotations
marking them as not native endian.

However, in dtc, we also use struct fdt_reserve_entry inside struct
reserve_info, and use it with native endian values.  This will cause sparse
errors.

This stops this abuse, making struct reserve_info have its own native
endian fields for the same information.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 8 years ago
parent
commit
49300f2ade
  1. 10
      data.c
  2. 4
      dtc.h
  3. 13
      flattree.c
  4. 12
      livetree.c
  5. 4
      treesource.c

10
data.c

@ -197,14 +197,14 @@ struct data data_append_integer(struct data d, uint64_t value, int bits)
} }
} }


struct data data_append_re(struct data d, const struct fdt_reserve_entry *re) struct data data_append_re(struct data d, uint64_t address, uint64_t size)
{ {
struct fdt_reserve_entry bere; struct fdt_reserve_entry re;


bere.address = cpu_to_fdt64(re->address); re.address = cpu_to_fdt64(address);
bere.size = cpu_to_fdt64(re->size); re.size = cpu_to_fdt64(size);


return data_append_data(d, &bere, sizeof(bere)); return data_append_data(d, &re, sizeof(re));
} }


struct data data_append_cell(struct data d, cell_t word) struct data data_append_cell(struct data d, cell_t word)

4
dtc.h

@ -114,7 +114,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m,
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_integer(struct data d, uint64_t word, int bits); struct data data_append_integer(struct data d, uint64_t word, int bits);
struct data data_append_re(struct data d, const struct fdt_reserve_entry *re); struct data data_append_re(struct data d, uint64_t address, uint64_t size);
struct data data_append_addr(struct data d, uint64_t addr); struct data data_append_addr(struct data d, uint64_t 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);
@ -227,7 +227,7 @@ uint32_t guess_boot_cpuid(struct node *tree);
/* Boot info (tree plus memreserve information */ /* Boot info (tree plus memreserve information */


struct reserve_info { struct reserve_info {
struct fdt_reserve_entry re; uint64_t address, size;


struct reserve_info *next; struct reserve_info *next;



13
flattree.c

@ -318,17 +318,16 @@ 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 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) {
d = data_append_re(d, &re->re); d = data_append_re(d, re->address, re->size);
} }
/* /*
* Add additional reserved slots if the user asked for them. * Add additional reserved slots if the user asked for them.
*/ */
for (j = 0; j < reservenum; j++) { for (j = 0; j < reservenum; j++) {
d = data_append_re(d, &null_re); d = data_append_re(d, 0, 0);
} }


return d; return d;
@ -544,11 +543,11 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
fprintf(f, "\t.globl\t%s\n", l->label); fprintf(f, "\t.globl\t%s\n", l->label);
fprintf(f, "%s:\n", l->label); fprintf(f, "%s:\n", l->label);
} }
ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.address >> 32)); ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->address >> 32));
ASM_EMIT_BELONG(f, "0x%08x", ASM_EMIT_BELONG(f, "0x%08x",
(unsigned int)(re->re.address & 0xffffffff)); (unsigned int)(re->address & 0xffffffff));
ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size >> 32)); ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->size >> 32));
ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->re.size & 0xffffffff)); ASM_EMIT_BELONG(f, "0x%08x", (unsigned int)(re->size & 0xffffffff));
} }
for (i = 0; i < reservenum; i++) { for (i = 0; i < reservenum; i++) {
fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n");

12
livetree.c

@ -319,8 +319,8 @@ struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size)


memset(new, 0, sizeof(*new)); memset(new, 0, sizeof(*new));


new->re.address = address; new->address = address;
new->re.size = size; new->size = size;


return new; return new;
} }
@ -599,13 +599,13 @@ static int cmp_reserve_info(const void *ax, const void *bx)
a = *((const struct reserve_info * const *)ax); a = *((const struct reserve_info * const *)ax);
b = *((const struct reserve_info * const *)bx); b = *((const struct reserve_info * const *)bx);


if (a->re.address < b->re.address) if (a->address < b->address)
return -1; return -1;
else if (a->re.address > b->re.address) else if (a->address > b->address)
return 1; return 1;
else if (a->re.size < b->re.size) else if (a->size < b->size)
return -1; return -1;
else if (a->re.size > b->re.size) else if (a->size > b->size)
return 1; return 1;
else else
return 0; return 0;

4
treesource.c

@ -275,8 +275,8 @@ void dt_to_source(FILE *f, struct dt_info *dti)
for_each_label(re->labels, l) for_each_label(re->labels, l)
fprintf(f, "%s: ", l->label); fprintf(f, "%s: ", l->label);
fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n", fprintf(f, "/memreserve/\t0x%016llx 0x%016llx;\n",
(unsigned long long)re->re.address, (unsigned long long)re->address,
(unsigned long long)re->re.size); (unsigned long long)re->size);
} }


write_tree_source_node(f, dti->dt, 0); write_tree_source_node(f, dti->dt, 0);

Loading…
Cancel
Save