aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libfdt/libfdt.swig3
-rw-r--r--tools/dtoc/fdt.py11
-rw-r--r--tools/dtoc/fdt_normal.py18
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/libfdt/libfdt.swig b/lib/libfdt/libfdt.swig
index 0cb7977..b24c72b 100644
--- a/lib/libfdt/libfdt.swig
+++ b/lib/libfdt/libfdt.swig
@@ -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);
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 403eb1f..816fdbe 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -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
diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py
index f2cf608..aae258e 100644
--- a/tools/dtoc/fdt_normal.py
+++ b/tools/dtoc/fdt_normal.py
@@ -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