Re: [U-Boot] [PATCH v2 07/29] libfdt: Bring in proposed pylibfdt changes

2018-07-09 Thread Simon Glass
On 6 July 2018 at 10:27, Simon Glass  wrote:
> This provides various patches sent to the devicetree-compiler mailing list
> to enhance the Python bindings. A final version of this patch may be
> created once upstreaming is complete, but if it takes too long, this can
> act as a placeholder.
>
> New pylibfdt features:
> - Support for most remaining, relevant libfdt functions
> - Support for sequential-write functions
>
> Changes are applied to existing U-Boot tools as needed.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v2: None
>
>  scripts/dtc/libfdt/libfdt.h   |   3 +
>  scripts/dtc/pylibfdt/libfdt.i_shipped | 705 +++---
>  tools/dtoc/dtoc.py|  20 +-
>  tools/dtoc/fdt.py |   3 +-
>  tools/dtoc/test_dtoc.py   |   3 +-
>  5 files changed, 663 insertions(+), 71 deletions(-)


Applied to u-boot-dm
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 07/29] libfdt: Bring in proposed pylibfdt changes

2018-07-06 Thread Simon Glass
This provides various patches sent to the devicetree-compiler mailing list
to enhance the Python bindings. A final version of this patch may be
created once upstreaming is complete, but if it takes too long, this can
act as a placeholder.

New pylibfdt features:
- Support for most remaining, relevant libfdt functions
- Support for sequential-write functions

Changes are applied to existing U-Boot tools as needed.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 scripts/dtc/libfdt/libfdt.h   |   3 +
 scripts/dtc/pylibfdt/libfdt.i_shipped | 705 +++---
 tools/dtoc/dtoc.py|  20 +-
 tools/dtoc/fdt.py |   3 +-
 tools/dtoc/test_dtoc.py   |   3 +-
 5 files changed, 663 insertions(+), 71 deletions(-)

diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
index 1e27780e11..fd73688f9e 100644
--- a/scripts/dtc/libfdt/libfdt.h
+++ b/scripts/dtc/libfdt/libfdt.h
@@ -1313,10 +1313,13 @@ static inline int fdt_property_u64(void *fdt, const 
char *name, uint64_t val)
fdt64_t tmp = cpu_to_fdt64(val);
return fdt_property(fdt, name, , sizeof(tmp));
 }
+
+#ifndef SWIG /* Not available in Python */
 static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
 {
return fdt_property_u32(fdt, name, val);
 }
+#endif
 
 /**
  * fdt_property_placeholder - add a new property and return a ptr to its value
diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped 
b/scripts/dtc/pylibfdt/libfdt.i_shipped
index 2c1c987c1d..6774b93b2c 100644
--- a/scripts/dtc/pylibfdt/libfdt.i_shipped
+++ b/scripts/dtc/pylibfdt/libfdt.i_shipped
@@ -12,6 +12,17 @@
 %{
 #define SWIG_FILE_WITH_INIT
 #include "libfdt.h"
+
+/*
+ * We rename this function here to avoid problems with swig, since we also have
+ * a struct called fdt_property. That struct causes swig to create a class in
+ * libfdt.py called fdt_property(), which confuses things.
+ */
+static int _fdt_property(void *fdt, const char *name, const char *val, int len)
+{
+return fdt_property(fdt, name, val, len);
+}
+
 %}
 
 %pythoncode %{
@@ -108,6 +119,7 @@ def check_err_null(val, quiet=()):
 raise FdtException(val)
 return val
 
+
 class Fdt:
 """Device tree class, supporting all operations
 
@@ -129,6 +141,163 @@ 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 bytearray(self._fdt)
+
+def next_node(self, nodeoffset, depth, quiet=()):
+"""Find the next subnode
+
+Args:
+nodeoffset: Node offset of previous node
+depth: On input, the depth of the node at nodeoffset. On output, 
the
+   depth of the returned node
+quiet: Errors to ignore (empty to raise on all errors)
+
+Returns:
+The offset of the next node, if any
+
+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
+
+Args:
+nodeoffset: Node offset of parent node
+quiet: Errors to ignore (empty to raise on all errors)
+
+Returns:
+The offset of the first subnode, if any
+
+Raises:
+FdtException if no subnodes found or other error occurs
+"""
+return check_err(fdt_first_subnode(self._fdt, nodeoffset), quiet)
+
+def next_subnode(self, nodeoffset, quiet=()):
+"""Find the next subnode
+
+Args:
+nodeoffset: Node offset of previous subnode
+quiet: Errors to ignore (empty to raise on all errors)
+
+Returns:
+The offset of the next subnode, if any
+
+Raises:
+FdtException if no more subnodes found or other error occurs
+"""
+return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet)
+
+def magic(self):
+"""Return the magic word from the header
+
+Returns:
+Magic word
+"""
+return fdt_magic(self._fdt) & 0x
+
+def totalsize(self):
+"""Return the total size of the device tree
+
+Returns:
+Total tree size in bytes
+"""
+return check_err(fdt_totalsize(self._fdt))
+
+def off_dt_struct(self):
+"""Return the start of the device-tree struct area
+
+Returns:
+Start offset of struct area
+"""
+return check_err(fdt_off_dt_struct(self._fdt))
+
+def off_dt_strings(self):
+"""Return the start of the