]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Don't add compression attribute for uncompressed files
authorSimon Glass <sjg@chromium.org>
Sat, 14 Oct 2023 20:40:26 +0000 (14:40 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 3 Nov 2023 02:37:50 +0000 (22:37 -0400)
cbfsutil changed to skip adding a compression attribute if there is no
compression. Adjust the binman implementation to do the same.

This mirrors commit 105cdf5625 in coreboot.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Neha Malcom Francis <n-francis@ti.com>
tools/binman/cbfs_util.py
tools/binman/cbfs_util_test.py
tools/binman/ftest.py

index fc56b40b7531cea6cb03dc67507143dbc36ebe5b..92d2add25146f0e548bcee98f53dd5a3c85f5188 100644 (file)
@@ -333,7 +333,8 @@ class CbfsFile(object):
         if self.ftype == TYPE_STAGE:
             pass
         elif self.ftype == TYPE_RAW:
-            hdr_len += ATTR_COMPRESSION_LEN
+            if self.compress:
+                hdr_len += ATTR_COMPRESSION_LEN
         elif self.ftype == TYPE_EMPTY:
             pass
         else:
@@ -369,9 +370,11 @@ class CbfsFile(object):
                 data = self.comp_bintool.compress(orig_data)
             self.memlen = len(orig_data)
             self.data_len = len(data)
-            attr = struct.pack(ATTR_COMPRESSION_FORMAT,
-                               FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN,
-                               self.compress, self.memlen)
+            if self.compress:
+                attr = struct.pack(ATTR_COMPRESSION_FORMAT,
+                                   FILE_ATTR_TAG_COMPRESSION,
+                                   ATTR_COMPRESSION_LEN, self.compress,
+                                   self.memlen)
         elif self.ftype == TYPE_EMPTY:
             data = tools.get_bytes(self.erase_byte, self.size)
         else:
@@ -405,7 +408,7 @@ class CbfsFile(object):
         if expected_len != actual_len:  # pragma: no cover
             # Test coverage of this is not available since this should never
             # happen. It probably indicates that get_header_len() is broken.
-            raise ValueError("Internal error: CBFS file '%s': Expected headers of %#x bytes, got %#d" %
+            raise ValueError("Internal error: CBFS file '%s': Expected headers of %#x bytes, got %#x" %
                              (self.name, expected_len, actual_len))
         return hdr + name + attr + pad + content + data, hdr_len
 
index ee951d10cf3bfb3651fcd13c241141ebeca57380..c3babbc64e786a82a1d9f36ac94da21cd8a4f5b6 100755 (executable)
@@ -96,7 +96,7 @@ class TestCbfs(unittest.TestCase):
         self.assertEqual(arch, cbfs.arch)
         return cbfs
 
-    def _check_uboot(self, cbfs, ftype=cbfs_util.TYPE_RAW, offset=0x38,
+    def _check_uboot(self, cbfs, ftype=cbfs_util.TYPE_RAW, offset=0x28,
                      data=U_BOOT_DATA, cbfs_offset=None):
         """Check that the U-Boot file is as expected
 
@@ -122,7 +122,7 @@ class TestCbfs(unittest.TestCase):
         self.assertEqual(len(data), cfile.memlen)
         return cfile
 
-    def _check_dtb(self, cbfs, offset=0x38, data=U_BOOT_DTB_DATA,
+    def _check_dtb(self, cbfs, offset=0x28, data=U_BOOT_DTB_DATA,
                    cbfs_offset=None):
         """Check that the U-Boot dtb file is as expected
 
@@ -598,8 +598,8 @@ class TestCbfs(unittest.TestCase):
         data = cbw.get_data()
 
         cbfs = cbfs_util.CbfsReader(data)
-        self.assertEqual(0x38, cbfs.files['u-boot'].cbfs_offset)
-        self.assertEqual(0x78, cbfs.files['u-boot-dtb'].cbfs_offset)
+        self.assertEqual(0x28, cbfs.files['u-boot'].cbfs_offset)
+        self.assertEqual(0x68, cbfs.files['u-boot-dtb'].cbfs_offset)
 
 
 if __name__ == '__main__':
index 16156b741052b06d2aff52dd3be6083d2a1737df..2875194d750ec091801e10f7647124f0ef6d191e 100644 (file)
@@ -2670,9 +2670,9 @@ class TestFunctional(unittest.TestCase):
             'cbfs/u-boot:offset': 0x38,
             'cbfs/u-boot:uncomp-size': len(U_BOOT_DATA),
             'cbfs/u-boot:image-pos': 0x38,
-            'cbfs/u-boot-dtb:offset': 0xb8,
+            'cbfs/u-boot-dtb:offset': 0xa8,
             'cbfs/u-boot-dtb:size': len(U_BOOT_DATA),
-            'cbfs/u-boot-dtb:image-pos': 0xb8,
+            'cbfs/u-boot-dtb:image-pos': 0xa8,
             }, props)
 
     def testCbfsBadType(self):
@@ -2854,7 +2854,7 @@ class TestFunctional(unittest.TestCase):
 '  u-boot                  0     4  u-boot             0',
 '  section               100   %x  section          100' % section_size,
 '    cbfs                100   400  cbfs               0',
-'      u-boot            138     4  u-boot            38',
+'      u-boot            128     4  u-boot            28',
 '      u-boot-dtb        180   105  u-boot-dtb        80          3c9',
 '    u-boot-dtb          500   %x  u-boot-dtb       400          3c9' % fdt_size,
 '  fdtmap                %x   3bd  fdtmap           %x' %