mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-22 21:47:22 +00:00
HV: code style change for sbl_seed_parse.c
- remark unused MACRO; - remove goto; - make sure procedure has one exit point; Tracked-On: #861 Signed-off-by: Victor Sun <victor.sun@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
f4cce46605
commit
c572a9f503
@ -8,9 +8,9 @@
|
||||
#include <sbl_seed_parse.h>
|
||||
|
||||
#define SEED_ENTRY_TYPE_SVNSEED 0x1U
|
||||
#define SEED_ENTRY_TYPE_RPMBSEED 0x2U
|
||||
/* #define SEED_ENTRY_TYPE_RPMBSEED 0x2U */
|
||||
|
||||
#define SEED_ENTRY_USAGE_USEED 0x1U
|
||||
/* #define SEED_ENTRY_USAGE_USEED 0x1U */
|
||||
#define SEED_ENTRY_USAGE_DSEED 0x2U
|
||||
|
||||
struct seed_list_hob {
|
||||
@ -57,56 +57,53 @@ static void parse_seed_list_sbl(struct seed_list_hob *seed_hob)
|
||||
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) {
|
||||
goto fail;
|
||||
}
|
||||
if ((seed_hob != NULL) && (seed_hob->total_seed_count != 0U)) {
|
||||
parse_success = true;
|
||||
|
||||
if (seed_hob->total_seed_count == 0U) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
entry = (struct seed_entry *)((uint8_t *)seed_hob +
|
||||
sizeof(struct seed_list_hob));
|
||||
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)) {
|
||||
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!");
|
||||
goto fail;
|
||||
parse_success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (entry->index >= BOOTLOADER_SEED_MAX_ENTRIES) {
|
||||
pr_warn("Index exceed max number!");
|
||||
goto fail;
|
||||
parse_success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
(void)memcpy_s((void *)&dseed_list[dseed_index],
|
||||
sizeof(struct seed_info),
|
||||
(void *)entry->seed,
|
||||
sizeof(struct seed_info));
|
||||
(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);
|
||||
entry = (struct seed_entry *)((uint8_t *)entry + entry->seed_entry_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_success) {
|
||||
trusty_set_dseed((void *)dseed_list, dseed_index);
|
||||
(void)memset((void *)dseed_list, 0U, sizeof(dseed_list));
|
||||
return;
|
||||
|
||||
fail:
|
||||
} else {
|
||||
trusty_set_dseed(NULL, 0U);
|
||||
}
|
||||
|
||||
(void)memset((void *)dseed_list, 0U, sizeof(dseed_list));
|
||||
}
|
||||
|
||||
@ -139,27 +136,18 @@ bool sbl_seed_parse(struct acrn_vm *vm, char *cmdline, char *out_arg, uint32_t o
|
||||
void *param_addr;
|
||||
struct image_boot_params *boot_params;
|
||||
uint32_t len;
|
||||
bool parse_success = false;
|
||||
|
||||
if (!is_vm0(vm) || (cmdline == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (is_vm0(vm) && (cmdline != NULL)) {
|
||||
len = strnlen_s(boot_params_arg, MEM_1K);
|
||||
arg = strstr_s(cmdline, MEM_2K, boot_params_arg, len);
|
||||
|
||||
if (arg == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
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) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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));
|
||||
parse_seed_list_sbl((struct seed_list_hob *)hpa2hva(boot_params->p_seed_list));
|
||||
|
||||
/*
|
||||
* Convert the addresses to SOS GPA since this structure will
|
||||
@ -174,8 +162,7 @@ bool sbl_seed_parse(struct acrn_vm *vm, char *cmdline, char *out_arg, uint32_t o
|
||||
* compose cmdline for SOS.
|
||||
*/
|
||||
arg_end = strchr(arg, ' ');
|
||||
len = (arg_end != NULL) ? (uint32_t)(arg_end - arg) :
|
||||
strnlen_s(arg, MEM_2K);
|
||||
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 */
|
||||
@ -184,9 +171,14 @@ bool sbl_seed_parse(struct acrn_vm *vm, char *cmdline, char *out_arg, uint32_t o
|
||||
boot_params_arg, hva2gpa(vm, param_addr));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
parse_seed_list_sbl(NULL);
|
||||
return false;
|
||||
parse_success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!parse_success) {
|
||||
parse_seed_list_sbl(NULL);
|
||||
}
|
||||
|
||||
return parse_success;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user