]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: allow user-defined filenames for mkimage entry
authorQuentin Schulz <quentin.schulz@theobroma-systems.com>
Fri, 2 Sep 2022 13:10:49 +0000 (15:10 +0200)
committerKever Yang <kever.yang@rock-chips.com>
Sun, 4 Sep 2022 12:00:39 +0000 (20:00 +0800)
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@0leil.net>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/binman/etype/mkimage.py
tools/binman/ftest.py
tools/binman/test/254_mkimage_filename.dts [new file with mode: 0644]

index 5f4bc6fa3cc8ec321ce1476fc215713c701f6bab..c2288c48eef3d01d82b6e3e741a7953653a0724e 100644 (file)
@@ -21,11 +21,13 @@ class Entry_mkimage(Entry):
         - multiple-data-files: boolean to tell binman to pass all files as
           datafiles to mkimage instead of creating a temporary file the result
           of datafiles concatenation
+        - filename: filename of output binary generated by mkimage
 
     The data passed to mkimage via the -d flag is collected from subnodes of the
     mkimage node, e.g.::
 
         mkimage {
+            filename = "imximage.bin";
             args = "-n test -T imximage";
 
             u-boot-spl {
@@ -38,8 +40,9 @@ class Entry_mkimage(Entry):
         mkimage -d <data_file> -n test -T imximage <output_file>
 
     The output from mkimage then becomes part of the image produced by
-    binman. If you need to put multiple things in the data file, you can use
-    a section, or just multiple subnodes like this::
+    binman but also is written into `imximage.bin` file. If you need to put
+    multiple things in the data file, you can use a section, or just multiple
+    subnodes like this::
 
         mkimage {
             args = "-n test -T imximage";
@@ -121,6 +124,7 @@ class Entry_mkimage(Entry):
         self._multiple_data_files = fdt_util.GetBool(self._node, 'multiple-data-files')
         self._mkimage_entries = OrderedDict()
         self._imagename = None
+        self._filename = fdt_util.GetString(self._node, 'filename')
         self.align_default = None
 
     def ReadNode(self):
@@ -164,7 +168,8 @@ class Entry_mkimage(Entry):
                 [self._imagename], 'mkimage-n', 1024)
             if image_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)
 
         args = ['-d', input_fname]
         if self._data_to_imagename:
index e0850b760bdb97bf83134a0e6c3ad0c5bab0311e..3ced14b7e981187a69c717be1e29b71241a438e7 100644 (file)
@@ -5921,6 +5921,13 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertIn('Could not complete processing of contents',
                       str(exc.exception))
 
+    def testMkimageFilename(self):
+        """Test using mkimage to build a binary with a filename"""
+        retcode = self._DoTestFile('254_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/254_mkimage_filename.dts b/tools/binman/test/254_mkimage_filename.dts
new file mode 100644 (file)
index 0000000..4483790
--- /dev/null
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               mkimage {
+                       filename = "mkimage-test.bin";
+                       args = "-T script";
+
+                       u-boot-spl {
+                       };
+               };
+       };
+};