Zheng Bao | addf340 | 2021-06-03 15:46:53 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <regex.h> |
| 5 | #include <string.h> |
| 6 | #include <stdlib.h> |
Idwer Vollering | 93df1d9 | 2020-12-30 00:01:59 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
Zheng Bao | dac4461 | 2021-05-27 11:11:34 +0800 | [diff] [blame] | 8 | #include <assert.h> |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 9 | |
| 10 | #include "amdfwtool.h" |
| 11 | |
| 12 | /* TODO: a empty line does not matched. */ |
| 13 | static const char blank_or_comment_regex[] = |
| 14 | /* a blank line */ |
| 15 | "(^[[:space:]]*$)" |
| 16 | "|" /* or ... */ |
| 17 | /* a line consisting of: optional whitespace followed by */ |
| 18 | "(^[[:space:]]*" |
| 19 | /* a '#' character and optionally, additional characters */ |
| 20 | "#.*$)"; |
| 21 | static regex_t blank_or_comment_expr; |
| 22 | |
| 23 | static const char entries_line_regex[] = |
| 24 | /* optional whitespace */ |
| 25 | "^[[:space:]]*" |
| 26 | /* followed by a chunk of nonwhitespace for macro field */ |
| 27 | "([^[:space:]]+)" |
| 28 | /* followed by one or more whitespace characters */ |
| 29 | "[[:space:]]+" |
| 30 | /* followed by a chunk of nonwhitespace for filename field */ |
| 31 | "([^[:space:]]+)" |
| 32 | /* followed by optional whitespace */ |
| 33 | "[[:space:]]*$"; |
| 34 | static regex_t entries_line_expr; |
| 35 | |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 36 | static const char entries_lvl_line_regex[] = |
| 37 | /* optional whitespace */ |
| 38 | "^[[:space:]]*" |
| 39 | /* followed by a chunk of nonwhitespace for macro field */ |
| 40 | "([^[:space:]]+)" |
| 41 | /* followed by one or more whitespace characters */ |
| 42 | "[[:space:]]+" |
| 43 | /* followed by a chunk of nonwhitespace for filename field */ |
| 44 | "([^[:space:]]+)" |
| 45 | /* followed by one or more whitespace characters */ |
| 46 | "[[:space:]]+" |
| 47 | /* followed by a chunk of nonwhitespace for level field |
| 48 | 1st char L: Indicator of field "level" |
| 49 | 2nd char: |
| 50 | Directory level to be dropped in. |
| 51 | 1: Level 1 |
| 52 | 2: Level 2 |
| 53 | b: Level both 1&2 |
| 54 | x: use default value hardcoded in table |
| 55 | 3rd char: |
| 56 | For A/B recovery. Defined same as 2nd char. |
| 57 | |
| 58 | Examples: |
| 59 | L2: Level 2 for normal mode |
| 60 | L12: Level 1 for normal mode, level 2 for A/B mode |
| 61 | Lx1: Use default value for normal mode, level 1 for A/B mode |
| 62 | */ |
| 63 | "([Ll][12bxBX]{1,2})" |
| 64 | /* followed by optional whitespace */ |
| 65 | "[[:space:]]*$"; |
| 66 | static regex_t entries_lvl_line_expr; |
| 67 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 68 | void compile_reg_expr(int cflags, const char *expr, regex_t *reg) |
| 69 | { |
| 70 | static const size_t ERROR_BUF_SIZE = 256; |
| 71 | char error_msg[ERROR_BUF_SIZE]; |
| 72 | int result; |
| 73 | |
| 74 | result = regcomp(reg, expr, cflags); |
| 75 | if (result != 0) { |
| 76 | regerror(result, reg, error_msg, ERROR_BUF_SIZE); |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 77 | fprintf(stderr, "%s\n", error_msg); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 81 | #define SET_LEVEL(tableptr, l, TABLE, ab) \ |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 82 | do { \ |
| 83 | switch ((l)) { \ |
| 84 | case '1': \ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 85 | (tableptr)->level = ab ? TABLE##_LVL1_AB : TABLE##_LVL1; \ |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 86 | break; \ |
| 87 | case '2': \ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 88 | (tableptr)->level = ab ? TABLE##_LVL2_AB : TABLE##_LVL2; \ |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 89 | break; \ |
| 90 | case 'b': \ |
| 91 | case 'B': \ |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 92 | (tableptr)->level = ab ? TABLE##_BOTH_AB : TABLE##_BOTH; \ |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 93 | break; \ |
| 94 | default: \ |
| 95 | /* use default value */ \ |
| 96 | break; \ |
| 97 | } \ |
| 98 | } while (0) |
| 99 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 100 | extern amd_fw_entry amd_psp_fw_table[]; |
| 101 | extern amd_bios_entry amd_bios_table[]; |
| 102 | |
| 103 | static uint8_t find_register_fw_filename_psp_dir(char *fw_name, char *filename, |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 104 | char level_to_set, amd_cb_config *cb_config) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 105 | { |
| 106 | amd_fw_type fw_type = AMD_FW_INVALID; |
| 107 | amd_fw_entry *psp_tableptr; |
| 108 | uint8_t subprog; |
Zheng Bao | 5ca1343 | 2022-10-16 20:18:40 +0800 | [diff] [blame] | 109 | uint8_t instance = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 110 | |
| 111 | if (strcmp(fw_name, "PSPBTLDR_WL_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 112 | if (cb_config->have_whitelist) { |
Nikolai Vyssotski | 1965f650 | 2021-05-06 22:15:36 -0500 | [diff] [blame] | 113 | fw_type = AMD_FW_PSP_BOOTLOADER_AB; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 114 | subprog = 0; |
| 115 | } else { |
| 116 | fw_type = AMD_FW_SKIP; |
| 117 | } |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 118 | } else if (strcmp(fw_name, "PSPBTLDR_AB_STAGE1_FILE") == 0) { |
| 119 | if (cb_config->recovery_ab) { |
| 120 | fw_type = AMD_FW_PSP_BOOTLOADER; |
| 121 | subprog = 0; |
| 122 | } else { |
| 123 | fw_type = AMD_FW_SKIP; |
| 124 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 125 | } else if (strcmp(fw_name, "PSPBTLDR_FILE") == 0) { |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 126 | if (!cb_config->recovery_ab) { |
| 127 | fw_type = AMD_FW_PSP_BOOTLOADER; |
| 128 | subprog = 0; |
| 129 | } else { |
| 130 | fw_type = AMD_FW_SKIP; |
| 131 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 132 | } else if (strcmp(fw_name, "AMD_PUBKEY_FILE") == 0) { |
| 133 | fw_type = AMD_FW_PSP_PUBKEY; |
| 134 | subprog = 0; |
| 135 | } else if (strcmp(fw_name, "PSPRCVR_FILE") == 0) { |
| 136 | fw_type = AMD_FW_PSP_RECOVERY; |
| 137 | subprog = 0; |
| 138 | } else if (strcmp(fw_name, "PUBSIGNEDKEY_FILE") == 0) { |
| 139 | fw_type = AMD_FW_PSP_RTM_PUBKEY; |
| 140 | subprog = 0; |
| 141 | } else if (strcmp(fw_name, "PSPNVRAM_FILE") == 0) { |
| 142 | fw_type = AMD_FW_PSP_NVRAM; |
| 143 | subprog = 0; |
| 144 | } else if (strcmp(fw_name, "SMUSCS_FILE") == 0) { |
| 145 | fw_type = AMD_FW_PSP_SMUSCS; |
| 146 | subprog = 0; |
| 147 | } else if (strcmp(fw_name, "PSPTRUSTLETS_FILE") == 0) { |
| 148 | fw_type = AMD_FW_PSP_TRUSTLETS; |
| 149 | subprog = 0; |
| 150 | } else if (strcmp(fw_name, "PSPSECUREDEBUG_FILE") == 0) { |
| 151 | fw_type = AMD_FW_PSP_SECURED_DEBUG; |
| 152 | subprog = 0; |
| 153 | } else if (strcmp(fw_name, "PSP_SMUFW1_SUB0_FILE") == 0) { |
| 154 | fw_type = AMD_FW_PSP_SMU_FIRMWARE; |
| 155 | subprog = 0; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 156 | } else if (strcmp(fw_name, "PSP_HW_IPCFG_FILE") == 0) { |
| 157 | fw_type = AMD_HW_IPCFG; |
| 158 | subprog = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 159 | } else if (strcmp(fw_name, "PSP_SMUFW1_SUB1_FILE") == 0) { |
| 160 | fw_type = AMD_FW_PSP_SMU_FIRMWARE; |
| 161 | subprog = 1; |
| 162 | } else if (strcmp(fw_name, "PSP_SMUFW1_SUB2_FILE") == 0) { |
| 163 | fw_type = AMD_FW_PSP_SMU_FIRMWARE; |
| 164 | subprog = 2; |
| 165 | } else if (strcmp(fw_name, "PSP_SMUFW2_SUB0_FILE") == 0) { |
| 166 | fw_type = AMD_FW_PSP_SMU_FIRMWARE2; |
| 167 | subprog = 0; |
| 168 | } else if (strcmp(fw_name, "PSP_SMUFW2_SUB1_FILE") == 0) { |
| 169 | fw_type = AMD_FW_PSP_SMU_FIRMWARE2; |
| 170 | subprog = 1; |
| 171 | } else if (strcmp(fw_name, "PSP_SMUFW2_SUB2_FILE") == 0) { |
| 172 | fw_type = AMD_FW_PSP_SMU_FIRMWARE2; |
| 173 | subprog = 2; |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 174 | } else if (strcmp(fw_name, "PSP_BOOT_DRIVER_FILE") == 0) { |
| 175 | fw_type = AMD_BOOT_DRIVER; |
| 176 | subprog = 0; |
| 177 | } else if (strcmp(fw_name, "PSP_SOC_DRIVER_FILE") == 0) { |
| 178 | fw_type = AMD_SOC_DRIVER; |
| 179 | subprog = 0; |
| 180 | } else if (strcmp(fw_name, "PSP_DEBUG_DRIVER_FILE") == 0) { |
| 181 | fw_type = AMD_DEBUG_DRIVER; |
| 182 | subprog = 0; |
| 183 | } else if (strcmp(fw_name, "PSP_INTERFACE_DRIVER_FILE") == 0) { |
| 184 | fw_type = AMD_INTERFACE_DRIVER; |
| 185 | subprog = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 186 | } else if (strcmp(fw_name, "PSP_SEC_DBG_KEY_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 187 | if (cb_config->unlock_secure) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 188 | fw_type = AMD_FW_PSP_SECURED_DEBUG; |
| 189 | subprog = 0; |
| 190 | } else { |
| 191 | fw_type = AMD_FW_SKIP; |
| 192 | } |
| 193 | } else if (strcmp(fw_name, "PSP_SEC_DEBUG_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 194 | if (cb_config->unlock_secure) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 195 | fw_type = AMD_DEBUG_UNLOCK; |
| 196 | subprog = 0; |
| 197 | } else { |
| 198 | fw_type = AMD_FW_SKIP; |
| 199 | } |
| 200 | } else if (strcmp(fw_name, "PSP_ABL0_FILE") == 0) { |
| 201 | fw_type = AMD_ABL0; |
| 202 | subprog = 0; |
| 203 | } else if (strcmp(fw_name, "PSP_ABL1_FILE") == 0) { |
| 204 | fw_type = AMD_ABL1; |
| 205 | subprog = 0; |
| 206 | } else if (strcmp(fw_name, "PSP_ABL2_FILE") == 0) { |
| 207 | fw_type = AMD_ABL2; |
| 208 | subprog = 0; |
| 209 | } else if (strcmp(fw_name, "PSP_ABL3_FILE") == 0) { |
| 210 | fw_type = AMD_ABL3; |
| 211 | subprog = 0; |
| 212 | } else if (strcmp(fw_name, "PSP_ABL4_FILE") == 0) { |
| 213 | fw_type = AMD_ABL4; |
| 214 | subprog = 0; |
| 215 | } else if (strcmp(fw_name, "PSP_ABL5_FILE") == 0) { |
| 216 | fw_type = AMD_ABL5; |
| 217 | subprog = 0; |
| 218 | } else if (strcmp(fw_name, "PSP_ABL6_FILE") == 0) { |
| 219 | fw_type = AMD_ABL6; |
| 220 | subprog = 0; |
| 221 | } else if (strcmp(fw_name, "PSP_ABL7_FILE") == 0) { |
| 222 | fw_type = AMD_ABL7; |
| 223 | subprog = 0; |
| 224 | } else if (strcmp(fw_name, "PSPSECUREOS_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 225 | if (cb_config->use_secureos) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 226 | fw_type = AMD_FW_PSP_SECURED_OS; |
| 227 | subprog = 0; |
| 228 | } else { |
| 229 | fw_type = AMD_FW_SKIP; |
| 230 | } |
| 231 | } else if (strcmp(fw_name, "PSPTRUSTLETS_FILE") == 0) { |
| 232 | if (cb_config->use_secureos) { |
| 233 | fw_type = AMD_FW_PSP_TRUSTLETS; |
| 234 | subprog = 0; |
| 235 | } else { |
| 236 | fw_type = AMD_FW_SKIP; |
| 237 | } |
| 238 | } else if (strcmp(fw_name, "TRUSTLETKEY_FILE") == 0) { |
| 239 | if (cb_config->use_secureos) { |
| 240 | fw_type = AMD_FW_PSP_TRUSTLETKEY; |
| 241 | subprog = 0; |
| 242 | } else { |
| 243 | fw_type = AMD_FW_SKIP; |
| 244 | } |
| 245 | } else if (strcmp(fw_name, "PSP_IKEK_FILE") == 0) { |
| 246 | fw_type = AMD_WRAPPED_IKEK; |
| 247 | subprog = 0; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 248 | } else if (strcmp(fw_name, "PSP_SECG0_FILE") == 0) { |
| 249 | fw_type = AMD_SEC_GASKET; |
| 250 | subprog = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 251 | } else if (strcmp(fw_name, "PSP_SECG1_FILE") == 0) { |
| 252 | fw_type = AMD_SEC_GASKET; |
| 253 | subprog = 1; |
| 254 | } else if (strcmp(fw_name, "PSP_SECG2_FILE") == 0) { |
| 255 | fw_type = AMD_SEC_GASKET; |
| 256 | subprog = 2; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 257 | } else if (strcmp(fw_name, "PSP_MP2FW0_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 258 | if (cb_config->load_mp2_fw) { |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 259 | fw_type = AMD_MP2_FW; |
| 260 | subprog = 0; |
| 261 | } else { |
| 262 | fw_type = AMD_FW_SKIP; |
| 263 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 264 | } else if (strcmp(fw_name, "PSP_MP2FW1_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 265 | if (cb_config->load_mp2_fw) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 266 | fw_type = AMD_MP2_FW; |
| 267 | subprog = 1; |
| 268 | } else { |
| 269 | fw_type = AMD_FW_SKIP; |
| 270 | } |
| 271 | } else if (strcmp(fw_name, "PSP_MP2FW2_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 272 | if (cb_config->load_mp2_fw) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 273 | fw_type = AMD_MP2_FW; |
| 274 | subprog = 2; |
| 275 | } else { |
| 276 | fw_type = AMD_FW_SKIP; |
| 277 | } |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 278 | } else if (strcmp(fw_name, "PSP_C20MP_FILE") == 0) { |
| 279 | fw_type = AMD_FW_C20_MP; |
| 280 | subprog = 0; |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 281 | } else if (strcmp(fw_name, "AMF_SRAM_FILE") == 0) { |
| 282 | fw_type = AMD_FW_AMF_SRAM; |
| 283 | subprog = 0; |
| 284 | } else if (strcmp(fw_name, "AMF_DRAM_FILE_INS0") == 0) { |
| 285 | fw_type = AMD_FW_AMF_DRAM; |
| 286 | subprog = 0; |
| 287 | instance = 0; |
| 288 | } else if (strcmp(fw_name, "AMF_DRAM_FILE_INS1") == 0) { |
| 289 | fw_type = AMD_FW_AMF_DRAM; |
| 290 | subprog = 0; |
| 291 | instance = 1; |
| 292 | } else if (strcmp(fw_name, "AMF_WLAN_FILE_INS0") == 0) { |
| 293 | fw_type = AMD_FW_AMF_WLAN; |
| 294 | subprog = 0; |
| 295 | instance = 0; |
| 296 | } else if (strcmp(fw_name, "AMF_WLAN_FILE_INS1") == 0) { |
| 297 | fw_type = AMD_FW_AMF_WLAN; |
| 298 | subprog = 0; |
| 299 | instance = 1; |
| 300 | } else if (strcmp(fw_name, "AMF_MFD_FILE") == 0) { |
| 301 | fw_type = AMD_FW_AMF_MFD; |
| 302 | subprog = 0; |
| 303 | } else if (strcmp(fw_name, "MPCCX_FILE") == 0) { |
| 304 | fw_type = AMD_FW_MPCCX; |
| 305 | subprog = 0; |
| 306 | } else if (strcmp(fw_name, "LSDMA_FILE") == 0) { |
| 307 | fw_type = AMD_FW_LSDMA; |
| 308 | subprog = 0; |
| 309 | } else if (strcmp(fw_name, "MINIMSMU_FILE") == 0) { |
| 310 | fw_type = AMD_FW_MINIMSMU; |
| 311 | instance = 0; |
| 312 | subprog = 0; |
| 313 | } else if (strcmp(fw_name, "MINIMSMU_FILE_INS1") == 0) { |
| 314 | fw_type = AMD_FW_MINIMSMU; |
| 315 | instance = 1; |
| 316 | subprog = 0; |
| 317 | } else if (strcmp(fw_name, "SRAM_FW_EXT_FILE") == 0) { |
| 318 | fw_type = AMD_FW_SRAM_FW_EXT; |
| 319 | subprog = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 320 | } else if (strcmp(fw_name, "PSP_DRIVERS_FILE") == 0) { |
| 321 | fw_type = AMD_DRIVER_ENTRIES; |
| 322 | subprog = 0; |
| 323 | } else if (strcmp(fw_name, "PSP_S0I3_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 324 | if (cb_config->s0i3) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 325 | fw_type = AMD_S0I3_DRIVER; |
| 326 | subprog = 0; |
| 327 | } else { |
| 328 | fw_type = AMD_FW_SKIP; |
| 329 | } |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 330 | } else if (strcmp(fw_name, "AMD_DRIVER_ENTRIES") == 0) { |
| 331 | fw_type = AMD_DRIVER_ENTRIES; |
| 332 | subprog = 0; |
| 333 | } else if (strcmp(fw_name, "VBIOS_BTLOADER_FILE") == 0) { |
| 334 | fw_type = AMD_VBIOS_BTLOADER; |
| 335 | subprog = 0; |
| 336 | } else if (strcmp(fw_name, "SECURE_POLICY_L1_FILE") == 0) { |
| 337 | fw_type = AMD_FW_TOS_SEC_POLICY; |
| 338 | subprog = 0; |
| 339 | } else if (strcmp(fw_name, "UNIFIEDUSB_FILE") == 0) { |
| 340 | fw_type = AMD_FW_USB_PHY; |
| 341 | subprog = 0; |
| 342 | } else if (strcmp(fw_name, "DRTMTA_FILE") == 0) { |
| 343 | fw_type = AMD_FW_DRTM_TA; |
| 344 | subprog = 0; |
| 345 | } else if (strcmp(fw_name, "KEYDBBL_FILE") == 0) { |
| 346 | fw_type = AMD_FW_KEYDB_BL; |
| 347 | subprog = 0; |
| 348 | } else if (strcmp(fw_name, "KEYDB_TOS_FILE") == 0) { |
| 349 | fw_type = AMD_FW_KEYDB_TOS; |
| 350 | subprog = 0; |
Zheng Bao | ab84fd7 | 2022-01-27 22:38:27 +0800 | [diff] [blame] | 351 | } else if (strcmp(fw_name, "SPL_TABLE_FILE") == 0) { |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 352 | if (cb_config->have_mb_spl) { |
Felix Held | 11b0d36 | 2022-04-02 03:49:07 +0200 | [diff] [blame] | 353 | fw_type = AMD_FW_SKIP; |
| 354 | } else { |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 355 | fw_type = AMD_FW_SPL; |
| 356 | subprog = 0; |
Zheng Bao | 6c5ec8e | 2022-02-11 11:51:26 +0800 | [diff] [blame] | 357 | } |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 358 | } else if (strcmp(fw_name, "DMCUERAMDCN21_FILE") == 0) { |
| 359 | fw_type = AMD_FW_DMCU_ERAM; |
| 360 | subprog = 0; |
| 361 | } else if (strcmp(fw_name, "DMCUINTVECTORSDCN21_FILE") == 0) { |
| 362 | fw_type = AMD_FW_DMCU_ISR; |
| 363 | subprog = 0; |
Felix Held | 5f18bb7 | 2022-03-24 02:04:51 +0100 | [diff] [blame] | 364 | } else if (strcmp(fw_name, "MSMU_FILE") == 0) { |
| 365 | fw_type = AMD_FW_MSMU; |
| 366 | subprog = 0; |
| 367 | } else if (strcmp(fw_name, "DMCUB_FILE") == 0) { |
| 368 | fw_type = AMD_FW_DMCUB; |
| 369 | subprog = 0; |
| 370 | } else if (strcmp(fw_name, "SPIROM_CONFIG_FILE") == 0) { |
| 371 | fw_type = AMD_FW_SPIROM_CFG; |
| 372 | subprog = 0; |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 373 | } else if (strcmp(fw_name, "MPIO_FILE") == 0) { |
| 374 | fw_type = AMD_FW_MPIO; |
| 375 | subprog = 0; |
| 376 | } else if (strcmp(fw_name, "TPMLITE_FILE") == 0) { |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 377 | fw_type = AMD_FW_TPMLITE; |
| 378 | subprog = 0; |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 379 | } else if (strcmp(fw_name, "PSP_KVM_ENGINE_DUMMY_FILE") == 0) { |
| 380 | fw_type = AMD_FW_KVM_IMAGE; |
| 381 | subprog = 0; |
| 382 | } else if (strcmp(fw_name, "RPMC_FILE") == 0) { |
| 383 | fw_type = AMD_RPMC_NVRAM; |
| 384 | subprog = 0; |
Zheng Bao | b993cb2 | 2021-02-02 18:48:23 +0800 | [diff] [blame] | 385 | } else if (strcmp(fw_name, "PSPBTLDR_AB_FILE") == 0) { |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 386 | if (!cb_config->have_whitelist || cb_config->recovery_ab) { |
Nikolai Vyssotski | 1965f650 | 2021-05-06 22:15:36 -0500 | [diff] [blame] | 387 | fw_type = AMD_FW_PSP_BOOTLOADER_AB; |
| 388 | subprog = 0; |
| 389 | } else { |
| 390 | fw_type = AMD_FW_SKIP; |
| 391 | } |
Karthikeyan Ramasubramanian | 0ab04d2 | 2022-05-03 18:16:34 -0600 | [diff] [blame] | 392 | } else if (strcmp(fw_name, "TA_IKEK_FILE") == 0) { |
| 393 | fw_type = AMD_TA_IKEK; |
| 394 | subprog = 0; |
Fred Reitberger | c4f3a33 | 2023-02-07 12:12:40 -0500 | [diff] [blame] | 395 | } else if (strcmp(fw_name, "UMSMU_FILE") == 0) { |
| 396 | fw_type = AMD_FW_UMSMU; |
| 397 | subprog = 0; |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 398 | } else if (strcmp(fw_name, "PSP_OEM_ABL_KEY_FILE") == 0) { |
| 399 | fw_type = AMD_FW_ABL_PUBKEY; |
| 400 | subprog = 0; |
| 401 | } else if (strcmp(fw_name, "PSP_MP5FW_SUB0_FILE") == 0) { |
| 402 | fw_type = AMD_FW_MP5; |
| 403 | subprog = 0; |
| 404 | } else if (strcmp(fw_name, "PSP_MP5FW_SUB1_FILE") == 0) { |
| 405 | fw_type = AMD_FW_MP5; |
| 406 | subprog = 1; |
| 407 | } else if (strcmp(fw_name, "PSP_MP5FW_SUB2_FILE") == 0) { |
| 408 | fw_type = AMD_FW_MP5; |
| 409 | subprog = 2; |
| 410 | } else if (strcmp(fw_name, "PSP_DXIOFW_FILE") == 0) { |
| 411 | fw_type = AMD_FW_DXIO; |
| 412 | subprog = 0; |
| 413 | } else if (strcmp(fw_name, "PSP_MPIOFW_FILE") == 0) { |
| 414 | fw_type = AMD_FW_MPIO; |
| 415 | subprog = 0; |
Zheng Bao | 85ee1fd | 2023-01-30 13:52:30 +0800 | [diff] [blame] | 416 | } else if (strcmp(fw_name, "PSP_RIB_FILE_SUB0") == 0) { |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 417 | fw_type = AMD_RIB; |
| 418 | subprog = 0; |
Zheng Bao | 85ee1fd | 2023-01-30 13:52:30 +0800 | [diff] [blame] | 419 | } else if (strcmp(fw_name, "PSP_RIB_FILE_SUB1") == 0) { |
| 420 | fw_type = AMD_RIB; |
| 421 | subprog = 1; |
Zheng Bao | 8eba662 | 2022-10-16 20:29:03 +0800 | [diff] [blame] | 422 | } else if (strcmp(fw_name, "FEATURE_TABLE_FILE") == 0) { |
| 423 | fw_type = AMD_FW_FCFG_TABLE; |
| 424 | subprog = 0; |
Arthur Heymans | 1f05c80 | 2022-10-04 17:50:21 +0200 | [diff] [blame] | 425 | } else if (strcmp(fw_name, "PSP_MPDMATFFW_FILE") == 0) { |
| 426 | fw_type = AMD_FW_MPDMA_TF; |
| 427 | subprog = 0; |
| 428 | } else if (strcmp(fw_name, "PSP_GMI3PHYFW_FILE") == 0) { |
| 429 | fw_type = AMD_FW_GMI3_PHY; |
| 430 | subprog = 0; |
| 431 | } else if (strcmp(fw_name, "PSP_MPDMAPMFW_FILE") == 0) { |
| 432 | fw_type = AMD_FW_MPDMA_PM; |
| 433 | subprog = 0; |
| 434 | } else if (strcmp(fw_name, "PSP_TOKEN_UNLOCK_FILE") == 0) { |
| 435 | fw_type = AMD_TOKEN_UNLOCK; |
| 436 | subprog = 0; |
| 437 | } else if (strcmp(fw_name, "SEV_DATA_FILE") == 0) { |
| 438 | fw_type = AMD_SEV_DATA; |
| 439 | subprog = 0; |
| 440 | } else if (strcmp(fw_name, "SEV_CODE_FILE") == 0) { |
| 441 | fw_type = AMD_SEV_CODE; |
| 442 | subprog = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 443 | } else { |
| 444 | fw_type = AMD_FW_INVALID; |
| 445 | /* TODO: Add more */ |
| 446 | } |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 447 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 448 | /* Search and fill the filename */ |
| 449 | psp_tableptr = &amd_psp_fw_table[0]; |
| 450 | if (fw_type != AMD_FW_SKIP && fw_type != AMD_FW_INVALID) { |
| 451 | while (psp_tableptr->type != AMD_FW_INVALID) { |
| 452 | /* instance are not used in PSP table */ |
Zheng Bao | 5ca1343 | 2022-10-16 20:18:40 +0800 | [diff] [blame] | 453 | if (psp_tableptr->type == fw_type && psp_tableptr->subprog == subprog |
| 454 | && psp_tableptr->inst == instance) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 455 | psp_tableptr->filename = filename; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 456 | SET_LEVEL(psp_tableptr, level_to_set, PSP, |
| 457 | cb_config->recovery_ab); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 458 | break; |
| 459 | } |
| 460 | psp_tableptr++; |
| 461 | } |
| 462 | } |
| 463 | if (fw_type == AMD_FW_INVALID) |
| 464 | return 0; |
| 465 | else |
| 466 | return 1; |
| 467 | } |
Zheng Bao | 1a9e543 | 2022-02-17 17:48:27 +0800 | [diff] [blame] | 468 | #define PMUI_STR_BASE "PSP_PMUI_FILE" |
| 469 | #define PMUD_STR_BASE "PSP_PMUD_FILE" |
| 470 | #define PMU_STR_BASE_LEN strlen(PMUI_STR_BASE) |
| 471 | #define PMU_STR_SUB_INDEX strlen(PMUI_STR_BASE"_SUB") |
| 472 | #define PMU_STR_INS_INDEX strlen(PMUI_STR_BASE"_SUBx_INS") |
Zheng Bao | fdb0294 | 2022-02-22 09:47:59 +0800 | [diff] [blame] | 473 | #define PMU_STR_ALL_LEN strlen(PMUI_STR_BASE"_SUBx_INSx") |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 474 | |
| 475 | static uint8_t find_register_fw_filename_bios_dir(char *fw_name, char *filename, |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 476 | char level_to_set, amd_cb_config *cb_config) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 477 | { |
| 478 | amd_bios_type fw_type = AMD_BIOS_INVALID; |
| 479 | amd_bios_entry *bhd_tableptr; |
Felix Held | ea3417b | 2020-11-20 20:08:42 +0100 | [diff] [blame] | 480 | uint8_t subprog = 0; |
| 481 | uint8_t instance = 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 482 | |
| 483 | (void) (cb_config); /* Remove warning and reserved for future. */ |
| 484 | |
Zheng Bao | 1a9e543 | 2022-02-17 17:48:27 +0800 | [diff] [blame] | 485 | if (strncmp(fw_name, PMUI_STR_BASE, PMU_STR_BASE_LEN) == 0) { |
Zheng Bao | fdb0294 | 2022-02-22 09:47:59 +0800 | [diff] [blame] | 486 | assert(strlen(fw_name) == PMU_STR_ALL_LEN); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 487 | fw_type = AMD_BIOS_PMUI; |
Felix Held | 3dfb485 | 2022-09-28 18:00:39 +0200 | [diff] [blame] | 488 | subprog = strtol(&fw_name[PMU_STR_SUB_INDEX], NULL, 16); |
| 489 | instance = strtol(&fw_name[PMU_STR_INS_INDEX], NULL, 16); |
Zheng Bao | 1a9e543 | 2022-02-17 17:48:27 +0800 | [diff] [blame] | 490 | } else if (strncmp(fw_name, PMUD_STR_BASE, PMU_STR_BASE_LEN) == 0) { |
Zheng Bao | fdb0294 | 2022-02-22 09:47:59 +0800 | [diff] [blame] | 491 | assert(strlen(fw_name) == PMU_STR_ALL_LEN); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 492 | fw_type = AMD_BIOS_PMUD; |
Felix Held | 3dfb485 | 2022-09-28 18:00:39 +0200 | [diff] [blame] | 493 | subprog = strtol(&fw_name[PMU_STR_SUB_INDEX], NULL, 16); |
| 494 | instance = strtol(&fw_name[PMU_STR_INS_INDEX], NULL, 16); |
Zheng Bao | bf29a0d | 2020-12-03 23:00:48 +0800 | [diff] [blame] | 495 | } else if (strcmp(fw_name, "RTM_PUBKEY_FILE") == 0) { |
| 496 | fw_type = AMD_BIOS_RTM_PUBKEY; |
| 497 | subprog = 0; |
| 498 | instance = 0; |
Zheng Bao | 5014373 | 2020-11-14 21:54:06 +0800 | [diff] [blame] | 499 | } else if (strcmp(fw_name, "PSP_MP2CFG_FILE") == 0) { |
Zheng Bao | ba3af5e | 2021-11-04 18:56:47 +0800 | [diff] [blame] | 500 | if (cb_config->load_mp2_fw) { |
Zheng Bao | 5014373 | 2020-11-14 21:54:06 +0800 | [diff] [blame] | 501 | fw_type = AMD_BIOS_MP2_CFG; |
| 502 | subprog = 0; |
| 503 | } else { |
Martin Roth | a8e31ca | 2021-02-13 21:42:46 -0700 | [diff] [blame] | 504 | fw_type = AMD_BIOS_SKIP; |
Zheng Bao | 5014373 | 2020-11-14 21:54:06 +0800 | [diff] [blame] | 505 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 506 | } else { |
| 507 | fw_type = AMD_BIOS_INVALID; |
| 508 | } |
| 509 | |
| 510 | bhd_tableptr = amd_bios_table; |
| 511 | |
| 512 | if (fw_type != AMD_BIOS_INVALID && fw_type != AMD_BIOS_SKIP) { |
| 513 | while (bhd_tableptr->type != AMD_BIOS_INVALID) { |
| 514 | if (bhd_tableptr->type == fw_type && |
| 515 | bhd_tableptr->subpr == subprog && |
| 516 | bhd_tableptr->inst == instance) { |
| 517 | bhd_tableptr->filename = filename; |
Zheng Bao | 990d154 | 2021-09-17 13:24:54 +0800 | [diff] [blame] | 518 | SET_LEVEL(bhd_tableptr, level_to_set, BDT, |
| 519 | cb_config->recovery_ab); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 520 | break; |
| 521 | } |
| 522 | bhd_tableptr++; |
| 523 | } |
| 524 | } |
| 525 | if (fw_type == AMD_BIOS_INVALID) |
| 526 | return 0; |
| 527 | else |
| 528 | return 1; |
| 529 | } |
| 530 | |
| 531 | #define MAX_LINE_SIZE 1024 |
| 532 | |
| 533 | int get_input_file_line(FILE *f, char line[], int line_buf_size) |
| 534 | { |
| 535 | if (fgets(line, line_buf_size, f) == NULL) |
| 536 | return LINE_EOF; |
| 537 | |
| 538 | /* If the file contains a line that is too long, then it's best |
| 539 | * to let the user know right away rather than passing back a |
| 540 | * truncated result that will lead to problems later on. |
| 541 | */ |
| 542 | line[strlen(line) - 1] = '\0'; |
| 543 | |
| 544 | if (strlen(line) == ((size_t) (line_buf_size - 1))) { |
Zheng Bao | 77a2c67 | 2020-10-01 17:05:43 +0800 | [diff] [blame] | 545 | fprintf(stderr, "The line size in config file should be lower than %d bytes.\n", |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 546 | MAX_LINE_SIZE); |
| 547 | exit(1); |
| 548 | } |
| 549 | |
| 550 | return OK; |
| 551 | } |
| 552 | |
Zheng Bao | 4df5af8 | 2022-03-01 17:18:00 +0800 | [diff] [blame] | 553 | #define N_MATCHES 4 |
| 554 | static int is_valid_entry(char *oneline, regmatch_t match[N_MATCHES]) |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 555 | { |
Zheng Bao | 4df5af8 | 2022-03-01 17:18:00 +0800 | [diff] [blame] | 556 | int retval, index; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 557 | |
Zheng Bao | 4df5af8 | 2022-03-01 17:18:00 +0800 | [diff] [blame] | 558 | for (index = 0; index < N_MATCHES; index++) { |
| 559 | match[index].rm_so = -1; |
| 560 | match[index].rm_eo = -1; |
| 561 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 562 | if (regexec(&entries_line_expr, oneline, 3, match, 0) == 0) { |
| 563 | oneline[match[1].rm_eo] = '\0'; |
| 564 | oneline[match[2].rm_eo] = '\0'; |
| 565 | retval = 1; |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 566 | } else if (regexec(&entries_lvl_line_expr, oneline, 4, match, 0) == 0) { |
| 567 | /* match[1]: FW type |
| 568 | match[2]: FW filename |
| 569 | match[3]: Directory level to be dropped |
| 570 | */ |
| 571 | oneline[match[1].rm_eo] = '\0'; |
| 572 | oneline[match[2].rm_eo] = '\0'; |
| 573 | oneline[match[3].rm_eo] = '\0'; |
| 574 | retval = 1; |
| 575 | } else { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 576 | retval = 0; |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 577 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 578 | |
| 579 | return retval; |
| 580 | } |
| 581 | |
| 582 | static int skip_comment_blank_line(char *oneline) |
| 583 | { |
| 584 | int retval; |
| 585 | |
| 586 | if (regexec(&blank_or_comment_expr, oneline, 0, NULL, 0) == 0) { |
| 587 | /* skip comment and blank */ |
| 588 | retval = 1; |
| 589 | } else { |
| 590 | /* no match */ |
| 591 | retval = 0; |
| 592 | } |
| 593 | |
| 594 | return retval; |
| 595 | } |
| 596 | |
Zheng Bao | 52a1898 | 2022-03-01 17:22:52 +0800 | [diff] [blame] | 597 | char get_level_from_config(char *line, regoff_t level_index, amd_cb_config *cb_config) |
| 598 | { |
| 599 | char lvl = 'x'; |
| 600 | /* If the optional level field is present, |
| 601 | extract the level char. */ |
| 602 | if (level_index != -1) { |
| 603 | if (cb_config->recovery_ab == 0) |
| 604 | lvl = line[level_index + 1]; |
| 605 | else if (strlen(&line[level_index]) >= 3) |
| 606 | lvl = line[level_index + 2]; |
| 607 | } |
| 608 | |
| 609 | assert(lvl == 'x' || lvl == 'X' || |
| 610 | lvl == 'b' || lvl == 'B' || |
| 611 | lvl == '1' || lvl == '2'); |
| 612 | |
| 613 | return lvl; |
| 614 | } |
| 615 | |
Zheng Bao | 7db7642 | 2021-03-27 18:15:35 +0800 | [diff] [blame] | 616 | static uint8_t process_one_line(char *oneline, regmatch_t *match, char *dir, |
| 617 | uint8_t print_deps, amd_cb_config *cb_config) |
| 618 | { |
| 619 | char *path_filename, *fn = &(oneline[match[2].rm_so]); |
| 620 | char *fw_type_str = &(oneline[match[1].rm_so]); |
| 621 | char ch_lvl = 'x'; |
| 622 | regoff_t ch_lvl_index = match[3].rm_so; |
| 623 | |
| 624 | /* If the optional level field is present, |
| 625 | extract the level char. */ |
| 626 | ch_lvl = get_level_from_config(oneline, ch_lvl_index, cb_config); |
| 627 | |
| 628 | path_filename = malloc(MAX_LINE_SIZE * 2 + 2); |
| 629 | snprintf(path_filename, MAX_LINE_SIZE * 2 + 2, "%.*s/%.*s", |
| 630 | MAX_LINE_SIZE, dir, MAX_LINE_SIZE, fn); |
| 631 | |
| 632 | if (find_register_fw_filename_psp_dir( |
| 633 | fw_type_str, path_filename, ch_lvl, cb_config) == 0) { |
| 634 | if (find_register_fw_filename_bios_dir( |
| 635 | fw_type_str, path_filename, ch_lvl, cb_config) == 0) { |
| 636 | fprintf(stderr, "Module's name \"%s\" is not valid\n", fw_type_str); |
| 637 | return 0; /* Stop parsing. */ |
| 638 | } else { |
| 639 | if (print_deps) |
| 640 | printf(" %s ", path_filename); |
| 641 | } |
| 642 | } else { |
| 643 | if (print_deps) |
| 644 | printf(" %s ", path_filename); |
| 645 | } |
| 646 | return 1; |
| 647 | } |
| 648 | |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 649 | /* |
| 650 | return value: |
| 651 | 0: The config file can not be parsed correctly. |
| 652 | 1: The config file can be parsed correctly. |
| 653 | */ |
| 654 | uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps) |
| 655 | { |
Zheng Bao | 7db7642 | 2021-03-27 18:15:35 +0800 | [diff] [blame] | 656 | char oneline[MAX_LINE_SIZE]; |
Zheng Bao | 4df5af8 | 2022-03-01 17:18:00 +0800 | [diff] [blame] | 657 | regmatch_t match[N_MATCHES]; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 658 | char dir[MAX_LINE_SIZE] = {'\0'}; |
Zheng Bao | dac4461 | 2021-05-27 11:11:34 +0800 | [diff] [blame] | 659 | uint32_t dir_len; |
Zheng Bao | 4df5af8 | 2022-03-01 17:18:00 +0800 | [diff] [blame] | 660 | int index; |
| 661 | |
| 662 | for (index = 0; index < N_MATCHES; index++) { |
| 663 | match[index].rm_so = -1; |
| 664 | match[index].rm_eo = -1; |
| 665 | } |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 666 | |
| 667 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, |
| 668 | blank_or_comment_regex, &blank_or_comment_expr); |
| 669 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, |
| 670 | entries_line_regex, &entries_line_expr); |
Zheng Bao | b1fb8ce | 2021-09-13 18:00:09 +0800 | [diff] [blame] | 671 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, |
| 672 | entries_lvl_line_regex, &entries_lvl_line_expr); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 673 | |
| 674 | /* Get a line */ |
Zheng Bao | 3384e4a | 2020-10-06 12:03:11 +0800 | [diff] [blame] | 675 | /* Get FIRMWARE_LOCATION in the first loop */ |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 676 | while (get_input_file_line(config, oneline, MAX_LINE_SIZE) == OK) { |
| 677 | /* get a line */ |
| 678 | if (skip_comment_blank_line(oneline)) |
| 679 | continue; |
| 680 | if (is_valid_entry(oneline, match)) { |
Zheng Bao | 3384e4a | 2020-10-06 12:03:11 +0800 | [diff] [blame] | 681 | if (strcmp(&(oneline[match[1].rm_so]), "FIRMWARE_LOCATION") == 0) { |
Zheng Bao | dac4461 | 2021-05-27 11:11:34 +0800 | [diff] [blame] | 682 | dir_len = match[2].rm_eo - match[2].rm_so; |
| 683 | assert(dir_len < MAX_LINE_SIZE); |
| 684 | snprintf(dir, MAX_LINE_SIZE, "%.*s", dir_len, |
| 685 | &(oneline[match[2].rm_so])); |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 686 | break; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | if (dir[0] == '\0') { |
| 692 | fprintf(stderr, "No line with FIRMWARE_LOCATION\n"); |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | fseek(config, 0, SEEK_SET); |
| 697 | /* Get a line */ |
| 698 | while (get_input_file_line(config, oneline, MAX_LINE_SIZE) == OK) { |
| 699 | /* get a line */ |
| 700 | if (skip_comment_blank_line(oneline)) |
| 701 | continue; |
| 702 | if (is_valid_entry(oneline, match)) { |
Zheng Bao | 29063fb | 2023-01-25 22:46:57 +0800 | [diff] [blame] | 703 | if (strcmp(&(oneline[match[1].rm_so]), "FIRMWARE_LOCATION") == 0 || |
| 704 | strcmp(&(oneline[match[1].rm_so]), "SOC_NAME") == 0) { |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 705 | continue; |
| 706 | } else { |
Zheng Bao | 7db7642 | 2021-03-27 18:15:35 +0800 | [diff] [blame] | 707 | if (process_one_line(oneline, match, dir, print_deps, |
| 708 | cb_config) == 0) |
| 709 | return 0; |
Zheng Bao | c5e28ab | 2020-10-28 11:38:09 +0800 | [diff] [blame] | 710 | } |
| 711 | } else { |
| 712 | fprintf(stderr, "AMDFWTOOL config file line can't be parsed \"%s\"\n", oneline); |
| 713 | return 0; |
| 714 | } |
| 715 | } |
| 716 | return 1; |
| 717 | } |