]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | Pei Core Firmware File System service routines.\r |
d1102dba | 3 | \r |
9ddd7d7a | 4 | Copyright (c) 2015 HP Development Company, L.P.\r |
d1102dba LG |
5 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
192f6d4c | 13 | \r |
615c6dd0 | 14 | **/\r |
192f6d4c | 15 | \r |
3b428ade | 16 | #include "FwVol.h"\r |
192f6d4c | 17 | \r |
c7935105 SZ |
18 | EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList[] = {\r |
19 | {\r | |
20 | EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r | |
21 | &gEfiPeiFirmwareVolumeInfoPpiGuid,\r | |
d1102dba | 22 | FirmwareVolmeInfoPpiNotifyCallback\r |
c7935105 SZ |
23 | },\r |
24 | {\r | |
25 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
26 | &gEfiPeiFirmwareVolumeInfo2PpiGuid,\r | |
d1102dba | 27 | FirmwareVolmeInfoPpiNotifyCallback\r |
c7935105 | 28 | }\r |
b0d803fe | 29 | };\r |
30 | \r | |
890e5417 SZ |
31 | PEI_FW_VOL_INSTANCE mPeiFfs2FwVol = {\r |
32 | PEI_FW_VOL_SIGNATURE,\r | |
33 | FALSE,\r | |
34 | {\r | |
35 | PeiFfsFvPpiProcessVolume,\r | |
36 | PeiFfsFvPpiFindFileByType,\r | |
37 | PeiFfsFvPpiFindFileByName,\r | |
38 | PeiFfsFvPpiGetFileInfo,\r | |
39 | PeiFfsFvPpiGetVolumeInfo,\r | |
c7935105 SZ |
40 | PeiFfsFvPpiFindSectionByType,\r |
41 | PeiFfsFvPpiGetFileInfo2,\r | |
42 | PeiFfsFvPpiFindSectionByType2,\r | |
43 | EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE,\r | |
44 | EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION\r | |
890e5417 SZ |
45 | }\r |
46 | };\r | |
47 | \r | |
48 | PEI_FW_VOL_INSTANCE mPeiFfs3FwVol = {\r | |
49 | PEI_FW_VOL_SIGNATURE,\r | |
50 | TRUE,\r | |
51 | {\r | |
52 | PeiFfsFvPpiProcessVolume,\r | |
53 | PeiFfsFvPpiFindFileByType,\r | |
54 | PeiFfsFvPpiFindFileByName,\r | |
55 | PeiFfsFvPpiGetFileInfo,\r | |
56 | PeiFfsFvPpiGetVolumeInfo,\r | |
c7935105 SZ |
57 | PeiFfsFvPpiFindSectionByType,\r |
58 | PeiFfsFvPpiGetFileInfo2,\r | |
59 | PeiFfsFvPpiFindSectionByType2,\r | |
60 | EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE,\r | |
61 | EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION\r | |
890e5417 | 62 | }\r |
3b428ade | 63 | };\r |
d1102dba | 64 | \r |
3b428ade | 65 | EFI_PEI_PPI_DESCRIPTOR mPeiFfs2FvPpiList = {\r |
66 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
67 | &gEfiFirmwareFileSystem2Guid,\r | |
890e5417 SZ |
68 | &mPeiFfs2FwVol.Fv\r |
69 | };\r | |
70 | \r | |
71 | EFI_PEI_PPI_DESCRIPTOR mPeiFfs3FvPpiList = {\r | |
72 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
73 | &gEfiFirmwareFileSystem3Guid,\r | |
74 | &mPeiFfs3FwVol.Fv\r | |
3b428ade | 75 | };\r |
795bb9b6 SZ |
76 | \r |
77 | /**\r | |
e411f8ca SZ |
78 | Required Alignment Alignment Value in FFS FFS_ATTRIB_DATA_ALIGNMENT2 Alignment Value in\r |
79 | (bytes) Attributes Field in FFS Attributes Field Firmware Volume Interfaces\r | |
80 | 1 0 0 0\r | |
81 | 16 1 0 4\r | |
82 | 128 2 0 7\r | |
83 | 512 3 0 9\r | |
84 | 1 KB 4 0 10\r | |
85 | 4 KB 5 0 12\r | |
86 | 32 KB 6 0 15\r | |
87 | 64 KB 7 0 16\r | |
88 | 128 KB 0 1 17\r | |
89 | 256 KB 1 1 18\r | |
90 | 512 KB 2 1 19\r | |
91 | 1 MB 3 1 20\r | |
92 | 2 MB 4 1 21\r | |
93 | 4 MB 5 1 22\r | |
94 | 8 MB 6 1 23\r | |
95 | 16 MB 7 1 24\r | |
795bb9b6 SZ |
96 | **/\r |
97 | UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16};\r | |
e411f8ca | 98 | UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24};\r |
795bb9b6 SZ |
99 | \r |
100 | /**\r | |
101 | Convert the FFS File Attributes to FV File Attributes\r | |
102 | \r | |
103 | @param FfsAttributes The attributes of UINT8 type.\r | |
104 | \r | |
105 | @return The attributes of EFI_FV_FILE_ATTRIBUTES\r | |
106 | \r | |
107 | **/\r | |
108 | EFI_FV_FILE_ATTRIBUTES\r | |
109 | FfsAttributes2FvFileAttributes (\r | |
110 | IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes\r | |
111 | )\r | |
112 | {\r | |
113 | UINT8 DataAlignment;\r | |
114 | EFI_FV_FILE_ATTRIBUTES FileAttribute;\r | |
115 | \r | |
116 | DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);\r | |
117 | ASSERT (DataAlignment < 8);\r | |
118 | \r | |
e411f8ca SZ |
119 | if ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT_2) != 0) {\r |
120 | FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes2[DataAlignment];\r | |
121 | } else {\r | |
122 | FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];\r | |
123 | }\r | |
795bb9b6 SZ |
124 | \r |
125 | if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) {\r | |
126 | FileAttribute |= EFI_FV_FILE_ATTRIB_FIXED;\r | |
127 | }\r | |
128 | \r | |
129 | return FileAttribute;\r | |
130 | }\r | |
131 | \r | |
b1f6a7c6 | 132 | /**\r |
ed299e3c | 133 | Returns the file state set by the highest zero bit in the State field\r |
192f6d4c | 134 | \r |
b1f6a7c6 | 135 | @param ErasePolarity Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY\r |
136 | in the Attributes field.\r | |
137 | @param FfsHeader Pointer to FFS File Header.\r | |
192f6d4c | 138 | \r |
d1102dba | 139 | @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit\r |
ed299e3c | 140 | in the header State field.\r |
b1f6a7c6 | 141 | **/\r |
142 | EFI_FFS_FILE_STATE\r | |
143 | GetFileState(\r | |
144 | IN UINT8 ErasePolarity,\r | |
145 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
146 | )\r | |
192f6d4c | 147 | {\r |
148 | EFI_FFS_FILE_STATE FileState;\r | |
149 | EFI_FFS_FILE_STATE HighestBit;\r | |
150 | \r | |
151 | FileState = FfsHeader->State;\r | |
152 | \r | |
153 | if (ErasePolarity != 0) {\r | |
154 | FileState = (EFI_FFS_FILE_STATE)~FileState;\r | |
155 | }\r | |
d1102dba | 156 | \r |
ed299e3c LG |
157 | //\r |
158 | // Get file state set by its highest none zero bit.\r | |
159 | //\r | |
192f6d4c | 160 | HighestBit = 0x80;\r |
161 | while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r | |
162 | HighestBit >>= 1;\r | |
163 | }\r | |
164 | \r | |
165 | return HighestBit;\r | |
d1102dba | 166 | }\r |
192f6d4c | 167 | \r |
b1f6a7c6 | 168 | /**\r |
169 | Calculates the checksum of the header of a file.\r | |
170 | \r | |
171 | @param FileHeader Pointer to FFS File Header.\r | |
172 | \r | |
173 | @return Checksum of the header.\r | |
b1f6a7c6 | 174 | Zero means the header is good.\r |
175 | Non-zero means the header is bad.\r | |
176 | **/\r | |
192f6d4c | 177 | UINT8\r |
178 | CalculateHeaderChecksum (\r | |
179 | IN EFI_FFS_FILE_HEADER *FileHeader\r | |
180 | )\r | |
192f6d4c | 181 | {\r |
890e5417 | 182 | EFI_FFS_FILE_HEADER2 TestFileHeader;\r |
192f6d4c | 183 | \r |
890e5417 SZ |
184 | if (IS_FFS_FILE2 (FileHeader)) {\r |
185 | CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER2));\r | |
186 | //\r | |
187 | // Ingore State and File field in FFS header.\r | |
188 | //\r | |
189 | TestFileHeader.State = 0;\r | |
190 | TestFileHeader.IntegrityCheck.Checksum.File = 0;\r | |
191 | \r | |
192 | return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER2));\r | |
193 | } else {\r | |
194 | CopyMem (&TestFileHeader, FileHeader, sizeof (EFI_FFS_FILE_HEADER));\r | |
195 | //\r | |
196 | // Ingore State and File field in FFS header.\r | |
197 | //\r | |
198 | TestFileHeader.State = 0;\r | |
199 | TestFileHeader.IntegrityCheck.Checksum.File = 0;\r | |
200 | \r | |
201 | return CalculateSum8 ((CONST UINT8 *) &TestFileHeader, sizeof (EFI_FFS_FILE_HEADER));\r | |
202 | }\r | |
192f6d4c | 203 | }\r |
204 | \r | |
b1f6a7c6 | 205 | /**\r |
3b428ade | 206 | Find FV handler according to FileHandle in that FV.\r |
b1f6a7c6 | 207 | \r |
208 | @param FileHandle Handle of file image\r | |
d1102dba | 209 | \r |
3b428ade | 210 | @return Pointer to instance of PEI_CORE_FV_HANDLE.\r |
b1f6a7c6 | 211 | **/\r |
3b428ade | 212 | PEI_CORE_FV_HANDLE*\r |
213 | FileHandleToVolume (\r | |
214 | IN EFI_PEI_FILE_HANDLE FileHandle\r | |
b0d803fe | 215 | )\r |
216 | {\r | |
217 | UINTN Index;\r | |
218 | PEI_CORE_INSTANCE *PrivateData;\r | |
219 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
01d3a570 | 220 | UINTN BestIndex;\r |
b0d803fe | 221 | \r |
222 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
01d3a570 | 223 | BestIndex = PrivateData->FvCount;\r |
d1102dba | 224 | \r |
01d3a570 LG |
225 | //\r |
226 | // Find the best matched FV image that includes this FileHandle.\r | |
d1102dba | 227 | // FV may include the child FV, and they are in the same continuous space.\r |
01d3a570 LG |
228 | // If FileHandle is from the child FV, the updated logic can find its matched FV.\r |
229 | //\r | |
b0d803fe | 230 | for (Index = 0; Index < PrivateData->FvCount; Index++) {\r |
231 | FwVolHeader = PrivateData->Fv[Index].FvHeader;\r | |
67a58d0f | 232 | if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \\r |
233 | ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r | |
01d3a570 LG |
234 | if (BestIndex == PrivateData->FvCount) {\r |
235 | BestIndex = Index;\r | |
236 | } else {\r | |
237 | if ((UINT64) (UINTN) PrivateData->Fv[BestIndex].FvHeader < (UINT64) (UINTN) FwVolHeader) {\r | |
238 | BestIndex = Index;\r | |
239 | }\r | |
240 | }\r | |
b0d803fe | 241 | }\r |
242 | }\r | |
01d3a570 LG |
243 | \r |
244 | if (BestIndex < PrivateData->FvCount) {\r | |
245 | return &PrivateData->Fv[BestIndex];\r | |
246 | }\r | |
247 | \r | |
3b428ade | 248 | return NULL;\r |
b0d803fe | 249 | }\r |
250 | \r | |
b1f6a7c6 | 251 | /**\r |
ed299e3c | 252 | Given the input file pointer, search for the first matching file in the\r |
b1f6a7c6 | 253 | FFS volume as defined by SearchType. The search starts from FileHeader inside\r |
254 | the Firmware Volume defined by FwVolHeader.\r | |
ed299e3c | 255 | If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r |
d1102dba LG |
256 | If SearchType is PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,\r |
257 | the first PEIM, or COMBINED PEIM or FV file type FFS file will return.\r | |
b1f6a7c6 | 258 | \r |
259 | @param FvHandle Pointer to the FV header of the volume to search\r | |
260 | @param FileName File name\r | |
261 | @param SearchType Filter to find only files of this type.\r | |
262 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
263 | @param FileHandle This parameter must point to a valid FFS volume.\r | |
264 | @param AprioriFile Pointer to AprioriFile image in this FV if has\r | |
b0d803fe | 265 | \r |
b1f6a7c6 | 266 | @return EFI_NOT_FOUND No files matching the search criteria were found\r |
267 | @retval EFI_SUCCESS Success to search given file\r | |
268 | \r | |
269 | **/\r | |
192f6d4c | 270 | EFI_STATUS\r |
3b428ade | 271 | FindFileEx (\r |
b0d803fe | 272 | IN CONST EFI_PEI_FV_HANDLE FvHandle,\r |
273 | IN CONST EFI_GUID *FileName, OPTIONAL\r | |
274 | IN EFI_FV_FILETYPE SearchType,\r | |
275 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle,\r | |
3837e91c | 276 | IN OUT EFI_PEI_FILE_HANDLE *AprioriFile OPTIONAL\r |
192f6d4c | 277 | )\r |
192f6d4c | 278 | {\r |
f95f107c SZ |
279 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r |
280 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader;\r | |
b0d803fe | 281 | EFI_FFS_FILE_HEADER **FileHeader;\r |
282 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r | |
b0d803fe | 283 | UINT32 FileLength;\r |
284 | UINT32 FileOccupiedSize;\r | |
285 | UINT32 FileOffset;\r | |
286 | UINT64 FvLength;\r | |
287 | UINT8 ErasePolarity;\r | |
288 | UINT8 FileState;\r | |
89cd8129 | 289 | UINT8 DataCheckSum;\r |
890e5417 | 290 | BOOLEAN IsFfs3Fv;\r |
d1102dba | 291 | \r |
3b428ade | 292 | //\r |
293 | // Convert the handle of FV to FV header for memory-mapped firmware volume\r | |
294 | //\r | |
295 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FvHandle;\r | |
b0d803fe | 296 | FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;\r |
192f6d4c | 297 | \r |
890e5417 SZ |
298 | IsFfs3Fv = CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid);\r |
299 | \r | |
192f6d4c | 300 | FvLength = FwVolHeader->FvLength;\r |
d976bf31 | 301 | if ((FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r |
192f6d4c | 302 | ErasePolarity = 1;\r |
303 | } else {\r | |
304 | ErasePolarity = 0;\r | |
305 | }\r | |
d1102dba | 306 | \r |
192f6d4c | 307 | //\r |
b0d803fe | 308 | // If FileHeader is not specified (NULL) or FileName is not NULL,\r |
309 | // start with the first file in the firmware volume. Otherwise,\r | |
310 | // start from the FileHeader.\r | |
192f6d4c | 311 | //\r |
b0d803fe | 312 | if ((*FileHeader == NULL) || (FileName != NULL)) {\r |
f95f107c SZ |
313 | if (FwVolHeader->ExtHeaderOffset != 0) {\r |
314 | //\r | |
315 | // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.\r | |
316 | //\r | |
317 | FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->ExtHeaderOffset);\r | |
318 | FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);\r | |
319 | FfsFileHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsFileHeader, 8);\r | |
320 | } else {\r | |
321 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r | |
322 | }\r | |
192f6d4c | 323 | } else {\r |
890e5417 SZ |
324 | if (IS_FFS_FILE2 (*FileHeader)) {\r |
325 | if (!IsFfs3Fv) {\r | |
326 | DEBUG ((EFI_D_ERROR, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &(*FileHeader)->Name));\r | |
327 | }\r | |
328 | FileLength = FFS_FILE2_SIZE (*FileHeader);\r | |
329 | ASSERT (FileLength > 0x00FFFFFF);\r | |
330 | } else {\r | |
331 | FileLength = FFS_FILE_SIZE (*FileHeader);\r | |
332 | }\r | |
192f6d4c | 333 | //\r |
192f6d4c | 334 | // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r |
335 | //\r | |
b0d803fe | 336 | FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r |
192f6d4c | 337 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);\r |
338 | }\r | |
d1102dba | 339 | \r |
192f6d4c | 340 | FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);\r |
341 | ASSERT (FileOffset <= 0xFFFFFFFF);\r | |
e98cd821 | 342 | \r |
b0d803fe | 343 | while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r |
192f6d4c | 344 | //\r |
d1102dba | 345 | // Get FileState which is the highest bit of the State\r |
192f6d4c | 346 | //\r |
347 | FileState = GetFileState (ErasePolarity, FfsFileHeader);\r | |
192f6d4c | 348 | switch (FileState) {\r |
349 | \r | |
890e5417 | 350 | case EFI_FILE_HEADER_CONSTRUCTION:\r |
192f6d4c | 351 | case EFI_FILE_HEADER_INVALID:\r |
890e5417 SZ |
352 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
353 | if (!IsFfs3Fv) {\r | |
354 | DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader->Name));\r | |
355 | }\r | |
356 | FileOffset += sizeof (EFI_FFS_FILE_HEADER2);\r | |
357 | FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER2));\r | |
358 | } else {\r | |
359 | FileOffset += sizeof (EFI_FFS_FILE_HEADER);\r | |
360 | FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r | |
361 | }\r | |
192f6d4c | 362 | break;\r |
d1102dba | 363 | \r |
192f6d4c | 364 | case EFI_FILE_DATA_VALID:\r |
365 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
b0d803fe | 366 | if (CalculateHeaderChecksum (FfsFileHeader) != 0) {\r |
192f6d4c | 367 | ASSERT (FALSE);\r |
e98cd821 | 368 | *FileHeader = NULL;\r |
192f6d4c | 369 | return EFI_NOT_FOUND;\r |
370 | }\r | |
b0d803fe | 371 | \r |
890e5417 SZ |
372 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
373 | FileLength = FFS_FILE2_SIZE (FfsFileHeader);\r | |
374 | ASSERT (FileLength > 0x00FFFFFF);\r | |
375 | FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r | |
376 | if (!IsFfs3Fv) {\r | |
377 | DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader->Name));\r | |
378 | FileOffset += FileOccupiedSize;\r | |
379 | FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r | |
380 | break;\r | |
381 | }\r | |
382 | } else {\r | |
383 | FileLength = FFS_FILE_SIZE (FfsFileHeader);\r | |
384 | FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);\r | |
385 | }\r | |
b0d803fe | 386 | \r |
89cd8129 LG |
387 | DataCheckSum = FFS_FIXED_CHECKSUM;\r |
388 | if ((FfsFileHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {\r | |
890e5417 SZ |
389 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
390 | DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER2), FileLength - sizeof(EFI_FFS_FILE_HEADER2));\r | |
391 | } else {\r | |
392 | DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER));\r | |
393 | }\r | |
89cd8129 LG |
394 | }\r |
395 | if (FfsFileHeader->IntegrityCheck.Checksum.File != DataCheckSum) {\r | |
396 | ASSERT (FALSE);\r | |
397 | *FileHeader = NULL;\r | |
398 | return EFI_NOT_FOUND;\r | |
399 | }\r | |
400 | \r | |
b0d803fe | 401 | if (FileName != NULL) {\r |
402 | if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {\r | |
403 | *FileHeader = FfsFileHeader;\r | |
404 | return EFI_SUCCESS;\r | |
405 | }\r | |
406 | } else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {\r | |
d1102dba | 407 | if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) ||\r |
288f9b38 | 408 | (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r |
d1102dba LG |
409 | (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) {\r |
410 | \r | |
b0d803fe | 411 | *FileHeader = FfsFileHeader;\r |
412 | return EFI_SUCCESS;\r | |
413 | } else if (AprioriFile != NULL) {\r | |
414 | if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {\r | |
415 | if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {\r | |
416 | *AprioriFile = FfsFileHeader;\r | |
d1102dba LG |
417 | }\r |
418 | }\r | |
b0d803fe | 419 | }\r |
d1102dba LG |
420 | } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) &&\r |
421 | (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) {\r | |
b0d803fe | 422 | *FileHeader = FfsFileHeader;\r |
423 | return EFI_SUCCESS;\r | |
424 | }\r | |
425 | \r | |
d1102dba | 426 | FileOffset += FileOccupiedSize;\r |
40f26b8f | 427 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r |
192f6d4c | 428 | break;\r |
d1102dba | 429 | \r |
192f6d4c | 430 | case EFI_FILE_DELETED:\r |
890e5417 SZ |
431 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
432 | if (!IsFfs3Fv) {\r | |
433 | DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader->Name));\r | |
434 | }\r | |
435 | FileLength = FFS_FILE2_SIZE (FfsFileHeader);\r | |
436 | ASSERT (FileLength > 0x00FFFFFF);\r | |
437 | } else {\r | |
438 | FileLength = FFS_FILE_SIZE (FfsFileHeader);\r | |
439 | }\r | |
40f26b8f | 440 | FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);\r |
441 | FileOffset += FileOccupiedSize;\r | |
442 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 443 | break;\r |
444 | \r | |
445 | default:\r | |
e98cd821 | 446 | *FileHeader = NULL;\r |
192f6d4c | 447 | return EFI_NOT_FOUND;\r |
d1102dba | 448 | }\r |
192f6d4c | 449 | }\r |
d1102dba | 450 | \r |
e98cd821 | 451 | *FileHeader = NULL;\r |
d1102dba | 452 | return EFI_NOT_FOUND;\r |
192f6d4c | 453 | }\r |
454 | \r | |
b1f6a7c6 | 455 | /**\r |
b1f6a7c6 | 456 | Initialize PeiCore Fv List.\r |
457 | \r | |
b1f6a7c6 | 458 | @param PrivateData - Pointer to PEI_CORE_INSTANCE.\r |
459 | @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.\r | |
b1f6a7c6 | 460 | **/\r |
d1102dba | 461 | VOID\r |
b0d803fe | 462 | PeiInitializeFv (\r |
463 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
464 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r | |
465 | )\r | |
b0d803fe | 466 | {\r |
3b428ade | 467 | EFI_STATUS Status;\r |
468 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
469 | EFI_PEI_FV_HANDLE FvHandle;\r | |
470 | EFI_FIRMWARE_VOLUME_HEADER *BfvHeader;\r | |
d1102dba | 471 | \r |
b0d803fe | 472 | //\r |
3b428ade | 473 | // Install FV_PPI for FFS2 file system.\r |
b0d803fe | 474 | //\r |
3b428ade | 475 | PeiServicesInstallPpi (&mPeiFfs2FvPpiList);\r |
890e5417 SZ |
476 | \r |
477 | //\r | |
478 | // Install FV_PPI for FFS3 file system.\r | |
479 | //\r | |
480 | PeiServicesInstallPpi (&mPeiFfs3FvPpiList);\r | |
481 | \r | |
3b428ade | 482 | BfvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;\r |
d1102dba | 483 | \r |
3b428ade | 484 | //\r |
485 | // The FV_PPI in BFV's format should be installed.\r | |
486 | //\r | |
487 | Status = PeiServicesLocatePpi (\r | |
488 | &BfvHeader->FileSystemGuid,\r | |
489 | 0,\r | |
490 | NULL,\r | |
491 | (VOID**)&FvPpi\r | |
492 | );\r | |
493 | ASSERT_EFI_ERROR (Status);\r | |
d1102dba | 494 | \r |
3b428ade | 495 | //\r |
496 | // Get handle of BFV\r | |
497 | //\r | |
38c977c1 MW |
498 | Status = FvPpi->ProcessVolume (\r |
499 | FvPpi,\r | |
500 | SecCoreData->BootFirmwareVolumeBase,\r | |
501 | (UINTN)BfvHeader->FvLength,\r | |
502 | &FvHandle\r | |
503 | );\r | |
504 | ASSERT_EFI_ERROR (Status);\r | |
dc6f9b35 | 505 | \r |
506 | //\r | |
507 | // Update internal PEI_CORE_FV array.\r | |
508 | //\r | |
509 | PrivateData->Fv[PrivateData->FvCount].FvHeader = BfvHeader;\r | |
510 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
511 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 512 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = 0;\r |
dc6f9b35 | 513 | DEBUG ((\r |
d1102dba LG |
514 | EFI_D_INFO,\r |
515 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",\r | |
516 | (UINT32) PrivateData->FvCount,\r | |
517 | (VOID *) BfvHeader,\r | |
3958242f | 518 | (UINT32) BfvHeader->FvLength,\r |
dc6f9b35 | 519 | FvHandle\r |
d1102dba | 520 | ));\r |
dc6f9b35 | 521 | PrivateData->FvCount ++;\r |
d1102dba | 522 | \r |
b0d803fe | 523 | //\r |
c7935105 | 524 | // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose\r |
b0d803fe | 525 | // additional Fvs to PeiCore.\r |
526 | //\r | |
c7935105 | 527 | Status = PeiServicesNotifyPpi (mNotifyOnFvInfoList);\r |
b0d803fe | 528 | ASSERT_EFI_ERROR (Status);\r |
529 | \r | |
530 | }\r | |
d1102dba | 531 | \r |
b1f6a7c6 | 532 | /**\r |
c7935105 | 533 | Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.\r |
ed299e3c | 534 | The FV Info will be registered into PeiCore private data structure.\r |
c7935105 | 535 | And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.\r |
b1f6a7c6 | 536 | \r |
ed299e3c | 537 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
731bd38e | 538 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
539 | @param Ppi Address of the PPI that was installed.\r | |
b1f6a7c6 | 540 | \r |
ed299e3c | 541 | @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r |
6a1ae84a | 542 | @return if not EFI_SUCESS, fail to verify FV.\r |
b1f6a7c6 | 543 | \r |
544 | **/\r | |
b0d803fe | 545 | EFI_STATUS\r |
546 | EFIAPI\r | |
547 | FirmwareVolmeInfoPpiNotifyCallback (\r | |
548 | IN EFI_PEI_SERVICES **PeiServices,\r | |
549 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
550 | IN VOID *Ppi\r | |
551 | )\r | |
b0d803fe | 552 | {\r |
c7935105 | 553 | EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi;\r |
3b428ade | 554 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r |
b0d803fe | 555 | PEI_CORE_INSTANCE *PrivateData;\r |
288f9b38 | 556 | EFI_STATUS Status;\r |
3b428ade | 557 | EFI_PEI_FV_HANDLE FvHandle;\r |
558 | UINTN FvIndex;\r | |
dc6f9b35 | 559 | EFI_PEI_FILE_HANDLE FileHandle;\r |
560 | VOID *DepexData;\r | |
387208ab | 561 | BOOLEAN IsFvInfo2;\r |
7147077b ZC |
562 | UINTN CurFvCount;\r |
563 | \r | |
288f9b38 LG |
564 | Status = EFI_SUCCESS;\r |
565 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
b0d803fe | 566 | \r |
c7935105 SZ |
567 | if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiFirmwareVolumeInfo2PpiGuid)) {\r |
568 | //\r | |
569 | // It is FvInfo2PPI.\r | |
570 | //\r | |
571 | CopyMem (&FvInfo2Ppi, Ppi, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI));\r | |
387208ab | 572 | IsFvInfo2 = TRUE;\r |
c7935105 SZ |
573 | } else {\r |
574 | //\r | |
575 | // It is FvInfoPPI.\r | |
576 | //\r | |
577 | CopyMem (&FvInfo2Ppi, Ppi, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI));\r | |
578 | FvInfo2Ppi.AuthenticationStatus = 0;\r | |
387208ab | 579 | IsFvInfo2 = FALSE;\r |
c7935105 | 580 | }\r |
b0d803fe | 581 | \r |
7bd39462 SZ |
582 | if (CompareGuid (&FvInfo2Ppi.FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r |
583 | //\r | |
584 | // gEfiFirmwareFileSystem2Guid is specified for FvFormat, then here to check the\r | |
585 | // FileSystemGuid pointed by FvInfo against gEfiFirmwareFileSystem2Guid to make sure\r | |
586 | // FvInfo has the firmware file system 2 format.\r | |
587 | //\r | |
588 | // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,\r | |
589 | // gEfiFirmwareFileSystem3Guid can be used for firmware file system 3 format, or\r | |
590 | // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both\r | |
591 | // firmware file system 2 and 3 format.\r | |
592 | //\r | |
593 | ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo2Ppi.FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid));\r | |
594 | }\r | |
595 | \r | |
97b2c9b5 | 596 | //\r |
3b428ade | 597 | // Locate the corresponding FV_PPI according to founded FV's format guid\r |
97b2c9b5 | 598 | //\r |
3b428ade | 599 | Status = PeiServicesLocatePpi (\r |
c7935105 SZ |
600 | &FvInfo2Ppi.FvFormat,\r |
601 | 0,\r | |
3b428ade | 602 | NULL,\r |
603 | (VOID**)&FvPpi\r | |
604 | );\r | |
605 | if (!EFI_ERROR (Status)) {\r | |
606 | //\r | |
607 | // Process new found FV and get FV handle.\r | |
608 | //\r | |
c7935105 | 609 | Status = FvPpi->ProcessVolume (FvPpi, FvInfo2Ppi.FvInfo, FvInfo2Ppi.FvInfoSize, &FvHandle);\r |
3b428ade | 610 | if (EFI_ERROR (Status)) {\r |
dc6f9b35 | 611 | DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!\n"));\r |
6a1ae84a | 612 | return Status;\r |
613 | }\r | |
dc6f9b35 | 614 | \r |
615 | //\r | |
616 | // Check whether the FV has already been processed.\r | |
617 | //\r | |
618 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
619 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
387208ab SZ |
620 | if (IsFvInfo2 && (FvInfo2Ppi.AuthenticationStatus != PrivateData->Fv[FvIndex].AuthenticationStatus)) {\r |
621 | PrivateData->Fv[FvIndex].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r | |
d1102dba | 622 | DEBUG ((EFI_D_INFO, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex, FvInfo2Ppi.AuthenticationStatus));\r |
387208ab | 623 | }\r |
c7935105 | 624 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo2Ppi.FvInfo));\r |
dc6f9b35 | 625 | return EFI_SUCCESS;\r |
626 | }\r | |
627 | }\r | |
628 | \r | |
6395c642 LG |
629 | if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
630 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r | |
631 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r | |
632 | ASSERT (FALSE);\r | |
633 | }\r | |
634 | \r | |
dc6f9b35 | 635 | //\r |
636 | // Update internal PEI_CORE_FV array.\r | |
637 | //\r | |
c7935105 | 638 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo2Ppi.FvInfo;\r |
dc6f9b35 | 639 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r |
640 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 641 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r |
7147077b | 642 | CurFvCount = PrivateData->FvCount;\r |
dc6f9b35 | 643 | DEBUG ((\r |
d1102dba LG |
644 | EFI_D_INFO,\r |
645 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",\r | |
7147077b | 646 | (UINT32) CurFvCount,\r |
d1102dba | 647 | (VOID *) FvInfo2Ppi.FvInfo,\r |
c7935105 | 648 | FvInfo2Ppi.FvInfoSize,\r |
dc6f9b35 | 649 | FvHandle\r |
d1102dba | 650 | ));\r |
dc6f9b35 | 651 | PrivateData->FvCount ++;\r |
652 | \r | |
653 | //\r | |
d1102dba | 654 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r |
dc6f9b35 | 655 | //\r |
656 | FileHandle = NULL;\r | |
657 | do {\r | |
658 | Status = FvPpi->FindFileByType (\r | |
659 | FvPpi,\r | |
660 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
661 | FvHandle,\r | |
662 | &FileHandle\r | |
663 | );\r | |
664 | if (!EFI_ERROR (Status)) {\r | |
665 | Status = FvPpi->FindSectionByType (\r | |
666 | FvPpi,\r | |
667 | EFI_SECTION_PEI_DEPEX,\r | |
668 | FileHandle,\r | |
669 | (VOID**)&DepexData\r | |
670 | );\r | |
671 | if (!EFI_ERROR (Status)) {\r | |
672 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
673 | //\r | |
674 | // Dependency is not satisfied.\r | |
675 | //\r | |
676 | continue;\r | |
677 | }\r | |
678 | }\r | |
d1102dba | 679 | \r |
7147077b ZC |
680 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r |
681 | ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r | |
dc6f9b35 | 682 | }\r |
683 | } while (FileHandle != NULL);\r | |
3b428ade | 684 | } else {\r |
c7935105 | 685 | DEBUG ((EFI_D_ERROR, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi.FvInfo));\r |
d1102dba | 686 | \r |
c7935105 | 687 | AddUnknownFormatFvInfo (PrivateData, &FvInfo2Ppi);\r |
288f9b38 | 688 | }\r |
d1102dba | 689 | \r |
b0d803fe | 690 | return EFI_SUCCESS;\r |
691 | }\r | |
692 | \r | |
8472f1f5 SZ |
693 | /**\r |
694 | Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.\r | |
695 | \r | |
696 | @param GuidedSectionGuid The Guided Section GUID.\r | |
697 | @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi\r | |
698 | for the Guided Section.\r | |
699 | \r | |
700 | @return TRUE The GuidedSectionGuid could be identified, and the pointer to\r | |
701 | the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.\r | |
d1102dba | 702 | @return FALSE The GuidedSectionGuid could not be identified, or\r |
8472f1f5 SZ |
703 | the Guided Section Extraction Ppi has not been installed yet.\r |
704 | \r | |
705 | **/\r | |
706 | BOOLEAN\r | |
707 | VerifyGuidedSectionGuid (\r | |
708 | IN EFI_GUID *GuidedSectionGuid,\r | |
709 | OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI **GuidedSectionExtraction\r | |
710 | )\r | |
711 | {\r | |
712 | EFI_PEI_HOB_POINTERS Hob;\r | |
713 | EFI_GUID *GuidRecorded;\r | |
714 | VOID *Interface;\r | |
715 | EFI_STATUS Status;\r | |
716 | \r | |
717 | //\r | |
718 | // Check if there is the Guided Section GUID HOB recorded the GUID itself.\r | |
719 | //\r | |
720 | Hob.Raw = GetFirstGuidHob (GuidedSectionGuid);\r | |
721 | if (Hob.Raw != NULL) {\r | |
722 | GuidRecorded = (EFI_GUID *) GET_GUID_HOB_DATA (Hob);\r | |
723 | if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {\r | |
724 | //\r | |
725 | // Found the recorded GuidedSectionGuid.\r | |
726 | //\r | |
727 | Status = PeiServicesLocatePpi (GuidedSectionGuid, 0, NULL, (VOID **) &Interface);\r | |
728 | if (!EFI_ERROR (Status) && Interface != NULL) {\r | |
729 | //\r | |
730 | // Found the supported Guided Section Extraction Ppi for the Guided Section.\r | |
731 | //\r | |
732 | *GuidedSectionExtraction = (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *) Interface;\r | |
733 | return TRUE;\r | |
734 | }\r | |
735 | return FALSE;\r | |
736 | }\r | |
737 | }\r | |
738 | \r | |
739 | return FALSE;\r | |
740 | }\r | |
741 | \r | |
b1f6a7c6 | 742 | /**\r |
d1102dba LG |
743 | Go through the file to search SectionType section.\r |
744 | Search within encapsulation sections (compression and GUIDed) recursively,\r | |
ed299e3c | 745 | until the match section is found.\r |
d1102dba | 746 | \r |
3b428ade | 747 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
748 | @param SectionType Filter to find only section of this type.\r | |
c7935105 | 749 | @param SectionInstance Pointer to the filter to find the specific instance of section.\r |
3b428ade | 750 | @param Section From where to search.\r |
751 | @param SectionSize The file size to search.\r | |
752 | @param OutputBuffer A pointer to the discovered section, if successful.\r | |
ed299e3c | 753 | NULL if section not found\r |
c7935105 | 754 | @param AuthenticationStatus Updated upon return to point to the authentication status for this section.\r |
890e5417 | 755 | @param IsFfs3Fv Indicates the FV format.\r |
b1f6a7c6 | 756 | \r |
ed299e3c LG |
757 | @return EFI_NOT_FOUND The match section is not found.\r |
758 | @return EFI_SUCCESS The match section is found.\r | |
b1f6a7c6 | 759 | \r |
760 | **/\r | |
b0d803fe | 761 | EFI_STATUS\r |
3b428ade | 762 | ProcessSection (\r |
b0d803fe | 763 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
764 | IN EFI_SECTION_TYPE SectionType,\r | |
c7935105 | 765 | IN OUT UINTN *SectionInstance,\r |
b0d803fe | 766 | IN EFI_COMMON_SECTION_HEADER *Section,\r |
767 | IN UINTN SectionSize,\r | |
890e5417 | 768 | OUT VOID **OutputBuffer,\r |
c7935105 | 769 | OUT UINT32 *AuthenticationStatus,\r |
890e5417 | 770 | IN BOOLEAN IsFfs3Fv\r |
b0d803fe | 771 | )\r |
b0d803fe | 772 | {\r |
773 | EFI_STATUS Status;\r | |
774 | UINT32 SectionLength;\r | |
775 | UINT32 ParsedLength;\r | |
b0d803fe | 776 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r |
b0d803fe | 777 | EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r |
778 | VOID *PpiOutput;\r | |
779 | UINTN PpiOutputSize;\r | |
288f9b38 LG |
780 | UINTN Index;\r |
781 | UINT32 Authentication;\r | |
782 | PEI_CORE_INSTANCE *PrivateData;\r | |
8472f1f5 | 783 | EFI_GUID *SectionDefinitionGuid;\r |
c7935105 SZ |
784 | BOOLEAN SectionCached;\r |
785 | VOID *TempOutputBuffer;\r | |
786 | UINT32 TempAuthenticationStatus;\r | |
9d8de12c | 787 | UINT16 GuidedSectionAttributes;\r |
b0d803fe | 788 | \r |
288f9b38 | 789 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
b0d803fe | 790 | *OutputBuffer = NULL;\r |
288f9b38 LG |
791 | ParsedLength = 0;\r |
792 | Index = 0;\r | |
793 | Status = EFI_NOT_FOUND;\r | |
794 | PpiOutput = NULL;\r | |
795 | PpiOutputSize = 0;\r | |
b0d803fe | 796 | while (ParsedLength < SectionSize) {\r |
890e5417 SZ |
797 | \r |
798 | if (IS_SECTION2 (Section)) {\r | |
799 | ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);\r | |
800 | if (!IsFfs3Fv) {\r | |
801 | DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));\r | |
802 | SectionLength = SECTION2_SIZE (Section);\r | |
803 | //\r | |
804 | // SectionLength is adjusted it is 4 byte aligned.\r | |
805 | // Go to the next section\r | |
806 | //\r | |
807 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
808 | ASSERT (SectionLength != 0);\r | |
809 | ParsedLength += SectionLength;\r | |
810 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);\r | |
811 | continue;\r | |
812 | }\r | |
813 | }\r | |
814 | \r | |
b0d803fe | 815 | if (Section->Type == SectionType) {\r |
c7935105 SZ |
816 | //\r |
817 | // The type matches, so check the instance count to see if it's the one we want.\r | |
818 | //\r | |
819 | (*SectionInstance)--;\r | |
820 | if (*SectionInstance == 0) {\r | |
821 | //\r | |
822 | // Got it!\r | |
823 | //\r | |
824 | if (IS_SECTION2 (Section)) {\r | |
825 | *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r | |
826 | } else {\r | |
827 | *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r | |
828 | }\r | |
829 | return EFI_SUCCESS;\r | |
890e5417 | 830 | } else {\r |
c7935105 SZ |
831 | if (IS_SECTION2 (Section)) {\r |
832 | SectionLength = SECTION2_SIZE (Section);\r | |
833 | } else {\r | |
834 | SectionLength = SECTION_SIZE (Section);\r | |
835 | }\r | |
836 | //\r | |
837 | // SectionLength is adjusted it is 4 byte aligned.\r | |
838 | // Go to the next section\r | |
839 | //\r | |
840 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
841 | ASSERT (SectionLength != 0);\r | |
842 | ParsedLength += SectionLength;\r | |
843 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
844 | continue;\r | |
890e5417 | 845 | }\r |
288f9b38 LG |
846 | } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r |
847 | //\r | |
848 | // Check the encapsulated section is extracted into the cache data.\r | |
849 | //\r | |
c7935105 | 850 | SectionCached = FALSE;\r |
288f9b38 LG |
851 | for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r |
852 | if (Section == PrivateData->CacheSection.Section[Index]) {\r | |
c7935105 | 853 | SectionCached = TRUE;\r |
288f9b38 LG |
854 | PpiOutput = PrivateData->CacheSection.SectionData[Index];\r |
855 | PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r | |
c7935105 | 856 | Authentication = PrivateData->CacheSection.AuthenticationStatus[Index];\r |
288f9b38 LG |
857 | //\r |
858 | // Search section directly from the cache data.\r | |
859 | //\r | |
c7935105 SZ |
860 | TempAuthenticationStatus = 0;\r |
861 | Status = ProcessSection (\r | |
862 | PeiServices,\r | |
863 | SectionType,\r | |
864 | SectionInstance,\r | |
d1102dba LG |
865 | PpiOutput,\r |
866 | PpiOutputSize,\r | |
c7935105 SZ |
867 | &TempOutputBuffer,\r |
868 | &TempAuthenticationStatus,\r | |
869 | IsFfs3Fv\r | |
3b428ade | 870 | );\r |
c7935105 SZ |
871 | if (!EFI_ERROR (Status)) {\r |
872 | *OutputBuffer = TempOutputBuffer;\r | |
873 | *AuthenticationStatus = TempAuthenticationStatus | Authentication;\r | |
874 | return EFI_SUCCESS;\r | |
875 | }\r | |
b0d803fe | 876 | }\r |
877 | }\r | |
c7935105 SZ |
878 | \r |
879 | //\r | |
880 | // If SectionCached is TRUE, the section data has been cached and scanned.\r | |
881 | //\r | |
882 | if (!SectionCached) {\r | |
883 | Status = EFI_NOT_FOUND;\r | |
884 | Authentication = 0;\r | |
885 | if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r | |
886 | if (IS_SECTION2 (Section)) {\r | |
9d8de12c LG |
887 | SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION2 *)Section)->SectionDefinitionGuid;\r |
888 | GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)Section)->Attributes;\r | |
c7935105 | 889 | } else {\r |
9d8de12c LG |
890 | SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid;\r |
891 | GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION *)Section)->Attributes;\r | |
c7935105 SZ |
892 | }\r |
893 | if (VerifyGuidedSectionGuid (SectionDefinitionGuid, &GuidSectionPpi)) {\r | |
894 | Status = GuidSectionPpi->ExtractSection (\r | |
895 | GuidSectionPpi,\r | |
896 | Section,\r | |
897 | &PpiOutput,\r | |
898 | &PpiOutputSize,\r | |
899 | &Authentication\r | |
900 | );\r | |
9d8de12c LG |
901 | } else if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) {\r |
902 | //\r | |
903 | // Figure out the proper authentication status for GUIDED section without processing required\r | |
904 | //\r | |
905 | Status = EFI_SUCCESS;\r | |
906 | if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r | |
907 | Authentication |= EFI_AUTH_STATUS_IMAGE_SIGNED | EFI_AUTH_STATUS_NOT_TESTED;\r | |
908 | }\r | |
909 | if (IS_SECTION2 (Section)) {\r | |
910 | PpiOutputSize = SECTION2_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r | |
911 | PpiOutput = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r | |
912 | } else {\r | |
913 | PpiOutputSize = SECTION_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r | |
914 | PpiOutput = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r | |
915 | }\r | |
c7935105 SZ |
916 | }\r |
917 | } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r | |
918 | Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r | |
919 | if (!EFI_ERROR (Status)) {\r | |
920 | Status = DecompressPpi->Decompress (\r | |
921 | DecompressPpi,\r | |
922 | (CONST EFI_COMPRESSION_SECTION*) Section,\r | |
923 | &PpiOutput,\r | |
924 | &PpiOutputSize\r | |
925 | );\r | |
926 | }\r | |
288f9b38 | 927 | }\r |
c7935105 | 928 | \r |
288f9b38 | 929 | if (!EFI_ERROR (Status)) {\r |
b8654f4d LG |
930 | if ((Authentication & EFI_AUTH_STATUS_NOT_TESTED) == 0) {\r |
931 | //\r | |
932 | // Update cache section data.\r | |
933 | //\r | |
934 | if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r | |
935 | PrivateData->CacheSection.AllSectionCount ++;\r | |
936 | }\r | |
937 | PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r | |
938 | PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r | |
939 | PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r | |
940 | PrivateData->CacheSection.AuthenticationStatus [PrivateData->CacheSection.SectionIndex] = Authentication;\r | |
941 | PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r | |
c7935105 | 942 | }\r |
c7935105 SZ |
943 | \r |
944 | TempAuthenticationStatus = 0;\r | |
945 | Status = ProcessSection (\r | |
946 | PeiServices,\r | |
947 | SectionType,\r | |
948 | SectionInstance,\r | |
d1102dba LG |
949 | PpiOutput,\r |
950 | PpiOutputSize,\r | |
c7935105 SZ |
951 | &TempOutputBuffer,\r |
952 | &TempAuthenticationStatus,\r | |
953 | IsFfs3Fv\r | |
954 | );\r | |
955 | if (!EFI_ERROR (Status)) {\r | |
956 | *OutputBuffer = TempOutputBuffer;\r | |
957 | *AuthenticationStatus = TempAuthenticationStatus | Authentication;\r | |
958 | return EFI_SUCCESS;\r | |
959 | }\r | |
288f9b38 | 960 | }\r |
288f9b38 | 961 | }\r |
b0d803fe | 962 | }\r |
963 | \r | |
890e5417 SZ |
964 | if (IS_SECTION2 (Section)) {\r |
965 | SectionLength = SECTION2_SIZE (Section);\r | |
966 | } else {\r | |
967 | SectionLength = SECTION_SIZE (Section);\r | |
968 | }\r | |
b0d803fe | 969 | //\r |
b0d803fe | 970 | // SectionLength is adjusted it is 4 byte aligned.\r |
971 | // Go to the next section\r | |
972 | //\r | |
b0d803fe | 973 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r |
974 | ASSERT (SectionLength != 0);\r | |
975 | ParsedLength += SectionLength;\r | |
976 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
977 | }\r | |
d1102dba | 978 | \r |
b0d803fe | 979 | return EFI_NOT_FOUND;\r |
980 | }\r | |
981 | \r | |
192f6d4c | 982 | \r |
b1f6a7c6 | 983 | /**\r |
3b428ade | 984 | Searches for the next matching section within the specified file.\r |
b1f6a7c6 | 985 | \r |
ed299e3c | 986 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 987 | @param SectionType Filter to find only sections of this type.\r |
988 | @param FileHandle Pointer to the current file to search.\r | |
ed299e3c | 989 | @param SectionData A pointer to the discovered section, if successful.\r |
b1f6a7c6 | 990 | NULL if section not found\r |
991 | \r | |
3b428ade | 992 | @retval EFI_NOT_FOUND The section was not found.\r |
993 | @retval EFI_SUCCESS The section was found.\r | |
b1f6a7c6 | 994 | \r |
995 | **/\r | |
192f6d4c | 996 | EFI_STATUS\r |
997 | EFIAPI\r | |
998 | PeiFfsFindSectionData (\r | |
3b428ade | 999 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 1000 | IN EFI_SECTION_TYPE SectionType,\r |
0c2b5da8 | 1001 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
3b428ade | 1002 | OUT VOID **SectionData\r |
192f6d4c | 1003 | )\r |
192f6d4c | 1004 | {\r |
3b428ade | 1005 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
d1102dba | 1006 | \r |
3b428ade | 1007 | CoreFvHandle = FileHandleToVolume (FileHandle);\r |
1008 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1009 | return EFI_NOT_FOUND;\r | |
1010 | }\r | |
d1102dba | 1011 | \r |
3b428ade | 1012 | return CoreFvHandle->FvPpi->FindSectionByType (CoreFvHandle->FvPpi, SectionType, FileHandle, SectionData);\r |
192f6d4c | 1013 | }\r |
1014 | \r | |
c7935105 SZ |
1015 | /**\r |
1016 | Searches for the next matching section within the specified file.\r | |
1017 | \r | |
1018 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
1019 | @param SectionType The value of the section type to find.\r | |
1020 | @param SectionInstance Section instance to find.\r | |
1021 | @param FileHandle Handle of the firmware file to search.\r | |
1022 | @param SectionData A pointer to the discovered section, if successful.\r | |
1023 | @param AuthenticationStatus A pointer to the authentication status for this section.\r | |
1024 | \r | |
1025 | @retval EFI_SUCCESS The section was found.\r | |
1026 | @retval EFI_NOT_FOUND The section was not found.\r | |
1027 | \r | |
1028 | **/\r | |
1029 | EFI_STATUS\r | |
1030 | EFIAPI\r | |
1031 | PeiFfsFindSectionData3 (\r | |
1032 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
1033 | IN EFI_SECTION_TYPE SectionType,\r | |
1034 | IN UINTN SectionInstance,\r | |
1035 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1036 | OUT VOID **SectionData,\r | |
1037 | OUT UINT32 *AuthenticationStatus\r | |
1038 | )\r | |
1039 | {\r | |
1040 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
d1102dba | 1041 | \r |
c7935105 SZ |
1042 | CoreFvHandle = FileHandleToVolume (FileHandle);\r |
1043 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1044 | return EFI_NOT_FOUND;\r | |
1045 | }\r | |
1046 | \r | |
1047 | if ((CoreFvHandle->FvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1048 | (CoreFvHandle->FvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1049 | return CoreFvHandle->FvPpi->FindSectionByType2 (CoreFvHandle->FvPpi, SectionType, SectionInstance, FileHandle, SectionData, AuthenticationStatus);\r | |
1050 | }\r | |
1051 | //\r | |
1052 | // The old FvPpi doesn't support to find section by section instance\r | |
1053 | // and return authentication status, so return EFI_UNSUPPORTED.\r | |
1054 | //\r | |
1055 | return EFI_UNSUPPORTED;\r | |
1056 | }\r | |
1057 | \r | |
b1f6a7c6 | 1058 | /**\r |
3b428ade | 1059 | Searches for the next matching file in the firmware volume.\r |
b1f6a7c6 | 1060 | \r |
d73d93c3 | 1061 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 1062 | @param SearchType Filter to find only files of this type.\r |
1063 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
aa75dfec | 1064 | @param FvHandle Handle of firmware volume in which to search.\r |
3b428ade | 1065 | @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start\r |
1066 | at the beginning of the firmware volume. On exit, points the file handle of the next file\r | |
1067 | in the volume or NULL if there are no more files.\r | |
1068 | \r | |
1069 | @retval EFI_NOT_FOUND The file was not found.\r | |
1070 | @retval EFI_NOT_FOUND The header checksum was not zero.\r | |
1071 | @retval EFI_SUCCESS The file was found.\r | |
b1f6a7c6 | 1072 | \r |
1073 | **/\r | |
192f6d4c | 1074 | EFI_STATUS\r |
1075 | EFIAPI\r | |
1076 | PeiFfsFindNextFile (\r | |
0c2b5da8 | 1077 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
1078 | IN UINT8 SearchType,\r | |
3b428ade | 1079 | IN EFI_PEI_FV_HANDLE FvHandle,\r |
0c2b5da8 | 1080 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r |
192f6d4c | 1081 | )\r |
192f6d4c | 1082 | {\r |
3b428ade | 1083 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
d1102dba | 1084 | \r |
3b428ade | 1085 | CoreFvHandle = FvHandleToCoreHandle (FvHandle);\r |
d1102dba | 1086 | \r |
2f016ba8 | 1087 | //\r |
1088 | // To make backward compatiblity, if can not find corresponding the handle of FV\r | |
890e5417 | 1089 | // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed\r |
2f016ba8 | 1090 | // to the address of first byte of FV.\r |
1091 | //\r | |
1092 | if ((CoreFvHandle == NULL) && FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
1093 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r | |
d1102dba LG |
1094 | }\r |
1095 | \r | |
3b428ade | 1096 | if ((CoreFvHandle == NULL) || CoreFvHandle->FvPpi == NULL) {\r |
1097 | return EFI_NOT_FOUND;\r | |
1098 | }\r | |
d1102dba | 1099 | \r |
3b428ade | 1100 | return CoreFvHandle->FvPpi->FindFileByType (CoreFvHandle->FvPpi, SearchType, FvHandle, FileHandle);\r |
192f6d4c | 1101 | }\r |
1102 | \r | |
b0d803fe | 1103 | \r |
b1f6a7c6 | 1104 | /**\r |
ed299e3c | 1105 | Search the firmware volumes by index\r |
b1f6a7c6 | 1106 | \r |
ed299e3c | 1107 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
3b428ade | 1108 | @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware\r |
1109 | Volume (BFV).\r | |
1110 | @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.\r | |
b1f6a7c6 | 1111 | \r |
3b428ade | 1112 | @retval EFI_INVALID_PARAMETER VolumeHandle is NULL\r |
1113 | @retval EFI_NOT_FOUND The volume was not found.\r | |
1114 | @retval EFI_SUCCESS The volume was found.\r | |
b1f6a7c6 | 1115 | \r |
1116 | **/\r | |
d1102dba | 1117 | EFI_STATUS\r |
192f6d4c | 1118 | EFIAPI\r |
3b428ade | 1119 | PeiFfsFindNextVolume (\r |
2a00326e | 1120 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 1121 | IN UINTN Instance,\r |
0c2b5da8 | 1122 | IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r |
192f6d4c | 1123 | )\r |
192f6d4c | 1124 | {\r |
3b428ade | 1125 | PEI_CORE_INSTANCE *Private;\r |
1126 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
d1102dba | 1127 | \r |
3e4c5b49 | 1128 | if (VolumeHandle == NULL) {\r |
1129 | return EFI_INVALID_PARAMETER;\r | |
1130 | }\r | |
d1102dba | 1131 | \r |
b0d803fe | 1132 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
d1102dba | 1133 | \r |
3b428ade | 1134 | CoreFvHandle = FindNextCoreFvHandle (Private, Instance);\r |
1135 | if (CoreFvHandle == NULL) {\r | |
1136 | *VolumeHandle = NULL;\r | |
1137 | return EFI_NOT_FOUND;\r | |
2a00326e | 1138 | }\r |
d1102dba | 1139 | \r |
3b428ade | 1140 | *VolumeHandle = CoreFvHandle->FvHandle;\r |
d1102dba | 1141 | \r |
b0d803fe | 1142 | return EFI_SUCCESS;\r |
1143 | }\r | |
192f6d4c | 1144 | \r |
192f6d4c | 1145 | \r |
b1f6a7c6 | 1146 | /**\r |
ed299e3c | 1147 | Find a file within a volume by its name.\r |
b1f6a7c6 | 1148 | \r |
ed299e3c LG |
1149 | @param FileName A pointer to the name of the file to find within the firmware volume.\r |
1150 | @param VolumeHandle The firmware volume to search\r | |
d1102dba | 1151 | @param FileHandle Upon exit, points to the found file's handle\r |
ed299e3c | 1152 | or NULL if it could not be found.\r |
b1f6a7c6 | 1153 | \r |
ed299e3c LG |
1154 | @retval EFI_SUCCESS File was found.\r |
1155 | @retval EFI_NOT_FOUND File was not found.\r | |
1156 | @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r | |
b1f6a7c6 | 1157 | \r |
b1f6a7c6 | 1158 | **/\r |
b0d803fe | 1159 | EFI_STATUS\r |
d1102dba | 1160 | EFIAPI\r |
b0d803fe | 1161 | PeiFfsFindFileByName (\r |
1162 | IN CONST EFI_GUID *FileName,\r | |
1163 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
1164 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
1165 | )\r | |
b0d803fe | 1166 | {\r |
3b428ade | 1167 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
d1102dba | 1168 | \r |
b0d803fe | 1169 | if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r |
192f6d4c | 1170 | return EFI_INVALID_PARAMETER;\r |
1171 | }\r | |
d1102dba | 1172 | \r |
3b428ade | 1173 | CoreFvHandle = FvHandleToCoreHandle (VolumeHandle);\r |
1174 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1175 | return EFI_NOT_FOUND;\r | |
b0d803fe | 1176 | }\r |
d1102dba | 1177 | \r |
3b428ade | 1178 | return CoreFvHandle->FvPpi->FindFileByName (CoreFvHandle->FvPpi, FileName, &VolumeHandle, FileHandle);\r |
b0d803fe | 1179 | }\r |
1180 | \r | |
b1f6a7c6 | 1181 | /**\r |
b1f6a7c6 | 1182 | Returns information about a specific file.\r |
1183 | \r | |
3b428ade | 1184 | @param FileHandle Handle of the file.\r |
4237d40b | 1185 | @param FileInfo Upon exit, points to the file's information.\r |
b1f6a7c6 | 1186 | \r |
3b428ade | 1187 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r |
1188 | @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r | |
1189 | @retval EFI_SUCCESS File information returned.\r | |
b1f6a7c6 | 1190 | \r |
1191 | **/\r | |
b0d803fe | 1192 | EFI_STATUS\r |
d1102dba | 1193 | EFIAPI\r |
b0d803fe | 1194 | PeiFfsGetFileInfo (\r |
1195 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1196 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
1197 | )\r | |
b0d803fe | 1198 | {\r |
3b428ade | 1199 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
d1102dba | 1200 | \r |
b0d803fe | 1201 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
1202 | return EFI_INVALID_PARAMETER;\r | |
1203 | }\r | |
1204 | \r | |
1205 | //\r | |
1206 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1207 | //\r | |
3b428ade | 1208 | CoreFvHandle = FileHandleToVolume (FileHandle);\r |
1209 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
b0d803fe | 1210 | return EFI_INVALID_PARAMETER;\r |
1211 | }\r | |
1212 | \r | |
3b428ade | 1213 | return CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r |
b0d803fe | 1214 | }\r |
1215 | \r | |
c7935105 SZ |
1216 | /**\r |
1217 | Returns information about a specific file.\r | |
1218 | \r | |
1219 | @param FileHandle Handle of the file.\r | |
1220 | @param FileInfo Upon exit, points to the file's information.\r | |
1221 | \r | |
1222 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1223 | @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r | |
1224 | @retval EFI_SUCCESS File information returned.\r | |
1225 | \r | |
1226 | **/\r | |
1227 | EFI_STATUS\r | |
d1102dba | 1228 | EFIAPI\r |
c7935105 SZ |
1229 | PeiFfsGetFileInfo2 (\r |
1230 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1231 | OUT EFI_FV_FILE_INFO2 *FileInfo\r | |
1232 | )\r | |
1233 | {\r | |
1234 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
d1102dba | 1235 | \r |
c7935105 SZ |
1236 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
1237 | return EFI_INVALID_PARAMETER;\r | |
1238 | }\r | |
1239 | \r | |
1240 | //\r | |
1241 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1242 | //\r | |
1243 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1244 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1245 | return EFI_INVALID_PARAMETER;\r | |
1246 | }\r | |
1247 | \r | |
1248 | if ((CoreFvHandle->FvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1249 | (CoreFvHandle->FvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1250 | return CoreFvHandle->FvPpi->GetFileInfo2 (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r | |
1251 | }\r | |
1252 | //\r | |
1253 | // The old FvPpi doesn't support to return file info with authentication status,\r | |
1254 | // so return EFI_UNSUPPORTED.\r | |
1255 | //\r | |
1256 | return EFI_UNSUPPORTED;\r | |
1257 | }\r | |
b0d803fe | 1258 | \r |
b1f6a7c6 | 1259 | /**\r |
3b428ade | 1260 | Returns information about the specified volume.\r |
b1f6a7c6 | 1261 | \r |
5a9403b8 | 1262 | This function returns information about a specific firmware\r |
1263 | volume, including its name, type, attributes, starting address\r | |
1264 | and size.\r | |
1265 | \r | |
1266 | @param VolumeHandle Handle of the volume.\r | |
1267 | @param VolumeInfo Upon exit, points to the volume's information.\r | |
1268 | \r | |
1269 | @retval EFI_SUCCESS Volume information returned.\r | |
1270 | @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.\r | |
1271 | @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.\r | |
1272 | @retval EFI_SUCCESS Information successfully returned.\r | |
1273 | @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.\r | |
b1f6a7c6 | 1274 | \r |
b1f6a7c6 | 1275 | **/\r |
b0d803fe | 1276 | EFI_STATUS\r |
d1102dba | 1277 | EFIAPI\r |
b0d803fe | 1278 | PeiFfsGetVolumeInfo (\r |
1279 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
1280 | OUT EFI_FV_INFO *VolumeInfo\r | |
1281 | )\r | |
b0d803fe | 1282 | {\r |
3b428ade | 1283 | PEI_CORE_FV_HANDLE *CoreHandle;\r |
d1102dba | 1284 | \r |
8fdcc412 | 1285 | if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) {\r |
b0d803fe | 1286 | return EFI_INVALID_PARAMETER;\r |
192f6d4c | 1287 | }\r |
d1102dba | 1288 | \r |
3b428ade | 1289 | CoreHandle = FvHandleToCoreHandle (VolumeHandle);\r |
d1102dba | 1290 | \r |
3b428ade | 1291 | if ((CoreHandle == NULL) || (CoreHandle->FvPpi == NULL)) {\r |
288f9b38 LG |
1292 | return EFI_INVALID_PARAMETER;\r |
1293 | }\r | |
d1102dba | 1294 | \r |
3b428ade | 1295 | return CoreHandle->FvPpi->GetVolumeInfo (CoreHandle->FvPpi, VolumeHandle, VolumeInfo);\r |
192f6d4c | 1296 | }\r |
b0d803fe | 1297 | \r |
56c909f3 SZ |
1298 | /**\r |
1299 | Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV used size.\r | |
1300 | \r | |
1301 | @param[in] FvHeader Pointer to FV header.\r | |
1302 | @param[out] FvUsedSize Pointer to FV used size returned,\r | |
1303 | only valid if USED_SIZE FV_EXT_TYPE entry is found.\r | |
1304 | @param[out] EraseByte Pointer to erase byte returned,\r | |
1305 | only valid if USED_SIZE FV_EXT_TYPE entry is found.\r | |
1306 | \r | |
1307 | @retval TRUE USED_SIZE FV_EXT_TYPE entry is found,\r | |
1308 | FV used size and erase byte are returned.\r | |
1309 | @retval FALSE No USED_SIZE FV_EXT_TYPE entry found.\r | |
1310 | \r | |
1311 | **/\r | |
1312 | BOOLEAN\r | |
1313 | GetFvUsedSize (\r | |
1314 | IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,\r | |
1315 | OUT UINT32 *FvUsedSize,\r | |
1316 | OUT UINT8 *EraseByte\r | |
1317 | )\r | |
1318 | {\r | |
1319 | UINT16 ExtHeaderOffset;\r | |
1320 | EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHeader;\r | |
1321 | EFI_FIRMWARE_VOLUME_EXT_ENTRY *ExtEntryList;\r | |
1322 | EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *ExtEntryUsedSize;\r | |
1323 | \r | |
1324 | ExtHeaderOffset = ReadUnaligned16 (&FvHeader->ExtHeaderOffset);\r | |
1325 | if (ExtHeaderOffset != 0) {\r | |
1326 | ExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FvHeader + ExtHeaderOffset);\r | |
1327 | ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) (ExtHeader + 1);\r | |
1328 | while ((UINTN) ExtEntryList < ((UINTN) ExtHeader + ReadUnaligned32 (&ExtHeader->ExtHeaderSize))) {\r | |
1329 | if (ReadUnaligned16 (&ExtEntryList->ExtEntryType) == EFI_FV_EXT_TYPE_USED_SIZE_TYPE) {\r | |
1330 | //\r | |
1331 | // USED_SIZE FV_EXT_TYPE entry is found.\r | |
1332 | //\r | |
1333 | ExtEntryUsedSize = (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *) ExtEntryList;\r | |
1334 | *FvUsedSize = ReadUnaligned32 (&ExtEntryUsedSize->UsedSize);\r | |
1335 | if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ERASE_POLARITY) != 0) {\r | |
1336 | *EraseByte = 0xFF;\r | |
1337 | } else {\r | |
1338 | *EraseByte = 0;\r | |
1339 | }\r | |
1340 | DEBUG ((\r | |
1341 | DEBUG_INFO,\r | |
1342 | "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n",\r | |
1343 | FvHeader,\r | |
1344 | *FvUsedSize,\r | |
1345 | *EraseByte\r | |
1346 | ));\r | |
1347 | return TRUE;\r | |
1348 | }\r | |
1349 | ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *)\r | |
1350 | ((UINT8 *) ExtEntryList + ReadUnaligned16 (&ExtEntryList->ExtEntrySize));\r | |
1351 | }\r | |
1352 | }\r | |
1353 | \r | |
1354 | //\r | |
1355 | // No USED_SIZE FV_EXT_TYPE entry found.\r | |
1356 | //\r | |
1357 | return FALSE;\r | |
1358 | }\r | |
1359 | \r | |
4c6486b9 | 1360 | /**\r |
0e042d0a | 1361 | Get Fv image(s) from the FV type file, then install FV INFO(2) ppi, Build FV(2, 3) hob.\r |
4c6486b9 | 1362 | \r |
c7935105 | 1363 | @param PrivateData PeiCore's private data structure\r |
3b428ade | 1364 | @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r |
97b2c9b5 | 1365 | @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r |
4c6486b9 | 1366 | \r |
1367 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
1368 | @retval EFI_SUCCESS Successfully to process it.\r | |
1369 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
c7935105 | 1370 | @retval EFI_SECURITY_VIOLATION Image is illegal\r |
4c6486b9 | 1371 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r |
d1102dba | 1372 | \r |
4c6486b9 | 1373 | **/\r |
1374 | EFI_STATUS\r | |
1375 | ProcessFvFile (\r | |
c7935105 | 1376 | IN PEI_CORE_INSTANCE *PrivateData,\r |
3b428ade | 1377 | IN PEI_CORE_FV_HANDLE *ParentFvCoreHandle,\r |
1378 | IN EFI_PEI_FILE_HANDLE ParentFvFileHandle\r | |
4c6486b9 | 1379 | )\r |
1380 | {\r | |
3b428ade | 1381 | EFI_STATUS Status;\r |
1382 | EFI_FV_INFO ParentFvImageInfo;\r | |
1383 | UINT32 FvAlignment;\r | |
1384 | VOID *NewFvBuffer;\r | |
1385 | EFI_PEI_HOB_POINTERS HobPtr;\r | |
1386 | EFI_PEI_FIRMWARE_VOLUME_PPI *ParentFvPpi;\r | |
1387 | EFI_PEI_FV_HANDLE ParentFvHandle;\r | |
1388 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r | |
1389 | EFI_FV_FILE_INFO FileInfo;\r | |
b4d856a6 | 1390 | UINT64 FvLength;\r |
c7935105 | 1391 | UINT32 AuthenticationStatus;\r |
56c909f3 SZ |
1392 | UINT32 FvUsedSize;\r |
1393 | UINT8 EraseByte;\r | |
0e042d0a | 1394 | UINTN Index;\r |
56c909f3 | 1395 | \r |
4c6486b9 | 1396 | //\r |
1397 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r | |
1398 | // been extracted.\r | |
1399 | //\r | |
1400 | HobPtr.Raw = GetHobList ();\r | |
1401 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
97b2c9b5 | 1402 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r |
4c6486b9 | 1403 | //\r |
1404 | // this FILE has been dispatched, it will not be dispatched again.\r | |
1405 | //\r | |
3b428ade | 1406 | DEBUG ((EFI_D_INFO, "FV file %p has been dispatched!\r\n", ParentFvFileHandle));\r |
4c6486b9 | 1407 | return EFI_SUCCESS;\r |
1408 | }\r | |
1409 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
1410 | }\r | |
1411 | \r | |
3b428ade | 1412 | ParentFvHandle = ParentFvCoreHandle->FvHandle;\r |
1413 | ParentFvPpi = ParentFvCoreHandle->FvPpi;\r | |
d1102dba | 1414 | \r |
4c6486b9 | 1415 | //\r |
0e042d0a | 1416 | // Find FvImage(s) in FvFile\r |
4c6486b9 | 1417 | //\r |
0e042d0a SZ |
1418 | Index = 0;\r |
1419 | do {\r | |
1420 | AuthenticationStatus = 0;\r | |
1421 | if ((ParentFvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1422 | (ParentFvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1423 | Status = ParentFvPpi->FindSectionByType2 (\r | |
1424 | ParentFvPpi,\r | |
1425 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
1426 | Index,\r | |
1427 | ParentFvFileHandle,\r | |
1428 | (VOID **)&FvHeader,\r | |
1429 | &AuthenticationStatus\r | |
1430 | );\r | |
1431 | } else {\r | |
1432 | //\r | |
1433 | // Old FvPpi has no parameter to input SearchInstance,\r | |
1434 | // only one instance is supported.\r | |
1435 | //\r | |
1436 | if (Index > 0) {\r | |
1437 | break;\r | |
1438 | }\r | |
1439 | Status = ParentFvPpi->FindSectionByType (\r | |
1440 | ParentFvPpi,\r | |
1441 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
1442 | ParentFvFileHandle,\r | |
1443 | (VOID **)&FvHeader\r | |
1444 | );\r | |
1445 | }\r | |
1446 | if (EFI_ERROR (Status)) {\r | |
1447 | break;\r | |
3837e91c SZ |
1448 | }\r |
1449 | \r | |
0e042d0a SZ |
1450 | Status = VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandle, AuthenticationStatus);\r |
1451 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
1452 | break;\r | |
1453 | }\r | |
56c909f3 | 1454 | \r |
3837e91c | 1455 | //\r |
0e042d0a SZ |
1456 | // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r |
1457 | // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r | |
1458 | // its initial linked location and maintain its alignment.\r | |
3837e91c | 1459 | //\r |
0e042d0a SZ |
1460 | if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r |
1461 | //\r | |
1462 | // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r | |
1463 | //\r | |
1464 | FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r | |
1465 | if (FvAlignment < 8) {\r | |
1466 | FvAlignment = 8;\r | |
3837e91c | 1467 | }\r |
0e042d0a SZ |
1468 | \r |
1469 | DEBUG ((\r | |
1470 | DEBUG_INFO,\r | |
1471 | "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r | |
1472 | __FUNCTION__,\r | |
1473 | FvHeader,\r | |
1474 | FvAlignment\r | |
1475 | ));\r | |
1476 | \r | |
1477 | //\r | |
1478 | // Check FvImage alignment.\r | |
1479 | //\r | |
1480 | if ((UINTN) FvHeader % FvAlignment != 0) {\r | |
1481 | FvLength = ReadUnaligned64 (&FvHeader->FvLength);\r | |
1482 | NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r | |
1483 | if (NewFvBuffer == NULL) {\r | |
1484 | Status = EFI_OUT_OF_RESOURCES;\r | |
1485 | break;\r | |
1486 | }\r | |
1487 | if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r | |
1488 | //\r | |
1489 | // Copy the used bytes and fill the rest with the erase value.\r | |
1490 | //\r | |
1491 | CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize);\r | |
1492 | SetMem (\r | |
1493 | (UINT8 *) NewFvBuffer + FvUsedSize,\r | |
1494 | (UINTN) (FvLength - FvUsedSize),\r | |
1495 | EraseByte\r | |
1496 | );\r | |
1497 | } else {\r | |
1498 | CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r | |
1499 | }\r | |
1500 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r | |
56c909f3 | 1501 | }\r |
4c6486b9 | 1502 | }\r |
d1102dba | 1503 | \r |
0e042d0a SZ |
1504 | Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r |
1505 | ASSERT_EFI_ERROR (Status);\r | |
d1102dba | 1506 | \r |
0e042d0a SZ |
1507 | Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r |
1508 | ASSERT_EFI_ERROR (Status);\r | |
4c6486b9 | 1509 | \r |
0e042d0a SZ |
1510 | //\r |
1511 | // Install FvInfo(2) Ppi\r | |
1512 | // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated\r | |
1513 | // FVs inherit the proper AuthenticationStatus.\r | |
1514 | //\r | |
1515 | PeiServicesInstallFvInfo2Ppi(\r | |
1516 | &FvHeader->FileSystemGuid,\r | |
1517 | (VOID**)FvHeader,\r | |
1518 | (UINT32)FvHeader->FvLength,\r | |
1519 | &ParentFvImageInfo.FvName,\r | |
1520 | &FileInfo.FileName,\r | |
1521 | AuthenticationStatus\r | |
1522 | );\r | |
1523 | \r | |
1524 | PeiServicesInstallFvInfoPpi (\r | |
1525 | &FvHeader->FileSystemGuid,\r | |
1526 | (VOID**) FvHeader,\r | |
1527 | (UINT32) FvHeader->FvLength,\r | |
1528 | &ParentFvImageInfo.FvName,\r | |
1529 | &FileInfo.FileName\r | |
1530 | );\r | |
4c6486b9 | 1531 | \r |
0e042d0a SZ |
1532 | //\r |
1533 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r | |
1534 | //\r | |
1535 | BuildFvHob (\r | |
1536 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r | |
1537 | FvHeader->FvLength\r | |
1538 | );\r | |
4c6486b9 | 1539 | \r |
0e042d0a SZ |
1540 | //\r |
1541 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
1542 | // encapsulated file again.\r | |
1543 | //\r | |
1544 | BuildFv2Hob (\r | |
1545 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r | |
1546 | FvHeader->FvLength,\r | |
1547 | &ParentFvImageInfo.FvName,\r | |
1548 | &FileInfo.FileName\r | |
1549 | );\r | |
c6037045 | 1550 | \r |
0e042d0a SZ |
1551 | //\r |
1552 | // Build FV3 HOB with authentication status to be propagated to DXE.\r | |
1553 | //\r | |
1554 | BuildFv3Hob (\r | |
1555 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r | |
1556 | FvHeader->FvLength,\r | |
1557 | AuthenticationStatus,\r | |
1558 | TRUE,\r | |
1559 | &ParentFvImageInfo.FvName,\r | |
1560 | &FileInfo.FileName\r | |
1561 | );\r | |
1562 | \r | |
1563 | Index++;\r | |
1564 | } while (TRUE);\r | |
1565 | \r | |
1566 | if (Index > 0) {\r | |
1567 | //\r | |
1568 | // At least one FvImage has been processed successfully.\r | |
1569 | //\r | |
1570 | return EFI_SUCCESS;\r | |
1571 | } else {\r | |
1572 | return Status;\r | |
1573 | }\r | |
4c6486b9 | 1574 | }\r |
1575 | \r | |
3b428ade | 1576 | /**\r |
1577 | Process a firmware volume and create a volume handle.\r | |
1578 | \r | |
1579 | Create a volume handle from the information in the buffer. For\r | |
1580 | memory-mapped firmware volumes, Buffer and BufferSize refer to\r | |
1581 | the start of the firmware volume and the firmware volume size.\r | |
1582 | For non memory-mapped firmware volumes, this points to a\r | |
1583 | buffer which contains the necessary information for creating\r | |
1584 | the firmware volume handle. Normally, these values are derived\r | |
1585 | from the EFI_FIRMWARE_VOLUME_INFO_PPI.\r | |
d1102dba LG |
1586 | \r |
1587 | \r | |
3b428ade | 1588 | @param This Points to this instance of the\r |
1589 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1590 | @param Buffer Points to the start of the buffer.\r | |
1591 | @param BufferSize Size of the buffer.\r | |
1592 | @param FvHandle Points to the returned firmware volume\r | |
1593 | handle. The firmware volume handle must\r | |
d1102dba | 1594 | be unique within the system.\r |
3b428ade | 1595 | \r |
1596 | @retval EFI_SUCCESS Firmware volume handle created.\r | |
1597 | @retval EFI_VOLUME_CORRUPTED Volume was corrupt.\r | |
1598 | \r | |
1599 | **/\r | |
1600 | EFI_STATUS\r | |
1601 | EFIAPI\r | |
890e5417 | 1602 | PeiFfsFvPpiProcessVolume (\r |
3b428ade | 1603 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1604 | IN VOID *Buffer,\r | |
1605 | IN UINTN BufferSize,\r | |
1606 | OUT EFI_PEI_FV_HANDLE *FvHandle\r | |
1607 | )\r | |
1608 | {\r | |
1609 | EFI_STATUS Status;\r | |
d1102dba | 1610 | \r |
dc6f9b35 | 1611 | ASSERT (FvHandle != NULL);\r |
d1102dba | 1612 | \r |
dc6f9b35 | 1613 | if (Buffer == NULL) {\r |
1614 | return EFI_VOLUME_CORRUPTED;\r | |
1615 | }\r | |
d1102dba | 1616 | \r |
3b428ade | 1617 | //\r |
890e5417 | 1618 | // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped\r |
3b428ade | 1619 | // FV image and the handle is pointed to Fv image's buffer.\r |
1620 | //\r | |
1621 | *FvHandle = (EFI_PEI_FV_HANDLE) Buffer;\r | |
d1102dba | 1622 | \r |
3b428ade | 1623 | //\r |
1624 | // Do verify for given FV buffer.\r | |
1625 | //\r | |
1626 | Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*) Buffer);\r | |
1627 | if (EFI_ERROR(Status)) {\r | |
1628 | DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", Buffer));\r | |
1629 | return EFI_VOLUME_CORRUPTED;\r | |
1630 | }\r | |
1631 | \r | |
3b428ade | 1632 | return EFI_SUCCESS;\r |
d1102dba | 1633 | }\r |
3b428ade | 1634 | \r |
1635 | /**\r | |
1636 | Finds the next file of the specified type.\r | |
1637 | \r | |
d1102dba | 1638 | This service enables PEI modules to discover additional firmware files.\r |
3b428ade | 1639 | The FileHandle must be unique within the system.\r |
1640 | \r | |
1641 | @param This Points to this instance of the\r | |
1642 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1643 | @param SearchType A filter to find only files of this type. Type\r | |
1644 | EFI_FV_FILETYPE_ALL causes no filtering to be\r | |
1645 | done.\r | |
1646 | @param FvHandle Handle of firmware volume in which to\r | |
1647 | search.\r | |
1648 | @param FileHandle Points to the current handle from which to\r | |
1649 | begin searching or NULL to start at the\r | |
1650 | beginning of the firmware volume. Updated\r | |
1651 | upon return to reflect the file found.\r | |
1652 | \r | |
1653 | @retval EFI_SUCCESS The file was found.\r | |
1654 | @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.\r | |
1655 | \r | |
1656 | **/\r | |
1657 | EFI_STATUS\r | |
1658 | EFIAPI\r | |
890e5417 | 1659 | PeiFfsFvPpiFindFileByType (\r |
3b428ade | 1660 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1661 | IN EFI_FV_FILETYPE SearchType,\r | |
1662 | IN EFI_PEI_FV_HANDLE FvHandle,\r | |
1663 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
1664 | )\r | |
d1102dba | 1665 | {\r |
3b428ade | 1666 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r |
1667 | }\r | |
1668 | \r | |
1669 | /**\r | |
d1102dba LG |
1670 | Find a file within a volume by its name.\r |
1671 | \r | |
3b428ade | 1672 | This service searches for files with a specific name, within\r |
1673 | either the specified firmware volume or all firmware volumes.\r | |
1674 | \r | |
1675 | @param This Points to this instance of the\r | |
1676 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1677 | @param FileName A pointer to the name of the file to find\r | |
1678 | within the firmware volume.\r | |
1679 | @param FvHandle Upon entry, the pointer to the firmware\r | |
1680 | volume to search or NULL if all firmware\r | |
1681 | volumes should be searched. Upon exit, the\r | |
1682 | actual firmware volume in which the file was\r | |
1683 | found.\r | |
1684 | @param FileHandle Upon exit, points to the found file's\r | |
1685 | handle or NULL if it could not be found.\r | |
1686 | \r | |
1687 | @retval EFI_SUCCESS File was found.\r | |
1688 | @retval EFI_NOT_FOUND File was not found.\r | |
1689 | @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or\r | |
1690 | FileName was NULL.\r | |
1691 | \r | |
1692 | \r | |
1693 | **/\r | |
1694 | EFI_STATUS\r | |
1695 | EFIAPI\r | |
890e5417 | 1696 | PeiFfsFvPpiFindFileByName (\r |
3b428ade | 1697 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1698 | IN CONST EFI_GUID *FileName,\r | |
1699 | IN EFI_PEI_FV_HANDLE *FvHandle,\r | |
d1102dba | 1700 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r |
3b428ade | 1701 | )\r |
1702 | {\r | |
1703 | EFI_STATUS Status;\r | |
1704 | PEI_CORE_INSTANCE *PrivateData;\r | |
1705 | UINTN Index;\r | |
d1102dba | 1706 | \r |
3b428ade | 1707 | if ((FvHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r |
1708 | return EFI_INVALID_PARAMETER;\r | |
1709 | }\r | |
d1102dba | 1710 | \r |
3b428ade | 1711 | if (*FvHandle != NULL) {\r |
1712 | Status = FindFileEx (*FvHandle, FileName, 0, FileHandle, NULL);\r | |
1713 | if (Status == EFI_NOT_FOUND) {\r | |
1714 | *FileHandle = NULL;\r | |
1715 | }\r | |
d1102dba | 1716 | } else {\r |
3b428ade | 1717 | //\r |
1718 | // If *FvHandle = NULL, so search all FV for given filename\r | |
1719 | //\r | |
1720 | Status = EFI_NOT_FOUND;\r | |
d1102dba | 1721 | \r |
3b428ade | 1722 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());\r |
1723 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r | |
1724 | //\r | |
1725 | // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.\r | |
1726 | //\r | |
1727 | if (PrivateData->Fv[Index].FvPpi != NULL) {\r | |
1728 | Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL);\r | |
1729 | if (!EFI_ERROR (Status)) {\r | |
1730 | *FvHandle = PrivateData->Fv[Index].FvHandle;\r | |
1c738c8f | 1731 | break;\r |
3b428ade | 1732 | }\r |
1733 | }\r | |
1734 | }\r | |
1735 | }\r | |
d1102dba LG |
1736 | \r |
1737 | return Status;\r | |
1738 | }\r | |
3b428ade | 1739 | \r |
1740 | /**\r | |
1741 | Returns information about a specific file.\r | |
1742 | \r | |
1743 | This function returns information about a specific\r | |
1744 | file, including its file name, type, attributes, starting\r | |
d1102dba LG |
1745 | address and size.\r |
1746 | \r | |
3b428ade | 1747 | @param This Points to this instance of the\r |
1748 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1749 | @param FileHandle Handle of the file.\r | |
1750 | @param FileInfo Upon exit, points to the file's\r | |
1751 | information.\r | |
1752 | \r | |
1753 | @retval EFI_SUCCESS File information returned.\r | |
1754 | @retval EFI_INVALID_PARAMETER If FileHandle does not\r | |
1755 | represent a valid file.\r | |
1756 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
d1102dba LG |
1757 | \r |
1758 | **/\r | |
3b428ade | 1759 | EFI_STATUS\r |
1760 | EFIAPI\r | |
890e5417 | 1761 | PeiFfsFvPpiGetFileInfo (\r |
d1102dba LG |
1762 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1763 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
3b428ade | 1764 | OUT EFI_FV_FILE_INFO *FileInfo\r |
1765 | )\r | |
1766 | {\r | |
1767 | UINT8 FileState;\r | |
1768 | UINT8 ErasePolarity;\r | |
1769 | EFI_FFS_FILE_HEADER *FileHeader;\r | |
1770 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
890e5417 SZ |
1771 | PEI_FW_VOL_INSTANCE *FwVolInstance;\r |
1772 | \r | |
3b428ade | 1773 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
1774 | return EFI_INVALID_PARAMETER;\r | |
1775 | }\r | |
1776 | \r | |
1777 | //\r | |
1778 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1779 | //\r | |
1780 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1781 | if (CoreFvHandle == NULL) {\r | |
1782 | return EFI_INVALID_PARAMETER;\r | |
1783 | }\r | |
1784 | \r | |
890e5417 SZ |
1785 | FwVolInstance = PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This);\r |
1786 | \r | |
4140a663 | 1787 | if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r |
3b428ade | 1788 | ErasePolarity = 1;\r |
1789 | } else {\r | |
1790 | ErasePolarity = 0;\r | |
1791 | }\r | |
1792 | \r | |
1793 | //\r | |
d1102dba | 1794 | // Get FileState which is the highest bit of the State\r |
3b428ade | 1795 | //\r |
1796 | FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r | |
1797 | \r | |
1798 | switch (FileState) {\r | |
1799 | case EFI_FILE_DATA_VALID:\r | |
1800 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
d1102dba | 1801 | break;\r |
3b428ade | 1802 | default:\r |
1803 | return EFI_INVALID_PARAMETER;\r | |
1804 | }\r | |
1805 | \r | |
1806 | FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r | |
890e5417 SZ |
1807 | if (IS_FFS_FILE2 (FileHeader)) {\r |
1808 | ASSERT (FFS_FILE2_SIZE (FileHeader) > 0x00FFFFFF);\r | |
1809 | if (!FwVolInstance->IsFfs3Fv) {\r | |
1810 | DEBUG ((EFI_D_ERROR, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader->Name));\r | |
1811 | return EFI_INVALID_PARAMETER;\r | |
1812 | }\r | |
1813 | FileInfo->BufferSize = FFS_FILE2_SIZE (FileHeader) - sizeof (EFI_FFS_FILE_HEADER2);\r | |
1814 | FileInfo->Buffer = (UINT8 *) FileHeader + sizeof (EFI_FFS_FILE_HEADER2);\r | |
1815 | } else {\r | |
1816 | FileInfo->BufferSize = FFS_FILE_SIZE (FileHeader) - sizeof (EFI_FFS_FILE_HEADER);\r | |
1817 | FileInfo->Buffer = (UINT8 *) FileHeader + sizeof (EFI_FFS_FILE_HEADER);\r | |
1818 | }\r | |
c7935105 SZ |
1819 | CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r |
1820 | FileInfo->FileType = FileHeader->Type;\r | |
1821 | FileInfo->FileAttributes = FfsAttributes2FvFileAttributes (FileHeader->Attributes);\r | |
1822 | if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {\r | |
1823 | FileInfo->FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;\r | |
1824 | }\r | |
1825 | return EFI_SUCCESS;\r | |
1826 | }\r | |
1827 | \r | |
1828 | /**\r | |
1829 | Returns information about a specific file.\r | |
1830 | \r | |
1831 | This function returns information about a specific\r | |
1832 | file, including its file name, type, attributes, starting\r | |
1833 | address, size and authentication status.\r | |
1834 | \r | |
1835 | @param This Points to this instance of the\r | |
1836 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1837 | @param FileHandle Handle of the file.\r | |
1838 | @param FileInfo Upon exit, points to the file's\r | |
1839 | information.\r | |
1840 | \r | |
1841 | @retval EFI_SUCCESS File information returned.\r | |
1842 | @retval EFI_INVALID_PARAMETER If FileHandle does not\r | |
1843 | represent a valid file.\r | |
1844 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1845 | \r | |
1846 | **/\r | |
1847 | EFI_STATUS\r | |
1848 | EFIAPI\r | |
1849 | PeiFfsFvPpiGetFileInfo2 (\r | |
d1102dba LG |
1850 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1851 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
c7935105 SZ |
1852 | OUT EFI_FV_FILE_INFO2 *FileInfo\r |
1853 | )\r | |
1854 | {\r | |
1855 | EFI_STATUS Status;\r | |
1856 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1857 | \r | |
1858 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
1859 | return EFI_INVALID_PARAMETER;\r | |
1860 | }\r | |
1861 | \r | |
1862 | //\r | |
1863 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1864 | //\r | |
1865 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1866 | if (CoreFvHandle == NULL) {\r | |
1867 | return EFI_INVALID_PARAMETER;\r | |
1868 | }\r | |
1869 | \r | |
1870 | Status = PeiFfsFvPpiGetFileInfo (This, FileHandle, (EFI_FV_FILE_INFO *) FileInfo);\r | |
1871 | if (!EFI_ERROR (Status)) {\r | |
1872 | FileInfo->AuthenticationStatus = CoreFvHandle->AuthenticationStatus;\r | |
1873 | }\r | |
1874 | \r | |
1875 | return Status;\r | |
1876 | }\r | |
1877 | \r | |
3b428ade | 1878 | /**\r |
1879 | This function returns information about the firmware volume.\r | |
d1102dba | 1880 | \r |
3b428ade | 1881 | @param This Points to this instance of the\r |
1882 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1883 | @param FvHandle Handle to the firmware handle.\r | |
1884 | @param VolumeInfo Points to the returned firmware volume\r | |
1885 | information.\r | |
1886 | \r | |
1887 | @retval EFI_SUCCESS Information returned successfully.\r | |
1888 | @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid\r | |
1889 | firmware volume or VolumeInfo is NULL.\r | |
1890 | \r | |
d1102dba | 1891 | **/\r |
3b428ade | 1892 | EFI_STATUS\r |
1893 | EFIAPI\r | |
890e5417 | 1894 | PeiFfsFvPpiGetVolumeInfo (\r |
d1102dba LG |
1895 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1896 | IN EFI_PEI_FV_HANDLE FvHandle,\r | |
3b428ade | 1897 | OUT EFI_FV_INFO *VolumeInfo\r |
1898 | )\r | |
1899 | {\r | |
1900 | EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r | |
1901 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r | |
1902 | \r | |
8fdcc412 | 1903 | if ((VolumeInfo == NULL) || (FvHandle == NULL)) {\r |
3b428ade | 1904 | return EFI_INVALID_PARAMETER;\r |
1905 | }\r | |
d1102dba | 1906 | \r |
3b428ade | 1907 | //\r |
d1102dba LG |
1908 | // VolumeHandle may not align at 8 byte,\r |
1909 | // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte.\r | |
3b428ade | 1910 | // So, Copy FvHeader into the local FvHeader structure.\r |
1911 | //\r | |
1912 | CopyMem (&FwVolHeader, FvHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r | |
1913 | \r | |
1914 | //\r | |
1915 | // Check Fv Image Signature\r | |
1916 | //\r | |
1917 | if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r | |
1918 | return EFI_INVALID_PARAMETER;\r | |
1919 | }\r | |
1920 | \r | |
1921 | ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r | |
1922 | VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r | |
1923 | VolumeInfo->FvStart = (VOID *) FvHandle;\r | |
1924 | VolumeInfo->FvSize = FwVolHeader.FvLength;\r | |
1925 | CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r | |
1926 | \r | |
1927 | if (FwVolHeader.ExtHeaderOffset != 0) {\r | |
1928 | FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FvHandle) + FwVolHeader.ExtHeaderOffset);\r | |
1929 | CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r | |
1930 | }\r | |
d1102dba LG |
1931 | \r |
1932 | return EFI_SUCCESS;\r | |
1933 | }\r | |
3b428ade | 1934 | \r |
1935 | /**\r | |
1936 | Find the next matching section in the firmware file.\r | |
d1102dba | 1937 | \r |
3b428ade | 1938 | This service enables PEI modules to discover sections\r |
1939 | of a given type within a valid file.\r | |
d1102dba | 1940 | \r |
3b428ade | 1941 | @param This Points to this instance of the\r |
1942 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1943 | @param SearchType A filter to find only sections of this\r | |
1944 | type.\r | |
1945 | @param FileHandle Handle of firmware file in which to\r | |
1946 | search.\r | |
890e5417 | 1947 | @param SectionData Updated upon return to point to the\r |
3b428ade | 1948 | section found.\r |
d1102dba | 1949 | \r |
3b428ade | 1950 | @retval EFI_SUCCESS Section was found.\r |
1951 | @retval EFI_NOT_FOUND Section of the specified type was not\r | |
1952 | found. SectionData contains NULL.\r | |
1953 | **/\r | |
1954 | EFI_STATUS\r | |
1955 | EFIAPI\r | |
890e5417 | 1956 | PeiFfsFvPpiFindSectionByType (\r |
3b428ade | 1957 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1958 | IN EFI_SECTION_TYPE SearchType,\r | |
1959 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1960 | OUT VOID **SectionData\r | |
1961 | )\r | |
1962 | {\r | |
c7935105 SZ |
1963 | UINT32 AuthenticationStatus;\r |
1964 | return PeiFfsFvPpiFindSectionByType2 (This, SearchType, 0, FileHandle, SectionData, &AuthenticationStatus);\r | |
1965 | }\r | |
1966 | \r | |
1967 | /**\r | |
1968 | Find the next matching section in the firmware file.\r | |
1969 | \r | |
1970 | This service enables PEI modules to discover sections\r | |
1971 | of a given instance and type within a valid file.\r | |
1972 | \r | |
1973 | @param This Points to this instance of the\r | |
1974 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1975 | @param SearchType A filter to find only sections of this\r | |
1976 | type.\r | |
1977 | @param SearchInstance A filter to find the specific instance\r | |
1978 | of sections.\r | |
1979 | @param FileHandle Handle of firmware file in which to\r | |
1980 | search.\r | |
1981 | @param SectionData Updated upon return to point to the\r | |
1982 | section found.\r | |
1983 | @param AuthenticationStatus Updated upon return to point to the\r | |
1984 | authentication status for this section.\r | |
1985 | \r | |
1986 | @retval EFI_SUCCESS Section was found.\r | |
1987 | @retval EFI_NOT_FOUND Section of the specified type was not\r | |
1988 | found. SectionData contains NULL.\r | |
1989 | **/\r | |
1990 | EFI_STATUS\r | |
1991 | EFIAPI\r | |
1992 | PeiFfsFvPpiFindSectionByType2 (\r | |
1993 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
1994 | IN EFI_SECTION_TYPE SearchType,\r | |
1995 | IN UINTN SearchInstance,\r | |
1996 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1997 | OUT VOID **SectionData,\r | |
1998 | OUT UINT32 *AuthenticationStatus\r | |
1999 | )\r | |
2000 | {\r | |
2001 | EFI_STATUS Status;\r | |
3b428ade | 2002 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r |
2003 | UINT32 FileSize;\r | |
2004 | EFI_COMMON_SECTION_HEADER *Section;\r | |
890e5417 | 2005 | PEI_FW_VOL_INSTANCE *FwVolInstance;\r |
c7935105 SZ |
2006 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
2007 | UINTN Instance;\r | |
2008 | UINT32 ExtractedAuthenticationStatus;\r | |
2009 | \r | |
2010 | if (SectionData == NULL) {\r | |
2011 | return EFI_NOT_FOUND;\r | |
2012 | }\r | |
890e5417 SZ |
2013 | \r |
2014 | FwVolInstance = PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This);\r | |
2015 | \r | |
c7935105 SZ |
2016 | //\r |
2017 | // Retrieve the FirmwareVolume which the file resides in.\r | |
2018 | //\r | |
2019 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
2020 | if (CoreFvHandle == NULL) {\r | |
2021 | return EFI_NOT_FOUND;\r | |
2022 | }\r | |
2023 | \r | |
3b428ade | 2024 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r |
2025 | \r | |
890e5417 SZ |
2026 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
2027 | ASSERT (FFS_FILE2_SIZE (FfsFileHeader) > 0x00FFFFFF);\r | |
2028 | if (!FwVolInstance->IsFfs3Fv) {\r | |
2029 | DEBUG ((EFI_D_ERROR, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader->Name));\r | |
2030 | return EFI_NOT_FOUND;\r | |
2031 | }\r | |
2032 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER2));\r | |
2033 | FileSize = FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER2);\r | |
2034 | } else {\r | |
2035 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r | |
2036 | FileSize = FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER);\r | |
2037 | }\r | |
3b428ade | 2038 | \r |
c7935105 SZ |
2039 | Instance = SearchInstance + 1;\r |
2040 | ExtractedAuthenticationStatus = 0;\r | |
2041 | Status = ProcessSection (\r | |
2042 | GetPeiServicesTablePointer (),\r | |
2043 | SearchType,\r | |
2044 | &Instance,\r | |
d1102dba LG |
2045 | Section,\r |
2046 | FileSize,\r | |
c7935105 SZ |
2047 | SectionData,\r |
2048 | &ExtractedAuthenticationStatus,\r | |
2049 | FwVolInstance->IsFfs3Fv\r | |
2050 | );\r | |
2051 | if (!EFI_ERROR (Status)) {\r | |
2052 | //\r | |
2053 | // Inherit the authentication status.\r | |
2054 | //\r | |
2055 | *AuthenticationStatus = ExtractedAuthenticationStatus | CoreFvHandle->AuthenticationStatus;\r | |
2056 | }\r | |
2057 | return Status;\r | |
2058 | }\r | |
3b428ade | 2059 | \r |
2060 | /**\r | |
2061 | Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.\r | |
d1102dba | 2062 | \r |
3b428ade | 2063 | @param FvHandle The handle of a FV.\r |
d1102dba | 2064 | \r |
3b428ade | 2065 | @retval NULL if can not find.\r |
d1102dba | 2066 | @return Pointer of corresponding PEI_CORE_FV_HANDLE.\r |
3b428ade | 2067 | **/\r |
2068 | PEI_CORE_FV_HANDLE *\r | |
2069 | FvHandleToCoreHandle (\r | |
2070 | IN EFI_PEI_FV_HANDLE FvHandle\r | |
2071 | )\r | |
2072 | {\r | |
2073 | UINTN Index;\r | |
2074 | PEI_CORE_INSTANCE *PrivateData;\r | |
d1102dba LG |
2075 | \r |
2076 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());\r | |
3b428ade | 2077 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r |
2078 | if (FvHandle == PrivateData->Fv[Index].FvHandle) {\r | |
2079 | return &PrivateData->Fv[Index];\r | |
2080 | }\r | |
2081 | }\r | |
d1102dba | 2082 | \r |
3b428ade | 2083 | return NULL;\r |
d1102dba | 2084 | }\r |
3b428ade | 2085 | \r |
2086 | /**\r | |
2087 | Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r | |
d1102dba | 2088 | \r |
3b428ade | 2089 | This routine also will install FvInfo ppi for FV hob in PI ways.\r |
d1102dba | 2090 | \r |
3b428ade | 2091 | @param Private Pointer of PEI_CORE_INSTANCE\r |
2092 | @param Instance The index of FV want to be searched.\r | |
d1102dba | 2093 | \r |
3b428ade | 2094 | @return Instance of PEI_CORE_FV_HANDLE.\r |
2095 | **/\r | |
2096 | PEI_CORE_FV_HANDLE *\r | |
2097 | FindNextCoreFvHandle (\r | |
2098 | IN PEI_CORE_INSTANCE *Private,\r | |
2099 | IN UINTN Instance\r | |
2100 | )\r | |
2101 | {\r | |
2102 | UINTN Index;\r | |
2103 | BOOLEAN Match;\r | |
2104 | EFI_HOB_FIRMWARE_VOLUME *FvHob;\r | |
d1102dba | 2105 | \r |
3b428ade | 2106 | //\r |
2107 | // Handle Framework FvHob and Install FvInfo Ppi for it.\r | |
2108 | //\r | |
2109 | if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
2110 | //\r | |
2111 | // Loop to search the wanted FirmwareVolume which supports FFS\r | |
2112 | //\r | |
2113 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r | |
2114 | while (FvHob != NULL) {\r | |
20ead725 | 2115 | //\r |
2116 | // Search whether FvHob has been installed into PeiCore's FV database.\r | |
2117 | // If found, no need install new FvInfoPpi for it.\r | |
2118 | //\r | |
3b428ade | 2119 | for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r |
2120 | if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r | |
2121 | Match = TRUE;\r | |
2122 | break;\r | |
2123 | }\r | |
2124 | }\r | |
d1102dba | 2125 | \r |
3b428ade | 2126 | //\r |
20ead725 | 2127 | // Search whether FvHob has been cached into PeiCore's Unknown FV database.\r |
2128 | // If found, no need install new FvInfoPpi for it.\r | |
2129 | //\r | |
2130 | if (!Match) {\r | |
2131 | for (Index = 0; Index < Private->UnknownFvInfoCount; Index ++) {\r | |
2132 | if ((UINTN)FvHob->BaseAddress == (UINTN)Private->UnknownFvInfo[Index].FvInfo) {\r | |
2133 | Match = TRUE;\r | |
2134 | break;\r | |
2135 | }\r | |
2136 | }\r | |
2137 | }\r | |
2138 | \r | |
2139 | //\r | |
2140 | // If the Fv in FvHob has not been installed into PeiCore's FV database and has\r | |
2141 | // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi\r | |
2142 | // for it then PeiCore will dispatch it in callback of FvInfoPpi.\r | |
3b428ade | 2143 | //\r |
2144 | if (!Match) {\r | |
2145 | PeiServicesInstallFvInfoPpi (\r | |
2146 | &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r | |
2147 | (VOID *)(UINTN)FvHob->BaseAddress,\r | |
2148 | (UINT32)FvHob->Length,\r | |
2149 | NULL,\r | |
2150 | NULL\r | |
2151 | );\r | |
2152 | }\r | |
d1102dba LG |
2153 | \r |
2154 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength));\r | |
3b428ade | 2155 | }\r |
2156 | }\r | |
2157 | \r | |
fe781940 | 2158 | ASSERT (Private->FvCount <= PcdGet32 (PcdPeiCoreMaxFvSupported));\r |
3b428ade | 2159 | if (Instance >= Private->FvCount) {\r |
2160 | return NULL;\r | |
2161 | }\r | |
4c6486b9 | 2162 | \r |
3b428ade | 2163 | return &Private->Fv[Instance];\r |
d1102dba | 2164 | }\r |
8e0e40ed | 2165 | \r |
2166 | /**\r | |
2167 | After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r | |
d1102dba | 2168 | be re-installed with the instance in permanent memory and all cached FvPpi pointers in\r |
6393d9c8 | 2169 | PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent\r |
8e0e40ed | 2170 | memory.\r |
d1102dba | 2171 | \r |
8e0e40ed | 2172 | @param PrivateData Pointer to PEI_CORE_INSTANCE.\r |
d1102dba | 2173 | **/\r |
8e0e40ed | 2174 | VOID\r |
2175 | PeiReinitializeFv (\r | |
2176 | IN PEI_CORE_INSTANCE *PrivateData\r | |
2177 | )\r | |
2178 | {\r | |
890e5417 | 2179 | VOID *OldFfsFvPpi;\r |
7ec93917 | 2180 | EFI_PEI_PPI_DESCRIPTOR *OldDescriptor;\r |
2181 | UINTN Index;\r | |
2182 | EFI_STATUS Status;\r | |
2183 | \r | |
2184 | //\r | |
2185 | // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which\r | |
2186 | // in flash.\r | |
2187 | //\r | |
2188 | Status = PeiServicesLocatePpi (\r | |
2189 | &gEfiFirmwareFileSystem2Guid,\r | |
2190 | 0,\r | |
2191 | &OldDescriptor,\r | |
890e5417 | 2192 | &OldFfsFvPpi\r |
7ec93917 | 2193 | );\r |
2194 | ASSERT_EFI_ERROR (Status);\r | |
2195 | \r | |
2196 | //\r | |
2197 | // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2\r | |
2198 | // which is shadowed from flash to permanent memory within PeiCore image.\r | |
2199 | //\r | |
2200 | Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs2FvPpiList);\r | |
2201 | ASSERT_EFI_ERROR (Status);\r | |
890e5417 | 2202 | \r |
7ec93917 | 2203 | //\r |
2204 | // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r | |
2205 | //\r | |
fe781940 | 2206 | for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r |
890e5417 SZ |
2207 | if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r |
2208 | PrivateData->Fv[Index].FvPpi = &mPeiFfs2FwVol.Fv;\r | |
7ec93917 | 2209 | }\r |
2210 | }\r | |
890e5417 SZ |
2211 | \r |
2212 | //\r | |
2213 | // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which\r | |
2214 | // in flash.\r | |
2215 | //\r | |
2216 | Status = PeiServicesLocatePpi (\r | |
2217 | &gEfiFirmwareFileSystem3Guid,\r | |
2218 | 0,\r | |
2219 | &OldDescriptor,\r | |
2220 | &OldFfsFvPpi\r | |
2221 | );\r | |
2222 | ASSERT_EFI_ERROR (Status);\r | |
2223 | \r | |
2224 | //\r | |
2225 | // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3\r | |
2226 | // which is shadowed from flash to permanent memory within PeiCore image.\r | |
2227 | //\r | |
2228 | Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs3FvPpiList);\r | |
2229 | ASSERT_EFI_ERROR (Status);\r | |
2230 | \r | |
2231 | //\r | |
2232 | // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r | |
2233 | //\r | |
fe781940 | 2234 | for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r |
890e5417 SZ |
2235 | if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r |
2236 | PrivateData->Fv[Index].FvPpi = &mPeiFfs3FwVol.Fv;\r | |
2237 | }\r | |
2238 | }\r | |
2239 | }\r | |
8e0e40ed | 2240 | \r |
f3358329 | 2241 | /**\r |
2242 | Report the information for a new discoveried FV in unknown third-party format.\r | |
d1102dba | 2243 | \r |
f3358329 | 2244 | If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but\r |
c7935105 | 2245 | the FV in this format has been discoveried, then this FV's information will be cached into\r |
f3358329 | 2246 | PEI_CORE_INSTANCE's UnknownFvInfo array.\r |
2247 | Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI\r | |
2248 | is installed later by platform's PEIM, the original unknown third-party FV will be processed by\r | |
2249 | using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
d1102dba | 2250 | \r |
f3358329 | 2251 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r |
c7935105 | 2252 | @param FvInfo2Ppi Point to FvInfo2 PPI.\r |
d1102dba | 2253 | \r |
f3358329 | 2254 | @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.\r |
2255 | @retval EFI_SUCCESS Success to add the information for unknown FV.\r | |
2256 | **/\r | |
2257 | EFI_STATUS\r | |
2258 | AddUnknownFormatFvInfo (\r | |
c7935105 SZ |
2259 | IN PEI_CORE_INSTANCE *PrivateData,\r |
2260 | IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI *FvInfo2Ppi\r | |
f3358329 | 2261 | )\r |
2262 | {\r | |
2263 | PEI_CORE_UNKNOW_FORMAT_FV_INFO *NewUnknownFv;\r | |
d1102dba | 2264 | \r |
fe781940 | 2265 | if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
f3358329 | 2266 | return EFI_OUT_OF_RESOURCES;\r |
2267 | }\r | |
d1102dba | 2268 | \r |
f3358329 | 2269 | NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];\r |
2270 | PrivateData->UnknownFvInfoCount ++;\r | |
d1102dba | 2271 | \r |
c7935105 SZ |
2272 | CopyGuid (&NewUnknownFv->FvFormat, &FvInfo2Ppi->FvFormat);\r |
2273 | NewUnknownFv->FvInfo = FvInfo2Ppi->FvInfo;\r | |
2274 | NewUnknownFv->FvInfoSize = FvInfo2Ppi->FvInfoSize;\r | |
2275 | NewUnknownFv->AuthenticationStatus = FvInfo2Ppi->AuthenticationStatus;\r | |
f3358329 | 2276 | NewUnknownFv->NotifyDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r |
2277 | NewUnknownFv->NotifyDescriptor.Guid = &NewUnknownFv->FvFormat;\r | |
2278 | NewUnknownFv->NotifyDescriptor.Notify = ThirdPartyFvPpiNotifyCallback;\r | |
d1102dba | 2279 | \r |
f3358329 | 2280 | PeiServicesNotifyPpi (&NewUnknownFv->NotifyDescriptor);\r |
2281 | return EFI_SUCCESS;\r | |
2282 | }\r | |
2283 | \r | |
2284 | /**\r | |
2285 | Find the FV information according to third-party FV format guid.\r | |
d1102dba | 2286 | \r |
f3358329 | 2287 | This routine also will remove the FV information found by given FV format guid from\r |
2288 | PrivateData->UnknownFvInfo[].\r | |
d1102dba | 2289 | \r |
f3358329 | 2290 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r |
2291 | @param Format Point to given FV format guid\r | |
2292 | @param FvInfo On return, the pointer of FV information buffer\r | |
2293 | @param FvInfoSize On return, the size of FV information buffer.\r | |
c7935105 | 2294 | @param AuthenticationStatus On return, the authentication status of FV information buffer.\r |
d1102dba | 2295 | \r |
f3358329 | 2296 | @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI\r |
2297 | @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
2298 | **/\r | |
2299 | EFI_STATUS\r | |
2300 | FindUnknownFormatFvInfo (\r | |
2301 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
2302 | IN EFI_GUID *Format,\r | |
2303 | OUT VOID **FvInfo,\r | |
c7935105 SZ |
2304 | OUT UINT32 *FvInfoSize,\r |
2305 | OUT UINT32 *AuthenticationStatus\r | |
f3358329 | 2306 | )\r |
2307 | {\r | |
2308 | UINTN Index;\r | |
2309 | UINTN Index2;\r | |
2310 | \r | |
2311 | Index = 0;\r | |
2312 | for (; Index < PrivateData->UnknownFvInfoCount; Index ++) {\r | |
2313 | if (CompareGuid (Format, &PrivateData->UnknownFvInfo[Index].FvFormat)) {\r | |
2314 | break;\r | |
2315 | }\r | |
2316 | }\r | |
d1102dba | 2317 | \r |
f3358329 | 2318 | if (Index == PrivateData->UnknownFvInfoCount) {\r |
2319 | return EFI_NOT_FOUND;\r | |
2320 | }\r | |
d1102dba | 2321 | \r |
f3358329 | 2322 | *FvInfo = PrivateData->UnknownFvInfo[Index].FvInfo;\r |
2323 | *FvInfoSize = PrivateData->UnknownFvInfo[Index].FvInfoSize;\r | |
c7935105 | 2324 | *AuthenticationStatus = PrivateData->UnknownFvInfo[Index].AuthenticationStatus;\r |
d1102dba | 2325 | \r |
f3358329 | 2326 | //\r |
2327 | // Remove an entry from UnknownFvInfo array.\r | |
2328 | //\r | |
2329 | Index2 = Index + 1;\r | |
2330 | for (;Index2 < PrivateData->UnknownFvInfoCount; Index2 ++, Index ++) {\r | |
2331 | CopyMem (&PrivateData->UnknownFvInfo[Index], &PrivateData->UnknownFvInfo[Index2], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO));\r | |
2332 | }\r | |
2333 | PrivateData->UnknownFvInfoCount --;\r | |
2334 | return EFI_SUCCESS;\r | |
d1102dba | 2335 | }\r |
f3358329 | 2336 | \r |
2337 | /**\r | |
2338 | Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
d1102dba LG |
2339 | \r |
2340 | When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this\r | |
f3358329 | 2341 | routine is called to process all discoveried FVs in this format.\r |
d1102dba | 2342 | \r |
f3358329 | 2343 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
2344 | @param NotifyDescriptor Address of the notification descriptor data structure.\r | |
2345 | @param Ppi Address of the PPI that was installed.\r | |
d1102dba | 2346 | \r |
f3358329 | 2347 | @retval EFI_SUCCESS The notification callback is processed correctly.\r |
2348 | **/\r | |
2349 | EFI_STATUS\r | |
2350 | EFIAPI\r | |
2351 | ThirdPartyFvPpiNotifyCallback (\r | |
2352 | IN EFI_PEI_SERVICES **PeiServices,\r | |
2353 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
2354 | IN VOID *Ppi\r | |
2355 | )\r | |
2356 | {\r | |
2357 | PEI_CORE_INSTANCE *PrivateData;\r | |
2358 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
2359 | VOID *FvInfo;\r | |
2360 | UINT32 FvInfoSize;\r | |
c7935105 | 2361 | UINT32 AuthenticationStatus;\r |
f3358329 | 2362 | EFI_STATUS Status;\r |
2363 | EFI_PEI_FV_HANDLE FvHandle;\r | |
2364 | BOOLEAN IsProcessed;\r | |
2365 | UINTN FvIndex;\r | |
2366 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
d1102dba | 2367 | VOID *DepexData;\r |
7147077b ZC |
2368 | UINTN CurFvCount;\r |
2369 | \r | |
f3358329 | 2370 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
2371 | FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r | |
d1102dba | 2372 | \r |
f3358329 | 2373 | do {\r |
c7935105 | 2374 | Status = FindUnknownFormatFvInfo (PrivateData, NotifyDescriptor->Guid, &FvInfo, &FvInfoSize, &AuthenticationStatus);\r |
f3358329 | 2375 | if (EFI_ERROR (Status)) {\r |
2376 | return EFI_SUCCESS;\r | |
2377 | }\r | |
d1102dba | 2378 | \r |
f3358329 | 2379 | //\r |
2380 | // Process new found FV and get FV handle.\r | |
2381 | //\r | |
2382 | Status = FvPpi->ProcessVolume (FvPpi, FvInfo, FvInfoSize, &FvHandle);\r | |
2383 | if (EFI_ERROR (Status)) {\r | |
2384 | DEBUG ((EFI_D_ERROR, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo));\r | |
2385 | continue;\r | |
2386 | }\r | |
2387 | \r | |
2388 | //\r | |
2389 | // Check whether the FV has already been processed.\r | |
2390 | //\r | |
2391 | IsProcessed = FALSE;\r | |
2392 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
2393 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
2394 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo));\r | |
2395 | IsProcessed = TRUE;\r | |
2396 | break;\r | |
2397 | }\r | |
2398 | }\r | |
d1102dba | 2399 | \r |
f3358329 | 2400 | if (IsProcessed) {\r |
2401 | continue;\r | |
2402 | }\r | |
d1102dba | 2403 | \r |
fe781940 SZ |
2404 | if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
2405 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r | |
ccf0f68d | 2406 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r |
2407 | ASSERT (FALSE);\r | |
2408 | }\r | |
d1102dba | 2409 | \r |
f3358329 | 2410 | //\r |
2411 | // Update internal PEI_CORE_FV array.\r | |
2412 | //\r | |
2413 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo;\r | |
2414 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
2415 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 2416 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = AuthenticationStatus;\r |
7147077b | 2417 | CurFvCount = PrivateData->FvCount;\r |
f3358329 | 2418 | DEBUG ((\r |
d1102dba LG |
2419 | EFI_D_INFO,\r |
2420 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n",\r | |
7147077b | 2421 | (UINT32) CurFvCount,\r |
d1102dba | 2422 | (VOID *) FvInfo,\r |
f3358329 | 2423 | FvInfoSize,\r |
2424 | FvHandle\r | |
d1102dba | 2425 | ));\r |
f3358329 | 2426 | PrivateData->FvCount ++;\r |
2427 | \r | |
2428 | //\r | |
d1102dba | 2429 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r |
f3358329 | 2430 | //\r |
2431 | FileHandle = NULL;\r | |
2432 | do {\r | |
2433 | Status = FvPpi->FindFileByType (\r | |
2434 | FvPpi,\r | |
2435 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
2436 | FvHandle,\r | |
2437 | &FileHandle\r | |
2438 | );\r | |
2439 | if (!EFI_ERROR (Status)) {\r | |
2440 | Status = FvPpi->FindSectionByType (\r | |
2441 | FvPpi,\r | |
2442 | EFI_SECTION_PEI_DEPEX,\r | |
2443 | FileHandle,\r | |
2444 | (VOID**)&DepexData\r | |
2445 | );\r | |
2446 | if (!EFI_ERROR (Status)) {\r | |
2447 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
2448 | //\r | |
2449 | // Dependency is not satisfied.\r | |
2450 | //\r | |
2451 | continue;\r | |
2452 | }\r | |
2453 | }\r | |
d1102dba | 2454 | \r |
7147077b ZC |
2455 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r |
2456 | ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r | |
f3358329 | 2457 | }\r |
2458 | } while (FileHandle != NULL);\r | |
2459 | } while (TRUE);\r | |
f3358329 | 2460 | }\r |