diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i index 1ab69fb..e4c2803 100644 --- a/pylibfdt/libfdt.i +++ b/pylibfdt/libfdt.i @@ -302,6 +302,38 @@ class FdtRo(object): check_err(val[0], quiet) return val[1:] + def address_cells(self, nodeoffset, quiet=()): + """Return the number of address cells used by a node's children + + Args: + nodeoffset: Offset of the node to check + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Number of address cells used by the children of @nodeoffset + + Raises: + FdtException if the node has an invalid #address-cells property, + or another error occurs + """ + return check_err(fdt_address_cells(self._fdt, nodeoffset), quiet) + + def size_cells(self, nodeoffset, quiet=()): + """Return the number of size cells used by a node's children + + Args: + nodeoffset: Offset of the node to check + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Number of size cells used by the children of @nodeoffset + + Raises: + FdtException if the node has an invalid #size-cells property, or + another error occurs + """ + return check_err(fdt_size_cells(self._fdt, nodeoffset), quiet) + 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 6af11f2..7178bb2 100644 --- a/tests/pylibfdt_tests.py +++ b/tests/pylibfdt_tests.py @@ -411,6 +411,21 @@ class PyLibfdtBasicTests(unittest.TestCase): self.fdt.get_mem_rsv(0)) self.assertEqual([123456789, 0o10000], self.fdt.get_mem_rsv(1)) + def testCells(self): + """Test that we can read #address-cells and #size-cells""" + self.assertEqual(1, self.fdt.address_cells(0)) + self.assertEqual(0, self.fdt.size_cells(0)) + + # A node without the properties inherits neither, so the libfdt + # defaults of 2 and 1 apply + node = self.fdt.path_offset('/subnode@1') + self.assertEqual(2, self.fdt.address_cells(node)) + self.assertEqual(1, self.fdt.size_cells(node)) + + node = self.fdt.path_offset('/subnode@2') + self.assertEqual(1, self.fdt.address_cells(node)) + self.assertEqual(0, self.fdt.size_cells(node)) + def testEmpty(self): """Test that we can create an empty tree""" self.assertEqual(-libfdt.NOSPACE,