Kangheui Won has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59449 )
Change subject: amdfwtool: clean up psp fw parsing ......................................................................
amdfwtool: clean up psp fw parsing
find_register_fw_filename_psp_dir parses first token from the fw.cfg and find fw_type and subprog for it. However every entries are hard-coded, which makes code to be hard to read and maintain.
Make a new lookup table so things are more organized than before.
Signed-off-by: Kangheui Won khwon@chromium.org Change-Id: Id7adb20db7bab73933b457f3449b2d8ce4217b8c --- M util/amdfwtool/data_parse.c 1 file changed, 80 insertions(+), 165 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/49/59449/1
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c index 8f93183..442155e 100644 --- a/util/amdfwtool/data_parse.c +++ b/util/amdfwtool/data_parse.c @@ -9,6 +9,8 @@
#include "amdfwtool.h"
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + /* TODO: a empty line does not matched. */ static const char blank_or_comment_regex[] = /* a blank line */ @@ -100,210 +102,123 @@ 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_DBG_KEY_FILE", AMD_FW_PSP_SECURED_DEBUG, 0}, + {"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}, + {"PSPTRUSTLETS_FILE", AMD_FW_PSP_TRUSTLETS, 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_DRIVERS_FILE", AMD_DRIVER_ENTRIES, 0}, + {"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 uint8_t find_register_fw_filename_psp_dir(char *fw_name, char *filename, char level_to_set, amd_cb_config *cb_config) { amd_fw_type fw_type = AMD_FW_INVALID; amd_fw_entry *psp_tableptr; - uint8_t subprog; + uint8_t subprog = 0; + unsigned long i = 0;
+ 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; + } + } if (strcmp(fw_name, "PSPBTLDR_WL_FILE") == 0) { - if (cb_config->have_whitelist) { - fw_type = AMD_FW_PSP_BOOTLOADER_AB; - subprog = 0; - } else { + if (!cb_config->have_whitelist) { fw_type = AMD_FW_SKIP; } - } else if (strcmp(fw_name, "PSPBTLDR_FILE") == 0) { - fw_type = AMD_FW_PSP_BOOTLOADER; - subprog = 0; - } else if (strcmp(fw_name, "AMD_PUBKEY_FILE") == 0) { - fw_type = AMD_FW_PSP_PUBKEY; - subprog = 0; - } else if (strcmp(fw_name, "PSPRCVR_FILE") == 0) { - fw_type = AMD_FW_PSP_RECOVERY; - subprog = 0; - } else if (strcmp(fw_name, "PUBSIGNEDKEY_FILE") == 0) { - fw_type = AMD_FW_PSP_RTM_PUBKEY; - subprog = 0; - } else if (strcmp(fw_name, "PSPNVRAM_FILE") == 0) { - fw_type = AMD_FW_PSP_NVRAM; - subprog = 0; - } else if (strcmp(fw_name, "SMUSCS_FILE") == 0) { - fw_type = AMD_FW_PSP_SMUSCS; - subprog = 0; - } else if (strcmp(fw_name, "PSPTRUSTLETS_FILE") == 0) { - fw_type = AMD_FW_PSP_TRUSTLETS; - subprog = 0; - } else if (strcmp(fw_name, "PSPSECUREDEBUG_FILE") == 0) { - fw_type = AMD_FW_PSP_SECURED_DEBUG; - subprog = 0; - } else if (strcmp(fw_name, "PSP_SMUFW1_SUB0_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE; - subprog = 0; - } else if (strcmp(fw_name, "PSP_HW_IPCFG_FILE") == 0) { - fw_type = AMD_HW_IPCFG; - subprog = 0; - } else if (strcmp(fw_name, "PSP_SMUFW1_SUB1_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE; - subprog = 1; - } else if (strcmp(fw_name, "PSP_SMUFW1_SUB2_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE; - subprog = 2; - } else if (strcmp(fw_name, "PSP_SMUFW2_SUB0_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE2; - subprog = 0; - } else if (strcmp(fw_name, "PSP_SMUFW2_SUB1_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE2; - subprog = 1; - } else if (strcmp(fw_name, "PSP_SMUFW2_SUB2_FILE") == 0) { - fw_type = AMD_FW_PSP_SMU_FIRMWARE2; - subprog = 2; } else if (strcmp(fw_name, "PSP_SEC_DBG_KEY_FILE") == 0) { - if (cb_config->unlock_secure) { - fw_type = AMD_FW_PSP_SECURED_DEBUG; - subprog = 0; - } else { + if (!cb_config->unlock_secure) { fw_type = AMD_FW_SKIP; } } else if (strcmp(fw_name, "PSP_SEC_DEBUG_FILE") == 0) { - if (cb_config->unlock_secure) { - fw_type = AMD_DEBUG_UNLOCK; - subprog = 0; - } else { + if (!cb_config->unlock_secure) { fw_type = AMD_FW_SKIP; } - } else if (strcmp(fw_name, "PSP_ABL0_FILE") == 0) { - fw_type = AMD_ABL0; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL1_FILE") == 0) { - fw_type = AMD_ABL1; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL2_FILE") == 0) { - fw_type = AMD_ABL2; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL3_FILE") == 0) { - fw_type = AMD_ABL3; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL4_FILE") == 0) { - fw_type = AMD_ABL4; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL5_FILE") == 0) { - fw_type = AMD_ABL5; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL6_FILE") == 0) { - fw_type = AMD_ABL6; - subprog = 0; - } else if (strcmp(fw_name, "PSP_ABL7_FILE") == 0) { - fw_type = AMD_ABL7; - subprog = 0; } else if (strcmp(fw_name, "PSPSECUREOS_FILE") == 0) { - if (cb_config->use_secureos) { - fw_type = AMD_FW_PSP_SECURED_OS; - subprog = 0; - } else { + if (!cb_config->use_secureos) { fw_type = AMD_FW_SKIP; } } else if (strcmp(fw_name, "PSPTRUSTLETS_FILE") == 0) { - if (cb_config->use_secureos) { - fw_type = AMD_FW_PSP_TRUSTLETS; - subprog = 0; - } else { + if (!cb_config->use_secureos) { fw_type = AMD_FW_SKIP; } } else if (strcmp(fw_name, "TRUSTLETKEY_FILE") == 0) { - if (cb_config->use_secureos) { - fw_type = AMD_FW_PSP_TRUSTLETKEY; - subprog = 0; - } else { + if (!cb_config->use_secureos) { fw_type = AMD_FW_SKIP; } - } else if (strcmp(fw_name, "PSP_IKEK_FILE") == 0) { - fw_type = AMD_WRAPPED_IKEK; - subprog = 0; - } else if (strcmp(fw_name, "PSP_SECG0_FILE") == 0) { - fw_type = AMD_SEC_GASKET; - subprog = 0; - } else if (strcmp(fw_name, "PSP_SECG1_FILE") == 0) { - fw_type = AMD_SEC_GASKET; - subprog = 1; - } else if (strcmp(fw_name, "PSP_SECG2_FILE") == 0) { - fw_type = AMD_SEC_GASKET; - subprog = 2; } else if (strcmp(fw_name, "PSP_MP2FW0_FILE") == 0) { - if (cb_config->load_mp2_fw) { - fw_type = AMD_MP2_FW; - subprog = 0; - } else { + if (!cb_config->load_mp2_fw) { fw_type = AMD_FW_SKIP; } } else if (strcmp(fw_name, "PSP_MP2FW1_FILE") == 0) { - if (cb_config->load_mp2_fw) { - fw_type = AMD_MP2_FW; - subprog = 1; - } else { + if (!cb_config->load_mp2_fw) { fw_type = AMD_FW_SKIP; } } else if (strcmp(fw_name, "PSP_MP2FW2_FILE") == 0) { - if (cb_config->load_mp2_fw) { - fw_type = AMD_MP2_FW; - subprog = 2; - } else { + if (!cb_config->load_mp2_fw) { fw_type = AMD_FW_SKIP; } - } else if (strcmp(fw_name, "PSP_DRIVERS_FILE") == 0) { - fw_type = AMD_DRIVER_ENTRIES; - subprog = 0; } else if (strcmp(fw_name, "PSP_S0I3_FILE") == 0) { - if (cb_config->s0i3) { - fw_type = AMD_S0I3_DRIVER; - subprog = 0; - } else { + if (!cb_config->s0i3) { fw_type = AMD_FW_SKIP; } - } else if (strcmp(fw_name, "AMD_DRIVER_ENTRIES") == 0) { - fw_type = AMD_DRIVER_ENTRIES; - subprog = 0; - } else if (strcmp(fw_name, "VBIOS_BTLOADER_FILE") == 0) { - fw_type = AMD_VBIOS_BTLOADER; - subprog = 0; - } else if (strcmp(fw_name, "SECURE_POLICY_L1_FILE") == 0) { - fw_type = AMD_FW_TOS_SEC_POLICY; - subprog = 0; - } else if (strcmp(fw_name, "UNIFIEDUSB_FILE") == 0) { - fw_type = AMD_FW_USB_PHY; - subprog = 0; - } else if (strcmp(fw_name, "DRTMTA_FILE") == 0) { - fw_type = AMD_FW_DRTM_TA; - subprog = 0; - } else if (strcmp(fw_name, "KEYDBBL_FILE") == 0) { - fw_type = AMD_FW_KEYDB_BL; - subprog = 0; - } else if (strcmp(fw_name, "KEYDB_TOS_FILE") == 0) { - fw_type = AMD_FW_KEYDB_TOS; - subprog = 0; - } else if (strcmp(fw_name, "DMCUERAMDCN21_FILE") == 0) { - fw_type = AMD_FW_DMCU_ERAM; - subprog = 0; - } else if (strcmp(fw_name, "DMCUINTVECTORSDCN21_FILE") == 0) { - fw_type = AMD_FW_DMCU_ISR; - subprog = 0; - } else if (strcmp(fw_name, "PSP_KVM_ENGINE_DUMMY_FILE") == 0) { - fw_type = AMD_FW_KVM_IMAGE; - subprog = 0; - } else if (strcmp(fw_name, "RPMC_FILE") == 0) { - fw_type = AMD_RPMC_NVRAM; - subprog = 0; } else if (strcmp(fw_name, "PSPBTLDR_AB_FILE") == 0) { - if (!cb_config->have_whitelist) { - fw_type = AMD_FW_PSP_BOOTLOADER_AB; - subprog = 0; - } else { + if (cb_config->have_whitelist) { fw_type = AMD_FW_SKIP; } - } else { - fw_type = AMD_FW_INVALID; - /* TODO: Add more */ }
/* Search and fill the filename */