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.
+
+ If need to pass different data in with -n, then use an `imagename` subnode::
+
+ mkimage {
+ args = "-T imximage";
+
+ imagename {
+ blob {
+ filename = "spl/u-boot-spl.cfgout"
+ };
+ };
+
+ u-boot-spl {
+ };
+ };
+
+ This will pass in u-boot-spl as the input data and the .cfgout file as the
+ -n data.
"""
def __init__(self, section, etype, node):
super().__init__(section, etype, node)
self._mkimage_entries = OrderedDict()
+ self._imagename = None
self.align_default = None
def ReadNode(self):
self._args = fdt_util.GetArgs(self._node, 'args')
self._data_to_imagename = fdt_util.GetBool(self._node,
'data-to-imagename')
+ if self._data_to_imagename and self._node.FindNode('imagename'):
+ self.Raise('Cannot use both imagename node and data-to-imagename')
self.ReadEntries()
def ReadEntries(self):
for node in self._node.subnodes:
entry = Entry.Create(self, node)
entry.ReadNode()
- self._mkimage_entries[entry.name] = entry
+ if entry.name == 'imagename':
+ self._imagename = entry
+ else:
+ self._mkimage_entries[entry.name] = entry
def ObtainContents(self):
# Use a non-zero size for any fake files to keep mkimage happy
self._mkimage_entries.values(), 'mkimage', 1024)
if data is None:
return False
+ if self._imagename:
+ image_data, imagename_fname, _ = self.collect_contents_to_file(
+ [self._imagename], 'mkimage-n', 1024)
+ if image_data is None:
+ return False
output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
args = ['-d', input_fname]
if self._data_to_imagename:
args += ['-n', input_fname]
+ elif self._imagename:
+ args += ['-n', imagename_fname]
args += self._args + [output_fname]
if self.mkimage.run_cmd(*args) is not None:
self.SetContents(tools.read_file(output_fname))
self.allow_missing = allow_missing
for entry in self._mkimage_entries.values():
entry.SetAllowMissing(allow_missing)
+ if self._imagename:
+ self._imagename.SetAllowMissing(allow_missing)
def SetAllowFakeBlob(self, allow_fake):
"""Set whether the sub nodes allows to create a fake blob
"""
for entry in self._mkimage_entries.values():
entry.SetAllowFakeBlob(allow_fake)
+ if self._imagename:
+ self._imagename.SetAllowFakeBlob(allow_fake)
def CheckFakedBlobs(self, faked_blobs_list):
"""Check if any entries in this section have faked external blobs
"""
for entry in self._mkimage_entries.values():
entry.CheckFakedBlobs(faked_blobs_list)
+ if self._imagename:
+ self._imagename.CheckFakedBlobs(faked_blobs_list)
def AddBintools(self, btools):
self.mkimage = self.AddBintool(btools, 'mkimage')
# Check that the image name is set to the temporary filename used
self.assertEqual(expect.encode('utf-8')[:0x20], name)
+ def testMkimageImage(self):
+ """Test using mkimage with -n holding the data too"""
+ data = self._DoReadFile('236_mkimage_image.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-n.mkimage')
+
+ # Check that the image name is set to the temporary filename used
+ self.assertEqual(expect.encode('utf-8')[:0x20], name)
+
+ # Check the corect data is in the imagename file
+ self.assertEqual(U_BOOT_DATA, tools.read_file(expect))
+
+ def testMkimageImageNoContent(self):
+ """Test using mkimage with -n and no data"""
+ with self.assertRaises(ValueError) as exc:
+ self._DoReadFile('237_mkimage_image_no_content.dts')
+ self.assertIn('Could not complete processing of contents',
+ str(exc.exception))
+
+ def testMkimageImageBad(self):
+ """Test using mkimage with imagename node and data-to-imagename"""
+ with self.assertRaises(ValueError) as exc:
+ self._DoReadFile('238_mkimage_image_bad.dts')
+ self.assertIn('Cannot use both imagename node and data-to-imagename',
+ str(exc.exception))
+
if __name__ == "__main__":
unittest.main()