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 | |
22 | //\r | |
23 | // Function prototype for Section Extraction PPI service\r | |
24 | //\r | |
25 | EFI_STATUS\r | |
26 | EFIAPI\r | |
27 | CustomGuidedSectionExtract (\r | |
28 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r | |
29 | IN CONST VOID *InputSection,\r | |
30 | OUT VOID **OutputBuffer,\r | |
31 | OUT UINTN *OutputSize,\r | |
32 | OUT UINT32 *AuthenticationStatus\r | |
33 | );\r | |
34 | \r | |
35 | //\r | |
36 | // Module global for the Section Extraction PPI instance\r | |
37 | //\r | |
38 | CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r | |
39 | CustomGuidedSectionExtract\r | |
40 | };\r | |
41 | \r | |
42 | /**\r | |
43 | The ExtractSection() function processes the input section and\r | |
44 | returns a pointer to the section contents. If the section being\r | |
45 | extracted does not require processing (if the section\r | |
46 | GuidedSectionHeader.Attributes has the\r | |
47 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
48 | OutputBuffer is just updated to point to the start of the\r | |
49 | section's contents. Otherwise, *Buffer must be allocated\r | |
50 | from PEI permanent memory.\r | |
51 | \r | |
52 | @param This Indicates the\r | |
53 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
54 | Buffer containing the input GUIDed section to be\r | |
55 | processed. OutputBuffer OutputBuffer is\r | |
56 | allocated from PEI permanent memory and contains\r | |
57 | the new section stream.\r | |
58 | @param InputSection A pointer to the input buffer, which contains\r | |
59 | the input section to be processed.\r | |
60 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
61 | size is specified by the contents of OutputSize.\r | |
62 | @param OutputSize A pointer to a caller-allocated\r | |
63 | UINTN in which the size of *OutputBuffer\r | |
64 | allocation is stored. If the function\r | |
65 | returns anything other than EFI_SUCCESS,\r | |
66 | the value of OutputSize is undefined.\r | |
67 | @param AuthenticationStatus A pointer to a caller-allocated\r | |
68 | UINT32 that indicates the\r | |
69 | authentication status of the\r | |
70 | output buffer. If the input\r | |
71 | section's GuidedSectionHeader.\r | |
72 | Attributes field has the\r | |
73 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID \r | |
74 | bit as clear,\r | |
75 | AuthenticationStatus must return\r | |
76 | zero. These bits reflect the\r | |
77 | status of the extraction\r | |
78 | operation. If the function\r | |
79 | returns anything other than\r | |
80 | EFI_SUCCESS, the value of\r | |
81 | AuthenticationStatus is\r | |
82 | undefined.\r | |
83 | \r | |
84 | @retval EFI_SUCCESS The InputSection was\r | |
85 | successfully processed and the\r | |
86 | section contents were returned.\r | |
87 | \r | |
88 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r | |
89 | resources to process the request.\r | |
90 | \r | |
91 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r | |
92 | not match this instance of the\r | |
93 | GUIDed Section Extraction PPI.\r | |
94 | \r | |
95 | **/\r | |
96 | EFI_STATUS\r | |
97 | EFIAPI\r | |
98 | CustomGuidedSectionExtract (\r | |
99 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r | |
100 | IN CONST VOID *InputSection,\r | |
101 | OUT VOID **OutputBuffer,\r | |
102 | OUT UINTN *OutputSize,\r | |
103 | OUT UINT32 *AuthenticationStatus\r | |
104 | )\r | |
105 | {\r | |
106 | EFI_STATUS Status;\r | |
107 | UINT8 *ScratchBuffer;\r | |
108 | UINT32 ScratchBufferSize;\r | |
109 | UINT32 OutputBufferSize;\r | |
110 | UINT16 SectionAttribute;\r | |
111 | \r | |
112 | //\r | |
113 | // Init local variable\r | |
114 | //\r | |
115 | ScratchBuffer = NULL;\r | |
116 | \r | |
117 | //\r | |
118 | // Call GetInfo to get the size and attribute of input guided section data.\r | |
119 | //\r | |
120 | Status = ExtractGuidedSectionGetInfo (\r | |
121 | InputSection,\r | |
122 | &OutputBufferSize,\r | |
123 | &ScratchBufferSize,\r | |
124 | &SectionAttribute\r | |
125 | );\r | |
126 | \r | |
127 | if (EFI_ERROR (Status)) {\r | |
128 | DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r | |
129 | return Status;\r | |
130 | }\r | |
131 | \r | |
132 | if (ScratchBufferSize != 0) {\r | |
133 | //\r | |
134 | // Allocate scratch buffer\r | |
135 | //\r | |
136 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r | |
137 | if (ScratchBuffer == NULL) {\r | |
138 | return EFI_OUT_OF_RESOURCES;\r | |
139 | }\r | |
140 | }\r | |
141 | \r | |
142 | if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) { \r | |
143 | //\r | |
144 | // Allocate output buffer\r | |
145 | //\r | |
146 | *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);\r | |
147 | if (*OutputBuffer == NULL) {\r | |
148 | return EFI_OUT_OF_RESOURCES;\r | |
149 | }\r | |
150 | DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r | |
151 | //\r | |
152 | // *OutputBuffer still is one section. Adjust *OutputBuffer offset, \r | |
153 | // skip EFI section header to make section data at page alignment.\r | |
154 | //\r | |
155 | *OutputBuffer = (VOID *)((UINT8 *) *OutputBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER));\r | |
156 | }\r | |
157 | \r | |
158 | Status = ExtractGuidedSectionDecode (\r | |
159 | InputSection, \r | |
160 | OutputBuffer,\r | |
161 | ScratchBuffer,\r | |
162 | AuthenticationStatus\r | |
163 | );\r | |
164 | if (EFI_ERROR (Status)) {\r | |
165 | //\r | |
166 | // Decode failed\r | |
167 | //\r | |
168 | DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r | |
169 | return Status;\r | |
170 | }\r | |
171 | \r | |
172 | *OutputSize = (UINTN) OutputBufferSize;\r | |
173 | \r | |
174 | return EFI_SUCCESS;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | Main entry for Section Extraction PEIM driver.\r | |
179 | \r | |
180 | This routine registers the Section Extraction PPIs that have been registered \r | |
181 | with the Section Extraction Library.\r | |
182 | \r | |
183 | @param FileHandle Handle of the file being invoked.\r | |
184 | @param PeiServices Describes the list of possible PEI Services.\r | |
185 | \r | |
186 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
187 | @retval other Some error occurs when executing this entry point.\r | |
188 | \r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | EFIAPI\r | |
192 | SectionExtractionPeiEntry (\r | |
193 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
194 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
195 | ) \r | |
196 | {\r | |
197 | EFI_STATUS Status;\r | |
198 | EFI_GUID *ExtractHandlerGuidTable;\r | |
199 | UINTN ExtractHandlerNumber;\r | |
200 | EFI_PEI_PPI_DESCRIPTOR *GuidPpi;\r | |
201 | \r | |
202 | //\r | |
203 | // Get custom extract guided section method guid list \r | |
204 | //\r | |
205 | ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r | |
206 | \r | |
207 | //\r | |
208 | // Install custom extraction guid PPI\r | |
209 | //\r | |
210 | if (ExtractHandlerNumber > 0) {\r | |
211 | GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
212 | ASSERT (GuidPpi != NULL);\r | |
213 | while (ExtractHandlerNumber-- > 0) {\r | |
214 | GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r | |
215 | GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi;\r | |
216 | GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r | |
217 | Status = PeiServicesInstallPpi (GuidPpi++);\r | |
218 | ASSERT_EFI_ERROR (Status);\r | |
219 | }\r | |
220 | }\r | |
221 | \r | |
222 | return EFI_SUCCESS;\r | |
223 | }\r |