TianoCore EDK2 master
Loading...
Searching...
No Matches
SectionExtractionPei.c
Go to the documentation of this file.
1
9#include <PiPei.h>
11#include <Library/DebugLib.h>
15
71EFIAPI
74 IN CONST VOID *InputSection,
75 OUT VOID **OutputBuffer,
76 OUT UINTN *OutputSize,
77 OUT UINT32 *AuthenticationStatus
78 );
79
80//
81// Module global for the Section Extraction PPI instance
82//
83CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
85};
86
142EFIAPI
145 IN CONST VOID *InputSection,
146 OUT VOID **OutputBuffer,
147 OUT UINTN *OutputSize,
148 OUT UINT32 *AuthenticationStatus
149 )
150{
151 EFI_STATUS Status;
152 UINT8 *ScratchBuffer;
153 UINT32 ScratchBufferSize;
154 UINT32 OutputBufferSize;
155 UINT16 SectionAttribute;
156
157 //
158 // Init local variable
159 //
160 ScratchBuffer = NULL;
161
162 //
163 // Call GetInfo to get the size and attribute of input guided section data.
164 //
166 InputSection,
167 &OutputBufferSize,
168 &ScratchBufferSize,
169 &SectionAttribute
170 );
171
172 if (EFI_ERROR (Status)) {
173 DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));
174 return Status;
175 }
176
177 if (ScratchBufferSize != 0) {
178 //
179 // Allocate scratch buffer
180 //
181 ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
182 if (ScratchBuffer == NULL) {
183 return EFI_OUT_OF_RESOURCES;
184 }
185 }
186
187 if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && (OutputBufferSize > 0)) {
188 //
189 // Allocate output buffer
190 //
191 *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize));
192 if (*OutputBuffer == NULL) {
193 return EFI_OUT_OF_RESOURCES;
194 }
195
196 DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));
197 }
198
199 Status = ExtractGuidedSectionDecode (
200 InputSection,
201 OutputBuffer,
202 ScratchBuffer,
203 AuthenticationStatus
204 );
205 if (EFI_ERROR (Status)) {
206 //
207 // Decode failed
208 //
209 DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
210 return Status;
211 }
212
213 *OutputSize = (UINTN)OutputBufferSize;
214
215 return EFI_SUCCESS;
216}
217
232EFIAPI
234 IN EFI_PEI_FILE_HANDLE FileHandle,
235 IN CONST EFI_PEI_SERVICES **PeiServices
236 )
237{
238 EFI_STATUS Status;
239 EFI_GUID *ExtractHandlerGuidTable;
240 UINTN ExtractHandlerNumber;
241 EFI_PEI_PPI_DESCRIPTOR *GuidPpi;
242
243 //
244 // Get custom extract guided section method guid list
245 //
246 ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);
247
248 //
249 // Install custom extraction guid PPI
250 //
251 if (ExtractHandlerNumber > 0) {
252 GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *)AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
253 ASSERT (GuidPpi != NULL);
254 while (ExtractHandlerNumber-- > 0) {
255 GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
256 GuidPpi->Ppi = (VOID *)&mCustomGuidedSectionExtractionPpi;
257 GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];
258 Status = PeiServicesInstallPpi (GuidPpi++);
259 ASSERT_EFI_ERROR (Status);
260 }
261 }
262
263 return EFI_SUCCESS;
264}
UINT64 UINTN
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define EFI_GUIDED_SECTION_PROCESSING_REQUIRED
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
RETURN_STATUS EFIAPI ExtractGuidedSectionGetInfo(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
EFI_STATUS EFIAPI CustomGuidedSectionExtract(IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This, IN CONST VOID *InputSection, OUT VOID **OutputBuffer, OUT UINTN *OutputSize, OUT UINT32 *AuthenticationStatus)
EFI_STATUS EFIAPI SectionExtractionPeiEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213