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