At present the logic skips the blob class' handling of compression, so
this is not supported with device tree entries. Fix this.
Signed-off-by: Simon Glass
---
Changes in v2:
- Update test to use _DoReadFileRealDtb() helper
tools/binman/etype/blob.py | 25 +
tools/binman/etype/blob_dtb.py | 8
tools/binman/ftest.py | 18 ++
tools/binman/test/124_compress_dtb.dts | 14 ++
4 files changed, 53 insertions(+), 12 deletions(-)
create mode 100644 tools/binman/test/124_compress_dtb.dts
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index ec94568ac0a..a4ff0efcebc 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -41,17 +41,26 @@ class Entry_blob(Entry):
self.ReadBlobContents()
return True
-def ReadBlobContents(self):
-# We assume the data is small enough to fit into memory. If this
-# is used for large filesystem image that might not be true.
-# In that case, Image.BuildImage() could be adjusted to use a
-# new Entry method which can read in chunks. Then we could copy
-# the data in chunks and avoid reading it all at once. For now
-# this seems like an unnecessary complication.
-indata = tools.ReadFile(self._pathname)
+def CompressData(self, indata):
if self.compress != 'none':
self.uncomp_size = len(indata)
data = tools.Compress(indata, self.compress)
+return data
+
+def ReadBlobContents(self):
+"""Read blob contents into memory
+
+This function compresses the data before storing if needed.
+
+We assume the data is small enough to fit into memory. If this
+is used for large filesystem image that might not be true.
+In that case, Image.BuildImage() could be adjusted to use a
+new Entry method which can read in chunks. Then we could copy
+the data in chunks and avoid reading it all at once. For now
+this seems like an unnecessary complication.
+"""
+indata = tools.ReadFile(self._pathname)
+data = self.CompressData(indata)
self.SetContents(data)
return True
diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py
index 09d5d727138..88ed55d8865 100644
--- a/tools/binman/etype/blob_dtb.py
+++ b/tools/binman/etype/blob_dtb.py
@@ -23,11 +23,11 @@ class Entry_blob_dtb(Entry_blob):
def ObtainContents(self):
"""Get the device-tree from the list held by the 'state' module"""
self._filename = self.GetDefaultFilename()
-self._pathname, data = state.GetFdtContents(self._filename)
-self.SetContents(data)
-return True
+self._pathname, _ = state.GetFdtContents(self._filename)
+return Entry_blob.ReadBlobContents(self)
def ProcessContents(self):
"""Re-read the DTB contents so that we get any calculated properties"""
-_, data = state.GetFdtContents(self._filename)
+_, indata = state.GetFdtContents(self._filename)
+data = self.CompressData(indata)
return self.ProcessContentsUpdate(data)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index aae8dbc1b33..89e732fca31 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -2142,6 +2142,24 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)])
self.assertEqual(b'aa', data[-2:])
+def testCompressDtb(self):
+"""Test that compress of device-tree files is supported"""
+self._CheckLz4()
+data = self.data = self._DoReadFileRealDtb('124_compress_dtb.dts')
+self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)])
+comp_data = data[len(U_BOOT_DATA):]
+orig = self._decompress(comp_data)
+dtb = fdt.Fdt.FromData(orig)
+dtb.Scan()
+props = self._GetPropTree(dtb, ['size', 'uncomp-size'])
+expected = {
+'u-boot:size': len(U_BOOT_DATA),
+'u-boot-dtb:uncomp-size': len(orig),
+'u-boot-dtb:size': len(comp_data),
+'size': len(data),
+}
+self.assertEqual(expected, props)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/binman/test/124_compress_dtb.dts
b/tools/binman/test/124_compress_dtb.dts
new file mode 100644
index 000..46bfd8b265f
--- /dev/null
+++ b/tools/binman/test/124_compress_dtb.dts
@@ -0,0 +1,14 @@
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ u-boot {
+ };
+ u-boot-dtb {
+ compress = "lz4";
+ };
+ };
+};
--
2.22.0.410.gd8fdbe21b5-goog
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot