From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.79806.1675761980760662649 for ; Tue, 07 Feb 2023 01:26:21 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=cDN6igO3; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ashraf.ali.s@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675761980; x=1707297980; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ZJWuEYUhSoQqAX5oZWx/utoDfGURscVUvW5ra/qOh6E=; b=cDN6igO3RGzn5sXBjkVcYDlSunwAw/k+bqFiZiRLyZtfat8AufLISyAZ sfMfkP2sTX/lxXUklRBCv2/yRdxjGtJCTLZuWTVYY5igVMenbfi9cIfVE AnGYr3taFldvt0p46sicklxjk0Xl9UOt03vdWb3b8TOkaGof3KralLlMw f8TpBSsm7WlEUSU64zIhtWpm3kEYZ3F+1n9WRAcn/Vv1fXkYjZrR6OhdT D4GU6JYibLe3W2/hX5NXgUAzoCLISsm7LkNvmILH9BWz37GrPKdgVhfez 6F/gUvrFkyZsMzkH3My0sBBqBEdB9p3Wt4Q4a2LqyQYugJnOfFsi5noMY A==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="394059364" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="394059364" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 01:26:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="755568512" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="755568512" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by FMSMGA003.fm.intel.com with ESMTP; 07 Feb 2023 01:26:04 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 7 Feb 2023 01:26:04 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 7 Feb 2023 01:26:04 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Tue, 7 Feb 2023 01:26:04 -0800 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.169) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Tue, 7 Feb 2023 01:26:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IJXgMk9W7oDbsw8CAE8eOUUKfobljr7zlf9CQjOkauLw1+jT4OW2P3iBKt8BrqHWxSN6nPYs6+xrEjE2yV14Lc4bdxYwddXI3Ot8nhqQynAtuMkogdRIn5W6HKxwX77KqvNSgS/FSQbix1gmtNx7q4BuUOtv4uT1/FDU65qLDSqxAaITUpLJuLJZ4rh5AtjnFqJKVjkv01E79TBtRy+WmIapAxpUbGvjOsyJ+nXPI3r93xe59UrnyB7yKyEduqCmgMedqBPIJut4vHURdb+v3gshqzA1afGDAk31K9z1iGu1CMqTvpXUtJLA11Ql9VLwgviAqGnmjJc58R8KeG/M+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fKMEpLaXYjqbALTmKdjyNRUxLNh2s+u/lVDwWd9r24g=; b=WI/c4/GDnLG6kB0NxumxxBHUQ7CEMNHCudwgdpQqALnHJNsqyuzDZx8hipTvWUyKxdGghrljgJzlct6te1kGbz6i9HhYO5qwFOBg28Mf0tyGTxzjfzhtpyF+UMYMLs2hUPcPRMj94K+UFhrh9Lu5oSlghAZR7U1Ap8eJiWM4Z9/2QmLxINngjP3zP1qMXpHdyOHMPxWNiN22o2KczeG4E4XYZNA4YYQp/sfC2CzHpj1eaICnuLrybBAIGtko85Tb7EY4IyR7L7Rfpb2mFSbeqGJEDC50014pwUO66+Qn6TZhMecWEypOYIIENcOYxpr3OXl6TuoWoE2X86nDEpKXcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM4PR11MB5280.namprd11.prod.outlook.com (2603:10b6:5:38b::18) by DM4PR11MB5533.namprd11.prod.outlook.com (2603:10b6:5:38a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.36; Tue, 7 Feb 2023 09:26:00 +0000 Received: from DM4PR11MB5280.namprd11.prod.outlook.com ([fe80::962:a825:20f5:6cc]) by DM4PR11MB5280.namprd11.prod.outlook.com ([fe80::962:a825:20f5:6cc%7]) with mapi id 15.20.6064.034; Tue, 7 Feb 2023 09:26:00 +0000 From: "Ashraf Ali S" To: "Chiu, Chasel" , "devel@edk2.groups.io" CC: "Oram, Isaac W" , "Chaganty, Rangasai V" , "Ni, Ray" , "Kubacki, Michael" Subject: Re: [edk2-platforms: PATCH v2] IntelSiliconPkg/SpiFvbServiceSmm: Rewrite VariableStore header. Thread-Topic: [edk2-platforms: PATCH v2] IntelSiliconPkg/SpiFvbServiceSmm: Rewrite VariableStore header. Thread-Index: AQHZOlvqtpUNtQgTrEmwAdkh1Y1tCa7DNd+Q Date: Tue, 7 Feb 2023 09:26:00 +0000 Message-ID: References: <20230206185015.1753-1-chasel.chiu@intel.com> In-Reply-To: <20230206185015.1753-1-chasel.chiu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB5280:EE_|DM4PR11MB5533:EE_ x-ms-office365-filtering-correlation-id: a2a44353-7d56-40e0-cd87-08db08ed5373 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: r/oLrbUWeKIrc8c1+EnuKetYzcZUlYLlWuNveIH5cPtFkrWDA/8xpVTJDvCggzzUVjfv3wm5seJuqIutAvL4Zx/f6nPUffEUZ1+jxfCJ+LbFDr+BiWyaA05MEqqh9I4T5ceMOl9K9/ACVL0ldL5fQOBqBCfhmngpruxXUQnKuzLkFtDooTz8YdNUq3ffZ9kS7D+UZjKIsNp+YWuVBgtRoZbwXPeG6v0UR9m2WTPGOnUprbNCipsNQ99H3vm23pMNrZOseh7og9M+CwyQw+qZj9n6QWFQHIadwknvyE94c2XtUfrDL+oc/6CE8YZzmjy1M+gOPvsRBFKv4L3H2LtJNy96pwuPpDcq/+yDysivU+OR8ha0vRNd/VzwIYVAT824Gq96mTmD49arpeUAg9XavGsjEY0Urel1GZL5RVQ2wUBMAUr8pi89leIuRHNtouu3P9KYkYOKCTgxwfI2dznwKQpnACbj2H9TZphpIirywmTrY/6lRsJh42V91g5yBhulpWuPKSrhLim1AsGCKQf1Oyvi+ye24dfpVYabDUoEMMb+1OzJHe2mieusKDvhKBfKehzEO8fgQn0ApOE1LMy/WMb01s9uUZXd/O4SoFVqIgYk59pasuy6hjFWk4BIy8TaAAYoB1KzO8hLGB20tAzDz4gIMy1zfp/2qJgq8qoDtfpPD0Ez46AnGpBMQ9OlmNqofJCDUrSNbdykhf+vBPMT3h1W9zVx3SShAS2AOtbcBCs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5280.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(376002)(396003)(136003)(39860400002)(366004)(451199018)(86362001)(54906003)(110136005)(186003)(33656002)(7696005)(71200400001)(55016003)(4326008)(2906002)(66946007)(76116006)(30864003)(5660300002)(64756008)(8676002)(8936002)(66556008)(66446008)(66476007)(41300700001)(26005)(478600001)(9686003)(6506007)(53546011)(38100700002)(82960400001)(52536014)(316002)(83380400001)(38070700005)(122000001)(19627235002)(14943795004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?QnzJXcjWDoZ4v2tkQRYUyl+BDJwXgDs8xRMHw4lfjzEonEMmYuk/1n1whoM1?= =?us-ascii?Q?7Cw6Ux49IqCG9fjZn1+GYq4UTf9g6jeEqPVwmUtYp36nuGlxNe1gzUonRUZP?= =?us-ascii?Q?VIX4lnQKY2I7hX7EqFXKn8GASi435CshuvW7EzvflsefcXxNqgbE74PhfX5B?= =?us-ascii?Q?JG/LvZnzNd2r8Mro3GjKyYsMoOZY8C8xT1pSM83GXnwgmkp7WsLobindR0UW?= =?us-ascii?Q?LKm9t9erwFHEMTgudbTmrqmw6OFv8+ta6khT3Ev5DMwaJUdl3Fi8g2RbgLl+?= =?us-ascii?Q?ncu9N4Lv3EudcuxK/aVIYA6XuzahFCGZq97PNqlgBZyqsfP8+HlQWeoG11/n?= =?us-ascii?Q?HE5aFPlOCgIwBmKZj9lLlYQwNnUjqVOXcpozn0DGQRlCZlod1vj3Bs7wA4QN?= =?us-ascii?Q?YlhnaVH1hmznamRZRy3eistRtgfAFLd4bN4OdrdZCHYHBuc1SpmPmUXZ/2zZ?= =?us-ascii?Q?VWARX9NClvH6e0hIp+WMw98weUtFGcuW/+eRhYy+A6twNGoQjpYn1JEoe1br?= =?us-ascii?Q?Plp9D9T+Mv+ZoBe+McLt4/j0yLYGJ9BMLLLgY+CXA4AH894jJECzJ9K5TG/a?= =?us-ascii?Q?xNCOg3L16GXIPJrztg9Eg4WF1sdw67kVnEz9FNHNix0B5CGqhk1/8lCquxJc?= =?us-ascii?Q?gD4dRywlZNan/CP+Klu6WfyHznugXduNx5yqPwqI/HJcz1mJ2VmGSlMwN2/r?= =?us-ascii?Q?e/JDW9ItxEX+nq+kZpZUYF2LHKeBAlqK0RoAdCu+AHfnlcZwkWfC1dVtBlLM?= =?us-ascii?Q?czSCTd05JbDWIryQPLVRJ01nimQvPxmjXTw93N7remHxyGIvRqaJU1ODVWCr?= =?us-ascii?Q?cxgVdCtfgu+uNd6uEvqamXTFNdJ0jikSbeU5FVrFlXL4tCJ8VsteE7u186D3?= =?us-ascii?Q?s8DV5+8CvVfFm7z86IOrPXUs/6ZWHRFyfZSy9RAZHUM8x/WtgTlShhIMvYkL?= =?us-ascii?Q?UnEQM8jVsdurB0+p/uZc+uOL4/JjHMWke3z+9RFhIWxLs0PlkL7VZpiZHZUK?= =?us-ascii?Q?S0gj7IJkR/VRy6juM7uptPcE3ikkU0q5U+M3Kuuw9MgI3IjvJi6A40tPb+Or?= =?us-ascii?Q?F9VH9ki7IOE3JRFl+jMGnPksb9wYGG9fkI7wxe2WFEUAuBsASU8Dxv6QRn/7?= =?us-ascii?Q?wcxBvVhcHqnz8SzAlZRRwiLcdslx9kEidBbLWxS5vxxU4sgZ1VjprPOVNlne?= =?us-ascii?Q?H53PJrc4KGsjVWYl27tkrbgVUDk58UBD5x3Lr8wvgD62uqNikk/kHSYxP1nG?= =?us-ascii?Q?CNuv8NWMYzLoZI9HRFSvT9p+zdPWJPqinDuiz7jYYPceGewCplcO+R1j45L0?= =?us-ascii?Q?mBZByptmCG1Bo0DHaIuvtLR+WfS5Kg7fyMyAMe5rssnPOjXY7nFGGZ6Qi5SX?= =?us-ascii?Q?3tWET/l4fg2q/Oq6wtcid9AV85eSaAfXMaHmUBQ235T7aoeiKBN3XSOALvyl?= =?us-ascii?Q?gqxJoJgJ1i6HscZJax3Bdri8nVHRKdSDvcMrOW9KeK/QNMtPjrx1Q/py/Ycf?= =?us-ascii?Q?xCCck5loHvGA8v8NeK668keHqwc6ijb1jpaio9sLykmUaOczIFaI8Bp5LOMS?= =?us-ascii?Q?28NTHd9GRTEzha1UMWQVc7wsiuWVX6kItaVrqrkG?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5280.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2a44353-7d56-40e0-cd87-08db08ed5373 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Feb 2023 09:26:00.3113 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: qSPYencvaGYOy/JjY01+X0p3Wx39iFeO4xePgAunladQkw2yaes2xMGwWPVv9mgJXH2rJnF8EynqO3AwztCObQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5533 Return-Path: ashraf.ali.s@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: S, Ashraf Ali -----Original Message----- From: Chiu, Chasel =20 Sent: Tuesday, February 7, 2023 12:20 AM To: devel@edk2.groups.io Cc: Chiu, Chasel ; S, Ashraf Ali ; Oram, Isaac W ; Chaganty, Rangasai V ; Ni, Ray ; Kubacki, Michael Subject: [edk2-platforms: PATCH v2] IntelSiliconPkg/SpiFvbServiceSmm: Rewri= te VariableStore header. When invalid VariableStore FV header detected, current SpiFvbService will e= rase both FV and VariableStore headers from flash, however, it will only re= write FV header back and cause invalid VariableStore header. This patch adding the support for rewriting both FV header and VariableStor= e 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 | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------= ----------------------------------- Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceSmm= .inf | 4 ++++ Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec = | 8 ++++++++ 3 files changed, 134 insertions(+), 52 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..6af2dfac10 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceMm.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbSe +++ rviceMm.c @@ -12,6 +12,7 @@ #include #include #include +#include /** The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol@= @ -25,12 +26,12 @@ **/ VOID InstallFvbProtocol (- IN EFI_FVB_INSTANCE *FvbIns= tance+ IN EFI_FVB_INSTANCE *FvbInstance ) {- EFI_FIRMWARE_VOLUME_HEAD= ER *FvHeader;- EFI_STATUS Status;- = EFI_HANDLE FvbHandle;+ EFI_FIRMWARE_VOLUME_HEAD= ER *FvHeader;+ EFI_STATUS Status;+ EFI_HANDLE = FvbHandle; ASSERT (FvbInstance !=3D NULL); if (FvbInstance =3D= =3D NULL) {@@ -52,19 +53,21 @@ InstallFvbProtocol ( // // FV does not contains extension header, then produce MEMMAP_D= EVICE_PATH //- FvbInstance->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL= *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevi= cePathTemplate);+ FvbInstance->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL = *)AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevice= PathTemplate); if (FvbInstance->DevicePath =3D=3D NULL) { DEBUG (= (DEBUG_INFO, "SpiFvbServiceSmm.c: Memory allocation for MEMMAP_DEVICE_PATH = failed\n")); return; }- ((FV_MEMMAP_DEVICE_PATH *) FvbInstance= ->DevicePath)->MemMapDevPath.StartingAddress =3D FvbInstance->FvBase;- (= (FV_MEMMAP_DEVICE_PATH *) FvbInstance->DevicePath)->MemMapDevPath.EndingAdd= ress =3D FvbInstance->FvBase + FvHeader->FvLength - 1;++ ((FV_MEMMAP_D= EVICE_PATH *)FvbInstance->DevicePath)->MemMapDevPath.StartingAddress =3D Fv= bInstance->FvBase;+ ((FV_MEMMAP_DEVICE_PATH *)FvbInstance->DevicePath)->= MemMapDevPath.EndingAddress =3D FvbInstance->FvBase + FvHeader->FvLength = - 1; } else {- FvbInstance->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *= ) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePath= Template);+ FvbInstance->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)Allo= cateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTempla= te); if (FvbInstance->DevicePath =3D=3D NULL) { DEBUG ((DEBUG_INF= O, "SpiFvbServiceSmm.c: Memory allocation for FV_PIWG_DEVICE_PATH failed\n"= )); return; }+ CopyGuid ( &((FV_PIWG_DEVICE_PATH *)FvbI= nstance->DevicePath)->FvDevPath.FvName, (GUID *)(UINTN)(FvbInstance->= FvBase + FvHeader->ExtHeaderOffset)@@ -103,17 +106,21 @@ FvbInitialize ( VOID ) {- EFI_FVB_INSTANCE *FvbInstance;- EFI_F= IRMWARE_VOLUME_HEADER *FvHeader;- EFI_FV_BLOCK_MAP_ENTRY = *PtrBlockMapEntry;- EFI_PHYSICAL_ADDRESS BaseAdd= ress;- EFI_STATUS Status;- UINTN = BufferSize;- UINTN Idx;= - UINT32 MaxLbaSize;- UINT32 = BytesWritten;- UINTN Byt= esErased;- UINT64 NvStorageFvSize;+ EFI_FV= B_INSTANCE *FvbInstance;+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader= ;+ EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;+ EFI_PHYSICAL_ADDRESS = BaseAddress;+ EFI_STATUS Status;+ UINTN = BufferSize;+ UINTN Idx;+ UINT32 = MaxLbaSize;+ UINT32 BytesWritten;+ UIN= TN BytesErased;+ UINT64 NvStora= geFvSize;+ UINT32 ExpectedBytesWritten;+ VARIABLE_ST= ORE_HEADER *VariableStoreHeader;+ UINT8 Variab= leStoreType;+ UINT8 *NvStoreBuffer; Status =3D Ge= tVariableFlashNvStorageInfo (&BaseAddress, &NvStorageFvSize); if (EFI_ERR= OR (Status)) {@@ -129,6 +136,7 @@ FvbInitialize ( DEBUG ((DEBUG_ERROR, "[%a] - 64-bit variable storage base address not = supported.\n", __FUNCTION__)); return; }+ Status =3D SafeUint64ToUi= nt32 (NvStorageFvSize, &mPlatformFvBaseAddress[0].FvSize); if (EFI_ERROR = (Status)) { ASSERT_EFI_ERROR (Status);@@ -136,8 +144,8 @@ FvbInitialize= ( return; } - mPlatformFvBaseAddress[1].FvBase =3D PcdGet32(PcdFlashM= icrocodeFvBase);- mPlatformFvBaseAddress[1].FvSize =3D PcdGet32(PcdFlashMi= crocodeFvSize);+ mPlatformFvBaseAddress[1].FvBase =3D PcdGet32 (PcdFlashMi= crocodeFvBase);+ mPlatformFvBaseAddress[1].FvSize =3D PcdGet32 (PcdFlashMi= crocodeFvSize); // // We will only continue with FVB installation if t= he@@ -147,17 +155,17 @@ FvbInitialize ( // // Make sure all FVB are valid and/or fix if possible //- = for (Idx =3D 0;; Idx++) {- if (mPlatformFvBaseAddress[Idx].FvSize = =3D=3D 0 && mPlatformFvBaseAddress[Idx].FvBase =3D=3D 0) {+ for (Idx =3D= 0; ; Idx++) {+ if ((mPlatformFvBaseAddress[Idx].FvSize =3D=3D 0) && (= mPlatformFvBaseAddress[Idx].FvBase =3D=3D 0)) { break; } = BaseAddress =3D mPlatformFvBaseAddress[Idx].FvBase;- FvHeader =3D (= EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;+ FvHeader =3D (E= FI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress; if (!IsFvHeaderValid= (BaseAddress, FvHeader)) { BytesWritten =3D 0;- BytesErased= =3D 0;+ BytesErased =3D 0; DEBUG ((DEBUG_ERROR, "ERROR - T= he FV in 0x%x is invalid!\n", FvHeader)); FvHeader =3D NULL; = Status =3D GetFvbInfo (BaseAddress, &FvHeader);@@ -165,57 +173,116 @@ F= vbInitialize ( DEBUG ((DEBUG_WARN, "ERROR - Can't recovery FV header at 0x%x. = GetFvbInfo Status %r\n", BaseAddress, Status)); continue; = }+ DEBUG ((DEBUG_INFO, "Rewriting FV header at 0x%X with static da= ta\n", BaseAddress)); // // Spi erase //- By= tesErased =3D (UINTN) FvHeader->BlockMap->Length;- Status =3D SpiFla= shBlockErase( (UINTN) BaseAddress, &BytesErased);+ BytesErased =3D (= UINTN)FvHeader->BlockMap->Length;+ Status =3D SpiFlashBlockEras= e ((UINTN)BaseAddress, &BytesErased); if (EFI_ERROR (Status)) { = DEBUG ((DEBUG_WARN, "ERROR - SpiFlashBlockErase Error %r\n", Status= )); if (FvHeader !=3D NULL) { FreePool (FvHeader); = }+ continue; }+ if (BytesErased !=3D FvHe= ader->BlockMap->Length) { DEBUG ((DEBUG_WARN, "ERROR - BytesErase= d !=3D FvHeader->BlockMap->Length\n")); DEBUG ((DEBUG_INFO, " Byt= esErased =3D 0x%X\n Length =3D 0x%X\n", BytesErased, FvHeader->BlockMap->Le= ngth)); if (FvHeader !=3D NULL) { FreePool (FvHeader)= ; }+ continue; }- BytesWritten =3D FvHea= der->HeaderLength;- Status =3D SpiFlashWrite ((UINTN)BaseAddress, &B= ytesWritten, (UINT8*)FvHeader);++ BytesWritten =3D FvHeader-= >HeaderLength;+ ExpectedBytesWritten =3D BytesWritten;+ if (I= dx !=3D 0) {+ Status =3D SpiFlashWrite ((UINTN)BaseAddress, &Bytes= Written, (UINT8 *)FvHeader);+ } else {+ //+ // Thi= s is Variable Store, rewrite both EFI_FIRMWARE_VOLUME_HEADER and VARIABLE_S= TORE_HEADER+ //+ NvStoreBuffer =3D NULL;+ NvStor= eBuffer =3D AllocateZeroPool (sizeof (VARIABLE_STORE_HEADER) + FvHeader->He= aderLength);+ if (NvStoreBuffer !=3D NULL) {+ //+ = // Combine FV header and VariableStore header into the buffer.+ = //+ CopyMem (NvStoreBuffer, FvHeader, FvHeader->HeaderLeng= th);+ VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)(NvStoreB= uffer + FvHeader->HeaderLength);+ VariableStoreType =3D PcdGet= 8 (PcdFlashVariableStoreType);+ switch (VariableStoreType) {+ = case 0:+ DEBUG ((DEBUG_ERROR, "Type: gEfiVariable= Guid\n"));+ CopyGuid (&VariableStoreHeader->Signature, &gEfi= VariableGuid);+ break;+ case 1:+ = DEBUG ((DEBUG_ERROR, "Type: gEfiAuthenticatedVariableGuid\n"));+ = CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariable= Guid);+ break;+ default:+ break;= + }++ //+ // Initialize common VariableSto= re header fields+ //+ VariableStoreHeader->Size = =3D PcdGet32 (PcdFlashNvStorageVariableSize) - FvHeader->HeaderLength;+ = VariableStoreHeader->Format =3D VARIABLE_STORE_FORMATTED;+ = VariableStoreHeader->State =3D VARIABLE_STORE_HEALTHY;+ = VariableStoreHeader->Reserved =3D 0;+ VariableStoreHeader->Re= served1 =3D 0;+ //+ // Write buffer to flash+ = //+ BytesWritten =3D FvHeader->HeaderLength + sizeof= (VARIABLE_STORE_HEADER);+ ExpectedBytesWritten =3D BytesWritten= ;+ Status =3D SpiFlashWrite ((UINTN)BaseAddress, &= BytesWritten, 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) = { FreePool (FvHeader); }+ continue; = }- if (BytesWritten !=3D FvHeader->HeaderLength) {- DEBUG = ((DEBUG_WARN, "ERROR - BytesWritten !=3D HeaderLength\n"));- DEBUG= ((DEBUG_INFO, " BytesWritten =3D 0x%X\n HeaderLength =3D 0x%X\n", BytesWri= tten, FvHeader->HeaderLength));++ if (BytesWritten !=3D ExpectedByte= sWritten) {+ DEBUG ((DEBUG_WARN, "ERROR - BytesWritten !=3D Expect= edBytesWritten\n"));+ DEBUG ((DEBUG_INFO, " BytesWritten =3D 0x%X\= n ExpectedBytesWritten =3D 0x%X\n", BytesWritten, ExpectedBytesWritten)); = if (FvHeader !=3D NULL) { FreePool (FvHeader); = }+ continue; }+ Status =3D SpiFlashLock (); = if (EFI_ERROR (Status)) { DEBUG ((DEBUG_WARN, "ERROR - SpiF= lashLock Error %r\n", Status)); if (FvHeader !=3D NULL) { = FreePool (FvHeader); }+ continue; }+ = DEBUG ((DEBUG_INFO, "FV Header @ 0x%X restored with static data\n", Bas= eAddress)); // // Clear cache for this range. //- = WriteBackInvalidateDataCacheRange ( (VOID *) (UINTN) BaseAddress, FvH= eader->BlockMap->Length);+ WriteBackInvalidateDataCacheRange ((VOID = *)(UINTN)BaseAddress, FvHeader->BlockMap->Length); if (FvHeader != =3D NULL) { FreePool (FvHeader); }@@ -227,11 +294,12 @@ F= vbInitialize ( // BufferSize =3D 0; for (Idx =3D 0; ; Idx++) {- if (mPla= tformFvBaseAddress[Idx].FvSize =3D=3D 0 && mPlatformFvBaseAddress[Idx].FvBa= se =3D=3D 0) {+ if ((mPlatformFvBaseAddress[Idx].FvSize =3D=3D 0) && (= mPlatformFvBaseAddress[Idx].FvBase =3D=3D 0)) { break; }+ = BaseAddress =3D mPlatformFvBaseAddress[Idx].FvBase;- FvHeader =3D (= EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;+ FvHeader =3D (E= FI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress; if (!IsFvHeaderValid= (BaseAddress, FvHeader)) { DEBUG ((DEBUG_WARN, "ERROR - The FV in = 0x%x is invalid!\n", FvHeader));@@ -239,27 +307,28 @@ FvbInitialize ( } BufferSize +=3D (FvHeader->HeaderLength +- = sizeof (EFI_FVB_INSTANCE) -- sizeof (EFI_FIRMWARE_VOL= UME_HEADER)- );+ sizeof (EFI_FVB_INS= TANCE) -+ sizeof (EFI_FIRMWARE_VOLUME_HEADER)+ = ); } - mFvbModuleGlobal.FvbInstance =3D (EFI_FVB_INSTAN= CE *) AllocateRuntimeZeroPool (BufferSize);+ mFvbModuleGlobal.FvbInstanc= e =3D (EFI_FVB_INSTANCE *)AllocateRuntimeZeroPool (BufferSize); if (mF= vbModuleGlobal.FvbInstance =3D=3D NULL) { ASSERT (FALSE); retur= n; } - MaxLbaSize =3D 0;- FvbInstance =3D mFvbModuleGlob= al.FvbInstance;- mFvbModuleGlobal.NumFv =3D 0;+ MaxLbaSize = =3D 0;+ FvbInstance =3D mFvbModuleGlobal.FvbInstance;+ = mFvbModuleGlobal.NumFv =3D 0; for (Idx =3D 0; ; Idx++) {- if (mP= latformFvBaseAddress[Idx].FvSize =3D=3D 0 && mPlatformFvBaseAddress[Idx].Fv= Base =3D=3D 0) {+ if ((mPlatformFvBaseAddress[Idx].FvSize =3D=3D 0) &&= (mPlatformFvBaseAddress[Idx].FvBase =3D=3D 0)) { break; }+ = BaseAddress =3D mPlatformFvBaseAddress[Idx].FvBase;- FvHeader =3D= (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;+ FvHeader =3D = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress; if (!IsFvHeaderVal= id (BaseAddress, FvHeader)) { DEBUG ((DEBUG_WARN, "ERROR - The FV i= n 0x%x is invalid!\n", FvHeader));@@ -269,22 +338,24 @@ FvbInitialize ( FvbInstance->Signature =3D FVB_INSTANCE_SIGNATURE; CopyMem (&(= FvbInstance->FvHeader), FvHeader, FvHeader->HeaderLength); - FvHeader = =3D &(FvbInstance->FvHeader);+ FvHeader =3D &(FvbInstance->= FvHeader); FvbInstance->FvBase =3D (UINTN)BaseAddress; // = // Process the block map for each FV //- FvbInstance->NumOfBlo= cks =3D 0;+ FvbInstance->NumOfBlocks =3D 0; for (PtrBlockMapEn= try =3D FvHeader->BlockMap; PtrBlockMapEntry->NumBlocks !=3D 0;-= PtrBlockMapEntry++) {+ PtrBlockMapEntry++)+ { = // // Get the maximum size of a block. // if (= MaxLbaSize < PtrBlockMapEntry->Length) {- MaxLbaSize =3D PtrBlock= MapEntry->Length;+ MaxLbaSize =3D PtrBlockMapEntry->Length; = }+ FvbInstance->NumOfBlocks +=3D PtrBlockMapEntry->NumBlocks; = } @@ -297,10 +368,9 @@ FvbInitialize ( // // Move on to the next FvbInstance //- FvbInstan= ce =3D (EFI_FVB_INSTANCE *) ((UINTN)((UINT8 *)FvbInstance) +- = FvHeader->HeaderLength +- = (sizeof (EFI_FVB_INSTANCE) - sizeof (EFI_FIRMWARE_V= OLUME_HEADER)));-+ FvbInstance =3D (EFI_FVB_INSTANCE *)((UINTN)((UINT8= *)FvbInstance) ++ FvHeader->Header= Length ++ (sizeof (EFI_FVB_INSTANCE= ) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))); } } }diff --git a/Silicon/= Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceSmm.inf b/Si= licon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServiceSmm.in= f index 0cfa3f909b..0485b73679 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbServi= ceSmm.inf +++ b/Silicon/Intel/IntelSiliconPkg/Feature/Flash/SpiFvbService/SpiFvbSe +++ rviceSmm.inf @@ -45,6 +45,8 @@ [Pcd] gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvBase ## = CONSUMES gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvSize #= # CONSUMES+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize = ## SOMETIMES_CONSUMES+ gIntelSiliconPkgTokenSpaceGuid.PcdFlashVariableSto= reType ## SOMETIMES_CONSUMES [Sources] FvbInfo.c@@ -61,6 +63,8 @@ [Guids] gEfiFirmwareFileSystem2Guid ## CONSUMES gEfi= SystemNvDataFvGuid ## CONSUMES+ gEfiVariableGuid = ## SOMETIMES_CONSUMES+ gEfiAuthenticatedVariabl= eGuid ## SOMETIMES_CONSUMES [Depex] TRUEdiff --git a/Sil= icon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/Intel/IntelSilicon= Pkg/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.P= cdVTdSupportAbortDmaMode|FALSE|BOOLEAN|0x0000000C + ## Define Flash Variab= le Store type.

+ # When Flash Variable Store corruption happened, = the SpiFvbService will recreate Variable Store+ # with valid header infor= mation provided by this PCD value.
+ # 0: Variable Store is gEfiVariab= leGuid type.
+ # 1: Variable Store is gEfiAuthenticatedVariableGuid ty= pe.
+ # Other value: reserved for future use.
+ # @Prompt Flash Va= riable Store type.+ gIntelSiliconPkgTokenSpaceGuid.PcdFlashVariableStoreTy= pe|0x00|UINT8|0x0000000E--=20 2.35.0.windows.1