Skip to content

Commit b3cb925

Browse files
committed
adt: additional tweaks to output
- treat function_ptd_read_mult as a function too - handle parent attributes with multiple phandles - strip "/device-tree/" from phandle paths Signed-off-by: Alba Mendez <me@alba.sh>
1 parent 971b4bc commit b3cb925

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

proxyclient/m1n1/adt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def parse_prop(node, path, node_name, name, v, is_template=False):
392392
if v == b'' or v is None:
393393
return None, None
394394

395-
if name.startswith("function-"):
395+
if name.startswith("function-") or name == 'function_ptd_read_mult':
396396
if len(v) == 4:
397397
t = FourCC
398398
else:
@@ -678,7 +678,7 @@ def _fmt_prop(self, k, v, fmt_phandle=None):
678678
return f"zeroes({len(v):#x})"
679679
else:
680680
return v.hex()
681-
elif isinstance(k, str) and k.startswith("function-"):
681+
elif isinstance(k, str) and (k.startswith("function-") or k == 'function_ptd_read_mult'):
682682
if isinstance(v, str):
683683
return f"{v}()"
684684
elif v is None:
@@ -875,8 +875,14 @@ def load_adt(data):
875875
assert '/' not in node.name
876876
assert len(set(n.name for n in node)) == len(node._children)
877877
def fmt_phandle(ph, context):
878+
# some properties can contain multiple phandles...
879+
# I should ideally make a type to label phandles rather than this hack
880+
if isinstance(ph, int) and ph >> 32:
881+
ph = ph.to_bytes(8, 'little')
882+
if isinstance(ph, bytes) and len(ph) % 4 == 0:
883+
return f"[{', '.join(fmt_phandle(int.from_bytes(ph[i:i+4], 'little'), context) for i in range(0, len(ph), 4))}]"
878884
if isinstance(ph, int) and ph in phandles:
879-
ph = phandles[ph]._path
885+
ph = phandles[ph]._path.split('/', 2)[2]
880886
return f"@{ph!r}"
881887

882888
print(adt.__str__(sort_keys=args.sort_keys, sort_nodes=args.sort_nodes, fmt_phandle=fmt_phandle))

0 commit comments

Comments
 (0)