]>
Commit | Line | Data |
---|---|---|
3f0055c8 DB |
1 | /** @file\r |
2 | UEFI Decompress Library implementation refer to UEFI specification.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include <PiPei.h>\r | |
11 | #include <Library/ExtractGuidedSectionLib.h>\r | |
12 | #include "BaseUefiDecompressLibInternals.h"\r | |
13 | \r | |
14 | /**\r | |
15 | Examines a GUIDed section and returns the size of the decoded buffer and the\r | |
16 | size of an optional scratch buffer required to actually decode the data in a GUIDed section.\r | |
17 | \r | |
18 | Examines a GUIDed section specified by InputSection.\r | |
19 | If GUID for InputSection does not match the GUID that this handler supports,\r | |
20 | then RETURN_UNSUPPORTED is returned.\r | |
21 | If the required information can not be retrieved from InputSection,\r | |
22 | then RETURN_INVALID_PARAMETER is returned.\r | |
23 | If the GUID of InputSection does match the GUID that this handler supports,\r | |
24 | then the size required to hold the decoded buffer is returned in OututBufferSize,\r | |
25 | the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r | |
26 | from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r | |
27 | \r | |
28 | If InputSection is NULL, then ASSERT().\r | |
29 | If OutputBufferSize is NULL, then ASSERT().\r | |
30 | If ScratchBufferSize is NULL, then ASSERT().\r | |
31 | If SectionAttribute is NULL, then ASSERT().\r | |
32 | \r | |
33 | \r | |
34 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
35 | @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r | |
36 | if the buffer specified by InputSection were decoded.\r | |
37 | @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r | |
38 | if the buffer specified by InputSection were decoded.\r | |
39 | @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r | |
40 | field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r | |
41 | \r | |
42 | @retval RETURN_SUCCESS The information about InputSection was returned.\r | |
43 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r | |
44 | @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r | |
45 | \r | |
46 | **/\r | |
47 | RETURN_STATUS\r | |
48 | EFIAPI\r | |
49 | TianoDecompressGetInfo (\r | |
50 | IN CONST VOID *InputSection,\r | |
51 | OUT UINT32 *OutputBufferSize,\r | |
52 | OUT UINT32 *ScratchBufferSize,\r | |
53 | OUT UINT16 *SectionAttribute\r | |
54 | )\r | |
55 | \r | |
56 | {\r | |
57 | ASSERT (SectionAttribute != NULL);\r | |
58 | \r | |
59 | if (InputSection == NULL) {\r | |
60 | return RETURN_INVALID_PARAMETER;\r | |
61 | }\r | |
62 | \r | |
63 | if (IS_SECTION2 (InputSection)) {\r | |
64 | if (!CompareGuid (\r | |
2f88bd3a MK |
65 | &gTianoCustomDecompressGuid,\r |
66 | &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r | |
67 | ))\r | |
68 | {\r | |
3f0055c8 DB |
69 | return RETURN_INVALID_PARAMETER;\r |
70 | }\r | |
2f88bd3a | 71 | \r |
3f0055c8 DB |
72 | //\r |
73 | // Get guid attribute of guid section.\r | |
74 | //\r | |
2f88bd3a | 75 | *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;\r |
3f0055c8 DB |
76 | \r |
77 | //\r | |
78 | // Call Tiano GetInfo to get the required size info.\r | |
79 | //\r | |
80 | return UefiDecompressGetInfo (\r | |
2f88bd3a MK |
81 | (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r |
82 | SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r | |
3f0055c8 DB |
83 | OutputBufferSize,\r |
84 | ScratchBufferSize\r | |
85 | );\r | |
86 | } else {\r | |
87 | if (!CompareGuid (\r | |
2f88bd3a MK |
88 | &gTianoCustomDecompressGuid,\r |
89 | &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r | |
90 | ))\r | |
91 | {\r | |
3f0055c8 DB |
92 | return RETURN_INVALID_PARAMETER;\r |
93 | }\r | |
2f88bd3a | 94 | \r |
3f0055c8 DB |
95 | //\r |
96 | // Get guid attribute of guid section.\r | |
97 | //\r | |
2f88bd3a | 98 | *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;\r |
3f0055c8 DB |
99 | \r |
100 | //\r | |
101 | // Call Tiano GetInfo to get the required size info.\r | |
102 | //\r | |
103 | return UefiDecompressGetInfo (\r | |
2f88bd3a MK |
104 | (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r |
105 | SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r | |
3f0055c8 DB |
106 | OutputBufferSize,\r |
107 | ScratchBufferSize\r | |
108 | );\r | |
109 | }\r | |
110 | }\r | |
111 | \r | |
112 | /**\r | |
113 | Decompress a Tiano compressed GUIDed section into a caller allocated output buffer.\r | |
114 | \r | |
115 | Decodes the GUIDed section specified by InputSection.\r | |
116 | If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r | |
117 | If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r | |
118 | If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r | |
119 | is decoded into the buffer specified by OutputBuffer and the authentication status of this\r | |
120 | decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r | |
121 | data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r | |
122 | the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r | |
123 | \r | |
124 | If InputSection is NULL, then ASSERT().\r | |
125 | If OutputBuffer is NULL, then ASSERT().\r | |
126 | If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r | |
127 | If AuthenticationStatus is NULL, then ASSERT().\r | |
128 | \r | |
129 | \r | |
130 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
131 | @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r | |
132 | @param[in] ScratchBuffer A caller allocated buffer that may be required by this function\r | |
133 | as a scratch buffer to perform the decode operation.\r | |
134 | @param[out] AuthenticationStatus\r | |
135 | A pointer to the authentication status of the decoded output buffer.\r | |
136 | See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r | |
137 | section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r | |
138 | never be set by this handler.\r | |
139 | \r | |
140 | @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r | |
141 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r | |
142 | @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r | |
143 | \r | |
144 | **/\r | |
145 | RETURN_STATUS\r | |
146 | EFIAPI\r | |
147 | TianoDecompress (\r | |
148 | IN CONST VOID *InputSection,\r | |
149 | OUT VOID **OutputBuffer,\r | |
d0e2f823 | 150 | IN VOID *ScratchBuffer OPTIONAL,\r |
3f0055c8 DB |
151 | OUT UINT32 *AuthenticationStatus\r |
152 | )\r | |
153 | {\r | |
154 | ASSERT (OutputBuffer != NULL);\r | |
155 | ASSERT (InputSection != NULL);\r | |
156 | \r | |
157 | if (IS_SECTION2 (InputSection)) {\r | |
158 | if (!CompareGuid (\r | |
2f88bd3a MK |
159 | &gTianoCustomDecompressGuid,\r |
160 | &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r | |
161 | ))\r | |
162 | {\r | |
3f0055c8 DB |
163 | return RETURN_INVALID_PARAMETER;\r |
164 | }\r | |
165 | \r | |
166 | //\r | |
167 | // Set Authentication to Zero.\r | |
168 | //\r | |
169 | *AuthenticationStatus = 0;\r | |
170 | \r | |
171 | //\r | |
172 | // Call Tiano Decompress to get the raw data\r | |
173 | //\r | |
174 | return UefiTianoDecompress (\r | |
2f88bd3a | 175 | (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r |
3f0055c8 DB |
176 | *OutputBuffer,\r |
177 | ScratchBuffer,\r | |
178 | 2\r | |
2f88bd3a | 179 | );\r |
3f0055c8 DB |
180 | } else {\r |
181 | if (!CompareGuid (\r | |
2f88bd3a MK |
182 | &gTianoCustomDecompressGuid,\r |
183 | &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r | |
184 | ))\r | |
185 | {\r | |
3f0055c8 DB |
186 | return RETURN_INVALID_PARAMETER;\r |
187 | }\r | |
188 | \r | |
189 | //\r | |
190 | // Set Authentication to Zero.\r | |
191 | //\r | |
192 | *AuthenticationStatus = 0;\r | |
193 | \r | |
194 | //\r | |
195 | // Call Tiano Decompress to get the raw data\r | |
196 | //\r | |
197 | return UefiTianoDecompress (\r | |
2f88bd3a | 198 | (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r |
3f0055c8 DB |
199 | *OutputBuffer,\r |
200 | ScratchBuffer,\r | |
201 | 2\r | |
2f88bd3a | 202 | );\r |
3f0055c8 DB |
203 | }\r |
204 | }\r | |
205 | \r | |
206 | /**\r | |
207 | Registers TianoDecompress and TianoDecompressGetInfo handlers with TianoCustomerDecompressGuid\r | |
208 | \r | |
209 | @retval RETURN_SUCCESS Register successfully.\r | |
210 | @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r | |
211 | **/\r | |
212 | RETURN_STATUS\r | |
213 | EFIAPI\r | |
214 | TianoDecompressLibConstructor (\r | |
215 | VOID\r | |
2f88bd3a | 216 | )\r |
3f0055c8 DB |
217 | {\r |
218 | return ExtractGuidedSectionRegisterHandlers (\r | |
2f88bd3a MK |
219 | &gTianoCustomDecompressGuid,\r |
220 | TianoDecompressGetInfo,\r | |
221 | TianoDecompress\r | |
222 | );\r | |
3f0055c8 | 223 | }\r |