]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c
MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteDxe.c
index 094e40f9d86cb782be6772d793c60a105125e6cc..24e507104bbe8c517a5f48e0f2731931cc727129 100644 (file)
@@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
+#include <Library/UefiBootServicesTableLib.h>\r
 #include "FaultTolerantWrite.h"\r
 EFI_EVENT                                 mFvbRegistration = NULL;\r
 \r
@@ -250,3 +251,33 @@ FaultTolerantWriteInitialize (
 \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