summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-06-25 08:40:49 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-06-25 08:40:49 +0000
commit182b1d16236001427c2929284eaba558a556c495 (patch)
tree96e21385ad4a369f0aca99202a290e8cc287bf79 /IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
parent24a2dd3d08c2d146b66cf0a2f1cec8988eca511d (diff)
downloadedk2-platforms-182b1d16236001427c2929284eaba558a556c495.tar.xz
Clean up Library LzmaCustomDecompressLib, PeiRecoveryLib and driver SectionExtraction
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8658 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c')
-rw-r--r--IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c190
1 files changed, 88 insertions, 102 deletions
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
index 2444f31def..ff91600afd 100644
--- a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
+++ b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
@@ -1,7 +1,9 @@
/** @file
- LZMA Decompress GUIDed Section Extraction Library
+ LZMA Decompress GUIDed Section Extraction Library.
+ It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces
+ and registers them into GUIDed handler table.
- Copyright (c) 2006 - 2009, Intel Corporation<BR>
+ Copyright (c) 2009, Intel Corporation<BR>
All rights reserved. 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
@@ -12,66 +14,39 @@
**/
-#include <Uefi.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/ExtractGuidedSectionLib.h>
-#include <Pi/PiFirmwareFile.h>
-#include <Guid/LzmaDecompress.h>
-
-#include "LzmaDecompress.h"
-
-
-STATIC
-RETURN_STATUS
-EFIAPI
-LzmaGuidedSectionGetCompressedLocation (
- IN CONST VOID *InputSection,
- OUT VOID **LmzaCompressedData,
- OUT UINT32 *LmzaCompressedDataSize OPTIONAL
- )
-{
- if (!CompareGuid (
- &gLzmaCustomDecompressGuid,
- &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
- return RETURN_INVALID_PARAMETER;
- }
-
- //
- // Retrieve the size and attribute of the input section data.
- //
- *LmzaCompressedData =
- (VOID*) (
- (UINT8 *) InputSection +
- ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset
- );
- if (LmzaCompressedDataSize != NULL) {
- *LmzaCompressedDataSize =
- (UINT32)(
- (
- (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size)) &
- 0x00ffffff
- ) -
- ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset
- );
- }
-
- return RETURN_SUCCESS;
-}
-
+#include "LzmaDecompressLibInternal.h"
/**
- The implementation of 'GetInfo' for Guided Section
- Extraction of LZMA compression.
-
- @param InputSection Buffer containing the input GUIDed section to be processed.
- @param OutputBufferSize The size of OutputBuffer.
- @param ScratchBufferSize The size of ScratchBuffer.
- @param SectionAttribute The attribute of the input guided section.
-
- @retval RETURN_SUCCESS The size of destination buffer and the size of scratch buffer are successull retrieved.
- @retval RETURN_INVALID_PARAMETER The source data is corrupted, or
- The GUID in InputSection does not match this instance guid.
+ Examines a GUIDed section and returns the size of the decoded buffer and the
+ size of an scratch buffer required to actually decode the data in a GUIDed section.
+
+ Examines a GUIDed section specified by InputSection.
+ If GUID for InputSection does not match the GUID that this handler supports,
+ then RETURN_UNSUPPORTED is returned.
+ If the required information can not be retrieved from InputSection,
+ then RETURN_INVALID_PARAMETER is returned.
+ If the GUID of InputSection does match the GUID that this handler supports,
+ then the size required to hold the decoded buffer is returned in OututBufferSize,
+ the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
+ from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
+
+ If InputSection is NULL, then ASSERT().
+ If OutputBufferSize is NULL, then ASSERT().
+ If ScratchBufferSize is NULL, then ASSERT().
+ If SectionAttribute is NULL, then ASSERT().
+
+
+ @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
+ @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
+ if the buffer specified by InputSection were decoded.
+ @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
+ if the buffer specified by InputSection were decoded.
+ @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
+ field of EFI_GUID_DEFINED_SECTION in the PI Specification.
+
+ @retval RETURN_SUCCESS The information about InputSection was returned.
+ @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
+ @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
**/
RETURN_STATUS
@@ -83,44 +58,58 @@ LzmaGuidedSectionGetInfo (
OUT UINT16 *SectionAttribute
)
{
- RETURN_STATUS Status;
- VOID *LzmaInput;
- UINT32 LzmaInputSize;
-
- Status = LzmaGuidedSectionGetCompressedLocation(
- InputSection,
- &LzmaInput,
- &LzmaInputSize
- );
- if (RETURN_ERROR (Status)) {
- return Status;
+ ASSERT (InputSection != NULL);
+ ASSERT (OutputBufferSize != NULL);
+ ASSERT (ScratchBufferSize != NULL);
+ ASSERT (SectionAttribute != NULL);
+
+ if (!CompareGuid (
+ &gLzmaCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
}
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
return LzmaUefiDecompressGetInfo (
- LzmaInput,
- LzmaInputSize,
- OutputBufferSize,
- ScratchBufferSize
- );
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
+ (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
+ OutputBufferSize,
+ ScratchBufferSize
+ );
}
/**
- The implementation of Guided Section Extraction
- for LZMA compression.
-
- @param InputSection Buffer containing the input GUIDed section to be processed.
- @param OutputBuffer OutputBuffer to point to the start of the section's contents.
- if guided data is not prcessed. Otherwise,
- OutputBuffer to contain the output data, which is allocated by the caller.
- @param ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
- @param AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
- authentication status of the output buffer.
-
- @retval RETURN_SUCCESS Decompression is successfull
- @retval RETURN_INVALID_PARAMETER The source data is corrupted, or
- The GUID in InputSection does not match this instance guid.
+ Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
+
+ Decodes the GUIDed section specified by InputSection.
+ If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
+ If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
+ If the GUID of InputSection does match the GUID that this handler supports, then InputSection
+ is decoded into the buffer specified by OutputBuffer and the authentication status of this
+ decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
+ data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
+ the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
+
+ If InputSection is NULL, then ASSERT().
+ If OutputBuffer is NULL, then ASSERT().
+ If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
+ If AuthenticationStatus is NULL, then ASSERT().
+
+
+ @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
+ @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
+ @param[out] ScratchBuffer A caller allocated buffer that may be required by this function
+ as a scratch buffer to perform the decode operation.
+ @param[out] AuthenticationStatus
+ A pointer to the authentication status of the decoded output buffer.
+ See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
+ section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
+ never be set by this handler.
+
+ @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
+ @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
+ @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
**/
RETURN_STATUS
@@ -128,20 +117,17 @@ EFIAPI
LzmaGuidedSectionExtraction (
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
- IN VOID *ScratchBuffer, OPTIONAL
+ OUT VOID *ScratchBuffer, OPTIONAL
OUT UINT32 *AuthenticationStatus
)
{
- RETURN_STATUS Status;
- VOID *LzmaInput;
+ ASSERT (OutputBuffer != NULL);
+ ASSERT (InputSection != NULL);
- Status = LzmaGuidedSectionGetCompressedLocation(
- InputSection,
- &LzmaInput,
- NULL
- );
- if (RETURN_ERROR (Status)) {
- return Status;
+ if (!CompareGuid (
+ &gLzmaCustomDecompressGuid,
+ &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
+ return RETURN_INVALID_PARAMETER;
}
//
@@ -150,7 +136,7 @@ LzmaGuidedSectionExtraction (
*AuthenticationStatus = 0;
return LzmaUefiDecompress (
- LzmaInput,
+ (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
*OutputBuffer,
ScratchBuffer
);
@@ -158,7 +144,7 @@ LzmaGuidedSectionExtraction (
/**
- Register LzmaDecompress handler.
+ Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.
@retval RETURN_SUCCESS Register successfully.
@retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.