]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Support missing compression tools
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Fri, 19 Aug 2022 14:25:31 +0000 (16:25 +0200)
committerSimon Glass <sjg@chromium.org>
Sun, 21 Aug 2022 00:07:33 +0000 (18:07 -0600)
Handle missing compression tools by returning empty data and record
missing bintool.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/binman/entry.py
tools/binman/entry_test.py
tools/binman/ftest.py

index af8e277995b9f899175c52d6e75649dd454d3055..88f228682aae41f161cf6d63506d7c8ebb8d2a74 100644 (file)
@@ -1118,7 +1118,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
@@ -1133,8 +1137,12 @@ features to produce new behaviours.
             Decompressed data
         """
         if self.compress != 'none':
-            data = self.comp_bintool.decompress(indata)
-            self.uncomp_size = len(data)
+            if self.comp_bintool.is_present():
+                data = self.comp_bintool.decompress(indata)
+                self.uncomp_size = len(data)
+            else:
+                self.record_missing_bintool(self.comp_bintool)
+                data = tools.get_bytes(0, 1024)
         else:
             data = indata
         self.uncomp_data = data
index 1d60076be114c67cb122e799c100a2a2da9dd433..aa470c581635acb256121c23461ed2bcb740d7a4 100644 (file)
@@ -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()
index 4be84f6e17f6a3db32a18afd99f3d77fc35af401..81ecc8829f975ea6e9a43408e23b3e7f42c51661 100644 (file)
@@ -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()