]>
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 | |
284 | \r | |
285 | \r | |
286 | //\r | |
287 | // Post a call-back for the FvInfoPPI services to expose\r | |
288 | // additional Fvs to PeiCore.\r | |
289 | //\r | |
290 | Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);\r | |
291 | ASSERT_EFI_ERROR (Status);\r | |
292 | \r | |
293 | }\r | |
294 | \r | |
b1f6a7c6 | 295 | /**\r |
296 | Process Firmware Volum Information once FvInfoPPI install.\r | |
ed299e3c LG |
297 | The FV Info will be registered into PeiCore private data structure.\r |
298 | And search the inside FV image, if found, the new FV INFO PPI will be installed.\r | |
b1f6a7c6 | 299 | \r |
ed299e3c | 300 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
731bd38e | 301 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
302 | @param Ppi Address of the PPI that was installed.\r | |
b1f6a7c6 | 303 | \r |
ed299e3c | 304 | @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r |
6a1ae84a | 305 | @return if not EFI_SUCESS, fail to verify FV.\r |
b1f6a7c6 | 306 | \r |
307 | **/\r | |
b0d803fe | 308 | EFI_STATUS\r |
309 | EFIAPI\r | |
310 | FirmwareVolmeInfoPpiNotifyCallback (\r | |
311 | IN EFI_PEI_SERVICES **PeiServices,\r | |
312 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
313 | IN VOID *Ppi\r | |
314 | )\r | |
b0d803fe | 315 | {\r |
316 | UINT8 FvCount;\r | |
317 | EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;\r | |
318 | PEI_CORE_INSTANCE *PrivateData;\r | |
288f9b38 LG |
319 | EFI_PEI_FILE_HANDLE FileHandle;\r |
320 | VOID *DepexData;\r | |
321 | UINT32 AuthenticationStatus;\r | |
322 | EFI_STATUS Status;\r | |
b0d803fe | 323 | \r |
288f9b38 LG |
324 | FileHandle = NULL;\r |
325 | DepexData = NULL;\r | |
326 | Status = EFI_SUCCESS;\r | |
327 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
b0d803fe | 328 | \r |
177aabe6 | 329 | if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
97b2c9b5 LG |
330 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, FixedPcdGet32 (PcdPeiCoreMaxFvSupported)));\r |
331 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r | |
b0d803fe | 332 | ASSERT (FALSE);\r |
333 | }\r | |
334 | \r | |
335 | Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;\r | |
336 | \r | |
97b2c9b5 LG |
337 | //\r |
338 | // Only add FileSystem2 Fv to Fv list\r | |
339 | //\r | |
288f9b38 LG |
340 | if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r |
341 | for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {\r | |
342 | if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {\r | |
343 | return EFI_SUCCESS;\r | |
344 | }\r | |
345 | }\r | |
6a1ae84a | 346 | \r |
347 | Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo);\r | |
348 | if (EFI_ERROR(Status)) {\r | |
349 | DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", (VOID *) Fv->FvInfo));\r | |
350 | return Status;\r | |
351 | }\r | |
352 | \r | |
b0d803fe | 353 | PrivateData->Fv[PrivateData->FvCount++].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo;\r |
b0d803fe | 354 | \r |
288f9b38 LG |
355 | PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;\r |
356 | \r | |
7df7393f | 357 | 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 |
358 | //\r |
359 | // Preprocess all FV type files in this new FileSystem2 Fv image\r | |
360 | //\r | |
361 | do {\r | |
362 | Status = PeiFindFileEx (\r | |
363 | (EFI_PEI_FV_HANDLE)Fv->FvInfo, \r | |
364 | NULL, \r | |
365 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, \r | |
366 | &FileHandle, \r | |
367 | NULL\r | |
368 | );\r | |
369 | if (!EFI_ERROR (Status)) {\r | |
370 | Status = PeiFfsFindSectionData (\r | |
371 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
372 | EFI_SECTION_PEI_DEPEX,\r | |
373 | FileHandle, \r | |
374 | (VOID **)&DepexData\r | |
375 | );\r | |
376 | if (!EFI_ERROR (Status)) {\r | |
377 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
378 | //\r | |
379 | // Dependency is not satisfied.\r | |
380 | //\r | |
381 | continue;\r | |
382 | }\r | |
383 | }\r | |
384 | //\r | |
385 | // Process FvFile to install FvInfo ppi and build FvHob\r | |
386 | // \r | |
97b2c9b5 | 387 | ProcessFvFile ((CONST EFI_PEI_SERVICES **) PeiServices, (EFI_PEI_FV_HANDLE)Fv->FvInfo, FileHandle, &AuthenticationStatus);\r |
288f9b38 LG |
388 | }\r |
389 | } while (FileHandle != NULL);\r | |
390 | }\r | |
b0d803fe | 391 | \r |
392 | return EFI_SUCCESS;\r | |
393 | }\r | |
394 | \r | |
b1f6a7c6 | 395 | /**\r |
ed299e3c LG |
396 | Go through the file to search SectionType section. \r |
397 | Search within encapsulation sections (compression and GUIDed) recursively, \r | |
398 | until the match section is found.\r | |
399 | \r | |
400 | @param PeiServices - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
401 | @param SectionType - Filter to find only section of this type.\r | |
402 | @param Section - From where to search.\r | |
403 | @param SectionSize - The file size to search.\r | |
404 | @param OutputBuffer - A pointer to the discovered section, if successful.\r | |
405 | NULL if section not found\r | |
b1f6a7c6 | 406 | \r |
ed299e3c LG |
407 | @return EFI_NOT_FOUND The match section is not found.\r |
408 | @return EFI_SUCCESS The match section is found.\r | |
b1f6a7c6 | 409 | \r |
410 | **/\r | |
b0d803fe | 411 | EFI_STATUS\r |
412 | PeiFfsProcessSection (\r | |
413 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
414 | IN EFI_SECTION_TYPE SectionType,\r | |
415 | IN EFI_COMMON_SECTION_HEADER *Section,\r | |
416 | IN UINTN SectionSize,\r | |
288f9b38 | 417 | OUT VOID **OutputBuffer\r |
b0d803fe | 418 | )\r |
b0d803fe | 419 | {\r |
420 | EFI_STATUS Status;\r | |
421 | UINT32 SectionLength;\r | |
422 | UINT32 ParsedLength;\r | |
b0d803fe | 423 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r |
b0d803fe | 424 | EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r |
425 | VOID *PpiOutput;\r | |
426 | UINTN PpiOutputSize;\r | |
288f9b38 LG |
427 | UINTN Index;\r |
428 | UINT32 Authentication;\r | |
429 | PEI_CORE_INSTANCE *PrivateData;\r | |
b0d803fe | 430 | \r |
288f9b38 | 431 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
b0d803fe | 432 | *OutputBuffer = NULL;\r |
288f9b38 LG |
433 | ParsedLength = 0;\r |
434 | Index = 0;\r | |
435 | Status = EFI_NOT_FOUND;\r | |
436 | PpiOutput = NULL;\r | |
437 | PpiOutputSize = 0;\r | |
b0d803fe | 438 | while (ParsedLength < SectionSize) {\r |
439 | if (Section->Type == SectionType) {\r | |
440 | *OutputBuffer = (VOID *)(Section + 1);\r | |
441 | return EFI_SUCCESS;\r | |
288f9b38 LG |
442 | } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r |
443 | //\r | |
444 | // Check the encapsulated section is extracted into the cache data.\r | |
445 | //\r | |
446 | for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r | |
447 | if (Section == PrivateData->CacheSection.Section[Index]) {\r | |
448 | PpiOutput = PrivateData->CacheSection.SectionData[Index];\r | |
449 | PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r | |
450 | //\r | |
451 | // Search section directly from the cache data.\r | |
452 | //\r | |
b0d803fe | 453 | return PeiFfsProcessSection (\r |
454 | PeiServices,\r | |
455 | SectionType, \r | |
456 | PpiOutput, \r | |
457 | PpiOutputSize, \r | |
288f9b38 | 458 | OutputBuffer \r |
b0d803fe | 459 | );\r |
460 | }\r | |
461 | }\r | |
288f9b38 LG |
462 | \r |
463 | Status = EFI_NOT_FOUND;\r | |
464 | if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r | |
465 | Status = PeiServicesLocatePpi (\r | |
466 | &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid, \r | |
467 | 0, \r | |
468 | NULL, \r | |
469 | (VOID **) &GuidSectionPpi\r | |
470 | );\r | |
b0d803fe | 471 | if (!EFI_ERROR (Status)) {\r |
288f9b38 LG |
472 | Status = GuidSectionPpi->ExtractSection (\r |
473 | GuidSectionPpi,\r | |
474 | Section,\r | |
475 | &PpiOutput,\r | |
476 | &PpiOutputSize,\r | |
477 | &Authentication\r | |
478 | );\r | |
479 | }\r | |
480 | } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r | |
481 | Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r | |
482 | if (!EFI_ERROR (Status)) {\r | |
483 | Status = DecompressPpi->Decompress (\r | |
484 | DecompressPpi,\r | |
485 | (CONST EFI_COMPRESSION_SECTION*) Section,\r | |
486 | &PpiOutput,\r | |
487 | &PpiOutputSize\r | |
488 | );\r | |
b0d803fe | 489 | }\r |
490 | }\r | |
288f9b38 LG |
491 | \r |
492 | if (!EFI_ERROR (Status)) {\r | |
493 | //\r | |
494 | // Update cache section data.\r | |
495 | //\r | |
496 | if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r | |
497 | PrivateData->CacheSection.AllSectionCount ++;\r | |
498 | }\r | |
499 | PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r | |
500 | PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r | |
501 | PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r | |
502 | PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r | |
503 | \r | |
504 | return PeiFfsProcessSection (\r | |
505 | PeiServices,\r | |
506 | SectionType, \r | |
507 | PpiOutput, \r | |
508 | PpiOutputSize, \r | |
509 | OutputBuffer \r | |
510 | );\r | |
511 | }\r | |
b0d803fe | 512 | }\r |
513 | \r | |
514 | //\r | |
515 | // Size is 24 bits wide so mask upper 8 bits. \r | |
516 | // SectionLength is adjusted it is 4 byte aligned.\r | |
517 | // Go to the next section\r | |
518 | //\r | |
519 | SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;\r | |
520 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
521 | ASSERT (SectionLength != 0);\r | |
522 | ParsedLength += SectionLength;\r | |
523 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
524 | }\r | |
525 | \r | |
526 | return EFI_NOT_FOUND;\r | |
527 | }\r | |
528 | \r | |
192f6d4c | 529 | \r |
b1f6a7c6 | 530 | /**\r |
ed299e3c | 531 | Given the input file pointer, search for the first matching section in the\r |
b1f6a7c6 | 532 | FFS volume.\r |
533 | \r | |
ed299e3c | 534 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 535 | @param SectionType Filter to find only sections of this type.\r |
536 | @param FileHandle Pointer to the current file to search.\r | |
ed299e3c | 537 | @param SectionData A pointer to the discovered section, if successful.\r |
b1f6a7c6 | 538 | NULL if section not found\r |
539 | \r | |
540 | @retval EFI_NOT_FOUND No files matching the search criteria were found\r | |
541 | @retval EFI_SUCCESS Success to find section data in given file\r | |
542 | \r | |
543 | **/\r | |
192f6d4c | 544 | EFI_STATUS\r |
545 | EFIAPI\r | |
546 | PeiFfsFindSectionData (\r | |
0c2b5da8 | 547 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 548 | IN EFI_SECTION_TYPE SectionType,\r |
0c2b5da8 | 549 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
192f6d4c | 550 | IN OUT VOID **SectionData\r |
551 | )\r | |
192f6d4c | 552 | {\r |
b0d803fe | 553 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r |
554 | UINT32 FileSize;\r | |
555 | EFI_COMMON_SECTION_HEADER *Section;\r | |
b0d803fe | 556 | \r |
557 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r | |
192f6d4c | 558 | \r |
559 | //\r | |
560 | // Size is 24 bits wide so mask upper 8 bits. \r | |
b0d803fe | 561 | // Does not include FfsFileHeader header size\r |
192f6d4c | 562 | // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r |
563 | //\r | |
564 | Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);\r | |
565 | FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;\r | |
b0d803fe | 566 | FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r |
567 | \r | |
568 | return PeiFfsProcessSection (\r | |
288f9b38 | 569 | PeiServices,\r |
b0d803fe | 570 | SectionType, \r |
571 | Section, \r | |
572 | FileSize, \r | |
288f9b38 | 573 | SectionData\r |
b0d803fe | 574 | );\r |
192f6d4c | 575 | }\r |
576 | \r | |
b1f6a7c6 | 577 | /**\r |
578 | Given the input file pointer, search for the next matching file in the\r | |
579 | FFS volume as defined by SearchType. The search starts from FileHeader inside\r | |
580 | the Firmware Volume defined by FwVolHeader.\r | |
192f6d4c | 581 | \r |
b1f6a7c6 | 582 | \r |
d73d93c3 | 583 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 584 | @param SearchType Filter to find only files of this type.\r |
585 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
586 | @param VolumeHandle Pointer to the FV header of the volume to search.\r | |
587 | @param FileHandle Pointer to the current file from which to begin searching.\r | |
588 | This pointer will be updated upon return to reflect the file found.\r | |
589 | @retval EFI_NOT_FOUND No files matching the search criteria were found\r | |
590 | @retval EFI_SUCCESS Success to find next file in given volume\r | |
591 | \r | |
592 | **/\r | |
192f6d4c | 593 | EFI_STATUS\r |
594 | EFIAPI\r | |
595 | PeiFfsFindNextFile (\r | |
0c2b5da8 | 596 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
597 | IN UINT8 SearchType,\r | |
598 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
599 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
192f6d4c | 600 | )\r |
192f6d4c | 601 | {\r |
b0d803fe | 602 | return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);\r |
192f6d4c | 603 | }\r |
604 | \r | |
b0d803fe | 605 | \r |
b1f6a7c6 | 606 | /**\r |
ed299e3c | 607 | Search the firmware volumes by index\r |
b1f6a7c6 | 608 | \r |
ed299e3c | 609 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 610 | @param Instance Instance of FV to find\r |
611 | @param VolumeHandle Pointer to found Volume.\r | |
612 | \r | |
613 | @retval EFI_INVALID_PARAMETER FwVolHeader is NULL\r | |
614 | @retval EFI_SUCCESS Firmware volume instance successfully found.\r | |
615 | \r | |
616 | **/\r | |
192f6d4c | 617 | EFI_STATUS \r |
618 | EFIAPI\r | |
619 | PeiFvFindNextVolume (\r | |
2a00326e | 620 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 621 | IN UINTN Instance,\r |
0c2b5da8 | 622 | IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r |
192f6d4c | 623 | )\r |
192f6d4c | 624 | {\r |
2a00326e LG |
625 | PEI_CORE_INSTANCE *Private;\r |
626 | UINTN Index;\r | |
627 | BOOLEAN Match;\r | |
628 | EFI_HOB_FIRMWARE_VOLUME *FvHob;\r | |
192f6d4c | 629 | \r |
b0d803fe | 630 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
631 | if (VolumeHandle == NULL) {\r | |
632 | return EFI_INVALID_PARAMETER;\r | |
2a00326e LG |
633 | }\r |
634 | \r | |
635 | //\r | |
636 | // Handle Framework FvHob and Install FvInfo Ppi for it.\r | |
637 | //\r | |
f806dd27 | 638 | if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r |
2a00326e LG |
639 | //\r |
640 | // Loop to search the wanted FirmwareVolume which supports FFS\r | |
641 | //\r | |
642 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r | |
643 | while (FvHob != NULL) {\r | |
644 | for (Index = 0, Match = FALSE; Index < Private->AllFvCount; Index++) {\r | |
645 | if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->AllFv[Index]) {\r | |
646 | Match = TRUE;\r | |
647 | break;\r | |
648 | }\r | |
649 | }\r | |
650 | //\r | |
651 | // If Not Found, Install FvInfo Ppi for it.\r | |
652 | //\r | |
653 | if (!Match) {\r | |
187f1a5b | 654 | PeiServicesInstallFvInfoPpi (\r |
2a00326e LG |
655 | NULL,\r |
656 | (VOID *)(UINTN)FvHob->BaseAddress,\r | |
657 | (UINT32)FvHob->Length,\r | |
658 | NULL,\r | |
659 | NULL\r | |
660 | );\r | |
661 | }\r | |
662 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r | |
663 | }\r | |
664 | }\r | |
192f6d4c | 665 | \r |
b0d803fe | 666 | if (Instance >= Private->AllFvCount) {\r |
667 | VolumeHandle = NULL;\r | |
668 | return EFI_NOT_FOUND;\r | |
669 | }\r | |
192f6d4c | 670 | \r |
b0d803fe | 671 | *VolumeHandle = Private->AllFv[Instance];\r |
672 | return EFI_SUCCESS;\r | |
673 | }\r | |
192f6d4c | 674 | \r |
192f6d4c | 675 | \r |
b1f6a7c6 | 676 | /**\r |
ed299e3c | 677 | Find a file within a volume by its name.\r |
b1f6a7c6 | 678 | \r |
ed299e3c LG |
679 | @param FileName A pointer to the name of the file to find within the firmware volume.\r |
680 | @param VolumeHandle The firmware volume to search\r | |
681 | @param FileHandle Upon exit, points to the found file's handle \r | |
682 | or NULL if it could not be found.\r | |
b1f6a7c6 | 683 | \r |
ed299e3c LG |
684 | @retval EFI_SUCCESS File was found.\r |
685 | @retval EFI_NOT_FOUND File was not found.\r | |
686 | @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r | |
b1f6a7c6 | 687 | \r |
b1f6a7c6 | 688 | **/\r |
b0d803fe | 689 | EFI_STATUS\r |
690 | EFIAPI \r | |
691 | PeiFfsFindFileByName (\r | |
692 | IN CONST EFI_GUID *FileName,\r | |
693 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
694 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
695 | )\r | |
b0d803fe | 696 | {\r |
697 | EFI_STATUS Status;\r | |
698 | if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r | |
192f6d4c | 699 | return EFI_INVALID_PARAMETER;\r |
700 | }\r | |
b0d803fe | 701 | Status = PeiFindFileEx (VolumeHandle, FileName, 0, FileHandle, NULL);\r |
702 | if (Status == EFI_NOT_FOUND) {\r | |
703 | *FileHandle = NULL;\r | |
704 | }\r | |
705 | return Status;\r | |
706 | }\r | |
707 | \r | |
b1f6a7c6 | 708 | /**\r |
709 | \r | |
710 | Returns information about a specific file.\r | |
711 | \r | |
712 | \r | |
713 | @param FileHandle - The handle to file.\r | |
714 | @param FileInfo - Pointer to the file information.\r | |
715 | \r | |
716 | @retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.\r | |
717 | @retval EFI_SUCCESS Success to collect file info.\r | |
718 | \r | |
719 | **/\r | |
b0d803fe | 720 | EFI_STATUS\r |
721 | EFIAPI \r | |
722 | PeiFfsGetFileInfo (\r | |
723 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
724 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
725 | )\r | |
b0d803fe | 726 | {\r |
727 | UINT8 FileState;\r | |
728 | UINT8 ErasePolarity;\r | |
729 | EFI_FFS_FILE_HEADER *FileHeader;\r | |
730 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
731 | \r | |
732 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
733 | return EFI_INVALID_PARAMETER;\r | |
734 | }\r | |
735 | \r | |
173b35e4 | 736 | VolumeHandle = 0;\r |
b0d803fe | 737 | //\r |
738 | // Retrieve the FirmwareVolume which the file resides in.\r | |
739 | //\r | |
740 | if (!PeiFileHandleToVolume(FileHandle, &VolumeHandle)) {\r | |
741 | return EFI_INVALID_PARAMETER;\r | |
742 | }\r | |
743 | \r | |
797a9d67 | 744 | if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB2_ERASE_POLARITY) {\r |
b0d803fe | 745 | ErasePolarity = 1;\r |
192f6d4c | 746 | } else {\r |
b0d803fe | 747 | ErasePolarity = 0;\r |
748 | }\r | |
749 | \r | |
750 | //\r | |
751 | // Get FileState which is the highest bit of the State \r | |
752 | //\r | |
753 | FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r | |
192f6d4c | 754 | \r |
b0d803fe | 755 | switch (FileState) {\r |
756 | case EFI_FILE_DATA_VALID:\r | |
757 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
758 | break; \r | |
759 | default:\r | |
760 | return EFI_INVALID_PARAMETER;\r | |
192f6d4c | 761 | }\r |
b0d803fe | 762 | \r |
763 | FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r | |
764 | CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r | |
765 | FileInfo->FileType = FileHeader->Type;\r | |
766 | FileInfo->FileAttributes = FileHeader->Attributes;\r | |
767 | FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);\r | |
768 | FileInfo->Buffer = (FileHeader + 1);\r | |
769 | return EFI_SUCCESS;\r | |
770 | }\r | |
771 | \r | |
772 | \r | |
b1f6a7c6 | 773 | /**\r |
774 | \r | |
775 | Collect information of given Fv Volume.\r | |
776 | \r | |
777 | @param VolumeHandle - The handle to Fv Volume.\r | |
778 | @param VolumeInfo - The pointer to volume information.\r | |
779 | \r | |
780 | @retval EFI_INVALID_PARAMETER VolumeInfo is NULL\r | |
781 | @retval EFI_SUCCESS Success to collect fv info.\r | |
782 | **/\r | |
b0d803fe | 783 | EFI_STATUS\r |
784 | EFIAPI \r | |
785 | PeiFfsGetVolumeInfo (\r | |
786 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
787 | OUT EFI_FV_INFO *VolumeInfo\r | |
788 | )\r | |
b0d803fe | 789 | {\r |
288f9b38 | 790 | EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r |
b0d803fe | 791 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r |
792 | \r | |
793 | if (VolumeInfo == NULL) {\r | |
794 | return EFI_INVALID_PARAMETER;\r | |
192f6d4c | 795 | }\r |
288f9b38 LG |
796 | \r |
797 | //\r | |
798 | // VolumeHandle may not align at 8 byte, \r | |
799 | // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r | |
800 | // So, Copy FvHeader into the local FvHeader structure.\r | |
801 | //\r | |
802 | CopyMem (&FwVolHeader, VolumeHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r | |
803 | //\r | |
804 | // Check Fv Image Signature\r | |
805 | //\r | |
806 | if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r | |
807 | return EFI_INVALID_PARAMETER;\r | |
808 | }\r | |
97b2c9b5 | 809 | ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r |
288f9b38 LG |
810 | VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r |
811 | VolumeInfo->FvStart = (VOID *) VolumeHandle;\r | |
812 | VolumeInfo->FvSize = FwVolHeader.FvLength;\r | |
813 | CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r | |
b0d803fe | 814 | \r |
288f9b38 LG |
815 | if (FwVolHeader.ExtHeaderOffset != 0) {\r |
816 | FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);\r | |
b0d803fe | 817 | CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r |
818 | }\r | |
819 | return EFI_SUCCESS;\r | |
192f6d4c | 820 | }\r |
b0d803fe | 821 | \r |
4c6486b9 | 822 | /**\r |
823 | Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r | |
824 | \r | |
825 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
97b2c9b5 LG |
826 | @param ParentFvHandle Fv handle to parent Fv image that contain this Fv image.\r |
827 | @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r | |
4c6486b9 | 828 | @param AuthenticationState Pointer to attestation authentication state of image.\r |
829 | \r | |
830 | \r | |
831 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
832 | @retval EFI_SUCCESS Successfully to process it.\r | |
833 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
834 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r | |
835 | \r | |
836 | **/\r | |
837 | EFI_STATUS\r | |
838 | ProcessFvFile (\r | |
6c7a807a | 839 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
97b2c9b5 LG |
840 | IN EFI_PEI_FV_HANDLE ParentFvHandle,\r |
841 | IN EFI_PEI_FILE_HANDLE ParentFvFileHandle,\r | |
6c7a807a | 842 | OUT UINT32 *AuthenticationState\r |
4c6486b9 | 843 | )\r |
844 | {\r | |
845 | EFI_STATUS Status;\r | |
846 | EFI_PEI_FV_HANDLE FvImageHandle;\r | |
847 | EFI_FV_INFO FvImageInfo;\r | |
97b2c9b5 | 848 | EFI_FV_INFO ParentFvImageInfo;\r |
4c6486b9 | 849 | UINT32 FvAlignment;\r |
850 | VOID *FvBuffer;\r | |
851 | EFI_PEI_HOB_POINTERS HobPtr;\r | |
852 | \r | |
853 | FvBuffer = NULL;\r | |
854 | *AuthenticationState = 0;\r | |
855 | \r | |
856 | //\r | |
857 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r | |
858 | // been extracted.\r | |
859 | //\r | |
860 | HobPtr.Raw = GetHobList ();\r | |
861 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
97b2c9b5 | 862 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r |
4c6486b9 | 863 | //\r |
864 | // this FILE has been dispatched, it will not be dispatched again.\r | |
865 | //\r | |
866 | return EFI_SUCCESS;\r | |
867 | }\r | |
868 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
869 | }\r | |
870 | \r | |
871 | //\r | |
872 | // Find FvImage in FvFile\r | |
873 | //\r | |
874 | Status = PeiFfsFindSectionData (\r | |
6c7a807a | 875 | PeiServices,\r |
4c6486b9 | 876 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r |
97b2c9b5 | 877 | ParentFvFileHandle,\r |
4c6486b9 | 878 | (VOID **)&FvImageHandle\r |
879 | );\r | |
880 | \r | |
881 | if (EFI_ERROR (Status)) {\r | |
882 | return Status;\r | |
883 | }\r | |
97b2c9b5 LG |
884 | \r |
885 | //\r | |
886 | // Collect Parent FvImage Info.\r | |
887 | //\r | |
888 | Status = PeiFfsGetVolumeInfo (ParentFvHandle, &ParentFvImageInfo);\r | |
889 | ASSERT_EFI_ERROR (Status); \r | |
890 | \r | |
4c6486b9 | 891 | //\r |
892 | // Collect FvImage Info.\r | |
893 | //\r | |
894 | Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo);\r | |
895 | ASSERT_EFI_ERROR (Status);\r | |
896 | \r | |
897 | //\r | |
898 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r | |
899 | //\r | |
900 | FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
901 | if (FvAlignment < 8) {\r | |
902 | FvAlignment = 8;\r | |
903 | }\r | |
904 | \r | |
905 | //\r | |
906 | // Check FvImage\r | |
907 | //\r | |
908 | if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r | |
909 | FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);\r | |
910 | if (FvBuffer == NULL) {\r | |
911 | return EFI_OUT_OF_RESOURCES;\r | |
912 | }\r | |
913 | CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);\r | |
914 | //\r | |
915 | // Update FvImageInfo after reload FvImage to new aligned memory\r | |
916 | //\r | |
97b2c9b5 LG |
917 | Status = PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r |
918 | ASSERT_EFI_ERROR (Status);\r | |
4c6486b9 | 919 | }\r |
920 | \r | |
921 | //\r | |
922 | // Install FvPpi and Build FvHob\r | |
923 | //\r | |
187f1a5b | 924 | PeiServicesInstallFvInfoPpi (\r |
4c6486b9 | 925 | NULL,\r |
926 | FvImageInfo.FvStart,\r | |
927 | (UINT32) FvImageInfo.FvSize,\r | |
97b2c9b5 LG |
928 | &ParentFvImageInfo.FvName,\r |
929 | &(((EFI_FFS_FILE_HEADER*)ParentFvFileHandle)->Name)\r | |
4c6486b9 | 930 | );\r |
931 | \r | |
932 | //\r | |
933 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r | |
4c6486b9 | 934 | //\r |
223c22d8 LG |
935 | BuildFvHob (\r |
936 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
937 | FvImageInfo.FvSize\r | |
938 | );\r | |
4c6486b9 | 939 | \r |
940 | //\r | |
941 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
942 | // encapsulated file again.\r | |
943 | //\r | |
944 | BuildFv2Hob (\r | |
945 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
946 | FvImageInfo.FvSize,\r | |
97b2c9b5 LG |
947 | &ParentFvImageInfo.FvName,\r |
948 | &(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name)\r | |
4c6486b9 | 949 | );\r |
950 | \r | |
951 | return EFI_SUCCESS;\r | |
952 | }\r | |
953 | \r | |
954 | \r |