Skip to content

Commit

Permalink
adt: additional tweaks to output
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
mildsunrise committed Oct 27, 2024
1 parent 971b4bc commit b3cb925
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions proxyclient/m1n1/adt.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def parse_prop(node, path, node_name, name, v, is_template=False):
if v == b'' or v is None:
return None, None

if name.startswith("function-"):
if name.startswith("function-") or name == 'function_ptd_read_mult':
if len(v) == 4:
t = FourCC
else:
Expand Down Expand Up @@ -678,7 +678,7 @@ def _fmt_prop(self, k, v, fmt_phandle=None):
return f"zeroes({len(v):#x})"
else:
return v.hex()
elif isinstance(k, str) and k.startswith("function-"):
elif isinstance(k, str) and (k.startswith("function-") or k == 'function_ptd_read_mult'):
if isinstance(v, str):
return f"{v}()"
elif v is None:
Expand Down Expand Up @@ -875,8 +875,14 @@ def load_adt(data):
assert '/' not in node.name
assert len(set(n.name for n in node)) == len(node._children)
def fmt_phandle(ph, context):
# some properties can contain multiple phandles...
# I should ideally make a type to label phandles rather than this hack
if isinstance(ph, int) and ph >> 32:
ph = ph.to_bytes(8, 'little')
if isinstance(ph, bytes) and len(ph) % 4 == 0:
return f"[{', '.join(fmt_phandle(int.from_bytes(ph[i:i+4], 'little'), context) for i in range(0, len(ph), 4))}]"
if isinstance(ph, int) and ph in phandles:
ph = phandles[ph]._path
ph = phandles[ph]._path.split('/', 2)[2]
return f"@{ph!r}"

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

0 comments on commit b3cb925

Please sign in to comment.