Commit ec7eddbf authored by Gary Ching-Pang Lin's avatar Gary Ching-Pang Lin Committed by Peter Jones

[fallback] Avoid duplicate old BootOrder

set_boot_order() already copies the old BootOrder to the variable,
bootorder. Besides, we can adjust BootOrder when adding the newly
generated boot option. So, we don't have to copy the old one again
in update_boot_order(). This avoid the duplicate entries in BootOrder.
Signed-off-by: default avatarGary Ching-Pang Lin <glin@suse.com>
parent a63d665f
......@@ -204,12 +204,12 @@ add_boot_option(EFI_DEVICE_PATH *hddp, EFI_DEVICE_PATH *fulldp,
return EFI_OUT_OF_RESOURCES;
int j = 0;
newbootorder[0] = i & 0xffff;
if (nbootorder) {
for (j = 0; j < nbootorder; j++)
newbootorder[j] = bootorder[j];
newbootorder[j+1] = bootorder[j];
FreePool(bootorder);
}
newbootorder[j] = i & 0xffff;
bootorder = newbootorder;
nbootorder += 1;
#ifdef DEBUG_FALLBACK
......@@ -307,28 +307,17 @@ set_boot_order(void)
EFI_STATUS
update_boot_order(void)
{
CHAR16 *oldbootorder;
UINTN size;
UINTN len = 0;
EFI_GUID global = EFI_GLOBAL_VARIABLE;
CHAR16 *newbootorder = NULL;
EFI_STATUS rc;
oldbootorder = LibGetVariableAndSize(L"BootOrder", &global, &size);
if (oldbootorder) {
int n = size / sizeof (CHAR16) + nbootorder;
newbootorder = AllocateZeroPool(n * sizeof (CHAR16));
if (!newbootorder)
return EFI_OUT_OF_RESOURCES;
CopyMem(newbootorder, bootorder, nbootorder * sizeof (CHAR16));
CopyMem(newbootorder + nbootorder, oldbootorder, size);
size = n * sizeof (CHAR16);
} else {
size = nbootorder * sizeof(CHAR16);
newbootorder = AllocateZeroPool(size);
if (!newbootorder)
return EFI_OUT_OF_RESOURCES;
CopyMem(newbootorder, bootorder, size);
}
size = nbootorder * sizeof(CHAR16);
newbootorder = AllocateZeroPool(size);
if (!newbootorder)
return EFI_OUT_OF_RESOURCES;
CopyMem(newbootorder, bootorder, size);
#ifdef DEBUG_FALLBACK
Print(L"nbootorder: %d\nBootOrder: ", size / sizeof (CHAR16));
......@@ -337,13 +326,11 @@ update_boot_order(void)
Print(L"%04x ", newbootorder[j]);
Print(L"\n");
#endif
if (oldbootorder) {
rc = uefi_call_wrapper(RT->GetVariable, 5, L"BootOrder", &global,
NULL, &len, NULL);
if (rc == EFI_BUFFER_TOO_SMALL)
LibDeleteVariable(L"BootOrder", &global);
FreePool(oldbootorder);
}
EFI_STATUS rc;
rc = uefi_call_wrapper(RT->SetVariable, 5, L"BootOrder", &global,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment