From: Jan Kiszka <jan.kis...@siemens.com> Now that we have strict boot-medium-first ordering in the volume list, we can easily perform the config filtering already while enumerating. Simplifies the code significantly.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- env/fatvars.c | 3 --- env/syspart.c | 60 +++++++++++------------------------------------ include/syspart.h | 1 - 3 files changed, 14 insertions(+), 50 deletions(-) diff --git a/env/fatvars.c b/env/fatvars.c index eacd72b..675f6cc 100644 --- a/env/fatvars.c +++ b/env/fatvars.c @@ -87,9 +87,6 @@ BG_STATUS load_config(BG_LOADER_PARAMS *bglp) ERROR(L"Could not enumerate config partitions.\n"); goto lc_cleanup; } - - numHandles = filter_cfg_parts(config_volumes, numHandles); - if (numHandles > ENV_NUM_CONFIG_PARTS) { ERROR(L"Too many config partitions found. Aborting.\n"); goto lc_cleanup; diff --git a/env/syspart.c b/env/syspart.c index fba5531..1bcde24 100644 --- a/env/syspart.c +++ b/env/syspart.c @@ -20,6 +20,7 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles) { + BOOLEAN use_envs_on_bootmedium_only = FALSE; EFI_STATUS status; UINTN rootCount = 0; @@ -36,9 +37,16 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles) status = open_cfg_file(volumes[index].root, &fh, EFI_FILE_MODE_READ); if (status == EFI_SUCCESS) { - INFO(L"Config file found on volume %d.\n", index); - config_volumes[rootCount] = index; - rootCount++; + if (volumes[index].onbootmedium) { + use_envs_on_bootmedium_only = TRUE; + } + if (!use_envs_on_bootmedium_only || volumes[index].onbootmedium) { + INFO(L"Config file found on volume %d.\n", index); + config_volumes[rootCount] = index; + rootCount++; + } else { + WARNING(L"Ignoring config file found on volume %d.\n", index); + } status = close_cfg_file(volumes[index].root, fh); if (EFI_ERROR(status)) { ERROR(L"Could not close config file on partition %d.\n", @@ -47,49 +55,9 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles) } } *numHandles = rootCount; + if (use_envs_on_bootmedium_only) { + INFO(L"Booting with environments from boot medium only.\n"); + } INFO(L"%d config partitions detected.\n", rootCount); return EFI_SUCCESS; } - -static VOID swap_uintn(UINTN *a, UINTN *b) -{ - UINTN tmp; - tmp = *a; - *a = *b; - *b = tmp; -} - -UINTN filter_cfg_parts(UINTN *config_volumes, UINTN numHandles) -{ - BOOLEAN use_envs_on_bootmedium_only = FALSE; - - INFO(L"Config filter: \n"); - for (UINTN index = 0; index < numHandles; index++) { - VOLUME_DESC *v = &volumes[config_volumes[index]]; - - if (v->onbootmedium) { - use_envs_on_bootmedium_only = TRUE; - }; - } - - if (!use_envs_on_bootmedium_only) { - // nothing to do - return numHandles; - } - - INFO(L"Booting with environments from boot medium only.\n"); - UINTN num_sorted = 0; - for (UINTN j = 0; j < numHandles; j++) { - UINTN cvi = config_volumes[j]; - VOLUME_DESC *v = &volumes[cvi]; - - if (v->onbootmedium) { - swap_uintn(&config_volumes[j], - &config_volumes[num_sorted++]); - } else { - WARNING(L"Ignoring config on volume #%d\n", cvi); - } - } - - return num_sorted; -} diff --git a/include/syspart.h b/include/syspart.h index 9792ae1..e7686e9 100644 --- a/include/syspart.h +++ b/include/syspart.h @@ -32,4 +32,3 @@ (file)->Read((file), (len), (buffer)) EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *maxHandles); -UINTN filter_cfg_parts(UINTN *config_volumes, UINTN maxHandles); -- 2.43.0 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to efibootguard-dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/efibootguard-dev/f8a342c2a51e71b2027920675dba71f321c7bccc.1733751547.git.jan.kiszka%40siemens.com.