71 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
72 &gEfiPeiRecoveryModulePpiGuid,
114 Guid =
PcdGetPtr (PcdSystemFmpCapsuleImageTypeIdGuid);
115 Count =
PcdGetSize (PcdSystemFmpCapsuleImageTypeIdGuid) /
sizeof (
GUID);
117 for (Index = 0; Index < Count; Index++, Guid++) {
118 if (
CompareGuid (&FmpImageHeader->UpdateImageTypeId, Guid)) {
139 if (
CompareGuid (&gEfiFmpCapsuleGuid, CapsuleGuid)) {
167 UINT64 *ItemOffsetList;
183 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
185 for (Index = 0; Index < ItemNum; Index++) {
210 IN UINT64 CapsuleSize
213 if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
217 if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) {
247 OUT UINT16 *EmbeddedDriverCount OPTIONAL
254 UINT64 *ItemOffsetList;
257 UINTN FmpCapsuleSize;
258 UINTN FmpCapsuleHeaderSize;
260 UINTN FmpImageHeaderSize;
262 if (CapsuleHeader->HeaderSize >= CapsuleHeader->CapsuleImageSize) {
263 DEBUG ((DEBUG_ERROR,
"HeaderSize(0x%x) >= CapsuleImageSize(0x%x)\n", CapsuleHeader->HeaderSize, CapsuleHeader->CapsuleImageSize));
264 return EFI_INVALID_PARAMETER;
268 EndOfCapsule = (UINT8 *)CapsuleHeader + CapsuleHeader->CapsuleImageSize;
269 FmpCapsuleSize = (
UINTN)EndOfCapsule - (
UINTN)FmpCapsuleHeader;
272 DEBUG ((DEBUG_ERROR,
"FmpCapsuleSize(0x%x) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER\n", FmpCapsuleSize));
273 return EFI_INVALID_PARAMETER;
277 if (FmpCapsuleHeader->Version != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION) {
278 DEBUG ((DEBUG_ERROR,
"FmpCapsuleHeader->Version(0x%x) != EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION\n", FmpCapsuleHeader->Version));
279 return EFI_INVALID_PARAMETER;
282 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
288 DEBUG ((DEBUG_ERROR,
"ItemNum(0x%x) too big\n", ItemNum));
289 return EFI_INVALID_PARAMETER;
295 for (Index = 0; Index < ItemNum; Index++) {
296 if (ItemOffsetList[Index] >= FmpCapsuleSize) {
297 DEBUG ((DEBUG_ERROR,
"ItemOffsetList[%d](0x%lx) >= FmpCapsuleSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleSize));
298 return EFI_INVALID_PARAMETER;
301 if (ItemOffsetList[Index] < FmpCapsuleHeaderSize) {
302 DEBUG ((DEBUG_ERROR,
"ItemOffsetList[%d](0x%lx) < FmpCapsuleHeaderSize(0x%x)\n", Index, ItemOffsetList[Index], FmpCapsuleHeaderSize));
303 return EFI_INVALID_PARAMETER;
310 if (ItemOffsetList[Index] <= ItemOffsetList[Index - 1]) {
311 DEBUG ((DEBUG_ERROR,
"ItemOffsetList[%d](0x%lx) < ItemOffsetList[%d](0x%x)\n", Index, ItemOffsetList[Index], Index, ItemOffsetList[Index - 1]));
312 return EFI_INVALID_PARAMETER;
320 if (Index == ItemNum - 1) {
321 EndOfPayload = (UINT8 *)((
UINTN)EndOfCapsule - (
UINTN)FmpCapsuleHeader);
323 EndOfPayload = (UINT8 *)(
UINTN)ItemOffsetList[Index+1];
326 FmpImageSize = (
UINTN)EndOfPayload - ItemOffsetList[Index];
329 DEBUG ((DEBUG_ERROR,
"FmpImageSize(0x%lx) < EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER\n", FmpImageSize));
330 return EFI_INVALID_PARAMETER;
334 if ((ImageHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) ||
335 (ImageHeader->Version < 1))
337 DEBUG ((DEBUG_ERROR,
"ImageHeader->Version(0x%x) Unknown\n", ImageHeader->Version));
338 return EFI_INVALID_PARAMETER;
345 if (ImageHeader->Version == 1) {
347 }
else if (ImageHeader->Version == 2) {
354 return EFI_INVALID_PARAMETER;
362 EndOfPayload = (UINT8 *)(FmpCapsuleHeader + 1);
363 if (EndOfPayload != EndOfCapsule) {
364 DEBUG ((DEBUG_ERROR,
"EndOfPayload(0x%x) mismatch, EndOfCapsule(0x%x)\n", EndOfPayload, EndOfCapsule));
365 return EFI_INVALID_PARAMETER;
368 return EFI_UNSUPPORTED;
378 if (EmbeddedDriverCount !=
NULL) {
404 ASSERT (BootMode == BOOT_IN_RECOVERY_MODE);
406 Status = (**PeiServices).InstallPpi (PeiServices, &mRecoveryPpiList);
442 DEBUG ((DEBUG_ERROR,
"CreateHobForRecoveryCapsule (Fv Signature Error)\n"));
443 return EFI_VOLUME_CORRUPTED;
459 if (FvAlignment < 8) {
466 if ((
UINTN)FvHeader % FvAlignment != 0) {
467 DEBUG ((DEBUG_INFO,
"CreateHobForRecoveryCapsule (FvHeader 0x%lx is not aligned)\n", (UINT64)(
UINTN)FvHeader));
470 if (NewFvBuffer ==
NULL) {
471 DEBUG ((DEBUG_ERROR,
"CreateHobForRecoveryCapsule (Not enough resource to allocate 0x%lx bytes)\n", FvLength));
472 return EFI_OUT_OF_RESOURCES;
481 DEBUG ((DEBUG_INFO,
"BuildFvHob (FV in recovery) - 0x%lx - 0x%lx\n", (UINT64)(
UINTN)FvHeader, FvHeader->
FvLength));
506 IN VOID *SystemFirmwareImage,
507 IN UINTN SystemFirmwareImageSize,
508 IN VOID *ConfigImage,
518 if (ConfigImage ==
NULL) {
519 DEBUG ((DEBUG_INFO,
"RecoverImage (NoConfig)\n"));
522 SystemFirmwareImageSize
528 ZeroMem (&ConfigHeader,
sizeof (ConfigHeader));
535 DEBUG ((DEBUG_INFO,
"ParseRecoveryDataFile - %r\n", Status));
536 if (EFI_ERROR (Status)) {
540 DEBUG ((DEBUG_INFO,
"ConfigHeader.NumOfRecovery - 0x%x\n", ConfigHeader.NumOfRecovery));
541 DEBUG ((DEBUG_INFO,
"PcdEdkiiSystemFirmwareFileGuid - %g\n",
PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid)));
544 RecoveryConfigData = ConfigData;
545 while (Index < ConfigHeader.NumOfRecovery) {
547 DEBUG ((DEBUG_INFO,
"FileGuid - %g (processing)\n", &RecoveryConfigData->FileGuid));
549 (UINT8 *)SystemFirmwareImage + RecoveryConfigData->ImageOffset,
550 RecoveryConfigData->Length
556 if (EFI_ERROR (Status)) {
560 DEBUG ((DEBUG_INFO,
"FileGuid - %g (ignored)\n", &RecoveryConfigData->FileGuid));
564 RecoveryConfigData++;
587 UINT32 LastAttemptVersion;
588 UINT32 LastAttemptStatus;
590 VOID *SystemFirmwareImage;
591 UINTN SystemFirmwareImageSize;
593 UINTN ConfigImageSize;
594 VOID *AuthenticatedImage;
595 UINTN AuthenticatedImageSize;
597 AuthenticatedImage =
NULL;
598 AuthenticatedImageSize = 0;
601 if (EFI_ERROR (Status)) {
602 DEBUG ((DEBUG_INFO,
"CapsuleAuthenticateSystemFirmware - %r\n", Status));
607 ExtractConfigImage (AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);
609 Status =
RecoverImage (SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize);
610 if (EFI_ERROR (Status)) {
611 DEBUG ((DEBUG_INFO,
"RecoverImage - %r\n", Status));
646 UINT64 *ItemOffsetList;
650 return EFI_UNSUPPORTED;
654 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
656 for (ItemIndex = 0; ItemIndex < FmpCapsuleHeader->
PayloadItemCount; ItemIndex++) {
658 if (ImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {
659 Image = (UINT8 *)(ImageHeader + 1);
666 if (ImageHeader->Version == 1) {
674 if (EFI_ERROR (Status)) {
697 IN VOID *CapsuleBuffer,
705 CapsuleHeader = CapsuleBuffer;
707 DEBUG ((DEBUG_ERROR,
"CapsuleImageSize incorrect\n"));
708 return EFI_SECURITY_VIOLATION;
715 DEBUG ((DEBUG_INFO,
"CreateHobForRecoveryCapsule\n"));
717 DEBUG ((DEBUG_INFO,
"ProcessCapsuleImage for FmpCapsule ...\n"));
718 DEBUG ((DEBUG_INFO,
"ValidateFmpCapsule ...\n"));
720 DEBUG ((DEBUG_INFO,
"ValidateFmpCapsule - %r\n", Status));
721 if (EFI_ERROR (Status)) {
728 DEBUG ((DEBUG_INFO,
"ProcessFmpCapsuleImage ...\n"));
730 DEBUG ((DEBUG_INFO,
"ProcessFmpCapsuleImage - %r\n", Status));
732 DEBUG ((DEBUG_INFO,
"CreateHobForRecoveryCapsule Done\n"));
736 return EFI_UNSUPPORTED;
760 UINTN NumberRecoveryCapsules;
762 UINTN CapsuleInstance;
767 DEBUG ((DEBUG_INFO | DEBUG_LOAD,
"Recovery Entry\n"));
769 for (Instance = 0; ; Instance++) {
771 &gEfiPeiDeviceRecoveryModulePpiGuid,
774 (VOID **)&DeviceRecoveryPpi
776 DEBUG ((DEBUG_ERROR,
"LoadRecoveryCapsule - LocateRecoveryPpi (%d) - %r\n", Instance, Status));
777 if (EFI_ERROR (Status)) {
781 NumberRecoveryCapsules = 0;
782 Status = DeviceRecoveryPpi->GetNumberRecoveryCapsules (
785 &NumberRecoveryCapsules
787 DEBUG ((DEBUG_ERROR,
"LoadRecoveryCapsule - GetNumberRecoveryCapsules (%d) - %r\n", NumberRecoveryCapsules, Status));
788 if (EFI_ERROR (Status)) {
792 for (CapsuleInstance = 1; CapsuleInstance <= NumberRecoveryCapsules; CapsuleInstance++) {
794 Status = DeviceRecoveryPpi->GetRecoveryCapsuleInfo (
801 DEBUG ((DEBUG_ERROR,
"LoadRecoveryCapsule - GetRecoveryCapsuleInfo (%d - %x) - %r\n", CapsuleInstance, CapsuleSize, Status));
802 if (EFI_ERROR (Status)) {
807 if (CapsuleBuffer ==
NULL) {
808 DEBUG ((DEBUG_ERROR,
"LoadRecoveryCapsule - AllocatePool fail\n"));
812 Status = DeviceRecoveryPpi->LoadRecoveryCapsule (
818 DEBUG ((DEBUG_ERROR,
"LoadRecoveryCapsule - LoadRecoveryCapsule (%d) - %r\n", CapsuleInstance, Status));
819 if (EFI_ERROR (Status)) {
832 return EFI_NOT_FOUND;
VOID EFIAPI BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
EFI_BOOT_MODE EFIAPI GetBootModeHob(VOID)
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI ExtractSystemFirmwareImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **SystemFirmwareImage, OUT UINTN *SystemFirmwareImageSize)
EFI_STATUS EFIAPI CapsuleAuthenticateSystemFirmware(IN VOID *Image, IN UINTN ImageSize, IN BOOLEAN ForceVersionMatch, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, OUT VOID **AuthenticatedImage, OUT UINTN *AuthenticatedImageSize)
BOOLEAN EFIAPI ExtractConfigImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **ConfigImage, OUT UINTN *ConfigImageSize)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID EFIAPI PeiServicesInstallFvInfoPpi(IN CONST EFI_GUID *FvFormat OPTIONAL, IN CONST VOID *FvInfo, IN UINT32 FvInfoSize, IN CONST EFI_GUID *ParentFvName OPTIONAL, IN CONST EFI_GUID *ParentFileName OPTIONAL)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
BOOLEAN IsSystemFmp(IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfo)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGetSize(TokenName)
#define PcdGetPtr(TokenName)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
BOOLEAN IsFmpCapsuleGuid(IN EFI_GUID *CapsuleGuid)
EFI_STATUS ProcessRecoveryImage(IN VOID *Image, IN UINTN Length)
EFI_STATUS ParseRecoveryDataFile(IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT CONFIG_HEADER *ConfigHeader, IN OUT RECOVERY_CONFIG_DATA **RecoveryArray)
EFI_STATUS EFIAPI LoadRecoveryCapsule(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_MODULE_PPI *This)
EFI_STATUS ProcessFmpCapsuleImage(IN EFI_CAPSULE_HEADER *CapsuleHeader, IN BOOLEAN IsSystemFmp)
EFI_STATUS EFIAPI CreateHobForRecoveryCapsule(IN VOID *FvImage, IN UINTN FvImageSize)
EFI_STATUS EFIAPI ProcessRecoveryCapsule(IN VOID *CapsuleBuffer, IN UINTN CapsuleSize)
EFI_STATUS EFIAPI InitializeRecoveryModule(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS ValidateFmpCapsule(IN EFI_CAPSULE_HEADER *CapsuleHeader, OUT BOOLEAN *IsSystemFmp OPTIONAL, OUT UINT16 *EmbeddedDriverCount OPTIONAL)
BOOLEAN IsSystemFmpCapsuleImage(IN EFI_CAPSULE_HEADER *CapsuleHeader)
BOOLEAN IsValidCapsuleHeader(IN EFI_CAPSULE_HEADER *CapsuleHeader, IN UINT64 CapsuleSize)
BOOLEAN IsSystemFmpImage(IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *FmpImageHeader)
EFI_STATUS RecoverImage(IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, IN VOID *ConfigImage, IN UINTN ConfigImageSize)
#define EFI_SIZE_TO_PAGES(Size)
UINT16 EmbeddedDriverCount
UINT32 UpdateVendorCodeSize
EFI_FVB_ATTRIBUTES_2 Attributes