TianoCore EDK2 master
Loading...
Searching...
No Matches
FaultTolerantWriteDxe.c File Reference

Go to the source code of this file.

Functions

EFI_STATUS FtwGetFvbByHandle (IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
 
EFI_STATUS FtwGetSarProtocol (OUT VOID **SarProtocol)
 
EFI_STATUS GetFvbCountAndBuffer (OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
 
VOID EFIAPI FvbNotificationEvent (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS EFIAPI FaultTolerantWriteInitialize (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 
UINT32 FtwCalculateCrc32 (IN VOID *Buffer, IN UINTN Length)
 

Variables

VOID * mFvbRegistration = NULL
 

Detailed Description

This is a simple fault tolerant write driver.

This boot service protocol only provides fault tolerant write capability for block devices. The protocol has internal non-volatile intermediate storage of the data and private information. It should be able to recover automatically from a critical fault, such as power failure.

The implementation uses an FTW (Fault Tolerant Write) Work Space. This work space is a memory copy of the work space on the Working Block, the size of the work space is the FTW_WORK_SPACE_SIZE bytes.

The work space stores each write record as EFI_FTW_RECORD structure. The spare block stores the write buffer before write to the target block.

The write record has three states to specify the different phase of write operation. 1) WRITE_ALLOCATED is that the record is allocated in write space. The information of write operation is stored in write record structure. 2) SPARE_COMPLETED is that the data from write buffer is writed into the spare block as the backup. 3) WRITE_COMPLETED is that the data is copied from the spare block to the target block.

This driver operates the data as the whole size of spare block. It first read the SpareAreaLength data from the target block into the spare memory buffer. Then copy the write buffer data into the spare memory buffer. Then write the spare memory buffer into the spare block. Final copy the data from the spare block to the target block.

To make this drive work well, the following conditions must be satisfied:

  1. The write NumBytes data must be fit within Spare area. Offset + NumBytes <= SpareAreaLength
  2. The whole flash range has the same block size.
  3. Working block is an area which contains working space in its last block and has the same size as spare block.
  4. Working Block area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  5. Spare area must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  6. Any write data area (SpareAreaLength Area) which the data will be written into must be in the single one Firmware Volume Block range which FVB protocol is produced on.
  7. If write data area (such as Variable range) is enlarged, the spare area range must be enlarged. The spare area must be enough large to store the write data before write them into the target range. If one of them is not satisfied, FtwWrite may fail. Usually, Spare area only takes one block. That's SpareAreaLength = BlockSize, NumberOfSpareBlock = 1.

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

Definition in file FaultTolerantWriteDxe.c.

Function Documentation

◆ FaultTolerantWriteInitialize()

EFI_STATUS EFIAPI FaultTolerantWriteInitialize ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

This function is the entry point of the Fault Tolerant Write driver.

Parameters
[in]ImageHandleA handle for the image that is initializing this driver
[in]SystemTableA pointer to the EFI system table
Return values
EFI_SUCCESSThe initialization finished successfully.
EFI_OUT_OF_RESOURCESAllocate memory error
EFI_INVALID_PARAMETERWorkspace or Spare block does not exist

Definition at line 214 of file FaultTolerantWriteDxe.c.

◆ FtwCalculateCrc32()

UINT32 FtwCalculateCrc32 ( IN VOID *  Buffer,
IN UINTN  Length 
)

Internal implementation of CRC32. Depending on the execution context (traditional SMM or DXE vs standalone MM), this function is implemented via a call to the CalculateCrc32 () boot service, or via a library call.

If Buffer is NULL, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
[in]BufferA pointer to the buffer on which the 32-bit CRC is to be computed.
[in]LengthThe number of bytes in the buffer Data.
Return values
Crc32The 32-bit CRC was computed for the data buffer.

Definition at line 262 of file FaultTolerantWriteDxe.c.

◆ FtwGetFvbByHandle()

EFI_STATUS FtwGetFvbByHandle ( IN EFI_HANDLE  FvBlockHandle,
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **  FvBlock 
)

Retrieve the FVB protocol interface by HANDLE.

Parameters
[in]FvBlockHandleThe handle of FVB protocol that provides services for reading, writing, and erasing the target block.
[out]FvBlockThe interface of FVB protocol
Return values
EFI_SUCCESSThe interface information for the specified protocol was returned.
EFI_UNSUPPORTEDThe device does not support the FVB protocol.
EFI_INVALID_PARAMETERFvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.

Definition at line 65 of file FaultTolerantWriteDxe.c.

◆ FtwGetSarProtocol()

EFI_STATUS FtwGetSarProtocol ( OUT VOID **  SarProtocol)

Retrieve the Swap Address Range protocol interface.

Parameters
[out]SarProtocolThe interface of SAR protocol
Return values
EFI_SUCCESSThe SAR protocol instance was found and returned in SarProtocol.
EFI_NOT_FOUNDThe SAR protocol instance was not found.
EFI_INVALID_PARAMETERSarProtocol is NULL.

Definition at line 91 of file FaultTolerantWriteDxe.c.

◆ FvbNotificationEvent()

VOID EFIAPI FvbNotificationEvent ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Firmware Volume Block Protocol notification event handler.

Parameters
[in]EventEvent whose notification function is being invoked.
[in]ContextPointer to the notification function's context.

Definition at line 153 of file FaultTolerantWriteDxe.c.

◆ GetFvbCountAndBuffer()

EFI_STATUS GetFvbCountAndBuffer ( OUT UINTN NumberHandles,
OUT EFI_HANDLE **  Buffer 
)

Function returns an array of handles that support the FVB protocol in a buffer allocated from pool.

Parameters
[out]NumberHandlesThe number of handles returned in Buffer.
[out]BufferA pointer to the buffer to return the requested array of handles that support FVB protocol.
Return values
EFI_SUCCESSThe array of handles was returned in Buffer, and the number of handles in Buffer was returned in NumberHandles.
EFI_NOT_FOUNDNo FVB handle was found.
EFI_OUT_OF_RESOURCESThere is not enough pool memory to store the matching results.
EFI_INVALID_PARAMETERNumberHandles is NULL or Buffer is NULL.

Definition at line 124 of file FaultTolerantWriteDxe.c.

Variable Documentation

◆ mFvbRegistration

VOID* mFvbRegistration = NULL

Definition at line 50 of file FaultTolerantWriteDxe.c.