Replies: 1 comment
-
|
InitRealNonVolatileVariableStore Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64); this function |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I use my SPI flash and place my variable.fd in my flash (my SPI controller does not have xip mode),
a crash occurs during the initialization of the variable service.
`EFI_STATUS
InitRealNonVolatileVariableStore (
OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase
)
{
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_STORE_HEADER *VariableStore;
UINT32 VariableStoreLength;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT8 *NvStorageData;
UINT32 NvStorageSize;
UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
UINT32 BackUpSize;
UINT32 HwErrStorageSize;
UINT32 MaxUserNvVariableSpaceSize;
UINT32 BoottimeReservedNvVariableSpaceSize;
EFI_STATUS Status;
VOID *FtwProtocol;
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.
// Keep the memory and the FLASH in sync as updates occur.
//
NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);
if (NvStorageData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Copy NV storage data to the memory buffer.
//
*CopyMem (NvStorageData, (UINT8 )(UINTN)NvStorageBase, NvStorageSize);
Status = GetFtwProtocol ((VOID **)&FtwProtocol);
//
// If FTW protocol has been installed, no need to check FTW last write data hob.
//
if (EFI_ERROR (Status)) {
//
// Check the FTW last write data hob.
//
GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
if (GuidHob != NULL) {
FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *)GET_GUID_HOB_DATA (GuidHob);
if (FtwLastWriteData->TargetAddress == NvStorageBase) {
DEBUG ((DEBUG_INFO, "Variable: NV storage is backed up in spare block: 0x%x\n", (UINTN)FtwLastWriteData->SpareAddress));
//
// Copy the backed up NV storage data to the memory buffer from spare block.
//
CopyMem (NvStorageData, (UINT8 *)(UINTN)(FtwLastWriteData->SpareAddress), NvStorageSize);
} else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
(FtwLastWriteData->TargetAddress < (NvStorageBase + NvStorageSize)))
{
//
// Flash NV storage from the Offset is backed up in spare block.
//
BackUpOffset = (UINT32)(FtwLastWriteData->TargetAddress - NvStorageBase);
BackUpSize = NvStorageSize - BackUpOffset;
DEBUG ((DEBUG_INFO, "Variable: High partial NV storage from offset: %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN)FtwLastWriteData->SpareAddress));
//
// Copy the partial backed up NV storage data to the memory buffer from spare block.
//
CopyMem (NvStorageData + BackUpOffset, (UINT8 *)(UINTN)FtwLastWriteData->SpareAddress, BackUpSize);
}
}
}
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)NvStorageData;
//
// Check if the Firmware Volume is not corrupted
//
if ((FvHeader->Signature != EFI_FVH_SIGNATURE) || (!CompareGuid (&gEfiSystemNvDataFvGuid, &FvHeader->FileSystemGuid))) {
FreePool (NvStorageData);
DEBUG ((DEBUG_ERROR, "Firmware Volume for Variable Store is corrupted\n"));
return EFI_VOLUME_CORRUPTED;
}
VariableStore = (VARIABLE_STORE_HEADER *)((UINTN)FvHeader + FvHeader->HeaderLength);
VariableStoreLength = NvStorageSize - FvHeader->HeaderLength;
ASSERT (sizeof (VARIABLE_STORE_HEADER) <= VariableStoreLength);
ASSERT (VariableStore->Size == VariableStoreLength);
//
// Check if the Variable Store header is not corrupted
//
if (GetVariableStoreStatus (VariableStore) != EfiValid) {
FreePool (NvStorageData);
DEBUG ((DEBUG_ERROR, "Variable Store header is corrupted\n"));
return EFI_VOLUME_CORRUPTED;
}
mNvFvHeaderCache = FvHeader;
*VariableStoreBase = (EFI_PHYSICAL_ADDRESS)(UINTN)VariableStore;
HwErrStorageSize = PcdGet32 (PcdHwErrStorageSize);
MaxUserNvVariableSpaceSize = PcdGet32 (PcdMaxUserNvVariableSpaceSize);
BoottimeReservedNvVariableSpaceSize = PcdGet32 (PcdBoottimeReservedNvVariableSpaceSize);
//
// Note that in EdkII variable driver implementation, Hardware Error Record type variable
// is stored with common variable in the same NV region. So the platform integrator should
// ensure that the value of PcdHwErrStorageSize is less than the value of
// (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).
//
ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));
//
// Ensure that the value of PcdMaxUserNvVariableSpaceSize is less than the value of
// (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).
//
ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));
//
// Ensure that the value of PcdBoottimeReservedNvVariableSpaceSize is less than the value of
// (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).
//
ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));
mVariableModuleGlobal->CommonVariableSpace = ((UINTN)VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonMaxUserVariableSpace = ((MaxUserNvVariableSpaceSize != 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->CommonVariableSpace);
mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize;
DEBUG ((
DEBUG_INFO,
"Variable driver common space: 0x%x 0x%x 0x%x\n",
mVariableModuleGlobal->CommonVariableSpace,
mVariableModuleGlobal->CommonMaxUserVariableSpace,
mVariableModuleGlobal->CommonRuntimeVariableSpace
));
//
// The max NV variable size should be < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).
//
ASSERT (GetNonVolatileMaxVariableSize () < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));
return EFI_SUCCESS;
}`
In the code I annotated, my NvSorageBase is the address in the flash instead of the actual DDR address, so there will be a crash when copying mem. Does the variable service not support non xip mode flash?
Beta Was this translation helpful? Give feedback.
All reactions