]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c
5a73933d2ac4e7f60ed1ba8a088f94b8eae973b6
[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 return RETURN_INVALID_PARAMETER;
68 }
69 //
70 // Get guid attribute of guid section.
71 //
72 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;
73
74 //
75 // Call Tiano GetInfo to get the required size info.
76 //
77 return UefiDecompressGetInfo (
78 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
79 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
80 OutputBufferSize,
81 ScratchBufferSize
82 );
83 } else {
84 if (!CompareGuid (
85 &gTianoCustomDecompressGuid,
86 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
87 return RETURN_INVALID_PARAMETER;
88 }
89 //
90 // Get guid attribute of guid section.
91 //
92 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
93
94 //
95 // Call Tiano GetInfo to get the required size info.
96 //
97 return UefiDecompressGetInfo (
98 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
99 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
100 OutputBufferSize,
101 ScratchBufferSize
102 );
103 }
104 }
105
106 /**
107 Decompress a Tiano compressed GUIDed section into a caller allocated output buffer.
108
109 Decodes the GUIDed section specified by InputSection.
110 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
111 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
112 If the GUID of InputSection does match the GUID that this handler supports, then InputSection
113 is decoded into the buffer specified by OutputBuffer and the authentication status of this
114 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
115 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
116 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
117
118 If InputSection is NULL, then ASSERT().
119 If OutputBuffer is NULL, then ASSERT().
120 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
121 If AuthenticationStatus is NULL, then ASSERT().
122
123
124 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
125 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
126 @param[in] ScratchBuffer A caller allocated buffer that may be required by this function
127 as a scratch buffer to perform the decode operation.
128 @param[out] AuthenticationStatus
129 A pointer to the authentication status of the decoded output buffer.
130 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
131 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
132 never be set by this handler.
133
134 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
135 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
136 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
137
138 **/
139 RETURN_STATUS
140 EFIAPI
141 TianoDecompress (
142 IN CONST VOID *InputSection,
143 OUT VOID **OutputBuffer,
144 IN VOID *ScratchBuffer, OPTIONAL
145 OUT UINT32 *AuthenticationStatus
146 )
147 {
148 ASSERT (OutputBuffer != NULL);
149 ASSERT (InputSection != NULL);
150
151 if (IS_SECTION2 (InputSection)) {
152 if (!CompareGuid (
153 &gTianoCustomDecompressGuid,
154 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
155 return RETURN_INVALID_PARAMETER;
156 }
157
158 //
159 // Set Authentication to Zero.
160 //
161 *AuthenticationStatus = 0;
162
163 //
164 // Call Tiano Decompress to get the raw data
165 //
166 return UefiTianoDecompress (
167 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
168 *OutputBuffer,
169 ScratchBuffer,
170 2
171 );
172 } else {
173 if (!CompareGuid (
174 &gTianoCustomDecompressGuid,
175 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
176 return RETURN_INVALID_PARAMETER;
177 }
178
179 //
180 // Set Authentication to Zero.
181 //
182 *AuthenticationStatus = 0;
183
184 //
185 // Call Tiano Decompress to get the raw data
186 //
187 return UefiTianoDecompress (
188 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
189 *OutputBuffer,
190 ScratchBuffer,
191 2
192 );
193 }
194 }
195
196 /**
197 Registers TianoDecompress and TianoDecompressGetInfo handlers with TianoCustomerDecompressGuid
198
199 @retval RETURN_SUCCESS Register successfully.
200 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
201 **/
202 RETURN_STATUS
203 EFIAPI
204 TianoDecompressLibConstructor (
205 VOID
206 )
207 {
208 return ExtractGuidedSectionRegisterHandlers (
209 &gTianoCustomDecompressGuid,
210 TianoDecompressGetInfo,
211 TianoDecompress
212 );
213 }