* [PATCH 01/10] pylibfdt: Add a test for use of uint32_t
@ 2017-08-19 17:17 Simon Glass
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
0 siblings, 1 reply; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
Using the libfdt function without going through the Python Fdt class
requires use of the uint32_t type. Add a test that this works correctly.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
tests/pylibfdt_tests.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index ae392bb..e8a4582 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -283,6 +283,11 @@ class PyLibfdtTests(unittest.TestCase):
self.assertEquals(-libfdt.BADPATH,
self.fdt.path_offset('missing', QUIET_ALL))
+ def testIntegers(self):
+ """Check that integers can be passed and returned"""
+ self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt._fdt, 0))
+ node2 = self.fdt.path_offset('/subnode@2')
+ self.assertEquals(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2))
if __name__ == "__main__":
unittest.main()
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 02/10] pylibfdt: Use local pylibfdt module
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2017-08-19 17:17 ` Simon Glass
2017-08-19 17:17 ` [PATCH 03/10] tests: Return a failure code when any tests fail Simon Glass
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
Some systems may have the Python libfdt.py library installed. Adjust the
tests to prepend the local libfdt path so that we test the local version
instead of the system version.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
tests/pylibfdt_tests.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index e8a4582..32a1daa 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -53,7 +53,7 @@ import sys
import types
import unittest
-sys.path.append('../pylibfdt')
+sys.path.insert(0, '../pylibfdt')
import libfdt
from libfdt import FdtException, QUIET_NOTFOUND, QUIET_ALL
@@ -66,7 +66,7 @@ def get_err(err_code):
Returns:
String error code
"""
- return 'pylibfdt error %d: %s' % (-err_code, libfdt.fdt_strerror(-err_code))
+ return 'pylibfdt error %d: %s' % (-err_code, libfdt.strerror(-err_code))
def _ReadFdt(fname):
"""Read a device tree file into an Fdt object, ready for use
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 03/10] tests: Return a failure code when any tests fail
[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 ` Simon Glass
2017-08-19 17:17 ` [PATCH 04/10] pylibfdt: Add support for fdt_get_phandle() Simon Glass
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
At present 'make check' succeeds even if some tests fail. Adjust this so
that we can use things like 'git bisect run make check' to find a failure.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
tests/run_tests.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 3bc5b41..fa7b2f7 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -900,3 +900,4 @@ fi
echo "* Strange test result: $tot_strange"
echo "**********"
+[ "$tot_tests" -eq "$tot_pass" ] || exit 1
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 04/10] pylibfdt: Add support for fdt_get_phandle()
[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 ` Simon Glass
2017-08-19 17:17 ` [PATCH 05/10] pylibfdt: Add support for fdt_parent_offset() Simon Glass
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
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 | 12 ++++++++++++
tests/pylibfdt_tests.py | 6 ++++++
2 files changed, 18 insertions(+)
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index c7b79ec..0731202 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -348,6 +348,18 @@ class Fdt:
return pdata
return bytearray(pdata[0])
+ def get_phandle(self, nodeoffset):
+ """Get the phandle of a node
+
+ Args:
+ nodeoffset: Node offset to check
+
+ Returns:
+ phandle of node, or 0 if the node has no phandle or another error
+ occurs
+ """
+ return fdt_get_phandle(self._fdt, nodeoffset)
+
class Property:
"""Holds a device tree property name and value.
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 32a1daa..14820d5 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -289,5 +289,11 @@ class PyLibfdtTests(unittest.TestCase):
node2 = self.fdt.path_offset('/subnode@2')
self.assertEquals(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2))
+ def testGetPhandle(self):
+ """Test for the get_phandle() method"""
+ self.assertEquals(0, self.fdt.get_phandle(0))
+ node2 = self.fdt.path_offset('/subnode@2')
+ self.assertEquals(0x2000, self.fdt.get_phandle(node2))
+
if __name__ == "__main__":
unittest.main()
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 05/10] pylibfdt: Add support for fdt_parent_offset()
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (2 preceding siblings ...)
2017-08-19 17:17 ` [PATCH 04/10] pylibfdt: Add support for fdt_get_phandle() Simon Glass
@ 2017-08-19 17:17 ` Simon Glass
2017-08-19 17:17 ` [PATCH 06/10] pylibfdt: Add support for fdt_node_offset_by_phandle() Simon Glass
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
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 | 15 +++++++++++++++
tests/pylibfdt_tests.py | 13 +++++++++++++
2 files changed, 28 insertions(+)
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 0731202..5a1eba5 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -360,6 +360,21 @@ class Fdt:
"""
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:
"""Holds a device tree property name and value.
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 14820d5..6b024d4 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -295,5 +295,18 @@ class PyLibfdtTests(unittest.TestCase):
node2 = self.fdt.path_offset('/subnode@2')
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__":
unittest.main()
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 06/10] pylibfdt: Add support for fdt_node_offset_by_phandle()
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (3 preceding siblings ...)
2017-08-19 17:17 ` [PATCH 05/10] pylibfdt: Add support for fdt_parent_offset() Simon Glass
@ 2017-08-19 17:17 ` Simon Glass
2017-08-19 17:18 ` [PATCH 07/10] pylibfdt: Add a method to access the device tree directly Simon Glass
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:17 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
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 | 14 ++++++++++++++
tests/pylibfdt_tests.py | 10 ++++++++++
2 files changed, 24 insertions(+)
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 5a1eba5..d492d58 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -375,6 +375,20 @@ class Fdt:
"""
return check_err(fdt_parent_offset(self._fdt, nodeoffset), quiet)
+ def node_offset_by_phandle(self, phandle, quiet=()):
+ """Get the offset of a node with the given phandle
+
+ Args:
+ phandle: Phandle to search for
+ quiet: Errors to ignore (empty to raise on all errors)
+
+ Returns:
+ The offset of node with that phandle, if any
+
+ Raises:
+ FdtException if no node found or other error occurs
+ """
+ return check_err(fdt_node_offset_by_phandle(self._fdt, phandle), quiet)
class Property:
"""Holds a device tree property name and value.
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 6b024d4..8028c1a 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -308,5 +308,15 @@ class PyLibfdtTests(unittest.TestCase):
node2 = self.fdt.path_offset('/subnode@2/subsubnode@0')
self.assertEquals(node1, self.fdt.parent_offset(node2))
+ def testNodeOffsetByPhandle(self):
+ """Test for the node_offset_by_phandle() method"""
+ self.assertEquals(-libfdt.NOTFOUND,
+ self.fdt.node_offset_by_phandle(1, QUIET_NOTFOUND))
+ node1 = self.fdt.path_offset('/subnode@2')
+ self.assertEquals(node1, self.fdt.node_offset_by_phandle(0x2000))
+ node2 = self.fdt.path_offset('/subnode@2/subsubnode@0')
+ self.assertEquals(node2, self.fdt.node_offset_by_phandle(0x2001))
+
+
if __name__ == "__main__":
unittest.main()
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 07/10] pylibfdt: Add a method to access the device tree directly
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (4 preceding siblings ...)
2017-08-19 17:17 ` [PATCH 06/10] pylibfdt: Add support for fdt_node_offset_by_phandle() Simon Glass
@ 2017-08-19 17:18 ` Simon Glass
[not found] ` <20170819171803.195806-7-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-19 17:18 ` [PATCH 08/10] pylibfdt: Add support for fdt_subnode_offset() Simon Glass
` (2 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:18 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
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>
---
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 d492d58..1f6809e 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 get_fdt(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 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 8028c1a..a775d37 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -285,9 +285,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.get_fdt(), 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.get_fdt(), node2))
def testGetPhandle(self):
"""Test for the get_phandle() method"""
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/10] pylibfdt: Add support for fdt_subnode_offset()
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (5 preceding siblings ...)
2017-08-19 17:18 ` [PATCH 07/10] pylibfdt: Add a method to access the device tree directly Simon Glass
@ 2017-08-19 17:18 ` Simon Glass
2017-08-19 17:18 ` [PATCH 09/10] README: Add a note about test_tree1.dts Simon Glass
2017-08-19 17:18 ` [PATCH 10/10] pylibfdt: Allow reading integer values from properties Simon Glass
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:18 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/10] README: Add a note about test_tree1.dts
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (6 preceding siblings ...)
2017-08-19 17:18 ` [PATCH 08/10] pylibfdt: Add support for fdt_subnode_offset() Simon Glass
@ 2017-08-19 17:18 ` Simon Glass
[not found] ` <20170819171803.195806-9-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-08-19 17:18 ` [PATCH 10/10] pylibfdt: Allow reading integer values from properties Simon Glass
8 siblings, 1 reply; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:18 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
Add a little note in the README about something which confused me.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
README | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/README b/README
index 17dc845..15232ab 100644
--- a/README
+++ b/README
@@ -73,6 +73,17 @@ More work remains to support all of libfdt, including access to numeric
values.
+Tests
+-----
+
+Test files are kept in the tests/ directory. Use 'make check' to build and run
+all tests.
+
+If you want to adjust a test file, be aware that tree_tree1.dts is compiled
+and checked against a binary tree from assembler macros in trees.S. So
+if you change that file you must change tree.S also.
+
+
Mailing list
------------
The following list is for discussion about dtc and libfdt implementation
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 10/10] pylibfdt: Allow reading integer values from properties
[not found] ` <20170819171803.195806-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (7 preceding siblings ...)
2017-08-19 17:18 ` [PATCH 09/10] README: Add a note about test_tree1.dts Simon Glass
@ 2017-08-19 17:18 ` Simon Glass
8 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-19 17:18 UTC (permalink / raw)
To: Devicetree Compiler; +Cc: David Gibson, Simon Glass
Extend the Properties class with some functions to read a single integer
property. Add a new getprop_obj() function to return a Property object
instead of the raw data.
This suggested approach can be extended to handle other types, as well as
arrays.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
pylibfdt/libfdt.i | 35 +++++++++++++++++++++++++++++++++++
tests/pylibfdt_tests.py | 12 ++++++++++++
tests/run_tests.sh | 1 +
tests/test_props.dts | 11 +++++++++++
4 files changed, 59 insertions(+)
create mode 100644 tests/test_props.dts
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index 47d34ae..557e50f 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -376,6 +376,26 @@ class Fdt:
return pdata
return bytearray(pdata[0])
+ def getprop_obj(self, nodeoffset, prop_name, quiet=()):
+ """Get a property from a node as a Property object
+
+ Args:
+ nodeoffset: Node offset containing property to get
+ prop_name: Name of property to get
+ quiet: Errors to ignore (empty to raise on all errors)
+
+ Returns:
+ Property object, or None if not found
+
+ Raises:
+ FdtError if any error occurs (e.g. the property is not found)
+ """
+ pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
+ quiet)
+ if isinstance(pdata, (int)):
+ return None
+ return Property(prop_name, bytearray(pdata[0]))
+
def get_phandle(self, nodeoffset):
"""Get the phandle of a node
@@ -432,6 +452,21 @@ class Property:
def __init__(self, name, value):
self.name = name
self.value = value
+
+ def to_cell(self, fmt):
+ return struct.unpack('>' + fmt, self.value)[0]
+
+ def to_uint32(self):
+ return self.to_cell('L')
+
+ def to_int32(self):
+ return self.to_cell('l')
+
+ def to_uint64(self):
+ return self.to_cell('Q')
+
+ def to_int64(self):
+ return self.to_cell('q')
%}
%rename(fdt_property) fdt_property_func;
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index a6e3354..e071582 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -89,6 +89,7 @@ class PyLibfdtTests(unittest.TestCase):
def setUp(self):
"""Read in the device tree we use for testing"""
self.fdt = _ReadFdt('test_tree1.dtb')
+ self.fdt2 = _ReadFdt('test_props.dtb')
def GetPropList(self, node_path):
"""Read a list of properties from a node
@@ -330,6 +331,17 @@ class PyLibfdtTests(unittest.TestCase):
node2 = self.fdt.path_offset('/subnode@2/subsubnode@0')
self.assertEquals(node2, self.fdt.node_offset_by_phandle(0x2001))
+ def get_prop(self, name):
+ return self.fdt2.getprop_obj(0, name)
+
+ def testGetIntProperties(self):
+ """Test that we can access properties as integers"""
+ self.assertEquals(0xdeadbeef, self.get_prop("prop-hex32").to_uint32())
+ self.assertEquals(123, self.get_prop("prop-uint32").to_uint32())
+ self.assertEquals(-2, self.get_prop("prop-int32").to_int32())
+ self.assertEquals(9223372036854775807,
+ self.get_prop("prop-uint64").to_uint64())
+ self.assertEquals(-2, self.get_prop("prop-int64").to_int64())
if __name__ == "__main__":
unittest.main()
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index fa7b2f7..441e773 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -809,6 +809,7 @@ fdtoverlay_tests() {
}
pylibfdt_tests () {
+ run_dtc_test -I dts -O dtb -o test_props.dtb test_props.dts
TMP=/tmp/tests.stderr.$$
python pylibfdt_tests.py -v 2> $TMP
diff --git a/tests/test_props.dts b/tests/test_props.dts
new file mode 100644
index 0000000..7e59bd1
--- /dev/null
+++ b/tests/test_props.dts
@@ -0,0 +1,11 @@
+/dts-v1/;
+
+/ {
+ compatible = "test_props";
+ prop-hex32 = <0xdeadbeef>;
+ prop-uint32 = <123>;
+ prop-int32 = <0xfffffffe>;
+ prop-hex64 = /bits/ 64 <0xdeadbeef01abcdef>;
+ prop-uint64 = /bits/ 64 <9223372036854775807>;
+ prop-int64 = /bits/ 64 <0xfffffffffffffffe>;
+};
--
2.14.1.480.gb18f417b89-goog
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 07/10] pylibfdt: Add a method to access the device tree directly
[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>
0 siblings, 1 reply; 15+ messages in thread
From: David Gibson @ 2017-08-21 0:17 UTC (permalink / raw)
To: Simon Glass, hg-K0bRW+63XPQe6aEkudXLsA; +Cc: Devicetree Compiler
[-- Attachment #1: Type: text/plain, Size: 2472 bytes --]
On Sat, Aug 19, 2017 at 11:18:00AM -0600, Simon Glass wrote:
> 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>
I've applied patches 1-6 already.
This looks fine, except I'm dubious about the name. "get_fdt" from an
fdt object seems a bit.. tautological? How about "as_bytestring"?
> ---
>
> 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 d492d58..1f6809e 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 get_fdt(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 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 8028c1a..a775d37 100644
> --- a/tests/pylibfdt_tests.py
> +++ b/tests/pylibfdt_tests.py
> @@ -285,9 +285,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.get_fdt(), 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.get_fdt(), node2))
>
> def testGetPhandle(self):
> """Test for the get_phandle() method"""
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/10] README: Add a note about test_tree1.dts
[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>
0 siblings, 1 reply; 15+ messages in thread
From: David Gibson @ 2017-08-21 0:25 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Compiler
[-- Attachment #1: Type: text/plain, Size: 1195 bytes --]
On Sat, Aug 19, 2017 at 11:18:02AM -0600, Simon Glass wrote:
> Add a little note in the README about something which confused me.
>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
I've applied patches 8 & 9.
> ---
>
> README | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/README b/README
> index 17dc845..15232ab 100644
> --- a/README
> +++ b/README
> @@ -73,6 +73,17 @@ More work remains to support all of libfdt, including access to numeric
> values.
>
>
> +Tests
> +-----
> +
> +Test files are kept in the tests/ directory. Use 'make check' to build and run
> +all tests.
> +
> +If you want to adjust a test file, be aware that tree_tree1.dts is compiled
> +and checked against a binary tree from assembler macros in trees.S. So
> +if you change that file you must change tree.S also.
> +
> +
> Mailing list
> ------------
> The following list is for discussion about dtc and libfdt implementation
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 07/10] pylibfdt: Add a method to access the device tree directly
[not found] ` <20170821001714.GC12356-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
@ 2017-08-21 3:04 ` Simon Glass
0 siblings, 0 replies; 15+ messages in thread
From: Simon Glass @ 2017-08-21 3:04 UTC (permalink / raw)
To: David Gibson; +Cc: hg-K0bRW+63XPQe6aEkudXLsA, Devicetree Compiler
Hi David,
On 20 August 2017 at 18:17, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> On Sat, Aug 19, 2017 at 11:18:00AM -0600, Simon Glass wrote:
>> 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>
>
> I've applied patches 1-6 already.
>
> This looks fine, except I'm dubious about the name. "get_fdt" from an
> fdt object seems a bit.. tautological? How about "as_bytestring"?
Well, sure it is.
It is the only way to get something that can be passed to the libfdt
function. So as_bytestring() seems a bit obscure, even though it is
more descriptive. I would suggest get_blob() except we don't really
use that name in libfdt.h.
I will have a think and then send v2.
Regards,
Simon
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/10] README: Add a note about test_tree1.dts
[not found] ` <20170821002557.GD12356-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
@ 2017-08-22 13:39 ` Simon Glass
[not found] ` <CAPnjgZ05qhg5hLAtRGS89qEcrPyfYXtJSjQTzaR0y8z4YOUvQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 15+ messages in thread
From: Simon Glass @ 2017-08-22 13:39 UTC (permalink / raw)
To: David Gibson; +Cc: Devicetree Compiler
Hi David,
On 20 August 2017 at 18:25, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> On Sat, Aug 19, 2017 at 11:18:02AM -0600, Simon Glass wrote:
>> Add a little note in the README about something which confused me.
>>
>> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>
> I've applied patches 8 & 9.
OK thanks. Will they appear at git.kernel.org at some point?
Regards,
Simon
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 09/10] README: Add a note about test_tree1.dts
[not found] ` <CAPnjgZ05qhg5hLAtRGS89qEcrPyfYXtJSjQTzaR0y8z4YOUvQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2017-08-23 0:36 ` David Gibson
0 siblings, 0 replies; 15+ messages in thread
From: David Gibson @ 2017-08-23 0:36 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Compiler
[-- Attachment #1: Type: text/plain, Size: 840 bytes --]
On Tue, Aug 22, 2017 at 07:39:57AM -0600, Simon Glass wrote:
> Hi David,
>
> On 20 August 2017 at 18:25, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> > On Sat, Aug 19, 2017 at 11:18:02AM -0600, Simon Glass wrote:
> >> Add a little note in the README about something which confused me.
> >>
> >> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> >
> > I've applied patches 8 & 9.
>
> OK thanks. Will they appear at git.kernel.org at some point?
Oh, sorry. I pushed it to my github tree to run the Travis tests,
then forgot to push it to kernel.org after. Done now.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2017-08-23 0:36 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 08/10] pylibfdt: Add support for fdt_subnode_offset() Simon Glass
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
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).