]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Don't reset offset/size if image doesn't allow repacking
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>
Sun, 27 Mar 2022 15:31:46 +0000 (18:31 +0300)
committerTom Rini <trini@konsulko.com>
Mon, 25 Apr 2022 14:11:05 +0000 (10:11 -0400)
When an image has the 'allow-repack' property, binman includes the
original offset and size properties from the image description in the
fdtmap. These are later used as the packing constraints when replacing
entries in an image, so other unconstrained entries can be freely
positioned.

Replacing an entry in an image without 'allow-repack' (and therefore the
original offsets) follows the same logic and results in entries being
merely concatenated. Instead, skip resetting the calculated offsets and
sizes to the missing originals for these images so that every entry is
constrained to its existing offset/size.

Add tests that replace an entry with smaller or equal-sized data, in an
image that doesn't allow repacking. Attempting to do so with bigger-size
data is already an error that is already being tested.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/binman/control.py
tools/binman/ftest.py

index e170aeae4fab07b10169a8966b4eae5134ce7d41..ce57dc7efc7bf69ee160bc067666ce83fc377b9e 100644 (file)
@@ -303,7 +303,7 @@ def BeforeReplace(image, allow_resize):
 
     # If repacking, drop the old offset/size values except for the original
     # ones, so we are only left with the constraints.
-    if allow_resize:
+    if image.allow_repack and allow_resize:
         image.ResetForPack()
 
 
index 03e6d9233b2af0f954f30584c3236791cfc3c5f3..c9a82094c56831924703b02f0a194cb8fe19a692 100644 (file)
@@ -5592,6 +5592,27 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         finally:
             shutil.rmtree(tmpdir)
 
+    def testReplaceResizeNoRepackSameSize(self):
+        """Test replacing entries with same-size data without repacking"""
+        expected = b'x' * len(U_BOOT_DATA)
+        data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', expected)
+        self.assertEqual(expected, data)
+
+        path, fdtmap = state.GetFdtContents('fdtmap')
+        self.assertIsNotNone(path)
+        self.assertEqual(expected_fdtmap, fdtmap)
+
+    def testReplaceResizeNoRepackSmallerSize(self):
+        """Test replacing entries with smaller-size data without repacking"""
+        new_data = b'x'
+        data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', new_data)
+        expected = new_data.ljust(len(U_BOOT_DATA), b'\0')
+        self.assertEqual(expected, data)
+
+        path, fdtmap = state.GetFdtContents('fdtmap')
+        self.assertIsNotNone(path)
+        self.assertEqual(expected_fdtmap, fdtmap)
+
 
 if __name__ == "__main__":
     unittest.main()