31#define EFI_AUTHENTICATED_VARIABLE_GUID \
32{ 0xaaf32c78, 0x947b, 0x439a, { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 } }
63 END_ENTIRE_DEVICE_PATH_SUBTYPE,
135 FvbDevice = FVB_DEVICE_FROM_THIS (This);
179 if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) {
180 return EFI_INVALID_PARAMETER;
183 FvbDevice = FVB_DEVICE_FROM_THIS (This);
185 *BlockSize = FvbDevice->BlockSize;
186 *NumberOfBlocks = (
UINTN)(EMU_FVB_NUM_TOTAL_BLOCKS - Lba);
215 EFI_FVB2_READ_ENABLED_CAP |
216 EFI_FVB2_READ_STATUS |
217 EFI_FVB2_WRITE_ENABLED_CAP |
218 EFI_FVB2_WRITE_STATUS |
219 EFI_FVB2_ERASE_POLARITY
254 return EFI_ACCESS_DENIED;
319 FvbDevice = FVB_DEVICE_FROM_THIS (This);
333 if ((StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS) ||
334 (NumOfLba > EMU_FVB_NUM_TOTAL_BLOCKS - StartingLba))
337 return EFI_INVALID_PARAMETER;
355 ErasePtr = FvbDevice->BufferPtr;
356 ErasePtr += (
UINTN)StartingLba * FvbDevice->BlockSize;
357 EraseSize = NumOfLba * FvbDevice->BlockSize;
359 SetMem (ErasePtr, EraseSize, ERASED_UINT8);
447 FvbDevice = FVB_DEVICE_FROM_THIS (This);
449 if ((Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) ||
450 (Offset > FvbDevice->BlockSize))
452 return EFI_INVALID_PARAMETER;
456 if (*NumBytes > FvbDevice->BlockSize - Offset) {
457 *NumBytes = FvbDevice->BlockSize - Offset;
458 Status = EFI_BAD_BUFFER_SIZE;
461 FvbDataPtr = FvbDevice->BufferPtr;
462 FvbDataPtr += (
UINTN)Lba * FvbDevice->BlockSize;
463 FvbDataPtr += Offset;
465 CopyMem (FvbDataPtr, Buffer, *NumBytes);
531 FvbDevice = FVB_DEVICE_FROM_THIS (This);
533 if ((Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) ||
534 (Offset > FvbDevice->BlockSize))
536 return EFI_INVALID_PARAMETER;
540 if (*NumBytes > FvbDevice->BlockSize - Offset) {
541 *NumBytes = FvbDevice->BlockSize - Offset;
542 Status = EFI_BAD_BUFFER_SIZE;
545 FvbDataPtr = FvbDevice->BufferPtr;
546 FvbDataPtr += (
UINTN)Lba * FvbDevice->BlockSize;
547 FvbDataPtr += Offset;
549 CopyMem (Buffer, FvbDataPtr, *NumBytes);
576 (FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||
577 (FwVolHeader->FvLength != EMU_FVB_SIZE) ||
578 (FwVolHeader->HeaderLength != EMU_FV_HEADER_LENGTH)
581 DEBUG ((DEBUG_INFO,
"EMU Variable FVB: Basic FV headers were invalid\n"));
582 return EFI_NOT_FOUND;
588 Checksum =
CalculateSum16 ((VOID *)FwVolHeader, FwVolHeader->HeaderLength);
591 DEBUG ((DEBUG_INFO,
"EMU Variable FVB: FV checksum was invalid\n"));
592 return EFI_NOT_FOUND;
616 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
619 EFI_SYSTEM_NV_DATA_FV_GUID,
631 EMU_FV_HEADER_LENGTH,
648 EMU_FVB_NUM_TOTAL_BLOCKS,
657 EFI_AUTHENTICATED_VARIABLE_GUID,
669 VARIABLE_STORE_HEALTHY,
686 &FvAndAuthenticatedVarTemplate,
687 sizeof FvAndAuthenticatedVarTemplate
719 RETURN_STATUS PcdStatus;
721 DEBUG ((DEBUG_INFO,
"EMU Variable FVB Started\n"));
728 EMU_FVB_BLOCK_SIZE == 0
731 (
PcdGet32 (PcdFlashNvStorageVariableSize) +
732 PcdGet32 (PcdFlashNvStorageFtwWorkingSize)
734 EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE
737 DEBUG ((DEBUG_ERROR,
"EMU Variable invalid PCD sizes\n"));
738 return EFI_INVALID_PARAMETER;
741 if (
PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
744 "Disabling EMU Variable FVB since "
745 "flash variables appear to be supported.\n"
759 if (
PcdGet64 (PcdEmuVariableNvStoreReserved) != 0) {
760 Ptr = (VOID *)(
UINTN)
PcdGet64 (PcdEmuVariableNvStoreReserved);
763 "EMU Variable FVB: Using pre-reserved block at %p\n",
767 if (!EFI_ERROR (Status)) {
768 DEBUG ((DEBUG_INFO,
"EMU Variable FVB: Found valid pre-existing FV\n"));
775 mEmuVarsFvb.BufferPtr = Ptr;
781 SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8);
785 PcdStatus =
PcdSet64S (PcdFlashNvStorageVariableBase64, (
UINTN)Ptr);
791 SubPtr = (VOID *)((UINT8 *)Ptr +
PcdGet32 (PcdFlashNvStorageVariableSize));
793 PcdFlashNvStorageFtwWorkingBase64,
801 SubPtr = (VOID *)((UINT8 *)Ptr +
802 EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE);
804 PcdFlashNvStorageFtwSpareBase64,
814 mEmuVarsFvb.DevicePath.MemMapDevPath.
EndingAddress = Address + EMU_FVB_SIZE - 1;
819 DEBUG ((DEBUG_INFO,
"Installing FVB for EMU Variable support\n"));
821 Status =
gBS->InstallMultipleProtocolInterfaces (
823 &gEfiFirmwareVolumeBlock2ProtocolGuid,
824 &mEmuVarsFvb.FwVolBlockInstance,
825 &gEfiDevicePathProtocolGuid,
826 &mEmuVarsFvb.DevicePath,
834 Status =
gBS->CreateEventEx (
839 &gEfiEventVirtualAddressChangeGuid,
840 &mEmuVarsFvbAddrChangeEvent
UINT16 EFIAPI CalculateSum16(IN CONST UINT16 *Buffer, IN UINTN Length)
UINT16 EFIAPI CalculateCheckSum16(IN CONST UINT16 *Buffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
#define HARDWARE_DEVICE_PATH
#define EFI_LBA_LIST_TERMINATOR
EFI_STATUS ValidateFvHeader(IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader)
EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address)
VOID EFIAPI FvbVirtualAddressChangeEvent(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI FvbProtocolGetBlockSize(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumberOfBlocks)
EFI_STATUS EFIAPI FvbInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI FvbProtocolGetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
EFI_STATUS EFIAPI FvbProtocolSetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
VOID InitializeFvAndVariableStoreHeaders(IN VOID *Ptr)
EFI_STATUS EFIAPI FvbProtocolRead(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, IN OUT UINT8 *Buffer)
EFI_STATUS EFIAPI FvbProtocolEraseBlocks(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,...)
EFI_STATUS EFIAPI FvbProtocolWrite(IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
#define VA_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define ASSERT_RETURN_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
#define FixedPcdGet32(TokenName)
#define PcdGet32(TokenName)
#define PcdSet64S(TokenName, Value)
UINT32 EFI_FVB_ATTRIBUTES_2
VOID *EFIAPI AllocateRuntimePages(IN UINTN Pages)
STATIC RETURN_STATUS Initialize(VOID)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)
EFI_STATUS EFIAPI EfiConvertPointer(IN UINTN DebugDisposition, IN OUT VOID **Address)
EFI_PHYSICAL_ADDRESS StartingAddress
EFI_PHYSICAL_ADDRESS EndingAddress