mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
pylibfdt: Add a method to access the device tree directly
When calling libfdt functions which are not supported by the Fdt class it is necessary to get direct access to the device tree data. At present this requries using the internal _fdt member. Add a new method to provide public access to this, without allowing the data to be changed. Note that a bytearray type is returned rather than str, since the swig types are set up for bytearray to map correctly to const void *. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
84e414b0b5
commit
24b1f3f064
2 changed files with 14 additions and 2 deletions
|
@ -174,6 +174,17 @@ class Fdt:
|
||||||
self._fdt = bytearray(data)
|
self._fdt = bytearray(data)
|
||||||
check_err(fdt_check_header(self._fdt));
|
check_err(fdt_check_header(self._fdt));
|
||||||
|
|
||||||
|
def as_bytearray(self):
|
||||||
|
"""Get the device tree contents as a bytearray
|
||||||
|
|
||||||
|
This can be passed directly to libfdt functions that access a
|
||||||
|
const void * for the device tree.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bytearray containing the device tree
|
||||||
|
"""
|
||||||
|
return bytearray(self._fdt)
|
||||||
|
|
||||||
def subnode_offset(self, parentoffset, name, quiet=()):
|
def subnode_offset(self, parentoffset, name, quiet=()):
|
||||||
"""Get the offset of a named subnode
|
"""Get the offset of a named subnode
|
||||||
|
|
||||||
|
|
|
@ -297,9 +297,10 @@ class PyLibfdtTests(unittest.TestCase):
|
||||||
|
|
||||||
def testIntegers(self):
|
def testIntegers(self):
|
||||||
"""Check that integers can be passed and returned"""
|
"""Check that integers can be passed and returned"""
|
||||||
self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt._fdt, 0))
|
self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt.as_bytearray(), 0))
|
||||||
node2 = self.fdt.path_offset('/subnode@2')
|
node2 = self.fdt.path_offset('/subnode@2')
|
||||||
self.assertEquals(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2))
|
self.assertEquals(
|
||||||
|
0x2000, libfdt.fdt_get_phandle(self.fdt.as_bytearray(), node2))
|
||||||
|
|
||||||
def testGetPhandle(self):
|
def testGetPhandle(self):
|
||||||
"""Test for the get_phandle() method"""
|
"""Test for the get_phandle() method"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue