TianoCore EDK2 master
Loading...
Searching...
No Matches
SectionExtractionDxe.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
11#include <Library/DebugLib.h>
16
101EFIAPI
104 IN CONST VOID *InputSection,
105 OUT VOID **OutputBuffer,
106 OUT UINTN *OutputSize,
107 OUT UINT32 *AuthenticationStatus
108 );
109
110//
111// Module global for the Section Extraction Protocol handle
112//
113EFI_HANDLE mSectionExtractionHandle = NULL;
114
115//
116// Module global for the Section Extraction Protocol instance
117//
118EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
120};
121
206EFIAPI
209 IN CONST VOID *InputSection,
210 OUT VOID **OutputBuffer,
211 OUT UINTN *OutputSize,
212 OUT UINT32 *AuthenticationStatus
213 )
214{
215 EFI_STATUS Status;
216 VOID *ScratchBuffer;
217 VOID *AllocatedOutputBuffer;
218 UINT32 OutputBufferSize;
219 UINT32 ScratchBufferSize;
220 UINT16 SectionAttribute;
221
222 //
223 // Init local variable
224 //
225 ScratchBuffer = NULL;
226 AllocatedOutputBuffer = NULL;
227
228 //
229 // Call GetInfo to get the size and attribute of input guided section data.
230 //
232 InputSection,
233 &OutputBufferSize,
234 &ScratchBufferSize,
235 &SectionAttribute
236 );
237
238 if (EFI_ERROR (Status)) {
239 DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));
240 return Status;
241 }
242
243 if (ScratchBufferSize > 0) {
244 //
245 // Allocate scratch buffer
246 //
247 ScratchBuffer = AllocatePool (ScratchBufferSize);
248 if (ScratchBuffer == NULL) {
249 return EFI_OUT_OF_RESOURCES;
250 }
251 }
252
253 if (OutputBufferSize > 0) {
254 //
255 // Allocate output buffer
256 //
257 AllocatedOutputBuffer = AllocatePool (OutputBufferSize);
258 if (AllocatedOutputBuffer == NULL) {
259 FreePool (ScratchBuffer);
260 return EFI_OUT_OF_RESOURCES;
261 }
262
263 *OutputBuffer = AllocatedOutputBuffer;
264 }
265
266 //
267 // Call decode function to extract raw data from the guided section.
268 //
269 Status = ExtractGuidedSectionDecode (
270 InputSection,
271 OutputBuffer,
272 ScratchBuffer,
273 AuthenticationStatus
274 );
275 if (EFI_ERROR (Status)) {
276 //
277 // Decode failed
278 //
279 if (AllocatedOutputBuffer != NULL) {
280 FreePool (AllocatedOutputBuffer);
281 }
282
283 if (ScratchBuffer != NULL) {
284 FreePool (ScratchBuffer);
285 }
286
287 DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
288 return Status;
289 }
290
291 if (*OutputBuffer != AllocatedOutputBuffer) {
292 //
293 // OutputBuffer was returned as a different value,
294 // so copy section contents to the allocated memory buffer.
295 //
296 CopyMem (AllocatedOutputBuffer, *OutputBuffer, OutputBufferSize);
297 *OutputBuffer = AllocatedOutputBuffer;
298 }
299
300 //
301 // Set real size of output buffer.
302 //
303 *OutputSize = (UINTN)OutputBufferSize;
304
305 //
306 // Free unused scratch buffer.
307 //
308 if (ScratchBuffer != NULL) {
309 FreePool (ScratchBuffer);
310 }
311
312 return EFI_SUCCESS;
313}
314
329EFIAPI
331 IN EFI_HANDLE ImageHandle,
332 IN EFI_SYSTEM_TABLE *SystemTable
333 )
334{
335 EFI_STATUS Status;
336 EFI_GUID *ExtractHandlerGuidTable;
337 UINTN ExtractHandlerNumber;
338
339 //
340 // Get custom extract guided section method guid list
341 //
342 ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);
343
344 //
345 // Install custom guided extraction protocol
346 //
347 while (ExtractHandlerNumber-- > 0) {
348 Status = gBS->InstallMultipleProtocolInterfaces (
349 &mSectionExtractionHandle,
350 &ExtractHandlerGuidTable[ExtractHandlerNumber],
351 &mCustomGuidedSectionExtractionProtocol,
352 NULL
353 );
354 ASSERT_EFI_ERROR (Status);
355 }
356
357 return EFI_SUCCESS;
358}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
#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
RETURN_STATUS EFIAPI ExtractGuidedSectionGetInfo(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI SectionExtractionDxeEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI CustomGuidedSectionExtract(IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This, IN CONST VOID *InputSection, OUT VOID **OutputBuffer, OUT UINTN *OutputSize, OUT UINT32 *AuthenticationStatus)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
Definition: Base.h:213