X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=IntelFrameworkModulePkg%2FUniversal%2FBdsDxe%2FBootMaint%2FBBSsupport.c;h=f9ba0a7bc78320037caa010e3490249085f77ed2;hb=0a6f48249a601f88af124ae1ff6814b195b699c3;hp=db0fed5834d512b415784f86e537d6f745ef131c;hpb=2d1f3dd497f343bc54b4a164d4e9f015ae04f7dc;p=mirror_edk2.git
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
index db0fed5834..f9ba0a7bc7 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
@@ -3,7 +3,7 @@
and manage the legacy boot option, all legacy boot option is getting from
the legacy BBS table.
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -53,9 +53,9 @@ OrderLegacyBootOption4SameType (
UINTN BootOrderSize;
UINTN Index;
UINTN StartPosition;
-
+
BDS_COMMON_OPTION *BootOption;
-
+
CHAR16 OptionName[sizeof ("Boot####")];
UINT16 *BbsIndexArray;
UINT16 *DeviceTypeArray;
@@ -82,12 +82,12 @@ OrderLegacyBootOption4SameType (
ASSERT (*DisBootOption != NULL);
for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
-
+
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);
InitializeListHead (&List);
BootOption = BdsLibVariableToOption (&List, OptionName);
ASSERT (BootOption != NULL);
-
+
if ((DevicePathType (BootOption->DevicePath) == BBS_DEVICE_PATH) &&
(DevicePathSubType (BootOption->DevicePath) == BBS_BBS_DP)) {
//
@@ -119,7 +119,7 @@ OrderLegacyBootOption4SameType (
if (BbsIndexArray[Index] == (DevOrder[DevOrderCount] & 0xFF)) {
StartPosition = MIN (StartPosition, Index);
NewBootOption[DevOrderCount] = BootOrder[Index];
-
+
if ((DevOrder[DevOrderCount] & 0xFF00) == 0xFF00) {
(*DisBootOption)[*DisBootOptionCount] = BootOrder[Index];
(*DisBootOptionCount)++;
@@ -143,17 +143,21 @@ OrderLegacyBootOption4SameType (
BootOrderSize,
BootOrder
);
+ //
+ // Changing content without increasing its size with current variable implementation shouldn't fail.
+ //
ASSERT_EFI_ERROR (Status);
FreePool (NewBootOption);
FreePool (DeviceTypeArray);
FreePool (BbsIndexArray);
+ FreePool (BootOrder);
}
/**
Group the legacy boot options in the BootOption.
- The routine assumes the boot options in the beginning that covers all the device
+ The routine assumes the boot options in the beginning that covers all the device
types are ordered properly and re-position the following boot options just after
the corresponding boot options with the same device type.
For example:
@@ -171,6 +175,7 @@ GroupMultipleLegacyBootOption4SameType (
VOID
)
{
+ EFI_STATUS Status;
UINTN Index;
UINTN DeviceIndex;
UINTN DeviceTypeIndex[7];
@@ -201,7 +206,7 @@ GroupMultipleLegacyBootOption4SameType (
//
// Legacy Boot Option
//
- ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]));
+ ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF) < ARRAY_SIZE (DeviceTypeIndex));
NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF];
if (*NextIndex == (UINTN) -1) {
@@ -220,7 +225,7 @@ GroupMultipleLegacyBootOption4SameType (
//
// Update the DeviceTypeIndex array to reflect the right shift operation
//
- for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) {
+ for (DeviceIndex = 0; DeviceIndex < ARRAY_SIZE (DeviceTypeIndex); DeviceIndex++) {
if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {
DeviceTypeIndex[DeviceIndex]++;
}
@@ -233,13 +238,17 @@ GroupMultipleLegacyBootOption4SameType (
FreePool (BootOption);
}
- gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- BootOrderSize,
- BootOrder
- );
+ Status = gRT->SetVariable (
+ L"BootOrder",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ BootOrderSize,
+ BootOrder
+ );
+ //
+ // Changing content without increasing its size with current variable implementation shouldn't fail.
+ //
+ ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
}