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