Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * ROMSIG At ROMBASE + 0x20000: |
zbao | c3b0b72 | 2016-02-19 13:47:31 +0800 | [diff] [blame] | 5 | * 0 4 8 C |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 6 | * +------------+---------------+----------------+------------+ |
| 7 | * | 0x55AA55AA |EC ROM Address |GEC ROM Address |USB3 ROM | |
| 8 | * +------------+---------------+----------------+------------+ |
zbao | c3b0b72 | 2016-02-19 13:47:31 +0800 | [diff] [blame] | 9 | * | PSPDIR ADDR|PSPDIR ADDR |<-- Field 0x14 could be either |
| 10 | * +------------+---------------+ 2nd PSP directory or PSP COMBO directory |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 11 | * EC ROM should be 64K aligned. |
| 12 | * |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 13 | * PSP directory (Where "PSPDIR ADDR" points) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 14 | * +------------+---------------+----------------+------------+ |
| 15 | * | 'PSP$' | Fletcher | Count | Reserved | |
| 16 | * +------------+---------------+----------------+------------+ |
| 17 | * | 0 | size | Base address | Reserved | Pubkey |
| 18 | * +------------+---------------+----------------+------------+ |
| 19 | * | 1 | size | Base address | Reserved | Bootloader |
| 20 | * +------------+---------------+----------------+------------+ |
| 21 | * | 8 | size | Base address | Reserved | Smu Firmware |
| 22 | * +------------+---------------+----------------+------------+ |
| 23 | * | 3 | size | Base address | Reserved | Recovery Firmware |
| 24 | * +------------+---------------+----------------+------------+ |
| 25 | * | | |
| 26 | * | | |
| 27 | * | Other PSP Firmware | |
| 28 | * | | |
| 29 | * | | |
| 30 | * +------------+---------------+----------------+------------+ |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 31 | * |
zbao | c3b0b72 | 2016-02-19 13:47:31 +0800 | [diff] [blame] | 32 | * PSP Combo directory |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 33 | * +------------+---------------+----------------+------------+ |
zbao | 6e2f3d1 | 2016-02-19 13:34:59 +0800 | [diff] [blame] | 34 | * | 'PSP2' | Fletcher | Count |Look up mode| |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 35 | * +------------+---------------+----------------+------------+ |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 36 | * | R e s e r v e d | |
| 37 | * +------------+---------------+----------------+------------+ |
zbao | 6e2f3d1 | 2016-02-19 13:34:59 +0800 | [diff] [blame] | 38 | * | ID-Sel | PSP ID | PSPDIR ADDR | | 2nd PSP directory |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 39 | * +------------+---------------+----------------+------------+ |
zbao | 6e2f3d1 | 2016-02-19 13:34:59 +0800 | [diff] [blame] | 40 | * | ID-Sel | PSP ID | PSPDIR ADDR | | 3rd PSP directory |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 41 | * +------------+---------------+----------------+------------+ |
| 42 | * | | |
| 43 | * | Other PSP | |
| 44 | * | | |
| 45 | * +------------+---------------+----------------+------------+ |
| 46 | * |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 47 | */ |
| 48 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 49 | #include <commonlib/bsd/helpers.h> |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 50 | #include <fcntl.h> |
| 51 | #include <errno.h> |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 52 | #include <limits.h> |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 53 | #include <openssl/sha.h> |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 54 | #include <stdbool.h> |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 55 | #include <stdio.h> |
| 56 | #include <sys/stat.h> |
| 57 | #include <sys/types.h> |
| 58 | #include <unistd.h> |
| 59 | #include <string.h> |
| 60 | #include <stdlib.h> |
| 61 | #include <getopt.h> |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 62 | #include <libgen.h> |
Idwer Vollering | 93df1d9 | 2020-12-30 00:01:59 +0100 | [diff] [blame] | 63 | #include <stdint.h> |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 64 | |
| 65 | #include "amdfwtool.h" |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 66 | |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 67 | #define AMD_ROMSIG_OFFSET 0x20000 |
| 68 | #define MIN_ROM_KB 256 |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 69 | |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 70 | #define _MAX(A, B) (((A) > (B)) ? (A) : (B)) |
| 71 | #define ERASE_ALIGNMENT 0x1000U |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 72 | #define TABLE_ALIGNMENT 0x1000U |
| 73 | #define BLOB_ALIGNMENT 0x100U |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 74 | #define TABLE_ERASE_ALIGNMENT _MAX(TABLE_ALIGNMENT, ERASE_ALIGNMENT) |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 75 | #define BLOB_ERASE_ALIGNMENT _MAX(BLOB_ALIGNMENT, ERASE_ALIGNMENT) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 76 | |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 77 | #define DEFAULT_SOFT_FUSE_CHAIN "0x1" |
| 78 | |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 79 | /* Defines related to hashing signed binaries */ |
| 80 | enum hash_header_ver { |
| 81 | HASH_HDR_V1 = 1, |
| 82 | }; |
| 83 | /* Signature ID enums are defined by PSP based on the algorithm used. */ |
| 84 | enum signature_id { |
| 85 | SIG_ID_RSA2048, |
| 86 | SIG_ID_RSA4096 = 2, |
| 87 | }; |
| 88 | #define HASH_FILE_SUFFIX ".hash" |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 89 | #define EFS_FILE_SUFFIX ".efs" |
| 90 | #define TMP_FILE_SUFFIX ".tmp" |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 91 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 92 | /* |
Marshall Dawson | 0e02ce8 | 2019-03-04 16:50:37 -0700 | [diff] [blame] | 93 | * Beginning with Family 15h Models 70h-7F, a.k.a Stoney Ridge, the PSP |
| 94 | * can support an optional "combo" implementation. If the PSP sees the |
| 95 | * PSP2 cookie, it interprets the table as a roadmap to additional PSP |
| 96 | * tables. Using this, support for multiple product generations may be |
| 97 | * built into one image. If the PSP$ cookie is found, the table is a |
| 98 | * normal directory table. |
| 99 | * |
| 100 | * Modern generations supporting the combo directories require the |
| 101 | * pointer to be at offset 0x14 of the Embedded Firmware Structure, |
| 102 | * regardless of the type of directory used. The --combo-capable |
| 103 | * argument enforces this placement. |
| 104 | * |
| 105 | * TODO: Future work may require fully implementing the PSP_COMBO feature. |
zbao | c3b0b72 | 2016-02-19 13:47:31 +0800 | [diff] [blame] | 106 | */ |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 107 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 108 | /* |
| 109 | * Creates the OSI Fletcher checksum. See 8473-1, Appendix C, section C.3. |
| 110 | * The checksum field of the passed PDU does not need to be reset to zero. |
| 111 | * |
| 112 | * The "Fletcher Checksum" was proposed in a paper by John G. Fletcher of |
| 113 | * Lawrence Livermore Labs. The Fletcher Checksum was proposed as an |
| 114 | * alternative to cyclical redundancy checks because it provides error- |
| 115 | * detection properties similar to cyclical redundancy checks but at the |
| 116 | * cost of a simple summation technique. Its characteristics were first |
| 117 | * published in IEEE Transactions on Communications in January 1982. One |
| 118 | * version has been adopted by ISO for use in the class-4 transport layer |
| 119 | * of the network protocol. |
| 120 | * |
| 121 | * This program expects: |
| 122 | * stdin: The input file to compute a checksum for. The input file |
| 123 | * not be longer than 256 bytes. |
| 124 | * stdout: Copied from the input file with the Fletcher's Checksum |
| 125 | * inserted 8 bytes after the beginning of the file. |
| 126 | * stderr: Used to print out error messages. |
| 127 | */ |
Marshall Dawson | 8a45a4d | 2019-02-24 07:18:44 -0700 | [diff] [blame] | 128 | static uint32_t fletcher32(const void *data, int length) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 129 | { |
| 130 | uint32_t c0; |
| 131 | uint32_t c1; |
| 132 | uint32_t checksum; |
| 133 | int index; |
Marshall Dawson | 8a45a4d | 2019-02-24 07:18:44 -0700 | [diff] [blame] | 134 | const uint16_t *pptr = data; |
| 135 | |
| 136 | length /= 2; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 137 | |
| 138 | c0 = 0xFFFF; |
| 139 | c1 = 0xFFFF; |
| 140 | |
Marshall Dawson | b85ddc5 | 2019-07-23 07:24:30 -0600 | [diff] [blame] | 141 | while (length) { |
| 142 | index = length >= 359 ? 359 : length; |
| 143 | length -= index; |
Zheng Bao | c88f2b5 | 2021-10-14 16:15:11 +0800 | [diff] [blame] | 144 | do { |
| 145 | c0 += *(pptr++); |
| 146 | c1 += c0; |
| 147 | } while (--index); |
Marshall Dawson | b85ddc5 | 2019-07-23 07:24:30 -0600 | [diff] [blame] | 148 | c0 = (c0 & 0xFFFF) + (c0 >> 16); |
| 149 | c1 = (c1 & 0xFFFF) + (c1 >> 16); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 150 | } |
| 151 | |
Marshall Dawson | 8a45a4d | 2019-02-24 07:18:44 -0700 | [diff] [blame] | 152 | /* Sums[0,1] mod 64K + overflow */ |
| 153 | c0 = (c0 & 0xFFFF) + (c0 >> 16); |
| 154 | c1 = (c1 & 0xFFFF) + (c1 >> 16); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 155 | checksum = (c1 << 16) | c0; |
| 156 | |
| 157 | return checksum; |
| 158 | } |
| 159 | |
Martin Roth | 8806f7f | 2016-11-08 10:44:18 -0700 | [diff] [blame] | 160 | static void usage(void) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 161 | { |
Martin Roth | 0e94062 | 2016-11-08 10:37:53 -0700 | [diff] [blame] | 162 | printf("amdfwtool: Create AMD Firmware combination\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 163 | printf("Usage: amdfwtool [options] --flashsize <size> --output <filename>\n"); |
| 164 | printf("--xhci <FILE> Add XHCI blob\n"); |
| 165 | printf("--imc <FILE> Add IMC blob\n"); |
| 166 | printf("--gec <FILE> Add GEC blob\n"); |
Martin Roth | 0e94062 | 2016-11-08 10:37:53 -0700 | [diff] [blame] | 167 | |
| 168 | printf("\nPSP options:\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 169 | printf("--combo-capable Place PSP directory pointer at Embedded\n"); |
| 170 | printf(" Firmware\n"); |
Marshall Dawson | 67d868d | 2019-02-28 11:43:40 -0700 | [diff] [blame] | 171 | printf(" offset able to support combo directory\n"); |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 172 | printf("--use-combo Use the COMBO layout\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 173 | printf("--multilevel Generate primary and secondary tables\n"); |
| 174 | printf("--nvram <FILE> Add nvram binary\n"); |
| 175 | printf("--soft-fuse Set soft fuse\n"); |
| 176 | printf("--token-unlock Set token unlock\n"); |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 177 | printf("--nvram-base <HEX_VAL> Base address of nvram\n"); |
| 178 | printf("--nvram-size <HEX_VAL> Size of nvram\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 179 | printf("--whitelist Set if there is a whitelist\n"); |
| 180 | printf("--use-pspsecureos Set if psp secure OS is needed\n"); |
| 181 | printf("--load-mp2-fw Set if load MP2 firmware\n"); |
| 182 | printf("--load-s0i3 Set if load s0i3 firmware\n"); |
| 183 | printf("--verstage <FILE> Add verstage\n"); |
| 184 | printf("--verstage_sig Add verstage signature\n"); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 185 | printf("--recovery-ab Use the recovery A/B layout\n"); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 186 | printf("\nBIOS options:\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 187 | printf("--instance <number> Sets instance field for the next BIOS\n"); |
Zheng Bao | 6f0b361 | 2021-04-27 17:19:43 +0800 | [diff] [blame] | 188 | printf(" firmware\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 189 | printf("--apcb <FILE> Add AGESA PSP customization block\n"); |
| 190 | printf("--apob-base <HEX_VAL> Destination for AGESA PSP output block\n"); |
| 191 | printf("--apob-nv-base <HEX_VAL> Location of S3 resume data\n"); |
| 192 | printf("--apob-nv-size <HEX_VAL> Size of S3 resume data\n"); |
| 193 | printf("--ucode <FILE> Add microcode patch\n"); |
| 194 | printf("--bios-bin <FILE> Add compressed image; auto source address\n"); |
| 195 | printf("--bios-bin-src <HEX_VAL> Address in flash of source if -V not used\n"); |
| 196 | printf("--bios-bin-dest <HEX_VAL> Destination for uncompressed BIOS\n"); |
| 197 | printf("--bios-uncomp-size <HEX> Uncompressed size of BIOS image\n"); |
| 198 | printf("--output <filename> output filename\n"); |
| 199 | printf("--flashsize <HEX_VAL> ROM size in bytes\n"); |
Marshall Dawson | f4b9b41 | 2017-03-17 16:30:51 -0600 | [diff] [blame] | 200 | printf(" size must be larger than %dKB\n", |
Martin Roth | 0e94062 | 2016-11-08 10:37:53 -0700 | [diff] [blame] | 201 | MIN_ROM_KB); |
Marshall Dawson | f4b9b41 | 2017-03-17 16:30:51 -0600 | [diff] [blame] | 202 | printf(" and must a multiple of 1024\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 203 | printf("--location Location of Directory\n"); |
| 204 | printf("--anywhere Use any 64-byte aligned addr for Directory\n"); |
| 205 | printf("--sharedmem Location of PSP/FW shared memory\n"); |
| 206 | printf("--sharedmem-size Maximum size of the PSP/FW shared memory\n"); |
Zheng Bao | 6f0b361 | 2021-04-27 17:19:43 +0800 | [diff] [blame] | 207 | printf(" area\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 208 | printf("--soc-name <socname> Specify SOC name. Supported names are\n"); |
Zheng Bao | 6f0b361 | 2021-04-27 17:19:43 +0800 | [diff] [blame] | 209 | printf(" Stoneyridge, Raven, Picasso, Renoir, Cezanne\n"); |
Martin Roth | 20646cd | 2023-01-04 21:27:06 -0700 | [diff] [blame] | 210 | printf(" Mendocino, Phoenix, Glinda, or Lucienne\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 211 | printf("\nEmbedded Firmware Structure options used by the PSP:\n"); |
| 212 | printf("--spi-speed <HEX_VAL> SPI fast speed to place in EFS Table\n"); |
| 213 | printf(" 0x0 66.66Mhz\n"); |
| 214 | printf(" 0x1 33.33MHz\n"); |
| 215 | printf(" 0x2 22.22MHz\n"); |
| 216 | printf(" 0x3 16.66MHz\n"); |
| 217 | printf(" 0x4 100MHz\n"); |
| 218 | printf(" 0x5 800KHz\n"); |
| 219 | printf("--spi-read-mode <HEX_VAL> SPI read mode to place in EFS Table\n"); |
| 220 | printf(" 0x0 Normal Read (up to 33M)\n"); |
| 221 | printf(" 0x1 Reserved\n"); |
| 222 | printf(" 0x2 Dual IO (1-1-2)\n"); |
| 223 | printf(" 0x3 Quad IO (1-1-4)\n"); |
| 224 | printf(" 0x4 Dual IO (1-2-2)\n"); |
| 225 | printf(" 0x5 Quad IO (1-4-4)\n"); |
| 226 | printf(" 0x6 Normal Read (up to 66M)\n"); |
| 227 | printf(" 0x7 Fast Read\n"); |
| 228 | printf("--spi-micron-flag <HEX_VAL> Micron SPI part support for RV and later SOC\n"); |
| 229 | printf(" 0x0 Micron parts are not used\n"); |
| 230 | printf(" 0x1 Micron parts are always used\n"); |
| 231 | printf(" 0x2 Micron parts optional, this option is only\n"); |
| 232 | printf(" supported with RN/LCN SOC\n"); |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 233 | printf("\nGeneral options:\n"); |
| 234 | printf("-c|--config <config file> Config file\n"); |
| 235 | printf("-d|--debug Print debug message\n"); |
| 236 | printf("-l|--list List out the firmware files\n"); |
| 237 | printf("-h|--help Show this help\n"); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 238 | } |
| 239 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 240 | amd_fw_entry amd_psp_fw_table[] = { |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 241 | { .type = AMD_FW_PSP_PUBKEY, .level = PSP_BOTH | PSP_LVL2_AB, .skip_hashing = true }, |
Zheng Bao | fb9b784 | 2022-02-24 15:15:50 +0800 | [diff] [blame] | 242 | { .type = AMD_FW_PSP_BOOTLOADER, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 243 | { .type = AMD_FW_PSP_SECURED_OS, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 244 | { .type = AMD_FW_PSP_RECOVERY, .level = PSP_LVL1 }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 245 | { .type = AMD_FW_PSP_NVRAM, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 246 | { .type = AMD_FW_PSP_RTM_PUBKEY, .level = PSP_BOTH }, |
| 247 | { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 0, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 248 | { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 1, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 249 | { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 2, .level = PSP_BOTH | PSP_LVL2_AB }, |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 250 | { .type = AMD_FW_PSP_SECURED_DEBUG, .level = PSP_LVL2 | PSP_LVL2_AB, |
| 251 | .skip_hashing = true }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 252 | { .type = AMD_FW_ABL_PUBKEY, .level = PSP_BOTH | PSP_BOTH_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 253 | { .type = AMD_PSP_FUSE_CHAIN, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 254 | { .type = AMD_FW_PSP_TRUSTLETS, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 255 | { .type = AMD_FW_PSP_TRUSTLETKEY, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 256 | { .type = AMD_FW_PSP_SMU_FIRMWARE2, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 257 | { .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 1, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 258 | { .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 2, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 259 | { .type = AMD_BOOT_DRIVER, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 260 | { .type = AMD_SOC_DRIVER, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 261 | { .type = AMD_DEBUG_DRIVER, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 262 | { .type = AMD_INTERFACE_DRIVER, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 263 | { .type = AMD_DEBUG_UNLOCK, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 264 | { .type = AMD_HW_IPCFG, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 265 | { .type = AMD_WRAPPED_IKEK, .level = PSP_BOTH | PSP_LVL2_AB, .skip_hashing = true }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 266 | { .type = AMD_TOKEN_UNLOCK, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 267 | { .type = AMD_SEC_GASKET, .subprog = 0, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 268 | { .type = AMD_SEC_GASKET, .subprog = 1, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 269 | { .type = AMD_SEC_GASKET, .subprog = 2, .level = PSP_BOTH | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 270 | { .type = AMD_MP2_FW, .subprog = 0, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 271 | { .type = AMD_MP2_FW, .subprog = 1, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 272 | { .type = AMD_MP2_FW, .subprog = 2, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 273 | { .type = AMD_DRIVER_ENTRIES, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 274 | { .type = AMD_FW_KVM_IMAGE, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 275 | { .type = AMD_FW_MP5, .subprog = 0, .level = PSP_BOTH | PSP_BOTH_AB }, |
| 276 | { .type = AMD_FW_MP5, .subprog = 1, .level = PSP_BOTH | PSP_BOTH_AB }, |
| 277 | { .type = AMD_FW_MP5, .subprog = 2, .level = PSP_BOTH | PSP_BOTH_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 278 | { .type = AMD_S0I3_DRIVER, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 279 | { .type = AMD_ABL0, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 280 | { .type = AMD_ABL1, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 281 | { .type = AMD_ABL2, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 282 | { .type = AMD_ABL3, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 283 | { .type = AMD_ABL4, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 284 | { .type = AMD_ABL5, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 285 | { .type = AMD_ABL6, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 286 | { .type = AMD_ABL7, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 287 | { .type = AMD_SEV_DATA, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 288 | { .type = AMD_SEV_CODE, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Karthikeyan Ramasubramanian | 51f914d | 2022-07-28 16:42:12 -0600 | [diff] [blame] | 289 | { .type = AMD_FW_PSP_WHITELIST, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 290 | { .type = AMD_VBIOS_BTLOADER, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 291 | { .type = AMD_FW_DXIO, .level = PSP_BOTH | PSP_BOTH_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 292 | { .type = AMD_FW_USB_PHY, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 293 | { .type = AMD_FW_TOS_SEC_POLICY, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 294 | { .type = AMD_FW_DRTM_TA, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 295 | { .type = AMD_FW_KEYDB_BL, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 296 | { .type = AMD_FW_KEYDB_TOS, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Karthikeyan Ramasubramanian | 234e370 | 2022-07-25 09:49:24 -0600 | [diff] [blame] | 297 | { .type = AMD_FW_PSP_VERSTAGE, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 298 | { .type = AMD_FW_VERSTAGE_SIG, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 299 | { .type = AMD_RPMC_NVRAM, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 300 | { .type = AMD_FW_SPL, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 301 | { .type = AMD_FW_DMCU_ERAM, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 302 | { .type = AMD_FW_DMCU_ISR, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 303 | { .type = AMD_FW_MSMU, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 304 | { .type = AMD_FW_SPIROM_CFG, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 305 | { .type = AMD_FW_MPIO, .level = PSP_LVL2 | PSP_BOTH_AB }, |
| 306 | { .type = AMD_FW_PSP_SMUSCS, .level = PSP_BOTH | PSP_LVL2_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 307 | { .type = AMD_FW_DMCUB, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 308 | { .type = AMD_FW_PSP_BOOTLOADER_AB, .level = PSP_LVL2 | PSP_LVL2_AB }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 309 | { .type = AMD_RIB, .level = PSP_LVL2 | PSP_BOTH_AB }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 310 | { .type = AMD_FW_MPDMA_TF, .level = PSP_BOTH | PSP_BOTH_AB }, |
Arthur Heymans | aafbe13 | 2022-09-30 08:33:28 +0200 | [diff] [blame] | 311 | { .type = AMD_TA_IKEK, .level = PSP_BOTH | PSP_LVL2_AB, .skip_hashing = true }, |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 312 | { .type = AMD_FW_GMI3_PHY, .level = PSP_BOTH | PSP_BOTH_AB }, |
| 313 | { .type = AMD_FW_MPDMA_PM, .level = PSP_BOTH | PSP_BOTH_AB }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 314 | { .type = AMD_FW_AMF_SRAM, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 315 | { .type = AMD_FW_AMF_DRAM, .inst = 0, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 316 | { .type = AMD_FW_AMF_DRAM, .inst = 1, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 317 | { .type = AMD_FW_FCFG_TABLE, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 318 | { .type = AMD_FW_AMF_WLAN, .inst = 0, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 319 | { .type = AMD_FW_AMF_WLAN, .inst = 1, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 320 | { .type = AMD_FW_AMF_MFD, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 321 | { .type = AMD_TA_IKEK, .level = PSP_BOTH | PSP_LVL2_AB, .skip_hashing = true }, |
| 322 | { .type = AMD_FW_MPCCX, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 323 | { .type = AMD_FW_LSDMA, .level = PSP_LVL2 | PSP_LVL2_AB }, |
| 324 | { .type = AMD_FW_C20_MP, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 325 | { .type = AMD_FW_MINIMSMU, .inst = 0, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 326 | { .type = AMD_FW_MINIMSMU, .inst = 1, .level = PSP_BOTH | PSP_LVL2_AB }, |
| 327 | { .type = AMD_FW_SRAM_FW_EXT, .level = PSP_LVL2 | PSP_LVL2_AB }, |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 328 | { .type = AMD_FW_INVALID }, |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 329 | }; |
| 330 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 331 | amd_fw_entry amd_fw_table[] = { |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 332 | { .type = AMD_FW_XHCI }, |
| 333 | { .type = AMD_FW_IMC }, |
| 334 | { .type = AMD_FW_GEC }, |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 335 | { .type = AMD_FW_INVALID }, |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 336 | }; |
| 337 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 338 | amd_bios_entry amd_bios_table[] = { |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 339 | { .type = AMD_BIOS_RTM_PUBKEY, .inst = 0, .level = BDT_BOTH }, |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 340 | { .type = AMD_BIOS_SIG, .inst = 0, .level = BDT_BOTH }, |
Marshall Dawson | 0581bf6 | 2019-09-25 11:03:53 -0600 | [diff] [blame] | 341 | { .type = AMD_BIOS_APCB, .inst = 0, .level = BDT_BOTH }, |
| 342 | { .type = AMD_BIOS_APCB, .inst = 1, .level = BDT_BOTH }, |
| 343 | { .type = AMD_BIOS_APCB, .inst = 2, .level = BDT_BOTH }, |
| 344 | { .type = AMD_BIOS_APCB, .inst = 3, .level = BDT_BOTH }, |
| 345 | { .type = AMD_BIOS_APCB, .inst = 4, .level = BDT_BOTH }, |
Rob Barnes | 18fd26c | 2020-03-03 10:35:02 -0700 | [diff] [blame] | 346 | { .type = AMD_BIOS_APCB, .inst = 5, .level = BDT_BOTH }, |
| 347 | { .type = AMD_BIOS_APCB, .inst = 6, .level = BDT_BOTH }, |
| 348 | { .type = AMD_BIOS_APCB, .inst = 7, .level = BDT_BOTH }, |
| 349 | { .type = AMD_BIOS_APCB, .inst = 8, .level = BDT_BOTH }, |
| 350 | { .type = AMD_BIOS_APCB, .inst = 9, .level = BDT_BOTH }, |
| 351 | { .type = AMD_BIOS_APCB, .inst = 10, .level = BDT_BOTH }, |
| 352 | { .type = AMD_BIOS_APCB, .inst = 11, .level = BDT_BOTH }, |
| 353 | { .type = AMD_BIOS_APCB, .inst = 12, .level = BDT_BOTH }, |
| 354 | { .type = AMD_BIOS_APCB, .inst = 13, .level = BDT_BOTH }, |
| 355 | { .type = AMD_BIOS_APCB, .inst = 14, .level = BDT_BOTH }, |
| 356 | { .type = AMD_BIOS_APCB, .inst = 15, .level = BDT_BOTH }, |
Marshall Dawson | 2dd3b5c | 2020-01-03 17:57:48 -0700 | [diff] [blame] | 357 | { .type = AMD_BIOS_APCB_BK, .inst = 0, .level = BDT_BOTH }, |
| 358 | { .type = AMD_BIOS_APCB_BK, .inst = 1, .level = BDT_BOTH }, |
| 359 | { .type = AMD_BIOS_APCB_BK, .inst = 2, .level = BDT_BOTH }, |
| 360 | { .type = AMD_BIOS_APCB_BK, .inst = 3, .level = BDT_BOTH }, |
| 361 | { .type = AMD_BIOS_APCB_BK, .inst = 4, .level = BDT_BOTH }, |
Rob Barnes | 18fd26c | 2020-03-03 10:35:02 -0700 | [diff] [blame] | 362 | { .type = AMD_BIOS_APCB_BK, .inst = 5, .level = BDT_BOTH }, |
| 363 | { .type = AMD_BIOS_APCB_BK, .inst = 6, .level = BDT_BOTH }, |
| 364 | { .type = AMD_BIOS_APCB_BK, .inst = 7, .level = BDT_BOTH }, |
| 365 | { .type = AMD_BIOS_APCB_BK, .inst = 8, .level = BDT_BOTH }, |
| 366 | { .type = AMD_BIOS_APCB_BK, .inst = 9, .level = BDT_BOTH }, |
| 367 | { .type = AMD_BIOS_APCB_BK, .inst = 10, .level = BDT_BOTH }, |
| 368 | { .type = AMD_BIOS_APCB_BK, .inst = 11, .level = BDT_BOTH }, |
| 369 | { .type = AMD_BIOS_APCB_BK, .inst = 12, .level = BDT_BOTH }, |
| 370 | { .type = AMD_BIOS_APCB_BK, .inst = 13, .level = BDT_BOTH }, |
| 371 | { .type = AMD_BIOS_APCB_BK, .inst = 14, .level = BDT_BOTH }, |
| 372 | { .type = AMD_BIOS_APCB_BK, .inst = 15, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 373 | { .type = AMD_BIOS_APOB, .level = BDT_BOTH }, |
| 374 | { .type = AMD_BIOS_BIN, |
Zheng Bao | 3d426f3 | 2022-10-16 20:34:57 +0800 | [diff] [blame] | 375 | .reset = 1, .copy = 1, .zlib = 1, .inst = 0, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 376 | { .type = AMD_BIOS_APOB_NV, .level = BDT_LVL2 }, |
| 377 | { .type = AMD_BIOS_PMUI, .inst = 1, .subpr = 0, .level = BDT_BOTH }, |
| 378 | { .type = AMD_BIOS_PMUD, .inst = 1, .subpr = 0, .level = BDT_BOTH }, |
Zheng Bao | e220faa | 2022-02-17 17:22:15 +0800 | [diff] [blame] | 379 | { .type = AMD_BIOS_PMUI, .inst = 2, .subpr = 0, .level = BDT_BOTH }, |
| 380 | { .type = AMD_BIOS_PMUD, .inst = 2, .subpr = 0, .level = BDT_BOTH }, |
Arthur Heymans | a83c502 | 2022-10-04 20:37:10 +0200 | [diff] [blame] | 381 | { .type = AMD_BIOS_PMUI, .inst = 3, .subpr = 0, .level = BDT_BOTH }, |
| 382 | { .type = AMD_BIOS_PMUD, .inst = 3, .subpr = 0, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 383 | { .type = AMD_BIOS_PMUI, .inst = 4, .subpr = 0, .level = BDT_BOTH }, |
| 384 | { .type = AMD_BIOS_PMUD, .inst = 4, .subpr = 0, .level = BDT_BOTH }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 385 | { .type = AMD_BIOS_PMUI, .inst = 5, .subpr = 0, .level = BDT_BOTH }, |
| 386 | { .type = AMD_BIOS_PMUD, .inst = 5, .subpr = 0, .level = BDT_BOTH }, |
| 387 | { .type = AMD_BIOS_PMUI, .inst = 6, .subpr = 0, .level = BDT_BOTH }, |
| 388 | { .type = AMD_BIOS_PMUD, .inst = 6, .subpr = 0, .level = BDT_BOTH }, |
| 389 | { .type = AMD_BIOS_PMUI, .inst = 7, .subpr = 0, .level = BDT_BOTH }, |
| 390 | { .type = AMD_BIOS_PMUD, .inst = 7, .subpr = 0, .level = BDT_BOTH }, |
Arthur Heymans | a83c502 | 2022-10-04 20:37:10 +0200 | [diff] [blame] | 391 | { .type = AMD_BIOS_PMUI, .inst = 9, .subpr = 0, .level = BDT_BOTH }, |
| 392 | { .type = AMD_BIOS_PMUD, .inst = 9, .subpr = 0, .level = BDT_BOTH }, |
| 393 | { .type = AMD_BIOS_PMUI, .inst = 10, .subpr = 0, .level = BDT_BOTH }, |
| 394 | { .type = AMD_BIOS_PMUD, .inst = 10, .subpr = 0, .level = BDT_BOTH }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 395 | { .type = AMD_BIOS_PMUI, .inst = 11, .subpr = 0, .level = BDT_BOTH }, |
| 396 | { .type = AMD_BIOS_PMUD, .inst = 11, .subpr = 0, .level = BDT_BOTH }, |
| 397 | { .type = AMD_BIOS_PMUI, .inst = 12, .subpr = 0, .level = BDT_BOTH }, |
| 398 | { .type = AMD_BIOS_PMUD, .inst = 12, .subpr = 0, .level = BDT_BOTH }, |
| 399 | { .type = AMD_BIOS_PMUI, .inst = 13, .subpr = 0, .level = BDT_BOTH }, |
| 400 | { .type = AMD_BIOS_PMUD, .inst = 13, .subpr = 0, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 401 | { .type = AMD_BIOS_PMUI, .inst = 1, .subpr = 1, .level = BDT_BOTH }, |
| 402 | { .type = AMD_BIOS_PMUD, .inst = 1, .subpr = 1, .level = BDT_BOTH }, |
Zheng Bao | e220faa | 2022-02-17 17:22:15 +0800 | [diff] [blame] | 403 | { .type = AMD_BIOS_PMUI, .inst = 2, .subpr = 1, .level = BDT_BOTH }, |
| 404 | { .type = AMD_BIOS_PMUD, .inst = 2, .subpr = 1, .level = BDT_BOTH }, |
Arthur Heymans | a83c502 | 2022-10-04 20:37:10 +0200 | [diff] [blame] | 405 | { .type = AMD_BIOS_PMUI, .inst = 3, .subpr = 1, .level = BDT_BOTH }, |
| 406 | { .type = AMD_BIOS_PMUD, .inst = 3, .subpr = 1, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 407 | { .type = AMD_BIOS_PMUI, .inst = 4, .subpr = 1, .level = BDT_BOTH }, |
| 408 | { .type = AMD_BIOS_PMUD, .inst = 4, .subpr = 1, .level = BDT_BOTH }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 409 | { .type = AMD_BIOS_PMUI, .inst = 5, .subpr = 1, .level = BDT_BOTH }, |
| 410 | { .type = AMD_BIOS_PMUD, .inst = 5, .subpr = 1, .level = BDT_BOTH }, |
| 411 | { .type = AMD_BIOS_PMUI, .inst = 6, .subpr = 1, .level = BDT_BOTH }, |
| 412 | { .type = AMD_BIOS_PMUD, .inst = 6, .subpr = 1, .level = BDT_BOTH }, |
| 413 | { .type = AMD_BIOS_PMUI, .inst = 7, .subpr = 1, .level = BDT_BOTH }, |
| 414 | { .type = AMD_BIOS_PMUD, .inst = 7, .subpr = 1, .level = BDT_BOTH }, |
Arthur Heymans | a83c502 | 2022-10-04 20:37:10 +0200 | [diff] [blame] | 415 | { .type = AMD_BIOS_PMUI, .inst = 9, .subpr = 1, .level = BDT_BOTH }, |
| 416 | { .type = AMD_BIOS_PMUD, .inst = 9, .subpr = 1, .level = BDT_BOTH }, |
| 417 | { .type = AMD_BIOS_PMUI, .inst = 10, .subpr = 1, .level = BDT_BOTH }, |
| 418 | { .type = AMD_BIOS_PMUD, .inst = 10, .subpr = 1, .level = BDT_BOTH }, |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 419 | { .type = AMD_BIOS_PMUI, .inst = 11, .subpr = 1, .level = BDT_BOTH }, |
| 420 | { .type = AMD_BIOS_PMUD, .inst = 11, .subpr = 1, .level = BDT_BOTH }, |
| 421 | { .type = AMD_BIOS_PMUI, .inst = 12, .subpr = 1, .level = BDT_BOTH }, |
| 422 | { .type = AMD_BIOS_PMUD, .inst = 12, .subpr = 1, .level = BDT_BOTH }, |
| 423 | { .type = AMD_BIOS_PMUI, .inst = 13, .subpr = 1, .level = BDT_BOTH }, |
| 424 | { .type = AMD_BIOS_PMUD, .inst = 13, .subpr = 1, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 425 | { .type = AMD_BIOS_UCODE, .inst = 0, .level = BDT_LVL2 }, |
| 426 | { .type = AMD_BIOS_UCODE, .inst = 1, .level = BDT_LVL2 }, |
| 427 | { .type = AMD_BIOS_UCODE, .inst = 2, .level = BDT_LVL2 }, |
Arthur Heymans | a83c502 | 2022-10-04 20:37:10 +0200 | [diff] [blame] | 428 | { .type = AMD_BIOS_UCODE, .inst = 3, .level = BDT_LVL2 }, |
| 429 | { .type = AMD_BIOS_UCODE, .inst = 4, .level = BDT_LVL2 }, |
| 430 | { .type = AMD_BIOS_UCODE, .inst = 5, .level = BDT_LVL2 }, |
| 431 | { .type = AMD_BIOS_UCODE, .inst = 6, .level = BDT_LVL2 }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 432 | { .type = AMD_BIOS_MP2_CFG, .level = BDT_LVL2 }, |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 433 | { .type = AMD_BIOS_PSP_SHARED_MEM, .inst = 0, .level = BDT_BOTH }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 434 | { .type = AMD_BIOS_INVALID }, |
| 435 | }; |
| 436 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 437 | typedef struct _context { |
| 438 | char *rom; /* target buffer, size of flash device */ |
| 439 | uint32_t rom_size; /* size of flash device */ |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 440 | uint32_t address_mode; /* 0:abs address; 1:relative to flash; 2: relative to table */ |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 441 | uint32_t current; /* pointer within flash & proxy buffer */ |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 442 | uint32_t current_table; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 443 | } context; |
| 444 | |
| 445 | #define RUN_BASE(ctx) (0xFFFFFFFF - (ctx).rom_size + 1) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 446 | #define RUN_OFFSET_MODE(ctx, offset, mode) \ |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 447 | ((mode) == AMD_ADDR_PHYSICAL ? RUN_BASE(ctx) + (offset) : \ |
| 448 | ((mode) == AMD_ADDR_REL_BIOS ? (offset) : \ |
| 449 | ((mode) == AMD_ADDR_REL_TAB ? (offset) - ctx.current_table : (offset)))) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 450 | #define RUN_OFFSET(ctx, offset) RUN_OFFSET_MODE((ctx), (offset), (ctx).address_mode) |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 451 | #define RUN_TO_OFFSET(ctx, run) ((ctx).address_mode == AMD_ADDR_PHYSICAL ? \ |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 452 | (run) - RUN_BASE(ctx) : (run)) /* TODO: */ |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 453 | #define RUN_CURRENT(ctx) RUN_OFFSET((ctx), (ctx).current) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 454 | /* The mode in entry can not be higher than the header's. |
| 455 | For example, if table mode is 0, all the entry mode will be 0. */ |
| 456 | #define RUN_CURRENT_MODE(ctx, mode) RUN_OFFSET_MODE((ctx), (ctx).current, \ |
| 457 | (ctx).address_mode < (mode) ? (ctx).address_mode : (mode)) |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 458 | #define BUFF_OFFSET(ctx, offset) ((void *)((ctx).rom + (offset))) |
| 459 | #define BUFF_CURRENT(ctx) BUFF_OFFSET((ctx), (ctx).current) |
| 460 | #define BUFF_TO_RUN(ctx, ptr) RUN_OFFSET((ctx), ((char *)(ptr) - (ctx).rom)) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 461 | #define BUFF_TO_RUN_MODE(ctx, ptr, mode) RUN_OFFSET_MODE((ctx), ((char *)(ptr) - (ctx).rom), \ |
| 462 | (ctx).address_mode < (mode) ? (ctx).address_mode : (mode)) |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 463 | #define BUFF_ROOM(ctx) ((ctx).rom_size - (ctx).current) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 464 | /* Only set the address mode in entry if the table is mode 2. */ |
| 465 | #define SET_ADDR_MODE(table, mode) \ |
| 466 | ((table)->header.additional_info_fields.address_mode == \ |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 467 | AMD_ADDR_REL_TAB ? (mode) : 0) |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 468 | #define SET_ADDR_MODE_BY_TABLE(table) \ |
| 469 | SET_ADDR_MODE((table), (table)->header.additional_info_fields.address_mode) |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 470 | |
Zheng Bao | 5164e4b | 2021-10-30 12:09:07 +0800 | [diff] [blame] | 471 | void assert_fw_entry(uint32_t count, uint32_t max, context *ctx) |
| 472 | { |
| 473 | if (count >= max) { |
| 474 | fprintf(stderr, "Error: BIOS entries (%d) exceeds max allowed items " |
| 475 | "(%d)\n", count, max); |
| 476 | free(ctx->rom); |
| 477 | exit(1); |
| 478 | } |
| 479 | } |
| 480 | |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 481 | static void *new_psp_dir(context *ctx, int multi) |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 482 | { |
| 483 | void *ptr; |
| 484 | |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 485 | /* |
| 486 | * Force both onto boundary when multi. Primary table is after |
| 487 | * updatable table, so alignment ensures primary can stay intact |
| 488 | * if secondary is reprogrammed. |
| 489 | */ |
| 490 | if (multi) |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 491 | ctx->current = ALIGN_UP(ctx->current, TABLE_ERASE_ALIGNMENT); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 492 | else |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 493 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 494 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 495 | ptr = BUFF_CURRENT(*ctx); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 496 | ((psp_directory_header *)ptr)->num_entries = 0; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 497 | ((psp_directory_header *)ptr)->additional_info = 0; |
| 498 | ((psp_directory_header *)ptr)->additional_info_fields.address_mode = ctx->address_mode; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 499 | ctx->current += sizeof(psp_directory_header) |
| 500 | + MAX_PSP_ENTRIES * sizeof(psp_directory_entry); |
| 501 | return ptr; |
| 502 | } |
| 503 | |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 504 | static void *new_ish_dir(context *ctx) |
| 505 | { |
| 506 | void *ptr; |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 507 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 508 | ptr = BUFF_CURRENT(*ctx); |
| 509 | ctx->current += TABLE_ALIGNMENT; |
| 510 | return ptr; |
| 511 | } |
| 512 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 513 | static void *new_combo_dir(context *ctx) |
| 514 | { |
| 515 | void *ptr; |
| 516 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 517 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 518 | ptr = BUFF_CURRENT(*ctx); |
| 519 | ctx->current += sizeof(psp_combo_header) |
| 520 | + MAX_COMBO_ENTRIES * sizeof(psp_combo_entry); |
| 521 | return ptr; |
| 522 | } |
| 523 | |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 524 | static void fill_dir_header(void *directory, uint32_t count, uint32_t cookie, context *ctx) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 525 | { |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 526 | psp_combo_directory *cdir = directory; |
| 527 | psp_directory_table *dir = directory; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 528 | bios_directory_table *bdir = directory; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 529 | uint32_t table_size = 0; |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 530 | |
| 531 | if (!count) |
| 532 | return; |
Zheng Bao | b035f58 | 2021-05-27 11:26:12 +0800 | [diff] [blame] | 533 | if (ctx == NULL || directory == NULL) { |
| 534 | fprintf(stderr, "Calling %s with NULL pointers\n", __func__); |
| 535 | return; |
| 536 | } |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 537 | |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 538 | /* The table size needs to be 0x1000 aligned. So align the end of table. */ |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 539 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 540 | |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 541 | switch (cookie) { |
| 542 | case PSP2_COOKIE: |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 543 | /* caller is responsible for lookup mode */ |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 544 | cdir->header.cookie = cookie; |
| 545 | cdir->header.num_entries = count; |
| 546 | cdir->header.reserved[0] = 0; |
| 547 | cdir->header.reserved[1] = 0; |
| 548 | /* checksum everything that comes after the Checksum field */ |
| 549 | cdir->header.checksum = fletcher32(&cdir->header.num_entries, |
| 550 | count * sizeof(psp_combo_entry) |
| 551 | + sizeof(cdir->header.num_entries) |
| 552 | + sizeof(cdir->header.lookup) |
| 553 | + 2 * sizeof(cdir->header.reserved[0])); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 554 | break; |
| 555 | case PSP_COOKIE: |
| 556 | case PSPL2_COOKIE: |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 557 | table_size = ctx->current - ctx->current_table; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 558 | if ((table_size % TABLE_ALIGNMENT) != 0) { |
| 559 | fprintf(stderr, "The PSP table size should be 4K aligned\n"); |
| 560 | exit(1); |
| 561 | } |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 562 | dir->header.cookie = cookie; |
| 563 | dir->header.num_entries = count; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 564 | dir->header.additional_info_fields.dir_size = table_size / TABLE_ALIGNMENT; |
| 565 | dir->header.additional_info_fields.spi_block_size = 1; |
| 566 | dir->header.additional_info_fields.base_addr = 0; |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 567 | /* checksum everything that comes after the Checksum field */ |
| 568 | dir->header.checksum = fletcher32(&dir->header.num_entries, |
Marshall Dawson | 8a45a4d | 2019-02-24 07:18:44 -0700 | [diff] [blame] | 569 | count * sizeof(psp_directory_entry) |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 570 | + sizeof(dir->header.num_entries) |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 571 | + sizeof(dir->header.additional_info)); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 572 | break; |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 573 | case BHD_COOKIE: |
| 574 | case BHDL2_COOKIE: |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 575 | table_size = ctx->current - ctx->current_table; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 576 | if ((table_size % TABLE_ALIGNMENT) != 0) { |
| 577 | fprintf(stderr, "The BIOS table size should be 4K aligned\n"); |
| 578 | exit(1); |
| 579 | } |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 580 | bdir->header.cookie = cookie; |
| 581 | bdir->header.num_entries = count; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 582 | bdir->header.additional_info_fields.dir_size = table_size / TABLE_ALIGNMENT; |
| 583 | bdir->header.additional_info_fields.spi_block_size = 1; |
| 584 | bdir->header.additional_info_fields.base_addr = 0; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 585 | /* checksum everything that comes after the Checksum field */ |
| 586 | bdir->header.checksum = fletcher32(&bdir->header.num_entries, |
| 587 | count * sizeof(bios_directory_entry) |
| 588 | + sizeof(bdir->header.num_entries) |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 589 | + sizeof(bdir->header.additional_info)); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 590 | break; |
Marshall Dawson | a378c22 | 2019-03-04 16:52:07 -0700 | [diff] [blame] | 591 | } |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 592 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 593 | } |
| 594 | |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 595 | static ssize_t copy_blob(void *dest, const char *src_file, size_t room) |
| 596 | { |
| 597 | int fd; |
| 598 | struct stat fd_stat; |
| 599 | ssize_t bytes; |
| 600 | |
| 601 | fd = open(src_file, O_RDONLY); |
| 602 | if (fd < 0) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 603 | fprintf(stderr, "Error opening file: %s: %s\n", |
Eric Peers | af50567 | 2020-03-05 16:04:15 -0700 | [diff] [blame] | 604 | src_file, strerror(errno)); |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 605 | return -1; |
| 606 | } |
| 607 | |
| 608 | if (fstat(fd, &fd_stat)) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 609 | fprintf(stderr, "fstat error: %s\n", strerror(errno)); |
Jacob Garber | 967f862 | 2019-07-02 10:35:10 -0600 | [diff] [blame] | 610 | close(fd); |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 611 | return -2; |
| 612 | } |
| 613 | |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 614 | if ((size_t)fd_stat.st_size > room) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 615 | fprintf(stderr, "Error: %s will not fit. Exiting.\n", src_file); |
Jacob Garber | 967f862 | 2019-07-02 10:35:10 -0600 | [diff] [blame] | 616 | close(fd); |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 617 | return -3; |
| 618 | } |
| 619 | |
| 620 | bytes = read(fd, dest, (size_t)fd_stat.st_size); |
| 621 | close(fd); |
| 622 | if (bytes != (ssize_t)fd_stat.st_size) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 623 | fprintf(stderr, "Error while reading %s\n", src_file); |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 624 | return -4; |
| 625 | } |
| 626 | |
| 627 | return bytes; |
| 628 | } |
| 629 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 630 | static ssize_t read_from_file_to_buf(int fd, void *buf, size_t buf_size) |
| 631 | { |
| 632 | ssize_t bytes; |
| 633 | size_t total_bytes = 0; |
| 634 | |
| 635 | do { |
| 636 | bytes = read(fd, buf + total_bytes, buf_size - total_bytes); |
| 637 | if (bytes == 0) { |
| 638 | fprintf(stderr, "Reached EOF probably\n"); |
| 639 | break; |
| 640 | } |
| 641 | |
| 642 | if (bytes < 0 && errno == EAGAIN) |
| 643 | bytes = 0; |
| 644 | |
| 645 | if (bytes < 0) { |
| 646 | fprintf(stderr, "Read failure %s\n", strerror(errno)); |
| 647 | return bytes; |
| 648 | } |
| 649 | |
| 650 | total_bytes += bytes; |
| 651 | } while (total_bytes < buf_size); |
| 652 | |
| 653 | if (total_bytes != buf_size) { |
| 654 | fprintf(stderr, "Read data size(%zu) != buffer size(%zu)\n", |
| 655 | total_bytes, buf_size); |
| 656 | return -1; |
| 657 | } |
| 658 | return buf_size; |
| 659 | } |
| 660 | |
| 661 | static ssize_t write_from_buf_to_file(int fd, const void *buf, size_t buf_size) |
| 662 | { |
| 663 | ssize_t bytes; |
| 664 | size_t total_bytes = 0; |
| 665 | |
| 666 | do { |
| 667 | bytes = write(fd, buf + total_bytes, buf_size - total_bytes); |
| 668 | if (bytes < 0 && errno == EAGAIN) |
| 669 | bytes = 0; |
| 670 | |
| 671 | if (bytes < 0) { |
| 672 | fprintf(stderr, "Write failure %s\n", strerror(errno)); |
| 673 | lseek(fd, SEEK_CUR, -total_bytes); |
| 674 | return bytes; |
| 675 | } |
| 676 | |
| 677 | total_bytes += bytes; |
| 678 | } while (total_bytes < buf_size); |
| 679 | |
| 680 | if (total_bytes != buf_size) { |
| 681 | fprintf(stderr, "Wrote more data(%zu) than buffer size(%zu)\n", |
| 682 | total_bytes, buf_size); |
| 683 | lseek(fd, SEEK_CUR, -total_bytes); |
| 684 | return -1; |
| 685 | } |
| 686 | |
| 687 | return buf_size; |
| 688 | } |
| 689 | |
Zheng Bao | eb0404e | 2021-10-14 15:09:09 +0800 | [diff] [blame] | 690 | enum platform { |
| 691 | PLATFORM_UNKNOWN, |
| 692 | PLATFORM_STONEYRIDGE, |
| 693 | PLATFORM_RAVEN, |
| 694 | PLATFORM_PICASSO, |
| 695 | PLATFORM_RENOIR, |
| 696 | PLATFORM_CEZANNE, |
| 697 | PLATFORM_MENDOCINO, |
| 698 | PLATFORM_LUCIENNE, |
Martin Roth | 20646cd | 2023-01-04 21:27:06 -0700 | [diff] [blame] | 699 | PLATFORM_PHOENIX, |
Martin Roth | 1349083 | 2022-10-06 17:18:02 -0600 | [diff] [blame] | 700 | PLATFORM_GLINDA |
Zheng Bao | eb0404e | 2021-10-14 15:09:09 +0800 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | static uint32_t get_psp_id(enum platform soc_id) |
| 704 | { |
| 705 | uint32_t psp_id; |
| 706 | switch (soc_id) { |
| 707 | case PLATFORM_RAVEN: |
| 708 | case PLATFORM_PICASSO: |
| 709 | psp_id = 0xBC0A0000; |
| 710 | break; |
| 711 | case PLATFORM_RENOIR: |
| 712 | case PLATFORM_LUCIENNE: |
| 713 | psp_id = 0xBC0C0000; |
| 714 | break; |
| 715 | case PLATFORM_CEZANNE: |
| 716 | psp_id = 0xBC0C0140; |
| 717 | break; |
| 718 | case PLATFORM_MENDOCINO: |
| 719 | psp_id = 0xBC0D0900; |
| 720 | break; |
| 721 | case PLATFORM_STONEYRIDGE: |
| 722 | psp_id = 0x10220B00; |
| 723 | break; |
Zheng Bao | de6f198 | 2022-10-16 20:32:43 +0800 | [diff] [blame] | 724 | case PLATFORM_GLINDA: |
| 725 | psp_id = 0xBC0E0200; |
| 726 | break; |
| 727 | case PLATFORM_PHOENIX: |
| 728 | psp_id = 0xBC0D0400; |
| 729 | break; |
Zheng Bao | eb0404e | 2021-10-14 15:09:09 +0800 | [diff] [blame] | 730 | default: |
| 731 | psp_id = 0; |
| 732 | break; |
| 733 | } |
| 734 | return psp_id; |
| 735 | } |
| 736 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 737 | static uint16_t get_psp_fw_type(enum platform soc_id, struct amd_fw_header *header) |
| 738 | { |
| 739 | switch (soc_id) { |
| 740 | case PLATFORM_MENDOCINO: |
| 741 | /* Fallback to fw_type if fw_id is not populated, which serves the same |
| 742 | purpose on older SoCs. */ |
| 743 | return header->fw_id ? header->fw_id : header->fw_type; |
| 744 | default: |
| 745 | return header->fw_type; |
| 746 | } |
| 747 | } |
| 748 | |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 749 | static int add_single_sha(amd_fw_entry_hash *entry, void *buf, enum platform soc_id) |
| 750 | { |
| 751 | uint8_t hash[SHA384_DIGEST_LENGTH]; |
| 752 | struct amd_fw_header *header = (struct amd_fw_header *)buf; |
| 753 | /* Include only signed part for hash calculation. */ |
| 754 | size_t len = header->fw_size_signed + sizeof(struct amd_fw_header); |
| 755 | uint8_t *body = (uint8_t *)buf; |
| 756 | |
| 757 | if (len > header->size_total) |
| 758 | return -1; |
| 759 | |
| 760 | if (header->sig_id == SIG_ID_RSA4096) { |
| 761 | SHA384(body, len, hash); |
| 762 | entry->sha_len = SHA384_DIGEST_LENGTH; |
| 763 | } else if (header->sig_id == SIG_ID_RSA2048) { |
| 764 | SHA256(body, len, hash); |
| 765 | entry->sha_len = SHA256_DIGEST_LENGTH; |
| 766 | } else { |
| 767 | fprintf(stderr, "%s: Unknown signature id: 0x%08x\n", |
| 768 | __func__, header->sig_id); |
| 769 | return -1; |
| 770 | } |
| 771 | |
| 772 | memcpy(entry->sha, hash, entry->sha_len); |
| 773 | entry->fw_id = get_psp_fw_type(soc_id, header); |
| 774 | entry->subtype = header->fw_subtype; |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | static int get_num_binaries(void *buf, size_t buf_size) |
| 780 | { |
| 781 | struct amd_fw_header *header = (struct amd_fw_header *)buf; |
| 782 | size_t total_len = 0; |
| 783 | int num_binaries = 0; |
| 784 | |
| 785 | while (total_len < buf_size) { |
| 786 | num_binaries++; |
| 787 | total_len += header->size_total; |
| 788 | header = (struct amd_fw_header *)(buf + total_len); |
| 789 | } |
| 790 | |
| 791 | if (total_len != buf_size) { |
| 792 | fprintf(stderr, "Malformed binary\n"); |
| 793 | return -1; |
| 794 | } |
| 795 | return num_binaries; |
| 796 | } |
| 797 | |
| 798 | static int add_sha(amd_fw_entry *entry, void *buf, size_t buf_size, enum platform soc_id) |
| 799 | { |
| 800 | struct amd_fw_header *header = (struct amd_fw_header *)buf; |
| 801 | /* Include only signed part for hash calculation. */ |
| 802 | size_t total_len = 0; |
| 803 | int num_binaries = get_num_binaries(buf, buf_size); |
| 804 | |
| 805 | if (num_binaries <= 0) |
| 806 | return num_binaries; |
| 807 | |
| 808 | entry->hash_entries = malloc(num_binaries * sizeof(amd_fw_entry_hash)); |
| 809 | if (!entry->hash_entries) { |
| 810 | fprintf(stderr, "Error allocating memory to add FW hash\n"); |
| 811 | return -1; |
| 812 | } |
| 813 | entry->num_hash_entries = num_binaries; |
| 814 | |
| 815 | /* Iterate through each binary */ |
| 816 | for (int i = 0; i < num_binaries; i++) { |
| 817 | if (add_single_sha(&entry->hash_entries[i], buf + total_len, soc_id)) { |
| 818 | free(entry->hash_entries); |
| 819 | return -1; |
| 820 | } |
| 821 | total_len += header->size_total; |
| 822 | header = (struct amd_fw_header *)(buf + total_len); |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 828 | static void integrate_firmwares(context *ctx, |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 829 | embedded_firmware *romsig, |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 830 | amd_fw_entry *fw_table) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 831 | { |
Richard Spiegel | 137484d | 2018-01-17 10:23:19 -0700 | [diff] [blame] | 832 | ssize_t bytes; |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 833 | uint32_t i; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 834 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 835 | ctx->current = ALIGN_UP(ctx->current, BLOB_ALIGNMENT); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 836 | |
Martin Roth | cd15bc8 | 2016-11-08 11:34:02 -0700 | [diff] [blame] | 837 | for (i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 838 | if (fw_table[i].filename != NULL) { |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 839 | switch (fw_table[i].type) { |
| 840 | case AMD_FW_IMC: |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 841 | ctx->current = ALIGN_UP(ctx->current, 0x10000U); |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 842 | romsig->imc_entry = RUN_CURRENT(*ctx); |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 843 | break; |
| 844 | case AMD_FW_GEC: |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 845 | romsig->gec_entry = RUN_CURRENT(*ctx); |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 846 | break; |
| 847 | case AMD_FW_XHCI: |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 848 | romsig->xhci_entry = RUN_CURRENT(*ctx); |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 849 | break; |
| 850 | default: |
| 851 | /* Error */ |
| 852 | break; |
| 853 | } |
| 854 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 855 | bytes = copy_blob(BUFF_CURRENT(*ctx), |
| 856 | fw_table[i].filename, BUFF_ROOM(*ctx)); |
Marshall Dawson | 02bd773 | 2019-03-13 14:43:17 -0600 | [diff] [blame] | 857 | if (bytes < 0) { |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 858 | free(ctx->rom); |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 859 | exit(1); |
| 860 | } |
| 861 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 862 | ctx->current = ALIGN_UP(ctx->current + bytes, |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 863 | BLOB_ALIGNMENT); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 864 | } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 865 | } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 866 | } |
| 867 | |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 868 | /* For debugging */ |
| 869 | static void dump_psp_firmwares(amd_fw_entry *fw_table) |
| 870 | { |
| 871 | amd_fw_entry *index; |
| 872 | |
| 873 | printf("PSP firmware components:"); |
| 874 | for (index = fw_table; index->type != AMD_FW_INVALID; index++) { |
| 875 | if (index->filename) |
Zheng Bao | 826f1c4 | 2021-05-25 16:26:55 +0800 | [diff] [blame] | 876 | printf(" %2x: %s\n", index->type, index->filename); |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | static void dump_bdt_firmwares(amd_bios_entry *fw_table) |
| 881 | { |
| 882 | amd_bios_entry *index; |
| 883 | |
| 884 | printf("BIOS Directory Table (BDT) components:"); |
| 885 | for (index = fw_table; index->type != AMD_BIOS_INVALID; index++) { |
| 886 | if (index->filename) |
Zheng Bao | 826f1c4 | 2021-05-25 16:26:55 +0800 | [diff] [blame] | 887 | printf(" %2x: %s\n", index->type, index->filename); |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 891 | static void free_psp_firmware_filenames(amd_fw_entry *fw_table) |
| 892 | { |
| 893 | amd_fw_entry *index; |
| 894 | |
| 895 | for (index = fw_table; index->type != AMD_FW_INVALID; index++) { |
| 896 | if (index->filename && |
| 897 | index->type != AMD_FW_VERSTAGE_SIG && |
| 898 | index->type != AMD_FW_PSP_VERSTAGE && |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 899 | index->type != AMD_FW_SPL && |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 900 | index->type != AMD_FW_PSP_WHITELIST) { |
| 901 | free(index->filename); |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | static void free_bdt_firmware_filenames(amd_bios_entry *fw_table) |
| 907 | { |
| 908 | amd_bios_entry *index; |
| 909 | |
| 910 | for (index = fw_table; index->type != AMD_BIOS_INVALID; index++) { |
| 911 | if (index->filename && |
| 912 | index->type != AMD_BIOS_APCB && |
| 913 | index->type != AMD_BIOS_BIN && |
Arthur Heymans | 1cffc55 | 2022-10-19 20:08:35 +0200 | [diff] [blame] | 914 | index->type != AMD_BIOS_APCB_BK && |
| 915 | index->type != AMD_BIOS_UCODE) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 916 | free(index->filename); |
| 917 | } |
| 918 | } |
| 919 | |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 920 | static void write_or_fail(int fd, void *ptr, size_t size) |
| 921 | { |
| 922 | ssize_t written; |
| 923 | |
| 924 | written = write_from_buf_to_file(fd, ptr, size); |
| 925 | if (written < 0 || (size_t)written != size) { |
| 926 | fprintf(stderr, "%s: Error writing %zu bytes - written %zd bytes\n", |
| 927 | __func__, size, written); |
| 928 | exit(-1); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | static void write_one_psp_firmware_hash_entry(int fd, amd_fw_entry_hash *entry) |
| 933 | { |
| 934 | uint16_t type = entry->fw_id; |
| 935 | uint16_t subtype = entry->subtype; |
| 936 | |
| 937 | write_or_fail(fd, &type, sizeof(type)); |
| 938 | write_or_fail(fd, &subtype, sizeof(subtype)); |
| 939 | write_or_fail(fd, entry->sha, entry->sha_len); |
| 940 | } |
| 941 | |
| 942 | static void write_psp_firmware_hash(const char *filename, |
| 943 | amd_fw_entry *fw_table) |
| 944 | { |
| 945 | struct psp_fw_hash_table hash_header = {0}; |
| 946 | int fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666); |
| 947 | |
| 948 | if (fd < 0) { |
| 949 | fprintf(stderr, "Error opening file: %s: %s\n", |
| 950 | filename, strerror(errno)); |
| 951 | exit(-1); |
| 952 | } |
| 953 | |
| 954 | hash_header.version = HASH_HDR_V1; |
| 955 | for (unsigned int i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
| 956 | for (unsigned int j = 0; j < fw_table[i].num_hash_entries; j++) { |
| 957 | if (fw_table[i].hash_entries[j].sha_len == SHA256_DIGEST_LENGTH) { |
| 958 | hash_header.no_of_entries_256++; |
| 959 | } else if (fw_table[i].hash_entries[j].sha_len == |
| 960 | SHA384_DIGEST_LENGTH) { |
| 961 | hash_header.no_of_entries_384++; |
| 962 | } else if (fw_table[i].hash_entries[j].sha_len) { |
| 963 | fprintf(stderr, "%s: Error invalid sha_len %d\n", |
| 964 | __func__, fw_table[i].hash_entries[j].sha_len); |
| 965 | exit(-1); |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | write_or_fail(fd, &hash_header, sizeof(hash_header)); |
| 971 | |
| 972 | /* Add all the SHA256 hash entries first followed by SHA384 entries. PSP verstage |
| 973 | processes the table in that order. Mixing and matching SHA256 and SHA384 entries |
| 974 | will cause the hash verification failure at run-time. */ |
| 975 | for (unsigned int i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
| 976 | for (unsigned int j = 0; j < fw_table[i].num_hash_entries; j++) { |
| 977 | if (fw_table[i].hash_entries[j].sha_len == SHA256_DIGEST_LENGTH) |
| 978 | write_one_psp_firmware_hash_entry(fd, |
| 979 | &fw_table[i].hash_entries[j]); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | for (unsigned int i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
| 984 | for (unsigned int j = 0; j < fw_table[i].num_hash_entries; j++) { |
| 985 | if (fw_table[i].hash_entries[j].sha_len == SHA384_DIGEST_LENGTH) |
| 986 | write_one_psp_firmware_hash_entry(fd, |
| 987 | &fw_table[i].hash_entries[j]); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | close(fd); |
| 992 | for (unsigned int i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
| 993 | if (!fw_table[i].num_hash_entries || !fw_table[i].hash_entries) |
| 994 | continue; |
| 995 | |
| 996 | free(fw_table[i].hash_entries); |
| 997 | fw_table[i].hash_entries = NULL; |
| 998 | fw_table[i].num_hash_entries = 0; |
| 999 | } |
| 1000 | } |
| 1001 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1002 | /** |
| 1003 | * process_signed_psp_firmwares() - Process the signed PSP binaries to keep them separate |
| 1004 | * @signed_rom: Output file path grouping all the signed PSP binaries. |
| 1005 | * @fw_table: Table of all the PSP firmware entries/binaries to be processed. |
| 1006 | * @signed_start_addr: Offset of the FMAP section, within the flash device, to hold |
| 1007 | * the signed PSP binaries. |
| 1008 | * @soc_id: SoC ID of the PSP binaries. |
| 1009 | */ |
| 1010 | static void process_signed_psp_firmwares(const char *signed_rom, |
| 1011 | amd_fw_entry *fw_table, |
| 1012 | uint64_t signed_start_addr, |
| 1013 | enum platform soc_id) |
| 1014 | { |
| 1015 | unsigned int i; |
| 1016 | int fd; |
| 1017 | int signed_rom_fd; |
| 1018 | ssize_t bytes, align_bytes; |
| 1019 | uint8_t *buf; |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 1020 | char *signed_rom_hash; |
| 1021 | size_t signed_rom_hash_strlen; |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1022 | struct amd_fw_header header; |
| 1023 | struct stat fd_stat; |
| 1024 | /* Every blob in amdfw*.rom has to start at address aligned to 0x100. Prepare an |
| 1025 | alignment data with 0xff to pad the blobs and meet the alignment requirement. */ |
| 1026 | uint8_t align_data[BLOB_ALIGNMENT - 1]; |
| 1027 | |
| 1028 | memset(align_data, 0xff, sizeof(align_data)); |
| 1029 | signed_rom_fd = open(signed_rom, O_RDWR | O_CREAT | O_TRUNC, |
| 1030 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
| 1031 | if (signed_rom_fd < 0) { |
| 1032 | fprintf(stderr, "Error opening file: %s: %s\n", |
| 1033 | signed_rom, strerror(errno)); |
| 1034 | return; |
| 1035 | } |
| 1036 | |
| 1037 | for (i = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 1038 | fw_table[i].num_hash_entries = 0; |
| 1039 | fw_table[i].hash_entries = NULL; |
| 1040 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1041 | if (!(fw_table[i].filename) || fw_table[i].skip_hashing) |
| 1042 | continue; |
| 1043 | |
| 1044 | memset(&header, 0, sizeof(header)); |
| 1045 | |
| 1046 | fd = open(fw_table[i].filename, O_RDONLY); |
| 1047 | if (fd < 0) { |
| 1048 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1049 | fprintf(stderr, "Error opening file: %s: %s\n", |
| 1050 | fw_table[i].filename, strerror(errno)); |
| 1051 | continue; |
| 1052 | } |
| 1053 | |
| 1054 | if (fstat(fd, &fd_stat)) { |
| 1055 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1056 | fprintf(stderr, "fstat error: %s\n", strerror(errno)); |
| 1057 | close(fd); |
| 1058 | continue; |
| 1059 | } |
| 1060 | |
| 1061 | bytes = read_from_file_to_buf(fd, &header, sizeof(struct amd_fw_header)); |
| 1062 | if (bytes != (ssize_t)sizeof(struct amd_fw_header)) { |
| 1063 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1064 | fprintf(stderr, "%s: Error reading header from %s\n", |
| 1065 | __func__, fw_table[i].filename); |
| 1066 | close(fd); |
| 1067 | continue; |
| 1068 | } |
| 1069 | |
| 1070 | /* If firmware header looks like invalid, assume it's not signed */ |
| 1071 | if (!header.fw_type && !header.fw_id) { |
| 1072 | fprintf(stderr, "%s: Invalid FWID for %s\n", |
| 1073 | __func__, fw_table[i].filename); |
| 1074 | close(fd); |
| 1075 | continue; |
| 1076 | } |
| 1077 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1078 | |
| 1079 | /* PSP binary is not signed and should not be part of signed PSP binaries |
| 1080 | set. */ |
| 1081 | if (header.sig_opt != 1) { |
| 1082 | close(fd); |
| 1083 | continue; |
| 1084 | } |
| 1085 | |
| 1086 | buf = malloc(fd_stat.st_size); |
| 1087 | if (!buf) { |
| 1088 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1089 | fprintf(stderr, "%s: failed to allocate memory with size %lld\n", |
| 1090 | __func__, (long long)fd_stat.st_size); |
| 1091 | close(fd); |
| 1092 | continue; |
| 1093 | } |
| 1094 | |
| 1095 | lseek(fd, SEEK_SET, 0); |
| 1096 | bytes = read_from_file_to_buf(fd, buf, fd_stat.st_size); |
| 1097 | if (bytes != fd_stat.st_size) { |
| 1098 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1099 | fprintf(stderr, "%s: failed to read %s\n", |
| 1100 | __func__, fw_table[i].filename); |
| 1101 | free(buf); |
| 1102 | close(fd); |
| 1103 | continue; |
| 1104 | } |
| 1105 | |
| 1106 | bytes = write_from_buf_to_file(signed_rom_fd, buf, fd_stat.st_size); |
| 1107 | if (bytes != fd_stat.st_size) { |
| 1108 | /* Keep the file along with set of unsigned PSP binaries & continue. */ |
| 1109 | fprintf(stderr, "%s: failed to write %s\n", |
| 1110 | __func__, fw_table[i].filename); |
| 1111 | free(buf); |
| 1112 | close(fd); |
| 1113 | continue; |
| 1114 | } |
| 1115 | |
| 1116 | /* Write Blob alignment bytes */ |
| 1117 | align_bytes = 0; |
| 1118 | if (fd_stat.st_size & (BLOB_ALIGNMENT - 1)) { |
| 1119 | align_bytes = BLOB_ALIGNMENT - |
| 1120 | (fd_stat.st_size & (BLOB_ALIGNMENT - 1)); |
| 1121 | bytes = write_from_buf_to_file(signed_rom_fd, align_data, align_bytes); |
| 1122 | if (bytes != align_bytes) { |
| 1123 | fprintf(stderr, "%s: failed to write alignment data for %s\n", |
| 1124 | __func__, fw_table[i].filename); |
| 1125 | lseek(signed_rom_fd, SEEK_CUR, -fd_stat.st_size); |
| 1126 | free(buf); |
| 1127 | close(fd); |
| 1128 | continue; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 1132 | if (add_sha(&fw_table[i], buf, fd_stat.st_size, soc_id)) |
| 1133 | exit(-1); |
| 1134 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1135 | /* File is successfully processed and is part of signed PSP binaries set. */ |
| 1136 | fw_table[i].fw_id = get_psp_fw_type(soc_id, &header); |
| 1137 | fw_table[i].addr_signed = signed_start_addr; |
| 1138 | fw_table[i].file_size = (uint32_t)fd_stat.st_size; |
| 1139 | |
| 1140 | signed_start_addr += fd_stat.st_size + align_bytes; |
| 1141 | |
| 1142 | free(buf); |
| 1143 | close(fd); |
| 1144 | } |
| 1145 | |
| 1146 | close(signed_rom_fd); |
Kangheui Won | 5b84dfd | 2021-12-21 15:45:06 +1100 | [diff] [blame] | 1147 | |
| 1148 | /* signed_rom file name + ".hash" + '\0' */ |
| 1149 | signed_rom_hash_strlen = strlen(signed_rom) + strlen(HASH_FILE_SUFFIX) + 1; |
| 1150 | signed_rom_hash = malloc(signed_rom_hash_strlen); |
| 1151 | if (!signed_rom_hash) { |
| 1152 | fprintf(stderr, "malloc(%lu) failed\n", signed_rom_hash_strlen); |
| 1153 | exit(-1); |
| 1154 | } |
| 1155 | strcpy(signed_rom_hash, signed_rom); |
| 1156 | strcat(signed_rom_hash, HASH_FILE_SUFFIX); |
| 1157 | write_psp_firmware_hash(signed_rom_hash, fw_table); |
| 1158 | free(signed_rom_hash); |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1159 | } |
| 1160 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1161 | static void integrate_psp_ab(context *ctx, psp_directory_table *pspdir, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1162 | psp_directory_table *pspdir2, ish_directory_table *ish, |
| 1163 | amd_fw_type ab, enum platform soc_id) |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1164 | { |
| 1165 | uint32_t count; |
| 1166 | uint32_t current_table_save; |
| 1167 | |
| 1168 | current_table_save = ctx->current_table; |
| 1169 | ctx->current_table = (char *)pspdir - ctx->rom; |
| 1170 | count = pspdir->header.num_entries; |
| 1171 | assert_fw_entry(count, MAX_PSP_ENTRIES, ctx); |
| 1172 | pspdir->entries[count].type = (uint8_t)ab; |
| 1173 | pspdir->entries[count].subprog = 0; |
| 1174 | pspdir->entries[count].rsvd = 0; |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1175 | if (ish != NULL) { |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1176 | ish->pl2_location = BUFF_TO_RUN_MODE(*ctx, pspdir2, AMD_ADDR_REL_BIOS); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1177 | ish->boot_priority = ab == AMD_FW_RECOVERYAB_A ? 0xFFFFFFFF : 1; |
| 1178 | ish->update_retry_count = 2; |
| 1179 | ish->glitch_retry_count = 0; |
| 1180 | ish->psp_id = get_psp_id(soc_id); |
| 1181 | ish->checksum = fletcher32(&ish->boot_priority, |
| 1182 | sizeof(ish_directory_table) - sizeof(uint32_t)); |
| 1183 | pspdir->entries[count].addr = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1184 | BUFF_TO_RUN_MODE(*ctx, ish, AMD_ADDR_REL_BIOS); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1185 | pspdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1186 | SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1187 | pspdir->entries[count].size = TABLE_ALIGNMENT; |
| 1188 | } else { |
| 1189 | pspdir->entries[count].addr = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1190 | BUFF_TO_RUN_MODE(*ctx, pspdir2, AMD_ADDR_REL_BIOS); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1191 | pspdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1192 | SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1193 | pspdir->entries[count].size = pspdir2->header.num_entries * |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1194 | sizeof(psp_directory_entry) + |
| 1195 | sizeof(psp_directory_header); |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1196 | } |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1197 | |
| 1198 | count++; |
| 1199 | pspdir->header.num_entries = count; |
| 1200 | ctx->current_table = current_table_save; |
| 1201 | } |
| 1202 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 1203 | static void integrate_psp_firmwares(context *ctx, |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 1204 | psp_directory_table *pspdir, |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1205 | psp_directory_table *pspdir2, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1206 | psp_directory_table *pspdir2_b, |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1207 | amd_fw_entry *fw_table, |
Zheng Bao | 2079589 | 2021-08-20 14:58:22 +0800 | [diff] [blame] | 1208 | uint32_t cookie, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1209 | enum platform soc_id, |
Zheng Bao | 2079589 | 2021-08-20 14:58:22 +0800 | [diff] [blame] | 1210 | amd_cb_config *cb_config) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1211 | { |
Richard Spiegel | 137484d | 2018-01-17 10:23:19 -0700 | [diff] [blame] | 1212 | ssize_t bytes; |
Marshall Dawson | c38c0c9 | 2019-02-23 16:41:35 -0700 | [diff] [blame] | 1213 | unsigned int i, count; |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1214 | int level; |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1215 | uint32_t size; |
| 1216 | uint64_t addr; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1217 | uint32_t current_table_save; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1218 | bool recovery_ab = cb_config->recovery_ab; |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1219 | ish_directory_table *ish_a_dir = NULL, *ish_b_dir = NULL; |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1220 | |
| 1221 | /* This function can create a primary table, a secondary table, or a |
| 1222 | * flattened table which contains all applicable types. These if-else |
| 1223 | * statements infer what the caller intended. If a 2nd-level cookie |
| 1224 | * is passed, clearly a 2nd-level table is intended. However, a |
| 1225 | * 1st-level cookie may indicate level 1 or flattened. If the caller |
| 1226 | * passes a pointer to a 2nd-level table, then assume not flat. |
| 1227 | */ |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 1228 | if (!cb_config->multi_level) |
Zheng Bao | 2079589 | 2021-08-20 14:58:22 +0800 | [diff] [blame] | 1229 | level = PSP_BOTH; |
| 1230 | else if (cookie == PSPL2_COOKIE) |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1231 | level = PSP_LVL2; |
| 1232 | else if (pspdir2) |
| 1233 | level = PSP_LVL1; |
| 1234 | else |
| 1235 | level = PSP_BOTH; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 1236 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1237 | if (recovery_ab) { |
| 1238 | if (cookie == PSPL2_COOKIE) |
| 1239 | level = PSP_LVL2_AB; |
| 1240 | else if (pspdir2) |
| 1241 | level = PSP_LVL1_AB; |
| 1242 | else |
| 1243 | level = PSP_BOTH_AB; |
| 1244 | } |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1245 | current_table_save = ctx->current_table; |
| 1246 | ctx->current_table = (char *)pspdir - ctx->rom; |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1247 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1248 | |
Marshall Dawson | c38c0c9 | 2019-02-23 16:41:35 -0700 | [diff] [blame] | 1249 | for (i = 0, count = 0; fw_table[i].type != AMD_FW_INVALID; i++) { |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1250 | if (!(fw_table[i].level & level)) |
| 1251 | continue; |
| 1252 | |
Zheng Bao | 5164e4b | 2021-10-30 12:09:07 +0800 | [diff] [blame] | 1253 | assert_fw_entry(count, MAX_PSP_ENTRIES, ctx); |
| 1254 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1255 | if (fw_table[i].type == AMD_TOKEN_UNLOCK) { |
| 1256 | if (!fw_table[i].other) |
| 1257 | continue; |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1258 | ctx->current = ALIGN_UP(ctx->current, ERASE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1259 | pspdir->entries[count].type = fw_table[i].type; |
| 1260 | pspdir->entries[count].size = 4096; /* TODO: doc? */ |
| 1261 | pspdir->entries[count].addr = RUN_CURRENT(*ctx); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1262 | pspdir->entries[count].address_mode = SET_ADDR_MODE_BY_TABLE(pspdir); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1263 | pspdir->entries[count].subprog = fw_table[i].subprog; |
| 1264 | pspdir->entries[count].rsvd = 0; |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1265 | ctx->current = ALIGN_UP(ctx->current + 4096, 0x100U); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1266 | count++; |
| 1267 | } else if (fw_table[i].type == AMD_PSP_FUSE_CHAIN) { |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 1268 | pspdir->entries[count].type = fw_table[i].type; |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 1269 | pspdir->entries[count].subprog = fw_table[i].subprog; |
| 1270 | pspdir->entries[count].rsvd = 0; |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 1271 | pspdir->entries[count].size = 0xFFFFFFFF; |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 1272 | pspdir->entries[count].addr = fw_table[i].other; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1273 | pspdir->entries[count].address_mode = 0; |
Marshall Dawson | c38c0c9 | 2019-02-23 16:41:35 -0700 | [diff] [blame] | 1274 | count++; |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 1275 | } else if (fw_table[i].type == AMD_FW_PSP_NVRAM) { |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1276 | if (fw_table[i].filename == NULL) { |
| 1277 | if (fw_table[i].size == 0) |
| 1278 | continue; |
| 1279 | size = fw_table[i].size; |
| 1280 | addr = fw_table[i].dest; |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1281 | if (addr != ALIGN_UP(addr, ERASE_ALIGNMENT)) { |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1282 | fprintf(stderr, |
| 1283 | "Error: PSP NVRAM section not aligned with erase block size.\n\n"); |
| 1284 | exit(1); |
| 1285 | } |
| 1286 | } else { |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1287 | ctx->current = ALIGN_UP(ctx->current, ERASE_ALIGNMENT); |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1288 | bytes = copy_blob(BUFF_CURRENT(*ctx), |
| 1289 | fw_table[i].filename, BUFF_ROOM(*ctx)); |
| 1290 | if (bytes <= 0) { |
| 1291 | free(ctx->rom); |
| 1292 | exit(1); |
| 1293 | } |
| 1294 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1295 | size = ALIGN_UP(bytes, ERASE_ALIGNMENT); |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1296 | addr = RUN_CURRENT(*ctx); |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1297 | ctx->current = ALIGN_UP(ctx->current + bytes, |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1298 | BLOB_ERASE_ALIGNMENT); |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | pspdir->entries[count].type = fw_table[i].type; |
| 1302 | pspdir->entries[count].subprog = fw_table[i].subprog; |
| 1303 | pspdir->entries[count].rsvd = 0; |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1304 | pspdir->entries[count].size = size; |
| 1305 | pspdir->entries[count].addr = addr; |
| 1306 | |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1307 | pspdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1308 | SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 1309 | |
Marshall Dawson | 7c1e142 | 2019-04-11 09:44:43 -0600 | [diff] [blame] | 1310 | count++; |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 1311 | } else if (fw_table[i].filename != NULL) { |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1312 | if (fw_table[i].addr_signed) { |
| 1313 | pspdir->entries[count].addr = |
| 1314 | RUN_OFFSET(*ctx, fw_table[i].addr_signed); |
| 1315 | pspdir->entries[count].address_mode = |
| 1316 | SET_ADDR_MODE_BY_TABLE(pspdir); |
| 1317 | bytes = fw_table[i].file_size; |
| 1318 | } else { |
| 1319 | bytes = copy_blob(BUFF_CURRENT(*ctx), |
| 1320 | fw_table[i].filename, BUFF_ROOM(*ctx)); |
| 1321 | if (bytes < 0) { |
| 1322 | free(ctx->rom); |
| 1323 | exit(1); |
| 1324 | } |
| 1325 | pspdir->entries[count].addr = RUN_CURRENT(*ctx); |
| 1326 | pspdir->entries[count].address_mode = |
| 1327 | SET_ADDR_MODE_BY_TABLE(pspdir); |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1328 | ctx->current = ALIGN_UP(ctx->current + bytes, |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1329 | BLOB_ALIGNMENT); |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 1332 | pspdir->entries[count].type = fw_table[i].type; |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 1333 | pspdir->entries[count].subprog = fw_table[i].subprog; |
| 1334 | pspdir->entries[count].rsvd = 0; |
Marshall Dawson | 8e0dca0 | 2019-02-27 18:40:49 -0700 | [diff] [blame] | 1335 | pspdir->entries[count].size = (uint32_t)bytes; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1336 | |
Marshall Dawson | c38c0c9 | 2019-02-23 16:41:35 -0700 | [diff] [blame] | 1337 | count++; |
zbao | c3a08a9 | 2016-03-02 14:47:27 +0800 | [diff] [blame] | 1338 | } else { |
| 1339 | /* This APU doesn't have this firmware. */ |
| 1340 | } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1341 | } |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 1342 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1343 | if (recovery_ab && (pspdir2 != NULL)) { |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1344 | if (cb_config->need_ish) { /* Need ISH */ |
| 1345 | ish_a_dir = new_ish_dir(ctx); |
| 1346 | if (pspdir2_b != NULL) |
| 1347 | ish_b_dir = new_ish_dir(ctx); |
| 1348 | } |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1349 | pspdir->header.num_entries = count; |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1350 | integrate_psp_ab(ctx, pspdir, pspdir2, ish_a_dir, |
| 1351 | AMD_FW_RECOVERYAB_A, soc_id); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1352 | if (pspdir2_b != NULL) |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 1353 | integrate_psp_ab(ctx, pspdir, pspdir2_b, ish_b_dir, |
| 1354 | AMD_FW_RECOVERYAB_B, soc_id); |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 1355 | else |
Karthikeyan Ramasubramanian | e5af14a | 2022-08-02 11:34:48 -0600 | [diff] [blame] | 1356 | integrate_psp_ab(ctx, pspdir, pspdir2, ish_a_dir, |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 1357 | AMD_FW_RECOVERYAB_B, soc_id); |
| 1358 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1359 | count = pspdir->header.num_entries; |
| 1360 | } else if (pspdir2 != NULL) { |
Zheng Bao | 5164e4b | 2021-10-30 12:09:07 +0800 | [diff] [blame] | 1361 | assert_fw_entry(count, MAX_PSP_ENTRIES, ctx); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1362 | pspdir->entries[count].type = AMD_FW_L2_PTR; |
| 1363 | pspdir->entries[count].subprog = 0; |
| 1364 | pspdir->entries[count].rsvd = 0; |
| 1365 | pspdir->entries[count].size = sizeof(pspdir2->header) |
| 1366 | + pspdir2->header.num_entries |
| 1367 | * sizeof(psp_directory_entry); |
| 1368 | |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1369 | pspdir->entries[count].addr = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1370 | BUFF_TO_RUN_MODE(*ctx, pspdir2, AMD_ADDR_REL_BIOS); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1371 | pspdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1372 | SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 1373 | count++; |
| 1374 | } |
| 1375 | |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 1376 | fill_dir_header(pspdir, count, cookie, ctx); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1377 | ctx->current_table = current_table_save; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1380 | static void add_psp_firmware_entry(context *ctx, |
| 1381 | psp_directory_table *pspdir, |
| 1382 | void *table, amd_fw_type type, uint32_t size) |
| 1383 | { |
| 1384 | uint32_t count = pspdir->header.num_entries; |
| 1385 | uint32_t index; |
| 1386 | uint32_t current_table_save; |
| 1387 | |
| 1388 | current_table_save = ctx->current_table; |
| 1389 | ctx->current_table = (char *)pspdir - ctx->rom; |
| 1390 | |
| 1391 | /* If there is an entry of "type", replace it. */ |
| 1392 | for (index = 0; index < count; index++) { |
| 1393 | if (pspdir->entries[index].type == (uint8_t)type) |
| 1394 | break; |
| 1395 | } |
| 1396 | |
| 1397 | assert_fw_entry(count, MAX_PSP_ENTRIES, ctx); |
| 1398 | pspdir->entries[index].type = (uint8_t)type; |
| 1399 | pspdir->entries[index].subprog = 0; |
| 1400 | pspdir->entries[index].rsvd = 0; |
| 1401 | pspdir->entries[index].addr = BUFF_TO_RUN(*ctx, table); |
| 1402 | pspdir->entries[index].address_mode = SET_ADDR_MODE_BY_TABLE(pspdir); |
| 1403 | pspdir->entries[index].size = size; |
| 1404 | if (index == count) |
| 1405 | count++; |
| 1406 | |
| 1407 | pspdir->header.num_entries = count; |
| 1408 | pspdir->header.checksum = fletcher32(&pspdir->header.num_entries, |
| 1409 | count * sizeof(psp_directory_entry) |
| 1410 | + sizeof(pspdir->header.num_entries) |
| 1411 | + sizeof(pspdir->header.additional_info)); |
| 1412 | |
| 1413 | ctx->current_table = current_table_save; |
| 1414 | } |
| 1415 | |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 1416 | static void *new_bios_dir(context *ctx, bool multi) |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1417 | { |
| 1418 | void *ptr; |
| 1419 | |
| 1420 | /* |
| 1421 | * Force both onto boundary when multi. Primary table is after |
| 1422 | * updatable table, so alignment ensures primary can stay intact |
| 1423 | * if secondary is reprogrammed. |
| 1424 | */ |
| 1425 | if (multi) |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1426 | ctx->current = ALIGN_UP(ctx->current, TABLE_ERASE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1427 | else |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1428 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1429 | ptr = BUFF_CURRENT(*ctx); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1430 | ((bios_directory_hdr *) ptr)->additional_info = 0; |
| 1431 | ((bios_directory_hdr *) ptr)->additional_info_fields.address_mode = ctx->address_mode; |
| 1432 | ctx->current_table = ctx->current; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1433 | ctx->current += sizeof(bios_directory_hdr) |
| 1434 | + MAX_BIOS_ENTRIES * sizeof(bios_directory_entry); |
| 1435 | return ptr; |
| 1436 | } |
| 1437 | |
| 1438 | static int locate_bdt2_bios(bios_directory_table *level2, |
| 1439 | uint64_t *source, uint32_t *size) |
| 1440 | { |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 1441 | uint32_t i; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1442 | |
| 1443 | *source = 0; |
| 1444 | *size = 0; |
| 1445 | if (!level2) |
| 1446 | return 0; |
| 1447 | |
| 1448 | for (i = 0 ; i < level2->header.num_entries ; i++) { |
| 1449 | if (level2->entries[i].type == AMD_BIOS_BIN) { |
| 1450 | *source = level2->entries[i].source; |
| 1451 | *size = level2->entries[i].size; |
| 1452 | return 1; |
| 1453 | } |
| 1454 | } |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
| 1458 | static int have_bios_tables(amd_bios_entry *table) |
| 1459 | { |
| 1460 | int i; |
| 1461 | |
| 1462 | for (i = 0 ; table[i].type != AMD_BIOS_INVALID; i++) { |
| 1463 | if (table[i].level & BDT_LVL1 && table[i].filename) |
| 1464 | return 1; |
| 1465 | } |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
Marshall Dawson | c4a8c48 | 2020-01-21 17:17:59 -0700 | [diff] [blame] | 1469 | static int find_bios_entry(amd_bios_type type) |
| 1470 | { |
| 1471 | int i; |
| 1472 | |
| 1473 | for (i = 0; amd_bios_table[i].type != AMD_BIOS_INVALID; i++) { |
| 1474 | if (amd_bios_table[i].type == type) |
| 1475 | return i; |
| 1476 | } |
| 1477 | return -1; |
| 1478 | } |
| 1479 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1480 | static void integrate_bios_firmwares(context *ctx, |
| 1481 | bios_directory_table *biosdir, |
| 1482 | bios_directory_table *biosdir2, |
| 1483 | amd_bios_entry *fw_table, |
Zheng Bao | 2079589 | 2021-08-20 14:58:22 +0800 | [diff] [blame] | 1484 | uint32_t cookie, |
| 1485 | amd_cb_config *cb_config) |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1486 | { |
| 1487 | ssize_t bytes; |
Martin Roth | ec93313 | 2019-07-13 20:03:34 -0600 | [diff] [blame] | 1488 | unsigned int i, count; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1489 | int level; |
Marshall Dawson | c4a8c48 | 2020-01-21 17:17:59 -0700 | [diff] [blame] | 1490 | int apob_idx; |
Martin Roth | eca423b | 2020-09-01 10:54:11 -0600 | [diff] [blame] | 1491 | uint32_t size; |
| 1492 | uint64_t source; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1493 | |
| 1494 | /* This function can create a primary table, a secondary table, or a |
| 1495 | * flattened table which contains all applicable types. These if-else |
| 1496 | * statements infer what the caller intended. If a 2nd-level cookie |
| 1497 | * is passed, clearly a 2nd-level table is intended. However, a |
| 1498 | * 1st-level cookie may indicate level 1 or flattened. If the caller |
| 1499 | * passes a pointer to a 2nd-level table, then assume not flat. |
| 1500 | */ |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 1501 | if (!cb_config->multi_level) |
Zheng Bao | 2079589 | 2021-08-20 14:58:22 +0800 | [diff] [blame] | 1502 | level = BDT_BOTH; |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 1503 | else if (cookie == BHDL2_COOKIE) |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1504 | level = BDT_LVL2; |
| 1505 | else if (biosdir2) |
| 1506 | level = BDT_LVL1; |
| 1507 | else |
| 1508 | level = BDT_BOTH; |
| 1509 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1510 | ctx->current = ALIGN_UP(ctx->current, TABLE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1511 | |
| 1512 | for (i = 0, count = 0; fw_table[i].type != AMD_BIOS_INVALID; i++) { |
| 1513 | if (!(fw_table[i].level & level)) |
| 1514 | continue; |
| 1515 | if (fw_table[i].filename == NULL && ( |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1516 | fw_table[i].type != AMD_BIOS_SIG && |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1517 | fw_table[i].type != AMD_BIOS_APOB && |
| 1518 | fw_table[i].type != AMD_BIOS_APOB_NV && |
| 1519 | fw_table[i].type != AMD_BIOS_L2_PTR && |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 1520 | fw_table[i].type != AMD_BIOS_BIN && |
| 1521 | fw_table[i].type != AMD_BIOS_PSP_SHARED_MEM)) |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1522 | continue; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1523 | |
| 1524 | /* BIOS Directory items may have additional requirements */ |
| 1525 | |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1526 | /* SIG needs a size, else no choice but to skip */ |
| 1527 | if (fw_table[i].type == AMD_BIOS_SIG && !fw_table[i].size) |
| 1528 | continue; |
| 1529 | |
Martin Roth | 48dd9fe | 2020-07-29 16:32:25 -0600 | [diff] [blame] | 1530 | /* Check APOB_NV requirements */ |
| 1531 | if (fw_table[i].type == AMD_BIOS_APOB_NV) { |
| 1532 | if (!fw_table[i].size && !fw_table[i].src) |
| 1533 | continue; /* APOB_NV not used */ |
| 1534 | if (fw_table[i].src && !fw_table[i].size) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1535 | fprintf(stderr, "Error: APOB NV address provided, but no size\n"); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1536 | free(ctx->rom); |
| 1537 | exit(1); |
| 1538 | } |
Martin Roth | 48dd9fe | 2020-07-29 16:32:25 -0600 | [diff] [blame] | 1539 | /* If the APOB isn't used, APOB_NV isn't used either */ |
Marshall Dawson | c4a8c48 | 2020-01-21 17:17:59 -0700 | [diff] [blame] | 1540 | apob_idx = find_bios_entry(AMD_BIOS_APOB); |
Martin Roth | 48dd9fe | 2020-07-29 16:32:25 -0600 | [diff] [blame] | 1541 | if (apob_idx < 0 || !fw_table[apob_idx].dest) |
| 1542 | continue; /* APOV NV not supported */ |
Marshall Dawson | c4a8c48 | 2020-01-21 17:17:59 -0700 | [diff] [blame] | 1543 | } |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1544 | |
| 1545 | /* APOB_DATA needs destination */ |
| 1546 | if (fw_table[i].type == AMD_BIOS_APOB && !fw_table[i].dest) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1547 | fprintf(stderr, "Error: APOB destination not provided\n"); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1548 | free(ctx->rom); |
| 1549 | exit(1); |
| 1550 | } |
| 1551 | |
| 1552 | /* BIOS binary must have destination and uncompressed size. If |
| 1553 | * no filename given, then user must provide a source address. |
| 1554 | */ |
| 1555 | if (fw_table[i].type == AMD_BIOS_BIN) { |
| 1556 | if (!fw_table[i].dest || !fw_table[i].size) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1557 | fprintf(stderr, "Error: BIOS binary destination and uncompressed size are required\n"); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1558 | free(ctx->rom); |
| 1559 | exit(1); |
| 1560 | } |
| 1561 | if (!fw_table[i].filename && !fw_table[i].src) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1562 | fprintf(stderr, "Error: BIOS binary assumed outside amdfw.rom but no source address given\n"); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1563 | free(ctx->rom); |
| 1564 | exit(1); |
| 1565 | } |
| 1566 | } |
| 1567 | |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 1568 | /* PSP_SHARED_MEM needs a destination and size */ |
| 1569 | if (fw_table[i].type == AMD_BIOS_PSP_SHARED_MEM && |
| 1570 | (!fw_table[i].dest || !fw_table[i].size)) |
| 1571 | continue; |
Zheng Bao | 5164e4b | 2021-10-30 12:09:07 +0800 | [diff] [blame] | 1572 | assert_fw_entry(count, MAX_BIOS_ENTRIES, ctx); |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 1573 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1574 | biosdir->entries[count].type = fw_table[i].type; |
| 1575 | biosdir->entries[count].region_type = fw_table[i].region_type; |
| 1576 | biosdir->entries[count].dest = fw_table[i].dest ? |
| 1577 | fw_table[i].dest : (uint64_t)-1; |
| 1578 | biosdir->entries[count].reset = fw_table[i].reset; |
| 1579 | biosdir->entries[count].copy = fw_table[i].copy; |
| 1580 | biosdir->entries[count].ro = fw_table[i].ro; |
| 1581 | biosdir->entries[count].compressed = fw_table[i].zlib; |
| 1582 | biosdir->entries[count].inst = fw_table[i].inst; |
| 1583 | biosdir->entries[count].subprog = fw_table[i].subpr; |
| 1584 | |
| 1585 | switch (fw_table[i].type) { |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1586 | case AMD_BIOS_SIG: |
| 1587 | /* Reserve size bytes within amdfw.rom */ |
| 1588 | biosdir->entries[count].size = fw_table[i].size; |
| 1589 | biosdir->entries[count].source = RUN_CURRENT(*ctx); |
| 1590 | biosdir->entries[count].address_mode = |
| 1591 | SET_ADDR_MODE_BY_TABLE(biosdir); |
| 1592 | memset(BUFF_CURRENT(*ctx), 0xff, |
| 1593 | biosdir->entries[count].size); |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1594 | ctx->current = ALIGN_UP(ctx->current |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1595 | + biosdir->entries[count].size, 0x100U); |
| 1596 | break; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1597 | case AMD_BIOS_APOB: |
| 1598 | biosdir->entries[count].size = fw_table[i].size; |
| 1599 | biosdir->entries[count].source = fw_table[i].src; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1600 | biosdir->entries[count].address_mode = SET_ADDR_MODE_BY_TABLE(biosdir); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1601 | break; |
| 1602 | case AMD_BIOS_APOB_NV: |
| 1603 | if (fw_table[i].src) { |
| 1604 | /* If source is given, use that and its size */ |
| 1605 | biosdir->entries[count].source = fw_table[i].src; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1606 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1607 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1608 | biosdir->entries[count].size = fw_table[i].size; |
| 1609 | } else { |
| 1610 | /* Else reserve size bytes within amdfw.rom */ |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1611 | ctx->current = ALIGN_UP(ctx->current, ERASE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1612 | biosdir->entries[count].source = RUN_CURRENT(*ctx); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1613 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1614 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1615 | biosdir->entries[count].size = ALIGN_UP( |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1616 | fw_table[i].size, ERASE_ALIGNMENT); |
| 1617 | memset(BUFF_CURRENT(*ctx), 0xff, |
| 1618 | biosdir->entries[count].size); |
| 1619 | ctx->current = ctx->current |
| 1620 | + biosdir->entries[count].size; |
| 1621 | } |
| 1622 | break; |
| 1623 | case AMD_BIOS_BIN: |
| 1624 | /* Don't make a 2nd copy, point to the same one */ |
Martin Roth | eca423b | 2020-09-01 10:54:11 -0600 | [diff] [blame] | 1625 | if (level == BDT_LVL1 && locate_bdt2_bios(biosdir2, &source, &size)) { |
| 1626 | biosdir->entries[count].source = source; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1627 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1628 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Martin Roth | eca423b | 2020-09-01 10:54:11 -0600 | [diff] [blame] | 1629 | biosdir->entries[count].size = size; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1630 | break; |
Martin Roth | eca423b | 2020-09-01 10:54:11 -0600 | [diff] [blame] | 1631 | } |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1632 | |
| 1633 | /* level 2, or level 1 and no copy found in level 2 */ |
| 1634 | biosdir->entries[count].source = fw_table[i].src; |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1635 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1636 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1637 | biosdir->entries[count].dest = fw_table[i].dest; |
| 1638 | biosdir->entries[count].size = fw_table[i].size; |
| 1639 | |
| 1640 | if (!fw_table[i].filename) |
| 1641 | break; |
| 1642 | |
| 1643 | bytes = copy_blob(BUFF_CURRENT(*ctx), |
| 1644 | fw_table[i].filename, BUFF_ROOM(*ctx)); |
| 1645 | if (bytes <= 0) { |
| 1646 | free(ctx->rom); |
| 1647 | exit(1); |
| 1648 | } |
| 1649 | |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1650 | biosdir->entries[count].source = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1651 | RUN_CURRENT_MODE(*ctx, AMD_ADDR_REL_BIOS); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1652 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1653 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1654 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1655 | ctx->current = ALIGN_UP(ctx->current + bytes, 0x100U); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1656 | break; |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 1657 | case AMD_BIOS_PSP_SHARED_MEM: |
| 1658 | biosdir->entries[count].dest = fw_table[i].dest; |
| 1659 | biosdir->entries[count].size = fw_table[i].size; |
| 1660 | break; |
| 1661 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1662 | default: /* everything else is copied from input */ |
| 1663 | if (fw_table[i].type == AMD_BIOS_APCB || |
| 1664 | fw_table[i].type == AMD_BIOS_APCB_BK) |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1665 | ctx->current = ALIGN_UP( |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1666 | ctx->current, ERASE_ALIGNMENT); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1667 | bytes = copy_blob(BUFF_CURRENT(*ctx), |
| 1668 | fw_table[i].filename, BUFF_ROOM(*ctx)); |
| 1669 | if (bytes <= 0) { |
| 1670 | free(ctx->rom); |
| 1671 | exit(1); |
| 1672 | } |
| 1673 | |
| 1674 | biosdir->entries[count].size = (uint32_t)bytes; |
| 1675 | biosdir->entries[count].source = RUN_CURRENT(*ctx); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1676 | biosdir->entries[count].address_mode = SET_ADDR_MODE_BY_TABLE(biosdir); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1677 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 1678 | ctx->current = ALIGN_UP(ctx->current + bytes, 0x100U); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1679 | break; |
| 1680 | } |
| 1681 | |
| 1682 | count++; |
| 1683 | } |
| 1684 | |
| 1685 | if (biosdir2) { |
Zheng Bao | 5164e4b | 2021-10-30 12:09:07 +0800 | [diff] [blame] | 1686 | assert_fw_entry(count, MAX_BIOS_ENTRIES, ctx); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1687 | biosdir->entries[count].type = AMD_BIOS_L2_PTR; |
Zheng Bao | e8e6043 | 2021-05-24 16:11:12 +0800 | [diff] [blame] | 1688 | biosdir->entries[count].region_type = 0; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1689 | biosdir->entries[count].size = |
| 1690 | + MAX_BIOS_ENTRIES |
| 1691 | * sizeof(bios_directory_entry); |
| 1692 | biosdir->entries[count].source = |
| 1693 | BUFF_TO_RUN(*ctx, biosdir2); |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 1694 | biosdir->entries[count].address_mode = |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 1695 | SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1696 | biosdir->entries[count].subprog = 0; |
| 1697 | biosdir->entries[count].inst = 0; |
| 1698 | biosdir->entries[count].copy = 0; |
| 1699 | biosdir->entries[count].compressed = 0; |
| 1700 | biosdir->entries[count].dest = -1; |
| 1701 | biosdir->entries[count].reset = 0; |
| 1702 | biosdir->entries[count].ro = 0; |
| 1703 | count++; |
| 1704 | } |
| 1705 | |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 1706 | fill_dir_header(biosdir, count, cookie, ctx); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1707 | } |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1708 | |
| 1709 | enum { |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1710 | AMDFW_OPT_CONFIG = 'c', |
| 1711 | AMDFW_OPT_DEBUG = 'd', |
| 1712 | AMDFW_OPT_HELP = 'h', |
| 1713 | AMDFW_OPT_LIST_DEPEND = 'l', |
| 1714 | |
| 1715 | AMDFW_OPT_XHCI = 128, |
| 1716 | AMDFW_OPT_IMC, |
| 1717 | AMDFW_OPT_GEC, |
| 1718 | AMDFW_OPT_COMBO, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1719 | AMDFW_OPT_RECOVERY_AB, |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 1720 | AMDFW_OPT_RECOVERY_AB_SINGLE_COPY, |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 1721 | AMDFW_OPT_USE_COMBO, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1722 | AMDFW_OPT_MULTILEVEL, |
| 1723 | AMDFW_OPT_NVRAM, |
| 1724 | |
| 1725 | AMDFW_OPT_FUSE, |
| 1726 | AMDFW_OPT_UNLOCK, |
| 1727 | AMDFW_OPT_WHITELIST, |
| 1728 | AMDFW_OPT_USE_PSPSECUREOS, |
| 1729 | AMDFW_OPT_LOAD_MP2FW, |
| 1730 | AMDFW_OPT_LOAD_S0I3, |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 1731 | AMDFW_OPT_SPL_TABLE, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1732 | AMDFW_OPT_VERSTAGE, |
| 1733 | AMDFW_OPT_VERSTAGE_SIG, |
| 1734 | |
| 1735 | AMDFW_OPT_INSTANCE, |
| 1736 | AMDFW_OPT_APCB, |
| 1737 | AMDFW_OPT_APOBBASE, |
| 1738 | AMDFW_OPT_BIOSBIN, |
| 1739 | AMDFW_OPT_BIOSBIN_SOURCE, |
| 1740 | AMDFW_OPT_BIOSBIN_DEST, |
| 1741 | AMDFW_OPT_BIOS_UNCOMP_SIZE, |
| 1742 | AMDFW_OPT_UCODE, |
| 1743 | AMDFW_OPT_APOB_NVBASE, |
| 1744 | AMDFW_OPT_APOB_NVSIZE, |
| 1745 | |
| 1746 | AMDFW_OPT_OUTPUT, |
| 1747 | AMDFW_OPT_FLASHSIZE, |
| 1748 | AMDFW_OPT_LOCATION, |
| 1749 | AMDFW_OPT_ANYWHERE, |
| 1750 | AMDFW_OPT_SHAREDMEM, |
| 1751 | AMDFW_OPT_SHAREDMEM_SIZE, |
| 1752 | AMDFW_OPT_SOC_NAME, |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1753 | AMDFW_OPT_SIGNED_OUTPUT, |
| 1754 | AMDFW_OPT_SIGNED_ADDR, |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 1755 | AMDFW_OPT_BODY_LOCATION, |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1756 | /* begin after ASCII characters */ |
| 1757 | LONGOPT_SPI_READ_MODE = 256, |
| 1758 | LONGOPT_SPI_SPEED = 257, |
| 1759 | LONGOPT_SPI_MICRON_FLAG = 258, |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1760 | LONGOPT_BIOS_SIG = 259, |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1761 | LONGOPT_NVRAM_BASE = 260, |
| 1762 | LONGOPT_NVRAM_SIZE = 261, |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1763 | }; |
| 1764 | |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1765 | static char const optstring[] = {AMDFW_OPT_CONFIG, ':', |
| 1766 | AMDFW_OPT_DEBUG, AMDFW_OPT_HELP, AMDFW_OPT_LIST_DEPEND |
| 1767 | }; |
Marc Jones | 90099b6 | 2016-09-20 21:05:45 -0600 | [diff] [blame] | 1768 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1769 | static struct option long_options[] = { |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1770 | {"xhci", required_argument, 0, AMDFW_OPT_XHCI }, |
| 1771 | {"imc", required_argument, 0, AMDFW_OPT_IMC }, |
| 1772 | {"gec", required_argument, 0, AMDFW_OPT_GEC }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1773 | /* PSP Directory Table items */ |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1774 | {"combo-capable", no_argument, 0, AMDFW_OPT_COMBO }, |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 1775 | {"recovery-ab", no_argument, 0, AMDFW_OPT_RECOVERY_AB }, |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 1776 | {"recovery-ab-single-copy", no_argument, 0, AMDFW_OPT_RECOVERY_AB_SINGLE_COPY }, |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 1777 | {"use-combo", no_argument, 0, AMDFW_OPT_USE_COMBO }, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1778 | {"multilevel", no_argument, 0, AMDFW_OPT_MULTILEVEL }, |
| 1779 | {"nvram", required_argument, 0, AMDFW_OPT_NVRAM }, |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1780 | {"nvram-base", required_argument, 0, LONGOPT_NVRAM_BASE }, |
| 1781 | {"nvram-size", required_argument, 0, LONGOPT_NVRAM_SIZE }, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1782 | {"soft-fuse", required_argument, 0, AMDFW_OPT_FUSE }, |
| 1783 | {"token-unlock", no_argument, 0, AMDFW_OPT_UNLOCK }, |
| 1784 | {"whitelist", required_argument, 0, AMDFW_OPT_WHITELIST }, |
| 1785 | {"use-pspsecureos", no_argument, 0, AMDFW_OPT_USE_PSPSECUREOS }, |
| 1786 | {"load-mp2-fw", no_argument, 0, AMDFW_OPT_LOAD_MP2FW }, |
| 1787 | {"load-s0i3", no_argument, 0, AMDFW_OPT_LOAD_S0I3 }, |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 1788 | {"spl-table", required_argument, 0, AMDFW_OPT_SPL_TABLE }, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1789 | {"verstage", required_argument, 0, AMDFW_OPT_VERSTAGE }, |
| 1790 | {"verstage_sig", required_argument, 0, AMDFW_OPT_VERSTAGE_SIG }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1791 | /* BIOS Directory Table items */ |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1792 | {"instance", required_argument, 0, AMDFW_OPT_INSTANCE }, |
| 1793 | {"apcb", required_argument, 0, AMDFW_OPT_APCB }, |
| 1794 | {"apob-base", required_argument, 0, AMDFW_OPT_APOBBASE }, |
| 1795 | {"bios-bin", required_argument, 0, AMDFW_OPT_BIOSBIN }, |
| 1796 | {"bios-bin-src", required_argument, 0, AMDFW_OPT_BIOSBIN_SOURCE }, |
| 1797 | {"bios-bin-dest", required_argument, 0, AMDFW_OPT_BIOSBIN_DEST }, |
| 1798 | {"bios-uncomp-size", required_argument, 0, AMDFW_OPT_BIOS_UNCOMP_SIZE }, |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 1799 | {"bios-sig-size", required_argument, 0, LONGOPT_BIOS_SIG }, |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1800 | {"ucode", required_argument, 0, AMDFW_OPT_UCODE }, |
| 1801 | {"apob-nv-base", required_argument, 0, AMDFW_OPT_APOB_NVBASE }, |
| 1802 | {"apob-nv-size", required_argument, 0, AMDFW_OPT_APOB_NVSIZE }, |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1803 | /* Embedded Firmware Structure items*/ |
| 1804 | {"spi-read-mode", required_argument, 0, LONGOPT_SPI_READ_MODE }, |
| 1805 | {"spi-speed", required_argument, 0, LONGOPT_SPI_SPEED }, |
| 1806 | {"spi-micron-flag", required_argument, 0, LONGOPT_SPI_MICRON_FLAG }, |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 1807 | {"body-location", required_argument, 0, AMDFW_OPT_BODY_LOCATION }, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1808 | /* other */ |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1809 | {"output", required_argument, 0, AMDFW_OPT_OUTPUT }, |
| 1810 | {"flashsize", required_argument, 0, AMDFW_OPT_FLASHSIZE }, |
| 1811 | {"location", required_argument, 0, AMDFW_OPT_LOCATION }, |
| 1812 | {"anywhere", no_argument, 0, AMDFW_OPT_ANYWHERE }, |
| 1813 | {"sharedmem", required_argument, 0, AMDFW_OPT_SHAREDMEM }, |
| 1814 | {"sharedmem-size", required_argument, 0, AMDFW_OPT_SHAREDMEM_SIZE }, |
| 1815 | {"soc-name", required_argument, 0, AMDFW_OPT_SOC_NAME }, |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 1816 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 1817 | {"signed-output", required_argument, 0, AMDFW_OPT_SIGNED_OUTPUT }, |
| 1818 | {"signed-addr", required_argument, 0, AMDFW_OPT_SIGNED_ADDR }, |
| 1819 | |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 1820 | {"config", required_argument, 0, AMDFW_OPT_CONFIG }, |
| 1821 | {"debug", no_argument, 0, AMDFW_OPT_DEBUG }, |
| 1822 | {"help", no_argument, 0, AMDFW_OPT_HELP }, |
| 1823 | {"list", no_argument, 0, AMDFW_OPT_LIST_DEPEND }, |
Marshall Dawson | f4b9b41 | 2017-03-17 16:30:51 -0600 | [diff] [blame] | 1824 | {NULL, 0, 0, 0 } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1825 | }; |
| 1826 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 1827 | void register_fw_fuse(char *str) |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 1828 | { |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 1829 | uint32_t i; |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 1830 | |
| 1831 | for (i = 0; i < sizeof(amd_psp_fw_table) / sizeof(amd_fw_entry); i++) { |
| 1832 | if (amd_psp_fw_table[i].type != AMD_PSP_FUSE_CHAIN) |
| 1833 | continue; |
| 1834 | |
| 1835 | amd_psp_fw_table[i].other = strtoull(str, NULL, 16); |
| 1836 | return; |
| 1837 | } |
| 1838 | } |
| 1839 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1840 | static void register_fw_token_unlock(void) |
| 1841 | { |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 1842 | uint32_t i; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1843 | |
| 1844 | for (i = 0; i < sizeof(amd_psp_fw_table) / sizeof(amd_fw_entry); i++) { |
| 1845 | if (amd_psp_fw_table[i].type != AMD_TOKEN_UNLOCK) |
| 1846 | continue; |
| 1847 | |
| 1848 | amd_psp_fw_table[i].other = 1; |
| 1849 | return; |
| 1850 | } |
| 1851 | } |
| 1852 | |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 1853 | static void register_fw_filename(amd_fw_type type, uint8_t sub, char filename[]) |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1854 | { |
Martin Roth | 8806f7f | 2016-11-08 10:44:18 -0700 | [diff] [blame] | 1855 | unsigned int i; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1856 | |
Martin Roth | cd15bc8 | 2016-11-08 11:34:02 -0700 | [diff] [blame] | 1857 | for (i = 0; i < sizeof(amd_fw_table) / sizeof(amd_fw_entry); i++) { |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1858 | if (amd_fw_table[i].type == type) { |
| 1859 | amd_fw_table[i].filename = filename; |
| 1860 | return; |
| 1861 | } |
| 1862 | } |
| 1863 | |
Marshall Dawson | 0e02ce8 | 2019-03-04 16:50:37 -0700 | [diff] [blame] | 1864 | for (i = 0; i < sizeof(amd_psp_fw_table) / sizeof(amd_fw_entry); i++) { |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 1865 | if (amd_psp_fw_table[i].type != type) |
| 1866 | continue; |
| 1867 | |
| 1868 | if (amd_psp_fw_table[i].subprog == sub) { |
Marshall Dawson | 0e02ce8 | 2019-03-04 16:50:37 -0700 | [diff] [blame] | 1869 | amd_psp_fw_table[i].filename = filename; |
| 1870 | return; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1871 | } |
| 1872 | } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 1873 | } |
| 1874 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1875 | static void register_bdt_data(amd_bios_type type, int sub, int ins, char name[]) |
| 1876 | { |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 1877 | uint32_t i; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1878 | |
| 1879 | for (i = 0; i < sizeof(amd_bios_table) / sizeof(amd_bios_entry); i++) { |
| 1880 | if (amd_bios_table[i].type == type |
| 1881 | && amd_bios_table[i].inst == ins |
| 1882 | && amd_bios_table[i].subpr == sub) { |
| 1883 | amd_bios_table[i].filename = name; |
| 1884 | return; |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 1889 | static void register_amd_psp_fw_addr(amd_fw_type type, int sub, |
| 1890 | char *dst_str, char *size_str) |
| 1891 | { |
| 1892 | unsigned int i; |
| 1893 | |
| 1894 | for (i = 0; i < sizeof(amd_psp_fw_table) / sizeof(amd_fw_entry); i++) { |
| 1895 | if (amd_psp_fw_table[i].type != type) |
| 1896 | continue; |
| 1897 | |
| 1898 | if (amd_psp_fw_table[i].subprog == sub) { |
| 1899 | if (dst_str) |
| 1900 | amd_psp_fw_table[i].dest = strtoull(dst_str, NULL, 16); |
| 1901 | if (size_str) |
| 1902 | amd_psp_fw_table[i].size = strtoul(size_str, NULL, 16); |
| 1903 | return; |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | static void register_bios_fw_addr(amd_bios_type type, char *src_str, |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1909 | char *dst_str, char *size_str) |
| 1910 | { |
Zheng Bao | 6d402ac | 2020-10-01 16:16:30 +0800 | [diff] [blame] | 1911 | uint32_t i; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 1912 | for (i = 0; i < sizeof(amd_bios_table) / sizeof(amd_bios_entry); i++) { |
| 1913 | if (amd_bios_table[i].type != type) |
| 1914 | continue; |
| 1915 | |
| 1916 | if (src_str) |
| 1917 | amd_bios_table[i].src = strtoull(src_str, NULL, 16); |
| 1918 | if (dst_str) |
| 1919 | amd_bios_table[i].dest = strtoull(dst_str, NULL, 16); |
| 1920 | if (size_str) |
| 1921 | amd_bios_table[i].size = strtoul(size_str, NULL, 16); |
| 1922 | |
| 1923 | return; |
| 1924 | } |
| 1925 | } |
| 1926 | |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 1927 | static int set_efs_table(uint8_t soc_id, amd_cb_config *cb_config, |
| 1928 | embedded_firmware *amd_romsig, uint8_t efs_spi_readmode, |
| 1929 | uint8_t efs_spi_speed, uint8_t efs_spi_micron_flag) |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1930 | { |
| 1931 | if ((efs_spi_readmode == 0xFF) || (efs_spi_speed == 0xFF)) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1932 | fprintf(stderr, "Error: EFS read mode and SPI speed must be set\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1933 | return 1; |
| 1934 | } |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 1935 | |
| 1936 | /* amd_romsig->efs_gen introduced after RAVEN/PICASSO. |
| 1937 | * Leave as 0xffffffff for first gen */ |
| 1938 | if (cb_config->second_gen) { |
| 1939 | amd_romsig->efs_gen.gen = EFS_SECOND_GEN; |
| 1940 | amd_romsig->efs_gen.reserved = 0; |
| 1941 | } else { |
Zheng Bao | 487d045 | 2022-04-03 12:50:07 +0800 | [diff] [blame] | 1942 | amd_romsig->efs_gen.gen = EFS_BEFORE_SECOND_GEN; |
| 1943 | amd_romsig->efs_gen.reserved = ~0; |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | switch (soc_id) { |
| 1947 | case PLATFORM_STONEYRIDGE: |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1948 | amd_romsig->spi_readmode_f15_mod_60_6f = efs_spi_readmode; |
| 1949 | amd_romsig->fast_speed_new_f15_mod_60_6f = efs_spi_speed; |
| 1950 | break; |
| 1951 | case PLATFORM_RAVEN: |
| 1952 | case PLATFORM_PICASSO: |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1953 | amd_romsig->spi_readmode_f17_mod_00_2f = efs_spi_readmode; |
| 1954 | amd_romsig->spi_fastspeed_f17_mod_00_2f = efs_spi_speed; |
| 1955 | switch (efs_spi_micron_flag) { |
| 1956 | case 0: |
| 1957 | amd_romsig->qpr_dummy_cycle_f17_mod_00_2f = 0xff; |
| 1958 | break; |
| 1959 | case 1: |
| 1960 | amd_romsig->qpr_dummy_cycle_f17_mod_00_2f = 0xa; |
| 1961 | break; |
| 1962 | default: |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1963 | fprintf(stderr, "Error: EFS Micron flag must be correctly set.\n\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1964 | return 1; |
| 1965 | } |
| 1966 | break; |
| 1967 | case PLATFORM_RENOIR: |
| 1968 | case PLATFORM_LUCIENNE: |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 1969 | case PLATFORM_CEZANNE: |
Zheng Bao | 535ec53 | 2021-08-12 16:30:19 +0800 | [diff] [blame] | 1970 | case PLATFORM_MENDOCINO: |
Zheng Bao | de6f198 | 2022-10-16 20:32:43 +0800 | [diff] [blame] | 1971 | case PLATFORM_PHOENIX: |
| 1972 | case PLATFORM_GLINDA: |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1973 | amd_romsig->spi_readmode_f17_mod_30_3f = efs_spi_readmode; |
| 1974 | amd_romsig->spi_fastspeed_f17_mod_30_3f = efs_spi_speed; |
| 1975 | switch (efs_spi_micron_flag) { |
| 1976 | case 0: |
| 1977 | amd_romsig->micron_detect_f17_mod_30_3f = 0xff; |
| 1978 | break; |
| 1979 | case 1: |
| 1980 | amd_romsig->micron_detect_f17_mod_30_3f = 0xaa; |
| 1981 | break; |
| 1982 | case 2: |
| 1983 | amd_romsig->micron_detect_f17_mod_30_3f = 0x55; |
| 1984 | break; |
| 1985 | default: |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1986 | fprintf(stderr, "Error: EFS Micron flag must be correctly set.\n\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1987 | return 1; |
| 1988 | } |
| 1989 | break; |
| 1990 | case PLATFORM_UNKNOWN: |
| 1991 | default: |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 1992 | fprintf(stderr, "Error: Invalid SOC name.\n\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 1993 | return 1; |
| 1994 | } |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 1998 | static ssize_t write_efs(char *output, embedded_firmware *amd_romsig) |
| 1999 | { |
| 2000 | char efs_name[PATH_MAX], efs_tmp_name[PATH_MAX]; |
| 2001 | int ret; |
| 2002 | int fd; |
| 2003 | ssize_t bytes = -1; |
| 2004 | |
| 2005 | /* Create a tmp file and rename it at the end so that make does not get confused |
| 2006 | if amdfwtool is killed for some unexpected reasons. */ |
| 2007 | ret = snprintf(efs_tmp_name, sizeof(efs_tmp_name), "%s%s%s", |
| 2008 | output, EFS_FILE_SUFFIX, TMP_FILE_SUFFIX); |
| 2009 | if (ret < 0) { |
| 2010 | fprintf(stderr, "Error %s forming EFS tmp file name: %d\n", |
| 2011 | strerror(errno), ret); |
| 2012 | exit(1); |
| 2013 | } else if ((unsigned int)ret >= sizeof(efs_tmp_name)) { |
| 2014 | fprintf(stderr, "EFS File name %d > %zu\n", ret, sizeof(efs_tmp_name)); |
| 2015 | exit(1); |
| 2016 | } |
| 2017 | |
| 2018 | fd = open(efs_tmp_name, O_RDWR | O_CREAT | O_TRUNC, 0666); |
| 2019 | if (fd < 0) { |
| 2020 | fprintf(stderr, "Error: Opening %s file: %s\n", efs_tmp_name, strerror(errno)); |
| 2021 | exit(1); |
| 2022 | } |
| 2023 | |
| 2024 | bytes = write_from_buf_to_file(fd, amd_romsig, sizeof(*amd_romsig)); |
| 2025 | if (bytes != sizeof(*amd_romsig)) { |
| 2026 | fprintf(stderr, "Error: Writing to file %s failed\n", efs_tmp_name); |
| 2027 | exit(1); |
| 2028 | } |
| 2029 | close(fd); |
| 2030 | |
| 2031 | /* Rename the tmp file */ |
| 2032 | ret = snprintf(efs_name, sizeof(efs_name), "%s%s", output, EFS_FILE_SUFFIX); |
| 2033 | if (ret < 0) { |
| 2034 | fprintf(stderr, "Error %s forming EFS file name: %d\n", strerror(errno), ret); |
| 2035 | exit(1); |
| 2036 | } |
| 2037 | |
| 2038 | if (rename(efs_tmp_name, efs_name)) { |
| 2039 | fprintf(stderr, "Error: renaming file %s to %s\n", efs_tmp_name, efs_name); |
| 2040 | exit(1); |
| 2041 | } |
| 2042 | |
| 2043 | return bytes; |
| 2044 | } |
| 2045 | |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2046 | static int identify_platform(char *soc_name) |
| 2047 | { |
| 2048 | if (!strcasecmp(soc_name, "Stoneyridge")) |
| 2049 | return PLATFORM_STONEYRIDGE; |
| 2050 | else if (!strcasecmp(soc_name, "Raven")) |
| 2051 | return PLATFORM_RAVEN; |
| 2052 | else if (!strcasecmp(soc_name, "Picasso")) |
| 2053 | return PLATFORM_PICASSO; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 2054 | else if (!strcasecmp(soc_name, "Cezanne")) |
| 2055 | return PLATFORM_CEZANNE; |
Zheng Bao | 535ec53 | 2021-08-12 16:30:19 +0800 | [diff] [blame] | 2056 | else if (!strcasecmp(soc_name, "Mendocino")) |
| 2057 | return PLATFORM_MENDOCINO; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2058 | else if (!strcasecmp(soc_name, "Renoir")) |
| 2059 | return PLATFORM_RENOIR; |
| 2060 | else if (!strcasecmp(soc_name, "Lucienne")) |
| 2061 | return PLATFORM_LUCIENNE; |
Martin Roth | 20646cd | 2023-01-04 21:27:06 -0700 | [diff] [blame] | 2062 | else if (!strcasecmp(soc_name, "Phoenix")) |
| 2063 | return PLATFORM_PHOENIX; |
Martin Roth | 1349083 | 2022-10-06 17:18:02 -0600 | [diff] [blame] | 2064 | else if (!strcasecmp(soc_name, "Glinda")) |
| 2065 | return PLATFORM_GLINDA; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2066 | else |
| 2067 | return PLATFORM_UNKNOWN; |
| 2068 | |
| 2069 | } |
| 2070 | |
Felix Held | f8e2e47 | 2022-03-29 23:28:49 +0200 | [diff] [blame] | 2071 | static bool needs_ish(enum platform platform_type) |
| 2072 | { |
Zheng Bao | de6f198 | 2022-10-16 20:32:43 +0800 | [diff] [blame] | 2073 | if (platform_type == PLATFORM_MENDOCINO || platform_type == PLATFORM_PHOENIX || platform_type == PLATFORM_GLINDA) |
Felix Held | f8e2e47 | 2022-03-29 23:28:49 +0200 | [diff] [blame] | 2074 | return true; |
| 2075 | else |
| 2076 | return false; |
| 2077 | } |
| 2078 | |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 2079 | static bool is_second_gen(enum platform platform_type) |
| 2080 | { |
| 2081 | switch (platform_type) { |
| 2082 | case PLATFORM_STONEYRIDGE: |
| 2083 | case PLATFORM_RAVEN: |
| 2084 | case PLATFORM_PICASSO: |
| 2085 | return false; |
| 2086 | case PLATFORM_RENOIR: |
| 2087 | case PLATFORM_LUCIENNE: |
| 2088 | case PLATFORM_CEZANNE: |
Jon Murphy | 9969f4b | 2022-08-05 13:56:38 -0600 | [diff] [blame] | 2089 | case PLATFORM_MENDOCINO: |
Zheng Bao | de6f198 | 2022-10-16 20:32:43 +0800 | [diff] [blame] | 2090 | case PLATFORM_PHOENIX: |
| 2091 | case PLATFORM_GLINDA: |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 2092 | return true; |
| 2093 | case PLATFORM_UNKNOWN: |
| 2094 | default: |
| 2095 | fprintf(stderr, "Error: Invalid SOC name.\n\n"); |
| 2096 | return false; |
| 2097 | } |
| 2098 | } |
| 2099 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2100 | int main(int argc, char **argv) |
| 2101 | { |
Marshall Dawson | 0e02ce8 | 2019-03-04 16:50:37 -0700 | [diff] [blame] | 2102 | int c; |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2103 | int retval = 0; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2104 | char *tmp; |
Martin Roth | 8806f7f | 2016-11-08 10:44:18 -0700 | [diff] [blame] | 2105 | char *rom = NULL; |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 2106 | embedded_firmware *amd_romsig; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2107 | psp_directory_table *pspdir = NULL; |
| 2108 | psp_directory_table *pspdir2 = NULL; |
| 2109 | psp_directory_table *pspdir2_b = NULL; |
Zheng Bao | 6e2c5a3 | 2021-11-10 14:09:06 +0800 | [diff] [blame] | 2110 | bool comboable = false; |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 2111 | int fuse_defined = 0; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2112 | int targetfd; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2113 | char *output = NULL, *config = NULL; |
| 2114 | FILE *config_handle; |
Zheng Bao | 9c8ce3e | 2020-09-28 10:36:29 +0800 | [diff] [blame] | 2115 | context ctx = { 0 }; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2116 | /* Values cleared after each firmware or parameter, regardless if N/A */ |
| 2117 | uint8_t sub = 0, instance = 0; |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2118 | uint32_t body_location = 0; |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2119 | uint32_t efs_location = 0; |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2120 | bool any_location = 0; |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2121 | uint32_t romsig_offset; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2122 | uint32_t rom_base_address; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2123 | uint8_t soc_id = PLATFORM_UNKNOWN; |
| 2124 | uint8_t efs_spi_readmode = 0xff; |
| 2125 | uint8_t efs_spi_speed = 0xff; |
| 2126 | uint8_t efs_spi_micron_flag = 0xff; |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 2127 | const char *signed_output_file = NULL; |
| 2128 | uint64_t signed_start_addr = 0x0; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2129 | |
Fred Reitberger | f36b013 | 2022-06-29 13:54:57 -0400 | [diff] [blame] | 2130 | amd_cb_config cb_config = { 0 }; |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 2131 | int debug = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2132 | int list_deps = 0; |
| 2133 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2134 | while (1) { |
| 2135 | int optindex = 0; |
| 2136 | |
| 2137 | c = getopt_long(argc, argv, optstring, long_options, &optindex); |
| 2138 | |
| 2139 | if (c == -1) |
| 2140 | break; |
| 2141 | |
| 2142 | switch (c) { |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2143 | case AMDFW_OPT_XHCI: |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 2144 | register_fw_filename(AMD_FW_XHCI, sub, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2145 | sub = instance = 0; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2146 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2147 | case AMDFW_OPT_IMC: |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 2148 | register_fw_filename(AMD_FW_IMC, sub, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2149 | sub = instance = 0; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2150 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2151 | case AMDFW_OPT_GEC: |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 2152 | register_fw_filename(AMD_FW_GEC, sub, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2153 | sub = instance = 0; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2154 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2155 | case AMDFW_OPT_COMBO: |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2156 | comboable = true; |
Marshall Dawson | 67d868d | 2019-02-28 11:43:40 -0700 | [diff] [blame] | 2157 | break; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2158 | case AMDFW_OPT_RECOVERY_AB: |
| 2159 | cb_config.recovery_ab = true; |
| 2160 | break; |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 2161 | case AMDFW_OPT_RECOVERY_AB_SINGLE_COPY: |
| 2162 | cb_config.recovery_ab = true; |
| 2163 | cb_config.recovery_ab_single_copy = true; |
| 2164 | break; |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 2165 | case AMDFW_OPT_USE_COMBO: |
| 2166 | cb_config.use_combo = true; |
| 2167 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2168 | case AMDFW_OPT_MULTILEVEL: |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2169 | cb_config.multi_level = true; |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 2170 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2171 | case AMDFW_OPT_UNLOCK: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2172 | register_fw_token_unlock(); |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2173 | cb_config.unlock_secure = true; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2174 | sub = instance = 0; |
| 2175 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2176 | case AMDFW_OPT_USE_PSPSECUREOS: |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2177 | cb_config.use_secureos = true; |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 2178 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2179 | case AMDFW_OPT_INSTANCE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2180 | instance = strtoul(optarg, &tmp, 16); |
| 2181 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2182 | case AMDFW_OPT_LOAD_MP2FW: |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2183 | cb_config.load_mp2_fw = true; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2184 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2185 | case AMDFW_OPT_NVRAM: |
Marshall Dawson | dbae632 | 2019-03-04 10:31:03 -0700 | [diff] [blame] | 2186 | register_fw_filename(AMD_FW_PSP_NVRAM, sub, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2187 | sub = instance = 0; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2188 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2189 | case AMDFW_OPT_FUSE: |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 2190 | register_fw_fuse(optarg); |
| 2191 | fuse_defined = 1; |
| 2192 | sub = 0; |
| 2193 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2194 | case AMDFW_OPT_APCB: |
Zheng Bao | 5caca94 | 2020-12-04 16:39:38 +0800 | [diff] [blame] | 2195 | if ((instance & 0xF0) == 0) |
| 2196 | register_bdt_data(AMD_BIOS_APCB, sub, instance & 0xF, optarg); |
| 2197 | else |
| 2198 | register_bdt_data(AMD_BIOS_APCB_BK, sub, |
| 2199 | instance & 0xF, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2200 | sub = instance = 0; |
| 2201 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2202 | case AMDFW_OPT_APOBBASE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2203 | /* APOB destination */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2204 | register_bios_fw_addr(AMD_BIOS_APOB, 0, optarg, 0); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2205 | sub = instance = 0; |
| 2206 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2207 | case AMDFW_OPT_APOB_NVBASE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2208 | /* APOB NV source */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2209 | register_bios_fw_addr(AMD_BIOS_APOB_NV, optarg, 0, 0); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2210 | sub = instance = 0; |
| 2211 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2212 | case AMDFW_OPT_APOB_NVSIZE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2213 | /* APOB NV size */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2214 | register_bios_fw_addr(AMD_BIOS_APOB_NV, 0, 0, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2215 | sub = instance = 0; |
| 2216 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2217 | case AMDFW_OPT_BIOSBIN: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2218 | register_bdt_data(AMD_BIOS_BIN, sub, instance, optarg); |
| 2219 | sub = instance = 0; |
| 2220 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2221 | case AMDFW_OPT_BIOSBIN_SOURCE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2222 | /* BIOS source */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2223 | register_bios_fw_addr(AMD_BIOS_BIN, optarg, 0, 0); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2224 | sub = instance = 0; |
| 2225 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2226 | case AMDFW_OPT_BIOSBIN_DEST: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2227 | /* BIOS destination */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2228 | register_bios_fw_addr(AMD_BIOS_BIN, 0, optarg, 0); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2229 | sub = instance = 0; |
| 2230 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2231 | case AMDFW_OPT_BIOS_UNCOMP_SIZE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2232 | /* BIOS destination size */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2233 | register_bios_fw_addr(AMD_BIOS_BIN, 0, 0, optarg); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2234 | sub = instance = 0; |
| 2235 | break; |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 2236 | case LONGOPT_BIOS_SIG: |
| 2237 | /* BIOS signature size */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2238 | register_bios_fw_addr(AMD_BIOS_SIG, 0, 0, optarg); |
Ritul Guru | 9a321f3 | 2022-07-29 11:06:40 +0530 | [diff] [blame] | 2239 | sub = instance = 0; |
| 2240 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2241 | case AMDFW_OPT_UCODE: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2242 | register_bdt_data(AMD_BIOS_UCODE, sub, |
| 2243 | instance, optarg); |
| 2244 | sub = instance = 0; |
| 2245 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2246 | case AMDFW_OPT_LOAD_S0I3: |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2247 | cb_config.s0i3 = true; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2248 | break; |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 2249 | case AMDFW_OPT_SPL_TABLE: |
| 2250 | register_fw_filename(AMD_FW_SPL, sub, optarg); |
| 2251 | sub = instance = 0; |
| 2252 | cb_config.have_mb_spl = true; |
| 2253 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2254 | case AMDFW_OPT_WHITELIST: |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2255 | register_fw_filename(AMD_FW_PSP_WHITELIST, sub, optarg); |
| 2256 | sub = instance = 0; |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 2257 | cb_config.have_whitelist = true; |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2258 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2259 | case AMDFW_OPT_VERSTAGE: |
Martin Roth | d3ce8c8 | 2019-07-13 20:13:07 -0600 | [diff] [blame] | 2260 | register_fw_filename(AMD_FW_PSP_VERSTAGE, sub, optarg); |
| 2261 | sub = instance = 0; |
| 2262 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2263 | case AMDFW_OPT_VERSTAGE_SIG: |
Martin Roth | b1f648f | 2020-09-01 09:36:59 -0600 | [diff] [blame] | 2264 | register_fw_filename(AMD_FW_VERSTAGE_SIG, sub, optarg); |
| 2265 | sub = instance = 0; |
| 2266 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2267 | case AMDFW_OPT_SOC_NAME: |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2268 | soc_id = identify_platform(optarg); |
| 2269 | if (soc_id == PLATFORM_UNKNOWN) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2270 | fprintf(stderr, "Error: Invalid SOC name specified\n\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2271 | retval = 1; |
| 2272 | } |
| 2273 | sub = instance = 0; |
| 2274 | break; |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 2275 | case AMDFW_OPT_SIGNED_OUTPUT: |
| 2276 | signed_output_file = optarg; |
| 2277 | sub = instance = 0; |
| 2278 | break; |
| 2279 | case AMDFW_OPT_SIGNED_ADDR: |
| 2280 | signed_start_addr = strtoull(optarg, NULL, 10); |
| 2281 | sub = instance = 0; |
| 2282 | break; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2283 | case LONGOPT_SPI_READ_MODE: |
| 2284 | efs_spi_readmode = strtoull(optarg, NULL, 16); |
| 2285 | sub = instance = 0; |
| 2286 | break; |
| 2287 | case LONGOPT_SPI_SPEED: |
| 2288 | efs_spi_speed = strtoull(optarg, NULL, 16); |
| 2289 | sub = instance = 0; |
| 2290 | break; |
| 2291 | case LONGOPT_SPI_MICRON_FLAG: |
| 2292 | efs_spi_micron_flag = strtoull(optarg, NULL, 16); |
| 2293 | sub = instance = 0; |
| 2294 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2295 | case AMDFW_OPT_OUTPUT: |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2296 | output = optarg; |
| 2297 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2298 | case AMDFW_OPT_FLASHSIZE: |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2299 | ctx.rom_size = (uint32_t)strtoul(optarg, &tmp, 16); |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2300 | if (*tmp != '\0') { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2301 | fprintf(stderr, "Error: ROM size specified" |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2302 | " incorrectly (%s)\n\n", optarg); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2303 | retval = 1; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2304 | } |
| 2305 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2306 | case AMDFW_OPT_LOCATION: |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2307 | efs_location = (uint32_t)strtoul(optarg, &tmp, 16); |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2308 | if (*tmp != '\0') { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2309 | fprintf(stderr, "Error: Directory Location specified" |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2310 | " incorrectly (%s)\n\n", optarg); |
| 2311 | retval = 1; |
| 2312 | } |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2313 | if (body_location == 0) |
| 2314 | body_location = efs_location; |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2315 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2316 | case AMDFW_OPT_ANYWHERE: |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2317 | any_location = 1; |
| 2318 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2319 | case AMDFW_OPT_SHAREDMEM: |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 2320 | /* shared memory destination */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2321 | register_bios_fw_addr(AMD_BIOS_PSP_SHARED_MEM, 0, optarg, 0); |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 2322 | sub = instance = 0; |
| 2323 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2324 | case AMDFW_OPT_SHAREDMEM_SIZE: |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 2325 | /* shared memory size */ |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2326 | register_bios_fw_addr(AMD_BIOS_PSP_SHARED_MEM, NULL, NULL, optarg); |
Martin Roth | 9455474 | 2020-04-14 14:59:36 -0600 | [diff] [blame] | 2327 | sub = instance = 0; |
| 2328 | break; |
Ritul Guru | a2cb340 | 2022-08-29 00:51:08 +0530 | [diff] [blame] | 2329 | case LONGOPT_NVRAM_BASE: |
| 2330 | /* PSP NV base */ |
| 2331 | register_amd_psp_fw_addr(AMD_FW_PSP_NVRAM, sub, optarg, 0); |
| 2332 | sub = instance = 0; |
| 2333 | break; |
| 2334 | case LONGOPT_NVRAM_SIZE: |
| 2335 | /* PSP NV size */ |
| 2336 | register_amd_psp_fw_addr(AMD_FW_PSP_NVRAM, sub, 0, optarg); |
| 2337 | sub = instance = 0; |
| 2338 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2339 | case AMDFW_OPT_CONFIG: |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2340 | config = optarg; |
| 2341 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2342 | case AMDFW_OPT_DEBUG: |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 2343 | debug = 1; |
| 2344 | break; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2345 | case AMDFW_OPT_HELP: |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2346 | usage(); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2347 | return 0; |
Zheng Bao | 806892a | 2021-04-27 17:21:54 +0800 | [diff] [blame] | 2348 | case AMDFW_OPT_LIST_DEPEND: |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2349 | list_deps = 1; |
| 2350 | break; |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2351 | case AMDFW_OPT_BODY_LOCATION: |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2352 | body_location = (uint32_t)strtoul(optarg, &tmp, 16); |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2353 | if (*tmp != '\0') { |
| 2354 | fprintf(stderr, "Error: Body Location specified" |
| 2355 | " incorrectly (%s)\n\n", optarg); |
| 2356 | retval = 1; |
| 2357 | } |
| 2358 | break; |
| 2359 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2360 | default: |
| 2361 | break; |
| 2362 | } |
| 2363 | } |
| 2364 | |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 2365 | cb_config.second_gen = is_second_gen(soc_id); |
| 2366 | |
Felix Held | f8e2e47 | 2022-03-29 23:28:49 +0200 | [diff] [blame] | 2367 | if (needs_ish(soc_id)) |
| 2368 | cb_config.need_ish = true; |
| 2369 | |
Felix Held | 830add6 | 2022-03-29 23:28:10 +0200 | [diff] [blame] | 2370 | if (cb_config.need_ish) |
| 2371 | cb_config.recovery_ab = true; |
| 2372 | |
| 2373 | if (cb_config.recovery_ab) |
| 2374 | cb_config.multi_level = true; |
| 2375 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2376 | if (config) { |
| 2377 | config_handle = fopen(config, "r"); |
| 2378 | if (config_handle == NULL) { |
| 2379 | fprintf(stderr, "Can not open file %s for reading: %s\n", |
| 2380 | config, strerror(errno)); |
| 2381 | exit(1); |
| 2382 | } |
| 2383 | if (process_config(config_handle, &cb_config, list_deps) == 0) { |
| 2384 | fprintf(stderr, "Configuration file %s parsing error\n", config); |
| 2385 | fclose(config_handle); |
| 2386 | exit(1); |
| 2387 | } |
| 2388 | fclose(config_handle); |
| 2389 | } |
Zheng Bao | 9e90807 | 2020-10-28 11:39:13 +0800 | [diff] [blame] | 2390 | /* For debug. */ |
| 2391 | if (debug) { |
| 2392 | dump_psp_firmwares(amd_psp_fw_table); |
| 2393 | dump_bdt_firmwares(amd_bios_table); |
| 2394 | } |
| 2395 | |
Marshall Dawson | ef79fcc | 2019-04-01 10:16:41 -0600 | [diff] [blame] | 2396 | if (!fuse_defined) |
| 2397 | register_fw_fuse(DEFAULT_SOFT_FUSE_CHAIN); |
| 2398 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2399 | if (!output && !list_deps) { |
| 2400 | fprintf(stderr, "Error: Output value is not specified.\n\n"); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2401 | retval = 1; |
| 2402 | } |
| 2403 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2404 | if ((ctx.rom_size % 1024 != 0) && !list_deps) { |
| 2405 | fprintf(stderr, "Error: ROM Size (%d bytes) should be a multiple of" |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2406 | " 1024 bytes.\n\n", ctx.rom_size); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2407 | retval = 1; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2410 | if ((ctx.rom_size < MIN_ROM_KB * 1024) && !list_deps) { |
| 2411 | fprintf(stderr, "Error: ROM Size (%dKB) must be at least %dKB.\n\n", |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2412 | ctx.rom_size / 1024, MIN_ROM_KB); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2413 | retval = 1; |
| 2414 | } |
| 2415 | |
| 2416 | if (retval) { |
| 2417 | usage(); |
| 2418 | return retval; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2421 | if (list_deps) { |
| 2422 | return retval; |
| 2423 | } |
| 2424 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2425 | printf(" AMDFWTOOL Using ROM size of %dKB\n", ctx.rom_size / 1024); |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2426 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2427 | rom_base_address = 0xFFFFFFFF - ctx.rom_size + 1; |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2428 | if (efs_location && (efs_location < rom_base_address)) { |
| 2429 | fprintf(stderr, "Error: EFS/Directory location outside of ROM.\n\n"); |
| 2430 | return 1; |
| 2431 | } |
| 2432 | |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2433 | if (!efs_location && body_location) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2434 | fprintf(stderr, "Error AMDFW body location specified without EFS location.\n"); |
| 2435 | return 1; |
| 2436 | } |
| 2437 | |
| 2438 | /* |
| 2439 | * On boards using vboot, there can be more than one instance of EFS + AMDFW Body. |
| 2440 | * For the instance in the RO section, there is no need to split EFS + AMDFW body |
| 2441 | * currently. This condition is to ensure that it is not accidentally split. Revisit |
| 2442 | * this condition if such a need arises in the future. |
| 2443 | */ |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2444 | if (!any_location && body_location != efs_location) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2445 | fprintf(stderr, "Error: EFS cannot be separate from AMDFW Body.\n"); |
| 2446 | return 1; |
| 2447 | } |
| 2448 | |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2449 | if (body_location != efs_location && |
| 2450 | body_location < ALIGN(efs_location + sizeof(embedded_firmware), BLOB_ALIGNMENT)) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2451 | fprintf(stderr, "Error: Insufficient space between EFS and Blobs.\n"); |
| 2452 | fprintf(stderr, " Require safe spacing of 256 bytes\n"); |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2453 | return 1; |
| 2454 | } |
| 2455 | |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2456 | if (any_location) { |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2457 | if ((body_location & 0x3f) || (efs_location & 0x3f)) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2458 | fprintf(stderr, "Error: Invalid Directory/EFS location.\n"); |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2459 | fprintf(stderr, " Valid locations are 64-byte aligned\n"); |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2460 | return 1; |
| 2461 | } |
| 2462 | } else { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2463 | switch (efs_location) { |
Zheng Bao | 92c920b | 2022-12-08 13:56:13 +0800 | [diff] [blame] | 2464 | case 0: |
| 2465 | case 0xFFFA0000: |
| 2466 | case 0xFFF20000: |
| 2467 | case 0xFFE20000: |
| 2468 | case 0xFFC20000: |
| 2469 | case 0xFF820000: |
| 2470 | case 0xFF020000: |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2471 | break; |
| 2472 | default: |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2473 | fprintf(stderr, "Error: Invalid Directory location.\n"); |
| 2474 | fprintf(stderr, " Valid locations are 0xFFFA0000, 0xFFF20000,\n"); |
| 2475 | fprintf(stderr, " 0xFFE20000, 0xFFC20000, 0xFF820000, 0xFF020000\n"); |
Martin Roth | 37305e7 | 2020-04-07 14:16:39 -0600 | [diff] [blame] | 2476 | return 1; |
| 2477 | } |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2478 | } |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2479 | ctx.rom = malloc(ctx.rom_size); |
| 2480 | if (!ctx.rom) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2481 | fprintf(stderr, "Error: Failed to allocate memory\n"); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2482 | return 1; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2483 | } |
| 2484 | memset(ctx.rom, 0xFF, ctx.rom_size); |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2485 | |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2486 | if (efs_location) { |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2487 | if (efs_location != body_location) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2488 | romsig_offset = efs_location - rom_base_address; |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2489 | ctx.current = body_location - rom_base_address; |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2490 | } else { |
| 2491 | romsig_offset = efs_location - rom_base_address; |
| 2492 | ctx.current = romsig_offset + sizeof(embedded_firmware); |
| 2493 | } |
| 2494 | } else { |
| 2495 | romsig_offset = AMD_ROMSIG_OFFSET; |
| 2496 | ctx.current = romsig_offset + sizeof(embedded_firmware); |
| 2497 | } |
Martin Roth | 0d3b118 | 2017-10-03 14:16:04 -0600 | [diff] [blame] | 2498 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2499 | amd_romsig = BUFF_OFFSET(ctx, romsig_offset); |
Marshall Dawson | 239286c | 2019-02-23 16:42:46 -0700 | [diff] [blame] | 2500 | amd_romsig->signature = EMBEDDED_FW_SIGNATURE; |
| 2501 | amd_romsig->imc_entry = 0; |
| 2502 | amd_romsig->gec_entry = 0; |
| 2503 | amd_romsig->xhci_entry = 0; |
Martin Roth | 60f1551 | 2016-11-08 09:55:01 -0700 | [diff] [blame] | 2504 | |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2505 | if (soc_id != PLATFORM_UNKNOWN) { |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 2506 | retval = set_efs_table(soc_id, &cb_config, amd_romsig, efs_spi_readmode, |
Zheng Bao | 570645d | 2021-11-03 10:25:03 +0800 | [diff] [blame] | 2507 | efs_spi_speed, efs_spi_micron_flag); |
| 2508 | if (retval) { |
| 2509 | fprintf(stderr, "ERROR: Failed to initialize EFS table!\n"); |
| 2510 | return retval; |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2511 | } |
| 2512 | } else { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2513 | fprintf(stderr, "WARNING: No SOC name specified.\n"); |
Matt Papageorge | be4376c | 2020-06-15 11:18:15 -0500 | [diff] [blame] | 2514 | } |
| 2515 | |
Felix Held | 21a8e38 | 2022-03-29 23:10:45 +0200 | [diff] [blame] | 2516 | if (cb_config.need_ish) |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 2517 | ctx.address_mode = AMD_ADDR_REL_TAB; |
Zheng Bao | c3007f3 | 2022-04-03 12:53:51 +0800 | [diff] [blame] | 2518 | else if (cb_config.second_gen) |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 2519 | ctx.address_mode = AMD_ADDR_REL_BIOS; |
Zheng Bao | da83d2c | 2021-06-04 19:03:10 +0800 | [diff] [blame] | 2520 | else |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 2521 | ctx.address_mode = AMD_ADDR_PHYSICAL; |
Zheng Bao | da83d2c | 2021-06-04 19:03:10 +0800 | [diff] [blame] | 2522 | printf(" AMDFWTOOL Using firmware directory location of %s address: 0x%08x\n", |
Robert Zieba | 29bc79f | 2022-03-14 15:59:12 -0600 | [diff] [blame] | 2523 | ctx.address_mode == AMD_ADDR_PHYSICAL ? "absolute" : "relative", |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 2524 | RUN_CURRENT(ctx)); |
Zheng Bao | da83d2c | 2021-06-04 19:03:10 +0800 | [diff] [blame] | 2525 | |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2526 | integrate_firmwares(&ctx, amd_romsig, amd_fw_table); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2527 | |
Elyes Haouas | 7d67a19 | 2022-10-14 09:58:29 +0200 | [diff] [blame] | 2528 | ctx.current = ALIGN_UP(ctx.current, 0x10000U); /* TODO: is it necessary? */ |
Zheng Bao | 6fff249 | 2021-11-15 19:53:21 +0800 | [diff] [blame] | 2529 | ctx.current_table = 0; |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2530 | |
Kangheui Won | 3c164e1 | 2021-12-03 20:25:05 +1100 | [diff] [blame] | 2531 | /* If the tool is invoked with command-line options to keep the signed PSP |
| 2532 | binaries separate, process the signed binaries first. */ |
| 2533 | if (signed_output_file && signed_start_addr) |
| 2534 | process_signed_psp_firmwares(signed_output_file, |
| 2535 | amd_psp_fw_table, |
| 2536 | signed_start_addr, |
| 2537 | soc_id); |
| 2538 | |
Zheng Bao | 481661e | 2021-08-20 14:47:46 +0800 | [diff] [blame] | 2539 | if (cb_config.multi_level) { |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 2540 | /* Do 2nd PSP directory followed by 1st */ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2541 | pspdir2 = new_psp_dir(&ctx, cb_config.multi_level); |
| 2542 | integrate_psp_firmwares(&ctx, pspdir2, NULL, NULL, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 2543 | amd_psp_fw_table, PSPL2_COOKIE, soc_id, &cb_config); |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 2544 | if (cb_config.recovery_ab && !cb_config.recovery_ab_single_copy) { |
| 2545 | /* Create a copy of PSP Directory 2 in the backup slot B. |
| 2546 | Related biosdir2_b copy will be created later. */ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2547 | pspdir2_b = new_psp_dir(&ctx, cb_config.multi_level); |
| 2548 | integrate_psp_firmwares(&ctx, pspdir2_b, NULL, NULL, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 2549 | amd_psp_fw_table, PSPL2_COOKIE, soc_id, &cb_config); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2550 | } else { |
Karthikeyan Ramasubramanian | ad06bae | 2022-04-08 14:19:55 -0600 | [diff] [blame] | 2551 | /* |
| 2552 | * Either the platform is using only one slot or B is same as above |
| 2553 | * directories for A. Skip creating pspdir2_b here to save flash space. |
| 2554 | * Related biosdir2_b will be skipped automatically. |
| 2555 | */ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2556 | pspdir2_b = NULL; /* More explicitly */ |
| 2557 | } |
Zheng Bao | 481661e | 2021-08-20 14:47:46 +0800 | [diff] [blame] | 2558 | pspdir = new_psp_dir(&ctx, cb_config.multi_level); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2559 | integrate_psp_firmwares(&ctx, pspdir, pspdir2, pspdir2_b, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 2560 | amd_psp_fw_table, PSP_COOKIE, soc_id, &cb_config); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 2561 | } else { |
| 2562 | /* flat: PSP 1 cookie and no pointer to 2nd table */ |
Zheng Bao | 481661e | 2021-08-20 14:47:46 +0800 | [diff] [blame] | 2563 | pspdir = new_psp_dir(&ctx, cb_config.multi_level); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2564 | integrate_psp_firmwares(&ctx, pspdir, NULL, NULL, |
Zheng Bao | fdd47ef | 2021-09-17 13:30:08 +0800 | [diff] [blame] | 2565 | amd_psp_fw_table, PSP_COOKIE, soc_id, &cb_config); |
Marshall Dawson | 24f73d4 | 2019-04-01 10:48:43 -0600 | [diff] [blame] | 2566 | } |
Marshall Dawson | 2794a86 | 2019-03-04 16:53:15 -0700 | [diff] [blame] | 2567 | |
Marshall Dawson | 0e02ce8 | 2019-03-04 16:50:37 -0700 | [diff] [blame] | 2568 | if (comboable) |
Zheng Bao | b749d3f | 2021-10-23 20:20:21 +0800 | [diff] [blame] | 2569 | amd_romsig->new_psp_directory = BUFF_TO_RUN(ctx, pspdir); |
Marshall Dawson | 67d868d | 2019-02-28 11:43:40 -0700 | [diff] [blame] | 2570 | else |
Felix Held | ad68b07 | 2021-10-18 14:00:35 +0200 | [diff] [blame] | 2571 | amd_romsig->psp_directory = BUFF_TO_RUN(ctx, pspdir); |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2572 | |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 2573 | if (cb_config.use_combo) { |
| 2574 | psp_combo_directory *combo_dir = new_combo_dir(&ctx); |
| 2575 | amd_romsig->combo_psp_directory = BUFF_TO_RUN(ctx, combo_dir); |
| 2576 | /* 0 -Compare PSP ID, 1 -Compare chip family ID */ |
| 2577 | combo_dir->entries[0].id_sel = 0; |
| 2578 | combo_dir->entries[0].id = get_psp_id(soc_id); |
| 2579 | combo_dir->entries[0].lvl2_addr = BUFF_TO_RUN(ctx, pspdir); |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 2580 | |
Zheng Bao | 993b43f | 2021-11-10 12:21:46 +0800 | [diff] [blame] | 2581 | combo_dir->header.lookup = 1; |
| 2582 | fill_dir_header(combo_dir, 1, PSP2_COOKIE, &ctx); |
| 2583 | } |
Zheng Bao | 4fcc9f2 | 2015-11-20 12:29:04 +0800 | [diff] [blame] | 2584 | |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2585 | if (have_bios_tables(amd_bios_table)) { |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2586 | bios_directory_table *biosdir = NULL; |
Zheng Bao | 481661e | 2021-08-20 14:47:46 +0800 | [diff] [blame] | 2587 | if (cb_config.multi_level) { |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2588 | /* Do 2nd level BIOS directory followed by 1st */ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2589 | bios_directory_table *biosdir2 = NULL; |
| 2590 | bios_directory_table *biosdir2_b = NULL; |
| 2591 | |
| 2592 | biosdir2 = new_bios_dir(&ctx, cb_config.multi_level); |
| 2593 | |
Zheng Bao | edd1e36 | 2021-11-04 17:47:07 +0800 | [diff] [blame] | 2594 | integrate_bios_firmwares(&ctx, biosdir2, NULL, |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 2595 | amd_bios_table, BHDL2_COOKIE, &cb_config); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2596 | if (cb_config.recovery_ab) { |
| 2597 | if (pspdir2_b != NULL) { |
| 2598 | biosdir2_b = new_bios_dir(&ctx, cb_config.multi_level); |
| 2599 | integrate_bios_firmwares(&ctx, biosdir2_b, NULL, |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 2600 | amd_bios_table, BHDL2_COOKIE, &cb_config); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2601 | } |
| 2602 | add_psp_firmware_entry(&ctx, pspdir2, biosdir2, |
| 2603 | AMD_FW_BIOS_TABLE, TABLE_ALIGNMENT); |
| 2604 | if (pspdir2_b != NULL) |
| 2605 | add_psp_firmware_entry(&ctx, pspdir2_b, biosdir2_b, |
| 2606 | AMD_FW_BIOS_TABLE, TABLE_ALIGNMENT); |
| 2607 | } else { |
| 2608 | biosdir = new_bios_dir(&ctx, cb_config.multi_level); |
| 2609 | integrate_bios_firmwares(&ctx, biosdir, biosdir2, |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 2610 | amd_bios_table, BHD_COOKIE, &cb_config); |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2611 | } |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2612 | } else { |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 2613 | /* flat: BHD1 cookie and no pointer to 2nd table */ |
Zheng Bao | 481661e | 2021-08-20 14:47:46 +0800 | [diff] [blame] | 2614 | biosdir = new_bios_dir(&ctx, cb_config.multi_level); |
Zheng Bao | edd1e36 | 2021-11-04 17:47:07 +0800 | [diff] [blame] | 2615 | integrate_bios_firmwares(&ctx, biosdir, NULL, |
Zheng Bao | 96a3371 | 2021-06-11 15:54:40 +0800 | [diff] [blame] | 2616 | amd_bios_table, BHD_COOKIE, &cb_config); |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2617 | } |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 2618 | switch (soc_id) { |
| 2619 | case PLATFORM_RENOIR: |
| 2620 | case PLATFORM_LUCIENNE: |
| 2621 | case PLATFORM_CEZANNE: |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 2622 | if (!cb_config.recovery_ab) |
| 2623 | amd_romsig->bios3_entry = BUFF_TO_RUN(ctx, biosdir); |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 2624 | break; |
Zheng Bao | 535ec53 | 2021-08-12 16:30:19 +0800 | [diff] [blame] | 2625 | case PLATFORM_MENDOCINO: |
Zheng Bao | de6f198 | 2022-10-16 20:32:43 +0800 | [diff] [blame] | 2626 | case PLATFORM_PHOENIX: |
| 2627 | case PLATFORM_GLINDA: |
Zheng Bao | 535ec53 | 2021-08-12 16:30:19 +0800 | [diff] [blame] | 2628 | break; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 2629 | case PLATFORM_STONEYRIDGE: |
| 2630 | case PLATFORM_RAVEN: |
| 2631 | case PLATFORM_PICASSO: |
| 2632 | default: |
| 2633 | amd_romsig->bios1_entry = BUFF_TO_RUN(ctx, biosdir); |
| 2634 | break; |
| 2635 | } |
Marshall Dawson | ce2b2ba | 2019-03-19 14:45:31 -0600 | [diff] [blame] | 2636 | } |
| 2637 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 2638 | /* Free the filename. */ |
| 2639 | free_psp_firmware_filenames(amd_psp_fw_table); |
| 2640 | free_bdt_firmware_filenames(amd_bios_table); |
| 2641 | |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2642 | targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2643 | if (targetfd >= 0) { |
Zheng Bao | 4739691 | 2020-09-29 17:33:17 +0800 | [diff] [blame] | 2644 | ssize_t bytes; |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2645 | uint32_t offset = body_location ? body_location - rom_base_address : AMD_ROMSIG_OFFSET; |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2646 | |
| 2647 | bytes = write(targetfd, BUFF_OFFSET(ctx, offset), ctx.current - offset); |
| 2648 | if (bytes != ctx.current - offset) { |
Zheng Bao | 4739691 | 2020-09-29 17:33:17 +0800 | [diff] [blame] | 2649 | fprintf(stderr, "Error: Writing to file %s failed\n", output); |
| 2650 | retval = 1; |
| 2651 | } |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2652 | close(targetfd); |
| 2653 | } else { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 2654 | fprintf(stderr, "Error: could not open file: %s\n", output); |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2655 | retval = 1; |
| 2656 | } |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2657 | |
Zheng Bao | 99945dc | 2023-01-02 10:55:56 +0800 | [diff] [blame] | 2658 | if (efs_location != body_location) { |
Karthikeyan Ramasubramanian | ecb4e31 | 2022-11-02 16:53:54 -0600 | [diff] [blame] | 2659 | ssize_t bytes; |
| 2660 | |
| 2661 | bytes = write_efs(output, amd_romsig); |
| 2662 | if (bytes != sizeof(*amd_romsig)) { |
| 2663 | fprintf(stderr, "Error: Writing EFS\n"); |
| 2664 | retval = 1; |
| 2665 | } |
| 2666 | } |
| 2667 | |
Martin Roth | 31d95a2 | 2016-11-08 11:22:12 -0700 | [diff] [blame] | 2668 | free(rom); |
| 2669 | return retval; |
Zheng Bao | 9c7ff7b | 2015-11-17 22:57:39 +0800 | [diff] [blame] | 2670 | } |