]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Image/Image.c
MdeModulePkg PeiCore: PEI dispatcher need retry to process NOT_DISPATCHED FV
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Image / Image.c
index cab08fed91db52dfb2699e665f18d3e765f1165f..9c54192d86b7366c3ccedc608207e6c26b75ee4c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Load Image Support\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -117,7 +117,8 @@ GetImageReadFunction (
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
   \r
-  if (Private->PeiMemoryInstalled  && ((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) || PcdGetBool (PcdShadowPeimOnS3Boot))  &&\r
+  if (Private->PeiMemoryInstalled  && (((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)) || \r
+      ((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) &&\r
       (EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) {\r
     // \r
     // Shadow algorithm makes lots of non ANSI C assumptions and only works for IA32 and X64 \r
@@ -328,6 +329,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
   Loads and relocates a PE/COFF image into memory.\r
   If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.\r
 \r
+  @param FileHandle      - Pointer to the FFS file header of the image.\r
   @param Pe32Data        - The base address of the PE/COFF file that is to be loaded and relocated\r
   @param ImageAddress    - The base address of the relocated PE/COFF image\r
   @param ImageSize       - The size of the relocated PE/COFF image\r
@@ -342,6 +344,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
 **/\r
 EFI_STATUS\r
 LoadAndRelocatePeCoffImage (\r
+  IN  EFI_PEI_FILE_HANDLE                       FileHandle,\r
   IN  VOID                                      *Pe32Data,\r
   OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
   OUT UINT64                                    *ImageSize,\r
@@ -354,6 +357,8 @@ LoadAndRelocatePeCoffImage (
   UINT64                                AlignImageSize;\r
   BOOLEAN                               IsXipImage;\r
   EFI_STATUS                            ReturnStatus;\r
+  BOOLEAN                               IsS3Boot;\r
+  BOOLEAN                               IsRegisterForShadow;\r
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
 \r
@@ -370,6 +375,19 @@ LoadAndRelocatePeCoffImage (
     return Status;\r
   }\r
   \r
+  //\r
+  // Initilize local IsS3Boot and IsRegisterForShadow variable\r
+  //\r
+  IsS3Boot = FALSE;\r
+  if (Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) {\r
+    IsS3Boot = TRUE;\r
+  }\r
+  IsRegisterForShadow = FALSE;\r
+  if ((Private->CurrentFileHandle == FileHandle) \r
+    && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW)) {\r
+    IsRegisterForShadow = TRUE;\r
+  }\r
+\r
   //\r
   // XIP image that ImageAddress is same to Image handle.\r
   //\r
@@ -380,7 +398,8 @@ LoadAndRelocatePeCoffImage (
   //\r
   // When Image has no reloc section, it can't be relocated into memory.\r
   //\r
-  if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
+  if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (\r
+      (!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
     DEBUG ((EFI_D_INFO|EFI_D_LOAD, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));\r
   }\r
 \r
@@ -390,9 +409,12 @@ LoadAndRelocatePeCoffImage (
   ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;\r
 \r
   //\r
-  // Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.\r
+  // Allocate Memory for the image when memory is ready, and image is relocatable.\r
+  // On normal boot, PcdShadowPeimOnBoot decides whether load PEIM or PeiCore into memory.\r
+  // On S3 boot, PcdShadowPeimOnS3Boot decides whether load PEIM or PeiCore into memory.\r
   //\r
-  if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
+  if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (\r
+      (!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
     //\r
     // Allocate more buffer to avoid buffer overflow.\r
     //\r
@@ -571,6 +593,7 @@ PeiLoadImageLoadImage (
   // If memory is installed, perform the shadow operations\r
   //\r
   Status = LoadAndRelocatePeCoffImage (\r
+    FileHandle,\r
     Pe32Data,\r
     &ImageAddress,\r
     &ImageSize,\r