intel_ifwi.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 entry import Entry
  9. from blob import Entry_blob
  10. import fdt_util
  11. import tools
  12. class Entry_intel_ifwi(Entry_blob):
  13. """Entry containing an 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. Entry_blob.__init__(self, 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. Entry_blob.ReadNode(self)
  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.GetData()
  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 contects 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. for entry in self._ifwi_entries.values():
  82. if not entry.ObtainContents():
  83. return False
  84. return self._BuildIfwi()
  85. def ProcessContents(self):
  86. orig_data = self.data
  87. self._BuildIfwi()
  88. same = orig_data == self.data
  89. return same
  90. def _ReadSubnodes(self):
  91. """Read the subnodes to find out what should go in this IFWI"""
  92. for node in self._node.subnodes:
  93. entry = Entry.Create(self.section, node)
  94. entry.ReadNode()
  95. entry._ifwi_replace = fdt_util.GetBool(node, 'ifwi-replace')
  96. entry._ifwi_subpart = fdt_util.GetString(node, 'ifwi-subpart')
  97. entry._ifwi_entry_name = fdt_util.GetString(node, 'ifwi-entry')
  98. self._ifwi_entries[entry._ifwi_subpart] = entry
  99. def WriteSymbols(self, section):
  100. """Write symbol values into binary files for access at run time"""
  101. for entry in self._ifwi_entries.values():
  102. entry.WriteSymbols(self)