Measure PEimage and ActionString data according to TPM requirement.
authorlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 4 Jan 2008 02:11:51 +0000 (02:11 +0000)
committerlgao4 <lgao4@de2fecce-e211-0410-80a6-f3fac2684e05>
Fri, 4 Jan 2008 02:11:51 +0000 (02:11 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4494 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/MdeModulePkg/Core/Dxe/DxeMain.h
edk2/MdeModulePkg/Core/Dxe/DxeMain.inf
edk2/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
edk2/MdeModulePkg/Core/Dxe/Image.h
edk2/MdeModulePkg/Core/Dxe/Image/Image.c

index 765db57..f0f57fe 100644 (file)
@@ -60,6 +60,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/Capsule.h>\r
 #include <Protocol/BusSpecificDriverOverride.h>\r
 #include <Protocol/Performance.h>\r
+#include <Uefi/UefiTcgPlatform.h>\r
+#include <Protocol/TcgPlatform.h>\r
 \r
 #include <Library/DxeCoreEntryPoint.h>\r
 #include <Library/DebugLib.h>\r
index 3bd6762..9257fba 100644 (file)
   gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
   gEfiLoadedImageProtocolGuid                   # PROTOCOL ALWAYS_PRODUCED\r
   gEfiEbcProtocolGuid                           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiTcgPlatformProtocolGuid\r
 \r
 [FixedPcd.common]\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeCoreEntry | 0x3041000          # EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT\r
index 87d98e8..0f785dd 100644 (file)
@@ -753,12 +753,37 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS    Status;\r
+  EFI_STATUS    StatusTemp;\r
+  EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
+\r
+  //\r
+  // Measure invocation of ExitBootServices, \r
+  // which is defined by TCG_EFI_Platform_1_20_Final Specification\r
+  //\r
+  TcgPlatformProtocol = NULL;\r
+  Status = CoreLocateProtocol (\r
+             &gEfiTcgPlatformProtocolGuid,\r
+             NULL,\r
+             (VOID **) &TcgPlatformProtocol\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   //\r
   // Terminate memory services if the MapKey matches\r
   //\r
   Status = CoreTerminateMemoryMap (MapKey);\r
   if (EFI_ERROR (Status)) {\r
+    //\r
+    // Measure failure of ExitBootServices\r
+    //\r
+    if (TcgPlatformProtocol != NULL) {\r
+      StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);\r
+      ASSERT_EFI_ERROR (StatusTemp);\r
+    }\r
+\r
     return Status;\r
   }\r
 \r
@@ -811,6 +836,14 @@ Returns:
   //\r
   gRuntime->AtRuntime = TRUE;\r
 \r
+  //\r
+  // Measure success of ExitBootServices\r
+  //\r
+  if (TcgPlatformProtocol != NULL) {\r
+    StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);\r
+    ASSERT_EFI_ERROR (StatusTemp);\r
+  }\r
\r
   return Status;\r
 }\r
 \r
index 13936a5..8ad1f9b 100644 (file)
@@ -223,6 +223,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
@@ -237,6 +238,7 @@ Routine Description:
 \r
 Arguments:\r
 \r
+  BootPolicy       - Policy for Open Image File.\r
   Pe32Handle       - The handle of PE32 image\r
   Image            - PE image to be loaded\r
   DstBuffer        - The buffer to store the image\r
index e38dfae..56c5fe5 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
@@ -247,6 +251,10 @@ Returns:
     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
@@ -346,6 +354,28 @@ 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
@@ -722,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
@@ -904,9 +934,6 @@ Returns:
            );\r
 }\r
 \r
-\r
-\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 CoreStartImage (\r