]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Print real entry point for IPF image.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 FwVol.c
15
16 Abstract:
17
18 Pei Core Firmware File System service routines.
19
20 --*/
21
22 #include <PeiMain.h>
23
24 STATIC EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnFvInfoList = {
25 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
26 &gEfiPeiFirmwareVolumeInfoPpiGuid,
27 FirmwareVolmeInfoPpiNotifyCallback
28 };
29
30
31 #define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
32 (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
33
34 STATIC
35 EFI_FFS_FILE_STATE
36 GetFileState(
37 IN UINT8 ErasePolarity,
38 IN EFI_FFS_FILE_HEADER *FfsHeader
39 )
40 /*++
41
42 Routine Description:
43
44 Returns the highest bit set of the State field
45
46 Arguments:
47
48 ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
49 in the Attributes field.
50 FfsHeader - Pointer to FFS File Header.
51
52 Returns:
53 Returns the highest bit in the State field
54
55 --*/
56 {
57 EFI_FFS_FILE_STATE FileState;
58 EFI_FFS_FILE_STATE HighestBit;
59
60 FileState = FfsHeader->State;
61
62 if (ErasePolarity != 0) {
63 FileState = (EFI_FFS_FILE_STATE)~FileState;
64 }
65
66 HighestBit = 0x80;
67 while (HighestBit != 0 && (HighestBit & FileState) == 0) {
68 HighestBit >>= 1;
69 }
70
71 return HighestBit;
72 }
73
74 STATIC
75 UINT8
76 CalculateHeaderChecksum (
77 IN EFI_FFS_FILE_HEADER *FileHeader
78 )
79 /*++
80
81 Routine Description:
82
83 Calculates the checksum of the header of a file.
84
85 Arguments:
86
87 FileHeader - Pointer to FFS File Header.
88
89 Returns:
90 Checksum of the header.
91
92 The header is zero byte checksum.
93 - Zero means the header is good.
94 - Non-zero means the header is bad.
95
96
97 Bugbug: For PEI performance reason, we comments this code at this time.
98 --*/
99 {
100 UINT8 *ptr;
101 UINTN Index;
102 UINT8 Sum;
103
104 Sum = 0;
105 ptr = (UINT8 *)FileHeader;
106
107 for (Index = 0; Index < sizeof(EFI_FFS_FILE_HEADER) - 3; Index += 4) {
108 Sum = (UINT8)(Sum + ptr[Index]);
109 Sum = (UINT8)(Sum + ptr[Index+1]);
110 Sum = (UINT8)(Sum + ptr[Index+2]);
111 Sum = (UINT8)(Sum + ptr[Index+3]);
112 }
113
114 for (; Index < sizeof(EFI_FFS_FILE_HEADER); Index++) {
115 Sum = (UINT8)(Sum + ptr[Index]);
116 }
117
118 //
119 // State field (since this indicates the different state of file).
120 //
121 Sum = (UINT8)(Sum - FileHeader->State);
122 //
123 // Checksum field of the file is not part of the header checksum.
124 //
125 Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);
126
127 return Sum;
128 }
129
130 STATIC
131 BOOLEAN
132 EFIAPI
133 PeiFileHandleToVolume (
134 IN EFI_PEI_FILE_HANDLE FileHandle,
135 OUT EFI_PEI_FV_HANDLE *VolumeHandle
136 )
137 {
138 UINTN Index;
139 PEI_CORE_INSTANCE *PrivateData;
140 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
141
142 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
143 for (Index = 0; Index < PrivateData->FvCount; Index++) {
144 FwVolHeader = PrivateData->Fv[Index].FvHeader;
145 if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \
146 ((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {
147 *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;
148 return TRUE;
149 }
150 }
151 return FALSE;
152 }
153
154
155 EFI_STATUS
156 PeiFindFileEx (
157 IN CONST EFI_PEI_FV_HANDLE FvHandle,
158 IN CONST EFI_GUID *FileName, OPTIONAL
159 IN EFI_FV_FILETYPE SearchType,
160 IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
161 IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL
162 )
163 /*++
164
165 Routine Description:
166 Given the input file pointer, search for the next matching file in the
167 FFS volume as defined by SearchType. The search starts from FileHeader inside
168 the Firmware Volume defined by FwVolHeader.
169
170 Arguments:
171 PeiServices - Pointer to the PEI Core Services Table.
172 SearchType - Filter to find only files of this type.
173 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
174 FwVolHeader - Pointer to the FV header of the volume to search.
175 This parameter must point to a valid FFS volume.
176 FileHeader - Pointer to the current file from which to begin searching.
177 This pointer will be updated upon return to reflect the file found.
178 Flag - Indicator for if this is for PEI Dispath search
179
180 Returns:
181 EFI_NOT_FOUND - No files matching the search criteria were found
182 EFI_SUCCESS
183
184 --*/
185 {
186 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
187 EFI_FFS_FILE_HEADER **FileHeader;
188 EFI_FFS_FILE_HEADER *FfsFileHeader;
189 EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;
190 UINT32 FileLength;
191 UINT32 FileOccupiedSize;
192 UINT32 FileOffset;
193 UINT64 FvLength;
194 UINT8 ErasePolarity;
195 UINT8 FileState;
196
197 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FvHandle;
198 FileHeader = (EFI_FFS_FILE_HEADER **)FileHandle;
199
200 FvLength = FwVolHeader->FvLength;
201 if (FwVolHeader->Attributes & EFI_FVB_ERASE_POLARITY) {
202 ErasePolarity = 1;
203 } else {
204 ErasePolarity = 0;
205 }
206
207 //
208 // If FileHeader is not specified (NULL) or FileName is not NULL,
209 // start with the first file in the firmware volume. Otherwise,
210 // start from the FileHeader.
211 //
212 if ((*FileHeader == NULL) || (FileName != NULL)) {
213 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader + FwVolHeader->HeaderLength);
214 if (FwVolHeader->ExtHeaderOffset != 0) {
215 FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);
216 FfsFileHeader = (EFI_FFS_FILE_HEADER *)(((UINT8 *)FwVolExHeaderInfo) + FwVolExHeaderInfo->ExtHeaderSize);
217 }
218 } else {
219 //
220 // Length is 24 bits wide so mask upper 8 bits
221 // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
222 //
223 FileLength = *(UINT32 *)(*FileHeader)->Size & 0x00FFFFFF;
224 FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
225 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);
226 }
227
228 FileOffset = (UINT32) ((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);
229 ASSERT (FileOffset <= 0xFFFFFFFF);
230
231 while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
232 //
233 // Get FileState which is the highest bit of the State
234 //
235 FileState = GetFileState (ErasePolarity, FfsFileHeader);
236 switch (FileState) {
237
238 case EFI_FILE_HEADER_INVALID:
239 FileOffset += sizeof(EFI_FFS_FILE_HEADER);
240 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER));
241 break;
242
243 case EFI_FILE_DATA_VALID:
244 case EFI_FILE_MARKED_FOR_UPDATE:
245 if (CalculateHeaderChecksum (FfsFileHeader) != 0) {
246 ASSERT (FALSE);
247 *FileHeader = NULL;
248 return EFI_NOT_FOUND;
249 }
250
251 FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
252 FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);
253
254 if (FileName != NULL) {
255 if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) {
256 *FileHeader = FfsFileHeader;
257 return EFI_SUCCESS;
258 }
259 } else if (SearchType == PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE) {
260 if ((FfsFileHeader->Type == EFI_FV_FILETYPE_PEIM) ||
261 (FfsFileHeader->Type == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER)) {
262
263 *FileHeader = FfsFileHeader;
264 return EFI_SUCCESS;
265 } else if (AprioriFile != NULL) {
266 if (FfsFileHeader->Type == EFI_FV_FILETYPE_FREEFORM) {
267 if (CompareGuid (&FfsFileHeader->Name, &gPeiAprioriFileNameGuid)) {
268 *AprioriFile = FfsFileHeader;
269 }
270 }
271 }
272 } else if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
273 *FileHeader = FfsFileHeader;
274 return EFI_SUCCESS;
275 }
276
277 FileOffset += FileOccupiedSize;
278 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
279 break;
280
281 case EFI_FILE_DELETED:
282 FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
283 FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8);
284 FileOffset += FileOccupiedSize;
285 FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
286 break;
287
288 default:
289 *FileHeader = NULL;
290 return EFI_NOT_FOUND;
291 }
292 }
293
294 *FileHeader = NULL;
295 return EFI_NOT_FOUND;
296 }
297
298 VOID
299 PeiInitializeFv (
300 IN PEI_CORE_INSTANCE *PrivateData,
301 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
302 )
303 /*++
304
305 Routine Description:
306
307 Initialize PeiCore Fv List.
308
309 Arguments:
310 PrivateData - Pointer to PEI_CORE_INSTANCE.
311 SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
312
313 Returns:
314 NONE
315
316 --*/
317 {
318 EFI_STATUS Status;
319 //
320 // The BFV must be the first entry. The Core FV support is stateless
321 // The AllFV list has a single entry per FV in PEI.
322 // The Fv list only includes FV that PEIMs will be dispatched from and
323 // its File System Format is PI 1.0 definition.
324 //
325 PrivateData->FvCount = 1;
326 PrivateData->Fv[0].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;
327
328 PrivateData->AllFvCount = 1;
329 PrivateData->AllFv[0] = (EFI_PEI_FV_HANDLE)PrivateData->Fv[0].FvHeader;
330
331
332 //
333 // Post a call-back for the FvInfoPPI services to expose
334 // additional Fvs to PeiCore.
335 //
336 Status = PeiServicesNotifyPpi (&mNotifyOnFvInfoList);
337 ASSERT_EFI_ERROR (Status);
338
339 }
340
341 EFI_STATUS
342 EFIAPI
343 FirmwareVolmeInfoPpiNotifyCallback (
344 IN EFI_PEI_SERVICES **PeiServices,
345 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
346 IN VOID *Ppi
347 )
348 /*++
349
350 Routine Description:
351
352 Process Firmware Volum Information once FvInfoPPI install.
353
354 Arguments:
355
356 PeiServices - General purpose services available to every PEIM.
357
358 Returns:
359
360 Status - EFI_SUCCESS if the interface could be successfully
361 installed
362
363 --*/
364 {
365 UINT8 FvCount;
366 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *Fv;
367 PEI_CORE_INSTANCE *PrivateData;
368
369 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
370
371 if (PrivateData->FvCount >= FixedPcdGet32 (PcdPeiCoreMaxFvSupported)) {
372 ASSERT (FALSE);
373 }
374
375 Fv = (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *)Ppi;
376
377 if (CompareGuid (&Fv->FvFormat, &gEfiFirmwareFileSystem2Guid)) {
378 for (FvCount = 0; FvCount < PrivateData->FvCount; FvCount ++) {
379 if ((UINTN)PrivateData->Fv[FvCount].FvHeader == (UINTN)Fv->FvInfo) {
380 return EFI_SUCCESS;
381 }
382 }
383 PrivateData->Fv[PrivateData->FvCount++].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Fv->FvInfo;
384 }
385
386 //
387 // Allways add to the All list
388 //
389 PrivateData->AllFv[PrivateData->AllFvCount++] = (EFI_PEI_FV_HANDLE)Fv->FvInfo;
390
391 return EFI_SUCCESS;
392 }
393
394 EFI_STATUS
395 PeiFfsProcessSection (
396 IN CONST EFI_PEI_SERVICES **PeiServices,
397 IN EFI_SECTION_TYPE SectionType,
398 IN EFI_COMMON_SECTION_HEADER *Section,
399 IN UINTN SectionSize,
400 OUT VOID **OutputBuffer,
401 OUT UINTN *OutputSize,
402 OUT UINT32 *Authentication
403 )
404 /*++
405
406 Routine Description:
407
408 Go through the file to search SectionType section,
409 when meeting an encapsuled section, search recursively.
410
411 Arguments:
412 PeiServices - Pointer to the PEI Core Services Table.
413 SearchType - Filter to find only section of this type.
414 Section - From where to search.
415 SectionSize - The file size to search.
416 OutputBuffer - Pointer to the section to search.
417 OutputSize - The size of the section to search.
418 Authentication - Authenticate the section.
419
420 Returns:
421 EFI_STATUS
422
423 --*/
424 {
425 EFI_STATUS Status;
426 UINT32 SectionLength;
427 UINT32 ParsedLength;
428 EFI_GUID_DEFINED_SECTION *GuidSection;
429 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi;
430 EFI_COMPRESSION_SECTION *CompressionSection;
431 EFI_PEI_DECOMPRESS_PPI *DecompressPpi;
432 VOID *PpiOutput;
433 UINTN PpiOutputSize;
434
435 *OutputBuffer = NULL;
436 ParsedLength = 0;
437 while (ParsedLength < SectionSize) {
438 if (Section->Type == SectionType) {
439 *OutputBuffer = (VOID *)(Section + 1);
440 return EFI_SUCCESS;
441 } else if (Section->Type == EFI_SECTION_GUID_DEFINED) {
442 GuidSection = (EFI_GUID_DEFINED_SECTION *)Section;
443 Status = PeiServicesLocatePpi (&GuidSection->SectionDefinitionGuid, 0, NULL, (VOID **) &GuidSectionPpi);
444 if (!EFI_ERROR (Status)) {
445 Status = GuidSectionPpi->ExtractSection (
446 GuidSectionPpi,
447 Section,
448 &PpiOutput,
449 &PpiOutputSize,
450 Authentication
451 );
452 if (!EFI_ERROR (Status)) {
453 return PeiFfsProcessSection (
454 PeiServices,
455 SectionType,
456 PpiOutput,
457 PpiOutputSize,
458 OutputBuffer,
459 OutputSize,
460 Authentication
461 );
462 }
463 }
464 } else if (Section->Type == EFI_SECTION_COMPRESSION) {
465 CompressionSection = (EFI_COMPRESSION_SECTION *)Section;
466 Status = PeiServicesLocatePpi (&gEfiPeiDecompressPpiGuid, 0, NULL, (VOID **) &DecompressPpi);
467 if (!EFI_ERROR (Status)) {
468 Status = DecompressPpi->Decompress (
469 DecompressPpi,
470 CompressionSection,
471 &PpiOutput,
472 &PpiOutputSize
473 );
474 if (!EFI_ERROR (Status)) {
475 return PeiFfsProcessSection (
476 PeiServices, SectionType, PpiOutput, PpiOutputSize, OutputBuffer, OutputSize, Authentication
477 );
478 }
479 }
480 }
481
482 //
483 // Size is 24 bits wide so mask upper 8 bits.
484 // SectionLength is adjusted it is 4 byte aligned.
485 // Go to the next section
486 //
487 SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF;
488 SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
489 ASSERT (SectionLength != 0);
490 ParsedLength += SectionLength;
491 Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);
492 }
493
494 return EFI_NOT_FOUND;
495 }
496
497
498 EFI_STATUS
499 EFIAPI
500 PeiFfsFindSectionData (
501 IN CONST EFI_PEI_SERVICES **PeiServices,
502 IN EFI_SECTION_TYPE SectionType,
503 IN EFI_PEI_FILE_HANDLE FileHandle,
504 IN OUT VOID **SectionData
505 )
506 /*++
507
508 Routine Description:
509 Given the input file pointer, search for the next matching section in the
510 FFS volume.
511
512 Arguments:
513 PeiServices - Pointer to the PEI Core Services Table.
514 SearchType - Filter to find only sections of this type.
515 FfsFileHeader - Pointer to the current file to search.
516 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
517 - NULL if section not found
518
519 Returns:
520 EFI_NOT_FOUND - No files matching the search criteria were found
521 EFI_SUCCESS
522
523 --*/
524 {
525 EFI_FFS_FILE_HEADER *FfsFileHeader;
526 UINT32 FileSize;
527 EFI_COMMON_SECTION_HEADER *Section;
528 UINTN OutputSize;
529 UINT32 AuthenticationStatus;
530
531
532 FfsFileHeader = (EFI_FFS_FILE_HEADER *)(FileHandle);
533
534 //
535 // Size is 24 bits wide so mask upper 8 bits.
536 // Does not include FfsFileHeader header size
537 // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
538 //
539 Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);
540 FileSize = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF;
541 FileSize -= sizeof (EFI_FFS_FILE_HEADER);
542
543 return PeiFfsProcessSection (
544 PeiServices,
545 SectionType,
546 Section,
547 FileSize,
548 SectionData,
549 &OutputSize,
550 &AuthenticationStatus
551 );
552 }
553
554
555 EFI_STATUS
556 FindNextPeim (
557 IN EFI_PEI_SERVICES **PeiServices,
558 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
559 IN OUT EFI_FFS_FILE_HEADER **PeimFileHeader
560 )
561 /*++
562
563 Routine Description:
564 Given the input file pointer, search for the next matching file in the
565 FFS volume. The search starts from FileHeader inside
566 the Firmware Volume defined by FwVolHeader.
567
568 Arguments:
569 PeiServices - Pointer to the PEI Core Services Table.
570
571 FwVolHeader - Pointer to the FV header of the volume to search.
572 This parameter must point to a valid FFS volume.
573
574 PeimFileHeader - Pointer to the current file from which to begin searching.
575 This pointer will be updated upon return to reflect the file found.
576
577 Returns:
578 EFI_NOT_FOUND - No files matching the search criteria were found
579 EFI_SUCCESS
580
581 --*/
582 {
583 return PeiFindFileEx (
584 (EFI_PEI_FV_HANDLE) FwVolHeader,
585 NULL,
586 EFI_FV_FILETYPE_PEIM,
587 (EFI_PEI_FILE_HANDLE *)PeimFileHeader,
588 NULL
589 );
590 }
591
592 EFI_STATUS
593 EFIAPI
594 PeiFfsFindNextFile (
595 IN CONST EFI_PEI_SERVICES **PeiServices,
596 IN UINT8 SearchType,
597 IN EFI_PEI_FV_HANDLE VolumeHandle,
598 IN OUT EFI_PEI_FILE_HANDLE *FileHandle
599 )
600 /*++
601
602 Routine Description:
603 Given the input file pointer, search for the next matching file in the
604 FFS volume as defined by SearchType. The search starts from FileHeader inside
605 the Firmware Volume defined by FwVolHeader.
606
607 Arguments:
608 PeiServices - Pointer to the PEI Core Services Table.
609
610 SearchType - Filter to find only files of this type.
611 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
612
613 FwVolHeader - Pointer to the FV header of the volume to search.
614 This parameter must point to a valid FFS volume.
615
616 FileHeader - Pointer to the current file from which to begin searching.
617 This pointer will be updated upon return to reflect the file found.
618
619 Returns:
620 EFI_NOT_FOUND - No files matching the search criteria were found
621 EFI_SUCCESS
622
623 --*/
624 {
625 return PeiFindFileEx (VolumeHandle, NULL, SearchType, FileHandle, NULL);
626 }
627
628
629 EFI_STATUS
630 EFIAPI
631 PeiFvFindNextVolume (
632 IN CONST EFI_PEI_SERVICES **PeiServices,
633 IN UINTN Instance,
634 IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
635 )
636 /*++
637
638 Routine Description:
639
640 Return the BFV location
641
642 BugBug -- Move this to the location of this code to where the
643 other FV and FFS support code lives.
644 Also, update to use FindFV for instances #'s >= 1.
645
646 Arguments:
647
648 PeiServices - The PEI core services table.
649 Instance - Instance of FV to find
650 FwVolHeader - Pointer to contain the data to return
651
652 Returns:
653 Pointer to the Firmware Volume instance requested
654
655 EFI_INVALID_PARAMETER - FwVolHeader is NULL
656
657 EFI_SUCCESS - Firmware volume instance successfully found.
658
659 --*/
660 {
661 PEI_CORE_INSTANCE *Private;
662
663 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
664 if (VolumeHandle == NULL) {
665 return EFI_INVALID_PARAMETER;
666 }
667
668 if (Instance >= Private->AllFvCount) {
669 VolumeHandle = NULL;
670 return EFI_NOT_FOUND;
671 }
672
673 *VolumeHandle = Private->AllFv[Instance];
674 return EFI_SUCCESS;
675 }
676
677
678 EFI_STATUS
679 EFIAPI
680 PeiFfsFindFileByName (
681 IN CONST EFI_GUID *FileName,
682 IN EFI_PEI_FV_HANDLE VolumeHandle,
683 OUT EFI_PEI_FILE_HANDLE *FileHandle
684 )
685 /*++
686
687 Routine Description:
688
689 Given the input VolumeHandle, search for the next matching name file.
690
691 Arguments:
692
693 FileName - File name to search.
694 VolumeHandle - The current FV to search.
695 FileHandle - Pointer to the file matching name in VolumeHandle.
696 - NULL if file not found
697 Returns:
698 EFI_STATUS
699
700 --*/
701 {
702 EFI_STATUS Status;
703 if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {
704 return EFI_INVALID_PARAMETER;
705 }
706 Status = PeiFindFileEx (VolumeHandle, FileName, 0, FileHandle, NULL);
707 if (Status == EFI_NOT_FOUND) {
708 *FileHandle = NULL;
709 }
710 return Status;
711 }
712
713 EFI_STATUS
714 EFIAPI
715 PeiFfsGetFileInfo (
716 IN EFI_PEI_FILE_HANDLE FileHandle,
717 OUT EFI_FV_FILE_INFO *FileInfo
718 )
719 /*++
720
721 Routine Description:
722
723 Collect information of given file.
724
725 Arguments:
726 FileHandle - The handle to file.
727 FileInfo - Pointer to the file information.
728
729 Returns:
730 EFI_STATUS
731
732 --*/
733 {
734 UINT8 FileState;
735 UINT8 ErasePolarity;
736 EFI_FFS_FILE_HEADER *FileHeader;
737 EFI_PEI_FV_HANDLE VolumeHandle;
738
739 if ((FileHandle == NULL) || (FileInfo == NULL)) {
740 return EFI_INVALID_PARAMETER;
741 }
742
743 //
744 // Retrieve the FirmwareVolume which the file resides in.
745 //
746 if (!PeiFileHandleToVolume(FileHandle, &VolumeHandle)) {
747 return EFI_INVALID_PARAMETER;
748 }
749
750 if (((EFI_FIRMWARE_VOLUME_HEADER*)VolumeHandle)->Attributes & EFI_FVB_ERASE_POLARITY) {
751 ErasePolarity = 1;
752 } else {
753 ErasePolarity = 0;
754 }
755
756 //
757 // Get FileState which is the highest bit of the State
758 //
759 FileState = GetFileState (ErasePolarity, (EFI_FFS_FILE_HEADER*)FileHandle);
760
761 switch (FileState) {
762 case EFI_FILE_DATA_VALID:
763 case EFI_FILE_MARKED_FOR_UPDATE:
764 break;
765 default:
766 return EFI_INVALID_PARAMETER;
767 }
768
769 FileHeader = (EFI_FFS_FILE_HEADER *)FileHandle;
770 CopyMem (&FileInfo->FileName, &FileHeader->Name, sizeof(EFI_GUID));
771 FileInfo->FileType = FileHeader->Type;
772 FileInfo->FileAttributes = FileHeader->Attributes;
773 FileInfo->BufferSize = ((*(UINT32 *)FileHeader->Size) & 0x00FFFFFF) - sizeof (EFI_FFS_FILE_HEADER);
774 FileInfo->Buffer = (FileHeader + 1);
775 return EFI_SUCCESS;
776 }
777
778
779 EFI_STATUS
780 EFIAPI
781 PeiFfsGetVolumeInfo (
782 IN EFI_PEI_FV_HANDLE VolumeHandle,
783 OUT EFI_FV_INFO *VolumeInfo
784 )
785 /*++
786
787 Routine Description:
788
789 Collect information of given Fv Volume.
790
791 Arguments:
792 VolumeHandle - The handle to Fv Volume.
793 VolumeInfo - The pointer to volume information.
794
795 Returns:
796 EFI_STATUS
797
798 --*/
799 {
800 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
801 EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExHeaderInfo;
802
803 if (VolumeInfo == NULL) {
804 return EFI_INVALID_PARAMETER;
805 }
806
807 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(VolumeHandle);
808 VolumeInfo->FvAttributes = FwVolHeader->Attributes;
809 VolumeInfo->FvStart = FwVolHeader;
810 VolumeInfo->FvSize = FwVolHeader->FvLength;
811 CopyMem (&VolumeInfo->FvFormat, &FwVolHeader->FileSystemGuid,sizeof(EFI_GUID));
812
813 if (FwVolHeader->ExtHeaderOffset != 0) {
814 FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(((UINT8 *)FwVolHeader) + FwVolHeader->ExtHeaderOffset);
815 CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof(EFI_GUID));
816 }
817 return EFI_SUCCESS;
818 }
819