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