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