aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2021-07-27 12:30:23 -0600
committerDavid Gibson <david@gibson.dropbear.id.au>2021-10-11 16:20:53 +1100
commit37fd700685da9001643d1b1f63ad4332e1148b04 (patch)
tree0e8b8ed54420ee63007ca996392967a2a65499d6
parente33ce1d6a8c7e54e3ad12cff33690b6da0aee1dc (diff)
downloaddtc-37fd700685da9001643d1b1f63ad4332e1148b04.tar.gz
treesource: Maintain phandle label/path on output
The dts output will just output phandle integer values, but often the necessary markers are present with path or label references. Improve the output and maintain phandle label or path references when present in dts output. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210727183023.3212077-6-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--tests/type-preservation.dt.yaml3
-rw-r--r--tests/type-preservation.dts3
-rw-r--r--treesource.c25
3 files changed, 25 insertions, 6 deletions
diff --git a/tests/type-preservation.dt.yaml b/tests/type-preservation.dt.yaml
index ee8cfde..a0cc64c 100644
--- a/tests/type-preservation.dt.yaml
+++ b/tests/type-preservation.dt.yaml
@@ -13,8 +13,11 @@
int64: [!u64 [0x200000000]]
int64-array: [!u64 [0x100000000, 0x0]]
a-string-with-nulls: ["foo\0bar", "baz"]
+ a-phandle: [[!phandle 0x1]]
+ a-phandle-with-args: [[!phandle 0x1, 0x0, 0x1], [!phandle 0x1, 0x2, 0x3]]
subsubnode:
compatible: ["subsubnode1", "subsubnode"]
+ phandle: [[0x1]]
subsubsubnode:
compatible: ["subsubsubnode1", [0x1234], "subsubsubnode"]
...
diff --git a/tests/type-preservation.dts b/tests/type-preservation.dts
index 3e380ba..921ea21 100644
--- a/tests/type-preservation.dts
+++ b/tests/type-preservation.dts
@@ -16,9 +16,12 @@
int64 = /bits/ 64 <0x200000000>;
int64-array = /bits/ 64 <0x100000000 0x00> int64_array_label_end:;
a-string-with-nulls = "foo\0bar", "baz";
+ a-phandle = <&subsub1>;
+ a-phandle-with-args = <&subsub1 0x00 0x01>, <&subsub1 0x02 0x03>;
subsub1: subsubnode {
compatible = "subsubnode1", "subsubnode";
+ phandle = <0x01>;
subsubsub1: subsubsubnode {
compatible = "subsubsubnode1", <0x1234>, valuea: valueb: "subsubsubnode";
diff --git a/treesource.c b/treesource.c
index db2ff69..33fedee 100644
--- a/treesource.c
+++ b/treesource.c
@@ -208,26 +208,39 @@ static void write_propval(FILE *f, struct property *prop)
size_t chunk_len = (m->next ? m->next->offset : len) - m->offset;
size_t data_len = type_marker_length(m) ? : len - m->offset;
const char *p = &prop->val.val[m->offset];
+ struct marker *m_phandle;
if (is_type_marker(m->type)) {
emit_type = m->type;
fprintf(f, " %s", delim_start[emit_type]);
} else if (m->type == LABEL)
fprintf(f, " %s:", m->ref);
- else if (m->offset)
- fputc(' ', f);
- if (emit_type == TYPE_NONE) {
- assert(chunk_len == 0);
+ if (emit_type == TYPE_NONE || chunk_len == 0)
continue;
- }
switch(emit_type) {
case TYPE_UINT16:
write_propval_int(f, p, chunk_len, 2);
break;
case TYPE_UINT32:
- write_propval_int(f, p, chunk_len, 4);
+ m_phandle = prop->val.markers;
+ for_each_marker_of_type(m_phandle, REF_PHANDLE)
+ if (m->offset == m_phandle->offset)
+ break;
+
+ if (m_phandle) {
+ if (m_phandle->ref[0] == '/')
+ fprintf(f, "&{%s}", m_phandle->ref);
+ else
+ fprintf(f, "&%s", m_phandle->ref);
+ if (chunk_len > 4) {
+ fputc(' ', f);
+ write_propval_int(f, p + 4, chunk_len - 4, 4);
+ }
+ } else {
+ write_propval_int(f, p, chunk_len, 4);
+ }
break;
case TYPE_UINT64:
write_propval_int(f, p, chunk_len, 8);