]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
StandaloneMmPkg: Fix ECC error 8005 in StandaloneMmCoreEntryPoint
[mirror_edk2.git] / StandaloneMmPkg / Library / StandaloneMmCoreEntryPoint / AArch64 / StandaloneMmCoreEntryPoint.c
index c8e11a253d24998235ec9c49480885e103ecc18c..fa2005e7e9e485faff9aedac9cefff7fc6c955e8 100644 (file)
@@ -2,14 +2,8 @@
   Entry point to the Standalone MM Foundation when initialized during the SEC\r
   phase on ARM platforms\r
 \r
-Copyright (c) 2017 - 2018, ARM Ltd. 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
-http://opensource.org/licenses/bsd-license.php.\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2017 - 2021, Arm Ltd. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -37,18 +31,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define SPM_MINOR_VER_MASK        0x0000FFFF\r
 #define SPM_MAJOR_VER_SHIFT       16\r
 \r
-CONST UINT32 SPM_MAJOR_VER = 0;\r
-CONST UINT32 SPM_MINOR_VER = 1;\r
+#define SPM_MAJOR_VER             0\r
+#define SPM_MINOR_VER             1\r
 \r
-CONST UINT8 BOOT_PAYLOAD_VERSION = 1;\r
+#define BOOT_PAYLOAD_VERSION      1\r
 \r
 PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT      CpuDriverEntryPoint = NULL;\r
 \r
 /**\r
   Retrieve a pointer to and print the boot information passed by privileged\r
-  secure firmware\r
+  secure firmware.\r
 \r
-  @param  SharedBufAddress The pointer memory shared with privileged firmware\r
+  @param  [in] SharedBufAddress   The pointer memory shared with privileged\r
+                                  firmware.\r
 \r
 **/\r
 EFI_SECURE_PARTITION_BOOT_INFO *\r
@@ -107,6 +102,12 @@ GetAndPrintBootinformation (
   return PayloadBootInfo;\r
 }\r
 \r
+/**\r
+  A loop to delegated events.\r
+\r
+  @param  [in] EventCompleteSvcArgs   Pointer to the event completion arguments.\r
+\r
+**/\r
 VOID\r
 EFIAPI\r
 DelegatedEventLoop (\r
@@ -162,6 +163,12 @@ DelegatedEventLoop (
   }\r
 }\r
 \r
+/**\r
+  Query the SPM version, check compatibility and return success if compatible.\r
+\r
+  @retval EFI_SUCCESS       SPM versions compatible.\r
+  @retval EFI_UNSUPPORTED   SPM versions not compatible.\r
+**/\r
 STATIC\r
 EFI_STATUS\r
 GetSpmVersion (VOID)\r
@@ -208,9 +215,10 @@ GetSpmVersion (VOID)
 /**\r
   The entry point of Standalone MM Foundation.\r
 \r
-  @param  SharedBufAddress  Pointer to the Buffer between SPM and SP.\r
-  @param  cookie1.\r
-  @param  cookie2.\r
+  @param  [in]  SharedBufAddress  Pointer to the Buffer between SPM and SP.\r
+  @param  [in]  SharedBufSize     Size of the shared buffer.\r
+  @param  [in]  cookie1           Cookie 1\r
+  @param  [in]  cookie2           Cookie 2\r
 \r
 **/\r
 VOID\r
@@ -231,6 +239,7 @@ _ModuleEntryPoint (
   VOID                                    *HobStart;\r
   VOID                                    *TeData;\r
   UINTN                                   TeDataSize;\r
+  EFI_PHYSICAL_ADDRESS                    ImageBase;\r
 \r
   // Get Secure Partition Manager Version Information\r
   Status = GetSpmVersion ();\r
@@ -259,6 +268,7 @@ _ModuleEntryPoint (
   Status = GetStandaloneMmCorePeCoffSections (\r
              TeData,\r
              &ImageContext,\r
+             &ImageBase,\r
              &SectionHeaderOffset,\r
              &NumberOfSections\r
              );\r
@@ -267,10 +277,21 @@ _ModuleEntryPoint (
     goto finish;\r
   }\r
 \r
+  //\r
+  // ImageBase may deviate from ImageContext.ImageAddress if we are dealing\r
+  // with a TE image, in which case the latter points to the actual offset\r
+  // of the image, whereas ImageBase refers to the address where the image\r
+  // would start if the stripped PE headers were still in place. In either\r
+  // case, we need to fix up ImageBase so it refers to the actual current\r
+  // load address.\r
+  //\r
+  ImageBase += (UINTN)TeData - ImageContext.ImageAddress;\r
+\r
   // Update the memory access permissions of individual sections in the\r
   // Standalone MM core module\r
   Status = UpdateMmFoundationPeCoffPermissions (\r
              &ImageContext,\r
+             ImageBase,\r
              SectionHeaderOffset,\r
              NumberOfSections,\r
              ArmSetMemoryRegionNoExec,\r
@@ -282,6 +303,15 @@ _ModuleEntryPoint (
     goto finish;\r
   }\r
 \r
+  if (ImageContext.ImageAddress != (UINTN)TeData) {\r
+    ImageContext.ImageAddress = (UINTN)TeData;\r
+    ArmSetMemoryRegionNoExec (ImageBase, SIZE_4KB);\r
+    ArmClearMemoryRegionReadOnly (ImageBase, SIZE_4KB);\r
+\r
+    Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
   //\r
   // Create Hoblist based upon boot information passed by privileged software\r
   //\r