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