mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 15:14:43 +00:00
dtoc: Add methods for reading data from properties
Provide easy helpers for reading integer, string and boolean values from device-tree properties. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
20024daee5
commit
8f224b3734
1 changed files with 25 additions and 0 deletions
|
@ -59,3 +59,28 @@ def EnsureCompiled(fname):
|
|||
args.append(dts_input)
|
||||
command.Run('dtc', *args)
|
||||
return dtb_output
|
||||
|
||||
def GetInt(node, propname, default=None):
|
||||
prop = node.props.get(propname)
|
||||
if not prop:
|
||||
return default
|
||||
value = fdt32_to_cpu(prop.value)
|
||||
if type(value) == type(list):
|
||||
raise ValueError("Node '%s' property '%' has list value: expecting"
|
||||
"a single integer" % (node.name, propname))
|
||||
return value
|
||||
|
||||
def GetString(node, propname, default=None):
|
||||
prop = node.props.get(propname)
|
||||
if not prop:
|
||||
return default
|
||||
value = prop.value
|
||||
if type(value) == type(list):
|
||||
raise ValueError("Node '%s' property '%' has list value: expecting"
|
||||
"a single string" % (node.name, propname))
|
||||
return value
|
||||
|
||||
def GetBool(node, propname, default=False):
|
||||
if propname in node.props:
|
||||
return True
|
||||
return default
|
||||
|
|
Loading…
Reference in a new issue