/** @file
FFS file access utilities.
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 "FwVolDriver.h"
/**
Set File State in the FfsHeader.
@param State File state to be set into FFS header.
@param FfsHeader Points to the FFS file header
**/
)
{
//
// Set File State in the FfsHeader
//
return ;
}
/**
Get the FFS file state by checking the highest bit set in the header's state field.
@param ErasePolarity Erase polarity attribute of the firmware volume
@param FfsHeader Points to the FFS file header
@return FFS File state
**/
)
{
if (ErasePolarity != 0) {
}
HighestBit = 0x80;
HighestBit >>= 1;
}
return (EFI_FFS_FILE_STATE) HighestBit;
}
/**
Convert the Buffer Address to LBA Entry Address.
@param FvDevice Cached FvDevice
@param BufferAddress Address of Buffer
@param LbaListEntry Pointer to the got LBA entry that contains the address.
@retval EFI_NOT_FOUND Buffer address is out of FvDevice.
@retval EFI_SUCCESS LBA entry is found for Buffer address.
**/
)
{
//
// Locate LBA which contains the address
//
break;
}
}
return EFI_NOT_FOUND;
}
return EFI_NOT_FOUND;
}
*LbaListEntry = LbaEntry;
return EFI_SUCCESS;
}
/**
Convert the Buffer Address to LBA Address & Offset.
@param FvDevice Cached FvDevice
@param BufferAddress Address of Buffer
@param Lba Pointer to the gob Lba value
@param Offset Pointer to the got Offset
@retval EFI_NOT_FOUND Buffer address is out of FvDevice.
@retval EFI_SUCCESS LBA and Offset is found for Buffer address.
**/
)
{
);
return Status;
}
return EFI_SUCCESS;
}
/**
Check if a block of buffer is erased.
@param ErasePolarity Erase polarity attribute of the firmware volume
@param Buffer The buffer to be checked
@param BufferSize Size of the buffer in bytes
@retval TRUE The block of buffer is erased
@retval FALSE The block of buffer is not erased
**/
)
{
if (ErasePolarity == 1) {
EraseByte = 0xFF;
} else {
EraseByte = 0;
}
return FALSE;
}
}
return TRUE;
}
/**
Verify checksum of the firmware volume header.
@param FvHeader Points to the firmware volume header to be checked
@retval TRUE Checksum verification passed
@retval FALSE Checksum verification failed
**/
)
{
if (Checksum == 0) {
return TRUE;
} else {
return FALSE;
}
}
/**
Verify checksum of the FFS file header.
@param FfsHeader Points to the FFS file header to be checked
@retval TRUE Checksum verification passed
@retval FALSE Checksum verification failed
**/
)
{
if (IS_FFS_FILE2 (FfsHeader)) {
} else {
}
HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
if (HeaderChecksum == 0) {
return TRUE;
} else {
return FALSE;
}
}
/**
Verify checksum of the FFS file data.
@param FfsHeader Points to the FFS file header to be checked
@retval TRUE Checksum verification passed
@retval FALSE Checksum verification failed
**/
)
{
if ((Attributes & FFS_ATTRIB_CHECKSUM) != 0) {
//
// Check checksum of FFS data
//
if (IS_FFS_FILE2 (FfsHeader)) {
FileChecksum = CalculateSum8 ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER2));
} else {
FileChecksum = CalculateSum8 ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER));
}
if (FileChecksum == 0) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
} else {
return TRUE;
}
}
}
/**
Check if it's a valid FFS file header.
@param ErasePolarity Erase polarity attribute of the firmware volume
@param FfsHeader Points to the FFS file header to be checked
@retval TRUE Valid FFS file header
@retval FALSE Invalid FFS file header
**/
)
{
//
// Check if it is a free space
//
if (IsBufferErased (
sizeof (EFI_FFS_FILE_HEADER)
)) {
return FALSE;
}
switch (FileState) {
//
// fall through
//
case EFI_FILE_HEADER_INVALID:
return FALSE;
case EFI_FILE_HEADER_VALID:
//
// fall through
//
case EFI_FILE_DATA_VALID:
//
// fall through
//
//
// fall through
//
case EFI_FILE_DELETED:
//
// Here we need to verify header checksum
//
if (!VerifyHeaderChecksum (FfsHeader)) {
return FALSE;
}
break;
default:
//
// return
//
return FALSE;
}
return TRUE;
}
/**
Get next possible of Firmware File System Header.
@param ErasePolarity Erase polarity attribute of the firmware volume
@param FfsHeader Points to the FFS file header to be skipped.
@return Pointer to next FFS header.
**/
)
{
//
// Skip this header
//
if (IS_FFS_FILE2 (FfsHeader)) {
} else {
}
}
if (IS_FFS_FILE2 (FfsHeader)) {
} else {
}
//
// Since FileLength is not multiple of 8, we need skip some bytes
// to get next possible header
//
while ((SkipLength & 0x07) != 0) {
SkipLength++;
}
}
/**
Search FFS file with the same FFS name in FV Cache.
@param FvDevice Cached FV image.
@param FfsHeader Points to the FFS file header to be skipped.
@param StateBit FFS file state bit to be checked.
@return Pointer to next found FFS header. NULL will return if no found.
**/
)
{
//
// Search duplicate file, not from the beginning of FV,
// just search the next ocurrence of this file
//
do {
);
if ((UINT8 *) PHYSICAL_ADDRESS_TO_POINTER (FvDevice->CachedFv) + FvDevice->FwVolHeader->FvLength - Ptr <
sizeof (EFI_FFS_FILE_HEADER)
) {
break;
}
continue;
}
if (!VerifyFileChecksum (NextFfsFile)) {
continue;
}
return NextFfsFile;
}
}
} while (Ptr < (UINT8 *) PHYSICAL_ADDRESS_TO_POINTER (FvDevice->CachedFv) + FvDevice->FwVolHeader->FvLength);
return NULL;
}
/**
Change FFS file header state and write to FV.
@param FvDevice Cached FV image.
@param FfsHeader Points to the FFS file header to be updated.
@param State FFS file state to be set.
@retval EFI_SUCCESS File state is writen into FV.
@retval others File state can't be writen into FV.
**/
)
{
Lba = 0;
Offset = 0;
&Lba,
);
//
// Write the state byte into FV
//
NumBytesWritten = sizeof (EFI_FFS_FILE_STATE);
Lba,
);
return Status;
}
/**
Check if it's a valid FFS file.
Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
@param FvDevice Cached FV image.
@param FfsHeader Points to the FFS file to be checked
@retval TRUE Valid FFS file
@retval FALSE Invalid FFS file
**/
)
{
switch (FileState) {
case EFI_FILE_DATA_VALID:
if (!VerifyFileChecksum (FfsHeader)) {
return FALSE;
}
break;
}
//
// Check if there is another duplicated file with the EFI_FILE_DATA_VALID
//
return FALSE;
}
break;
if (!VerifyFileChecksum (FfsHeader)) {
return FALSE;
}
//
// since its data area is not unperturbed, it cannot be reclaimed,
// marked it as deleted
//
return TRUE;
//
// Here the found file is more recent than this file,
// mark it as deleted
//
return TRUE;
} else {
return TRUE;
}
break;
case EFI_FILE_DELETED:
if (!VerifyFileChecksum (FfsHeader)) {
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}