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