Support creating an Fdt object without having to write the data to a file first.
Signed-off-by: Simon Glass <s...@chromium.org> --- tools/dtoc/fdt.py | 14 ++++++++++++++ tools/dtoc/test_fdt.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index c5054e8cc91..2df2d4b0cc7 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -472,6 +472,20 @@ class Fdt: 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 diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 22a075d6c57..d2597020500 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -407,6 +407,14 @@ class TestProp(unittest.TestCase): self.node.SetData('empty', '123') self.assertEqual('123', prop.bytes) + def testFromData(self): + dtb2 = fdt.Fdt.FromData(self.dtb.GetContents()) + self.assertEqual(dtb2.GetContents(), self.dtb.GetContents()) + + self.node.AddEmptyProp('empty', 5) + self.dtb.Sync(auto_resize=True) + self.assertTrue(dtb2.GetContents() != self.dtb.GetContents()) + class TestFdtUtil(unittest.TestCase): """Tests for the fdt_util module -- 2.19.0.397.gdd90340f6a-goog _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot