summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h14
-rw-r--r--MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c2
-rw-r--r--MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c137
3 files changed, 71 insertions, 82 deletions
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
index 39bc743e24..8deae8851a 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
@@ -3,7 +3,7 @@
The internal header file includes the common header files, defines
internal structure and functions used by FtwLite module.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <PiDxe.h>
#include <Guid/SystemNvDataGuid.h>
+#include <Guid/ZeroGuid.h>
#include <Protocol/FaultTolerantWrite.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Protocol/SwapAddressRange.h>
@@ -736,5 +737,16 @@ EFI_STATUS
InitFtwProtocol (
IN OUT EFI_FTW_DEVICE *FtwDevice
);
+
+/**
+ Initialize a local work space header.
+
+ Since Signature and WriteQueueSize have been known, Crc can be calculated out,
+ then the work space header will be fixed.
+**/
+VOID
+InitializeLocalWorkSpaceHeader (
+ VOID
+ );
#endif
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
index f1d64942b4..c5f41d7378 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
@@ -1174,6 +1174,8 @@ InitFtwProtocol (
FtwDevice->FtwLastWriteHeader = NULL;
FtwDevice->FtwLastWriteRecord = NULL;
+ InitializeLocalWorkSpaceHeader ();
+
//
// Refresh the working space data from working block
//
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index 340e167ac9..bd8285d00e 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -16,77 +16,90 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "FaultTolerantWrite.h"
-/**
- Check to see if it is a valid work space.
-
-
- @param WorkingHeader Pointer of working block header
+EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = {ZERO_GUID, 0, 0, 0, 0, {0, 0, 0}, 0};
- @retval TRUE The work space is valid.
- @retval FALSE The work space is invalid.
+/**
+ Initialize a local work space header.
+ Since Signature and WriteQueueSize have been known, Crc can be calculated out,
+ then the work space header will be fixed.
**/
-BOOLEAN
-IsValidWorkSpace (
- IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+VOID
+InitializeLocalWorkSpaceHeader (
+ VOID
)
{
EFI_STATUS Status;
- EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER WorkingBlockHeader;
-
- if (WorkingHeader == NULL) {
- return FALSE;
- }
- if (WorkingHeader->WorkingBlockValid != FTW_VALID_STATE) {
- DEBUG ((EFI_D_ERROR, "Ftw: Work block header valid bit check error\n"));
- return FALSE;
- }
//
- // Check signature with gEfiSystemNvDataFvGuid
+ // Check signature with gEfiSystemNvDataFvGuid.
//
- if (!CompareGuid (&gEfiSystemNvDataFvGuid, &WorkingHeader->Signature)) {
- DEBUG ((EFI_D_ERROR, "Ftw: Work block header signature check error\n"));
- return FALSE;
+ if (CompareGuid (&gEfiSystemNvDataFvGuid, &mWorkingBlockHeader.Signature)) {
+ //
+ // The local work space header has been initialized.
+ //
+ return;
}
+
+ SetMem (
+ &mWorkingBlockHeader,
+ sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
+ FTW_ERASED_BYTE
+ );
+
//
- // Check the CRC of header
+ // Here using gEfiSystemNvDataFvGuid as the signature.
//
CopyMem (
- &WorkingBlockHeader,
- WorkingHeader,
- sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)
+ &mWorkingBlockHeader.Signature,
+ &gEfiSystemNvDataFvGuid,
+ sizeof (EFI_GUID)
);
+ mWorkingBlockHeader.WriteQueueSize = (UINT64) (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
//
- // Filter out the Crc and State fields
+ // Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.
//
- SetMem (
- &WorkingBlockHeader.Crc,
- sizeof (UINT32),
- FTW_ERASED_BYTE
- );
- WorkingBlockHeader.WorkingBlockValid = FTW_ERASE_POLARITY;
- WorkingBlockHeader.WorkingBlockInvalid = FTW_ERASE_POLARITY;
//
// Calculate the Crc of woking block header
//
Status = gBS->CalculateCrc32 (
- (UINT8 *) &WorkingBlockHeader,
+ &mWorkingBlockHeader,
sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
- &WorkingBlockHeader.Crc
+ &mWorkingBlockHeader.Crc
);
- if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+
+ mWorkingBlockHeader.WorkingBlockValid = FTW_VALID_STATE;
+ mWorkingBlockHeader.WorkingBlockInvalid = FTW_INVALID_STATE;
+}
+
+/**
+ Check to see if it is a valid work space.
+
+
+ @param WorkingHeader Pointer of working block header
+
+ @retval TRUE The work space is valid.
+ @retval FALSE The work space is invalid.
+
+**/
+BOOLEAN
+IsValidWorkSpace (
+ IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+ )
+{
+ if (WorkingHeader == NULL) {
return FALSE;
}
- if (WorkingBlockHeader.Crc != WorkingHeader->Crc) {
- DEBUG ((EFI_D_ERROR, "Ftw: Work block header CRC check error\n"));
- return FALSE;
+ if (CompareMem (WorkingHeader, &mWorkingBlockHeader, sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)) == 0) {
+ return TRUE;
}
- return TRUE;
+ DEBUG ((EFI_D_ERROR, "Ftw: Work block header check error\n"));
+ return FALSE;
}
/**
@@ -103,49 +116,11 @@ InitWorkSpaceHeader (
IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
)
{
- EFI_STATUS Status;
-
if (WorkingHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
- //
- // Here using gEfiSystemNvDataFvGuid as the signature.
- //
- CopyMem (
- &WorkingHeader->Signature,
- &gEfiSystemNvDataFvGuid,
- sizeof (EFI_GUID)
- );
- WorkingHeader->WriteQueueSize = (UINT64) (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
-
- //
- // Crc is calculated with all the fields except Crc and STATE
- //
- WorkingHeader->WorkingBlockValid = FTW_ERASE_POLARITY;
- WorkingHeader->WorkingBlockInvalid = FTW_ERASE_POLARITY;
- SetMem (
- &WorkingHeader->Crc,
- sizeof (UINT32),
- FTW_ERASED_BYTE
- );
-
- //
- // Calculate the CRC value
- //
- Status = gBS->CalculateCrc32 (
- (UINT8 *) WorkingHeader,
- sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
- &WorkingHeader->Crc
- );
- if (EFI_ERROR (Status)) {
- return EFI_ABORTED;
- }
- //
- // Restore the WorkingBlockValid flag to VALID state
- //
- WorkingHeader->WorkingBlockValid = FTW_VALID_STATE;
- WorkingHeader->WorkingBlockInvalid = FTW_INVALID_STATE;
+ CopyMem (WorkingHeader, &mWorkingBlockHeader, sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
return EFI_SUCCESS;
}