blob: a7ac7c1e3c683736bbfc4eabd204310ed515d20c [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,
46 AMD_FW_KEYDB_BL = 0x50,
47 AMD_FW_KEYDB_TOS = 0x51,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080048 AMD_FW_PSP_VERSTAGE = 0x52,
49 AMD_FW_VERSTAGE_SIG = 0x53,
Zheng Baobf29a0d2020-12-03 23:00:48 +080050 AMD_RPMC_NVRAM = 0x54,
51 AMD_FW_DMCU_ERAM = 0x58,
52 AMD_FW_DMCU_ISR = 0x59,
Zheng Baob993cb22021-02-02 18:48:23 +080053 AMD_FW_PSP_BOOTLOADER_AB = 0x73,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080054 AMD_FW_IMC = 0x200, /* Large enough to be larger than the top BHD entry type. */
55 AMD_FW_GEC,
56 AMD_FW_XHCI,
57 AMD_FW_INVALID, /* Real last one to detect the last entry in table. */
58 AMD_FW_SKIP /* This is for non-applicable options. */
59} amd_fw_type;
60
61typedef enum _amd_bios_type {
Zheng Baobf29a0d2020-12-03 23:00:48 +080062 AMD_BIOS_RTM_PUBKEY = 5,
Zheng Baoc5e28ab2020-10-28 11:38:09 +080063 AMD_BIOS_APCB = 0x60,
64 AMD_BIOS_APOB = 0x61,
65 AMD_BIOS_BIN = 0x62,
66 AMD_BIOS_APOB_NV = 0x63,
67 AMD_BIOS_PMUI = 0x64,
68 AMD_BIOS_PMUD = 0x65,
69 AMD_BIOS_UCODE = 0x66,
70 AMD_BIOS_APCB_BK = 0x68,
71 AMD_BIOS_MP2_CFG = 0x6a,
72 AMD_BIOS_PSP_SHARED_MEM = 0x6b,
73 AMD_BIOS_L2_PTR = 0x70,
74 AMD_BIOS_INVALID,
75 AMD_BIOS_SKIP
76} amd_bios_type;
77
Zheng Bao6be1ab62021-05-26 10:16:33 +080078struct second_gen_efs { /* todo: expand for Server products */
79 int gen:1; /* Client products only use bit 0 */
80 int reserved:31;
81} __attribute__((packed));
82
83#define EFS_SECOND_GEN 0
84
85typedef struct _embedded_firmware {
86 uint32_t signature; /* 0x55aa55aa */
87 uint32_t imc_entry;
88 uint32_t gec_entry;
89 uint32_t xhci_entry;
Felix Heldad68b072021-10-18 14:00:35 +020090 uint32_t psp_directory;
91 uint32_t combo_psp_directory;
Zheng Bao6be1ab62021-05-26 10:16:33 +080092 uint32_t bios0_entry; /* todo: add way to select correct entry */
93 uint32_t bios1_entry;
94 uint32_t bios2_entry;
95 struct second_gen_efs efs_gen;
96 uint32_t bios3_entry;
97 uint32_t reserved_2Ch;
98 uint32_t promontory_fw_ptr;
99 uint32_t lp_promontory_fw_ptr;
100 uint32_t reserved_38h;
101 uint32_t reserved_3Ch;
102 uint8_t spi_readmode_f15_mod_60_6f;
103 uint8_t fast_speed_new_f15_mod_60_6f;
104 uint8_t reserved_42h;
105 uint8_t spi_readmode_f17_mod_00_2f;
106 uint8_t spi_fastspeed_f17_mod_00_2f;
107 uint8_t qpr_dummy_cycle_f17_mod_00_2f;
108 uint8_t reserved_46h;
109 uint8_t spi_readmode_f17_mod_30_3f;
110 uint8_t spi_fastspeed_f17_mod_30_3f;
111 uint8_t micron_detect_f17_mod_30_3f;
112 uint8_t reserved_4Ah;
113 uint8_t reserved_4Bh;
114 uint32_t reserved_4Ch;
115} __attribute__((packed, aligned(16))) embedded_firmware;
116
117typedef struct _psp_directory_header {
118 uint32_t cookie;
119 uint32_t checksum;
120 uint32_t num_entries;
121 uint32_t additional_info;
122} __attribute__((packed, aligned(16))) psp_directory_header;
123
124typedef struct _psp_directory_entry {
125 uint8_t type;
126 uint8_t subprog;
127 uint16_t rsvd;
128 uint32_t size;
129 uint64_t addr; /* or a value in some cases */
130} __attribute__((packed)) psp_directory_entry;
131
132typedef struct _psp_directory_table {
133 psp_directory_header header;
134 psp_directory_entry entries[];
135} __attribute__((packed, aligned(16))) psp_directory_table;
136
137#define MAX_PSP_ENTRIES 0x1f
138
139typedef struct _psp_combo_header {
140 uint32_t cookie;
141 uint32_t checksum;
142 uint32_t num_entries;
143 uint32_t lookup;
144 uint64_t reserved[2];
145} __attribute__((packed, aligned(16))) psp_combo_header;
146
147typedef struct _psp_combo_entry {
148 uint32_t id_sel;
149 uint32_t id;
150 uint64_t lvl2_addr;
151} __attribute__((packed)) psp_combo_entry;
152
153typedef struct _psp_combo_directory {
154 psp_combo_header header;
155 psp_combo_entry entries[];
156} __attribute__((packed, aligned(16))) psp_combo_directory;
157
158#define MAX_COMBO_ENTRIES 1
159
160typedef struct _bios_directory_hdr {
161 uint32_t cookie;
162 uint32_t checksum;
163 uint32_t num_entries;
164 uint32_t additional_info;
165} __attribute__((packed, aligned(16))) bios_directory_hdr;
166
167typedef struct _bios_directory_entry {
168 uint8_t type;
169 uint8_t region_type;
170 int reset:1;
171 int copy:1;
172 int ro:1;
173 int compressed:1;
174 int inst:4;
175 uint8_t subprog; /* b[7:3] reserved */
176 uint32_t size;
177 uint64_t source;
178 uint64_t dest;
179} __attribute__((packed)) bios_directory_entry;
180
181typedef struct _bios_directory_table {
182 bios_directory_hdr header;
183 bios_directory_entry entries[];
184} bios_directory_table;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800185
Zheng Bao33351332021-10-30 16:53:23 +0800186#define BDT_LVL1 (1 << 0)
187#define BDT_LVL2 (1 << 1)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800188#define BDT_BOTH (BDT_LVL1 | BDT_LVL2)
189typedef struct _amd_bios_entry {
190 amd_bios_type type;
191 char *filename;
192 int subpr;
193 int region_type;
194 int reset;
195 int copy;
196 int ro;
197 int zlib;
198 int inst;
199 uint64_t src;
200 uint64_t dest;
201 size_t size;
202 int level;
203} amd_bios_entry;
204
Zheng Bao6be1ab62021-05-26 10:16:33 +0800205#define EMBEDDED_FW_SIGNATURE 0x55aa55aa
206#define PSP_COOKIE 0x50535024 /* 'PSP$' */
207#define PSPL2_COOKIE 0x324c5024 /* '2LP$' */
208#define PSP2_COOKIE 0x50535032 /* 'PSP2' */
209#define BDT1_COOKIE 0x44484224 /* 'DHB$ */
210#define BDT2_COOKIE 0x324c4224 /* '2LB$ */
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800211
Zheng Bao33351332021-10-30 16:53:23 +0800212#define PSP_LVL1 (1 << 0)
213#define PSP_LVL2 (1 << 1)
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800214#define PSP_BOTH (PSP_LVL1 | PSP_LVL2)
215typedef struct _amd_fw_entry {
216 amd_fw_type type;
217 char *filename;
218 uint8_t subprog;
219 int level;
220 uint64_t other;
221} amd_fw_entry;
222
223typedef struct _amd_cb_config {
Zheng Baoba3af5e2021-11-04 18:56:47 +0800224 bool have_whitelist;
225 bool unlock_secure;
226 bool use_secureos;
227 bool load_mp2_fw;
228 bool multi_level;
229 bool s0i3;
Zheng Baoc5e28ab2020-10-28 11:38:09 +0800230} amd_cb_config;
231
232void register_fw_fuse(char *str);
233uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps);
234
235#define OK 0
236
237#define LINE_EOF (1)
238#define LINE_TOO_LONG (2)
239
240
241#endif /* _AMD_FW_TOOL_H_ */