MdeModulePkg/Variable: Consume Variable Flash Info
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479 Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm to acquire variable flash information from the Variable Flash Information library. Note: This introduces a dependency on VariableFlashInfoLib in these modules. Therefore, a platform building the variable modules must specify an instance of VariableFlashInfoLib in their platform build. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
This commit is contained in:
committed by
mergify[bot]
parent
60b519456c
commit
4dbebc2d10
@ -567,11 +567,13 @@ GetVariableStore (
|
|||||||
OUT VARIABLE_STORE_INFO *StoreInfo
|
OUT VARIABLE_STORE_INFO *StoreInfo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
EFI_HOB_GUID_TYPE *GuidHob;
|
EFI_HOB_GUID_TYPE *GuidHob;
|
||||||
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
|
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
|
||||||
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||||
EFI_PHYSICAL_ADDRESS NvStorageBase;
|
EFI_PHYSICAL_ADDRESS NvStorageBase;
|
||||||
UINT32 NvStorageSize;
|
UINT32 NvStorageSize;
|
||||||
|
UINT64 NvStorageSize64;
|
||||||
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
|
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
|
||||||
UINT32 BackUpOffset;
|
UINT32 BackUpOffset;
|
||||||
|
|
||||||
@ -591,11 +593,13 @@ GetVariableStore (
|
|||||||
// Emulated non-volatile variable mode is not enabled.
|
// Emulated non-volatile variable mode is not enabled.
|
||||||
//
|
//
|
||||||
|
|
||||||
NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
|
Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
|
||||||
NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
|
ASSERT_EFI_ERROR (Status);
|
||||||
PcdGet64 (PcdFlashNvStorageVariableBase64) :
|
|
||||||
PcdGet32 (PcdFlashNvStorageVariableBase)
|
Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
|
||||||
);
|
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
ASSERT (NvStorageBase != 0);
|
ASSERT (NvStorageBase != 0);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/PeiServicesTablePointerLib.h>
|
#include <Library/PeiServicesTablePointerLib.h>
|
||||||
#include <Library/PeiServicesLib.h>
|
#include <Library/PeiServicesLib.h>
|
||||||
|
#include <Library/SafeIntLib.h>
|
||||||
|
#include <Library/VariableFlashInfoLib.h>
|
||||||
|
|
||||||
#include <Guid/VariableFormat.h>
|
#include <Guid/VariableFormat.h>
|
||||||
#include <Guid/VariableIndexTable.h>
|
#include <Guid/VariableIndexTable.h>
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
DebugLib
|
DebugLib
|
||||||
PeiServicesTablePointerLib
|
PeiServicesTablePointerLib
|
||||||
PeiServicesLib
|
PeiServicesLib
|
||||||
|
SafeIntLib
|
||||||
|
VariableFlashInfoLib
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
## CONSUMES ## GUID # Variable store header
|
## CONSUMES ## GUID # Variable store header
|
||||||
@ -59,9 +61,6 @@
|
|||||||
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
|
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## SOMETIMES_CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## SOMETIMES_CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
|
@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
#include <Library/MemoryAllocationLib.h>
|
#include <Library/MemoryAllocationLib.h>
|
||||||
#include <Library/AuthVariableLib.h>
|
#include <Library/AuthVariableLib.h>
|
||||||
#include <Library/VarCheckLib.h>
|
#include <Library/VarCheckLib.h>
|
||||||
|
#include <Library/VariableFlashInfoLib.h>
|
||||||
|
#include <Library/SafeIntLib.h>
|
||||||
#include <Guid/GlobalVariable.h>
|
#include <Guid/GlobalVariable.h>
|
||||||
#include <Guid/EventGroup.h>
|
#include <Guid/EventGroup.h>
|
||||||
#include <Guid/VariableFormat.h>
|
#include <Guid/VariableFormat.h>
|
||||||
@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
|
|
||||||
#include "PrivilegePolymorphic.h"
|
#include "PrivilegePolymorphic.h"
|
||||||
|
|
||||||
#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\
|
|
||||||
(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \
|
|
||||||
PcdGet64 (PcdFlashNvStorageVariableBase64) : \
|
|
||||||
PcdGet32 (PcdFlashNvStorageVariableBase))
|
|
||||||
|
|
||||||
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
|
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
|
||||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
|
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
|
||||||
EFI_VARIABLE_RUNTIME_ACCESS | \
|
EFI_VARIABLE_RUNTIME_ACCESS | \
|
||||||
|
@ -423,6 +423,8 @@ FtwNotificationEvent (
|
|||||||
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
EFI_PHYSICAL_ADDRESS VariableStoreBase;
|
||||||
UINT64 VariableStoreLength;
|
UINT64 VariableStoreLength;
|
||||||
UINTN FtwMaxBlockSize;
|
UINTN FtwMaxBlockSize;
|
||||||
|
UINT32 NvStorageVariableSize;
|
||||||
|
UINT64 NvStorageVariableSize64;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ensure FTW protocol is installed.
|
// Ensure FTW protocol is installed.
|
||||||
@ -432,14 +434,20 @@ FtwNotificationEvent (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
|
||||||
|
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
|
||||||
|
|
||||||
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
|
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
|
ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
|
|
||||||
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
|
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
|
||||||
//
|
//
|
||||||
|
@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore (
|
|||||||
EFI_PHYSICAL_ADDRESS NvStorageBase;
|
EFI_PHYSICAL_ADDRESS NvStorageBase;
|
||||||
UINT8 *NvStorageData;
|
UINT8 *NvStorageData;
|
||||||
UINT32 NvStorageSize;
|
UINT32 NvStorageSize;
|
||||||
|
UINT64 NvStorageSize64;
|
||||||
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
|
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
|
||||||
UINT32 BackUpOffset;
|
UINT32 BackUpOffset;
|
||||||
UINT32 BackUpSize;
|
UINT32 BackUpSize;
|
||||||
@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore (
|
|||||||
|
|
||||||
mVariableModuleGlobal->FvbInstance = NULL;
|
mVariableModuleGlobal->FvbInstance = NULL;
|
||||||
|
|
||||||
|
Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
|
||||||
|
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
ASSERT (NvStorageBase != 0);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate runtime memory used for a memory copy of the FLASH region.
|
// Allocate runtime memory used for a memory copy of the FLASH region.
|
||||||
// Keep the memory and the FLASH in sync as updates occur.
|
// Keep the memory and the FLASH in sync as updates occur.
|
||||||
//
|
//
|
||||||
NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
|
|
||||||
NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);
|
NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);
|
||||||
if (NvStorageData == NULL) {
|
if (NvStorageData == NULL) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
NvStorageBase = NV_STORAGE_VARIABLE_BASE;
|
|
||||||
ASSERT (NvStorageBase != 0);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy NV storage data to the memory buffer.
|
// Copy NV storage data to the memory buffer.
|
||||||
//
|
//
|
||||||
|
@ -71,8 +71,10 @@
|
|||||||
TpmMeasurementLib
|
TpmMeasurementLib
|
||||||
AuthVariableLib
|
AuthVariableLib
|
||||||
VarCheckLib
|
VarCheckLib
|
||||||
|
VariableFlashInfoLib
|
||||||
VariablePolicyLib
|
VariablePolicyLib
|
||||||
VariablePolicyHelperLib
|
VariablePolicyHelperLib
|
||||||
|
SafeIntLib
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
||||||
@ -125,9 +127,6 @@
|
|||||||
gEfiImageSecurityDatabaseGuid
|
gEfiImageSecurityDatabaseGuid
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
||||||
|
@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent (
|
|||||||
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
|
||||||
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
|
||||||
UINTN FtwMaxBlockSize;
|
UINTN FtwMaxBlockSize;
|
||||||
|
UINT32 NvStorageVariableSize;
|
||||||
|
UINT64 NvStorageVariableSize64;
|
||||||
|
|
||||||
if (mVariableModuleGlobal->FvbInstance != NULL) {
|
if (mVariableModuleGlobal->FvbInstance != NULL) {
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
|
||||||
|
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
ASSERT (NvStorageVariableBase != 0);
|
||||||
|
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
|
||||||
|
|
||||||
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
|
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
|
ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
|
|
||||||
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
|
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
|
||||||
//
|
//
|
||||||
|
@ -80,8 +80,10 @@
|
|||||||
AuthVariableLib
|
AuthVariableLib
|
||||||
VarCheckLib
|
VarCheckLib
|
||||||
UefiBootServicesTableLib
|
UefiBootServicesTableLib
|
||||||
|
VariableFlashInfoLib
|
||||||
VariablePolicyLib
|
VariablePolicyLib
|
||||||
VariablePolicyHelperLib
|
VariablePolicyHelperLib
|
||||||
|
SafeIntLib
|
||||||
|
|
||||||
[Protocols]
|
[Protocols]
|
||||||
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
|
||||||
@ -127,9 +129,6 @@
|
|||||||
gEdkiiVarErrorFlagGuid
|
gEdkiiVarErrorFlagGuid
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
||||||
|
@ -73,9 +73,11 @@
|
|||||||
HobLib
|
HobLib
|
||||||
MemoryAllocationLib
|
MemoryAllocationLib
|
||||||
MmServicesTableLib
|
MmServicesTableLib
|
||||||
|
SafeIntLib
|
||||||
StandaloneMmDriverEntryPoint
|
StandaloneMmDriverEntryPoint
|
||||||
SynchronizationLib
|
SynchronizationLib
|
||||||
VarCheckLib
|
VarCheckLib
|
||||||
|
VariableFlashInfoLib
|
||||||
VariablePolicyLib
|
VariablePolicyLib
|
||||||
VariablePolicyHelperLib
|
VariablePolicyHelperLib
|
||||||
|
|
||||||
@ -120,9 +122,6 @@
|
|||||||
gEdkiiVarErrorFlagGuid
|
gEdkiiVarErrorFlagGuid
|
||||||
|
|
||||||
[Pcd]
|
[Pcd]
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
|
||||||
|
Reference in New Issue
Block a user