/** @file
Internal functions to operate Working Block Space.
Copyright (c) 2006 - 2011, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
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
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
**/
)
{
if (WorkingHeader == NULL) {
return FALSE;
}
return FALSE;
}
//
// Check signature with gEfiSystemNvDataFvGuid
//
return FALSE;
}
//
// Check the CRC of header
//
CopyMem (
);
//
// Filter out the Crc and State fields
//
SetMem (
sizeof (UINT32),
);
//
// Calculate the Crc of woking block header
//
(UINT8 *) &WorkingBlockHeader,
sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
);
return FALSE;
}
return FALSE;
}
return TRUE;
}
/**
Initialize a work space when there is no work space.
@param WorkingHeader Pointer of working block header
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
**/
)
{
if (WorkingHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Here using gEfiSystemNvDataFvGuid as the signature.
//
CopyMem (
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
//
SetMem (
&WorkingHeader->Crc,
sizeof (UINT32),
);
//
// Calculate the CRC value
//
(UINT8 *) WorkingHeader,
sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
);
return EFI_ABORTED;
}
//
// Restore the WorkingBlockValid flag to VALID state
//
return EFI_SUCCESS;
}
/**
Read from working block to refresh the work space in memory.
@param FtwDevice Point to private data of FTW driver
@retval EFI_SUCCESS The function completed successfully
@retval EFI_ABORTED The function could not complete successfully.
**/
)
{
//
// Initialize WorkSpace as FTW_ERASED_BYTE
//
SetMem (
);
//
// Read from working block
//
&Length,
);
return EFI_ABORTED;
}
//
// Refresh the FtwLastWriteHeader
//
);
//
// if the Header is out of the workspace limit, call reclaim.
//
//
// reclaim work space in working block.
//
return EFI_ABORTED;
}
//
// Read from working block again
//
&Length,
);
return EFI_ABORTED;
}
);
}
//
// Refresh the FtwLastWriteRecord
//
);
return EFI_ABORTED;
}
return EFI_SUCCESS;
}
/**
Reclaim the work space on the working block.
@param FtwDevice 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
@retval EFI_ABORTED The function could not complete successfully
**/
)
{
//
// Read all original data from working block to a memory buffer
//
if (TempBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Ptr = TempBuffer;
0,
&Length,
);
return EFI_ABORTED;
}
}
//
// Clean up the workspace, remove all the completed records.
//
Ptr = TempBuffer +
//
// Clear the content of buffer that will save the new work space data
//
//
// Copy EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER to buffer
//
CopyMem (
Ptr,
);
if (PreserveRecord) {
//
// Get the last record following the header,
//
);
if (!EFI_ERROR (Status) && (Header != NULL) && (Header->Complete != FTW_VALID_STATE) && (Header->HeaderAllocated == FTW_VALID_STATE)) {
CopyMem (
Ptr + sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
);
}
}
CopyMem (
Ptr,
);
);
//
// Set the WorkingBlockValid and WorkingBlockInvalid as INVALID
//
WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (TempBuffer + FtwDevice->FtwWorkSpaceBase);
//
// Try to keep the content of spare block
// Save spare block into a spare backup memory buffer (Sparebuffer)
//
if (SpareBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Ptr = SpareBuffer;
0,
&Length,
);
return EFI_ABORTED;
}
}
//
// Write the memory buffer to spare block
//
Ptr = TempBuffer;
0,
&Length,
);
return EFI_ABORTED;
}
}
//
// Free TempBuffer
//
//
// Set the WorkingBlockValid in spare block
//
);
return EFI_ABORTED;
}
//
// Before erase the working block, set WorkingBlockInvalid in working block.
//
// Offset = OFFSET_OF(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER,
// WorkingBlockInvalid);
//
);
return EFI_ABORTED;
}
//
// Write the spare block to working block
//
return Status;
}
//
// Restore spare backup buffer into spare block , if no failure happened during FtwWrite.
//
Ptr = SpareBuffer;
0,
&Length,
);
return EFI_ABORTED;
}
}
return EFI_SUCCESS;
}