Add core FFS3 support, DxeCore.

Signed-off-by: lzeng14
Reviewed-by: lgao4

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12584 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lzeng14 2011-10-27 09:23:19 +00:00
parent 890e54170e
commit 6c85d16217
7 changed files with 150 additions and 56 deletions

View File

@ -54,6 +54,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/SmmBase2.h>
#include <Guid/MemoryTypeInformation.h>
#include <Guid/FirmwareFileSystem2.h>
#include <Guid/FirmwareFileSystem3.h>
#include <Guid/HobList.h>
#include <Guid/DebugImageInfoTable.h>
#include <Guid/FileInfo.h>
@ -2255,6 +2256,7 @@ OpenSectionStream (
function returns anything other than
EFI_SUCCESS, the value of *AuthenticationStatus
is undefined.
@param IsFfs3Fv Indicates the FV format.
@retval EFI_SUCCESS Section was retrieved successfully
@retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the
@ -2285,7 +2287,8 @@ GetSection (
IN UINTN SectionInstance,
IN VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT UINT32 *AuthenticationStatus
OUT UINT32 *AuthenticationStatus,
IN BOOLEAN IsFfs3Fv
);

View File

@ -100,6 +100,7 @@
gEfiHobMemoryAllocModuleGuid ## CONSUMES ## Hob
gEfiFileInfoGuid ## CONSUMES ## File
gEfiFirmwareFileSystem2Guid ## CONSUMES ## GUID
gEfiFirmwareFileSystem3Guid ## CONSUMES ## GUID
gAprioriGuid ## CONSUMES ## GUID
gEfiDebugImageInfoTableGuid ## CONSUMES ## GUID
gEfiHobListGuid ## CONSUMES ## GUID

View File

@ -133,7 +133,11 @@ VerifyHeaderChecksum (
{
UINT8 HeaderChecksum;
HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
if (IS_FFS_FILE2 (FfsHeader)) {
HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));
} else {
HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
}
HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
if (HeaderChecksum == 0) {
@ -202,7 +206,6 @@ IsValidFfsFile (
{
EFI_FFS_FILE_STATE FileState;
UINT8 DataCheckSum;
UINT32 FileLength;
FileState = GetFileState (ErasePolarity, FfsHeader);
switch (FileState) {
@ -211,9 +214,12 @@ IsValidFfsFile (
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
DataCheckSum = FFS_FIXED_CHECKSUM;
FileLength = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF;
if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER));
if (IS_FFS_FILE2 (FfsHeader)) {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER2));
} else {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER));
}
}
if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {
return TRUE;

View File

@ -3,7 +3,7 @@
Layers on top of Firmware Block protocol to produce a file abstraction
of FV based files.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
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
@ -304,7 +304,6 @@ FvCheck (
UINTN Index;
EFI_LBA LbaIndex;
UINTN Size;
UINTN FileLength;
EFI_FFS_FILE_STATE FileState;
UINT8 *TopFvAddress;
UINTN TestLength;
@ -438,7 +437,14 @@ FvCheck (
if (!IsValidFfsHeader (FvDevice->ErasePolarity, FfsHeader, &FileState)) {
if ((FileState == EFI_FILE_HEADER_INVALID) ||
(FileState == EFI_FILE_HEADER_CONSTRUCTION)) {
FfsHeader++;
if (IS_FFS_FILE2 (FfsHeader)) {
if (!FvDevice->IsFfs3Fv) {
DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));
}
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER));
}
continue;
} else {
//
@ -457,10 +463,18 @@ FvCheck (
goto Done;
}
//
// Size[3] is a three byte array, read 4 bytes and throw one away
//
FileLength = *(UINT32 *)&FfsHeader->Size[0] & 0x00FFFFFF;
if (IS_FFS_FILE2 (FfsHeader)) {
ASSERT (FFS_FILE2_SIZE (FfsHeader) > 0x00FFFFFF);
if (!FvDevice->IsFfs3Fv) {
DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (FfsHeader));
//
// Adjust pointer to the next 8-byte aligned boundry.
//
FfsHeader = (EFI_FFS_FILE_HEADER *) (((UINTN) FfsHeader + 7) & ~0x07);
continue;
}
}
FileState = GetFileState (FvDevice->ErasePolarity, FfsHeader);
@ -481,7 +495,11 @@ FvCheck (
InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link);
}
FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FfsHeader) + FileLength);
if (IS_FFS_FILE2 (FfsHeader)) {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (FfsHeader));
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE_SIZE (FfsHeader));
}
//
// Adjust pointer to the next 8-byte aligned boundry.
@ -502,7 +520,7 @@ Done:
/**
This notification function is invoked when an instance of the
EFI_FW_VOLUME_BLOCK_PROTOCOL is produced. It layers an instance of the
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is produced. It layers an instance of the
EFI_FIRMWARE_VOLUME2_PROTOCOL on the same handle. This is the function where
the actual initialization of the EFI_FIRMWARE_VOLUME2_PROTOCOL is done.
@ -577,7 +595,8 @@ NotifyFwVolBlock (
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
if (!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) {
if ((!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
continue;
}
@ -610,6 +629,7 @@ NotifyFwVolBlock (
FvDevice->Handle = Handle;
FvDevice->FwVolHeader = FwVolHeader;
FvDevice->Fv.ParentHandle = Fvb->ParentHandle;
FvDevice->IsFfs3Fv = CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid);
//
// Install an New FV protocol on the existing handle

View File

@ -2,7 +2,7 @@
Firmware File System protocol. Layers on top of Firmware
Block protocol to produce a file abstraction of FV based files.
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
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
@ -43,6 +43,7 @@ typedef struct {
LIST_ENTRY FfsFileListHeader;
UINT8 ErasePolarity;
BOOLEAN IsFfs3Fv;
} FV_DEVICE;
#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)

View File

@ -1,7 +1,7 @@
/** @file
Implements functions to read firmware file
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
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
@ -119,7 +119,6 @@ FvGetNextFile (
UINTN *KeyValue;
LIST_ENTRY *Link;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
UINTN FileLength;
FvDevice = FV_DEVICE_FROM_THIS (This);
@ -201,15 +200,14 @@ FvGetNextFile (
CopyGuid (NameGuid, &FfsFileHeader->Name);
*Attributes = FfsAttributes2FvFileAttributes (FfsFileHeader->Attributes);
//
// Read four bytes out of the 3 byte array and throw out extra data
//
FileLength = *(UINT32 *)&FfsFileHeader->Size[0] & 0x00FFFFFF;
//
// we need to substract the header size
//
*Size = FileLength - sizeof(EFI_FFS_FILE_HEADER);
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);
}
return EFI_SUCCESS;
}
@ -333,7 +331,11 @@ FvReadFile (
//
// Skip over file header
//
SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
if (IS_FFS_FILE2 (FfsHeader)) {
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
} else {
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
}
Status = EFI_SUCCESS;
if (*Buffer == NULL) {
@ -447,7 +449,7 @@ FvReadFileSection (
}
//
// Use FfsEntry to cache Section Extraction Protocol Inforomation
// Use FfsEntry to cache Section Extraction Protocol Information
//
if (FfsEntry->StreamHandle == 0) {
Status = OpenSectionStream (
@ -470,7 +472,8 @@ FvReadFileSection (
(SectionType == 0) ? 0 : SectionInstance,
Buffer,
BufferSize,
AuthenticationStatus
AuthenticationStatus,
FvDevice->IsFfs3Fv
);
//

View File

@ -27,7 +27,7 @@
3) A support protocol is not found, and the data is not available to be read
without it. This results in EFI_PROTOCOL_ERROR.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
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
@ -269,7 +269,11 @@ IsValidSectionStream (
SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;
while (TotalLength < SectionStreamLength) {
SectionLength = SECTION_SIZE (SectionHeader);
if (IS_SECTION2 (SectionHeader)) {
SectionLength = SECTION2_SIZE (SectionHeader);
} else {
SectionLength = SECTION_SIZE (SectionHeader);
}
TotalLength += SectionLength;
if (TotalLength == SectionStreamLength) {
@ -475,7 +479,11 @@ ChildIsType (
return TRUE;
}
GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
if (IS_SECTION2 (GuidedSection)) {
return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
} else {
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
}
}
/**
@ -625,7 +633,11 @@ CreateChildNode (
UINT32 ScratchSize;
UINTN NewStreamBufferSize;
UINT32 AuthenticationStatus;
UINT32 SectionLength;
VOID *CompressionSource;
UINT32 CompressionSourceSize;
UINT32 UncompressedLength;
UINT8 CompressionType;
UINT16 GuidedSectionAttributes;
CORE_SECTION_CHILD_NODE *Node;
@ -645,7 +657,11 @@ CreateChildNode (
//
Node->Signature = CORE_SECTION_CHILD_SIGNATURE;
Node->Type = SectionHeader->Type;
Node->Size = SECTION_SIZE (SectionHeader);
if (IS_SECTION2 (SectionHeader)) {
Node->Size = SECTION2_SIZE (SectionHeader);
} else {
Node->Size = SECTION_SIZE (SectionHeader);
}
Node->OffsetInStream = ChildOffset;
Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;
Node->EncapsulationGuid = NULL;
@ -662,23 +678,35 @@ CreateChildNode (
CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;
if (IS_SECTION2 (CompressionHeader)) {
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;
CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;
} else {
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
UncompressedLength = CompressionHeader->UncompressedLength;
CompressionType = CompressionHeader->CompressionType;
}
//
// Allocate space for the new stream
//
if (CompressionHeader->UncompressedLength > 0) {
NewStreamBufferSize = CompressionHeader->UncompressedLength;
if (UncompressedLength > 0) {
NewStreamBufferSize = UncompressedLength;
NewStreamBuffer = AllocatePool (NewStreamBufferSize);
if (NewStreamBuffer == NULL) {
CoreFreePool (Node);
return EFI_OUT_OF_RESOURCES;
}
if (CompressionHeader->CompressionType == EFI_NOT_COMPRESSED) {
if (CompressionType == EFI_NOT_COMPRESSED) {
//
// stream is not actually compressed, just encapsulated. So just copy it.
//
CopyMem (NewStreamBuffer, CompressionHeader + 1, NewStreamBufferSize);
} else if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION) {
CopyMem (NewStreamBuffer, CompressionSource, NewStreamBufferSize);
} else if (CompressionType == EFI_STANDARD_COMPRESSION) {
//
// Only support the EFI_SATNDARD_COMPRESSION algorithm.
//
@ -692,13 +720,13 @@ CreateChildNode (
Status = Decompress->GetInfo (
Decompress,
CompressionHeader + 1,
Node->Size - sizeof (EFI_COMPRESSION_SECTION),
CompressionSource,
CompressionSourceSize,
(UINT32 *)&NewStreamBufferSize,
&ScratchSize
);
ASSERT_EFI_ERROR (Status);
ASSERT (NewStreamBufferSize == CompressionHeader->UncompressedLength);
ASSERT (NewStreamBufferSize == UncompressedLength);
ScratchBuffer = AllocatePool (ScratchSize);
if (ScratchBuffer == NULL) {
@ -709,8 +737,8 @@ CreateChildNode (
Status = Decompress->Decompress (
Decompress,
CompressionHeader + 1,
Node->Size - sizeof (EFI_COMPRESSION_SECTION),
CompressionSource,
CompressionSourceSize,
NewStreamBuffer,
(UINT32)NewStreamBufferSize,
ScratchBuffer,
@ -740,7 +768,13 @@ CreateChildNode (
case EFI_SECTION_GUID_DEFINED:
GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
if (IS_SECTION2 (GuidedHeader)) {
Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);
GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;
} else {
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
GuidedSectionAttributes = GuidedHeader->Attributes;
}
Status = CoreLocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);
if (!EFI_ERROR (Status) && GuidedExtraction != NULL) {
//
@ -763,7 +797,7 @@ CreateChildNode (
// Make sure we initialize the new stream with the correct
// authentication status for both aggregate and local status fields.
//
if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {
//
// OR in the parent stream's aggregate status.
//
@ -792,7 +826,7 @@ CreateChildNode (
//
// There's no GUIDed section extraction protocol available.
//
if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {
if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {
//
// If the section REQUIRES an extraction protocol, register for RPN
// when the required GUIDed extraction protocol becomes available.
@ -804,14 +838,23 @@ CreateChildNode (
//
AuthenticationStatus = Stream->AuthenticationStatus;
SectionLength = SECTION_SIZE (GuidedHeader);
Status = OpenSectionStreamEx (
SectionLength - GuidedHeader->DataOffset,
(UINT8 *) GuidedHeader + GuidedHeader->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
if (IS_SECTION2 (GuidedHeader)) {
Status = OpenSectionStreamEx (
SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
} else {
Status = OpenSectionStreamEx (
SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
}
if (EFI_ERROR (Status)) {
CoreFreePool (Node);
return Status;
@ -1075,6 +1118,7 @@ FindStreamNode (
function returns anything other than
EFI_SUCCESS, the value of *AuthenticationStatus
is undefined.
@param IsFfs3Fv Indicates the FV format.
@retval EFI_SUCCESS Section was retrieved successfully
@retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the
@ -1105,7 +1149,8 @@ GetSection (
IN UINTN SectionInstance,
IN VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT UINT32 *AuthenticationStatus
OUT UINT32 *AuthenticationStatus,
IN BOOLEAN IsFfs3Fv
)
{
CORE_SECTION_STREAM_NODE *StreamNode;
@ -1118,6 +1163,7 @@ GetSection (
UINTN Instance;
UINT8 *CopyBuffer;
UINTN SectionSize;
EFI_COMMON_SECTION_HEADER *Section;
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
@ -1158,8 +1204,22 @@ GetSection (
if (EFI_ERROR (Status)) {
goto GetSection_Done;
}
CopySize = ChildNode->Size - sizeof (EFI_COMMON_SECTION_HEADER);
CopyBuffer = ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream + sizeof (EFI_COMMON_SECTION_HEADER);
Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
if (IS_SECTION2 (Section)) {
ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);
if (!IsFfs3Fv) {
DEBUG ((DEBUG_ERROR, "It is a FFS3 formatted section in a non-FFS3 formatted FV.\n"));
Status = EFI_NOT_FOUND;
goto GetSection_Done;
}
CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);
} else {
CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);
}
*AuthenticationStatus = ExtractedAuthenticationStatus;
}