[PATCH v4 2/8] binman: allow user-defined filenames for mkimage entry

Quentin Schulz foss+uboot at 0leil.net
Wed Aug 3 14:19:00 CEST 2022


From: Quentin Schulz <quentin.schulz at theobroma-systems.com>

mkimage entry currently creates a file whose name is derived from the
section name containing said entry.

Let's allow the user to define a filename for the mkimage-generated
binary by using the 'filename' DT property.

Cc: Quentin Schulz <foss+uboot at 0leil.net>
Signed-off-by: Quentin Schulz <quentin.schulz at theobroma-systems.com>
---

v4:
 - added binman test,
 - fixed >80 chars-long line,

added in v3

 tools/binman/etype/mkimage.py              |  9 ++++++--
 tools/binman/ftest.py                      |  6 ++++++
 tools/binman/test/235_mkimage_filename.dts | 24 ++++++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/test/235_mkimage_filename.dts

diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index 52297c23ea..009b26f10a 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -20,11 +20,13 @@ class Entry_mkimage(Entry):
           datafiles to mkimage instead of creating a temporary file the result
           of datafiles concatenation
         - args: Other arguments to pass
+        - filename: filename of output binary generated by mkimage
 
     The data passed to mkimage is collected from subnodes of the mkimage node,
     e.g.::
 
         mkimage {
+            filename = "imximage.bin";
             args = "-n test -T imximage";
 
             u-boot-spl {
@@ -33,7 +35,7 @@ class Entry_mkimage(Entry):
 
     This calls mkimage to create an imximage with u-boot-spl.bin as the input
     file. The output from mkimage then becomes part of the image produced by
-    binman.
+    binman but also is written into imximage.bin file.
 
 	To pass all datafiles untouched to mkimage::
 
@@ -70,6 +72,7 @@ class Entry_mkimage(Entry):
         self._args = fdt_util.GetArgs(self._node, 'args')
         self._multiple_data_files = fdt_util.GetBool(self._node, 'multiple-data-files')
         self._mkimage_entries = OrderedDict()
+        self._filename = fdt_util.GetString(self._node, 'filename')
         self.align_default = None
         self.ReadEntries()
 
@@ -89,7 +92,9 @@ class Entry_mkimage(Entry):
                 self._mkimage_entries.values(), 'mkimage', fake_size)
             if data is None:
                 return False
-        output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
+
+        outfile = self._filename if self._filename else 'mkimage-out.%s' % uniq
+        output_fname = tools.get_output_filename(outfile)
         if self.mkimage.run_cmd('-d', input_fname, *self._args,
                                 output_fname) is not None:
             self.SetContents(tools.read_file(output_fname))
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index fa1f421c05..9820d50c3c 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5703,6 +5703,12 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             dts='234_replace_section_simple.dts')
         self.assertEqual(new_data, data)
 
+    def testMkimageFilename(self):
+        """Test using mkimage to build a binary with a filename"""
+        retcode = self._DoTestFile('235_mkimage_filename.dts')
+        self.assertEqual(0, retcode)
+        fname = tools.get_output_filename('mkimage-test.bin')
+        self.assertTrue(os.path.exists(fname))
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/235_mkimage_filename.dts b/tools/binman/test/235_mkimage_filename.dts
new file mode 100644
index 0000000000..b6f28eb9ab
--- /dev/null
+++ b/tools/binman/test/235_mkimage_filename.dts
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		size = <0x80>;
+
+		mkimage {
+			filename = "mkimage-test.bin";
+			args = "-n test -T script";
+
+			u-boot-spl {
+			};
+
+			_testing {
+				return-contents-later;
+			};
+		};
+	};
+};
-- 
2.37.1



More information about the U-Boot mailing list