[PATCH v5 14/21] binman: Support missing compression tools

Stefan Herbrechtsmeier stefan.herbrechtsmeier-oss at weidmueller.com
Fri Aug 19 16:00:28 CEST 2022


From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier at weidmueller.com>

Handle missing compression tools by returning empty data and record
missing bintool.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier at weidmueller.com>
---

Changes in v5:
- Use record_missing_bintool function
- Use tools.get_bytes function
- Add support to DecompressData function
- Reuse 85_compress_section.dts file
- Remove 236_compress_dtb_missing_bintool.dts file

Changes in v4:
- Add missing 236_compress_dtb_missing_bintool.dts file

Changes in v3:
- Add commit to support missing compression tools

 tools/binman/entry.py      | 12 ++++++++++--
 tools/binman/entry_test.py |  9 +++++++++
 tools/binman/ftest.py      |  9 +++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 6a6c3e6bb4..31389be672 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -1084,7 +1084,11 @@ features to produce new behaviours.
         self.uncomp_data = indata
         if self.compress != 'none':
             self.uncomp_size = len(indata)
-            data = self.comp_bintool.compress(indata)
+            if self.comp_bintool.is_present():
+                data = self.comp_bintool.compress(indata)
+            else:
+                self.record_missing_bintool(self.comp_bintool)
+                data = tools.get_bytes(0, 1024)
         else:
             data = indata
         return data
@@ -1100,7 +1104,11 @@ features to produce new behaviours.
         """
         if self.compress != 'none':
             self.uncomp_size = len(data)
-            data = self.comp_bintool.decompress(indata)
+            if self.comp_bintool.is_present():
+                data = self.comp_bintool.decompress(indata)
+            else:
+                self.record_missing_bintool(self.comp_bintool)
+                return tools.get_bytes(0, 1024)
         else:
             data = indata
         self.uncomp_data = data
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index 1d60076be1..aa470c5816 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -105,6 +105,15 @@ class TestEntry(unittest.TestCase):
         self.assertTrue(isinstance(ent, Entry_blob))
         self.assertEquals('missing', ent.etype)
 
+    def testDecompressData(self):
+        """Test the DecompressData() method of the base class"""
+        base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
+        base.compress = 'lz4'
+        bintools = {}
+        base.comp_bintool = base.AddBintool(bintools, '_testing')
+        self.assertEquals(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
+        self.assertEquals(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 939b265d7c..ffcd7d2567 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -4422,6 +4422,15 @@ class TestFunctional(unittest.TestCase):
             }
         self.assertEqual(expected, props)
 
+    def testLz4Missing(self):
+        """Test that binman still produces an image if lz4 is missing"""
+        with test_util.capture_sys_output() as (_, stderr):
+            self._DoTestFile('185_compress_section.dts',
+                             force_missing_bintools='lz4')
+        err = stderr.getvalue()
+        self.assertRegex(err,
+                         "Image 'main-section'.*missing bintools.*: lz4")
+
     def testCompressExtra(self):
         """Test compression of a section with no fixed size"""
         self._CheckLz4()
-- 
2.30.2



More information about the U-Boot mailing list