~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 96778fce87f4c2a18552107bbd234a9464467c09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# SPDX-License-Identifier: GPL-2.0+
# Copyright 2022 Google LLC
#
"""Bintool implementation for ifwitool

ifwitool provides a way to package firmware in an Intel Firmware Image (IFWI)
file on some Intel SoCs, e.g. Apolo Lake.

Documentation is not really available so far as I can tell

Source code is at tools/ifwitool.c which is a cleaned-up version of
https://github.com/coreboot/coreboot/blob/master/util/cbfstool/ifwitool.c

Here is the help:

ifwitool: Utility for IFWI manipulation

USAGE:
 /tmp/b/sandbox/tools/ifwitool [-h]
 /tmp/b/sandbox/tools/ifwitool FILE COMMAND [PARAMETERS]

COMMANDs:
 add -f FILE -n NAME [-d -e ENTRY]
 create -f FILE
 delete -n NAME
 extract -f FILE -n NAME [-d -e ENTRY]
 print [-d]
 replace -f FILE -n NAME [-d -e ENTRY]
OPTIONs:
 -f FILE : File to read/write/create/extract
 -d      : Perform directory operation
 -e ENTRY: Name of directory entry to operate on
 -v      : Verbose level
 -h      : Help message
 -n NAME : Name of sub-partition to operate on

NAME should be one of:
SMIP(SMIP)
RBEP(CSE_RBE)
FTPR(CSE_BUP)
UCOD(Microcode)
IBBP(Bootblock)
S_BPDT(S-BPDT)
OBBP(OEM boot block)
NFTP(CSE_MAIN)
ISHP(ISH)
DLMP(CSE_IDLM)
IFP_OVERRIDE(IFP_OVERRIDE)
DEBUG_TOKENS(Debug Tokens)
UFS_PHY(UFS Phy)
UFS_GPP(UFS GPP)
PMCP(PMC firmware)
IUNP(IUNIT)
NVM_CONFIG(NVM Config)
UEP(UEP)
UFS_RATE_B(UFS Rate B Config)
"""

from binman import bintool

class Bintoolifwitool(bintool.Bintool):
    """Handles the 'ifwitool' tool

    This bintool supports running `ifwitool` with some basic parameters as
    neeed by binman. It includes creating a file from a FIT as well as adding,
    replacing, deleting and extracting subparts.

    The tool is built as part of U-Boot, but a binary version can be fetched if
    required.

    ifwitool provides a way to package firmware in an Intel Firmware Image
    (IFWI) file on some Intel SoCs, e.g. Apolo Lake.
    """
    def __init__(self, name):
        super().__init__(name, 'Manipulate Intel IFWI files')

    def create_ifwi(self, intel_fit, ifwi_file):
        """Create a new IFWI file, using an existing Intel FIT binary

        Args:
            intel_fit (str): Filename of exist Intel FIT file
            ifwi_file (str): Output filename to write the new IFWI too

        Returns:
            str: Tool output
        """
        args = [intel_fit, 'create', '-f', ifwi_file]
        return self.run_cmd(*args)

    def delete_subpart(self, ifwi_file, subpart):
        """Delete a subpart within the IFWI file

        Args:
            ifwi_file (str): IFWI filename to update
            subpart (str): Name of subpart to delete, e.g. 'OBBP'

        Returns:
            str: Tool output
        """
        args = [ifwi_file, 'delete', '-n', subpart]
        return self.run_cmd(*args)

    # pylint: disable=R0913
    def add_subpart(self, ifwi_file, subpart, entry_name, infile,
                    replace=False):
        """Add or replace a subpart within the IFWI file

        Args:
            ifwi_file (str): IFWI filename to update
            subpart (str): Name of subpart to add/replace
            entry_nme (str): Name of entry to add/replace
            replace (bool): True to replace the existing entry, False to add a
                new one

        Returns:
            str: Tool output
        """
        args = [
            ifwi_file,
            'replace' if replace else 'add',
            '-n', subpart,
            '-d', '-e', entry_name,
            '-f', infile,
            ]
        return self.run_cmd(*args)

    def extract(self, ifwi_file, subpart, entry_name, outfile):
        """Extract a subpart from the IFWI file

        Args:
            ifwi_file (str): IFWI filename to extract from
            subpart (str): Name of subpart to extract
            entry_nme (str): Name of entry to extract

        Returns:
            str: Tool output
        """
        args = [
            ifwi_file,
            'extract',
            '-n', subpart,
            '-d', '-e', entry_name,
            '-f', outfile,
            ]
        return self.run_cmd(*args)

    def fetch(self, method):
        """Fetch handler for ifwitool

        This installs ifwitool using a binary download.

        Args:
            method (FETCH_...): Method to use

        Returns:
            True if the file was fetched, None if a method other than FETCH_BIN
            was requested

        Raises:
            Valuerror: Fetching could not be completed
        """
        if method != bintool.FETCH_BIN:
            return None
        fname, tmpdir = self.fetch_from_drive(
            '18JDghOxlt2Hcc5jv51O1t6uNVHQ0XKJS')
        return fname, tmpdir