]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
Roll back changes to apply GetBestLanguage() in HiiDataBase. Exact language match...
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / DxeLoad.c
index 914f4575fdc642753e18824465bb3c510f630165..d8f047e80d8677731f300b8be9bb4f39690c328d 100644 (file)
@@ -2,7 +2,7 @@
   Last PEIM.\r
   Responsibility of this module is to load the DXE Core from a Firmware Volume.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation. <BR>\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
@@ -14,155 +14,61 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "DxeIpl.h"\r
-#include <Ppi/GuidedSectionExtraction.h>\r
 \r
 \r
-\r
-/**\r
-  The ExtractSection() function processes the input section and\r
-  returns a pointer to the section contents. If the section being\r
-  extracted does not require processing (if the section\r
-  GuidedSectionHeader.Attributes has the\r
-  EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r
-  OutputBuffer is just updated to point to the start of the\r
-  section's contents. Otherwise, *Buffer must be allocated\r
-  from PEI permanent memory.\r
-\r
-  @param This                   Indicates the\r
-                                EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r
-                                Buffer containing the input GUIDed section to be\r
-                                processed. OutputBuffer OutputBuffer is\r
-                                allocated from PEI permanent memory and contains\r
-                                the new section stream.\r
-  @param InputSection           A pointer to the input buffer, which contains\r
-                                the input section to be processed.\r
-  @param OutputBuffer           A pointer to a caller-allocated buffer, whose\r
-                                size is specified by the contents of OutputSize.\r
-  @param OutputSize             A pointer to a caller-allocated\r
-                                UINTN in which the size of *OutputBuffer\r
-                                allocation is stored. If the function\r
-                                returns anything other than EFI_SUCCESS,\r
-                                the value of OutputSize is undefined.\r
-  @param AuthenticationStatus   A pointer to a caller-allocated\r
-                                UINT32 that indicates the\r
-                                authentication status of the\r
-                                output buffer. If the input\r
-                                section's GuidedSectionHeader.\r
-                                Attributes field has the\r
-                                EFI_GUIDED_SECTION_AUTH_STATUS_VALID \r
-                                bit as clear,\r
-                                AuthenticationStatus must return\r
-                                zero. These bits reflect the\r
-                                status of the extraction\r
-                                operation. If the function\r
-                                returns anything other than\r
-                                EFI_SUCCESS, the value of\r
-                                AuthenticationStatus is\r
-                                undefined.\r
-  \r
-  @retval EFI_SUCCESS           The InputSection was\r
-                                successfully processed and the\r
-                                section contents were returned.\r
-  \r
-  @retval EFI_OUT_OF_RESOURCES  The system has insufficient\r
-                                resources to process the request.\r
-  \r
-  @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r
-                                not match this instance of the\r
-                                GUIDed Section Extraction PPI.\r
-\r
-**/\r
-EFI_STATUS\r
-CustomGuidedSectionExtract (\r
-  IN CONST  EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r
-  IN CONST  VOID                                  *InputSection,\r
-  OUT       VOID                                  **OutputBuffer,\r
-  OUT       UINTN                                 *OutputSize,\r
-  OUT       UINT32                                *AuthenticationStatus\r
-);\r
-\r
-\r
-/**\r
-   Decompresses a section to the output buffer.\r
-\r
-   This function lookes up the compression type field in the input section and\r
-   applies the appropriate compression algorithm to compress the section to a\r
-   callee allocated buffer.\r
-    \r
-   @param  This                  Points to this instance of the\r
-                                 EFI_PEI_DECOMPRESS_PEI PPI.\r
-   @param  CompressionSection    Points to the compressed section.\r
-   @param  OutputBuffer          Holds the returned pointer to the decompressed\r
-                                 sections.\r
-   @param  OutputSize            Holds the returned size of the decompress\r
-                                 section streams.\r
-   \r
-   @retval EFI_SUCCESS           The section was decompressed successfully.\r
-                                 OutputBuffer contains the resulting data and\r
-                                 OutputSize contains the resulting size.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI \r
-Decompress (\r
-  IN CONST  EFI_PEI_DECOMPRESS_PPI  *This,\r
-  IN CONST  EFI_COMPRESSION_SECTION *CompressionSection,\r
-  OUT       VOID                    **OutputBuffer,\r
-  OUT       UINTN                   *OutputSize\r
- );\r
-\r
-\r
-BOOLEAN gInMemory = FALSE;\r
-\r
 //\r
-// Module Globals used in the DXE to PEI handoff\r
+// Module Globals used in the DXE to PEI hand off\r
 // These must be module globals, so the stack can be switched\r
 //\r
-STATIC EFI_DXE_IPL_PPI mDxeIplPpi = {\r
+CONST EFI_DXE_IPL_PPI mDxeIplPpi = {\r
   DxeLoadCore\r
 };\r
 \r
-STATIC EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r
+CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r
   CustomGuidedSectionExtract\r
 };\r
 \r
-STATIC EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {\r
+CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {\r
   Decompress\r
 };\r
 \r
-STATIC EFI_PEI_PPI_DESCRIPTOR     mPpiList[] = {\r
+CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r
   {\r
     EFI_PEI_PPI_DESCRIPTOR_PPI,\r
     &gEfiDxeIplPpiGuid,\r
-    &mDxeIplPpi\r
+    (VOID *) &mDxeIplPpi\r
   },\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
     &gEfiPeiDecompressPpiGuid,\r
-    &mDecompressPpi\r
+    (VOID *) &mDecompressPpi\r
   }\r
 };\r
 \r
-STATIC EFI_PEI_PPI_DESCRIPTOR     mPpiSignal = {\r
+CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {\r
   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiEndOfPeiSignalPpiGuid,\r
   NULL\r
 };\r
 \r
 /**\r
-  Initializes the Dxe Ipl PPI\r
+  Entry point of DXE IPL PEIM.\r
+  \r
+  This function installs DXE IPL PPI and Decompress PPI.  It also reloads\r
+  itself to memory on non-S3 resume boot path.\r
 \r
-  @param  FfsHandle   The handle of FFS file.\r
-  @param  PeiServices General purpose services available to\r
-                      every PEIM.\r
-  @return EFI_SUCESS\r
+  @param  FileHandle  Handle of the file being invoked.\r
+  @param  PeiServices Describes the list of possible PEI Services.\r
+\r
+  @retval EFI_SUCESS  The entry point of DXE IPL PEIM executes successfully.\r
+  @retval Others      Some error occurs during the execution of this function. \r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializeDxeIpl (\r
-  IN EFI_PEI_FILE_HANDLE       FfsHandle,\r
-  IN EFI_PEI_SERVICES          **PeiServices\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
   EFI_STATUS                                Status;\r
@@ -171,43 +77,42 @@ PeimInitializeDxeIpl (
   UINTN                                     ExtractHandlerNumber;\r
   EFI_PEI_PPI_DESCRIPTOR                    *GuidPpi;\r
   \r
-  Status = PeiServicesGetBootMode (&BootMode);\r
-  ASSERT_EFI_ERROR (Status);\r
+  BootMode = GetBootModeHob ();\r
 \r
   if (BootMode != BOOT_ON_S3_RESUME) {\r
-    Status = PeiServicesRegisterForShadow (FfsHandle);\r
+    Status = PeiServicesRegisterForShadow (FileHandle);\r
     if (Status == EFI_SUCCESS) {\r
       //\r
-      // EFI_SUCESS means the first time call register for shadow \r
+      // EFI_SUCESS means it is the first time to call register for shadow. \r
       // \r
       return Status;\r
-    } else if (Status == EFI_ALREADY_STARTED) {\r
-      \r
-      gInMemory = TRUE;\r
-      \r
-      //\r
-      // Get custom extract guided section method guid list \r
-      //\r
-      ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r
-      \r
-      //\r
-      // Install custom extraction guid ppi\r
-      //\r
-      if (ExtractHandlerNumber > 0) {\r
-        GuidPpi = NULL;\r
-        GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
-        ASSERT (GuidPpi != NULL);\r
-        while (ExtractHandlerNumber-- > 0) {\r
-          GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
-          GuidPpi->Ppi   = &mCustomGuidedSectionExtractionPpi;\r
-          GuidPpi->Guid  = &(ExtractHandlerGuidTable [ExtractHandlerNumber]);\r
-          Status = PeiServicesInstallPpi (GuidPpi++);\r
-          ASSERT_EFI_ERROR(Status);\r
-        }\r
+    }\r
+    \r
+    //\r
+    // Ensure that DXE IPL is shadowed to permanent memory.\r
+    //\r
+    ASSERT (Status == EFI_ALREADY_STARTED);\r
+     \r
+    //\r
+    // Get custom extract guided section method guid list \r
+    //\r
+    ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r
+    \r
+    //\r
+    // Install custom extraction guid PPI\r
+    //\r
+    if (ExtractHandlerNumber > 0) {\r
+      GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
+      ASSERT (GuidPpi != NULL);\r
+      while (ExtractHandlerNumber-- > 0) {\r
+        GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
+        GuidPpi->Ppi   = (VOID *) &mCustomGuidedSectionExtractionPpi;\r
+        GuidPpi->Guid  = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r
+        Status = PeiServicesInstallPpi (GuidPpi++);\r
+        ASSERT_EFI_ERROR(Status);\r
       }\r
-    } else {\r
-      ASSERT (FALSE);\r
     }\r
+    \r
   }\r
   \r
   //\r
@@ -220,11 +125,14 @@ PeimInitializeDxeIpl (
 }\r
 \r
 /**\r
-   Main entry point to last PEIM \r
+   Main entry point to last PEIM. \r
+\r
+   This function finds DXE Core in the firmware volume and transfer the control to\r
+   DXE core.\r
     \r
-   @param This          Entry point for DXE IPL PPI\r
+   @param This          Entry point for DXE IPL PPI.\r
    @param PeiServices   General purpose services available to every PEIM.\r
-   @param HobList       Address to the Pei HOB list\r
+   @param HobList       Address to the Pei HOB list.\r
    \r
    @return EFI_SUCCESS              DXE core was successfully loaded. \r
    @return EFI_OUT_OF_RESOURCES     There are not enough resources to load DXE core.\r
@@ -233,13 +141,13 @@ PeimInitializeDxeIpl (
 EFI_STATUS\r
 EFIAPI\r
 DxeLoadCore (\r
-  IN EFI_DXE_IPL_PPI       *This,\r
+  IN CONST EFI_DXE_IPL_PPI *This,\r
   IN EFI_PEI_SERVICES      **PeiServices,\r
   IN EFI_PEI_HOB_POINTERS  HobList\r
   )\r
 {\r
   EFI_STATUS                                Status;\r
-  EFI_GUID                                  DxeCoreFileName;\r
+  EFI_FV_FILE_INFO                          DxeCoreFileInfo;\r
   EFI_PHYSICAL_ADDRESS                      DxeCoreAddress;\r
   UINT64                                    DxeCoreSize;\r
   EFI_PHYSICAL_ADDRESS                      DxeCoreEntryPoint;\r
@@ -252,8 +160,7 @@ DxeLoadCore (
   //\r
   // if in S3 Resume, restore configure\r
   //\r
-  Status = PeiServicesGetBootMode (&BootMode);\r
-  ASSERT_EFI_ERROR(Status);\r
+  BootMode = GetBootModeHob ();\r
 \r
   if (BootMode == BOOT_ON_S3_RESUME) {\r
     Status = AcpiS3ResumeOs();\r
@@ -266,7 +173,7 @@ DxeLoadCore (
     }\r
 \r
     //\r
-    // Now should have a HOB with the DXE core w/ the old HOB destroyed\r
+    // Now should have a HOB with the DXE core\r
     //\r
   }\r
 \r
@@ -276,91 +183,75 @@ DxeLoadCore (
              NULL,\r
              (VOID **)&Variable\r
              );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  DataSize = sizeof (MemoryData);\r
-  Status = Variable->GetVariable ( \r
-                       Variable, \r
-                       EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
-                       &gEfiMemoryTypeInformationGuid,\r
-                       NULL,\r
-                       &DataSize,\r
-                       &MemoryData\r
-                       );\r
-\r
   if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Build the GUID'd HOB for DXE\r
-    //\r
-    BuildGuidDataHob (\r
-      &gEfiMemoryTypeInformationGuid,\r
-      MemoryData,\r
-      DataSize\r
-      );\r
+    DataSize = sizeof (MemoryData);\r
+    Status = Variable->GetVariable ( \r
+                         Variable, \r
+                         EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+                         &gEfiMemoryTypeInformationGuid,\r
+                         NULL,\r
+                         &DataSize,\r
+                         &MemoryData\r
+                         );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Build the GUID'd HOB for DXE\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiMemoryTypeInformationGuid,\r
+        MemoryData,\r
+        DataSize\r
+        );\r
+    }\r
   }\r
 \r
   //\r
-  // Look in all the FVs present in PEI and find the DXE Core\r
+  // Look in all the FVs present in PEI and find the DXE Core FileHandle\r
   //\r
-  FileHandle = NULL;\r
-  Status = DxeIplFindDxeCore (&FileHandle);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  CopyMem(&DxeCoreFileName, &(((EFI_FFS_FILE_HEADER*)FileHandle)->Name), sizeof (EFI_GUID));\r
+  FileHandle = DxeIplFindDxeCore ();\r
 \r
   //\r
-  // Load the DXE Core from a Firmware Volume, may use LoadFile ppi to do this for save code size.\r
+  // Load the DXE Core from a Firmware Volume, may use LoadFile PPI to do this to save code size.\r
   //\r
   Status = PeiLoadFile (\r
-            FileHandle,\r
-            &DxeCoreAddress,\r
-            &DxeCoreSize,\r
-            &DxeCoreEntryPoint\r
-            );\r
+             FileHandle,\r
+             &DxeCoreAddress,\r
+             &DxeCoreSize,\r
+             &DxeCoreEntryPoint\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.\r
+  //\r
+  Status = PeiServicesFfsGetFileInfo (FileHandle, &DxeCoreFileInfo);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Add HOB for the DXE Core\r
   //\r
   BuildModuleHob (\r
-    &DxeCoreFileName,\r
+    &DxeCoreFileInfo.FileName,\r
     DxeCoreAddress,\r
-    EFI_SIZE_TO_PAGES ((UINT32) DxeCoreSize) * EFI_PAGE_SIZE,\r
+    ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),\r
     DxeCoreEntryPoint\r
     );\r
 \r
   //\r
   // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
   //\r
-  REPORT_STATUS_CODE (\r
-    EFI_PROGRESS_CODE,\r
-    PcdGet32(PcdStatusCodeValuePeiHandoffToDxe)\r
-    );\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValuePeiHandoffToDxe));\r
 \r
-  DEBUG_CODE_BEGIN ();\r
+  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r
 \r
-    EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION       PtrPeImage;\r
-    PtrPeImage.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) DxeCoreAddress + ((EFI_IMAGE_DOS_HEADER *) (UINTN) DxeCoreAddress)->e_lfanew);\r
-    \r
-    if (PtrPeImage.Pe32->FileHeader.Machine != IMAGE_FILE_MACHINE_IA64) {\r
-      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)DxeCoreAddress, (VOID *)(UINTN)DxeCoreEntryPoint));\r
-    } else {\r
-      //\r
-      // For IPF Image, the real entry point should be print.\r
-      //\r
-      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)DxeCoreAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)DxeCoreEntryPoint)));\r
-    }\r
-\r
-  DEBUG_CODE_END ();\r
   //\r
   // Transfer control to the DXE Core\r
-  // The handoff state is simply a pointer to the HOB list\r
+  // The hand off state is simply a pointer to the HOB list\r
   //\r
-  HandOffToDxeCore (DxeCoreEntryPoint, HobList, &mPpiSignal);\r
+  HandOffToDxeCore (DxeCoreEntryPoint, HobList);\r
   //\r
   // If we get here, then the DXE Core returned.  This is an error\r
-  // Dxe Core should not return.\r
+  // DxeCore should not return.\r
   //\r
   ASSERT (FALSE);\r
   CpuDeadLoop ();\r
@@ -369,46 +260,55 @@ DxeLoadCore (
 }\r
 \r
 \r
-\r
-\r
 /**\r
-   Find DxeCore driver from all First Volumes.\r
+   Searches DxeCore in all firmware Volumes and loads the first\r
+   instance that contains DxeCore.\r
 \r
-   @param FileHandle    Pointer to FFS file to search.\r
+   @return FileHandle of DxeCore to load DxeCore.\r
    \r
-   @return EFI_SUCESS   Success to find the FFS in specificed FV\r
-   @return others       Fail to find the FFS in specificed FV\r
-\r
 **/\r
-EFI_STATUS\r
+EFI_PEI_FILE_HANDLE\r
 DxeIplFindDxeCore (\r
-  OUT EFI_PEI_FILE_HANDLE   *FileHandle\r
+  VOID\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  EFI_STATUS        FileStatus;\r
-  UINTN             Instance;\r
-  EFI_PEI_FV_HANDLE VolumeHandle;\r
+  EFI_STATUS            Status;\r
+  UINTN                 Instance;\r
+  EFI_PEI_FV_HANDLE     VolumeHandle;\r
+  EFI_PEI_FILE_HANDLE   FileHandle;\r
   \r
   Instance    = 0;\r
-  *FileHandle = NULL;\r
-\r
-  do {\r
-    Status = PeiServicesFfsFindNextVolume (Instance++, &VolumeHandle);\r
+  while (TRUE) {\r
+    //\r
+    // Traverse all firmware volume instances\r
+    //\r
+    Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r
+    //\r
+    // If some error occurs here, then we cannot find any firmware\r
+    // volume that may contain DxeCore.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Find the DxeCore file type from the beginning in this firmware volume.\r
+    //\r
+    FileHandle = NULL;\r
+    Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);\r
     if (!EFI_ERROR (Status)) {\r
-      FileStatus = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, FileHandle);\r
-      if (!EFI_ERROR (FileStatus)) {\r
-        return FileStatus;\r
-      }\r
+      //\r
+      // Find DxeCore FileHandle in this volume, then we skip other firmware volume and\r
+      // return the FileHandle.\r
+      //\r
+      return FileHandle;\r
     }\r
-  } while (!EFI_ERROR (Status));\r
-\r
-  return EFI_NOT_FOUND;\r
+    //\r
+    // We cannot find DxeCore in this firmware volume, then search the next volume.\r
+    //\r
+    Instance++;\r
+  }\r
 }\r
 \r
 \r
-\r
-\r
 /**\r
    Loads and relocates a PE/COFF image into memory.\r
 \r
@@ -433,6 +333,7 @@ PeiLoadFile (
   EFI_STATUS                        Status;\r
   PE_COFF_LOADER_IMAGE_CONTEXT      ImageContext;\r
   VOID                              *Pe32Data;\r
+\r
   //\r
   // First try to find the PE32 section in this ffs file.\r
   //\r
@@ -441,7 +342,6 @@ PeiLoadFile (
              FileHandle,\r
              &Pe32Data\r
              );\r
-  \r
   if (EFI_ERROR (Status)) {\r
     //\r
     // NO image types we support so exit.\r
@@ -451,9 +351,8 @@ PeiLoadFile (
 \r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
   ImageContext.Handle = Pe32Data;\r
-  Status              = GetImageReadFunction (&ImageContext);\r
+  ImageContext.ImageRead = PeiImageRead;\r
 \r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
@@ -462,7 +361,12 @@ PeiLoadFile (
   //\r
   // Allocate Memory for the image\r
   //\r
-  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize));\r
+  Status = PeiServicesAllocatePages (\r
+             EfiBootServicesCode, \r
+             EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize), \r
+             &ImageContext.ImageAddress\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
   ASSERT (ImageContext.ImageAddress != 0);\r
 \r
   //\r
@@ -481,9 +385,9 @@ PeiLoadFile (
   }\r
 \r
   //\r
-  // Flush the instruction cache so the image data is written before we execute it\r
+  // Flush the instruction cache so the image data are written before we execute it\r
   //\r
-  InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r
+  InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize);\r
 \r
   *ImageAddress = ImageContext.ImageAddress;\r
   *ImageSize    = ImageContext.ImageSize;\r
@@ -550,6 +454,7 @@ PeiLoadFile (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 CustomGuidedSectionExtract (\r
   IN CONST  EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r
   IN CONST  VOID                                  *InputSection,\r
@@ -573,11 +478,11 @@ CustomGuidedSectionExtract (
   // Call GetInfo to get the size and attribute of input guided section data.\r
   //\r
   Status = ExtractGuidedSectionGetInfo (\r
-            InputSection,\r
-            &OutputBufferSize,\r
-            &ScratchBufferSize,\r
-            &SectionAttribute\r
-           );\r
+             InputSection,\r
+             &OutputBufferSize,\r
+             &ScratchBufferSize,\r
+             &SectionAttribute\r
+             );\r
   \r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r
@@ -602,7 +507,7 @@ CustomGuidedSectionExtract (
     if (*OutputBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    DEBUG ((DEBUG_INFO, "Customed Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r
+    DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r
     //\r
     // *OutputBuffer still is one section. Adjust *OutputBuffer offset, \r
     // skip EFI section header to make section data at page alignment.\r
@@ -615,8 +520,7 @@ CustomGuidedSectionExtract (
              OutputBuffer,\r
              ScratchBuffer,\r
              AuthenticationStatus\r
-           );\r
-\r
+             );\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Decode failed\r
@@ -635,7 +539,7 @@ CustomGuidedSectionExtract (
 /**\r
    Decompresses a section to the output buffer.\r
 \r
-   This function lookes up the compression type field in the input section and\r
+   This function looks up the compression type field in the input section and\r
    applies the appropriate compression algorithm to compress the section to a\r
    callee allocated buffer.\r
     \r
@@ -675,65 +579,74 @@ Decompress (
   }\r
 \r
   Section = (EFI_COMMON_SECTION_HEADER *) CompressionSection;\r
-  SectionLength         = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
+  SectionLength = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
   \r
   //\r
   // This is a compression set, expand it\r
   //\r
   switch (CompressionSection->CompressionType) {\r
   case EFI_STANDARD_COMPRESSION:\r
-    //\r
-    // Load EFI standard compression.\r
-    // For compressed data, decompress them to dstbuffer.\r
-    //\r
-    Status = UefiDecompressGetInfo (\r
-               (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-               (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
-               (UINT32 *) &DstBufferSize,\r
-               &ScratchBufferSize\r
-               );\r
-    if (EFI_ERROR (Status)) {\r
+    if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {\r
       //\r
-      // GetInfo failed\r
+      // Load EFI standard compression.\r
+      // For compressed data, decompress them to destination buffer.\r
       //\r
-      DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
-      return EFI_NOT_FOUND;\r
-    }\r
-    //\r
-    // Allocate scratch buffer\r
-    //\r
-    ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
-    if (ScratchBuffer == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    //\r
-    // Allocate destination buffer, extra one page for adjustment \r
-    //\r
-    DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r
-    if (DstBuffer == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    //\r
-    // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r
-    // to make section data at page alignment.\r
-    //\r
-    DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r
-    //\r
-    // Call decompress function\r
-    //\r
-    Status = UefiDecompress (\r
-                (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                DstBuffer,\r
-                ScratchBuffer\r
-                );\r
-    if (EFI_ERROR (Status)) {\r
+      Status = UefiDecompressGetInfo (\r
+                 (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                 (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                 (UINT32 *) &DstBufferSize,\r
+                 &ScratchBufferSize\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // GetInfo failed\r
+        //\r
+        DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      //\r
+      // Allocate scratch buffer\r
+      //\r
+      ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+      if (ScratchBuffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      //\r
+      // Allocate destination buffer, extra one page for adjustment \r
       //\r
-      // Decompress failed\r
+      DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r
+      if (DstBuffer == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      //\r
+      // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r
+      // to make section data at page alignment.\r
+      //\r
+      DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r
+      //\r
+      // Call decompress function\r
       //\r
-      DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r
+      Status = UefiDecompress (\r
+                  (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                  DstBuffer,\r
+                  ScratchBuffer\r
+                  );\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Decompress failed\r
+        //\r
+        DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      break;\r
+    } else {\r
+      //\r
+      // PcdDxeIplSupportUefiDecompress is FALSE\r
+      // Don't support UEFI decompression algorithm.\r
+      //\r
+      ASSERT (FALSE);\r
       return EFI_NOT_FOUND;\r
     }\r
-    break;\r
 \r
   case EFI_NOT_COMPRESSED:\r
     //\r
@@ -770,8 +683,6 @@ Decompress (
 }\r
 \r
 \r
-\r
-\r
 /**\r
    Updates the Stack HOB passed to DXE phase.\r
 \r