]>
Commit | Line | Data |
---|---|---|
a402e129 MK |
1 | /** @file\r |
2 | Section Extraction PEIM\r | |
3 | \r | |
bc6a7a27 | 4 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a402e129 MK |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
10 | #include <Ppi/GuidedSectionExtraction.h>\r | |
11 | #include <Library/DebugLib.h>\r | |
12 | #include <Library/ExtractGuidedSectionLib.h>\r | |
13 | #include <Library/MemoryAllocationLib.h>\r | |
14 | #include <Library/PeiServicesLib.h>\r | |
15 | \r | |
d5eea98e ED |
16 | /**\r |
17 | The ExtractSection() function processes the input section and\r | |
18 | returns a pointer to the section contents. If the section being\r | |
19 | extracted does not require processing (if the section\r | |
20 | GuidedSectionHeader.Attributes has the\r | |
21 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
22 | OutputBuffer is just updated to point to the start of the\r | |
23 | section's contents. Otherwise, *Buffer must be allocated\r | |
24 | from PEI permanent memory.\r | |
25 | \r | |
26 | @param This Indicates the\r | |
27 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
28 | Buffer containing the input GUIDed section to be\r | |
29 | processed. OutputBuffer OutputBuffer is\r | |
30 | allocated from PEI permanent memory and contains\r | |
31 | the new section stream.\r | |
32 | @param InputSection A pointer to the input buffer, which contains\r | |
33 | the input section to be processed.\r | |
34 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
35 | size is specified by the contents of OutputSize.\r | |
36 | @param OutputSize A pointer to a caller-allocated\r | |
37 | UINTN in which the size of *OutputBuffer\r | |
38 | allocation is stored. If the function\r | |
39 | returns anything other than EFI_SUCCESS,\r | |
40 | the value of OutputSize is undefined.\r | |
41 | @param AuthenticationStatus A pointer to a caller-allocated\r | |
42 | UINT32 that indicates the\r | |
43 | authentication status of the\r | |
44 | output buffer. If the input\r | |
45 | section's GuidedSectionHeader.\r | |
46 | Attributes field has the\r | |
d1102dba | 47 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID\r |
d5eea98e ED |
48 | bit as clear,\r |
49 | AuthenticationStatus must return\r | |
50 | zero. These bits reflect the\r | |
51 | status of the extraction\r | |
52 | operation. If the function\r | |
53 | returns anything other than\r | |
54 | EFI_SUCCESS, the value of\r | |
55 | AuthenticationStatus is\r | |
56 | undefined.\r | |
d1102dba | 57 | \r |
d5eea98e ED |
58 | @retval EFI_SUCCESS The InputSection was\r |
59 | successfully processed and the\r | |
60 | section contents were returned.\r | |
d1102dba | 61 | \r |
d5eea98e ED |
62 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r |
63 | resources to process the request.\r | |
d1102dba | 64 | \r |
d5eea98e ED |
65 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r |
66 | not match this instance of the\r | |
67 | GUIDed Section Extraction PPI.\r | |
68 | \r | |
69 | **/\r | |
a402e129 MK |
70 | EFI_STATUS\r |
71 | EFIAPI\r | |
72 | CustomGuidedSectionExtract (\r | |
73 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r | |
74 | IN CONST VOID *InputSection,\r | |
75 | OUT VOID **OutputBuffer,\r | |
76 | OUT UINTN *OutputSize,\r | |
77 | OUT UINT32 *AuthenticationStatus\r | |
78 | );\r | |
79 | \r | |
80 | //\r | |
81 | // Module global for the Section Extraction PPI instance\r | |
82 | //\r | |
83 | CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r | |
84 | CustomGuidedSectionExtract\r | |
85 | };\r | |
86 | \r | |
87 | /**\r | |
88 | The ExtractSection() function processes the input section and\r | |
89 | returns a pointer to the section contents. If the section being\r | |
90 | extracted does not require processing (if the section\r | |
91 | GuidedSectionHeader.Attributes has the\r | |
92 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
93 | OutputBuffer is just updated to point to the start of the\r | |
94 | section's contents. Otherwise, *Buffer must be allocated\r | |
95 | from PEI permanent memory.\r | |
96 | \r | |
97 | @param This Indicates the\r | |
98 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
99 | Buffer containing the input GUIDed section to be\r | |
100 | processed. OutputBuffer OutputBuffer is\r | |
101 | allocated from PEI permanent memory and contains\r | |
102 | the new section stream.\r | |
103 | @param InputSection A pointer to the input buffer, which contains\r | |
104 | the input section to be processed.\r | |
105 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
106 | size is specified by the contents of OutputSize.\r | |
107 | @param OutputSize A pointer to a caller-allocated\r | |
108 | UINTN in which the size of *OutputBuffer\r | |
109 | allocation is stored. If the function\r | |
110 | returns anything other than EFI_SUCCESS,\r | |
111 | the value of OutputSize is undefined.\r | |
112 | @param AuthenticationStatus A pointer to a caller-allocated\r | |
113 | UINT32 that indicates the\r | |
114 | authentication status of the\r | |
115 | output buffer. If the input\r | |
116 | section's GuidedSectionHeader.\r | |
117 | Attributes field has the\r | |
d1102dba | 118 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID\r |
a402e129 MK |
119 | bit as clear,\r |
120 | AuthenticationStatus must return\r | |
121 | zero. These bits reflect the\r | |
122 | status of the extraction\r | |
123 | operation. If the function\r | |
124 | returns anything other than\r | |
125 | EFI_SUCCESS, the value of\r | |
126 | AuthenticationStatus is\r | |
127 | undefined.\r | |
d1102dba | 128 | \r |
a402e129 MK |
129 | @retval EFI_SUCCESS The InputSection was\r |
130 | successfully processed and the\r | |
131 | section contents were returned.\r | |
d1102dba | 132 | \r |
a402e129 MK |
133 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r |
134 | resources to process the request.\r | |
d1102dba | 135 | \r |
a402e129 MK |
136 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r |
137 | not match this instance of the\r | |
138 | GUIDed Section Extraction PPI.\r | |
139 | \r | |
140 | **/\r | |
141 | EFI_STATUS\r | |
142 | EFIAPI\r | |
143 | CustomGuidedSectionExtract (\r | |
144 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r | |
145 | IN CONST VOID *InputSection,\r | |
146 | OUT VOID **OutputBuffer,\r | |
147 | OUT UINTN *OutputSize,\r | |
148 | OUT UINT32 *AuthenticationStatus\r | |
149 | )\r | |
150 | {\r | |
151 | EFI_STATUS Status;\r | |
152 | UINT8 *ScratchBuffer;\r | |
153 | UINT32 ScratchBufferSize;\r | |
154 | UINT32 OutputBufferSize;\r | |
155 | UINT16 SectionAttribute;\r | |
d1102dba | 156 | \r |
a402e129 MK |
157 | //\r |
158 | // Init local variable\r | |
159 | //\r | |
160 | ScratchBuffer = NULL;\r | |
161 | \r | |
162 | //\r | |
163 | // Call GetInfo to get the size and attribute of input guided section data.\r | |
164 | //\r | |
165 | Status = ExtractGuidedSectionGetInfo (\r | |
166 | InputSection,\r | |
167 | &OutputBufferSize,\r | |
168 | &ScratchBufferSize,\r | |
169 | &SectionAttribute\r | |
170 | );\r | |
d1102dba | 171 | \r |
a402e129 MK |
172 | if (EFI_ERROR (Status)) {\r |
173 | DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r | |
174 | return Status;\r | |
175 | }\r | |
d1102dba | 176 | \r |
a402e129 MK |
177 | if (ScratchBufferSize != 0) {\r |
178 | //\r | |
179 | // Allocate scratch buffer\r | |
180 | //\r | |
181 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r | |
182 | if (ScratchBuffer == NULL) {\r | |
183 | return EFI_OUT_OF_RESOURCES;\r | |
184 | }\r | |
185 | }\r | |
186 | \r | |
d1102dba | 187 | if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) {\r |
a402e129 MK |
188 | //\r |
189 | // Allocate output buffer\r | |
190 | //\r | |
bc6a7a27 | 191 | *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize));\r |
a402e129 MK |
192 | if (*OutputBuffer == NULL) {\r |
193 | return EFI_OUT_OF_RESOURCES;\r | |
194 | }\r | |
195 | DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r | |
a402e129 | 196 | }\r |
d1102dba | 197 | \r |
a402e129 | 198 | Status = ExtractGuidedSectionDecode (\r |
d1102dba | 199 | InputSection,\r |
a402e129 MK |
200 | OutputBuffer,\r |
201 | ScratchBuffer,\r | |
202 | AuthenticationStatus\r | |
203 | );\r | |
204 | if (EFI_ERROR (Status)) {\r | |
205 | //\r | |
206 | // Decode failed\r | |
207 | //\r | |
208 | DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r | |
209 | return Status;\r | |
210 | }\r | |
d1102dba | 211 | \r |
a402e129 | 212 | *OutputSize = (UINTN) OutputBufferSize;\r |
d1102dba | 213 | \r |
a402e129 MK |
214 | return EFI_SUCCESS;\r |
215 | }\r | |
216 | \r | |
217 | /**\r | |
218 | Main entry for Section Extraction PEIM driver.\r | |
d1102dba LG |
219 | \r |
220 | This routine registers the Section Extraction PPIs that have been registered\r | |
a402e129 MK |
221 | with the Section Extraction Library.\r |
222 | \r | |
223 | @param FileHandle Handle of the file being invoked.\r | |
224 | @param PeiServices Describes the list of possible PEI Services.\r | |
225 | \r | |
226 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
227 | @retval other Some error occurs when executing this entry point.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | SectionExtractionPeiEntry (\r | |
233 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
234 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
d1102dba | 235 | )\r |
a402e129 MK |
236 | {\r |
237 | EFI_STATUS Status;\r | |
238 | EFI_GUID *ExtractHandlerGuidTable;\r | |
239 | UINTN ExtractHandlerNumber;\r | |
240 | EFI_PEI_PPI_DESCRIPTOR *GuidPpi;\r | |
241 | \r | |
242 | //\r | |
d1102dba | 243 | // Get custom extract guided section method guid list\r |
a402e129 MK |
244 | //\r |
245 | ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r | |
d1102dba | 246 | \r |
a402e129 MK |
247 | //\r |
248 | // Install custom extraction guid PPI\r | |
249 | //\r | |
250 | if (ExtractHandlerNumber > 0) {\r | |
251 | GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
252 | ASSERT (GuidPpi != NULL);\r | |
253 | while (ExtractHandlerNumber-- > 0) {\r | |
254 | GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r | |
255 | GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi;\r | |
256 | GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r | |
257 | Status = PeiServicesInstallPpi (GuidPpi++);\r | |
258 | ASSERT_EFI_ERROR (Status);\r | |
259 | }\r | |
260 | }\r | |
d1102dba | 261 | \r |
a402e129 MK |
262 | return EFI_SUCCESS;\r |
263 | }\r |