MdeModulePkg: DeleteLoadOptionVariable() removes Boot####

Change EfiBootManagerDeleteLoadOptionVariable() to not just
remove #### from BootOrder but also remove Boot#### variable.

The old behavior tries to do less for performance but it leaves
unreferenced Boot#### which cannot be reclaimed in variable
reclaim operation though the Boot#### will be eventually be overwritten
by EfiBootManagerAddLoadOptionVariable().

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19626 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ruiyu Ni 2016-01-08 07:16:22 +00:00 committed by niruiyu
parent 20fe162556
commit 2e26862c6d

View File

@ -1,7 +1,7 @@
/** @file /** @file
Load option library functions which relate with creating and processing load options. Load option library functions which relate with creating and processing load options.
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -564,7 +564,6 @@ EfiBootManagerDeleteLoadOptionVariable (
{ {
UINT16 *OptionOrder; UINT16 *OptionOrder;
UINTN OptionOrderSize; UINTN OptionOrderSize;
EFI_STATUS Status;
UINTN Index; UINTN Index;
CHAR16 OptionName[BM_OPTION_NAME_LEN]; CHAR16 OptionName[BM_OPTION_NAME_LEN];
@ -572,11 +571,10 @@ EfiBootManagerDeleteLoadOptionVariable (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = EFI_NOT_FOUND;
if (OptionType == LoadOptionTypeDriver || OptionType == LoadOptionTypeSysPrep || OptionType == LoadOptionTypeBoot) { if (OptionType == LoadOptionTypeDriver || OptionType == LoadOptionTypeSysPrep || OptionType == LoadOptionTypeBoot) {
// //
// If the associated *Order exists, just remove the reference in *Order. // If the associated *Order exists, firstly remove the reference in *Order for
// Driver####, SysPrep#### and Boot####.
// //
GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **) &OptionOrder, &OptionOrderSize); GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **) &OptionOrder, &OptionOrderSize);
ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0)); ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0));
@ -585,7 +583,7 @@ EfiBootManagerDeleteLoadOptionVariable (
if (OptionOrder[Index] == OptionNumber) { if (OptionOrder[Index] == OptionNumber) {
OptionOrderSize -= sizeof (UINT16); OptionOrderSize -= sizeof (UINT16);
CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16)); CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16));
Status = gRT->SetVariable ( gRT->SetVariable (
mBmLoadOptionOrderName[OptionType], mBmLoadOptionOrderName[OptionType],
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
@ -598,21 +596,19 @@ EfiBootManagerDeleteLoadOptionVariable (
if (OptionOrder != NULL) { if (OptionOrder != NULL) {
FreePool (OptionOrder); FreePool (OptionOrder);
} }
} else if (OptionType == LoadOptionTypePlatformRecovery) { }
// //
// PlatformRecovery#### doesn't have assiciated PlatformRecoveryOrder, remove the PlatformRecovery#### itself. // Remove the Driver####, SysPrep####, Boot#### or PlatformRecovery#### itself.
// //
UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber); UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber);
Status = gRT->SetVariable ( return gRT->SetVariable (
OptionName, OptionName,
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
0, 0,
0, 0,
NULL NULL
); );
}
return Status;
} }
/** /**