Kangheui Won has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59584 )
Change subject: amdfwtool: merge lookup table to psp fw table ......................................................................
amdfwtool: merge lookup table to psp fw table
Merge psp_dir_valid_entries into amd_psp_fw_table. PSPBTLDR_WL_FILE and PSPBTLDR_AB_FILE needs additional logic since both points to the same firmware entry and which one to include depends on commandline option.
BUG=b:206909680 TEST=build guybrush and confirm amdfw and coreboot.rom are identical
Signed-off-by: Kangheui Won khwon@chromium.org Change-Id: I552240e53fa0e2f8bef5026e007c8b54458bd656 --- M util/amdfwtool/amdfwtool.c M util/amdfwtool/amdfwtool.h M util/amdfwtool/data_parse.c 3 files changed, 115 insertions(+), 128 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/84/59584/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 957c81e..6e663ae 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -220,54 +220,100 @@ }
amd_fw_entry amd_psp_fw_table[] = { - { .type = AMD_FW_PSP_PUBKEY, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_BOOTLOADER, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 0, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_RECOVERY, .level = PSP_LVL1 }, - { .type = AMD_FW_PSP_RTM_PUBKEY, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SECURED_OS, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_NVRAM, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 2, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SECURED_DEBUG, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_TRUSTLETS, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_TRUSTLETKEY, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 2, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 1, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 1, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SMU_FIRMWARE2, .level = PSP_BOTH }, - { .type = AMD_FW_PSP_SMUSCS, .level = PSP_BOTH }, + { .fw_name = "AMD_PUBKEY_FILE", + .type = AMD_FW_PSP_PUBKEY, .level = PSP_BOTH }, + { .fw_name = "PSPBTLDR_FILE", + .type = AMD_FW_PSP_BOOTLOADER, .level = PSP_BOTH }, + { .fw_name = "PSP_SMUFW1_SUB0_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 0, .level = PSP_BOTH }, + { .fw_name = "PSPRCVR_FILE", + .type = AMD_FW_PSP_RECOVERY, .level = PSP_LVL1 }, + { .fw_name = "PUBSIGNEDKEY_FILE", + .type = AMD_FW_PSP_RTM_PUBKEY, .level = PSP_BOTH }, + { .fw_name = "PSPSECUREOS_FILE", + .type = AMD_FW_PSP_SECURED_OS, .level = PSP_LVL2 }, + { .fw_name = "PSPNVRAM_FILE", + .type = AMD_FW_PSP_NVRAM, .level = PSP_LVL2 }, + { .fw_name = "PSP_SMUFW1_SUB2_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 2, .level = PSP_BOTH }, + { .fw_name = "PSPSECUREDEBUG_FILE", + .type = AMD_FW_PSP_SECURED_DEBUG, .level = PSP_LVL2 }, + { .fw_name = "PSPTRUSTLETS_FILE", + .type = AMD_FW_PSP_TRUSTLETS, .level = PSP_LVL2 }, + { .fw_name = "TRUSTLETKEY_FILE", + .type = AMD_FW_PSP_TRUSTLETKEY, .level = PSP_LVL2 }, + { .fw_name = "PSP_SMUFW2_SUB2_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 2, .level = PSP_BOTH }, + { .fw_name = "PSP_SMUFW1_SUB1_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE, .subprog = 1, .level = PSP_BOTH }, + { .fw_name = "PSP_SMUFW2_SUB1_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE2, .subprog = 1, .level = PSP_BOTH }, + { .fw_name = "PSP_SMUFW2_SUB0_FILE", + .type = AMD_FW_PSP_SMU_FIRMWARE2, .level = PSP_BOTH }, + { .fw_name = "SMUSCS_FILE", + .type = AMD_FW_PSP_SMUSCS, .level = PSP_BOTH }, { .type = AMD_PSP_FUSE_CHAIN, .level = PSP_LVL2 }, - { .type = AMD_DEBUG_UNLOCK, .level = PSP_LVL2 }, - { .type = AMD_HW_IPCFG, .level = PSP_LVL2 }, - { .type = AMD_WRAPPED_IKEK, .level = PSP_BOTH }, + { .fw_name = "PSP_SEC_DEBUG_FILE", + .type = AMD_DEBUG_UNLOCK, .level = PSP_LVL2 }, + { .fw_name = "PSP_HW_IPCFG_FILE", + .type = AMD_HW_IPCFG, .level = PSP_LVL2 }, + { .fw_name = "PSP_IKEK_FILE", + .type = AMD_WRAPPED_IKEK, .level = PSP_BOTH }, { .type = AMD_TOKEN_UNLOCK, .level = PSP_BOTH }, - { .type = AMD_SEC_GASKET, .subprog = 0, .level = PSP_BOTH }, - { .type = AMD_SEC_GASKET, .subprog = 2, .level = PSP_BOTH }, - { .type = AMD_SEC_GASKET, .subprog = 1, .level = PSP_BOTH }, - { .type = AMD_MP2_FW, .subprog = 2, .level = PSP_LVL2 }, - { .type = AMD_MP2_FW, .subprog = 1, .level = PSP_LVL2 }, - { .type = AMD_MP2_FW, .subprog = 0, .level = PSP_LVL2 }, - { .type = AMD_DRIVER_ENTRIES, .level = PSP_LVL2 }, - { .type = AMD_FW_KVM_IMAGE, .level = PSP_LVL2}, - { .type = AMD_S0I3_DRIVER, .level = PSP_LVL2 }, - { .type = AMD_VBIOS_BTLOADER, .level = PSP_BOTH }, - { .type = AMD_FW_TOS_SEC_POLICY, .level = PSP_BOTH }, - { .type = AMD_FW_USB_PHY, .level = PSP_LVL2 }, - { .type = AMD_FW_DRTM_TA, .level = PSP_LVL2 }, - { .type = AMD_FW_KEYDB_BL, .level = PSP_BOTH }, - { .type = AMD_FW_KEYDB_TOS, .level = PSP_LVL2 }, - { .type = AMD_FW_DMCU_ERAM, .level = PSP_LVL2 }, - { .type = AMD_FW_DMCU_ISR, .level = PSP_LVL2 }, - { .type = AMD_RPMC_NVRAM, .level = PSP_LVL2 }, - { .type = AMD_FW_PSP_BOOTLOADER_AB, .level = PSP_LVL2 }, - { .type = AMD_ABL0, .level = PSP_BOTH }, - { .type = AMD_ABL1, .level = PSP_BOTH }, - { .type = AMD_ABL2, .level = PSP_BOTH }, - { .type = AMD_ABL3, .level = PSP_BOTH }, - { .type = AMD_ABL4, .level = PSP_BOTH }, - { .type = AMD_ABL5, .level = PSP_BOTH }, - { .type = AMD_ABL6, .level = PSP_BOTH }, - { .type = AMD_ABL7, .level = PSP_BOTH }, + { .fw_name = "PSP_SECG0_FILE", + .type = AMD_SEC_GASKET, .subprog = 0, .level = PSP_BOTH }, + { .fw_name = "PSP_SECG2_FILE", + .type = AMD_SEC_GASKET, .subprog = 2, .level = PSP_BOTH }, + { .fw_name = "PSP_SECG1_FILE", + .type = AMD_SEC_GASKET, .subprog = 1, .level = PSP_BOTH }, + { .fw_name = "PSP_MP2FW2_FILE", + .type = AMD_MP2_FW, .subprog = 2, .level = PSP_LVL2 }, + { .fw_name = "PSP_MP2FW1_FILE", + .type = AMD_MP2_FW, .subprog = 1, .level = PSP_LVL2 }, + { .fw_name = "PSP_MP2FW0_FILE", + .type = AMD_MP2_FW, .subprog = 0, .level = PSP_LVL2 }, + { .fw_name = "AMD_DRIVER_ENTRIES", + .type = AMD_DRIVER_ENTRIES, .level = PSP_LVL2 }, + { .fw_name = "PSP_KVM_ENGINE_DUMMY_FILE", + .type = AMD_FW_KVM_IMAGE, .level = PSP_LVL2 }, + { .fw_name = "PSP_S0I3_FILE", + .type = AMD_S0I3_DRIVER, .level = PSP_LVL2 }, + { .fw_name = "VBIOS_BTLOADER_FILE", + .type = AMD_VBIOS_BTLOADER, .level = PSP_BOTH }, + { .fw_name = "SECURE_POLICY_L1_FILE", + .type = AMD_FW_TOS_SEC_POLICY, .level = PSP_BOTH }, + { .fw_name = "UNIFIEDUSB_FILE", + .type = AMD_FW_USB_PHY, .level = PSP_LVL2 }, + { .fw_name = "DRTMTA_FILE", + .type = AMD_FW_DRTM_TA, .level = PSP_LVL2 }, + { .fw_name = "KEYDBBL_FILE", + .type = AMD_FW_KEYDB_BL, .level = PSP_BOTH }, + { .fw_name = "KEYDB_TOS_FILE", + .type = AMD_FW_KEYDB_TOS, .level = PSP_LVL2 }, + { .fw_name = "DMCUERAMDCN21_FILE", + .type = AMD_FW_DMCU_ERAM, .level = PSP_LVL2 }, + { .fw_name = "DMCUINTVECTORSDCN21_FILE", + .type = AMD_FW_DMCU_ISR, .level = PSP_LVL2 }, + { .fw_name = "RPMC_FILE", + .type = AMD_RPMC_NVRAM, .level = PSP_LVL2 }, + { .fw_name = "PSPBTLDR_AB_FILE", + .type = AMD_FW_PSP_BOOTLOADER_AB, .level = PSP_LVL2 }, + { .fw_name = "PSP_ABL0_FILE", + .type = AMD_ABL0, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL1_FILE", + .type = AMD_ABL1, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL2_FILE", + .type = AMD_ABL2, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL3_FILE", + .type = AMD_ABL3, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL4_FILE", + .type = AMD_ABL4, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL5_FILE", + .type = AMD_ABL5, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL6_FILE", + .type = AMD_ABL6, .level = PSP_BOTH }, + { .fw_name = "PSP_ABL7_FILE", + .type = AMD_ABL7, .level = PSP_BOTH }, { .type = AMD_FW_PSP_WHITELIST, .level = PSP_LVL2 }, { .type = AMD_FW_PSP_VERSTAGE, .level = PSP_BOTH }, { .type = AMD_FW_VERSTAGE_SIG, .level = PSP_BOTH }, diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h index a7ac7c1..203e960 100644 --- a/util/amdfwtool/amdfwtool.h +++ b/util/amdfwtool/amdfwtool.h @@ -213,6 +213,7 @@ #define PSP_LVL2 (1 << 1) #define PSP_BOTH (PSP_LVL1 | PSP_LVL2) typedef struct _amd_fw_entry { + const char *fw_name; amd_fw_type type; char *filename; uint8_t subprog; diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c index 25e739a..9dd0272 100644 --- a/util/amdfwtool/data_parse.c +++ b/util/amdfwtool/data_parse.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */
-#include <commonlib/helpers.h> #include <stdio.h> #include <regex.h> #include <string.h> @@ -101,64 +100,7 @@ extern amd_fw_entry amd_psp_fw_table[]; extern amd_bios_entry amd_bios_table[];
-struct psp_valid_entry_table { - const char *fw_name; - amd_fw_type fw_type; - uint8_t subprog; -}; - -static const struct psp_valid_entry_table psp_dir_valid_entries[] = { - {"PSPBTLDR_WL_FILE", AMD_FW_PSP_BOOTLOADER_AB, 0}, - {"PSPBTLDR_FILE", AMD_FW_PSP_BOOTLOADER, 0}, - {"AMD_PUBKEY_FILE", AMD_FW_PSP_PUBKEY, 0}, - {"PSPRCVR_FILE", AMD_FW_PSP_RECOVERY, 0}, - {"PUBSIGNEDKEY_FILE", AMD_FW_PSP_RTM_PUBKEY, 0}, - {"PSPNVRAM_FILE", AMD_FW_PSP_NVRAM, 0}, - {"SMUSCS_FILE", AMD_FW_PSP_SMUSCS, 0}, - {"PSPTRUSTLETS_FILE", AMD_FW_PSP_TRUSTLETS, 0}, - {"PSPSECUREDEBUG_FILE", AMD_FW_PSP_SECURED_DEBUG, 0}, - {"PSP_SMUFW1_SUB0_FILE", AMD_FW_PSP_SMU_FIRMWARE, 0}, - {"PSP_HW_IPCFG_FILE", AMD_HW_IPCFG, 0}, - {"PSP_SMUFW1_SUB1_FILE", AMD_FW_PSP_SMU_FIRMWARE, 1}, - {"PSP_SMUFW1_SUB2_FILE", AMD_FW_PSP_SMU_FIRMWARE, 2}, - {"PSP_SMUFW2_SUB0_FILE", AMD_FW_PSP_SMU_FIRMWARE2, 0}, - {"PSP_SMUFW2_SUB1_FILE", AMD_FW_PSP_SMU_FIRMWARE2, 1}, - {"PSP_SMUFW2_SUB2_FILE", AMD_FW_PSP_SMU_FIRMWARE2, 2}, - {"PSP_SEC_DEBUG_FILE", AMD_DEBUG_UNLOCK, 0}, - {"PSP_ABL0_FILE", AMD_ABL0, 0}, - {"PSP_ABL1_FILE", AMD_ABL1, 0}, - {"PSP_ABL2_FILE", AMD_ABL2, 0}, - {"PSP_ABL3_FILE", AMD_ABL3, 0}, - {"PSP_ABL4_FILE", AMD_ABL4, 0}, - {"PSP_ABL5_FILE", AMD_ABL5, 0}, - {"PSP_ABL6_FILE", AMD_ABL6, 0}, - {"PSP_ABL7_FILE", AMD_ABL7, 0}, - {"PSPSECUREOS_FILE", AMD_FW_PSP_SECURED_OS, 0}, - {"TRUSTLETKEY_FILE", AMD_FW_PSP_TRUSTLETKEY, 0}, - {"PSP_IKEK_FILE", AMD_WRAPPED_IKEK, 0}, - {"PSP_SECG0_FILE", AMD_SEC_GASKET, 0}, - {"PSP_SECG1_FILE", AMD_SEC_GASKET, 1}, - {"PSP_SECG2_FILE", AMD_SEC_GASKET, 2}, - {"PSP_MP2FW0_FILE", AMD_MP2_FW, 0}, - {"PSP_MP2FW1_FILE", AMD_MP2_FW, 1}, - {"PSP_MP2FW2_FILE", AMD_MP2_FW, 2}, - {"PSP_S0I3_FILE", AMD_S0I3_DRIVER, 0}, - {"AMD_DRIVER_ENTRIES", AMD_DRIVER_ENTRIES, 0}, - {"VBIOS_BTLOADER_FILE", AMD_VBIOS_BTLOADER, 0}, - {"SECURE_POLICY_L1_FILE", AMD_FW_TOS_SEC_POLICY, 0}, - {"UNIFIEDUSB_FILE", AMD_FW_USB_PHY, 0}, - {"DRTMTA_FILE", AMD_FW_DRTM_TA, 0}, - {"KEYDBBL_FILE", AMD_FW_KEYDB_BL, 0}, - {"KEYDB_TOS_FILE", AMD_FW_KEYDB_TOS, 0}, - {"DMCUERAMDCN21_FILE", AMD_FW_DMCU_ERAM, 0}, - {"DMCUINTVECTORSDCN21_FILE", AMD_FW_DMCU_ISR, 0}, - {"PSP_KVM_ENGINE_DUMMY_FILE", AMD_FW_KVM_IMAGE, 0}, - {"RPMC_FILE", AMD_RPMC_NVRAM, 0}, - {"PSPBTLDR_AB_FILE", AMD_FW_PSP_BOOTLOADER_AB, 0} -}; - -static bool should_skip_entry(char *fw_name, amd_fw_type fw_type, - amd_cb_config *cb_config) +static bool should_skip_entry(amd_fw_type fw_type, amd_cb_config *cb_config) { switch (fw_type) { case AMD_FW_PSP_SECURED_DEBUG: @@ -172,13 +114,6 @@ return !(cb_config->load_mp2_fw); case AMD_S0I3_DRIVER: return !(cb_config->s0i3); - case AMD_FW_PSP_BOOTLOADER_AB: - if (strcmp(fw_name, "PSPBTLDR_WL_FILE") == 0) { - return !(cb_config->have_whitelist); - } else { - return (cb_config->have_whitelist); - } - break; default: /* default to include */ return 0; @@ -190,33 +125,38 @@ { amd_fw_type fw_type = AMD_FW_INVALID; amd_fw_entry *psp_tableptr; - uint8_t subprog = 0; - unsigned long i = 0; + char *tmp = fw_name;
- for (i = 0; i < ARRAY_SIZE(psp_dir_valid_entries); i++) { - if (strcmp(fw_name, psp_dir_valid_entries[i].fw_name) == 0) { - fw_type = psp_dir_valid_entries[i].fw_type; - subprog = psp_dir_valid_entries[i].subprog; - break; - } + /* Special handling for AB bootloader */ + if (strcmp(fw_name, "PSPBTLDR_WL_FILE") == 0) { + if (cb_config->have_whitelist) + tmp = "PSPBTLDR_AB_FILE"; + else + return 1; } - if (should_skip_entry(fw_name, fw_type, cb_config)) { - fw_type = AMD_FW_SKIP; + + if (strcmp(fw_name, "PSPBTLDR_AB_FILE") == 0) { + if (cb_config->have_whitelist) + return 1; }
+ fw_name = tmp; + /* Search and fill the filename */ psp_tableptr = &amd_psp_fw_table[0]; - if (fw_type != AMD_FW_SKIP && fw_type != AMD_FW_INVALID) { - while (psp_tableptr->type != AMD_FW_INVALID) { - /* instance are not used in PSP table */ - if (psp_tableptr->type == fw_type && psp_tableptr->subprog == subprog) { + while (psp_tableptr->type != AMD_FW_INVALID) { + if (psp_tableptr->fw_name && + strcmp(fw_name, psp_tableptr->fw_name) == 0) { + fw_type = psp_tableptr->type; + if (!should_skip_entry(fw_type, cb_config)) { psp_tableptr->filename = filename; SET_LEVEL(psp_tableptr, level_to_set, PSP); - break; } - psp_tableptr++; + break; } + psp_tableptr++; } + if (fw_type == AMD_FW_INVALID) return 0; else