and volatile storage space and install variable architecture protocol.\r
\r
Copyright (C) 2013, Red Hat, Inc.\r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include "Variable.h"\r
\r
-extern VARIABLE_STORE_HEADER *mNvVariableCache;\r
-extern EFI_FIRMWARE_VOLUME_HEADER *mNvFvHeaderCache;\r
-extern VARIABLE_INFO_ENTRY *gVariableInfo;\r
EFI_HANDLE mHandle = NULL;\r
EFI_EVENT mVirtualAddressChangeEvent = NULL;\r
EFI_EVENT mFtwRegistration = NULL;\r
-extern BOOLEAN mEndOfDxe;\r
VOID ***mVarCheckAddressPointer = NULL;\r
UINTN mVarCheckAddressPointerCount = 0;\r
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock };\r
{\r
UINTN Index;\r
\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);\r
- EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);\r
+ if (mVariableModuleGlobal->FvbInstance != NULL) {\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);\r
+ EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);\r
+ }\r
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r
gBS->CloseEvent (Event);\r
}\r
\r
+/**\r
+ Initializes variable write service for DXE.\r
+\r
+**/\r
+VOID\r
+VariableWriteServiceInitializeDxe (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = VariableWriteServiceInitialize ();\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
+ }\r
+\r
+ //\r
+ // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r
+ // Secure Boot Policy Variable change. Record their initial value.\r
+ //\r
+ RecordSecureBootPolicyVarData();\r
+\r
+ //\r
+ // Install the Variable Write Architectural protocol.\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &mHandle,\r
+ &gEfiVariableWriteArchProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
/**\r
Fault Tolerant Write protocol notification event handler.\r
\r
ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
}\r
\r
+ NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r
+ VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
+\r
+ //\r
+ // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r
+ //\r
+ mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r
+\r
//\r
// Find the proper FVB protocol for variable.\r
//\r
- NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r
- if (NvStorageVariableBase == 0) {\r
- NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r
- }\r
Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
if (EFI_ERROR (Status)) {\r
return ;\r
//\r
// Mark the variable storage region of the FLASH as RUNTIME.\r
//\r
- VariableStoreBase = NvStorageVariableBase + (((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(NvStorageVariableBase))->HeaderLength);\r
- VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;\r
+ VariableStoreLength = mNvVariableCache->Size;\r
BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r
Length = VariableStoreLength + (VariableStoreBase - BaseAddress);\r
Length = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
}\r
}\r
\r
- Status = VariableWriteServiceInitialize ();\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
- }\r
-\r
- //\r
- // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r
- // Secure Boot Policy Variable change. Record their initial value.\r
- //\r
- RecordSecureBootPolicyVarData();\r
-\r
//\r
- // Install the Variable Write Architectural protocol.\r
+ // Initializes variable write service after FTW was ready.\r
//\r
- Status = gBS->InstallProtocolInterface (\r
- &mHandle,\r
- &gEfiVariableWriteArchProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ VariableWriteServiceInitializeDxe ();\r
\r
//\r
// Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- //\r
- // Register FtwNotificationEvent () notify function.\r
- //\r
- EfiCreateProtocolNotifyEvent (\r
- &gEfiFaultTolerantWriteProtocolGuid,\r
- TPL_CALLBACK,\r
- FtwNotificationEvent,\r
- (VOID *)SystemTable,\r
- &mFtwRegistration\r
- );\r
+ if (!PcdGetBool (PcdEmuVariableNvModeEnable)) {\r
+ //\r
+ // Register FtwNotificationEvent () notify function.\r
+ //\r
+ EfiCreateProtocolNotifyEvent (\r
+ &gEfiFaultTolerantWriteProtocolGuid,\r
+ TPL_CALLBACK,\r
+ FtwNotificationEvent,\r
+ (VOID *)SystemTable,\r
+ &mFtwRegistration\r
+ );\r
+ } else {\r
+ //\r
+ // Emulated non-volatile variable mode does not depend on FVB and FTW.\r
+ //\r
+ VariableWriteServiceInitializeDxe ();\r
+ }\r
\r
Status = gBS->CreateEventEx (\r
EVT_NOTIFY_SIGNAL,\r