TianoCore EDK2 master
Loading...
Searching...
No Matches
FvbService.c File Reference
#include "FvbService.h"

Go to the source code of this file.

Functions

EFI_FW_VOL_INSTANCEGetFvbInstance (IN UINTN Instance)
 
STATIC EFI_FVB_ATTRIBUTES_2 FvbGetVolumeAttributes (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 FvbReadBlock (IN UINTN Instance, IN EFI_LBA Lba, IN UINTN BlockOffset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
 
EFI_STATUS FvbWriteBlock (IN UINTN Instance, IN EFI_LBA Lba, IN UINTN BlockOffset, IN OUT UINTN *NumBytes, IN UINT8 *Buffer)
 
EFI_STATUS FvbEraseBlock (IN UINTN Instance, IN EFI_LBA Lba)
 
STATIC EFI_STATUS FvbSetVolumeAttributes (IN UINTN Instance, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
 
EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address)
 
EFI_STATUS EFIAPI FvbProtocolGetBlockSize (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks)
 
EFI_STATUS EFIAPI FvbProtocolGetAttributes (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
 
EFI_STATUS EFIAPI FvbProtocolSetAttributes (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
 
EFI_STATUS EFIAPI FvbProtocolEraseBlocks (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,...)
 
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 FvbProtocolRead (IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, OUT UINT8 *Buffer)
 
BOOLEAN IsFvHeaderValid (IN EFI_PHYSICAL_ADDRESS FvBase)
 
EFI_STATUS GetInitialVariableData (OUT VOID **VarData, OUT UINTN *VarSize)
 
EFI_STATUS FvbInitialize (VOID)
 

Variables

FWB_GLOBAL mFvbModuleGlobal
 
FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate
 
FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate
 
EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate
 

Detailed Description

Firmware Volume Block Driver to provide FVB service.

Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file FvbService.c.

Function Documentation

◆ FvbEraseBlock()

EFI_STATUS FvbEraseBlock ( IN UINTN  Instance,
IN EFI_LBA  Lba 
)

Erases and initializes a firmware volume block

Parameters
[in]InstanceThe FV instance to be erased
[in]LbaThe logical block index to be erased
Return values
EFI_SUCCESSThe erase request was successfully completed
EFI_ACCESS_DENIEDThe firmware volume is in the WriteDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be written. Firmware device may have been partially erased
EFI_INVALID_PARAMETERInstance not found

Definition at line 405 of file FvbService.c.

◆ FvbGetLbaAddress()

STATIC EFI_STATUS FvbGetLbaAddress ( IN UINTN  Instance,
IN EFI_LBA  Lba,
OUT UINTN LbaAddress,
OUT UINTN LbaLength,
OUT UINTN NumOfBlocks 
)

Retrieves the starting address of an LBA in an FV. It also return a few other attribut of the FV.

Parameters
[in]InstanceThe index of the EFI_FW_VOL_INSTANCE.
[in]LbaThe logical block address
[out]LbaAddressOn output, contains the physical starting address of the Lba
[out]LbaLengthOn output, contains the length of the block
[out]NumOfBlocksA pointer to a caller allocated UINTN in which the number of consecutive blocks starting with Lba is returned. All blocks in this range have a size of BlockSize
Return values
EFI_SUCCESSSuccessfully returns
EFI_INVALID_PARAMETERInstance not found

Definition at line 162 of file FvbService.c.

◆ FvbGetVolumeAttributes()

STATIC EFI_FVB_ATTRIBUTES_2 FvbGetVolumeAttributes ( IN UINTN  Instance)

Get the EFI_FVB_ATTRIBUTES_2 of a FV.

Parameters
[in]InstanceThe index of the EFI_FW_VOL_INSTANCE.
Return values
EFI_FVB_ATTRIBUTES_2of the FV identified by Instance.

Definition at line 126 of file FvbService.c.

◆ FvbInitialize()

EFI_STATUS FvbInitialize ( VOID  )

The function does the necessary initialization work for Firmware Volume Block Driver.

Return values
EFI_SUCCESSThis funtion always return EFI_SUCCESS. It will ASSERT on errors.

Definition at line 996 of file FvbService.c.

◆ FvbProtocolEraseBlocks()

EFI_STATUS EFIAPI FvbProtocolEraseBlocks ( IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL This,
  ... 
)

This function erases one or more blocks as denoted by the variable argument list. The entire parameter list of blocks must be verified prior to erasing any blocks. If a block is requested that does not exist within the associated firmware volume (it has a larger index than the last block of the firmware volume), the EraseBlock() function must return EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.

Parameters
[in]ThisCalling context
[in]...Starting LBA followed by Number of Lba to erase. a -1 to terminate the list.
Return values
EFI_SUCCESSThe erase request was successfully completed
EFI_ACCESS_DENIEDThe firmware volume is in the WriteDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be written. Firmware device may have been partially erased

Definition at line 704 of file FvbService.c.

◆ FvbProtocolGetAttributes()

EFI_STATUS EFIAPI FvbProtocolGetAttributes ( IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL This,
OUT EFI_FVB_ATTRIBUTES_2 Attributes 
)

Retrieves Volume attributes. No polarity translations are done.

Parameters
[in]ThisCalling context
[out]AttributesOutput buffer which contains attributes
Return values
EFI_SUCCESSThe function always return successfully.

Definition at line 646 of file FvbService.c.

◆ FvbProtocolGetBlockSize()

EFI_STATUS EFIAPI FvbProtocolGetBlockSize ( IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL This,
IN EFI_LBA  Lba,
OUT UINTN BlockSize,
OUT UINTN NumOfBlocks 
)

Retrieve the size of a logical block

Parameters
[in]ThisCalling context
[in]LbaIndicates which block to return the size for.
[out]BlockSizeA pointer to a caller allocated UINTN in which the size of the block is returned
[out]NumOfBlocksA pointer to a caller allocated UINTN in which the number of consecutive blocks starting with Lba is returned. All blocks in this range have a size of BlockSize
Return values
EFI_SUCCESSThe function always return successfully.

Definition at line 622 of file FvbService.c.

◆ FvbProtocolGetPhysicalAddress()

EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress ( IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL This,
OUT EFI_PHYSICAL_ADDRESS Address 
)

Retrieves the physical address of the device.

Parameters
[in]ThisA pointer to EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL.
[out]AddressOutput buffer containing the address.
Return values
EFI_SUCCESSThe function always return successfully.
EFI_INVALID_PARAMETERInstance not found.

Definition at line 587 of file FvbService.c.

◆ FvbProtocolRead()

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 
)

Reads data beginning at Lba:Offset from FV. The Read terminates either when *NumBytes of data have been read, or when a block boundary is reached. *NumBytes is updated to reflect the actual number of bytes written. The write opertion does not include erase. This routine will attempt to write only the specified bytes. If the writes do not stick, it will return an error.

Parameters
[in]ThisCalling context
[in]LbaBlock in which to begin write
[in]OffsetOffset in the block at which to begin write
[in,out]NumBytesOn input, indicates the requested write size. On output, indicates the actual number of bytes written
[out]BufferBuffer containing source data for the write.

Returns:

Return values
EFI_SUCCESSThe firmware volume was read successfully and contents are in Buffer
EFI_BAD_BUFFER_SIZERead attempted across a LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer
EFI_ACCESS_DENIEDThe firmware volume is in the ReadDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be read
EFI_INVALID_PARAMETERNumBytes or Buffer are NULL

Definition at line 858 of file FvbService.c.

◆ FvbProtocolSetAttributes()

EFI_STATUS EFIAPI FvbProtocolSetAttributes ( IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL This,
IN OUT EFI_FVB_ATTRIBUTES_2 Attributes 
)

Sets Volume attributes. No polarity translations are done.

Parameters
[in]ThisCalling context
[in,out]AttributesOutput buffer which contains attributes
Return values
EFI_SUCCESSThe function always return successfully.

Definition at line 670 of file FvbService.c.

◆ FvbProtocolWrite()

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 
)

Writes data beginning at Lba:Offset from FV. The write terminates either when *NumBytes of data have been written, or when a block boundary is reached. *NumBytes is updated to reflect the actual number of bytes written. The write opertion does not include erase. This routine will attempt to write only the specified bytes. If the writes do not stick, it will return an error.

Parameters
[in]ThisCalling context
[in]LbaBlock in which to begin write
[in]OffsetOffset in the block at which to begin write
[in,out]NumBytesOn input, indicates the requested write size. On output, indicates the actual number of bytes written
[in]BufferBuffer containing source data for the write.
Return values
EFI_SUCCESSThe firmware volume was written successfully
EFI_BAD_BUFFER_SIZEWrite attempted across a LBA boundary. On output, NumBytes contains the total number of bytes actually written
EFI_ACCESS_DENIEDThe firmware volume is in the WriteDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be written
EFI_INVALID_PARAMETERNumBytes or Buffer are NULL

Definition at line 802 of file FvbService.c.

◆ FvbReadBlock()

STATIC EFI_STATUS FvbReadBlock ( IN UINTN  Instance,
IN EFI_LBA  Lba,
IN UINTN  BlockOffset,
IN OUT UINTN NumBytes,
IN UINT8 *  Buffer 
)

Reads specified number of bytes into a buffer from the specified block

Parameters
[in]InstanceThe FV instance to be read from
[in]LbaThe logical block address to be read from
[in]BlockOffsetOffset into the block at which to begin reading
[in,out]NumBytesPointer that on input contains the total size of the buffer. On output, it contains the total number of bytes read
[in]BufferPointer to a caller allocated buffer that will be used to hold the data read
Return values
EFI_SUCCESSThe firmware volume was read successfully and contents are in Buffer
EFI_BAD_BUFFER_SIZERead attempted across a LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer
EFI_ACCESS_DENIEDThe firmware volume is in the ReadDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be read
EFI_INVALID_PARAMETERInstance not found, or NumBytes, Buffer are NULL

Definition at line 258 of file FvbService.c.

◆ FvbSetVolumeAttributes()

STATIC EFI_STATUS FvbSetVolumeAttributes ( IN UINTN  Instance,
IN OUT EFI_FVB_ATTRIBUTES_2 Attributes 
)

Modifies the current settings of the firmware volume according to the input parameter, and returns the new setting of the volume

Parameters
[in]InstanceThe FV instance whose attributes is going to be modified
[in,out]AttributesOn input, it is a pointer to EFI_FVB_ATTRIBUTES_2 containing the desired firmware volume settings. On successful return, it contains the new settings of the firmware volume
Return values
EFI_SUCCESSSuccessfully returns
EFI_ACCESS_DENIEDThe volume setting is locked and cannot be modified
EFI_INVALID_PARAMETERInstance not found, or The attributes requested are in conflict with the capabilities as declared in the firmware volume header

Definition at line 463 of file FvbService.c.

◆ FvbWriteBlock()

EFI_STATUS FvbWriteBlock ( IN UINTN  Instance,
IN EFI_LBA  Lba,
IN UINTN  BlockOffset,
IN OUT UINTN NumBytes,
IN UINT8 *  Buffer 
)

Writes specified number of bytes from the input buffer to the block

Parameters
[in]InstanceThe FV instance to be written to
[in]LbaThe starting logical block index to write to
[in]BlockOffsetOffset into the block at which to begin writing
[in,out]NumBytesPointer that on input contains the total size of the buffer. On output, it contains the total number of bytes actually written
[in]BufferPointer to a caller allocated buffer that contains the source for the write
Return values
EFI_SUCCESSThe firmware volume was written successfully
EFI_BAD_BUFFER_SIZEWrite attempted across a LBA boundary. On output, NumBytes contains the total number of bytes actually written
EFI_ACCESS_DENIEDThe firmware volume is in the WriteDisabled state
EFI_DEVICE_ERRORThe block device is not functioning correctly and could not be written
EFI_INVALID_PARAMETERInstance not found, or NumBytes, Buffer are NULL

Definition at line 330 of file FvbService.c.

◆ GetFvbInstance()

EFI_FW_VOL_INSTANCE * GetFvbInstance ( IN UINTN  Instance)

Get the pointer to EFI_FW_VOL_INSTANCE from the buffer pointed by mFvbModuleGlobal.FvInstance based on a index. Each EFI_FW_VOL_INSTANCE is with variable length as we have a block map at the end of the EFI_FIRMWARE_VOLUME_HEADER.

Parameters
[in]InstanceThe index of the EFI_FW_VOL_INSTANCE.
Returns
A pointer to EFI_FW_VOL_INSTANCE.

Definition at line 91 of file FvbService.c.

◆ GetInitialVariableData()

EFI_STATUS GetInitialVariableData ( OUT VOID **  VarData,
OUT UINTN VarSize 
)

Get intial variable data.

Parameters
[out]VarDataValid variable data.
[out]VarSizeValid variable size.
Return values
RETURN_SUCCESSSuccessfully found initial variable data.
RETURN_NOT_FOUNDFailed to find the variable data file from FV.
EFI_INVALID_PARAMETERVarData or VarSize is null.

Definition at line 945 of file FvbService.c.

◆ IsFvHeaderValid()

BOOLEAN IsFvHeaderValid ( IN EFI_PHYSICAL_ADDRESS  FvBase)

Check the integrity of firmware volume header in FvBase

Parameters
[in]FvBaseA pointer to firmware volume base address.
Return values
TRUEThe firmware volume is consistent
FALSEThe firmware volume has corrupted.

Definition at line 894 of file FvbService.c.

Variable Documentation

◆ mFvbDeviceTemplate

EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate
Initial value:
= {
FVB_DEVICE_SIGNATURE,
0,
{
}
}
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)
Definition: FvbService.c:858
EFI_STATUS EFIAPI FvbProtocolSetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
Definition: FvbService.c:670
EFI_STATUS EFIAPI FvbProtocolEraseBlocks(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,...)
Definition: FvbService.c:704
EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address)
Definition: FvbService.c:587
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)
Definition: FvbService.c:802
EFI_STATUS EFIAPI FvbProtocolGetBlockSize(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks)
Definition: FvbService.c:622
EFI_STATUS EFIAPI FvbProtocolGetAttributes(IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes)
Definition: FvbService.c:646
#define NULL
Definition: Base.h:319

Definition at line 63 of file FvbService.c.

◆ mFvbModuleGlobal

FWB_GLOBAL mFvbModuleGlobal

Definition at line 15 of file FvbService.c.

◆ mFvMemmapDevicePathTemplate

FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate
Initial value:
= {
{
{
{
(UINT8)(sizeof (MEMMAP_DEVICE_PATH)),
(UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8)
}
},
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
END_DEVICE_PATH_LENGTH,
0
}
}
}
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_MEMMAP_DP
Definition: DevicePath.h:109
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
@ EfiMemoryMappedIO

Definition at line 17 of file FvbService.c.

◆ mFvPIWGDevicePathTemplate

FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate
Initial value:
= {
{
{
MEDIA_DEVICE_PATH,
{
(UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)),
(UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8)
}
},
{ 0 }
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
END_DEVICE_PATH_LENGTH,
0
}
}
}
#define MEDIA_PIWG_FW_VOL_DP
Definition: DevicePath.h:1146

Definition at line 41 of file FvbService.c.