mirror of https://github.com/acidanthera/audk.git
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
This commit is contained in:
parent
ba57315e64
commit
e11ae3a58f
|
@ -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;
|
||||
|
|
|
@ -568,34 +568,12 @@ 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
|
||||
)
|
||||
;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -297,66 +298,6 @@ WorkSpaceRefresh (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
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,
|
||||
|
|
|
@ -258,6 +258,7 @@ FlushSpareBlockToBootBlock (
|
|||
Length = FtwLiteDevice->SpareAreaLength;
|
||||
Buffer = AllocatePool (Length);
|
||||
if (Buffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
//
|
||||
// Get TopSwap bit state
|
||||
|
|
Loading…
Reference in New Issue