TianoCore EDK2 master
|
#include "FaultTolerantWrite.h"
Go to the source code of this file.
Internal generic functions to operate flash block.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file FtwMisc.c.
EFI_STATUS FindFvbForFtw | ( | IN OUT EFI_FTW_DEVICE * | FtwDevice | ) |
Find the proper Firmware Volume Block protocol for FTW operation.
[in,out] | FtwDevice | Pointer to the FTW device structure |
EFI_SUCCESS | Find the FVB protocol successfully. |
EFI_NOT_FOUND | No proper FVB protocol was found. |
EFI_ABORTED | Some data can not be got or be invalid. |
EFI_STATUS FlushSpareBlockToBootBlock | ( | EFI_FTW_DEVICE * | FtwDevice | ) |
Copy the content of spare block to a boot block. Size is FTW_BLOCK_SIZE. Spare block is accessed by FTW working FVB protocol interface. Target block is accessed by FvBlock protocol interface.
FTW will do extra work on boot block update. FTW should depend on a protocol of EFI_ADDRESS_RANGE_SWAP_PROTOCOL, which is produced by a chipset driver. FTW updating boot block steps may be:
FtwDevice | The private data of FTW driver |
EFI_SUCCESS | Spare block content is copied to boot block |
EFI_INVALID_PARAMETER | Input parameter error |
EFI_OUT_OF_RESOURCES | Allocate memory error |
EFI_ABORTED | The function could not complete successfully |
EFI_STATUS FlushSpareBlockToTargetBlock | ( | EFI_FTW_DEVICE * | FtwDevice, |
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL * | FvBlock, | ||
EFI_LBA | Lba, | ||
UINTN | BlockSize, | ||
UINTN | NumberOfBlocks | ||
) |
Copy the content of spare block to a target block. Spare block is accessed by FTW backup FVB protocol interface. Target block is accessed by FvBlock protocol interface.
FtwDevice | The private data of FTW driver |
FvBlock | FVB Protocol interface to access target block |
Lba | Lba of the target block |
BlockSize | The size of the block |
NumberOfBlocks | The number of consecutive blocks starting with Lba |
EFI_SUCCESS | Spare block content is copied to target block |
EFI_INVALID_PARAMETER | Input parameter error |
EFI_OUT_OF_RESOURCES | Allocate memory error |
EFI_ABORTED | The function could not complete successfully |
EFI_STATUS FlushSpareBlockToWorkingBlock | ( | EFI_FTW_DEVICE * | FtwDevice | ) |
Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE. Spare block is accessed by FTW backup FVB protocol interface. LBA is FtwDevice->FtwSpareLba. Working block is accessed by FTW working FVB protocol interface. LBA is FtwDevice->FtwWorkBlockLba.
Since the working block header is important when FTW initializes, the state of the operation should be handled carefully. The Crc value is calculated without STATE element.
FtwDevice | The private data of FTW driver |
EFI_SUCCESS | Spare block content is copied to target block |
EFI_OUT_OF_RESOURCES | Allocate memory error |
EFI_ABORTED | The function could not complete successfully |
EFI_STATUS FtwEraseBlock | ( | IN EFI_FTW_DEVICE * | FtwDevice, |
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL * | FvBlock, | ||
EFI_LBA | Lba, | ||
UINTN | NumberOfBlocks | ||
) |
To erase the block with specified blocks.
FtwDevice | The private data of FTW driver |
FvBlock | FVB Protocol interface |
Lba | Lba of the firmware block |
NumberOfBlocks | The number of consecutive blocks starting with Lba |
EFI_SUCCESS | Block LBA is Erased successfully |
Others | Error occurs |
EFI_STATUS FtwEraseSpareBlock | ( | IN EFI_FTW_DEVICE * | FtwDevice | ) |
Erase spare block.
FtwDevice | The private data of FTW driver |
EFI_SUCCESS | The erase request was successfully completed. |
EFI_ACCESS_DENIED | The firmware volume is in the WriteDisabled state. |
EFI_DEVICE_ERROR | The block device is not functioning correctly and could not be written. The firmware device may have been partially erased. |
EFI_INVALID_PARAMETER | One or more of the LBAs listed in the variable argument list do not exist in the firmware volume. |
EFI_STATUS FtwGetLastWriteHeader | ( | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER * | FtwWorkSpaceHeader, |
IN UINTN | FtwWorkSpaceSize, | ||
OUT EFI_FAULT_TOLERANT_WRITE_HEADER ** | FtwWriteHeader | ||
) |
Get the last Write Header pointer. The last write header is the header whose 'complete' state hasn't been set. After all, this header may be a EMPTY header entry for next Allocate.
FtwWorkSpaceHeader | Pointer of the working block header |
FtwWorkSpaceSize | Size of the work space |
FtwWriteHeader | Pointer to retrieve the last write header |
EFI_SUCCESS | Get the last write record successfully |
EFI_ABORTED | The FTW work space is damaged |
EFI_STATUS FtwGetLastWriteRecord | ( | IN EFI_FAULT_TOLERANT_WRITE_HEADER * | FtwWriteHeader, |
OUT EFI_FAULT_TOLERANT_WRITE_RECORD ** | FtwWriteRecord | ||
) |
Get the last Write Record pointer. The last write Record is the Record whose DestinationCompleted state hasn't been set. After all, this Record may be a EMPTY record entry for next write.
FtwWriteHeader | Pointer to the write record header |
FtwWriteRecord | Pointer to retrieve the last write record |
EFI_SUCCESS | Get the last write record successfully |
EFI_ABORTED | The FTW work space is damaged |
EFI_STATUS FtwUpdateFvState | ( | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL * | FvBlock, |
IN UINTN | BlockSize, | ||
IN EFI_LBA | Lba, | ||
IN UINTN | Offset, | ||
IN UINT8 | NewBit | ||
) |
Update a bit of state on a block device. The location of the bit is calculated by the (Lba, Offset, bit). Here bit is determined by the the name of a certain bit.
FvBlock | FVB Protocol interface to access SrcBlock and DestBlock |
BlockSize | The size of the block |
Lba | Lba of a block |
Offset | Offset on the Lba |
NewBit | New value that will override the old value if it can be change |
EFI_SUCCESS | A state bit has been updated successfully |
Others | Access block device error. Notes: Assume all bits of State are inside the same BYTE. |
EFI_ABORTED | Read block fail |
EFI_HANDLE GetFvbByAddress | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL ** | FvBlock | ||
) |
EFI_STATUS GetPreviousRecordOfWrites | ( | IN EFI_FAULT_TOLERANT_WRITE_HEADER * | FtwHeader, |
IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD ** | FtwRecord | ||
) |
To check if FtwRecord is the first record of FtwHeader.
FtwHeader | Pointer to the write record header |
FtwRecord | Pointer to retrieve the previous write record |
EFI_ACCESS_DENIED | Input record is the first record, no previous record is return. |
EFI_SUCCESS | The previous write record is found. |
EFI_STATUS InitFtwDevice | ( | OUT EFI_FTW_DEVICE ** | FtwData | ) |
Allocate private data for FTW driver and initialize it.
[out] | FtwData | Pointer to the FTW device structure |
EFI_SUCCESS | Initialize the FTW device successfully. |
EFI_OUT_OF_RESOURCES | Allocate memory error |
EFI_INVALID_PARAMETER | Workspace or Spare block does not exist |
EFI_STATUS InitFtwProtocol | ( | IN OUT EFI_FTW_DEVICE * | FtwDevice | ) |
BOOLEAN IsBootBlock | ( | EFI_FTW_DEVICE * | FtwDevice, |
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL * | FvBlock | ||
) |
BOOLEAN IsFirstRecordOfWrites | ( | IN EFI_FAULT_TOLERANT_WRITE_HEADER * | FtwHeader, |
IN EFI_FAULT_TOLERANT_WRITE_RECORD * | FtwRecord | ||
) |
To check if FtwRecord is the first record of FtwHeader.
FtwHeader | Pointer to the write record header |
FtwRecord | Pointer to the write record |
TRUE | FtwRecord is the first Record of the FtwHeader |
FALSE | FtwRecord is not the first Record of the FtwHeader |
BOOLEAN IsLastRecordOfWrites | ( | IN EFI_FAULT_TOLERANT_WRITE_HEADER * | FtwHeader, |
IN EFI_FAULT_TOLERANT_WRITE_RECORD * | FtwRecord | ||
) |
To check if FtwRecord is the last record of FtwHeader. Because the FtwHeader has NumberOfWrites & PrivateDataSize, the FtwRecord can be determined if it is the last record of FtwHeader.
FtwHeader | Pointer to the write record header |
FtwRecord | Pointer to the write record |
TRUE | FtwRecord is the last Record of the FtwHeader |
FALSE | FtwRecord is not the last Record of the FtwHeader |
BOOLEAN IsWorkingBlock | ( | EFI_FTW_DEVICE * | FtwDevice, |
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL * | FvBlock, | ||
EFI_LBA | Lba | ||
) |