Browse Source

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>
main
Rob Herring 3 years ago committed by David Gibson
parent
commit
37fd700685
  1. 3
      tests/type-preservation.dt.yaml
  2. 3
      tests/type-preservation.dts
  3. 25
      treesource.c

3
tests/type-preservation.dt.yaml

@ -13,8 +13,11 @@ @@ -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"]
...

3
tests/type-preservation.dts

@ -16,9 +16,12 @@ @@ -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";

25
treesource.c

@ -208,26 +208,39 @@ static void write_propval(FILE *f, struct property *prop) @@ -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);

Loading…
Cancel
Save