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>
const char *fdt_strerror(int errval);
int fdt_pack(void *fdt);
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);
+ 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
class NodeBase:
"""A device tree node
return
self.type, self.value = self.BytesToValue(bytes)
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
class Node(NodeBase):
"""A device tree node
"""Refresh the offset cache"""
self._root.Refresh(0)
"""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
@classmethod
def Node(self, fdt, offset, name, path):
"""Create a new node