Report the setting variable failure to platform through the status code when core cannot handle the error.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15385 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
|
||||
to enter BDS phase.
|
||||
|
||||
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
|
||||
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
|
||||
@@ -164,13 +164,17 @@ BdsBootDeviceSelect (
|
||||
//
|
||||
// Clear the this variable so it's only exist in this time boot
|
||||
//
|
||||
gRT->SetVariable (
|
||||
L"BootNext",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
0,
|
||||
mBootNext
|
||||
);
|
||||
Status = gRT->SetVariable (
|
||||
L"BootNext",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
//
|
||||
// Deleting variable with current variable implementation shouldn't fail.
|
||||
//
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
//
|
||||
// Add the boot next boot option
|
||||
@@ -368,6 +372,9 @@ BdsFormalizeConsoleVariable (
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
//
|
||||
// Deleting variable with current variable implementation shouldn't fail.
|
||||
//
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
}
|
||||
@@ -406,14 +413,13 @@ BdsFormalizeEfiGlobalVariable (
|
||||
OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \
|
||||
| EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;
|
||||
|
||||
Status = gRT->SetVariable (
|
||||
L"OsIndicationsSupported",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof(UINT64),
|
||||
&OsIndicationSupport
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
BdsDxeSetVariableAndReportStatusCodeOnError (
|
||||
L"OsIndicationsSupported",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof(UINT64),
|
||||
&OsIndicationSupport
|
||||
);
|
||||
|
||||
//
|
||||
// If OsIndications is invalid, remove it.
|
||||
@@ -442,10 +448,13 @@ BdsFormalizeEfiGlobalVariable (
|
||||
Status = gRT->SetVariable (
|
||||
L"OsIndications",
|
||||
&gEfiGlobalVariableGuid,
|
||||
Attributes,
|
||||
0,
|
||||
&OsIndication
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
//
|
||||
// Deleting variable with current variable implementation shouldn't fail.
|
||||
//
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
}
|
||||
@@ -481,16 +490,19 @@ BdsAllocateMemoryForPerformanceData (
|
||||
//
|
||||
// Save the pointer to variable for use in S3 resume.
|
||||
//
|
||||
Status = gRT->SetVariable (
|
||||
L"PerfDataMemAddr",
|
||||
&gPerformanceProtocolGuid,
|
||||
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof (EFI_PHYSICAL_ADDRESS),
|
||||
&AcpiLowMemoryBase
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
BdsDxeSetVariableAndReportStatusCodeOnError (
|
||||
L"PerfDataMemAddr",
|
||||
&gPerformanceProtocolGuid,
|
||||
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof (EFI_PHYSICAL_ADDRESS),
|
||||
&AcpiLowMemoryBase
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase));
|
||||
}
|
||||
//
|
||||
// Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists
|
||||
// Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.
|
||||
//
|
||||
Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
@@ -594,14 +606,13 @@ BdsEntry (
|
||||
// If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification
|
||||
// define same behavior between no value or 0xFFFF value for L"Timeout".
|
||||
//
|
||||
Status = gRT->SetVariable (
|
||||
BdsDxeSetVariableAndReportStatusCodeOnError (
|
||||
L"Timeout",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
sizeof (UINT16),
|
||||
&BootTimeOut
|
||||
);
|
||||
ASSERT_EFI_ERROR(Status);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -655,3 +666,89 @@ BdsEntry (
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
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
|
||||
BdsDxeSetVariableAndReportStatusCodeOnError (
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user