]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Support an assumed size for missing binaries
authorSimon Glass <sjg@chromium.org>
Sun, 23 Jun 2024 17:55:06 +0000 (11:55 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 3 Jul 2024 06:36:33 +0000 (07:36 +0100)
Binman has a the useful feature of handling missing external blobs
gracefully, including allowing them to be missing, deciding whether the
resulting image is functional or not and faking blobs when this is
necessary for particular tools (e.g. mkimage).

This feature is widely used in CI. One drawback is that if U-Boot grows
too large to fit along with the required blobs, then this is not
discovered until someone does a 'real' build which includes the blobs.

Add a 'assume-size' property to entries to allow Binman to reserve a
given size for missing external blobs.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/binman.rst
tools/binman/entry.py
tools/binman/etype/blob.py
tools/binman/ftest.py
tools/binman/test/326_assume_size.dts [new file with mode: 0644]
tools/binman/test/327_assume_size_ok.dts [new file with mode: 0644]

index 230e055667f38063eb8670df438ce9c7b072f78f..872e9746c8cf4f978091294effb5a2d9af1f65ab 100644 (file)
@@ -711,6 +711,13 @@ missing-msg:
     information about what needs to be fixed. See missing-blob-help for the
     message for each tag.
 
+assume-size:
+    Sets the assumed size of a blob entry if it is missing. This allows for a
+    check that the rest of the image fits into the available space, even when
+    the contents are not available. If the entry is missing, Binman will use
+    this assumed size for the entry size, including creating a fake file of that
+    size if requested.
+
 no-expanded:
     By default binman substitutes entries with expanded versions if available,
     so that a `u-boot` entry type turns into `u-boot-expanded`, for example. The
index 2ed65800d22522a0750d8b0a546ba43c3f551509..219d5dcecab75b65b7e2a18de837c0796f880029 100644 (file)
@@ -315,6 +315,7 @@ class Entry(object):
         self.overlap = fdt_util.GetBool(self._node, 'overlap')
         if self.overlap:
             self.required_props += ['offset', 'size']
+        self.assume_size = fdt_util.GetInt(self._node, 'assume-size', 0)
 
         # This is only supported by blobs and sections at present
         self.compress = fdt_util.GetString(self._node, 'compress', 'none')
index 064fae503651c2942e3bfbb8f8432ea5589f64af..041e1122953ef80c0c48735fa8116f56def58f58 100644 (file)
@@ -48,11 +48,16 @@ class Entry_blob(Entry):
             self.external and (self.optional or self.section.GetAllowMissing()))
         # Allow the file to be missing
         if not self._pathname:
+            if not fake_size and self.assume_size:
+                fake_size = self.assume_size
             self._pathname, faked = self.check_fake_fname(self._filename,
                                                           fake_size)
             self.missing = True
             if not faked:
-                self.SetContents(b'')
+                content_size = 0
+                if self.assume_size: # Ensure we get test coverage on next line
+                    content_size = self.assume_size
+                self.SetContents(tools.get_bytes(0, content_size))
                 return True
 
         self.ReadBlobContents()
index 567849bbab0f885cda88bd6888fcfeed0bf792ff..e4da04030a51e6fe921497e53f49cafcf97e73f6 100644 (file)
@@ -7460,5 +7460,33 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         with self.assertRaises(ValueError) as e:
             self._DoReadFile('323_capsule_accept_revert_missing.dts')
 
+    def test_assume_size(self):
+        """Test handling of the assume-size property for external blob"""
+        with self.assertRaises(ValueError) as e:
+            self._DoTestFile('326_assume_size.dts', allow_missing=True,
+                             allow_fake_blobs=True)
+        self.assertIn("contents size 0xa (10) exceeds section size 0x9 (9)",
+                      str(e.exception))
+
+    def test_assume_size_ok(self):
+        """Test handling of the assume-size where it fits OK"""
+        with test_util.capture_sys_output() as (stdout, stderr):
+            self._DoTestFile('327_assume_size_ok.dts', allow_missing=True,
+                             allow_fake_blobs=True)
+        err = stderr.getvalue()
+        self.assertRegex(
+            err,
+            "Image '.*' has faked external blobs and is non-functional: .*")
+
+    def test_assume_size_no_fake(self):
+        """Test handling of the assume-size where it fits OK"""
+        with test_util.capture_sys_output() as (stdout, stderr):
+            self._DoTestFile('327_assume_size_ok.dts', allow_missing=True)
+        err = stderr.getvalue()
+        self.assertRegex(
+            err,
+            "Image '.*' is missing external blobs and is non-functional: .*")
+
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/326_assume_size.dts b/tools/binman/test/326_assume_size.dts
new file mode 100644 (file)
index 0000000..4c5f8b4
--- /dev/null
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               size = <9>;
+               blob-ext {
+                       filename = "assume_blob";
+                       assume-size = <10>;
+               };
+       };
+};
diff --git a/tools/binman/test/327_assume_size_ok.dts b/tools/binman/test/327_assume_size_ok.dts
new file mode 100644 (file)
index 0000000..00ed726
--- /dev/null
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               size = <10>;
+               blob-ext {
+                       filename = "assume_blob";
+                       assume-size = <10>;
+               };
+       };
+};