aboutsummaryrefslogtreecommitdiff
path: root/pylibfdt
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-06-12 23:37:31 -0600
committerDavid Gibson <david@gibson.dropbear.id.au>2018-06-13 16:59:18 +1000
commit3c374d46accee1911f5679ccb131d1404abbdbbf (patch)
treee462fa2a6ff7e6365f8deccaf3f3b617794721b3 /pylibfdt
parent49d32ce40bb44a35536326236c4f82ca6848b0f0 (diff)
downloaddtc-3c374d46accee1911f5679ccb131d1404abbdbbf.zip
dtc-3c374d46accee1911f5679ccb131d1404abbdbbf.tar.gz
dtc-3c374d46accee1911f5679ccb131d1404abbdbbf.tar.bz2
pylibfdt: Allow reading integer values from properties
Extend the Properties class with some functions to read a single integer property. Add a new getprop_obj() function to return a Property object instead of the raw data. This suggested approach can be extended to handle other types, as well as arrays. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'pylibfdt')
-rw-r--r--pylibfdt/libfdt.i22
1 files changed, 19 insertions, 3 deletions
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 520911e..adb4ee8 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -488,7 +488,9 @@ class Fdt:
quiet: Errors to ignore (empty to raise on all errors)
Returns:
- Value of property as a string of bytes, or -ve error number
+ Value of property as a Property object (which can be used as a
+ bytearray/string), or -ve error number. On failure, returns an
+ integer error
Raises:
FdtError if any error occurs (e.g. the property is not found)
@@ -497,8 +499,7 @@ class Fdt:
quiet)
if isinstance(pdata, (int)):
return pdata
- # Use bytes() rather than string(). This works on both Python 2 and 3
- return bytes(pdata[0])
+ return Property(prop_name, bytearray(pdata[0]))
def get_phandle(self, nodeoffset):
"""Get the phandle of a node
@@ -623,6 +624,21 @@ class Property(bytearray):
def __init__(self, name, value):
bytearray.__init__(self, value)
self.name = name
+
+ def as_cell(self, fmt):
+ return struct.unpack('>' + fmt, self)[0]
+
+ def as_uint32(self):
+ return self.as_cell('L')
+
+ def as_int32(self):
+ return self.as_cell('l')
+
+ def as_uint64(self):
+ return self.as_cell('Q')
+
+ def as_int64(self):
+ return self.as_cell('q')
%}
%rename(fdt_property) fdt_property_func;