]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | Pei Core Firmware File System service routines.\r |
3 | \r | |
1c738c8f | 4 | Copyright (c) 2006 - 2010, 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 |
3b428ade | 15 | #include "FwVol.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 | |
3b428ade | 23 | EFI_PEI_FIRMWARE_VOLUME_PPI mPeiFfs2FvPpi = {\r |
24 | PeiFfs2FvPpiProcessVolume,\r | |
25 | PeiFfs2FvPpiFindFileByType,\r | |
26 | PeiFfs2FvPpiFindFileByName,\r | |
27 | PeiFfs2FvPpiGetFileInfo,\r | |
28 | PeiFfs2FvPpiGetVolumeInfo,\r | |
29 | PeiFfs2FvPpiFindSectionByType\r | |
30 | };\r | |
31 | \r | |
32 | EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList = {\r | |
33 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
34 | &gEfiFirmwareFileSystem2Guid,\r | |
35 | &mPeiFfs2FvPpi\r | |
36 | };\r | |
37 | \r | |
b1f6a7c6 | 38 | /**\r |
ed299e3c | 39 | Returns the file state set by the highest zero bit in the State field\r |
192f6d4c | 40 | \r |
b1f6a7c6 | 41 | @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r |
42 | in the Attributes field.\r | |
43 | @param FfsHeader Pointer to FFS File Header.\r | |
192f6d4c | 44 | \r |
ed299e3c LG |
45 | @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit \r |
46 | in the header State field.\r | |
b1f6a7c6 | 47 | **/\r |
48 | EFI_FFS_FILE_STATE\r | |
49 | GetFileState(\r | |
50 | IN UINT8 ErasePolarity,\r | |
51 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
52 | )\r | |
192f6d4c | 53 | {\r |
54 | EFI_FFS_FILE_STATE FileState;\r | |
55 | EFI_FFS_FILE_STATE HighestBit;\r | |
56 | \r | |
57 | FileState = FfsHeader->State;\r | |
58 | \r | |
59 | if (ErasePolarity != 0) {\r | |
60 | FileState = (EFI_FFS_FILE_STATE)~FileState;\r | |
61 | }\r | |
ed299e3c LG |
62 | \r |
63 | //\r | |
64 | // Get file state set by its highest none zero bit.\r | |
65 | //\r | |
192f6d4c | 66 | HighestBit = 0x80;\r |
67 | while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r | |
68 | HighestBit >>= 1;\r | |
69 | }\r | |
70 | \r | |
71 | return HighestBit;\r | |
72 | } \r | |
73 | \r | |
b1f6a7c6 | 74 | /**\r |
75 | Calculates the checksum of the header of a file.\r | |
76 | \r | |
77 | @param FileHeader Pointer to FFS File Header.\r | |
78 | \r | |
79 | @return Checksum of the header.\r | |
b1f6a7c6 | 80 | Zero means the header is good.\r |
81 | Non-zero means the header is bad.\r | |
82 | **/\r | |
192f6d4c | 83 | UINT8\r |
84 | CalculateHeaderChecksum (\r | |
85 | IN EFI_FFS_FILE_HEADER *FileHeader\r | |
86 | )\r | |
192f6d4c | 87 | {\r |
ed299e3c | 88 | EFI_FFS_FILE_HEADER TestFileHeader;\r |
192f6d4c | 89 | \r |
ed299e3c | 90 | CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r |
192f6d4c | 91 | //\r |
ed299e3c | 92 | // Ingore State and File field in FFS header.\r |
192f6d4c | 93 | //\r |
ed299e3c LG |
94 | TestFileHeader.State = 0;\r |
95 | TestFileHeader.IntegrityCheck.Checksum.File = 0;\r | |
192f6d4c | 96 | \r |
ed299e3c | 97 | return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));\r |
192f6d4c | 98 | }\r |
99 | \r | |
b1f6a7c6 | 100 | /**\r |
3b428ade | 101 | Find FV handler according to FileHandle in that FV.\r |
b1f6a7c6 | 102 | \r |
103 | @param FileHandle Handle of file image\r | |
3b428ade | 104 | \r |
105 | @return Pointer to instance of PEI_CORE_FV_HANDLE.\r | |
b1f6a7c6 | 106 | **/\r |
3b428ade | 107 | PEI_CORE_FV_HANDLE*\r |
108 | FileHandleToVolume (\r | |
109 | IN EFI_PEI_FILE_HANDLE FileHandle\r | |
b0d803fe | 110 | )\r |
111 | {\r | |
112 | UINTN Index;\r | |
113 | PEI_CORE_INSTANCE *PrivateData;\r | |
114 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
115 | \r | |
116 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
3b428ade | 117 | \r |
b0d803fe | 118 | for (Index = 0; Index < PrivateData->FvCount; Index++) {\r |
119 | FwVolHeader = PrivateData->Fv[Index].FvHeader;\r | |
67a58d0f | 120 | if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \\r |
121 | ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r | |
3b428ade | 122 | return &PrivateData->Fv[Index];\r |
b0d803fe | 123 | }\r |
124 | }\r | |
3b428ade | 125 | return NULL;\r |
b0d803fe | 126 | }\r |
127 | \r | |
b1f6a7c6 | 128 | /**\r |
ed299e3c | 129 | Given the input file pointer, search for the first matching file in the\r |
b1f6a7c6 | 130 | FFS volume as defined by SearchType. The search starts from FileHeader inside\r |
131 | the Firmware Volume defined by FwVolHeader.\r | |
ed299e3c LG |
132 | If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r |
133 | If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r | |
134 | the first PEIM, or COMBINED PEIM or FV file type FFS file will return. \r | |
b1f6a7c6 | 135 | \r |
136 | @param FvHandle Pointer to the FV header of the volume to search\r | |
137 | @param FileName File name\r | |
138 | @param SearchType Filter to find only files of this type.\r | |
139 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
140 | @param FileHandle This parameter must point to a valid FFS volume.\r | |
141 | @param AprioriFile Pointer to AprioriFile image in this FV if has\r | |
b0d803fe | 142 | \r |
b1f6a7c6 | 143 | @return EFI_NOT_FOUND No files matching the search criteria were found\r |
144 | @retval EFI_SUCCESS Success to search given file\r | |
145 | \r | |
146 | **/\r | |
192f6d4c | 147 | EFI_STATUS\r |
3b428ade | 148 | FindFileEx (\r |
b0d803fe | 149 | IN CONST EFI_PEI_FV_HANDLE FvHandle,\r |
150 | IN CONST EFI_GUID *FileName, OPTIONAL\r | |
151 | IN EFI_FV_FILETYPE SearchType,\r | |
152 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle,\r | |
153 | IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL\r | |
192f6d4c | 154 | )\r |
192f6d4c | 155 | {\r |
b0d803fe | 156 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r |
157 | EFI_FFS_FILE_HEADER **FileHeader;\r | |
158 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r | |
b0d803fe | 159 | UINT32 FileLength;\r |
160 | UINT32 FileOccupiedSize;\r | |
161 | UINT32 FileOffset;\r | |
162 | UINT64 FvLength;\r | |
163 | UINT8 ErasePolarity;\r | |
164 | UINT8 FileState;\r | |
3b428ade | 165 | \r |
166 | //\r | |
167 | // Convert the handle of FV to FV header for memory-mapped firmware volume\r | |
168 | //\r | |
169 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvHandle;\r | |
b0d803fe | 170 | FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;\r |
192f6d4c | 171 | \r |
172 | FvLength = FwVolHeader->FvLength;\r | |
d976bf31 | 173 | if ((FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r |
192f6d4c | 174 | ErasePolarity = 1;\r |
175 | } else {\r | |
176 | ErasePolarity = 0;\r | |
177 | }\r | |
178 | \r | |
179 | //\r | |
b0d803fe | 180 | // If FileHeader is not specified (NULL) or FileName is not NULL,\r |
181 | // start with the first file in the firmware volume. Otherwise,\r | |
182 | // start from the FileHeader.\r | |
192f6d4c | 183 | //\r |
b0d803fe | 184 | if ((*FileHeader == NULL) || (FileName != NULL)) {\r |
192f6d4c | 185 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);\r |
186 | } else {\r | |
187 | //\r | |
188 | // Length is 24 bits wide so mask upper 8 bits\r | |
189 | // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r | |
190 | //\r | |
191 | FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;\r | |
b0d803fe | 192 | FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r |
192f6d4c | 193 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r |
194 | }\r | |
e98cd821 | 195 | \r |
192f6d4c | 196 | FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r |
197 | ASSERT (FileOffset <= 0xFFFFFFFF);\r | |
e98cd821 | 198 | \r |
b0d803fe | 199 | while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r |
192f6d4c | 200 | //\r |
201 | // Get FileState which is the highest bit of the State \r | |
202 | //\r | |
203 | FileState = GetFileState (ErasePolarity, FfsFileHeader);\r | |
192f6d4c | 204 | switch (FileState) {\r |
205 | \r | |
206 | case EFI_FILE_HEADER_INVALID:\r | |
40f26b8f | 207 | FileOffset += sizeof(EFI_FFS_FILE_HEADER);\r |
208 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));\r | |
192f6d4c | 209 | break;\r |
210 | \r | |
211 | case EFI_FILE_DATA_VALID:\r | |
212 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
b0d803fe | 213 | if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r |
192f6d4c | 214 | ASSERT (FALSE);\r |
e98cd821 | 215 | *FileHeader = NULL;\r |
192f6d4c | 216 | return EFI_NOT_FOUND;\r |
217 | }\r | |
b0d803fe | 218 | \r |
40f26b8f | 219 | FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r |
b0d803fe | 220 | FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r |
221 | \r | |
222 | if (FileName != NULL) {\r | |
223 | if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r | |
224 | *FileHeader = FfsFileHeader;\r | |
225 | return EFI_SUCCESS;\r | |
226 | }\r | |
227 | } else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {\r | |
228 | if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) || \r | |
288f9b38 LG |
229 | (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r |
230 | (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) { \r | |
b0d803fe | 231 | \r |
232 | *FileHeader = FfsFileHeader;\r | |
233 | return EFI_SUCCESS;\r | |
234 | } else if (AprioriFile != NULL) {\r | |
235 | if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {\r | |
236 | if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {\r | |
237 | *AprioriFile = FfsFileHeader;\r | |
238 | } \r | |
239 | } \r | |
240 | }\r | |
7e181f2f | 241 | } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && \r |
242 | (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { \r | |
b0d803fe | 243 | *FileHeader = FfsFileHeader;\r |
244 | return EFI_SUCCESS;\r | |
245 | }\r | |
246 | \r | |
40f26b8f | 247 | FileOffset += FileOccupiedSize; \r |
248 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 249 | break;\r |
250 | \r | |
251 | case EFI_FILE_DELETED:\r | |
40f26b8f | 252 | FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r |
253 | FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r | |
254 | FileOffset += FileOccupiedSize;\r | |
255 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 256 | break;\r |
257 | \r | |
258 | default:\r | |
e98cd821 | 259 | *FileHeader = NULL;\r |
192f6d4c | 260 | return EFI_NOT_FOUND;\r |
192f6d4c | 261 | } \r |
262 | }\r | |
e98cd821 LG |
263 | \r |
264 | *FileHeader = NULL;\r | |
192f6d4c | 265 | return EFI_NOT_FOUND; \r |
266 | }\r | |
267 | \r | |
b1f6a7c6 | 268 | /**\r |
b1f6a7c6 | 269 | Initialize PeiCore Fv List.\r |
270 | \r | |
b1f6a7c6 | 271 | @param PrivateData - Pointer to PEI_CORE_INSTANCE.\r |
272 | @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r | |
b1f6a7c6 | 273 | **/\r |
b0d803fe | 274 | VOID \r |
275 | PeiInitializeFv (\r | |
276 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
277 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r | |
278 | )\r | |
b0d803fe | 279 | {\r |
3b428ade | 280 | EFI_STATUS Status;\r |
281 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
282 | EFI_PEI_FV_HANDLE FvHandle;\r | |
283 | EFI_FIRMWARE_VOLUME_HEADER *BfvHeader;\r | |
284 | \r | |
b0d803fe | 285 | //\r |
3b428ade | 286 | // Install FV_PPI for FFS2 file system.\r |
b0d803fe | 287 | //\r |
3b428ade | 288 | PeiServicesInstallPpi (&mPeiFfs2FvPpiList);\r |
289 | \r | |
290 | BfvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;\r | |
291 | \r | |
292 | //\r | |
293 | // The FV_PPI in BFV's format should be installed.\r | |
294 | //\r | |
295 | Status = PeiServicesLocatePpi (\r | |
296 | &BfvHeader->FileSystemGuid,\r | |
297 | 0,\r | |
298 | NULL,\r | |
299 | (VOID**)&FvPpi\r | |
300 | );\r | |
301 | ASSERT_EFI_ERROR (Status);\r | |
302 | \r | |
303 | //\r | |
304 | // Get handle of BFV\r | |
305 | //\r | |
306 | FvPpi->ProcessVolume (\r | |
307 | FvPpi, \r | |
308 | SecCoreData->BootFirmwareVolumeBase,\r | |
309 | (UINTN)BfvHeader->FvLength,\r | |
310 | &FvHandle\r | |
311 | );\r | |
dc6f9b35 | 312 | \r |
313 | //\r | |
314 | // Update internal PEI_CORE_FV array.\r | |
315 | //\r | |
316 | PrivateData->Fv[PrivateData->FvCount].FvHeader = BfvHeader;\r | |
317 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
318 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
319 | DEBUG ((\r | |
320 | EFI_D_INFO, \r | |
321 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
322 | (UINT32) PrivateData->FvCount, \r | |
323 | (VOID *) BfvHeader, \r | |
324 | BfvHeader->FvLength,\r | |
325 | FvHandle\r | |
326 | )); \r | |
327 | PrivateData->FvCount ++;\r | |
328 | \r | |
b0d803fe | 329 | //\r |
330 | // Post a call-back for the FvInfoPPI services to expose\r | |
331 | // additional Fvs to PeiCore.\r | |
332 | //\r | |
333 | Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);\r | |
334 | ASSERT_EFI_ERROR (Status);\r | |
335 | \r | |
336 | }\r | |
3b428ade | 337 | \r |
b1f6a7c6 | 338 | /**\r |
339 | Process Firmware Volum Information once FvInfoPPI install.\r | |
ed299e3c LG |
340 | The FV Info will be registered into PeiCore private data structure.\r |
341 | And search the inside FV image, if found, the new FV INFO PPI will be installed.\r | |
b1f6a7c6 | 342 | \r |
ed299e3c | 343 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
731bd38e | 344 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
345 | @param Ppi Address of the PPI that was installed.\r | |
b1f6a7c6 | 346 | \r |
ed299e3c | 347 | @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r |
6a1ae84a | 348 | @return if not EFI_SUCESS, fail to verify FV.\r |
b1f6a7c6 | 349 | \r |
350 | **/\r | |
b0d803fe | 351 | EFI_STATUS\r |
352 | EFIAPI\r | |
353 | FirmwareVolmeInfoPpiNotifyCallback (\r | |
354 | IN EFI_PEI_SERVICES **PeiServices,\r | |
355 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
356 | IN VOID *Ppi\r | |
357 | )\r | |
b0d803fe | 358 | {\r |
3b428ade | 359 | EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfoPpi;\r |
360 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
b0d803fe | 361 | PEI_CORE_INSTANCE *PrivateData;\r |
288f9b38 | 362 | EFI_STATUS Status;\r |
3b428ade | 363 | EFI_PEI_FV_HANDLE FvHandle;\r |
364 | UINTN FvIndex;\r | |
dc6f9b35 | 365 | EFI_PEI_FILE_HANDLE FileHandle;\r |
366 | VOID *DepexData;\r | |
b0d803fe | 367 | \r |
288f9b38 LG |
368 | Status = EFI_SUCCESS;\r |
369 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
b0d803fe | 370 | \r |
177aabe6 | 371 | if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
97b2c9b5 LG |
372 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r |
373 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r | |
b0d803fe | 374 | ASSERT (FALSE);\r |
375 | }\r | |
376 | \r | |
3b428ade | 377 | FvInfoPpi = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;\r |
b0d803fe | 378 | \r |
97b2c9b5 | 379 | //\r |
3b428ade | 380 | // Locate the corresponding FV_PPI according to founded FV's format guid\r |
97b2c9b5 | 381 | //\r |
3b428ade | 382 | Status = PeiServicesLocatePpi (\r |
383 | &FvInfoPpi->FvFormat, \r | |
384 | 0, \r | |
385 | NULL,\r | |
386 | (VOID**)&FvPpi\r | |
387 | );\r | |
388 | if (!EFI_ERROR (Status)) {\r | |
389 | //\r | |
390 | // Process new found FV and get FV handle.\r | |
391 | //\r | |
392 | Status = FvPpi->ProcessVolume (FvPpi, FvInfoPpi->FvInfo, FvInfoPpi->FvInfoSize, &FvHandle);\r | |
393 | if (EFI_ERROR (Status)) {\r | |
dc6f9b35 | 394 | DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!\n"));\r |
6a1ae84a | 395 | return Status;\r |
396 | }\r | |
dc6f9b35 | 397 | \r |
398 | //\r | |
399 | // Check whether the FV has already been processed.\r | |
400 | //\r | |
401 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
402 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
403 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfoPpi->FvInfo));\r | |
404 | return EFI_SUCCESS;\r | |
405 | }\r | |
406 | }\r | |
407 | \r | |
408 | //\r | |
409 | // Update internal PEI_CORE_FV array.\r | |
410 | //\r | |
411 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfoPpi->FvInfo;\r | |
412 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
413 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
414 | DEBUG ((\r | |
415 | EFI_D_INFO, \r | |
416 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
417 | (UINT32) PrivateData->FvCount, \r | |
418 | (VOID *) FvInfoPpi->FvInfo, \r | |
419 | FvInfoPpi->FvInfoSize,\r | |
420 | FvHandle\r | |
421 | )); \r | |
422 | PrivateData->FvCount ++;\r | |
423 | \r | |
424 | //\r | |
425 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r | |
426 | //\r | |
427 | FileHandle = NULL;\r | |
428 | do {\r | |
429 | Status = FvPpi->FindFileByType (\r | |
430 | FvPpi,\r | |
431 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
432 | FvHandle,\r | |
433 | &FileHandle\r | |
434 | );\r | |
435 | if (!EFI_ERROR (Status)) {\r | |
436 | Status = FvPpi->FindSectionByType (\r | |
437 | FvPpi,\r | |
438 | EFI_SECTION_PEI_DEPEX,\r | |
439 | FileHandle,\r | |
440 | (VOID**)&DepexData\r | |
441 | );\r | |
442 | if (!EFI_ERROR (Status)) {\r | |
443 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
444 | //\r | |
445 | // Dependency is not satisfied.\r | |
446 | //\r | |
447 | continue;\r | |
448 | }\r | |
449 | }\r | |
450 | \r | |
451 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r | |
452 | ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r | |
453 | }\r | |
454 | } while (FileHandle != NULL);\r | |
3b428ade | 455 | } else {\r |
456 | DEBUG ((EFI_D_ERROR, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfoPpi->FvInfo));\r | |
6a1ae84a | 457 | \r |
f3358329 | 458 | AddUnknownFormatFvInfo (PrivateData, &FvInfoPpi->FvFormat, FvInfoPpi->FvInfo, FvInfoPpi->FvInfoSize);\r |
288f9b38 | 459 | }\r |
3b428ade | 460 | \r |
b0d803fe | 461 | return EFI_SUCCESS;\r |
462 | }\r | |
463 | \r | |
b1f6a7c6 | 464 | /**\r |
ed299e3c LG |
465 | Go through the file to search SectionType section. \r |
466 | Search within encapsulation sections (compression and GUIDed) recursively, \r | |
467 | until the match section is found.\r | |
468 | \r | |
3b428ade | 469 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
470 | @param SectionType Filter to find only section of this type.\r | |
471 | @param Section From where to search.\r | |
472 | @param SectionSize The file size to search.\r | |
473 | @param OutputBuffer A pointer to the discovered section, if successful.\r | |
ed299e3c | 474 | NULL if section not found\r |
b1f6a7c6 | 475 | \r |
ed299e3c LG |
476 | @return EFI_NOT_FOUND The match section is not found.\r |
477 | @return EFI_SUCCESS The match section is found.\r | |
b1f6a7c6 | 478 | \r |
479 | **/\r | |
b0d803fe | 480 | EFI_STATUS\r |
3b428ade | 481 | ProcessSection (\r |
b0d803fe | 482 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
483 | IN EFI_SECTION_TYPE SectionType,\r | |
484 | IN EFI_COMMON_SECTION_HEADER *Section,\r | |
485 | IN UINTN SectionSize,\r | |
288f9b38 | 486 | OUT VOID **OutputBuffer\r |
b0d803fe | 487 | )\r |
b0d803fe | 488 | {\r |
489 | EFI_STATUS Status;\r | |
490 | UINT32 SectionLength;\r | |
491 | UINT32 ParsedLength;\r | |
b0d803fe | 492 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r |
b0d803fe | 493 | EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r |
494 | VOID *PpiOutput;\r | |
495 | UINTN PpiOutputSize;\r | |
288f9b38 LG |
496 | UINTN Index;\r |
497 | UINT32 Authentication;\r | |
498 | PEI_CORE_INSTANCE *PrivateData;\r | |
b0d803fe | 499 | \r |
288f9b38 | 500 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
b0d803fe | 501 | *OutputBuffer = NULL;\r |
288f9b38 LG |
502 | ParsedLength = 0;\r |
503 | Index = 0;\r | |
504 | Status = EFI_NOT_FOUND;\r | |
505 | PpiOutput = NULL;\r | |
506 | PpiOutputSize = 0;\r | |
b0d803fe | 507 | while (ParsedLength < SectionSize) {\r |
508 | if (Section->Type == SectionType) {\r | |
509 | *OutputBuffer = (VOID *)(Section + 1);\r | |
510 | return EFI_SUCCESS;\r | |
288f9b38 LG |
511 | } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r |
512 | //\r | |
513 | // Check the encapsulated section is extracted into the cache data.\r | |
514 | //\r | |
515 | for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r | |
516 | if (Section == PrivateData->CacheSection.Section[Index]) {\r | |
517 | PpiOutput = PrivateData->CacheSection.SectionData[Index];\r | |
518 | PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r | |
519 | //\r | |
520 | // Search section directly from the cache data.\r | |
521 | //\r | |
3b428ade | 522 | return ProcessSection (\r |
523 | PeiServices,\r | |
524 | SectionType, \r | |
525 | PpiOutput, \r | |
526 | PpiOutputSize, \r | |
527 | OutputBuffer \r | |
528 | );\r | |
b0d803fe | 529 | }\r |
530 | }\r | |
288f9b38 LG |
531 | \r |
532 | Status = EFI_NOT_FOUND;\r | |
533 | if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r | |
534 | Status = PeiServicesLocatePpi (\r | |
535 | &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid, \r | |
536 | 0, \r | |
537 | NULL, \r | |
538 | (VOID **) &GuidSectionPpi\r | |
539 | );\r | |
b0d803fe | 540 | if (!EFI_ERROR (Status)) {\r |
288f9b38 | 541 | Status = GuidSectionPpi->ExtractSection (\r |
3b428ade | 542 | GuidSectionPpi,\r |
543 | Section,\r | |
544 | &PpiOutput,\r | |
545 | &PpiOutputSize,\r | |
546 | &Authentication\r | |
547 | );\r | |
288f9b38 LG |
548 | }\r |
549 | } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r | |
550 | Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r | |
551 | if (!EFI_ERROR (Status)) {\r | |
552 | Status = DecompressPpi->Decompress (\r | |
553 | DecompressPpi,\r | |
554 | (CONST EFI_COMPRESSION_SECTION*) Section,\r | |
555 | &PpiOutput,\r | |
556 | &PpiOutputSize\r | |
557 | );\r | |
b0d803fe | 558 | }\r |
559 | }\r | |
288f9b38 LG |
560 | \r |
561 | if (!EFI_ERROR (Status)) {\r | |
562 | //\r | |
563 | // Update cache section data.\r | |
564 | //\r | |
565 | if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r | |
566 | PrivateData->CacheSection.AllSectionCount ++;\r | |
567 | }\r | |
568 | PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r | |
569 | PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r | |
570 | PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r | |
571 | PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r | |
572 | \r | |
3b428ade | 573 | return ProcessSection (\r |
574 | PeiServices,\r | |
575 | SectionType, \r | |
576 | PpiOutput, \r | |
577 | PpiOutputSize, \r | |
578 | OutputBuffer \r | |
579 | );\r | |
288f9b38 | 580 | }\r |
b0d803fe | 581 | }\r |
582 | \r | |
583 | //\r | |
584 | // Size is 24 bits wide so mask upper 8 bits. \r | |
585 | // SectionLength is adjusted it is 4 byte aligned.\r | |
586 | // Go to the next section\r | |
587 | //\r | |
588 | SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r | |
589 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
590 | ASSERT (SectionLength != 0);\r | |
591 | ParsedLength += SectionLength;\r | |
592 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
593 | }\r | |
594 | \r | |
595 | return EFI_NOT_FOUND;\r | |
596 | }\r | |
597 | \r | |
192f6d4c | 598 | \r |
b1f6a7c6 | 599 | /**\r |
3b428ade | 600 | Searches for the next matching section within the specified file.\r |
b1f6a7c6 | 601 | \r |
ed299e3c | 602 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 603 | @param SectionType Filter to find only sections of this type.\r |
604 | @param FileHandle Pointer to the current file to search.\r | |
ed299e3c | 605 | @param SectionData A pointer to the discovered section, if successful.\r |
b1f6a7c6 | 606 | NULL if section not found\r |
607 | \r | |
3b428ade | 608 | @retval EFI_NOT_FOUND The section was not found.\r |
609 | @retval EFI_SUCCESS The section was found.\r | |
b1f6a7c6 | 610 | \r |
611 | **/\r | |
192f6d4c | 612 | EFI_STATUS\r |
613 | EFIAPI\r | |
614 | PeiFfsFindSectionData (\r | |
3b428ade | 615 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 616 | IN EFI_SECTION_TYPE SectionType,\r |
0c2b5da8 | 617 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
3b428ade | 618 | OUT VOID **SectionData\r |
192f6d4c | 619 | )\r |
192f6d4c | 620 | {\r |
3b428ade | 621 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
622 | \r | |
623 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
624 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
625 | return EFI_NOT_FOUND;\r | |
626 | }\r | |
627 | \r | |
628 | return CoreFvHandle->FvPpi->FindSectionByType (CoreFvHandle->FvPpi, SectionType, FileHandle, SectionData);\r | |
192f6d4c | 629 | }\r |
630 | \r | |
b1f6a7c6 | 631 | /**\r |
3b428ade | 632 | Searches for the next matching file in the firmware volume.\r |
b1f6a7c6 | 633 | \r |
d73d93c3 | 634 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 635 | @param SearchType Filter to find only files of this type.\r |
636 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
aa75dfec | 637 | @param FvHandle Handle of firmware volume in which to search.\r |
3b428ade | 638 | @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start\r |
639 | at the beginning of the firmware volume. On exit, points the file handle of the next file\r | |
640 | in the volume or NULL if there are no more files.\r | |
641 | \r | |
642 | @retval EFI_NOT_FOUND The file was not found.\r | |
643 | @retval EFI_NOT_FOUND The header checksum was not zero.\r | |
644 | @retval EFI_SUCCESS The file was found.\r | |
b1f6a7c6 | 645 | \r |
646 | **/\r | |
192f6d4c | 647 | EFI_STATUS\r |
648 | EFIAPI\r | |
649 | PeiFfsFindNextFile (\r | |
0c2b5da8 | 650 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
651 | IN UINT8 SearchType,\r | |
3b428ade | 652 | IN EFI_PEI_FV_HANDLE FvHandle,\r |
0c2b5da8 | 653 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r |
192f6d4c | 654 | )\r |
192f6d4c | 655 | {\r |
3b428ade | 656 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
657 | \r | |
658 | CoreFvHandle = FvHandleToCoreHandle (FvHandle);\r | |
659 | \r | |
2f016ba8 | 660 | //\r |
661 | // To make backward compatiblity, if can not find corresponding the handle of FV\r | |
662 | // then treat FV as build-in FFS2 format and memory mapped FV that FV handle is pointed\r | |
663 | // to the address of first byte of FV.\r | |
664 | //\r | |
665 | if ((CoreFvHandle == NULL) && FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
666 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r | |
667 | } \r | |
668 | \r | |
3b428ade | 669 | if ((CoreFvHandle == NULL) || CoreFvHandle->FvPpi == NULL) {\r |
670 | return EFI_NOT_FOUND;\r | |
671 | }\r | |
672 | \r | |
673 | return CoreFvHandle->FvPpi->FindFileByType (CoreFvHandle->FvPpi, SearchType, FvHandle, FileHandle);\r | |
192f6d4c | 674 | }\r |
675 | \r | |
b0d803fe | 676 | \r |
b1f6a7c6 | 677 | /**\r |
ed299e3c | 678 | Search the firmware volumes by index\r |
b1f6a7c6 | 679 | \r |
ed299e3c | 680 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
3b428ade | 681 | @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware\r |
682 | Volume (BFV).\r | |
683 | @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.\r | |
b1f6a7c6 | 684 | \r |
3b428ade | 685 | @retval EFI_INVALID_PARAMETER VolumeHandle is NULL\r |
686 | @retval EFI_NOT_FOUND The volume was not found.\r | |
687 | @retval EFI_SUCCESS The volume was found.\r | |
b1f6a7c6 | 688 | \r |
689 | **/\r | |
192f6d4c | 690 | EFI_STATUS \r |
691 | EFIAPI\r | |
3b428ade | 692 | PeiFfsFindNextVolume (\r |
2a00326e | 693 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 694 | IN UINTN Instance,\r |
0c2b5da8 | 695 | IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r |
192f6d4c | 696 | )\r |
192f6d4c | 697 | {\r |
3b428ade | 698 | PEI_CORE_INSTANCE *Private;\r |
699 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
700 | \r | |
3e4c5b49 | 701 | if (VolumeHandle == NULL) {\r |
702 | return EFI_INVALID_PARAMETER;\r | |
703 | }\r | |
704 | \r | |
b0d803fe | 705 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
2a00326e | 706 | \r |
3b428ade | 707 | CoreFvHandle = FindNextCoreFvHandle (Private, Instance);\r |
708 | if (CoreFvHandle == NULL) {\r | |
709 | *VolumeHandle = NULL;\r | |
710 | return EFI_NOT_FOUND;\r | |
2a00326e | 711 | }\r |
3b428ade | 712 | \r |
713 | *VolumeHandle = CoreFvHandle->FvHandle;\r | |
714 | \r | |
b0d803fe | 715 | return EFI_SUCCESS;\r |
716 | }\r | |
192f6d4c | 717 | \r |
192f6d4c | 718 | \r |
b1f6a7c6 | 719 | /**\r |
ed299e3c | 720 | Find a file within a volume by its name.\r |
b1f6a7c6 | 721 | \r |
ed299e3c LG |
722 | @param FileName A pointer to the name of the file to find within the firmware volume.\r |
723 | @param VolumeHandle The firmware volume to search\r | |
724 | @param FileHandle Upon exit, points to the found file's handle \r | |
725 | or NULL if it could not be found.\r | |
b1f6a7c6 | 726 | \r |
ed299e3c LG |
727 | @retval EFI_SUCCESS File was found.\r |
728 | @retval EFI_NOT_FOUND File was not found.\r | |
729 | @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r | |
b1f6a7c6 | 730 | \r |
b1f6a7c6 | 731 | **/\r |
b0d803fe | 732 | EFI_STATUS\r |
733 | EFIAPI \r | |
734 | PeiFfsFindFileByName (\r | |
735 | IN CONST EFI_GUID *FileName,\r | |
736 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
737 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
738 | )\r | |
b0d803fe | 739 | {\r |
3b428ade | 740 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
741 | \r | |
b0d803fe | 742 | if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r |
192f6d4c | 743 | return EFI_INVALID_PARAMETER;\r |
744 | }\r | |
3b428ade | 745 | \r |
746 | CoreFvHandle = FvHandleToCoreHandle (VolumeHandle);\r | |
747 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
748 | return EFI_NOT_FOUND;\r | |
b0d803fe | 749 | }\r |
3b428ade | 750 | \r |
751 | return CoreFvHandle->FvPpi->FindFileByName (CoreFvHandle->FvPpi, FileName, &VolumeHandle, FileHandle);\r | |
b0d803fe | 752 | }\r |
753 | \r | |
b1f6a7c6 | 754 | /**\r |
b1f6a7c6 | 755 | Returns information about a specific file.\r |
756 | \r | |
3b428ade | 757 | @param FileHandle Handle of the file.\r |
758 | @param FileInfo Upon exit, points to the file’s information.\r | |
b1f6a7c6 | 759 | \r |
3b428ade | 760 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r |
761 | @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r | |
762 | @retval EFI_SUCCESS File information returned.\r | |
b1f6a7c6 | 763 | \r |
764 | **/\r | |
b0d803fe | 765 | EFI_STATUS\r |
766 | EFIAPI \r | |
767 | PeiFfsGetFileInfo (\r | |
768 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
769 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
770 | )\r | |
b0d803fe | 771 | {\r |
3b428ade | 772 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
773 | \r | |
b0d803fe | 774 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
775 | return EFI_INVALID_PARAMETER;\r | |
776 | }\r | |
777 | \r | |
778 | //\r | |
779 | // Retrieve the FirmwareVolume which the file resides in.\r | |
780 | //\r | |
3b428ade | 781 | CoreFvHandle = FileHandleToVolume (FileHandle);\r |
782 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
b0d803fe | 783 | return EFI_INVALID_PARAMETER;\r |
784 | }\r | |
785 | \r | |
3b428ade | 786 | return CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r |
b0d803fe | 787 | }\r |
788 | \r | |
789 | \r | |
b1f6a7c6 | 790 | /**\r |
3b428ade | 791 | Returns information about the specified volume.\r |
b1f6a7c6 | 792 | \r |
5a9403b8 | 793 | This function returns information about a specific firmware\r |
794 | volume, including its name, type, attributes, starting address\r | |
795 | and size.\r | |
796 | \r | |
797 | @param VolumeHandle Handle of the volume.\r | |
798 | @param VolumeInfo Upon exit, points to the volume's information.\r | |
799 | \r | |
800 | @retval EFI_SUCCESS Volume information returned.\r | |
801 | @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.\r | |
802 | @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.\r | |
803 | @retval EFI_SUCCESS Information successfully returned.\r | |
804 | @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.\r | |
b1f6a7c6 | 805 | \r |
b1f6a7c6 | 806 | **/\r |
b0d803fe | 807 | EFI_STATUS\r |
808 | EFIAPI \r | |
809 | PeiFfsGetVolumeInfo (\r | |
810 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
811 | OUT EFI_FV_INFO *VolumeInfo\r | |
812 | )\r | |
b0d803fe | 813 | {\r |
3b428ade | 814 | PEI_CORE_FV_HANDLE *CoreHandle;\r |
815 | \r | |
8fdcc412 | 816 | if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) {\r |
b0d803fe | 817 | return EFI_INVALID_PARAMETER;\r |
192f6d4c | 818 | }\r |
288f9b38 | 819 | \r |
3b428ade | 820 | CoreHandle = FvHandleToCoreHandle (VolumeHandle);\r |
821 | \r | |
822 | if ((CoreHandle == NULL) || (CoreHandle->FvPpi == NULL)) {\r | |
288f9b38 LG |
823 | return EFI_INVALID_PARAMETER;\r |
824 | }\r | |
3b428ade | 825 | \r |
826 | return CoreHandle->FvPpi->GetVolumeInfo (CoreHandle->FvPpi, VolumeHandle, VolumeInfo);\r | |
192f6d4c | 827 | }\r |
b0d803fe | 828 | \r |
4c6486b9 | 829 | /**\r |
830 | Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r | |
831 | \r | |
3b428ade | 832 | @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r |
97b2c9b5 | 833 | @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r |
4c6486b9 | 834 | \r |
835 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
836 | @retval EFI_SUCCESS Successfully to process it.\r | |
837 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
838 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r | |
839 | \r | |
840 | **/\r | |
841 | EFI_STATUS\r | |
842 | ProcessFvFile (\r | |
3b428ade | 843 | IN PEI_CORE_FV_HANDLE *ParentFvCoreHandle,\r |
844 | IN EFI_PEI_FILE_HANDLE ParentFvFileHandle\r | |
4c6486b9 | 845 | )\r |
846 | {\r | |
3b428ade | 847 | EFI_STATUS Status;\r |
848 | EFI_FV_INFO ParentFvImageInfo;\r | |
849 | UINT32 FvAlignment;\r | |
850 | VOID *NewFvBuffer;\r | |
851 | EFI_PEI_HOB_POINTERS HobPtr;\r | |
852 | EFI_PEI_FIRMWARE_VOLUME_PPI *ParentFvPpi;\r | |
853 | EFI_PEI_FV_HANDLE ParentFvHandle;\r | |
854 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r | |
855 | EFI_FV_FILE_INFO FileInfo;\r | |
856 | \r | |
4c6486b9 | 857 | //\r |
858 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r | |
859 | // been extracted.\r | |
860 | //\r | |
861 | HobPtr.Raw = GetHobList ();\r | |
862 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
97b2c9b5 | 863 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r |
4c6486b9 | 864 | //\r |
865 | // this FILE has been dispatched, it will not be dispatched again.\r | |
866 | //\r | |
3b428ade | 867 | DEBUG ((EFI_D_INFO, "FV file %p has been dispatched!\r\n", ParentFvFileHandle));\r |
4c6486b9 | 868 | return EFI_SUCCESS;\r |
869 | }\r | |
870 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
871 | }\r | |
872 | \r | |
3b428ade | 873 | ParentFvHandle = ParentFvCoreHandle->FvHandle;\r |
874 | ParentFvPpi = ParentFvCoreHandle->FvPpi;\r | |
875 | \r | |
4c6486b9 | 876 | //\r |
877 | // Find FvImage in FvFile\r | |
878 | //\r | |
3b428ade | 879 | Status = ParentFvPpi->FindSectionByType (\r |
880 | ParentFvPpi,\r | |
881 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
882 | ParentFvFileHandle,\r | |
883 | (VOID **)&FvHeader\r | |
884 | );\r | |
885 | \r | |
4c6486b9 | 886 | if (EFI_ERROR (Status)) {\r |
887 | return Status;\r | |
888 | }\r | |
97b2c9b5 LG |
889 | \r |
890 | //\r | |
3b428ade | 891 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r |
4c6486b9 | 892 | //\r |
3b428ade | 893 | FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r |
4c6486b9 | 894 | if (FvAlignment < 8) {\r |
895 | FvAlignment = 8;\r | |
896 | }\r | |
897 | \r | |
898 | //\r | |
899 | // Check FvImage\r | |
900 | //\r | |
3b428ade | 901 | if ((UINTN) FvHeader % FvAlignment != 0) {\r |
902 | NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvHeader->FvLength), FvAlignment);\r | |
903 | if (NewFvBuffer == NULL) {\r | |
4c6486b9 | 904 | return EFI_OUT_OF_RESOURCES;\r |
905 | }\r | |
3b428ade | 906 | CopyMem (NewFvBuffer, FvHeader, (UINTN) FvHeader->FvLength);\r |
907 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r | |
4c6486b9 | 908 | }\r |
3b428ade | 909 | \r |
910 | Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r | |
911 | ASSERT_EFI_ERROR (Status);\r | |
912 | \r | |
913 | Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r | |
914 | ASSERT_EFI_ERROR (Status);\r | |
915 | \r | |
4c6486b9 | 916 | //\r |
917 | // Install FvPpi and Build FvHob\r | |
918 | //\r | |
187f1a5b | 919 | PeiServicesInstallFvInfoPpi (\r |
3b428ade | 920 | &FvHeader->FileSystemGuid,\r |
921 | (VOID**) FvHeader,\r | |
922 | (UINT32) FvHeader->FvLength,\r | |
97b2c9b5 | 923 | &ParentFvImageInfo.FvName,\r |
3b428ade | 924 | &FileInfo.FileName\r |
4c6486b9 | 925 | );\r |
926 | \r | |
927 | //\r | |
928 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r | |
4c6486b9 | 929 | //\r |
223c22d8 | 930 | BuildFvHob (\r |
3b428ade | 931 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r |
932 | FvHeader->FvLength\r | |
18fcd6a7 | 933 | );\r |
4c6486b9 | 934 | \r |
935 | //\r | |
936 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
937 | // encapsulated file again.\r | |
938 | //\r | |
939 | BuildFv2Hob (\r | |
3b428ade | 940 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r |
941 | FvHeader->FvLength,\r | |
97b2c9b5 | 942 | &ParentFvImageInfo.FvName,\r |
3b428ade | 943 | &FileInfo.FileName\r |
4c6486b9 | 944 | );\r |
945 | \r | |
946 | return EFI_SUCCESS;\r | |
947 | }\r | |
948 | \r | |
3b428ade | 949 | /**\r |
950 | Process a firmware volume and create a volume handle.\r | |
951 | \r | |
952 | Create a volume handle from the information in the buffer. For\r | |
953 | memory-mapped firmware volumes, Buffer and BufferSize refer to\r | |
954 | the start of the firmware volume and the firmware volume size.\r | |
955 | For non memory-mapped firmware volumes, this points to a\r | |
956 | buffer which contains the necessary information for creating\r | |
957 | the firmware volume handle. Normally, these values are derived\r | |
958 | from the EFI_FIRMWARE_VOLUME_INFO_PPI.\r | |
959 | \r | |
960 | \r | |
961 | @param This Points to this instance of the\r | |
962 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
963 | @param Buffer Points to the start of the buffer.\r | |
964 | @param BufferSize Size of the buffer.\r | |
965 | @param FvHandle Points to the returned firmware volume\r | |
966 | handle. The firmware volume handle must\r | |
967 | be unique within the system. \r | |
968 | \r | |
969 | @retval EFI_SUCCESS Firmware volume handle created.\r | |
970 | @retval EFI_VOLUME_CORRUPTED Volume was corrupt.\r | |
971 | \r | |
972 | **/\r | |
973 | EFI_STATUS\r | |
974 | EFIAPI\r | |
975 | PeiFfs2FvPpiProcessVolume (\r | |
976 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
977 | IN VOID *Buffer,\r | |
978 | IN UINTN BufferSize,\r | |
979 | OUT EFI_PEI_FV_HANDLE *FvHandle\r | |
980 | )\r | |
981 | {\r | |
982 | EFI_STATUS Status;\r | |
3b428ade | 983 | \r |
dc6f9b35 | 984 | ASSERT (FvHandle != NULL);\r |
985 | \r | |
986 | if (Buffer == NULL) {\r | |
987 | return EFI_VOLUME_CORRUPTED;\r | |
988 | }\r | |
3b428ade | 989 | \r |
990 | //\r | |
991 | // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2 support memory-mapped\r | |
992 | // FV image and the handle is pointed to Fv image's buffer.\r | |
993 | //\r | |
994 | *FvHandle = (EFI_PEI_FV_HANDLE) Buffer;\r | |
995 | \r | |
996 | //\r | |
997 | // Do verify for given FV buffer.\r | |
998 | //\r | |
999 | Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*) Buffer);\r | |
1000 | if (EFI_ERROR(Status)) {\r | |
1001 | DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", Buffer));\r | |
1002 | return EFI_VOLUME_CORRUPTED;\r | |
1003 | }\r | |
1004 | \r | |
3b428ade | 1005 | return EFI_SUCCESS;\r |
1006 | } \r | |
1007 | \r | |
1008 | /**\r | |
1009 | Finds the next file of the specified type.\r | |
1010 | \r | |
1011 | This service enables PEI modules to discover additional firmware files. \r | |
1012 | The FileHandle must be unique within the system.\r | |
1013 | \r | |
1014 | @param This Points to this instance of the\r | |
1015 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1016 | @param SearchType A filter to find only files of this type. Type\r | |
1017 | EFI_FV_FILETYPE_ALL causes no filtering to be\r | |
1018 | done.\r | |
1019 | @param FvHandle Handle of firmware volume in which to\r | |
1020 | search.\r | |
1021 | @param FileHandle Points to the current handle from which to\r | |
1022 | begin searching or NULL to start at the\r | |
1023 | beginning of the firmware volume. Updated\r | |
1024 | upon return to reflect the file found.\r | |
1025 | \r | |
1026 | @retval EFI_SUCCESS The file was found.\r | |
1027 | @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.\r | |
1028 | \r | |
1029 | **/\r | |
1030 | EFI_STATUS\r | |
1031 | EFIAPI\r | |
1032 | PeiFfs2FvPpiFindFileByType (\r | |
1033 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
1034 | IN EFI_FV_FILETYPE SearchType,\r | |
1035 | IN EFI_PEI_FV_HANDLE FvHandle,\r | |
1036 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
1037 | )\r | |
1038 | { \r | |
1039 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r | |
1040 | }\r | |
1041 | \r | |
1042 | /**\r | |
1043 | Find a file within a volume by its name. \r | |
1044 | \r | |
1045 | This service searches for files with a specific name, within\r | |
1046 | either the specified firmware volume or all firmware volumes.\r | |
1047 | \r | |
1048 | @param This Points to this instance of the\r | |
1049 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1050 | @param FileName A pointer to the name of the file to find\r | |
1051 | within the firmware volume.\r | |
1052 | @param FvHandle Upon entry, the pointer to the firmware\r | |
1053 | volume to search or NULL if all firmware\r | |
1054 | volumes should be searched. Upon exit, the\r | |
1055 | actual firmware volume in which the file was\r | |
1056 | found.\r | |
1057 | @param FileHandle Upon exit, points to the found file's\r | |
1058 | handle or NULL if it could not be found.\r | |
1059 | \r | |
1060 | @retval EFI_SUCCESS File was found.\r | |
1061 | @retval EFI_NOT_FOUND File was not found.\r | |
1062 | @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or\r | |
1063 | FileName was NULL.\r | |
1064 | \r | |
1065 | \r | |
1066 | **/\r | |
1067 | EFI_STATUS\r | |
1068 | EFIAPI\r | |
1069 | PeiFfs2FvPpiFindFileByName (\r | |
1070 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
1071 | IN CONST EFI_GUID *FileName,\r | |
1072 | IN EFI_PEI_FV_HANDLE *FvHandle,\r | |
1073 | OUT EFI_PEI_FILE_HANDLE *FileHandle \r | |
1074 | )\r | |
1075 | {\r | |
1076 | EFI_STATUS Status;\r | |
1077 | PEI_CORE_INSTANCE *PrivateData;\r | |
1078 | UINTN Index;\r | |
1079 | \r | |
1080 | if ((FvHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r | |
1081 | return EFI_INVALID_PARAMETER;\r | |
1082 | }\r | |
1083 | \r | |
1084 | if (*FvHandle != NULL) {\r | |
1085 | Status = FindFileEx (*FvHandle, FileName, 0, FileHandle, NULL);\r | |
1086 | if (Status == EFI_NOT_FOUND) {\r | |
1087 | *FileHandle = NULL;\r | |
1088 | }\r | |
1089 | } else { \r | |
1090 | //\r | |
1091 | // If *FvHandle = NULL, so search all FV for given filename\r | |
1092 | //\r | |
1093 | Status = EFI_NOT_FOUND;\r | |
1094 | \r | |
1095 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());\r | |
1096 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r | |
1097 | //\r | |
1098 | // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.\r | |
1099 | //\r | |
1100 | if (PrivateData->Fv[Index].FvPpi != NULL) {\r | |
1101 | Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL);\r | |
1102 | if (!EFI_ERROR (Status)) {\r | |
1103 | *FvHandle = PrivateData->Fv[Index].FvHandle;\r | |
1c738c8f | 1104 | break;\r |
3b428ade | 1105 | }\r |
1106 | }\r | |
1107 | }\r | |
1108 | }\r | |
1109 | \r | |
1110 | return Status; \r | |
1111 | } \r | |
1112 | \r | |
1113 | /**\r | |
1114 | Returns information about a specific file.\r | |
1115 | \r | |
1116 | This function returns information about a specific\r | |
1117 | file, including its file name, type, attributes, starting\r | |
1118 | address and size. \r | |
1119 | \r | |
1120 | @param This Points to this instance of the\r | |
1121 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1122 | @param FileHandle Handle of the file.\r | |
1123 | @param FileInfo Upon exit, points to the file's\r | |
1124 | information.\r | |
1125 | \r | |
1126 | @retval EFI_SUCCESS File information returned.\r | |
1127 | @retval EFI_INVALID_PARAMETER If FileHandle does not\r | |
1128 | represent a valid file.\r | |
1129 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1130 | \r | |
1131 | **/ \r | |
1132 | EFI_STATUS\r | |
1133 | EFIAPI\r | |
1134 | PeiFfs2FvPpiGetFileInfo (\r | |
1135 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r | |
1136 | IN EFI_PEI_FILE_HANDLE FileHandle, \r | |
1137 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
1138 | )\r | |
1139 | {\r | |
1140 | UINT8 FileState;\r | |
1141 | UINT8 ErasePolarity;\r | |
1142 | EFI_FFS_FILE_HEADER *FileHeader;\r | |
1143 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1144 | \r | |
1145 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
1146 | return EFI_INVALID_PARAMETER;\r | |
1147 | }\r | |
1148 | \r | |
1149 | //\r | |
1150 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1151 | //\r | |
1152 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1153 | if (CoreFvHandle == NULL) {\r | |
1154 | return EFI_INVALID_PARAMETER;\r | |
1155 | }\r | |
1156 | \r | |
1157 | if (CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r | |
1158 | ErasePolarity = 1;\r | |
1159 | } else {\r | |
1160 | ErasePolarity = 0;\r | |
1161 | }\r | |
1162 | \r | |
1163 | //\r | |
1164 | // Get FileState which is the highest bit of the State \r | |
1165 | //\r | |
1166 | FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r | |
1167 | \r | |
1168 | switch (FileState) {\r | |
1169 | case EFI_FILE_DATA_VALID:\r | |
1170 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
1171 | break; \r | |
1172 | default:\r | |
1173 | return EFI_INVALID_PARAMETER;\r | |
1174 | }\r | |
1175 | \r | |
1176 | FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r | |
1177 | CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r | |
1178 | FileInfo->FileType = FileHeader->Type;\r | |
1179 | FileInfo->FileAttributes = FileHeader->Attributes;\r | |
1180 | FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);\r | |
1181 | FileInfo->Buffer = (FileHeader + 1);\r | |
1182 | return EFI_SUCCESS; \r | |
1183 | } \r | |
1184 | \r | |
1185 | /**\r | |
1186 | This function returns information about the firmware volume.\r | |
1187 | \r | |
1188 | @param This Points to this instance of the\r | |
1189 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1190 | @param FvHandle Handle to the firmware handle.\r | |
1191 | @param VolumeInfo Points to the returned firmware volume\r | |
1192 | information.\r | |
1193 | \r | |
1194 | @retval EFI_SUCCESS Information returned successfully.\r | |
1195 | @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid\r | |
1196 | firmware volume or VolumeInfo is NULL.\r | |
1197 | \r | |
1198 | **/ \r | |
1199 | EFI_STATUS\r | |
1200 | EFIAPI\r | |
1201 | PeiFfs2FvPpiGetVolumeInfo (\r | |
1202 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r | |
1203 | IN EFI_PEI_FV_HANDLE FvHandle, \r | |
1204 | OUT EFI_FV_INFO *VolumeInfo\r | |
1205 | )\r | |
1206 | {\r | |
1207 | EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r | |
1208 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r | |
1209 | \r | |
8fdcc412 | 1210 | if ((VolumeInfo == NULL) || (FvHandle == NULL)) {\r |
3b428ade | 1211 | return EFI_INVALID_PARAMETER;\r |
1212 | }\r | |
1213 | \r | |
1214 | //\r | |
1215 | // VolumeHandle may not align at 8 byte, \r | |
1216 | // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r | |
1217 | // So, Copy FvHeader into the local FvHeader structure.\r | |
1218 | //\r | |
1219 | CopyMem (&FwVolHeader, FvHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r | |
1220 | \r | |
1221 | //\r | |
1222 | // Check Fv Image Signature\r | |
1223 | //\r | |
1224 | if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r | |
1225 | return EFI_INVALID_PARAMETER;\r | |
1226 | }\r | |
1227 | \r | |
1228 | ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r | |
1229 | VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r | |
1230 | VolumeInfo->FvStart = (VOID *) FvHandle;\r | |
1231 | VolumeInfo->FvSize = FwVolHeader.FvLength;\r | |
1232 | CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r | |
1233 | \r | |
1234 | if (FwVolHeader.ExtHeaderOffset != 0) {\r | |
1235 | FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FvHandle) + FwVolHeader.ExtHeaderOffset);\r | |
1236 | CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r | |
1237 | }\r | |
1238 | \r | |
1239 | return EFI_SUCCESS; \r | |
1240 | } \r | |
1241 | \r | |
1242 | /**\r | |
1243 | Find the next matching section in the firmware file.\r | |
1244 | \r | |
1245 | This service enables PEI modules to discover sections\r | |
1246 | of a given type within a valid file.\r | |
1247 | \r | |
1248 | @param This Points to this instance of the\r | |
1249 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1250 | @param SearchType A filter to find only sections of this\r | |
1251 | type.\r | |
1252 | @param FileHandle Handle of firmware file in which to\r | |
1253 | search.\r | |
1254 | @param SectionData Updated upon return to point to the\r | |
1255 | section found.\r | |
1256 | \r | |
1257 | @retval EFI_SUCCESS Section was found.\r | |
1258 | @retval EFI_NOT_FOUND Section of the specified type was not\r | |
1259 | found. SectionData contains NULL.\r | |
1260 | **/\r | |
1261 | EFI_STATUS\r | |
1262 | EFIAPI\r | |
1263 | PeiFfs2FvPpiFindSectionByType (\r | |
1264 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
1265 | IN EFI_SECTION_TYPE SearchType,\r | |
1266 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1267 | OUT VOID **SectionData\r | |
1268 | )\r | |
1269 | {\r | |
1270 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r | |
1271 | UINT32 FileSize;\r | |
1272 | EFI_COMMON_SECTION_HEADER *Section;\r | |
1273 | \r | |
1274 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r | |
1275 | \r | |
1276 | //\r | |
1277 | // Size is 24 bits wide so mask upper 8 bits. \r | |
1278 | // Does not include FfsFileHeader header size\r | |
1279 | // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r | |
1280 | //\r | |
1281 | Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);\r | |
1282 | FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r | |
1283 | FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r | |
1284 | \r | |
1285 | return ProcessSection (\r | |
1286 | GetPeiServicesTablePointer (),\r | |
1287 | SearchType, \r | |
1288 | Section, \r | |
1289 | FileSize, \r | |
1290 | SectionData\r | |
1291 | ); \r | |
1292 | } \r | |
1293 | \r | |
1294 | /**\r | |
1295 | Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.\r | |
1296 | \r | |
1297 | @param FvHandle The handle of a FV.\r | |
1298 | \r | |
1299 | @retval NULL if can not find.\r | |
1300 | @return Pointer of corresponding PEI_CORE_FV_HANDLE. \r | |
1301 | **/\r | |
1302 | PEI_CORE_FV_HANDLE *\r | |
1303 | FvHandleToCoreHandle (\r | |
1304 | IN EFI_PEI_FV_HANDLE FvHandle\r | |
1305 | )\r | |
1306 | {\r | |
1307 | UINTN Index;\r | |
1308 | PEI_CORE_INSTANCE *PrivateData;\r | |
1309 | \r | |
1310 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer()); \r | |
1311 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r | |
1312 | if (FvHandle == PrivateData->Fv[Index].FvHandle) {\r | |
1313 | return &PrivateData->Fv[Index];\r | |
1314 | }\r | |
1315 | }\r | |
1316 | \r | |
1317 | return NULL;\r | |
1318 | } \r | |
1319 | \r | |
1320 | /**\r | |
1321 | Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r | |
1322 | \r | |
1323 | This routine also will install FvInfo ppi for FV hob in PI ways.\r | |
1324 | \r | |
1325 | @param Private Pointer of PEI_CORE_INSTANCE\r | |
1326 | @param Instance The index of FV want to be searched.\r | |
1327 | \r | |
1328 | @return Instance of PEI_CORE_FV_HANDLE.\r | |
1329 | **/\r | |
1330 | PEI_CORE_FV_HANDLE *\r | |
1331 | FindNextCoreFvHandle (\r | |
1332 | IN PEI_CORE_INSTANCE *Private,\r | |
1333 | IN UINTN Instance\r | |
1334 | )\r | |
1335 | {\r | |
1336 | UINTN Index;\r | |
1337 | BOOLEAN Match;\r | |
1338 | EFI_HOB_FIRMWARE_VOLUME *FvHob;\r | |
1339 | \r | |
1340 | //\r | |
1341 | // Handle Framework FvHob and Install FvInfo Ppi for it.\r | |
1342 | //\r | |
1343 | if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
1344 | //\r | |
1345 | // Loop to search the wanted FirmwareVolume which supports FFS\r | |
1346 | //\r | |
1347 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r | |
1348 | while (FvHob != NULL) {\r | |
1349 | for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r | |
1350 | if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r | |
1351 | Match = TRUE;\r | |
1352 | break;\r | |
1353 | }\r | |
1354 | }\r | |
1355 | //\r | |
1356 | // If Not Found, Install FvInfo Ppi for it.\r | |
1357 | //\r | |
1358 | if (!Match) {\r | |
1359 | PeiServicesInstallFvInfoPpi (\r | |
1360 | &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r | |
1361 | (VOID *)(UINTN)FvHob->BaseAddress,\r | |
1362 | (UINT32)FvHob->Length,\r | |
1363 | NULL,\r | |
1364 | NULL\r | |
1365 | );\r | |
1366 | }\r | |
1367 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r | |
1368 | }\r | |
1369 | }\r | |
1370 | \r | |
1371 | if (Instance >= Private->FvCount) {\r | |
1372 | return NULL;\r | |
1373 | }\r | |
4c6486b9 | 1374 | \r |
3b428ade | 1375 | return &Private->Fv[Instance];\r |
1376 | } \r | |
8e0e40ed | 1377 | \r |
1378 | /**\r | |
1379 | After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r | |
1380 | be re-installed with the instance in permanent memory and all cached FvPpi pointers in \r | |
1381 | PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant\r | |
1382 | memory.\r | |
1383 | \r | |
1384 | @param PrivateData Pointer to PEI_CORE_INSTANCE.\r | |
1385 | **/ \r | |
1386 | VOID\r | |
1387 | PeiReinitializeFv (\r | |
1388 | IN PEI_CORE_INSTANCE *PrivateData\r | |
1389 | )\r | |
1390 | {\r | |
7ec93917 | 1391 | VOID *OldFfs2FvPpi;\r |
1392 | EFI_PEI_PPI_DESCRIPTOR *OldDescriptor;\r | |
1393 | UINTN Index;\r | |
1394 | EFI_STATUS Status;\r | |
1395 | \r | |
1396 | //\r | |
1397 | // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which\r | |
1398 | // in flash.\r | |
1399 | //\r | |
1400 | Status = PeiServicesLocatePpi (\r | |
1401 | &gEfiFirmwareFileSystem2Guid,\r | |
1402 | 0,\r | |
1403 | &OldDescriptor,\r | |
1404 | &OldFfs2FvPpi\r | |
1405 | );\r | |
1406 | ASSERT_EFI_ERROR (Status);\r | |
1407 | \r | |
1408 | //\r | |
1409 | // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2\r | |
1410 | // which is shadowed from flash to permanent memory within PeiCore image.\r | |
1411 | //\r | |
1412 | Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs2FvPpiList);\r | |
1413 | ASSERT_EFI_ERROR (Status);\r | |
1414 | \r | |
1415 | //\r | |
1416 | // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r | |
1417 | //\r | |
1418 | for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r | |
1419 | if (PrivateData->Fv[Index].FvPpi == OldFfs2FvPpi) {\r | |
1420 | PrivateData->Fv[Index].FvPpi = &mPeiFfs2FvPpi;\r | |
1421 | }\r | |
1422 | }\r | |
8e0e40ed | 1423 | } \r |
1424 | \r | |
f3358329 | 1425 | /**\r |
1426 | Report the information for a new discoveried FV in unknown third-party format.\r | |
1427 | \r | |
1428 | If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but\r | |
1429 | the FV in this format has been discoveried, then this FV's information will be cached into \r | |
1430 | PEI_CORE_INSTANCE's UnknownFvInfo array.\r | |
1431 | Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI\r | |
1432 | is installed later by platform's PEIM, the original unknown third-party FV will be processed by\r | |
1433 | using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1434 | \r | |
1435 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r | |
1436 | @param Format Point to the unknown third-party format guid.\r | |
1437 | @param FvInfo Point to FvInfo buffer.\r | |
1438 | @param FvInfoSize The size of FvInfo buffer.\r | |
1439 | \r | |
1440 | @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.\r | |
1441 | @retval EFI_SUCCESS Success to add the information for unknown FV.\r | |
1442 | **/\r | |
1443 | EFI_STATUS\r | |
1444 | AddUnknownFormatFvInfo (\r | |
1445 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
1446 | IN EFI_GUID *Format,\r | |
1447 | IN VOID *FvInfo,\r | |
1448 | IN UINT32 FvInfoSize\r | |
1449 | )\r | |
1450 | {\r | |
1451 | PEI_CORE_UNKNOW_FORMAT_FV_INFO *NewUnknownFv;\r | |
1452 | \r | |
1453 | if (PrivateData->UnknownFvInfoCount + 1 >= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r | |
1454 | return EFI_OUT_OF_RESOURCES;\r | |
1455 | }\r | |
1456 | \r | |
1457 | NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];\r | |
1458 | PrivateData->UnknownFvInfoCount ++;\r | |
1459 | \r | |
1460 | CopyGuid (&NewUnknownFv->FvFormat, Format);\r | |
1461 | NewUnknownFv->FvInfo = FvInfo;\r | |
1462 | NewUnknownFv->FvInfoSize = FvInfoSize;\r | |
1463 | NewUnknownFv->NotifyDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r | |
1464 | NewUnknownFv->NotifyDescriptor.Guid = &NewUnknownFv->FvFormat;\r | |
1465 | NewUnknownFv->NotifyDescriptor.Notify = ThirdPartyFvPpiNotifyCallback;\r | |
1466 | \r | |
1467 | PeiServicesNotifyPpi (&NewUnknownFv->NotifyDescriptor);\r | |
1468 | return EFI_SUCCESS;\r | |
1469 | }\r | |
1470 | \r | |
1471 | /**\r | |
1472 | Find the FV information according to third-party FV format guid.\r | |
1473 | \r | |
1474 | This routine also will remove the FV information found by given FV format guid from\r | |
1475 | PrivateData->UnknownFvInfo[].\r | |
1476 | \r | |
1477 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r | |
1478 | @param Format Point to given FV format guid\r | |
1479 | @param FvInfo On return, the pointer of FV information buffer\r | |
1480 | @param FvInfoSize On return, the size of FV information buffer.\r | |
1481 | \r | |
1482 | @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI\r | |
1483 | @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1484 | **/\r | |
1485 | EFI_STATUS\r | |
1486 | FindUnknownFormatFvInfo (\r | |
1487 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
1488 | IN EFI_GUID *Format,\r | |
1489 | OUT VOID **FvInfo,\r | |
1490 | OUT UINT32 *FvInfoSize\r | |
1491 | )\r | |
1492 | {\r | |
1493 | UINTN Index;\r | |
1494 | UINTN Index2;\r | |
1495 | \r | |
1496 | Index = 0;\r | |
1497 | for (; Index < PrivateData->UnknownFvInfoCount; Index ++) {\r | |
1498 | if (CompareGuid (Format, &PrivateData->UnknownFvInfo[Index].FvFormat)) {\r | |
1499 | break;\r | |
1500 | }\r | |
1501 | }\r | |
1502 | \r | |
1503 | if (Index == PrivateData->UnknownFvInfoCount) {\r | |
1504 | return EFI_NOT_FOUND;\r | |
1505 | }\r | |
1506 | \r | |
1507 | *FvInfo = PrivateData->UnknownFvInfo[Index].FvInfo;\r | |
1508 | *FvInfoSize = PrivateData->UnknownFvInfo[Index].FvInfoSize;\r | |
1509 | \r | |
1510 | //\r | |
1511 | // Remove an entry from UnknownFvInfo array.\r | |
1512 | //\r | |
1513 | Index2 = Index + 1;\r | |
1514 | for (;Index2 < PrivateData->UnknownFvInfoCount; Index2 ++, Index ++) {\r | |
1515 | CopyMem (&PrivateData->UnknownFvInfo[Index], &PrivateData->UnknownFvInfo[Index2], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO));\r | |
1516 | }\r | |
1517 | PrivateData->UnknownFvInfoCount --;\r | |
1518 | return EFI_SUCCESS;\r | |
1519 | } \r | |
1520 | \r | |
1521 | /**\r | |
1522 | Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1523 | \r | |
1524 | When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this \r | |
1525 | routine is called to process all discoveried FVs in this format.\r | |
1526 | \r | |
1527 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r | |
1528 | @param NotifyDescriptor Address of the notification descriptor data structure.\r | |
1529 | @param Ppi Address of the PPI that was installed.\r | |
1530 | \r | |
1531 | @retval EFI_SUCCESS The notification callback is processed correctly.\r | |
1532 | **/\r | |
1533 | EFI_STATUS\r | |
1534 | EFIAPI\r | |
1535 | ThirdPartyFvPpiNotifyCallback (\r | |
1536 | IN EFI_PEI_SERVICES **PeiServices,\r | |
1537 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
1538 | IN VOID *Ppi\r | |
1539 | )\r | |
1540 | {\r | |
1541 | PEI_CORE_INSTANCE *PrivateData;\r | |
1542 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
1543 | VOID *FvInfo;\r | |
1544 | UINT32 FvInfoSize;\r | |
1545 | EFI_STATUS Status;\r | |
1546 | EFI_PEI_FV_HANDLE FvHandle;\r | |
1547 | BOOLEAN IsProcessed;\r | |
1548 | UINTN FvIndex;\r | |
1549 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
1550 | VOID *DepexData; \r | |
1551 | \r | |
1552 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
1553 | FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r | |
1554 | \r | |
1555 | do {\r | |
1556 | Status = FindUnknownFormatFvInfo (PrivateData, NotifyDescriptor->Guid, &FvInfo, &FvInfoSize);\r | |
1557 | if (EFI_ERROR (Status)) {\r | |
1558 | return EFI_SUCCESS;\r | |
1559 | }\r | |
1560 | \r | |
1561 | //\r | |
1562 | // Process new found FV and get FV handle.\r | |
1563 | //\r | |
1564 | Status = FvPpi->ProcessVolume (FvPpi, FvInfo, FvInfoSize, &FvHandle);\r | |
1565 | if (EFI_ERROR (Status)) {\r | |
1566 | DEBUG ((EFI_D_ERROR, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo));\r | |
1567 | continue;\r | |
1568 | }\r | |
1569 | \r | |
1570 | //\r | |
1571 | // Check whether the FV has already been processed.\r | |
1572 | //\r | |
1573 | IsProcessed = FALSE;\r | |
1574 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
1575 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
1576 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo));\r | |
1577 | IsProcessed = TRUE;\r | |
1578 | break;\r | |
1579 | }\r | |
1580 | }\r | |
1581 | \r | |
1582 | if (IsProcessed) {\r | |
1583 | continue;\r | |
1584 | }\r | |
1585 | \r | |
1586 | //\r | |
1587 | // Update internal PEI_CORE_FV array.\r | |
1588 | //\r | |
1589 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo;\r | |
1590 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
1591 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
1592 | DEBUG ((\r | |
1593 | EFI_D_INFO, \r | |
1594 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
1595 | (UINT32) PrivateData->FvCount, \r | |
1596 | (VOID *) FvInfo, \r | |
1597 | FvInfoSize,\r | |
1598 | FvHandle\r | |
1599 | )); \r | |
1600 | PrivateData->FvCount ++;\r | |
1601 | \r | |
1602 | //\r | |
1603 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r | |
1604 | //\r | |
1605 | FileHandle = NULL;\r | |
1606 | do {\r | |
1607 | Status = FvPpi->FindFileByType (\r | |
1608 | FvPpi,\r | |
1609 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
1610 | FvHandle,\r | |
1611 | &FileHandle\r | |
1612 | );\r | |
1613 | if (!EFI_ERROR (Status)) {\r | |
1614 | Status = FvPpi->FindSectionByType (\r | |
1615 | FvPpi,\r | |
1616 | EFI_SECTION_PEI_DEPEX,\r | |
1617 | FileHandle,\r | |
1618 | (VOID**)&DepexData\r | |
1619 | );\r | |
1620 | if (!EFI_ERROR (Status)) {\r | |
1621 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
1622 | //\r | |
1623 | // Dependency is not satisfied.\r | |
1624 | //\r | |
1625 | continue;\r | |
1626 | }\r | |
1627 | }\r | |
1628 | \r | |
1629 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r | |
1630 | ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r | |
1631 | }\r | |
1632 | } while (FileHandle != NULL);\r | |
1633 | } while (TRUE);\r | |
f3358329 | 1634 | }\r |