]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | Pei Core Firmware File System service routines.\r |
3 | \r | |
ed299e3c | 4 | Copyright (c) 2006 - 2008, Intel Corporation \r |
192f6d4c | 5 | All rights reserved. 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 | |
615c6dd0 | 13 | **/\r |
192f6d4c | 14 | \r |
0d516397 | 15 | #include "PeiMain.h"\r |
192f6d4c | 16 | \r |
fe1e36e5 | 17 | EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = {\r |
b0d803fe | 18 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
19 | &gEfiPeiFirmwareVolumeInfoPpiGuid,\r | |
20 | FirmwareVolmeInfoPpiNotifyCallback \r | |
21 | };\r | |
22 | \r | |
23 | \r | |
24 | #define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r | |
ed299e3c | 25 | ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))\r |
192f6d4c | 26 | \r |
b1f6a7c6 | 27 | /**\r |
ed299e3c | 28 | Returns the file state set by the highest zero bit in the State field\r |
192f6d4c | 29 | \r |
b1f6a7c6 | 30 | @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r |
31 | in the Attributes field.\r | |
32 | @param FfsHeader Pointer to FFS File Header.\r | |
192f6d4c | 33 | \r |
ed299e3c LG |
34 | @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit \r |
35 | in the header State field.\r | |
b1f6a7c6 | 36 | **/\r |
37 | EFI_FFS_FILE_STATE\r | |
38 | GetFileState(\r | |
39 | IN UINT8 ErasePolarity,\r | |
40 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
41 | )\r | |
192f6d4c | 42 | {\r |
43 | EFI_FFS_FILE_STATE FileState;\r | |
44 | EFI_FFS_FILE_STATE HighestBit;\r | |
45 | \r | |
46 | FileState = FfsHeader->State;\r | |
47 | \r | |
48 | if (ErasePolarity != 0) {\r | |
49 | FileState = (EFI_FFS_FILE_STATE)~FileState;\r | |
50 | }\r | |
ed299e3c LG |
51 | \r |
52 | //\r | |
53 | // Get file state set by its highest none zero bit.\r | |
54 | //\r | |
192f6d4c | 55 | HighestBit = 0x80;\r |
56 | while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r | |
57 | HighestBit >>= 1;\r | |
58 | }\r | |
59 | \r | |
60 | return HighestBit;\r | |
61 | } \r | |
62 | \r | |
b1f6a7c6 | 63 | /**\r |
64 | Calculates the checksum of the header of a file.\r | |
65 | \r | |
66 | @param FileHeader Pointer to FFS File Header.\r | |
67 | \r | |
68 | @return Checksum of the header.\r | |
b1f6a7c6 | 69 | Zero means the header is good.\r |
70 | Non-zero means the header is bad.\r | |
71 | **/\r | |
192f6d4c | 72 | UINT8\r |
73 | CalculateHeaderChecksum (\r | |
74 | IN EFI_FFS_FILE_HEADER *FileHeader\r | |
75 | )\r | |
192f6d4c | 76 | {\r |
ed299e3c | 77 | EFI_FFS_FILE_HEADER TestFileHeader;\r |
192f6d4c | 78 | \r |
ed299e3c | 79 | CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r |
192f6d4c | 80 | //\r |
ed299e3c | 81 | // Ingore State and File field in FFS header.\r |
192f6d4c | 82 | //\r |
ed299e3c LG |
83 | TestFileHeader.State = 0;\r |
84 | TestFileHeader.IntegrityCheck.Checksum.File = 0;\r | |
192f6d4c | 85 | \r |
ed299e3c | 86 | return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));\r |
192f6d4c | 87 | }\r |
88 | \r | |
b1f6a7c6 | 89 | /**\r |
90 | Find FV handler according some FileHandle in that FV.\r | |
91 | \r | |
92 | @param FileHandle Handle of file image\r | |
ed299e3c | 93 | @param VolumeHandle Handle of the found FV, if not found, NULL will be set.\r |
b1f6a7c6 | 94 | \r |
ed299e3c LG |
95 | @retval TRUE The corresponding FV handler is found.\r |
96 | @retval FALSE The corresponding FV handler is not found.\r | |
b1f6a7c6 | 97 | \r |
98 | **/\r | |
b0d803fe | 99 | BOOLEAN\r |
100 | EFIAPI\r | |
101 | PeiFileHandleToVolume (\r | |
102 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
103 | OUT EFI_PEI_FV_HANDLE *VolumeHandle\r | |
104 | )\r | |
105 | {\r | |
106 | UINTN Index;\r | |
107 | PEI_CORE_INSTANCE *PrivateData;\r | |
108 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
109 | \r | |
110 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
111 | for (Index = 0; Index < PrivateData->FvCount; Index++) {\r | |
112 | FwVolHeader = PrivateData->Fv[Index].FvHeader;\r | |
67a58d0f | 113 | if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \\r |
114 | ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r | |
b0d803fe | 115 | *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;\r |
116 | return TRUE;\r | |
117 | }\r | |
118 | }\r | |
ed299e3c | 119 | *VolumeHandle = NULL;\r |
b0d803fe | 120 | return FALSE;\r |
121 | }\r | |
122 | \r | |
b1f6a7c6 | 123 | /**\r |
ed299e3c | 124 | Given the input file pointer, search for the first matching file in the\r |
b1f6a7c6 | 125 | FFS volume as defined by SearchType. The search starts from FileHeader inside\r |
126 | the Firmware Volume defined by FwVolHeader.\r | |
ed299e3c LG |
127 | If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r |
128 | If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r | |
129 | the first PEIM, or COMBINED PEIM or FV file type FFS file will return. \r | |
b1f6a7c6 | 130 | \r |
131 | @param FvHandle Pointer to the FV header of the volume to search\r | |
132 | @param FileName File name\r | |
133 | @param SearchType Filter to find only files of this type.\r | |
134 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
135 | @param FileHandle This parameter must point to a valid FFS volume.\r | |
136 | @param AprioriFile Pointer to AprioriFile image in this FV if has\r | |
b0d803fe | 137 | \r |
b1f6a7c6 | 138 | @return EFI_NOT_FOUND No files matching the search criteria were found\r |
139 | @retval EFI_SUCCESS Success to search given file\r | |
140 | \r | |
141 | **/\r | |
192f6d4c | 142 | EFI_STATUS\r |
b0d803fe | 143 | PeiFindFileEx (\r |
144 | IN CONST EFI_PEI_FV_HANDLE FvHandle,\r | |
145 | IN CONST EFI_GUID *FileName, OPTIONAL\r | |
146 | IN EFI_FV_FILETYPE SearchType,\r | |
147 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle,\r | |
148 | IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL\r | |
192f6d4c | 149 | )\r |
192f6d4c | 150 | {\r |
b0d803fe | 151 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r |
152 | EFI_FFS_FILE_HEADER **FileHeader;\r | |
153 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r | |
b0d803fe | 154 | UINT32 FileLength;\r |
155 | UINT32 FileOccupiedSize;\r | |
156 | UINT32 FileOffset;\r | |
157 | UINT64 FvLength;\r | |
158 | UINT8 ErasePolarity;\r | |
159 | UINT8 FileState;\r | |
160 | \r | |
161 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle;\r | |
162 | FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;\r | |
192f6d4c | 163 | \r |
164 | FvLength = FwVolHeader->FvLength;\r | |
d976bf31 | 165 | if ((FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r |
192f6d4c | 166 | ErasePolarity = 1;\r |
167 | } else {\r | |
168 | ErasePolarity = 0;\r | |
169 | }\r | |
170 | \r | |
171 | //\r | |
b0d803fe | 172 | // If FileHeader is not specified (NULL) or FileName is not NULL,\r |
173 | // start with the first file in the firmware volume. Otherwise,\r | |
174 | // start from the FileHeader.\r | |
192f6d4c | 175 | //\r |
b0d803fe | 176 | if ((*FileHeader == NULL) || (FileName != NULL)) {\r |
192f6d4c | 177 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);\r |
178 | } else {\r | |
179 | //\r | |
180 | // Length is 24 bits wide so mask upper 8 bits\r | |
181 | // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r | |
182 | //\r | |
183 | FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;\r | |
b0d803fe | 184 | FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r |
192f6d4c | 185 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r |
186 | }\r | |
e98cd821 | 187 | \r |
192f6d4c | 188 | FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r |
189 | ASSERT (FileOffset <= 0xFFFFFFFF);\r | |
e98cd821 | 190 | \r |
b0d803fe | 191 | while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r |
192f6d4c | 192 | //\r |
193 | // Get FileState which is the highest bit of the State \r | |
194 | //\r | |
195 | FileState = GetFileState (ErasePolarity, FfsFileHeader);\r | |
192f6d4c | 196 | switch (FileState) {\r |
197 | \r | |
198 | case EFI_FILE_HEADER_INVALID:\r | |
40f26b8f | 199 | FileOffset += sizeof(EFI_FFS_FILE_HEADER);\r |
200 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r | |
192f6d4c | 201 | break;\r |
202 | \r | |
203 | case EFI_FILE_DATA_VALID:\r | |
204 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
b0d803fe | 205 | if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r |
192f6d4c | 206 | ASSERT (FALSE);\r |
e98cd821 | 207 | *FileHeader = NULL;\r |
192f6d4c | 208 | return EFI_NOT_FOUND;\r |
209 | }\r | |
b0d803fe | 210 | \r |
40f26b8f | 211 | FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r |
b0d803fe | 212 | FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r |
213 | \r | |
214 | if (FileName != NULL) {\r | |
215 | if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r | |
216 | *FileHeader = FfsFileHeader;\r | |
217 | return EFI_SUCCESS;\r | |
218 | }\r | |
219 | } else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {\r | |
220 | if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) || \r | |
288f9b38 LG |
221 | (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r |
222 | (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) { \r | |
b0d803fe | 223 | \r |
224 | *FileHeader = FfsFileHeader;\r | |
225 | return EFI_SUCCESS;\r | |
226 | } else if (AprioriFile != NULL) {\r | |
227 | if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {\r | |
228 | if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {\r | |
229 | *AprioriFile = FfsFileHeader;\r | |
230 | } \r | |
231 | } \r | |
232 | }\r | |
7e181f2f | 233 | } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && \r |
234 | (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { \r | |
b0d803fe | 235 | *FileHeader = FfsFileHeader;\r |
236 | return EFI_SUCCESS;\r | |
237 | }\r | |
238 | \r | |
40f26b8f | 239 | FileOffset += FileOccupiedSize; \r |
240 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 241 | break;\r |
242 | \r | |
243 | case EFI_FILE_DELETED:\r | |
40f26b8f | 244 | FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r |
245 | FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r | |
246 | FileOffset += FileOccupiedSize;\r | |
247 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 248 | break;\r |
249 | \r | |
250 | default:\r | |
e98cd821 | 251 | *FileHeader = NULL;\r |
192f6d4c | 252 | return EFI_NOT_FOUND;\r |
192f6d4c | 253 | } \r |
254 | }\r | |
e98cd821 LG |
255 | \r |
256 | *FileHeader = NULL;\r | |
192f6d4c | 257 | return EFI_NOT_FOUND; \r |
258 | }\r | |
259 | \r | |
b1f6a7c6 | 260 | /**\r |
b1f6a7c6 | 261 | Initialize PeiCore Fv List.\r |
262 | \r | |
b1f6a7c6 | 263 | @param PrivateData - Pointer to PEI_CORE_INSTANCE.\r |
264 | @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r | |
b1f6a7c6 | 265 | **/\r |
b0d803fe | 266 | VOID \r |
267 | PeiInitializeFv (\r | |
268 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
269 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r | |
270 | )\r | |
b0d803fe | 271 | {\r |
272 | EFI_STATUS Status;\r | |
273 | //\r | |
274 | // The BFV must be the first entry. The Core FV support is stateless \r | |
275 | // The AllFV list has a single entry per FV in PEI. \r | |
276 | // The Fv list only includes FV that PEIMs will be dispatched from and\r | |
277 | // its File System Format is PI 1.0 definition.\r | |
278 | //\r | |
279 | PrivateData->FvCount = 1;\r | |
280 | PrivateData->Fv[0].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;\r | |
281 | \r | |
282 | PrivateData->AllFvCount = 1;\r | |
283 | PrivateData->AllFv[0] = (EFI_PEI_FV_HANDLE)PrivateData->Fv[0].FvHeader;\r | |
b0d803fe | 284 | //\r |
285 | // Post a call-back for the FvInfoPPI services to expose\r | |
286 | // additional Fvs to PeiCore.\r | |
287 | //\r | |
288 | Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);\r | |
289 | ASSERT_EFI_ERROR (Status);\r | |
290 | \r | |
291 | }\r | |
292 | \r | |
b1f6a7c6 | 293 | /**\r |
294 | Process Firmware Volum Information once FvInfoPPI install.\r | |
ed299e3c LG |
295 | The FV Info will be registered into PeiCore private data structure.\r |
296 | And search the inside FV image, if found, the new FV INFO PPI will be installed.\r | |
b1f6a7c6 | 297 | \r |
ed299e3c | 298 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
731bd38e | 299 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
300 | @param Ppi Address of the PPI that was installed.\r | |
b1f6a7c6 | 301 | \r |
ed299e3c | 302 | @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r |
6a1ae84a | 303 | @return if not EFI_SUCESS, fail to verify FV.\r |
b1f6a7c6 | 304 | \r |
305 | **/\r | |
b0d803fe | 306 | EFI_STATUS\r |
307 | EFIAPI\r | |
308 | FirmwareVolmeInfoPpiNotifyCallback (\r | |
309 | IN EFI_PEI_SERVICES **PeiServices,\r | |
310 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
311 | IN VOID *Ppi\r | |
312 | )\r | |
b0d803fe | 313 | {\r |
314 | UINT8 FvCount;\r | |
315 | EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;\r | |
316 | PEI_CORE_INSTANCE *PrivateData;\r | |
288f9b38 LG |
317 | EFI_PEI_FILE_HANDLE FileHandle;\r |
318 | VOID *DepexData;\r | |
319 | UINT32 AuthenticationStatus;\r | |
320 | EFI_STATUS Status;\r | |
b0d803fe | 321 | \r |
288f9b38 LG |
322 | FileHandle = NULL;\r |
323 | DepexData = NULL;\r | |
324 | Status = EFI_SUCCESS;\r | |
325 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
b0d803fe | 326 | \r |
177aabe6 | 327 | if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
97b2c9b5 LG |
328 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r |
329 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r | |
b0d803fe | 330 | ASSERT (FALSE);\r |
331 | }\r | |
332 | \r | |
333 | Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;\r | |
334 | \r | |
97b2c9b5 LG |
335 | //\r |
336 | // Only add FileSystem2 Fv to Fv list\r | |
337 | //\r | |
288f9b38 LG |
338 | if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r |
339 | for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {\r | |
340 | if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {\r | |
341 | return EFI_SUCCESS;\r | |
342 | }\r | |
343 | }\r | |
6a1ae84a | 344 | \r |
345 | Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo);\r | |
346 | if (EFI_ERROR(Status)) {\r | |
347 | DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", (VOID *) Fv->FvInfo));\r | |
348 | return Status;\r | |
349 | }\r | |
350 | \r | |
b0d803fe | 351 | PrivateData->Fv[PrivateData->FvCount++].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo;\r |
b0d803fe | 352 | \r |
288f9b38 LG |
353 | PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;\r |
354 | \r | |
7df7393f | 355 | DEBUG ((EFI_D_INFO, "The %dth FvImage start address is 0x%11p and size is 0x%08x\n", (UINT32)PrivateData->AllFvCount, (VOID *) Fv->FvInfo, Fv->FvInfoSize));\r |
288f9b38 LG |
356 | //\r |
357 | // Preprocess all FV type files in this new FileSystem2 Fv image\r | |
358 | //\r | |
359 | do {\r | |
360 | Status = PeiFindFileEx (\r | |
361 | (EFI_PEI_FV_HANDLE)Fv->FvInfo, \r | |
362 | NULL, \r | |
363 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, \r | |
364 | &FileHandle, \r | |
365 | NULL\r | |
366 | );\r | |
367 | if (!EFI_ERROR (Status)) {\r | |
368 | Status = PeiFfsFindSectionData (\r | |
369 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
370 | EFI_SECTION_PEI_DEPEX,\r | |
371 | FileHandle, \r | |
372 | (VOID **)&DepexData\r | |
373 | );\r | |
374 | if (!EFI_ERROR (Status)) {\r | |
375 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
376 | //\r | |
377 | // Dependency is not satisfied.\r | |
378 | //\r | |
379 | continue;\r | |
380 | }\r | |
381 | }\r | |
382 | //\r | |
383 | // Process FvFile to install FvInfo ppi and build FvHob\r | |
384 | // \r | |
97b2c9b5 | 385 | ProcessFvFile ((CONST EFI_PEI_SERVICES **) PeiServices, (EFI_PEI_FV_HANDLE)Fv->FvInfo, FileHandle, &AuthenticationStatus);\r |
288f9b38 LG |
386 | }\r |
387 | } while (FileHandle != NULL);\r | |
388 | }\r | |
b0d803fe | 389 | \r |
390 | return EFI_SUCCESS;\r | |
391 | }\r | |
392 | \r | |
b1f6a7c6 | 393 | /**\r |
ed299e3c LG |
394 | Go through the file to search SectionType section. \r |
395 | Search within encapsulation sections (compression and GUIDed) recursively, \r | |
396 | until the match section is found.\r | |
397 | \r | |
398 | @param PeiServices - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
399 | @param SectionType - Filter to find only section of this type.\r | |
400 | @param Section - From where to search.\r | |
401 | @param SectionSize - The file size to search.\r | |
402 | @param OutputBuffer - A pointer to the discovered section, if successful.\r | |
403 | NULL if section not found\r | |
b1f6a7c6 | 404 | \r |
ed299e3c LG |
405 | @return EFI_NOT_FOUND The match section is not found.\r |
406 | @return EFI_SUCCESS The match section is found.\r | |
b1f6a7c6 | 407 | \r |
408 | **/\r | |
b0d803fe | 409 | EFI_STATUS\r |
410 | PeiFfsProcessSection (\r | |
411 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
412 | IN EFI_SECTION_TYPE SectionType,\r | |
413 | IN EFI_COMMON_SECTION_HEADER *Section,\r | |
414 | IN UINTN SectionSize,\r | |
288f9b38 | 415 | OUT VOID **OutputBuffer\r |
b0d803fe | 416 | )\r |
b0d803fe | 417 | {\r |
418 | EFI_STATUS Status;\r | |
419 | UINT32 SectionLength;\r | |
420 | UINT32 ParsedLength;\r | |
b0d803fe | 421 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r |
b0d803fe | 422 | EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r |
423 | VOID *PpiOutput;\r | |
424 | UINTN PpiOutputSize;\r | |
288f9b38 LG |
425 | UINTN Index;\r |
426 | UINT32 Authentication;\r | |
427 | PEI_CORE_INSTANCE *PrivateData;\r | |
b0d803fe | 428 | \r |
288f9b38 | 429 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
b0d803fe | 430 | *OutputBuffer = NULL;\r |
288f9b38 LG |
431 | ParsedLength = 0;\r |
432 | Index = 0;\r | |
433 | Status = EFI_NOT_FOUND;\r | |
434 | PpiOutput = NULL;\r | |
435 | PpiOutputSize = 0;\r | |
b0d803fe | 436 | while (ParsedLength < SectionSize) {\r |
437 | if (Section->Type == SectionType) {\r | |
438 | *OutputBuffer = (VOID *)(Section + 1);\r | |
439 | return EFI_SUCCESS;\r | |
288f9b38 LG |
440 | } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r |
441 | //\r | |
442 | // Check the encapsulated section is extracted into the cache data.\r | |
443 | //\r | |
444 | for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r | |
445 | if (Section == PrivateData->CacheSection.Section[Index]) {\r | |
446 | PpiOutput = PrivateData->CacheSection.SectionData[Index];\r | |
447 | PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r | |
448 | //\r | |
449 | // Search section directly from the cache data.\r | |
450 | //\r | |
b0d803fe | 451 | return PeiFfsProcessSection (\r |
452 | PeiServices,\r | |
453 | SectionType, \r | |
454 | PpiOutput, \r | |
455 | PpiOutputSize, \r | |
288f9b38 | 456 | OutputBuffer \r |
b0d803fe | 457 | );\r |
458 | }\r | |
459 | }\r | |
288f9b38 LG |
460 | \r |
461 | Status = EFI_NOT_FOUND;\r | |
462 | if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r | |
463 | Status = PeiServicesLocatePpi (\r | |
464 | &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid, \r | |
465 | 0, \r | |
466 | NULL, \r | |
467 | (VOID **) &GuidSectionPpi\r | |
468 | );\r | |
b0d803fe | 469 | if (!EFI_ERROR (Status)) {\r |
288f9b38 LG |
470 | Status = GuidSectionPpi->ExtractSection (\r |
471 | GuidSectionPpi,\r | |
472 | Section,\r | |
473 | &PpiOutput,\r | |
474 | &PpiOutputSize,\r | |
475 | &Authentication\r | |
476 | );\r | |
477 | }\r | |
478 | } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r | |
479 | Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r | |
480 | if (!EFI_ERROR (Status)) {\r | |
481 | Status = DecompressPpi->Decompress (\r | |
482 | DecompressPpi,\r | |
483 | (CONST EFI_COMPRESSION_SECTION*) Section,\r | |
484 | &PpiOutput,\r | |
485 | &PpiOutputSize\r | |
486 | );\r | |
b0d803fe | 487 | }\r |
488 | }\r | |
288f9b38 LG |
489 | \r |
490 | if (!EFI_ERROR (Status)) {\r | |
491 | //\r | |
492 | // Update cache section data.\r | |
493 | //\r | |
494 | if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r | |
495 | PrivateData->CacheSection.AllSectionCount ++;\r | |
496 | }\r | |
497 | PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r | |
498 | PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r | |
499 | PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r | |
500 | PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r | |
501 | \r | |
502 | return PeiFfsProcessSection (\r | |
503 | PeiServices,\r | |
504 | SectionType, \r | |
505 | PpiOutput, \r | |
506 | PpiOutputSize, \r | |
507 | OutputBuffer \r | |
508 | );\r | |
509 | }\r | |
b0d803fe | 510 | }\r |
511 | \r | |
512 | //\r | |
513 | // Size is 24 bits wide so mask upper 8 bits. \r | |
514 | // SectionLength is adjusted it is 4 byte aligned.\r | |
515 | // Go to the next section\r | |
516 | //\r | |
517 | SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r | |
518 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
519 | ASSERT (SectionLength != 0);\r | |
520 | ParsedLength += SectionLength;\r | |
521 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
522 | }\r | |
523 | \r | |
524 | return EFI_NOT_FOUND;\r | |
525 | }\r | |
526 | \r | |
192f6d4c | 527 | \r |
b1f6a7c6 | 528 | /**\r |
ed299e3c | 529 | Given the input file pointer, search for the first matching section in the\r |
b1f6a7c6 | 530 | FFS volume.\r |
531 | \r | |
ed299e3c | 532 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 533 | @param SectionType Filter to find only sections of this type.\r |
534 | @param FileHandle Pointer to the current file to search.\r | |
ed299e3c | 535 | @param SectionData A pointer to the discovered section, if successful.\r |
b1f6a7c6 | 536 | NULL if section not found\r |
537 | \r | |
538 | @retval EFI_NOT_FOUND No files matching the search criteria were found\r | |
539 | @retval EFI_SUCCESS Success to find section data in given file\r | |
540 | \r | |
541 | **/\r | |
192f6d4c | 542 | EFI_STATUS\r |
543 | EFIAPI\r | |
544 | PeiFfsFindSectionData (\r | |
0c2b5da8 | 545 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 546 | IN EFI_SECTION_TYPE SectionType,\r |
0c2b5da8 | 547 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
192f6d4c | 548 | IN OUT VOID **SectionData\r |
549 | )\r | |
192f6d4c | 550 | {\r |
b0d803fe | 551 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r |
552 | UINT32 FileSize;\r | |
553 | EFI_COMMON_SECTION_HEADER *Section;\r | |
b0d803fe | 554 | \r |
555 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r | |
192f6d4c | 556 | \r |
557 | //\r | |
558 | // Size is 24 bits wide so mask upper 8 bits. \r | |
b0d803fe | 559 | // Does not include FfsFileHeader header size\r |
192f6d4c | 560 | // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r |
561 | //\r | |
562 | Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);\r | |
563 | FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r | |
b0d803fe | 564 | FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r |
565 | \r | |
566 | return PeiFfsProcessSection (\r | |
288f9b38 | 567 | PeiServices,\r |
b0d803fe | 568 | SectionType, \r |
569 | Section, \r | |
570 | FileSize, \r | |
288f9b38 | 571 | SectionData\r |
b0d803fe | 572 | );\r |
192f6d4c | 573 | }\r |
574 | \r | |
b1f6a7c6 | 575 | /**\r |
576 | Given the input file pointer, search for the next matching file in the\r | |
577 | FFS volume as defined by SearchType. The search starts from FileHeader inside\r | |
578 | the Firmware Volume defined by FwVolHeader.\r | |
192f6d4c | 579 | \r |
b1f6a7c6 | 580 | \r |
d73d93c3 | 581 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 582 | @param SearchType Filter to find only files of this type.\r |
583 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
584 | @param VolumeHandle Pointer to the FV header of the volume to search.\r | |
585 | @param FileHandle Pointer to the current file from which to begin searching.\r | |
586 | This pointer will be updated upon return to reflect the file found.\r | |
587 | @retval EFI_NOT_FOUND No files matching the search criteria were found\r | |
588 | @retval EFI_SUCCESS Success to find next file in given volume\r | |
589 | \r | |
590 | **/\r | |
192f6d4c | 591 | EFI_STATUS\r |
592 | EFIAPI\r | |
593 | PeiFfsFindNextFile (\r | |
0c2b5da8 | 594 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
595 | IN UINT8 SearchType,\r | |
596 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
597 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
192f6d4c | 598 | )\r |
192f6d4c | 599 | {\r |
b0d803fe | 600 | return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);\r |
192f6d4c | 601 | }\r |
602 | \r | |
b0d803fe | 603 | \r |
b1f6a7c6 | 604 | /**\r |
ed299e3c | 605 | Search the firmware volumes by index\r |
b1f6a7c6 | 606 | \r |
ed299e3c | 607 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 608 | @param Instance Instance of FV to find\r |
609 | @param VolumeHandle Pointer to found Volume.\r | |
610 | \r | |
611 | @retval EFI_INVALID_PARAMETER FwVolHeader is NULL\r | |
612 | @retval EFI_SUCCESS Firmware volume instance successfully found.\r | |
613 | \r | |
614 | **/\r | |
192f6d4c | 615 | EFI_STATUS \r |
616 | EFIAPI\r | |
617 | PeiFvFindNextVolume (\r | |
2a00326e | 618 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 619 | IN UINTN Instance,\r |
0c2b5da8 | 620 | IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r |
192f6d4c | 621 | )\r |
192f6d4c | 622 | {\r |
2a00326e LG |
623 | PEI_CORE_INSTANCE *Private;\r |
624 | UINTN Index;\r | |
625 | BOOLEAN Match;\r | |
626 | EFI_HOB_FIRMWARE_VOLUME *FvHob;\r | |
192f6d4c | 627 | \r |
b0d803fe | 628 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
629 | if (VolumeHandle == NULL) {\r | |
630 | return EFI_INVALID_PARAMETER;\r | |
2a00326e LG |
631 | }\r |
632 | \r | |
633 | //\r | |
634 | // Handle Framework FvHob and Install FvInfo Ppi for it.\r | |
635 | //\r | |
f806dd27 | 636 | if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r |
2a00326e LG |
637 | //\r |
638 | // Loop to search the wanted FirmwareVolume which supports FFS\r | |
639 | //\r | |
640 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r | |
641 | while (FvHob != NULL) {\r | |
642 | for (Index = 0, Match = FALSE; Index < Private->AllFvCount; Index++) {\r | |
643 | if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->AllFv[Index]) {\r | |
644 | Match = TRUE;\r | |
645 | break;\r | |
646 | }\r | |
647 | }\r | |
648 | //\r | |
649 | // If Not Found, Install FvInfo Ppi for it.\r | |
650 | //\r | |
651 | if (!Match) {\r | |
187f1a5b | 652 | PeiServicesInstallFvInfoPpi (\r |
ed5ac057 | 653 | &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r |
2a00326e LG |
654 | (VOID *)(UINTN)FvHob->BaseAddress,\r |
655 | (UINT32)FvHob->Length,\r | |
656 | NULL,\r | |
657 | NULL\r | |
658 | );\r | |
659 | }\r | |
660 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r | |
661 | }\r | |
662 | }\r | |
192f6d4c | 663 | \r |
b0d803fe | 664 | if (Instance >= Private->AllFvCount) {\r |
665 | VolumeHandle = NULL;\r | |
666 | return EFI_NOT_FOUND;\r | |
667 | }\r | |
192f6d4c | 668 | \r |
b0d803fe | 669 | *VolumeHandle = Private->AllFv[Instance];\r |
670 | return EFI_SUCCESS;\r | |
671 | }\r | |
192f6d4c | 672 | \r |
192f6d4c | 673 | \r |
b1f6a7c6 | 674 | /**\r |
ed299e3c | 675 | Find a file within a volume by its name.\r |
b1f6a7c6 | 676 | \r |
ed299e3c LG |
677 | @param FileName A pointer to the name of the file to find within the firmware volume.\r |
678 | @param VolumeHandle The firmware volume to search\r | |
679 | @param FileHandle Upon exit, points to the found file's handle \r | |
680 | or NULL if it could not be found.\r | |
b1f6a7c6 | 681 | \r |
ed299e3c LG |
682 | @retval EFI_SUCCESS File was found.\r |
683 | @retval EFI_NOT_FOUND File was not found.\r | |
684 | @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r | |
b1f6a7c6 | 685 | \r |
b1f6a7c6 | 686 | **/\r |
b0d803fe | 687 | EFI_STATUS\r |
688 | EFIAPI \r | |
689 | PeiFfsFindFileByName (\r | |
690 | IN CONST EFI_GUID *FileName,\r | |
691 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
692 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
693 | )\r | |
b0d803fe | 694 | {\r |
695 | EFI_STATUS Status;\r | |
696 | if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r | |
192f6d4c | 697 | return EFI_INVALID_PARAMETER;\r |
698 | }\r | |
b0d803fe | 699 | Status = PeiFindFileEx (VolumeHandle, FileName, 0, FileHandle, NULL);\r |
700 | if (Status == EFI_NOT_FOUND) {\r | |
701 | *FileHandle = NULL;\r | |
702 | }\r | |
703 | return Status;\r | |
704 | }\r | |
705 | \r | |
b1f6a7c6 | 706 | /**\r |
707 | \r | |
708 | Returns information about a specific file.\r | |
709 | \r | |
710 | \r | |
711 | @param FileHandle - The handle to file.\r | |
712 | @param FileInfo - Pointer to the file information.\r | |
713 | \r | |
714 | @retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.\r | |
715 | @retval EFI_SUCCESS Success to collect file info.\r | |
716 | \r | |
717 | **/\r | |
b0d803fe | 718 | EFI_STATUS\r |
719 | EFIAPI \r | |
720 | PeiFfsGetFileInfo (\r | |
721 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
722 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
723 | )\r | |
b0d803fe | 724 | {\r |
725 | UINT8 FileState;\r | |
726 | UINT8 ErasePolarity;\r | |
727 | EFI_FFS_FILE_HEADER *FileHeader;\r | |
728 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
729 | \r | |
730 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
731 | return EFI_INVALID_PARAMETER;\r | |
732 | }\r | |
733 | \r | |
173b35e4 | 734 | VolumeHandle = 0;\r |
b0d803fe | 735 | //\r |
736 | // Retrieve the FirmwareVolume which the file resides in.\r | |
737 | //\r | |
738 | if (!PeiFileHandleToVolume(FileHandle, &VolumeHandle)) {\r | |
739 | return EFI_INVALID_PARAMETER;\r | |
740 | }\r | |
741 | \r | |
797a9d67 | 742 | if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {\r |
b0d803fe | 743 | ErasePolarity = 1;\r |
192f6d4c | 744 | } else {\r |
b0d803fe | 745 | ErasePolarity = 0;\r |
746 | }\r | |
747 | \r | |
748 | //\r | |
749 | // Get FileState which is the highest bit of the State \r | |
750 | //\r | |
751 | FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r | |
192f6d4c | 752 | \r |
b0d803fe | 753 | switch (FileState) {\r |
754 | case EFI_FILE_DATA_VALID:\r | |
755 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
756 | break; \r | |
757 | default:\r | |
758 | return EFI_INVALID_PARAMETER;\r | |
192f6d4c | 759 | }\r |
b0d803fe | 760 | \r |
761 | FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r | |
762 | CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r | |
763 | FileInfo->FileType = FileHeader->Type;\r | |
764 | FileInfo->FileAttributes = FileHeader->Attributes;\r | |
765 | FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);\r | |
766 | FileInfo->Buffer = (FileHeader + 1);\r | |
767 | return EFI_SUCCESS;\r | |
768 | }\r | |
769 | \r | |
770 | \r | |
b1f6a7c6 | 771 | /**\r |
772 | \r | |
773 | Collect information of given Fv Volume.\r | |
774 | \r | |
775 | @param VolumeHandle - The handle to Fv Volume.\r | |
776 | @param VolumeInfo - The pointer to volume information.\r | |
777 | \r | |
778 | @retval EFI_INVALID_PARAMETER VolumeInfo is NULL\r | |
779 | @retval EFI_SUCCESS Success to collect fv info.\r | |
780 | **/\r | |
b0d803fe | 781 | EFI_STATUS\r |
782 | EFIAPI \r | |
783 | PeiFfsGetVolumeInfo (\r | |
784 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
785 | OUT EFI_FV_INFO *VolumeInfo\r | |
786 | )\r | |
b0d803fe | 787 | {\r |
288f9b38 | 788 | EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r |
b0d803fe | 789 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r |
790 | \r | |
791 | if (VolumeInfo == NULL) {\r | |
792 | return EFI_INVALID_PARAMETER;\r | |
192f6d4c | 793 | }\r |
288f9b38 LG |
794 | \r |
795 | //\r | |
796 | // VolumeHandle may not align at 8 byte, \r | |
797 | // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r | |
798 | // So, Copy FvHeader into the local FvHeader structure.\r | |
799 | //\r | |
800 | CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r | |
801 | //\r | |
802 | // Check Fv Image Signature\r | |
803 | //\r | |
804 | if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r | |
805 | return EFI_INVALID_PARAMETER;\r | |
806 | }\r | |
97b2c9b5 | 807 | ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r |
288f9b38 LG |
808 | VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r |
809 | VolumeInfo->FvStart = (VOID *) VolumeHandle;\r | |
810 | VolumeInfo->FvSize = FwVolHeader.FvLength;\r | |
811 | CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r | |
b0d803fe | 812 | \r |
288f9b38 LG |
813 | if (FwVolHeader.ExtHeaderOffset != 0) {\r |
814 | FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);\r | |
b0d803fe | 815 | CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r |
816 | }\r | |
817 | return EFI_SUCCESS;\r | |
192f6d4c | 818 | }\r |
b0d803fe | 819 | \r |
4c6486b9 | 820 | /**\r |
821 | Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r | |
822 | \r | |
823 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
97b2c9b5 LG |
824 | @param ParentFvHandle Fv handle to parent Fv image that contain this Fv image.\r |
825 | @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r | |
4c6486b9 | 826 | @param AuthenticationState Pointer to attestation authentication state of image.\r |
827 | \r | |
828 | \r | |
829 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
830 | @retval EFI_SUCCESS Successfully to process it.\r | |
831 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
832 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r | |
833 | \r | |
834 | **/\r | |
835 | EFI_STATUS\r | |
836 | ProcessFvFile (\r | |
6c7a807a | 837 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
97b2c9b5 LG |
838 | IN EFI_PEI_FV_HANDLE ParentFvHandle,\r |
839 | IN EFI_PEI_FILE_HANDLE ParentFvFileHandle,\r | |
6c7a807a | 840 | OUT UINT32 *AuthenticationState\r |
4c6486b9 | 841 | )\r |
842 | {\r | |
843 | EFI_STATUS Status;\r | |
844 | EFI_PEI_FV_HANDLE FvImageHandle;\r | |
845 | EFI_FV_INFO FvImageInfo;\r | |
97b2c9b5 | 846 | EFI_FV_INFO ParentFvImageInfo;\r |
4c6486b9 | 847 | UINT32 FvAlignment;\r |
848 | VOID *FvBuffer;\r | |
849 | EFI_PEI_HOB_POINTERS HobPtr;\r | |
850 | \r | |
851 | FvBuffer = NULL;\r | |
852 | *AuthenticationState = 0;\r | |
853 | \r | |
854 | //\r | |
855 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r | |
856 | // been extracted.\r | |
857 | //\r | |
858 | HobPtr.Raw = GetHobList ();\r | |
859 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
97b2c9b5 | 860 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r |
4c6486b9 | 861 | //\r |
862 | // this FILE has been dispatched, it will not be dispatched again.\r | |
863 | //\r | |
864 | return EFI_SUCCESS;\r | |
865 | }\r | |
866 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
867 | }\r | |
868 | \r | |
869 | //\r | |
870 | // Find FvImage in FvFile\r | |
871 | //\r | |
872 | Status = PeiFfsFindSectionData (\r | |
6c7a807a | 873 | PeiServices,\r |
4c6486b9 | 874 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r |
97b2c9b5 | 875 | ParentFvFileHandle,\r |
4c6486b9 | 876 | (VOID **)&FvImageHandle\r |
877 | );\r | |
878 | \r | |
879 | if (EFI_ERROR (Status)) {\r | |
880 | return Status;\r | |
881 | }\r | |
97b2c9b5 LG |
882 | \r |
883 | //\r | |
884 | // Collect Parent FvImage Info.\r | |
885 | //\r | |
886 | Status = PeiFfsGetVolumeInfo (ParentFvHandle, &ParentFvImageInfo);\r | |
887 | ASSERT_EFI_ERROR (Status); \r | |
888 | \r | |
4c6486b9 | 889 | //\r |
890 | // Collect FvImage Info.\r | |
891 | //\r | |
892 | Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo);\r | |
893 | ASSERT_EFI_ERROR (Status);\r | |
894 | \r | |
895 | //\r | |
6d9a0f28 | 896 | // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r |
4c6486b9 | 897 | //\r |
898 | FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
899 | if (FvAlignment < 8) {\r | |
900 | FvAlignment = 8;\r | |
901 | }\r | |
902 | \r | |
903 | //\r | |
904 | // Check FvImage\r | |
905 | //\r | |
906 | if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r | |
907 | FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);\r | |
908 | if (FvBuffer == NULL) {\r | |
909 | return EFI_OUT_OF_RESOURCES;\r | |
910 | }\r | |
911 | CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);\r | |
912 | //\r | |
913 | // Update FvImageInfo after reload FvImage to new aligned memory\r | |
914 | //\r | |
97b2c9b5 LG |
915 | Status = PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r |
916 | ASSERT_EFI_ERROR (Status);\r | |
4c6486b9 | 917 | }\r |
918 | \r | |
919 | //\r | |
920 | // Install FvPpi and Build FvHob\r | |
921 | //\r | |
187f1a5b | 922 | PeiServicesInstallFvInfoPpi (\r |
4c6486b9 | 923 | NULL,\r |
924 | FvImageInfo.FvStart,\r | |
925 | (UINT32) FvImageInfo.FvSize,\r | |
97b2c9b5 LG |
926 | &ParentFvImageInfo.FvName,\r |
927 | &(((EFI_FFS_FILE_HEADER*)ParentFvFileHandle)->Name)\r | |
4c6486b9 | 928 | );\r |
929 | \r | |
930 | //\r | |
931 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r | |
4c6486b9 | 932 | //\r |
223c22d8 LG |
933 | BuildFvHob (\r |
934 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
935 | FvImageInfo.FvSize\r | |
18fcd6a7 | 936 | );\r |
4c6486b9 | 937 | \r |
938 | //\r | |
939 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
940 | // encapsulated file again.\r | |
941 | //\r | |
942 | BuildFv2Hob (\r | |
943 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
944 | FvImageInfo.FvSize,\r | |
97b2c9b5 LG |
945 | &ParentFvImageInfo.FvName,\r |
946 | &(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name)\r | |
4c6486b9 | 947 | );\r |
948 | \r | |
949 | return EFI_SUCCESS;\r | |
950 | }\r | |
951 | \r | |
952 | \r |