]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / LzmaCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
306bf4e2 1/** @file\r
182b1d16
LG
2 LZMA Decompress GUIDed Section Extraction Library.\r
3 It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces\r
4 and registers them into GUIDed handler table.\r
306bf4e2 5\r
0a6f4824 6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
c0a00b14 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
306bf4e2 8\r
9**/\r
10\r
182b1d16 11#include "LzmaDecompressLibInternal.h"\r
306bf4e2 12\r
13/**\r
182b1d16
LG
14 Examines a GUIDed section and returns the size of the decoded buffer and the\r
15 size of an scratch buffer required to actually decode the data in a GUIDed section.\r
16\r
0a6f4824 17 Examines a GUIDed section specified by InputSection.\r
182b1d16 18 If GUID for InputSection does not match the GUID that this handler supports,\r
0a6f4824 19 then RETURN_UNSUPPORTED is returned.\r
182b1d16
LG
20 If the required information can not be retrieved from InputSection,\r
21 then RETURN_INVALID_PARAMETER is returned.\r
22 If the GUID of InputSection does match the GUID that this handler supports,\r
23 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
24 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
25 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
0a6f4824 26\r
182b1d16
LG
27 If InputSection is NULL, then ASSERT().\r
28 If OutputBufferSize is NULL, then ASSERT().\r
29 If ScratchBufferSize is NULL, then ASSERT().\r
30 If SectionAttribute is NULL, then ASSERT().\r
31\r
32\r
33 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
34 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
35 if the buffer specified by InputSection were decoded.\r
36 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
37 if the buffer specified by InputSection were decoded.\r
38 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
39 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
40\r
41 @retval RETURN_SUCCESS The information about InputSection was returned.\r
42 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
43 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
306bf4e2 44\r
45**/\r
46RETURN_STATUS\r
47EFIAPI\r
48LzmaGuidedSectionGetInfo (\r
49 IN CONST VOID *InputSection,\r
50 OUT UINT32 *OutputBufferSize,\r
51 OUT UINT32 *ScratchBufferSize,\r
52 OUT UINT16 *SectionAttribute\r
53 )\r
54{\r
182b1d16
LG
55 ASSERT (InputSection != NULL);\r
56 ASSERT (OutputBufferSize != NULL);\r
57 ASSERT (ScratchBufferSize != NULL);\r
58 ASSERT (SectionAttribute != NULL);\r
59\r
30f001ca
SZ
60 if (IS_SECTION2 (InputSection)) {\r
61 if (!CompareGuid (\r
62 &gLzmaCustomDecompressGuid,\r
63 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
64 return RETURN_INVALID_PARAMETER;\r
65 }\r
66\r
67 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
68\r
69 return LzmaUefiDecompressGetInfo (\r
70 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
71 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
72 OutputBufferSize,\r
73 ScratchBufferSize\r
74 );\r
75 } else {\r
76 if (!CompareGuid (\r
77 &gLzmaCustomDecompressGuid,\r
182b1d16 78 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
30f001ca
SZ
79 return RETURN_INVALID_PARAMETER;\r
80 }\r
306bf4e2 81\r
30f001ca 82 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
306bf4e2 83\r
30f001ca
SZ
84 return LzmaUefiDecompressGetInfo (\r
85 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
86 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
87 OutputBufferSize,\r
88 ScratchBufferSize\r
89 );\r
90 }\r
306bf4e2 91}\r
92\r
93/**\r
182b1d16 94 Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.\r
0a6f4824
LG
95\r
96 Decodes the GUIDed section specified by InputSection.\r
97 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
182b1d16
LG
98 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
99 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
100 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
101 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
102 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
103 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
0a6f4824 104\r
182b1d16
LG
105 If InputSection is NULL, then ASSERT().\r
106 If OutputBuffer is NULL, then ASSERT().\r
107 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
108 If AuthenticationStatus is NULL, then ASSERT().\r
109\r
110\r
111 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
0a6f4824 112 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
182b1d16 113 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
0a6f4824
LG
114 as a scratch buffer to perform the decode operation.\r
115 @param[out] AuthenticationStatus\r
182b1d16
LG
116 A pointer to the authentication status of the decoded output buffer.\r
117 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
118 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
119 never be set by this handler.\r
120\r
121 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
122 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
123 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
306bf4e2 124\r
125**/\r
126RETURN_STATUS\r
127EFIAPI\r
128LzmaGuidedSectionExtraction (\r
129 IN CONST VOID *InputSection,\r
130 OUT VOID **OutputBuffer,\r
182b1d16 131 OUT VOID *ScratchBuffer, OPTIONAL\r
306bf4e2 132 OUT UINT32 *AuthenticationStatus\r
133 )\r
134{\r
182b1d16
LG
135 ASSERT (OutputBuffer != NULL);\r
136 ASSERT (InputSection != NULL);\r
306bf4e2 137\r
30f001ca
SZ
138 if (IS_SECTION2 (InputSection)) {\r
139 if (!CompareGuid (\r
140 &gLzmaCustomDecompressGuid,\r
141 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
142 return RETURN_INVALID_PARAMETER;\r
143 }\r
144\r
145 //\r
146 // Authentication is set to Zero, which may be ignored.\r
147 //\r
148 *AuthenticationStatus = 0;\r
149\r
150 return LzmaUefiDecompress (\r
151 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
152 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
153 *OutputBuffer,\r
154 ScratchBuffer\r
155 );\r
156 } else {\r
157 if (!CompareGuid (\r
158 &gLzmaCustomDecompressGuid,\r
182b1d16 159 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
30f001ca
SZ
160 return RETURN_INVALID_PARAMETER;\r
161 }\r
162\r
163 //\r
164 // Authentication is set to Zero, which may be ignored.\r
165 //\r
166 *AuthenticationStatus = 0;\r
167\r
168 return LzmaUefiDecompress (\r
169 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
170 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
171 *OutputBuffer,\r
172 ScratchBuffer\r
306bf4e2 173 );\r
30f001ca 174 }\r
306bf4e2 175}\r
176\r
177\r
178/**\r
182b1d16 179 Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.\r
306bf4e2 180\r
181 @retval RETURN_SUCCESS Register successfully.\r
182 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r
183**/\r
184EFI_STATUS\r
185EFIAPI\r
186LzmaDecompressLibConstructor (\r
2344d341 187 VOID\r
306bf4e2 188 )\r
189{\r
190 return ExtractGuidedSectionRegisterHandlers (\r
191 &gLzmaCustomDecompressGuid,\r
192 LzmaGuidedSectionGetInfo,\r
193 LzmaGuidedSectionExtraction\r
0a6f4824 194 );\r
306bf4e2 195}\r
196\r