fiptool.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright 2022 Google LLC
  3. #
  4. """Bintool implementation for fiptool
  5. fiptool provides a way to package firmware in an ARM Trusted Firmware Firmware
  6. Image Package (ATF FIP) format. It is used with Trusted Firmware A, for example.
  7. Documentation is at:
  8. https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/tools-build.html?highlight=fiptool#building-and-using-the-fip-tool
  9. Source code is at:
  10. https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
  11. Here is the help:
  12. usage: fiptool [--verbose] <command> [<args>]
  13. Global options supported:
  14. --verbose Enable verbose output for all commands.
  15. Commands supported:
  16. info List images contained in FIP.
  17. create Create a new FIP with the given images.
  18. update Update an existing FIP with the given images.
  19. unpack Unpack images from FIP.
  20. remove Remove images from FIP.
  21. version Show fiptool version.
  22. help Show help for given command.
  23. """
  24. from binman import bintool
  25. class Bintoolfiptool(bintool.Bintool):
  26. """Image generation for ARM Trusted Firmware
  27. This bintool supports running `fiptool` with some basic parameters as
  28. neeed by binman.
  29. It also supports build fiptool from source.
  30. fiptool provides a way to package firmware in an ARM Trusted Firmware
  31. Firmware Image Package (ATF FIP) format. It is used with Trusted Firmware A,
  32. for example.
  33. See `TF-A FIP tool documentation`_ for more information.
  34. .. _`TF-A FIP tool documentation`:
  35. https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/tools-build.html?highlight=fiptool#building-and-using-the-fip-tool
  36. """
  37. def __init__(self, name):
  38. super().__init__(name, 'Manipulate ATF FIP files', r'^(.*)$', 'version')
  39. def info(self, fname):
  40. """Get info on a FIP image
  41. Args:
  42. fname (str): Filename to check
  43. Returns:
  44. str: Tool output
  45. """
  46. args = ['info', fname]
  47. return self.run_cmd(*args)
  48. # pylint: disable=R0913
  49. def create_new(self, fname, align, plat_toc_flags, fwu, tb_fw, blob_uuid,
  50. blob_file):
  51. """Create a new FIP
  52. Args:
  53. fname (str): Filename to write to
  54. align (int): Alignment to use for entries
  55. plat_toc_flags (int): Flags to use for the TOC header
  56. fwu (str): Filename for the fwu entry
  57. tb_fw (str): Filename for the tb_fw entry
  58. blob_uuid (str): UUID for the blob entry
  59. blob_file (str): Filename for the blob entry
  60. Returns:
  61. str: Tool output
  62. """
  63. args = [
  64. 'create',
  65. '--align', f'{align:x}',
  66. '--plat-toc-flags', f'{plat_toc_flags:#x}',
  67. '--fwu', fwu,
  68. '--tb-fw', tb_fw,
  69. '--blob', f'uuid={blob_uuid},file={blob_file}',
  70. fname]
  71. return self.run_cmd(*args)
  72. def create_bad(self):
  73. """Run fiptool with invalid arguments"""
  74. args = ['create', '--fred']
  75. return self.run_cmd_result(*args)
  76. def fetch(self, method):
  77. """Fetch handler for fiptool
  78. This builds the tool from source
  79. Returns:
  80. tuple:
  81. str: Filename of fetched file to copy to a suitable directory
  82. str: Name of temp directory to remove, or None
  83. """
  84. if method != bintool.FETCH_BUILD:
  85. return None
  86. result = self.build_from_git(
  87. 'https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git',
  88. 'fiptool',
  89. 'tools/fiptool/fiptool')
  90. return result