2008-05-21 03:40:12 +02:00
|
|
|
/** @file
|
2008-04-09 09:07:50 +02:00
|
|
|
Implements functions to read firmware file
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2011-10-27 11:23:19 +02:00
|
|
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2008-05-21 03:40:12 +02:00
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2008-09-23 09:35:34 +02:00
|
|
|
#include "FwVolDriver.h"
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-09-23 09:35:34 +02:00
|
|
|
/**
|
|
|
|
Required Alignment Alignment Value in FFS Alignment Value in
|
2007-07-04 12:51:54 +02:00
|
|
|
(bytes) Attributes Field Firmware Volume Interfaces
|
|
|
|
1 0 0
|
|
|
|
16 1 4
|
|
|
|
128 2 7
|
|
|
|
512 3 9
|
|
|
|
1 KB 4 10
|
|
|
|
4 KB 5 12
|
|
|
|
32 KB 6 15
|
|
|
|
64 KB 7 16
|
2008-09-23 09:35:34 +02:00
|
|
|
**/
|
2008-07-24 04:54:45 +02:00
|
|
|
UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16};
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Convert the FFS File Attributes to FV File Attributes
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param FfsAttributes The attributes of UINT8 type.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
@return The attributes of EFI_FV_FILE_ATTRIBUTES
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_FV_FILE_ATTRIBUTES
|
|
|
|
FfsAttributes2FvFileAttributes (
|
|
|
|
IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
|
|
|
|
)
|
|
|
|
{
|
2011-11-25 02:57:23 +01:00
|
|
|
UINT8 DataAlignment;
|
|
|
|
EFI_FV_FILE_ATTRIBUTES FileAttribute;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2011-11-25 02:57:23 +01:00
|
|
|
DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);
|
|
|
|
ASSERT (DataAlignment < 8);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2011-11-25 02:57:23 +01:00
|
|
|
FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2011-11-25 02:57:23 +01:00
|
|
|
if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) {
|
|
|
|
FileAttribute |= EFI_FV_FILE_ATTRIB_FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileAttribute;
|
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Given the input key, search for the next matching file in the volume.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param This Indicates the calling context.
|
|
|
|
@param Key Key is a pointer to a caller allocated
|
|
|
|
buffer that contains implementation specific
|
|
|
|
data that is used to track where to begin
|
|
|
|
the search for the next file. The size of
|
|
|
|
the buffer must be at least This->KeySize
|
|
|
|
bytes long. To reinitialize the search and
|
|
|
|
begin from the beginning of the firmware
|
|
|
|
volume, the entire buffer must be cleared to
|
|
|
|
zero. Other than clearing the buffer to
|
|
|
|
initiate a new search, the caller must not
|
|
|
|
modify the data in the buffer between calls
|
|
|
|
to GetNextFile().
|
|
|
|
@param FileType FileType is a pointer to a caller allocated
|
|
|
|
EFI_FV_FILETYPE. The GetNextFile() API can
|
|
|
|
filter it's search for files based on the
|
|
|
|
value of *FileType input. A *FileType input
|
|
|
|
of 0 causes GetNextFile() to search for
|
|
|
|
files of all types. If a file is found, the
|
|
|
|
file's type is returned in *FileType.
|
|
|
|
*FileType is not modified if no file is
|
|
|
|
found.
|
|
|
|
@param NameGuid NameGuid is a pointer to a caller allocated
|
|
|
|
EFI_GUID. If a file is found, the file's
|
|
|
|
name is returned in *NameGuid. *NameGuid is
|
|
|
|
not modified if no file is found.
|
|
|
|
@param Attributes Attributes is a pointer to a caller
|
|
|
|
allocated EFI_FV_FILE_ATTRIBUTES. If a file
|
|
|
|
is found, the file's attributes are returned
|
|
|
|
in *Attributes. *Attributes is not modified
|
|
|
|
if no file is found.
|
|
|
|
@param Size Size is a pointer to a caller allocated
|
|
|
|
UINTN. If a file is found, the file's size
|
|
|
|
is returned in *Size. *Size is not modified
|
|
|
|
if no file is found.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Successfully find the file.
|
|
|
|
@retval EFI_DEVICE_ERROR Device error.
|
|
|
|
@retval EFI_ACCESS_DENIED Fv could not read.
|
|
|
|
@retval EFI_NOT_FOUND No matching file found.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Invalid parameter
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FvGetNextFile (
|
2007-09-04 08:12:48 +02:00
|
|
|
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
|
|
|
|
IN OUT VOID *Key,
|
|
|
|
IN OUT EFI_FV_FILETYPE *FileType,
|
2007-07-04 12:51:54 +02:00
|
|
|
OUT EFI_GUID *NameGuid,
|
|
|
|
OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
|
2008-05-09 09:08:30 +02:00
|
|
|
OUT UINTN *Size
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FV_DEVICE *FvDevice;
|
|
|
|
EFI_FV_ATTRIBUTES FvAttributes;
|
|
|
|
EFI_FFS_FILE_HEADER *FfsFileHeader;
|
|
|
|
UINTN *KeyValue;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
FFS_FILE_LIST_ENTRY *FfsFileEntry;
|
|
|
|
|
|
|
|
FvDevice = FV_DEVICE_FROM_THIS (This);
|
|
|
|
|
|
|
|
Status = FvGetVolumeAttributes (This, &FvAttributes);
|
|
|
|
if (EFI_ERROR (Status)){
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check if read operation is enabled
|
|
|
|
//
|
2007-09-04 08:12:48 +02:00
|
|
|
if ((FvAttributes & EFI_FV2_READ_STATUS) == 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2009-12-23 07:51:36 +01:00
|
|
|
if (*FileType > EFI_FV_FILETYPE_SMM_CORE) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2009-12-23 07:51:36 +01:00
|
|
|
// File type needs to be in 0 - 0x0D
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2007-10-18 03:00:01 +02:00
|
|
|
return EFI_NOT_FOUND;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KeyValue = (UINTN *)Key;
|
|
|
|
for (;;) {
|
|
|
|
if (*KeyValue == 0) {
|
|
|
|
//
|
|
|
|
// Search for 1st matching file
|
|
|
|
//
|
|
|
|
Link = &FvDevice->FfsFileListHeader;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Key is pointer to FFsFileEntry, so get next one
|
|
|
|
//
|
|
|
|
Link = (LIST_ENTRY *)(*KeyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Link->ForwardLink == &FvDevice->FfsFileListHeader) {
|
|
|
|
//
|
|
|
|
// Next is end of list so we did not find data
|
|
|
|
//
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
FfsFileEntry = (FFS_FILE_LIST_ENTRY *)Link->ForwardLink;
|
|
|
|
FfsFileHeader = (EFI_FFS_FILE_HEADER *)FfsFileEntry->FfsHeader;
|
|
|
|
|
|
|
|
//
|
|
|
|
// remember the key
|
|
|
|
//
|
|
|
|
*KeyValue = (UINTN)FfsFileEntry;
|
|
|
|
|
|
|
|
if (FfsFileHeader->Type == EFI_FV_FILETYPE_FFS_PAD) {
|
|
|
|
//
|
|
|
|
// we ignore pad files
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-11-19 09:03:35 +01:00
|
|
|
if (*FileType == EFI_FV_FILETYPE_ALL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Process all file types so we have a match
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*FileType == FfsFileHeader->Type) {
|
|
|
|
//
|
|
|
|
// Found a matching file type
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Return FileType, NameGuid, and Attributes
|
|
|
|
//
|
|
|
|
*FileType = FfsFileHeader->Type;
|
2008-07-18 11:50:09 +02:00
|
|
|
CopyGuid (NameGuid, &FfsFileHeader->Name);
|
2007-07-04 12:51:54 +02:00
|
|
|
*Attributes = FfsAttributes2FvFileAttributes (FfsFileHeader->Attributes);
|
2011-11-25 02:57:23 +01:00
|
|
|
if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
|
|
|
|
*Attributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// we need to substract the header size
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_FFS_FILE2 (FfsFileHeader)) {
|
|
|
|
*Size = FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER2);
|
|
|
|
} else {
|
|
|
|
*Size = FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Locates a file in the firmware volume and
|
|
|
|
copies it to the supplied buffer.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param This Indicates the calling context.
|
|
|
|
@param NameGuid Pointer to an EFI_GUID, which is the
|
|
|
|
filename.
|
|
|
|
@param Buffer Buffer is a pointer to pointer to a buffer
|
|
|
|
in which the file or section contents or are
|
|
|
|
returned.
|
|
|
|
@param BufferSize BufferSize is a pointer to caller allocated
|
|
|
|
UINTN. On input *BufferSize indicates the
|
|
|
|
size in bytes of the memory region pointed
|
|
|
|
to by Buffer. On output, *BufferSize
|
|
|
|
contains the number of bytes required to
|
|
|
|
read the file.
|
|
|
|
@param FoundType FoundType is a pointer to a caller allocated
|
|
|
|
EFI_FV_FILETYPE that on successful return
|
|
|
|
from Read() contains the type of file read.
|
|
|
|
This output reflects the file type
|
|
|
|
irrespective of the value of the SectionType
|
|
|
|
input.
|
|
|
|
@param FileAttributes FileAttributes is a pointer to a caller
|
|
|
|
allocated EFI_FV_FILE_ATTRIBUTES. On
|
|
|
|
successful return from Read(),
|
|
|
|
*FileAttributes contains the attributes of
|
|
|
|
the file read.
|
|
|
|
@param AuthenticationStatus AuthenticationStatus is a pointer to a
|
|
|
|
caller allocated UINTN in which the
|
|
|
|
authentication status is returned.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Successfully read to memory buffer.
|
|
|
|
@retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.
|
|
|
|
@retval EFI_NOT_FOUND Not found.
|
|
|
|
@retval EFI_DEVICE_ERROR Device error.
|
|
|
|
@retval EFI_ACCESS_DENIED Could not read.
|
|
|
|
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FvReadFile (
|
2007-09-04 08:12:48 +02:00
|
|
|
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
|
|
|
|
IN CONST EFI_GUID *NameGuid,
|
|
|
|
IN OUT VOID **Buffer,
|
|
|
|
IN OUT UINTN *BufferSize,
|
|
|
|
OUT EFI_FV_FILETYPE *FoundType,
|
|
|
|
OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FV_DEVICE *FvDevice;
|
|
|
|
EFI_GUID SearchNameGuid;
|
|
|
|
EFI_FV_FILETYPE LocalFoundType;
|
|
|
|
EFI_FV_FILE_ATTRIBUTES LocalAttributes;
|
|
|
|
UINTN FileSize;
|
|
|
|
UINT8 *SrcPtr;
|
|
|
|
EFI_FFS_FILE_HEADER *FfsHeader;
|
|
|
|
UINTN InputBufferSize;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
if (NameGuid == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
FvDevice = FV_DEVICE_FROM_THIS (This);
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Keep looking until we find the matching NameGuid.
|
|
|
|
// The Key is really an FfsFileEntry
|
|
|
|
//
|
|
|
|
FvDevice->LastKey = 0;
|
|
|
|
do {
|
|
|
|
LocalFoundType = 0;
|
|
|
|
Status = FvGetNextFile (
|
|
|
|
This,
|
|
|
|
&FvDevice->LastKey,
|
|
|
|
&LocalFoundType,
|
|
|
|
&SearchNameGuid,
|
|
|
|
&LocalAttributes,
|
|
|
|
&FileSize
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
} while (!CompareGuid (&SearchNameGuid, NameGuid));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get a pointer to the header
|
|
|
|
//
|
|
|
|
FfsHeader = FvDevice->LastKey->FfsHeader;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remember callers buffer size
|
|
|
|
//
|
|
|
|
InputBufferSize = *BufferSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Calculate return values
|
|
|
|
//
|
|
|
|
*FoundType = FfsHeader->Type;
|
|
|
|
*FileAttributes = FfsAttributes2FvFileAttributes (FfsHeader->Attributes);
|
2011-11-25 02:57:23 +01:00
|
|
|
if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
|
|
|
|
*FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
*AuthenticationStatus = 0;
|
|
|
|
*BufferSize = FileSize;
|
|
|
|
|
|
|
|
if (Buffer == NULL) {
|
|
|
|
//
|
2011-02-12 02:34:05 +01:00
|
|
|
// If Buffer is NULL, we only want to get the information collected so far
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Skip over file header
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
if (IS_FFS_FILE2 (FfsHeader)) {
|
|
|
|
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
|
|
|
|
} else {
|
|
|
|
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
if (*Buffer == NULL) {
|
|
|
|
//
|
|
|
|
// Caller passed in a pointer so allocate buffer for them
|
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
*Buffer = AllocatePool (FileSize);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (*Buffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
} else if (FileSize > InputBufferSize) {
|
|
|
|
//
|
|
|
|
// Callers buffer was not big enough
|
2008-07-24 04:54:45 +02:00
|
|
|
//
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = EFI_WARN_BUFFER_TOO_SMALL;
|
|
|
|
FileSize = InputBufferSize;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// Copy data into callers buffer
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
CopyMem (*Buffer, SrcPtr, FileSize);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Locates a section in a given FFS File and
|
|
|
|
copies it to the supplied buffer (not including section header).
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param This Indicates the calling context.
|
|
|
|
@param NameGuid Pointer to an EFI_GUID, which is the
|
|
|
|
filename.
|
|
|
|
@param SectionType Indicates the section type to return.
|
|
|
|
@param SectionInstance Indicates which instance of sections with a
|
|
|
|
type of SectionType to return.
|
|
|
|
@param Buffer Buffer is a pointer to pointer to a buffer
|
|
|
|
in which the file or section contents or are
|
|
|
|
returned.
|
|
|
|
@param BufferSize BufferSize is a pointer to caller allocated
|
2008-05-09 09:08:30 +02:00
|
|
|
UINTN.
|
2008-07-24 04:54:45 +02:00
|
|
|
@param AuthenticationStatus AuthenticationStatus is a pointer to a
|
|
|
|
caller allocated UINT32 in which the
|
|
|
|
authentication status is returned.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Successfully read the file section into
|
|
|
|
buffer.
|
|
|
|
@retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.
|
|
|
|
@retval EFI_NOT_FOUND Section not found.
|
|
|
|
@retval EFI_DEVICE_ERROR Device error.
|
|
|
|
@retval EFI_ACCESS_DENIED Could not read.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FvReadFileSection (
|
2007-09-04 08:12:48 +02:00
|
|
|
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
|
|
|
|
IN CONST EFI_GUID *NameGuid,
|
|
|
|
IN EFI_SECTION_TYPE SectionType,
|
|
|
|
IN UINTN SectionInstance,
|
|
|
|
IN OUT VOID **Buffer,
|
|
|
|
IN OUT UINTN *BufferSize,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FV_DEVICE *FvDevice;
|
|
|
|
EFI_FV_FILETYPE FileType;
|
|
|
|
EFI_FV_FILE_ATTRIBUTES FileAttributes;
|
|
|
|
UINTN FileSize;
|
|
|
|
UINT8 *FileBuffer;
|
|
|
|
FFS_FILE_LIST_ENTRY *FfsEntry;
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
if (NameGuid == NULL || Buffer == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
FvDevice = FV_DEVICE_FROM_THIS (This);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Read the whole file into buffer
|
|
|
|
//
|
|
|
|
FileBuffer = NULL;
|
|
|
|
Status = FvReadFile (
|
|
|
|
This,
|
|
|
|
NameGuid,
|
|
|
|
(VOID **)&FileBuffer,
|
|
|
|
&FileSize,
|
|
|
|
&FileType,
|
|
|
|
&FileAttributes,
|
|
|
|
AuthenticationStatus
|
2008-07-24 04:54:45 +02:00
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Get the last key used by our call to FvReadFile as it is the FfsEntry for this file.
|
2008-07-24 04:54:45 +02:00
|
|
|
//
|
2008-07-18 11:50:09 +02:00
|
|
|
FfsEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->LastKey;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Check to see that the file actually HAS sections before we go any further.
|
|
|
|
//
|
|
|
|
if (FileType == EFI_FV_FILETYPE_RAW) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2011-10-27 11:23:19 +02:00
|
|
|
// Use FfsEntry to cache Section Extraction Protocol Information
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
if (FfsEntry->StreamHandle == 0) {
|
2007-12-10 04:47:56 +01:00
|
|
|
Status = OpenSectionStream (
|
2008-07-18 11:50:09 +02:00
|
|
|
FileSize,
|
|
|
|
FileBuffer,
|
|
|
|
&FfsEntry->StreamHandle
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If SectionType == 0 We need the whole section stream
|
|
|
|
//
|
2007-12-10 04:47:56 +01:00
|
|
|
Status = GetSection (
|
|
|
|
FfsEntry->StreamHandle,
|
|
|
|
(SectionType == 0) ? NULL : &SectionType,
|
|
|
|
NULL,
|
|
|
|
(SectionType == 0) ? 0 : SectionInstance,
|
|
|
|
Buffer,
|
|
|
|
BufferSize,
|
2011-10-27 11:23:19 +02:00
|
|
|
AuthenticationStatus,
|
|
|
|
FvDevice->IsFfs3Fv
|
2007-12-10 04:47:56 +01:00
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Close of stream defered to close of FfsHeader list to allow SEP to cache data
|
|
|
|
//
|
|
|
|
|
|
|
|
Done:
|
|
|
|
CoreFreePool (FileBuffer);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|