diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-07-17 02:18:13 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-07-17 02:18:13 +0000 |
commit | e11ae3a58f3ac26b417505379cc7416711175669 (patch) | |
tree | cf0c5a5810fac32f0c3253deaaf6d74b3883d181 /MdeModulePkg/Universal | |
parent | ba57315e64f8a8dd547d3e7dd527c0e7f536647f (diff) | |
download | edk2-e11ae3a58f3ac26b417505379cc7416711175669.tar.gz edk2-e11ae3a58f3ac26b417505379cc7416711175669.tar.bz2 edk2-e11ae3a58f3ac26b417505379cc7416711175669.zip |
Enhance FtwReclaimWorkSpace() so that it can be called when the working space header is not correct.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5510 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal')
4 files changed, 45 insertions, 103 deletions
diff --git a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.c b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.c index 264ef4ba5c..fd974d5d70 100644 --- a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.c +++ b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.c @@ -119,7 +119,7 @@ FtwLiteWrite ( // Check if there is enough free space for allocate a record
//
if ((MyOffset + WRITE_TOTAL_SIZE) > FtwLiteDevice->FtwWorkSpaceSize) {
- Status = FtwReclaimWorkSpace (FtwLiteDevice);
+ Status = FtwReclaimWorkSpace (FtwLiteDevice, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "FtwLite: Reclaim work space - %r", Status));
return EFI_ABORTED;
@@ -827,16 +827,10 @@ InitializeFtwLite ( );
InitWorkSpaceHeader (FtwLiteDevice->FtwWorkSpaceHeader);
//
- // Write to work space on the working block
+ // Initialize the work space
//
- Length = FtwLiteDevice->FtwWorkSpaceSize;
- Status = FtwLiteDevice->FtwFvBlock->Write (
- FtwLiteDevice->FtwFvBlock,
- FtwLiteDevice->FtwWorkSpaceLba,
- FtwLiteDevice->FtwWorkSpaceBase,
- &Length,
- FtwLiteDevice->FtwWorkSpace
- );
+ Status = FtwReclaimWorkSpace (FtwLiteDevice, FALSE);
+
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
@@ -897,7 +891,7 @@ InitializeFtwLite ( FtwLiteDevice->FtwWorkSpaceSize - Offset
)) {
DEBUG ((EFI_D_FTW_LITE, "FtwLite: Workspace is dirty, call reclaim...\n"));
- Status = FtwReclaimWorkSpace (FtwLiteDevice);
+ Status = FtwReclaimWorkSpace (FtwLiteDevice, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_FTW_LITE, "FtwLite: Workspace reclaim - %r\n", Status));
return EFI_ABORTED;
diff --git a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.h b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.h index 6199952e94..90a9fd85d2 100644 --- a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.h +++ b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.h @@ -569,33 +569,11 @@ IsValidWorkSpace ( ;
/**
- Reclaim the work space. Get rid of all the completed write records
- and write records in the Fault Tolerant work space.
-
-
- @param FtwLiteDevice Point to private data of FTW driver
- FtwSpaceBuffer - Buffer to contain the reclaimed clean data
- @param BlockBuffer The data buffer for the block.
- @param BufferSize Size of the FtwSpaceBuffer
-
- @retval EFI_SUCCESS The function completed successfully
- @retval EFI_BUFFER_TOO_SMALL The FtwSpaceBuffer is too small
- @retval EFI_ABORTED The function could not complete successfully.
-
-**/
-EFI_STATUS
-CleanupWorkSpace (
- IN EFI_FTW_LITE_DEVICE *FtwLiteDevice,
- IN OUT UINT8 *BlockBuffer,
- IN UINTN BufferSize
- )
-;
-
-/**
Reclaim the work space on the working block.
@param FtwLiteDevice Point to private data of FTW driver
+ @param PreserveRecord Whether to preserve the working record is needed
@retval EFI_SUCCESS The function completed successfully
@retval EFI_OUT_OF_RESOURCES Allocate memory error
@@ -604,7 +582,8 @@ CleanupWorkSpace ( **/
EFI_STATUS
FtwReclaimWorkSpace (
- IN EFI_FTW_LITE_DEVICE *FtwLiteDevice
+ IN EFI_FTW_LITE_DEVICE *FtwLiteDevice,
+ IN BOOLEAN PreserveRecord
)
;
diff --git a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwWorkSpace.c b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwWorkSpace.c index 3da4d42cd3..5583518e52 100644 --- a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwWorkSpace.c +++ b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwWorkSpace.c @@ -210,6 +210,7 @@ FtwGetLastRecord ( {
EFI_FTW_LITE_RECORD *Record;
+ *FtwLastRecord = NULL;
Record = (EFI_FTW_LITE_RECORD *) (FtwLiteDevice->FtwWorkSpaceHeader + 1);
while (Record->WriteCompleted == FTW_VALID_STATE) {
//
@@ -287,7 +288,7 @@ WorkSpaceRefresh ( //
// reclaim work space in working block.
//
- Status = FtwReclaimWorkSpace (FtwLiteDevice);
+ Status = FtwReclaimWorkSpace (FtwLiteDevice, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_FTW_LITE, "FtwLite: Reclaim workspace - %r\n", Status));
return EFI_ABORTED;
@@ -298,66 +299,6 @@ WorkSpaceRefresh ( }
/**
- Reclaim the work space. Get rid of all the completed write records
- and write records in the Fault Tolerant work space.
-
-
- @param FtwLiteDevice Point to private data of FTW driver
- @param FtwSpaceBuffer Buffer to contain the reclaimed clean data
- @param BufferSize Size of the FtwSpaceBuffer
-
- @retval EFI_SUCCESS The function completed successfully
- @retval EFI_BUFFER_TOO_SMALL The FtwSpaceBuffer is too small
- @retval EFI_ABORTED The function could not complete successfully.
-
-**/
-EFI_STATUS
-CleanupWorkSpace (
- IN EFI_FTW_LITE_DEVICE *FtwLiteDevice,
- IN OUT UINT8 *FtwSpaceBuffer,
- IN UINTN BufferSize
- )
-{
- UINTN Length;
- EFI_FTW_LITE_RECORD *Record;
-
- //
- // To check if the buffer is large enough
- //
- Length = FtwLiteDevice->FtwWorkSpaceSize;
- if (BufferSize < Length) {
- return EFI_BUFFER_TOO_SMALL;
- }
- //
- // Clear the content of buffer that will save the new work space data
- //
- SetMem (FtwSpaceBuffer, Length, FTW_ERASED_BYTE);
-
- //
- // Copy EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER to buffer
- //
- CopyMem (
- FtwSpaceBuffer,
- FtwLiteDevice->FtwWorkSpaceHeader,
- sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)
- );
-
- //
- // Get the last record
- //
- Record = FtwLiteDevice->FtwLastRecord;
- if ((Record != NULL) && (Record->WriteAllocated == FTW_VALID_STATE) && (Record->WriteCompleted != FTW_VALID_STATE)) {
- CopyMem (
- (UINT8 *) FtwSpaceBuffer + sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
- Record,
- WRITE_TOTAL_SIZE
- );
- }
-
- return EFI_SUCCESS;
-}
-
-/**
Reclaim the work space on the working block.
@@ -370,7 +311,8 @@ CleanupWorkSpace ( **/
EFI_STATUS
FtwReclaimWorkSpace (
- IN EFI_FTW_LITE_DEVICE *FtwLiteDevice
+ IN EFI_FTW_LITE_DEVICE *FtwLiteDevice,
+ IN BOOLEAN PreserveRecord
)
{
EFI_STATUS Status;
@@ -382,6 +324,7 @@ FtwReclaimWorkSpace ( UINTN SpareBufferSize;
UINT8 *SpareBuffer;
EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
+ EFI_FTW_LITE_RECORD *Record;
DEBUG ((EFI_D_FTW_LITE, "FtwLite: start to reclaim work space\n"));
@@ -390,7 +333,7 @@ FtwReclaimWorkSpace ( //
TempBufferSize = FtwLiteDevice->SpareAreaLength;
TempBuffer = AllocateZeroPool (TempBufferSize);
- if (TempBuffer != NULL) {
+ if (TempBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -418,11 +361,36 @@ FtwReclaimWorkSpace ( ((UINTN) (FtwLiteDevice->FtwWorkSpaceLba - FtwLiteDevice->FtwWorkBlockLba)) *
FtwLiteDevice->SizeOfSpareBlock + FtwLiteDevice->FtwWorkSpaceBase;
- Status = CleanupWorkSpace (
- FtwLiteDevice,
- Ptr,
- FtwLiteDevice->FtwWorkSpaceSize
- );
+ //
+ // Clear the content of buffer that will save the new work space data
+ //
+ SetMem (Ptr, FtwLiteDevice->FtwWorkSpaceSize, FTW_ERASED_BYTE);
+
+ //
+ // Copy EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER to buffer
+ //
+ CopyMem (
+ Ptr,
+ FtwLiteDevice->FtwWorkSpaceHeader,
+ sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)
+ );
+ if (PreserveRecord) {
+ //
+ // Get the last record
+ //
+ Status = FtwGetLastRecord (FtwLiteDevice, &FtwLiteDevice->FtwLastRecord);
+ Record = FtwLiteDevice->FtwLastRecord;
+ if (!EFI_ERROR (Status) &&
+ Record != NULL &&
+ Record->WriteAllocated == FTW_VALID_STATE &&
+ Record->WriteCompleted != FTW_VALID_STATE) {
+ CopyMem (
+ (UINT8 *) Ptr + sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
+ Record,
+ WRITE_TOTAL_SIZE
+ );
+ }
+ }
CopyMem (
FtwLiteDevice->FtwWorkSpace,
diff --git a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/Ia32/Ia32FtwMisc.c b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/Ia32/Ia32FtwMisc.c index e626f1da65..2c359b231c 100644 --- a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/Ia32/Ia32FtwMisc.c +++ b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/Ia32/Ia32FtwMisc.c @@ -258,6 +258,7 @@ FlushSpareBlockToBootBlock ( Length = FtwLiteDevice->SpareAreaLength;
Buffer = AllocatePool (Length);
if (Buffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
}
//
// Get TopSwap bit state
|