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:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user