dtc: Allow multiple labels on nodes and properties
At present, both the grammar and our internal data structures mean
that there can be only one label on a node or property. This is a
fairly arbitrary constraint, given that any number of value labels can
appear at the same point, and that in C you can have any number of
labels on the same statement.
This is pretty much a non-issue now, but it may become important with
some of the extensions that Grant and I have in mind. It's not that
hard to change, so this patch does so, allowing an arbitrary number of
labels on any given node or property. As usual a testcase is added
too.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
diff --git a/flattree.c b/flattree.c
index 8637407..ead0332 100644
--- a/flattree.c
+++ b/flattree.c
@@ -52,9 +52,9 @@
void (*string)(void *, char *, int);
void (*align)(void *, int);
void (*data)(void *, struct data);
- void (*beginnode)(void *, const char *);
- void (*endnode)(void *, const char *);
- void (*property)(void *, const char *);
+ void (*beginnode)(void *, struct label *labels);
+ void (*endnode)(void *, struct label *labels);
+ void (*property)(void *, struct label *labels);
};
static void bin_emit_cell(void *e, cell_t val)
@@ -89,17 +89,17 @@
*dtbuf = data_append_data(*dtbuf, d.val, d.len);
}
-static void bin_emit_beginnode(void *e, const char *label)
+static void bin_emit_beginnode(void *e, struct label *labels)
{
bin_emit_cell(e, FDT_BEGIN_NODE);
}
-static void bin_emit_endnode(void *e, const char *label)
+static void bin_emit_endnode(void *e, struct label *labels)
{
bin_emit_cell(e, FDT_END_NODE);
}
-static void bin_emit_property(void *e, const char *label)
+static void bin_emit_property(void *e, struct label *labels)
{
bin_emit_cell(e, FDT_PROP);
}
@@ -191,37 +191,40 @@
assert(off == d.len);
}
-static void asm_emit_beginnode(void *e, const char *label)
+static void asm_emit_beginnode(void *e, struct label *labels)
{
FILE *f = e;
+ struct label *l;
- if (label) {
- fprintf(f, "\t.globl\t%s\n", label);
- fprintf(f, "%s:\n", label);
+ for_each_label(labels, l) {
+ fprintf(f, "\t.globl\t%s\n", l->label);
+ fprintf(f, "%s:\n", l->label);
}
fprintf(f, "\t/* FDT_BEGIN_NODE */\n");
asm_emit_cell(e, FDT_BEGIN_NODE);
}
-static void asm_emit_endnode(void *e, const char *label)
+static void asm_emit_endnode(void *e, struct label *labels)
{
FILE *f = e;
+ struct label *l;
fprintf(f, "\t/* FDT_END_NODE */\n");
asm_emit_cell(e, FDT_END_NODE);
- if (label) {
- fprintf(f, "\t.globl\t%s_end\n", label);
- fprintf(f, "%s_end:\n", label);
+ for_each_label(labels, l) {
+ fprintf(f, "\t.globl\t%s_end\n", l->label);
+ fprintf(f, "%s_end:\n", l->label);
}
}
-static void asm_emit_property(void *e, const char *label)
+static void asm_emit_property(void *e, struct label *labels)
{
FILE *f = e;
+ struct label *l;
- if (label) {
- fprintf(f, "\t.globl\t%s\n", label);
- fprintf(f, "%s:\n", label);
+ for_each_label(labels, l) {
+ fprintf(f, "\t.globl\t%s\n", l->label);
+ fprintf(f, "%s:\n", l->label);
}
fprintf(f, "\t/* FDT_PROP */\n");
asm_emit_cell(e, FDT_PROP);
@@ -260,7 +263,7 @@
struct node *child;
int seen_name_prop = 0;
- emit->beginnode(etarget, tree->label);
+ emit->beginnode(etarget, tree->labels);
if (vi->flags & FTF_FULLPATH)
emit->string(etarget, tree->fullpath, 0);
@@ -277,7 +280,7 @@
nameoff = stringtable_insert(strbuf, prop->name);
- emit->property(etarget, prop->label);
+ emit->property(etarget, prop->labels);
emit->cell(etarget, prop->val.len);
emit->cell(etarget, nameoff);
@@ -304,7 +307,7 @@
flatten_tree(child, emit, etarget, strbuf, vi);
}
- emit->endnode(etarget, tree->label);
+ emit->endnode(etarget, tree->labels);
}
static struct data flatten_reserve_list(struct reserve_info *reservelist,
@@ -525,9 +528,11 @@
* as it appears .quad isn't available in some assemblers.
*/
for (re = bi->reservelist; re; re = re->next) {
- if (re->label) {
- fprintf(f, "\t.globl\t%s\n", re->label);
- fprintf(f, "%s:\n", re->label);
+ struct label *l;
+
+ for_each_label(re->labels, l) {
+ fprintf(f, "\t.globl\t%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",
@@ -684,7 +689,7 @@
val = flat_read_data(dtbuf, proplen);
- return build_property(name, val, NULL);
+ return build_property(name, val);
}
@@ -709,7 +714,7 @@
if (re.size == 0)
break;
- new = build_reserve_entry(re.address, re.size, NULL);
+ new = build_reserve_entry(re.address, re.size);
reservelist = add_reserve_entry(reservelist, new);
}