summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-07-25 18:59:18 -0600
committerSimon Glass <sjg@chromium.org>2016-09-18 21:04:39 -0600
commit8f224b3734d042884a8981a14db64c48e87b87a2 (patch)
tree7c9d794b6f96a174e36adc078c5c6f1d2698a68d /tools
parent20024daee58906712f71b927bd86951d1ddb469d (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/dtoc/fdt_util.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index 32f41d72d79..3a108381099 100644
--- a/tools/dtoc/fdt_util.py
+++ b/tools/dtoc/fdt_util.py
@@ -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