]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Image/Image.c
Enable PeiCore to dispatch the encapsulated fv images with depex expression. This...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Image / Image.c
index a430d3ea7a78617f95b2047f019e9e7db6004139..2c7e5846cb8a710e61faef2b94cf2814937f3a75 100644 (file)
@@ -238,10 +238,26 @@ Returns:
     return Status;\r
   }\r
   //\r
+  // 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
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
   // Allocate Memory for the image\r
   //\r
   ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));\r
   ASSERT (ImageContext.ImageAddress != 0);\r
+  \r
+  //\r
+  // Skip the reserved space for the stripped PeHeader when load TeImage into memory.\r
+  //\r
+  if (ImageContext.IsTeImage) {\r
+    ImageContext.ImageAddress = ImageContext.ImageAddress + \r
+                                ((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize -\r
+                                sizeof (EFI_TE_IMAGE_HEADER);\r
+  }\r
 \r
   //\r
   // Load the image to our new buffer\r
@@ -310,25 +326,35 @@ Returns:
   UINT16                      Machine;\r
   PEI_CORE_INSTANCE           *Private;\r
   VOID                        *EntryPointArg;\r
+  EFI_SECTION_TYPE            SearchType1;\r
+  EFI_SECTION_TYPE            SearchType2;\r
 \r
   *EntryPoint          = 0;\r
   ImageSize            = 0;\r
   *AuthenticationState = 0;\r
 \r
+  if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst)) {\r
+    SearchType1 = EFI_SECTION_TE;\r
+    SearchType2 = EFI_SECTION_PE32;\r
+  } else {\r
+    SearchType1 = EFI_SECTION_PE32;\r
+    SearchType2 = EFI_SECTION_TE;\r
+  }\r
   //\r
-  // Try to find a TE section.\r
+  // Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst \r
+  // is true, TE will be searched first).\r
   //\r
   Status = PeiServicesFfsFindSectionData (\r
-             EFI_SECTION_TE,\r
+             SearchType1,\r
              FileHandle,\r
              &Pe32Data\r
              );\r
   //\r
-  // If we didn't find a TE section, try to find a PE32 section.\r
+  // If we didn't find a first exe section, try to find the second exe section.\r
   //\r
   if (EFI_ERROR (Status)) {\r
     Status = PeiServicesFfsFindSectionData (\r
-               EFI_SECTION_PE32,\r
+               SearchType2,\r
                FileHandle,\r
                &Pe32Data\r
                );\r
@@ -390,20 +416,31 @@ Returns:
     *ImageSizeArg = ImageSize;\r
   }\r
   \r
-  //\r
-  // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi\r
-  //\r
-  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, *EntryPoint));\r
   DEBUG_CODE_BEGIN ();\r
     CHAR8                              *AsciiString;\r
     CHAR8                              AsciiBuffer[512];\r
     INT32                              Index;\r
     INT32                              Index1;\r
+\r
+    //\r
+    // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi\r
+    //\r
+    if (Machine != IMAGE_FILE_MACHINE_IA64) {\r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%10p EntryPoint=0x%10p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)*EntryPoint));\r
+    } else {\r
+      //\r
+      // For IPF Image, the real entry point should be print.\r
+      //\r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%10p EntryPoint=0x%10p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));\r
+    }\r
     \r
+    //\r
+    // Print Module Name by PeImage PDB file name.\r
+    //\r
     AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);\r
     \r
     if (AsciiString != NULL) {\r
-      for (Index = AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) {\r
+      for (Index = (INT32) AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) {\r
         if (AsciiString[Index] == '\\') {\r
           break;\r
         }\r
@@ -557,8 +594,7 @@ InitializeImageServices (
 \r
 Routine Description:\r
 \r
-  Regitser PeCoffLoader to PeiCore PrivateData. And install\r
-  Pei Load File PPI.\r
+  Install Pei Load File PPI.\r
 \r
 Arguments:\r
 \r