|
|
e97c83 |
From 382a0b66e6c06ccf6775e3c05d5f9ce5f0eab5db Mon Sep 17 00:00:00 2001
|
|
|
e97c83 |
From: Gary Ching-Pang Lin <glin@suse.com>
|
|
|
e97c83 |
Date: Thu, 6 Mar 2014 11:58:36 +0800
|
|
|
e97c83 |
Subject: [PATCH 26/74] [fallback] Avoid duplicate old BootOrder
|
|
|
e97c83 |
|
|
|
e97c83 |
set_boot_order() already copies the old BootOrder to the variable,
|
|
|
e97c83 |
bootorder. Besides, we can adjust BootOrder when adding the newly
|
|
|
e97c83 |
generated boot option. So, we don't have to copy the old one again
|
|
|
e97c83 |
in update_boot_order(). This avoid the duplicate entries in BootOrder.
|
|
|
e97c83 |
|
|
|
e97c83 |
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
|
|
|
e97c83 |
---
|
|
|
e97c83 |
fallback.c | 37 ++++++++++++-------------------------
|
|
|
e97c83 |
1 file changed, 12 insertions(+), 25 deletions(-)
|
|
|
e97c83 |
|
|
|
e97c83 |
diff --git a/fallback.c b/fallback.c
|
|
|
e97c83 |
index bc9a3c9..4bde9c1 100644
|
|
|
e97c83 |
--- a/fallback.c
|
|
|
e97c83 |
+++ b/fallback.c
|
|
|
e97c83 |
@@ -204,12 +204,12 @@ add_boot_option(EFI_DEVICE_PATH *hddp, EFI_DEVICE_PATH *fulldp,
|
|
|
e97c83 |
return EFI_OUT_OF_RESOURCES;
|
|
|
e97c83 |
|
|
|
e97c83 |
int j = 0;
|
|
|
e97c83 |
+ newbootorder[0] = i & 0xffff;
|
|
|
e97c83 |
if (nbootorder) {
|
|
|
e97c83 |
for (j = 0; j < nbootorder; j++)
|
|
|
e97c83 |
- newbootorder[j] = bootorder[j];
|
|
|
e97c83 |
+ newbootorder[j+1] = bootorder[j];
|
|
|
e97c83 |
FreePool(bootorder);
|
|
|
e97c83 |
}
|
|
|
e97c83 |
- newbootorder[j] = i & 0xffff;
|
|
|
e97c83 |
bootorder = newbootorder;
|
|
|
e97c83 |
nbootorder += 1;
|
|
|
e97c83 |
#ifdef DEBUG_FALLBACK
|
|
|
e97c83 |
@@ -307,28 +307,17 @@ set_boot_order(void)
|
|
|
e97c83 |
EFI_STATUS
|
|
|
e97c83 |
update_boot_order(void)
|
|
|
e97c83 |
{
|
|
|
e97c83 |
- CHAR16 *oldbootorder;
|
|
|
e97c83 |
UINTN size;
|
|
|
e97c83 |
+ UINTN len = 0;
|
|
|
e97c83 |
EFI_GUID global = EFI_GLOBAL_VARIABLE;
|
|
|
e97c83 |
CHAR16 *newbootorder = NULL;
|
|
|
e97c83 |
+ EFI_STATUS rc;
|
|
|
e97c83 |
|
|
|
e97c83 |
- oldbootorder = LibGetVariableAndSize(L"BootOrder", &global, &size);
|
|
|
e97c83 |
- if (oldbootorder) {
|
|
|
e97c83 |
- int n = size / sizeof (CHAR16) + nbootorder;
|
|
|
e97c83 |
-
|
|
|
e97c83 |
- newbootorder = AllocateZeroPool(n * sizeof (CHAR16));
|
|
|
e97c83 |
- if (!newbootorder)
|
|
|
e97c83 |
- return EFI_OUT_OF_RESOURCES;
|
|
|
e97c83 |
- CopyMem(newbootorder, bootorder, nbootorder * sizeof (CHAR16));
|
|
|
e97c83 |
- CopyMem(newbootorder + nbootorder, oldbootorder, size);
|
|
|
e97c83 |
- size = n * sizeof (CHAR16);
|
|
|
e97c83 |
- } else {
|
|
|
e97c83 |
- size = nbootorder * sizeof(CHAR16);
|
|
|
e97c83 |
- newbootorder = AllocateZeroPool(size);
|
|
|
e97c83 |
- if (!newbootorder)
|
|
|
e97c83 |
- return EFI_OUT_OF_RESOURCES;
|
|
|
e97c83 |
- CopyMem(newbootorder, bootorder, size);
|
|
|
e97c83 |
- }
|
|
|
e97c83 |
+ size = nbootorder * sizeof(CHAR16);
|
|
|
e97c83 |
+ newbootorder = AllocateZeroPool(size);
|
|
|
e97c83 |
+ if (!newbootorder)
|
|
|
e97c83 |
+ return EFI_OUT_OF_RESOURCES;
|
|
|
e97c83 |
+ CopyMem(newbootorder, bootorder, size);
|
|
|
e97c83 |
|
|
|
e97c83 |
#ifdef DEBUG_FALLBACK
|
|
|
e97c83 |
Print(L"nbootorder: %d\nBootOrder: ", size / sizeof (CHAR16));
|
|
|
e97c83 |
@@ -337,13 +326,11 @@ update_boot_order(void)
|
|
|
e97c83 |
Print(L"%04x ", newbootorder[j]);
|
|
|
e97c83 |
Print(L"\n");
|
|
|
e97c83 |
#endif
|
|
|
e97c83 |
-
|
|
|
e97c83 |
- if (oldbootorder) {
|
|
|
e97c83 |
+ rc = uefi_call_wrapper(RT->GetVariable, 5, L"BootOrder", &global,
|
|
|
e97c83 |
+ NULL, &len, NULL);
|
|
|
e97c83 |
+ if (rc == EFI_BUFFER_TOO_SMALL)
|
|
|
e97c83 |
LibDeleteVariable(L"BootOrder", &global);
|
|
|
e97c83 |
- FreePool(oldbootorder);
|
|
|
e97c83 |
- }
|
|
|
e97c83 |
|
|
|
e97c83 |
- EFI_STATUS rc;
|
|
|
e97c83 |
rc = uefi_call_wrapper(RT->SetVariable, 5, L"BootOrder", &global,
|
|
|
e97c83 |
EFI_VARIABLE_NON_VOLATILE |
|
|
|
e97c83 |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
e97c83 |
--
|
|
|
e97c83 |
1.9.3
|
|
|
e97c83 |
|