diff options
author | Michael Kubacki <michael.kubacki@microsoft.com> | 2021-12-05 14:54:02 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2021-12-07 17:24:28 +0000 |
commit | 1436aea4d5707e672672a11bda72be2c63c936c3 (patch) | |
tree | 370c9d5bd8823aa8ea7bce71a0f29bff71feff67 /MdeModulePkg/Universal/FaultTolerantWriteDxe | |
parent | 7c7184e201a90a1d2376e615e55e3f4074731468 (diff) | |
download | edk2-1436aea4d5707e672672a11bda72be2c63c936c3.zip edk2-1436aea4d5707e672672a11bda72be2c63c936c3.tar.gz edk2-1436aea4d5707e672672a11bda72be2c63c936c3.tar.bz2 |
MdeModulePkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737
Apply uncrustify changes to .c/.h files in the MdeModulePkg package
Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Diffstat (limited to 'MdeModulePkg/Universal/FaultTolerantWriteDxe')
11 files changed, 851 insertions, 768 deletions
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c index dbe5c00..53f9aef 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Fault Tolerant Write Protocol API
//
+
/**
Query the largest block that may be updated in a fault tolerant manner.
@@ -27,19 +28,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS
EFIAPI
FtwGetMaxBlockSize (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT UINTN *BlockSize
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT UINTN *BlockSize
)
{
EFI_FTW_DEVICE *FtwDevice;
- if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
+ if (!FeaturePcdGet (PcdFullFtwServiceEnable)) {
return EFI_UNSUPPORTED;
}
- FtwDevice = FTW_CONTEXT_FROM_THIS (This);
+ FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- *BlockSize = FtwDevice->SpareAreaLength;
+ *BlockSize = FtwDevice->SpareAreaLength;
return EFI_SUCCESS;
}
@@ -68,23 +69,24 @@ FtwGetMaxBlockSize ( EFI_STATUS
EFIAPI
FtwAllocate (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_GUID *CallerId,
- IN UINTN PrivateDataSize,
- IN UINTN NumberOfWrites
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_GUID *CallerId,
+ IN UINTN PrivateDataSize,
+ IN UINTN NumberOfWrites
)
{
- EFI_STATUS Status;
- UINTN Offset;
- EFI_FTW_DEVICE *FtwDevice;
- EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader;
+ EFI_STATUS Status;
+ UINTN Offset;
+ EFI_FTW_DEVICE *FtwDevice;
+ EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader;
FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- Status = WorkSpaceRefresh (FtwDevice);
+ Status = WorkSpaceRefresh (FtwDevice);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
+
//
// Check if there is enough space for the coming allocation
//
@@ -92,6 +94,7 @@ FtwAllocate ( DEBUG ((DEBUG_ERROR, "Ftw: Allocate() request exceed Workspace, Caller: %g\n", CallerId));
return EFI_BUFFER_TOO_SMALL;
}
+
//
// Find the last write header and record.
// If the FtwHeader is complete, skip the completed last write header/records
@@ -104,10 +107,11 @@ FtwAllocate ( if ((FtwHeader->HeaderAllocated == FTW_VALID_STATE) || (FtwHeader->WritesAllocated == FTW_VALID_STATE)) {
return EFI_ACCESS_DENIED;
}
+
//
// If workspace is not enough, then reclaim workspace
//
- Offset = (UINT8 *) FtwHeader - (UINT8 *) FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)FtwHeader - (UINT8 *)FtwDevice->FtwWorkSpace;
if (Offset + FTW_WRITE_TOTAL_SIZE (NumberOfWrites, PrivateDataSize) > FtwDevice->FtwWorkSpaceSize) {
Status = FtwReclaimWorkSpace (FtwDevice, TRUE);
if (EFI_ERROR (Status)) {
@@ -116,16 +120,17 @@ FtwAllocate ( FtwHeader = FtwDevice->FtwLastWriteHeader;
}
+
//
// Prepare FTW write header,
// overwrite the buffer and write to workspace.
//
- FtwHeader->WritesAllocated = FTW_INVALID_STATE;
- FtwHeader->Complete = FTW_INVALID_STATE;
+ FtwHeader->WritesAllocated = FTW_INVALID_STATE;
+ FtwHeader->Complete = FTW_INVALID_STATE;
CopyMem (&FtwHeader->CallerId, CallerId, sizeof (EFI_GUID));
- FtwHeader->NumberOfWrites = NumberOfWrites;
- FtwHeader->PrivateDataSize = PrivateDataSize;
- FtwHeader->HeaderAllocated = FTW_VALID_STATE;
+ FtwHeader->NumberOfWrites = NumberOfWrites;
+ FtwHeader->PrivateDataSize = PrivateDataSize;
+ FtwHeader->HeaderAllocated = FTW_VALID_STATE;
Status = WriteWorkSpaceData (
FtwDevice->FtwFvBlock,
@@ -133,36 +138,36 @@ FtwAllocate ( FtwDevice->FtwWorkSpaceLba,
FtwDevice->FtwWorkSpaceBase + Offset,
sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER),
- (UINT8 *) FtwHeader
+ (UINT8 *)FtwHeader
);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
+
//
// Update Header->WriteAllocated as VALID
//
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + Offset,
- WRITES_ALLOCATED
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + Offset,
+ WRITES_ALLOCATED
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
DEBUG (
(DEBUG_INFO,
- "Ftw: Allocate() success, Caller:%g, # %d\n",
- CallerId,
- NumberOfWrites)
+ "Ftw: Allocate() success, Caller:%g, # %d\n",
+ CallerId,
+ NumberOfWrites)
);
return EFI_SUCCESS;
}
-
/**
Write a record with fault tolerant manner.
Since the content has already backuped in spare block, the write is
@@ -179,17 +184,17 @@ FtwAllocate ( **/
EFI_STATUS
FtwWriteRecord (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
- IN UINTN BlockSize
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
+ IN UINTN BlockSize
)
{
- EFI_STATUS Status;
- EFI_FTW_DEVICE *FtwDevice;
- EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
- EFI_FAULT_TOLERANT_WRITE_RECORD *Record;
- UINTN Offset;
- UINTN NumberOfWriteBlocks;
+ EFI_STATUS Status;
+ EFI_FTW_DEVICE *FtwDevice;
+ EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
+ EFI_FAULT_TOLERANT_WRITE_RECORD *Record;
+ UINTN Offset;
+ UINTN NumberOfWriteBlocks;
FtwDevice = FTW_CONTEXT_FROM_THIS (This);
@@ -197,8 +202,8 @@ FtwWriteRecord ( // Spare Complete but Destination not complete,
// Recover the target block with the spare block.
//
- Header = FtwDevice->FtwLastWriteHeader;
- Record = FtwDevice->FtwLastWriteRecord;
+ Header = FtwDevice->FtwLastWriteHeader;
+ Record = FtwDevice->FtwLastWriteRecord;
//
// IF target block is working block, THEN Flush Spare Block To Working Block;
@@ -209,14 +214,14 @@ FtwWriteRecord ( // If target block is working block,
// it also need to set SPARE_COMPLETED to spare block.
//
- Offset = (UINT8 *) Record - FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)Record - FtwDevice->FtwWorkSpace;
Status = FtwUpdateFvState (
- FtwDevice->FtwBackupFvb,
- FtwDevice->SpareBlockSize,
- FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
- FtwDevice->FtwWorkSpaceBaseInSpare + Offset,
- SPARE_COMPLETED
- );
+ FtwDevice->FtwBackupFvb,
+ FtwDevice->SpareBlockSize,
+ FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
+ FtwDevice->FtwWorkSpaceBaseInSpare + Offset,
+ SPARE_COMPLETED
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -231,24 +236,25 @@ FtwWriteRecord ( //
// Update blocks other than working block or boot block
//
- NumberOfWriteBlocks = FTW_BLOCKS ((UINTN) (Record->Offset + Record->Length), BlockSize);
- Status = FlushSpareBlockToTargetBlock (FtwDevice, Fvb, Record->Lba, BlockSize, NumberOfWriteBlocks);
+ NumberOfWriteBlocks = FTW_BLOCKS ((UINTN)(Record->Offset + Record->Length), BlockSize);
+ Status = FlushSpareBlockToTargetBlock (FtwDevice, Fvb, Record->Lba, BlockSize, NumberOfWriteBlocks);
}
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
+
//
// Record the DestionationComplete in record
//
- Offset = (UINT8 *) Record - FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)Record - FtwDevice->FtwWorkSpace;
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + Offset,
- DEST_COMPLETED
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + Offset,
+ DEST_COMPLETED
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -260,14 +266,14 @@ FtwWriteRecord ( // set the complete flag of write header.
//
if (IsLastRecordOfWrites (Header, Record)) {
- Offset = (UINT8 *) Header - FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)Header - FtwDevice->FtwWorkSpace;
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + Offset,
- WRITES_COMPLETED
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + Offset,
+ WRITES_COMPLETED
+ );
Header->Complete = FTW_VALID_STATE;
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
@@ -305,13 +311,13 @@ FtwWriteRecord ( EFI_STATUS
EFIAPI
FtwWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN VOID *PrivateData,
- IN EFI_HANDLE FvBlockHandle,
- IN VOID *Buffer
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN VOID *PrivateData,
+ IN EFI_HANDLE FvBlockHandle,
+ IN VOID *Buffer
)
{
EFI_STATUS Status;
@@ -335,15 +341,15 @@ FtwWrite ( FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- Status = WorkSpaceRefresh (FtwDevice);
+ Status = WorkSpaceRefresh (FtwDevice);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
- Header = FtwDevice->FtwLastWriteHeader;
- Record = FtwDevice->FtwLastWriteRecord;
+ Header = FtwDevice->FtwLastWriteHeader;
+ Record = FtwDevice->FtwLastWriteRecord;
- if (IsErasedFlashBuffer ((UINT8 *) Header, sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER))) {
+ if (IsErasedFlashBuffer ((UINT8 *)Header, sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER))) {
if (PrivateData == NULL) {
//
// Ftw Write Header is not allocated.
@@ -367,7 +373,7 @@ FtwWrite ( //
// If Record is out of the range of Header, return access denied.
//
- if (((UINTN) Record - (UINTN) Header) > FTW_WRITE_TOTAL_SIZE (Header->NumberOfWrites - 1, Header->PrivateDataSize)) {
+ if (((UINTN)Record - (UINTN)Header) > FTW_WRITE_TOTAL_SIZE (Header->NumberOfWrites - 1, Header->PrivateDataSize)) {
return EFI_ACCESS_DENIED;
}
@@ -430,19 +436,20 @@ FtwWrite ( //
ASSERT ((BlockSize == FtwDevice->SpareBlockSize) && (NumberOfWriteBlocks == FtwDevice->NumberOfSpareBlock));
}
+
//
// Write the record to the work space.
//
- Record->Lba = Lba;
- Record->Offset = Offset;
- Record->Length = Length;
- Record->RelativeOffset = (INT64) (FvbPhysicalAddress + (UINTN) Lba * BlockSize) - (INT64) FtwDevice->SpareAreaAddress;
+ Record->Lba = Lba;
+ Record->Offset = Offset;
+ Record->Length = Length;
+ Record->RelativeOffset = (INT64)(FvbPhysicalAddress + (UINTN)Lba * BlockSize) - (INT64)FtwDevice->SpareAreaAddress;
if (PrivateData != NULL) {
- CopyMem ((Record + 1), PrivateData, (UINTN) Header->PrivateDataSize);
+ CopyMem ((Record + 1), PrivateData, (UINTN)Header->PrivateDataSize);
}
- MyOffset = (UINT8 *) Record - FtwDevice->FtwWorkSpace;
- MyLength = FTW_RECORD_SIZE (Header->PrivateDataSize);
+ MyOffset = (UINT8 *)Record - FtwDevice->FtwWorkSpace;
+ MyLength = FTW_RECORD_SIZE (Header->PrivateDataSize);
Status = WriteWorkSpaceData (
FtwDevice->FtwFvBlock,
@@ -450,29 +457,31 @@ FtwWrite ( FtwDevice->FtwWorkSpaceLba,
FtwDevice->FtwWorkSpaceBase + MyOffset,
MyLength,
- (UINT8 *) Record
+ (UINT8 *)Record
);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
+
//
// Record has written to working block, then do the data.
//
//
// Allocate a memory buffer
//
- MyBufferSize = WriteLength;
- MyBuffer = AllocatePool (MyBufferSize);
+ MyBufferSize = WriteLength;
+ MyBuffer = AllocatePool (MyBufferSize);
if (MyBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Read all original data from target block to memory buffer
//
Ptr = MyBuffer;
for (Index = 0; Index < NumberOfWriteBlocks; Index += 1) {
- MyLength = BlockSize;
- Status = Fvb->Read (Fvb, Lba + Index, 0, &MyLength, Ptr);
+ MyLength = BlockSize;
+ Status = Fvb->Read (Fvb, Lba + Index, 0, &MyLength, Ptr);
if (EFI_ERROR (Status)) {
FreePool (MyBuffer);
return EFI_ABORTED;
@@ -480,6 +489,7 @@ FtwWrite ( Ptr += MyLength;
}
+
//
// Overwrite the updating range data with
// the input buffer content
@@ -500,13 +510,13 @@ FtwWrite ( Ptr = SpareBuffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
MyLength = FtwDevice->SpareBlockSize;
- Status = FtwDevice->FtwBackupFvb->Read (
- FtwDevice->FtwBackupFvb,
- FtwDevice->FtwSpareLba + Index,
- 0,
- &MyLength,
- Ptr
- );
+ Status = FtwDevice->FtwBackupFvb->Read (
+ FtwDevice->FtwBackupFvb,
+ FtwDevice->FtwSpareLba + Index,
+ 0,
+ &MyLength,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
FreePool (MyBuffer);
FreePool (SpareBuffer);
@@ -515,23 +525,26 @@ FtwWrite ( Ptr += MyLength;
}
+
//
// Write the memory buffer to spare block
// Do not assume Spare Block and Target Block have same block size
//
- Status = FtwEraseSpareBlock (FtwDevice);
+ Status = FtwEraseSpareBlock (FtwDevice);
if (EFI_ERROR (Status)) {
FreePool (MyBuffer);
FreePool (SpareBuffer);
return EFI_ABORTED;
}
- Ptr = MyBuffer;
+
+ Ptr = MyBuffer;
for (Index = 0; MyBufferSize > 0; Index += 1) {
if (MyBufferSize > FtwDevice->SpareBlockSize) {
MyLength = FtwDevice->SpareBlockSize;
} else {
MyLength = MyBufferSize;
}
+
Status = FtwDevice->FtwBackupFvb->Write (
FtwDevice->FtwBackupFvb,
FtwDevice->FtwSpareLba + Index,
@@ -545,9 +558,10 @@ FtwWrite ( return EFI_ABORTED;
}
- Ptr += MyLength;
+ Ptr += MyLength;
MyBufferSize -= MyLength;
}
+
//
// Free MyBuffer
//
@@ -556,14 +570,14 @@ FtwWrite ( //
// Set the SpareComplete in the FTW record,
//
- MyOffset = (UINT8 *) Record - FtwDevice->FtwWorkSpace;
- Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + MyOffset,
- SPARE_COMPLETED
- );
+ MyOffset = (UINT8 *)Record - FtwDevice->FtwWorkSpace;
+ Status = FtwUpdateFvState (
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + MyOffset,
+ SPARE_COMPLETED
+ );
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
@@ -580,24 +594,26 @@ FtwWrite ( FreePool (SpareBuffer);
return EFI_ABORTED;
}
+
//
// Restore spare backup buffer into spare block , if no failure happened during FtwWrite.
//
- Status = FtwEraseSpareBlock (FtwDevice);
+ Status = FtwEraseSpareBlock (FtwDevice);
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
}
- Ptr = SpareBuffer;
+
+ Ptr = SpareBuffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
MyLength = FtwDevice->SpareBlockSize;
- Status = FtwDevice->FtwBackupFvb->Write (
- FtwDevice->FtwBackupFvb,
- FtwDevice->FtwSpareLba + Index,
- 0,
- &MyLength,
- Ptr
- );
+ Status = FtwDevice->FtwBackupFvb->Write (
+ FtwDevice->FtwBackupFvb,
+ FtwDevice->FtwSpareLba + Index,
+ 0,
+ &MyLength,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
@@ -605,6 +621,7 @@ FtwWrite ( Ptr += MyLength;
}
+
//
// All success.
//
@@ -612,10 +629,10 @@ FtwWrite ( DEBUG (
(DEBUG_INFO,
- "Ftw: Write() success, (Lba:Offset)=(%lx:0x%x), Length: 0x%x\n",
- Lba,
- Offset,
- Length)
+ "Ftw: Write() success, (Lba:Offset)=(%lx:0x%x), Length: 0x%x\n",
+ Lba,
+ Offset,
+ Length)
);
return EFI_SUCCESS;
@@ -638,8 +655,8 @@ FtwWrite ( EFI_STATUS
EFIAPI
FtwRestart (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_HANDLE FvBlockHandle
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_HANDLE FvBlockHandle
)
{
EFI_STATUS Status;
@@ -652,13 +669,13 @@ FtwRestart ( FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- Status = WorkSpaceRefresh (FtwDevice);
+ Status = WorkSpaceRefresh (FtwDevice);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
- Header = FtwDevice->FtwLastWriteHeader;
- Record = FtwDevice->FtwLastWriteRecord;
+ Header = FtwDevice->FtwLastWriteHeader;
+ Record = FtwDevice->FtwLastWriteRecord;
//
// Spare Complete but Destination not complete,
@@ -731,7 +748,7 @@ FtwRestart ( EFI_STATUS
EFIAPI
FtwAbort (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
)
{
EFI_STATUS Status;
@@ -740,7 +757,7 @@ FtwAbort ( FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- Status = WorkSpaceRefresh (FtwDevice);
+ Status = WorkSpaceRefresh (FtwDevice);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -752,17 +769,18 @@ FtwAbort ( if (FtwDevice->FtwLastWriteHeader->Complete == FTW_VALID_STATE) {
return EFI_NOT_FOUND;
}
+
//
// Update the complete state of the header as VALID and abort.
//
- Offset = (UINT8 *) FtwDevice->FtwLastWriteHeader - FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)FtwDevice->FtwLastWriteHeader - FtwDevice->FtwWorkSpace;
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + Offset,
- WRITES_COMPLETED
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + Offset,
+ WRITES_COMPLETED
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -799,34 +817,34 @@ FtwAbort ( EFI_STATUS
EFIAPI
FtwGetLastWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT EFI_GUID *CallerId,
- OUT EFI_LBA *Lba,
- OUT UINTN *Offset,
- OUT UINTN *Length,
- IN OUT UINTN *PrivateDataSize,
- OUT VOID *PrivateData,
- OUT BOOLEAN *Complete
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT EFI_GUID *CallerId,
+ OUT EFI_LBA *Lba,
+ OUT UINTN *Offset,
+ OUT UINTN *Length,
+ IN OUT UINTN *PrivateDataSize,
+ OUT VOID *PrivateData,
+ OUT BOOLEAN *Complete
)
{
- EFI_STATUS Status;
- EFI_FTW_DEVICE *FtwDevice;
- EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
- EFI_FAULT_TOLERANT_WRITE_RECORD *Record;
+ EFI_STATUS Status;
+ EFI_FTW_DEVICE *FtwDevice;
+ EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
+ EFI_FAULT_TOLERANT_WRITE_RECORD *Record;
- if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
+ if (!FeaturePcdGet (PcdFullFtwServiceEnable)) {
return EFI_UNSUPPORTED;
}
FtwDevice = FTW_CONTEXT_FROM_THIS (This);
- Status = WorkSpaceRefresh (FtwDevice);
+ Status = WorkSpaceRefresh (FtwDevice);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
- Header = FtwDevice->FtwLastWriteHeader;
- Record = FtwDevice->FtwLastWriteRecord;
+ Header = FtwDevice->FtwLastWriteHeader;
+ Record = FtwDevice->FtwLastWriteRecord;
//
// If Header is incompleted and the last record has completed, then
@@ -835,12 +853,13 @@ FtwGetLastWrite ( if ((Header->Complete != FTW_VALID_STATE) &&
(Record->DestinationComplete == FTW_VALID_STATE) &&
IsLastRecordOfWrites (Header, Record)
- ) {
-
+ )
+ {
Status = FtwAbort (This);
*Complete = TRUE;
return EFI_NOT_FOUND;
}
+
//
// If there is no write header/record, return not found.
//
@@ -848,6 +867,7 @@ FtwGetLastWrite ( *Complete = TRUE;
return EFI_NOT_FOUND;
}
+
//
// If this record SpareComplete has not set, then it can not restart.
//
@@ -858,6 +878,7 @@ FtwGetLastWrite ( *Complete = TRUE;
return EFI_NOT_FOUND;
}
+
ASSERT (Record != NULL);
}
@@ -866,16 +887,16 @@ FtwGetLastWrite ( //
CopyMem (CallerId, &Header->CallerId, sizeof (EFI_GUID));
*Lba = Record->Lba;
- *Offset = (UINTN) Record->Offset;
- *Length = (UINTN) Record->Length;
- *Complete = (BOOLEAN) (Record->DestinationComplete == FTW_VALID_STATE);
+ *Offset = (UINTN)Record->Offset;
+ *Length = (UINTN)Record->Length;
+ *Complete = (BOOLEAN)(Record->DestinationComplete == FTW_VALID_STATE);
if (*PrivateDataSize < Header->PrivateDataSize) {
- *PrivateDataSize = (UINTN) Header->PrivateDataSize;
- PrivateData = NULL;
- Status = EFI_BUFFER_TOO_SMALL;
+ *PrivateDataSize = (UINTN)Header->PrivateDataSize;
+ PrivateData = NULL;
+ Status = EFI_BUFFER_TOO_SMALL;
} else {
- *PrivateDataSize = (UINTN) Header->PrivateDataSize;
+ *PrivateDataSize = (UINTN)Header->PrivateDataSize;
CopyMem (PrivateData, Record + 1, *PrivateDataSize);
Status = EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h index fe1c9f3..c14e47b 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h @@ -32,18 +32,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
#define FTW_ERASE_POLARITY 1
-#define FTW_ERASED_BYTE ((UINT8) (255))
-#define FTW_POLARITY_REVERT ((UINT8) (255))
+#define FTW_ERASED_BYTE ((UINT8) (255))
+#define FTW_POLARITY_REVERT ((UINT8) (255))
#define HEADER_ALLOCATED 0x1
#define WRITES_ALLOCATED 0x2
#define WRITES_COMPLETED 0x4
-#define BOOT_BLOCK_UPDATE 0x1
-#define SPARE_COMPLETED 0x2
-#define DEST_COMPLETED 0x4
+#define BOOT_BLOCK_UPDATE 0x1
+#define SPARE_COMPLETED 0x2
+#define DEST_COMPLETED 0x4
-#define FTW_BLOCKS(Length, BlockSize) ((UINTN) ((Length) / (BlockSize) + (((Length) & ((BlockSize) - 1)) ? 1 : 0)))
+#define FTW_BLOCKS(Length, BlockSize) ((UINTN) ((Length) / (BlockSize) + (((Length) & ((BlockSize) - 1)) ? 1 : 0)))
#define FTW_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'T', 'W', 'D')
@@ -51,31 +51,31 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // EFI Fault tolerant protocol private data structure
//
typedef struct {
- UINTN Signature;
- EFI_HANDLE Handle;
- EFI_FAULT_TOLERANT_WRITE_PROTOCOL FtwInstance;
- EFI_PHYSICAL_ADDRESS WorkSpaceAddress; // Base address of working space range in flash.
- EFI_PHYSICAL_ADDRESS SpareAreaAddress; // Base address of spare range in flash.
- UINTN WorkSpaceLength; // Size of working space range in flash.
- UINTN NumberOfWorkSpaceBlock; // Number of the blocks in work block for work space.
- UINTN WorkBlockSize; // Block size in bytes of the work blocks in flash
- UINTN SpareAreaLength; // Size of spare range in flash.
- UINTN NumberOfSpareBlock; // Number of the blocks in spare block.
- UINTN SpareBlockSize; // Block size in bytes of the spare blocks in flash
- EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader;// Pointer to Working Space Header in memory buffer
- EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader;// Pointer to last record header in memory buffer
- EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord;// Pointer to last record in memory buffer
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwFvBlock; // FVB of working block
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwBackupFvb; // FVB of spare block
- EFI_LBA FtwSpareLba; // Start LBA of spare block
- EFI_LBA FtwWorkBlockLba; // Start LBA of working block that contains working space in its last block.
- UINTN NumberOfWorkBlock; // Number of the blocks in work block.
- EFI_LBA FtwWorkSpaceLba; // Start LBA of working space
- UINTN FtwWorkSpaceBase; // Offset into the FtwWorkSpaceLba block.
- UINTN FtwWorkSpaceSize; // Size of working space range that stores write record.
- EFI_LBA FtwWorkSpaceLbaInSpare; // Start LBA of working space in spare block.
- UINTN FtwWorkSpaceBaseInSpare;// Offset into the FtwWorkSpaceLbaInSpare block.
- UINT8 *FtwWorkSpace; // Point to Work Space in memory buffer
+ UINTN Signature;
+ EFI_HANDLE Handle;
+ EFI_FAULT_TOLERANT_WRITE_PROTOCOL FtwInstance;
+ EFI_PHYSICAL_ADDRESS WorkSpaceAddress; // Base address of working space range in flash.
+ EFI_PHYSICAL_ADDRESS SpareAreaAddress; // Base address of spare range in flash.
+ UINTN WorkSpaceLength; // Size of working space range in flash.
+ UINTN NumberOfWorkSpaceBlock; // Number of the blocks in work block for work space.
+ UINTN WorkBlockSize; // Block size in bytes of the work blocks in flash
+ UINTN SpareAreaLength; // Size of spare range in flash.
+ UINTN NumberOfSpareBlock; // Number of the blocks in spare block.
+ UINTN SpareBlockSize; // Block size in bytes of the spare blocks in flash
+ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader; // Pointer to Working Space Header in memory buffer
+ EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader; // Pointer to last record header in memory buffer
+ EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord; // Pointer to last record in memory buffer
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwFvBlock; // FVB of working block
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwBackupFvb; // FVB of spare block
+ EFI_LBA FtwSpareLba; // Start LBA of spare block
+ EFI_LBA FtwWorkBlockLba; // Start LBA of working block that contains working space in its last block.
+ UINTN NumberOfWorkBlock; // Number of the blocks in work block.
+ EFI_LBA FtwWorkSpaceLba; // Start LBA of working space
+ UINTN FtwWorkSpaceBase; // Offset into the FtwWorkSpaceLba block.
+ UINTN FtwWorkSpaceSize; // Size of working space range that stores write record.
+ EFI_LBA FtwWorkSpaceLbaInSpare; // Start LBA of working space in spare block.
+ UINTN FtwWorkSpaceBaseInSpare; // Offset into the FtwWorkSpaceLbaInSpare block.
+ UINT8 *FtwWorkSpace; // Point to Work Space in memory buffer
//
// Following a buffer of FtwWorkSpace[FTW_WORK_SPACE_SIZE],
// Allocated with EFI_FTW_DEVICE.
@@ -87,6 +87,7 @@ typedef struct { //
// Driver entry point
//
+
/**
This function is the entry point of the Fault Tolerant Write driver.
@@ -103,8 +104,8 @@ typedef struct { EFI_STATUS
EFIAPI
InitializeFaultTolerantWrite (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
);
//
@@ -125,8 +126,8 @@ InitializeFaultTolerantWrite ( EFI_STATUS
EFIAPI
FtwGetMaxBlockSize (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT UINTN *BlockSize
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT UINTN *BlockSize
);
/**
@@ -153,10 +154,10 @@ FtwGetMaxBlockSize ( EFI_STATUS
EFIAPI
FtwAllocate (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_GUID *CallerId,
- IN UINTN PrivateDataSize,
- IN UINTN NumberOfWrites
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_GUID *CallerId,
+ IN UINTN PrivateDataSize,
+ IN UINTN NumberOfWrites
);
/**
@@ -188,13 +189,13 @@ FtwAllocate ( EFI_STATUS
EFIAPI
FtwWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN VOID *PrivateData,
- IN EFI_HANDLE FvBlockHandle,
- IN VOID *Buffer
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN VOID *PrivateData,
+ IN EFI_HANDLE FvBlockHandle,
+ IN VOID *Buffer
);
/**
@@ -214,8 +215,8 @@ FtwWrite ( EFI_STATUS
EFIAPI
FtwRestart (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_HANDLE FvBlockHandle
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_HANDLE FvBlockHandle
);
/**
@@ -231,7 +232,7 @@ FtwRestart ( EFI_STATUS
EFIAPI
FtwAbort (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
);
/**
@@ -260,14 +261,14 @@ FtwAbort ( EFI_STATUS
EFIAPI
FtwGetLastWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT EFI_GUID *CallerId,
- OUT EFI_LBA *Lba,
- OUT UINTN *Offset,
- OUT UINTN *Length,
- IN OUT UINTN *PrivateDataSize,
- OUT VOID *PrivateData,
- OUT BOOLEAN *Complete
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT EFI_GUID *CallerId,
+ OUT EFI_LBA *Lba,
+ OUT UINTN *Offset,
+ OUT UINTN *Length,
+ IN OUT UINTN *PrivateDataSize,
+ OUT VOID *PrivateData,
+ OUT BOOLEAN *Complete
);
/**
@@ -289,7 +290,7 @@ FtwGetLastWrite ( **/
EFI_STATUS
FtwEraseSpareBlock (
- IN EFI_FTW_DEVICE *FtwDevice
+ IN EFI_FTW_DEVICE *FtwDevice
);
/**
@@ -391,7 +392,7 @@ FlushSpareBlockToTargetBlock ( **/
EFI_STATUS
FlushSpareBlockToWorkingBlock (
- EFI_FTW_DEVICE *FtwDevice
+ EFI_FTW_DEVICE *FtwDevice
);
/**
@@ -422,7 +423,7 @@ FlushSpareBlockToWorkingBlock ( **/
EFI_STATUS
FlushSpareBlockToBootBlock (
- EFI_FTW_DEVICE *FtwDevice
+ EFI_FTW_DEVICE *FtwDevice
);
/**
@@ -489,8 +490,8 @@ FtwGetLastWriteHeader ( **/
EFI_STATUS
FtwGetLastWriteRecord (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,
- OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,
+ OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord
);
/**
@@ -505,8 +506,8 @@ FtwGetLastWriteRecord ( **/
BOOLEAN
IsFirstRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
);
/**
@@ -523,8 +524,8 @@ IsFirstRecordOfWrites ( **/
BOOLEAN
IsLastRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
);
/**
@@ -539,8 +540,8 @@ IsLastRecordOfWrites ( **/
EFI_STATUS
GetPreviousRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord
);
/**
@@ -555,9 +556,10 @@ GetPreviousRecordOfWrites ( **/
BOOLEAN
IsErasedFlashBuffer (
- IN UINT8 *Buffer,
- IN UINTN BufferSize
+ IN UINT8 *Buffer,
+ IN UINTN BufferSize
);
+
/**
Initialize a work space when there is no work space.
@@ -569,8 +571,9 @@ IsErasedFlashBuffer ( **/
EFI_STATUS
InitWorkSpaceHeader (
- IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+ IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
);
+
/**
Read from working block to refresh the work space in memory.
@@ -584,6 +587,7 @@ EFI_STATUS WorkSpaceRefresh (
IN EFI_FTW_DEVICE *FtwDevice
);
+
/**
Check to see if it is a valid work space.
@@ -596,8 +600,9 @@ WorkSpaceRefresh ( **/
BOOLEAN
IsValidWorkSpace (
- IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+ IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
);
+
/**
Reclaim the work space on the working block.
@@ -629,8 +634,8 @@ FtwReclaimWorkSpace ( **/
EFI_HANDLE
GetFvbByAddress (
- IN EFI_PHYSICAL_ADDRESS Address,
- OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
+ IN EFI_PHYSICAL_ADDRESS Address,
+ OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
);
/**
@@ -645,7 +650,7 @@ GetFvbByAddress ( **/
EFI_STATUS
FtwGetSarProtocol (
- OUT VOID **SarProtocol
+ OUT VOID **SarProtocol
);
/**
@@ -665,11 +670,10 @@ FtwGetSarProtocol ( **/
EFI_STATUS
GetFvbCountAndBuffer (
- OUT UINTN *NumberHandles,
- OUT EFI_HANDLE **Buffer
+ OUT UINTN *NumberHandles,
+ OUT EFI_HANDLE **Buffer
);
-
/**
Allocate private data for FTW driver and initialize it.
@@ -682,10 +686,9 @@ GetFvbCountAndBuffer ( **/
EFI_STATUS
InitFtwDevice (
- OUT EFI_FTW_DEVICE **FtwData
+ OUT EFI_FTW_DEVICE **FtwData
);
-
/**
Initialization for Fault Tolerant Write is done in this handler.
@@ -697,7 +700,7 @@ InitFtwDevice ( **/
EFI_STATUS
InitFtwProtocol (
- IN OUT EFI_FTW_DEVICE *FtwDevice
+ IN OUT EFI_FTW_DEVICE *FtwDevice
);
/**
@@ -727,12 +730,12 @@ InitializeLocalWorkSpaceHeader ( **/
EFI_STATUS
ReadWorkSpaceData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
- IN UINTN BlockSize,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- OUT UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
+ IN UINTN BlockSize,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ OUT UINT8 *Buffer
);
/**
@@ -751,12 +754,12 @@ ReadWorkSpaceData ( **/
EFI_STATUS
WriteWorkSpaceData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
- IN UINTN BlockSize,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
+ IN UINTN BlockSize,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN UINT8 *Buffer
);
/**
@@ -777,8 +780,8 @@ WriteWorkSpaceData ( **/
UINT32
FtwCalculateCrc32 (
- IN VOID *Buffer,
- IN UINTN Length
+ IN VOID *Buffer,
+ IN UINTN Length
);
#endif
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c index de38ea0..965dd39 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c @@ -47,8 +47,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/UefiBootServicesTableLib.h>
#include "FaultTolerantWrite.h"
-VOID *mFvbRegistration = NULL;
-
+VOID *mFvbRegistration = NULL;
/**
Retrieve the FVB protocol interface by HANDLE.
@@ -74,7 +73,7 @@ FtwGetFvbByHandle ( return gBS->HandleProtocol (
FvBlockHandle,
&gEfiFirmwareVolumeBlockProtocolGuid,
- (VOID **) FvBlock
+ (VOID **)FvBlock
);
}
@@ -90,10 +89,10 @@ FtwGetFvbByHandle ( **/
EFI_STATUS
FtwGetSarProtocol (
- OUT VOID **SarProtocol
+ OUT VOID **SarProtocol
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Locate Swap Address Range protocol
@@ -123,11 +122,11 @@ FtwGetSarProtocol ( **/
EFI_STATUS
GetFvbCountAndBuffer (
- OUT UINTN *NumberHandles,
- OUT EFI_HANDLE **Buffer
+ OUT UINTN *NumberHandles,
+ OUT EFI_HANDLE **Buffer
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Locate all handles of Fvb protocol
@@ -142,7 +141,6 @@ GetFvbCountAndBuffer ( return Status;
}
-
/**
Firmware Volume Block Protocol notification event handler.
@@ -153,13 +151,13 @@ GetFvbCountAndBuffer ( VOID
EFIAPI
FvbNotificationEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_STATUS Status;
+ EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
+ EFI_FTW_DEVICE *FtwDevice;
//
// Just return to avoid installing FaultTolerantWriteProtocol again
@@ -168,19 +166,19 @@ FvbNotificationEvent ( Status = gBS->LocateProtocol (
&gEfiFaultTolerantWriteProtocolGuid,
NULL,
- (VOID **) &FtwProtocol
+ (VOID **)&FtwProtocol
);
if (!EFI_ERROR (Status)) {
- return ;
+ return;
}
//
// Found proper FVB protocol and initialize FtwDevice for protocol installation
//
FtwDevice = (EFI_FTW_DEVICE *)Context;
- Status = InitFtwProtocol (FtwDevice);
- if (EFI_ERROR(Status)) {
- return ;
+ Status = InitFtwProtocol (FtwDevice);
+ if (EFI_ERROR (Status)) {
+ return;
}
//
@@ -200,7 +198,6 @@ FvbNotificationEvent ( return;
}
-
/**
This function is the entry point of the Fault Tolerant Write driver.
@@ -215,12 +212,12 @@ FvbNotificationEvent ( EFI_STATUS
EFIAPI
FaultTolerantWriteInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_STATUS Status;
+ EFI_FTW_DEVICE *FtwDevice;
FtwDevice = NULL;
@@ -228,7 +225,7 @@ FaultTolerantWriteInitialize ( // Allocate private data structure for FTW protocol and do some initialization
//
Status = InitFtwDevice (&FtwDevice);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -263,12 +260,12 @@ FaultTolerantWriteInitialize ( **/
UINT32
FtwCalculateCrc32 (
- IN VOID *Buffer,
- IN UINTN Length
+ IN VOID *Buffer,
+ IN UINTN Length
)
{
- EFI_STATUS Status;
- UINT32 ReturnValue;
+ EFI_STATUS Status;
+ UINT32 ReturnValue;
Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);
ASSERT_EFI_ERROR (Status);
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c index de7544e..8c2d209 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c @@ -56,13 +56,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "FaultTolerantWriteSmmCommon.h"
#include <Protocol/MmEndOfDxe.h>
-VOID *mFvbRegistration = NULL;
-EFI_FTW_DEVICE *mFtwDevice = NULL;
+VOID *mFvbRegistration = NULL;
+EFI_FTW_DEVICE *mFtwDevice = NULL;
///
/// The flag to indicate whether the platform has left the DXE phase of execution.
///
-BOOLEAN mEndOfDxe = FALSE;
+BOOLEAN mEndOfDxe = FALSE;
/**
Retrieve the SMM FVB protocol interface by HANDLE.
@@ -88,7 +88,7 @@ FtwGetFvbByHandle ( return gMmst->MmHandleProtocol (
FvBlockHandle,
&gEfiSmmFirmwareVolumeBlockProtocolGuid,
- (VOID **) FvBlock
+ (VOID **)FvBlock
);
}
@@ -104,10 +104,10 @@ FtwGetFvbByHandle ( **/
EFI_STATUS
FtwGetSarProtocol (
- OUT VOID **SarProtocol
+ OUT VOID **SarProtocol
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Locate Smm Swap Address Range protocol
@@ -137,12 +137,12 @@ FtwGetSarProtocol ( **/
EFI_STATUS
GetFvbCountAndBuffer (
- OUT UINTN *NumberHandles,
- OUT EFI_HANDLE **Buffer
+ OUT UINTN *NumberHandles,
+ OUT EFI_HANDLE **Buffer
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
+ EFI_STATUS Status;
+ UINTN BufferSize;
if ((NumberHandles == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -151,14 +151,14 @@ GetFvbCountAndBuffer ( BufferSize = 0;
*NumberHandles = 0;
*Buffer = NULL;
- Status = gMmst->MmLocateHandle (
- ByProtocol,
- &gEfiSmmFirmwareVolumeBlockProtocolGuid,
- NULL,
- &BufferSize,
- *Buffer
- );
- if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {
+ Status = gMmst->MmLocateHandle (
+ ByProtocol,
+ &gEfiSmmFirmwareVolumeBlockProtocolGuid,
+ NULL,
+ &BufferSize,
+ *Buffer
+ );
+ if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
return EFI_NOT_FOUND;
}
@@ -175,8 +175,8 @@ GetFvbCountAndBuffer ( *Buffer
);
- *NumberHandles = BufferSize / sizeof(EFI_HANDLE);
- if (EFI_ERROR(Status)) {
+ *NumberHandles = BufferSize / sizeof (EFI_HANDLE);
+ if (EFI_ERROR (Status)) {
*NumberHandles = 0;
FreePool (*Buffer);
*Buffer = NULL;
@@ -185,7 +185,6 @@ GetFvbCountAndBuffer ( return Status;
}
-
/**
Get the handle of the SMM FVB protocol by the FVB base address and attributes.
@@ -199,9 +198,9 @@ GetFvbCountAndBuffer ( **/
EFI_STATUS
GetFvbByAddressAndAttribute (
- IN EFI_PHYSICAL_ADDRESS Address,
- IN EFI_FVB_ATTRIBUTES_2 Attributes,
- OUT EFI_HANDLE *SmmFvbHandle
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN EFI_FVB_ATTRIBUTES_2 Attributes,
+ OUT EFI_HANDLE *SmmFvbHandle
)
{
EFI_STATUS Status;
@@ -230,6 +229,7 @@ GetFvbByAddressAndAttribute ( if (EFI_ERROR (Status)) {
break;
}
+
//
// Compare the address.
//
@@ -237,8 +237,9 @@ GetFvbByAddressAndAttribute ( if (EFI_ERROR (Status)) {
continue;
}
+
if (Address != FvbBaseAddress) {
- continue;
+ continue;
}
//
@@ -248,8 +249,9 @@ GetFvbByAddressAndAttribute ( if (EFI_ERROR (Status)) {
continue;
}
+
if (Attributes != FvbAttributes) {
- continue;
+ continue;
}
//
@@ -293,31 +295,31 @@ GetFvbByAddressAndAttribute ( EFI_STATUS
EFIAPI
SmmFaultTolerantWriteHandler (
- IN EFI_HANDLE DispatchHandle,
- IN CONST VOID *RegisterContext,
- IN OUT VOID *CommBuffer,
- IN OUT UINTN *CommBufferSize
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *RegisterContext,
+ IN OUT VOID *CommBuffer,
+ IN OUT UINTN *CommBufferSize
)
{
- EFI_STATUS Status;
- SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
- SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmGetMaxBlockSizeHeader;
- SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;
- SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;
- SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;
- SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;
- VOID *PrivateData;
- EFI_HANDLE SmmFvbHandle;
- UINTN InfoSize;
- UINTN CommBufferPayloadSize;
- UINTN PrivateDataSize;
- UINTN Length;
- UINTN TempCommBufferSize;
+ EFI_STATUS Status;
+ SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
+ SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmGetMaxBlockSizeHeader;
+ SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;
+ SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;
+ SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;
+ SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;
+ VOID *PrivateData;
+ EFI_HANDLE SmmFvbHandle;
+ UINTN InfoSize;
+ UINTN CommBufferPayloadSize;
+ UINTN PrivateDataSize;
+ UINTN Length;
+ UINTN TempCommBufferSize;
//
// If input is invalid, stop processing this SMI
//
- if (CommBuffer == NULL || CommBufferSize == NULL) {
+ if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
return EFI_SUCCESS;
}
@@ -327,6 +329,7 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "SmmFtwHandler: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
+
CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;
if (!FtwSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
@@ -351,7 +354,8 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "GetMaxBlockSize: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- SmmGetMaxBlockSizeHeader = (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *) SmmFtwFunctionHeader->Data;
+
+ SmmGetMaxBlockSizeHeader = (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *)SmmFtwFunctionHeader->Data;
Status = FtwGetMaxBlockSize (
&mFtwDevice->FtwInstance,
@@ -364,13 +368,14 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "Allocate: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- SmmFtwAllocateHeader = (SMM_FTW_ALLOCATE_HEADER *) SmmFtwFunctionHeader->Data;
- Status = FtwAllocate (
- &mFtwDevice->FtwInstance,
- &SmmFtwAllocateHeader->CallerId,
- SmmFtwAllocateHeader->PrivateDataSize,
- SmmFtwAllocateHeader->NumberOfWrites
- );
+
+ SmmFtwAllocateHeader = (SMM_FTW_ALLOCATE_HEADER *)SmmFtwFunctionHeader->Data;
+ Status = FtwAllocate (
+ &mFtwDevice->FtwInstance,
+ &SmmFtwAllocateHeader->CallerId,
+ SmmFtwAllocateHeader->PrivateDataSize,
+ SmmFtwAllocateHeader->NumberOfWrites
+ );
break;
case FTW_FUNCTION_WRITE:
@@ -378,17 +383,20 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "Write: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- SmmFtwWriteHeader = (SMM_FTW_WRITE_HEADER *) SmmFtwFunctionHeader->Data;
- Length = SmmFtwWriteHeader->Length;
- PrivateDataSize = SmmFtwWriteHeader->PrivateDataSize;
+
+ SmmFtwWriteHeader = (SMM_FTW_WRITE_HEADER *)SmmFtwFunctionHeader->Data;
+ Length = SmmFtwWriteHeader->Length;
+ PrivateDataSize = SmmFtwWriteHeader->PrivateDataSize;
if (((UINTN)(~0) - Length < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data)) ||
- ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length)) {
+ ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length))
+ {
//
// Prevent InfoSize overflow
//
Status = EFI_ACCESS_DENIED;
break;
}
+
InfoSize = OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length + PrivateDataSize;
//
@@ -405,6 +413,7 @@ SmmFaultTolerantWriteHandler ( } else {
PrivateData = (VOID *)&SmmFtwWriteHeader->Data[Length];
}
+
Status = GetFvbByAddressAndAttribute (
SmmFtwWriteHeader->FvbBaseAddress,
SmmFtwWriteHeader->FvbAttributes,
@@ -417,7 +426,7 @@ SmmFaultTolerantWriteHandler ( // calling into FtwWrite().
//
SpeculationBarrier ();
- Status = FtwWrite(
+ Status = FtwWrite (
&mFtwDevice->FtwInstance,
SmmFtwWriteHeader->Lba,
SmmFtwWriteHeader->Offset,
@@ -427,6 +436,7 @@ SmmFaultTolerantWriteHandler ( SmmFtwWriteHeader->Data
);
}
+
break;
case FTW_FUNCTION_RESTART:
@@ -434,15 +444,17 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "Restart: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- SmmFtwRestartHeader = (SMM_FTW_RESTART_HEADER *) SmmFtwFunctionHeader->Data;
- Status = GetFvbByAddressAndAttribute (
- SmmFtwRestartHeader->FvbBaseAddress,
- SmmFtwRestartHeader->FvbAttributes,
- &SmmFvbHandle
- );
+
+ SmmFtwRestartHeader = (SMM_FTW_RESTART_HEADER *)SmmFtwFunctionHeader->Data;
+ Status = GetFvbByAddressAndAttribute (
+ SmmFtwRestartHeader->FvbBaseAddress,
+ SmmFtwRestartHeader->FvbAttributes,
+ &SmmFvbHandle
+ );
if (!EFI_ERROR (Status)) {
Status = FtwRestart (&mFtwDevice->FtwInstance, SmmFvbHandle);
}
+
break;
case FTW_FUNCTION_ABORT:
@@ -454,15 +466,17 @@ SmmFaultTolerantWriteHandler ( DEBUG ((DEBUG_ERROR, "GetLastWrite: SMM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}
- SmmFtwGetLastWriteHeader = (SMM_FTW_GET_LAST_WRITE_HEADER *) SmmFtwFunctionHeader->Data;
- PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;
- if ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data)){
+
+ SmmFtwGetLastWriteHeader = (SMM_FTW_GET_LAST_WRITE_HEADER *)SmmFtwFunctionHeader->Data;
+ PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;
+ if ((UINTN)(~0) - PrivateDataSize < OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data)) {
//
// Prevent InfoSize overflow
//
Status = EFI_ACCESS_DENIED;
break;
}
+
InfoSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + PrivateDataSize;
//
@@ -496,7 +510,6 @@ SmmFaultTolerantWriteHandler ( return EFI_SUCCESS;
}
-
/**
SMM Firmware Volume Block Protocol notification event handler.
@@ -510,14 +523,14 @@ SmmFaultTolerantWriteHandler ( EFI_STATUS
EFIAPI
FvbNotificationEvent (
- IN CONST EFI_GUID *Protocol,
- IN VOID *Interface,
- IN EFI_HANDLE Handle
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
- EFI_HANDLE SmmFtwHandle;
+ EFI_STATUS Status;
+ EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
+ EFI_HANDLE SmmFtwHandle;
//
// Just return to avoid install SMM FaultTolerantWriteProtocol again
@@ -526,7 +539,7 @@ FvbNotificationEvent ( Status = gMmst->MmLocateProtocol (
&gEfiSmmFaultTolerantWriteProtocolGuid,
NULL,
- (VOID **) &FtwProtocol
+ (VOID **)&FtwProtocol
);
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
@@ -536,7 +549,7 @@ FvbNotificationEvent ( // Found proper FVB protocol and initialize FtwDevice for protocol installation
//
Status = InitFtwProtocol (mFtwDevice);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -578,9 +591,9 @@ FvbNotificationEvent ( EFI_STATUS
EFIAPI
MmEndOfDxeCallback (
- IN CONST EFI_GUID *Protocol,
- IN VOID *Interface,
- IN EFI_HANDLE Handle
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
)
{
mEndOfDxe = TRUE;
@@ -599,14 +612,14 @@ MmFaultTolerantWriteInitialize ( VOID
)
{
- EFI_STATUS Status;
- VOID *MmEndOfDxeRegistration;
+ EFI_STATUS Status;
+ VOID *MmEndOfDxeRegistration;
//
// Allocate private data structure for SMM FTW protocol and do some initialization
//
Status = InitFtwDevice (&mFtwDevice);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h index 5f0eec0..f717432 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h @@ -13,17 +13,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/SmmFirmwareVolumeBlock.h>
#include <Protocol/SmmFaultTolerantWrite.h>
-#define FTW_FUNCTION_GET_MAX_BLOCK_SIZE 1
-#define FTW_FUNCTION_ALLOCATE 2
-#define FTW_FUNCTION_WRITE 3
-#define FTW_FUNCTION_RESTART 4
-#define FTW_FUNCTION_ABORT 5
-#define FTW_FUNCTION_GET_LAST_WRITE 6
+#define FTW_FUNCTION_GET_MAX_BLOCK_SIZE 1
+#define FTW_FUNCTION_ALLOCATE 2
+#define FTW_FUNCTION_WRITE 3
+#define FTW_FUNCTION_RESTART 4
+#define FTW_FUNCTION_ABORT 5
+#define FTW_FUNCTION_GET_LAST_WRITE 6
typedef struct {
- UINTN Function;
- EFI_STATUS ReturnStatus;
- UINT8 Data[1];
+ UINTN Function;
+ EFI_STATUS ReturnStatus;
+ UINT8 Data[1];
} SMM_FTW_COMMUNICATE_FUNCTION_HEADER;
///
@@ -37,38 +37,38 @@ typedef struct { #define SMM_FTW_COMMUNICATE_HEADER_SIZE (OFFSET_OF (SMM_FTW_COMMUNICATE_FUNCTION_HEADER, Data))
typedef struct {
- UINTN BlockSize;
+ UINTN BlockSize;
} SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER;
typedef struct {
- EFI_GUID CallerId;
- UINTN PrivateDataSize;
- UINTN NumberOfWrites;
+ EFI_GUID CallerId;
+ UINTN PrivateDataSize;
+ UINTN NumberOfWrites;
} SMM_FTW_ALLOCATE_HEADER;
typedef struct {
- EFI_LBA Lba;
- UINTN Offset;
- UINTN PrivateDataSize;
- EFI_PHYSICAL_ADDRESS FvbBaseAddress;
- EFI_FVB_ATTRIBUTES_2 FvbAttributes;
- UINTN Length;
- UINT8 Data[1];
+ EFI_LBA Lba;
+ UINTN Offset;
+ UINTN PrivateDataSize;
+ EFI_PHYSICAL_ADDRESS FvbBaseAddress;
+ EFI_FVB_ATTRIBUTES_2 FvbAttributes;
+ UINTN Length;
+ UINT8 Data[1];
} SMM_FTW_WRITE_HEADER;
typedef struct {
- EFI_PHYSICAL_ADDRESS FvbBaseAddress;
- EFI_FVB_ATTRIBUTES_2 FvbAttributes;
+ EFI_PHYSICAL_ADDRESS FvbBaseAddress;
+ EFI_FVB_ATTRIBUTES_2 FvbAttributes;
} SMM_FTW_RESTART_HEADER;
typedef struct {
- EFI_GUID CallerId;
- EFI_LBA Lba;
- UINTN Offset;
- UINTN Length;
- UINTN PrivateDataSize;
- BOOLEAN Complete;
- UINT8 Data[1];
+ EFI_GUID CallerId;
+ EFI_LBA Lba;
+ UINTN Offset;
+ UINTN Length;
+ UINTN PrivateDataSize;
+ BOOLEAN Complete;
+ UINT8 Data[1];
} SMM_FTW_GET_LAST_WRITE_HEADER;
/**
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c index 24c2095..d273e4d 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c @@ -10,9 +10,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "FaultTolerantWriteSmmDxe.h"
-EFI_HANDLE mHandle = NULL;
-EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
-UINTN mPrivateDataSize = 0;
+EFI_HANDLE mHandle = NULL;
+EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
+UINTN mPrivateDataSize = 0;
EFI_FAULT_TOLERANT_WRITE_PROTOCOL mFaultTolerantWriteDriver = {
FtwGetMaxBlockSize,
@@ -34,14 +34,14 @@ EFI_FAULT_TOLERANT_WRITE_PROTOCOL mFaultTolerantWriteDriver = { **/
VOID
InitCommunicateBuffer (
- OUT VOID **CommunicateBuffer,
- OUT VOID **DataPtr,
- IN UINTN DataSize,
- IN UINTN Function
+ OUT VOID **CommunicateBuffer,
+ OUT VOID **DataPtr,
+ IN UINTN DataSize,
+ IN UINTN Function
)
{
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
//
// The whole buffer size: SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE + DataSize.
@@ -55,7 +55,7 @@ InitCommunicateBuffer ( CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmFaultTolerantWriteProtocolGuid);
SmmCommunicateHeader->MessageLength = DataSize + SMM_FTW_COMMUNICATE_HEADER_SIZE;
- SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *) SmmCommunicateHeader->Data;
+ SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *)SmmCommunicateHeader->Data;
SmmFtwFunctionHeader->Function = Function;
*CommunicateBuffer = SmmCommunicateHeader;
@@ -64,7 +64,6 @@ InitCommunicateBuffer ( }
}
-
/**
Send the data in communicate buffer to SMI handler and get response.
@@ -74,26 +73,27 @@ InitCommunicateBuffer ( **/
EFI_STATUS
SendCommunicateBuffer (
- IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader,
- IN UINTN DataSize
+ IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader,
+ IN UINTN DataSize
)
{
- EFI_STATUS Status;
- UINTN CommSize;
- SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
+ EFI_STATUS Status;
+ UINTN CommSize;
+ SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;
CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE;
- Status = mMmCommunication2->Communicate (mMmCommunication2,
- SmmCommunicateHeader,
- SmmCommunicateHeader,
- &CommSize);
+ Status = mMmCommunication2->Communicate (
+ mMmCommunication2,
+ SmmCommunicateHeader,
+ SmmCommunicateHeader,
+ &CommSize
+ );
ASSERT_EFI_ERROR (Status);
- SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *) SmmCommunicateHeader->Data;
- return SmmFtwFunctionHeader->ReturnStatus;
+ SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *)SmmCommunicateHeader->Data;
+ return SmmFtwFunctionHeader->ReturnStatus;
}
-
/**
Get the FvbBaseAddress and FvbAttributes from the FVB handle FvbHandle.
@@ -107,15 +107,15 @@ SendCommunicateBuffer ( **/
EFI_STATUS
ConvertFvbHandle (
- IN EFI_HANDLE FvbHandle,
- OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress,
- OUT EFI_FVB_ATTRIBUTES_2 *FvbAttributes
+ IN EFI_HANDLE FvbHandle,
+ OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress,
+ OUT EFI_FVB_ATTRIBUTES_2 *FvbAttributes
)
{
- EFI_STATUS Status;
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
+ EFI_STATUS Status;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
- Status = gBS->HandleProtocol (FvbHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **) &Fvb);
+ Status = gBS->HandleProtocol (FvbHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **)&Fvb);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -129,7 +129,6 @@ ConvertFvbHandle ( return Status;
}
-
/**
Get the size of the largest block that can be updated in a fault-tolerant manner.
@@ -145,19 +144,19 @@ ConvertFvbHandle ( EFI_STATUS
EFIAPI
FtwGetMaxBlockSize (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT UINTN *BlockSize
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT UINTN *BlockSize
)
{
- EFI_STATUS Status;
- UINTN PayloadSize;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmFtwBlockSizeHeader;
+ EFI_STATUS Status;
+ UINTN PayloadSize;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmFtwBlockSizeHeader;
//
// Initialize the communicate buffer.
//
- PayloadSize = sizeof (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER);
+ PayloadSize = sizeof (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER);
InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwBlockSizeHeader, PayloadSize, FTW_FUNCTION_GET_MAX_BLOCK_SIZE);
//
@@ -174,7 +173,6 @@ FtwGetMaxBlockSize ( return Status;
}
-
/**
Allocates space for the protocol to maintain information about writes.
Since writes must be completed in a fault-tolerant manner and multiple
@@ -199,21 +197,21 @@ FtwGetMaxBlockSize ( EFI_STATUS
EFIAPI
FtwAllocate (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_GUID *CallerId,
- IN UINTN PrivateDataSize,
- IN UINTN NumberOfWrites
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_GUID *CallerId,
+ IN UINTN PrivateDataSize,
+ IN UINTN NumberOfWrites
)
{
- EFI_STATUS Status;
- UINTN PayloadSize;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;
+ EFI_STATUS Status;
+ UINTN PayloadSize;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;
//
// Initialize the communicate buffer.
//
- PayloadSize = sizeof (SMM_FTW_ALLOCATE_HEADER);
+ PayloadSize = sizeof (SMM_FTW_ALLOCATE_HEADER);
InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwAllocateHeader, PayloadSize, FTW_FUNCTION_ALLOCATE);
CopyGuid (&SmmFtwAllocateHeader->CallerId, CallerId);
SmmFtwAllocateHeader->PrivateDataSize = PrivateDataSize;
@@ -223,7 +221,7 @@ FtwAllocate ( // Send data to SMM.
//
Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);
- if (!EFI_ERROR( Status)) {
+ if (!EFI_ERROR (Status)) {
mPrivateDataSize = PrivateDataSize;
}
@@ -231,7 +229,6 @@ FtwAllocate ( return Status;
}
-
/**
Starts a target block update. This records information about the write
in fault tolerant storage, and will complete the write in a recoverable
@@ -262,30 +259,31 @@ FtwAllocate ( EFI_STATUS
EFIAPI
FtwWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN VOID *PrivateData,
- IN EFI_HANDLE FvBlockHandle,
- IN VOID *Buffer
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN VOID *PrivateData,
+ IN EFI_HANDLE FvBlockHandle,
+ IN VOID *Buffer
)
{
- EFI_STATUS Status;
- UINTN PayloadSize;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;
+ EFI_STATUS Status;
+ UINTN PayloadSize;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;
//
// Initialize the communicate buffer.
//
- PayloadSize = OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length;
+ PayloadSize = OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length;
if (PrivateData != NULL) {
//
// The private data buffer size should be the same one in FtwAllocate API.
//
PayloadSize += mPrivateDataSize;
}
+
InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwWriteHeader, PayloadSize, FTW_FUNCTION_WRITE);
//
@@ -317,7 +315,6 @@ FtwWrite ( return Status;
}
-
/**
Restarts a previously interrupted write. The caller must provide the
block protocol needed to complete the interrupted write.
@@ -333,19 +330,19 @@ FtwWrite ( EFI_STATUS
EFIAPI
FtwRestart (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_HANDLE FvBlockHandle
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_HANDLE FvBlockHandle
)
{
- EFI_STATUS Status;
- UINTN PayloadSize;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;
+ EFI_STATUS Status;
+ UINTN PayloadSize;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;
//
// Initialize the communicate buffer.
//
- PayloadSize = sizeof (SMM_FTW_RESTART_HEADER);
+ PayloadSize = sizeof (SMM_FTW_RESTART_HEADER);
InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwRestartHeader, PayloadSize, FTW_FUNCTION_RESTART);
//
@@ -366,7 +363,6 @@ FtwRestart ( return Status;
}
-
/**
Aborts all previously allocated writes.
@@ -380,11 +376,11 @@ FtwRestart ( EFI_STATUS
EFIAPI
FtwAbort (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
)
{
- EFI_STATUS Status;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ EFI_STATUS Status;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
//
// Initialize the communicate buffer.
@@ -400,7 +396,6 @@ FtwAbort ( return Status;
}
-
/**
Starts a target block update. This function records information about the write
in fault-tolerant storage and completes the write in a recoverable
@@ -429,25 +424,25 @@ FtwAbort ( EFI_STATUS
EFIAPI
FtwGetLastWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT EFI_GUID *CallerId,
- OUT EFI_LBA *Lba,
- OUT UINTN *Offset,
- OUT UINTN *Length,
- IN OUT UINTN *PrivateDataSize,
- OUT VOID *PrivateData,
- OUT BOOLEAN *Complete
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT EFI_GUID *CallerId,
+ OUT EFI_LBA *Lba,
+ OUT UINTN *Offset,
+ OUT UINTN *Length,
+ IN OUT UINTN *PrivateDataSize,
+ OUT VOID *PrivateData,
+ OUT BOOLEAN *Complete
)
{
- EFI_STATUS Status;
- UINTN PayloadSize;
- EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
- SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;
+ EFI_STATUS Status;
+ UINTN PayloadSize;
+ EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;
+ SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;
//
// Initialize the communicate buffer.
//
- PayloadSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + *PrivateDataSize;
+ PayloadSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + *PrivateDataSize;
InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwGetLastWriteHeader, PayloadSize, FTW_FUNCTION_GET_LAST_WRITE);
SmmFtwGetLastWriteHeader->PrivateDataSize = *PrivateDataSize;
@@ -460,7 +455,7 @@ FtwGetLastWrite ( // Get data from SMM
//
*PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;
- if (Status == EFI_SUCCESS || Status == EFI_BUFFER_TOO_SMALL) {
+ if ((Status == EFI_SUCCESS) || (Status == EFI_BUFFER_TOO_SMALL)) {
*Lba = SmmFtwGetLastWriteHeader->Lba;
*Offset = SmmFtwGetLastWriteHeader->Offset;
*Length = SmmFtwGetLastWriteHeader->Length;
@@ -488,12 +483,12 @@ FtwGetLastWrite ( VOID
EFIAPI
SmmFtwReady (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
+ EFI_STATUS Status;
+ EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
//
// Just return to avoid install SMM FaultTolerantWriteProtocol again
@@ -504,7 +499,7 @@ SmmFtwReady ( return;
}
- Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2);
+ Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);
ASSERT_EFI_ERROR (Status);
//
@@ -522,7 +517,6 @@ SmmFtwReady ( ASSERT_EFI_ERROR (Status);
}
-
/**
The driver entry point for Fault Tolerant Write driver.
@@ -537,11 +531,11 @@ SmmFtwReady ( EFI_STATUS
EFIAPI
FaultTolerantWriteSmmInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- VOID *SmmFtwRegistration;
+ VOID *SmmFtwRegistration;
//
// Smm FTW driver is ready
@@ -556,4 +550,3 @@ FaultTolerantWriteSmmInitialize ( return EFI_SUCCESS;
}
-
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h index a15644a..894b6de 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h @@ -42,11 +42,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS
EFIAPI
FtwGetMaxBlockSize (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT UINTN *BlockSize
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT UINTN *BlockSize
);
-
/**
Allocates space for the protocol to maintain information about writes.
Since writes must be completed in a fault-tolerant manner and multiple
@@ -71,13 +70,12 @@ FtwGetMaxBlockSize ( EFI_STATUS
EFIAPI
FtwAllocate (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_GUID *CallerId,
- IN UINTN PrivateDataSize,
- IN UINTN NumberOfWrites
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_GUID *CallerId,
+ IN UINTN PrivateDataSize,
+ IN UINTN NumberOfWrites
);
-
/**
Starts a target block update. This records information about the write
in fault tolerant storage, and will complete the write in a recoverable
@@ -108,16 +106,15 @@ FtwAllocate ( EFI_STATUS
EFIAPI
FtwWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN VOID *PrivateData,
- IN EFI_HANDLE FvBlockHandle,
- IN VOID *Buffer
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN VOID *PrivateData,
+ IN EFI_HANDLE FvBlockHandle,
+ IN VOID *Buffer
);
-
/**
Restarts a previously interrupted write. The caller must provide the
block protocol needed to complete the interrupted write.
@@ -133,11 +130,10 @@ FtwWrite ( EFI_STATUS
EFIAPI
FtwRestart (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- IN EFI_HANDLE FvBlockHandle
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ IN EFI_HANDLE FvBlockHandle
);
-
/**
Aborts all previously allocated writes.
@@ -151,10 +147,9 @@ FtwRestart ( EFI_STATUS
EFIAPI
FtwAbort (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
);
-
/**
Starts a target block update. This function records information about the write
in fault-tolerant storage and completes the write in a recoverable
@@ -183,14 +178,14 @@ FtwAbort ( EFI_STATUS
EFIAPI
FtwGetLastWrite (
- IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
- OUT EFI_GUID *CallerId,
- OUT EFI_LBA *Lba,
- OUT UINTN *Offset,
- OUT UINTN *Length,
- IN OUT UINTN *PrivateDataSize,
- OUT VOID *PrivateData,
- OUT BOOLEAN *Complete
+ IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
+ OUT EFI_GUID *CallerId,
+ OUT EFI_LBA *Lba,
+ OUT UINTN *Offset,
+ OUT UINTN *Length,
+ IN OUT UINTN *PrivateDataSize,
+ OUT VOID *PrivateData,
+ OUT BOOLEAN *Complete
);
#endif
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c index 5af49e0..52922a0 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c @@ -51,8 +51,8 @@ FtwSmmIsBufferOutsideSmmValid ( **/
UINT32
FtwCalculateCrc32 (
- IN VOID *Buffer,
- IN UINTN Length
+ IN VOID *Buffer,
+ IN UINTN Length
)
{
return CalculateCrc32 (Buffer, Length);
@@ -82,8 +82,8 @@ FtwNotifySmmReady ( EFI_STATUS
EFIAPI
StandaloneMmFaultTolerantWriteInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
return MmFaultTolerantWriteInitialize ();
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c index 10e56e9..a7241e6 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c @@ -52,12 +52,12 @@ FtwSmmIsBufferOutsideSmmValid ( **/
UINT32
FtwCalculateCrc32 (
- IN VOID *Buffer,
- IN UINTN Length
+ IN VOID *Buffer,
+ IN UINTN Length
)
{
- EFI_STATUS Status;
- UINT32 ReturnValue;
+ EFI_STATUS Status;
+ UINT32 ReturnValue;
Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);
ASSERT_EFI_ERROR (Status);
@@ -73,16 +73,16 @@ FtwNotifySmmReady ( VOID
)
{
- EFI_HANDLE FtwHandle;
- EFI_STATUS Status;
+ EFI_HANDLE FtwHandle;
+ EFI_STATUS Status;
FtwHandle = NULL;
- Status = gBS->InstallProtocolInterface (
- &FtwHandle,
- &gEfiSmmFaultTolerantWriteProtocolGuid,
- EFI_NATIVE_INTERFACE,
- NULL
- );
+ Status = gBS->InstallProtocolInterface (
+ &FtwHandle,
+ &gEfiSmmFaultTolerantWriteProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
ASSERT_EFI_ERROR (Status);
}
@@ -100,8 +100,8 @@ FtwNotifySmmReady ( EFI_STATUS
EFIAPI
SmmFaultTolerantWriteInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
return MmFaultTolerantWriteInitialize ();
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c index dce50e8..661e148 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c @@ -21,13 +21,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
BOOLEAN
IsErasedFlashBuffer (
- IN UINT8 *Buffer,
- IN UINTN BufferSize
+ IN UINT8 *Buffer,
+ IN UINTN BufferSize
)
{
- BOOLEAN IsEmpty;
- UINT8 *Ptr;
- UINTN Index;
+ BOOLEAN IsEmpty;
+ UINT8 *Ptr;
+ UINTN Index;
Ptr = Buffer;
IsEmpty = TRUE;
@@ -89,7 +89,7 @@ FtwEraseBlock ( **/
EFI_STATUS
FtwEraseSpareBlock (
- IN EFI_FTW_DEVICE *FtwDevice
+ IN EFI_FTW_DEVICE *FtwDevice
)
{
return FtwDevice->FtwBackupFvb->EraseBlocks (
@@ -124,11 +124,11 @@ IsWorkingBlock ( // 2. Lba falls into the range of working block.
//
return (BOOLEAN)
- (
- (FvBlock == FtwDevice->FtwFvBlock) &&
- (Lba >= FtwDevice->FtwWorkBlockLba) &&
- (Lba <= FtwDevice->FtwWorkSpaceLba)
- );
+ (
+ (FvBlock == FtwDevice->FtwFvBlock) &&
+ (Lba >= FtwDevice->FtwWorkBlockLba) &&
+ (Lba <= FtwDevice->FtwWorkSpaceLba)
+ );
}
/**
@@ -145,8 +145,8 @@ IsWorkingBlock ( **/
EFI_HANDLE
GetFvbByAddress (
- IN EFI_PHYSICAL_ADDRESS Address,
- OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
+ IN EFI_PHYSICAL_ADDRESS Address,
+ OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
)
{
EFI_STATUS Status;
@@ -159,8 +159,8 @@ GetFvbByAddress ( UINTN BlockSize;
UINTN NumberOfBlocks;
- *FvBlock = NULL;
- FvbHandle = NULL;
+ *FvBlock = NULL;
+ FvbHandle = NULL;
HandleBuffer = NULL;
//
// Locate all handles of Fvb protocol
@@ -169,6 +169,7 @@ GetFvbByAddress ( if (EFI_ERROR (Status)) {
return NULL;
}
+
//
// Get the FVB to access variable store
//
@@ -177,6 +178,7 @@ GetFvbByAddress ( if (EFI_ERROR (Status)) {
break;
}
+
//
// Compare the address and select the right one
//
@@ -195,7 +197,7 @@ GetFvbByAddress ( if ((Address >= FvbBaseAddress) && (Address < (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
*FvBlock = Fvb;
- FvbHandle = HandleBuffer[Index];
+ FvbHandle = HandleBuffer[Index];
break;
}
}
@@ -230,14 +232,15 @@ IsBootBlock ( BOOLEAN IsSwapped;
EFI_HANDLE FvbHandle;
- if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
+ if (!FeaturePcdGet (PcdFullFtwServiceEnable)) {
return FALSE;
}
- Status = FtwGetSarProtocol ((VOID **) &SarProtocol);
+ Status = FtwGetSarProtocol ((VOID **)&SarProtocol);
if (EFI_ERROR (Status)) {
return FALSE;
}
+
//
// Get the boot block range
//
@@ -256,6 +259,7 @@ IsBootBlock ( if (EFI_ERROR (Status)) {
return FALSE;
}
+
//
// Get FVB by address
//
@@ -268,10 +272,11 @@ IsBootBlock ( if (FvbHandle == NULL) {
return FALSE;
}
+
//
// Compare the Fvb
//
- return (BOOLEAN) (FvBlock == BootFvb);
+ return (BOOLEAN)(FvBlock == BootFvb);
}
/**
@@ -302,7 +307,7 @@ IsBootBlock ( **/
EFI_STATUS
FlushSpareBlockToBootBlock (
- EFI_FTW_DEVICE *FtwDevice
+ EFI_FTW_DEVICE *FtwDevice
)
{
EFI_STATUS Status;
@@ -316,25 +321,27 @@ FlushSpareBlockToBootBlock ( EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *BootFvb;
EFI_LBA BootLba;
- if (!FeaturePcdGet(PcdFullFtwServiceEnable)) {
+ if (!FeaturePcdGet (PcdFullFtwServiceEnable)) {
return EFI_UNSUPPORTED;
}
//
// Locate swap address range protocol
//
- Status = FtwGetSarProtocol ((VOID **) &SarProtocol);
+ Status = FtwGetSarProtocol ((VOID **)&SarProtocol);
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// Allocate a memory buffer
//
Length = FtwDevice->SpareAreaLength;
- Buffer = AllocatePool (Length);
+ Buffer = AllocatePool (Length);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Get TopSwap bit state
//
@@ -353,13 +360,14 @@ FlushSpareBlockToBootBlock ( FreePool (Buffer);
return EFI_ABORTED;
}
+
//
// Read data from current boot block
//
BootLba = 0;
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
- Count = FtwDevice->SpareBlockSize;
+ Count = FtwDevice->SpareBlockSize;
Status = BootFvb->Read (
BootFvb,
BootLba + Index,
@@ -380,7 +388,7 @@ FlushSpareBlockToBootBlock ( //
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
- Count = FtwDevice->SpareBlockSize;
+ Count = FtwDevice->SpareBlockSize;
Status = FtwDevice->FtwBackupFvb->Read (
FtwDevice->FtwBackupFvb,
FtwDevice->FtwSpareLba + Index,
@@ -395,6 +403,7 @@ FlushSpareBlockToBootBlock ( Ptr += Count;
}
+
//
// Set TopSwap bit
//
@@ -404,6 +413,7 @@ FlushSpareBlockToBootBlock ( return Status;
}
}
+
//
// Erase current spare block
// Because TopSwap is set, this actually erase the top block (boot block)!
@@ -413,12 +423,13 @@ FlushSpareBlockToBootBlock ( FreePool (Buffer);
return EFI_ABORTED;
}
+
//
// Write memory buffer to current spare block. Still top block.
//
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
- Count = FtwDevice->SpareBlockSize;
+ Count = FtwDevice->SpareBlockSize;
Status = FtwDevice->FtwBackupFvb->Write (
FtwDevice->FtwBackupFvb,
FtwDevice->FtwSpareLba + Index,
@@ -482,20 +493,22 @@ FlushSpareBlockToTargetBlock ( if ((FtwDevice == NULL) || (FvBlock == NULL)) {
return EFI_INVALID_PARAMETER;
}
+
//
// Allocate a memory buffer
//
Length = FtwDevice->SpareAreaLength;
- Buffer = AllocatePool (Length);
+ Buffer = AllocatePool (Length);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Read all content of spare block to memory buffer
//
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
- Count = FtwDevice->SpareBlockSize;
+ Count = FtwDevice->SpareBlockSize;
Status = FtwDevice->FtwBackupFvb->Read (
FtwDevice->FtwBackupFvb,
FtwDevice->FtwSpareLba + Index,
@@ -510,6 +523,7 @@ FlushSpareBlockToTargetBlock ( Ptr += Count;
}
+
//
// Erase the target block
//
@@ -518,13 +532,14 @@ FlushSpareBlockToTargetBlock ( FreePool (Buffer);
return EFI_ABORTED;
}
+
//
// Write memory buffer to block, using the FvBlock protocol interface
//
Ptr = Buffer;
for (Index = 0; Index < NumberOfBlocks; Index += 1) {
- Count = BlockSize;
- Status = FvBlock->Write (FvBlock, Lba + Index, 0, &Count, Ptr);
+ Count = BlockSize;
+ Status = FvBlock->Write (FvBlock, Lba + Index, 0, &Count, Ptr);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Ftw: FVB Write block - %r\n", Status));
FreePool (Buffer);
@@ -559,22 +574,22 @@ FlushSpareBlockToTargetBlock ( **/
EFI_STATUS
FlushSpareBlockToWorkingBlock (
- EFI_FTW_DEVICE *FtwDevice
+ EFI_FTW_DEVICE *FtwDevice
)
{
- EFI_STATUS Status;
- UINTN Length;
- UINT8 *Buffer;
- EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
- UINTN Count;
- UINT8 *Ptr;
- UINTN Index;
+ EFI_STATUS Status;
+ UINTN Length;
+ UINT8 *Buffer;
+ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
+ UINTN Count;
+ UINT8 *Ptr;
+ UINTN Index;
//
// Allocate a memory buffer
//
Length = FtwDevice->SpareAreaLength;
- Buffer = AllocatePool (Length);
+ Buffer = AllocatePool (Length);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -598,7 +613,7 @@ FlushSpareBlockToWorkingBlock ( //
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
- Count = FtwDevice->SpareBlockSize;
+ Count = FtwDevice->SpareBlockSize;
Status = FtwDevice->FtwBackupFvb->Read (
FtwDevice->FtwBackupFvb,
FtwDevice->FtwSpareLba + Index,
@@ -613,10 +628,11 @@ FlushSpareBlockToWorkingBlock ( Ptr += Count;
}
+
//
// Clear the CRC and STATE, copy data from spare to working block.
//
- WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (Buffer + (UINTN) FtwDevice->FtwWorkSpaceLbaInSpare * FtwDevice->SpareBlockSize + FtwDevice->FtwWorkSpaceBaseInSpare);
+ WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *)(Buffer + (UINTN)FtwDevice->FtwWorkSpaceLbaInSpare * FtwDevice->SpareBlockSize + FtwDevice->FtwWorkSpaceBaseInSpare);
InitWorkSpaceHeader (WorkingBlockHeader);
WorkingBlockHeader->WorkingBlockValid = FTW_ERASE_POLARITY;
WorkingBlockHeader->WorkingBlockInvalid = FTW_ERASE_POLARITY;
@@ -632,12 +648,12 @@ FlushSpareBlockToWorkingBlock ( // skip Signature and Crc.
//
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
- WORKING_BLOCK_INVALID
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
+ WORKING_BLOCK_INVALID
+ );
if (EFI_ERROR (Status)) {
FreePool (Buffer);
return EFI_ABORTED;
@@ -653,12 +669,13 @@ FlushSpareBlockToWorkingBlock ( FreePool (Buffer);
return EFI_ABORTED;
}
+
//
// Write memory buffer to working block, using the FvBlock protocol interface
//
Ptr = Buffer;
for (Index = 0; Index < FtwDevice->NumberOfWorkBlock; Index += 1) {
- Count = FtwDevice->WorkBlockSize;
+ Count = FtwDevice->WorkBlockSize;
Status = FtwDevice->FtwFvBlock->Write (
FtwDevice->FtwFvBlock,
FtwDevice->FtwWorkBlockLba + Index,
@@ -674,6 +691,7 @@ FlushSpareBlockToWorkingBlock ( Ptr += Count;
}
+
//
// Since the memory buffer will not be used, free memory Buffer.
//
@@ -686,18 +704,18 @@ FlushSpareBlockToWorkingBlock ( // So hardcode offset as sizeof(EFI_GUID)+sizeof(UINT32) to skip Signature and Crc.
//
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
- WORKING_BLOCK_VALID
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
+ WORKING_BLOCK_VALID
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
FtwDevice->FtwWorkSpaceHeader->WorkingBlockInvalid = FTW_INVALID_STATE;
- FtwDevice->FtwWorkSpaceHeader->WorkingBlockValid = FTW_VALID_STATE;
+ FtwDevice->FtwWorkSpaceHeader->WorkingBlockValid = FTW_VALID_STATE;
return EFI_SUCCESS;
}
@@ -745,21 +763,21 @@ FtwUpdateFvState ( //
// Read state from device, assume State is only one byte.
//
- Length = sizeof (UINT8);
- Status = FvBlock->Read (FvBlock, Lba, Offset, &Length, &State);
+ Length = sizeof (UINT8);
+ Status = FvBlock->Read (FvBlock, Lba, Offset, &Length, &State);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
State ^= FTW_POLARITY_REVERT;
- State = (UINT8) (State | NewBit);
+ State = (UINT8)(State | NewBit);
State ^= FTW_POLARITY_REVERT;
//
// Write state back to device
//
- Length = sizeof (UINT8);
- Status = FvBlock->Write (FvBlock, Lba, Offset, &Length, &State);
+ Length = sizeof (UINT8);
+ Status = FvBlock->Write (FvBlock, Lba, Offset, &Length, &State);
return Status;
}
@@ -785,11 +803,11 @@ FtwGetLastWriteHeader ( OUT EFI_FAULT_TOLERANT_WRITE_HEADER **FtwWriteHeader
)
{
- UINTN Offset;
- EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader;
+ UINTN Offset;
+ EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader;
*FtwWriteHeader = NULL;
- FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *) (FtwWorkSpaceHeader + 1);
+ FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *)(FtwWorkSpaceHeader + 1);
Offset = sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
while (FtwHeader->Complete == FTW_VALID_STATE) {
@@ -802,8 +820,9 @@ FtwGetLastWriteHeader ( return EFI_ABORTED;
}
- FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *) ((UINT8 *) FtwWorkSpaceHeader + Offset);
+ FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *)((UINT8 *)FtwWorkSpaceHeader + Offset);
}
+
//
// Last write header is found
//
@@ -827,15 +846,15 @@ FtwGetLastWriteHeader ( **/
EFI_STATUS
FtwGetLastWriteRecord (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,
- OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,
+ OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord
)
{
- UINTN Index;
- EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord;
+ UINTN Index;
+ EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord;
*FtwWriteRecord = NULL;
- FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) (FtwWriteHeader + 1);
+ FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *)(FtwWriteHeader + 1);
//
// Try to find the last write record "that has not completed"
@@ -852,9 +871,10 @@ FtwGetLastWriteRecord ( FtwRecord++;
if (FtwWriteHeader->PrivateDataSize != 0) {
- FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) ((UINTN) FtwRecord + (UINTN) FtwWriteHeader->PrivateDataSize);
+ FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *)((UINTN)FtwRecord + (UINTN)FtwWriteHeader->PrivateDataSize);
}
}
+
//
// if Index == NumberOfWrites, then
// the last record has been written successfully,
@@ -862,7 +882,7 @@ FtwGetLastWriteRecord ( // also return the last record.
//
if (Index == FtwWriteHeader->NumberOfWrites) {
- *FtwWriteRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) ((UINTN) FtwRecord - FTW_RECORD_SIZE (FtwWriteHeader->PrivateDataSize));
+ *FtwWriteRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *)((UINTN)FtwRecord - FTW_RECORD_SIZE (FtwWriteHeader->PrivateDataSize));
return EFI_SUCCESS;
}
@@ -881,18 +901,18 @@ FtwGetLastWriteRecord ( **/
BOOLEAN
IsFirstRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
)
{
- UINT8 *Head;
- UINT8 *Ptr;
+ UINT8 *Head;
+ UINT8 *Ptr;
- Head = (UINT8 *) FtwHeader;
- Ptr = (UINT8 *) FtwRecord;
+ Head = (UINT8 *)FtwHeader;
+ Ptr = (UINT8 *)FtwRecord;
Head += sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER);
- return (BOOLEAN) (Head == Ptr);
+ return (BOOLEAN)(Head == Ptr);
}
/**
@@ -909,18 +929,18 @@ IsFirstRecordOfWrites ( **/
BOOLEAN
IsLastRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
)
{
- UINT8 *Head;
- UINT8 *Ptr;
+ UINT8 *Head;
+ UINT8 *Ptr;
- Head = (UINT8 *) FtwHeader;
- Ptr = (UINT8 *) FtwRecord;
+ Head = (UINT8 *)FtwHeader;
+ Ptr = (UINT8 *)FtwRecord;
Head += FTW_WRITE_TOTAL_SIZE (FtwHeader->NumberOfWrites - 1, FtwHeader->PrivateDataSize);
- return (BOOLEAN) (Head == Ptr);
+ return (BOOLEAN)(Head == Ptr);
}
/**
@@ -935,20 +955,20 @@ IsLastRecordOfWrites ( **/
EFI_STATUS
GetPreviousRecordOfWrites (
- IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
- IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord
+ IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
+ IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord
)
{
- UINT8 *Ptr;
+ UINT8 *Ptr;
if (IsFirstRecordOfWrites (FtwHeader, *FtwRecord)) {
*FtwRecord = NULL;
return EFI_ACCESS_DENIED;
}
- Ptr = (UINT8 *) (*FtwRecord);
- Ptr -= FTW_RECORD_SIZE (FtwHeader->PrivateDataSize);
- *FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) Ptr;
+ Ptr = (UINT8 *)(*FtwRecord);
+ Ptr -= FTW_RECORD_SIZE (FtwHeader->PrivateDataSize);
+ *FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *)Ptr;
return EFI_SUCCESS;
}
@@ -964,10 +984,10 @@ GetPreviousRecordOfWrites ( **/
EFI_STATUS
InitFtwDevice (
- OUT EFI_FTW_DEVICE **FtwData
+ OUT EFI_FTW_DEVICE **FtwData
)
{
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_FTW_DEVICE *FtwDevice;
//
// Allocate private data of this driver,
@@ -981,35 +1001,34 @@ InitFtwDevice ( //
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
- FtwDevice->WorkSpaceLength = (UINTN) PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
- FtwDevice->SpareAreaLength = (UINTN) PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ FtwDevice->WorkSpaceLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ FtwDevice->SpareAreaLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
if ((FtwDevice->WorkSpaceLength == 0) || (FtwDevice->SpareAreaLength == 0)) {
DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\n"));
FreePool (FtwDevice);
return EFI_INVALID_PARAMETER;
}
- FtwDevice->Signature = FTW_DEVICE_SIGNATURE;
- FtwDevice->FtwFvBlock = NULL;
- FtwDevice->FtwBackupFvb = NULL;
- FtwDevice->FtwWorkSpaceLba = (EFI_LBA) (-1);
- FtwDevice->FtwSpareLba = (EFI_LBA) (-1);
+ FtwDevice->Signature = FTW_DEVICE_SIGNATURE;
+ FtwDevice->FtwFvBlock = NULL;
+ FtwDevice->FtwBackupFvb = NULL;
+ FtwDevice->FtwWorkSpaceLba = (EFI_LBA)(-1);
+ FtwDevice->FtwSpareLba = (EFI_LBA)(-1);
- FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
+ FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
if (FtwDevice->WorkSpaceAddress == 0) {
- FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
+ FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
}
- FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
+ FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
if (FtwDevice->SpareAreaAddress == 0) {
- FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageFtwSpareBase);
+ FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwSpareBase);
}
*FtwData = FtwDevice;
return EFI_SUCCESS;
}
-
/**
Find the proper Firmware Volume Block protocol for FTW operation.
@@ -1022,7 +1041,7 @@ InitFtwDevice ( **/
EFI_STATUS
FindFvbForFtw (
- IN OUT EFI_FTW_DEVICE *FtwDevice
+ IN OUT EFI_FTW_DEVICE *FtwDevice
)
{
EFI_STATUS Status;
@@ -1064,6 +1083,7 @@ FindFvbForFtw ( if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) {
continue;
}
+
//
// Compare the address and select the right one
//
@@ -1081,28 +1101,31 @@ FindFvbForFtw ( }
if ((FtwDevice->FtwFvBlock == NULL) && (FtwDevice->WorkSpaceAddress >= FvbBaseAddress) &&
- ((FtwDevice->WorkSpaceAddress + FtwDevice->WorkSpaceLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
+ ((FtwDevice->WorkSpaceAddress + FtwDevice->WorkSpaceLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks)))
+ {
FtwDevice->FtwFvBlock = Fvb;
//
// To get the LBA of work space
//
for (LbaIndex = 1; LbaIndex <= NumberOfBlocks; LbaIndex += 1) {
- if ((FtwDevice->WorkSpaceAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
- && (FtwDevice->WorkSpaceAddress < (FvbBaseAddress + BlockSize * LbaIndex))) {
+ if ( (FtwDevice->WorkSpaceAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
+ && (FtwDevice->WorkSpaceAddress < (FvbBaseAddress + BlockSize * LbaIndex)))
+ {
FtwDevice->FtwWorkSpaceLba = LbaIndex - 1;
//
// Get the Work space size and Base(Offset)
//
- FtwDevice->FtwWorkSpaceSize = FtwDevice->WorkSpaceLength;
- FtwDevice->WorkBlockSize = BlockSize;
- FtwDevice->FtwWorkSpaceBase = (UINTN) (FtwDevice->WorkSpaceAddress - (FvbBaseAddress + FtwDevice->WorkBlockSize * (LbaIndex - 1)));
+ FtwDevice->FtwWorkSpaceSize = FtwDevice->WorkSpaceLength;
+ FtwDevice->WorkBlockSize = BlockSize;
+ FtwDevice->FtwWorkSpaceBase = (UINTN)(FtwDevice->WorkSpaceAddress - (FvbBaseAddress + FtwDevice->WorkBlockSize * (LbaIndex - 1)));
FtwDevice->NumberOfWorkSpaceBlock = FTW_BLOCKS (FtwDevice->FtwWorkSpaceBase + FtwDevice->FtwWorkSpaceSize, FtwDevice->WorkBlockSize);
if (FtwDevice->FtwWorkSpaceSize >= FtwDevice->WorkBlockSize) {
//
// Check the alignment of work space address and length, they should be block size aligned when work space size is larger than one block size.
//
if (((FtwDevice->WorkSpaceAddress & (FtwDevice->WorkBlockSize - 1)) != 0) ||
- ((FtwDevice->WorkSpaceLength & (FtwDevice->WorkBlockSize - 1)) != 0)) {
+ ((FtwDevice->WorkSpaceLength & (FtwDevice->WorkBlockSize - 1)) != 0))
+ {
DEBUG ((DEBUG_ERROR, "Ftw: Work space address or length is not block size aligned when work space size is larger than one block size\n"));
FreePool (HandleBuffer);
ASSERT (FALSE);
@@ -1114,20 +1137,23 @@ FindFvbForFtw ( ASSERT (FALSE);
return EFI_ABORTED;
}
+
break;
}
}
}
if ((FtwDevice->FtwBackupFvb == NULL) && (FtwDevice->SpareAreaAddress >= FvbBaseAddress) &&
- ((FtwDevice->SpareAreaAddress + FtwDevice->SpareAreaLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
+ ((FtwDevice->SpareAreaAddress + FtwDevice->SpareAreaLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks)))
+ {
FtwDevice->FtwBackupFvb = Fvb;
//
// To get the LBA of spare
//
for (LbaIndex = 1; LbaIndex <= NumberOfBlocks; LbaIndex += 1) {
- if ((FtwDevice->SpareAreaAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
- && (FtwDevice->SpareAreaAddress < (FvbBaseAddress + BlockSize * LbaIndex))) {
+ if ( (FtwDevice->SpareAreaAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
+ && (FtwDevice->SpareAreaAddress < (FvbBaseAddress + BlockSize * LbaIndex)))
+ {
//
// Get the NumberOfSpareBlock and BlockSize
//
@@ -1143,11 +1169,13 @@ FindFvbForFtw ( ASSERT (FALSE);
return EFI_ABORTED;
}
+
//
// Check the alignment of spare area address and length, they should be block size aligned
//
if (((FtwDevice->SpareAreaAddress & (FtwDevice->SpareBlockSize - 1)) != 0) ||
- ((FtwDevice->SpareAreaLength & (FtwDevice->SpareBlockSize - 1)) != 0)) {
+ ((FtwDevice->SpareAreaLength & (FtwDevice->SpareBlockSize - 1)) != 0))
+ {
DEBUG ((DEBUG_ERROR, "Ftw: Spare area address or length is not block size aligned\n"));
FreePool (HandleBuffer);
//
@@ -1157,24 +1185,27 @@ FindFvbForFtw ( ASSERT (FALSE);
CpuDeadLoop ();
}
+
break;
}
}
}
}
+
FreePool (HandleBuffer);
if ((FtwDevice->FtwBackupFvb == NULL) || (FtwDevice->FtwFvBlock == NULL) ||
- (FtwDevice->FtwWorkSpaceLba == (EFI_LBA) (-1)) || (FtwDevice->FtwSpareLba == (EFI_LBA) (-1))) {
+ (FtwDevice->FtwWorkSpaceLba == (EFI_LBA)(-1)) || (FtwDevice->FtwSpareLba == (EFI_LBA)(-1)))
+ {
return EFI_ABORTED;
}
+
DEBUG ((DEBUG_INFO, "Ftw: FtwWorkSpaceLba - 0x%lx, WorkBlockSize - 0x%x, FtwWorkSpaceBase - 0x%x\n", FtwDevice->FtwWorkSpaceLba, FtwDevice->WorkBlockSize, FtwDevice->FtwWorkSpaceBase));
DEBUG ((DEBUG_INFO, "Ftw: FtwSpareLba - 0x%lx, SpareBlockSize - 0x%x\n", FtwDevice->FtwSpareLba, FtwDevice->SpareBlockSize));
return EFI_SUCCESS;
}
-
/**
Initialization for Fault Tolerant Write protocol.
@@ -1186,7 +1217,7 @@ FindFvbForFtw ( **/
EFI_STATUS
InitFtwProtocol (
- IN OUT EFI_FTW_DEVICE *FtwDevice
+ IN OUT EFI_FTW_DEVICE *FtwDevice
)
{
EFI_STATUS Status;
@@ -1219,11 +1250,12 @@ InitFtwProtocol ( // block, unless there are not enough blocks before the block that contains
// working space.
//
- FtwDevice->NumberOfWorkBlock = (UINTN) (FtwDevice->FtwWorkSpaceLba + FtwDevice->NumberOfWorkSpaceBlock);
+ FtwDevice->NumberOfWorkBlock = (UINTN)(FtwDevice->FtwWorkSpaceLba + FtwDevice->NumberOfWorkSpaceBlock);
while (FtwDevice->NumberOfWorkBlock * FtwDevice->WorkBlockSize > FtwDevice->SpareAreaLength) {
FtwDevice->NumberOfWorkBlock--;
}
}
+
FtwDevice->FtwWorkBlockLba = FtwDevice->FtwWorkSpaceLba + FtwDevice->NumberOfWorkSpaceBlock - FtwDevice->NumberOfWorkBlock;
DEBUG ((DEBUG_INFO, "Ftw: NumberOfWorkBlock - 0x%x, FtwWorkBlockLba - 0x%lx\n", FtwDevice->NumberOfWorkBlock, FtwDevice->FtwWorkBlockLba));
@@ -1231,16 +1263,16 @@ InitFtwProtocol ( // Calcualte the LBA and base of work space in spare block.
// Note: Do not assume Spare Block and Work Block have same block size.
//
- WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
- FtwDevice->FtwWorkSpaceLbaInSpare = (EFI_LBA) (((UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) / FtwDevice->SpareBlockSize);
- FtwDevice->FtwWorkSpaceBaseInSpare = ((UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) % FtwDevice->SpareBlockSize;
+ WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
+ FtwDevice->FtwWorkSpaceLbaInSpare = (EFI_LBA)(((UINTN)WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) / FtwDevice->SpareBlockSize);
+ FtwDevice->FtwWorkSpaceBaseInSpare = ((UINTN)WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) % FtwDevice->SpareBlockSize;
DEBUG ((DEBUG_INFO, "Ftw: WorkSpaceLbaInSpare - 0x%lx, WorkSpaceBaseInSpare - 0x%x\n", FtwDevice->FtwWorkSpaceLbaInSpare, FtwDevice->FtwWorkSpaceBaseInSpare));
//
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
- FtwDevice->FtwWorkSpace = (UINT8 *) (FtwDevice + 1);
- FtwDevice->FtwWorkSpaceHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) FtwDevice->FtwWorkSpace;
+ FtwDevice->FtwWorkSpace = (UINT8 *)(FtwDevice + 1);
+ FtwDevice->FtwWorkSpaceHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *)FtwDevice->FtwWorkSpace;
FtwDevice->FtwLastWriteHeader = NULL;
FtwDevice->FtwLastWriteRecord = NULL;
@@ -1274,8 +1306,12 @@ InitFtwProtocol ( //
if (IsValidWorkSpace (FtwDevice->FtwWorkSpaceHeader)) {
Status = FlushSpareBlockToWorkingBlock (FtwDevice);
- DEBUG ((DEBUG_INFO, "Ftw: Restart working block update in %a() - %r\n",
- __FUNCTION__, Status));
+ DEBUG ((
+ DEBUG_INFO,
+ "Ftw: Restart working block update in %a() - %r\n",
+ __FUNCTION__,
+ Status
+ ));
FtwAbort (&FtwDevice->FtwInstance);
//
// Refresh work space.
@@ -1283,8 +1319,10 @@ InitFtwProtocol ( Status = WorkSpaceRefresh (FtwDevice);
ASSERT_EFI_ERROR (Status);
} else {
- DEBUG ((DEBUG_INFO,
- "Ftw: Both working and spare blocks are invalid, init workspace\n"));
+ DEBUG ((
+ DEBUG_INFO,
+ "Ftw: Both working and spare blocks are invalid, init workspace\n"
+ ));
//
// If both are invalid, then initialize work space.
//
@@ -1301,34 +1339,39 @@ InitFtwProtocol ( ASSERT_EFI_ERROR (Status);
}
}
+
//
// If the FtwDevice->FtwLastWriteRecord is 1st record of write header &&
// (! SpareComplete) THEN call Abort().
//
if ((FtwDevice->FtwLastWriteHeader->HeaderAllocated == FTW_VALID_STATE) &&
- (FtwDevice->FtwLastWriteRecord->SpareComplete != FTW_VALID_STATE) &&
- IsFirstRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
- ) {
+ (FtwDevice->FtwLastWriteRecord->SpareComplete != FTW_VALID_STATE) &&
+ IsFirstRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
+ )
+ {
DEBUG ((DEBUG_ERROR, "Ftw: Init.. find first record not SpareCompleted, abort()\n"));
FtwAbort (&FtwDevice->FtwInstance);
}
+
//
// If Header is incompleted and the last record has completed, then
// call Abort() to set the Header->Complete FLAG.
//
if ((FtwDevice->FtwLastWriteHeader->Complete != FTW_VALID_STATE) &&
- (FtwDevice->FtwLastWriteRecord->DestinationComplete == FTW_VALID_STATE) &&
- IsLastRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
- ) {
+ (FtwDevice->FtwLastWriteRecord->DestinationComplete == FTW_VALID_STATE) &&
+ IsLastRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
+ )
+ {
DEBUG ((DEBUG_ERROR, "Ftw: Init.. find last record completed but header not, abort()\n"));
FtwAbort (&FtwDevice->FtwInstance);
}
+
//
// To check the workspace buffer following last Write header/records is EMPTY or not.
// If it's not EMPTY, FTW also need to call reclaim().
//
FtwHeader = FtwDevice->FtwLastWriteHeader;
- Offset = (UINT8 *) FtwHeader - FtwDevice->FtwWorkSpace;
+ Offset = (UINT8 *)FtwHeader - FtwDevice->FtwWorkSpace;
if (FtwDevice->FtwWorkSpace[Offset] != FTW_ERASED_BYTE) {
Offset += FTW_WRITE_TOTAL_SIZE (FtwHeader->NumberOfWrites, FtwHeader->PrivateDataSize);
}
@@ -1342,8 +1385,9 @@ InitFtwProtocol ( // Restart if it's boot block
//
if ((FtwDevice->FtwLastWriteHeader->Complete != FTW_VALID_STATE) &&
- (FtwDevice->FtwLastWriteRecord->SpareComplete == FTW_VALID_STATE)
- ) {
+ (FtwDevice->FtwLastWriteRecord->SpareComplete == FTW_VALID_STATE)
+ )
+ {
if (FtwDevice->FtwLastWriteRecord->BootBlockUpdate == FTW_VALID_STATE) {
Status = FlushSpareBlockToBootBlock (FtwDevice);
DEBUG ((DEBUG_ERROR, "Ftw: Restart boot block update - %r\n", Status));
@@ -1354,15 +1398,17 @@ InitFtwProtocol ( // if (SpareCompleted) THEN Restart to fault tolerant write.
//
FvbHandle = NULL;
- FvbHandle = GetFvbByAddress ((EFI_PHYSICAL_ADDRESS) (UINTN) ((INT64) FtwDevice->SpareAreaAddress + FtwDevice->FtwLastWriteRecord->RelativeOffset), &Fvb);
+ FvbHandle = GetFvbByAddress ((EFI_PHYSICAL_ADDRESS)(UINTN)((INT64)FtwDevice->SpareAreaAddress + FtwDevice->FtwLastWriteRecord->RelativeOffset), &Fvb);
if (FvbHandle != NULL) {
Status = FtwRestart (&FtwDevice->FtwInstance, FvbHandle);
DEBUG ((DEBUG_ERROR, "Ftw: Restart last write - %r\n", Status));
ASSERT_EFI_ERROR (Status);
}
+
FtwAbort (&FtwDevice->FtwInstance);
}
}
+
//
// Hook the protocol API
//
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c index 703da6d..61e7a92 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c @@ -7,10 +7,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#include "FaultTolerantWrite.h"
-EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = {ZERO_GUID, 0, 0, 0, 0, {0, 0, 0}, 0};
+EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = { ZERO_GUID, 0, 0, 0, 0, { 0, 0, 0 }, 0 };
/**
Initialize a local work space header.
@@ -56,11 +55,13 @@ InitializeLocalWorkSpaceHeader ( //
// Calculate the Crc of woking block header
//
- mWorkingBlockHeader.Crc = FtwCalculateCrc32 (&mWorkingBlockHeader,
- sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
+ mWorkingBlockHeader.Crc = FtwCalculateCrc32 (
+ &mWorkingBlockHeader,
+ sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)
+ );
- mWorkingBlockHeader.WorkingBlockValid = FTW_VALID_STATE;
- mWorkingBlockHeader.WorkingBlockInvalid = FTW_INVALID_STATE;
+ mWorkingBlockHeader.WorkingBlockValid = FTW_VALID_STATE;
+ mWorkingBlockHeader.WorkingBlockInvalid = FTW_INVALID_STATE;
}
/**
@@ -75,7 +76,7 @@ InitializeLocalWorkSpaceHeader ( **/
BOOLEAN
IsValidWorkSpace (
- IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+ IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
)
{
if (WorkingHeader == NULL) {
@@ -101,7 +102,7 @@ IsValidWorkSpace ( **/
EFI_STATUS
InitWorkSpaceHeader (
- IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+ IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
)
{
if (WorkingHeader == NULL) {
@@ -129,17 +130,17 @@ InitWorkSpaceHeader ( **/
EFI_STATUS
ReadWorkSpaceData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
- IN UINTN BlockSize,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- OUT UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
+ IN UINTN BlockSize,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ OUT UINT8 *Buffer
)
{
- EFI_STATUS Status;
- UINT8 *Ptr;
- UINTN MyLength;
+ EFI_STATUS Status;
+ UINT8 *Ptr;
+ UINTN MyLength;
//
// Calculate the real Offset and Lba to write.
@@ -167,9 +168,10 @@ ReadWorkSpaceData ( if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
- Offset = 0;
+
+ Offset = 0;
Length -= MyLength;
- Ptr += MyLength;
+ Ptr += MyLength;
Lba++;
}
@@ -192,17 +194,17 @@ ReadWorkSpaceData ( **/
EFI_STATUS
WriteWorkSpaceData (
- IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
- IN UINTN BlockSize,
- IN EFI_LBA Lba,
- IN UINTN Offset,
- IN UINTN Length,
- IN UINT8 *Buffer
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
+ IN UINTN BlockSize,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN UINT8 *Buffer
)
{
- EFI_STATUS Status;
- UINT8 *Ptr;
- UINTN MyLength;
+ EFI_STATUS Status;
+ UINT8 *Ptr;
+ UINTN MyLength;
//
// Calculate the real Offset and Lba to write.
@@ -230,11 +232,13 @@ WriteWorkSpaceData ( if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
- Offset = 0;
+
+ Offset = 0;
Length -= MyLength;
- Ptr += MyLength;
+ Ptr += MyLength;
Lba++;
}
+
return EFI_SUCCESS;
}
@@ -252,8 +256,8 @@ WorkSpaceRefresh ( IN EFI_FTW_DEVICE *FtwDevice
)
{
- EFI_STATUS Status;
- UINTN RemainingSpaceSize;
+ EFI_STATUS Status;
+ UINTN RemainingSpaceSize;
//
// Initialize WorkSpace as FTW_ERASED_BYTE
@@ -278,15 +282,16 @@ WorkSpaceRefresh ( if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
+
//
// Refresh the FtwLastWriteHeader
//
Status = FtwGetLastWriteHeader (
- FtwDevice->FtwWorkSpaceHeader,
- FtwDevice->FtwWorkSpaceSize,
- &FtwDevice->FtwLastWriteHeader
- );
- RemainingSpaceSize = FtwDevice->FtwWorkSpaceSize - ((UINTN) FtwDevice->FtwLastWriteHeader - (UINTN) FtwDevice->FtwWorkSpace);
+ FtwDevice->FtwWorkSpaceHeader,
+ FtwDevice->FtwWorkSpaceSize,
+ &FtwDevice->FtwLastWriteHeader
+ );
+ RemainingSpaceSize = FtwDevice->FtwWorkSpaceSize - ((UINTN)FtwDevice->FtwLastWriteHeader - (UINTN)FtwDevice->FtwWorkSpace);
DEBUG ((DEBUG_INFO, "Ftw: Remaining work space size - %x\n", RemainingSpaceSize));
//
// If FtwGetLastWriteHeader() returns error, or the remaining space size is even not enough to contain
@@ -294,7 +299,7 @@ WorkSpaceRefresh ( // pointed by FtwDevice->FtwLastWriteHeader or record pointed by FtwDevice->FtwLastWriteRecord may contain invalid data),
// it needs to reclaim work space.
//
- if (EFI_ERROR (Status) || RemainingSpaceSize < sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER) + sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD)) {
+ if (EFI_ERROR (Status) || (RemainingSpaceSize < sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER) + sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD))) {
//
// reclaim work space in working block.
//
@@ -303,6 +308,7 @@ WorkSpaceRefresh ( DEBUG ((DEBUG_ERROR, "Ftw: Reclaim workspace - %r\n", Status));
return EFI_ABORTED;
}
+
//
// Read from working block again
//
@@ -319,21 +325,22 @@ WorkSpaceRefresh ( }
Status = FtwGetLastWriteHeader (
- FtwDevice->FtwWorkSpaceHeader,
- FtwDevice->FtwWorkSpaceSize,
- &FtwDevice->FtwLastWriteHeader
- );
+ FtwDevice->FtwWorkSpaceHeader,
+ FtwDevice->FtwWorkSpaceSize,
+ &FtwDevice->FtwLastWriteHeader
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
}
+
//
// Refresh the FtwLastWriteRecord
//
Status = FtwGetLastWriteRecord (
- FtwDevice->FtwLastWriteHeader,
- &FtwDevice->FtwLastWriteRecord
- );
+ FtwDevice->FtwLastWriteHeader,
+ &FtwDevice->FtwLastWriteRecord
+ );
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -358,17 +365,17 @@ FtwReclaimWorkSpace ( IN BOOLEAN PreserveRecord
)
{
- EFI_STATUS Status;
- UINTN Length;
- EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
- UINT8 *TempBuffer;
- UINTN TempBufferSize;
- UINTN SpareBufferSize;
- UINT8 *SpareBuffer;
- EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
- UINTN Index;
- UINT8 *Ptr;
- EFI_LBA WorkSpaceLbaOffset;
+ EFI_STATUS Status;
+ UINTN Length;
+ EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
+ UINT8 *TempBuffer;
+ UINTN TempBufferSize;
+ UINTN SpareBufferSize;
+ UINT8 *SpareBuffer;
+ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
+ UINTN Index;
+ UINT8 *Ptr;
+ EFI_LBA WorkSpaceLbaOffset;
DEBUG ((DEBUG_INFO, "Ftw: start to reclaim work space\n"));
@@ -387,12 +394,12 @@ FtwReclaimWorkSpace ( for (Index = 0; Index < FtwDevice->NumberOfWorkBlock; Index += 1) {
Length = FtwDevice->WorkBlockSize;
Status = FtwDevice->FtwFvBlock->Read (
- FtwDevice->FtwFvBlock,
- FtwDevice->FtwWorkBlockLba + Index,
- 0,
- &Length,
- Ptr
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->FtwWorkBlockLba + Index,
+ 0,
+ &Length,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
FreePool (TempBuffer);
return EFI_ABORTED;
@@ -400,11 +407,12 @@ FtwReclaimWorkSpace ( Ptr += Length;
}
+
//
// Clean up the workspace, remove all the completed records.
//
Ptr = TempBuffer +
- (UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize +
+ (UINTN)WorkSpaceLbaOffset * FtwDevice->WorkBlockSize +
FtwDevice->FtwWorkSpaceBase;
//
@@ -459,9 +467,9 @@ FtwReclaimWorkSpace ( //
// Set the WorkingBlockValid and WorkingBlockInvalid as INVALID
//
- WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (TempBuffer +
- (UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize +
- FtwDevice->FtwWorkSpaceBase);
+ WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *)(TempBuffer +
+ (UINTN)WorkSpaceLbaOffset * FtwDevice->WorkBlockSize +
+ FtwDevice->FtwWorkSpaceBase);
WorkingBlockHeader->WorkingBlockValid = FTW_INVALID_STATE;
WorkingBlockHeader->WorkingBlockInvalid = FTW_INVALID_STATE;
@@ -494,38 +502,42 @@ FtwReclaimWorkSpace ( Ptr += Length;
}
+
//
// Write the memory buffer to spare block
//
- Status = FtwEraseSpareBlock (FtwDevice);
+ Status = FtwEraseSpareBlock (FtwDevice);
if (EFI_ERROR (Status)) {
FreePool (TempBuffer);
FreePool (SpareBuffer);
return EFI_ABORTED;
}
- Ptr = TempBuffer;
+
+ Ptr = TempBuffer;
for (Index = 0; TempBufferSize > 0; Index += 1) {
if (TempBufferSize > FtwDevice->SpareBlockSize) {
Length = FtwDevice->SpareBlockSize;
} else {
Length = TempBufferSize;
}
+
Status = FtwDevice->FtwBackupFvb->Write (
- FtwDevice->FtwBackupFvb,
- FtwDevice->FtwSpareLba + Index,
- 0,
- &Length,
- Ptr
- );
+ FtwDevice->FtwBackupFvb,
+ FtwDevice->FtwSpareLba + Index,
+ 0,
+ &Length,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
FreePool (TempBuffer);
FreePool (SpareBuffer);
return EFI_ABORTED;
}
- Ptr += Length;
+ Ptr += Length;
TempBufferSize -= Length;
}
+
//
// Free TempBuffer
//
@@ -535,16 +547,17 @@ FtwReclaimWorkSpace ( // Set the WorkingBlockValid in spare block
//
Status = FtwUpdateFvState (
- FtwDevice->FtwBackupFvb,
- FtwDevice->SpareBlockSize,
- FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
- FtwDevice->FtwWorkSpaceBaseInSpare + sizeof (EFI_GUID) + sizeof (UINT32),
- WORKING_BLOCK_VALID
- );
+ FtwDevice->FtwBackupFvb,
+ FtwDevice->SpareBlockSize,
+ FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
+ FtwDevice->FtwWorkSpaceBaseInSpare + sizeof (EFI_GUID) + sizeof (UINT32),
+ WORKING_BLOCK_VALID
+ );
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
}
+
//
// Before erase the working block, set WorkingBlockInvalid in working block.
//
@@ -552,12 +565,12 @@ FtwReclaimWorkSpace ( // WorkingBlockInvalid);
//
Status = FtwUpdateFvState (
- FtwDevice->FtwFvBlock,
- FtwDevice->WorkBlockSize,
- FtwDevice->FtwWorkSpaceLba,
- FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
- WORKING_BLOCK_INVALID
- );
+ FtwDevice->FtwFvBlock,
+ FtwDevice->WorkBlockSize,
+ FtwDevice->FtwWorkSpaceLba,
+ FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
+ WORKING_BLOCK_INVALID
+ );
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
@@ -573,15 +586,17 @@ FtwReclaimWorkSpace ( FreePool (SpareBuffer);
return Status;
}
+
//
// Restore spare backup buffer into spare block , if no failure happened during FtwWrite.
//
- Status = FtwEraseSpareBlock (FtwDevice);
+ Status = FtwEraseSpareBlock (FtwDevice);
if (EFI_ERROR (Status)) {
FreePool (SpareBuffer);
return EFI_ABORTED;
}
- Ptr = SpareBuffer;
+
+ Ptr = SpareBuffer;
for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
Length = FtwDevice->SpareBlockSize;
Status = FtwDevice->FtwBackupFvb->Write (
|