[PATCH 6/6] Fold filter_cfg_parts into enumerate_cfg_parts

2 views
Skip to first unread message

Jan Kiszka

unread,
Dec 9, 2024, 8:39:12 AM12/9/24
to efibootg...@googlegroups.com, Maxime Roussin-Bélanger, Felix Moessbauer, Christian Storm
From: Jan Kiszka <jan.k...@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.k...@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

Reply all
Reply to author
Forward
0 new messages