mirror of
https://github.com/dgibson/dtc.git
synced 2026-04-12 00:47:46 -04:00
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>
This commit is contained in:
parent
49d32ce40b
commit
3c374d46ac
4 changed files with 43 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue