From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.4029.1596676235559971203 for ; Wed, 05 Aug 2020 18:10:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=TSQaYLpt; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: chasel.chiu@intel.com) IronPort-SDR: 5XjxP7n5b7JUv9s1nva24i3DOGX7bevlRiD832pB4KJ4oObayerQ/Vo3fIYA3yCw7Pp3TRkjB9 VfkiFnGAlY0g== X-IronPort-AV: E=McAfee;i="6000,8403,9704"; a="214211342" X-IronPort-AV: E=Sophos;i="5.75,440,1589266800"; d="scan'208";a="214211342" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2020 18:10:33 -0700 IronPort-SDR: quZQWMzPoqgA8RGbaR4BTc/2zDGhaCvofBcZsXhxKLYjv0TcRZxOeCy+Sf+Ga3DdBHBGpGITDt f+9KXTYHVUSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,440,1589266800"; d="scan'208";a="323274493" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga008.jf.intel.com with ESMTP; 05 Aug 2020 18:10:33 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 5 Aug 2020 18:10:30 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 5 Aug 2020 18:10:30 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 5 Aug 2020 18:10:29 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.102) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 5 Aug 2020 18:09:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jmdINuyMtRfnbcJ4vXYVLY0R506SCqUEur0B13GU2DIaBviEWox9MzM6ODmsjW59Gf7799RBa7mLd9eg4dARh4FAmZt5yEv+uoqUbCkIgRnPDm+ORjyBxqkIPE9oo7qFf8zECLurvWuKLoQjBpR03l9f2RTI4M4bJz+spVTJtvnU1sPveouLU2Uh3mEOiKRtrlUHseITf+OQ4cawkFs65/PSjRI6nYxtF5f22o6ExCvgLqQelRVEX32TXslVW2UPfJdsujdcRndbdOUzljLDhrY/7bgsxFPdtxw7ANk3lmpLNePW9Pxk0spvB0Fmew8fq1PTHcyN6OnXjedLB8DdnA== 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-SenderADCheck; bh=VoppkIe7KIM7ri48OxZsFJuWtnagH+xJj4DIf1GKGvQ=; b=Yt7PfdH575bTnpsIsi3uiSL4SnCGxzuTplbU3gPolNvWyHtHGawaOD/X2arvLwBel1aZw9U+0aJC9fe+1hTjkTZQk8GzFf7SL4NGOlpt93M90T1FXVVOd4AGtFgSujUTTCre5YB7z4II4LPuTfhvg1xk0I2Gbb+2WMQe5pdJg/THUiJsAuFKDLloXLc3O5lLH2LxubGgAVFQYaydM82oiAgXxsfndgb7dmlwu/umPSxpvYqRHN7RPKWtqcOTQLx5TK3pNQ+sibcyUAeAMvrij6emLkOHlQMNJUCVD39E0sEgmLsDY5Y94pCF0bgLqAJzMQmdH3hH42w+C1LgMn6SnA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VoppkIe7KIM7ri48OxZsFJuWtnagH+xJj4DIf1GKGvQ=; b=TSQaYLptJUemQwSFYKWjCPLE0EaB85cXYPFD4Jgay0upKvfsfpJarBS8KQzaLYJ8MyG05ATkuiIcTjMAM9Z4DUVJQoESSysOxs40sKBaAa9vAINOvF22GVc9OYaSbkfucuxj7T7XvTOdvrigWH4gFMt5jgduCfCIKUcmGhRleOA= Received: from SN6PR11MB2814.namprd11.prod.outlook.com (2603:10b6:805:55::15) by SN6PR11MB3262.namprd11.prod.outlook.com (2603:10b6:805:bf::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15; Thu, 6 Aug 2020 01:09:54 +0000 Received: from SN6PR11MB2814.namprd11.prod.outlook.com ([fe80::4843:7aba:799b:326]) by SN6PR11MB2814.namprd11.prod.outlook.com ([fe80::4843:7aba:799b:326%5]) with mapi id 15.20.3261.015; Thu, 6 Aug 2020 01:09:53 +0000 From: "Chiu, Chasel" To: "Zhang, Qi1" , "devel@edk2.groups.io" CC: "Yao, Jiewen" , "Desimone, Nathaniel L" , "Zeng, Star" Subject: Re: [PATCH v2 6/9] IntelFsp2WrapperPkg/FspMeasurementLib: Add BaseFspMeasurementLib. Thread-Topic: [PATCH v2 6/9] IntelFsp2WrapperPkg/FspMeasurementLib: Add BaseFspMeasurementLib. Thread-Index: AQHWa4lQSz/RpRBgy0mhhIfv4YAicakqRE/g Date: Thu, 6 Aug 2020 01:09:53 +0000 Message-ID: References: <20200806003342.17866-1-qi1.zhang@intel.com> <20200806003342.17866-7-qi1.zhang@intel.com> In-Reply-To: <20200806003342.17866-7-qi1.zhang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [61.60.205.141] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b28a1316-b18f-4716-4b03-08d839a56d5a x-ms-traffictypediagnostic: SN6PR11MB3262: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4125; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jokBFyABKsuh/mrVqEBklxZ1yzXfKchjWRHUGTCUkaQ3Ruj+4pNzWNvI5cIwrOxwlhVYlveVEiz1bYfWwH8u0/c7ocAHVykU/ougFbuQlsznZfFDlLMN3fH+P09ottBKdlRXWKxOtm4FUS2iaWu72UrlmugY/UhSVrkTbYZRSP9h4Ov9LNHR5qhCoKfoxzAUI6kN8LzGct1qPo3d701Y5JTQ94GYia0+Hkhq37aYlR1oNem/0C6qFiUyDrv57zcVn34wx3ignXx9qKOqouvvfrw0TXSRX1j2QbdANwtU79mMLDLnrR/JfYKPog01NXINJd6t2X5Iy7qaifltfIeQRKGRFsf352PW5vDmrndVcJxWHpQGik5y3i+SPUDFEbdSAnhZqr2a+eS2p7RNLYtoCw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB2814.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(39860400002)(366004)(376002)(396003)(346002)(966005)(316002)(54906003)(30864003)(55016002)(5660300002)(9686003)(110136005)(2906002)(478600001)(52536014)(4326008)(19627235002)(7696005)(26005)(107886003)(83380400001)(86362001)(6506007)(53546011)(66446008)(33656002)(8936002)(66946007)(186003)(66476007)(66556008)(76116006)(8676002)(71200400001)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: aEQEq/ZpQOctGwNI+dcPlYwN0YyBzX5SuyoYIYec77qUC8NLu9TtheNMwbW4cDlIxeYeIYagVHzs227P3GPxOt2OpEEgrQ9WxujjkHZjjyspI1R8xYxRKjbeEBHFKVNOxo/SrUB9uDoteQy7KJ4/PVGOq1F/HtwGl4FfoJlIDj694Xc5WFJDxQtQyvauuC8v/BO6cP9Vglio+mwHenrLD1SNl0c8WKooglpe3ntaEUMaC/amKrdOPkhBEZfx7IuEkgdbAP32tXD+M4tGhdHI3+Cj5/jzQGULUqUMw0240I2gCX1CRaPub/dTDSLgQR0YZl8Tcu3vp7XGT2OhIHn06+wvLH/4PxbHEJcnzNr7mi4pvHNjRuF4wHOYKTBjponhSwrBbknYjgt85TRR4zscP56WeARdhC9xbYopdHLmqagc6jNoEtFRJJHO5ynxI9l+IDeyK/KkckkFrRGWrqcUeGnjo4cnM57oiS0J+VN8abjSp7r3IQXfcO4RAW/ud3Hn3ruURb9JbT+0V5lySPCXp9o2Heoub72Hl5apzQVXxHHe4sNCAS1zY9GLXsBBWHLwSSxBKYChq5W1VEchVBs0mYMCWfB+k+6NiPUUlqogEJ19dpMHFfzzOuzl410FLTCBYt6MMnQHZc4I6wmhzyWmJA== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2814.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b28a1316-b18f-4716-4b03-08d839a56d5a X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2020 01:09:53.7877 (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: w2w97E5JOdChBcR/oceTPgquNLelD4nxcYrl84OZxxsX4+ratSoFpy+87tVxcAiEyrMtTn3QvBBXF/OJMxEx+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3262 Return-Path: chasel.chiu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Qi, Please see my comments below inline. Thanks, Chasel > -----Original Message----- > From: Zhang, Qi1 > Sent: Thursday, August 6, 2020 8:34 AM > To: devel@edk2.groups.io > Cc: Yao, Jiewen ; Chiu, Chasel > ; Desimone, Nathaniel L > ; Zeng, Star ; Zhang= , > Qi1 > Subject: [PATCH v2 6/9] IntelFsp2WrapperPkg/FspMeasurementLib: Add > BaseFspMeasurementLib. >=20 > From: Jiewen Yao >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2376 >=20 > Cc: Jiewen Yao > Cc: Chasel Chiu > Cc: Nate DeSimone > Cc: Star Zeng > Cc: Qi Zhang > Signed-off-by: Jiewen Yao > --- > .../BaseFspMeasurementLib.inf | 54 +++ > .../BaseFspMeasurementLib/FspMeasurementLib.c | 349 > ++++++++++++++++++ > 2 files changed, 403 insertions(+) > create mode 100644 > IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/BaseFspMeasuremen > tLib.inf > create mode 100644 > IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/FspMeasurementLib. > c >=20 > diff --git > a/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/BaseFspMeasurem > entLib.inf > b/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/BaseFspMeasurem > entLib.inf > new file mode 100644 > index 0000000000..d30168117d > --- /dev/null > +++ > b/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/BaseFspMeasurem > entLib.inf > @@ -0,0 +1,54 @@ > +## @file >=20 > +# Provides FSP measurement functions. >=20 > +# >=20 > +# This library provides MeasureFspFirmwareBlob() to measure FSP binary. >=20 > +# >=20 > +# Copyright (c) 2020, Intel Corporation. All rights reserved.
>=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x00010005 >=20 > + BASE_NAME =3D FspMeasurementLib >=20 > + FILE_GUID =3D > 9A62C49D-C45A-4322-9F3C-45958DF0056B >=20 > + MODULE_TYPE =3D BASE >=20 > + VERSION_STRING =3D 1.0 >=20 > + LIBRARY_CLASS =3D FspMeasurementLib >=20 > + >=20 > +# >=20 > +# The following information is for reference only and not required by th= e > build tools. >=20 > +# >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 >=20 > +# >=20 > + >=20 > +[Sources] >=20 > + FspMeasurementLib.c >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + SecurityPkg/SecurityPkg.dec >=20 > + IntelFsp2Pkg/IntelFsp2Pkg.dec >=20 > + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + BaseMemoryLib >=20 > + DebugLib >=20 > + PrintLib >=20 > + PcdLib >=20 > + PeiServicesLib >=20 > + PeiServicesTablePointerLib >=20 > + FspWrapperApiLib >=20 > + TpmMeasurementLib >=20 > + HashLib >=20 > + >=20 > +[Ppis] >=20 > + gEdkiiTcgPpiGuid > ## CONSUMES >=20 > + >=20 > +[Pcd] >=20 > + gIntelFsp2WrapperTokenSpaceGuid.PcdFspMeasurementConfig > ## CONSUMES >=20 > + gIntelFsp2WrapperTokenSpaceGuid.PcdFspmBaseAddress > ## CONSUMES >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTcgPfpMeasurementRevision > ## CONSUMES >=20 > + >=20 > diff --git > a/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/FspMeasurementLi > b.c > b/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/FspMeasurementLi > b.c > new file mode 100644 > index 0000000000..316570cd2c > --- /dev/null > +++ > b/IntelFsp2WrapperPkg/Library/BaseFspMeasurementLib/FspMeasurementLi > b.c > @@ -0,0 +1,349 @@ > +/** @file >=20 > + This library is used by FSP modules to measure data to TPM. >=20 > + >=20 > +Copyright (c) 2020, Intel Corporation. All rights reserved.
>=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > + >=20 > +#include >=20 > +#include >=20 > + >=20 > +#pragma pack (1) >=20 > + >=20 > +#define PLATFORM_FIRMWARE_BLOB_DESC > "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)" >=20 > +typedef struct { >=20 > + UINT8 BlobDescriptionSize; >=20 > + UINT8 > BlobDescription[sizeof(PLATFORM_FIRMWARE_BLOB_DESC)]; >=20 > + EFI_PHYSICAL_ADDRESS BlobBase; >=20 > + UINT64 BlobLength; >=20 > +} PLATFORM_FIRMWARE_BLOB2_STRUCT; >=20 > + >=20 > +#define HANDOFF_TABLE_POINTER_DESC "1234567890ABCDEF" >=20 > +typedef struct { >=20 > + UINT8 TableDescriptionSize; >=20 > + UINT8 > TableDescription[sizeof(HANDOFF_TABLE_POINTER_DESC)]; >=20 > + UINT64 NumberOfTables; >=20 > + EFI_CONFIGURATION_TABLE TableEntry[1]; >=20 > +} HANDOFF_TABLE_POINTERS2_STRUCT; >=20 > + >=20 > +#pragma pack () >=20 > + >=20 > +/** >=20 > + Tpm measure and log data, and extend the measurement result into a > specific PCR. >=20 > + >=20 > + @param[in] PcrIndex PCR Index. >=20 > + @param[in] EventType Event type. >=20 > + @param[in] EventLog Measurement event log. >=20 > + @param[in] LogLen Event log length in bytes. >=20 > + @param[in] HashData The start of the data buffer to be > hashed, extended. >=20 > + @param[in] HashDataLen The length, in bytes, of the buffer > referenced by HashData >=20 > + @param[in] Flags Bitmap providing additional > information. >=20 > + >=20 > + @retval EFI_SUCCESS Operation completed successfully. >=20 > + @retval EFI_UNSUPPORTED TPM device not available. >=20 > + @retval EFI_OUT_OF_RESOURCES Out of memory. >=20 > + @retval EFI_DEVICE_ERROR The operation was unsuccessful. >=20 > +**/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +TpmMeasureAndLogDataWithFlags ( >=20 > + IN UINT32 PcrIndex, >=20 > + IN UINT32 EventType, >=20 > + IN VOID *EventLog, >=20 > + IN UINT32 LogLen, >=20 > + IN VOID *HashData, >=20 > + IN UINT64 HashDataLen, >=20 > + IN UINT64 Flags >=20 > + ) >=20 > +{ >=20 > + EFI_STATUS Status; >=20 > + EDKII_TCG_PPI *TcgPpi; >=20 > + TCG_PCR_EVENT_HDR TcgEventHdr; >=20 > + >=20 > + Status =3D PeiServicesLocatePpi( >=20 > + &gEdkiiTcgPpiGuid, >=20 > + 0, >=20 > + NULL, >=20 > + (VOID**)&TcgPpi >=20 > + ); >=20 > + if (EFI_ERROR(Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + TcgEventHdr.PCRIndex =3D PcrIndex; >=20 > + TcgEventHdr.EventType =3D EventType; >=20 > + TcgEventHdr.EventSize =3D LogLen; >=20 > + >=20 > + Status =3D TcgPpi->HashLogExtendEvent ( >=20 > + TcgPpi, >=20 > + Flags, >=20 > + HashData, >=20 > + (UINTN)HashDataLen, >=20 > + &TcgEventHdr, >=20 > + EventLog >=20 > + ); >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Get the FvName from the FV header. >=20 > + >=20 > + Causion: The FV is untrusted input. >=20 > + >=20 > + @param[in] FvBase Base address of FV image. >=20 > + @param[in] FvLength Length of FV image. >=20 > + >=20 > + @return FvName pointer >=20 > + @retval NULL FvName is NOT found >=20 > +**/ >=20 > +STATIC >=20 > +VOID * >=20 > +TpmMeasurementGetFvName ( >=20 > + IN EFI_PHYSICAL_ADDRESS FvBase, >=20 > + IN UINT64 FvLength >=20 > + ) >=20 > +{ >=20 > + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; >=20 > + EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader; >=20 > + >=20 > + if (FvBase >=3D MAX_ADDRESS) { >=20 > + return NULL; >=20 > + } >=20 > + if (FvLength >=3D MAX_ADDRESS - FvBase) { >=20 > + return NULL; >=20 > + } >=20 > + if (FvLength < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvBase; >=20 > + if (FvHeader->Signature !=3D EFI_FVH_SIGNATURE) { >=20 > + return NULL; >=20 > + } >=20 > + if (FvHeader->ExtHeaderOffset < > sizeof(EFI_FIRMWARE_VOLUME_HEADER)) { >=20 > + return NULL; >=20 > + } >=20 > + if (FvHeader->ExtHeaderOffset + > sizeof(EFI_FIRMWARE_VOLUME_EXT_HEADER) > FvLength) { >=20 > + return NULL; >=20 > + } >=20 > + FvExtHeader =3D (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(UINTN)(FvBase > + FvHeader->ExtHeaderOffset); >=20 > + >=20 > + return &FvExtHeader->FvName; >=20 > +} >=20 > + >=20 > +/** >=20 > + Mesure a FSP FirmwareBlob. >=20 > + >=20 > + @param[in] Descrption Description for this > FirmwareBlob. >=20 > + @param[in] FirmwareBlobBase Base address of this > FirmwareBlob. >=20 > + @param[in] FirmwareBlobLength Size in bytes of this > FirmwareBlob. >=20 > + @param[in] CfgRegionOffset Configuration region offset in > bytes. >=20 > + @param[in] CfgRegionSize Configuration region in bytes. >=20 > + >=20 > + @retval EFI_SUCCESS Operation completed successfully. >=20 > + @retval EFI_UNSUPPORTED TPM device not available. >=20 > + @retval EFI_OUT_OF_RESOURCES Out of memory. >=20 > + @retval EFI_DEVICE_ERROR The operation was unsuccessful. >=20 > +*/ >=20 > +STATIC >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +MeasureFspFirmwareBlobWithCfg ( >=20 > + IN CHAR8 *Description OPTIONAL, >=20 > + IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase, >=20 > + IN UINT64 FirmwareBlobLength, >=20 > + IN UINT32 CfgRegionOffset, >=20 > + IN UINT32 CfgRegionSize >=20 > + ) >=20 > +{ >=20 > + EFI_PLATFORM_FIRMWARE_BLOB FvBlob, UPDBlob; >=20 > + PLATFORM_FIRMWARE_BLOB2_STRUCT FvBlob2, UPDBlob2; >=20 > + VOID *FvName; >=20 > + UINT32 FvEventType; >=20 > + VOID *FvEventLog, *UPDEventLog; >=20 > + UINT32 FvEventLogSize, > UPDEventLogSize; >=20 > + EFI_STATUS Status; >=20 > + HASH_HANDLE HashHandle; >=20 > + UINT8 *HashBase; >=20 > + UINTN HashSize; >=20 > + TPML_DIGEST_VALUES DigestList; >=20 > + >=20 > + FvName =3D TpmMeasurementGetFvName (FirmwareBlobBase, > FirmwareBlobLength); >=20 > + >=20 > + if (((Description !=3D NULL) || (FvName !=3D NULL)) && >=20 > + (PcdGet32(PcdTcgPfpMeasurementRevision) >=3D > TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2_REV_105)) { >=20 > + ZeroMem (&FvBlob2, sizeof(FvBlob2)); >=20 > + ZeroMem (&UPDBlob2, sizeof(UPDBlob2)); >=20 > + if (Description !=3D NULL) { >=20 > + AsciiSPrint((CHAR8*)FvBlob2.BlobDescription, > sizeof(FvBlob2.BlobDescription), "%a", Description); >=20 > + AsciiSPrint((CHAR8*)UPDBlob2.BlobDescription, > sizeof(UPDBlob2.BlobDescription), "%aUDP", Description); >=20 > + } else { >=20 > + AsciiSPrint((CHAR8*)FvBlob2.BlobDescription, > sizeof(FvBlob2.BlobDescription), "Fv(%g)", FvName); >=20 > + AsciiSPrint((CHAR8*)UPDBlob2.BlobDescription, > sizeof(UPDBlob2.BlobDescription), "(%g)UDP", FvName); >=20 > + } >=20 > + >=20 > + FvBlob2.BlobDescriptionSize =3D sizeof(FvBlob2.BlobDescription); >=20 > + FvBlob2.BlobBase =3D FirmwareBlobBase; >=20 > + FvBlob2.BlobLength =3D FirmwareBlobLength; >=20 > + FvEventType =3D EV_EFI_PLATFORM_FIRMWARE_BLOB2; >=20 > + FvEventLog =3D &FvBlob2; >=20 > + FvEventLogSize =3D sizeof(FvBlob2); >=20 > + >=20 > + UPDBlob2.BlobDescriptionSize =3D sizeof(UPDBlob2.BlobDescription); >=20 > + UPDBlob2.BlobBase =3D CfgRegionOffset; >=20 > + UPDBlob2.BlobLength =3D CfgRegionSize; >=20 > + UPDEventLog =3D &UPDBlob2; >=20 > + UPDEventLogSize =3D sizeof(UPDBlob2); >=20 > + } else { >=20 > + FvBlob.BlobBase =3D FirmwareBlobBase; >=20 > + FvBlob.BlobLength =3D FirmwareBlobLength; >=20 > + FvEventType =3D EV_EFI_PLATFORM_FIRMWARE_BLOB; >=20 > + FvEventLog =3D &FvBlob; >=20 > + FvEventLogSize =3D sizeof(FvBlob); >=20 > + >=20 > + UPDBlob.BlobBase =3D CfgRegionOffset; >=20 > + UPDBlob.BlobLength =3D CfgRegionSize; >=20 > + UPDEventLog =3D &UPDBlob; >=20 > + UPDEventLogSize =3D sizeof(UPDBlob); >=20 > + } >=20 > + >=20 > + // Initialize a SHA hash context. >=20 > + Status =3D HashStart (&HashHandle); >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "HashStart failed - %r\n", Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + // Hash FSP binary before UDP >=20 > + HashBase =3D (UINT8 *) (UINTN) FirmwareBlobBase; >=20 > + HashSize =3D (UINTN) CfgRegionOffset; >=20 > + Status =3D HashUpdate (HashHandle, HashBase, HashSize); >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "HashUpdate failed - %r\n", Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + // Hash FSP binary after UDP >=20 > + HashBase =3D (UINT8 *) (UINTN) FirmwareBlobBase + CfgRegionOffset + > CfgRegionSize; >=20 > + HashSize =3D (UINTN)(FirmwareBlobLength - CfgRegionOffset - > CfgRegionSize); >=20 > + Status =3D HashUpdate (HashHandle, HashBase, HashSize); >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "HashUpdate failed - %r\n", Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + // Finalize the SHA hash. >=20 > + Status =3D HashCompleteAndExtend (HashHandle, 0, NULL, 0, &DigestList)= ; >=20 > + if (EFI_ERROR (Status)) { >=20 > + DEBUG ((DEBUG_ERROR, "HashCompleteAndExtend failed - %r\n", > Status)); >=20 > + return Status; >=20 > + } >=20 > + >=20 > + Status =3D TpmMeasureAndLogDataWithFlags ( >=20 > + 0, >=20 > + FvEventType, >=20 > + FvEventLog, >=20 > + FvEventLogSize, >=20 > + (UINT8 *) &DigestList, >=20 > + (UINTN) sizeof(DigestList), >=20 > + EDKII_TCG_PRE_HASH_LOG_ONLY >=20 > + ); >=20 > + >=20 > + Status =3D TpmMeasureAndLogData ( >=20 > + 1, >=20 > + EV_PLATFORM_CONFIG_FLAGS, >=20 > + UPDEventLog, >=20 > + UPDEventLogSize, >=20 > + (UINT8 *) (UINTN) FirmwareBlobBase + CfgRegionOffset, >=20 > + CfgRegionSize >=20 > + ); >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +FSP_INFO_HEADER * >=20 > +EFIAPI >=20 > +mFspFindFspHeader ( Can we use existing function from same package? FspWrapperApiLib.c->FspFind= FspHeader () >=20 > + IN EFI_PHYSICAL_ADDRESS FlashFvFspBase >=20 > + ) >=20 > +{ >=20 > + UINT8 *CheckPointer; >=20 > + >=20 > + CheckPointer =3D (UINT8 *) (UINTN) FlashFvFspBase; >=20 > + >=20 > + if (((EFI_FIRMWARE_VOLUME_HEADER *)CheckPointer)->Signature !=3D > EFI_FVH_SIGNATURE) { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + if (((EFI_FIRMWARE_VOLUME_HEADER > *)CheckPointer)->ExtHeaderOffset !=3D 0) { >=20 > + CheckPointer =3D CheckPointer + ((EFI_FIRMWARE_VOLUME_HEADER > *)CheckPointer)->ExtHeaderOffset; >=20 > + CheckPointer =3D CheckPointer + > ((EFI_FIRMWARE_VOLUME_EXT_HEADER *)CheckPointer)->ExtHeaderSize; >=20 > + CheckPointer =3D (UINT8 *) ALIGN_POINTER (CheckPointer, 8); >=20 > + } else { >=20 > + CheckPointer =3D CheckPointer + ((EFI_FIRMWARE_VOLUME_HEADER > *)CheckPointer)->HeaderLength; >=20 > + } >=20 > + >=20 > + >=20 > + CheckPointer =3D CheckPointer + sizeof (EFI_FFS_FILE_HEADER); >=20 > + >=20 > + if (((EFI_RAW_SECTION *)CheckPointer)->Type !=3D EFI_SECTION_RAW) { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + CheckPointer =3D CheckPointer + sizeof (EFI_RAW_SECTION); >=20 > + >=20 > + return (FSP_INFO_HEADER *)CheckPointer; >=20 > +} >=20 > +/** >=20 > + Mesure a FSP FirmwareBlob. >=20 > + >=20 > + @param[in] PcrIndex PCR Index. >=20 > + @param[in] Descrption Description for this > FirmwareBlob. >=20 > + @param[in] FirmwareBlobBase Base address of this > FirmwareBlob. >=20 > + @param[in] FirmwareBlobLength Size in bytes of this > FirmwareBlob. >=20 > + >=20 > + @retval EFI_SUCCESS Operation completed successfully. >=20 > + @retval EFI_UNSUPPORTED TPM device not available. >=20 > + @retval EFI_OUT_OF_RESOURCES Out of memory. >=20 > + @retval EFI_DEVICE_ERROR The operation was unsuccessful. >=20 > +*/ >=20 > +EFI_STATUS >=20 > +EFIAPI >=20 > +MeasureFspFirmwareBlob ( >=20 > + IN UINT32 PcrIndex, >=20 > + IN CHAR8 *Description OPTIONAL, >=20 > + IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase, >=20 > + IN UINT64 FirmwareBlobLength >=20 > + ) >=20 > +{ >=20 > + UINT32 FspMeasureMask; >=20 > + FSP_INFO_HEADER *FspHeaderPtr; >=20 > + >=20 > + FspMeasureMask =3D PcdGet32 (PcdFspMeasurementConfig); >=20 > + if (FspMeasureMask & FSP_MEASURE_FSPUPD) { >=20 > + FspHeaderPtr =3D (FSP_INFO_HEADER *) mFspFindFspHeader > (FirmwareBlobBase); >=20 > + if (FspHeaderPtr =3D=3D NULL) { >=20 > + return MeasureFirmwareBlob (PcrIndex, Description, > FirmwareBlobBase, FirmwareBlobLength);; Double ";;" >=20 > + } >=20 > + return MeasureFspFirmwareBlobWithCfg(Description, > FirmwareBlobBase, FirmwareBlobLength, >=20 > + > FspHeaderPtr->CfgRegionOffset, FspHeaderPtr->CfgRegionSize); >=20 > + } else { >=20 > + return MeasureFirmwareBlob (PcrIndex, Description, > FirmwareBlobBase, FirmwareBlobLength); >=20 > + } >=20 > +} >=20 > + >=20 > -- > 2.26.2.windows.1