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 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "LzmaDecompressLibInternal.h"
14 Examines a GUIDed section and returns the size of the decoded buffer and the
15 size of an scratch buffer required to actually decode the data in a GUIDed section.
17 Examines a GUIDed section specified by InputSection.
18 If GUID for InputSection does not match the GUID that this handler supports,
19 then RETURN_UNSUPPORTED is returned.
20 If the required information can not be retrieved from InputSection,
21 then RETURN_INVALID_PARAMETER is returned.
22 If the GUID of InputSection does match the GUID that this handler supports,
23 then the size required to hold the decoded buffer is returned in OututBufferSize,
24 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
25 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
27 If InputSection is NULL, then ASSERT().
28 If OutputBufferSize is NULL, then ASSERT().
29 If ScratchBufferSize is NULL, then ASSERT().
30 If SectionAttribute is NULL, then ASSERT().
33 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
34 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
35 if the buffer specified by InputSection were decoded.
36 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
37 if the buffer specified by InputSection were decoded.
38 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
39 field of EFI_GUID_DEFINED_SECTION in the PI Specification.
41 @retval RETURN_SUCCESS The information about InputSection was returned.
42 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
43 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
48 LzmaGuidedSectionGetInfo (
49 IN CONST VOID
*InputSection
,
50 OUT UINT32
*OutputBufferSize
,
51 OUT UINT32
*ScratchBufferSize
,
52 OUT UINT16
*SectionAttribute
55 ASSERT (InputSection
!= NULL
);
56 ASSERT (OutputBufferSize
!= NULL
);
57 ASSERT (ScratchBufferSize
!= NULL
);
58 ASSERT (SectionAttribute
!= NULL
);
60 if (IS_SECTION2 (InputSection
)) {
62 &gLzmaCustomDecompressGuid
,
63 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
64 return RETURN_INVALID_PARAMETER
;
67 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->Attributes
;
69 return LzmaUefiDecompressGetInfo (
70 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
71 SECTION2_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
77 &gLzmaCustomDecompressGuid
,
78 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
79 return RETURN_INVALID_PARAMETER
;
82 *SectionAttribute
= ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->Attributes
;
84 return LzmaUefiDecompressGetInfo (
85 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
86 SECTION_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
94 Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
96 Decodes the GUIDed section specified by InputSection.
97 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
98 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
99 If the GUID of InputSection does match the GUID that this handler supports, then InputSection
100 is decoded into the buffer specified by OutputBuffer and the authentication status of this
101 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
102 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
103 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
105 If InputSection is NULL, then ASSERT().
106 If OutputBuffer is NULL, then ASSERT().
107 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
108 If AuthenticationStatus is NULL, then ASSERT().
111 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
112 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
113 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function
114 as a scratch buffer to perform the decode operation.
115 @param[out] AuthenticationStatus
116 A pointer to the authentication status of the decoded output buffer.
117 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
118 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
119 never be set by this handler.
121 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
122 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
123 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
128 LzmaGuidedSectionExtraction (
129 IN CONST VOID
*InputSection
,
130 OUT VOID
**OutputBuffer
,
131 OUT VOID
*ScratchBuffer
, OPTIONAL
132 OUT UINT32
*AuthenticationStatus
135 ASSERT (OutputBuffer
!= NULL
);
136 ASSERT (InputSection
!= NULL
);
138 if (IS_SECTION2 (InputSection
)) {
140 &gLzmaCustomDecompressGuid
,
141 &(((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->SectionDefinitionGuid
))) {
142 return RETURN_INVALID_PARAMETER
;
146 // Authentication is set to Zero, which may be ignored.
148 *AuthenticationStatus
= 0;
150 return LzmaUefiDecompress (
151 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
152 SECTION2_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION2
*) InputSection
)->DataOffset
,
158 &gLzmaCustomDecompressGuid
,
159 &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
160 return RETURN_INVALID_PARAMETER
;
164 // Authentication is set to Zero, which may be ignored.
166 *AuthenticationStatus
= 0;
168 return LzmaUefiDecompress (
169 (UINT8
*) InputSection
+ ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
170 SECTION_SIZE (InputSection
) - ((EFI_GUID_DEFINED_SECTION
*) InputSection
)->DataOffset
,
179 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.
181 @retval RETURN_SUCCESS Register successfully.
182 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
186 LzmaDecompressLibConstructor (
190 return ExtractGuidedSectionRegisterHandlers (
191 &gLzmaCustomDecompressGuid
,
192 LzmaGuidedSectionGetInfo
,
193 LzmaGuidedSectionExtraction