From e381aef220d4880c84057e82f8ec15e5512ce69e Mon Sep 17 00:00:00 2001 From: Qi Yadong Date: Wed, 20 Mar 2019 14:09:00 +0800 Subject: [PATCH] hv: seed: remove unused seed parsing source files Remove the unused seed parsing source files under hypervisor/boot/sbl and related header files. Tracked-On: #2724 Signed-off-by: Qi Yadong --- hypervisor/boot/sbl/abl_seed_parse.c | 159 ---------------- hypervisor/boot/sbl/sbl_seed_parse.c | 190 ------------------- hypervisor/include/arch/x86/abl_seed_parse.h | 12 -- hypervisor/include/arch/x86/sbl_seed_parse.h | 12 -- 4 files changed, 373 deletions(-) delete mode 100644 hypervisor/boot/sbl/abl_seed_parse.c delete mode 100644 hypervisor/boot/sbl/sbl_seed_parse.c delete mode 100644 hypervisor/include/arch/x86/abl_seed_parse.h delete mode 100644 hypervisor/include/arch/x86/sbl_seed_parse.h diff --git a/hypervisor/boot/sbl/abl_seed_parse.c b/hypervisor/boot/sbl/abl_seed_parse.c deleted file mode 100644 index f95a5e5b4..000000000 --- a/hypervisor/boot/sbl/abl_seed_parse.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define ABL_SEED_LEN 32U -struct abl_seed_info { - uint8_t svn; - uint8_t reserved[3]; - uint8_t seed[ABL_SEED_LEN]; -}; - -#define ABL_SEED_LIST_MAX 4U -struct dev_sec_info { - uint32_t size_of_this_struct; - uint32_t version; - uint32_t num_seeds; - struct abl_seed_info seed_list[ABL_SEED_LIST_MAX]; -}; - -static const char *abl_seed_arg[] = { - "ABL.svnseed=", - "dev_sec_info.param_addr=", - NULL -}; - -static void parse_seed_list_abl(void *param_addr) -{ - uint32_t i; - uint32_t legacy_seed_index = 0U; - struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES]; - struct dev_sec_info *sec_info = (struct dev_sec_info *)param_addr; - bool parse_success = false; - - if ((sec_info != NULL) && (sec_info->num_seeds >= 2U) && (sec_info->num_seeds <= ABL_SEED_LIST_MAX)) { - /* - * The seed_list from ABL contains several seeds which based on SVN - * and one legacy seed which is not based on SVN. The legacy seed's - * svn value is minimum in the seed list. And CSE ensures at least two - * seeds will be generated which will contain the legacy seed. - * Here find the legacy seed index first. - */ - for (i = 1U; i < sec_info->num_seeds; i++) { - if (sec_info->seed_list[i].svn < sec_info->seed_list[legacy_seed_index].svn) { - legacy_seed_index = i; - } - } - - /* - * Copy out abl_seed for trusty and clear the original seed in memory. - * The SOS requires the legacy seed to derive RPMB key. So skip the - * legacy seed when clear original seed. - */ - (void)memset((void *)dseed_list, 0U, (BOOTLOADER_SEED_MAX_ENTRIES * sizeof(struct seed_info))); - for (i = 0U; i < sec_info->num_seeds; i++) { - dseed_list[i].cse_svn = sec_info->seed_list[i].svn; - (void)memcpy_s((void *)dseed_list[i].seed, sizeof(dseed_list[i].seed), - (void *)sec_info->seed_list[i].seed, sizeof(sec_info->seed_list[i].seed)); - - if (i == legacy_seed_index) { - continue; - } - - (void)memset((void *)sec_info->seed_list[i].seed, 0U, sizeof(sec_info->seed_list[i].seed)); - } - - parse_success = true; - } - - if (parse_success) { - trusty_set_dseed((void *)dseed_list, (uint8_t)(sec_info->num_seeds)); - } else { - trusty_set_dseed(NULL, 0U); - } - - (void)memset((void *)dseed_list, 0U, sizeof(dseed_list)); -} - -/* - * abl_seed_parse - * - * description: - * This function parse dev_sec_info from cmdline. Mainly on - * 1. parse structure address from cmdline - * 2. call parse_seed_list_abl to parse seed_list - * 3. convert address in the structure from HPA to SOS's GPA - * 4. clear original image_boot_params argument in cmdline since - * original address is HPA. - * - * input: - * cmdline pointer to cmdline string - * out_len the max len of out_arg - * - * output: - * out_arg the argument with SOS's GPA - * - * return value: - * true if parse successfully, otherwise false. - */ -bool abl_seed_parse(char *cmdline, char *out_arg, uint32_t out_len) -{ - char *arg = NULL, *arg_end; - char *param; - void *param_addr; - uint32_t len = 0U, i; - bool parse_success = false; - - if (cmdline != NULL) { - - for (i = 0U; abl_seed_arg[i] != NULL; i++) { - len = strnlen_s(abl_seed_arg[i], MEM_1K); - arg = strstr_s((const char *)cmdline, MEM_2K, abl_seed_arg[i], len); - if (arg != NULL) { - break; - } - } - - if (arg != NULL) { - param = arg + len; - param_addr = (void *)hpa2hva(strtoul_hex(param)); - if (param_addr != NULL) { - parse_seed_list_abl(param_addr); - - /* - * Replace original arguments with spaces since SOS's GPA is not - * identity mapped to HPA. The argument will be appended later when - * compose cmdline for SOS. - */ - arg_end = strchr(arg, ' '); - len = (arg_end != NULL) ? (uint32_t)(arg_end - arg) : strnlen_s(arg, MEM_2K); - (void)memset((void *)arg, ' ', len); - - /* Convert the param_addr to SOS GPA and copy to caller */ - if (out_arg != NULL) { - snprintf(out_arg, out_len, "%s0x%X ", - abl_seed_arg[i], sos_vm_hpa2gpa(hva2hpa(param_addr))); - } - - parse_success = true; - } - } - } - - if (!parse_success) { - parse_seed_list_abl(NULL); - } - - return parse_success; -} diff --git a/hypervisor/boot/sbl/sbl_seed_parse.c b/hypervisor/boot/sbl/sbl_seed_parse.c deleted file mode 100644 index 5be77ddd1..000000000 --- a/hypervisor/boot/sbl/sbl_seed_parse.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define SEED_ENTRY_TYPE_SVNSEED 0x1U -/* #define SEED_ENTRY_TYPE_RPMBSEED 0x2U */ - -/* #define SEED_ENTRY_USAGE_USEED 0x1U */ -#define SEED_ENTRY_USAGE_DSEED 0x2U - -struct seed_list_hob { - uint8_t revision; - uint8_t reserved0[3]; - uint32_t buffer_size; - uint8_t total_seed_count; - uint8_t reserved1[3]; -}; - -struct seed_entry { - /* SVN based seed or RPMB seed or attestation key_box */ - uint8_t type; - /* For SVN seed: useed or dseed - * For RPMB seed: serial number based or not - */ - uint8_t usage; - /* index for the same type and usage seed */ - uint8_t index; - uint8_t reserved; - /* reserved for future use */ - uint16_t flags; - /* Total size of this seed entry */ - uint16_t seed_entry_size; - /* SVN seed: struct seed_info - * RPMB seed: uint8_t rpmb_key[key_len] - */ - uint8_t seed[0]; -}; - -struct image_boot_params { - uint32_t size_of_this_struct; - uint32_t version; - uint64_t p_seed_list; - uint64_t p_platform_info; - uint64_t reserved; -}; - -static const char *boot_params_arg = "ImageBootParamsAddr="; - -static void parse_seed_list_sbl(struct seed_list_hob *seed_hob) -{ - uint8_t i; - uint8_t dseed_index = 0U; - struct seed_entry *entry; - struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES]; - bool parse_success = false; - - if ((seed_hob != NULL) && (seed_hob->total_seed_count != 0U)) { - parse_success = true; - - entry = (struct seed_entry *)((uint8_t *)seed_hob + sizeof(struct seed_list_hob)); - - for (i = 0U; i < seed_hob->total_seed_count; i++) { - if (entry == NULL) { - break; - } - /* retrieve dseed */ - if ((SEED_ENTRY_TYPE_SVNSEED == entry->type) && (SEED_ENTRY_USAGE_DSEED == entry->usage)) { - - /* The seed_entry with same type/usage are always - * arranged by index in order of 0~3. - */ - if (entry->index != dseed_index) { - pr_warn("Index mismatch. Use fake seed!"); - parse_success = false; - break; - } - - if (entry->index >= BOOTLOADER_SEED_MAX_ENTRIES) { - pr_warn("Index exceed max number!"); - parse_success = false; - break; - } - - (void)memcpy_s((void *)&dseed_list[dseed_index], sizeof(struct seed_info), - (void *)entry->seed, sizeof(struct seed_info)); - dseed_index++; - - /* erase original seed in seed entry */ - (void)memset((void *)entry->seed, 0U, sizeof(struct seed_info)); - } - - entry = (struct seed_entry *)((uint8_t *)entry + entry->seed_entry_size); - } - } - - if (parse_success) { - trusty_set_dseed((void *)dseed_list, dseed_index); - } else { - trusty_set_dseed(NULL, 0U); - } - - (void)memset((void *)dseed_list, 0U, sizeof(dseed_list)); -} - -/* - * sbl_seed_parse - * - * description: - * This function parse image_boot_params from cmdline. Mainly on - * 1. parse structure address from cmdline - * 2. get seed_list address and call parse_seed_list_sbl to parse seed - * 3. convert address in the structure from HPA to SOS's GPA - * 4. clear original image_boot_params argument in cmdline since - * original address is HPA. - * - * input: - * vm_is_sos Boolean to check if vm is sos - * cmdline pointer to cmdline string - * out_len the max len of out_arg - * - * output: - * out_arg the argument with SOS's GPA - * - * return value: - * true if parse successfully, otherwise false. - */ -bool sbl_seed_parse(bool vm_is_sos, char *cmdline, char *out_arg, uint32_t out_len) -{ - char *arg, *arg_end; - char *param; - void *param_addr; - struct image_boot_params *boot_params; - uint32_t len; - bool parse_success = false; - - if (vm_is_sos && (cmdline != NULL)) { - len = strnlen_s(boot_params_arg, MEM_1K); - arg = strstr_s((const char *)cmdline, MEM_2K, boot_params_arg, len); - - if (arg != NULL) { - param = arg + len; - param_addr = (void *)hpa2hva(strtoul_hex(param)); - if (param_addr != NULL) { - boot_params = (struct image_boot_params *)param_addr; - parse_seed_list_sbl((struct seed_list_hob *)hpa2hva(boot_params->p_seed_list)); - - /* - * Convert the addresses to SOS GPA since this structure will - * be used in SOS. - */ - boot_params->p_seed_list = sos_vm_hpa2gpa(boot_params->p_seed_list); - boot_params->p_platform_info = sos_vm_hpa2gpa(boot_params->p_platform_info); - - /* - * Replace original arguments with spaces since SOS's GPA is not - * identity mapped to HPA. The argument will be appended later when - * compose cmdline for SOS. - */ - arg_end = strchr(arg, ' '); - len = (arg_end != NULL) ? (uint32_t)(arg_end - arg) : strnlen_s(arg, MEM_2K); - (void)memset((void *)arg, ' ', len); - - /* Convert the param_addr to SOS GPA and copy to caller */ - if (out_arg != NULL) { - snprintf(out_arg, out_len, "%s0x%X ", - boot_params_arg, sos_vm_hpa2gpa(hva2hpa(param_addr))); - } - - parse_success = true; - } - } - } - - if (!parse_success) { - parse_seed_list_sbl(NULL); - } - - return parse_success; -} diff --git a/hypervisor/include/arch/x86/abl_seed_parse.h b/hypervisor/include/arch/x86/abl_seed_parse.h deleted file mode 100644 index c442b823f..000000000 --- a/hypervisor/include/arch/x86/abl_seed_parse.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef ABL_SEED_PARSE_H_ -#define ABL_SEED_PARSE_H_ - -bool abl_seed_parse(char *cmdline, char *out_arg, uint32_t out_len); - -#endif /* ABL_SEED_PARSE_H_ */ diff --git a/hypervisor/include/arch/x86/sbl_seed_parse.h b/hypervisor/include/arch/x86/sbl_seed_parse.h deleted file mode 100644 index 48f61a9c7..000000000 --- a/hypervisor/include/arch/x86/sbl_seed_parse.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef SBL_SEED_PARSE_H_ -#define SBL_SEED_PARSE_H_ - -bool sbl_seed_parse(bool vm_is_sos, char *cmdline, char *out_arg, uint32_t out_len); - -#endif /* SBL_SEED_PARSE_H_ */