Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #ifndef _AMD_FW_TOOL_H_ |
| 4 | #define _AMD_FW_TOOL_H_ |
| 5 | |
Karthikeyan Ramasubramanian | 236245e | 2022-09-06 14:02:41 -0600 | [diff] [blame] | 6 | #include <commonlib/bsd/compiler.h> |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 7 | #include <commonlib/bsd/helpers.h> |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 8 | #include <openssl/sha.h> |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 9 | #include <stdint.h> |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 10 | #include <stdbool.h> |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 11 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 12 | typedef enum _amd_fw_type { |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 13 | AMD_FW_PSP_PUBKEY = 0x00, |
| 14 | AMD_FW_PSP_BOOTLOADER = 0x01, |
| 15 | AMD_FW_PSP_SECURED_OS = 0x02, |
| 16 | AMD_FW_PSP_RECOVERY = 0x03, |
| 17 | AMD_FW_PSP_NVRAM = 0x04, |
| 18 | AMD_FW_PSP_RTM_PUBKEY = 0x05, |
| 19 | AMD_FW_PSP_SMU_FIRMWARE = 0x08, |
| 20 | AMD_FW_PSP_SECURED_DEBUG = 0x09, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 21 | AMD_FW_ABL_PUBKEY = 0x0a, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 22 | AMD_PSP_FUSE_CHAIN = 0x0b, |
| 23 | AMD_FW_PSP_TRUSTLETS = 0x0c, |
| 24 | AMD_FW_PSP_TRUSTLETKEY = 0x0d, |
| 25 | AMD_FW_PSP_SMU_FIRMWARE2 = 0x12, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 26 | AMD_DEBUG_UNLOCK = 0x13, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 27 | AMD_BOOT_DRIVER = 0x1b, |
| 28 | AMD_SOC_DRIVER = 0x1c, |
| 29 | AMD_DEBUG_DRIVER = 0x1d, |
| 30 | AMD_INTERFACE_DRIVER = 0x1f, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 31 | AMD_HW_IPCFG = 0x20, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 32 | AMD_WRAPPED_IKEK = 0x21, |
| 33 | AMD_TOKEN_UNLOCK = 0x22, |
| 34 | AMD_SEC_GASKET = 0x24, |
| 35 | AMD_MP2_FW = 0x25, |
| 36 | AMD_DRIVER_ENTRIES = 0x28, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 37 | AMD_FW_KVM_IMAGE = 0x29, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 38 | AMD_FW_MP5 = 0x2a, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 39 | AMD_S0I3_DRIVER = 0x2d, |
| 40 | AMD_ABL0 = 0x30, |
| 41 | AMD_ABL1 = 0x31, |
| 42 | AMD_ABL2 = 0x32, |
| 43 | AMD_ABL3 = 0x33, |
| 44 | AMD_ABL4 = 0x34, |
| 45 | AMD_ABL5 = 0x35, |
| 46 | AMD_ABL6 = 0x36, |
| 47 | AMD_ABL7 = 0x37, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 48 | AMD_SEV_DATA = 0x38, |
| 49 | AMD_SEV_CODE = 0x39, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 50 | AMD_FW_PSP_WHITELIST = 0x3a, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 51 | AMD_VBIOS_BTLOADER = 0x3c, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 52 | AMD_FW_L2_PTR = 0x40, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 53 | AMD_FW_DXIO = 0x42, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 54 | AMD_FW_USB_PHY = 0x44, |
| 55 | AMD_FW_TOS_SEC_POLICY = 0x45, |
| 56 | AMD_FW_DRTM_TA = 0x47, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 57 | AMD_FW_RECOVERYAB_A = 0x48, |
| 58 | AMD_FW_RECOVERYAB_B = 0x4A, |
| 59 | AMD_FW_BIOS_TABLE = 0x49, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 60 | AMD_FW_KEYDB_BL = 0x50, |
| 61 | AMD_FW_KEYDB_TOS = 0x51, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 62 | AMD_FW_PSP_VERSTAGE = 0x52, |
| 63 | AMD_FW_VERSTAGE_SIG = 0x53, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 64 | AMD_RPMC_NVRAM = 0x54, |
Zheng Bao | ab84fd7 | 2022-01-27 22:38:27 +0800 | [diff] [blame] | 65 | AMD_FW_SPL = 0x55, |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 66 | AMD_FW_DMCU_ERAM = 0x58, |
| 67 | AMD_FW_DMCU_ISR = 0x59, |
Felix Held | 5f18bb7 | 2022-03-24 02:04:51 +0100 | [diff] [blame] | 68 | AMD_FW_MSMU = 0x5a, |
| 69 | AMD_FW_SPIROM_CFG = 0x5c, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 70 | AMD_FW_MPIO = 0x5d, |
Felix Held | 9f5a5ee | 2023-02-01 19:21:11 +0100 | [diff] [blame] | 71 | AMD_FW_TPMLITE = 0x5f, /* family 17h & 19h */ |
| 72 | AMD_FW_PSP_SMUSCS = 0x5f, /* family 15h & 16h */ |
Felix Held | 5f18bb7 | 2022-03-24 02:04:51 +0100 | [diff] [blame] | 73 | AMD_FW_DMCUB = 0x71, |
Zheng Bao | b993cb2 | 2021-02-02 18:48:23 +0800 | [diff] [blame] | 74 | AMD_FW_PSP_BOOTLOADER_AB = 0x73, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 75 | AMD_RIB = 0x76, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 76 | AMD_FW_AMF_SRAM = 0x85, |
| 77 | AMD_FW_AMF_DRAM = 0x86, |
| 78 | AMD_FW_AMF_WLAN = 0x88, |
| 79 | AMD_FW_AMF_MFD = 0x89, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 80 | AMD_FW_MPDMA_TF = 0x8c, |
Karthikeyan Ramasubramanian | 0ab04d2 | 2022-05-03 18:16:34 -0600 | [diff] [blame] | 81 | AMD_TA_IKEK = 0x8d, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 82 | AMD_FW_MPCCX = 0x90, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 83 | AMD_FW_GMI3_PHY = 0x91, |
| 84 | AMD_FW_MPDMA_PM = 0x92, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 85 | AMD_FW_LSDMA = 0x94, |
| 86 | AMD_FW_C20_MP = 0x95, |
| 87 | AMD_FW_FCFG_TABLE = 0x98, |
| 88 | AMD_FW_MINIMSMU = 0x9a, |
| 89 | AMD_FW_SRAM_FW_EXT = 0x9d, |
Fred Reitberger | c4f3a33 | 2023-02-07 12:12:40 -0500 | [diff] [blame] | 90 | AMD_FW_UMSMU = 0xa2, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 91 | AMD_FW_IMC = 0x200, /* Large enough to be larger than the top BHD entry type. */ |
| 92 | AMD_FW_GEC, |
| 93 | AMD_FW_XHCI, |
| 94 | AMD_FW_INVALID, /* Real last one to detect the last entry in table. */ |
| 95 | AMD_FW_SKIP /* This is for non-applicable options. */ |
| 96 | } amd_fw_type; |
| 97 | |
| 98 | typedef enum _amd_bios_type { |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 99 | AMD_BIOS_RTM_PUBKEY = 0x05, |
| 100 | AMD_BIOS_SIG = 0x07, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 101 | AMD_BIOS_APCB = 0x60, |
| 102 | AMD_BIOS_APOB = 0x61, |
| 103 | AMD_BIOS_BIN = 0x62, |
| 104 | AMD_BIOS_APOB_NV = 0x63, |
| 105 | AMD_BIOS_PMUI = 0x64, |
| 106 | AMD_BIOS_PMUD = 0x65, |
| 107 | AMD_BIOS_UCODE = 0x66, |
| 108 | AMD_BIOS_APCB_BK = 0x68, |
| 109 | AMD_BIOS_MP2_CFG = 0x6a, |
| 110 | AMD_BIOS_PSP_SHARED_MEM = 0x6b, |
| 111 | AMD_BIOS_L2_PTR = 0x70, |
| 112 | AMD_BIOS_INVALID, |
| 113 | AMD_BIOS_SKIP |
| 114 | } amd_bios_type; |
| 115 | |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 116 | typedef enum _amd_addr_mode { |
| 117 | AMD_ADDR_PHYSICAL = 0, /* Physical address */ |
| 118 | AMD_ADDR_REL_BIOS, /* Relative to beginning of image */ |
| 119 | AMD_ADDR_REL_TAB, /* Relative to table */ |
| 120 | AMD_ADDR_REL_SLOT, /* Relative to slot */ |
| 121 | } amd_addr_mode; |
| 122 | |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 123 | struct second_gen_efs { /* todo: expand for Server products */ |
| 124 | int gen:1; /* Client products only use bit 0 */ |
| 125 | int reserved:31; |
| 126 | } __attribute__((packed)); |
| 127 | |
| 128 | #define EFS_SECOND_GEN 0 |
Zheng Bao | 487d045 | 2022-04-03 12:50:07 +0800 | [diff] [blame] | 129 | #define EFS_BEFORE_SECOND_GEN 1 |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 130 | |
| 131 | typedef struct _embedded_firmware { |
| 132 | uint32_t signature; /* 0x55aa55aa */ |
| 133 | uint32_t imc_entry; |
| 134 | uint32_t gec_entry; |
| 135 | uint32_t xhci_entry; |
Felix Held | ad68b07 | 2021-10-18 14:00:35 +0200 | [diff] [blame] | 136 | uint32_t psp_directory; |
Zheng Bao | b749d3f | 2021-10-23 20:20:21 +0800 | [diff] [blame] | 137 | union { |
| 138 | uint32_t new_psp_directory; |
| 139 | uint32_t combo_psp_directory; |
| 140 | }; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 141 | uint32_t bios0_entry; /* todo: add way to select correct entry */ |
| 142 | uint32_t bios1_entry; |
| 143 | uint32_t bios2_entry; |
| 144 | struct second_gen_efs efs_gen; |
| 145 | uint32_t bios3_entry; |
| 146 | uint32_t reserved_2Ch; |
| 147 | uint32_t promontory_fw_ptr; |
| 148 | uint32_t lp_promontory_fw_ptr; |
| 149 | uint32_t reserved_38h; |
| 150 | uint32_t reserved_3Ch; |
| 151 | uint8_t spi_readmode_f15_mod_60_6f; |
| 152 | uint8_t fast_speed_new_f15_mod_60_6f; |
| 153 | uint8_t reserved_42h; |
| 154 | uint8_t spi_readmode_f17_mod_00_2f; |
| 155 | uint8_t spi_fastspeed_f17_mod_00_2f; |
| 156 | uint8_t qpr_dummy_cycle_f17_mod_00_2f; |
| 157 | uint8_t reserved_46h; |
| 158 | uint8_t spi_readmode_f17_mod_30_3f; |
| 159 | uint8_t spi_fastspeed_f17_mod_30_3f; |
| 160 | uint8_t micron_detect_f17_mod_30_3f; |
| 161 | uint8_t reserved_4Ah; |
| 162 | uint8_t reserved_4Bh; |
| 163 | uint32_t reserved_4Ch; |
| 164 | } __attribute__((packed, aligned(16))) embedded_firmware; |
| 165 | |
| 166 | typedef struct _psp_directory_header { |
| 167 | uint32_t cookie; |
| 168 | uint32_t checksum; |
| 169 | uint32_t num_entries; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 170 | union { |
| 171 | uint32_t additional_info; |
| 172 | struct { |
| 173 | uint32_t dir_size:10; |
| 174 | uint32_t spi_block_size:4; |
| 175 | uint32_t base_addr:15; |
| 176 | uint32_t address_mode:2; |
| 177 | uint32_t not_used:1; |
| 178 | } __attribute__((packed)) additional_info_fields; |
| 179 | }; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 180 | } __attribute__((packed, aligned(16))) psp_directory_header; |
| 181 | |
| 182 | typedef struct _psp_directory_entry { |
| 183 | uint8_t type; |
| 184 | uint8_t subprog; |
Zheng Bao | 5ca1343 | 2022-10-16 20:18:40 +0800 | [diff] [blame] | 185 | union { |
| 186 | uint16_t rsvd; |
| 187 | struct { |
| 188 | uint8_t rom_id:2; |
| 189 | uint8_t writable:1; |
| 190 | uint8_t inst:4; |
| 191 | uint8_t rsvd_1:1; |
| 192 | uint8_t rsvd_2:8; |
| 193 | } __attribute__((packed)); |
| 194 | }; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 195 | uint32_t size; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 196 | uint64_t addr:62; /* or a value in some cases */ |
| 197 | uint64_t address_mode:2; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 198 | } __attribute__((packed)) psp_directory_entry; |
| 199 | |
| 200 | typedef struct _psp_directory_table { |
| 201 | psp_directory_header header; |
| 202 | psp_directory_entry entries[]; |
| 203 | } __attribute__((packed, aligned(16))) psp_directory_table; |
| 204 | |
Altamshali Hirani | 8915abe | 2022-03-17 13:26:31 -0500 | [diff] [blame] | 205 | #define MAX_PSP_ENTRIES 0x2f |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 206 | |
| 207 | typedef struct _psp_combo_header { |
| 208 | uint32_t cookie; |
| 209 | uint32_t checksum; |
| 210 | uint32_t num_entries; |
| 211 | uint32_t lookup; |
| 212 | uint64_t reserved[2]; |
| 213 | } __attribute__((packed, aligned(16))) psp_combo_header; |
| 214 | |
| 215 | typedef struct _psp_combo_entry { |
| 216 | uint32_t id_sel; |
| 217 | uint32_t id; |
| 218 | uint64_t lvl2_addr; |
| 219 | } __attribute__((packed)) psp_combo_entry; |
| 220 | |
| 221 | typedef struct _psp_combo_directory { |
| 222 | psp_combo_header header; |
| 223 | psp_combo_entry entries[]; |
| 224 | } __attribute__((packed, aligned(16))) psp_combo_directory; |
| 225 | |
| 226 | #define MAX_COMBO_ENTRIES 1 |
| 227 | |
| 228 | typedef struct _bios_directory_hdr { |
| 229 | uint32_t cookie; |
| 230 | uint32_t checksum; |
| 231 | uint32_t num_entries; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 232 | union { |
| 233 | uint32_t additional_info; |
| 234 | struct { |
| 235 | uint32_t dir_size:10; |
| 236 | uint32_t spi_block_size:4; |
| 237 | uint32_t base_addr:15; |
| 238 | uint32_t address_mode:2; |
| 239 | uint32_t not_used:1; |
| 240 | } __attribute__((packed)) additional_info_fields; |
| 241 | }; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 242 | } __attribute__((packed, aligned(16))) bios_directory_hdr; |
| 243 | |
| 244 | typedef struct _bios_directory_entry { |
| 245 | uint8_t type; |
| 246 | uint8_t region_type; |
| 247 | int reset:1; |
| 248 | int copy:1; |
| 249 | int ro:1; |
| 250 | int compressed:1; |
| 251 | int inst:4; |
| 252 | uint8_t subprog; /* b[7:3] reserved */ |
| 253 | uint32_t size; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 254 | uint64_t source:62; |
| 255 | uint64_t address_mode:2; |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 256 | uint64_t dest; |
| 257 | } __attribute__((packed)) bios_directory_entry; |
| 258 | |
| 259 | typedef struct _bios_directory_table { |
| 260 | bios_directory_hdr header; |
| 261 | bios_directory_entry entries[]; |
| 262 | } bios_directory_table; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 263 | |
Altamshali Hirani | 8915abe | 2022-03-17 13:26:31 -0500 | [diff] [blame] | 264 | #define MAX_BIOS_ENTRIES 0x2f |
| 265 | |
Zheng Bao | 3335133 | 2021-10-30 16:53:23 +0800 | [diff] [blame] | 266 | #define BDT_LVL1 (1 << 0) |
| 267 | #define BDT_LVL2 (1 << 1) |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 268 | #define BDT_LVL1_AB (1 << 2) |
| 269 | #define BDT_LVL2_AB (1 << 3) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 270 | #define BDT_BOTH (BDT_LVL1 | BDT_LVL2) |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 271 | #define BDT_BOTH_AB (BDT_LVL1_AB | BDT_LVL2_AB) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 272 | typedef struct _amd_bios_entry { |
| 273 | amd_bios_type type; |
| 274 | char *filename; |
| 275 | int subpr; |
| 276 | int region_type; |
| 277 | int reset; |
| 278 | int copy; |
| 279 | int ro; |
| 280 | int zlib; |
| 281 | int inst; |
| 282 | uint64_t src; |
| 283 | uint64_t dest; |
| 284 | size_t size; |
| 285 | int level; |
| 286 | } amd_bios_entry; |
| 287 | |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 288 | typedef struct _ish_directory_table { |
| 289 | uint32_t checksum; |
| 290 | uint32_t boot_priority; |
| 291 | uint32_t update_retry_count; |
| 292 | uint8_t glitch_retry_count; |
| 293 | uint8_t glitch_higherbits_reserved[3]; |
| 294 | uint32_t pl2_location; |
| 295 | uint32_t psp_id; |
| 296 | uint32_t slot_max_size; |
| 297 | uint32_t reserved; |
| 298 | } __attribute__((packed)) ish_directory_table; |
| 299 | |
Zheng Bao | 6be1ab6 | 2021-05-26 10:16:33 +0800 | [diff] [blame] | 300 | #define EMBEDDED_FW_SIGNATURE 0x55aa55aa |
| 301 | #define PSP_COOKIE 0x50535024 /* 'PSP$' */ |
| 302 | #define PSPL2_COOKIE 0x324c5024 /* '2LP$' */ |
| 303 | #define PSP2_COOKIE 0x50535032 /* 'PSP2' */ |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 304 | #define BHD_COOKIE 0x44484224 /* 'DHB$ */ |
| 305 | #define BHDL2_COOKIE 0x324c4224 /* '2LB$ */ |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 306 | |
Zheng Bao | 3335133 | 2021-10-30 16:53:23 +0800 | [diff] [blame] | 307 | #define PSP_LVL1 (1 << 0) |
| 308 | #define PSP_LVL2 (1 << 1) |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 309 | #define PSP_LVL1_AB (1 << 2) |
| 310 | #define PSP_LVL2_AB (1 << 3) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 311 | #define PSP_BOTH (PSP_LVL1 | PSP_LVL2) |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 312 | #define PSP_BOTH_AB (PSP_LVL1_AB | PSP_LVL2_AB) |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 313 | |
| 314 | typedef struct _amd_fw_entry_hash { |
| 315 | uint16_t fw_id; |
| 316 | uint16_t subtype; |
| 317 | uint32_t sha_len; |
| 318 | uint8_t sha[SHA384_DIGEST_LENGTH]; |
| 319 | } amd_fw_entry_hash; |
| 320 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 321 | typedef struct _amd_fw_entry { |
| 322 | amd_fw_type type; |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 323 | /* Mendocino and later SoCs use fw_id instead of fw_type. fw_type is still around |
| 324 | for backwards compatibility. fw_id can be populated from the PSP binary file. */ |
| 325 | uint16_t fw_id; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 326 | char *filename; |
| 327 | uint8_t subprog; |
Zheng Bao | 5ca1343 | 2022-10-16 20:18:40 +0800 | [diff] [blame] | 328 | uint8_t inst; |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 329 | uint64_t dest; |
| 330 | size_t size; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 331 | int level; |
| 332 | uint64_t other; |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 333 | /* If the binary is signed and the tool is invoked to keep the signed binaries separate, |
| 334 | then this field is populated with the offset of the concerned PSP binary (relative to |
| 335 | BIOS or PSP Directory table). */ |
| 336 | uint64_t addr_signed; |
| 337 | uint32_t file_size; |
| 338 | /* Some files that don't have amd_fw_header have to be skipped from hashing. These files |
| 339 | include but not limited to: *iKek*, *.tkn, *.stkn */ |
| 340 | bool skip_hashing; |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 341 | uint32_t num_hash_entries; |
| 342 | amd_fw_entry_hash *hash_entries; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 343 | } amd_fw_entry; |
| 344 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 345 | /* Most PSP binaries, if not all, have the following header format. */ |
| 346 | struct amd_fw_header { |
| 347 | uint8_t reserved_0[20]; |
| 348 | uint32_t fw_size_signed; |
| 349 | uint8_t reserved_18[24]; |
| 350 | /* 1 if the image is signed, 0 otherwise */ |
| 351 | uint32_t sig_opt; |
| 352 | uint32_t sig_id; |
| 353 | uint8_t sig_param[16]; |
| 354 | uint32_t comp_opt; |
| 355 | uint8_t reserved_4c[4]; |
| 356 | uint32_t uncomp_size; |
| 357 | uint32_t comp_size; |
| 358 | /* Starting MDN fw_id is populated instead of fw_type. */ |
| 359 | uint16_t fw_id; |
| 360 | uint8_t reserved_5a[18]; |
| 361 | uint32_t size_total; |
| 362 | uint8_t reserved_70[12]; |
| 363 | /* Starting MDN fw_id is populated instead of fw_type. fw_type will still be around |
| 364 | for backwards compatibility. */ |
| 365 | uint8_t fw_type; |
| 366 | uint8_t fw_subtype; |
| 367 | uint8_t fw_subprog; |
| 368 | uint8_t reserved_7f; |
| 369 | uint8_t reserved_80[128]; |
| 370 | } __packed; |
| 371 | |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 372 | struct psp_fw_hash_table { |
| 373 | uint16_t version; |
| 374 | uint16_t no_of_entries_256; |
| 375 | uint16_t no_of_entries_384; |
| 376 | /* The next 2 elements are pointers to arrays of SHA256 and SHA384 entries. */ |
| 377 | /* It does not make sense to store pointers in the CBFS file */ |
| 378 | } __packed; |
| 379 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 380 | typedef struct _amd_cb_config { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 381 | bool have_whitelist; |
| 382 | bool unlock_secure; |
| 383 | bool use_secureos; |
| 384 | bool load_mp2_fw; |
| 385 | bool multi_level; |
| 386 | bool s0i3; |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 387 | bool second_gen; |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 388 | bool have_mb_spl; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 389 | bool recovery_ab; |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 390 | bool recovery_ab_single_copy; |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 391 | bool need_ish; |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 392 | bool use_combo; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 393 | } amd_cb_config; |
| 394 | |
| 395 | void register_fw_fuse(char *str); |
| 396 | uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps); |
| 397 | |
| 398 | #define OK 0 |
| 399 | |
| 400 | #define LINE_EOF (1) |
| 401 | #define LINE_TOO_LONG (2) |
| 402 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 403 | #endif /* _AMD_FW_TOOL_H_ */ |