aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-06-06 15:37:01 -0600
committerDavid Gibson <david@gibson.dropbear.id.au>2018-06-08 22:26:03 +1000
commit582a7159a5d0e1f4c96d5bdaab63defc69762c95 (patch)
tree2f6ac55e744b8e30629335d1d86a219d183cdb7c
parentf0f8c9169819e5505e63e247e40e9593625e01a4 (diff)
downloaddtc-582a7159a5d0e1f4c96d5bdaab63defc69762c95.zip
dtc-582a7159a5d0e1f4c96d5bdaab63defc69762c95.tar.gz
dtc-582a7159a5d0e1f4c96d5bdaab63defc69762c95.tar.bz2
pylibfdt: Add support for fdt_next_node()
This function requires a bit of typemap effort to get the depth parameter to work correctly. Add support for it, along with a test. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--pylibfdt/libfdt.i33
-rw-r--r--tests/pylibfdt_tests.py18
2 files changed, 51 insertions, 0 deletions
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 2ad9d33..e8282a4 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -185,6 +185,25 @@ class Fdt:
"""
return bytearray(self._fdt)
+ def next_node(self, nodeoffset, depth, quiet=()):
+ """Find the next subnode
+
+ Args:
+ nodeoffset: Node offset of previous node
+ depth: The depth of the node at nodeoffset. This is used to
+ calculate the depth of the returned node
+ quiet: Errors to ignore (empty to raise on all errors)
+
+ Returns:
+ Typle:
+ Offset of the next node, if any, else a -ve error
+ Depth of the returned node, if any, else undefined
+
+ Raises:
+ FdtException if no more nodes found or other error occurs
+ """
+ return check_err(fdt_next_node(self._fdt, nodeoffset, depth), quiet)
+
def first_subnode(self, nodeoffset, quiet=()):
"""Find the first subnode of a parent node
@@ -466,6 +485,7 @@ typedef int fdt32_t;
fdt = fdt; /* avoid unused variable warning */
}
+/* typemap used for fdt_get_property_by_offset() */
%typemap(out) (struct fdt_property *) {
PyObject *buff;
@@ -488,6 +508,19 @@ typedef int fdt32_t;
$result = Py_BuildValue("s#", $1, *arg4);
}
+/* typemaps used for fdt_next_node() */
+%typemap(in, numinputs=1) int *depth (int depth) {
+ depth = (int) PyInt_AsLong($input);
+ $1 = &depth;
+}
+
+%typemap(argout) int *depth {
+ PyObject *val = Py_BuildValue("i", *arg$argnum);
+ resultobj = SWIG_Python_AppendOutput(resultobj, val);
+}
+
+%apply int *depth { int *depth };
+
/* We have both struct fdt_property and a function fdt_property() */
%warnfilter(302) fdt_property;
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 343a1e4..900644d 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -220,6 +220,24 @@ class PyLibfdtTests(unittest.TestCase):
self.assertEquals(libfdt.strerror(-libfdt.NOTFOUND),
'FDT_ERR_NOTFOUND')
+ def testNextNodeOffset(self):
+ """Check that we can walk through nodes"""
+ node_list = []
+ node = 0
+ depth = 0
+ while depth >= 0:
+ node_list.append([depth, self.fdt.get_name(node)])
+ node, depth = self.fdt.next_node(node, depth, (libfdt.BADOFFSET,))
+ self.assertEquals(node_list, [
+ [0, ''],
+ [1, 'subnode@1'],
+ [2, 'subsubnode'],
+ [2, 'ss1'],
+ [1, 'subnode@2'],
+ [2, 'subsubnode@0'],
+ [2, 'ss2'],
+ ])
+
def testFirstNextSubnodeOffset(self):
"""Check that we can walk through subnodes"""
node_list = []