We have the BINMAN_INDIRS for any external binaries, so they don't have
to be copied into the source/build directory of u-boot. This is
especially important for image builders like buildroot.

Use the get_input_filename() helper which will also look up the paths in
BINMAN_INDIRS. The append case only handles external files, thus we can
use that helper unconditionally.

While at it, update and extend the test case for this image format.
That is, first create the image in the input directory and then check if
there is actually an append command with that image name in the resulting
.cfgout file. To cover the not-found path also add a missing external
image.

Signed-off-by: Michael Walle <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
---
v5:
 - add a missing blob in the test dts, to cover the else branch in
   the test

v4:
 - reword commit message
 - update test case
 - (RESEND) to the new uboot mailing list address.

v3:
 - emit the command strings

v2:
 - forgot to add second lookup. add the same fix

 tools/binman/etype/nxp_imx9image.py    | 22 ++++++++++++----------
 tools/binman/ftest.py                  |  9 ++++++---
 tools/binman/test/vendor/nxp_imx95.dts |  1 +
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/binman/etype/nxp_imx9image.py 
b/tools/binman/etype/nxp_imx9image.py
index e0e806f2b7f..1a1465d7e7b 100644
--- a/tools/binman/etype/nxp_imx9image.py
+++ b/tools/binman/etype/nxp_imx9image.py
@@ -50,21 +50,23 @@ class Entry_nxp_imx9image(Entry_mkimage):
 
                 if key.startswith('image') and isinstance(value, list) and 
len(value) == 3:
                     file = value[1]
-                    image_path = os.path.join(tools.get_output_dir(), value[1])
-                    value[1] = image_path
-                    combined = ' '.join(map(str, value))
-
-                    if file in external_files and not os.path.exists(value[1]):
-                        print(f"file '{image_path}' does not exist. flash.bin 
may be not-functional.")
+                    if file in external_files:
+                        value[1] = tools.get_input_filename(file, 
allow_missing=True)
+                        if not value[1]:
+                            print(f"file '{file}' does not exist. flash.bin 
may be not-functional.")
+                            continue
                     else:
-                        f.write(f'image {combined}\n')
+                        value[1] = os.path.join(tools.get_output_dir(), file)
+
+                    combined = ' '.join(map(str, value))
+                    f.write(f'image {combined}\n')
                 elif isinstance(value, str):
                     if key.startswith('append'):
-                        file_path = os.path.join(tools.get_output_dir(), value)
-                        if os.path.exists(file_path):
+                        file_path = tools.get_input_filename(value, 
allow_missing=True)
+                        if file_path:
                             f.write(f'append {file_path}\n')
                         else:
-                            print(f"file '{file_path}' does not exist. 
flash.bin may be not-functional.")
+                            print(f"file '{value}' does not exist. flash.bin 
may be not-functional.")
                     else:
                         f.write(f'{formatted_key} {value}\n')
                 elif isinstance(value, bool):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index bf98b268ac1..48c5a08b4eb 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -8126,12 +8126,15 @@ fdt         fdtmap                Extract the 
devicetree blob from the fdtmap
         image_path = os.path.join(testdir, 'image.bin')
         with open(image_path, 'w') as f:
             pass
-        container_path = os.path.join(testdir, 'mx95b0-ahab-container.img')
-        with open(container_path, 'w') as f:
-            f.write(bytes([0x87]).decode('latin1') * 32768)
+        self._MakeInputFile('mx95b0-ahab-container.img', bytes([0x87] * 32768))
         with terminal.capture():
             self._DoTestFile('vendor/nxp_imx95.dts', output_dir=testdir)
 
+        fname = tools.get_output_filename('u-boot-container.cfgout')
+        with open(fname, 'r') as fd:
+            data = fd.read()
+            self.assertRegex(data, "append .*/mx95b0-ahab-container.img\n")
+
     def testFitSignSimple(self):
         """Test that image with FIT and signature nodes can be signed"""
         if not elf.ELF_TOOLS:
diff --git a/tools/binman/test/vendor/nxp_imx95.dts 
b/tools/binman/test/vendor/nxp_imx95.dts
index 3fc2de44b4a..36495792282 100644
--- a/tools/binman/test/vendor/nxp_imx95.dts
+++ b/tools/binman/test/vendor/nxp_imx95.dts
@@ -20,6 +20,7 @@
                        container;
                        image0 = "a55", "bl31.bin", "0x8a200000";
                        image1 = "a55", "image.bin", "0x90200000";
+                       image2 = "m33", "m33_image.bin", "0x1ffc0000";
                };
        };
 };
-- 
2.47.3

Reply via email to