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 v2 1/2] pylibfdt: Add a method to access the device tree directly
Date: Thu, 31 Aug 2017 04:41:59 -0600 [thread overview]
Message-ID: <20170831104200.47974-1-sjg@chromium.org> (raw)
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.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v2:
- Change from get_fdt() to as_bytearray()
pylibfdt/libfdt.i | 11 +++++++++++
tests/pylibfdt_tests.py | 5 +++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 415820d..f8e3a2c 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 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"""
--
2.14.1.581.gf28d330327-goog
next reply other threads:[~2017-08-31 10:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 10:41 Simon Glass [this message]
[not found] ` <20170831104200.47974-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-31 10:42 ` [PATCH v2 2/2] pylibfdt: Allow reading integer values from properties Simon Glass
[not found] ` <20170831104200.47974-2-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-09-13 12:42 ` David Gibson
2017-09-10 6:43 ` [PATCH v2 1/2] pylibfdt: Add a method to access the device tree directly David Gibson
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=20170831104200.47974-1-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).