mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
pylibfdt: Add support for fdt_parent_offset()
Add this into the class to simplify use of this function. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
a198af8034
commit
a3ae437236
2 changed files with 28 additions and 0 deletions
|
@ -360,6 +360,21 @@ class Fdt:
|
||||||
"""
|
"""
|
||||||
return fdt_get_phandle(self._fdt, nodeoffset)
|
return fdt_get_phandle(self._fdt, nodeoffset)
|
||||||
|
|
||||||
|
def parent_offset(self, nodeoffset, quiet=()):
|
||||||
|
"""Get the offset of a node's parent
|
||||||
|
|
||||||
|
Args:
|
||||||
|
nodeoffset: Node offset to check
|
||||||
|
quiet: Errors to ignore (empty to raise on all errors)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The offset of the parent node, if any
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FdtException if no parent found or other error occurs
|
||||||
|
"""
|
||||||
|
return check_err(fdt_parent_offset(self._fdt, nodeoffset), quiet)
|
||||||
|
|
||||||
|
|
||||||
class Property:
|
class Property:
|
||||||
"""Holds a device tree property name and value.
|
"""Holds a device tree property name and value.
|
||||||
|
|
|
@ -295,5 +295,18 @@ class PyLibfdtTests(unittest.TestCase):
|
||||||
node2 = self.fdt.path_offset('/subnode@2')
|
node2 = self.fdt.path_offset('/subnode@2')
|
||||||
self.assertEquals(0x2000, self.fdt.get_phandle(node2))
|
self.assertEquals(0x2000, self.fdt.get_phandle(node2))
|
||||||
|
|
||||||
|
def testParentOffset(self):
|
||||||
|
"""Test for the parent_offset() method"""
|
||||||
|
self.assertEquals(-libfdt.NOTFOUND,
|
||||||
|
self.fdt.parent_offset(0, QUIET_NOTFOUND))
|
||||||
|
with self.assertRaises(FdtException) as e:
|
||||||
|
self.fdt.parent_offset(0)
|
||||||
|
self.assertEquals(e.exception.err, -libfdt.NOTFOUND)
|
||||||
|
|
||||||
|
node1 = self.fdt.path_offset('/subnode@2')
|
||||||
|
self.assertEquals(0, self.fdt.parent_offset(node1))
|
||||||
|
node2 = self.fdt.path_offset('/subnode@2/subsubnode@0')
|
||||||
|
self.assertEquals(node1, self.fdt.parent_offset(node2))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue