]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fdt: Support use of the new python libfdt library
authorSimon Glass <sjg@chromium.org>
Sat, 27 May 2017 13:38:22 +0000 (07:38 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 2 Jun 2017 16:16:48 +0000 (10:16 -0600)
Use the new library if available, while retaining backwards compatibility
with the old library for now.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/binman.py
tools/dtoc/fdt.py
tools/dtoc/fdt_normal.py

index 857d698b4c249994dfa0b0321a2a355fef3d1891..95d3a048d86ac05b4c39726eb5292a8cee85205b 100755 (executable)
@@ -21,6 +21,9 @@ sys.path.append(os.path.join(our_path, '../patman'))
 sys.path.append(os.path.join(our_path, '../dtoc'))
 sys.path.append(os.path.join(our_path, '../'))
 
+# Bring in the libfdt module
+sys.path.append('tools')
+
 # Also allow entry-type modules to be brought in from the etype directory.
 sys.path.append(os.path.join(our_path, 'etype'))
 
index 816fdbe5258523a0c9f8074bd463229a9f60d302..c40b9b6babc9ac12e1c042cbaae1f28501a5ec25 100644 (file)
@@ -96,6 +96,7 @@ class PropBase:
                     TYPE_INT: a byte-swapped integer stored as a 4-byte string
                     TYPE_BYTE: a byte stored as a single-byte string
         """
+        bytes = str(bytes)
         size = len(bytes)
         strings = bytes.split('\0')
         is_string = True
index 17b0a9a7262ab21b364759f6c59d5ac9ed1a51fd..e793f49fa8fa1d50c0b24e1ebde729d1214b9c29 100644 (file)
@@ -12,7 +12,13 @@ import sys
 import fdt
 from fdt import Fdt, NodeBase, PropBase
 import fdt_util
-import libfdt_legacy as libfdt
+try:
+    import libfdt
+    legacy = False
+except ImportError:
+    import libfdt_legacy as libfdt
+    legacy = True
+
 
 # This deals with a device tree, presenting it as a list of Node and Prop
 # objects, representing nodes and properties, respectively.
@@ -36,7 +42,7 @@ class Prop(PropBase):
     """
     def __init__(self, node, offset, name, bytes):
         PropBase.__init__(self, node, offset, name)
-        self.bytes = bytes
+        self.bytes = str(bytes)
         if not bytes:
             self.type = fdt.TYPE_BOOL
             self.value = True
@@ -86,7 +92,10 @@ class Node(NodeBase):
         offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset())
         while offset >= 0:
             sep = '' if self.path[-1] == '/' else '/'
-            name = libfdt.Name(self._fdt.GetFdt(), offset)
+            if legacy:
+                name = libfdt.Name(self._fdt.GetFdt(), offset)
+            else:
+                name = self._fdt._fdt_obj.get_name(offset)
             path = self.path + sep + name
             node = Node(self._fdt, offset, name, path)
             self.subnodes.append(node)
@@ -139,6 +148,8 @@ class FdtNormal(Fdt):
 
             with open(self._fname) as fd:
                 self._fdt = bytearray(fd.read())
+                if not legacy:
+                    self._fdt_obj = libfdt.Fdt(self._fdt)
 
     def GetFdt(self):
         """Get the contents of the FDT
@@ -175,12 +186,18 @@ class FdtNormal(Fdt):
         props_dict = {}
         poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset)
         while poffset >= 0:
-            dprop, plen = libfdt.fdt_get_property_by_offset(self._fdt, poffset)
-            prop = Prop(node, poffset, libfdt.String(self._fdt, dprop.nameoff),
-                        libfdt.Data(dprop))
-            props_dict[prop.name] = prop
-
-            poffset = libfdt.fdt_next_property_offset(self._fdt, poffset)
+            if legacy:
+                dprop, plen = libfdt.fdt_get_property_by_offset(self._fdt,
+                                                                poffset)
+                prop = Prop(node, poffset,
+                            libfdt.String(self._fdt, dprop.nameoff),
+                            libfdt.Data(dprop))
+            else:
+                p = self._fdt_obj.get_property_by_offset(poffset)
+                prop = Prop(node, poffset, p.name, p.value)
+                props_dict[prop.name] = prop
+
+                poffset = libfdt.fdt_next_property_offset(self._fdt, poffset)
         return props_dict
 
     def Invalidate(self):