From nobody Fri May 17 19:59:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99763+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99763+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1675798991; cv=none; d=zohomail.com; s=zohoarc; b=aFe7TDxTJsYb6CoTlMWyoQlK9VXfW0dWN96Zd21EJi5yl6apjHKMR5sw1wbLlO6p2HOvT4Rpp/kJp7Hua99pWhNk0BtEQSwrmecuGLH18fJ6wbpFKXx3orm4ketamrLH/Asr2fP6fjw0GSi0nVZ7174JdqunLvuLxTdn4r+WUOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675798991; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=FHuLJq919KzleqysNDjNYODbLLDpr1oAa2PTeD2f6us=; b=U86uf/jL5IEmp5I0mMoFUBC+K5y3X2nHsg+s7KQU1g162oaH+haHqW80ZAVt6LB/PnzonbAPxlTCkd1reQ06vTBBDmkN2WPndnolTn2TqPIa/vlK8mZhI1M48ka0FKOKX4sZUTyhZjDFebsfH6T+UyP0Z7M3LUqRwRPFybWbSTE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99763+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1675798991143969.2390842461755; Tue, 7 Feb 2023 11:43:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6tPhYY1788612xqzfn5JNaNs; Tue, 07 Feb 2023 11:43:10 -0800 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.128.1675798989732216064 for ; Tue, 07 Feb 2023 11:43:10 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="331740091" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="331740091" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 11:43:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="735655699" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="735655699" X-Received: from wanggan1-mobl1.amr.corp.intel.com (HELO cchiu4-mobl.gar.corp.intel.com) ([10.212.162.80]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 11:43:08 -0800 From: "Chiu, Chasel" To: devel@edk2.groups.io Cc: Chasel Chiu , Ashraf Ali S , Isaac Oram , Rangasai V Chaganty , Ray Ni , Michael Kubacki Subject: [edk2-devel] [edk2-platforms: PATCH v3] IntelSiliconPkg/SpiFvbServiceSmm: Rewrite VariableStore header. Date: Tue, 7 Feb 2023 11:42:58 -0800 Message-Id: <20230207194258.2598-1-chasel.chiu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,chasel.chiu@intel.com X-Gm-Message-State: L1ubxcKLeFlxGUY9BvWb89fTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675798990; bh=iqKdtdMfrcTzfU9PdgfuOtFfM/UUiyKNthrnOCDJVxc=; h=Cc:Date:From:Reply-To:Subject:To; b=LQGv9ht/XFQkKctCj1mKCc0cN5+wGM3tDS4Qotix47kW+DmUD9LmyNQfLaRihlrjLSB k7rQocMuy4Uduu5PWLI+cck/lnLQfV5ADuPExMDnPpxPsIXUejYcoYkbrN4srLKBSa6zu flysFktp7Pqj6Wna2J2xE4rtg9GltcwiCkc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675798992557100001 Content-Type: text/plain; charset="utf-8" When invalid VariableStore FV header detected, current SpiFvbService will erase both FV and VariableStore headers from flash, however, it will only rewrite FV header back and cause invalid VariableStore header. This patch adding the support for rewriting both FV header and VariableStore header when VariableStore corruption happened. Platform has to set PcdFlashVariableStoreType to inform SpiFvbService which VariableStoreType should be rewritten. Cc: Ashraf Ali S Cc: Isaac Oram Cc: Rangasai V Chaganty Cc: Ray Ni Cc: Michael Kubacki Signed-off-by: Chasel Chiu --- Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceMm.= c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceSmm= .inf | 4 ++++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 8 ++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiF= vbServiceMm.c b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/S= piFvbServiceMm.c index 6b4bcdcfe3..6338442e1a 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceMm.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceMm.c @@ -12,6 +12,7 @@ #include #include #include +#include =20 /** The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol @@ -114,6 +115,10 @@ FvbInitialize ( UINT32 BytesWritten; UINTN BytesErased; UINT64 NvStorageFvSize; + UINT32 ExpectedBytesWritten; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINT8 VariableStoreType; + UINT8 *NvStoreBuffer; =20 Status =3D GetVariableFlashNvStorageInfo (&BaseAddress, &NvStorageFvSize= ); if (EFI_ERROR (Status)) { @@ -186,8 +191,57 @@ FvbInitialize ( } continue; } - BytesWritten =3D FvHeader->HeaderLength; - Status =3D SpiFlashWrite ((UINTN)BaseAddress, &BytesWritten, (UINT= 8*)FvHeader); + + BytesWritten =3D FvHeader->HeaderLength; + ExpectedBytesWritten =3D BytesWritten; + if (Idx !=3D 0) { + Status =3D SpiFlashWrite ((UINTN)BaseAddress, &BytesWritten, (UI= NT8 *)FvHeader); + } else { + // + // This is Variable Store, rewrite both EFI_FIRMWARE_VOLUME_HEAD= ER and VARIABLE_STORE_HEADER + // + NvStoreBuffer =3D NULL; + NvStoreBuffer =3D AllocateZeroPool (sizeof (VARIABLE_STORE_HEADE= R) + FvHeader->HeaderLength); + if (NvStoreBuffer !=3D NULL) { + // + // Combine FV header and VariableStore header into the buffer. + // + CopyMem (NvStoreBuffer, FvHeader, FvHeader->HeaderLength); + VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)(NvStoreBuffe= r + FvHeader->HeaderLength); + VariableStoreType =3D PcdGet8 (PcdFlashVariableStoreType); + switch (VariableStoreType) { + case 0: + DEBUG ((DEBUG_ERROR, "Type: gEfiVariableGuid\n")); + CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGu= id); + break; + case 1: + DEBUG ((DEBUG_ERROR, "Type: gEfiAuthenticatedVariableGuid\= n")); + CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthentica= tedVariableGuid); + break; + default: + break; + } + + // + // Initialize common VariableStore header fields + // + VariableStoreHeader->Size =3D PcdGet32 (PcdFlashNvStorage= VariableSize) - FvHeader->HeaderLength; + VariableStoreHeader->Format =3D VARIABLE_STORE_FORMATTED; + VariableStoreHeader->State =3D VARIABLE_STORE_HEALTHY; + VariableStoreHeader->Reserved =3D 0; + VariableStoreHeader->Reserved1 =3D 0; + // + // Write buffer to flash + // + BytesWritten =3D FvHeader->HeaderLength + sizeof (VARI= ABLE_STORE_HEADER); + ExpectedBytesWritten =3D BytesWritten; + Status =3D SpiFlashWrite ((UINTN)BaseAddress, &B= ytesWritten, NvStoreBuffer); + FreePool (NvStoreBuffer); + } else { + Status =3D EFI_OUT_OF_RESOURCES; + } + } + if (EFI_ERROR (Status)) { DEBUG ((DEBUG_WARN, "ERROR - SpiFlashWrite Error %r\n", Status)= ); if (FvHeader !=3D NULL) { @@ -195,9 +249,9 @@ FvbInitialize ( } continue; } - if (BytesWritten !=3D FvHeader->HeaderLength) { - DEBUG ((DEBUG_WARN, "ERROR - BytesWritten !=3D HeaderLength\n")); - DEBUG ((DEBUG_INFO, " BytesWritten =3D 0x%X\n HeaderLength =3D 0= x%X\n", BytesWritten, FvHeader->HeaderLength)); + if (BytesWritten !=3D ExpectedBytesWritten) { + DEBUG ((DEBUG_WARN, "ERROR - BytesWritten !=3D ExpectedBytesWrit= ten\n")); + DEBUG ((DEBUG_INFO, " BytesWritten =3D 0x%X\n ExpectedBytesWritt= en =3D 0x%X\n", BytesWritten, ExpectedBytesWritten)); if (FvHeader !=3D NULL) { FreePool (FvHeader); } diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiF= vbServiceSmm.inf b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbServic= e/SpiFvbServiceSmm.inf index 0cfa3f909b..0485b73679 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceSmm.inf +++ b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceSmm.inf @@ -45,6 +45,8 @@ [Pcd] gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvBase ## CONSUM= ES gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvSize ## CONSUM= ES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## SOMETI= MES_CONSUMES + gIntelSiliconPkgTokenSpaceGuid.PcdFlashVariableStoreType ## SOMETI= MES_CONSUMES =20 [Sources] FvbInfo.c @@ -61,6 +63,8 @@ [Guids] gEfiFirmwareFileSystem2Guid ## CONSUMES gEfiSystemNvDataFvGuid ## CONSUMES + gEfiVariableGuid ## SOMETIMES_CONSUMES + gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES =20 [Depex] TRUE diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/In= tel/IntelSiliconPkg/IntelSiliconPkg.dec index 485cb3e80a..63dae756ad 100644 --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec @@ -186,3 +186,11 @@ # @Prompt VTd abort DMA mode support. gIntelSiliconPkgTokenSpaceGuid.PcdVTdSupportAbortDmaMode|FALSE|BOOLEAN|0= x0000000C =20 + ## Define Flash Variable Store type.

+ # When Flash Variable Store corruption happened, the SpiFvbService will= recreate Variable Store + # with valid header information provided by this PCD value.
+ # 0: Variable Store is gEfiVariableGuid type.
+ # 1: Variable Store is gEfiAuthenticatedVariableGuid type.
+ # Other value: reserved for future use.
+ # @Prompt Flash Variable Store type. + gIntelSiliconPkgTokenSpaceGuid.PcdFlashVariableStoreType|0x00|UINT8|0x00= 00000E --=20 2.35.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99763): https://edk2.groups.io/g/devel/message/99763 Mute This Topic: https://groups.io/mt/96815037/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-