Skip to contentSkip to conversation

Fix handling of optional blobs in binman

PATCH In review Yannic Moog 4 participants 16 messages Jun 13, 2025 – Aug 15, 2025

lore
Share & tools
lore
#0 lore raw

v3 cover Fix handling of optional blobs in binman

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

Here is an example build output of a phycore-imx8mp:

BINMAN .binman_stamp
Image 'image' is missing optional external blobs but is still functional: tee-os

/binman/section/fit/images/tee/tee-os (tee.bin):
See the documentation for your board. You may need to build Open Portable Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin

Image 'image' has faked optional external blobs and is still functional: tee.bin

OFCHK .config

The output stays to inform/warn the user, but in this case the tee-os entry will not be present in the final image.

---
Changes in v3:
- Fix all failing tests
- add commit that reworks bin.elf test
- add section data to failing tests. E.g. tee-os contains missing
tee.bin, but is still included in the image.
- remove _entries -> GetEntries() refactor patch
- reorder commits -> smaller fixes before refactor EDITME: use bulletpoints and terse descriptions.
- squash commits so that for each commits all binman tests should pass now
- rebase on next
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- mark as RFC due to failing tests. In current state, series is more of
a concept
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Yannic Moog (6):
binman: drop "faked" return value from check_fake_fname
binman: mark optional missing blobs as absent
binman: rework dropping absent entries from packaged image
binman: add faked optional entry case in CheckForProblems
binman: ftest: pass allow_fake_blob to _DoReadFileDtb
binman: test: assert optional blobs don't cause non-functionality

 tools/binman/binman.rst             |  7 +++++
 tools/binman/control.py             | 30 ++++++++++++++++-----
 tools/binman/entry.py               | 17 +++++++-----
 tools/binman/etype/blob.py          |  9 ++++---
 tools/binman/etype/blob_ext_list.py |  4 +--
 tools/binman/etype/cbfs.py          |  3 ++-
 tools/binman/etype/mkimage.py       |  2 +-
 tools/binman/etype/section.py       | 16 ++++++++---
 tools/binman/ftest.py               | 54 +++++++++++++++++++++++++------------
 tools/binman/image.py               |  2 ++
 10 files changed, 102 insertions(+), 42 deletions(-)

---
base-commit: 548d997229b7929bd7f0782415952d5a85eb7e64
change-id: 20250122-binman_faked_optional-5025f7046e25

Best regards,

Signature · 1 line
Yannic Moog <[email protected]>
#1 lore raw

PATCH v3 1/6 binman: drop "faked" return value from check_fake_fname

check_fake_fname sets the faked member of the entry. Use that member to get the faked status instead of a returned value indicating the same. Add type annotations to the modified functions while at it.

---
 tools/binman/entry.py               | 11 +++++------
 tools/binman/etype/blob.py          |  7 +++----
 tools/binman/etype/blob_ext_list.py |  4 ++--
 3 files changed, 10 insertions(+), 12 deletions(-)
tools/binman/entry.py +5 -6
index bdc60e47fcab7bc69907eb08de9b50e977934b74..6390917e5083e40a4e3294e5d36ec300d2057fe9 100644
@@ -88,6 +88,7 @@ class Entry(object):
             updated with a hash of the entry contents
         comp_bintool: Bintools used for compress and decompress data
         fake_fname: Fake filename, if one was created, else None
+        faked (bool): True if the entry is absent and faked
         required_props (dict of str): Properties which must be present. This can
             be added to by subclasses
         elf_fname (str): Filename of the ELF file, if this entry holds an ELF
@@ -1120,7 +1121,7 @@ features to produce new behaviours.
         if self.missing and not self.optional:
             missing_list.append(self)
 
-    def check_fake_fname(self, fname, size=0):
+    def check_fake_fname(self, fname: str, size: int = 0) -> str:
         """If the file is missing and the entry allows fake blobs, fake it
 
         Sets self.faked to True if faked
@@ -1130,9 +1131,7 @@ features to produce new behaviours.
             size (int): Size of fake file to create
 
         Returns:
-            tuple:
-                fname (str): Filename of faked file
-                bool: True if the blob was faked, False if not
+            fname (str): Filename of faked file
         """
         if self.allow_fake and not pathlib.Path(fname).is_file():
             if not self.fake_fname:
@@ -1142,8 +1141,8 @@ features to produce new behaviours.
                 tout.info(f"Entry '{self._node.path}': Faked blob '{outfname}'")
                 self.fake_fname = outfname
             self.faked = True
-            return self.fake_fname, True
-        return fname, False
+            return self.fake_fname
+        return fname
 
     def CheckFakedBlobs(self, faked_blobs_list):
         """Check if any entries in this section have faked external blobs
tools/binman/etype/blob.py +3 -4
index 041e1122953ef80c0c48735fa8116f56def58f58..970fae91cd9b2a31b3f31d2ecdb77e27a89d69fb 100644
@@ -42,7 +42,7 @@ class Entry_blob(Entry):
             if fdt_util.GetBool(self._node, 'write-symbols'):
                 self.auto_write_symbols = True
 
-    def ObtainContents(self, fake_size=0):
+    def ObtainContents(self, fake_size: int = 0) -> bool:
         self._filename = self.GetDefaultFilename()
         self._pathname = tools.get_input_filename(self._filename,
             self.external and (self.optional or self.section.GetAllowMissing()))
@@ -50,10 +50,9 @@ class Entry_blob(Entry):
         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._pathname = self.check_fake_fname(self._filename, fake_size)
             self.missing = True
-            if not faked:
+            if not self.faked:
                 content_size = 0
                 if self.assume_size: # Ensure we get test coverage on next line
                     content_size = self.assume_size
tools/binman/etype/blob_ext_list.py +2 -2
index 1bfcf6733a752d3552d5adbbf5a1cd206d36963f..a8b5a24c3a1c2c9b0b1bd7ab793ba3993cb4368e 100644
@@ -33,11 +33,11 @@ class Entry_blob_ext_list(Entry_blob):
         self._filenames = fdt_util.GetStringList(self._node, 'filenames')
         self._pathnames = []
 
-    def ObtainContents(self):
+    def ObtainContents(self) -> bool:
         missing = False
         pathnames = []
         for fname in self._filenames:
-            fname, _ = self.check_fake_fname(fname)
+            fname = self.check_fake_fname(fname)
             pathname = tools.get_input_filename(
                 fname, self.external and self.section.GetAllowMissing())
             # Allow the file to be missing
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/6 binman: mark optional missing blobs as absent

In reply to Yannic Moog

Optional blobs should mark themselves as absent to avoid being packed into an image.
Extend the documentation of this behaviour. Although the documentation implied this before, the "optional" property had not been explained properly before.
The behaviour will change as now absent entries are no longer packed into an image. The image map will also reflect this. As a result, the CheckForProblems() function will no longer alert on optional (blob) entries. This is because the missing optional images were removed before CheckForProblems is called.
Adjust the testExtblobOptional test case to highlight that we are testing not only an optional image but the image is missing as well. The behaviour for these is different where the latter will not be packaged into the image.

---
 tools/binman/binman.rst    | 7 +++++++
 tools/binman/etype/blob.py | 2 ++
 tools/binman/ftest.py      | 8 +++-----
 3 files changed, 12 insertions(+), 5 deletions(-)
tools/binman/binman.rst +7 -0
index 84b1331df5c006f72167016b7f33de73f4a269fa..392e507d449c75eeba4431fe2db01d820bce8f61 100644
@@ -1143,6 +1143,13 @@ Optional entries
 
 Some entries need to exist only if certain conditions are met. For example, an
 entry may want to appear in the image only if a file has a particular format.
+Also, the ``optional`` property may be used to mark entries as optional::
+
+    tee-os {
+        filename = "tee.bin";
+        optional;
+    };
+
 Obviously the entry must exist in the image description for it to be processed
 at all, so a way needs to be found to have the entry remove itself.
 
tools/binman/etype/blob.py +2 -0
index 970fae91cd9b2a31b3f31d2ecdb77e27a89d69fb..acd9ae34074e4b4b9792b107cc80514dfdd88b3b 100644
@@ -52,6 +52,8 @@ class Entry_blob(Entry):
                 fake_size = self.assume_size
             self._pathname = self.check_fake_fname(self._filename, fake_size)
             self.missing = True
+            if self.optional:
+                self.mark_absent("missing but optional")
             if not self.faked:
                 content_size = 0
                 if self.assume_size: # Ensure we get test coverage on next line
tools/binman/ftest.py +3 -5
index 4cf7dfc82165b37752d048e5fa76da6860d2003d..4a8d330c8f89adc3c248199760a936dd243158a2 100644
@@ -84,6 +84,7 @@ FILES_DATA            = (b"sorry I'm late\nOh, don't bother apologising, I'm " +
                          b"sorry you're alive\n")
 COMPRESS_DATA         = b'compress xxxxxxxxxxxxxxxxxxxxxx data'
 COMPRESS_DATA_BIG     = COMPRESS_DATA * 2
+MISSING_DATA          = b'missing'
 REFCODE_DATA          = b'refcode'
 FSP_M_DATA            = b'fsp_m'
 FSP_S_DATA            = b'fsp_s'
@@ -6537,15 +6538,12 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             "Node '/binman/fit/images/@tee-SEQ/tee-os': Invalid OP-TEE file: size mismatch (expected 0x4, have 0xe)",
             str(exc.exception))
 
-    def testExtblobOptional(self):
+    def testExtblobMissingOptional(self):
         """Test an image with an external blob that is optional"""
         with terminal.capture() as (stdout, stderr):
             data = self._DoReadFile('266_blob_ext_opt.dts')
         self.assertEqual(REFCODE_DATA, data)
-        err = stderr.getvalue()
-        self.assertRegex(
-            err,
-            "Image '.*' is missing optional external blobs but is still functional: missing")
+        self.assertNotIn(MISSING_DATA, data)
 
     def testSectionInner(self):
         """Test an inner section with a size"""
Signature · 1 line
2.43.0
#3 lore raw

PATCH v3 3/6 binman: rework dropping absent entries from packaged image

In reply to Yannic Moog

When blobs are absent and are marked as optional, they can be safely dropped from the binman tree. Use the drop_absent function for that. Rename drop_absent to drop_absent_optional as we do not want to drop any entries that are absent; they should be reported by binman as errors when they are missing.
We also reorder the processing of the image the following:
- We call the CheckForProblems function before the image is built.
- We drop entries after we checked for problems with the image. This is okay because CheckForProblems does not look at the file we have written but rather queries the data structure (image) built with binman. This also allows us to get all error and warning messages that we want to report while avoiding putting missing optional entries in the final image.
As only the blobs are dropped, the sections still remain in the assembled image. Thus add them to the expected test case checks where necessary.

In addition, a rework of testPackTeeOsOptional test case is necessary.

The test did not really do what it was supposed to. The description said that optional binary is tested, but the binary is not marked as optional. Further, the tee.elf file, when included in the image properly, also shows up in the image data. This must be added as well.

As there is no global variable for the elf data, set the pathname to the elf file that was created when setting up the test suite. For the test case get the filename and read the contents, comparing them to the contents of the created binman image.

---
 tools/binman/control.py       |  5 ++---
 tools/binman/entry.py         |  6 +++++-
 tools/binman/etype/cbfs.py    |  3 ++-
 tools/binman/etype/mkimage.py |  2 +-
 tools/binman/etype/section.py | 16 ++++++++++++----
 tools/binman/ftest.py         | 14 ++++++++------
 tools/binman/image.py         |  2 ++
 7 files changed, 32 insertions(+), 16 deletions(-)
tools/binman/control.py +2 -3
index 1946656f7d368209df3299a0e7c833b93edf2120..5a66c06d346cc74dc3e0e037eb263b6ced64a9b4 100644
@@ -697,7 +697,6 @@ def ProcessImage(image, update_fdt, write_map, get_contents=True,
         image.SetAllowMissing(allow_missing)
         image.SetAllowFakeBlob(allow_fake_blobs)
         image.GetEntryContents()
-        image.drop_absent()
     image.GetEntryOffsets()
 
     # We need to pack the entries to figure out where everything
@@ -736,12 +735,12 @@ def ProcessImage(image, update_fdt, write_map, get_contents=True,
         image.Raise('Entries changed size after packing (tried %s passes)' %
                     passes)
 
+    has_problems = CheckForProblems(image)
+
     image.BuildImage()
     if write_map:
         image.WriteMap()
 
-    has_problems = CheckForProblems(image)
-
     image.WriteAlternates()
 
     return has_problems
tools/binman/entry.py +5 -1
index 6390917e5083e40a4e3294e5d36ec300d2057fe9..ce7ef28e94b17e349544776070c457d5882661b1 100644
@@ -760,7 +760,7 @@ class Entry(object):
                           self.image_pos)
 
     # pylint: disable=assignment-from-none
-    def GetEntries(self):
+    def GetEntries(self) -> None:
         """Return a list of entries contained by this entry
 
         Returns:
@@ -1351,6 +1351,10 @@ features to produce new behaviours.
             os.mkdir(cls.fake_dir)
         tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")
 
+    def drop_absent_optional(self) -> None:
+        """Entries don't have any entries, do nothing"""
+        pass
+
     def ensure_props(self):
         """Raise an exception if properties are missing
 
tools/binman/etype/cbfs.py +2 -1
index 124fa1e4ffc7d0374b27c09d32ead8429567d304..5879f377231bf94697bea97c3cfc3a2515665b8f 100644
@@ -276,7 +276,8 @@ class Entry_cbfs(Entry):
         for entry in self._entries.values():
             entry.ListEntries(entries, indent + 1)
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
+        """Returns the entries (tree children) of this section"""
         return self._entries
 
     def ReadData(self, decomp=True, alt_format=None):
tools/binman/etype/mkimage.py +1 -1
index 6ae5d0c8a4f3c54e1277a575b8e235cc1aba4e13..75e59c3d3a3104da7559982f64968fdd99b7bd5f 100644
@@ -205,7 +205,7 @@ class Entry_mkimage(Entry_section):
             self.record_missing_bintool(self.mkimage)
             return data
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
         # Make a copy so we don't change the original
         entries = OrderedDict(self._entries)
         if self._imagename:
tools/binman/etype/section.py +12 -4
index 1d50bb477534702019502d08f8648d4c9a367c0f..03c4f7c6ec74c6fa75c9362e2fecdb0e6ab568cb 100644
@@ -537,7 +537,7 @@ class Entry_section(Entry):
         for entry in self._entries.values():
             entry.WriteMap(fd, indent + 1)
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
         return self._entries
 
     def GetContentsByPhandle(self, phandle, source_entry, required):
@@ -772,9 +772,17 @@ class Entry_section(Entry):
                        todo)
         return True
 
-    def drop_absent(self):
-        """Drop entries which are absent"""
-        self._entries = {n: e for n, e in self._entries.items() if not e.absent}
+    def drop_absent_optional(self) -> None:
+        """Drop entries which are absent.
+        Call for all nodes in the tree. Leaf nodes will do nothing per
+        definition. Sections however have _entries and should drop all children
+        which are absent.
+        """
+        self._entries = {n: e for n, e in self._entries.items() if not (e.absent and e.optional)}
+        # Drop nodes first before traversing children to avoid superfluous calls
+        # to children of absent nodes.
+        for e in self.GetEntries().values():
+            e.drop_absent_optional()
 
     def _SetEntryOffsetSize(self, name, offset, size):
         """Set the offset and size of an entry
tools/binman/ftest.py +8 -6
index 4a8d330c8f89adc3c248199760a936dd243158a2..d707e2aa555b39316d206a4c170ebb83aa6daf72 100644
@@ -251,7 +251,7 @@ class TestFunctional(unittest.TestCase):
         # ATF and OP_TEE
         TestFunctional._MakeInputFile('bl31.elf',
             tools.read_file(cls.ElfTestFile('elf_sections')))
-        TestFunctional._MakeInputFile('tee.elf',
+        TestFunctional.tee_elf_path = TestFunctional._MakeInputFile('tee.elf',
             tools.read_file(cls.ElfTestFile('elf_sections')))
 
         # Newer OP_TEE file in v1 binary format
@@ -6459,16 +6459,18 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
     def testAbsent(self):
         """Check handling of absent entries"""
         data = self._DoReadFile('262_absent.dts')
-        self.assertEqual(U_BOOT_DATA + U_BOOT_IMG_DATA, data)
+        self.assertEqual(U_BOOT_DATA + b'aa' + U_BOOT_IMG_DATA, data)
 
-    def testPackTeeOsOptional(self):
-        """Test that an image with an optional TEE binary can be created"""
+    def testPackTeeOsElf(self):
+        """Test that an image with a TEE elf binary can be created"""
         entry_args = {
             'tee-os-path': 'tee.elf',
         }
+        tee_path = self.tee_elf_path
         data = self._DoReadFileDtb('263_tee_os_opt.dts',
                                    entry_args=entry_args)[0]
-        self.assertEqual(U_BOOT_DATA + U_BOOT_IMG_DATA, data)
+        self.assertEqual(U_BOOT_DATA + tools.read_file(tee_path) +
+                         U_BOOT_IMG_DATA, data)
 
     def checkFitTee(self, dts, tee_fname):
         """Check that a tee-os entry works and returns data
@@ -6724,7 +6726,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
         node = dtb.GetNode('/configurations/conf-missing-tee-1')
         self.assertEqual('atf-1', node.props['firmware'].value)
-        self.assertEqual(['u-boot', 'atf-2'],
+        self.assertEqual(['u-boot', 'tee', 'atf-2'],
                          fdt_util.GetStringList(node, 'loadables'))
 
     def testTooldir(self):
tools/binman/image.py +2 -0
index 24ce0af7c72b5256a9a71963a6d94c080ed8bdd4..698cfa4148e1a0f762d90d99ee3bc581cff5105a 100644
@@ -183,6 +183,8 @@ class Image(section.Entry_section):
         fname = tools.get_output_filename(self._filename)
         tout.info("Writing image to '%s'" % fname)
         with open(fname, 'wb') as fd:
+            # For final image, don't write absent blobs to file
+            self.drop_absent_optional()
             data = self.GetPaddedData()
             fd.write(data)
         tout.info("Wrote %#x bytes" % len(data))
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v3 3/6] binman: rework dropping absent entries from packaged image

Quoted 213 lines · Yannic Moog

When blobs are absent and are marked as optional, they can be safely dropped from the binman tree. Use the drop_absent function for that. Rename drop_absent to drop_absent_optional as we do not want to drop any entries that are absent; they should be reported by binman as errors when they are missing.
We also reorder the processing of the image the following:
- We call the CheckForProblems function before the image is built.
- We drop entries after we checked for problems with the image. This is okay because CheckForProblems does not look at the file we have written but rather queries the data structure (image) built with binman. This also allows us to get all error and warning messages that we want to report while avoiding putting missing optional entries in the final image.
As only the blobs are dropped, the sections still remain in the assembled image. Thus add them to the expected test case checks where necessary.

In addition, a rework of testPackTeeOsOptional test case is necessary.

The test did not really do what it was supposed to. The description said that optional binary is tested, but the binary is not marked as optional. Further, the tee.elf file, when included in the image properly, also shows up in the image data. This must be added as well.

As there is no global variable for the elf data, set the pathname to the elf file that was created when setting up the test suite. For the test case get the filename and read the contents, comparing them to the contents of the created binman image.

---
 tools/binman/control.py       |  5 ++---
 tools/binman/entry.py         |  6 +++++-
 tools/binman/etype/cbfs.py    |  3 ++-
 tools/binman/etype/mkimage.py |  2 +-
 tools/binman/etype/section.py | 16 ++++++++++++----
 tools/binman/ftest.py         | 14 ++++++++------
 tools/binman/image.py         |  2 ++
 7 files changed, 32 insertions(+), 16 deletions(-)
tools/binman/control.py +2 -3
index 1946656f7d368209df3299a0e7c833b93edf2120..5a66c06d346cc74dc3e0e037eb263b6ced64a9b4 100644
@@ -697,7 +697,6 @@ def ProcessImage(image, update_fdt, write_map, get_contents=True,
         image.SetAllowMissing(allow_missing)
         image.SetAllowFakeBlob(allow_fake_blobs)
         image.GetEntryContents()
-        image.drop_absent()
     image.GetEntryOffsets()
 
     # We need to pack the entries to figure out where everything
@@ -736,12 +735,12 @@ def ProcessImage(image, update_fdt, write_map, get_contents=True,
         image.Raise('Entries changed size after packing (tried %s passes)' %
                     passes)
 
+    has_problems = CheckForProblems(image)
+
     image.BuildImage()
     if write_map:
         image.WriteMap()
 
-    has_problems = CheckForProblems(image)
-
     image.WriteAlternates()
 
     return has_problems
tools/binman/entry.py +5 -1
index 6390917e5083e40a4e3294e5d36ec300d2057fe9..ce7ef28e94b17e349544776070c457d5882661b1 100644
@@ -760,7 +760,7 @@ class Entry(object):
                           self.image_pos)
 
     # pylint: disable=assignment-from-none
-    def GetEntries(self):
+    def GetEntries(self) -> None:
         """Return a list of entries contained by this entry
 
         Returns:
@@ -1351,6 +1351,10 @@ features to produce new behaviours.
             os.mkdir(cls.fake_dir)
         tout.notice(f"Fake-blob dir is '{cls.fake_dir}'")
 
+    def drop_absent_optional(self) -> None:
+        """Entries don't have any entries, do nothing"""
+        pass
+
     def ensure_props(self):
         """Raise an exception if properties are missing
 
tools/binman/etype/cbfs.py +2 -1
index 124fa1e4ffc7d0374b27c09d32ead8429567d304..5879f377231bf94697bea97c3cfc3a2515665b8f 100644
@@ -276,7 +276,8 @@ class Entry_cbfs(Entry):
         for entry in self._entries.values():
             entry.ListEntries(entries, indent + 1)
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
+        """Returns the entries (tree children) of this section"""
         return self._entries
 
     def ReadData(self, decomp=True, alt_format=None):
tools/binman/etype/mkimage.py +1 -1
index 6ae5d0c8a4f3c54e1277a575b8e235cc1aba4e13..75e59c3d3a3104da7559982f64968fdd99b7bd5f 100644
@@ -205,7 +205,7 @@ class Entry_mkimage(Entry_section):
             self.record_missing_bintool(self.mkimage)
             return data
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
         # Make a copy so we don't change the original
         entries = OrderedDict(self._entries)
         if self._imagename:
tools/binman/etype/section.py +12 -4
index 1d50bb477534702019502d08f8648d4c9a367c0f..03c4f7c6ec74c6fa75c9362e2fecdb0e6ab568cb 100644
@@ -537,7 +537,7 @@ class Entry_section(Entry):
         for entry in self._entries.values():
             entry.WriteMap(fd, indent + 1)
 
-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:
         return self._entries
 
     def GetContentsByPhandle(self, phandle, source_entry, required):
@@ -772,9 +772,17 @@ class Entry_section(Entry):
                        todo)
         return True
 
-    def drop_absent(self):
-        """Drop entries which are absent"""
-        self._entries = {n: e for n, e in self._entries.items() if not e.absent}
+    def drop_absent_optional(self) -> None:
+        """Drop entries which are absent.
+        Call for all nodes in the tree. Leaf nodes will do nothing per
+        definition. Sections however have _entries and should drop all children
+        which are absent.
+        """
+        self._entries = {n: e for n, e in self._entries.items() if not (e.absent and e.optional)}
+        # Drop nodes first before traversing children to avoid superfluous calls
+        # to children of absent nodes.
+        for e in self.GetEntries().values():
+            e.drop_absent_optional()
 
     def _SetEntryOffsetSize(self, name, offset, size):
         """Set the offset and size of an entry
tools/binman/ftest.py +8 -6
index 4a8d330c8f89adc3c248199760a936dd243158a2..d707e2aa555b39316d206a4c170ebb83aa6daf72 100644
@@ -251,7 +251,7 @@ class TestFunctional(unittest.TestCase):
         # ATF and OP_TEE
         TestFunctional._MakeInputFile('bl31.elf',
             tools.read_file(cls.ElfTestFile('elf_sections')))
-        TestFunctional._MakeInputFile('tee.elf',
+        TestFunctional.tee_elf_path = TestFunctional._MakeInputFile('tee.elf',
             tools.read_file(cls.ElfTestFile('elf_sections')))
 
         # Newer OP_TEE file in v1 binary format
@@ -6459,16 +6459,18 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
     def testAbsent(self):
         """Check handling of absent entries"""
         data = self._DoReadFile('262_absent.dts')
-        self.assertEqual(U_BOOT_DATA + U_BOOT_IMG_DATA, data)
+        self.assertEqual(U_BOOT_DATA + b'aa' + U_BOOT_IMG_DATA, data)
 
-    def testPackTeeOsOptional(self):
-        """Test that an image with an optional TEE binary can be created"""
+    def testPackTeeOsElf(self):
+        """Test that an image with a TEE elf binary can be created"""
         entry_args = {
             'tee-os-path': 'tee.elf',
         }
+        tee_path = self.tee_elf_path
         data = self._DoReadFileDtb('263_tee_os_opt.dts',
                                    entry_args=entry_args)[0]
-        self.assertEqual(U_BOOT_DATA + U_BOOT_IMG_DATA, data)
+        self.assertEqual(U_BOOT_DATA + tools.read_file(tee_path) +
+                         U_BOOT_IMG_DATA, data)
 
     def checkFitTee(self, dts, tee_fname):
         """Check that a tee-os entry works and returns data
@@ -6724,7 +6726,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
         node = dtb.GetNode('/configurations/conf-missing-tee-1')
         self.assertEqual('atf-1', node.props['firmware'].value)
-        self.assertEqual(['u-boot', 'atf-2'],
+        self.assertEqual(['u-boot', 'tee', 'atf-2'],
                          fdt_util.GetStringList(node, 'loadables'))
 
     def testTooldir(self):
tools/binman/image.py +2 -1
index 24ce0af7c72b5256a9a71963a6d94c080ed8bdd4..698cfa4148e1a0f762d90d99ee3bc581cff5105a 100644
@@ -183,6 +183,8 @@ class Image(section.Entry_section):
         fname = tools.get_output_filename(self._filename)
         tout.info("Writing image to '%s'" % fname)
         with open(fname, 'wb') as fd:
+            # For final image, don't write absent blobs to file
+            self.drop_absent_optional()
             data = self.GetPaddedData()
             fd.write(data)
         tout.info("Wrote %#x bytes" % len(data))
 
--
Quoted 2 lines

2.43.0

Hi Yannic,

This series just got merged to master and I noticed it failing building imx8mm_venice on my Ubuntu 20.04 dev host which has Python 3.8.10.

make imx8mm_venice_defconfig
make
...
BINMAN .binman_stamp
binman: 'type' object is not subscriptable
make: *** [Makefile:1336: .binman_stamp] Error 1

Do you know what the minimum version of python required is or what would need to be changed here to support the previous version of python that worked?

Best Regards,

Tim

#5 lore raw

Re: [PATCH v3 3/6] binman: rework dropping absent entries from packaged image

Hi Tim

Am Mittwoch, dem 09.07.2025 um 10:50 -0700 schrieb Tim Harvey:

Quoted 43 lines · Yannic Moog
Quoted 42 lines

When blobs are absent and are marked as optional, they can be safely dropped from the binman tree. Use the drop_absent function for that. Rename drop_absent to drop_absent_optional as we do not want to drop any entries that are absent; they should be reported by binman as errors when they are missing.
We also reorder the processing of the image the following:
- We call the CheckForProblems function before the image is built.
- We drop entries after we checked for problems with the image. This is okay because CheckForProblems does not look at the file we have written but rather queries the data structure (image) built with binman. This also allows us to get all error and warning messages that we want to report while avoiding putting missing optional entries in the final image.
As only the blobs are dropped, the sections still remain in the assembled image. Thus add them to the expected test case checks where necessary.

In addition, a rework of testPackTeeOsOptional test case is necessary.

The test did not really do what it was supposed to. The description said that optional binary is tested, but the binary is not marked as optional. Further, the tee.elf file, when included in the image properly, also shows up in the image data. This must be added as well.

As there is no global variable for the elf data, set the pathname to the elf file that was created when setting up the test suite. For the test case get the filename and read the contents, comparing them to the contents of the created binman image.

---
 tools/binman/control.py       |  5 ++--- tools/binman/entry.py         |  6 +++++- tools/binman/etype/cbfs.py    |  3 ++- tools/binman/etype/mkimage.py |  2 +- tools/binman/etype/section.py | 16 ++++++++++++---- tools/binman/ftest.py         | 14 ++++++++------ tools/binman/image.py         |  2 ++

 7 files changed, 32 insertions(+), 16 deletions(-)

[...]

Quoted 10 lines
Quoted 10 lines
tools/binman/etype/section.py +0 -0

index 1d50bb477534702019502d08f8648d4c9a367c0f..03c4f7c6ec74c6fa75c9362e2fecdb0e6a b568cb 100644

tools/binman/etype/section.py +0 -0
@@ -537,7 +537,7 @@ class Entry_section(Entry):

         for entry in self._entries.values():
             entry.WriteMap(fd, indent + 1)

Quoted 3 lines
Quoted 3 lines

-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:

the problem is that I forgot to "packport" typing support for older python versions < 3.9.
Thank you for bringing this to my attention.

Quoted 14 lines

Hi Yannic,

This series just got merged to master and I noticed it failing building imx8mm_venice on my Ubuntu 20.04 dev host which has Python 3.8.10.

make imx8mm_venice_defconfig
make
...
  BINMAN  .binman_stamp
binman: 'type' object is not subscriptable
make: *** [Makefile:1336: .binman_stamp] Error 1

Quoted 3 lines

Do you know what the minimum version of python required is or what would need to be changed here to support the previous version of python that worked?

Absolute minimum version is 3.5. That is when typing got introduced.

Quoting from binman pyproject.toml:

Quoted 4 lines

description = "Binman firmware-packaging tool"
readme = "README.rst"
requires-python = ">=3.7"

But there has been a patch that tried to make binman work for 3.6. de65b122a2534 ("tools: Fall back to importlib_resources on Python 3.6")

Should I create a solution for python >= 3.5 or >= 3.7?

Yannic

Quoted 4 lines

Best Regards,

Tim

#6 lore raw

Re: [PATCH v3 3/6] binman: rework dropping absent entries from packaged image

Quoted 94 lines · Yannic Moog

Hi Tim

Am Mittwoch, dem 09.07.2025 um 10:50 -0700 schrieb Tim Harvey:

Quoted 43 lines · Yannic Moog
Quoted 42 lines

When blobs are absent and are marked as optional, they can be safely dropped from the binman tree. Use the drop_absent function for that. Rename drop_absent to drop_absent_optional as we do not want to drop any entries that are absent; they should be reported by binman as errors when they are missing.
We also reorder the processing of the image the following:
- We call the CheckForProblems function before the image is built.
- We drop entries after we checked for problems with the image. This is okay because CheckForProblems does not look at the file we have written but rather queries the data structure (image) built with binman. This also allows us to get all error and warning messages that we want to report while avoiding putting missing optional entries in the final image.
As only the blobs are dropped, the sections still remain in the assembled image. Thus add them to the expected test case checks where necessary.

In addition, a rework of testPackTeeOsOptional test case is necessary.

The test did not really do what it was supposed to. The description said that optional binary is tested, but the binary is not marked as optional. Further, the tee.elf file, when included in the image properly, also shows up in the image data. This must be added as well.

As there is no global variable for the elf data, set the pathname to the elf file that was created when setting up the test suite. For the test case get the filename and read the contents, comparing them to the contents of the created binman image.

---
 tools/binman/control.py       |  5 ++--- tools/binman/entry.py         |  6 +++++- tools/binman/etype/cbfs.py    |  3 ++- tools/binman/etype/mkimage.py |  2 +- tools/binman/etype/section.py | 16 ++++++++++++---- tools/binman/ftest.py         | 14 ++++++++------ tools/binman/image.py         |  2 ++

 7 files changed, 32 insertions(+), 16 deletions(-)

[...]

Quoted 10 lines
Quoted 10 lines
tools/binman/etype/section.py +0 -0

index 1d50bb477534702019502d08f8648d4c9a367c0f..03c4f7c6ec74c6fa75c9362e2fecdb0e6a b568cb 100644

tools/binman/etype/section.py +0 -0
@@ -537,7 +537,7 @@ class Entry_section(Entry):

         for entry in self._entries.values():
             entry.WriteMap(fd, indent + 1)

Quoted 3 lines
Quoted 3 lines

-    def GetEntries(self):
+    def GetEntries(self) -> dict[str, Entry]:

the problem is that I forgot to "packport" typing support for older python versions < 3.9.
Thank you for bringing this to my attention.

Quoted 14 lines

Hi Yannic,

This series just got merged to master and I noticed it failing building imx8mm_venice on my Ubuntu 20.04 dev host which has Python 3.8.10.

make imx8mm_venice_defconfig
make
...
  BINMAN  .binman_stamp
binman: 'type' object is not subscriptable
make: *** [Makefile:1336: .binman_stamp] Error 1

Quoted 3 lines

Do you know what the minimum version of python required is or what would need to be changed here to support the previous version of python that worked?

Absolute minimum version is 3.5. That is when typing got introduced.

Quoting from binman pyproject.toml:

Quoted 4 lines

description = "Binman firmware-packaging tool"
readme = "README.rst"
requires-python = ">=3.7"

Quoted 4 lines

But there has been a patch that tried to make binman work for 3.6. de65b122a2534 ("tools: Fall back to importlib_resources on Python 3.6")

Should I create a solution for python >= 3.5 or >= 3.7?

I think we should aim for >= 3.5, since the toml file is out of date if someone else fixed it for 3.6 (and so I assume some other LTS distro uses 3.6). Thanks!

Signature · 1 line
Tom
#7 lore raw

PATCH v3 4/6 binman: add faked optional entry case in CheckForProblems

In reply to Yannic Moog

When having an entry that is marked as optional and is missing in the final image, the following output is observed:

CFGS spl/u-boot-spl.cfgout
BINMAN .binman_stamp
Image 'image' has faked external blobs and is non-functional: tee.bin

Image 'image' is missing optional external blobs but is still functional: tee-os

/binman/section/fit/images/tee/tee-os (tee.bin):
See the documentation for your board. You may need to build Open Portable Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin

Some images are invalid
make: *** [Makefile:1135: .binman_stamp] Error 103

To solve this contradictory messaging, when checking the faked blob list, remove entries that are allowed to be missing. Instead add an info message for faked optional blobs. Also reduce verbosity of the optional image warning to an info message.

---
 tools/binman/control.py | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
tools/binman/control.py +22 -3
index 5a66c06d346cc74dc3e0e037eb263b6ced64a9b4..df66c527d7b4a3d168fa8ad03ab32b2ba3badf0a 100644
@@ -645,14 +645,27 @@ def CheckForProblems(image):
         _ShowHelpForMissingBlobs(tout.ERROR, missing_list)
 
     faked_list = []
+    faked_optional_list = []
+    faked_required_list = []
     image.CheckFakedBlobs(faked_list)
-    if faked_list:
+    for e in faked_list:
+        if e.optional:
+            faked_optional_list.append(e)
+        else:
+            faked_required_list.append(e)
+    if faked_required_list:
         tout.warning(
             "Image '%s' has faked external blobs and is non-functional: %s\n" %
             (image.name, ' '.join([os.path.basename(e.GetDefaultFilename())
-                                   for e in faked_list])))
+                                   for e in faked_required_list])))
 
     optional_list = []
+    # For optional blobs, we should inform the user when the blob is not present. This will come as
+    # a warning since it may not be immediately apparent that something is missing otherwise.
+    # E.g. user thinks they supplied a blob, but there is no info of the contrary if they made an
+    # error.
+    # Faked optional blobs are not relevant for final images (as they are dropped anyway) so we
+    # will omit the message with default verbosity.
     image.CheckOptional(optional_list)
     if optional_list:
         tout.warning(
@@ -660,6 +673,12 @@ def CheckForProblems(image):
             (image.name, ' '.join([e.name for e in optional_list])))
         _ShowHelpForMissingBlobs(tout.WARNING, optional_list)
 
+    if faked_optional_list:
+        tout.info(
+            "Image '%s' has faked optional external blobs but is still functional: %s\n" %
+            (image.name, ' '.join([os.path.basename(e.GetDefaultFilename())
+                                   for e in faked_optional_list])))
+
     missing_bintool_list = []
     image.check_missing_bintools(missing_bintool_list)
     if missing_bintool_list:
@@ -667,7 +686,7 @@ def CheckForProblems(image):
             "Image '%s' has missing bintools and is non-functional: %s\n" %
             (image.name, ' '.join([os.path.basename(bintool.name)
                                    for bintool in missing_bintool_list])))
-    return any([missing_list, faked_list, missing_bintool_list])
+    return any([missing_list, faked_required_list, missing_bintool_list])
 
 def ProcessImage(image, update_fdt, write_map, get_contents=True,
                  allow_resize=True, allow_missing=False,
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 5/6 binman: ftest: pass allow_fake_blob to _DoReadFileDtb

In reply to Yannic Moog

Some test cases don't use _DoTestFile directly which accepts allow_fake_blobs. However, they specifically test functionality that requires external blobs not to be faked. Extend the _DoReadFileDtb signature to allow passing that option to _DoTestFile.

Also fix tests that require non-faked ext blobs.
By default, external blobs are faked. Some tests care only about more basic functionality. In those cases no external blobs should be faked. That would trigger a different (binman) case which is not in scope for those particular tests.
Thus, disable faked blobs for those test cases.

---
 tools/binman/ftest.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
tools/binman/ftest.py +15 -11
index d707e2aa555b39316d206a4c170ebb83aa6daf72..32e1e0a14c03c9ebf1d9ce1f8278841959d7e5d8 100644
@@ -515,9 +515,9 @@ class TestFunctional(unittest.TestCase):
         return dtb.GetContents()
 
     def _DoReadFileDtb(self, fname, use_real_dtb=False, use_expanded=False,
-                       verbosity=None, map=False, update_dtb=False,
-                       entry_args=None, reset_dtbs=True, extra_indirs=None,
-                       threads=None):
+                       verbosity=None, allow_fake_blobs=True, map=False,
+                       update_dtb=False, entry_args=None, reset_dtbs=True,
+                       extra_indirs=None, threads=None):
         """Run binman and return the resulting image
 
         This runs binman with a given test file and then reads the resulting
@@ -535,6 +535,7 @@ class TestFunctional(unittest.TestCase):
             use_expanded: True to use expanded entries where available, e.g.
                 'u-boot-expanded' instead of 'u-boot'
             verbosity: Verbosity level to use (0-3, None=don't set it)
+            allow_fake_blobs: whether binman should fake missing ext blobs
             map: True to output map files for the images
             update_dtb: Update the offset and size of each entry in the device
                 tree before packing it into the image
@@ -572,7 +573,7 @@ class TestFunctional(unittest.TestCase):
             retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb,
                     entry_args=entry_args, use_real_dtb=use_real_dtb,
                     use_expanded=use_expanded, verbosity=verbosity,
-                    extra_indirs=extra_indirs,
+                    allow_fake_blobs=allow_fake_blobs, extra_indirs=extra_indirs,
                     threads=threads)
             self.assertEqual(0, retcode)
             out_dtb_fname = tools.get_output_filename('u-boot.dtb.out')
@@ -5211,13 +5212,15 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
     def testExtblobList(self):
         """Test an image with an external blob list"""
-        data = self._DoReadFile('215_blob_ext_list.dts')
-        self.assertEqual(REFCODE_DATA + FSP_M_DATA, data)
+        data = self._DoReadFileDtb('215_blob_ext_list.dts',
+                                   allow_fake_blobs=False)
+        self.assertEqual(REFCODE_DATA + FSP_M_DATA, data[0])
 
     def testExtblobListMissing(self):
         """Test an image with a missing external blob"""
         with self.assertRaises(ValueError) as e:
-            self._DoReadFile('216_blob_ext_list_missing.dts')
+            self._DoReadFileDtb('216_blob_ext_list_missing.dts',
+                                allow_fake_blobs=False)
         self.assertIn("Filename 'missing-file' not found in input path",
                       str(e.exception))
 
@@ -5225,7 +5228,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         """Test an image with an missing external blob that is allowed"""
         with terminal.capture() as (stdout, stderr):
             self._DoTestFile('216_blob_ext_list_missing.dts',
-                             allow_missing=True)
+                             allow_missing=True, allow_fake_blobs=False)
         err = stderr.getvalue()
         self.assertRegex(err, "Image 'image'.*missing.*: blob-ext")
 
@@ -5767,10 +5770,10 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
 
 
     def testFitSplitElfMissing(self):
-        """Test an split-elf FIT with a missing ELF file"""
+        """Test an split-elf FIT with a missing ELF file. Don't fake the file."""
         if not elf.ELF_TOOLS:
             self.skipTest('Python elftools not available')
-        out, err = self.checkFitSplitElf(allow_missing=True)
+        out, err = self.checkFitSplitElf(allow_missing=True, allow_fake_blobs=False)
         self.assertRegex(
             err,
             "Image '.*' is missing external blobs and is non-functional: .*")
@@ -6543,7 +6546,8 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
     def testExtblobMissingOptional(self):
         """Test an image with an external blob that is optional"""
         with terminal.capture() as (stdout, stderr):
-            data = self._DoReadFile('266_blob_ext_opt.dts')
+            data = self._DoReadFileDtb('266_blob_ext_opt.dts',
+                                       allow_fake_blobs=False)[0]
         self.assertEqual(REFCODE_DATA, data)
         self.assertNotIn(MISSING_DATA, data)
 
Signature · 1 line
2.43.0
#9 lore raw

PATCH v3 6/6 binman: test: assert optional blobs don't cause non-functionality

In reply to Yannic Moog

When external blobs are marked optional, they should not cause a build to fail. Extend the test cases for FitTeeOsOptional and ExtblobOptional.

---
 tools/binman/ftest.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/binman/ftest.py +16 -0
index 32e1e0a14c03c9ebf1d9ce1f8278841959d7e5d8..bedfcb53c48bd3b73c059fb406ce28ed09112b2d 100644
@@ -6518,6 +6518,9 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertRegex(
             err,
             "Image '.*' is missing optional external blobs but is still functional: tee-os")
+        self.assertNotRegex(
+            err,
+            "Image '.*' has faked external blobs and is non-functional: tee-os")
 
     def testFitTeeOsOptionalFitBad(self):
         """Test an image with a FIT with an optional OP-TEE binary"""
@@ -6551,6 +6554,19 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertEqual(REFCODE_DATA, data)
         self.assertNotIn(MISSING_DATA, data)
 
+    def testExtblobFakedOptional(self):
+        """Test an image with an external blob that is optional"""
+        with terminal.capture() as (stdout, stderr):
+            data = self._DoReadFile('266_blob_ext_opt.dts')
+        self.assertEqual(REFCODE_DATA, data)
+        err = stderr.getvalue()
+        self.assertRegex(
+            err,
+            "Image '.*' is missing optional external blobs but is still functional: missing")
+        self.assertNotRegex(
+            err,
+            "Image '.*' has faked external blobs and is non-functional: missing")
+
     def testSectionInner(self):
         """Test an inner section with a size"""
         data = self._DoReadFile('267_section_inner.dts')
Signature · 1 line
2.43.0
Reviewed-by on the v3 series
#10 lore raw
In reply to Yannic Moog

On June 13, 2025 thus sayeth Yannic Moog:

Quoted 27 lines

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

Here is an example build output of a phycore-imx8mp:

BINMAN .binman_stamp
Image 'image' is missing optional external blobs but is still functional: tee-os

/binman/section/fit/images/tee/tee-os (tee.bin):
See the documentation for your board. You may need to build Open Portable Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin

Image 'image' has faked optional external blobs and is still functional: tee.bin

OFCHK .config

The output stays to inform/warn the user, but in this case the tee-os entry will not be present in the final image.

Quoted 12 lines

---
Changes in v3:
- Fix all failing tests
- add commit that reworks bin.elf test
- add section data to failing tests. E.g. tee-os contains missing
tee.bin, but is still included in the image.
- remove _entries -> GetEntries() refactor patch
- reorder commits -> smaller fixes before refactor EDITME: use bulletpoints and terse descriptions.
- squash commits so that for each commits all binman tests should pass now
- rebase on next
- Link to v2: https://lore.kernel.org/r/[email protected]

Thanks for fixing this. That error message has been on my todo list for a while as well :)

~Bryan

#11 lore raw
In reply to Yannic Moog
Quoted 6 lines · Yannic Moog

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Quoted 6 lines

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

[...]

Applied to u-boot/next, thanks!

[1/6] binman: drop "faked" return value from check_fake_fname

      commit: a657d87f08789c4c50423897bd5ee052c6223ee6
[2/6] binman: mark optional missing blobs as absent
      commit: 3ae668b9d2101d111d257ee7d8912c19cfb0e102
[3/6] binman: rework dropping absent entries from packaged image
      commit: 21bc3433a43d3add3430543c9eee2a95d4dee2f6
[4/6] binman: add faked optional entry case in CheckForProblems
      commit: f5817e05efd39dd455c2e6a0f0622d709fe7ea2d
[5/6] binman: ftest: pass allow_fake_blob to _DoReadFileDtb
      commit: e749d64b4622806072c56a839cf9a36a5081b575
[6/6] binman: test: assert optional blobs don't cause non-functionality
      commit: 0dbb0a8d1f2aefb2a7fdd8e627edd955e4fe8d3a
Signature · 1 line
Tom
#12 lore raw
Quoted 30 lines · Tom Rini
Quoted 6 lines · Yannic Moog

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Quoted 6 lines

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

[...]

Applied to u-boot/next, thanks!

[1/6] binman: drop "faked" return value from check_fake_fname

      commit: a657d87f08789c4c50423897bd5ee052c6223ee6
[2/6] binman: mark optional missing blobs as absent
      commit: 3ae668b9d2101d111d257ee7d8912c19cfb0e102
[3/6] binman: rework dropping absent entries from packaged image
      commit: 21bc3433a43d3add3430543c9eee2a95d4dee2f6
[4/6] binman: add faked optional entry case in CheckForProblems
      commit: f5817e05efd39dd455c2e6a0f0622d709fe7ea2d
[5/6] binman: ftest: pass allow_fake_blob to _DoReadFileDtb
      commit: e749d64b4622806072c56a839cf9a36a5081b575
[6/6] binman: test: assert optional blobs don't cause non-functionality
      commit: 0dbb0a8d1f2aefb2a7fdd8e627edd955e4fe8d3a
Quoted 4 lines

--
Tom

Hi Yannic,

I haven't had time to dig into it in detail yet but it looks like imx8m boards are failing again in master due to tee changes again and perhaps its this series that is causing it.

Here's what I see with today's mater:
make imx8mm_evk_defconfig
make
...
BINMAN .binman_stamp
Image 'image' is missing optional external blobs but is still functional: tee-os

binman: module 'importlib.resources' has no attribute 'files'
make: *** [Makefile:1339: .binman_stamp] Error 1

I thought I had read something about a warning that wasn't an error but above is clearly a build failure.

Am I missing something here?

Best Regards,

Tim

#13 lore raw

Hi Tim,

Am Donnerstag, dem 14.08.2025 um 12:54 -0700 schrieb Tim Harvey:

Quoted 36 lines · Tom Rini
Quoted 18 lines · Yannic Moog
Quoted 7 lines

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Quoted 6 lines

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

[...]

Applied to u-boot/next, thanks!

Quoted 16 lines

[1/6] binman: drop "faked" return value from check_fake_fname
      commit: a657d87f08789c4c50423897bd5ee052c6223ee6
[2/6] binman: mark optional missing blobs as absent
      commit: 3ae668b9d2101d111d257ee7d8912c19cfb0e102
[3/6] binman: rework dropping absent entries from packaged image
      commit: 21bc3433a43d3add3430543c9eee2a95d4dee2f6
[4/6] binman: add faked optional entry case in CheckForProblems
      commit: f5817e05efd39dd455c2e6a0f0622d709fe7ea2d
[5/6] binman: ftest: pass allow_fake_blob to _DoReadFileDtb
      commit: e749d64b4622806072c56a839cf9a36a5081b575
[6/6] binman: test: assert optional blobs don't cause non-functionality
      commit: 0dbb0a8d1f2aefb2a7fdd8e627edd955e4fe8d3a
--
Tom

Quoted 5 lines

Hi Yannic,

I haven't had time to dig into it in detail yet but it looks like imx8m boards are failing again in master due to tee changes again and perhaps its this series that is causing it.

Thanks for reporting,

Quoted 9 lines

Here's what I see with today's mater:
make imx8mm_evk_defconfig
make
...
  BINMAN  .binman_stamp
Image 'image' is missing optional external blobs but is still functional: tee- os

Quoted 7 lines

binman: module 'importlib.resources' has no attribute 'files'
make: *** [Makefile:1339: .binman_stamp] Error 1

I thought I had read something about a warning that wasn't an error but above is clearly a build failure.

Am I missing something here?

My initial gut feeling says it could be related to this series:
https://lore.kernel.org/u-boot/[email protected]/

Maybe the combination of the 2 series causes this. Anyway, I'll investigate and report back.

Yannic

Quoted 4 lines

Best Regards,

Tim

#14 lore raw

Am Freitag, dem 15.08.2025 um 05:44 +0000 schrieb Yannic Moog:

Quoted 63 lines

Hi Tim,

Am Donnerstag, dem 14.08.2025 um 12:54 -0700 schrieb Tim Harvey:

Quoted 36 lines · Tom Rini
Quoted 18 lines · Yannic Moog
Quoted 7 lines

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Quoted 6 lines

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

[...]

Applied to u-boot/next, thanks!

Quoted 16 lines

[1/6] binman: drop "faked" return value from check_fake_fname
      commit: a657d87f08789c4c50423897bd5ee052c6223ee6
[2/6] binman: mark optional missing blobs as absent
      commit: 3ae668b9d2101d111d257ee7d8912c19cfb0e102
[3/6] binman: rework dropping absent entries from packaged image
      commit: 21bc3433a43d3add3430543c9eee2a95d4dee2f6
[4/6] binman: add faked optional entry case in CheckForProblems
      commit: f5817e05efd39dd455c2e6a0f0622d709fe7ea2d
[5/6] binman: ftest: pass allow_fake_blob to _DoReadFileDtb
      commit: e749d64b4622806072c56a839cf9a36a5081b575
[6/6] binman: test: assert optional blobs don't cause non-functionality
      commit: 0dbb0a8d1f2aefb2a7fdd8e627edd955e4fe8d3a
--
Tom

Quoted 5 lines

Hi Yannic,

I haven't had time to dig into it in detail yet but it looks like imx8m boards are failing again in master due to tee changes again and perhaps its this series that is causing it.

Thanks for reporting,

Quoted 16 lines

Here's what I see with today's mater:
make imx8mm_evk_defconfig
make
...
  BINMAN  .binman_stamp
Image 'image' is missing optional external blobs but is still functional:
tee-
os

binman: module 'importlib.resources' has no attribute 'files'
make: *** [Makefile:1339: .binman_stamp] Error 1

I thought I had read something about a warning that wasn't an error but above is clearly a build failure.

Quoted 8 lines
Quoted 1 line

Am I missing something here?

My initial gut feeling says it could be related to this series:
https://lore.kernel.org/u-boot/[email protected]/

Maybe the combination of the 2 series causes this. Anyway, I'll investigate and
report back.

So the error you are seeing is encountered here:
https://github.com/u-boot/u-boot/blob/0c558bbad9e7581808b358091d1fd979f860e8ac/tools/binman/control.py#L98

This is indeed caused by the patch I linked above.
When writing the patch (i.e. following the migration guide) I foolishly overlooked the fact that importlib.resources.files was only introduced in python 3.9, yet we support >=3.7.

I remember you use python 3.8, so that is why you see the error (and I don't).

I believe I need some help on finding a good solution. For this diff

-    glob_list = pkg_resources.resource_listdir(__name__, 'etype')
-    glob_list = [fname for fname in glob_list if fname.endswith('.py')]
+    entries = importlib_resources.files(__package__).joinpath('etype')
+    glob_list = [entry.name for entry in entries.iterdir()

+ if entry.name.endswith('.py') and entry.is_file()]

I haven't found a good replacement that is python 3.7 compatible. Any ideas?

Yannic

Quoted 6 lines

Yannic

Quoted 4 lines

Best Regards,

Tim

#15 lore raw
Quoted 77 lines · Yannic Moog

Am Freitag, dem 15.08.2025 um 05:44 +0000 schrieb Yannic Moog:

Quoted 63 lines

Hi Tim,

Am Donnerstag, dem 14.08.2025 um 12:54 -0700 schrieb Tim Harvey:

Quoted 36 lines · Tom Rini
Quoted 30 lines · Yannic Moog
Quoted 7 lines

This series solves a contradiction regarding ext blobs packaged in binman. When they are marked as optional, by default they are faked, two messages are emitted. One says the image is not functional the other says the image is still functional. Both concern the same binman entry/blob.

Quoted 6 lines

Binman is set up to have fake external blobs in case they are missing. This is regardless on whether they are optional or not.
The implementation does not allow different types of entries to override the faking decision; at least there wouldn't be much sense in doing so.

[...]

Applied to u-boot/next, thanks!

[1/6] binman: drop "faked" return value from check_fake_fname

      commit: a657d87f08789c4c50423897bd5ee052c6223ee6
[2/6] binman: mark optional missing blobs as absent
      commit: 3ae668b9d2101d111d257ee7d8912c19cfb0e102
[3/6] binman: rework dropping absent entries from packaged image
      commit: 21bc3433a43d3add3430543c9eee2a95d4dee2f6
[4/6] binman: add faked optional entry case in CheckForProblems
      commit: f5817e05efd39dd455c2e6a0f0622d709fe7ea2d
[5/6] binman: ftest: pass allow_fake_blob to _DoReadFileDtb
      commit: e749d64b4622806072c56a839cf9a36a5081b575
[6/6] binman: test: assert optional blobs don't cause non-functionality
      commit: 0dbb0a8d1f2aefb2a7fdd8e627edd955e4fe8d3a
Quoted 4 lines

--
Tom

Quoted 5 lines

Hi Yannic,

I haven't had time to dig into it in detail yet but it looks like imx8m boards are failing again in master due to tee changes again and perhaps its this series that is causing it.

Thanks for reporting,

Quoted 16 lines

Here's what I see with today's mater:
make imx8mm_evk_defconfig
make
...
BINMAN .binman_stamp
Image 'image' is missing optional external blobs but is still functional:
tee-
os

binman: module 'importlib.resources' has no attribute 'files'
make: *** [Makefile:1339: .binman_stamp] Error 1

I thought I had read something about a warning that wasn't an error but above is clearly a build failure.

Quoted 8 lines
Quoted 1 line

Am I missing something here?

My initial gut feeling says it could be related to this series:
https://lore.kernel.org/u-boot/[email protected]/

Maybe the combination of the 2 series causes this. Anyway, I'll investigate and
report back.

So the error you are seeing is encountered here:
https://github.com/u-boot/u-boot/blob/0c558bbad9e7581808b358091d1fd979f860e8ac/tools/binman/control.py#L98

Quoted 6 lines

This is indeed caused by the patch I linked above.
When writing the patch (i.e. following the migration guide) I foolishly overlooked the fact that importlib.resources.files was only introduced in python 3.9, yet we support >=3.7.

I remember you use python 3.8, so that is why you see the error (and I don't).

Hi Yannic,

I confirmed via docker containers that ubuntu-noble 24.04 (python 3.12.3) and ubuntu-jammy 22.04.04 (python 3.10.12) build ok and that ubuntu-focal 20.04.6 (python 3.8.10) which I was using fails.

I recall Tom saying we should aim for supporting Python 3.7+

Quoted 10 lines

I believe I need some help on finding a good solution. For this diff

(quoted diff) +3 -2
-    glob_list = pkg_resources.resource_listdir(__name__, 'etype')
-    glob_list = [fname for fname in glob_list if fname.endswith('.py')]
+    entries = importlib_resources.files(__package__).joinpath('etype')
+    glob_list = [entry.name for entry in entries.iterdir()
+                 if entry.name.endswith('.py') and entry.is_file()]
Quoted 2 lines

I haven't found a good replacement that is python 3.7 compatible. Any ideas?

Sorry, I haven't embraced the snake.

I guess I should update my build system to stop hitting this stuff :)

Best Regards,

Tim