]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/SecCore: Wrong Debug Information for SecCore
authorChasel, Chiu <chasel.chiu@intel.com>
Tue, 19 Feb 2019 07:30:23 +0000 (15:30 +0800)
committerChasel, Chiu <chasel.chiu@intel.com>
Wed, 20 Feb 2019 01:41:23 +0000 (09:41 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1533

When SecCore and PeiCore in different FV, current
implementation still assuming SecCore and PeiCore are in
the same FV.
To fix this issue 2 FVs will be input parameters for
FindAndReportEntryPoints () and SecCore and PeiCore will
be found in each FV and correct debug information will
be reported.

Test: Booted with internal platform successfully.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
UefiCpuPkg/SecCore/FindPeiCore.c
UefiCpuPkg/SecCore/SecMain.c
UefiCpuPkg/SecCore/SecMain.h

index bb9c434d1e5372d46c14f81ba044f1d3e0a95d7a..6f2046ad95c0005f0b3157dc0e5e3856824bc97e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Locate the entry point for the PEI Core\r
 \r
-  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2019, 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
 /**\r
   Find core image base.\r
 \r
-  @param   BootFirmwareVolumePtr    Point to the boot firmware volume.\r
-  @param   SecCoreImageBase         The base address of the SEC core image.\r
-  @param   PeiCoreImageBase         The base address of the PEI core image.\r
+  @param   FirmwareVolumePtr        Point to the firmware volume for finding core image.\r
+  @param   FileType                 The FileType for searching, either SecCore or PeiCore.\r
+  @param   CoreImageBase            The base address of the core image.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 FindImageBase (\r
-  IN  EFI_FIRMWARE_VOLUME_HEADER       *BootFirmwareVolumePtr,\r
-  OUT EFI_PHYSICAL_ADDRESS             *SecCoreImageBase,\r
-  OUT EFI_PHYSICAL_ADDRESS             *PeiCoreImageBase\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER       *FirmwareVolumePtr,\r
+  IN  EFI_FV_FILETYPE                  FileType,\r
+  OUT EFI_PHYSICAL_ADDRESS             *CoreImageBase\r
   )\r
 {\r
   EFI_PHYSICAL_ADDRESS        CurrentAddress;\r
@@ -40,16 +40,15 @@ FindImageBase (
   EFI_COMMON_SECTION_HEADER   *Section;\r
   EFI_PHYSICAL_ADDRESS        EndOfSection;\r
 \r
-  *SecCoreImageBase = 0;\r
-  *PeiCoreImageBase = 0;\r
+  *CoreImageBase = 0;\r
 \r
-  CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) BootFirmwareVolumePtr;\r
-  EndOfFirmwareVolume = CurrentAddress + BootFirmwareVolumePtr->FvLength;\r
+  CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) FirmwareVolumePtr;\r
+  EndOfFirmwareVolume = CurrentAddress + FirmwareVolumePtr->FvLength;\r
 \r
   //\r
   // Loop through the FFS files in the Boot Firmware Volume\r
   //\r
-  for (EndOfFile = CurrentAddress + BootFirmwareVolumePtr->HeaderLength; ; ) {\r
+  for (EndOfFile = CurrentAddress + FirmwareVolumePtr->HeaderLength; ; ) {\r
 \r
     CurrentAddress = (EndOfFile + 7) & 0xfffffffffffffff8ULL;\r
     if (CurrentAddress > EndOfFirmwareVolume) {\r
@@ -75,10 +74,9 @@ FindImageBase (
     }\r
 \r
     //\r
-    // Look for SEC Core / PEI Core files\r
+    // Look for particular Core file (either SEC Core or PEI Core)\r
     //\r
-    if (File->Type != EFI_FV_FILETYPE_SECURITY_CORE &&\r
-        File->Type != EFI_FV_FILETYPE_PEI_CORE) {\r
+    if (File->Type != FileType) {\r
       continue;\r
     }\r
 \r
@@ -115,17 +113,11 @@ FindImageBase (
       // Look for executable sections\r
       //\r
       if (Section->Type == EFI_SECTION_PE32 || Section->Type == EFI_SECTION_TE) {\r
-        if (File->Type == EFI_FV_FILETYPE_SECURITY_CORE) {\r
+        if (File->Type == FileType) {\r
           if (IS_SECTION2 (Section)) {\r
-            *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
+            *CoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
           } else {\r
-            *SecCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
-          }\r
-        } else {\r
-          if (IS_SECTION2 (Section)) {\r
-            *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2));\r
-          } else {\r
-            *PeiCoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
+            *CoreImageBase = (PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER));\r
           }\r
         }\r
         break;\r
@@ -133,9 +125,9 @@ FindImageBase (
     }\r
 \r
     //\r
-    // Both SEC Core and PEI Core images found\r
+    // Either SEC Core or PEI Core images found\r
     //\r
-    if (*SecCoreImageBase != 0 && *PeiCoreImageBase != 0) {\r
+    if (*CoreImageBase != 0) {\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -147,14 +139,16 @@ FindImageBase (
   It also find SEC and PEI Core file debug information. It will report them if\r
   remote debug is enabled.\r
 \r
-  @param   BootFirmwareVolumePtr    Point to the boot firmware volume.\r
+  @param   SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.\r
+  @param   PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.\r
   @param   PeiCoreEntryPoint        The entry point of the PEI core.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 FindAndReportEntryPoints (\r
-  IN  EFI_FIRMWARE_VOLUME_HEADER       *BootFirmwareVolumePtr,\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER       *SecCoreFirmwareVolumePtr,\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER       *PeiCoreFirmwareVolumePtr,\r
   OUT EFI_PEI_CORE_ENTRY_POINT         *PeiCoreEntryPoint\r
   )\r
 {\r
@@ -164,9 +158,9 @@ FindAndReportEntryPoints (
   PE_COFF_LOADER_IMAGE_CONTEXT     ImageContext;\r
 \r
   //\r
-  // Find SEC Core and PEI Core image base\r
+  // Find SEC Core image base\r
   //\r
-  Status = FindImageBase (BootFirmwareVolumePtr, &SecCoreImageBase, &PeiCoreImageBase);\r
+  Status = FindImageBase (SecCoreFirmwareVolumePtr, EFI_FV_FILETYPE_SECURITY_CORE, &SecCoreImageBase);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   ZeroMem ((VOID *) &ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));\r
@@ -177,6 +171,12 @@ FindAndReportEntryPoints (
   ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
   PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
 \r
+  //\r
+  // Find PEI Core image base\r
+  //\r
+  Status = FindImageBase (PeiCoreFirmwareVolumePtr, EFI_FV_FILETYPE_PEI_CORE, &PeiCoreImageBase);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
   // Report PEI Core debug information when remote debug is enabled\r
   //\r
index 752156a98e2e6ecdd89cd86d8253a155de93f451..14696c81a5486cee036153e176483416995e6043 100644 (file)
@@ -248,8 +248,17 @@ SecStartupPhase2(
     for (Index = 0;\r
       (PpiList[Index].Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
       Index++) {\r
-      if (CompareGuid (PpiList[Index].Guid, &gEfiPeiCoreFvLocationPpiGuid) && (((EFI_PEI_CORE_FV_LOCATION_PPI *) PpiList[Index].Ppi)->PeiCoreFvLocation != 0)) {\r
-        FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER *) ((EFI_PEI_CORE_FV_LOCATION_PPI *) PpiList[Index].Ppi)->PeiCoreFvLocation, &PeiCoreEntryPoint);\r
+      if (CompareGuid (PpiList[Index].Guid, &gEfiPeiCoreFvLocationPpiGuid) &&\r
+          (((EFI_PEI_CORE_FV_LOCATION_PPI *) PpiList[Index].Ppi)->PeiCoreFvLocation != 0)\r
+         ) {\r
+        //\r
+        // In this case, SecCore is in BFV but PeiCore is in another FV reported by PPI.\r
+        //\r
+        FindAndReportEntryPoints (\r
+          (EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase,\r
+          (EFI_FIRMWARE_VOLUME_HEADER *) ((EFI_PEI_CORE_FV_LOCATION_PPI *) PpiList[Index].Ppi)->PeiCoreFvLocation,\r
+          &PeiCoreEntryPoint\r
+          );\r
         if (PeiCoreEntryPoint != NULL) {\r
           break;\r
         } else {\r
@@ -265,7 +274,14 @@ SecStartupPhase2(
   // If EFI_PEI_CORE_FV_LOCATION_PPI not found, try to locate PeiCore from BFV.\r
   //\r
   if (PeiCoreEntryPoint == NULL) {\r
-    FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase, &PeiCoreEntryPoint);\r
+    //\r
+    // Both SecCore and PeiCore are in BFV.\r
+    //\r
+    FindAndReportEntryPoints (\r
+      (EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase,\r
+      (EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase,\r
+      &PeiCoreEntryPoint\r
+      );\r
     if (PeiCoreEntryPoint == NULL) {\r
       CpuDeadLoop ();\r
     }\r
index 80045d34f445a1e68a82242625db3bde882d185f..6f3b0c5d1290be8fe62ddad1596ba5545450d6ff 100644 (file)
@@ -89,14 +89,16 @@ SecStartup (
   It also find SEC and PEI Core file debug information. It will report them if\r
   remote debug is enabled.\r
 \r
-  @param  BootFirmwareVolumePtr  Point to the boot firmware volume.\r
-  @param  PeiCoreEntryPoint      Point to the PEI core entry point.\r
+  @param   SecCoreFirmwareVolumePtr Point to the firmware volume for finding SecCore.\r
+  @param   PeiCoreFirmwareVolumePtr Point to the firmware volume for finding PeiCore.\r
+  @param   PeiCoreEntryPoint        The entry point of the PEI core.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 FindAndReportEntryPoints (\r
-  IN  EFI_FIRMWARE_VOLUME_HEADER       *BootFirmwareVolumePtr,\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER       *SecCoreFirmwareVolumePtr,\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER       *PeiCoreFirmwareVolumePtr,\r
   OUT EFI_PEI_CORE_ENTRY_POINT         *PeiCoreEntryPoint\r
   );\r
 \r