]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Image/Image.c
Measure PEimage and ActionString data according to TPM requirement.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image / Image.c
index e227f3a6bfc961bd22822221954484fb28cfdae6..56c5fe5ea2812ca434eb22513fc30d7d3849dbe7 100644 (file)
@@ -169,6 +169,7 @@ Returns:
 \r
 EFI_STATUS\r
 CoreLoadPeImage (\r
+  IN BOOLEAN                     BootPolicy,  \r
   IN VOID                        *Pe32Handle,\r
   IN LOADED_IMAGE_PRIVATE_DATA   *Image,\r
   IN EFI_PHYSICAL_ADDRESS        DstBuffer    OPTIONAL,\r
@@ -182,7 +183,8 @@ Routine Description:
   Loads, relocates, and invokes a PE/COFF image\r
 \r
 Arguments:\r
-\r
+  BootPolicy       - If TRUE, indicates that the request originates from the boot manager,\r
+                     and that the boot manager is attempting to load FilePath as a boot selection.\r
   Pe32Handle       - The handle of PE32 image\r
   Image            - PE image to be loaded\r
   DstBuffer        - The buffer to store the image\r
@@ -201,9 +203,11 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS      Status;\r
-  BOOLEAN         DstBufAlocated;\r
-  UINTN           Size;\r
+  EFI_STATUS                Status;\r
+  BOOLEAN                   DstBufAlocated;\r
+  UINTN                     Size;\r
+  UINTN                     LinkTimeBase;\r
+  EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
 \r
   ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));\r
 \r
@@ -213,7 +217,7 @@ Returns:
   //\r
   // Get information about the image being loaded\r
   //\r
-  Status = gEfiPeiPeCoffLoader->GetImageInfo (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderGetImageInfo (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -225,7 +229,32 @@ Returns:
     //\r
     return EFI_UNSUPPORTED;\r
   }\r
-\r
+  \r
+  //\r
+  // Set EFI memory type based on ImageType\r
+  //\r
+  switch (Image->ImageContext.ImageType) {\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:\r
+    Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;\r
+    Image->ImageContext.ImageDataMemoryType = EfiLoaderData;\r
+    break;\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:\r
+    Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;\r
+    Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;\r
+    break;\r
+  case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:\r
+  case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:\r
+    Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;\r
+    Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;\r
+    break;\r
+  default:\r
+    Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get the image base address in the original PeImage.\r
+  //\r
+  LinkTimeBase = (UINTN) Image->ImageContext.ImageAddress;\r
 \r
   //\r
   // Allocate memory of the correct memory type aligned on the required image boundry\r
@@ -305,7 +334,7 @@ Returns:
   //\r
   // Load the image from the file into the allocated memory\r
   //\r
-  Status = gEfiPeiPeCoffLoader->LoadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderLoadImage (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -325,10 +354,32 @@ Returns:
     }\r
   }\r
 \r
+  //\r
+  // Measure the image before applying fixup\r
+  //\r
+  Status = CoreLocateProtocol (\r
+             &gEfiTcgPlatformProtocolGuid,\r
+             NULL,\r
+             (VOID **) &TcgPlatformProtocol\r
+             );\r
+  if (!EFI_ERROR (Status)) {    \r
+    Status = TcgPlatformProtocol->MeasurePeImage (\r
+                                    BootPolicy,\r
+                                    Image->ImageContext.ImageAddress,\r
+                                    (UINTN) Image->ImageContext.ImageSize,\r
+                                    LinkTimeBase,\r
+                                    Image->ImageContext.ImageType,\r
+                                    Image->Info.DeviceHandle,\r
+                                    Image->Info.FilePath\r
+                                    );\r
+    \r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
   //\r
   // Relocate the image in memory\r
   //\r
-  Status = gEfiPeiPeCoffLoader->RelocateImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderRelocateImage (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -425,8 +476,25 @@ Returns:
     UINTN Index;\r
     UINTN StartIndex;\r
     CHAR8 EfiFileName[256];\r
-\r
-    DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading driver at 0x%10p EntryPoint=0x%10p ", (VOID *)(UINTN)Image->ImageContext.ImageAddress, (VOID *)(UINTN)Image->ImageContext.EntryPoint));\r
+    \r
+    if (Image->ImageContext.Machine != IMAGE_FILE_MACHINE_IA64) {\r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
+              "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
+              (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
+              (VOID *)(UINTN)Image->ImageContext.EntryPoint));\r
+    } else {\r
+      //\r
+      // For IPF Image, the real entry point should be print.\r
+      //      \r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, \r
+              "Loading driver at 0x%10p EntryPoint=0x%10p ", \r
+              (VOID *)(UINTN)Image->ImageContext.ImageAddress, \r
+              (VOID *)(UINTN)(*(UINT64 *)(UINTN)Image->ImageContext.EntryPoint)));\r
+    }\r
+    \r
+    //\r
+    // Print Module Name by Pdb file path\r
+    //\r
     if (Image->ImageContext.PdbPointer != NULL) {\r
       StartIndex = 0;\r
       for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {\r
@@ -601,7 +669,7 @@ Returns:
              BootPolicy,\r
              SourceBuffer,\r
              SourceSize,\r
-             FilePath,\r
+             &FilePath,\r
              &DeviceHandle,\r
              &FHand,\r
              &AuthenticationStatus\r
@@ -641,6 +709,7 @@ Returns:
   //\r
   // Pull out just the file portion of the DevicePath for the LoadedImage FilePath\r
   //\r
+  FilePath = OriginalFilePath;\r
   Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
   if (!EFI_ERROR (Status)) {\r
     FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
@@ -683,7 +752,7 @@ Returns:
   //\r
   // Load the image.  If EntryPoint is Null, it will not be set.\r
   //\r
-  Status = CoreLoadPeImage (&FHand, Image, DstBuffer, EntryPoint, Attribute);\r
+  Status = CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryPoint, Attribute);\r
   if (EFI_ERROR (Status)) {\r
     if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_OUT_OF_RESOURCES)) {\r
       if (NumberOfPages != NULL) {\r
@@ -865,9 +934,6 @@ Returns:
            );\r
 }\r
 \r
-\r
-\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 CoreStartImage (\r
@@ -1085,7 +1151,7 @@ Returns:
   //\r
   // Unload image, free Image->ImageContext->ModHandle\r
   //\r
-  gEfiPeiPeCoffLoader->UnloadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  PeCoffLoaderUnloadImage (&Image->ImageContext);\r
 \r
   //\r
   // Free our references to the image handle\r