aboutsummaryrefslogtreecommitdiff
path: root/yamltree.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2019-09-18 13:35:34 -0500
committerDavid Gibson <david@gibson.dropbear.id.au>2019-09-25 11:48:50 +1000
commit18d7b2f4ee45fec422b7d82bab0b3c762ee907e4 (patch)
treebdb3c655521626c38df497d5ff8b9c15e2631b5e /yamltree.c
parent67f790c1adccdf56f6560739a2a6194b99fdc838 (diff)
downloaddtc-18d7b2f4ee45fec422b7d82bab0b3c762ee907e4.zip
dtc-18d7b2f4ee45fec422b7d82bab0b3c762ee907e4.tar.gz
dtc-18d7b2f4ee45fec422b7d82bab0b3c762ee907e4.tar.bz2
yamltree: Ensure consistent bracketing of properties with phandles
The dts syntax allows for '<>' around phandles and arg cells or not which it didn't matter until adding type information. However, the YAML encoding expects each phandle + args to be bracketed. If TYPE_UINT32 markers are not present before each REF_PHANDLE, fix up the markers and add the TYPE_UINT32 markers. This allows the subsequent YAML emitting code to work as-is. Adding the markers at an earlier stage doesn't work because of possible labels in dts output. We'd have to define the ordering of labels and brackets. Also, it is probably best to have dts output match the input. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20190918183534.24205-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'yamltree.c')
-rw-r--r--yamltree.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/yamltree.c b/yamltree.c
index 5b6ea8e..43ca869 100644
--- a/yamltree.c
+++ b/yamltree.c
@@ -138,6 +138,27 @@ static void yaml_propval(yaml_emitter_t *emitter, struct property *prop)
(yaml_char_t *)YAML_SEQ_TAG, 1, YAML_FLOW_SEQUENCE_STYLE);
yaml_emitter_emit_or_die(emitter, &event);
+ /* Ensure we have a type marker before any phandle */
+ for_each_marker(m) {
+ int last_offset = 0;
+ struct marker *type_m;
+
+ if (m->type >= TYPE_UINT8)
+ last_offset = m->offset;
+
+ if (!(m->next && m->next->type == REF_PHANDLE &&
+ last_offset < m->next->offset))
+ continue;
+
+ type_m = xmalloc(sizeof(*type_m));
+ type_m->offset = m->next->offset;
+ type_m->type = TYPE_UINT32;
+ type_m->ref = NULL;
+ type_m->next = m->next;
+ m->next = type_m;
+ }
+
+ m = prop->val.markers;
for_each_marker(m) {
int chunk_len;
char *data = &prop->val.val[m->offset];