blob: 70afe3c6df689f45b38e8e11bd4fcfa8cb523781 [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,
Zheng Baob993cb22021-02-02 18:48:23 +080057 AMD_FW_PSP_BOOTLOADER_AB = 0x73,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080058 AMD_FW_IMC = 0x200, /* Large enough to be larger than the top BHD entry type. */
59 AMD_FW_GEC,
60 AMD_FW_XHCI,
61 AMD_FW_INVALID, /* Real last one to detect the last entry in table. */
62 AMD_FW_SKIP /* This is for non-applicable options. */
63} amd_fw_type;
64
65typedef enum _amd_bios_type {
Zheng Baobf29a0d2020-12-03 23:00:48 +080066 AMD_BIOS_RTM_PUBKEY = 5,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080067 AMD_BIOS_APCB = 0x60,
68 AMD_BIOS_APOB = 0x61,
69 AMD_BIOS_BIN = 0x62,
70 AMD_BIOS_APOB_NV = 0x63,
71 AMD_BIOS_PMUI = 0x64,
72 AMD_BIOS_PMUD = 0x65,
73 AMD_BIOS_UCODE = 0x66,
74 AMD_BIOS_APCB_BK = 0x68,
75 AMD_BIOS_MP2_CFG = 0x6a,
76 AMD_BIOS_PSP_SHARED_MEM = 0x6b,
77 AMD_BIOS_L2_PTR = 0x70,
78 AMD_BIOS_INVALID,
79 AMD_BIOS_SKIP
80} amd_bios_type;
81
Zheng Bao6be1ab62021-05-26 10:16:33 +080082struct second_gen_efs { /* todo: expand for Server products */
83 int gen:1; /* Client products only use bit 0 */
84 int reserved:31;
85} __attribute__((packed));
86
87#define EFS_SECOND_GEN 0
88
89typedef struct _embedded_firmware {
90 uint32_t signature; /* 0x55aa55aa */
91 uint32_t imc_entry;
92 uint32_t gec_entry;
93 uint32_t xhci_entry;
Felix Heldad68b072021-10-18 14:00:35 +020094 uint32_t psp_directory;
Zheng Baob749d3f2021-10-23 20:20:21 +080095 union {
96 uint32_t new_psp_directory;
97 uint32_t combo_psp_directory;
98 };
Zheng Bao6be1ab62021-05-26 10:16:33 +080099 uint32_t bios0_entry; /* todo: add way to select correct entry */
100 uint32_t bios1_entry;
101 uint32_t bios2_entry;
102 struct second_gen_efs efs_gen;
103 uint32_t bios3_entry;
104 uint32_t reserved_2Ch;
105 uint32_t promontory_fw_ptr;
106 uint32_t lp_promontory_fw_ptr;
107 uint32_t reserved_38h;
108 uint32_t reserved_3Ch;
109 uint8_t spi_readmode_f15_mod_60_6f;
110 uint8_t fast_speed_new_f15_mod_60_6f;
111 uint8_t reserved_42h;
112 uint8_t spi_readmode_f17_mod_00_2f;
113 uint8_t spi_fastspeed_f17_mod_00_2f;
114 uint8_t qpr_dummy_cycle_f17_mod_00_2f;
115 uint8_t reserved_46h;
116 uint8_t spi_readmode_f17_mod_30_3f;
117 uint8_t spi_fastspeed_f17_mod_30_3f;
118 uint8_t micron_detect_f17_mod_30_3f;
119 uint8_t reserved_4Ah;
120 uint8_t reserved_4Bh;
121 uint32_t reserved_4Ch;
122} __attribute__((packed, aligned(16))) embedded_firmware;
123
124typedef struct _psp_directory_header {
125 uint32_t cookie;
126 uint32_t checksum;
127 uint32_t num_entries;
Zheng Bao6fff2492021-11-15 19:53:21 +0800128 union {
129 uint32_t additional_info;
130 struct {
131 uint32_t dir_size:10;
132 uint32_t spi_block_size:4;
133 uint32_t base_addr:15;
134 uint32_t address_mode:2;
135 uint32_t not_used:1;
136 } __attribute__((packed)) additional_info_fields;
137 };
Zheng Bao6be1ab62021-05-26 10:16:33 +0800138} __attribute__((packed, aligned(16))) psp_directory_header;
139
140typedef struct _psp_directory_entry {
141 uint8_t type;
142 uint8_t subprog;
143 uint16_t rsvd;
144 uint32_t size;
Zheng Bao6fff2492021-11-15 19:53:21 +0800145 uint64_t addr:62; /* or a value in some cases */
146 uint64_t address_mode:2;
Zheng Bao6be1ab62021-05-26 10:16:33 +0800147} __attribute__((packed)) psp_directory_entry;
148
149typedef struct _psp_directory_table {
150 psp_directory_header header;
151 psp_directory_entry entries[];
152} __attribute__((packed, aligned(16))) psp_directory_table;
153
154#define MAX_PSP_ENTRIES 0x1f
155
156typedef struct _psp_combo_header {
157 uint32_t cookie;
158 uint32_t checksum;
159 uint32_t num_entries;
160 uint32_t lookup;
161 uint64_t reserved[2];
162} __attribute__((packed, aligned(16))) psp_combo_header;
163
164typedef struct _psp_combo_entry {
165 uint32_t id_sel;
166 uint32_t id;
167 uint64_t lvl2_addr;
168} __attribute__((packed)) psp_combo_entry;
169
170typedef struct _psp_combo_directory {
171 psp_combo_header header;
172 psp_combo_entry entries[];
173} __attribute__((packed, aligned(16))) psp_combo_directory;
174
175#define MAX_COMBO_ENTRIES 1
176
177typedef struct _bios_directory_hdr {
178 uint32_t cookie;
179 uint32_t checksum;
180 uint32_t num_entries;
Zheng Bao6fff2492021-11-15 19:53:21 +0800181 union {
182 uint32_t additional_info;
183 struct {
184 uint32_t dir_size:10;
185 uint32_t spi_block_size:4;
186 uint32_t base_addr:15;
187 uint32_t address_mode:2;
188 uint32_t not_used:1;
189 } __attribute__((packed)) additional_info_fields;
190 };
Zheng Bao6be1ab62021-05-26 10:16:33 +0800191} __attribute__((packed, aligned(16))) bios_directory_hdr;
192
193typedef struct _bios_directory_entry {
194 uint8_t type;
195 uint8_t region_type;
196 int reset:1;
197 int copy:1;
198 int ro:1;
199 int compressed:1;
200 int inst:4;
201 uint8_t subprog; /* b[7:3] reserved */
202 uint32_t size;
Zheng Bao6fff2492021-11-15 19:53:21 +0800203 uint64_t source:62;
204 uint64_t address_mode:2;
Zheng Bao6be1ab62021-05-26 10:16:33 +0800205 uint64_t dest;
206} __attribute__((packed)) bios_directory_entry;
207
208typedef struct _bios_directory_table {
209 bios_directory_hdr header;
210 bios_directory_entry entries[];
211} bios_directory_table;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800212
Zheng Bao33351332021-10-30 16:53:23 +0800213#define BDT_LVL1 (1 << 0)
214#define BDT_LVL2 (1 << 1)
Zheng Bao990d1542021-09-17 13:24:54 +0800215#define BDT_LVL1_AB (1 << 2)
216#define BDT_LVL2_AB (1 << 3)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800217#define BDT_BOTH (BDT_LVL1 | BDT_LVL2)
Zheng Bao990d1542021-09-17 13:24:54 +0800218#define BDT_BOTH_AB (BDT_LVL1_AB | BDT_LVL2_AB)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800219typedef struct _amd_bios_entry {
220 amd_bios_type type;
221 char *filename;
222 int subpr;
223 int region_type;
224 int reset;
225 int copy;
226 int ro;
227 int zlib;
228 int inst;
229 uint64_t src;
230 uint64_t dest;
231 size_t size;
232 int level;
233} amd_bios_entry;
234
Zheng Bao6be1ab62021-05-26 10:16:33 +0800235#define EMBEDDED_FW_SIGNATURE 0x55aa55aa
236#define PSP_COOKIE 0x50535024 /* 'PSP$' */
237#define PSPL2_COOKIE 0x324c5024 /* '2LP$' */
238#define PSP2_COOKIE 0x50535032 /* 'PSP2' */
239#define BDT1_COOKIE 0x44484224 /* 'DHB$ */
240#define BDT2_COOKIE 0x324c4224 /* '2LB$ */
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800241
Zheng Bao33351332021-10-30 16:53:23 +0800242#define PSP_LVL1 (1 << 0)
243#define PSP_LVL2 (1 << 1)
Zheng Bao990d1542021-09-17 13:24:54 +0800244#define PSP_LVL1_AB (1 << 2)
245#define PSP_LVL2_AB (1 << 3)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800246#define PSP_BOTH (PSP_LVL1 | PSP_LVL2)
Zheng Bao990d1542021-09-17 13:24:54 +0800247#define PSP_BOTH_AB (PSP_LVL1_AB | PSP_LVL2_AB)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800248typedef struct _amd_fw_entry {
249 amd_fw_type type;
250 char *filename;
251 uint8_t subprog;
252 int level;
253 uint64_t other;
254} amd_fw_entry;
255
256typedef struct _amd_cb_config {
Zheng Baoba3af5e2021-11-04 18:56:47 +0800257 bool have_whitelist;
258 bool unlock_secure;
259 bool use_secureos;
260 bool load_mp2_fw;
261 bool multi_level;
262 bool s0i3;
Zheng Bao6c5ec8e2022-02-11 11:51:26 +0800263 bool have_mb_spl;
Zheng Bao990d1542021-09-17 13:24:54 +0800264 bool recovery_ab;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800265} amd_cb_config;
266
267void register_fw_fuse(char *str);
268uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps);
269
270#define OK 0
271
272#define LINE_EOF (1)
273#define LINE_TOO_LONG (2)
274
275
276#endif /* _AMD_FW_TOOL_H_ */