mkimage.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2016 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Entry-type module for producing an image using mkimage
  6. #
  7. from collections import OrderedDict
  8. from binman.entry import Entry
  9. from dtoc import fdt_util
  10. from patman import tools
  11. class Entry_mkimage(Entry):
  12. """Entry containing a binary produced by mkimage
  13. Properties / Entry arguments:
  14. - datafile: Filename for -d argument
  15. - args: Other arguments to pass
  16. The data passed to mkimage is collected from subnodes of the mkimage node,
  17. e.g.::
  18. mkimage {
  19. args = "-n test -T imximage";
  20. u-boot-spl {
  21. };
  22. };
  23. This calls mkimage to create an imximage with u-boot-spl.bin as the input
  24. file. The output from mkimage then becomes part of the image produced by
  25. binman.
  26. """
  27. def __init__(self, section, etype, node):
  28. super().__init__(section, etype, node)
  29. self._args = fdt_util.GetString(self._node, 'args').split(' ')
  30. self._mkimage_entries = OrderedDict()
  31. self._ReadSubnodes()
  32. def ObtainContents(self):
  33. data = b''
  34. for entry in self._mkimage_entries.values():
  35. # First get the input data and put it in a file. If not available,
  36. # try later.
  37. if not entry.ObtainContents():
  38. return False
  39. data += entry.GetData()
  40. uniq = self.GetUniqueName()
  41. input_fname = tools.GetOutputFilename('mkimage.%s' % uniq)
  42. tools.WriteFile(input_fname, data)
  43. output_fname = tools.GetOutputFilename('mkimage-out.%s' % uniq)
  44. tools.Run('mkimage', '-d', input_fname, *self._args, output_fname)
  45. self.SetContents(tools.ReadFile(output_fname))
  46. return True
  47. def _ReadSubnodes(self):
  48. """Read the subnodes to find out what should go in this image"""
  49. for node in self._node.subnodes:
  50. entry = Entry.Create(self, node)
  51. entry.ReadNode()
  52. self._mkimage_entries[entry.name] = entry