devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Devicetree Compiler
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: David Gibson
	<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>,
	Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Subject: [PATCH 08/10] pylibfdt: Add support for fdt_subnode_offset()
Date: Sat, 19 Aug 2017 11:18:01 -0600	[thread overview]
Message-ID: <20170819171803.195806-8-sjg@chromium.org> (raw)
In-Reply-To: <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

Add this into the class to simplify use of this function.

Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---

 pylibfdt/libfdt.i       | 17 +++++++++++++++++
 tests/pylibfdt_tests.py | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 1f6809e..47d34ae 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -185,6 +185,23 @@ class Fdt:
         """
         return self._fdt
 
+    def subnode_offset(self, parentoffset, name, quiet=()):
+        """Get the offset of a named subnode
+
+        Args:
+            parentoffset: Offset of the parent node to check
+            name: Name of the required subnode, e.g. 'subnode@1'
+            quiet: Errors to ignore (empty to raise on all errors)
+
+        Returns:
+            The node offset of the found node, if any
+
+        Raises
+            FdtException if there is no node with that name, or other error
+        """
+        return check_err(fdt_subnode_offset(self._fdt, parentoffset, name),
+                         quiet)
+
     def path_offset(self, path, quiet=()):
         """Get the offset for a given path
 
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index a775d37..a6e3354 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -118,6 +118,18 @@ class PyLibfdtTests(unittest.TestCase):
             fdt = libfdt.Fdt('a string')
         self.assertEquals(e.exception.err, -libfdt.BADMAGIC)
 
+    def testSubnodeOffset(self):
+        """check that we can locate a subnode by name"""
+        node1 = self.fdt.path_offset('/subnode@1')
+        self.assertEquals(self.fdt.subnode_offset(0, 'subnode@1'), node1)
+
+        with self.assertRaises(FdtException) as e:
+            self.fdt.subnode_offset(0, 'missing')
+        self.assertEquals(e.exception.err, -libfdt.NOTFOUND)
+
+        node2 = self.fdt.path_offset('/subnode@1/subsubnode')
+        self.assertEquals(self.fdt.subnode_offset(node1, 'subsubnode'), node2)
+
     def testPathOffset(self):
         """Check that we can find the offset of a node"""
         self.assertEquals(self.fdt.path_offset('/'), 0)
-- 
2.14.1.480.gb18f417b89-goog

  parent reply	other threads:[~2017-08-19 17:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-19 17:17 [PATCH 01/10] pylibfdt: Add a test for use of uint32_t Simon Glass
     [not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-19 17:17   ` [PATCH 02/10] pylibfdt: Use local pylibfdt module Simon Glass
2017-08-19 17:17   ` [PATCH 03/10] tests: Return a failure code when any tests fail Simon Glass
2017-08-19 17:17   ` [PATCH 04/10] pylibfdt: Add support for fdt_get_phandle() Simon Glass
2017-08-19 17:17   ` [PATCH 05/10] pylibfdt: Add support for fdt_parent_offset() Simon Glass
2017-08-19 17:17   ` [PATCH 06/10] pylibfdt: Add support for fdt_node_offset_by_phandle() Simon Glass
2017-08-19 17:18   ` [PATCH 07/10] pylibfdt: Add a method to access the device tree directly Simon Glass
     [not found]     ` <20170819171803.195806-7-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-21  0:17       ` David Gibson
     [not found]         ` <20170821001714.GC12356-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-08-21  3:04           ` Simon Glass
2017-08-19 17:18   ` Simon Glass [this message]
2017-08-19 17:18   ` [PATCH 09/10] README: Add a note about test_tree1.dts Simon Glass
     [not found]     ` <20170819171803.195806-9-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-21  0:25       ` David Gibson
     [not found]         ` <20170821002557.GD12356-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-08-22 13:39           ` Simon Glass
     [not found]             ` <CAPnjgZ05qhg5hLAtRGS89qEcrPyfYXtJSjQTzaR0y8z4YOUvQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-23  0:36               ` David Gibson
2017-08-19 17:18   ` [PATCH 10/10] pylibfdt: Allow reading integer values from properties Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170819171803.195806-8-sjg@chromium.org \
    --to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).