diff --git a/util/dtc/data.c b/util/dtc/data.c index 1e6c3fb6a9..915a9ded08 100644 --- a/util/dtc/data.c +++ b/util/dtc/data.c @@ -64,6 +64,7 @@ struct data data_grow_for(struct data d, int xlen) nd.asize = newsize; nd.val = xrealloc(d.val, newsize); nd.len = d.len; + nd.type = d.type; nd.refs = d.refs; assert(nd.asize >= (d.len + xlen)); @@ -199,7 +200,11 @@ struct data data_append_data(struct data d, void *p, int len) struct data data_append_cell(struct data d, cell_t word) { - cell_t beword = cpu_to_be32(word); + // Don't do system/network order byte translation. We don't do it for scalars either. + //cell_t beword = cpu_to_be32(word); + cell_t beword = word; + // Mark this property as being of the 'cell' type + d.type = 'C'; return data_append_data(d, &beword, sizeof(beword)); } @@ -223,6 +228,8 @@ struct data data_append_addr(struct data d, u64 addr) struct data data_append_byte(struct data d, uint8_t byte) { + // Mark this property as being of the 'byte' type + d.type = 'B'; return data_append_data(d, &byte, 1); } diff --git a/util/dtc/dtc.h b/util/dtc/dtc.h index 1ab702ab92..a1a09e3838 100644 --- a/util/dtc/dtc.h +++ b/util/dtc/dtc.h @@ -105,6 +105,7 @@ struct fixup { struct data { int len; unsigned char *val; + unsigned char type; int asize; struct fixup *refs; }; diff --git a/util/dtc/flattree.c b/util/dtc/flattree.c index 5f29b767e4..8c3e52291a 100644 --- a/util/dtc/flattree.c +++ b/util/dtc/flattree.c @@ -452,9 +452,24 @@ static void coreboot_emit_data(void *e, struct property *p) return; cleanname = clean(p->name, 1); - fprintf(f, "\t.%s = ", cleanname); + if (d.type == 'S') { + // Standard property (scalar) + fprintf(f, "\t.%s = ", cleanname); + fprintf(f, "0x%lx,\n", strtoul((char *)d.val, 0, 0)); + } else if (d.type == 'C') { + // 'Cell' property (array of 4-byte elements) + fprintf(f, "\t.%s = {\n", cleanname); + int i; + for (i = 0; (i < d.len) && (0 != *(u32 *)(d.val+i)); i = i+4) { + fprintf(f, "\t\t[%d] = 0x%08X,\n",i/4,*(u32 *)(d.val+i)); + } + fprintf(f, "\t\t[%d] = 0x0,\n",i/4); // Make sure to end our array with a zero element + fprintf(f, "\t},\n"); + } else if (d.type == 'B') { + fprintf(f, "\tUNIMPLEMENTED: FIXME\n"); + } free(cleanname); - fprintf(f, "0x%lx,\n", strtoul((char *)d.val, 0, 0)); + #if 0 /* sorry, but right now, u32 is all you get */ fprintf(f, "0"); @@ -785,7 +800,16 @@ static void flatten_tree_emit_structdecls(struct node *tree, struct emitter *emi if (streq(prop->name, "device_operations")) /* this is special */ continue; cleanname = clean(prop->name, 0); - fprintf(f, "\tu32 %s;\n", cleanname); + if (prop->val.type == 'S') { + // Standard property, scalar + fprintf(f, "\tu32 %s;\n", cleanname); + } else if (prop->val.type == 'C') { + // 'Cell' property (array of 4-byte elements) + fprintf(f, "\tu32 %s[%d];\n", cleanname,prop->val.len/4+1); + } else if (prop->val.type == 'B') { + // Byte property + fprintf(f, "\tUNIMPLEMENTED: FIXME\n"); + } free(cleanname); } diff --git a/util/dtc/livetree.c b/util/dtc/livetree.c index 80a16d1612..4877991526 100644 --- a/util/dtc/livetree.c +++ b/util/dtc/livetree.c @@ -32,6 +32,9 @@ struct property *build_property(char *name, struct data val, char *label) new->name = name; new->val = val; + if (new->val.type == NULL) { + new->val.type = 'S'; // Default to 'scalar' type; if this is a cell or byte value, type will already be set + } new->next = NULL; @@ -301,7 +304,9 @@ static struct { } prop_checker_table[] = { {"name", must_be_string}, {"name", name_prop_check}, -/* we don't care about these things now -- we think */ + /* unwanted_vpci must be a cells field (i.e. an array) */ + {"unwanted_vpci", must_be_cells}, + /* we don't care about these things now -- we think */ {"linux,phandle", must_be_one_cell}, {"#address-cells", must_be_one_cell}, {"#size-cells", must_be_one_cell},