dtoc: Add a way to create an Fdt object from a data block
Support creating an Fdt object without having to write the data to a file
first.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index c5054e8..2df2d4b 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -472,6 +472,20 @@
with open(self._fname) as fd:
self._fdt_obj = libfdt.Fdt(fd.read())
+ @staticmethod
+ def FromData(data):
+ """Create a new Fdt object from the given data
+
+ Args:
+ data: Device-tree data blob
+
+ Returns:
+ Fdt object containing the data
+ """
+ fdt = Fdt(None)
+ fdt._fdt_obj = libfdt.Fdt(bytearray(data))
+ return fdt
+
def LookupPhandle(self, phandle):
"""Look up a phandle