Align the overrider with UDK2014.SP1 core.

The override fixed Showing IPv4 and IPv6 string format as 

"EFI Network <MAC Address><IP version>" in Boot Manager Group under BIOS setup.

This override will be removed after core fixing. 

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Shifei Lu <shifeix.a.lu@intel.com>
Reviewed-by: Tim He <tim.he@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16675 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Shifei Lu 2015-01-28 08:24:57 +00:00 committed by timhe
parent 14030c5c85
commit 217abb4659
7 changed files with 448 additions and 111 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
BDS Lib functions which relate with create or process the boot option. BDS Lib functions which relate with create or process the boot option.
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "InternalBdsLib.h" #include "InternalBdsLib.h"
#include "String.h" #include "String.h"
#include <Library/NetLib.h>
#include "Library/DebugLib.h"
BOOLEAN mEnumBootDevice = FALSE; BOOLEAN mEnumBootDevice = FALSE;
EFI_HII_HANDLE gBdsLibStringPackHandle = NULL; EFI_HII_HANDLE gBdsLibStringPackHandle = NULL;
@ -82,6 +84,10 @@ BdsDeleteBootOption (
0, 0,
NULL NULL
); );
//
// Deleting variable with existing variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
// //
// adjust boot order array // adjust boot order array
@ -517,6 +523,15 @@ BdsDeleteAllInvalidLegacyBootOptions (
return Status; return Status;
} }
BootOrder = BdsLibGetVariableAndSize (
L"BootOrder",
&gEfiGlobalVariableGuid,
&BootOrderSize
);
if (BootOrder == NULL) {
return EFI_NOT_FOUND;
}
LegacyBios->GetBbsInfo ( LegacyBios->GetBbsInfo (
LegacyBios, LegacyBios,
&HddCount, &HddCount,
@ -525,15 +540,6 @@ BdsDeleteAllInvalidLegacyBootOptions (
&LocalBbsTable &LocalBbsTable
); );
BootOrder = BdsLibGetVariableAndSize (
L"BootOrder",
&gEfiGlobalVariableGuid,
&BootOrderSize
);
if (BootOrder == NULL) {
BootOrderSize = 0;
}
Index = 0; Index = 0;
while (Index < BootOrderSize / sizeof (UINT16)) { while (Index < BootOrderSize / sizeof (UINT16)) {
UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]); UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
@ -626,9 +632,11 @@ BdsDeleteAllInvalidLegacyBootOptions (
BootOrderSize, BootOrderSize,
BootOrder BootOrder
); );
if (BootOrder != NULL) { //
FreePool (BootOrder); // Shrinking variable with existing variable implementation shouldn't fail.
} //
ASSERT_EFI_ERROR (Status);
FreePool (BootOrder);
return Status; return Status;
} }
@ -857,11 +865,11 @@ BdsAddNonExistingLegacyBootOptions (
&BootOrder, &BootOrder,
&BootOrderSize &BootOrderSize
); );
if (EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
break; ASSERT (BootOrder != NULL);
BbsIndex = Index;
OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
} }
BbsIndex = Index;
OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
} }
ASSERT (BbsIndex == Index); ASSERT (BbsIndex == Index);
@ -1036,7 +1044,7 @@ BdsCreateDevOrder (
Status = gRT->SetVariable ( Status = gRT->SetVariable (
VAR_LEGACY_DEV_ORDER, VAR_LEGACY_DEV_ORDER,
&gEfiLegacyDevOrderVariableGuid, &gEfiLegacyDevOrderVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
TotalSize, TotalSize,
DevOrder DevOrder
); );
@ -1357,7 +1365,7 @@ BdsUpdateLegacyDevOrder (
Status = gRT->SetVariable ( Status = gRT->SetVariable (
VAR_LEGACY_DEV_ORDER, VAR_LEGACY_DEV_ORDER,
&gEfiLegacyDevOrderVariableGuid, &gEfiLegacyDevOrderVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
TotalSize, TotalSize,
NewDevOrder NewDevOrder
); );
@ -1407,7 +1415,7 @@ BdsSetBootPriority4SameTypeDev (
break; break;
} }
DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) ((UINT8 *) DevOrderPtr + sizeof (BBS_TYPE) + DevOrderPtr->Length); DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) ((UINTN) DevOrderPtr + sizeof (BBS_TYPE) + DevOrderPtr->Length);
} }
if ((UINT8 *) DevOrderPtr >= (UINT8 *) DevOrder + DevOrderSize) { if ((UINT8 *) DevOrderPtr >= (UINT8 *) DevOrder + DevOrderSize) {
@ -1636,6 +1644,8 @@ BdsRefreshBbsTableForBoot (
} }
} }
FreePool (DeviceType);
if (BootOrder != NULL) { if (BootOrder != NULL) {
FreePool (BootOrder); FreePool (BootOrder);
} }
@ -2265,7 +2275,7 @@ BdsLibBootViaBootOption (
// In this case, "BootCurrent" is not created. // In this case, "BootCurrent" is not created.
// Only create the BootCurrent variable when it points to a valid Boot#### variable. // Only create the BootCurrent variable when it points to a valid Boot#### variable.
// //
gRT->SetVariable ( SetVariableAndReportStatusCodeOnError (
L"BootCurrent", L"BootCurrent",
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@ -2463,13 +2473,14 @@ Done:
// //
// Clear Boot Current // Clear Boot Current
// Deleting variable with current implementation shouldn't fail.
// //
gRT->SetVariable ( gRT->SetVariable (
L"BootCurrent", L"BootCurrent",
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0, 0,
&Option->BootCurrent NULL
); );
return Status; return Status;
@ -2518,11 +2529,28 @@ BdsExpandPartitionPartialDevicePathToFull (
// If exist, search the front path which point to partition node in the variable instants. // If exist, search the front path which point to partition node in the variable instants.
// If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system
// //
CachedDevicePath = BdsLibGetVariableAndSize ( GetVariable2 (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME, HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
&gHdBootDevicePathVariablGuid, &gHdBootDevicePathVariablGuid,
&CachedDevicePathSize (VOID **) &CachedDevicePath,
); &CachedDevicePathSize
);
//
// Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.
//
if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {
FreePool (CachedDevicePath);
CachedDevicePath = NULL;
Status = gRT->SetVariable (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
&gHdBootDevicePathVariablGuid,
0,
0,
NULL
);
ASSERT_EFI_ERROR (Status);
}
if (CachedDevicePath != NULL) { if (CachedDevicePath != NULL) {
TempNewDevicePath = CachedDevicePath; TempNewDevicePath = CachedDevicePath;
@ -2580,11 +2608,12 @@ BdsExpandPartitionPartialDevicePathToFull (
FreePool (TempNewDevicePath); FreePool (TempNewDevicePath);
// //
// Save the matching Device Path so we don't need to do a connect all next time // Save the matching Device Path so we don't need to do a connect all next time
// Failure to set the variable only impacts the performance when next time expanding the short-form device path.
// //
Status = gRT->SetVariable ( Status = gRT->SetVariable (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME, HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
&gHdBootDevicePathVariablGuid, &gHdBootDevicePathVariablGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
GetDevicePathSize (CachedDevicePath), GetDevicePathSize (CachedDevicePath),
CachedDevicePath CachedDevicePath
); );
@ -2678,11 +2707,12 @@ BdsExpandPartitionPartialDevicePathToFull (
// //
// Save the matching Device Path so we don't need to do a connect all next time // Save the matching Device Path so we don't need to do a connect all next time
// Failure to set the variable only impacts the performance when next time expanding the short-form device path.
// //
Status = gRT->SetVariable ( Status = gRT->SetVariable (
HD_BOOT_DEVICE_PATH_VARIABLE_NAME, HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
&gHdBootDevicePathVariablGuid, &gHdBootDevicePathVariablGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
GetDevicePathSize (CachedDevicePath), GetDevicePathSize (CachedDevicePath),
CachedDevicePath CachedDevicePath
); );
@ -2887,6 +2917,10 @@ BdsLibDeleteOptionFromHandle (
BootOrderSize, BootOrderSize,
BootOrder BootOrder
); );
//
// Shrinking variable with existing variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
FreePool (BootOrder); FreePool (BootOrder);
@ -2985,6 +3019,10 @@ BdsDeleteAllInvalidEfiBootOption (
NULL NULL
); );
// //
// Deleting variable with current variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
//
// Mark this boot option in boot order as deleted // Mark this boot option in boot order as deleted
// //
BootOrder[Index] = 0xffff; BootOrder[Index] = 0xffff;
@ -3012,6 +3050,10 @@ BdsDeleteAllInvalidEfiBootOption (
Index2 * sizeof (UINT16), Index2 * sizeof (UINT16),
BootOrder BootOrder
); );
//
// Shrinking variable with current variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
FreePool (BootOrder); FreePool (BootOrder);
@ -3103,6 +3145,10 @@ BdsLibEnumerateAllBootOption (
CHAR8 *LastLang; CHAR8 *LastLang;
EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
CHAR16 *MacStr;
CHAR16 *IPverStr;
EFI_HANDLE *NetworkHandles;
UINTN BufferSize;
FloppyNumber = 0; FloppyNumber = 0;
HarddriveNumber = 0; HarddriveNumber = 0;
@ -3135,7 +3181,9 @@ BdsLibEnumerateAllBootOption (
AsciiStrSize (PlatLang), AsciiStrSize (PlatLang),
PlatLang PlatLang
); );
ASSERT_EFI_ERROR (Status); //
// Failure to set the variable only impacts the performance next time enumerating the boot options.
//
if (LastLang != NULL) { if (LastLang != NULL) {
FreePool (LastLang); FreePool (LastLang);
@ -3180,9 +3228,16 @@ BdsLibEnumerateAllBootOption (
(VOID **) &BlkIo (VOID **) &BlkIo
); );
// //
// skip the fixed block io then the removable block io // skip the logical partition
// //
if (EFI_ERROR (Status) || (BlkIo->Media->RemovableMedia == Removable[RemovableIndex])) { if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {
continue;
}
//
// firstly fixed block io then the removable block io
//
if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {
continue; continue;
} }
DevicePath = DevicePathFromHandle (BlockIoHandles[Index]); DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);
@ -3244,6 +3299,7 @@ BdsLibEnumerateAllBootOption (
break; break;
case BDS_EFI_MESSAGE_MISC_BOOT: case BDS_EFI_MESSAGE_MISC_BOOT:
default:
if (MiscNumber != 0) { if (MiscNumber != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber); UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
} else { } else {
@ -3252,9 +3308,6 @@ BdsLibEnumerateAllBootOption (
BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer); BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
MiscNumber++; MiscNumber++;
break; break;
default:
break;
} }
} }
} }
@ -3341,11 +3394,113 @@ BdsLibEnumerateAllBootOption (
); );
for (Index = 0; Index < NumOfLoadFileHandles; Index++) { for (Index = 0; Index < NumOfLoadFileHandles; Index++) {
if (Index != 0) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)), 6); //
} else { //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)), 4); //
Status = gBS->HandleProtocol (
LoadFileHandles[Index],
&gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath
);
ASSERT_EFI_ERROR (Status);
while (!IsDevicePathEnd (DevicePath)) {
if ((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
(DevicePath->SubType == MSG_IPv4_DP)) {
//
//Get handle infomation
//
BufferSize = 0;
NetworkHandles = NULL;
Status = gBS->LocateHandle (
ByProtocol,
&gEfiSimpleNetworkProtocolGuid,
NULL,
&BufferSize,
NetworkHandles
);
if (Status == EFI_BUFFER_TOO_SMALL) {
NetworkHandles = AllocateZeroPool(BufferSize);
if (NetworkHandles == NULL) {
return (EFI_OUT_OF_RESOURCES);
} }
Status = gBS->LocateHandle(
ByProtocol,
&gEfiSimpleNetworkProtocolGuid,
NULL,
&BufferSize,
NetworkHandles
);
}
//
//Get the MAC string
//
Status = NetLibGetMacString (
*NetworkHandles,
NULL,
&MacStr
);
if (EFI_ERROR (Status)) {
return Status;
}
IPverStr = L" IPv4";
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
break;
}
if((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
(DevicePath->SubType == MSG_IPv6_DP)) {
//
//Get handle infomation
//
BufferSize = 0;
NetworkHandles = NULL;
Status = gBS->LocateHandle (
ByProtocol,
&gEfiSimpleNetworkProtocolGuid,
NULL,
&BufferSize,
NetworkHandles
);
if (Status == EFI_BUFFER_TOO_SMALL) {
NetworkHandles = AllocateZeroPool(BufferSize);
if (NetworkHandles == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
Status = gBS->LocateHandle(
ByProtocol,
&gEfiSimpleNetworkProtocolGuid,
NULL,
&BufferSize,
NetworkHandles
);
}
//
//Get the MAC string
//
Status = NetLibGetMacString (
*NetworkHandles,
NULL,
&MacStr
);
if (EFI_ERROR (Status)) {
return Status;
}
IPverStr = L" IPv6";
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
break;
}
DevicePath = NextDevicePathNode (DevicePath);
}
BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer); BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);
} }
@ -3478,6 +3633,7 @@ BdsLibBootNext (
VOID VOID
) )
{ {
EFI_STATUS Status;
UINT16 *BootNext; UINT16 *BootNext;
UINTN BootNextSize; UINTN BootNextSize;
CHAR16 Buffer[20]; CHAR16 Buffer[20];
@ -3502,13 +3658,17 @@ BdsLibBootNext (
// Clear the boot next variable first // Clear the boot next variable first
// //
if (BootNext != NULL) { if (BootNext != NULL) {
gRT->SetVariable ( Status = gRT->SetVariable (
L"BootNext", L"BootNext",
&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,
0, 0,
BootNext NULL
); );
//
// Deleting variable with current variable implementation shouldn't fail.
//
ASSERT_EFI_ERROR (Status);
// //
// Start to build the boot option and try to boot // Start to build the boot option and try to boot
@ -3518,6 +3678,8 @@ BdsLibBootNext (
ASSERT (BootOption != NULL); ASSERT (BootOption != NULL);
BdsLibConnectDevicePath (BootOption->DevicePath); BdsLibConnectDevicePath (BootOption->DevicePath);
BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData); BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
FreePool(BootOption);
FreePool(BootNext);
} }
} }
@ -4303,6 +4465,7 @@ BdsLibUpdateFvFileDevicePath (
NewDevicePath = DevicePathFromHandle (FoundFvHandle); NewDevicePath = DevicePathFromHandle (FoundFvHandle);
EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid); EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode); NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
ASSERT (NewDevicePath != NULL);
*DevicePath = NewDevicePath; *DevicePath = NewDevicePath;
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
BDS Lib functions which contain all the code to connect console device BDS Lib functions which contain all the code to connect console device
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -65,9 +65,9 @@ IsNvNeed (
@param VarName The name of the EFI console variable. @param VarName The name of the EFI console variable.
@param ConsoleGuid Specified Console protocol GUID. @param ConsoleGuid Specified Console protocol GUID.
@param ConsoleHandle On IN, console handle in System Table to be checked. @param ConsoleHandle On IN, console handle in System Table to be checked.
On OUT, new console hanlde in system table. On OUT, new console handle in system table.
@param ProtocolInterface On IN, console protocol on console handle in System Table to be checked. @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked.
On OUT, new console protocol on new console hanlde in system table. On OUT, new console protocol on new console handle in system table.
@retval TRUE System Table has been updated. @retval TRUE System Table has been updated.
@retval FALSE System Table hasn't been updated. @retval FALSE System Table hasn't been updated.
@ -285,17 +285,16 @@ BdsLibUpdateConsoleVariable (
// Finally, Update the variable of the default console by NewDevicePath // Finally, Update the variable of the default console by NewDevicePath
// //
DevicePathSize = GetDevicePathSize (NewDevicePath); DevicePathSize = GetDevicePathSize (NewDevicePath);
Status = gRT->SetVariable ( Status = SetVariableAndReportStatusCodeOnError (
ConVarName, ConVarName,
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
Attributes, Attributes,
DevicePathSize, DevicePathSize,
NewDevicePath NewDevicePath
); );
if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) { if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
ASSERT_EFI_ERROR (Status);
if (VarConsole == NewDevicePath) { if (VarConsole == NewDevicePath) {
if (VarConsole != NULL) { if (VarConsole != NULL) {

View File

@ -1,7 +1,7 @@
/** @file /** @file
Misc BDS library function Misc BDS library function
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -168,6 +168,7 @@ BdsLibGetFreeOptionNumber (
if (OptionBuffer == NULL) { if (OptionBuffer == NULL) {
break; break;
} }
FreePool(OptionBuffer);
Index++; Index++;
} while (TRUE); } while (TRUE);
@ -217,6 +218,9 @@ BdsLibRegisterNewOption (
UINT16 BootOrderEntry; UINT16 BootOrderEntry;
UINTN OrderItemNum; UINTN OrderItemNum;
if (DevicePath == NULL) {
return EFI_INVALID_PARAMETER;
}
OptionPtr = NULL; OptionPtr = NULL;
OptionSize = 0; OptionSize = 0;
@ -262,6 +266,7 @@ BdsLibRegisterNewOption (
// Validate the variable. // Validate the variable.
// //
if (!ValidateOption(OptionPtr, OptionSize)) { if (!ValidateOption(OptionPtr, OptionSize)) {
FreePool(OptionPtr);
continue; continue;
} }
@ -623,6 +628,7 @@ BdsLibVariableToOption (
// Validate Boot#### variable data. // Validate Boot#### variable data.
// //
if (!ValidateOption(Variable, VariableSize)) { if (!ValidateOption(Variable, VariableSize)) {
FreePool (Variable);
return NULL; return NULL;
} }
@ -671,6 +677,7 @@ BdsLibVariableToOption (
// //
Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION)); Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
if (Option == NULL) { if (Option == NULL) {
FreePool (Variable);
return NULL; return NULL;
} }
@ -1419,22 +1426,26 @@ BdsSetMemoryTypeInformationVariable (
// Or create the variable in first boot. // Or create the variable in first boot.
// //
if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) { if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
Status = gRT->SetVariable ( Status = SetVariableAndReportStatusCodeOnError (
EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME, EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
&gEfiMemoryTypeInformationGuid, &gEfiMemoryTypeInformationGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
VariableSize, VariableSize,
PreviousMemoryTypeInformation PreviousMemoryTypeInformation
); );
// if (!EFI_ERROR (Status)) {
// If the Memory Type Information settings have been modified, then reset the platform //
// so the new Memory Type Information setting will be used to guarantee that an S4 // If the Memory Type Information settings have been modified, then reset the platform
// entry/resume cycle will not fail. // so the new Memory Type Information setting will be used to guarantee that an S4
// // entry/resume cycle will not fail.
if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) { //
DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n")); if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
}
} else {
DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. OS S4 may fail!\n"));
} }
} }
} }
@ -1482,3 +1493,89 @@ BdsLibUserIdentify (
return Manager->Identify (Manager, User); return Manager->Identify (Manager, User);
} }
/**
Set the variable and report the error through status code upon failure.
@param VariableName A Null-terminated string that is the name of the vendor's variable.
Each VariableName is unique for each VendorGuid. VariableName must
contain 1 or more characters. If VariableName is an empty string,
then EFI_INVALID_PARAMETER is returned.
@param VendorGuid A unique identifier for the vendor.
@param Attributes Attributes bitmask to set for the variable.
@param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
set, then a SetVariable() call with a DataSize of zero will not cause any change to
the variable value (the timestamp associated with the variable may be updated however
even if no new data value is provided,see the description of the
EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
@param Data The contents for the variable.
@retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
defined by the Attributes.
@retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
DataSize exceeds the maximum allowed.
@retval EFI_INVALID_PARAMETER VariableName is an empty string.
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
@retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
@retval EFI_WRITE_PROTECTED The variable in question is read-only.
@retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
@retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
does NOT pass the validation check carried out by the firmware.
@retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
**/
EFI_STATUS
SetVariableAndReportStatusCodeOnError (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
{
EFI_STATUS Status;
EDKII_SET_VARIABLE_STATUS *SetVariableStatus;
UINTN NameSize;
Status = gRT->SetVariable (
VariableName,
VendorGuid,
Attributes,
DataSize,
Data
);
if (EFI_ERROR (Status)) {
NameSize = StrSize (VariableName);
SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);
if (SetVariableStatus != NULL) {
CopyGuid (&SetVariableStatus->Guid, VendorGuid);
SetVariableStatus->NameSize = NameSize;
SetVariableStatus->DataSize = DataSize;
SetVariableStatus->SetStatus = Status;
SetVariableStatus->Attributes = Attributes;
CopyMem (SetVariableStatus + 1, VariableName, NameSize);
if ((Data != NULL) && (DataSize != 0)) {
CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data, DataSize);
}
REPORT_STATUS_CODE_EX (
EFI_ERROR_CODE,
PcdGet32 (PcdErrorCodeSetVariable),
0,
NULL,
&gEdkiiStatusCodeDataTypeVariableGuid,
SetVariableStatus,
sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
);
FreePool (SetVariableStatus);
}
}
return Status;
}

View File

@ -1,11 +1,12 @@
## @file ## @file
# General BDS library.
# #
# General BDS defines and produce general interfaces for platform BDS driver including: # General BDS defines and produce general interfaces for platform BDS driver including:
# 1) BDS boot policy interface; # 1) BDS boot policy interface;
# 2) BDS boot device connect interface; # 2) BDS boot device connect interface;
# 3) BDS Misc interfaces for mainting boot variable, ouput string, etc. # 3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
# #
# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<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
# which accompanies this distribution. The full text of the license may be found at # which accompanies this distribution. The full text of the license may be found at
@ -19,6 +20,7 @@
[Defines] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = GenericBdsLib BASE_NAME = GenericBdsLib
MODULE_UNI_FILE = GenericBdsLib.uni
FILE_GUID = e405ec31-ccaa-4dd4-83e8-0aec01703f7e FILE_GUID = e405ec31-ccaa-4dd4-83e8-0aec01703f7e
MODULE_TYPE = DXE_DRIVER MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
@ -68,47 +70,78 @@
DxeServicesLib DxeServicesLib
HiiLib HiiLib
ReportStatusCodeLib ReportStatusCodeLib
NetLib
[Guids] [Guids]
gEfiMemoryTypeInformationGuid ## CONSUMES ## GUID (The identifier of memory type information type in system table) ## SOMETIMES_CONSUMES ## HOB # The hob holding memory type information
gEfiGlobalVariableGuid ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" (The boot option of current boot) ## SOMETIMES_CONSUMES ## SystemTable # The identifier of memory type information type in system table
gEfiFileInfoGuid ## CONSUMES ## GUID ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"
gPerformanceProtocolGuid ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" (The ACPI address of performance data) ## SOMETIMES_PRODUCES ## Variable:L"MemoryTypeInformation"
gEfiUartDevicePathGuid ## CONSUMES ## GUID (Identify the device path for UARD device) gEfiMemoryTypeInformationGuid
gLastEnumLangGuid ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" (Platform language at last time enumeration.) ## SOMETIMES_CONSUMES ## Variable:L"BootXXXX" # Boot option variable
gHdBootDevicePathVariablGuid ## SOMETIMES_PRODUCES ## Variable:L"HDDP" (The device path of Boot file on Hard device.) ## SOMETIMES_PRODUCES ## Variable:L"BootXXXX" # Boot option variable
gBdsLibStringPackageGuid ## PRODUCES ## GUID (HII String PackageList Guid) ## SOMETIMES_CONSUMES ## Variable:L"DriverXXXX" # Driver load option.
gEfiLegacyDevOrderVariableGuid ## CONSUMES ## GUID ## SOMETIMES_PRODUCES ## Variable:L"DriverXXXX" # Driver load option.
## SOMETIMES_CONSUMES ## Variable:L"BootNext" # Next Boot Option
## SOMETIMES_PRODUCES ## Variable:L"BootNext" # Next Boot Option
## SOMETIMES_CONSUMES ## Variable:L"BootOrder" # The boot option array
## SOMETIMES_PRODUCES ## Variable:L"BootOrder" # The boot option array
## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" # The driver order list
## SOMETIMES_CONSUMES ## Variable:L"ConIn" # The device path of console in device
## SOMETIMES_PRODUCES ## Variable:L"ConIn" # The device path of console in device
## SOMETIMES_CONSUMES ## Variable:L"ConOut" # The device path of console out device
## SOMETIMES_PRODUCES ## Variable:L"ConOut" # The device path of console out device
## SOMETIMES_CONSUMES ## Variable:L"ErrOut" # The device path of error out device
## SOMETIMES_PRODUCES ## Variable:L"ErrOut" # The device path of error out device
## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" # The boot option of current boot
## SOMETIMES_PRODUCES ## Variable:L"BootNext" # The number of next boot option
gEfiGlobalVariableGuid
gEfiFileInfoGuid ## SOMETIMES_CONSUMES ## GUID
gPerformanceProtocolGuid ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" # The ACPI address of performance data
gLastEnumLangGuid ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" # Platform language at last time enumeration.
gHdBootDevicePathVariablGuid ## SOMETIMES_PRODUCES ## Variable:L"HDDP" # The device path of Boot file on Hard device.
gBdsLibStringPackageGuid ## CONSUMES ## HII # HII String PackageList Guid
## SOMETIMES_PRODUCES ## Variable:L"LegacyDevOrder"
## SOMETIMES_CONSUMES ## Variable:L"LegacyDevOrder"
gEfiLegacyDevOrderVariableGuid
gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES ## GUID
[Protocols] [Protocols]
gEfiSimpleFileSystemProtocolGuid # PROTOCOL CONSUMES gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES
gEfiLoadFileProtocolGuid # PROTOCOL CONSUMES gEfiLoadFileProtocolGuid ## SOMETIMES_CONSUMES
gEfiSimpleTextOutProtocolGuid # PROTOCOL CONSUMES gEfiSimpleTextOutProtocolGuid ## CONSUMES
gEfiPciIoProtocolGuid # PROTOCOL CONSUMES gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiLoadedImageProtocolGuid # PROTOCOL CONSUMES gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES
gEfiSimpleNetworkProtocolGuid # PROTOCOL CONSUMES gEfiSimpleNetworkProtocolGuid ## SOMETIMES_CONSUMES
gEfiDebugPortProtocolGuid # PROTOCOL CONSUMES gEfiDebugPortProtocolGuid ## SOMETIMES_CONSUMES
gEfiSimpleTextInProtocolGuid # PROTOCOL CONSUMES gEfiSimpleTextInProtocolGuid ## CONSUMES
gEfiBlockIoProtocolGuid # PROTOCOL CONSUMES gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiFirmwareVolume2ProtocolGuid # PROTOCOL CONSUMES gEfiFirmwareVolume2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiLegacyBiosProtocolGuid # PROTOCOL SOMETIMES_CONSUMES gEfiLegacyBiosProtocolGuid ## SOMETIMES_CONSUMES
gEfiCpuArchProtocolGuid # PROTOCOL CONSUMES gEfiCpuArchProtocolGuid ## CONSUMES
gEfiDevicePathProtocolGuid # PROTOCOL CONSUMES gEfiDevicePathProtocolGuid ## CONSUMES
gEfiAcpiS3SaveProtocolGuid # PROTOCOL CONSUMES gEfiAcpiS3SaveProtocolGuid ## SOMETIMES_CONSUMES
gEfiGraphicsOutputProtocolGuid # PROTOCOL SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES
gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport # PROTOCOL SOMETIMES_CONSUMES gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## SOMETIMES_CONSUMES
gEfiOEMBadgingProtocolGuid # PROTOCOL CONSUMES gEfiOEMBadgingProtocolGuid ## SOMETIMES_CONSUMES
gEfiHiiFontProtocolGuid # PROTOCOL CONSUMES gEfiHiiFontProtocolGuid ## CONSUMES
gEfiUserManagerProtocolGuid # PROTOCOL CONSUMES gEfiUserManagerProtocolGuid ## SOMETIMES_CONSUMES
gEfiUsbIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMES gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiBootLogoProtocolGuid # PROTOCOL SOMETIMES_CONSUMES gEfiBootLogoProtocolGuid ## SOMETIMES_CONSUMES
[FeaturePcd] [FeaturePcd]
gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## CONSUMES
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable ## CONSUMES
[Pcd] [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart ## SOMETIMES_CONSUMES
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## CONSUMES
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile ## CONSUMES
#
# [BootMode]
# RECOVERY_FULL ## SOMETIMES_CONSUMES # Memory Type Information variable
#

View File

@ -1,7 +1,7 @@
/** @file /** @file
BDS library definition, include the file and data structure BDS library definition, include the file and data structure
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<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
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/HdBootVariable.h> #include <Guid/HdBootVariable.h>
#include <Guid/LastEnumLang.h> #include <Guid/LastEnumLang.h>
#include <Guid/LegacyDevOrder.h> #include <Guid/LegacyDevOrder.h>
#include <Guid/StatusCodeDataTypeVariable.h>
#include <Library/PrintLib.h> #include <Library/PrintLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
@ -147,4 +148,48 @@ ValidateOption (
UINTN VariableSize UINTN VariableSize
); );
/**
Set the variable and report the error through status code upon failure.
@param VariableName A Null-terminated string that is the name of the vendor's variable.
Each VariableName is unique for each VendorGuid. VariableName must
contain 1 or more characters. If VariableName is an empty string,
then EFI_INVALID_PARAMETER is returned.
@param VendorGuid A unique identifier for the vendor.
@param Attributes Attributes bitmask to set for the variable.
@param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
set, then a SetVariable() call with a DataSize of zero will not cause any change to
the variable value (the timestamp associated with the variable may be updated however
even if no new data value is provided,see the description of the
EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
@param Data The contents for the variable.
@retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
defined by the Attributes.
@retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
DataSize exceeds the maximum allowed.
@retval EFI_INVALID_PARAMETER VariableName is an empty string.
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
@retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
@retval EFI_WRITE_PROTECTED The variable in question is read-only.
@retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
@retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
does NOT pass the validation check carried out by the firmware.
@retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
**/
EFI_STATUS
SetVariableAndReportStatusCodeOnError (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
#endif // _BDS_LIB_H_ #endif // _BDS_LIB_H_