binman: Allow the image name to be the data file
Some image types use the -n parameter to pass in the data file. Add support for this, with a new property. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -1167,6 +1167,8 @@ Entry: mkimage: Binary produced by mkimage
|
|||||||
|
|
||||||
Properties / Entry arguments:
|
Properties / Entry arguments:
|
||||||
- args: Arguments to pass
|
- args: Arguments to pass
|
||||||
|
- data-to-imagename: Indicates that the -d data should be passed in as
|
||||||
|
the image name also (-n)
|
||||||
|
|
||||||
The data passed to mkimage via the -d flag is collected from subnodes of the
|
The data passed to mkimage via the -d flag is collected from subnodes of the
|
||||||
mkimage node, e.g.::
|
mkimage node, e.g.::
|
||||||
@@ -1207,6 +1209,19 @@ this example which also produces four arguments::
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
If you need to pass the input data in with the -n argument as well, then use
|
||||||
|
the 'data-to-imagename' property::
|
||||||
|
|
||||||
|
mkimage {
|
||||||
|
args = "-T imximage";
|
||||||
|
data-to-imagename';
|
||||||
|
|
||||||
|
u-boot-spl {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
That will pass the data to mkimage both as the data file (with -d) and as
|
||||||
|
the image name (with -n).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,6 +16,8 @@ class Entry_mkimage(Entry):
|
|||||||
|
|
||||||
Properties / Entry arguments:
|
Properties / Entry arguments:
|
||||||
- args: Arguments to pass
|
- args: Arguments to pass
|
||||||
|
- data-to-imagename: Indicates that the -d data should be passed in as
|
||||||
|
the image name also (-n)
|
||||||
|
|
||||||
The data passed to mkimage via the -d flag is collected from subnodes of the
|
The data passed to mkimage via the -d flag is collected from subnodes of the
|
||||||
mkimage node, e.g.::
|
mkimage node, e.g.::
|
||||||
@@ -59,6 +61,20 @@ class Entry_mkimage(Entry):
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
If you need to pass the input data in with the -n argument as well, then use
|
||||||
|
the 'data-to-imagename' property::
|
||||||
|
|
||||||
|
mkimage {
|
||||||
|
args = "-T imximage";
|
||||||
|
data-to-imagename;
|
||||||
|
|
||||||
|
u-boot-spl {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
That will pass the data to mkimage both as the data file (with -d) and as
|
||||||
|
the image name (with -n). In both cases, a filename is passed as the
|
||||||
|
argument, with the actual data being in that file.
|
||||||
"""
|
"""
|
||||||
def __init__(self, section, etype, node):
|
def __init__(self, section, etype, node):
|
||||||
super().__init__(section, etype, node)
|
super().__init__(section, etype, node)
|
||||||
@@ -68,6 +84,8 @@ class Entry_mkimage(Entry):
|
|||||||
def ReadNode(self):
|
def ReadNode(self):
|
||||||
super().ReadNode()
|
super().ReadNode()
|
||||||
self._args = fdt_util.GetArgs(self._node, 'args')
|
self._args = fdt_util.GetArgs(self._node, 'args')
|
||||||
|
self._data_to_imagename = fdt_util.GetBool(self._node,
|
||||||
|
'data-to-imagename')
|
||||||
self.ReadEntries()
|
self.ReadEntries()
|
||||||
|
|
||||||
def ReadEntries(self):
|
def ReadEntries(self):
|
||||||
@@ -79,13 +97,18 @@ class Entry_mkimage(Entry):
|
|||||||
|
|
||||||
def ObtainContents(self):
|
def ObtainContents(self):
|
||||||
# Use a non-zero size for any fake files to keep mkimage happy
|
# Use a non-zero size for any fake files to keep mkimage happy
|
||||||
|
# Note that testMkimageImagename() relies on this 'mkimage' parameter
|
||||||
data, input_fname, uniq = self.collect_contents_to_file(
|
data, input_fname, uniq = self.collect_contents_to_file(
|
||||||
self._mkimage_entries.values(), 'mkimage', 1024)
|
self._mkimage_entries.values(), 'mkimage', 1024)
|
||||||
if data is None:
|
if data is None:
|
||||||
return False
|
return False
|
||||||
output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
|
output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
|
||||||
if self.mkimage.run_cmd('-d', input_fname, *self._args,
|
|
||||||
output_fname) is not None:
|
args = ['-d', input_fname]
|
||||||
|
if self._data_to_imagename:
|
||||||
|
args += ['-n', input_fname]
|
||||||
|
args += self._args + [output_fname]
|
||||||
|
if self.mkimage.run_cmd(*args) is not None:
|
||||||
self.SetContents(tools.read_file(output_fname))
|
self.SetContents(tools.read_file(output_fname))
|
||||||
else:
|
else:
|
||||||
# Bintool is missing; just use the input data as the output
|
# Bintool is missing; just use the input data as the output
|
||||||
|
@@ -5722,6 +5722,23 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
|
|||||||
"Node '/section': Replacing sections is not implemented yet",
|
"Node '/section': Replacing sections is not implemented yet",
|
||||||
str(exc.exception))
|
str(exc.exception))
|
||||||
|
|
||||||
|
def testMkimageImagename(self):
|
||||||
|
"""Test using mkimage with -n holding the data too"""
|
||||||
|
data = self._DoReadFile('235_mkimage_name.dts')
|
||||||
|
|
||||||
|
# Check that the data appears in the file somewhere
|
||||||
|
self.assertIn(U_BOOT_SPL_DATA, data)
|
||||||
|
|
||||||
|
# Get struct image_header -> ih_name
|
||||||
|
name = data[0x20:0x40]
|
||||||
|
|
||||||
|
# Build the filename that we expect to be placed in there, by virtue of
|
||||||
|
# the -n paraameter
|
||||||
|
expect = os.path.join(tools.get_output_dir(), 'mkimage.mkimage')
|
||||||
|
|
||||||
|
# Check that the image name is set to the temporary filename used
|
||||||
|
self.assertEqual(expect.encode('utf-8')[:0x20], name)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
18
tools/binman/test/235_mkimage_name.dts
Normal file
18
tools/binman/test/235_mkimage_name.dts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
|
||||||
|
binman {
|
||||||
|
mkimage {
|
||||||
|
args = "-T script";
|
||||||
|
data-to-imagename;
|
||||||
|
|
||||||
|
u-boot-spl {
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
Reference in New Issue
Block a user