]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 3 Jan 2019 18:28:22 +0000 (19:28 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 16 Jan 2019 19:10:51 +0000 (20:10 +0100)
In preparation of providing a standalone MM based FTW driver, move
the existing SMM driver to the new MM services table, and factor out
some pieces that are specific to the traditional driver, mainly
related to the use of UEFI boot services, which are not accessible
to standalone MM drivers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c [new file with mode: 0644]
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c

index 844cf3bee04db2214d1c1f8dd93e9b7417e4aa91..a23cb620e2f20f3eaa4ae6c703f6a68919b1a201 100644 (file)
@@ -31,7 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 \r
 //\r
 #include <Library/ReportStatusCodeLib.h>\r
 \r
 //\r
@@ -766,4 +765,26 @@ WriteWorkSpaceData (
   IN UINT8                              *Buffer\r
   );\r
 \r
   IN UINT8                              *Buffer\r
   );\r
 \r
+/**\r
+  Internal implementation of CRC32. Depending on the execution context\r
+  (traditional SMM or DXE vs standalone MM), this function is implemented\r
+  via a call to the CalculateCrc32 () boot service, or via a library\r
+  call.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param[in]  Buffer       A pointer to the buffer on which the 32-bit CRC is\r
+                           to be computed.\r
+  @param[in]  Length       The number of bytes in the buffer Data.\r
+\r
+  @retval Crc32            The 32-bit CRC was computed for the data buffer.\r
+\r
+**/\r
+UINT32\r
+FtwCalculateCrc32 (\r
+  IN  VOID                         *Buffer,\r
+  IN  UINTN                        Length\r
+  );\r
+\r
 #endif\r
 #endif\r
index 094e40f9d86cb782be6772d793c60a105125e6cc..24e507104bbe8c517a5f48e0f2731931cc727129 100644 (file)
@@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
 \r
 **/\r
 \r
+#include <Library/UefiBootServicesTableLib.h>\r
 #include "FaultTolerantWrite.h"\r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 \r
 #include "FaultTolerantWrite.h"\r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 \r
@@ -250,3 +251,33 @@ FaultTolerantWriteInitialize (
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Internal implementation of CRC32. Depending on the execution context\r
+  (traditional SMM or DXE vs standalone MM), this function is implemented\r
+  via a call to the CalculateCrc32 () boot service, or via a library\r
+  call.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param[in]  Buffer       A pointer to the buffer on which the 32-bit CRC is to be computed.\r
+  @param[in]  Length       The number of bytes in the buffer Data.\r
+\r
+  @retval Crc32            The 32-bit CRC was computed for the data buffer.\r
+\r
+**/\r
+UINT32\r
+FtwCalculateCrc32 (\r
+  IN  VOID                         *Buffer,\r
+  IN  UINTN                        Length\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT32        ReturnValue;\r
+\r
+  Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return ReturnValue;\r
+}\r
index 481fea3f1fdfc953c4d4ae478e848744e1dd682a..2cc4e177a31d5620cffff7ce22fec0641945ddef 100644 (file)
@@ -54,14 +54,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
 \r
 **/\r
 \r
-#include <PiSmm.h>\r
-#include <Library/SmmServicesTableLib.h>\r
-#include <Library/SmmMemLib.h>\r
+#include <PiMm.h>\r
+#include <Library/MmServicesTableLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Protocol/SmmSwapAddressRange.h>\r
 #include "FaultTolerantWrite.h"\r
 #include "FaultTolerantWriteSmmCommon.h"\r
 #include <Library/BaseLib.h>\r
 #include <Protocol/SmmSwapAddressRange.h>\r
 #include "FaultTolerantWrite.h"\r
 #include "FaultTolerantWriteSmmCommon.h"\r
-#include <Protocol/SmmEndOfDxe.h>\r
+#include <Protocol/MmEndOfDxe.h>\r
 \r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 EFI_FTW_DEVICE                            *mFtwDevice      = NULL;\r
 \r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 EFI_FTW_DEVICE                            *mFtwDevice      = NULL;\r
@@ -92,7 +91,7 @@ FtwGetFvbByHandle (
   //\r
   // To get the SMM FVB protocol interface on the handle\r
   //\r
   //\r
   // To get the SMM FVB protocol interface on the handle\r
   //\r
-  return gSmst->SmmHandleProtocol (\r
+  return gMmst->MmHandleProtocol (\r
                   FvBlockHandle,\r
                   &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                   (VOID **) FvBlock\r
                   FvBlockHandle,\r
                   &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                   (VOID **) FvBlock\r
@@ -119,7 +118,7 @@ FtwGetSarProtocol (
   //\r
   // Locate Smm Swap Address Range protocol\r
   //\r
   //\r
   // Locate Smm Swap Address Range protocol\r
   //\r
-  Status = gSmst->SmmLocateProtocol (\r
+  Status = gMmst->MmLocateProtocol (\r
                     &gEfiSmmSwapAddressRangeProtocolGuid,\r
                     NULL,\r
                     SarProtocol\r
                     &gEfiSmmSwapAddressRangeProtocolGuid,\r
                     NULL,\r
                     SarProtocol\r
@@ -158,7 +157,7 @@ GetFvbCountAndBuffer (
   BufferSize     = 0;\r
   *NumberHandles = 0;\r
   *Buffer        = NULL;\r
   BufferSize     = 0;\r
   *NumberHandles = 0;\r
   *Buffer        = NULL;\r
-  Status = gSmst->SmmLocateHandle (\r
+  Status = gMmst->MmLocateHandle (\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
@@ -174,7 +173,7 @@ GetFvbCountAndBuffer (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Status = gSmst->SmmLocateHandle (\r
+  Status = gMmst->MmLocateHandle (\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
                     ByProtocol,\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     NULL,\r
@@ -336,7 +335,7 @@ SmmFaultTolerantWriteHandler (
   }\r
   CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
 \r
   }\r
   CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
 \r
-  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+  if (!FtwSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
     DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
     return EFI_SUCCESS;\r
   }\r
     DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
     return EFI_SUCCESS;\r
   }\r
@@ -525,13 +524,12 @@ FvbNotificationEvent (
   EFI_STATUS                              Status;\r
   EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL   *FtwProtocol;\r
   EFI_HANDLE                              SmmFtwHandle;\r
   EFI_STATUS                              Status;\r
   EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL   *FtwProtocol;\r
   EFI_HANDLE                              SmmFtwHandle;\r
-  EFI_HANDLE                              FtwHandle;\r
 \r
   //\r
   // Just return to avoid install SMM FaultTolerantWriteProtocol again\r
   // if SMM Fault Tolerant Write protocol had been installed.\r
   //\r
 \r
   //\r
   // Just return to avoid install SMM FaultTolerantWriteProtocol again\r
   // if SMM Fault Tolerant Write protocol had been installed.\r
   //\r
-  Status = gSmst->SmmLocateProtocol (\r
+  Status = gMmst->MmLocateProtocol (\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     NULL,\r
                     (VOID **) &FtwProtocol\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     NULL,\r
                     (VOID **) &FtwProtocol\r
@@ -551,7 +549,7 @@ FvbNotificationEvent (
   //\r
   // Install protocol interface\r
   //\r
   //\r
   // Install protocol interface\r
   //\r
-  Status = gSmst->SmmInstallProtocolInterface (\r
+  Status = gMmst->MmInstallProtocolInterface (\r
                     &mFtwDevice->Handle,\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     EFI_NATIVE_INTERFACE,\r
                     &mFtwDevice->Handle,\r
                     &gEfiSmmFaultTolerantWriteProtocolGuid,\r
                     EFI_NATIVE_INTERFACE,\r
@@ -562,20 +560,13 @@ FvbNotificationEvent (
   ///\r
   /// Register SMM FTW SMI handler\r
   ///\r
   ///\r
   /// Register SMM FTW SMI handler\r
   ///\r
-  Status = gSmst->SmiHandlerRegister (SmmFaultTolerantWriteHandler, &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle);\r
+  Status = gMmst->MmiHandlerRegister (SmmFaultTolerantWriteHandler, &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Notify the Ftw wrapper driver SMM Ftw is ready\r
   //\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Notify the Ftw wrapper driver SMM Ftw is ready\r
   //\r
-  FtwHandle = NULL;\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &FtwHandle,\r
-                  &gEfiSmmFaultTolerantWriteProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  FtwNotifySmmReady ();\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -592,7 +583,7 @@ FvbNotificationEvent (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-SmmEndOfDxeCallback (\r
+MmEndOfDxeCallback (\r
   IN CONST EFI_GUID                       *Protocol,\r
   IN VOID                                 *Interface,\r
   IN EFI_HANDLE                           Handle\r
   IN CONST EFI_GUID                       *Protocol,\r
   IN VOID                                 *Interface,\r
   IN EFI_HANDLE                           Handle\r
@@ -603,25 +594,19 @@ SmmEndOfDxeCallback (
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  This function is the entry point of the Fault Tolerant Write driver.\r
-\r
-  @param[in] ImageHandle        A handle for the image that is initializing this driver\r
-  @param[in] SystemTable        A pointer to the EFI system table\r
+  Shared entry point of the module\r
 \r
   @retval EFI_SUCCESS           The initialization finished successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
   @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
 \r
   @retval EFI_SUCCESS           The initialization finished successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
   @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
-\r
 **/\r
 EFI_STATUS\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SmmFaultTolerantWriteInitialize (\r
-  IN EFI_HANDLE                           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                     *SystemTable\r
+MmFaultTolerantWriteInitialize (\r
+  VOID\r
   )\r
 {\r
   EFI_STATUS                              Status;\r
   )\r
 {\r
   EFI_STATUS                              Status;\r
-  VOID                                    *SmmEndOfDxeRegistration;\r
+  VOID                                    *MmEndOfDxeRegistration;\r
 \r
   //\r
   // Allocate private data structure for SMM FTW protocol and do some initialization\r
 \r
   //\r
   // Allocate private data structure for SMM FTW protocol and do some initialization\r
@@ -634,17 +619,17 @@ SmmFaultTolerantWriteInitialize (
   //\r
   // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
   //\r
   //\r
   // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
   //\r
-  Status = gSmst->SmmRegisterProtocolNotify (\r
-                    &gEfiSmmEndOfDxeProtocolGuid,\r
-                    SmmEndOfDxeCallback,\r
-                    &SmmEndOfDxeRegistration\r
+  Status = gMmst->MmRegisterProtocolNotify (\r
+                    &gEfiMmEndOfDxeProtocolGuid,\r
+                    MmEndOfDxeCallback,\r
+                    &MmEndOfDxeRegistration\r
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Register FvbNotificationEvent () notify function.\r
   //\r
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Register FvbNotificationEvent () notify function.\r
   //\r
-  Status = gSmst->SmmRegisterProtocolNotify (\r
+  Status = gMmst->MmRegisterProtocolNotify (\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     FvbNotificationEvent,\r
                     &mFvbRegistration\r
                     &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
                     FvbNotificationEvent,\r
                     &mFvbRegistration\r
index 606cc2266bda6869a17273029e1d892e0c9f7489..1653365bc247f39966d48c9984a33a737fcba0c4 100644 (file)
@@ -37,6 +37,7 @@
   FtwMisc.c\r
   UpdateWorkingBlock.c\r
   FaultTolerantWrite.c\r
   FtwMisc.c\r
   UpdateWorkingBlock.c\r
   FaultTolerantWrite.c\r
+  FaultTolerantWriteTraditionalMm.c\r
   FaultTolerantWriteSmm.c\r
   FaultTolerantWrite.h\r
   FaultTolerantWriteSmmCommon.h\r
   FaultTolerantWriteSmm.c\r
   FaultTolerantWrite.h\r
   FaultTolerantWriteSmmCommon.h\r
@@ -46,7 +47,7 @@
   MdeModulePkg/MdeModulePkg.dec\r
 \r
 [LibraryClasses]\r
   MdeModulePkg/MdeModulePkg.dec\r
 \r
 [LibraryClasses]\r
-  SmmServicesTableLib\r
+  MmServicesTableLib\r
   MemoryAllocationLib\r
   BaseMemoryLib\r
   UefiDriverEntryPoint\r
   MemoryAllocationLib\r
   BaseMemoryLib\r
   UefiDriverEntryPoint\r
@@ -73,7 +74,7 @@
   ## PRODUCES\r
   ## UNDEFINED # SmiHandlerRegister\r
   gEfiSmmFaultTolerantWriteProtocolGuid\r
   ## PRODUCES\r
   ## UNDEFINED # SmiHandlerRegister\r
   gEfiSmmFaultTolerantWriteProtocolGuid\r
-  gEfiSmmEndOfDxeProtocolGuid                      ## CONSUMES\r
+  gEfiMmEndOfDxeProtocolGuid                      ## CONSUMES\r
 \r
 [FeaturePcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable    ## CONSUMES\r
 \r
 [FeaturePcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable    ## CONSUMES\r
index 8ad0015f3c9e5d6f26c0d81ead9e770b1c901efe..61293ca864e8fd4efbb861f7e095fd065bcfbe92 100644 (file)
@@ -77,4 +77,43 @@ typedef struct {
   UINT8                                 Data[1];\r
 } SMM_FTW_GET_LAST_WRITE_HEADER;\r
 \r
   UINT8                                 Data[1];\r
 } SMM_FTW_GET_LAST_WRITE_HEADER;\r
 \r
+/**\r
+  Shared entry point of the module\r
+\r
+  @retval EFI_SUCCESS           The initialization finished successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
+  @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
+\r
+**/\r
+EFI_STATUS\r
+MmFaultTolerantWriteInitialize (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This function checks if the buffer is valid per processor architecture and\r
+  does not overlap with SMRAM.\r
+\r
+  @param Buffer The buffer start address to be checked.\r
+  @param Length The buffer length to be checked.\r
+\r
+  @retval TRUE  This buffer is valid per processor architecture and does not\r
+                overlap with SMRAM.\r
+  @retval FALSE This buffer is not valid per processor architecture or overlaps\r
+                with SMRAM.\r
+**/\r
+BOOLEAN\r
+FtwSmmIsBufferOutsideSmmValid (\r
+  IN EFI_PHYSICAL_ADDRESS  Buffer,\r
+  IN UINT64                Length\r
+  );\r
+\r
+/**\r
+  Notify the system that the SMM FTW driver is ready\r
+**/\r
+VOID\r
+FtwNotifySmmReady (\r
+  VOID\r
+  );\r
+\r
 #endif\r
 #endif\r
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c
new file mode 100644 (file)
index 0000000..0981c3c
--- /dev/null
@@ -0,0 +1,114 @@
+/** @file\r
+\r
+  Parts of the SMM/MM implementation that are specific to traditional MM\r
+\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2018, Linaro, 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
+\r
+**/\r
+\r
+#include <Library/SmmMemLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "FaultTolerantWrite.h"\r
+#include "FaultTolerantWriteSmmCommon.h"\r
+\r
+/**\r
+  This function checks if the buffer is valid per processor architecture and\r
+  does not overlap with SMRAM.\r
+\r
+  @param Buffer The buffer start address to be checked.\r
+  @param Length The buffer length to be checked.\r
+\r
+  @retval TRUE  This buffer is valid per processor architecture and does not\r
+                overlap with SMRAM.\r
+  @retval FALSE This buffer is not valid per processor architecture or overlaps\r
+                with SMRAM.\r
+**/\r
+BOOLEAN\r
+FtwSmmIsBufferOutsideSmmValid (\r
+  IN EFI_PHYSICAL_ADDRESS  Buffer,\r
+  IN UINT64                Length\r
+  )\r
+{\r
+  return SmmIsBufferOutsideSmmValid (Buffer, Length);\r
+}\r
+\r
+/**\r
+  Internal implementation of CRC32. Depending on the execution context\r
+  (traditional SMM or DXE vs standalone MM), this function is implemented\r
+  via a call to the CalculateCrc32 () boot service, or via a library\r
+  call.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param[in]  Buffer       A pointer to the buffer on which the 32-bit CRC is\r
+                           to be computed.\r
+  @param[in]  Length       The number of bytes in the buffer Data.\r
+\r
+  @retval Crc32            The 32-bit CRC was computed for the data buffer.\r
+\r
+**/\r
+UINT32\r
+FtwCalculateCrc32 (\r
+  IN  VOID                         *Buffer,\r
+  IN  UINTN                        Length\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT32        ReturnValue;\r
+\r
+  Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return ReturnValue;\r
+}\r
+\r
+/**\r
+  Notify the system that the SMM FTW driver is ready\r
+**/\r
+VOID\r
+FtwNotifySmmReady (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HANDLE          FtwHandle;\r
+  EFI_STATUS          Status;\r
+\r
+  FtwHandle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &FtwHandle,\r
+                  &gEfiSmmFaultTolerantWriteProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  This function is the entry point of the Fault Tolerant Write driver.\r
+\r
+  @param[in] ImageHandle        A handle for the image that is initializing this driver\r
+  @param[in] SystemTable        A pointer to the EFI system table\r
+\r
+  @retval EFI_SUCCESS           The initialization finished successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  Allocate memory error\r
+  @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmFaultTolerantWriteInitialize (\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE      *SystemTable\r
+  )\r
+{\r
+  return MmFaultTolerantWriteInitialize ();\r
+}\r
index 50d3421b88bbdb18afefaaa394ba9c8a1f4cb5b9..d09e9719cf0586e1bfaec06298213fafb198cc78 100644 (file)
@@ -29,8 +29,6 @@ InitializeLocalWorkSpaceHeader (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  EFI_STATUS                              Status;\r
-\r
   //\r
   // Check signature with gEdkiiWorkingBlockSignatureGuid.\r
   //\r
   //\r
   // Check signature with gEdkiiWorkingBlockSignatureGuid.\r
   //\r
@@ -64,12 +62,8 @@ InitializeLocalWorkSpaceHeader (
   //\r
   // Calculate the Crc of woking block header\r
   //\r
   //\r
   // Calculate the Crc of woking block header\r
   //\r
-  Status = gBS->CalculateCrc32 (\r
-                  &mWorkingBlockHeader,\r
-                  sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),\r
-                  &mWorkingBlockHeader.Crc\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  mWorkingBlockHeader.Crc = FtwCalculateCrc32 (&mWorkingBlockHeader,\r
+                              sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));\r
 \r
   mWorkingBlockHeader.WorkingBlockValid    = FTW_VALID_STATE;\r
   mWorkingBlockHeader.WorkingBlockInvalid  = FTW_INVALID_STATE;\r
 \r
   mWorkingBlockHeader.WorkingBlockValid    = FTW_VALID_STATE;\r
   mWorkingBlockHeader.WorkingBlockInvalid  = FTW_INVALID_STATE;\r