diff options
author | Simon Glass <sjg@chromium.org> | 2018-05-17 23:09:13 -0600 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2018-06-04 18:18:38 +1000 |
commit | 24b1f3f064d4fde60ab7ba3ec40161edb3fab4b3 (patch) | |
tree | 3ee6e3de9d8bfa973ad2d4b47357cfb80179e355 | |
parent | 84e414b0b5bcea3a82875d79cc15520440e1e49b (diff) | |
download | dtc-24b1f3f064d4fde60ab7ba3ec40161edb3fab4b3.zip dtc-24b1f3f064d4fde60ab7ba3ec40161edb3fab4b3.tar.gz dtc-24b1f3f064d4fde60ab7ba3ec40161edb3fab4b3.tar.bz2 |
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>
-rw-r--r-- | pylibfdt/libfdt.i | 11 | ||||
-rw-r--r-- | tests/pylibfdt_tests.py | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i index 415820d..29695bb 100644 --- a/pylibfdt/libfdt.i +++ b/pylibfdt/libfdt.i @@ -174,6 +174,17 @@ class Fdt: self._fdt = bytearray(data) 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=()): """Get the offset of a named subnode diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py index 95d911a..0ec0f38 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -297,9 +297,10 @@ class PyLibfdtTests(unittest.TestCase): def testIntegers(self): """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') - 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): """Test for the get_phandle() method""" |