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