]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | Pei Core Firmware File System service routines.\r |
3 | \r | |
9ddd7d7a | 4 | Copyright (c) 2015 HP Development Company, L.P.\r |
b8654f4d | 5 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 6 | This program and the accompanying materials \r |
192f6d4c | 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 | |
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 | |
22 | FirmwareVolmeInfoPpiNotifyCallback \r | |
23 | },\r | |
24 | {\r | |
25 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
26 | &gEfiPeiFirmwareVolumeInfo2PpiGuid,\r | |
27 | FirmwareVolmeInfoPpiNotifyCallback \r | |
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 |
64 | \r | |
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 |
ed299e3c LG |
139 | @retval EFI_FFS_FILE_STATE File state is set by the highest none zero bit \r |
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 | |
ed299e3c LG |
156 | \r |
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 | |
166 | } \r | |
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 | |
3b428ade | 209 | \r |
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 |
3b428ade | 224 | \r |
01d3a570 LG |
225 | //\r |
226 | // Find the best matched FV image that includes this FileHandle.\r | |
227 | // FV may include the child FV, and they are in the same continuous space. \r | |
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 LG |
255 | If SearchType is EFI_FV_FILETYPE_ALL, the first FFS file will return without check its file type.\r |
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 |
3b428ade | 291 | \r |
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 | |
306 | \r | |
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 | |
e98cd821 | 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 |
345 | // Get FileState which is the highest bit of the State \r | |
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 |
363 | \r | |
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 | |
407 | if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) || \r | |
288f9b38 LG |
408 | (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) ||\r |
409 | (FfsFileHeader->Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE)) { \r | |
b0d803fe | 410 | \r |
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 | |
417 | } \r | |
418 | } \r | |
419 | }\r | |
7e181f2f | 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 | |
40f26b8f | 426 | FileOffset += FileOccupiedSize; \r |
427 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);\r | |
192f6d4c | 428 | break;\r |
429 | \r | |
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 |
192f6d4c | 448 | } \r |
449 | }\r | |
e98cd821 LG |
450 | \r |
451 | *FileHeader = NULL;\r | |
192f6d4c | 452 | return EFI_NOT_FOUND; \r |
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 |
b0d803fe | 461 | VOID \r |
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 | |
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 |
483 | \r | |
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 | |
494 | \r | |
495 | //\r | |
496 | // Get handle of BFV\r | |
497 | //\r | |
498 | FvPpi->ProcessVolume (\r | |
499 | FvPpi, \r | |
500 | SecCoreData->BootFirmwareVolumeBase,\r | |
501 | (UINTN)BfvHeader->FvLength,\r | |
502 | &FvHandle\r | |
503 | );\r | |
dc6f9b35 | 504 | \r |
505 | //\r | |
506 | // Update internal PEI_CORE_FV array.\r | |
507 | //\r | |
508 | PrivateData->Fv[PrivateData->FvCount].FvHeader = BfvHeader;\r | |
509 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
510 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 511 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = 0;\r |
dc6f9b35 | 512 | DEBUG ((\r |
513 | EFI_D_INFO, \r | |
514 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
515 | (UINT32) PrivateData->FvCount, \r | |
516 | (VOID *) BfvHeader, \r | |
517 | BfvHeader->FvLength,\r | |
518 | FvHandle\r | |
519 | )); \r | |
520 | PrivateData->FvCount ++;\r | |
521 | \r | |
b0d803fe | 522 | //\r |
c7935105 | 523 | // Post a call-back for the FvInfoPPI and FvInfo2PPI services to expose\r |
b0d803fe | 524 | // additional Fvs to PeiCore.\r |
525 | //\r | |
c7935105 | 526 | Status = PeiServicesNotifyPpi (mNotifyOnFvInfoList);\r |
b0d803fe | 527 | ASSERT_EFI_ERROR (Status);\r |
528 | \r | |
529 | }\r | |
3b428ade | 530 | \r |
b1f6a7c6 | 531 | /**\r |
c7935105 | 532 | Process Firmware Volum Information once FvInfoPPI or FvInfo2PPI install.\r |
ed299e3c | 533 | The FV Info will be registered into PeiCore private data structure.\r |
c7935105 | 534 | And search the inside FV image, if found, the new FV INFO(2) PPI will be installed.\r |
b1f6a7c6 | 535 | \r |
ed299e3c | 536 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
731bd38e | 537 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
538 | @param Ppi Address of the PPI that was installed.\r | |
b1f6a7c6 | 539 | \r |
ed299e3c | 540 | @retval EFI_SUCCESS The FV Info is registered into PeiCore private data structure.\r |
6a1ae84a | 541 | @return if not EFI_SUCESS, fail to verify FV.\r |
b1f6a7c6 | 542 | \r |
543 | **/\r | |
b0d803fe | 544 | EFI_STATUS\r |
545 | EFIAPI\r | |
546 | FirmwareVolmeInfoPpiNotifyCallback (\r | |
547 | IN EFI_PEI_SERVICES **PeiServices,\r | |
548 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
549 | IN VOID *Ppi\r | |
550 | )\r | |
b0d803fe | 551 | {\r |
c7935105 | 552 | EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI FvInfo2Ppi;\r |
3b428ade | 553 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r |
b0d803fe | 554 | PEI_CORE_INSTANCE *PrivateData;\r |
288f9b38 | 555 | EFI_STATUS Status;\r |
3b428ade | 556 | EFI_PEI_FV_HANDLE FvHandle;\r |
557 | UINTN FvIndex;\r | |
dc6f9b35 | 558 | EFI_PEI_FILE_HANDLE FileHandle;\r |
559 | VOID *DepexData;\r | |
387208ab | 560 | BOOLEAN IsFvInfo2;\r |
7147077b ZC |
561 | UINTN CurFvCount;\r |
562 | \r | |
288f9b38 LG |
563 | Status = EFI_SUCCESS;\r |
564 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
b0d803fe | 565 | \r |
c7935105 SZ |
566 | if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiFirmwareVolumeInfo2PpiGuid)) {\r |
567 | //\r | |
568 | // It is FvInfo2PPI.\r | |
569 | //\r | |
570 | CopyMem (&FvInfo2Ppi, Ppi, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI));\r | |
387208ab | 571 | IsFvInfo2 = TRUE;\r |
c7935105 SZ |
572 | } else {\r |
573 | //\r | |
574 | // It is FvInfoPPI.\r | |
575 | //\r | |
576 | CopyMem (&FvInfo2Ppi, Ppi, sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI));\r | |
577 | FvInfo2Ppi.AuthenticationStatus = 0;\r | |
387208ab | 578 | IsFvInfo2 = FALSE;\r |
c7935105 | 579 | }\r |
b0d803fe | 580 | \r |
7bd39462 SZ |
581 | if (CompareGuid (&FvInfo2Ppi.FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r |
582 | //\r | |
583 | // gEfiFirmwareFileSystem2Guid is specified for FvFormat, then here to check the\r | |
584 | // FileSystemGuid pointed by FvInfo against gEfiFirmwareFileSystem2Guid to make sure\r | |
585 | // FvInfo has the firmware file system 2 format.\r | |
586 | //\r | |
587 | // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,\r | |
588 | // gEfiFirmwareFileSystem3Guid can be used for firmware file system 3 format, or\r | |
589 | // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both\r | |
590 | // firmware file system 2 and 3 format.\r | |
591 | //\r | |
592 | ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo2Ppi.FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid));\r | |
593 | }\r | |
594 | \r | |
97b2c9b5 | 595 | //\r |
3b428ade | 596 | // Locate the corresponding FV_PPI according to founded FV's format guid\r |
97b2c9b5 | 597 | //\r |
3b428ade | 598 | Status = PeiServicesLocatePpi (\r |
c7935105 SZ |
599 | &FvInfo2Ppi.FvFormat,\r |
600 | 0,\r | |
3b428ade | 601 | NULL,\r |
602 | (VOID**)&FvPpi\r | |
603 | );\r | |
604 | if (!EFI_ERROR (Status)) {\r | |
605 | //\r | |
606 | // Process new found FV and get FV handle.\r | |
607 | //\r | |
c7935105 | 608 | Status = FvPpi->ProcessVolume (FvPpi, FvInfo2Ppi.FvInfo, FvInfo2Ppi.FvInfoSize, &FvHandle);\r |
3b428ade | 609 | if (EFI_ERROR (Status)) {\r |
dc6f9b35 | 610 | DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!\n"));\r |
6a1ae84a | 611 | return Status;\r |
612 | }\r | |
dc6f9b35 | 613 | \r |
614 | //\r | |
615 | // Check whether the FV has already been processed.\r | |
616 | //\r | |
617 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
618 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
387208ab SZ |
619 | if (IsFvInfo2 && (FvInfo2Ppi.AuthenticationStatus != PrivateData->Fv[FvIndex].AuthenticationStatus)) {\r |
620 | PrivateData->Fv[FvIndex].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r | |
621 | DEBUG ((EFI_D_INFO, "Update AuthenticationStatus of the %dth FV to 0x%x!\n", FvIndex, FvInfo2Ppi.AuthenticationStatus)); \r | |
622 | }\r | |
c7935105 | 623 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo2Ppi.FvInfo));\r |
dc6f9b35 | 624 | return EFI_SUCCESS;\r |
625 | }\r | |
626 | }\r | |
627 | \r | |
6395c642 LG |
628 | if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
629 | DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r | |
630 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r | |
631 | ASSERT (FALSE);\r | |
632 | }\r | |
633 | \r | |
dc6f9b35 | 634 | //\r |
635 | // Update internal PEI_CORE_FV array.\r | |
636 | //\r | |
c7935105 | 637 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo2Ppi.FvInfo;\r |
dc6f9b35 | 638 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r |
639 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 640 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r |
7147077b | 641 | CurFvCount = PrivateData->FvCount;\r |
dc6f9b35 | 642 | DEBUG ((\r |
643 | EFI_D_INFO, \r | |
644 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
7147077b | 645 | (UINT32) CurFvCount,\r |
c7935105 SZ |
646 | (VOID *) FvInfo2Ppi.FvInfo, \r |
647 | FvInfo2Ppi.FvInfoSize,\r | |
dc6f9b35 | 648 | FvHandle\r |
649 | )); \r | |
650 | PrivateData->FvCount ++;\r | |
651 | \r | |
652 | //\r | |
653 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r | |
654 | //\r | |
655 | FileHandle = NULL;\r | |
656 | do {\r | |
657 | Status = FvPpi->FindFileByType (\r | |
658 | FvPpi,\r | |
659 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
660 | FvHandle,\r | |
661 | &FileHandle\r | |
662 | );\r | |
663 | if (!EFI_ERROR (Status)) {\r | |
664 | Status = FvPpi->FindSectionByType (\r | |
665 | FvPpi,\r | |
666 | EFI_SECTION_PEI_DEPEX,\r | |
667 | FileHandle,\r | |
668 | (VOID**)&DepexData\r | |
669 | );\r | |
670 | if (!EFI_ERROR (Status)) {\r | |
671 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
672 | //\r | |
673 | // Dependency is not satisfied.\r | |
674 | //\r | |
675 | continue;\r | |
676 | }\r | |
677 | }\r | |
678 | \r | |
7147077b ZC |
679 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r |
680 | ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r | |
dc6f9b35 | 681 | }\r |
682 | } while (FileHandle != NULL);\r | |
3b428ade | 683 | } else {\r |
c7935105 | 684 | DEBUG ((EFI_D_ERROR, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfo2Ppi.FvInfo));\r |
6a1ae84a | 685 | \r |
c7935105 | 686 | AddUnknownFormatFvInfo (PrivateData, &FvInfo2Ppi);\r |
288f9b38 | 687 | }\r |
3b428ade | 688 | \r |
b0d803fe | 689 | return EFI_SUCCESS;\r |
690 | }\r | |
691 | \r | |
8472f1f5 SZ |
692 | /**\r |
693 | Verify the Guided Section GUID by checking if there is the Guided Section GUID HOB recorded the GUID itself.\r | |
694 | \r | |
695 | @param GuidedSectionGuid The Guided Section GUID.\r | |
696 | @param GuidedSectionExtraction A pointer to the pointer to the supported Guided Section Extraction Ppi\r | |
697 | for the Guided Section.\r | |
698 | \r | |
699 | @return TRUE The GuidedSectionGuid could be identified, and the pointer to\r | |
700 | the Guided Section Extraction Ppi will be returned to *GuidedSectionExtraction.\r | |
701 | @return FALSE The GuidedSectionGuid could not be identified, or \r | |
702 | the Guided Section Extraction Ppi has not been installed yet.\r | |
703 | \r | |
704 | **/\r | |
705 | BOOLEAN\r | |
706 | VerifyGuidedSectionGuid (\r | |
707 | IN EFI_GUID *GuidedSectionGuid,\r | |
708 | OUT EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI **GuidedSectionExtraction\r | |
709 | )\r | |
710 | {\r | |
711 | EFI_PEI_HOB_POINTERS Hob;\r | |
712 | EFI_GUID *GuidRecorded;\r | |
713 | VOID *Interface;\r | |
714 | EFI_STATUS Status;\r | |
715 | \r | |
716 | //\r | |
717 | // Check if there is the Guided Section GUID HOB recorded the GUID itself.\r | |
718 | //\r | |
719 | Hob.Raw = GetFirstGuidHob (GuidedSectionGuid);\r | |
720 | if (Hob.Raw != NULL) {\r | |
721 | GuidRecorded = (EFI_GUID *) GET_GUID_HOB_DATA (Hob);\r | |
722 | if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {\r | |
723 | //\r | |
724 | // Found the recorded GuidedSectionGuid.\r | |
725 | //\r | |
726 | Status = PeiServicesLocatePpi (GuidedSectionGuid, 0, NULL, (VOID **) &Interface);\r | |
727 | if (!EFI_ERROR (Status) && Interface != NULL) {\r | |
728 | //\r | |
729 | // Found the supported Guided Section Extraction Ppi for the Guided Section.\r | |
730 | //\r | |
731 | *GuidedSectionExtraction = (EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *) Interface;\r | |
732 | return TRUE;\r | |
733 | }\r | |
734 | return FALSE;\r | |
735 | }\r | |
736 | }\r | |
737 | \r | |
738 | return FALSE;\r | |
739 | }\r | |
740 | \r | |
b1f6a7c6 | 741 | /**\r |
ed299e3c LG |
742 | Go through the file to search SectionType section. \r |
743 | Search within encapsulation sections (compression and GUIDed) recursively, \r | |
744 | until the match section is found.\r | |
745 | \r | |
3b428ade | 746 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
747 | @param SectionType Filter to find only section of this type.\r | |
c7935105 | 748 | @param SectionInstance Pointer to the filter to find the specific instance of section.\r |
3b428ade | 749 | @param Section From where to search.\r |
750 | @param SectionSize The file size to search.\r | |
751 | @param OutputBuffer A pointer to the discovered section, if successful.\r | |
ed299e3c | 752 | NULL if section not found\r |
c7935105 | 753 | @param AuthenticationStatus Updated upon return to point to the authentication status for this section.\r |
890e5417 | 754 | @param IsFfs3Fv Indicates the FV format.\r |
b1f6a7c6 | 755 | \r |
ed299e3c LG |
756 | @return EFI_NOT_FOUND The match section is not found.\r |
757 | @return EFI_SUCCESS The match section is found.\r | |
b1f6a7c6 | 758 | \r |
759 | **/\r | |
b0d803fe | 760 | EFI_STATUS\r |
3b428ade | 761 | ProcessSection (\r |
b0d803fe | 762 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
763 | IN EFI_SECTION_TYPE SectionType,\r | |
c7935105 | 764 | IN OUT UINTN *SectionInstance,\r |
b0d803fe | 765 | IN EFI_COMMON_SECTION_HEADER *Section,\r |
766 | IN UINTN SectionSize,\r | |
890e5417 | 767 | OUT VOID **OutputBuffer,\r |
c7935105 | 768 | OUT UINT32 *AuthenticationStatus,\r |
890e5417 | 769 | IN BOOLEAN IsFfs3Fv\r |
b0d803fe | 770 | )\r |
b0d803fe | 771 | {\r |
772 | EFI_STATUS Status;\r | |
773 | UINT32 SectionLength;\r | |
774 | UINT32 ParsedLength;\r | |
b0d803fe | 775 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;\r |
b0d803fe | 776 | EFI_PEI_DECOMPRESS_PPI *DecompressPpi;\r |
777 | VOID *PpiOutput;\r | |
778 | UINTN PpiOutputSize;\r | |
288f9b38 LG |
779 | UINTN Index;\r |
780 | UINT32 Authentication;\r | |
781 | PEI_CORE_INSTANCE *PrivateData;\r | |
8472f1f5 | 782 | EFI_GUID *SectionDefinitionGuid;\r |
c7935105 SZ |
783 | BOOLEAN SectionCached;\r |
784 | VOID *TempOutputBuffer;\r | |
785 | UINT32 TempAuthenticationStatus;\r | |
9d8de12c | 786 | UINT16 GuidedSectionAttributes;\r |
b0d803fe | 787 | \r |
288f9b38 | 788 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
b0d803fe | 789 | *OutputBuffer = NULL;\r |
288f9b38 LG |
790 | ParsedLength = 0;\r |
791 | Index = 0;\r | |
792 | Status = EFI_NOT_FOUND;\r | |
793 | PpiOutput = NULL;\r | |
794 | PpiOutputSize = 0;\r | |
b0d803fe | 795 | while (ParsedLength < SectionSize) {\r |
890e5417 SZ |
796 | \r |
797 | if (IS_SECTION2 (Section)) {\r | |
798 | ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);\r | |
799 | if (!IsFfs3Fv) {\r | |
800 | DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted section in a non-FFS3 formatted FV.\n"));\r | |
801 | SectionLength = SECTION2_SIZE (Section);\r | |
802 | //\r | |
803 | // SectionLength is adjusted it is 4 byte aligned.\r | |
804 | // Go to the next section\r | |
805 | //\r | |
806 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
807 | ASSERT (SectionLength != 0);\r | |
808 | ParsedLength += SectionLength;\r | |
809 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);\r | |
810 | continue;\r | |
811 | }\r | |
812 | }\r | |
813 | \r | |
b0d803fe | 814 | if (Section->Type == SectionType) {\r |
c7935105 SZ |
815 | //\r |
816 | // The type matches, so check the instance count to see if it's the one we want.\r | |
817 | //\r | |
818 | (*SectionInstance)--;\r | |
819 | if (*SectionInstance == 0) {\r | |
820 | //\r | |
821 | // Got it!\r | |
822 | //\r | |
823 | if (IS_SECTION2 (Section)) {\r | |
824 | *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r | |
825 | } else {\r | |
826 | *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r | |
827 | }\r | |
828 | return EFI_SUCCESS;\r | |
890e5417 | 829 | } else {\r |
c7935105 SZ |
830 | if (IS_SECTION2 (Section)) {\r |
831 | SectionLength = SECTION2_SIZE (Section);\r | |
832 | } else {\r | |
833 | SectionLength = SECTION_SIZE (Section);\r | |
834 | }\r | |
835 | //\r | |
836 | // SectionLength is adjusted it is 4 byte aligned.\r | |
837 | // Go to the next section\r | |
838 | //\r | |
839 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r | |
840 | ASSERT (SectionLength != 0);\r | |
841 | ParsedLength += SectionLength;\r | |
842 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
843 | continue;\r | |
890e5417 | 844 | }\r |
288f9b38 LG |
845 | } else if ((Section->Type == EFI_SECTION_GUID_DEFINED) || (Section->Type == EFI_SECTION_COMPRESSION)) {\r |
846 | //\r | |
847 | // Check the encapsulated section is extracted into the cache data.\r | |
848 | //\r | |
c7935105 | 849 | SectionCached = FALSE;\r |
288f9b38 LG |
850 | for (Index = 0; Index < PrivateData->CacheSection.AllSectionCount; Index ++) {\r |
851 | if (Section == PrivateData->CacheSection.Section[Index]) {\r | |
c7935105 | 852 | SectionCached = TRUE;\r |
288f9b38 LG |
853 | PpiOutput = PrivateData->CacheSection.SectionData[Index];\r |
854 | PpiOutputSize = PrivateData->CacheSection.SectionSize[Index];\r | |
c7935105 | 855 | Authentication = PrivateData->CacheSection.AuthenticationStatus[Index];\r |
288f9b38 LG |
856 | //\r |
857 | // Search section directly from the cache data.\r | |
858 | //\r | |
c7935105 SZ |
859 | TempAuthenticationStatus = 0;\r |
860 | Status = ProcessSection (\r | |
861 | PeiServices,\r | |
862 | SectionType,\r | |
863 | SectionInstance,\r | |
864 | PpiOutput, \r | |
865 | PpiOutputSize, \r | |
866 | &TempOutputBuffer,\r | |
867 | &TempAuthenticationStatus,\r | |
868 | IsFfs3Fv\r | |
3b428ade | 869 | );\r |
c7935105 SZ |
870 | if (!EFI_ERROR (Status)) {\r |
871 | *OutputBuffer = TempOutputBuffer;\r | |
872 | *AuthenticationStatus = TempAuthenticationStatus | Authentication;\r | |
873 | return EFI_SUCCESS;\r | |
874 | }\r | |
b0d803fe | 875 | }\r |
876 | }\r | |
c7935105 SZ |
877 | \r |
878 | //\r | |
879 | // If SectionCached is TRUE, the section data has been cached and scanned.\r | |
880 | //\r | |
881 | if (!SectionCached) {\r | |
882 | Status = EFI_NOT_FOUND;\r | |
883 | Authentication = 0;\r | |
884 | if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r | |
885 | if (IS_SECTION2 (Section)) {\r | |
9d8de12c LG |
886 | SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION2 *)Section)->SectionDefinitionGuid;\r |
887 | GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)Section)->Attributes;\r | |
c7935105 | 888 | } else {\r |
9d8de12c LG |
889 | SectionDefinitionGuid = &((EFI_GUID_DEFINED_SECTION *)Section)->SectionDefinitionGuid;\r |
890 | GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION *)Section)->Attributes;\r | |
c7935105 SZ |
891 | }\r |
892 | if (VerifyGuidedSectionGuid (SectionDefinitionGuid, &GuidSectionPpi)) {\r | |
893 | Status = GuidSectionPpi->ExtractSection (\r | |
894 | GuidSectionPpi,\r | |
895 | Section,\r | |
896 | &PpiOutput,\r | |
897 | &PpiOutputSize,\r | |
898 | &Authentication\r | |
899 | );\r | |
9d8de12c LG |
900 | } else if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) {\r |
901 | //\r | |
902 | // Figure out the proper authentication status for GUIDED section without processing required\r | |
903 | //\r | |
904 | Status = EFI_SUCCESS;\r | |
905 | if ((GuidedSectionAttributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {\r | |
906 | Authentication |= EFI_AUTH_STATUS_IMAGE_SIGNED | EFI_AUTH_STATUS_NOT_TESTED;\r | |
907 | }\r | |
908 | if (IS_SECTION2 (Section)) {\r | |
909 | PpiOutputSize = SECTION2_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r | |
910 | PpiOutput = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION2 *) Section)->DataOffset;\r | |
911 | } else {\r | |
912 | PpiOutputSize = SECTION_SIZE (Section) - ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r | |
913 | PpiOutput = (UINT8 *) Section + ((EFI_GUID_DEFINED_SECTION *) Section)->DataOffset;\r | |
914 | }\r | |
c7935105 SZ |
915 | }\r |
916 | } else if (Section->Type == EFI_SECTION_COMPRESSION) {\r | |
917 | Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);\r | |
918 | if (!EFI_ERROR (Status)) {\r | |
919 | Status = DecompressPpi->Decompress (\r | |
920 | DecompressPpi,\r | |
921 | (CONST EFI_COMPRESSION_SECTION*) Section,\r | |
922 | &PpiOutput,\r | |
923 | &PpiOutputSize\r | |
924 | );\r | |
925 | }\r | |
288f9b38 | 926 | }\r |
c7935105 | 927 | \r |
288f9b38 | 928 | if (!EFI_ERROR (Status)) {\r |
b8654f4d LG |
929 | if ((Authentication & EFI_AUTH_STATUS_NOT_TESTED) == 0) {\r |
930 | //\r | |
931 | // Update cache section data.\r | |
932 | //\r | |
933 | if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r | |
934 | PrivateData->CacheSection.AllSectionCount ++;\r | |
935 | }\r | |
936 | PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r | |
937 | PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r | |
938 | PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r | |
939 | PrivateData->CacheSection.AuthenticationStatus [PrivateData->CacheSection.SectionIndex] = Authentication;\r | |
940 | PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r | |
c7935105 | 941 | }\r |
c7935105 SZ |
942 | \r |
943 | TempAuthenticationStatus = 0;\r | |
944 | Status = ProcessSection (\r | |
945 | PeiServices,\r | |
946 | SectionType,\r | |
947 | SectionInstance,\r | |
948 | PpiOutput, \r | |
949 | PpiOutputSize, \r | |
950 | &TempOutputBuffer,\r | |
951 | &TempAuthenticationStatus,\r | |
952 | IsFfs3Fv\r | |
953 | );\r | |
954 | if (!EFI_ERROR (Status)) {\r | |
955 | *OutputBuffer = TempOutputBuffer;\r | |
956 | *AuthenticationStatus = TempAuthenticationStatus | Authentication;\r | |
957 | return EFI_SUCCESS;\r | |
958 | }\r | |
288f9b38 | 959 | }\r |
288f9b38 | 960 | }\r |
b0d803fe | 961 | }\r |
962 | \r | |
890e5417 SZ |
963 | if (IS_SECTION2 (Section)) {\r |
964 | SectionLength = SECTION2_SIZE (Section);\r | |
965 | } else {\r | |
966 | SectionLength = SECTION_SIZE (Section);\r | |
967 | }\r | |
b0d803fe | 968 | //\r |
b0d803fe | 969 | // SectionLength is adjusted it is 4 byte aligned.\r |
970 | // Go to the next section\r | |
971 | //\r | |
b0d803fe | 972 | SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r |
973 | ASSERT (SectionLength != 0);\r | |
974 | ParsedLength += SectionLength;\r | |
975 | Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);\r | |
976 | }\r | |
977 | \r | |
978 | return EFI_NOT_FOUND;\r | |
979 | }\r | |
980 | \r | |
192f6d4c | 981 | \r |
b1f6a7c6 | 982 | /**\r |
3b428ade | 983 | Searches for the next matching section within the specified file.\r |
b1f6a7c6 | 984 | \r |
ed299e3c | 985 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
b1f6a7c6 | 986 | @param SectionType Filter to find only sections of this type.\r |
987 | @param FileHandle Pointer to the current file to search.\r | |
ed299e3c | 988 | @param SectionData A pointer to the discovered section, if successful.\r |
b1f6a7c6 | 989 | NULL if section not found\r |
990 | \r | |
3b428ade | 991 | @retval EFI_NOT_FOUND The section was not found.\r |
992 | @retval EFI_SUCCESS The section was found.\r | |
b1f6a7c6 | 993 | \r |
994 | **/\r | |
192f6d4c | 995 | EFI_STATUS\r |
996 | EFIAPI\r | |
997 | PeiFfsFindSectionData (\r | |
3b428ade | 998 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 999 | IN EFI_SECTION_TYPE SectionType,\r |
0c2b5da8 | 1000 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
3b428ade | 1001 | OUT VOID **SectionData\r |
192f6d4c | 1002 | )\r |
192f6d4c | 1003 | {\r |
3b428ade | 1004 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
1005 | \r | |
1006 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1007 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1008 | return EFI_NOT_FOUND;\r | |
1009 | }\r | |
1010 | \r | |
1011 | return CoreFvHandle->FvPpi->FindSectionByType (CoreFvHandle->FvPpi, SectionType, FileHandle, SectionData);\r | |
192f6d4c | 1012 | }\r |
1013 | \r | |
c7935105 SZ |
1014 | /**\r |
1015 | Searches for the next matching section within the specified file.\r | |
1016 | \r | |
1017 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r | |
1018 | @param SectionType The value of the section type to find.\r | |
1019 | @param SectionInstance Section instance to find.\r | |
1020 | @param FileHandle Handle of the firmware file to search.\r | |
1021 | @param SectionData A pointer to the discovered section, if successful.\r | |
1022 | @param AuthenticationStatus A pointer to the authentication status for this section.\r | |
1023 | \r | |
1024 | @retval EFI_SUCCESS The section was found.\r | |
1025 | @retval EFI_NOT_FOUND The section was not found.\r | |
1026 | \r | |
1027 | **/\r | |
1028 | EFI_STATUS\r | |
1029 | EFIAPI\r | |
1030 | PeiFfsFindSectionData3 (\r | |
1031 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
1032 | IN EFI_SECTION_TYPE SectionType,\r | |
1033 | IN UINTN SectionInstance,\r | |
1034 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1035 | OUT VOID **SectionData,\r | |
1036 | OUT UINT32 *AuthenticationStatus\r | |
1037 | )\r | |
1038 | {\r | |
1039 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1040 | \r | |
1041 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1042 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1043 | return EFI_NOT_FOUND;\r | |
1044 | }\r | |
1045 | \r | |
1046 | if ((CoreFvHandle->FvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1047 | (CoreFvHandle->FvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1048 | return CoreFvHandle->FvPpi->FindSectionByType2 (CoreFvHandle->FvPpi, SectionType, SectionInstance, FileHandle, SectionData, AuthenticationStatus);\r | |
1049 | }\r | |
1050 | //\r | |
1051 | // The old FvPpi doesn't support to find section by section instance\r | |
1052 | // and return authentication status, so return EFI_UNSUPPORTED.\r | |
1053 | //\r | |
1054 | return EFI_UNSUPPORTED;\r | |
1055 | }\r | |
1056 | \r | |
b1f6a7c6 | 1057 | /**\r |
3b428ade | 1058 | Searches for the next matching file in the firmware volume.\r |
b1f6a7c6 | 1059 | \r |
d73d93c3 | 1060 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 1061 | @param SearchType Filter to find only files of this type.\r |
1062 | Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r | |
aa75dfec | 1063 | @param FvHandle Handle of firmware volume in which to search.\r |
3b428ade | 1064 | @param FileHandle On entry, points to the current handle from which to begin searching or NULL to start\r |
1065 | at the beginning of the firmware volume. On exit, points the file handle of the next file\r | |
1066 | in the volume or NULL if there are no more files.\r | |
1067 | \r | |
1068 | @retval EFI_NOT_FOUND The file was not found.\r | |
1069 | @retval EFI_NOT_FOUND The header checksum was not zero.\r | |
1070 | @retval EFI_SUCCESS The file was found.\r | |
b1f6a7c6 | 1071 | \r |
1072 | **/\r | |
192f6d4c | 1073 | EFI_STATUS\r |
1074 | EFIAPI\r | |
1075 | PeiFfsFindNextFile (\r | |
0c2b5da8 | 1076 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
1077 | IN UINT8 SearchType,\r | |
3b428ade | 1078 | IN EFI_PEI_FV_HANDLE FvHandle,\r |
0c2b5da8 | 1079 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r |
192f6d4c | 1080 | )\r |
192f6d4c | 1081 | {\r |
3b428ade | 1082 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
1083 | \r | |
1084 | CoreFvHandle = FvHandleToCoreHandle (FvHandle);\r | |
1085 | \r | |
2f016ba8 | 1086 | //\r |
1087 | // To make backward compatiblity, if can not find corresponding the handle of FV\r | |
890e5417 | 1088 | // then treat FV as build-in FFS2/FFS3 format and memory mapped FV that FV handle is pointed\r |
2f016ba8 | 1089 | // to the address of first byte of FV.\r |
1090 | //\r | |
1091 | if ((CoreFvHandle == NULL) && FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
1092 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r | |
1093 | } \r | |
1094 | \r | |
3b428ade | 1095 | if ((CoreFvHandle == NULL) || CoreFvHandle->FvPpi == NULL) {\r |
1096 | return EFI_NOT_FOUND;\r | |
1097 | }\r | |
1098 | \r | |
1099 | return CoreFvHandle->FvPpi->FindFileByType (CoreFvHandle->FvPpi, SearchType, FvHandle, FileHandle);\r | |
192f6d4c | 1100 | }\r |
1101 | \r | |
b0d803fe | 1102 | \r |
b1f6a7c6 | 1103 | /**\r |
ed299e3c | 1104 | Search the firmware volumes by index\r |
b1f6a7c6 | 1105 | \r |
ed299e3c | 1106 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
3b428ade | 1107 | @param Instance This instance of the firmware volume to find. The value 0 is the Boot Firmware\r |
1108 | Volume (BFV).\r | |
1109 | @param VolumeHandle On exit, points to the next volume handle or NULL if it does not exist.\r | |
b1f6a7c6 | 1110 | \r |
3b428ade | 1111 | @retval EFI_INVALID_PARAMETER VolumeHandle is NULL\r |
1112 | @retval EFI_NOT_FOUND The volume was not found.\r | |
1113 | @retval EFI_SUCCESS The volume was found.\r | |
b1f6a7c6 | 1114 | \r |
1115 | **/\r | |
192f6d4c | 1116 | EFI_STATUS \r |
1117 | EFIAPI\r | |
3b428ade | 1118 | PeiFfsFindNextVolume (\r |
2a00326e | 1119 | IN CONST EFI_PEI_SERVICES **PeiServices,\r |
192f6d4c | 1120 | IN UINTN Instance,\r |
0c2b5da8 | 1121 | IN OUT EFI_PEI_FV_HANDLE *VolumeHandle\r |
192f6d4c | 1122 | )\r |
192f6d4c | 1123 | {\r |
3b428ade | 1124 | PEI_CORE_INSTANCE *Private;\r |
1125 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1126 | \r | |
3e4c5b49 | 1127 | if (VolumeHandle == NULL) {\r |
1128 | return EFI_INVALID_PARAMETER;\r | |
1129 | }\r | |
1130 | \r | |
b0d803fe | 1131 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
2a00326e | 1132 | \r |
3b428ade | 1133 | CoreFvHandle = FindNextCoreFvHandle (Private, Instance);\r |
1134 | if (CoreFvHandle == NULL) {\r | |
1135 | *VolumeHandle = NULL;\r | |
1136 | return EFI_NOT_FOUND;\r | |
2a00326e | 1137 | }\r |
3b428ade | 1138 | \r |
1139 | *VolumeHandle = CoreFvHandle->FvHandle;\r | |
1140 | \r | |
b0d803fe | 1141 | return EFI_SUCCESS;\r |
1142 | }\r | |
192f6d4c | 1143 | \r |
192f6d4c | 1144 | \r |
b1f6a7c6 | 1145 | /**\r |
ed299e3c | 1146 | Find a file within a volume by its name.\r |
b1f6a7c6 | 1147 | \r |
ed299e3c LG |
1148 | @param FileName A pointer to the name of the file to find within the firmware volume.\r |
1149 | @param VolumeHandle The firmware volume to search\r | |
1150 | @param FileHandle Upon exit, points to the found file's handle \r | |
1151 | or NULL if it could not be found.\r | |
b1f6a7c6 | 1152 | \r |
ed299e3c LG |
1153 | @retval EFI_SUCCESS File was found.\r |
1154 | @retval EFI_NOT_FOUND File was not found.\r | |
1155 | @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or FileName was NULL.\r | |
b1f6a7c6 | 1156 | \r |
b1f6a7c6 | 1157 | **/\r |
b0d803fe | 1158 | EFI_STATUS\r |
1159 | EFIAPI \r | |
1160 | PeiFfsFindFileByName (\r | |
1161 | IN CONST EFI_GUID *FileName,\r | |
1162 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
1163 | OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
1164 | )\r | |
b0d803fe | 1165 | {\r |
3b428ade | 1166 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
1167 | \r | |
b0d803fe | 1168 | if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r |
192f6d4c | 1169 | return EFI_INVALID_PARAMETER;\r |
1170 | }\r | |
3b428ade | 1171 | \r |
1172 | CoreFvHandle = FvHandleToCoreHandle (VolumeHandle);\r | |
1173 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1174 | return EFI_NOT_FOUND;\r | |
b0d803fe | 1175 | }\r |
3b428ade | 1176 | \r |
1177 | return CoreFvHandle->FvPpi->FindFileByName (CoreFvHandle->FvPpi, FileName, &VolumeHandle, FileHandle);\r | |
b0d803fe | 1178 | }\r |
1179 | \r | |
b1f6a7c6 | 1180 | /**\r |
b1f6a7c6 | 1181 | Returns information about a specific file.\r |
1182 | \r | |
3b428ade | 1183 | @param FileHandle Handle of the file.\r |
4237d40b | 1184 | @param FileInfo Upon exit, points to the file's information.\r |
b1f6a7c6 | 1185 | \r |
3b428ade | 1186 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r |
1187 | @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r | |
1188 | @retval EFI_SUCCESS File information returned.\r | |
b1f6a7c6 | 1189 | \r |
1190 | **/\r | |
b0d803fe | 1191 | EFI_STATUS\r |
1192 | EFIAPI \r | |
1193 | PeiFfsGetFileInfo (\r | |
1194 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1195 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
1196 | )\r | |
b0d803fe | 1197 | {\r |
3b428ade | 1198 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
1199 | \r | |
b0d803fe | 1200 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
1201 | return EFI_INVALID_PARAMETER;\r | |
1202 | }\r | |
1203 | \r | |
1204 | //\r | |
1205 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1206 | //\r | |
3b428ade | 1207 | CoreFvHandle = FileHandleToVolume (FileHandle);\r |
1208 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
b0d803fe | 1209 | return EFI_INVALID_PARAMETER;\r |
1210 | }\r | |
1211 | \r | |
3b428ade | 1212 | return CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r |
b0d803fe | 1213 | }\r |
1214 | \r | |
c7935105 SZ |
1215 | /**\r |
1216 | Returns information about a specific file.\r | |
1217 | \r | |
1218 | @param FileHandle Handle of the file.\r | |
1219 | @param FileInfo Upon exit, points to the file's information.\r | |
1220 | \r | |
1221 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1222 | @retval EFI_INVALID_PARAMETER If FileHandle does not represent a valid file.\r | |
1223 | @retval EFI_SUCCESS File information returned.\r | |
1224 | \r | |
1225 | **/\r | |
1226 | EFI_STATUS\r | |
1227 | EFIAPI \r | |
1228 | PeiFfsGetFileInfo2 (\r | |
1229 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1230 | OUT EFI_FV_FILE_INFO2 *FileInfo\r | |
1231 | )\r | |
1232 | {\r | |
1233 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1234 | \r | |
1235 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
1236 | return EFI_INVALID_PARAMETER;\r | |
1237 | }\r | |
1238 | \r | |
1239 | //\r | |
1240 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1241 | //\r | |
1242 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1243 | if ((CoreFvHandle == NULL) || (CoreFvHandle->FvPpi == NULL)) {\r | |
1244 | return EFI_INVALID_PARAMETER;\r | |
1245 | }\r | |
1246 | \r | |
1247 | if ((CoreFvHandle->FvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1248 | (CoreFvHandle->FvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1249 | return CoreFvHandle->FvPpi->GetFileInfo2 (CoreFvHandle->FvPpi, FileHandle, FileInfo);\r | |
1250 | }\r | |
1251 | //\r | |
1252 | // The old FvPpi doesn't support to return file info with authentication status,\r | |
1253 | // so return EFI_UNSUPPORTED.\r | |
1254 | //\r | |
1255 | return EFI_UNSUPPORTED;\r | |
1256 | }\r | |
b0d803fe | 1257 | \r |
b1f6a7c6 | 1258 | /**\r |
3b428ade | 1259 | Returns information about the specified volume.\r |
b1f6a7c6 | 1260 | \r |
5a9403b8 | 1261 | This function returns information about a specific firmware\r |
1262 | volume, including its name, type, attributes, starting address\r | |
1263 | and size.\r | |
1264 | \r | |
1265 | @param VolumeHandle Handle of the volume.\r | |
1266 | @param VolumeInfo Upon exit, points to the volume's information.\r | |
1267 | \r | |
1268 | @retval EFI_SUCCESS Volume information returned.\r | |
1269 | @retval EFI_INVALID_PARAMETER If VolumeHandle does not represent a valid volume.\r | |
1270 | @retval EFI_INVALID_PARAMETER If VolumeHandle is NULL.\r | |
1271 | @retval EFI_SUCCESS Information successfully returned.\r | |
1272 | @retval EFI_INVALID_PARAMETER The volume designated by the VolumeHandle is not available.\r | |
b1f6a7c6 | 1273 | \r |
b1f6a7c6 | 1274 | **/\r |
b0d803fe | 1275 | EFI_STATUS\r |
1276 | EFIAPI \r | |
1277 | PeiFfsGetVolumeInfo (\r | |
1278 | IN EFI_PEI_FV_HANDLE VolumeHandle,\r | |
1279 | OUT EFI_FV_INFO *VolumeInfo\r | |
1280 | )\r | |
b0d803fe | 1281 | {\r |
3b428ade | 1282 | PEI_CORE_FV_HANDLE *CoreHandle;\r |
1283 | \r | |
8fdcc412 | 1284 | if ((VolumeInfo == NULL) || (VolumeHandle == NULL)) {\r |
b0d803fe | 1285 | return EFI_INVALID_PARAMETER;\r |
192f6d4c | 1286 | }\r |
288f9b38 | 1287 | \r |
3b428ade | 1288 | CoreHandle = FvHandleToCoreHandle (VolumeHandle);\r |
1289 | \r | |
1290 | if ((CoreHandle == NULL) || (CoreHandle->FvPpi == NULL)) {\r | |
288f9b38 LG |
1291 | return EFI_INVALID_PARAMETER;\r |
1292 | }\r | |
3b428ade | 1293 | \r |
1294 | return CoreHandle->FvPpi->GetVolumeInfo (CoreHandle->FvPpi, VolumeHandle, VolumeInfo);\r | |
192f6d4c | 1295 | }\r |
b0d803fe | 1296 | \r |
4c6486b9 | 1297 | /**\r |
c7935105 | 1298 | Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.\r |
4c6486b9 | 1299 | \r |
c7935105 | 1300 | @param PrivateData PeiCore's private data structure\r |
3b428ade | 1301 | @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent Fv image that contain this Fv image.\r |
97b2c9b5 | 1302 | @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.\r |
4c6486b9 | 1303 | \r |
1304 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
1305 | @retval EFI_SUCCESS Successfully to process it.\r | |
1306 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
c7935105 | 1307 | @retval EFI_SECURITY_VIOLATION Image is illegal\r |
4c6486b9 | 1308 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r |
1309 | \r | |
1310 | **/\r | |
1311 | EFI_STATUS\r | |
1312 | ProcessFvFile (\r | |
c7935105 | 1313 | IN PEI_CORE_INSTANCE *PrivateData,\r |
3b428ade | 1314 | IN PEI_CORE_FV_HANDLE *ParentFvCoreHandle,\r |
1315 | IN EFI_PEI_FILE_HANDLE ParentFvFileHandle\r | |
4c6486b9 | 1316 | )\r |
1317 | {\r | |
3b428ade | 1318 | EFI_STATUS Status;\r |
1319 | EFI_FV_INFO ParentFvImageInfo;\r | |
1320 | UINT32 FvAlignment;\r | |
1321 | VOID *NewFvBuffer;\r | |
1322 | EFI_PEI_HOB_POINTERS HobPtr;\r | |
1323 | EFI_PEI_FIRMWARE_VOLUME_PPI *ParentFvPpi;\r | |
1324 | EFI_PEI_FV_HANDLE ParentFvHandle;\r | |
1325 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r | |
1326 | EFI_FV_FILE_INFO FileInfo;\r | |
b4d856a6 | 1327 | UINT64 FvLength;\r |
c7935105 | 1328 | UINT32 AuthenticationStatus;\r |
3b428ade | 1329 | \r |
4c6486b9 | 1330 | //\r |
1331 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r | |
1332 | // been extracted.\r | |
1333 | //\r | |
1334 | HobPtr.Raw = GetHobList ();\r | |
1335 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
97b2c9b5 | 1336 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)ParentFvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r |
4c6486b9 | 1337 | //\r |
1338 | // this FILE has been dispatched, it will not be dispatched again.\r | |
1339 | //\r | |
3b428ade | 1340 | DEBUG ((EFI_D_INFO, "FV file %p has been dispatched!\r\n", ParentFvFileHandle));\r |
4c6486b9 | 1341 | return EFI_SUCCESS;\r |
1342 | }\r | |
1343 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
1344 | }\r | |
1345 | \r | |
3b428ade | 1346 | ParentFvHandle = ParentFvCoreHandle->FvHandle;\r |
1347 | ParentFvPpi = ParentFvCoreHandle->FvPpi;\r | |
1348 | \r | |
4c6486b9 | 1349 | //\r |
1350 | // Find FvImage in FvFile\r | |
1351 | //\r | |
c7935105 SZ |
1352 | AuthenticationStatus = 0;\r |
1353 | if ((ParentFvPpi->Signature == EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) &&\r | |
1354 | (ParentFvPpi->Revision == EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) {\r | |
1355 | Status = ParentFvPpi->FindSectionByType2 (\r | |
1356 | ParentFvPpi,\r | |
1357 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
1358 | 0,\r | |
1359 | ParentFvFileHandle,\r | |
1360 | (VOID **)&FvHeader,\r | |
1361 | &AuthenticationStatus\r | |
1362 | );\r | |
1363 | } else {\r | |
1364 | Status = ParentFvPpi->FindSectionByType (\r | |
1365 | ParentFvPpi,\r | |
1366 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
1367 | ParentFvFileHandle,\r | |
1368 | (VOID **)&FvHeader\r | |
1369 | );\r | |
1370 | }\r | |
4c6486b9 | 1371 | if (EFI_ERROR (Status)) {\r |
1372 | return Status;\r | |
1373 | }\r | |
97b2c9b5 | 1374 | \r |
c7935105 SZ |
1375 | Status = VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandle, AuthenticationStatus);\r |
1376 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
1377 | return Status;\r | |
1378 | }\r | |
1379 | \r | |
97b2c9b5 | 1380 | //\r |
3837e91c SZ |
1381 | // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r |
1382 | // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r | |
1383 | // its initial linked location and maintain its alignment.\r | |
4c6486b9 | 1384 | //\r |
3837e91c SZ |
1385 | if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r |
1386 | //\r | |
1387 | // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r | |
1388 | //\r | |
1389 | FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r | |
1390 | if (FvAlignment < 8) {\r | |
1391 | FvAlignment = 8;\r | |
1392 | }\r | |
1393 | \r | |
1394 | //\r | |
1395 | // Check FvImage\r | |
1396 | //\r | |
1397 | if ((UINTN) FvHeader % FvAlignment != 0) {\r | |
1398 | FvLength = ReadUnaligned64 (&FvHeader->FvLength);\r | |
1399 | NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r | |
1400 | if (NewFvBuffer == NULL) {\r | |
1401 | return EFI_OUT_OF_RESOURCES;\r | |
1402 | }\r | |
1403 | CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r | |
1404 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r | |
4c6486b9 | 1405 | }\r |
4c6486b9 | 1406 | }\r |
3837e91c | 1407 | \r |
3b428ade | 1408 | Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, &ParentFvImageInfo);\r |
1409 | ASSERT_EFI_ERROR (Status);\r | |
1410 | \r | |
1411 | Status = ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, &FileInfo);\r | |
1412 | ASSERT_EFI_ERROR (Status);\r | |
1413 | \r | |
4c6486b9 | 1414 | //\r |
387208ab | 1415 | // Install FvInfo(2) Ppi\r |
9ddd7d7a EC |
1416 | // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated\r |
1417 | // FVs inherit the proper AuthenticationStatus.\r | |
4c6486b9 | 1418 | //\r |
9ddd7d7a | 1419 | PeiServicesInstallFvInfo2Ppi(\r |
387208ab | 1420 | &FvHeader->FileSystemGuid,\r |
9ddd7d7a EC |
1421 | (VOID**)FvHeader,\r |
1422 | (UINT32)FvHeader->FvLength,\r | |
387208ab | 1423 | &ParentFvImageInfo.FvName,\r |
9ddd7d7a EC |
1424 | &FileInfo.FileName,\r |
1425 | AuthenticationStatus\r | |
387208ab SZ |
1426 | );\r |
1427 | \r | |
9ddd7d7a | 1428 | PeiServicesInstallFvInfoPpi (\r |
3b428ade | 1429 | &FvHeader->FileSystemGuid,\r |
1430 | (VOID**) FvHeader,\r | |
1431 | (UINT32) FvHeader->FvLength,\r | |
97b2c9b5 | 1432 | &ParentFvImageInfo.FvName,\r |
9ddd7d7a | 1433 | &FileInfo.FileName\r |
4c6486b9 | 1434 | );\r |
1435 | \r | |
1436 | //\r | |
1437 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r | |
4c6486b9 | 1438 | //\r |
223c22d8 | 1439 | BuildFvHob (\r |
3b428ade | 1440 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r |
1441 | FvHeader->FvLength\r | |
18fcd6a7 | 1442 | );\r |
4c6486b9 | 1443 | \r |
1444 | //\r | |
1445 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
1446 | // encapsulated file again.\r | |
1447 | //\r | |
1448 | BuildFv2Hob (\r | |
3b428ade | 1449 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r |
1450 | FvHeader->FvLength,\r | |
97b2c9b5 | 1451 | &ParentFvImageInfo.FvName,\r |
3b428ade | 1452 | &FileInfo.FileName\r |
4c6486b9 | 1453 | );\r |
1454 | \r | |
1455 | return EFI_SUCCESS;\r | |
1456 | }\r | |
1457 | \r | |
3b428ade | 1458 | /**\r |
1459 | Process a firmware volume and create a volume handle.\r | |
1460 | \r | |
1461 | Create a volume handle from the information in the buffer. For\r | |
1462 | memory-mapped firmware volumes, Buffer and BufferSize refer to\r | |
1463 | the start of the firmware volume and the firmware volume size.\r | |
1464 | For non memory-mapped firmware volumes, this points to a\r | |
1465 | buffer which contains the necessary information for creating\r | |
1466 | the firmware volume handle. Normally, these values are derived\r | |
1467 | from the EFI_FIRMWARE_VOLUME_INFO_PPI.\r | |
1468 | \r | |
1469 | \r | |
1470 | @param This Points to this instance of the\r | |
1471 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1472 | @param Buffer Points to the start of the buffer.\r | |
1473 | @param BufferSize Size of the buffer.\r | |
1474 | @param FvHandle Points to the returned firmware volume\r | |
1475 | handle. The firmware volume handle must\r | |
1476 | be unique within the system. \r | |
1477 | \r | |
1478 | @retval EFI_SUCCESS Firmware volume handle created.\r | |
1479 | @retval EFI_VOLUME_CORRUPTED Volume was corrupt.\r | |
1480 | \r | |
1481 | **/\r | |
1482 | EFI_STATUS\r | |
1483 | EFIAPI\r | |
890e5417 | 1484 | PeiFfsFvPpiProcessVolume (\r |
3b428ade | 1485 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1486 | IN VOID *Buffer,\r | |
1487 | IN UINTN BufferSize,\r | |
1488 | OUT EFI_PEI_FV_HANDLE *FvHandle\r | |
1489 | )\r | |
1490 | {\r | |
1491 | EFI_STATUS Status;\r | |
3b428ade | 1492 | \r |
dc6f9b35 | 1493 | ASSERT (FvHandle != NULL);\r |
1494 | \r | |
1495 | if (Buffer == NULL) {\r | |
1496 | return EFI_VOLUME_CORRUPTED;\r | |
1497 | }\r | |
3b428ade | 1498 | \r |
1499 | //\r | |
890e5417 | 1500 | // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2/FFS3 support memory-mapped\r |
3b428ade | 1501 | // FV image and the handle is pointed to Fv image's buffer.\r |
1502 | //\r | |
1503 | *FvHandle = (EFI_PEI_FV_HANDLE) Buffer;\r | |
1504 | \r | |
1505 | //\r | |
1506 | // Do verify for given FV buffer.\r | |
1507 | //\r | |
1508 | Status = VerifyFv ((EFI_FIRMWARE_VOLUME_HEADER*) Buffer);\r | |
1509 | if (EFI_ERROR(Status)) {\r | |
1510 | DEBUG ((EFI_D_ERROR, "Fail to verify FV which address is 0x%11p", Buffer));\r | |
1511 | return EFI_VOLUME_CORRUPTED;\r | |
1512 | }\r | |
1513 | \r | |
3b428ade | 1514 | return EFI_SUCCESS;\r |
1515 | } \r | |
1516 | \r | |
1517 | /**\r | |
1518 | Finds the next file of the specified type.\r | |
1519 | \r | |
1520 | This service enables PEI modules to discover additional firmware files. \r | |
1521 | The FileHandle must be unique within the system.\r | |
1522 | \r | |
1523 | @param This Points to this instance of the\r | |
1524 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1525 | @param SearchType A filter to find only files of this type. Type\r | |
1526 | EFI_FV_FILETYPE_ALL causes no filtering to be\r | |
1527 | done.\r | |
1528 | @param FvHandle Handle of firmware volume in which to\r | |
1529 | search.\r | |
1530 | @param FileHandle Points to the current handle from which to\r | |
1531 | begin searching or NULL to start at the\r | |
1532 | beginning of the firmware volume. Updated\r | |
1533 | upon return to reflect the file found.\r | |
1534 | \r | |
1535 | @retval EFI_SUCCESS The file was found.\r | |
1536 | @retval EFI_NOT_FOUND The file was not found. FileHandle contains NULL.\r | |
1537 | \r | |
1538 | **/\r | |
1539 | EFI_STATUS\r | |
1540 | EFIAPI\r | |
890e5417 | 1541 | PeiFfsFvPpiFindFileByType (\r |
3b428ade | 1542 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1543 | IN EFI_FV_FILETYPE SearchType,\r | |
1544 | IN EFI_PEI_FV_HANDLE FvHandle,\r | |
1545 | IN OUT EFI_PEI_FILE_HANDLE *FileHandle\r | |
1546 | )\r | |
1547 | { \r | |
1548 | return FindFileEx (FvHandle, NULL, SearchType, FileHandle, NULL);\r | |
1549 | }\r | |
1550 | \r | |
1551 | /**\r | |
1552 | Find a file within a volume by its name. \r | |
1553 | \r | |
1554 | This service searches for files with a specific name, within\r | |
1555 | either the specified firmware volume or all firmware volumes.\r | |
1556 | \r | |
1557 | @param This Points to this instance of the\r | |
1558 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1559 | @param FileName A pointer to the name of the file to find\r | |
1560 | within the firmware volume.\r | |
1561 | @param FvHandle Upon entry, the pointer to the firmware\r | |
1562 | volume to search or NULL if all firmware\r | |
1563 | volumes should be searched. Upon exit, the\r | |
1564 | actual firmware volume in which the file was\r | |
1565 | found.\r | |
1566 | @param FileHandle Upon exit, points to the found file's\r | |
1567 | handle or NULL if it could not be found.\r | |
1568 | \r | |
1569 | @retval EFI_SUCCESS File was found.\r | |
1570 | @retval EFI_NOT_FOUND File was not found.\r | |
1571 | @retval EFI_INVALID_PARAMETER FvHandle or FileHandle or\r | |
1572 | FileName was NULL.\r | |
1573 | \r | |
1574 | \r | |
1575 | **/\r | |
1576 | EFI_STATUS\r | |
1577 | EFIAPI\r | |
890e5417 | 1578 | PeiFfsFvPpiFindFileByName (\r |
3b428ade | 1579 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1580 | IN CONST EFI_GUID *FileName,\r | |
1581 | IN EFI_PEI_FV_HANDLE *FvHandle,\r | |
1582 | OUT EFI_PEI_FILE_HANDLE *FileHandle \r | |
1583 | )\r | |
1584 | {\r | |
1585 | EFI_STATUS Status;\r | |
1586 | PEI_CORE_INSTANCE *PrivateData;\r | |
1587 | UINTN Index;\r | |
1588 | \r | |
1589 | if ((FvHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {\r | |
1590 | return EFI_INVALID_PARAMETER;\r | |
1591 | }\r | |
1592 | \r | |
1593 | if (*FvHandle != NULL) {\r | |
1594 | Status = FindFileEx (*FvHandle, FileName, 0, FileHandle, NULL);\r | |
1595 | if (Status == EFI_NOT_FOUND) {\r | |
1596 | *FileHandle = NULL;\r | |
1597 | }\r | |
1598 | } else { \r | |
1599 | //\r | |
1600 | // If *FvHandle = NULL, so search all FV for given filename\r | |
1601 | //\r | |
1602 | Status = EFI_NOT_FOUND;\r | |
1603 | \r | |
1604 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer());\r | |
1605 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r | |
1606 | //\r | |
1607 | // Only search the FV which is associated with a EFI_PEI_FIRMWARE_VOLUME_PPI instance.\r | |
1608 | //\r | |
1609 | if (PrivateData->Fv[Index].FvPpi != NULL) {\r | |
1610 | Status = FindFileEx (PrivateData->Fv[Index].FvHandle, FileName, 0, FileHandle, NULL);\r | |
1611 | if (!EFI_ERROR (Status)) {\r | |
1612 | *FvHandle = PrivateData->Fv[Index].FvHandle;\r | |
1c738c8f | 1613 | break;\r |
3b428ade | 1614 | }\r |
1615 | }\r | |
1616 | }\r | |
1617 | }\r | |
1618 | \r | |
1619 | return Status; \r | |
1620 | } \r | |
1621 | \r | |
1622 | /**\r | |
1623 | Returns information about a specific file.\r | |
1624 | \r | |
1625 | This function returns information about a specific\r | |
1626 | file, including its file name, type, attributes, starting\r | |
1627 | address and size. \r | |
1628 | \r | |
1629 | @param This Points to this instance of the\r | |
1630 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1631 | @param FileHandle Handle of the file.\r | |
1632 | @param FileInfo Upon exit, points to the file's\r | |
1633 | information.\r | |
1634 | \r | |
1635 | @retval EFI_SUCCESS File information returned.\r | |
1636 | @retval EFI_INVALID_PARAMETER If FileHandle does not\r | |
1637 | represent a valid file.\r | |
1638 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1639 | \r | |
1640 | **/ \r | |
1641 | EFI_STATUS\r | |
1642 | EFIAPI\r | |
890e5417 | 1643 | PeiFfsFvPpiGetFileInfo (\r |
3b428ade | 1644 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r |
1645 | IN EFI_PEI_FILE_HANDLE FileHandle, \r | |
1646 | OUT EFI_FV_FILE_INFO *FileInfo\r | |
1647 | )\r | |
1648 | {\r | |
1649 | UINT8 FileState;\r | |
1650 | UINT8 ErasePolarity;\r | |
1651 | EFI_FFS_FILE_HEADER *FileHeader;\r | |
1652 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
890e5417 SZ |
1653 | PEI_FW_VOL_INSTANCE *FwVolInstance;\r |
1654 | \r | |
3b428ade | 1655 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r |
1656 | return EFI_INVALID_PARAMETER;\r | |
1657 | }\r | |
1658 | \r | |
1659 | //\r | |
1660 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1661 | //\r | |
1662 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1663 | if (CoreFvHandle == NULL) {\r | |
1664 | return EFI_INVALID_PARAMETER;\r | |
1665 | }\r | |
1666 | \r | |
890e5417 SZ |
1667 | FwVolInstance = PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This);\r |
1668 | \r | |
4140a663 | 1669 | if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r |
3b428ade | 1670 | ErasePolarity = 1;\r |
1671 | } else {\r | |
1672 | ErasePolarity = 0;\r | |
1673 | }\r | |
1674 | \r | |
1675 | //\r | |
1676 | // Get FileState which is the highest bit of the State \r | |
1677 | //\r | |
1678 | FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);\r | |
1679 | \r | |
1680 | switch (FileState) {\r | |
1681 | case EFI_FILE_DATA_VALID:\r | |
1682 | case EFI_FILE_MARKED_FOR_UPDATE:\r | |
1683 | break; \r | |
1684 | default:\r | |
1685 | return EFI_INVALID_PARAMETER;\r | |
1686 | }\r | |
1687 | \r | |
1688 | FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;\r | |
890e5417 SZ |
1689 | if (IS_FFS_FILE2 (FileHeader)) {\r |
1690 | ASSERT (FFS_FILE2_SIZE (FileHeader) > 0x00FFFFFF);\r | |
1691 | if (!FwVolInstance->IsFfs3Fv) {\r | |
1692 | DEBUG ((EFI_D_ERROR, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FileHeader->Name));\r | |
1693 | return EFI_INVALID_PARAMETER;\r | |
1694 | }\r | |
1695 | FileInfo->BufferSize = FFS_FILE2_SIZE (FileHeader) - sizeof (EFI_FFS_FILE_HEADER2);\r | |
1696 | FileInfo->Buffer = (UINT8 *) FileHeader + sizeof (EFI_FFS_FILE_HEADER2);\r | |
1697 | } else {\r | |
1698 | FileInfo->BufferSize = FFS_FILE_SIZE (FileHeader) - sizeof (EFI_FFS_FILE_HEADER);\r | |
1699 | FileInfo->Buffer = (UINT8 *) FileHeader + sizeof (EFI_FFS_FILE_HEADER);\r | |
1700 | }\r | |
c7935105 SZ |
1701 | CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));\r |
1702 | FileInfo->FileType = FileHeader->Type;\r | |
1703 | FileInfo->FileAttributes = FfsAttributes2FvFileAttributes (FileHeader->Attributes);\r | |
1704 | if ((CoreFvHandle->FvHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {\r | |
1705 | FileInfo->FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;\r | |
1706 | }\r | |
1707 | return EFI_SUCCESS;\r | |
1708 | }\r | |
1709 | \r | |
1710 | /**\r | |
1711 | Returns information about a specific file.\r | |
1712 | \r | |
1713 | This function returns information about a specific\r | |
1714 | file, including its file name, type, attributes, starting\r | |
1715 | address, size and authentication status.\r | |
1716 | \r | |
1717 | @param This Points to this instance of the\r | |
1718 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1719 | @param FileHandle Handle of the file.\r | |
1720 | @param FileInfo Upon exit, points to the file's\r | |
1721 | information.\r | |
1722 | \r | |
1723 | @retval EFI_SUCCESS File information returned.\r | |
1724 | @retval EFI_INVALID_PARAMETER If FileHandle does not\r | |
1725 | represent a valid file.\r | |
1726 | @retval EFI_INVALID_PARAMETER If FileInfo is NULL.\r | |
1727 | \r | |
1728 | **/\r | |
1729 | EFI_STATUS\r | |
1730 | EFIAPI\r | |
1731 | PeiFfsFvPpiGetFileInfo2 (\r | |
1732 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r | |
1733 | IN EFI_PEI_FILE_HANDLE FileHandle, \r | |
1734 | OUT EFI_FV_FILE_INFO2 *FileInfo\r | |
1735 | )\r | |
1736 | {\r | |
1737 | EFI_STATUS Status;\r | |
1738 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r | |
1739 | \r | |
1740 | if ((FileHandle == NULL) || (FileInfo == NULL)) {\r | |
1741 | return EFI_INVALID_PARAMETER;\r | |
1742 | }\r | |
1743 | \r | |
1744 | //\r | |
1745 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1746 | //\r | |
1747 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1748 | if (CoreFvHandle == NULL) {\r | |
1749 | return EFI_INVALID_PARAMETER;\r | |
1750 | }\r | |
1751 | \r | |
1752 | Status = PeiFfsFvPpiGetFileInfo (This, FileHandle, (EFI_FV_FILE_INFO *) FileInfo);\r | |
1753 | if (!EFI_ERROR (Status)) {\r | |
1754 | FileInfo->AuthenticationStatus = CoreFvHandle->AuthenticationStatus;\r | |
1755 | }\r | |
1756 | \r | |
1757 | return Status;\r | |
1758 | }\r | |
1759 | \r | |
3b428ade | 1760 | /**\r |
1761 | This function returns information about the firmware volume.\r | |
1762 | \r | |
1763 | @param This Points to this instance of the\r | |
1764 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1765 | @param FvHandle Handle to the firmware handle.\r | |
1766 | @param VolumeInfo Points to the returned firmware volume\r | |
1767 | information.\r | |
1768 | \r | |
1769 | @retval EFI_SUCCESS Information returned successfully.\r | |
1770 | @retval EFI_INVALID_PARAMETER FvHandle does not indicate a valid\r | |
1771 | firmware volume or VolumeInfo is NULL.\r | |
1772 | \r | |
1773 | **/ \r | |
1774 | EFI_STATUS\r | |
1775 | EFIAPI\r | |
890e5417 | 1776 | PeiFfsFvPpiGetVolumeInfo (\r |
3b428ade | 1777 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This, \r |
1778 | IN EFI_PEI_FV_HANDLE FvHandle, \r | |
1779 | OUT EFI_FV_INFO *VolumeInfo\r | |
1780 | )\r | |
1781 | {\r | |
1782 | EFI_FIRMWARE_VOLUME_HEADER FwVolHeader;\r | |
1783 | EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;\r | |
1784 | \r | |
8fdcc412 | 1785 | if ((VolumeInfo == NULL) || (FvHandle == NULL)) {\r |
3b428ade | 1786 | return EFI_INVALID_PARAMETER;\r |
1787 | }\r | |
1788 | \r | |
1789 | //\r | |
1790 | // VolumeHandle may not align at 8 byte, \r | |
1791 | // but FvLength is UINT64 type, which requires FvHeader align at least 8 byte. \r | |
1792 | // So, Copy FvHeader into the local FvHeader structure.\r | |
1793 | //\r | |
1794 | CopyMem (&FwVolHeader, FvHandle, sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r | |
1795 | \r | |
1796 | //\r | |
1797 | // Check Fv Image Signature\r | |
1798 | //\r | |
1799 | if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {\r | |
1800 | return EFI_INVALID_PARAMETER;\r | |
1801 | }\r | |
1802 | \r | |
1803 | ZeroMem (VolumeInfo, sizeof (EFI_FV_INFO));\r | |
1804 | VolumeInfo->FvAttributes = FwVolHeader.Attributes;\r | |
1805 | VolumeInfo->FvStart = (VOID *) FvHandle;\r | |
1806 | VolumeInfo->FvSize = FwVolHeader.FvLength;\r | |
1807 | CopyMem (&VolumeInfo->FvFormat, &FwVolHeader.FileSystemGuid, sizeof(EFI_GUID));\r | |
1808 | \r | |
1809 | if (FwVolHeader.ExtHeaderOffset != 0) {\r | |
1810 | FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FvHandle) + FwVolHeader.ExtHeaderOffset);\r | |
1811 | CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));\r | |
1812 | }\r | |
1813 | \r | |
1814 | return EFI_SUCCESS; \r | |
1815 | } \r | |
1816 | \r | |
1817 | /**\r | |
1818 | Find the next matching section in the firmware file.\r | |
1819 | \r | |
1820 | This service enables PEI modules to discover sections\r | |
1821 | of a given type within a valid file.\r | |
1822 | \r | |
1823 | @param This Points to this instance of the\r | |
1824 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1825 | @param SearchType A filter to find only sections of this\r | |
1826 | type.\r | |
1827 | @param FileHandle Handle of firmware file in which to\r | |
1828 | search.\r | |
890e5417 | 1829 | @param SectionData Updated upon return to point to the\r |
3b428ade | 1830 | section found.\r |
1831 | \r | |
1832 | @retval EFI_SUCCESS Section was found.\r | |
1833 | @retval EFI_NOT_FOUND Section of the specified type was not\r | |
1834 | found. SectionData contains NULL.\r | |
1835 | **/\r | |
1836 | EFI_STATUS\r | |
1837 | EFIAPI\r | |
890e5417 | 1838 | PeiFfsFvPpiFindSectionByType (\r |
3b428ade | 1839 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r |
1840 | IN EFI_SECTION_TYPE SearchType,\r | |
1841 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1842 | OUT VOID **SectionData\r | |
1843 | )\r | |
1844 | {\r | |
c7935105 SZ |
1845 | UINT32 AuthenticationStatus;\r |
1846 | return PeiFfsFvPpiFindSectionByType2 (This, SearchType, 0, FileHandle, SectionData, &AuthenticationStatus);\r | |
1847 | }\r | |
1848 | \r | |
1849 | /**\r | |
1850 | Find the next matching section in the firmware file.\r | |
1851 | \r | |
1852 | This service enables PEI modules to discover sections\r | |
1853 | of a given instance and type within a valid file.\r | |
1854 | \r | |
1855 | @param This Points to this instance of the\r | |
1856 | EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
1857 | @param SearchType A filter to find only sections of this\r | |
1858 | type.\r | |
1859 | @param SearchInstance A filter to find the specific instance\r | |
1860 | of sections.\r | |
1861 | @param FileHandle Handle of firmware file in which to\r | |
1862 | search.\r | |
1863 | @param SectionData Updated upon return to point to the\r | |
1864 | section found.\r | |
1865 | @param AuthenticationStatus Updated upon return to point to the\r | |
1866 | authentication status for this section.\r | |
1867 | \r | |
1868 | @retval EFI_SUCCESS Section was found.\r | |
1869 | @retval EFI_NOT_FOUND Section of the specified type was not\r | |
1870 | found. SectionData contains NULL.\r | |
1871 | **/\r | |
1872 | EFI_STATUS\r | |
1873 | EFIAPI\r | |
1874 | PeiFfsFvPpiFindSectionByType2 (\r | |
1875 | IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,\r | |
1876 | IN EFI_SECTION_TYPE SearchType,\r | |
1877 | IN UINTN SearchInstance,\r | |
1878 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
1879 | OUT VOID **SectionData,\r | |
1880 | OUT UINT32 *AuthenticationStatus\r | |
1881 | )\r | |
1882 | {\r | |
1883 | EFI_STATUS Status;\r | |
3b428ade | 1884 | EFI_FFS_FILE_HEADER *FfsFileHeader;\r |
1885 | UINT32 FileSize;\r | |
1886 | EFI_COMMON_SECTION_HEADER *Section;\r | |
890e5417 | 1887 | PEI_FW_VOL_INSTANCE *FwVolInstance;\r |
c7935105 SZ |
1888 | PEI_CORE_FV_HANDLE *CoreFvHandle;\r |
1889 | UINTN Instance;\r | |
1890 | UINT32 ExtractedAuthenticationStatus;\r | |
1891 | \r | |
1892 | if (SectionData == NULL) {\r | |
1893 | return EFI_NOT_FOUND;\r | |
1894 | }\r | |
890e5417 SZ |
1895 | \r |
1896 | FwVolInstance = PEI_FW_VOL_INSTANCE_FROM_FV_THIS (This);\r | |
1897 | \r | |
c7935105 SZ |
1898 | //\r |
1899 | // Retrieve the FirmwareVolume which the file resides in.\r | |
1900 | //\r | |
1901 | CoreFvHandle = FileHandleToVolume (FileHandle);\r | |
1902 | if (CoreFvHandle == NULL) {\r | |
1903 | return EFI_NOT_FOUND;\r | |
1904 | }\r | |
1905 | \r | |
3b428ade | 1906 | FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);\r |
1907 | \r | |
890e5417 SZ |
1908 | if (IS_FFS_FILE2 (FfsFileHeader)) {\r |
1909 | ASSERT (FFS_FILE2_SIZE (FfsFileHeader) > 0x00FFFFFF);\r | |
1910 | if (!FwVolInstance->IsFfs3Fv) {\r | |
1911 | DEBUG ((EFI_D_ERROR, "It is a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsFileHeader->Name));\r | |
1912 | return EFI_NOT_FOUND;\r | |
1913 | }\r | |
1914 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER2));\r | |
1915 | FileSize = FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER2);\r | |
1916 | } else {\r | |
1917 | Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r | |
1918 | FileSize = FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER);\r | |
1919 | }\r | |
3b428ade | 1920 | \r |
c7935105 SZ |
1921 | Instance = SearchInstance + 1;\r |
1922 | ExtractedAuthenticationStatus = 0;\r | |
1923 | Status = ProcessSection (\r | |
1924 | GetPeiServicesTablePointer (),\r | |
1925 | SearchType,\r | |
1926 | &Instance,\r | |
1927 | Section, \r | |
1928 | FileSize, \r | |
1929 | SectionData,\r | |
1930 | &ExtractedAuthenticationStatus,\r | |
1931 | FwVolInstance->IsFfs3Fv\r | |
1932 | );\r | |
1933 | if (!EFI_ERROR (Status)) {\r | |
1934 | //\r | |
1935 | // Inherit the authentication status.\r | |
1936 | //\r | |
1937 | *AuthenticationStatus = ExtractedAuthenticationStatus | CoreFvHandle->AuthenticationStatus;\r | |
1938 | }\r | |
1939 | return Status;\r | |
1940 | }\r | |
3b428ade | 1941 | \r |
1942 | /**\r | |
1943 | Convert the handle of FV to pointer of corresponding PEI_CORE_FV_HANDLE.\r | |
1944 | \r | |
1945 | @param FvHandle The handle of a FV.\r | |
1946 | \r | |
1947 | @retval NULL if can not find.\r | |
1948 | @return Pointer of corresponding PEI_CORE_FV_HANDLE. \r | |
1949 | **/\r | |
1950 | PEI_CORE_FV_HANDLE *\r | |
1951 | FvHandleToCoreHandle (\r | |
1952 | IN EFI_PEI_FV_HANDLE FvHandle\r | |
1953 | )\r | |
1954 | {\r | |
1955 | UINTN Index;\r | |
1956 | PEI_CORE_INSTANCE *PrivateData;\r | |
1957 | \r | |
1958 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer()); \r | |
1959 | for (Index = 0; Index < PrivateData->FvCount; Index ++) {\r | |
1960 | if (FvHandle == PrivateData->Fv[Index].FvHandle) {\r | |
1961 | return &PrivateData->Fv[Index];\r | |
1962 | }\r | |
1963 | }\r | |
1964 | \r | |
1965 | return NULL;\r | |
1966 | } \r | |
1967 | \r | |
1968 | /**\r | |
1969 | Get instance of PEI_CORE_FV_HANDLE for next volume according to given index.\r | |
1970 | \r | |
1971 | This routine also will install FvInfo ppi for FV hob in PI ways.\r | |
1972 | \r | |
1973 | @param Private Pointer of PEI_CORE_INSTANCE\r | |
1974 | @param Instance The index of FV want to be searched.\r | |
1975 | \r | |
1976 | @return Instance of PEI_CORE_FV_HANDLE.\r | |
1977 | **/\r | |
1978 | PEI_CORE_FV_HANDLE *\r | |
1979 | FindNextCoreFvHandle (\r | |
1980 | IN PEI_CORE_INSTANCE *Private,\r | |
1981 | IN UINTN Instance\r | |
1982 | )\r | |
1983 | {\r | |
1984 | UINTN Index;\r | |
1985 | BOOLEAN Match;\r | |
1986 | EFI_HOB_FIRMWARE_VOLUME *FvHob;\r | |
1987 | \r | |
1988 | //\r | |
1989 | // Handle Framework FvHob and Install FvInfo Ppi for it.\r | |
1990 | //\r | |
1991 | if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {\r | |
1992 | //\r | |
1993 | // Loop to search the wanted FirmwareVolume which supports FFS\r | |
1994 | //\r | |
1995 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetFirstHob (EFI_HOB_TYPE_FV);\r | |
1996 | while (FvHob != NULL) {\r | |
20ead725 | 1997 | //\r |
1998 | // Search whether FvHob has been installed into PeiCore's FV database.\r | |
1999 | // If found, no need install new FvInfoPpi for it.\r | |
2000 | //\r | |
3b428ade | 2001 | for (Index = 0, Match = FALSE; Index < Private->FvCount; Index++) {\r |
2002 | if ((EFI_PEI_FV_HANDLE)(UINTN)FvHob->BaseAddress == Private->Fv[Index].FvHeader) {\r | |
2003 | Match = TRUE;\r | |
2004 | break;\r | |
2005 | }\r | |
2006 | }\r | |
20ead725 | 2007 | \r |
3b428ade | 2008 | //\r |
20ead725 | 2009 | // Search whether FvHob has been cached into PeiCore's Unknown FV database.\r |
2010 | // If found, no need install new FvInfoPpi for it.\r | |
2011 | //\r | |
2012 | if (!Match) {\r | |
2013 | for (Index = 0; Index < Private->UnknownFvInfoCount; Index ++) {\r | |
2014 | if ((UINTN)FvHob->BaseAddress == (UINTN)Private->UnknownFvInfo[Index].FvInfo) {\r | |
2015 | Match = TRUE;\r | |
2016 | break;\r | |
2017 | }\r | |
2018 | }\r | |
2019 | }\r | |
2020 | \r | |
2021 | //\r | |
2022 | // If the Fv in FvHob has not been installed into PeiCore's FV database and has\r | |
2023 | // not been cached into PeiCore's Unknown FV database, install a new FvInfoPpi\r | |
2024 | // for it then PeiCore will dispatch it in callback of FvInfoPpi.\r | |
3b428ade | 2025 | //\r |
2026 | if (!Match) {\r | |
2027 | PeiServicesInstallFvInfoPpi (\r | |
2028 | &(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHob->BaseAddress)->FileSystemGuid),\r | |
2029 | (VOID *)(UINTN)FvHob->BaseAddress,\r | |
2030 | (UINT32)FvHob->Length,\r | |
2031 | NULL,\r | |
2032 | NULL\r | |
2033 | );\r | |
2034 | }\r | |
20ead725 | 2035 | \r |
3b428ade | 2036 | FvHob = (EFI_HOB_FIRMWARE_VOLUME *)GetNextHob (EFI_HOB_TYPE_FV, (VOID *)((UINTN)FvHob + FvHob->Header.HobLength)); \r |
2037 | }\r | |
2038 | }\r | |
2039 | \r | |
fe781940 | 2040 | ASSERT (Private->FvCount <= PcdGet32 (PcdPeiCoreMaxFvSupported));\r |
3b428ade | 2041 | if (Instance >= Private->FvCount) {\r |
2042 | return NULL;\r | |
2043 | }\r | |
4c6486b9 | 2044 | \r |
3b428ade | 2045 | return &Private->Fv[Instance];\r |
2046 | } \r | |
8e0e40ed | 2047 | \r |
2048 | /**\r | |
2049 | After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r | |
2050 | be re-installed with the instance in permanent memory and all cached FvPpi pointers in \r | |
6393d9c8 | 2051 | PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent\r |
8e0e40ed | 2052 | memory.\r |
2053 | \r | |
2054 | @param PrivateData Pointer to PEI_CORE_INSTANCE.\r | |
2055 | **/ \r | |
2056 | VOID\r | |
2057 | PeiReinitializeFv (\r | |
2058 | IN PEI_CORE_INSTANCE *PrivateData\r | |
2059 | )\r | |
2060 | {\r | |
890e5417 | 2061 | VOID *OldFfsFvPpi;\r |
7ec93917 | 2062 | EFI_PEI_PPI_DESCRIPTOR *OldDescriptor;\r |
2063 | UINTN Index;\r | |
2064 | EFI_STATUS Status;\r | |
2065 | \r | |
2066 | //\r | |
2067 | // Locate old build-in Ffs2 EFI_PEI_FIRMWARE_VOLUME_PPI which\r | |
2068 | // in flash.\r | |
2069 | //\r | |
2070 | Status = PeiServicesLocatePpi (\r | |
2071 | &gEfiFirmwareFileSystem2Guid,\r | |
2072 | 0,\r | |
2073 | &OldDescriptor,\r | |
890e5417 | 2074 | &OldFfsFvPpi\r |
7ec93917 | 2075 | );\r |
2076 | ASSERT_EFI_ERROR (Status);\r | |
2077 | \r | |
2078 | //\r | |
2079 | // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs2\r | |
2080 | // which is shadowed from flash to permanent memory within PeiCore image.\r | |
2081 | //\r | |
2082 | Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs2FvPpiList);\r | |
2083 | ASSERT_EFI_ERROR (Status);\r | |
890e5417 | 2084 | \r |
7ec93917 | 2085 | //\r |
2086 | // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r | |
2087 | //\r | |
fe781940 | 2088 | for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r |
890e5417 SZ |
2089 | if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r |
2090 | PrivateData->Fv[Index].FvPpi = &mPeiFfs2FwVol.Fv;\r | |
7ec93917 | 2091 | }\r |
2092 | }\r | |
890e5417 SZ |
2093 | \r |
2094 | //\r | |
2095 | // Locate old build-in Ffs3 EFI_PEI_FIRMWARE_VOLUME_PPI which\r | |
2096 | // in flash.\r | |
2097 | //\r | |
2098 | Status = PeiServicesLocatePpi (\r | |
2099 | &gEfiFirmwareFileSystem3Guid,\r | |
2100 | 0,\r | |
2101 | &OldDescriptor,\r | |
2102 | &OldFfsFvPpi\r | |
2103 | );\r | |
2104 | ASSERT_EFI_ERROR (Status);\r | |
2105 | \r | |
2106 | //\r | |
2107 | // Re-install the EFI_PEI_FIRMWARE_VOLUME_PPI for build-in Ffs3\r | |
2108 | // which is shadowed from flash to permanent memory within PeiCore image.\r | |
2109 | //\r | |
2110 | Status = PeiServicesReInstallPpi (OldDescriptor, &mPeiFfs3FvPpiList);\r | |
2111 | ASSERT_EFI_ERROR (Status);\r | |
2112 | \r | |
2113 | //\r | |
2114 | // Fixup all FvPpi pointers for the implementation in flash to permanent memory.\r | |
2115 | //\r | |
fe781940 | 2116 | for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r |
890e5417 SZ |
2117 | if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {\r |
2118 | PrivateData->Fv[Index].FvPpi = &mPeiFfs3FwVol.Fv;\r | |
2119 | }\r | |
2120 | }\r | |
2121 | }\r | |
8e0e40ed | 2122 | \r |
f3358329 | 2123 | /**\r |
2124 | Report the information for a new discoveried FV in unknown third-party format.\r | |
2125 | \r | |
2126 | If the EFI_PEI_FIRMWARE_VOLUME_PPI has not been installed for third-party FV format, but\r | |
c7935105 | 2127 | the FV in this format has been discoveried, then this FV's information will be cached into\r |
f3358329 | 2128 | PEI_CORE_INSTANCE's UnknownFvInfo array.\r |
2129 | Also a notification would be installed for unknown third-party FV format guid, if EFI_PEI_FIRMWARE_VOLUME_PPI\r | |
2130 | is installed later by platform's PEIM, the original unknown third-party FV will be processed by\r | |
2131 | using new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
2132 | \r | |
2133 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r | |
c7935105 | 2134 | @param FvInfo2Ppi Point to FvInfo2 PPI.\r |
f3358329 | 2135 | \r |
2136 | @retval EFI_OUT_OF_RESOURCES The FV info array in PEI_CORE_INSTANCE has no more spaces.\r | |
2137 | @retval EFI_SUCCESS Success to add the information for unknown FV.\r | |
2138 | **/\r | |
2139 | EFI_STATUS\r | |
2140 | AddUnknownFormatFvInfo (\r | |
c7935105 SZ |
2141 | IN PEI_CORE_INSTANCE *PrivateData,\r |
2142 | IN EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI *FvInfo2Ppi\r | |
f3358329 | 2143 | )\r |
2144 | {\r | |
2145 | PEI_CORE_UNKNOW_FORMAT_FV_INFO *NewUnknownFv;\r | |
2146 | \r | |
fe781940 | 2147 | if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
f3358329 | 2148 | return EFI_OUT_OF_RESOURCES;\r |
2149 | }\r | |
2150 | \r | |
2151 | NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];\r | |
2152 | PrivateData->UnknownFvInfoCount ++;\r | |
2153 | \r | |
c7935105 SZ |
2154 | CopyGuid (&NewUnknownFv->FvFormat, &FvInfo2Ppi->FvFormat);\r |
2155 | NewUnknownFv->FvInfo = FvInfo2Ppi->FvInfo;\r | |
2156 | NewUnknownFv->FvInfoSize = FvInfo2Ppi->FvInfoSize;\r | |
2157 | NewUnknownFv->AuthenticationStatus = FvInfo2Ppi->AuthenticationStatus;\r | |
f3358329 | 2158 | NewUnknownFv->NotifyDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r |
2159 | NewUnknownFv->NotifyDescriptor.Guid = &NewUnknownFv->FvFormat;\r | |
2160 | NewUnknownFv->NotifyDescriptor.Notify = ThirdPartyFvPpiNotifyCallback;\r | |
2161 | \r | |
2162 | PeiServicesNotifyPpi (&NewUnknownFv->NotifyDescriptor);\r | |
2163 | return EFI_SUCCESS;\r | |
2164 | }\r | |
2165 | \r | |
2166 | /**\r | |
2167 | Find the FV information according to third-party FV format guid.\r | |
2168 | \r | |
2169 | This routine also will remove the FV information found by given FV format guid from\r | |
2170 | PrivateData->UnknownFvInfo[].\r | |
2171 | \r | |
2172 | @param PrivateData Point to instance of PEI_CORE_INSTANCE\r | |
2173 | @param Format Point to given FV format guid\r | |
2174 | @param FvInfo On return, the pointer of FV information buffer\r | |
2175 | @param FvInfoSize On return, the size of FV information buffer.\r | |
c7935105 | 2176 | @param AuthenticationStatus On return, the authentication status of FV information buffer.\r |
f3358329 | 2177 | \r |
2178 | @retval EFI_NOT_FOUND The FV is not found for new installed EFI_PEI_FIRMWARE_VOLUME_PPI\r | |
2179 | @retval EFI_SUCCESS Success to find a FV which could be processed by new installed EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
2180 | **/\r | |
2181 | EFI_STATUS\r | |
2182 | FindUnknownFormatFvInfo (\r | |
2183 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
2184 | IN EFI_GUID *Format,\r | |
2185 | OUT VOID **FvInfo,\r | |
c7935105 SZ |
2186 | OUT UINT32 *FvInfoSize,\r |
2187 | OUT UINT32 *AuthenticationStatus\r | |
f3358329 | 2188 | )\r |
2189 | {\r | |
2190 | UINTN Index;\r | |
2191 | UINTN Index2;\r | |
2192 | \r | |
2193 | Index = 0;\r | |
2194 | for (; Index < PrivateData->UnknownFvInfoCount; Index ++) {\r | |
2195 | if (CompareGuid (Format, &PrivateData->UnknownFvInfo[Index].FvFormat)) {\r | |
2196 | break;\r | |
2197 | }\r | |
2198 | }\r | |
2199 | \r | |
2200 | if (Index == PrivateData->UnknownFvInfoCount) {\r | |
2201 | return EFI_NOT_FOUND;\r | |
2202 | }\r | |
2203 | \r | |
2204 | *FvInfo = PrivateData->UnknownFvInfo[Index].FvInfo;\r | |
2205 | *FvInfoSize = PrivateData->UnknownFvInfo[Index].FvInfoSize;\r | |
c7935105 | 2206 | *AuthenticationStatus = PrivateData->UnknownFvInfo[Index].AuthenticationStatus;\r |
f3358329 | 2207 | \r |
2208 | //\r | |
2209 | // Remove an entry from UnknownFvInfo array.\r | |
2210 | //\r | |
2211 | Index2 = Index + 1;\r | |
2212 | for (;Index2 < PrivateData->UnknownFvInfoCount; Index2 ++, Index ++) {\r | |
2213 | CopyMem (&PrivateData->UnknownFvInfo[Index], &PrivateData->UnknownFvInfo[Index2], sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO));\r | |
2214 | }\r | |
2215 | PrivateData->UnknownFvInfoCount --;\r | |
2216 | return EFI_SUCCESS;\r | |
2217 | } \r | |
2218 | \r | |
2219 | /**\r | |
2220 | Notification callback function for EFI_PEI_FIRMWARE_VOLUME_PPI.\r | |
2221 | \r | |
2222 | When a EFI_PEI_FIRMWARE_VOLUME_PPI is installed to support new FV format, this \r | |
2223 | routine is called to process all discoveried FVs in this format.\r | |
2224 | \r | |
2225 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r | |
2226 | @param NotifyDescriptor Address of the notification descriptor data structure.\r | |
2227 | @param Ppi Address of the PPI that was installed.\r | |
2228 | \r | |
2229 | @retval EFI_SUCCESS The notification callback is processed correctly.\r | |
2230 | **/\r | |
2231 | EFI_STATUS\r | |
2232 | EFIAPI\r | |
2233 | ThirdPartyFvPpiNotifyCallback (\r | |
2234 | IN EFI_PEI_SERVICES **PeiServices,\r | |
2235 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r | |
2236 | IN VOID *Ppi\r | |
2237 | )\r | |
2238 | {\r | |
2239 | PEI_CORE_INSTANCE *PrivateData;\r | |
2240 | EFI_PEI_FIRMWARE_VOLUME_PPI *FvPpi;\r | |
2241 | VOID *FvInfo;\r | |
2242 | UINT32 FvInfoSize;\r | |
c7935105 | 2243 | UINT32 AuthenticationStatus;\r |
f3358329 | 2244 | EFI_STATUS Status;\r |
2245 | EFI_PEI_FV_HANDLE FvHandle;\r | |
2246 | BOOLEAN IsProcessed;\r | |
2247 | UINTN FvIndex;\r | |
2248 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
2249 | VOID *DepexData; \r | |
7147077b ZC |
2250 | UINTN CurFvCount;\r |
2251 | \r | |
f3358329 | 2252 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r |
2253 | FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r | |
2254 | \r | |
2255 | do {\r | |
c7935105 | 2256 | Status = FindUnknownFormatFvInfo (PrivateData, NotifyDescriptor->Guid, &FvInfo, &FvInfoSize, &AuthenticationStatus);\r |
f3358329 | 2257 | if (EFI_ERROR (Status)) {\r |
2258 | return EFI_SUCCESS;\r | |
2259 | }\r | |
2260 | \r | |
2261 | //\r | |
2262 | // Process new found FV and get FV handle.\r | |
2263 | //\r | |
2264 | Status = FvPpi->ProcessVolume (FvPpi, FvInfo, FvInfoSize, &FvHandle);\r | |
2265 | if (EFI_ERROR (Status)) {\r | |
2266 | DEBUG ((EFI_D_ERROR, "Fail to process the FV 0x%p, FV may be corrupted!\n", FvInfo));\r | |
2267 | continue;\r | |
2268 | }\r | |
2269 | \r | |
2270 | //\r | |
2271 | // Check whether the FV has already been processed.\r | |
2272 | //\r | |
2273 | IsProcessed = FALSE;\r | |
2274 | for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r | |
2275 | if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r | |
2276 | DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfo));\r | |
2277 | IsProcessed = TRUE;\r | |
2278 | break;\r | |
2279 | }\r | |
2280 | }\r | |
2281 | \r | |
2282 | if (IsProcessed) {\r | |
2283 | continue;\r | |
2284 | }\r | |
2285 | \r | |
fe781940 SZ |
2286 | if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r |
2287 | 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 | 2288 | DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r |
2289 | ASSERT (FALSE);\r | |
2290 | }\r | |
2291 | \r | |
f3358329 | 2292 | //\r |
2293 | // Update internal PEI_CORE_FV array.\r | |
2294 | //\r | |
2295 | PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfo;\r | |
2296 | PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r | |
2297 | PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r | |
c7935105 | 2298 | PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = AuthenticationStatus;\r |
7147077b | 2299 | CurFvCount = PrivateData->FvCount;\r |
f3358329 | 2300 | DEBUG ((\r |
2301 | EFI_D_INFO, \r | |
2302 | "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r | |
7147077b | 2303 | (UINT32) CurFvCount,\r |
f3358329 | 2304 | (VOID *) FvInfo, \r |
2305 | FvInfoSize,\r | |
2306 | FvHandle\r | |
2307 | )); \r | |
2308 | PrivateData->FvCount ++;\r | |
2309 | \r | |
2310 | //\r | |
2311 | // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r | |
2312 | //\r | |
2313 | FileHandle = NULL;\r | |
2314 | do {\r | |
2315 | Status = FvPpi->FindFileByType (\r | |
2316 | FvPpi,\r | |
2317 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r | |
2318 | FvHandle,\r | |
2319 | &FileHandle\r | |
2320 | );\r | |
2321 | if (!EFI_ERROR (Status)) {\r | |
2322 | Status = FvPpi->FindSectionByType (\r | |
2323 | FvPpi,\r | |
2324 | EFI_SECTION_PEI_DEPEX,\r | |
2325 | FileHandle,\r | |
2326 | (VOID**)&DepexData\r | |
2327 | );\r | |
2328 | if (!EFI_ERROR (Status)) {\r | |
2329 | if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r | |
2330 | //\r | |
2331 | // Dependency is not satisfied.\r | |
2332 | //\r | |
2333 | continue;\r | |
2334 | }\r | |
2335 | }\r | |
2336 | \r | |
7147077b ZC |
2337 | DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r |
2338 | ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r | |
f3358329 | 2339 | }\r |
2340 | } while (FileHandle != NULL);\r | |
2341 | } while (TRUE);\r | |
f3358329 | 2342 | }\r |