intel_ifwi.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Intel Management Engine binary blob
  6. #
  7. from collections import OrderedDict
  8. from binman.entry import Entry
  9. from binman.etype.blob_ext import Entry_blob_ext
  10. from dtoc import fdt_util
  11. from patman import tools
  12. class Entry_intel_ifwi(Entry_blob_ext):
  13. """Intel Integrated Firmware Image (IFWI) file
  14. Properties / Entry arguments:
  15. - filename: Filename of file to read into entry. This is either the
  16. IFWI file itself, or a file that can be converted into one using a
  17. tool
  18. - convert-fit: If present this indicates that the ifwitool should be
  19. used to convert the provided file into a IFWI.
  20. This file contains code and data used by the SoC that is required to make
  21. it work. It includes U-Boot TPL, microcode, things related to the CSE
  22. (Converged Security Engine, the microcontroller that loads all the firmware)
  23. and other items beyond the wit of man.
  24. A typical filename is 'ifwi.bin' for an IFWI file, or 'fitimage.bin' for a
  25. file that will be converted to an IFWI.
  26. The position of this entry is generally set by the intel-descriptor entry.
  27. The contents of the IFWI are specified by the subnodes of the IFWI node.
  28. Each subnode describes an entry which is placed into the IFWFI with a given
  29. sub-partition (and optional entry name).
  30. Properties for subnodes:
  31. - ifwi-subpart: sub-parition to put this entry into, e.g. "IBBP"
  32. - ifwi-entry: entry name t use, e.g. "IBBL"
  33. - ifwi-replace: if present, indicates that the item should be replaced
  34. in the IFWI. Otherwise it is added.
  35. See README.x86 for information about x86 binary blobs.
  36. """
  37. def __init__(self, section, etype, node):
  38. super().__init__(section, etype, node)
  39. self._convert_fit = fdt_util.GetBool(self._node, 'convert-fit')
  40. self._ifwi_entries = OrderedDict()
  41. def ReadNode(self):
  42. self._ReadSubnodes()
  43. super().ReadNode()
  44. def _BuildIfwi(self):
  45. """Build the contents of the IFWI and write it to the 'data' property"""
  46. # Create the IFWI file if needed
  47. if self._convert_fit:
  48. inname = self._pathname
  49. outname = tools.GetOutputFilename('ifwi.bin')
  50. tools.RunIfwiTool(inname, tools.CMD_CREATE, outname)
  51. self._filename = 'ifwi.bin'
  52. self._pathname = outname
  53. else:
  54. # Provide a different code path here to ensure we have test coverage
  55. outname = self._pathname
  56. # Delete OBBP if it is there, then add the required new items.
  57. tools.RunIfwiTool(outname, tools.CMD_DELETE, subpart='OBBP')
  58. for entry in self._ifwi_entries.values():
  59. # First get the input data and put it in a file
  60. data = entry.GetPaddedData()
  61. uniq = self.GetUniqueName()
  62. input_fname = tools.GetOutputFilename('input.%s' % uniq)
  63. tools.WriteFile(input_fname, data)
  64. tools.RunIfwiTool(outname,
  65. tools.CMD_REPLACE if entry._ifwi_replace else tools.CMD_ADD,
  66. input_fname, entry._ifwi_subpart, entry._ifwi_entry_name)
  67. self.ReadBlobContents()
  68. return True
  69. def ObtainContents(self):
  70. """Get the contents for the IFWI
  71. Unfortunately we cannot create anything from scratch here, as Intel has
  72. tools which create precursor binaries with lots of data and settings,
  73. and these are not incorporated into binman.
  74. The first step is to get a file in the IFWI format. This is either
  75. supplied directly or is extracted from a fitimage using the 'create'
  76. subcommand.
  77. After that we delete the OBBP sub-partition and add each of the files
  78. that we want in the IFWI file, one for each sub-entry of the IWFI node.
  79. """
  80. self._pathname = tools.GetInputFilename(self._filename,
  81. self.section.GetAllowMissing())
  82. # Allow the file to be missing
  83. if not self._pathname:
  84. self.SetContents(b'')
  85. self.missing = True
  86. return True
  87. for entry in self._ifwi_entries.values():
  88. if not entry.ObtainContents():
  89. return False
  90. return self._BuildIfwi()
  91. def ProcessContents(self):
  92. if self.missing:
  93. return True
  94. orig_data = self.data
  95. self._BuildIfwi()
  96. same = orig_data == self.data
  97. return same
  98. def _ReadSubnodes(self):
  99. """Read the subnodes to find out what should go in this IFWI"""
  100. for node in self._node.subnodes:
  101. entry = Entry.Create(self.section, node)
  102. entry.ReadNode()
  103. entry._ifwi_replace = fdt_util.GetBool(node, 'ifwi-replace')
  104. entry._ifwi_subpart = fdt_util.GetString(node, 'ifwi-subpart')
  105. entry._ifwi_entry_name = fdt_util.GetString(node, 'ifwi-entry')
  106. self._ifwi_entries[entry._ifwi_subpart] = entry
  107. def WriteSymbols(self, section):
  108. """Write symbol values into binary files for access at run time"""
  109. if not self.missing:
  110. for entry in self._ifwi_entries.values():
  111. entry.WriteSymbols(self)