From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 18D47211ADA29 for ; Wed, 9 Jan 2019 17:36:51 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 17:36:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,459,1539673200"; d="scan'208";a="310566625" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga005.fm.intel.com with ESMTP; 09 Jan 2019 17:36:50 -0800 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 9 Jan 2019 17:36:49 -0800 Received: from shsmsx108.ccr.corp.intel.com (10.239.4.97) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 9 Jan 2019 17:36:49 -0800 Received: from shsmsx107.ccr.corp.intel.com ([169.254.9.239]) by SHSMSX108.ccr.corp.intel.com ([169.254.8.85]) with mapi id 14.03.0415.000; Thu, 10 Jan 2019 09:36:47 +0800 From: "Wang, Jian J" To: Ard Biesheuvel , "edk2-devel@lists.01.org" CC: Laszlo Ersek , Leif Lindholm , "Kinney, Michael D" , "Gao, Liming" , "Wu, Hao A" , Jagadeesh Ujja , Achin Gupta , Thomas Panakamattam Abraham , Sami Mujawar Thread-Topic: [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses Thread-Index: AQHUo5Izjb+tjnxA/U6+0YQfirJP1qWnwq/g Date: Thu, 10 Jan 2019 01:36:46 +0000 Message-ID: References: <20190103182825.32231-1-ard.biesheuvel@linaro.org> <20190103182825.32231-5-ard.biesheuvel@linaro.org> In-Reply-To: <20190103182825.32231-5-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNzg2YmE0MzEtMWZlMS00YzdhLWE0MTQtNmFmNjRmNjViMTY2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiN2J6NzFoUEZxZkdQbkpiNVd5bTB2UzBkVjk0VUsrN0Fqb05obCtOUzJGR1JyMjVVZkt4UlFHNHBCZ1lIdUNRTiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jan 2019 01:36:51 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jian J Wang > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Friday, January 04, 2019 2:28 AM > To: edk2-devel@lists.01.org > Cc: Ard Biesheuvel ; Laszlo Ersek > ; Leif Lindholm ; Kinney, > Michael D ; Gao, Liming ; > Wang, Jian J ; Wu, Hao A ; > Jagadeesh Ujja ; Achin Gupta > ; Thomas Panakamattam Abraham > ; Sami Mujawar > Subject: [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot > service accesses >=20 > 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. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/MdeModulePkg.dsc = | 1 + > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > | 22 ++++- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > | 31 +++++++ > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > | 54 +++++------ > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > | 5 +- >=20 > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCom > mon.h | 31 +++++++ >=20 > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c > | 1 + >=20 > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditiona > lMm.c | 94 ++++++++++++++++++++ > MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > | 10 +-- > 9 files changed, 205 insertions(+), 44 deletions(-) >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dsc > b/MdeModulePkg/MdeModulePkg.dsc > index 5d042be3a862..ef3c144ed524 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -153,6 +153,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] > DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf >=20 > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemory > AllocationLib.inf >=20 > SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTable > Lib.inf > + > MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib > .inf > LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf > SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf >=20 > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > index 844cf3bee04d..8d146264b129 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > @@ -31,7 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > -#include > #include >=20 > // > @@ -766,4 +765,25 @@ WriteWorkSpaceData ( > IN UINT8 *Buffer > ); >=20 > +/** > + Internal implementation of CRC32. Depending on the execution context > + (traditional SMM or DXE vs standalone MM), this function is implemente= d > + via a call to the CalculateCrc32 () boot service, or via a library > + call. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param[in] Buffer A pointer to the buffer on which the 32-bit C= RC is to be > computed. > + @param[in] Length The number of bytes in the buffer Data. > + > + @retval Crc32 The 32-bit CRC was computed for the data buff= er. > + > +**/ > +UINT32 > +FtwCalculateCrc32 ( > + IN VOID *Buffer, > + IN UINTN Length > + ); > + > #endif > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > index 094e40f9d86c..24e507104bbe 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > @@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. >=20 > **/ >=20 > +#include > #include "FaultTolerantWrite.h" > EFI_EVENT mFvbRegistration =3D NULL; >=20 > @@ -250,3 +251,33 @@ FaultTolerantWriteInitialize ( >=20 > return EFI_SUCCESS; > } > + > +/** > + Internal implementation of CRC32. Depending on the execution context > + (traditional SMM or DXE vs standalone MM), this function is implemente= d > + via a call to the CalculateCrc32 () boot service, or via a library > + call. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param[in] Buffer A pointer to the buffer on which the 32-bit C= RC is to be > computed. > + @param[in] Length The number of bytes in the buffer Data. > + > + @retval Crc32 The 32-bit CRC was computed for the data buff= er. > + > +**/ > +UINT32 > +FtwCalculateCrc32 ( > + IN VOID *Buffer, > + IN UINTN Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 ReturnValue; > + > + Status =3D gBS->CalculateCrc32 (Buffer, Length, &ReturnValue); > + ASSERT_EFI_ERROR (Status); > + > + return ReturnValue; > +} > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > index 481fea3f1fdf..e91d04e56d7c 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > @@ -54,14 +54,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. >=20 > **/ >=20 > -#include > -#include > -#include > +#include > +#include > #include > #include > #include "FaultTolerantWrite.h" > #include "FaultTolerantWriteSmmCommon.h" > -#include > +#include >=20 > EFI_EVENT mFvbRegistration =3D NULL; > EFI_FTW_DEVICE *mFtwDevice =3D NULL; > @@ -92,7 +91,7 @@ FtwGetFvbByHandle ( > // > // To get the SMM FVB protocol interface on the handle > // > - return gSmst->SmmHandleProtocol ( > + return gMmst->MmHandleProtocol ( > FvBlockHandle, > &gEfiSmmFirmwareVolumeBlockProtocolGuid, > (VOID **) FvBlock > @@ -119,7 +118,7 @@ FtwGetSarProtocol ( > // > // Locate Smm Swap Address Range protocol > // > - Status =3D gSmst->SmmLocateProtocol ( > + Status =3D gMmst->MmLocateProtocol ( > &gEfiSmmSwapAddressRangeProtocolGuid, > NULL, > SarProtocol > @@ -158,7 +157,7 @@ GetFvbCountAndBuffer ( > BufferSize =3D 0; > *NumberHandles =3D 0; > *Buffer =3D NULL; > - Status =3D gSmst->SmmLocateHandle ( > + Status =3D gMmst->MmLocateHandle ( > ByProtocol, > &gEfiSmmFirmwareVolumeBlockProtocolGuid, > NULL, > @@ -174,7 +173,7 @@ GetFvbCountAndBuffer ( > return EFI_OUT_OF_RESOURCES; > } >=20 > - Status =3D gSmst->SmmLocateHandle ( > + Status =3D gMmst->MmLocateHandle ( > ByProtocol, > &gEfiSmmFirmwareVolumeBlockProtocolGuid, > NULL, > @@ -336,8 +335,7 @@ SmmFaultTolerantWriteHandler ( > } > CommBufferPayloadSize =3D TempCommBufferSize - > SMM_FTW_COMMUNICATE_HEADER_SIZE; >=20 > - if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, > TempCommBufferSize)) { > - DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in > SMRAM or overflow!\n")); > + if (!FtwSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, > TempCommBufferSize)) { > return EFI_SUCCESS; > } >=20 > @@ -525,13 +523,12 @@ FvbNotificationEvent ( > EFI_STATUS Status; > EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; > EFI_HANDLE SmmFtwHandle; > - EFI_HANDLE FtwHandle; >=20 > // > // Just return to avoid install SMM FaultTolerantWriteProtocol again > // if SMM Fault Tolerant Write protocol had been installed. > // > - Status =3D gSmst->SmmLocateProtocol ( > + Status =3D gMmst->MmLocateProtocol ( > &gEfiSmmFaultTolerantWriteProtocolGuid, > NULL, > (VOID **) &FtwProtocol > @@ -551,7 +548,7 @@ FvbNotificationEvent ( > // > // Install protocol interface > // > - Status =3D gSmst->SmmInstallProtocolInterface ( > + Status =3D gMmst->MmInstallProtocolInterface ( > &mFtwDevice->Handle, > &gEfiSmmFaultTolerantWriteProtocolGuid, > EFI_NATIVE_INTERFACE, > @@ -562,20 +559,13 @@ FvbNotificationEvent ( > /// > /// Register SMM FTW SMI handler > /// > - Status =3D gSmst->SmiHandlerRegister (SmmFaultTolerantWriteHandler, > &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle); > + Status =3D gMmst->MmiHandlerRegister (SmmFaultTolerantWriteHandler, > &gEfiSmmFaultTolerantWriteProtocolGuid, &SmmFtwHandle); > ASSERT_EFI_ERROR (Status); >=20 > // > // Notify the Ftw wrapper driver SMM Ftw is ready > // > - FtwHandle =3D NULL; > - Status =3D gBS->InstallProtocolInterface ( > - &FtwHandle, > - &gEfiSmmFaultTolerantWriteProtocolGuid, > - EFI_NATIVE_INTERFACE, > - NULL > - ); > - ASSERT_EFI_ERROR (Status); > + FtwNotifySmmReady (); >=20 > return EFI_SUCCESS; > } > @@ -592,7 +582,7 @@ FvbNotificationEvent ( > **/ > EFI_STATUS > EFIAPI > -SmmEndOfDxeCallback ( > +MmEndOfDxeCallback ( > IN CONST EFI_GUID *Protocol, > IN VOID *Interface, > IN EFI_HANDLE Handle > @@ -614,14 +604,12 @@ SmmEndOfDxeCallback ( >=20 > **/ > EFI_STATUS > -EFIAPI > -SmmFaultTolerantWriteInitialize ( > - IN EFI_HANDLE ImageHandle, > - IN EFI_SYSTEM_TABLE *SystemTable > +MmFaultTolerantWriteInitialize ( > + VOID > ) > { > EFI_STATUS Status; > - VOID *SmmEndOfDxeRegistration; > + VOID *MmEndOfDxeRegistration; >=20 > // > // Allocate private data structure for SMM FTW protocol and do some > initialization > @@ -634,17 +622,17 @@ SmmFaultTolerantWriteInitialize ( > // > // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function. > // > - Status =3D gSmst->SmmRegisterProtocolNotify ( > - &gEfiSmmEndOfDxeProtocolGuid, > - SmmEndOfDxeCallback, > - &SmmEndOfDxeRegistration > + Status =3D gMmst->MmRegisterProtocolNotify ( > + &gEfiMmEndOfDxeProtocolGuid, > + MmEndOfDxeCallback, > + &MmEndOfDxeRegistration > ); > ASSERT_EFI_ERROR (Status); >=20 > // > // Register FvbNotificationEvent () notify function. > // > - Status =3D gSmst->SmmRegisterProtocolNotify ( > + Status =3D gMmst->MmRegisterProtocolNotify ( > &gEfiSmmFirmwareVolumeBlockProtocolGuid, > FvbNotificationEvent, > &mFvbRegistration > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > index 606cc2266bda..1653365bc247 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > @@ -37,6 +37,7 @@ [Sources] > FtwMisc.c > UpdateWorkingBlock.c > FaultTolerantWrite.c > + FaultTolerantWriteTraditionalMm.c > FaultTolerantWriteSmm.c > FaultTolerantWrite.h > FaultTolerantWriteSmmCommon.h > @@ -46,7 +47,7 @@ [Packages] > MdeModulePkg/MdeModulePkg.dec >=20 > [LibraryClasses] > - SmmServicesTableLib > + MmServicesTableLib > MemoryAllocationLib > BaseMemoryLib > UefiDriverEntryPoint > @@ -73,7 +74,7 @@ [Protocols] > ## PRODUCES > ## UNDEFINED # SmiHandlerRegister > gEfiSmmFaultTolerantWriteProtocolGuid > - gEfiSmmEndOfDxeProtocolGuid ## CONSUMES > + gEfiMmEndOfDxeProtocolGuid ## CONSUMES >=20 > [FeaturePcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCo > mmon.h > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCo > mmon.h > index 8ad0015f3c9e..25b5f7c87326 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCo > mmon.h > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCo > mmon.h > @@ -77,4 +77,35 @@ typedef struct { > UINT8 Data[1]; > } SMM_FTW_GET_LAST_WRITE_HEADER; >=20 > +/** > + Entry point of the module > +**/ > +EFI_STATUS > +MmFaultTolerantWriteInitialize ( > + VOID > + ); > + > +/** > + This function check if the buffer is valid per processor architecture = and not > overlap with SMRAM. > + > + @param Buffer The buffer start address to be checked. > + @param Length The buffer length to be checked. > + > + @retval TRUE This buffer is valid per processor architecture and not = overlap > with SMRAM. > + @retval FALSE This buffer is not valid per processor architecture or o= verlap > with SMRAM. > +**/ > +BOOLEAN > +FtwSmmIsBufferOutsideSmmValid ( > + IN EFI_PHYSICAL_ADDRESS Buffer, > + IN UINT64 Length > + ); > + > +/** > + Notify the system that the SMM driver is ready > +**/ > +VOID > +FtwNotifySmmReady ( > + VOID > + ); > + > #endif > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDx > e.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDx > e.c > index 259e9365f483..8694b9254cde 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDx > e.c > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDx > e.c > @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. >=20 > **/ >=20 > +#include > #include "FaultTolerantWriteSmmDxe.h" >=20 > EFI_HANDLE mHandle =3D NULL; > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditio > nalMm.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditio > nalMm.c > new file mode 100644 > index 000000000000..440dced37bf8 > --- /dev/null > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditio > nalMm.c > @@ -0,0 +1,94 @@ > +/** @file > + > + Parts of the SMM/MM implementation that are specific to traditional MM > + > +Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2018, Linaro, Ltd. All rights reserved.
> +This program and the accompanying materials > +are licensed and made available under the terms and conditions of the BS= D > License > +which accompanies this distribution. The full text of the license may b= e found > at > +http://opensource.org/licenses/bsd-license.php > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > + > +**/ > + > +#include > +#include > +#include "FaultTolerantWrite.h" > +#include "FaultTolerantWriteSmmCommon.h" > + > +BOOLEAN > +FtwSmmIsBufferOutsideSmmValid ( > + IN EFI_PHYSICAL_ADDRESS Buffer, > + IN UINT64 Length > + ) > +{ > + if (!SmmIsBufferOutsideSmmValid (Buffer, Length)) { > + DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in > SMRAM or overflow!\n")); > + return FALSE; > + } > + return TRUE; > +} > + > +/** > + Internal implementation of CRC32. Depending on the execution context > + (traditional SMM or DXE vs standalone MM), this function is implemente= d > + via a call to the CalculateCrc32 () boot service, or via a library > + call. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param[in] Buffer A pointer to the buffer on which the 32-bit C= RC is to be > computed. > + @param[in] Length The number of bytes in the buffer Data. > + > + @retval Crc32 The 32-bit CRC was computed for the data buff= er. > + > +**/ > +UINT32 > +FtwCalculateCrc32 ( > + IN VOID *Buffer, > + IN UINTN Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 ReturnValue; > + > + Status =3D gBS->CalculateCrc32 (Buffer, Length, &ReturnValue); > + ASSERT_EFI_ERROR (Status); > + > + return ReturnValue; > +} > + > +/** > + Notify the system that the SMM driver is ready > +**/ > +VOID > +FtwNotifySmmReady ( > + VOID > + ) > +{ > + EFI_HANDLE FtwHandle; > + EFI_STATUS Status; > + > + FtwHandle =3D NULL; > + Status =3D gBS->InstallProtocolInterface ( > + &FtwHandle, > + &gEfiSmmFaultTolerantWriteProtocolGuid, > + EFI_NATIVE_INTERFACE, > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > +} > + > +EFI_STATUS > +EFIAPI > +SmmFaultTolerantWriteInitialize ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + return MmFaultTolerantWriteInitialize (); > +} > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > index 50d3421b88bb..d09e9719cf05 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > @@ -29,8 +29,6 @@ InitializeLocalWorkSpaceHeader ( > VOID > ) > { > - EFI_STATUS Status; > - > // > // Check signature with gEdkiiWorkingBlockSignatureGuid. > // > @@ -64,12 +62,8 @@ InitializeLocalWorkSpaceHeader ( > // > // Calculate the Crc of woking block header > // > - Status =3D gBS->CalculateCrc32 ( > - &mWorkingBlockHeader, > - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER), > - &mWorkingBlockHeader.Crc > - ); > - ASSERT_EFI_ERROR (Status); > + mWorkingBlockHeader.Crc =3D FtwCalculateCrc32 (&mWorkingBlockHeader, > + sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_H= EADER)); >=20 > mWorkingBlockHeader.WorkingBlockValid =3D FTW_VALID_STATE; > mWorkingBlockHeader.WorkingBlockInvalid =3D FTW_INVALID_STATE; > -- > 2.17.1