From nobody Sun May 19 12:00:51 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+99818+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+99818+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1675894664; cv=none; d=zohomail.com; s=zohoarc; b=LoOtClIeBhc4s8dZqOu0X6QueG5Y49zsRBg5R7aNGFZWLqgjrR94HopPF2CQSaTs1NDvlO5p/8moY5uvY5ycImcjCe/e7t1NHQchd84X3P2up5/vLASLK/YBDxEGRTe3eERFLAnhbMZp+X/0cE2beQSEK76Qh7N17os0CHmQ5g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675894664; 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=ap849qubcmFDnhAbF6MOQr74YkwrI4lbZRrnN2/hiDM=; b=FNLM65CqPJ8XPbu7O9xuYv5x3cdhY3mM33ZlfibBBB1fDpNZex1n0mVj4bNekqEGD2tiQdT5bJCCVN/2+QoCqSN1hBDtkWHYpZOVsPd0/ZmaAbA0prs98FZhuEdlG6swQ4DBCkkSs45YUNzmoAEumqhRCR2zzhNPthiBdFPMOjo= 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+99818+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 1675894664119736.5147827214938; Wed, 8 Feb 2023 14:17:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id b4BIYY1788612xIZtVhvy8Xd; Wed, 08 Feb 2023 14:17:43 -0800 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.12976.1675894662717788800 for ; Wed, 08 Feb 2023 14:17:42 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="309591224" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="309591224" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 14:17:41 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="645036206" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="645036206" X-Received: from cchiu4-mobl.gar.corp.intel.com ([10.212.221.164]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 14:17:41 -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 v4] IntelSiliconPkg/SpiFvbServiceSmm: Rewrite VariableStore header. Date: Wed, 8 Feb 2023 14:17:23 -0800 Message-Id: <20230208221723.917-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: BudhbSmwuHHy2TGUKUTDHcPHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675894663; bh=oKDKVn5pu40Y2FSEF5xqod/FuE7Ivob8f6t+uHFdEEI=; h=Cc:Date:From:Reply-To:Subject:To; b=FPgyoH3uWMl1819PfbJ6FScjvkiZZ9NZJ3H6CsuRA9/mOJMJF6OIsbh6ldX+og3nhHY /wD2L0xOr+1ipceSrKitN+AQPsPqJzY5F9NjPSs8TkGF0VXrmDeztLsgQrArqoEeFqGSg iBs3K3j18rcqi900+pWiD4Thj/N7u0gsUUc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675894665552100002 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. The Corrupted variable content should be taken care by FaultTolerantWrite driver later. 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 Reviewed-by: Isaac Oram Reviewed-by: Michael Kubacki --- Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceMm.= c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-= ---- Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceSmm= .inf | 3 +++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 8 ++++++++ 3 files changed, 75 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..052be97872 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 @@ -113,7 +114,12 @@ FvbInitialize ( UINT32 MaxLbaSize; UINT32 BytesWritten; UINTN BytesErased; + EFI_PHYSICAL_ADDRESS NvStorageBaseAddress; UINT64 NvStorageFvSize; + UINT32 ExpectedBytesWritten; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINT8 VariableStoreType; + UINT8 *NvStoreBuffer; =20 Status =3D GetVariableFlashNvStorageInfo (&BaseAddress, &NvStorageFvSize= ); if (EFI_ERROR (Status)) { @@ -124,12 +130,14 @@ FvbInitialize ( =20 // Stay within the current UINT32 size assumptions in the variable stack. Status =3D SafeUint64ToUint32 (BaseAddress, &mPlatformFvBaseAddress[0].F= vBase); + NvStorageBaseAddress =3D mPlatformFvBaseAddress[0].FvBase; if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); DEBUG ((DEBUG_ERROR, "[%a] - 64-bit variable storage base address not = supported.\n", __FUNCTION__)); return; } Status =3D SafeUint64ToUint32 (NvStorageFvSize, &mPlatformFvBaseAddress[= 0].FvSize); + NvStorageFvSize =3D mPlatformFvBaseAddress[0].FvSize; if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); DEBUG ((DEBUG_ERROR, "[%a] - 64-bit variable storage size not supporte= d.\n", __FUNCTION__)); @@ -186,8 +194,59 @@ FvbInitialize ( } continue; } - BytesWritten =3D FvHeader->HeaderLength; - Status =3D SpiFlashWrite ((UINTN)BaseAddress, &BytesWritten, (UINT= 8*)FvHeader); + + BytesWritten =3D FvHeader->HeaderLength; + ExpectedBytesWritten =3D BytesWritten; + if (BaseAddress !=3D NvStorageBaseAddress) { + 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. + // The corrupted Variable content should be taken care by FaultT= olerantWrite driver later. + // + 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 (UINT32) (NvStorageFvSize -= 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 +254,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..73049eceb2 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceSmm.inf +++ b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceSmm.inf @@ -45,6 +45,7 @@ [Pcd] gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvBase ## CONSUM= ES gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvSize ## CONSUM= ES + gIntelSiliconPkgTokenSpaceGuid.PcdFlashVariableStoreType ## SOMETI= MES_CONSUMES =20 [Sources] FvbInfo.c @@ -61,6 +62,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 (#99818): https://edk2.groups.io/g/devel/message/99818 Mute This Topic: https://groups.io/mt/96841486/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-