VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/SectionExtractionPei/SectionExtractionPei.c

Last change on this file was 99404, checked in by vboxsync, 19 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 10.2 KB
Line 
1/** @file
2 Section Extraction PEIM
3
4Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <PiPei.h>
10#include <Ppi/GuidedSectionExtraction.h>
11#include <Library/DebugLib.h>
12#include <Library/ExtractGuidedSectionLib.h>
13#include <Library/MemoryAllocationLib.h>
14#include <Library/PeiServicesLib.h>
15
16/**
17 The ExtractSection() function processes the input section and
18 returns a pointer to the section contents. If the section being
19 extracted does not require processing (if the section
20 GuidedSectionHeader.Attributes has the
21 EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
22 OutputBuffer is just updated to point to the start of the
23 section's contents. Otherwise, *Buffer must be allocated
24 from PEI permanent memory.
25
26 @param This Indicates the
27 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
28 Buffer containing the input GUIDed section to be
29 processed. OutputBuffer OutputBuffer is
30 allocated from PEI permanent memory and contains
31 the new section stream.
32 @param InputSection A pointer to the input buffer, which contains
33 the input section to be processed.
34 @param OutputBuffer A pointer to a caller-allocated buffer, whose
35 size is specified by the contents of OutputSize.
36 @param OutputSize A pointer to a caller-allocated
37 UINTN in which the size of *OutputBuffer
38 allocation is stored. If the function
39 returns anything other than EFI_SUCCESS,
40 the value of OutputSize is undefined.
41 @param AuthenticationStatus A pointer to a caller-allocated
42 UINT32 that indicates the
43 authentication status of the
44 output buffer. If the input
45 section's GuidedSectionHeader.
46 Attributes field has the
47 EFI_GUIDED_SECTION_AUTH_STATUS_VALID
48 bit as clear,
49 AuthenticationStatus must return
50 zero. These bits reflect the
51 status of the extraction
52 operation. If the function
53 returns anything other than
54 EFI_SUCCESS, the value of
55 AuthenticationStatus is
56 undefined.
57
58 @retval EFI_SUCCESS The InputSection was
59 successfully processed and the
60 section contents were returned.
61
62 @retval EFI_OUT_OF_RESOURCES The system has insufficient
63 resources to process the request.
64
65 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
66 not match this instance of the
67 GUIDed Section Extraction PPI.
68
69**/
70EFI_STATUS
71EFIAPI
72CustomGuidedSectionExtract (
73 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
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 = {
84 CustomGuidedSectionExtract
85};
86
87/**
88 The ExtractSection() function processes the input section and
89 returns a pointer to the section contents. If the section being
90 extracted does not require processing (if the section
91 GuidedSectionHeader.Attributes has the
92 EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
93 OutputBuffer is just updated to point to the start of the
94 section's contents. Otherwise, *Buffer must be allocated
95 from PEI permanent memory.
96
97 @param This Indicates the
98 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
99 Buffer containing the input GUIDed section to be
100 processed. OutputBuffer OutputBuffer is
101 allocated from PEI permanent memory and contains
102 the new section stream.
103 @param InputSection A pointer to the input buffer, which contains
104 the input section to be processed.
105 @param OutputBuffer A pointer to a caller-allocated buffer, whose
106 size is specified by the contents of OutputSize.
107 @param OutputSize A pointer to a caller-allocated
108 UINTN in which the size of *OutputBuffer
109 allocation is stored. If the function
110 returns anything other than EFI_SUCCESS,
111 the value of OutputSize is undefined.
112 @param AuthenticationStatus A pointer to a caller-allocated
113 UINT32 that indicates the
114 authentication status of the
115 output buffer. If the input
116 section's GuidedSectionHeader.
117 Attributes field has the
118 EFI_GUIDED_SECTION_AUTH_STATUS_VALID
119 bit as clear,
120 AuthenticationStatus must return
121 zero. These bits reflect the
122 status of the extraction
123 operation. If the function
124 returns anything other than
125 EFI_SUCCESS, the value of
126 AuthenticationStatus is
127 undefined.
128
129 @retval EFI_SUCCESS The InputSection was
130 successfully processed and the
131 section contents were returned.
132
133 @retval EFI_OUT_OF_RESOURCES The system has insufficient
134 resources to process the request.
135
136 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
137 not match this instance of the
138 GUIDed Section Extraction PPI.
139
140**/
141EFI_STATUS
142EFIAPI
143CustomGuidedSectionExtract (
144 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
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 //
165 Status = ExtractGuidedSectionGetInfo (
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
218/**
219 Main entry for Section Extraction PEIM driver.
220
221 This routine registers the Section Extraction PPIs that have been registered
222 with the Section Extraction Library.
223
224 @param FileHandle Handle of the file being invoked.
225 @param PeiServices Describes the list of possible PEI Services.
226
227 @retval EFI_SUCCESS The entry point is executed successfully.
228 @retval other Some error occurs when executing this entry point.
229
230**/
231EFI_STATUS
232EFIAPI
233SectionExtractionPeiEntry (
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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette