Skip to contentSkip to conversation

Fix handling of optional blobs in binman

RFC PATCH Superseded Yannic Moog 2 participants 20 messages May 27, 2025 – Jun 13, 2025 Arm i.MX and Layerscape

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 will stay to inform/warn the user, but in this case the tee-os entry will not be present in the final image.

The first patch makes binman test with --fake_ext_blobs by default to be consistent with the default make target when building U-Boot. This exposes an error as one test is failing where it should not (loadables). Then, fix some tests that must not fake ext blobs and thus failed due to the change.

---
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 (8):
tools: binman: ftest: pass allow_fake_blob to _DoReadFileDtb
tools: binman: drop "faked" return value from check_fake_fname
tools: binman: mark optional missing blobs as absent
binman: replace _entries with GetEntries()
binman: rework dropping absent entries from packaged image
tools: binman: add faked optional entry case in CheckForProblems
tools: binman: ftest: fix tests that require non-faked ext blobs
binman: test: assert optional blobs don't cause non-functionality

 tools/binman/binman.rst               |  7 ++++
 tools/binman/control.py               | 27 +++++++++++----
 tools/binman/entry.py                 | 17 ++++++----
 tools/binman/etype/atf_fip.py         |  4 +--
 tools/binman/etype/blob.py            |  9 ++---
 tools/binman/etype/blob_ext_list.py   |  4 +--
 tools/binman/etype/blob_phase.py      |  4 +--
 tools/binman/etype/cbfs.py            | 15 +++++----
 tools/binman/etype/efi_capsule.py     |  2 +-
 tools/binman/etype/fit.py             |  4 +--
 tools/binman/etype/mkimage.py         |  6 ++--
 tools/binman/etype/nxp_imx8mcst.py    |  2 +-
 tools/binman/etype/nxp_imx8mimage.py  |  2 +-
 tools/binman/etype/section.py         | 62 ++++++++++++++++++++---------------
 tools/binman/etype/ti_board_config.py |  8 ++---
 tools/binman/ftest.py                 | 43 +++++++++++++++++-------
 tools/binman/image.py                 |  4 ++-
 17 files changed, 138 insertions(+), 82 deletions(-)

---
base-commit: eeb5ff1a468b2303efa9deb2483b5edbebb568c6
change-id: 20250122-binman_faked_optional-5025f7046e25

Best regards,

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

RFC PATCH v2 1/8 tools: binman: ftest: pass allow_fake_blob to _DoReadFileDtb

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.

---
 tools/binman/ftest.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
tools/binman/ftest.py +5 -4
index fa17490001488a297090a65c0c099ecc9a40e0f8..52f0a729bdab0a0bd00f798bbc07d678dd4513de 100644
@@ -510,9 +510,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
@@ -530,6 +530,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_blob: 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
@@ -567,7 +568,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')
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH v2 2/8 tools: binman: drop "faked" return value from check_fake_fname

In reply to Yannic Moog

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
Reviewed-by on v2 2/8
#3 lore raw

Re: [PATCH RFC v2 2/8] tools: binman: drop "faked" return value from check_fake_fname

Hi Yannic,

Quoted 11 lines · Yannic Moog

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

For the commit message, single quotes and <=60 chars are preferred. How about:

tools: binman: Don't return 'faked' from check_fake_fname()

#4 lore raw

RFC PATCH v2 3/8 tools: 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.
Note that the intended behaviour is the same, this patch just documents it.
The actual 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.
This, as well, is intended behaviour.

---
 tools/binman/binman.rst    | 7 +++++++
 tools/binman/etype/blob.py | 2 ++
 2 files changed, 9 insertions(+)
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
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH RFC v2 3/8] tools: binman: mark optional missing blobs as absent

Hi Yannic,

Quoted 8 lines · 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.
Note that the intended behaviour is the same, this patch just documents it.

This seems to indicate that it is just a doc change

Quoted 2 lines

The actual behaviour will change as now absent entries are no longer packed into an image. The image map will also reflect this.

But this indicates that it changes the functionality. Can you clarify this in your commit message?

Quoted 4 lines

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.
This, as well, is intended behaviour.

This breaks testExtblobOptional() for me.

I applied your patch: tools: binman: drop "faked" return value from check_fake_fname

Then I applied this one and got the error.

I could not apply patch 2 (ools: binman: ftest: pass allow_fake_blob to _DoReadFileDtb) as it broke a lot of tests.

For testExtblobOptional() I see that you have fixed it by the end of the series, but I get 11/12 test failures . Are you able to make the series bisectable, so that 'binman test' works for each commit? It's hard for me to comment on the series in this state.

Also there's no need to put an 'RFC' tag on this series. We do want to resolve this, one way or another.

Quoted 41 lines
---
 tools/binman/binman.rst    | 7 +++++++
 tools/binman/etype/blob.py | 2 ++
 2 files changed, 9 insertions(+)
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 -1
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
 
--
Quoted 2 lines

2.43.0

Regards,
Simon

#6 lore raw

Re: [PATCH RFC v2 3/8] tools: binman: mark optional missing blobs as absent

Hi Simon,

Am Freitag, dem 30.05.2025 um 12:18 +0100 schrieb Simon Glass:

Quoted 12 lines

Hi Yannic,

Quoted 8 lines · 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.
Note that the intended behaviour is the same, this patch just documents it.

Quoted 7 lines

This seems to indicate that it is just a doc change

Quoted 2 lines

The actual behaviour will change as now absent entries are no longer packed into an image. The image map will also reflect this.

But this indicates that it changes the functionality. Can you clarify this in your commit message?

Will clarify. I wrote that the intended! behaviour is the same, but due to a bug, the actual behaviour changes ...

The bug being that even though the documentation says optional blobs will be removed, they are not.

Quoted 7 lines
Quoted 5 lines

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.
This, as well, is intended behaviour.

This breaks testExtblobOptional() for me.

... That is why this test fails I believe. Since it relies on the bug to be present (i.e. absent optional blobs still included in the image).

Quoted 6 lines

I applied your patch: tools: binman: drop "faked" return value from check_fake_fname

Then I applied this one and got the error.

Quoted 7 lines

I could not apply patch 2 (ools: binman: ftest: pass allow_fake_blob to _DoReadFileDtb) as it broke a lot of tests.

For testExtblobOptional() I see that you have fixed it by the end of the series, but I get 11/12 test failures . Are you able to make the series bisectable, so that 'binman test' works for each commit? It's hard for me to comment on the series in this state.

Yes, will do.

Quoted 3 lines

Also there's no need to put an 'RFC' tag on this series. We do want to resolve this, one way or another.

I put RFC, because imo it is not to the quality standards expected of patches. You wanted to review the current state, but I didn't clean up yet, so that is why I sent as RFC.

Yannic

Quoted 56 lines
Quoted 50 lines

---
 tools/binman/binman.rst    | 7 +++++++
 tools/binman/etype/blob.py | 2 ++

 2 files changed, 9 insertions(+)
tools/binman/binman.rst +0 -0

index 84b1331df5c006f72167016b7f33de73f4a269fa..392e507d449c75eeba4431fe2db01d820b ce8f61 100644

tools/binman/binman.rst +0 -0
@@ -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.

tools/binman/binman.rst +7 -0
+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 +0 -0

index 970fae91cd9b2a31b3f31d2ecdb77e27a89d69fb..acd9ae34074e4b4b9792b107cc80514dfd d88b3b 100644

tools/binman/etype/blob.py +0 -0
@@ -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

Quoted 3 lines

--
2.43.0

Regards,
Simon

#7 lore raw

RFC PATCH v2 4/8 binman: replace _entries with GetEntries()

In reply to Yannic Moog

_entries, as highlighted by leading _, is a private member and thus should not be accessed directly. As a result use the GetEntries function instead.
GetEntries() returns _entries. No functional change introduced in this commit.

---
 tools/binman/etype/atf_fip.py         |  4 ++--
 tools/binman/etype/blob_phase.py      |  4 ++--
 tools/binman/etype/cbfs.py            | 12 +++++-----
 tools/binman/etype/efi_capsule.py     |  2 +-
 tools/binman/etype/fit.py             |  4 ++--
 tools/binman/etype/mkimage.py         |  4 ++--
 tools/binman/etype/nxp_imx8mcst.py    |  2 +-
 tools/binman/etype/nxp_imx8mimage.py  |  2 +-
 tools/binman/etype/section.py         | 44 +++++++++++++++++------------------
 tools/binman/etype/ti_board_config.py |  8 +++----
 tools/binman/ftest.py                 |  2 +-
 11 files changed, 44 insertions(+), 44 deletions(-)
tools/binman/etype/atf_fip.py +2 -2
index 636e073afc84b37d64934e6dd03945e9d515483a..56c5b2a8189453d83dd48fd37416690ded140f2a 100644
@@ -220,7 +220,7 @@ class Entry_atf_fip(Entry_section):
             bytes: Data obtained, or None if None
         """
         fip = FipWriter(self._fip_flags, self._fip_align)
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             # First get the input data and put it in an entry. If not available,
             # try later.
             entry_data = entry.GetData(required)
@@ -244,7 +244,7 @@ class Entry_atf_fip(Entry_section):
         super().SetImagePos(image_pos)
 
         # Now update the entries with info from the FIP entries
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             fent = entry._fip_entry
             entry.size = fent.size
             entry.offset = fent.offset
tools/binman/etype/blob_phase.py +2 -2
index 09bb89b3b7849834c3572f4c8080ce0fdcca1dc2..0f9ab3f05dd19baecb052ab8b3af513ecca15936 100644
@@ -55,10 +55,10 @@ class Entry_blob_phase(Entry_section):
 
         # Propagate the no-write-symbols property
         if self.no_write_symbols:
-            for entry in self._entries.values():
+            for entry in self.GetEntries().values():
                 entry.no_write_symbols = True
 
         # Propagate the symbols-base property
         if self.symbols_base is not None:
-            for entry in self._entries.values():
+            for entry in self.GetEntries().values():
                 entry.symbols_base = self.symbols_base
tools/binman/etype/cbfs.py +6 -6
index 124fa1e4ffc7d0374b27c09d32ead8429567d304..886e34ef8221ad50e9f881e8abad16015c9790b5 100644
@@ -220,7 +220,7 @@ class Entry_cbfs(Entry):
         if self.size is None:
             self.Raise("'cbfs' entry must have a size property")
         cbfs = CbfsWriter(self.size, arch)
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             if entry != skip_entry and not entry.ObtainContents():
                 return False
             cfile = self.ObtainCfile(cbfs, entry)
@@ -241,7 +241,7 @@ class Entry_cbfs(Entry):
         super().SetImagePos(image_pos)
 
         # Now update the entries with info from the CBFS entries
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             cfile = entry._cbfs_file
             entry.size = cfile.data_len
             entry.offset = cfile.calced_cbfs_offset
@@ -251,7 +251,7 @@ class Entry_cbfs(Entry):
 
     def AddMissingProperties(self, have_image_pos):
         super().AddMissingProperties(have_image_pos)
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             entry.AddMissingProperties(have_image_pos)
             if entry._cbfs_compress:
                 state.AddZeroProp(entry._node, 'uncomp-size')
@@ -263,7 +263,7 @@ class Entry_cbfs(Entry):
     def SetCalculatedProperties(self):
         """Set the value of device-tree properties calculated by binman"""
         super().SetCalculatedProperties()
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             state.SetInt(entry._node, 'offset', entry.offset)
             state.SetInt(entry._node, 'size', entry.size)
             state.SetInt(entry._node, 'image-pos', entry.image_pos)
@@ -273,7 +273,7 @@ class Entry_cbfs(Entry):
     def ListEntries(self, entries, indent):
         """Override this method to list all files in the section"""
         super().ListEntries(entries, indent)
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             entry.ListEntries(entries, indent + 1)
 
     def GetEntries(self):
@@ -299,5 +299,5 @@ class Entry_cbfs(Entry):
 
     def AddBintools(self, btools):
         super().AddBintools(btools)
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             entry.AddBintools(btools)
tools/binman/etype/efi_capsule.py +1 -1
index 9f06cc88e6e505448800c05988a039d287525b7b..5cdc6536795b824aea74b22b198a177df8cb35e2 100644
@@ -130,7 +130,7 @@ class Entry_efi_capsule(Entry_section):
             if not os.path.isabs(self.public_key_cert):
                 public_key_cert = tools.get_input_filename(self.public_key_cert)
         data, payload, uniq = self.collect_contents_to_file(
-            self._entries.values(), 'capsule_in')
+            self.GetEntries().values(), 'capsule_in')
         outfile = self._filename if self._filename else 'capsule.%s' % uniq
         capsule_fname = tools.get_output_filename(outfile)
         guid = self.image_guid
tools/binman/etype/fit.py +2 -2
index ed3cac4ee7e9706bc46f1cffc90c41946591ec2f..f03e64319eeb3c23b59e368bfac698765e68e1b5 100644
@@ -962,7 +962,7 @@ class Entry_fit(Entry_section):
 
         # Remove generator entries from the main list
         for path in to_remove:
-            if path in self._entries:
+            if path in self.GetEntries():
                 del self._entries[path]
 
         # Pack this new FDT and scan it so we can add the data later
@@ -994,7 +994,7 @@ class Entry_fit(Entry_section):
         fdt = Fdt.FromData(self.GetData())
         fdt.Scan()
 
-        for image_name, entry in self._entries.items():
+        for image_name, entry in self.GetEntries().items():
             path = f"/images/{image_name}"
             node = fdt.GetNode(path)
 
tools/binman/etype/mkimage.py +2 -2
index 6ae5d0c8a4f3c54e1277a575b8e235cc1aba4e13..19ee30a13ca75a5d05a17d4c26424e84934b6ea2 100644
@@ -168,7 +168,7 @@ class Entry_mkimage(Entry_section):
         if self._multiple_data_files:
             fnames = []
             uniq = self.GetUniqueName()
-            for entry in self._entries.values():
+            for entry in self.GetEntries().values():
                 # Put the contents in a temporary file
                 ename = f'mkimage-in-{uniq}-{entry.name}'
                 fname = tools.get_output_filename(ename)
@@ -179,7 +179,7 @@ class Entry_mkimage(Entry_section):
             data = b''
         else:
             data, input_fname, uniq = self.collect_contents_to_file(
-                self._entries.values(), 'mkimage', fake_size)
+                self.GetEntries().values(), 'mkimage', fake_size)
         if self._imagename:
             image_data, imagename_fname, _ = self.collect_contents_to_file(
                 [self._imagename], 'mkimage-n', 1024)
tools/binman/etype/nxp_imx8mcst.py +1 -1
index dd9f226b7514ff4070652273c5520498bec02f90..8b3785a318bcc4c92c3ac0ed23b745f08911e4fb 100644
@@ -95,7 +95,7 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
 
     def BuildSectionData(self, required):
         data, input_fname, uniq = self.collect_contents_to_file(
-            self._entries.values(), 'input')
+            self.GetEntries().values(), 'input')
 
         # Parse the input data and figure out what it is that is being signed.
         # - If it is mkimage'd imx8mimage, then extract to be signed data size
tools/binman/etype/nxp_imx8mimage.py +1 -1
index 8ad177b3b65e8c45e7f2fd74768b319930704e10..2fc572f2dc09a40b8e255d6157de31f806649e7d 100644
@@ -39,7 +39,7 @@ class Entry_nxp_imx8mimage(Entry_mkimage):
 
     def BuildSectionData(self, required):
         data, input_fname, uniq = self.collect_contents_to_file(
-            self._entries.values(), 'input')
+            self.GetEntries().values(), 'input')
         # Generate mkimage configuration file similar to imx8mimage.cfg
         # and pass it to mkimage to generate SPL image for us here.
         cfg_fname = tools.get_output_filename('nxp.imx8mimage.cfg.%s' % uniq)
tools/binman/etype/section.py +22 -22

163 lines not on this page · raw message

tools/binman/etype/ti_board_config.py +4 -4
index 7c6773ac7bcd2780b5bbe7b3cd6d7d62b38dfe77..a78c7ba14561072ff64ad64ebcbcbbe95d074859 100644
@@ -227,16 +227,16 @@ class Entry_ti_board_config(Entry_section):
             self._binary_offset += t_bytes
             self._binary_offset += self._num_elems * struct.calcsize(self._fmt)
 
-            if 'board-cfg' in self._entries:
+            if 'board-cfg' in self.GetEntries():
                 self._add_boardcfg(BOARDCFG, self._entries['board-cfg']._cfg_data)
 
-            if 'sec-cfg' in self._entries:
+            if 'sec-cfg' in self.GetEntries():
                 self._add_boardcfg(BOARDCFG_SEC, self._entries['sec-cfg']._cfg_data)
 
-            if 'pm-cfg' in self._entries:
+            if 'pm-cfg' in self.GetEntries():
                 self._add_boardcfg(BOARDCFG_PM, self._entries['pm-cfg']._cfg_data)
 
-            if 'rm-cfg' in self._entries:
+            if 'rm-cfg' in self.GetEntries():
                 self._add_boardcfg(BOARDCFG_RM, self._entries['rm-cfg']._cfg_data)
 
             data = self._finalize()
tools/binman/ftest.py +1 -1
index 52f0a729bdab0a0bd00f798bbc07d678dd4513de..3fccd4c8ef5f8757b54f3b3fe5fe7898fd166dcb 100644
@@ -2198,7 +2198,7 @@ class TestFunctional(unittest.TestCase):
         image = control.images['image']
         entries = image.GetEntries()
         files = entries['files']
-        entries = files._entries
+        entries = files.GetEntries()
 
         orig = b''
         for i in range(1, 3):
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH RFC v2 4/8] binman: replace _entries with GetEntries()

Hi Yannic,

Quoted 8 lines · Yannic Moog

_entries, as highlighted by leading _, is a private member and thus should not be accessed directly. As a result use the GetEntries function instead.
GetEntries() returns _entries. No functional change introduced in this commit.

Quoted 13 lines
---
 tools/binman/etype/atf_fip.py         |  4 ++--
 tools/binman/etype/blob_phase.py      |  4 ++--
 tools/binman/etype/cbfs.py            | 12 +++++-----
 tools/binman/etype/efi_capsule.py     |  2 +-
 tools/binman/etype/fit.py             |  4 ++--
 tools/binman/etype/mkimage.py         |  4 ++--
 tools/binman/etype/nxp_imx8mcst.py    |  2 +-
 tools/binman/etype/nxp_imx8mimage.py  |  2 +-
 tools/binman/etype/section.py         | 44 +++++++++++++++++------------------
 tools/binman/etype/ti_board_config.py |  8 +++----
 tools/binman/ftest.py                 |  2 +-
 11 files changed, 44 insertions(+), 44 deletions(-)

Are you sure this is right? The classes which use _entries are subclasses, except for ftest.py which is test code where we should probably add:

#pylint: disable=protected-access

Regards,
Simon

#9 lore raw

Re: [PATCH RFC v2 4/8] binman: replace _entries with GetEntries()

Am Freitag, dem 30.05.2025 um 12:18 +0100 schrieb Simon Glass:

Quoted 26 lines

Hi Yannic,

Quoted 21 lines · Yannic Moog

_entries, as highlighted by leading _, is a private member and thus should not be accessed directly. As a result use the GetEntries function instead.
GetEntries() returns _entries. No functional change introduced in this commit.

---
 tools/binman/etype/atf_fip.py         |  4 ++-- tools/binman/etype/blob_phase.py      |  4 ++-- tools/binman/etype/cbfs.py            | 12 +++++----- tools/binman/etype/efi_capsule.py     |  2 +- tools/binman/etype/fit.py             |  4 ++-- tools/binman/etype/mkimage.py         |  4 ++-- tools/binman/etype/nxp_imx8mcst.py    |  2 +- tools/binman/etype/nxp_imx8mimage.py  |  2 +- tools/binman/etype/section.py         | 44 +++++++++++++++++---------------
---
 tools/binman/etype/ti_board_config.py |  8 +++---- tools/binman/ftest.py                 |  2 +-

Quoted 1 line
 11 files changed, 44 insertions(+), 44 deletions(-)
Quoted 5 lines

Are you sure this is right? The classes which use _entries are subclasses, except for ftest.py which is test code where we should probably add:

#pylint: disable=protected-access

I don't think this is right on second thought. I'll drop this patch altogether as I would like to focus on (imo) more important aspects of the series first.

Quoted 3 lines

Regards,
Simon

#10 lore raw

RFC PATCH v2 5/8 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.

---
 tools/binman/control.py       |  8 ++++----
 tools/binman/entry.py         |  6 +++++-
 tools/binman/etype/cbfs.py    |  3 ++-
 tools/binman/etype/mkimage.py |  2 +-
 tools/binman/etype/section.py | 18 +++++++++++++-----
 tools/binman/image.py         |  4 +++-
 6 files changed, 28 insertions(+), 13 deletions(-)
tools/binman/control.py +4 -4
index 81f61e3e152a9eab558cfc9667131a38082b61a1..c2a4d3eae9d4e8f4a3c5be1abfb1469ba1c0ed93 100644
@@ -18,6 +18,7 @@ import re
 
 import sys
 
+import image
 from binman import bintool
 from binman import cbfs_util
 from binman import elf
@@ -669,7 +670,7 @@ def CheckForProblems(image):
                                    for bintool in missing_bintool_list])))
     return any([missing_list, faked_list, missing_bintool_list])
 
-def ProcessImage(image, update_fdt, write_map, get_contents=True,
+def ProcessImage(image: image.Image, update_fdt, write_map, get_contents=True,
                  allow_resize=True, allow_missing=False,
                  allow_fake_blobs=False):
     """Perform all steps for this image, including checking and # writing it.
@@ -697,7 +698,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 +736,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 886e34ef8221ad50e9f881e8abad16015c9790b5..bb97b227ef78356b08b5cc31b04d98c6fa0633ef 100644
@@ -276,7 +276,8 @@ class Entry_cbfs(Entry):
         for entry in self.GetEntries().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 19ee30a13ca75a5d05a17d4c26424e84934b6ea2..c9362c6bbf740da946abe2fadefe35ebfc89fced 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 +13 -5
index 44b1b85e93496d0ca114907f42a98da1f0af09b9..8e5c20e3017c9b320ebfdfd3bf82489ed6161c98 100644
@@ -450,7 +450,7 @@ class Entry_section(Entry):
     def _PackEntries(self):
         """Pack all entries into the section"""
         offset = self._skip_at_start
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():
             offset = entry.Pack(offset)
         return offset
 
@@ -533,7 +533,7 @@ class Entry_section(Entry):
         for entry in self.GetEntries().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):
@@ -768,9 +768,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/image.py +3 -1
index 24ce0af7c72b5256a9a71963a6d94c080ed8bdd4..86543ad8db36b38afc1957fde7e20152067b79aa 100644
@@ -15,7 +15,7 @@ import sys
 from binman.entry import Entry
 from binman.etype import fdtmap
 from binman.etype import image_header
-from binman.etype import section
+from etype import section
 from dtoc import fdt
 from dtoc import fdt_util
 from u_boot_pylib import tools
@@ -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
#11 lore raw

Re: [PATCH RFC v2 5/8] binman: rework dropping absent entries from packaged image

Hi Yannic,

Quoted 30 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.

---
 tools/binman/control.py       |  8 ++++----
 tools/binman/entry.py         |  6 +++++-
 tools/binman/etype/cbfs.py    |  3 ++-
 tools/binman/etype/mkimage.py |  2 +-
 tools/binman/etype/section.py | 18 +++++++++++++-----
 tools/binman/image.py         |  4 +++-
 6 files changed, 28 insertions(+), 13 deletions(-)
tools/binman/control.py +0 -0
index 81f61e3e152a9eab558cfc9667131a38082b61a1..c2a4d3eae9d4e8f4a3c5be1abfb1469ba1c0ed93 100644

tools/binman/control.py import re · line 21

Quoted 4 lines
tools/binman/control.py +1 -0
@@ -18,6 +18,7 @@ import re
 
 import sys
 
+import image

This is done later in this file, to avoid warnings about missing modules when trying to get help ('binman -h'). I am guessing you need it for the type declaration below.

It may be that this is not necessary anymore though, in which case could you put this in a separate patch, use the 'from binman import' syntax and drop the other 'imports' from below?

Quoted 91 lines
tools/binman/control.py +3 -4
 from binman import bintool
 from binman import cbfs_util
 from binman import elf
@@ -669,7 +670,7 @@ def CheckForProblems(image):
                                    for bintool in missing_bintool_list])))
     return any([missing_list, faked_list, missing_bintool_list])
 
-def ProcessImage(image, update_fdt, write_map, get_contents=True,
+def ProcessImage(image: image.Image, update_fdt, write_map, get_contents=True,
                  allow_resize=True, allow_missing=False,
                  allow_fake_blobs=False):
     """Perform all steps for this image, including checking and # writing it.
@@ -697,7 +698,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 +736,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 886e34ef8221ad50e9f881e8abad16015c9790b5..bb97b227ef78356b08b5cc31b04d98c6fa0633ef 100644
@@ -276,7 +276,8 @@ class Entry_cbfs(Entry):
         for entry in self.GetEntries().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 19ee30a13ca75a5d05a17d4c26424e84934b6ea2..c9362c6bbf740da946abe2fadefe35ebfc89fced 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 +0 -0
index 44b1b85e93496d0ca114907f42a98da1f0af09b9..8e5c20e3017c9b320ebfdfd3bf82489ed6161c98 100644

tools/binman/etype/section.py class Entry_section(Entry): · line 453

Quoted 5 lines
tools/binman/etype/section.py +1 -1
@@ -450,7 +450,7 @@ class Entry_section(Entry):
     def _PackEntries(self):
         """Pack all entries into the section"""
         offset = self._skip_at_start
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():

As per previous patch, this should not be needed.

Quoted 13 lines
tools/binman/etype/section.py +1 -1
             offset = entry.Pack(offset)
         return offset
 
@@ -533,7 +533,7 @@ class Entry_section(Entry):
         for entry in self.GetEntries().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):

tools/binman/etype/section.py class Entry_section(Entry): · line 774

Quoted 10 lines
tools/binman/etype/section.py +4 -3
@@ -768,9 +768,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

should this be: all optional children ?

tools/binman/etype/section.py class Entry_section(Entry): · line 780

Quoted 6 lines
tools/binman/etype/section.py +6 -0
+        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():

As above, I think self._entries is correct

Quoted 9 lines
tools/binman/etype/section.py +1 -0
+            e.drop_absent_optional()
 
     def _SetEntryOffsetSize(self, name, offset, size):
         """Set the offset and size of an entry
tools/binman/image.py +0 -0
index 24ce0af7c72b5256a9a71963a6d94c080ed8bdd4..86543ad8db36b38afc1957fde7e20152067b79aa 100644

tools/binman/image.py import sys · line 18

Quoted 5 lines
tools/binman/image.py +1 -1
@@ -15,7 +15,7 @@ import sys
 from binman.entry import Entry
 from binman.etype import fdtmap
 from binman.etype import image_header
-from binman.etype import section
+from etype import section

Why this change? I suspect it will break when installed with 'pip install binary-manager'

Quoted 14 lines
tools/binman/image.py +2 -1
 from dtoc import fdt
 from dtoc import fdt_util
 from u_boot_pylib import tools
@@ -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

Regards,
Simon

#12 lore raw

Re: [PATCH RFC v2 5/8] binman: rework dropping absent entries from packaged image

Am Freitag, dem 30.05.2025 um 12:18 +0100 schrieb Simon Glass:

Quoted 44 lines

Hi Yannic,

Quoted 35 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.

---
 tools/binman/control.py       |  8 ++++---- tools/binman/entry.py         |  6 +++++- tools/binman/etype/cbfs.py    |  3 ++- tools/binman/etype/mkimage.py |  2 +- tools/binman/etype/section.py | 18 +++++++++++++----- tools/binman/image.py         |  4 +++-

 6 files changed, 28 insertions(+), 13 deletions(-)
tools/binman/control.py +0 -0

index 81f61e3e152a9eab558cfc9667131a38082b61a1..c2a4d3eae9d4e8f4a3c5be1abfb1469ba1 c0ed93 100644

tools/binman/control.py +0 -0
@@ -18,6 +18,7 @@ import re
 

 import sys

Quoted 1 line

+import image

This is done later in this file, to avoid warnings about missing modules when trying to get help ('binman -h'). I am guessing you need it for the type declaration below.

Quoted 3 lines

It may be that this is not necessary anymore though, in which case could you put this in a separate patch, use the 'from binman import' syntax and drop the other 'imports' from below?

Would like to leave this untouched to keep diff short after thinking about it.

Quoted 104 lines
Quoted 104 lines

 from binman import bintool
 from binman import cbfs_util
 from binman import elf

tools/binman/control.py +1 -1
@@ -669,7 +670,7 @@ def CheckForProblems(image):
                                     for bintool in missing_bintool_list])))
      return any([missing_list, faked_list, missing_bintool_list])
 
-def ProcessImage(image, update_fdt, write_map, get_contents=True,
+def ProcessImage(image: image.Image, update_fdt, write_map,
 get_contents=True,
                   allow_resize=True, allow_missing=False,

                  allow_fake_blobs=False):
     """Perform all steps for this image, including checking and # writing it.

tools/binman/control.py +0 -1
@@ -697,7 +698,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

tools/binman/control.py +0 -0
@@ -736,12 +736,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 +0 -0

index 6390917e5083e40a4e3294e5d36ec300d2057fe9..ce7ef28e94b17e349544776070c457d588 2661b1 100644

tools/binman/entry.py +1 -1
@@ -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:

tools/binman/entry.py +4 -0
@@ -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 +0 -0

index 886e34ef8221ad50e9f881e8abad16015c9790b5..bb97b227ef78356b08b5cc31b04d98c6fa 0633ef 100644

tools/binman/etype/cbfs.py +0 -0
@@ -276,7 +276,8 @@ class Entry_cbfs(Entry):

         for entry in self.GetEntries().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 +0 -0

index 19ee30a13ca75a5d05a17d4c26424e84934b6ea2..c9362c6bbf740da946abe2fadefe35ebfc 89fced 100644

tools/binman/etype/mkimage.py +0 -0
@@ -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 +0 -0

index 44b1b85e93496d0ca114907f42a98da1f0af09b9..8e5c20e3017c9b320ebfdfd3bf82489ed6 161c98 100644

tools/binman/etype/section.py +0 -0
Quoted 8 lines
Quoted 6 lines
tools/binman/etype/section.py +0 -0
@@ -450,7 +450,7 @@ class Entry_section(Entry):

     def _PackEntries(self):
         """Pack all entries into the section"""
         offset = self._skip_at_start
-        for entry in self._entries.values():
+        for entry in self.GetEntries().values():

As per previous patch, this should not be needed.

Agree.

Quoted 17 lines
Quoted 17 lines

             offset = entry.Pack(offset)
         return offset

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

         for entry in self.GetEntries().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):

tools/binman/etype/section.py +0 -0
@@ -768,9 +768,17 @@ class Entry_section(Entry):
                         todo)

         return True

Quoted 11 lines
Quoted 9 lines

-    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

should this be: all optional children ?

Yes, forgot to update, thanks.

Quoted 23 lines
Quoted 9 lines

+        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():

As above, I think self._entries is correct

Quoted 11 lines

+            e.drop_absent_optional()

     def _SetEntryOffsetSize(self, name, offset, size):
         """Set the offset and size of an entry

tools/binman/image.py +0 -0

index 24ce0af7c72b5256a9a71963a6d94c080ed8bdd4..86543ad8db36b38afc1957fde7e2015206 7b79aa 100644

tools/binman/image.py +0 -0
@@ -15,7 +15,7 @@ import sys
Quoted 8 lines

tools/binman/image.py import sys · line 18

Quoted 5 lines

 from binman.entry import Entry
 from binman.etype import fdtmap
 from binman.etype import image_header

tools/binman/image.py +1 -1
-from binman.etype import section
+from etype import section

Why this change? I suspect it will break when installed with 'pip install binary-manager'

I only used this to get lsp working, will drop this change.

Quoted 20 lines
Quoted 14 lines

 from dtoc import fdt
 from dtoc import fdt_util
 from u_boot_pylib import tools

tools/binman/image.py +0 -0
@@ -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 3 lines

--
2.43.0

Regards,
Simon

#13 lore raw

RFC PATCH v2 6/8 tools: 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. This patch does not change the behaviour as blobs remove themselves before CheckForProblems is called.

---
 tools/binman/control.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tools/binman/control.py +16 -3
index c2a4d3eae9d4e8f4a3c5be1abfb1469ba1c0ed93..baccb647c56f6abf987d787ef4826fbea625bc0f 100644
@@ -646,12 +646,19 @@ 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 = []
     image.CheckOptional(optional_list)
@@ -661,6 +668,12 @@ def CheckForProblems(image):
             (image.name, ' '.join([e.name for e in optional_list])))
         _ShowHelpForMissingBlobs(tout.WARNING, optional_list)
 
+    if faked_optional_list:
+        tout.warning(
+            "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:
@@ -668,7 +681,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: image.Image, update_fdt, write_map, get_contents=True,
                  allow_resize=True, allow_missing=False,
Signature · 1 line
2.43.0
#14 lore raw

RFC PATCH v2 7/8 tools: binman: ftest: fix tests that require non-faked ext blobs

In reply to Yannic Moog

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 | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
tools/binman/ftest.py +11 -7
index 3fccd4c8ef5f8757b54f3b3fe5fe7898fd166dcb..d7deb3e68ce69c9c1a132f8f29cb71638646277a 100644
@@ -5207,13 +5207,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))
 
@@ -5221,7 +5223,7 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         """Test an image with an missing external blob that is allowed"""
         with test_util.capture_sys_output() 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")
 
@@ -5758,10 +5760,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: .*")
@@ -6532,7 +6534,9 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
     def testExtblobOptional(self):
         """Test an image with an external blob that is optional"""
         with test_util.capture_sys_output() 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)
         err = stderr.getvalue()
         self.assertRegex(
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH RFC v2 7/8] tools: binman: ftest: fix tests that require non-faked ext blobs

Hi Yannic,

Quoted 6 lines · Yannic Moog

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.

I still don't really understand why the default for tests needs to be to fake the blobs, i.e. the default for allow_fake_blobs becomes True instead of False in tests. For most tests, there is no external blob anyway,

But let's try it for now.

Can you push these changes into the other commits so that the series is bisectable with 'binman test' ?

Quoted 6 lines
---
 tools/binman/ftest.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Regards,
Simon

#16 lore raw

Re: [PATCH RFC v2 7/8] tools: binman: ftest: fix tests that require non-faked ext blobs

Am Freitag, dem 30.05.2025 um 12:18 +0100 schrieb Simon Glass:

Quoted 15 lines

Hi Yannic,

Quoted 6 lines · Yannic Moog

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.

I still don't really understand why the default for tests needs to be to fake the blobs, i.e. the default for allow_fake_blobs becomes True instead of False in tests. For most tests, there is no external blob anyway,

Quoted 4 lines

But let's try it for now.

Can you push these changes into the other commits so that the series is bisectable with 'binman test' ?

Although I think this complicates reviewing, I'll give it a shot. Commit description will be lengthy, then.

Yannic

Quoted 10 lines
Quoted 7 lines

---
 tools/binman/ftest.py | 18 +++++++++++-------

 1 file changed, 11 insertions(+), 7 deletions(-)

Regards,
Simon

#17 lore raw

RFC PATCH v2 8/8 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 d7deb3e68ce69c9c1a132f8f29cb71638646277a..31083c22bbf9e5898840505b0ffbd4512c61ae80 100644
@@ -6506,6 +6506,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"""
@@ -6543,6 +6546,19 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             err,
             "Image '.*' is missing optional external blobs but is still functional: missing")
 
+    def testExtblobFakedOptional(self):
+        """Test an image with an external blob that is optional"""
+        with test_util.capture_sys_output() 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
#18 lore raw
In reply to Yannic Moog

Hi Yannic,

Quoted 21 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.

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

Quoted 5 lines

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

OFCHK .config

The output will stay to inform/warn the user, but in this case the

s/will stay/stays/

We should use present / imperative tense.

Quoted 7 lines

tee-os entry will not be present in the final image.

The first patch makes binman test with --fake_ext_blobs by default to be consistent with the default make target when building U-Boot. This exposes an error as one test is failing where it should not (loadables). Then, fix some tests that must not fake ext blobs and thus failed due to the change.

Again I'm still not sure why we need to change the default, but once we have a bisectable series I will probably understand it better.

Please also rebase on -next

Quoted 36 lines

---
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 (8):
tools: binman: ftest: pass allow_fake_blob to _DoReadFileDtb
tools: binman: drop "faked" return value from check_fake_fname
tools: binman: mark optional missing blobs as absent
binman: replace _entries with GetEntries()
binman: rework dropping absent entries from packaged image
tools: binman: add faked optional entry case in CheckForProblems
tools: binman: ftest: fix tests that require non-faked ext blobs
binman: test: assert optional blobs don't cause non-functionality

 tools/binman/binman.rst               |  7 ++++
 tools/binman/control.py               | 27 +++++++++++----
 tools/binman/entry.py                 | 17 ++++++----
 tools/binman/etype/atf_fip.py         |  4 +--
 tools/binman/etype/blob.py            |  9 ++---
 tools/binman/etype/blob_ext_list.py   |  4 +--
 tools/binman/etype/blob_phase.py      |  4 +--
 tools/binman/etype/cbfs.py            | 15 +++++----
 tools/binman/etype/efi_capsule.py     |  2 +-
 tools/binman/etype/fit.py             |  4 +--
 tools/binman/etype/mkimage.py         |  6 ++--
 tools/binman/etype/nxp_imx8mcst.py    |  2 +-
 tools/binman/etype/nxp_imx8mimage.py  |  2 +-
 tools/binman/etype/section.py         | 62 ++++++++++++++++++++---------------
 tools/binman/etype/ti_board_config.py |  8 ++---
 tools/binman/ftest.py                 | 43 +++++++++++++++++-------
 tools/binman/image.py                 |  4 ++-
 17 files changed, 138 insertions(+), 82 deletions(-)
Quoted 8 lines

---
base-commit: eeb5ff1a468b2303efa9deb2483b5edbebb568c6
change-id: 20250122-binman_faked_optional-5025f7046e25

Best regards,
--
Yannic Moog <[email protected]>

Regards,
Simon

#19 lore raw

Hi Simon,

Am Freitag, dem 30.05.2025 um 12:18 +0100 schrieb Simon Glass:

Quoted 29 lines

Hi Yannic,

Quoted 26 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.

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

Quoted 7 lines
Quoted 3 lines

  OFCHK   .config

The output will stay to inform/warn the user, but in this case the

s/will stay/stays/

We should use present / imperative tense.

Will change, thanks.

Quoted 9 lines
Quoted 8 lines

tee-os entry will not be present in the final image.

The first patch makes binman test with --fake_ext_blobs by default to be consistent with the default make target when building U-Boot. This exposes an error as one test is failing where it should not (loadables). Then, fix some tests that must not fake ext blobs and thus failed due to the change.

Quoted 4 lines

Again I'm still not sure why we need to change the default, but once we have a bisectable series I will probably understand it better.

Please also rebase on -next

Will do.

Quoted 2 lines