mkimage.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. """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.align_default = None
  32. self._ReadSubnodes()
  33. def ObtainContents(self):
  34. data = b''
  35. for entry in self._mkimage_entries.values():
  36. # First get the input data and put it in a file. If not available,
  37. # try later.
  38. if not entry.ObtainContents():
  39. return False
  40. data += entry.GetData()
  41. uniq = self.GetUniqueName()
  42. input_fname = tools.GetOutputFilename('mkimage.%s' % uniq)
  43. tools.WriteFile(input_fname, data)
  44. output_fname = tools.GetOutputFilename('mkimage-out.%s' % uniq)
  45. tools.Run('mkimage', '-d', input_fname, *self._args, output_fname)
  46. self.SetContents(tools.ReadFile(output_fname))
  47. return True
  48. def _ReadSubnodes(self):
  49. """Read the subnodes to find out what should go in this image"""
  50. for node in self._node.subnodes:
  51. entry = Entry.Create(self, node)
  52. entry.ReadNode()
  53. self._mkimage_entries[entry.name] = entry