mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
MdeModulePkg/SecurityPkg Variable: Calculate enough space for PlatformLang and Lang variables and use PcdUefiVariableDefaultLangDeprecate to turn off auto update between PlatformLang and Lang variables.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Guo Dong <guo.dong@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15388 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
a8d8d43051
commit
b2bd493edb
@ -462,7 +462,7 @@ InitializeLanguage (
|
|||||||
if (LangCodesSettingRequired) {
|
if (LangCodesSettingRequired) {
|
||||||
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
||||||
//
|
//
|
||||||
// UEFI 2.1 depricated this variable so we support turning it off
|
// UEFI 2.0 depricated this variable so we support turning it off
|
||||||
//
|
//
|
||||||
Status = gRT->SetVariable (
|
Status = gRT->SetVariable (
|
||||||
L"LangCodes",
|
L"LangCodes",
|
||||||
@ -492,7 +492,7 @@ InitializeLanguage (
|
|||||||
|
|
||||||
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
||||||
//
|
//
|
||||||
// UEFI 2.1 depricated this variable so we support turning it off
|
// UEFI 2.0 depricated this variable so we support turning it off
|
||||||
//
|
//
|
||||||
InitializeLangVariable (L"Lang", LangCodes, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang), TRUE);
|
InitializeLangVariable (L"Lang", LangCodes, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang), TRUE);
|
||||||
}
|
}
|
||||||
|
@ -1258,6 +1258,121 @@ VariableGetBestLanguage (
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This function is to check if the remaining variable space is enough to set
|
||||||
|
all Variables from argument list successfully. The purpose of the check
|
||||||
|
is to keep the consistency of the Variables to be in variable storage.
|
||||||
|
|
||||||
|
Note: Variables are assumed to be in same storage.
|
||||||
|
The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
|
||||||
|
so follow the argument sequence to check the Variables.
|
||||||
|
|
||||||
|
@param[in] Attributes Variable attributes for Variable entries.
|
||||||
|
@param ... Variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
|
||||||
|
A NULL terminates the list.
|
||||||
|
|
||||||
|
@retval TRUE Have enough variable space to set the Variables successfully.
|
||||||
|
@retval FALSE No enough variable space to set the Variables successfully.
|
||||||
|
|
||||||
|
**/
|
||||||
|
BOOLEAN
|
||||||
|
EFIAPI
|
||||||
|
CheckRemainingSpaceForConsistency (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
VA_LIST Args;
|
||||||
|
VARIABLE_ENTRY_CONSISTENCY *VariableEntry;
|
||||||
|
UINT64 MaximumVariableStorageSize;
|
||||||
|
UINT64 RemainingVariableStorageSize;
|
||||||
|
UINT64 MaximumVariableSize;
|
||||||
|
UINTN TotalNeededSize;
|
||||||
|
UINTN OriginalVarSize;
|
||||||
|
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||||
|
VARIABLE_POINTER_TRACK VariablePtrTrack;
|
||||||
|
VARIABLE_HEADER *NextVariable;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Non-Volatile related.
|
||||||
|
//
|
||||||
|
VariableStoreHeader = mNvVariableCache;
|
||||||
|
|
||||||
|
Status = VariableServiceQueryVariableInfoInternal (
|
||||||
|
Attributes,
|
||||||
|
&MaximumVariableStorageSize,
|
||||||
|
&RemainingVariableStorageSize,
|
||||||
|
&MaximumVariableSize
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
TotalNeededSize = 0;
|
||||||
|
VA_START (Args, Attributes);
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
while (VariableEntry != NULL) {
|
||||||
|
TotalNeededSize += VariableEntry->VariableSize;
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
}
|
||||||
|
VA_END (Args);
|
||||||
|
|
||||||
|
if (RemainingVariableStorageSize >= TotalNeededSize) {
|
||||||
|
//
|
||||||
|
// Already have enough space.
|
||||||
|
//
|
||||||
|
return TRUE;
|
||||||
|
} else if (AtRuntime ()) {
|
||||||
|
//
|
||||||
|
// At runtime, no reclaim.
|
||||||
|
// The original variable space of Variables can't be reused.
|
||||||
|
//
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VA_START (Args, Attributes);
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
while (VariableEntry != NULL) {
|
||||||
|
//
|
||||||
|
// Check if Variable[Index] has been present and get its size.
|
||||||
|
//
|
||||||
|
OriginalVarSize = 0;
|
||||||
|
VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
|
||||||
|
VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
|
||||||
|
Status = FindVariableEx (
|
||||||
|
VariableEntry->Name,
|
||||||
|
VariableEntry->Guid,
|
||||||
|
FALSE,
|
||||||
|
&VariablePtrTrack
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
//
|
||||||
|
// Get size of Variable[Index].
|
||||||
|
//
|
||||||
|
NextVariable = GetNextVariablePtr (VariablePtrTrack.CurrPtr);
|
||||||
|
OriginalVarSize = (UINTN) NextVariable - (UINTN) VariablePtrTrack.CurrPtr;
|
||||||
|
//
|
||||||
|
// Add the original size of Variable[Index] to remaining variable storage size.
|
||||||
|
//
|
||||||
|
RemainingVariableStorageSize += OriginalVarSize;
|
||||||
|
}
|
||||||
|
if (VariableEntry->VariableSize > RemainingVariableStorageSize) {
|
||||||
|
//
|
||||||
|
// No enough space for Variable[Index].
|
||||||
|
//
|
||||||
|
VA_END (Args);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Sub the (new) size of Variable[Index] from remaining variable storage size.
|
||||||
|
//
|
||||||
|
RemainingVariableStorageSize -= VariableEntry->VariableSize;
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
}
|
||||||
|
VA_END (Args);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
|
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
|
||||||
|
|
||||||
@ -1292,6 +1407,9 @@ AutoUpdateLangVariable (
|
|||||||
UINT32 Attributes;
|
UINT32 Attributes;
|
||||||
VARIABLE_POINTER_TRACK Variable;
|
VARIABLE_POINTER_TRACK Variable;
|
||||||
BOOLEAN SetLanguageCodes;
|
BOOLEAN SetLanguageCodes;
|
||||||
|
UINTN VarNameSize;
|
||||||
|
UINTN VarDataSize;
|
||||||
|
VARIABLE_ENTRY_CONSISTENCY VariableEntry[2];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Don't do updates for delete operation
|
// Don't do updates for delete operation
|
||||||
@ -1413,6 +1531,30 @@ AutoUpdateLangVariable (
|
|||||||
//
|
//
|
||||||
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
|
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for Lang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
|
||||||
|
VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
|
||||||
|
VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for PlatformLang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = AsciiStrSize (BestPlatformLang);
|
||||||
|
VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
|
||||||
|
VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
|
||||||
|
if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
|
||||||
|
//
|
||||||
|
// No enough variable space to set both Lang and PlatformLang successfully.
|
||||||
|
//
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
// Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
|
// Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
|
||||||
//
|
//
|
||||||
@ -1420,8 +1562,9 @@ AutoUpdateLangVariable (
|
|||||||
|
|
||||||
Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
|
Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
|
||||||
ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);
|
ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a: Status: %r\n", BestPlatformLang, BestLang, Status));
|
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1445,6 +1588,30 @@ AutoUpdateLangVariable (
|
|||||||
//
|
//
|
||||||
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
|
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for PlatformLang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = AsciiStrSize (BestPlatformLang);
|
||||||
|
VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
|
||||||
|
VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for Lang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
|
||||||
|
VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
|
||||||
|
VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
|
||||||
|
if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
|
||||||
|
//
|
||||||
|
// No enough variable space to set both PlatformLang and Lang successfully.
|
||||||
|
//
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
// Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
|
// Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
|
||||||
//
|
//
|
||||||
@ -1452,13 +1619,21 @@ AutoUpdateLangVariable (
|
|||||||
|
|
||||||
Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
|
Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
|
||||||
AsciiStrSize (BestPlatformLang), Attributes, &Variable);
|
AsciiStrSize (BestPlatformLang), Attributes, &Variable);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
|
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SetLanguageCodes) {
|
||||||
|
//
|
||||||
|
// Continue to set PlatformLangCodes or LangCodes.
|
||||||
|
//
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
} else {
|
||||||
return Status;
|
return Status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2492,6 +2667,7 @@ VariableServiceSetVariable (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
||||||
//
|
//
|
||||||
// Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
|
// Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
|
||||||
//
|
//
|
||||||
@ -2502,6 +2678,7 @@ VariableServiceSetVariable (
|
|||||||
//
|
//
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, Attributes, &Variable);
|
Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, Attributes, &Variable);
|
||||||
|
|
||||||
@ -2525,14 +2702,12 @@ Done:
|
|||||||
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
associated with the attributes specified.
|
associated with the attributes specified.
|
||||||
|
|
||||||
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
|
|
||||||
@return EFI_SUCCESS Query successfully.
|
@return EFI_SUCCESS Query successfully.
|
||||||
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
VariableServiceQueryVariableInfo (
|
VariableServiceQueryVariableInfoInternal (
|
||||||
IN UINT32 Attributes,
|
IN UINT32 Attributes,
|
||||||
OUT UINT64 *MaximumVariableStorageSize,
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
OUT UINT64 *RemainingVariableStorageSize,
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
@ -2545,43 +2720,12 @@ VariableServiceQueryVariableInfo (
|
|||||||
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||||
UINT64 CommonVariableTotalSize;
|
UINT64 CommonVariableTotalSize;
|
||||||
UINT64 HwErrVariableTotalSize;
|
UINT64 HwErrVariableTotalSize;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
VARIABLE_POINTER_TRACK VariablePtrTrack;
|
||||||
|
|
||||||
CommonVariableTotalSize = 0;
|
CommonVariableTotalSize = 0;
|
||||||
HwErrVariableTotalSize = 0;
|
HwErrVariableTotalSize = 0;
|
||||||
|
|
||||||
if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
|
|
||||||
//
|
|
||||||
// Make sure the Attributes combination is supported by the platform.
|
|
||||||
//
|
|
||||||
return EFI_UNSUPPORTED;
|
|
||||||
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
|
|
||||||
//
|
|
||||||
// Make sure if runtime bit is set, boot service bit is set also.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
} else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
|
|
||||||
//
|
|
||||||
// Make sure RT Attribute is set if we are in Runtime phase.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
} else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
|
||||||
//
|
|
||||||
// Make sure Hw Attribute is set with NV.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
} else if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {
|
|
||||||
//
|
|
||||||
// Not support authentiated variable write yet.
|
|
||||||
//
|
|
||||||
return EFI_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
|
||||||
|
|
||||||
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
|
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
|
||||||
//
|
//
|
||||||
// Query is Volatile related.
|
// Query is Volatile related.
|
||||||
@ -2653,6 +2797,27 @@ VariableServiceQueryVariableInfo (
|
|||||||
} else {
|
} else {
|
||||||
CommonVariableTotalSize += VariableSize;
|
CommonVariableTotalSize += VariableSize;
|
||||||
}
|
}
|
||||||
|
} else if (Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
|
||||||
|
//
|
||||||
|
// If it is a IN_DELETED_TRANSITION variable,
|
||||||
|
// and there is not also a same ADDED one at the same time,
|
||||||
|
// this IN_DELETED_TRANSITION variable is valid.
|
||||||
|
//
|
||||||
|
VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
|
||||||
|
VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
|
||||||
|
Status = FindVariableEx (
|
||||||
|
GetVariableNamePtr (Variable),
|
||||||
|
&Variable->VendorGuid,
|
||||||
|
FALSE,
|
||||||
|
&VariablePtrTrack
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State != VAR_ADDED) {
|
||||||
|
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||||
|
HwErrVariableTotalSize += VariableSize;
|
||||||
|
} else {
|
||||||
|
CommonVariableTotalSize += VariableSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2674,10 +2839,81 @@ VariableServiceQueryVariableInfo (
|
|||||||
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
|
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
This code returns information about the EFI variables.
|
||||||
|
|
||||||
|
@param Attributes Attributes bitmask to specify the type of variables
|
||||||
|
on which to return information.
|
||||||
|
@param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
|
||||||
|
for the EFI variables associated with the attributes specified.
|
||||||
|
@param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
|
||||||
|
for EFI variables associated with the attributes specified.
|
||||||
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
|
associated with the attributes specified.
|
||||||
|
|
||||||
|
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
|
||||||
|
@return EFI_SUCCESS Query successfully.
|
||||||
|
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
VariableServiceQueryVariableInfo (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
|
OUT UINT64 *MaximumVariableSize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
|
||||||
|
//
|
||||||
|
// Make sure the Attributes combination is supported by the platform.
|
||||||
|
//
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
|
||||||
|
//
|
||||||
|
// Make sure if runtime bit is set, boot service bit is set also.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
} else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
|
||||||
|
//
|
||||||
|
// Make sure RT Attribute is set if we are in Runtime phase.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
} else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||||
|
//
|
||||||
|
// Make sure Hw Attribute is set with NV.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
} else if ((Attributes & (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_APPEND_WRITE)) != 0) {
|
||||||
|
//
|
||||||
|
// Not support authenticated or append variable write yet.
|
||||||
|
//
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||||
|
|
||||||
|
Status = VariableServiceQueryVariableInfoInternal (
|
||||||
|
Attributes,
|
||||||
|
MaximumVariableStorageSize,
|
||||||
|
RemainingVariableStorageSize,
|
||||||
|
MaximumVariableSize
|
||||||
|
);
|
||||||
|
|
||||||
|
ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function reclaims variable storage if free size is below the threshold.
|
This function reclaims variable storage if free size is below the threshold.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
The internal header file includes the common header files, defines
|
The internal header file includes the common header files, defines
|
||||||
internal structure and functions used by Variable modules.
|
internal structure and functions used by Variable modules.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 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
|
||||||
@ -101,10 +101,12 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
EFI_GUID *Guid;
|
EFI_GUID *Guid;
|
||||||
CHAR16 *Name;
|
CHAR16 *Name;
|
||||||
UINT32 Attributes;
|
// UINT32 Attributes;
|
||||||
UINTN DataSize;
|
//
|
||||||
VOID *Data;
|
// Variable size include variable header, name and data.
|
||||||
} VARIABLE_CACHE_ENTRY;
|
//
|
||||||
|
UINTN VariableSize;
|
||||||
|
} VARIABLE_ENTRY_CONSISTENCY;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EFI_GUID Guid;
|
EFI_GUID Guid;
|
||||||
@ -443,6 +445,31 @@ VariableServiceSetVariable (
|
|||||||
IN VOID *Data
|
IN VOID *Data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
This code returns information about the EFI variables.
|
||||||
|
|
||||||
|
@param Attributes Attributes bitmask to specify the type of variables
|
||||||
|
on which to return information.
|
||||||
|
@param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
|
||||||
|
for the EFI variables associated with the attributes specified.
|
||||||
|
@param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
|
||||||
|
for EFI variables associated with the attributes specified.
|
||||||
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
|
associated with the attributes specified.
|
||||||
|
|
||||||
|
@return EFI_SUCCESS Query successfully.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
VariableServiceQueryVariableInfoInternal (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
|
OUT UINT64 *MaximumVariableSize
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
This code returns information about the EFI variables.
|
This code returns information about the EFI variables.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Component description file for Variable module.
|
# Component description file for Variable module.
|
||||||
#
|
#
|
||||||
# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.
|
# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.
|
||||||
# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
# Copyright (c) 2006 - 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
|
||||||
@ -80,7 +80,8 @@
|
|||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
|
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
|
||||||
|
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# This external input must be validated carefully to avoid security issue like
|
# This external input must be validated carefully to avoid security issue like
|
||||||
# buffer overflow, integer overflow.
|
# buffer overflow, integer overflow.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
|
# Copyright (c) 2010 - 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
|
||||||
@ -89,7 +89,8 @@
|
|||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
|
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
|
||||||
|
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
@ -1375,7 +1375,8 @@
|
|||||||
## If TRUE, the driver diagnostics2 protocol will not be installed.
|
## If TRUE, the driver diagnostics2 protocol will not be installed.
|
||||||
gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE|BOOLEAN|0x00000011
|
gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE|BOOLEAN|0x00000011
|
||||||
|
|
||||||
## Indicates whether EFI 1.1 ISO 639-2 language supports are obsolete
|
## Indicates whether EFI 1.1 ISO 639-2 language supports are obsolete.
|
||||||
|
# If TRUE, Variable driver will be also not to auto update between PlatformLang and Lang variables.
|
||||||
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate|FALSE|BOOLEAN|0x00000012
|
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate|FALSE|BOOLEAN|0x00000012
|
||||||
|
|
||||||
## If TRUE, UGA Draw Protocol is still consumed.
|
## If TRUE, UGA Draw Protocol is still consumed.
|
||||||
|
@ -1508,6 +1508,121 @@ VariableGetBestLanguage (
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This function is to check if the remaining variable space is enough to set
|
||||||
|
all Variables from argument list successfully. The purpose of the check
|
||||||
|
is to keep the consistency of the Variables to be in variable storage.
|
||||||
|
|
||||||
|
Note: Variables are assumed to be in same storage.
|
||||||
|
The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
|
||||||
|
so follow the argument sequence to check the Variables.
|
||||||
|
|
||||||
|
@param[in] Attributes Variable attributes for Variable entries.
|
||||||
|
@param ... Variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
|
||||||
|
A NULL terminates the list.
|
||||||
|
|
||||||
|
@retval TRUE Have enough variable space to set the Variables successfully.
|
||||||
|
@retval FALSE No enough variable space to set the Variables successfully.
|
||||||
|
|
||||||
|
**/
|
||||||
|
BOOLEAN
|
||||||
|
EFIAPI
|
||||||
|
CheckRemainingSpaceForConsistency (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
VA_LIST Args;
|
||||||
|
VARIABLE_ENTRY_CONSISTENCY *VariableEntry;
|
||||||
|
UINT64 MaximumVariableStorageSize;
|
||||||
|
UINT64 RemainingVariableStorageSize;
|
||||||
|
UINT64 MaximumVariableSize;
|
||||||
|
UINTN TotalNeededSize;
|
||||||
|
UINTN OriginalVarSize;
|
||||||
|
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||||
|
VARIABLE_POINTER_TRACK VariablePtrTrack;
|
||||||
|
VARIABLE_HEADER *NextVariable;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Non-Volatile related.
|
||||||
|
//
|
||||||
|
VariableStoreHeader = mNvVariableCache;
|
||||||
|
|
||||||
|
Status = VariableServiceQueryVariableInfoInternal (
|
||||||
|
Attributes,
|
||||||
|
&MaximumVariableStorageSize,
|
||||||
|
&RemainingVariableStorageSize,
|
||||||
|
&MaximumVariableSize
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
TotalNeededSize = 0;
|
||||||
|
VA_START (Args, Attributes);
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
while (VariableEntry != NULL) {
|
||||||
|
TotalNeededSize += VariableEntry->VariableSize;
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
}
|
||||||
|
VA_END (Args);
|
||||||
|
|
||||||
|
if (RemainingVariableStorageSize >= TotalNeededSize) {
|
||||||
|
//
|
||||||
|
// Already have enough space.
|
||||||
|
//
|
||||||
|
return TRUE;
|
||||||
|
} else if (AtRuntime ()) {
|
||||||
|
//
|
||||||
|
// At runtime, no reclaim.
|
||||||
|
// The original variable space of Variables can't be reused.
|
||||||
|
//
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VA_START (Args, Attributes);
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
while (VariableEntry != NULL) {
|
||||||
|
//
|
||||||
|
// Check if Variable[Index] has been present and get its size.
|
||||||
|
//
|
||||||
|
OriginalVarSize = 0;
|
||||||
|
VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
|
||||||
|
VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
|
||||||
|
Status = FindVariableEx (
|
||||||
|
VariableEntry->Name,
|
||||||
|
VariableEntry->Guid,
|
||||||
|
FALSE,
|
||||||
|
&VariablePtrTrack
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
//
|
||||||
|
// Get size of Variable[Index].
|
||||||
|
//
|
||||||
|
NextVariable = GetNextVariablePtr (VariablePtrTrack.CurrPtr);
|
||||||
|
OriginalVarSize = (UINTN) NextVariable - (UINTN) VariablePtrTrack.CurrPtr;
|
||||||
|
//
|
||||||
|
// Add the original size of Variable[Index] to remaining variable storage size.
|
||||||
|
//
|
||||||
|
RemainingVariableStorageSize += OriginalVarSize;
|
||||||
|
}
|
||||||
|
if (VariableEntry->VariableSize > RemainingVariableStorageSize) {
|
||||||
|
//
|
||||||
|
// No enough space for Variable[Index].
|
||||||
|
//
|
||||||
|
VA_END (Args);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Sub the (new) size of Variable[Index] from remaining variable storage size.
|
||||||
|
//
|
||||||
|
RemainingVariableStorageSize -= VariableEntry->VariableSize;
|
||||||
|
VariableEntry = VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *);
|
||||||
|
}
|
||||||
|
VA_END (Args);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
|
Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
|
||||||
|
|
||||||
@ -1542,6 +1657,9 @@ AutoUpdateLangVariable (
|
|||||||
UINT32 Attributes;
|
UINT32 Attributes;
|
||||||
VARIABLE_POINTER_TRACK Variable;
|
VARIABLE_POINTER_TRACK Variable;
|
||||||
BOOLEAN SetLanguageCodes;
|
BOOLEAN SetLanguageCodes;
|
||||||
|
UINTN VarNameSize;
|
||||||
|
UINTN VarDataSize;
|
||||||
|
VARIABLE_ENTRY_CONSISTENCY VariableEntry[2];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Don't do updates for delete operation
|
// Don't do updates for delete operation
|
||||||
@ -1663,6 +1781,30 @@ AutoUpdateLangVariable (
|
|||||||
//
|
//
|
||||||
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
|
BestLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->LangCodes, Index, TRUE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for Lang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
|
||||||
|
VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
|
||||||
|
VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[0].Name = EFI_LANG_VARIABLE_NAME;
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for PlatformLang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = AsciiStrSize (BestPlatformLang);
|
||||||
|
VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
|
||||||
|
VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[1].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
|
||||||
|
if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
|
||||||
|
//
|
||||||
|
// No enough variable space to set both Lang and PlatformLang successfully.
|
||||||
|
//
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
// Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
|
// Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
|
||||||
//
|
//
|
||||||
@ -1670,6 +1812,7 @@ AutoUpdateLangVariable (
|
|||||||
|
|
||||||
Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
|
Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,
|
||||||
ISO_639_2_ENTRY_SIZE + 1, Attributes, 0, 0, &Variable, NULL);
|
ISO_639_2_ENTRY_SIZE + 1, Attributes, 0, 0, &Variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
|
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a Status: %r\n", BestPlatformLang, BestLang, Status));
|
||||||
}
|
}
|
||||||
@ -1695,6 +1838,30 @@ AutoUpdateLangVariable (
|
|||||||
//
|
//
|
||||||
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
|
BestPlatformLang = GetLangFromSupportedLangCodes (mVariableModuleGlobal->PlatformLangCodes, Index, FALSE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for PlatformLang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_PLATFORM_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = AsciiStrSize (BestPlatformLang);
|
||||||
|
VariableEntry[0].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[0].VariableSize = HEADER_ALIGN (VariableEntry[0].VariableSize);
|
||||||
|
VariableEntry[0].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[0].Name = EFI_PLATFORM_LANG_VARIABLE_NAME;
|
||||||
|
//
|
||||||
|
// Calculate the needed variable size for Lang variable.
|
||||||
|
//
|
||||||
|
VarNameSize = StrSize (EFI_LANG_VARIABLE_NAME);
|
||||||
|
VarDataSize = ISO_639_2_ENTRY_SIZE + 1;
|
||||||
|
VariableEntry[1].VariableSize = sizeof (VARIABLE_HEADER) + VarNameSize + GET_PAD_SIZE (VarNameSize) + VarDataSize + GET_PAD_SIZE (VarDataSize);
|
||||||
|
VariableEntry[1].VariableSize = HEADER_ALIGN (VariableEntry[1].VariableSize);
|
||||||
|
VariableEntry[1].Guid = &gEfiGlobalVariableGuid;
|
||||||
|
VariableEntry[1].Name = EFI_LANG_VARIABLE_NAME;
|
||||||
|
if (!CheckRemainingSpaceForConsistency (VARIABLE_ATTRIBUTE_NV_BS_RT, &VariableEntry[0], &VariableEntry[1], NULL)) {
|
||||||
|
//
|
||||||
|
// No enough variable space to set both PlatformLang and Lang successfully.
|
||||||
|
//
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
//
|
//
|
||||||
// Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
|
// Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
|
||||||
//
|
//
|
||||||
@ -1702,13 +1869,21 @@ AutoUpdateLangVariable (
|
|||||||
|
|
||||||
Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
|
Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,
|
||||||
AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL);
|
AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
|
DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a Status: %r\n", BestLang, BestPlatformLang, Status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SetLanguageCodes) {
|
||||||
|
//
|
||||||
|
// Continue to set PlatformLangCodes or LangCodes.
|
||||||
|
//
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
} else {
|
||||||
return Status;
|
return Status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2993,6 +3168,7 @@ VariableServiceSetVariable (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
|
||||||
//
|
//
|
||||||
// Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
|
// Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.
|
||||||
//
|
//
|
||||||
@ -3003,6 +3179,7 @@ VariableServiceSetVariable (
|
|||||||
//
|
//
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Process PK, KEK, Sigdb seperately.
|
// Process PK, KEK, Sigdb seperately.
|
||||||
@ -3053,14 +3230,12 @@ Done:
|
|||||||
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
associated with the attributes specified.
|
associated with the attributes specified.
|
||||||
|
|
||||||
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
|
|
||||||
@return EFI_SUCCESS Query successfully.
|
@return EFI_SUCCESS Query successfully.
|
||||||
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
VariableServiceQueryVariableInfo (
|
VariableServiceQueryVariableInfoInternal (
|
||||||
IN UINT32 Attributes,
|
IN UINT32 Attributes,
|
||||||
OUT UINT64 *MaximumVariableStorageSize,
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
OUT UINT64 *RemainingVariableStorageSize,
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
@ -3073,38 +3248,12 @@ VariableServiceQueryVariableInfo (
|
|||||||
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||||
UINT64 CommonVariableTotalSize;
|
UINT64 CommonVariableTotalSize;
|
||||||
UINT64 HwErrVariableTotalSize;
|
UINT64 HwErrVariableTotalSize;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
VARIABLE_POINTER_TRACK VariablePtrTrack;
|
||||||
|
|
||||||
CommonVariableTotalSize = 0;
|
CommonVariableTotalSize = 0;
|
||||||
HwErrVariableTotalSize = 0;
|
HwErrVariableTotalSize = 0;
|
||||||
|
|
||||||
if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
|
|
||||||
//
|
|
||||||
// Make sure the Attributes combination is supported by the platform.
|
|
||||||
//
|
|
||||||
return EFI_UNSUPPORTED;
|
|
||||||
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
|
|
||||||
//
|
|
||||||
// Make sure if runtime bit is set, boot service bit is set also.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
} else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
|
|
||||||
//
|
|
||||||
// Make sure RT Attribute is set if we are in Runtime phase.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
} else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
|
||||||
//
|
|
||||||
// Make sure Hw Attribute is set with NV.
|
|
||||||
//
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
|
||||||
|
|
||||||
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
|
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
|
||||||
//
|
//
|
||||||
// Query is Volatile related.
|
// Query is Volatile related.
|
||||||
@ -3176,6 +3325,27 @@ VariableServiceQueryVariableInfo (
|
|||||||
} else {
|
} else {
|
||||||
CommonVariableTotalSize += VariableSize;
|
CommonVariableTotalSize += VariableSize;
|
||||||
}
|
}
|
||||||
|
} else if (Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
|
||||||
|
//
|
||||||
|
// If it is a IN_DELETED_TRANSITION variable,
|
||||||
|
// and there is not also a same ADDED one at the same time,
|
||||||
|
// this IN_DELETED_TRANSITION variable is valid.
|
||||||
|
//
|
||||||
|
VariablePtrTrack.StartPtr = GetStartPointer (VariableStoreHeader);
|
||||||
|
VariablePtrTrack.EndPtr = GetEndPointer (VariableStoreHeader);
|
||||||
|
Status = FindVariableEx (
|
||||||
|
GetVariableNamePtr (Variable),
|
||||||
|
&Variable->VendorGuid,
|
||||||
|
FALSE,
|
||||||
|
&VariablePtrTrack
|
||||||
|
);
|
||||||
|
if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State != VAR_ADDED) {
|
||||||
|
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||||
|
HwErrVariableTotalSize += VariableSize;
|
||||||
|
} else {
|
||||||
|
CommonVariableTotalSize += VariableSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3197,10 +3367,79 @@ VariableServiceQueryVariableInfo (
|
|||||||
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
|
*MaximumVariableSize = *RemainingVariableStorageSize - sizeof (VARIABLE_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
This code returns information about the EFI variables.
|
||||||
|
|
||||||
|
Caution: This function may receive untrusted input.
|
||||||
|
This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
|
||||||
|
|
||||||
|
@param Attributes Attributes bitmask to specify the type of variables
|
||||||
|
on which to return information.
|
||||||
|
@param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
|
||||||
|
for the EFI variables associated with the attributes specified.
|
||||||
|
@param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
|
||||||
|
for EFI variables associated with the attributes specified.
|
||||||
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
|
associated with the attributes specified.
|
||||||
|
|
||||||
|
@return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
|
||||||
|
@return EFI_SUCCESS Query successfully.
|
||||||
|
@return EFI_UNSUPPORTED The attribute is not supported on this platform.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
VariableServiceQueryVariableInfo (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
|
OUT UINT64 *MaximumVariableSize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == 0) {
|
||||||
|
//
|
||||||
|
// Make sure the Attributes combination is supported by the platform.
|
||||||
|
//
|
||||||
|
return EFI_UNSUPPORTED;
|
||||||
|
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {
|
||||||
|
//
|
||||||
|
// Make sure if runtime bit is set, boot service bit is set also.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
} else if (AtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {
|
||||||
|
//
|
||||||
|
// Make sure RT Attribute is set if we are in Runtime phase.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
} else if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||||
|
//
|
||||||
|
// Make sure Hw Attribute is set with NV.
|
||||||
|
//
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||||
|
|
||||||
|
Status = VariableServiceQueryVariableInfoInternal (
|
||||||
|
Attributes,
|
||||||
|
MaximumVariableStorageSize,
|
||||||
|
RemainingVariableStorageSize,
|
||||||
|
MaximumVariableSize
|
||||||
|
);
|
||||||
|
|
||||||
|
ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function reclaims variable storage if free size is below the threshold.
|
This function reclaims variable storage if free size is below the threshold.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
The internal header file includes the common header files, defines
|
The internal header file includes the common header files, defines
|
||||||
internal structure and functions used by Variable modules.
|
internal structure and functions used by Variable modules.
|
||||||
|
|
||||||
Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2009 - 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
|
||||||
@ -111,10 +111,12 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
EFI_GUID *Guid;
|
EFI_GUID *Guid;
|
||||||
CHAR16 *Name;
|
CHAR16 *Name;
|
||||||
UINT32 Attributes;
|
// UINT32 Attributes;
|
||||||
UINTN DataSize;
|
//
|
||||||
VOID *Data;
|
// Variable size include variable header, name and data.
|
||||||
} VARIABLE_CACHE_ENTRY;
|
//
|
||||||
|
UINTN VariableSize;
|
||||||
|
} VARIABLE_ENTRY_CONSISTENCY;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EFI_GUID Guid;
|
EFI_GUID Guid;
|
||||||
@ -564,6 +566,34 @@ VariableServiceSetVariable (
|
|||||||
IN VOID *Data
|
IN VOID *Data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
This code returns information about the EFI variables.
|
||||||
|
|
||||||
|
Caution: This function may receive untrusted input.
|
||||||
|
This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
|
||||||
|
|
||||||
|
@param Attributes Attributes bitmask to specify the type of variables
|
||||||
|
on which to return information.
|
||||||
|
@param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
|
||||||
|
for the EFI variables associated with the attributes specified.
|
||||||
|
@param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
|
||||||
|
for EFI variables associated with the attributes specified.
|
||||||
|
@param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
|
||||||
|
associated with the attributes specified.
|
||||||
|
|
||||||
|
@return EFI_SUCCESS Query successfully.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
VariableServiceQueryVariableInfoInternal (
|
||||||
|
IN UINT32 Attributes,
|
||||||
|
OUT UINT64 *MaximumVariableStorageSize,
|
||||||
|
OUT UINT64 *RemainingVariableStorageSize,
|
||||||
|
OUT UINT64 *MaximumVariableSize
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
This code returns information about the EFI variables.
|
This code returns information about the EFI variables.
|
||||||
|
@ -99,7 +99,8 @@
|
|||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
|
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
|
||||||
|
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
@ -102,7 +102,8 @@
|
|||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## SOMETIME_CONSUMES (statistic the information of variable.)
|
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUMES # statistic the information of variable.
|
||||||
|
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
TRUE
|
TRUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user