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