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