[U-Boot] [PATCH 17/30] dtoc: Move to using bytearray

Simon Glass sjg at chromium.org
Tue Jul 26 02:59:13 CEST 2016


Since we want to be able to change the in-memory device tree using libfdt,
use a bytearray instead of a string. This makes interfacing from Python
easier.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 lib/libfdt/libfdt.swig   | 8 ++++++++
 tools/dtoc/fdt_normal.py | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/libfdt/libfdt.swig b/lib/libfdt/libfdt.swig
index 14f583d..26d42fc 100644
--- a/lib/libfdt/libfdt.swig
+++ b/lib/libfdt/libfdt.swig
@@ -75,6 +75,14 @@ struct fdt_property {
     }
 %}
 
+%typemap(in) (const void *) {
+  if (!PyByteArray_Check($input)) {
+    SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument "
+                       "$argnum"" of type '" "$type""'");
+  }
+  $1 = (void *) PyByteArray_AsString($input);
+}
+
 const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
 int fdt_path_offset(const void *fdt, const char *path);
 int fdt_first_property_offset(const void *fdt, int nodeoffset);
diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py
index 4a667a1..eb45742 100644
--- a/tools/dtoc/fdt_normal.py
+++ b/tools/dtoc/fdt_normal.py
@@ -110,7 +110,7 @@ class FdtNormal(Fdt):
             self._fname = fdt_util.EnsureCompiled(self._fname)
 
             with open(self._fname) as fd:
-                self._fdt = fd.read()
+                self._fdt = bytearray(fd.read())
 
     def GetFdt(self):
         """Get the contents of the FDT
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list