/** @file
Firmware File System driver that produce full Firmware Volume2 protocol.
Layers on top of Firmware Block protocol to produce a file abstraction
of FV based files.
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
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"
/**
Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and
copy the real length volume header into it.
@param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to
read the volume header
@param FwVolHeader Pointer to pointer to allocated buffer in which
the volume header is returned.
@retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
@retval EFI_ACCESS_DENIED Read status of FV is not enabled.
**/
)
{
//
// Determine the real length of FV header
//
Fvb,
);
return Status;
}
if ((FvbAttributes & EFI_FVB2_READ_STATUS) == 0) {
return EFI_ACCESS_DENIED;
}
//
// Just avoid compiling warning
//
BaseAddress = 0;
FvhLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER);
//
// memory-mapped FV and non memory-mapped has different ways to read
//
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
Fvb,
);
return Status;
}
} else {
Fvb,
0,
0,
);
}
if (*FwVolHeader == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Read the whole header
//
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
} else {
//
// Assumed the first block is bigger than the length of Fv headder
//
Fvb,
0,
0,
(UINT8 *) *FwVolHeader
);
//
// Check whether Read successes.
//
FreePool (*FwVolHeader);
*FwVolHeader = NULL;
return Status;
}
}
return EFI_SUCCESS;
}
/**
Free FvDevice resource when error happens.
@param FvDevice Pointer to the FvDevice to be freed.
**/
)
{
//
// Free LAB Entry
//
}
//
// Free File List Entry
//
}
//
// Free Space Entry
//
}
//
// Free the cache
//
return ;
}
/**
Check if an FV is consistent and allocate cache for it.
@param FvDevice A pointer to the FvDevice to be checked.
@retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.
@retval EFI_VOLUME_CORRUPTED File system is corrupted.
@retval EFI_SUCCESS FV is consistent and cache is allocated.
**/
FvCheck (
)
{
return Status;
}
FwVolHeader = NULL;
return Status;
}
//
// Double Check firmware volume header here
//
if (!VerifyFvHeaderChecksum (FwVolHeader)) {
return EFI_VOLUME_CORRUPTED;
}
//
// FwVolHeader->FvLength is the whole FV length including FV header
//
return EFI_OUT_OF_RESOURCES;
}
//
// Copy to memory
//
LbaIndex = 0;
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
//
// Get volume base address
//
return Status;
}
}
//
// Copy whole FV into the memory
//
return EFI_OUT_OF_RESOURCES;
}
//
// Copy each LBA into memory
//
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
} else {
Fvb,
0,
&Size,
);
//
// Not check EFI_BAD_BUFFER_SIZE, for Size = BlockMap->Length
//
return Status;
}
}
LbaIndex++;
}
BlockMap++;
}
//
// it is not used any more, so free FwVolHeader
//
//
// Scan to check the free space & File list
//
if ((FvbAttributes & EFI_FVB2_ERASE_POLARITY) != 0) {
ErasePolarity = 1;
} else {
ErasePolarity = 0;
}
//
// go through the whole FV cache, check the consistence of the FV
//
//
// Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
//
FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->ExtHeaderOffset);
} else {
}
//
// Build FFS list & Free Space List here
//
while (Ptr < TopFvAddress) {
if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof (EFI_FFS_FILE_HEADER);
}
//
// We found free space
//
FreeSize = 0;
do {
if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof (EFI_FFS_FILE_HEADER);
}
break;
}
FreeSize += TestLength;
Ptr += TestLength;
} while (Ptr < TopFvAddress);
if (FreeSpaceEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create a Free space entry
//
continue;
}
//
// double check boundry
//
if (TestLength < sizeof (EFI_FFS_FILE_HEADER)) {
break;
}
if (!IsValidFFSHeader (
)) {
);
if (IS_FFS_FILE2 (Ptr)) {
DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &((EFI_FFS_FILE_HEADER *) Ptr)->Name));
}
} else {
}
continue;
} else {
//
// File system is corrputed, return
//
return EFI_VOLUME_CORRUPTED;
}
}
if (IS_FFS_FILE2 (Ptr)) {
DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &((EFI_FFS_FILE_HEADER *) Ptr)->Name));
//
// Adjust Ptr to the next 8-byte aligned boundry.
//
Ptr++;
}
continue;
}
}
);
//
// check for non-deleted file
//
if (FileState != EFI_FILE_DELETED) {
//
// Create a FFS list entry for each non-deleted file
//
if (FfsFileEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
if (IS_FFS_FILE2 (Ptr)) {
} else {
}
//
// Adjust Ptr to the next 8-byte aligned boundry.
//
Ptr++;
}
} else {
//
// File system is corrupted, return
//
return EFI_VOLUME_CORRUPTED;
}
}
return EFI_SUCCESS;
}
/**
@param ImageHandle A handle for the image that is initializing this driver
@param SystemTable A pointer to the EFI system table
**/
)
{
InstallFlag = FALSE;
//
// Locate all handles of Fvb protocol
//
NULL,
);
return EFI_NOT_FOUND;
}
);
continue;
}
FwVolHeader = NULL;
continue;
}
//
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
continue;
}
//
// Check if there is an FV protocol already installed in that handle
//
);
}
//
// FwVol protocol on the handle so create a new one
//
goto Done;
}
//
// Firmware Volume Protocol interface
//
//
// The file system is not consistence
//
continue;
}
if (Reinstall) {
//
// Reinstall an New FV protocol
//
// FvDevice = FV_DEVICE_FROM_THIS (Fv);
// FvDevice->Fvb = Fvb;
// FreeFvDeviceResource (FvDevice);
//
Fv,
);
InstallFlag = TRUE;
} else {
}
} else {
//
// Install an New FV protocol
//
);
InstallFlag = TRUE;
} else {
}
}
}
Done:
//
// success should return to ensure this image will be not unloaded.
// Otherwise, new Fv protocols are corrupted by other loaded driver.
//
if (InstallFlag) {
return EFI_SUCCESS;
}
//
// EFI_NOT_FOUND should return to ensure this image will be unloaded.
//
return EFI_NOT_FOUND;
}