]> git.baikalelectronics.ru Git - uboot.git/commitdiff
binman: Mark mkimage entry missing when its subnodes is missing
authorJonas Karlman <jonas@kwiboo.se>
Sat, 25 Feb 2023 19:01:35 +0000 (19:01 +0000)
committerKever Yang <kever.yang@rock-chips.com>
Tue, 28 Feb 2023 10:07:26 +0000 (18:07 +0800)
Using the mkimage entry with the multiple-data-files prop and having a
missing external blob result in an unexpected ValueError exception using
the --allow-missing flag.

  ValueError: Filename 'missing.bin' not found in input path (...)

Fix this by using _pathname that is resolved by ObtainContents for blob
entries, ObtainContents also handles allow missing for external blobs.

Mark mkimage entry as missing and return without running mkimage when
missing entries is reported by CheckMissing.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
tools/binman/etype/mkimage.py
tools/binman/ftest.py
tools/binman/test/278_mkimage_missing_multiple.dts [new file with mode: 0644]

index cb264c3cad0b945b70334906af586be1eccaafa7..8a13d5ea8d77e0d8523f76df0c2f8f1d12390cff 100644 (file)
@@ -156,7 +156,8 @@ class Entry_mkimage(Entry):
             for entry in self._mkimage_entries.values():
                 if not entry.ObtainContents(fake_size=fake_size):
                     return False
-                fnames.append(tools.get_input_filename(entry.GetDefaultFilename()))
+                if entry._pathname:
+                    fnames.append(entry._pathname)
             input_fname = ":".join(fnames)
         else:
             data, input_fname, uniq = self.collect_contents_to_file(
@@ -171,6 +172,13 @@ class Entry_mkimage(Entry):
         outfile = self._filename if self._filename else 'mkimage-out.%s' % uniq
         output_fname = tools.get_output_filename(outfile)
 
+        missing_list = []
+        self.CheckMissing(missing_list)
+        self.missing = bool(missing_list)
+        if self.missing:
+            self.SetContents(b'')
+            return self.allow_missing
+
         args = ['-d', input_fname]
         if self._data_to_imagename:
             args += ['-n', input_fname]
@@ -216,6 +224,20 @@ class Entry_mkimage(Entry):
         if self._imagename:
             self._imagename.SetAllowFakeBlob(allow_fake)
 
+    def CheckMissing(self, missing_list):
+        """Check if any entries in this section have missing external blobs
+
+        If there are missing (non-optional) blobs, the entries are added to the
+        list
+
+        Args:
+            missing_list: List of Entry objects to be added to
+        """
+        for entry in self._mkimage_entries.values():
+            entry.CheckMissing(missing_list)
+        if self._imagename:
+            self._imagename.CheckMissing(missing_list)
+
     def CheckFakedBlobs(self, faked_blobs_list):
         """Check if any entries in this section have faked external blobs
 
index 48ac1540bfd86ff2b5fb851cc0bfd3390932912a..d74aa90a620743caad0658dbd0d82c83183e58c0 100644 (file)
@@ -6393,6 +6393,17 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         data = self._DoReadFile('277_rockchip_tpl.dts')
         self.assertEqual(ROCKCHIP_TPL_DATA, data[:len(ROCKCHIP_TPL_DATA)])
 
+    def testMkimageMissingBlobMultiple(self):
+        """Test missing blob with mkimage entry and multiple-data-files"""
+        with test_util.capture_sys_output() as (stdout, stderr):
+            self._DoTestFile('278_mkimage_missing_multiple.dts', allow_missing=True)
+        err = stderr.getvalue()
+        self.assertIn("is missing external blobs and is non-functional", err)
+
+        with self.assertRaises(ValueError) as e:
+            self._DoTestFile('278_mkimage_missing_multiple.dts', allow_missing=False)
+        self.assertIn("not found in input path", str(e.exception))
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/278_mkimage_missing_multiple.dts b/tools/binman/test/278_mkimage_missing_multiple.dts
new file mode 100644 (file)
index 0000000..f84aea4
--- /dev/null
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               mkimage {
+                       args = "-n test -T script";
+                       multiple-data-files;
+
+                       blob-ext {
+                               filename = "missing.bin";
+                       };
+               };
+       };
+};