All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>,
	Tom Rini <trini@konsulko.com>,
	Philippe Reynes <philippe.reynes@softathome.com>,
	Roger Quadros <rogerq@ti.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	huang lin <hl@rock-chips.com>,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Simon Glass <sjg@chromium.org>,
	Kever Yang <kever.yang@rock-chips.com>,
	Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Subject: [PATCH v2 14/25] binman: Allow mkimage to use a non-zero fake-blob size
Date: Wed, 23 Feb 2022 16:00:29 -0700	[thread overview]
Message-ID: <20220223230040.159317-15-sjg@chromium.org> (raw)
In-Reply-To: <20220223230040.159317-1-sjg@chromium.org>

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>
---

Changes in v2:
- Add a patch to allow mkimage to use a non-zero fake-blob size

 tools/binman/entry.py                     | 11 ++++++++---
 tools/binman/etype/_testing.py            |  2 +-
 tools/binman/etype/blob.py                |  5 +++--
 tools/binman/etype/mkimage.py             | 13 ++++++++++++-
 tools/binman/etype/section.py             |  2 +-
 tools/binman/ftest.py                     | 10 ++++++++++
 tools/binman/test/229_mkimage_missing.dts | 18 ++++++++++++++++++
 7 files changed, 53 insertions(+), 8 deletions(-)
 create mode 100644 tools/binman/test/229_mkimage_missing.dts

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e4c0fbe23d..249f117ace 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -415,9 +415,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.
@@ -1130,12 +1134,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.
@@ -1150,7 +1155,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()
diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py
index 0800c25899..5089de3642 100644
--- a/tools/binman/etype/_testing.py
+++ b/tools/binman/etype/_testing.py
@@ -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:
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index 89f089e740..ceaefb07b7 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -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'')
diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index 9f4717e4ea..5f6def2287 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -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
 
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 16ee5ed723..fab42c20f7 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -246,7 +246,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):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 4eac913d06..106027d245 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5330,6 +5330,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
index 0000000000..54a5a6c571
--- /dev/null
+++ b/tools/binman/test/229_mkimage_missing.dts
@@ -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";
+			};
+		};
+	};
+};
-- 
2.35.1.574.g5d30c73bfb-goog


  parent reply	other threads:[~2022-02-23 23:05 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 23:00 [PATCH v2 00/25] binman: rockchip: Migrate from rockchip SPL_FIT_GENERATOR script Simon Glass
2022-02-23 23:00 ` [PATCH v2 01/25] dtoc: Make GetArgs() more flexible Simon Glass
2022-03-03 21:07   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 02/25] moveconfig: Remove remove_defconfig() Simon Glass
2022-03-03 21:07   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 03/25] moveconfig: Use re.fullmatch() to avoid extra check Simon Glass
2022-03-03 21:07   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 04/25] spl: Correct Kconfig help for TPL_BINMAN_SYMBOLS Simon Glass
2022-03-03 21:08   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList() Simon Glass
2022-03-03 21:08   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 06/25] elf: Rename load_segments() and module failure Simon Glass
2022-03-03 21:08   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 07/25] binman: Tweak collect_contents_to_file() and docs Simon Glass
2022-03-03 21:08   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 08/25] binman: Rename ExpandToLimit to extend_to_limit Simon Glass
2022-03-03 21:08   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 09/25] binman: Rename ExpandEntries to gen_entries Simon Glass
2022-03-03 21:09   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 10/25] binman: Refactor fit to generate output at the end Simon Glass
2022-03-03 21:09   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 11/25] binman: Rename tools parameter to btools Simon Glass
2022-03-03 21:09   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 12/25] binman: Change how faked blobs are created Simon Glass
2022-03-03 21:09   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-03-10 19:29       ` Alper Nebi Yasak
2022-03-12  5:02         ` Simon Glass
2022-03-14 21:29           ` Alper Nebi Yasak
2022-03-14 22:20             ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 13/25] binman: Make fake blobs zero-sized by default Simon Glass
2022-03-03 21:09   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-02-23 23:00 ` Simon Glass [this message]
2022-03-03 21:09   ` [PATCH v2 14/25] binman: Allow mkimage to use a non-zero fake-blob size Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-03-10 19:30       ` Alper Nebi Yasak
2022-03-12  5:02         ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 15/25] binman: Read the fit entries only once Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 16/25] binman: Fix some pylint warnings in fit Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 17/25] binman: Add a consistent way to report errors with fit Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 18/25] binman: Update fit to use node instead of subnode Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 19/25] binman: Keep a separate list of entries for fit Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-03-10 19:30       ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 20/25] binman: Support splitting an ELF file into multiple nodes Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-03-06  3:08     ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 21/25] rockchip: evb-rk3288: Drop raw-image support Simon Glass
2022-02-23 23:00 ` [PATCH v2 22/25] rockchip: Include binman script in 64-bit boards Simon Glass
2022-03-03 21:10   ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 23/25] rockchip: Support building the all output files in binman Simon Glass
2022-03-02 22:16   ` Peter Geis
2022-03-03 21:11     ` Alper Nebi Yasak
2022-03-03 22:34       ` Peter Geis
2022-03-06  3:08         ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 24/25] rockchip: Convert all boards to use binman Simon Glass
2022-02-23 23:00 ` [PATCH v2 25/25] rockchip: Drop the FIT generator script Simon Glass
2022-03-01  2:48 ` [RFC] [PATCH] binman: support mkimage split files Peter Geis
2022-03-03 21:11   ` Alper Nebi Yasak
2022-03-04 17:47     ` Peter Geis
2022-03-04 19:56       ` [PATCH v2] binman: support mkimage separate files Peter Geis
2022-03-06  3:08         ` Simon Glass
2022-03-06 14:44           ` Peter Geis
2022-03-10 19:29             ` Alper Nebi Yasak
2022-03-10 23:19               ` Peter Geis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220223230040.159317-15-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=alpernebiyasak@gmail.com \
    --cc=hl@rock-chips.com \
    --cc=ivan.mikhaylov@siemens.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=kever.yang@rock-chips.com \
    --cc=philipp.tomsich@theobroma-systems.com \
    --cc=philippe.reynes@softathome.com \
    --cc=rogerq@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.