dtoc: Add a way to read a phandle with params

Add a function to read a phandle and associated name and offset. This is
useful for binman.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-01-11 16:10:18 -07:00
parent c1157860c5
commit 8f5afe21ae
4 changed files with 43 additions and 0 deletions

View File

@@ -281,6 +281,34 @@ def GetPhandleList(node, propname):
value = [value]
return [fdt32_to_cpu(v) for v in value]
def GetPhandleNameOffset(node, propname):
"""Get a <&phandle>, "string", <offset> value from a property
Args:
node: Node object to read from
propname: property name to read
Returns:
tuple:
Node object
str
int
or None if the property does not exist
"""
prop = node.props.get(propname)
if not prop:
return None
value = prop.bytes
phandle = fdt32_to_cpu(value[:4])
node = node.GetFdt().LookupPhandle(phandle)
name = ''
for byte in value[4:]:
if not byte:
break
name += chr(byte)
val = fdt32_to_cpu(value[4 + len(name) + 1:])
return node, name, val
def GetDatatype(node, propname, datatype):
"""Get a value of a given type from a property