2 LZMA Decompress GUIDed Section Extraction Library.
3 It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces
4 and registers them into GUIDed handler table.
6 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "LzmaDecompressLibInternal.h"
20 Examines a GUIDed section and returns the size of the decoded buffer and the
21 size of an scratch buffer required to actually decode the data in a GUIDed section.
23 Examines a GUIDed section specified by InputSection.
24 If GUID for InputSection does not match the GUID that this handler supports,
25 then RETURN_UNSUPPORTED is returned.
26 If the required information can not be retrieved from InputSection,
27 then RETURN_INVALID_PARAMETER is returned.
28 If the GUID of InputSection does match the GUID that this handler supports,
29 then the size required to hold the decoded buffer is returned in OututBufferSize,
30 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
31 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
33 If InputSection is NULL, then ASSERT().
34 If OutputBufferSize is NULL, then ASSERT().
35 If ScratchBufferSize is NULL, then ASSERT().
36 If SectionAttribute is NULL, then ASSERT().
39 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
40 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
41 if the buffer specified by InputSection were decoded.
42 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
43 if the buffer specified by InputSection were decoded.
44 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
45 field of EFI_GUID_DEFINED_SECTION in the PI Specification.
47 @retval RETURN_SUCCESS The information about InputSection was returned.
48 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
49 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
54 LzmaGuidedSectionGetInfo (
55 IN CONST VOID
*InputSection
,
56 OUT UINT32
*OutputBufferSize
,
57 OUT UINT32
*ScratchBufferSize
,
58 OUT UINT16
*SectionAttribute
61 ASSERT (InputSection
!= NULL
);
62 ASSERT (OutputBufferSize
!= NULL
);
63 ASSERT (ScratchBufferSize
!= NULL
);
64 ASSERT (SectionAttribute
!= NULL
);
66 if (IS_SECTION2 (InputSection
)) {
68 &gLzmaCustomDecompressGuid
,
69 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
70 return RETURN_INVALID_PARAMETER
;
73 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->Attributes
;
75 return LzmaUefiDecompressGetInfo (
76 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
77 SECTION2_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
83 &gLzmaCustomDecompressGuid
,
84 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
85 return RETURN_INVALID_PARAMETER
;
88 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
90 return LzmaUefiDecompressGetInfo (
91 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
92 SECTION_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
100 Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
102 Decodes the GUIDed section specified by InputSection.
103 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
104 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
105 If the GUID of InputSection does match the GUID that this handler supports, then InputSection
106 is decoded into the buffer specified by OutputBuffer and the authentication status of this
107 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
108 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
109 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
111 If InputSection is NULL, then ASSERT().
112 If OutputBuffer is NULL, then ASSERT().
113 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
114 If AuthenticationStatus is NULL, then ASSERT().
117 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
118 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
119 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function
120 as a scratch buffer to perform the decode operation.
121 @param[out] AuthenticationStatus
122 A pointer to the authentication status of the decoded output buffer.
123 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
124 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
125 never be set by this handler.
127 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
128 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
129 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
134 LzmaGuidedSectionExtraction (
135 IN CONST VOID
*InputSection
,
136 OUT VOID
**OutputBuffer
,
137 OUT VOID
*ScratchBuffer
, OPTIONAL
138 OUT UINT32
*AuthenticationStatus
141 ASSERT (OutputBuffer
!= NULL
);
142 ASSERT (InputSection
!= NULL
);
144 if (IS_SECTION2 (InputSection
)) {
146 &gLzmaCustomDecompressGuid
,
147 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
148 return RETURN_INVALID_PARAMETER
;
152 // Authentication is set to Zero, which may be ignored.
154 *AuthenticationStatus
= 0;
156 return LzmaUefiDecompress (
157 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
158 SECTION2_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
164 &gLzmaCustomDecompressGuid
,
165 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
166 return RETURN_INVALID_PARAMETER
;
170 // Authentication is set to Zero, which may be ignored.
172 *AuthenticationStatus
= 0;
174 return LzmaUefiDecompress (
175 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
176 SECTION_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
185 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.
187 @retval RETURN_SUCCESS Register successfully.
188 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
192 LzmaDecompressLibConstructor (
195 return ExtractGuidedSectionRegisterHandlers (
196 &gLzmaCustomDecompressGuid
,
197 LzmaGuidedSectionGetInfo
,
198 LzmaGuidedSectionExtraction