]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Correct PeiCore not dispatch the register for shadow image without relocation.
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 24 Jan 2010 12:55:59 +0000 (12:55 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 24 Jan 2010 12:55:59 +0000 (12:55 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9796 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg/Core/Pei/Image/Image.c
MdeModulePkg/Core/Pei/PeiMain.h

index c63bce8fd8afae409e6e8f8f7a9b307f6b1f66fc..6883bc300f1f35ecaeb110cb92501d751b889cb6 100644 (file)
@@ -221,6 +221,7 @@ ShadowPeiCore(
   Status = PeiLoadImage (\r
               PeiServices,\r
               *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+              PEIM_STATE_REGISITER_FOR_SHADOW,\r
               &EntryPoint,\r
               &AuthenticationState\r
               );\r
@@ -298,6 +299,7 @@ PeiDispatcher (
           Status = PeiLoadImage (\r
                     (CONST EFI_PEI_SERVICES **) &Private->PS,\r
                     PeimFileHandle,\r
+                    PEIM_STATE_REGISITER_FOR_SHADOW,\r
                     &EntryPoint,\r
                     &AuthenticationState\r
                     );\r
@@ -401,6 +403,7 @@ PeiDispatcher (
               Status = PeiLoadImage (\r
                          PeiServices,\r
                          PeimFileHandle,\r
+                         PEIM_STATE_NOT_DISPATCHED,\r
                          &EntryPoint,\r
                          &AuthenticationState\r
                          );\r
@@ -820,3 +823,4 @@ PeiRegisterForShadow (
 }\r
 \r
 \r
+\r
index 24ecd93ad88b2f6e4b4416a67cd457d82be2bc96..b7c1f96e0fcb68a6ef14b85fd8dd00fda2c5010b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Load Image Support\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2010, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -100,7 +100,7 @@ GetImageReadFunction (
 /**\r
 \r
   Loads and relocates a PE/COFF image into memory.\r
-\r
+  If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.\r
 \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
@@ -109,7 +109,6 @@ GetImageReadFunction (
 \r
   @retval EFI_SUCCESS           The file was loaded and relocated\r
   @retval EFI_OUT_OF_RESOURCES  There was not enough memory to load and relocate the PE/COFF file\r
-  @retval EFI_INVALID_PARAMETER The image withou .reloc section can't be relocated.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -140,14 +139,23 @@ LoadAndRelocatePeCoffImage (
   // When Image has no reloc section, it can't be relocated into memory.\r
   //\r
   if (ImageContext.RelocationsStripped) {\r
-    DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));\r
+    DEBUG ((EFI_D_INFO, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));\r
   }\r
+  \r
+  //\r
+  // Set default base address to current image address.\r
+  //\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;\r
+  \r
   //\r
-  // Allocate Memory for the image\r
+  // Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.\r
   //\r
   if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
     ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));\r
     ASSERT (ImageContext.ImageAddress != 0);\r
+    if (ImageContext.ImageAddress == 0) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
     \r
     //\r
     // Skip the reserved space for the stripped PeHeader when load TeImage into memory.\r
@@ -157,8 +165,6 @@ LoadAndRelocatePeCoffImage (
                                   ((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize -\r
                                   sizeof (EFI_TE_IMAGE_HEADER);\r
     }\r
-  } else {\r
-    ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;\r
   }\r
 \r
   //\r
@@ -179,7 +185,7 @@ LoadAndRelocatePeCoffImage (
   //\r
   // Flush the instruction cache so the image data is written before we execute it\r
   //\r
-  if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
+  if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
     InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r
   }\r
 \r
@@ -386,6 +392,66 @@ PeiLoadImageLoadImageWrapper (
            );\r
 }\r
 \r
+/**\r
+  Check whether the input image has the relocation.\r
+\r
+  @param  Pe32Data   Pointer to the PE/COFF or TE image.\r
+\r
+  @retval TRUE       Relocation is stripped.\r
+  @retval FALSE      Relocation is not stripped.\r
+\r
+**/\r
+BOOLEAN\r
+RelocationIsStrip (\r
+  IN VOID  *Pe32Data\r
+  )\r
+{\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
+  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
+\r
+  ASSERT (Pe32Data != NULL);\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+  } else {\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+  }\r
+\r
+  //\r
+  // Three cases with regards to relocations:\r
+  // - Image has base relocs, RELOCS_STRIPPED==0    => image is relocatable\r
+  // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable\r
+  // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but\r
+  //   has no base relocs to apply\r
+  // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.\r
+  //\r
+  // Look at the file header to determine if relocations have been stripped, and\r
+  // save this info in the image context for later use.\r
+  //\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    if ((Hdr.Te->DataDirectory[0].Size == 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {\r
+      return TRUE;\r
+    } else {\r
+      return FALSE;\r
+    }\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+    if ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0) {\r
+      return TRUE;\r
+    } else {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Routine to load image file for subsequent execution by LoadFile Ppi.\r
   If any LoadFile Ppi is not found, the build-in support function for the PE32+/TE \r
@@ -393,6 +459,7 @@ PeiLoadImageLoadImageWrapper (
 \r
   @param PeiServices     - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
   @param FileHandle      - Pointer to the FFS file header of the image.\r
+  @param PeimState       - The dispatch state of the input PEIM handle.\r
   @param EntryPoint      - Pointer to entry point of specified image file for output.\r
   @param AuthenticationState - Pointer to attestation authentication state of image.\r
 \r
@@ -405,6 +472,7 @@ EFI_STATUS
 PeiLoadImage (\r
   IN     CONST EFI_PEI_SERVICES       **PeiServices,\r
   IN     EFI_PEI_FILE_HANDLE          FileHandle,\r
+  IN     UINT8                        PeimState,\r
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
   )\r
@@ -415,7 +483,9 @@ PeiLoadImage (
   EFI_PEI_LOAD_FILE_PPI   *LoadFile;\r
   EFI_PHYSICAL_ADDRESS    ImageAddress;\r
   UINT64                  ImageSize;\r
+  BOOLEAN                 IsStrip;\r
 \r
+  IsStrip = FALSE;\r
   //\r
   // If any instances of PEI_LOAD_FILE_PPI are installed, they are called.\r
   // one at a time, until one reports EFI_SUCCESS.\r
@@ -438,6 +508,17 @@ PeiLoadImage (
                           AuthenticationState\r
                           );\r
       if (!EFI_ERROR (Status)) {\r
+        //\r
+        // The shadowed PEIM must be relocatable.\r
+        //\r
+        if (PeimState == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
+          IsStrip = RelocationIsStrip ((VOID *) (UINTN) ImageAddress);\r
+          ASSERT (!IsStrip);\r
+          if (IsStrip) {\r
+            return EFI_UNSUPPORTED;\r
+          }\r
+        }\r
+\r
         //\r
         // The image to be started must have the machine type supported by PeiCore.\r
         //\r
@@ -488,3 +569,4 @@ InitializeImageServices (
 \r
 \r
 \r
+\r
index 130a16d526a0983fc6c5b1294634c91bc25244b4..aa23cc57edae9caf6096233f78cde112c7f4682f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Definition of Pei Core Structures and Services\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation\r
+Copyright (c) 2006 - 2010, Intel Corporation\r
 All rights reserved. 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
@@ -815,6 +815,7 @@ PeiAllocatePool (
 \r
   @param PeiServices            An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param FileHandle             Pointer to the FFS file header of the image.\r
+  @param PeimState              The dispatch state of the input PEIM handle.\r
   @param EntryPoint             Pointer to entry point of specified image file for output.\r
   @param AuthenticationState    Pointer to attestation authentication state of image.\r
 \r
@@ -827,6 +828,7 @@ EFI_STATUS
 PeiLoadImage (\r
   IN  CONST EFI_PEI_SERVICES      **PeiServices,\r
   IN  EFI_PEI_FILE_HANDLE         FileHandle,\r
+  IN  UINT8                       PeimState,\r
   OUT    EFI_PHYSICAL_ADDRESS     *EntryPoint,\r
   OUT    UINT32                   *AuthenticationState\r
   );\r