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.2596.1649302321459836458 for ; Wed, 06 Apr 2022 20:32:02 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CooeLWr5; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: hao.a.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649302321; x=1680838321; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Z6zzSuu8nj/wUkoSIWTDf1/J/4jky5S3gmWnfRFTb9E=; b=CooeLWr5VmkFXvNTAxtjwuExmmwg3XCWRJyapn77AP9VSI0RrbTcIbZL EEeezp2blj4MnfFy8fOQtbp8+sI/G4yKQh6XvUdtj2QaSErGgWtjemrEU lqBs3uoncdLwfQ+9IhgfNtxL8NiEqnA7hiZntTtsNAJvIaWD8OowqyXyE 29X7LiidGo6CtzPXqrVbvHpUnBHfDhFXXEkWx42rZXQujm3tTHq5hf1UJ wAmeTPlNVD3dTgo0dsVsab/ofyh8uiLLGeXQ1UlE9/3btlokaC0gcCcaU j0aotp3DZKtspXSKNz8vip/x2DiqsXAw+5nH3k7Z7plJq9NhVqba+XaEd w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="324382460" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="324382460" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2022 20:32:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="791917547" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by fmsmga006.fm.intel.com with ESMTP; 06 Apr 2022 20:32:00 -0700 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 6 Apr 2022 20:31:59 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Wed, 6 Apr 2022 20:31:59 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Wed, 6 Apr 2022 20:31:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AXv67lACGkGRe1sh8REiu+rULVaBDoRsCTWbwjUFvyQghfp9BWBh4cIh3OoykJTOTfmZPbzyhAkvCH3PfIZaTVsNoFeUb+FDGU5Fo3Ue2bo0vUI8vl2wM+7Lmapt2wxeafviKmpElxsSGOldUwBS0CeAtzWDl0tdJt3c/mDq9MPHXib++wutfqseRTCWTtzl3Cwu3QQfOUYpIWEyensqM18ElUejvKK+l2N2ALf55zdr73FxZu9tKN41s3Pjn1kwvtH4wMeNfP14D9B4cUX0re34CJmPa50jbmo/2VWyCyZL4tY36dEEYm4hqjeB8SfsjsB/cDAc6G+g9l4fmjAymA== 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=eZnCIUDQcK1zEWKYTg/39vby35iBr7qXrjvvRVhLwXc=; b=h2KpQOtubV0uEfUWzUWgWww9kUT42S7tPHUV/az58V8ILaCdSEYJmGXz2TatffpGC9KSJ/3PPAXs0EkSPOE0wBD2rD2cX5ps5r19EMaY6YBPSGHyaDrxqBCPDnWYouD0Kil8sa8+EaB2odwQkJgfnQKbCQDEgrDOAtA2SFYXvTjzgxnF/4p3j6mHdolqxBU9C63hm5vdjQe387diynxgLKNFYw9fS2GDDcd1EEGiluZ8ZIsKrfTjpbwDH/X069FzqA7eVrR7EwLfo4PvTyz5dJ7pdQOaFw0N8ZsrQOgOghAtaJpCID1b3XAkiGjJu1vvFtAvAuosVQQEvpY9miI9sQ== 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 DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by SN6PR11MB3471.namprd11.prod.outlook.com (2603:10b6:805:c1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 03:31:56 +0000 Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::7852:37e2:513c:470b]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::7852:37e2:513c:470b%7]) with mapi id 15.20.5123.031; Thu, 7 Apr 2022 03:31:56 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "mikuback@linux.microsoft.com" CC: "Wang, Jian J" , "Gao, Liming" Subject: Re: [edk2-devel] [PATCH v1 3/3] MdeModulePkg/FaultTolerantWrite: Consume Variable Info HOB Thread-Topic: [edk2-devel] [PATCH v1 3/3] MdeModulePkg/FaultTolerantWrite: Consume Variable Info HOB Thread-Index: AQHYSdM7XLv8gTQXy0iPBhK5dZSByazjwivw Date: Thu, 7 Apr 2022 03:31:56 +0000 Message-ID: References: <20220406162648.234-1-mikuback@linux.microsoft.com> <20220406162648.234-4-mikuback@linux.microsoft.com> In-Reply-To: <20220406162648.234-4-mikuback@linux.microsoft.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 83b4fad8-aad0-49c2-56e5-08da18472add x-ms-traffictypediagnostic: SN6PR11MB3471:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EH7j0l1y+RC1Hb+TL5+hlAIgd/xFcwQnyZ0zYdLKaxOZ2yDf5eGrl70OqWJ9c8Qn28upzL+kb9XkmhessAGeTcF7KzknIJAfiChMrf1TDIq0SHCWY4rhrcngA2WD49+OnrP6K5UHp4yluQGuiclrVo4bUDBGLNEprDmVhs0ue5yseq/ogJqWB7lfyn2cVrIODfnoAt1pxCb51HES3uSXO18/kEcWX6QnzvmIkn1eLvdhmcO9BcEG1nHciYCsGWySZV6Ps32bJu1XFbjQq+e9DcgzFE+8FSSbQHGGKuTabYYxVsNBigDb80mP0c+jQvBb7vMwCL5QtifJR/URnj+FlfdYNch3bC7xiBvCsfHYXuxpixTJ8BwnR6vSxoMkF5J63scn7N8X28w+EG2s0i4ARD2E5QfOz3XdGhSD/Thrw7vk8V0TT3jiyx0tqBanax7aZgLMpw+67H3SL+MWm4nKxXNxKhf63BMSOVAewlRpJCG0HAmHGZVB8I6qDrkld5XKLf1qAX64rwDhDEASeD4lZrO4CiYzBHK82500MQXZVB/pB4ue3Qb0eVjhjZjdDAwWfoRCP13WXtv6kBNV7OsoX8XNuDjTzyI5O3CbpKCt/uBNy47ghKvm/2+dk5yTx9opX/g8QiXOJPHiQDmU9Hmi3XifNz/aPUWhRYI68XC7+uhxz7QE7ojojba2Q4cYUA4sj1GbJOoyyThMzt9DIwbF86LJs3O04KUkzsgD1XrrnrlLVvfS7RAaFHl5m9tzEdPviLs+Yga5SteE0ND5C9PKmvIU7g6Yn5/wOFv+S4sbmKq+ga7XUrdX+ivVkgbDfFHBfOpBxqANm/FnLhhtQczdgg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4025.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(9686003)(7696005)(6506007)(26005)(54906003)(86362001)(316002)(5660300002)(186003)(2906002)(55016003)(53546011)(71200400001)(83380400001)(110136005)(508600001)(966005)(8936002)(30864003)(52536014)(33656002)(38100700002)(38070700005)(66556008)(4326008)(8676002)(66446008)(122000001)(64756008)(66476007)(66946007)(82960400001)(76116006)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?9AGIAsX4vVArgpcSrB7lYJ7Z2Z1xl+SdgHqmeU/lyX6hTBgEjprryvyMM3Wr?= =?us-ascii?Q?8Cr0EO/plau0ZItsYNDib9Twz6rumUk95Uj2DNNHCnVz61KYa023r1lAkAJ7?= =?us-ascii?Q?T2iEgZciDlKRI7aDYUvPkAWbyE2HBHkB/YVr2i5nTtEqxwBA+7g7UWEtpa3l?= =?us-ascii?Q?tPbFnuzrovUjWEPpDGrWA1RIDmwrYz4jqPHBXVLJZfZjUhMGJPeqOzXC2yS6?= =?us-ascii?Q?om7KONWVT8L0zTknC51BH4kL+wHkmnuG0A3qJXhh+wmLbkkp2Sdvp14AgYv2?= =?us-ascii?Q?lo0OI5DxXyv3/HTpRnerqJREN6SrY3qHnK4/ejuSlOW+G7vGVMv3KjBbt+bR?= =?us-ascii?Q?6BoPYBRT5k7fr5faq2Sq5fg+hy1SsxZ/5IQcT77lXpo+MHNFpeedh3ZsRb/E?= =?us-ascii?Q?X/b9KFZvibCezPIUQ1Lfnf7/2Q61NHmlhZ6/jMA/8BljmW+UbarwlX+zGkUj?= =?us-ascii?Q?anNNVq40DLno+J0HMELJ+OrIzgFN5eIpDgv88dnWvEmpozBQMGiMo5x4WvzU?= =?us-ascii?Q?SLcXcgSW1PLdGIR5kCrOC5XNjGLr10rm3N5WvA7bgxwU5l7vZBuiiyuwbLD9?= =?us-ascii?Q?pCS+lUSVDovxoY7y3F1tUZ+5RZ80SrKtThCCVit8k+FU6kEsASZFAmHibCcA?= =?us-ascii?Q?ipCqdfrp2581upoQAKzQ7RbkF7jiLsRehlTwvh5/hkUa3wBlSkP86Flk+/Z3?= =?us-ascii?Q?vqwFlkMxOf89akPGSpJ8IWptzGLr1/JrRPy2dpI85QC0iRIpgc1Xt/7aRFWL?= =?us-ascii?Q?Mya0TUgxH+9UzJW3CoPEfrvny5cIo1rIQ2gA906hwZwCFMcH7TYfODJt/Xcu?= =?us-ascii?Q?WOnLEDKRH7uIIYpz3QjirGWbuzezHxPUyIEDX4D3YE13/EgjvBkKIBR6bsLE?= =?us-ascii?Q?IMIZWqLl2RNkVjjhaO6HoUzClNXgRBfRpIJOENlXFIW6kGDDorkNzH/ymX1T?= =?us-ascii?Q?CgLj1FOHlcJ5l3u7Cse4j5FtF40JjB9gADcmoV7dUSqJY5G3uD4NXTiyVsjr?= =?us-ascii?Q?aj0SP6i27Duc3P2N1HNcP6VDyFotaN0y+AFAajF1TLiLYGhQIEIKBqZ7DKuN?= =?us-ascii?Q?lRjhdlqoS7P6F1Ppq+pxBwG4jlwiFLcjrIw7xm+PhCULtvNXZreWlVZ4A+1y?= =?us-ascii?Q?oAC1yTfAdUvBSuagg9nrEr362h7rxKibwuCbsg1pOqEUbkxJdWD0KOuH/lf0?= =?us-ascii?Q?GGStREL24beqTjjIM8lsMcBgIORkDHhwHGUf68ccLzLtdjLCoG/gOvAPhrq8?= =?us-ascii?Q?7TO1HCO/Jo1z3+8oDZcMB1hLK/AAFi3TuhUlAqfdNYZd5cl8L5xqcgGRHRZn?= =?us-ascii?Q?06o37Yvs3wAKCDtXSiJ2CuwZMg9IqdhH+4/3WnqyzYWpdpmU+Pt+zZU1Q1vw?= =?us-ascii?Q?luyXYjHKLT5nAjNJitXqwuukiFm/Auu1QUznSvJuyT7rYDvMhdO3P2SIOBW7?= =?us-ascii?Q?KteuEIkk7MEGxVH/zXYU6gf5JsRbUb1uMIzCzU6DjTV6G23ejkMkwKM5DOAV?= =?us-ascii?Q?YsotGBrfg1UhKt7e/Np5IgWHXjWYUyz4/q0B7NX4z89ju/tOtSmd4dsn8YL2?= =?us-ascii?Q?NFdZkrrNiKPM3yBRgQE+MM0bSuflxRac2CqxW83rOe+XXw9AWAuCqDr0tp53?= =?us-ascii?Q?roFOJMr9muRFKoGh9pN+jaiUz8xlmXfheqxpRo1O9XH3UiJXng3lNupZtHXZ?= =?us-ascii?Q?P/v/ET2oeS8raxFvrHymLUd30ENHoLEolCPyJOeY3Rxb0x/rY79lHqi98qAI?= =?us-ascii?Q?fD8ShOPkLQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83b4fad8-aad0-49c2-56e5-08da18472add X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Apr 2022 03:31:56.6614 (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: AxbxuanYUI3T+kxaa82k0uVjBpu5eqNqlaTSYkZiAst44XzZ4+2vuX3AsDyHspx8XUAdm2eWsZGbwZ2YNixPvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3471 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Two minor inline comments: > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael > Kubacki > Sent: Thursday, April 7, 2022 12:27 AM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A ; > Gao, Liming > Subject: [edk2-devel] [PATCH v1 3/3] MdeModulePkg/FaultTolerantWrite: > Consume Variable Info HOB >=20 > From: Michael Kubacki >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479 >=20 > Adds support to the UEFI variable fault tolerant write (FTW) drivers > to receive FTW base and size information dynamically via the Variable > Flash Information HOB. >=20 > This supplements support added earlier for the variable store base > address and size passed with the Variable Flash Information HOB. >=20 > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Liming Gao > Signed-off-by: Michael Kubacki > --- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c = | > 111 +++++++++++++++++--- > MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > | 7 +- > MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c > | 92 ++++++++++++++-- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > | 9 +- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > | 11 +- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > | 11 +- >=20 > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon > eMm.inf | 11 +- > MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf > | 10 +- > 8 files changed, 221 insertions(+), 41 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c > index 661e1487673b..5066fe0d3711 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c > @@ -972,6 +972,48 @@ GetPreviousRecordOfWrites ( > return EFI_SUCCESS; > } >=20 > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the var= iable > flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found s= uccessfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is > NULL. > + @retval EFI_NOT_FOUND Variable flash information could not b= e found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfo ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ) > +{ > + EFI_HOB_GUID_TYPE *GuidHob; > + > + if (VariableFlashInfo =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid); > + if (GuidHob =3D=3D NULL) { > + return EFI_NOT_FOUND; > + } > + > + *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob); > + > + // > + // Assert if more than one variable flash information HOB is present. > + // > + DEBUG_CODE ( > + if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB > (GuidHob)) !=3D NULL)) { > + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information > HOBs\n")); > + ASSERT (FALSE); > + } > + > + ); > + > + return EFI_SUCCESS; > +} > + > /** > Allocate private data for FTW driver and initialize it. >=20 > @@ -987,22 +1029,71 @@ InitFtwDevice ( > OUT EFI_FTW_DEVICE **FtwData > ) > { > - EFI_FTW_DEVICE *FtwDevice; > + EFI_STATUS Status; > + EFI_STATUS VariableFlashInfoStatus; > + UINTN FtwWorkingSize; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > + EFI_FTW_DEVICE *FtwDevice; > + > + FtwWorkingSize =3D 0; > + VariableFlashInfoStatus =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (VariableFlashInfoStatus)) { > + Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwWorkingLength, > &FtwWorkingSize); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + FtwWorkingSize =3D 0; > + } > + } > + > + if (FtwWorkingSize =3D=3D 0) { > + FtwWorkingSize =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize)= ; > + } >=20 > // > // Allocate private data of this driver, > // Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE]. > // > - FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 > (PcdFlashNvStorageFtwWorkingSize)); > + FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + FtwWorkingSi= ze); > if (FtwDevice =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } >=20 > + FtwDevice->WorkSpaceLength =3D FtwWorkingSize; > + > + if (!EFI_ERROR (VariableFlashInfoStatus)) { > + // This driver currently assumes the size will be UINT32 so only acc= ept "the size will be UINT32", UINTN to be more precise. > + // that for now. > + Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwSpareLength, > &FtwDevice->SpareAreaLength); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + FtwDevice->SpareAreaLength =3D 0; > + } > + > + FtwDevice->SpareAreaAddress =3D VariableFlashInfo->FtwSpareBaseAddre= ss; > + FtwDevice->WorkSpaceAddress =3D VariableFlashInfo- > >FtwWorkingBaseAddress; > + } > + > + if (FtwDevice->SpareAreaLength =3D=3D 0) { > + FtwDevice->SpareAreaLength =3D (UINTN)PcdGet32 > (PcdFlashNvStorageFtwSpareSize); > + } > + > + if (FtwDevice->SpareAreaAddress =3D=3D 0) { > + FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwSpareBase64); > + if (FtwDevice->SpareAreaAddress =3D=3D 0) { > + FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwSpareBase); > + } > + } > + > + if (FtwDevice->WorkSpaceAddress =3D=3D 0) { > + FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwWorkingBase64); > + if (FtwDevice->WorkSpaceAddress =3D=3D 0) { > + FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwWorkingBase); > + } > + } > + > // > // Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE. > // > - FtwDevice->WorkSpaceLength =3D (UINTN)PcdGet32 > (PcdFlashNvStorageFtwWorkingSize); > - FtwDevice->SpareAreaLength =3D (UINTN)PcdGet32 > (PcdFlashNvStorageFtwSpareSize); > if ((FtwDevice->WorkSpaceLength =3D=3D 0) || (FtwDevice->SpareAreaLeng= th =3D=3D 0)) > { > DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\= n")); > FreePool (FtwDevice); > @@ -1015,16 +1106,6 @@ InitFtwDevice ( > FtwDevice->FtwWorkSpaceLba =3D (EFI_LBA)(-1); > FtwDevice->FtwSpareLba =3D (EFI_LBA)(-1); >=20 > - FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwWorkingBase64); > - if (FtwDevice->WorkSpaceAddress =3D=3D 0) { > - FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwWorkingBase); > - } > - > - FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwSpareBase64); > - if (FtwDevice->SpareAreaAddress =3D=3D 0) { > - FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwSpareBase); > - } > - > *FtwData =3D FtwDevice; > return EFI_SUCCESS; > } > @@ -1277,7 +1358,7 @@ InitFtwProtocol ( > FtwDevice->FtwLastWriteHeader =3D NULL; > FtwDevice->FtwLastWriteRecord =3D NULL; >=20 > - InitializeLocalWorkSpaceHeader (); > + InitializeLocalWorkSpaceHeader (FtwDevice->WorkSpaceLength); >=20 > // > // Refresh the working space data from working block > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > index 61e7a92ccea1..fd563643eb63 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > @@ -16,10 +16,13 @@ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER > mWorkingBlockHeader =3D { ZERO_GUID, 0, 0 >=20 > Since Signature and WriteQueueSize have been known, Crc can be calcula= ted > out, > then the work space header will be fixed. > + > + @param[in] WorkSpaceLength Length in bytes of the FTW workspace a= rea. > + > **/ > VOID > InitializeLocalWorkSpaceHeader ( > - VOID > + IN UINTN WorkSpaceLength > ) > { > // > @@ -46,7 +49,7 @@ InitializeLocalWorkSpaceHeader ( > &gEdkiiWorkingBlockSignatureGuid, > sizeof (EFI_GUID) > ); > - mWorkingBlockHeader.WriteQueueSize =3D PcdGet32 > (PcdFlashNvStorageFtwWorkingSize) - sizeof > (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER); > + mWorkingBlockHeader.WriteQueueSize =3D WorkSpaceLength - sizeof > (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER); >=20 > // > // Crc is calculated with all the fields except Crc and STATE, so leav= e them as > FTW_ERASED_BYTE. > diff --git > a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c > b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c > index 15543f12ed29..7abf8f72d569 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.= c > +++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.= c > @@ -11,11 +11,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > #include > #include > +#include > #include > #include > #include > #include > #include > +#include >=20 > EFI_PEI_PPI_DESCRIPTOR mPpiListVariable =3D { > (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), > @@ -186,6 +188,48 @@ IsValidWorkSpace ( > return TRUE; > } >=20 > +/** > + Get the HOB that contains variable flash information. > + > + @param[out] VariableFlashInfo Pointer to a pointer to set to the var= iable > flash information structure. > + > + @retval EFI_SUCCESS Variable flash information was found s= uccessfully. > + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is > NULL. > + @retval EFI_NOT_FOUND Variable flash information could not b= e found. > + > +**/ > +EFI_STATUS > +GetVariableFlashInfo ( > + OUT VARIABLE_FLASH_INFO **VariableFlashInfo > + ) > +{ > + EFI_HOB_GUID_TYPE *GuidHob; > + > + if (VariableFlashInfo =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid); > + if (GuidHob =3D=3D NULL) { > + return EFI_NOT_FOUND; > + } > + > + *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob); > + > + // > + // Assert if more than one variable flash information HOB is present. > + // > + DEBUG_CODE ( > + if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB > (GuidHob)) !=3D NULL)) { > + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information > HOBs\n")); > + ASSERT (FALSE); > + } > + > + ); > + > + return EFI_SUCCESS; > +} > + > /** > Main entry for Fault Tolerant Write PEIM. >=20 > @@ -207,6 +251,7 @@ PeimFaultTolerantWriteInitialize ( > EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkingBlockHeader; > EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader; > EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord; > + VARIABLE_FLASH_INFO *VariableFlashInfo; > EFI_PHYSICAL_ADDRESS WorkSpaceAddress; > UINTN WorkSpaceLength; > EFI_PHYSICAL_ADDRESS SpareAreaAddress; > @@ -218,19 +263,52 @@ PeimFaultTolerantWriteInitialize ( > FtwLastWriteHeader =3D NULL; > FtwLastWriteRecord =3D NULL; >=20 > - WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwWorkingBase64); > - if (WorkSpaceAddress =3D=3D 0) { > - WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwWorkingBase); > + SpareAreaAddress =3D 0; > + SpareAreaLength =3D 0; > + WorkSpaceAddress =3D 0; > + WorkSpaceLength =3D 0; > + > + Status =3D GetVariableFlashInfo (&VariableFlashInfo); > + if (!EFI_ERROR (Status)) { > + // This driver currently assumes the size will be UINT32 so only acc= ept "the size will be UINT32", UINTN to be more precise. Best Regards, Hao Wu > + // that for now. > + Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwSpareLength, > &SpareAreaLength); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + SpareAreaLength =3D 0; > + } > + > + Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwWorkingLength, > &WorkSpaceLength); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + WorkSpaceLength =3D 0; > + } > + > + SpareAreaAddress =3D VariableFlashInfo->FtwSpareBaseAddress; > + WorkSpaceAddress =3D VariableFlashInfo->FtwWorkingBaseAddress; > } >=20 > - WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize); > + if (SpareAreaLength =3D=3D 0) { > + SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize); > + } > + > + if (WorkSpaceLength =3D=3D 0) { > + WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize= ); > + } >=20 > - SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwSpareBase64); > if (SpareAreaAddress =3D=3D 0) { > - SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwSpareBase); > + SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwSpareBase64); > + if (SpareAreaAddress =3D=3D 0) { > + SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwSpareBase); > + } > } >=20 > - SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize); > + if (WorkSpaceAddress =3D=3D 0) { > + WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdFlashNvStorageFtwWorkingBase64); > + if (WorkSpaceAddress =3D=3D 0) { > + WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 > (PcdFlashNvStorageFtwWorkingBase); > + } > + } >=20 > // > // The address of FTW working base and spare base must not be 0. > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > index c14e47b5c7b2..40ef44c069eb 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > @@ -14,11 +14,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include >=20 > #include > +#include > #include > #include > #include > #include >=20 > +#include > +#include > #include > #include > #include > @@ -706,12 +709,16 @@ InitFtwProtocol ( > /** > Initialize a local work space header. >=20 > + > Since Signature and WriteQueueSize have been known, Crc can be calcula= ted > out, > then the work space header will be fixed. > + > + @param[in] WorkSpaceLength Length in bytes of the FTW workspace a= rea. > + > **/ > VOID > InitializeLocalWorkSpaceHeader ( > - VOID > + IN UINTN WorkSpaceLength > ); >=20 > /** > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > index 96165614d178..923f0231a047 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > @@ -46,6 +46,8 @@ [LibraryClasses] > UefiLib > PcdLib > ReportStatusCodeLib > + HobLib > + SafeIntLib >=20 > [Guids] > # > @@ -54,6 +56,7 @@ [Guids] > ## CONSUMES ## GUID > ## PRODUCES ## GUID > gEdkiiWorkingBlockSignatureGuid > + gVariableFlashInfoHobGuid ## CONSUMES ## HOB >=20 > [Protocols] > gEfiSwapAddressRangeProtocolGuid | > gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## > SOMETIMES_CONSUMES > @@ -67,11 +70,11 @@ [FeaturePcd] >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > SOMETIMES_CONSUMES >=20 > # > # gBS->CalculateCrc32() is consumed in EntryPoint. > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > index 8cc6028470d8..bbed17e4b611 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > @@ -52,6 +52,8 @@ [LibraryClasses] > ReportStatusCodeLib > SmmMemLib > BaseLib > + HobLib > + SafeIntLib >=20 > [Guids] > # > @@ -60,6 +62,7 @@ [Guids] > ## CONSUMES ## GUID > ## PRODUCES ## GUID > gEdkiiWorkingBlockSignatureGuid > + gVariableFlashInfoHobGuid ## CONSUMES ## HOB >=20 > [Protocols] > gEfiSmmSwapAddressRangeProtocolGuid | > gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## > SOMETIMES_CONSUMES > @@ -76,11 +79,11 @@ [FeaturePcd] >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > SOMETIMES_CONSUMES >=20 > # > # gBS->CalculateCrc32() is consumed in EntryPoint. > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandal > oneMm.inf > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandal > oneMm.inf > index d0fab7d9414f..0b394b04da7b 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandal > oneMm.inf > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandal > oneMm.inf > @@ -46,10 +46,12 @@ [LibraryClasses] > BaseLib > BaseMemoryLib > DebugLib > + HobLib > MemoryAllocationLib > MmServicesTableLib > PcdLib > ReportStatusCodeLib > + SafeIntLib > StandaloneMmDriverEntryPoint >=20 > [Guids] > @@ -59,6 +61,7 @@ [Guids] > ## CONSUMES ## GUID > ## PRODUCES ## GUID > gEdkiiWorkingBlockSignatureGuid > + gVariableFlashInfoHobGuid ## CONSUMES ## HOB >=20 > [Protocols] > gEfiSmmSwapAddressRangeProtocolGuid | > gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## > SOMETIMES_CONSUMES > @@ -75,11 +78,11 @@ [FeaturePcd] >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > SOMETIMES_CONSUMES >=20 > [Depex] > TRUE > diff --git > a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf > b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf > index f90892ad4493..ff9d53bf7040 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.= inf > +++ > b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf > @@ -39,6 +39,7 @@ [LibraryClasses] > HobLib > BaseMemoryLib > PcdLib > + SafeIntLib >=20 > [Guids] > ## SOMETIMES_PRODUCES ## HOB > @@ -46,14 +47,15 @@ [Guids] > gEdkiiFaultTolerantWriteGuid > gEdkiiWorkingBlockSignatureGuid ## SOMETIMES_CONSUMES = ## > GUID > gEfiSystemNvDataFvGuid ## SOMETIMES_CONSUMES = ## GUID > + gVariableFlashInfoHobGuid ## CONSUMES = ## HOB >=20 > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 > ## SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## > SOMETIMES_CONSUMES > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## > SOMETIMES_CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > CONSUMES > - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## > SOMETIMES_CONSUMES >=20 > [Depex] > TRUE > -- > 2.28.0.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#88464): https://edk2.groups.io/g/devel/message/88464 > Mute This Topic: https://groups.io/mt/90293667/1768737 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a.wu@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20