]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dtoc: Support finding the offset of a property
authorSimon Glass <sjg@chromium.org>
Tue, 26 Jul 2016 00:59:16 +0000 (18:59 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 19 Sep 2016 03:04:39 +0000 (21:04 -0600)
Add a way to find the byte offset of a property within the device tree. This
is only supported with the normal libfdt implementation since fdtget does
not provide this information.

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

index 0cb7977ffe5ebeec6cb2baf2216cd48fa4e42af7..b24c72b1a22ba5d87224e6e2b5e922757d948d8b 100644 (file)
@@ -108,3 +108,6 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name);
 
 const char *fdt_strerror(int errval);
 int fdt_pack(void *fdt);
+
+int fdt_totalsize(const void *fdt);
+int fdt_off_dt_struct(const void *fdt);
index 403eb1fe6d0507d0233d2563fe8089d760f34823..816fdbe5258523a0c9f8074bd463229a9f60d302 100644 (file)
@@ -144,6 +144,17 @@ class PropBase:
         else:
             return True
 
+    def GetOffset(self):
+        """Get the offset of a property
+
+        This can be implemented by subclasses.
+
+        Returns:
+            The offset of the property (struct fdt_property) within the
+            file, or None if not known.
+        """
+        return None
+
 class NodeBase:
     """A device tree node
 
index f2cf608b1e881c7e778844251f39c055bd96cfe9..aae258e4128accd2095798664861a666856cdcd4 100644 (file)
@@ -43,6 +43,14 @@ class Prop(PropBase):
             return
         self.type, self.value = self.BytesToValue(bytes)
 
+    def GetOffset(self):
+        """Get the offset of a property
+
+        Returns:
+            The offset of the property (struct fdt_property) within the file
+        """
+        return self._node._fdt.GetStructOffset(self._offset)
+
 class Node(NodeBase):
     """A device tree node
 
@@ -193,6 +201,16 @@ class FdtNormal(Fdt):
         """Refresh the offset cache"""
         self._root.Refresh(0)
 
+    def GetStructOffset(self, offset):
+        """Get the file offset of a given struct offset
+
+        Args:
+            offset: Offset within the 'struct' region of the device tree
+        Returns:
+            Position of @offset within the device tree binary
+        """
+        return libfdt.fdt_off_dt_struct(self._fdt) + offset
+
     @classmethod
     def Node(self, fdt, offset, name, path):
         """Create a new node