mkimage.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright 2022 Google LLC
  3. #
  4. """Bintool implementation for mkimage"""
  5. import re
  6. from binman import bintool
  7. class Bintoolmkimage(bintool.Bintool):
  8. """Image generation for U-Boot
  9. This bintool supports running `mkimage` with some basic parameters as
  10. neeed by binman.
  11. Normally binman uses the mkimage built by U-Boot. But when run outside the
  12. U-Boot build system, binman can use the version installed in your system.
  13. Support is provided for fetching this on Debian-like systems, using apt.
  14. """
  15. def __init__(self, name):
  16. super().__init__(name, 'Generate image for U-Boot', r'mkimage version (.*)')
  17. # pylint: disable=R0913
  18. def run(self, reset_timestamp=False, output_fname=None, external=False,
  19. pad=None, align=None):
  20. """Run mkimage
  21. Args:
  22. reset_timestamp: True to update the timestamp in the FIT
  23. output_fname: Output filename to write to
  24. external: True to create an 'external' FIT, where the binaries are
  25. located outside the main data structure
  26. pad: Bytes to use for padding the FIT devicetree output. This allows
  27. other things to be easily added later, if required, such as
  28. signatures
  29. align: Bytes to use for alignment of the FIT and its external data
  30. version: True to get the mkimage version
  31. """
  32. args = []
  33. if external:
  34. args.append('-E')
  35. if pad:
  36. args += ['-p', f'{pad:x}']
  37. if align:
  38. args += ['-B', f'{align:x}']
  39. if reset_timestamp:
  40. args.append('-t')
  41. if output_fname:
  42. args += ['-F', output_fname]
  43. return self.run_cmd(*args)
  44. def fetch(self, method):
  45. """Fetch handler for mkimage
  46. This installs mkimage using the apt utility.
  47. Args:
  48. method (FETCH_...): Method to use
  49. Returns:
  50. True if the file was fetched and now installed, None if a method
  51. other than FETCH_BIN was requested
  52. Raises:
  53. Valuerror: Fetching could not be completed
  54. """
  55. if method != bintool.FETCH_BIN:
  56. return None
  57. return self.apt_install('u-boot-tools')