1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright 2022 Google LLC
4 """Bintool implementation for ifwitool
6 ifwitool provides a way to package firmware in an Intel Firmware Image (IFWI)
7 file on some Intel SoCs, e.g. Apolo Lake.
9 Documentation is not really available so far as I can tell
11 Source code is at tools/ifwitool.c which is a cleaned-up version of
12 https://github.com/coreboot/coreboot/blob/master/util/cbfstool/ifwitool.c
16 ifwitool: Utility for IFWI manipulation
19 /tmp/b/sandbox/tools/ifwitool [-h]
20 /tmp/b/sandbox/tools/ifwitool FILE COMMAND [PARAMETERS]
23 add -f FILE -n NAME [-d -e ENTRY]
26 extract -f FILE -n NAME [-d -e ENTRY]
28 replace -f FILE -n NAME [-d -e ENTRY]
30 -f FILE : File to read/write/create/extract
31 -d : Perform directory operation
32 -e ENTRY: Name of directory entry to operate on
35 -n NAME : Name of sub-partition to operate on
37 NAME should be one of:
48 IFP_OVERRIDE(IFP_OVERRIDE)
49 DEBUG_TOKENS(Debug Tokens)
54 NVM_CONFIG(NVM Config)
56 UFS_RATE_B(UFS Rate B Config)
59 from binman import bintool
61 class Bintoolifwitool(bintool.Bintool):
62 """Handles the 'ifwitool' tool
64 This bintool supports running `ifwitool` with some basic parameters as
65 neeed by binman. It includes creating a file from a FIT as well as adding,
66 replacing, deleting and extracting subparts.
68 The tool is built as part of U-Boot, but a binary version can be fetched if
71 ifwitool provides a way to package firmware in an Intel Firmware Image
72 (IFWI) file on some Intel SoCs, e.g. Apolo Lake.
74 def __init__(self, name):
75 super().__init__(name, 'Manipulate Intel IFWI files')
77 def create_ifwi(self, intel_fit, ifwi_file):
78 """Create a new IFWI file, using an existing Intel FIT binary
81 intel_fit (str): Filename of exist Intel FIT file
82 ifwi_file (str): Output filename to write the new IFWI too
87 args = [intel_fit, 'create', '-f', ifwi_file]
88 return self.run_cmd(*args)
90 def delete_subpart(self, ifwi_file, subpart):
91 """Delete a subpart within the IFWI file
94 ifwi_file (str): IFWI filename to update
95 subpart (str): Name of subpart to delete, e.g. 'OBBP'
100 args = [ifwi_file, 'delete', '-n', subpart]
101 return self.run_cmd(*args)
103 # pylint: disable=R0913
104 def add_subpart(self, ifwi_file, subpart, entry_name, infile,
106 """Add or replace a subpart within the IFWI file
109 ifwi_file (str): IFWI filename to update
110 subpart (str): Name of subpart to add/replace
111 entry_nme (str): Name of entry to add/replace
112 replace (bool): True to replace the existing entry, False to add a
120 'replace' if replace else 'add',
122 '-d', '-e', entry_name,
125 return self.run_cmd(*args)
127 def extract(self, ifwi_file, subpart, entry_name, outfile):
128 """Extract a subpart from the IFWI file
131 ifwi_file (str): IFWI filename to extract from
132 subpart (str): Name of subpart to extract
133 entry_nme (str): Name of entry to extract
142 '-d', '-e', entry_name,
145 return self.run_cmd(*args)
147 def fetch(self, method):
148 """Fetch handler for ifwitool
150 This installs ifwitool using a binary download.
153 method (FETCH_...): Method to use
156 True if the file was fetched, None if a method other than FETCH_BIN
160 Valuerror: Fetching could not be completed
162 if method != bintool.FETCH_BIN:
164 fname, tmpdir = self.fetch_from_drive(
165 '18JDghOxlt2Hcc5jv51O1t6uNVHQ0XKJS')