]> git.baikalelectronics.ru Git - uboot.git/commitdiff
binman: Allow mkimage to use a non-zero fake-blob size
authorSimon Glass <sjg@chromium.org>
Sun, 6 Mar 2022 03:19:05 +0000 (20:19 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 19 Mar 2022 01:24:25 +0000 (19:24 -0600)
Unfortunately mkimage gets upset with zero-sized files. Update the
ObtainContents() method to support specifying the size, if a fake blob is
created.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
tools/binman/entry.py
tools/binman/etype/_testing.py
tools/binman/etype/blob.py
tools/binman/etype/mkimage.py
tools/binman/etype/section.py
tools/binman/ftest.py
tools/binman/test/229_mkimage_missing.dts [new file with mode: 0644]

index 21d3457788a116353952ceee98fc3f0cfa0a3d7b..18a7a3510548552f9277471e44cea32eeed4172e 100644 (file)
@@ -417,9 +417,13 @@ class Entry(object):
         self.SetContents(data)
         return size_ok
 
-    def ObtainContents(self):
+    def ObtainContents(self, skip_entry=None, fake_size=0):
         """Figure out the contents of an entry.
 
+        Args:
+            skip_entry (Entry): Entry to skip when obtaining section contents
+            fake_size (int): Size of fake file to create if needed
+
         Returns:
             True if the contents were found, False if another call is needed
             after the other entries are processed.
@@ -1132,12 +1136,13 @@ features to produce new behaviours.
         """
         self.update_hash = update_hash
 
-    def collect_contents_to_file(self, entries, prefix):
+    def collect_contents_to_file(self, entries, prefix, fake_size=0):
         """Put the contents of a list of entries into a file
 
         Args:
             entries (list of Entry): Entries to collect
             prefix (str): Filename prefix of file to write to
+            fake_size (int): Size of fake file to create if needed
 
         If any entry does not have contents yet, this function returns False
         for the data.
@@ -1152,7 +1157,7 @@ features to produce new behaviours.
         for entry in entries:
             # First get the input data and put it in a file. If not available,
             # try later.
-            if not entry.ObtainContents():
+            if not entry.ObtainContents(fake_size=fake_size):
                 return None, None, None
             data += entry.GetData()
         uniq = self.GetUniqueName()
index 0800c25899a5336cfe5773704b7429cb48d21c7e..5089de36429459da65acf561691f72e361fba3fc 100644 (file)
@@ -82,7 +82,7 @@ class Entry__testing(Entry):
         self.return_contents = True
         self.contents = b'aa'
 
-    def ObtainContents(self):
+    def ObtainContents(self, fake_size=0):
         if self.return_unknown_contents or not self.return_contents:
             return False
         if self.return_contents_later:
index 89f089e740ef5d2cbefa00f83e3f742197b7c886..ceaefb07b73c44c19b8d80953ac1acc278d7dce9 100644 (file)
@@ -35,13 +35,14 @@ class Entry_blob(Entry):
         super().__init__(section, etype, node)
         self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
 
-    def ObtainContents(self):
+    def ObtainContents(self, fake_size=0):
         self._filename = self.GetDefaultFilename()
         self._pathname = tools.get_input_filename(self._filename,
             self.external and self.section.GetAllowMissing())
         # Allow the file to be missing
         if not self._pathname:
-            self._pathname, faked = self.check_fake_fname(self._filename)
+            self._pathname, faked = self.check_fake_fname(self._filename,
+                                                          fake_size)
             self.missing = True
             if not faked:
                 self.SetContents(b'')
index 9f4717e4eab9ed953e3834abc451e399e4fb1a87..5f6def2287f67ad32739abd78b14c423c7e69848 100644 (file)
@@ -51,8 +51,9 @@ class Entry_mkimage(Entry):
         self.ReadEntries()
 
     def ObtainContents(self):
+        # Use a non-zero size for any fake files to keep mkimage happy
         data, input_fname, uniq = self.collect_contents_to_file(
-            self._mkimage_entries.values(), 'mkimage')
+            self._mkimage_entries.values(), 'mkimage', 1024)
         if data is None:
             return False
         output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
@@ -73,6 +74,16 @@ class Entry_mkimage(Entry):
             entry.ReadNode()
             self._mkimage_entries[entry.name] = entry
 
+    def SetAllowMissing(self, allow_missing):
+        """Set whether a section allows missing external blobs
+
+        Args:
+            allow_missing: True if allowed, False if not allowed
+        """
+        self.allow_missing = allow_missing
+        for entry in self._mkimage_entries.values():
+            entry.SetAllowMissing(allow_missing)
+
     def SetAllowFakeBlob(self, allow_fake):
         """Set whether the sub nodes allows to create a fake blob
 
index ac61d3de28a6aae17601fcd11b230b43e5af3499..ccac658c1831b6813fa688da42fe8bc9ff1e0e9b 100644 (file)
@@ -247,7 +247,7 @@ class Entry_section(Entry):
         for entry in self._entries.values():
             entry.AddMissingProperties(have_image_pos)
 
-    def ObtainContents(self, skip_entry=None):
+    def ObtainContents(self, fake_size=0, skip_entry=None):
         return self.GetEntryContents(skip_entry=skip_entry)
 
     def GetPaddedDataForEntry(self, entry, entry_data):
index 18a6b140d54aa74504ea5d6f8f2aa079a7f350f8..3d672e6e3e886b7ae20e9ef377adb79b95caf1cb 100644 (file)
@@ -5314,6 +5314,16 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             "Node '/binman/u-boot': Please use 'extend-size' instead of 'expand-size'",
             str(e.exception))
 
+    def testMkimageMissingBlob(self):
+        """Test using mkimage to build an image"""
+        with test_util.capture_sys_output() as (stdout, stderr):
+            self._DoTestFile('229_mkimage_missing.dts', allow_missing=True,
+                             allow_fake_blobs=True)
+        err = stderr.getvalue()
+        self.assertRegex(
+            err,
+            "Image '.*' has faked external blobs and is non-functional: .*")
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/229_mkimage_missing.dts b/tools/binman/test/229_mkimage_missing.dts
new file mode 100644 (file)
index 0000000..54a5a6c
--- /dev/null
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               mkimage {
+                       args = "-n test -T script";
+
+                       blob-ext {
+                               filename = "missing.bin";
+                       };
+               };
+       };
+};