[U-Boot] [PATCH 22/30] dtoc: Add methods for reading data from properties

Simon Glass sjg at chromium.org
Tue Jul 26 02:59:18 CEST 2016


Provide easy helpers for reading integer, string and boolean values from
device-tree properties.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/dtoc/fdt_util.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index 32f41d7..3a10838 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
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list