blob: d40e60d2377a0102578895a0d4af649a2cf4139e [file] [log] [blame]
Zheng Baoc5e28ab2020-10-28 11:38:09 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#ifndef _AMD_FW_TOOL_H_
4#define _AMD_FW_TOOL_H_
5
Zheng Bao6be1ab62021-05-26 10:16:33 +08006#include <stdint.h>
Zheng Baoba3af5e2021-11-04 18:56:47 +08007#include <stdbool.h>
Zheng Bao6be1ab62021-05-26 10:16:33 +08008
Zheng Baoc5e28ab2020-10-28 11:38:09 +08009typedef enum _amd_fw_type {
10 AMD_FW_PSP_PUBKEY = 0,
11 AMD_FW_PSP_BOOTLOADER = 1,
12 AMD_FW_PSP_SMU_FIRMWARE = 8,
13 AMD_FW_PSP_RECOVERY = 3,
14 AMD_FW_PSP_RTM_PUBKEY = 5,
15 AMD_FW_PSP_SECURED_OS = 2,
16 AMD_FW_PSP_NVRAM = 4,
17 AMD_FW_PSP_SECURED_DEBUG = 9,
18 AMD_FW_PSP_TRUSTLETS = 12,
19 AMD_FW_PSP_TRUSTLETKEY = 13,
20 AMD_FW_PSP_SMU_FIRMWARE2 = 18,
21 AMD_PSP_FUSE_CHAIN = 11,
22 AMD_FW_PSP_SMUSCS = 95,
23 AMD_DEBUG_UNLOCK = 0x13,
Zheng Baobf29a0d2020-12-03 23:00:48 +080024 AMD_HW_IPCFG = 0x20,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080025 AMD_WRAPPED_IKEK = 0x21,
26 AMD_TOKEN_UNLOCK = 0x22,
27 AMD_SEC_GASKET = 0x24,
28 AMD_MP2_FW = 0x25,
29 AMD_DRIVER_ENTRIES = 0x28,
Zheng Baobf29a0d2020-12-03 23:00:48 +080030 AMD_FW_KVM_IMAGE = 0x29,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080031 AMD_S0I3_DRIVER = 0x2d,
32 AMD_ABL0 = 0x30,
33 AMD_ABL1 = 0x31,
34 AMD_ABL2 = 0x32,
35 AMD_ABL3 = 0x33,
36 AMD_ABL4 = 0x34,
37 AMD_ABL5 = 0x35,
38 AMD_ABL6 = 0x36,
39 AMD_ABL7 = 0x37,
40 AMD_FW_PSP_WHITELIST = 0x3a,
Zheng Baobf29a0d2020-12-03 23:00:48 +080041 AMD_VBIOS_BTLOADER = 0x3c,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080042 AMD_FW_L2_PTR = 0x40,
Zheng Baobf29a0d2020-12-03 23:00:48 +080043 AMD_FW_USB_PHY = 0x44,
44 AMD_FW_TOS_SEC_POLICY = 0x45,
45 AMD_FW_DRTM_TA = 0x47,
Zheng Bao990d1542021-09-17 13:24:54 +080046 AMD_FW_RECOVERYAB_A = 0x48,
47 AMD_FW_RECOVERYAB_B = 0x4A,
48 AMD_FW_BIOS_TABLE = 0x49,
Zheng Baobf29a0d2020-12-03 23:00:48 +080049 AMD_FW_KEYDB_BL = 0x50,
50 AMD_FW_KEYDB_TOS = 0x51,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080051 AMD_FW_PSP_VERSTAGE = 0x52,
52 AMD_FW_VERSTAGE_SIG = 0x53,
Zheng Baobf29a0d2020-12-03 23:00:48 +080053 AMD_RPMC_NVRAM = 0x54,
Zheng Baoab84fd72022-01-27 22:38:27 +080054 AMD_FW_SPL = 0x55,
Zheng Baobf29a0d2020-12-03 23:00:48 +080055 AMD_FW_DMCU_ERAM = 0x58,
56 AMD_FW_DMCU_ISR = 0x59,
Felix Held5f18bb72022-03-24 02:04:51 +010057 AMD_FW_MSMU = 0x5a,
58 AMD_FW_SPIROM_CFG = 0x5c,
59 AMD_FW_DMCUB = 0x71,
Zheng Baob993cb22021-02-02 18:48:23 +080060 AMD_FW_PSP_BOOTLOADER_AB = 0x73,
Karthikeyan Ramasubramanian0ab04d22022-05-03 18:16:34 -060061 AMD_TA_IKEK = 0x8d,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080062 AMD_FW_IMC = 0x200, /* Large enough to be larger than the top BHD entry type. */
63 AMD_FW_GEC,
64 AMD_FW_XHCI,
65 AMD_FW_INVALID, /* Real last one to detect the last entry in table. */
66 AMD_FW_SKIP /* This is for non-applicable options. */
67} amd_fw_type;
68
69typedef enum _amd_bios_type {
Zheng Baobf29a0d2020-12-03 23:00:48 +080070 AMD_BIOS_RTM_PUBKEY = 5,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080071 AMD_BIOS_APCB = 0x60,
72 AMD_BIOS_APOB = 0x61,
73 AMD_BIOS_BIN = 0x62,
74 AMD_BIOS_APOB_NV = 0x63,
75 AMD_BIOS_PMUI = 0x64,
76 AMD_BIOS_PMUD = 0x65,
77 AMD_BIOS_UCODE = 0x66,
78 AMD_BIOS_APCB_BK = 0x68,
79 AMD_BIOS_MP2_CFG = 0x6a,
80 AMD_BIOS_PSP_SHARED_MEM = 0x6b,
81 AMD_BIOS_L2_PTR = 0x70,
82 AMD_BIOS_INVALID,
83 AMD_BIOS_SKIP
84} amd_bios_type;
85
Robert Zieba29bc79f2022-03-14 15:59:12 -060086typedef enum _amd_addr_mode {
87 AMD_ADDR_PHYSICAL = 0, /* Physical address */
88 AMD_ADDR_REL_BIOS, /* Relative to beginning of image */
89 AMD_ADDR_REL_TAB, /* Relative to table */
90 AMD_ADDR_REL_SLOT, /* Relative to slot */
91} amd_addr_mode;
92
Zheng Bao6be1ab62021-05-26 10:16:33 +080093struct second_gen_efs { /* todo: expand for Server products */
94 int gen:1; /* Client products only use bit 0 */
95 int reserved:31;
96} __attribute__((packed));
97
98#define EFS_SECOND_GEN 0
Zheng Bao487d0452022-04-03 12:50:07 +080099#define EFS_BEFORE_SECOND_GEN 1
Zheng Bao6be1ab62021-05-26 10:16:33 +0800100
101typedef struct _embedded_firmware {
102 uint32_t signature; /* 0x55aa55aa */
103 uint32_t imc_entry;
104 uint32_t gec_entry;
105 uint32_t xhci_entry;
Felix Heldad68b072021-10-18 14:00:35 +0200106 uint32_t psp_directory;
Zheng Baob749d3f2021-10-23 20:20:21 +0800107 union {
108 uint32_t new_psp_directory;
109 uint32_t combo_psp_directory;
110 };
Zheng Bao6be1ab62021-05-26 10:16:33 +0800111 uint32_t bios0_entry; /* todo: add way to select correct entry */
112 uint32_t bios1_entry;
113 uint32_t bios2_entry;
114 struct second_gen_efs efs_gen;
115 uint32_t bios3_entry;
116 uint32_t reserved_2Ch;
117 uint32_t promontory_fw_ptr;
118 uint32_t lp_promontory_fw_ptr;
119 uint32_t reserved_38h;
120 uint32_t reserved_3Ch;
121 uint8_t spi_readmode_f15_mod_60_6f;
122 uint8_t fast_speed_new_f15_mod_60_6f;
123 uint8_t reserved_42h;
124 uint8_t spi_readmode_f17_mod_00_2f;
125 uint8_t spi_fastspeed_f17_mod_00_2f;
126 uint8_t qpr_dummy_cycle_f17_mod_00_2f;
127 uint8_t reserved_46h;
128 uint8_t spi_readmode_f17_mod_30_3f;
129 uint8_t spi_fastspeed_f17_mod_30_3f;
130 uint8_t micron_detect_f17_mod_30_3f;
131 uint8_t reserved_4Ah;
132 uint8_t reserved_4Bh;
133 uint32_t reserved_4Ch;
134} __attribute__((packed, aligned(16))) embedded_firmware;
135
136typedef struct _psp_directory_header {
137 uint32_t cookie;
138 uint32_t checksum;
139 uint32_t num_entries;
Zheng Bao6fff2492021-11-15 19:53:21 +0800140 union {
141 uint32_t additional_info;
142 struct {
143 uint32_t dir_size:10;
144 uint32_t spi_block_size:4;
145 uint32_t base_addr:15;
146 uint32_t address_mode:2;
147 uint32_t not_used:1;
148 } __attribute__((packed)) additional_info_fields;
149 };
Zheng Bao6be1ab62021-05-26 10:16:33 +0800150} __attribute__((packed, aligned(16))) psp_directory_header;
151
152typedef struct _psp_directory_entry {
153 uint8_t type;
154 uint8_t subprog;
155 uint16_t rsvd;
156 uint32_t size;
Zheng Bao6fff2492021-11-15 19:53:21 +0800157 uint64_t addr:62; /* or a value in some cases */
158 uint64_t address_mode:2;
Zheng Bao6be1ab62021-05-26 10:16:33 +0800159} __attribute__((packed)) psp_directory_entry;
160
161typedef struct _psp_directory_table {
162 psp_directory_header header;
163 psp_directory_entry entries[];
164} __attribute__((packed, aligned(16))) psp_directory_table;
165
166#define MAX_PSP_ENTRIES 0x1f
167
168typedef struct _psp_combo_header {
169 uint32_t cookie;
170 uint32_t checksum;
171 uint32_t num_entries;
172 uint32_t lookup;
173 uint64_t reserved[2];
174} __attribute__((packed, aligned(16))) psp_combo_header;
175
176typedef struct _psp_combo_entry {
177 uint32_t id_sel;
178 uint32_t id;
179 uint64_t lvl2_addr;
180} __attribute__((packed)) psp_combo_entry;
181
182typedef struct _psp_combo_directory {
183 psp_combo_header header;
184 psp_combo_entry entries[];
185} __attribute__((packed, aligned(16))) psp_combo_directory;
186
187#define MAX_COMBO_ENTRIES 1
188
189typedef struct _bios_directory_hdr {
190 uint32_t cookie;
191 uint32_t checksum;
192 uint32_t num_entries;
Zheng Bao6fff2492021-11-15 19:53:21 +0800193 union {
194 uint32_t additional_info;
195 struct {
196 uint32_t dir_size:10;
197 uint32_t spi_block_size:4;
198 uint32_t base_addr:15;
199 uint32_t address_mode:2;
200 uint32_t not_used:1;
201 } __attribute__((packed)) additional_info_fields;
202 };
Zheng Bao6be1ab62021-05-26 10:16:33 +0800203} __attribute__((packed, aligned(16))) bios_directory_hdr;
204
205typedef struct _bios_directory_entry {
206 uint8_t type;
207 uint8_t region_type;
208 int reset:1;
209 int copy:1;
210 int ro:1;
211 int compressed:1;
212 int inst:4;
213 uint8_t subprog; /* b[7:3] reserved */
214 uint32_t size;
Zheng Bao6fff2492021-11-15 19:53:21 +0800215 uint64_t source:62;
216 uint64_t address_mode:2;
Zheng Bao6be1ab62021-05-26 10:16:33 +0800217 uint64_t dest;
218} __attribute__((packed)) bios_directory_entry;
219
220typedef struct _bios_directory_table {
221 bios_directory_hdr header;
222 bios_directory_entry entries[];
223} bios_directory_table;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800224
Zheng Bao33351332021-10-30 16:53:23 +0800225#define BDT_LVL1 (1 << 0)
226#define BDT_LVL2 (1 << 1)
Zheng Bao990d1542021-09-17 13:24:54 +0800227#define BDT_LVL1_AB (1 << 2)
228#define BDT_LVL2_AB (1 << 3)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800229#define BDT_BOTH (BDT_LVL1 | BDT_LVL2)
Zheng Bao990d1542021-09-17 13:24:54 +0800230#define BDT_BOTH_AB (BDT_LVL1_AB | BDT_LVL2_AB)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800231typedef struct _amd_bios_entry {
232 amd_bios_type type;
233 char *filename;
234 int subpr;
235 int region_type;
236 int reset;
237 int copy;
238 int ro;
239 int zlib;
240 int inst;
241 uint64_t src;
242 uint64_t dest;
243 size_t size;
244 int level;
245} amd_bios_entry;
246
Zheng Baofdd47ef2021-09-17 13:30:08 +0800247typedef struct _ish_directory_table {
248 uint32_t checksum;
249 uint32_t boot_priority;
250 uint32_t update_retry_count;
251 uint8_t glitch_retry_count;
252 uint8_t glitch_higherbits_reserved[3];
253 uint32_t pl2_location;
254 uint32_t psp_id;
255 uint32_t slot_max_size;
256 uint32_t reserved;
257} __attribute__((packed)) ish_directory_table;
258
Zheng Bao6be1ab62021-05-26 10:16:33 +0800259#define EMBEDDED_FW_SIGNATURE 0x55aa55aa
260#define PSP_COOKIE 0x50535024 /* 'PSP$' */
261#define PSPL2_COOKIE 0x324c5024 /* '2LP$' */
262#define PSP2_COOKIE 0x50535032 /* 'PSP2' */
Zheng Bao96a33712021-06-11 15:54:40 +0800263#define BHD_COOKIE 0x44484224 /* 'DHB$ */
264#define BHDL2_COOKIE 0x324c4224 /* '2LB$ */
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800265
Zheng Bao33351332021-10-30 16:53:23 +0800266#define PSP_LVL1 (1 << 0)
267#define PSP_LVL2 (1 << 1)
Zheng Bao990d1542021-09-17 13:24:54 +0800268#define PSP_LVL1_AB (1 << 2)
269#define PSP_LVL2_AB (1 << 3)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800270#define PSP_BOTH (PSP_LVL1 | PSP_LVL2)
Zheng Bao990d1542021-09-17 13:24:54 +0800271#define PSP_BOTH_AB (PSP_LVL1_AB | PSP_LVL2_AB)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800272typedef struct _amd_fw_entry {
273 amd_fw_type type;
274 char *filename;
275 uint8_t subprog;
276 int level;
277 uint64_t other;
278} amd_fw_entry;
279
280typedef struct _amd_cb_config {
Zheng Baoba3af5e2021-11-04 18:56:47 +0800281 bool have_whitelist;
282 bool unlock_secure;
283 bool use_secureos;
284 bool load_mp2_fw;
285 bool multi_level;
286 bool s0i3;
Zheng Baoc3007f32022-04-03 12:53:51 +0800287 bool second_gen;
Zheng Bao6c5ec8e2022-02-11 11:51:26 +0800288 bool have_mb_spl;
Zheng Bao990d1542021-09-17 13:24:54 +0800289 bool recovery_ab;
Karthikeyan Ramasubramanianad06bae2022-04-08 14:19:55 -0600290 bool recovery_ab_single_copy;
Zheng Baofdd47ef2021-09-17 13:30:08 +0800291 bool need_ish;
Zheng Bao993b43f2021-11-10 12:21:46 +0800292 bool use_combo;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800293} amd_cb_config;
294
295void register_fw_fuse(char *str);
296uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps);
297
298#define OK 0
299
300#define LINE_EOF (1)
301#define LINE_TOO_LONG (2)
302
Robert Zieba29bc79f2022-03-14 15:59:12 -0600303#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800304
305#endif /* _AMD_FW_TOOL_H_ */