33 END_ENTIRE_DEVICE_PATH_SUBTYPE,
35 END_DEVICE_PATH_LENGTH,
55 END_ENTIRE_DEVICE_PATH_SUBTYPE,
57 END_DEVICE_PATH_LENGTH,
97 if ( Instance >= mFvbModuleGlobal.NumFv ) {
105 FwhRecord = mFvbModuleGlobal.FvInstance;
106 while ( Instance > 0 ) {
133 ASSERT (FwInstance !=
NULL);
135 if (FwInstance ==
NULL) {
182 if (FwhInstance ==
NULL) {
183 return EFI_INVALID_PARAMETER;
188 BlockMap = &FwhInstance->VolumeHeader.
BlockMap[0];
189 ASSERT (BlockMap !=
NULL);
195 if ( BlockMap !=
NULL) {
197 BlockLength = BlockMap->
Length;
200 if ((NumBlocks == 0) || (BlockLength == 0)) {
201 return EFI_INVALID_PARAMETER;
204 NextLba = StartLba + NumBlocks;
209 if ((Lba >= StartLba) && (Lba < NextLba)) {
211 if (LbaAddress !=
NULL) {
212 *LbaAddress = FwhInstance->FvBase + Offset;
215 if (LbaLength !=
NULL) {
216 *LbaLength = BlockLength;
219 if (NumOfBlocks !=
NULL) {
220 *NumOfBlocks = (
UINTN)(NextLba - Lba);
227 Offset = Offset + NumBlocks * BlockLength;
272 if ((NumBytes ==
NULL) || (Buffer ==
NULL)) {
273 return (EFI_INVALID_PARAMETER);
276 if (*NumBytes == 0) {
277 return (EFI_INVALID_PARAMETER);
281 if (EFI_ERROR (Status)) {
287 if ((Attributes & EFI_FVB2_READ_STATUS) == 0) {
288 return (EFI_ACCESS_DENIED);
291 if (BlockOffset > LbaLength) {
292 return (EFI_INVALID_PARAMETER);
295 if (LbaLength < (*NumBytes + BlockOffset)) {
296 *NumBytes = (UINT32)(LbaLength - BlockOffset);
297 Status = EFI_BAD_BUFFER_SIZE;
343 if ((NumBytes ==
NULL) || (Buffer ==
NULL)) {
344 return (EFI_INVALID_PARAMETER);
347 if (*NumBytes == 0) {
348 return (EFI_INVALID_PARAMETER);
352 if (EFI_ERROR (Status)) {
360 if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {
361 return EFI_ACCESS_DENIED;
367 if (BlockOffset > LbaLength) {
368 return EFI_INVALID_PARAMETER;
371 if ( LbaLength < (*NumBytes + BlockOffset)) {
374 "FvWriteBlock: Reducing Numbytes from 0x%x to 0x%x\n",
376 (UINT32)(LbaLength - BlockOffset)
378 *NumBytes = (UINT32)(LbaLength - BlockOffset);
379 return EFI_BAD_BUFFER_SIZE;
420 if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {
421 return (EFI_ACCESS_DENIED);
428 if (EFI_ERROR (Status)) {
480 if (FwhInstance ==
NULL) {
481 return EFI_INVALID_PARAMETER;
485 ASSERT (AttribPtr !=
NULL);
486 if ( AttribPtr ==
NULL) {
487 return EFI_INVALID_PARAMETER;
490 OldAttributes = *AttribPtr;
491 Capabilities = OldAttributes & EFI_FVB2_CAPABILITIES;
492 OldStatus = OldAttributes & EFI_FVB2_STATUS;
493 NewStatus = *Attributes & EFI_FVB2_STATUS;
495 UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP | \
496 EFI_FVB2_READ_ENABLED_CAP | \
497 EFI_FVB2_WRITE_DISABLED_CAP | \
498 EFI_FVB2_WRITE_ENABLED_CAP | \
499 EFI_FVB2_LOCK_CAP | \
500 EFI_FVB2_STICKY_WRITE | \
501 EFI_FVB2_MEMORY_MAPPED | \
502 EFI_FVB2_ERASE_POLARITY | \
503 EFI_FVB2_READ_LOCK_CAP | \
504 EFI_FVB2_WRITE_LOCK_CAP | \
510 if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {
511 return EFI_INVALID_PARAMETER;
517 if ((OldAttributes & EFI_FVB2_LOCK_STATUS) != 0) {
518 if ((OldStatus ^ NewStatus) != 0) {
519 return EFI_ACCESS_DENIED;
526 if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {
527 if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {
528 return EFI_INVALID_PARAMETER;
535 if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {
536 if ((NewStatus & EFI_FVB2_READ_STATUS) != 0) {
537 return EFI_INVALID_PARAMETER;
544 if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {
545 if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {
546 return EFI_INVALID_PARAMETER;
553 if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {
554 if ((NewStatus & EFI_FVB2_WRITE_STATUS) != 0) {
555 return EFI_INVALID_PARAMETER;
562 if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {
563 if ((NewStatus & EFI_FVB2_LOCK_STATUS) != 0) {
564 return EFI_INVALID_PARAMETER;
568 *AttribPtr = (*AttribPtr) & (0xFFFFFFFF & (~EFI_FVB2_STATUS));
569 *AttribPtr = (*AttribPtr) | NewStatus;
570 *Attributes = *AttribPtr;
595 FvbDevice = FVB_DEVICE_FROM_THIS (This);
597 if (FwhInstance ==
NULL) {
598 return EFI_INVALID_PARAMETER;
601 *Address = FwhInstance->FvBase;
631 FvbDevice = FVB_DEVICE_FROM_THIS (This);
653 FvbDevice = FVB_DEVICE_FROM_THIS (This);
678 FvbDevice = FVB_DEVICE_FROM_THIS (This);
717 FvbDevice = FVB_DEVICE_FROM_THIS (This);
719 if (FwhInstance ==
NULL) {
720 return EFI_OUT_OF_RESOURCES;
723 NumOfBlocks = FwhInstance->NumOfBlocks;
732 NumOfLba =
VA_ARG (args, UINT32);
739 return EFI_INVALID_PARAMETER;
742 if ((StartingLba + NumOfLba) > NumOfBlocks ) {
743 return EFI_INVALID_PARAMETER;
756 NumOfLba =
VA_ARG (args, UINT32);
758 while ( NumOfLba > 0 ) {
760 if ( EFI_ERROR (Status)) {
813 FvbDevice = FVB_DEVICE_FROM_THIS (This);
814 Status =
FvbWriteBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer);
817 "FvbWrite: Lba: 0x%lx Offset: 0x%x NumBytes: 0x%x, Buffer: 0x%x Status:%r\n",
869 FvbDevice = FVB_DEVICE_FROM_THIS (This);
870 Status =
FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer);
873 "FvbRead: Lba: 0x%lx Offset: 0x%x NumBytes: 0x%x, Buffer: 0x%x, Status:%r\n",
902 if (FvBase ==
PcdGet32 (PcdFlashNvStorageVariableBase)) {
909 DEBUG ((DEBUG_INFO,
" --not expected guid.\n"));
915 (FwVolHeader->
Signature != EFI_FVH_SIGNATURE) ||
919 DEBUG ((DEBUG_INFO,
" -- >Revision = 0x%x, Signature = 0x%x\n", FwVolHeader->
Revision, FwVolHeader->
Signature));
926 DEBUG ((DEBUG_INFO,
"error: checksum: 0x%04X (expect 0x0)\n", Sum));
959 if ((VarData ==
NULL) || (VarSize ==
NULL)) {
960 return EFI_INVALID_PARAMETER;
964 if (EFI_ERROR (Status)) {
970 VarEndAddr = (
UINTN)VariableStore + VariableStore->
Size;
972 *VarData = (VOID *)Variable;
973 while (((
UINTN)Variable < VarEndAddr)) {
982 *VarSize = (
UINTN)Variable - HEADER_ALIGN (VariableStore + 1);
1012 BaseAddress =
PcdGet32 (PcdFlashNvStorageVariableBase);
1022 DEBUG ((DEBUG_ERROR,
"Fvb: Writing back a healthy FV header: 0x%lx\n", BaseAddress));
1030 WriteAddr = (
UINTN)BaseAddress;
1032 WriteAddr += Length;
1038 VariableStore.
Size =
PcdGet32 (PcdFlashNvStorageVariableSize) - FvHeader->HeaderLength;
1040 VariableStore.
State = VARIABLE_STORE_HEALTHY;
1044 WriteAddr += BufferSize;
1051 if (!EFI_ERROR (Status)) {
1065 if (FwVolInstance ==
NULL) {
1066 return EFI_OUT_OF_RESOURCES;
1069 FwVolInstance->FvBase = (
UINTN)BaseAddress;
1075 FwVolInstance->NumOfBlocks = 0;
1076 FvHeader = &FwVolInstance->VolumeHeader;
1078 FwVolInstance->NumOfBlocks += BlockMap->
NumBlocks;
1085 mFvbModuleGlobal.NumFv++;
1086 mFvbModuleGlobal.FvInstance = FwVolInstance;
VOID *EFIAPI WriteBackInvalidateDataCacheRange(IN VOID *Address, IN UINTN Length)
UINT16 EFIAPI CalculateSum16(IN CONST UINT16 *Buffer, IN UINTN Length)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
#define HARDWARE_DEVICE_PATH
#define MEDIA_PIWG_FW_VOL_DP
EFI_STATUS EFIAPI GetSectionFromAnyFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
#define EFI_LBA_LIST_TERMINATOR
EFI_STATUS EFIAPI LibFvbFlashDeviceRead(IN UINTN PAddress, IN OUT UINTN *NumBytes, OUT UINT8 *Buffer)
EFI_STATUS EFIAPI LibFvbFlashDeviceBlockLock(IN UINTN PAddress, IN UINTN LbaLength, IN BOOLEAN Lock)
EFI_STATUS EFIAPI LibFvbFlashDeviceBlockErase(IN UINTN PAddress, IN UINTN LbaLength)
EFI_STATUS EFIAPI LibFvbFlashDeviceWrite(IN UINTN PAddress, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
EFI_STATUS EFIAPI FvbProtocolRead(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, OUT UINT8 *Buffer)
EFI_STATUS EFIAPI FvbProtocolSetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
EFI_STATUS FvbInitialize(VOID)
BOOLEAN IsFvHeaderValid(IN EFI_PHYSICAL_ADDRESS FvBase)
EFI_FW_VOL_INSTANCE * GetFvbInstance(IN UINTN Instance)
STATIC EFI_STATUS FvbGetLbaAddress(IN UINTN Instance, IN EFI_LBA Lba, OUT UINTN *LbaAddress, OUT UINTN *LbaLength, OUT UINTN *NumOfBlocks)
STATIC EFI_STATUS FvbSetVolumeAttributes(IN UINTN Instance, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
EFI_STATUS EFIAPI FvbProtocolEraseBlocks(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,...)
EFI_STATUS FvbWriteBlock(IN UINTN Instance, IN EFI_LBA Lba, IN UINTN BlockOffset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address)
EFI_STATUS EFIAPI FvbProtocolWrite(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
EFI_STATUS EFIAPI FvbProtocolGetBlockSize(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks)
EFI_STATUS FvbEraseBlock(IN UINTN Instance, IN EFI_LBA Lba)
STATIC EFI_FVB_ATTRIBUTES_2 FvbGetVolumeAttributes(IN UINTN Instance)
STATIC EFI_STATUS FvbReadBlock(IN UINTN Instance, IN EFI_LBA Lba, IN UINTN BlockOffset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
EFI_STATUS GetInitialVariableData(OUT VOID **VarData, OUT UINTN *VarSize)
EFI_STATUS EFIAPI FvbProtocolGetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
EFI_STATUS InstallFvbProtocol(IN EFI_FW_VOL_INSTANCE *FwhInstance, IN UINTN InstanceNum)
#define VA_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
#define PcdGetPtr(TokenName)
UINT32 EFI_FVB_ATTRIBUTES_2
EFI_STATUS EFIAPI ReadStatus(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 LengthInBytes, OUT UINT8 *FlashStatus)
UINT64 EFI_PHYSICAL_ADDRESS
EFI_STATUS InitVariableStore(VOID)
EFI_FIRMWARE_VOLUME_HEADER * GetFvHeaderTemplate(VOID)
EFI_FV_BLOCK_MAP_ENTRY BlockMap[1]
EFI_FVB_ATTRIBUTES_2 Attributes