From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.92.23.97]) by mx.groups.io with SMTP id smtpd.web12.1473.1596784573965883251 for ; Fri, 07 Aug 2020 00:16:14 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=ED3jHToo; spf=pass (domain: outlook.com, ip: 40.92.23.97, mailfrom: michael.kubacki@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=joIHQLz+qrtVw42H31jbiaWhjXlqyLI1a7by3i+B/OThg2P9obyTGLwTKZq1iS/an3UYwLjGJxyEFGgyTAbIf3f1pLKdCQFTTZjRHoR1B7MBEZxU3MDtNnmaa33O0M3vzERFwYtP8LT+KVeNeD1muq4YWkYoUN+urI13OtQE4AIr4+BVkktaMbO1/ZwEzBYqBoTkarl450VRJaGdpGSb+1g/XwAj7lYuQxqbfFC72qFdSHDOs1JSJAfndPj7kl7UGr2r8v547V0KlpQAFe2UJtl5av9l7rWiWV31QEMrG1OFa5AdQTvabwVAS2IE/rrRi5UgkpK94PuPhRd+eJjLDQ== 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=pGwT5iqyCWSm8xpelyc9aLi/z/3qdd9eCvVncB3/QKw=; b=lF4yDnCS78XHK22MDyK45LNZVxa4Ojy74EZ9AMMz4GFSnGH0cnRLYrX973MkZ05Q6nYpvrOQ1Lj6kqT/0KSrX18bBF0wW94qK2/yot8nLxspCjbr8QZXwRFpfwnWbRAanjZ63YIOEsRGOherO4iKG7Wn2GgpCDNn4/0z3GiEYtzuMU43oGZNHjcMCUbf702RtEex0mWbj5upkrtgwRPZl7RE8OhqDQXgewUaNxo2s8PTTVIxky1UabxKw+JZdd3WLVK30aDqHfANXziMba1GOQ5b6jrFUP6g/Ov1MwXqHQcATj0aiuTUxnNX0mhC+yUJcWQJncfrYHDMepg1V6tdhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pGwT5iqyCWSm8xpelyc9aLi/z/3qdd9eCvVncB3/QKw=; b=ED3jHTooXpOe22zDE2KrlvpiDh3SSjid/PYM8RAdC0Ffgv8g/nk6jehvGPkxbmz5Jeh44x0jAFS8gBcIHA8jeXl2oeUVT+4q1FPwSW9h7bK4ebdVVxAQ2SNmxWUkqKxsuUor8bxTYTfDb0mdd4y9hND7MXCIkI2QFthl5QI1uVzVqzJDqMN4eUk7/zxq7WPsVIo3cMmnMkRm4v9wqXj8ECe/Z/DCUV4ouZx64RBeT+daJIZfa6++jMvXt7rmrL9dQk3/ubWkgMHzU5LIXgjccQpuhKTg3arLGYbYXkQ2xYZM5+Pe3bgQjLwn1nynBBwUw2xOr/uNMJO69kK0beKlXg== Received: from BN8NAM12FT047.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::46) by BN8NAM12HT085.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.10; Fri, 7 Aug 2020 07:16:12 +0000 Received: from MWHPR07MB3440.namprd07.prod.outlook.com (2a01:111:e400:fc66::49) by BN8NAM12FT047.mail.protection.outlook.com (2a01:111:e400:fc66::318) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.10 via Frontend Transport; Fri, 7 Aug 2020 07:16:12 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:8ED6DB6E4EFEFE5E3906292EAC12506B2EA91B9855C139F977718985701273B0;UpperCasedChecksum:46AC51C355F34FCB338F42020E5CBEDE336FA9F25A21F2BCFF6F83FD6BF8B4F8;SizeAsReceived:7804;Count:49 Received: from MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::9856:570e:1735:974e]) by MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::9856:570e:1735:974e%7]) with mapi id 15.20.3261.019; Fri, 7 Aug 2020 07:16:12 +0000 From: "Michael Kubacki" To: devel@edk2.groups.io CC: Liming Gao , Michael D Kinney , Guomin Jiang , Wei6 Xu Subject: [PATCH v1 6/7] FmpDevicePkg: Add Last Attempt Status support to dependency libs Date: Fri, 7 Aug 2020 00:15:25 -0700 Message-ID: X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200807071526.1837-1-michael.kubacki@outlook.com> References: <20200807071526.1837-1-michael.kubacki@outlook.com> X-ClientProxiedBy: MWHPR15CA0042.namprd15.prod.outlook.com (2603:10b6:300:ad::28) To MWHPR07MB3440.namprd07.prod.outlook.com (2603:10b6:301:69::28) Return-Path: michael.kubacki@outlook.com X-Microsoft-Original-Message-ID: <20200807071526.1837-7-michael.kubacki@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2001:4898:80e8:a:adbb:8e69:1fd3:409e) by MWHPR15CA0042.namprd15.prod.outlook.com (2603:10b6:300:ad::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 07:16:12 +0000 X-Mailer: git-send-email 2.28.0.windows.1 X-Microsoft-Original-Message-ID: <20200807071526.1837-7-michael.kubacki@outlook.com> X-TMN: [wriqddIbgTL91xkB5Rv8O3j0v9O9Sza4f67m7F7aUhkLosKy6hxwGmnfnX1bNdWd] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: f71642d7-36a2-4b88-437a-08d83aa1c3e7 X-MS-TrafficTypeDiagnostic: BN8NAM12HT085: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KD7jTnRUlKPMYSfdoezxSH0zv/XwTtflzwUs65SLnO4luMI9bEA3p4wYSEsGnHFj4DEpyswsMXr2s9Ucg82ewmNYxSqVYD5UAcYon0u4WEwzwafJLVpV+UO1J77FLqwU6n1iuQ8KYuZmL5K34J1cn9bZp/u9CBg7ccSkeXStIol7cSdKTCJBkdbRPLSIU7I/Gub0aeA6W19RurHGhTsulQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR07MB3440.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: lElHwQOKuL+IHhgt6/kXscrQhhmDlmFojWAIFYrX9kRcMvLPOBBOb9s5hduD7hTaYC073QJiBlM0H5XtrhLyhJ0RpdMEzXhzqm6FR/5rg45xv7TMwhbAQndisWQueUb5bYiBtnEmY6WnFRKTXMrazSattkSoLAgqklE94rtIhw9fM5THhEN9TNN32QMdt1jM26J9FLiT8d3Arrau566Ppw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f71642d7-36a2-4b88-437a-08d83aa1c3e7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 07:16:12.6142 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT047.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM12HT085 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Michael Kubacki The FMP dependency libraries are leveraged during firmware update to check for dependencies required to update the image. This change adds granular Last Attempt Status code support to these services so failures can be more easily observed during the firmware update process via Last Attempt Status codes. Cc: Liming Gao Cc: Michael D Kinney Cc: Guomin Jiang Cc: Wei6 Xu Signed-off-by: Michael Kubacki --- FmpDevicePkg/FmpDxe/FmpDxe.c = | 25 +++++- FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c = | 38 +++++--- FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibNull.c= | 9 +- FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c = | 95 +++++++++++++++++--- FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependencyUnit= Test.c | 7 +- FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h = | 8 +- FmpDevicePkg/Include/Library/FmpDependencyLib.h = | 44 +++++---- 7 files changed, 179 insertions(+), 47 deletions(-) diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index aeb888c86bc3..84a8e15cfc17 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -929,7 +929,17 @@ CheckTheImageInternal ( // // Get the dependency from Image. // - Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); + Dependencies =3D GetImageDependency ( + (EFI_FIRMWARE_IMAGE_AUTHENTICATION *) Image, + ImageSize, + &DependenciesSize, + &LocalLastAttemptStatus + ); + if (LocalLastAttemptStatus !=3D LAST_ATTEMPT_STATUS_SUCCESS) { + Status =3D EFI_ABORTED; + *LastAttemptStatus =3D LocalLastAttemptStatus; + goto cleanup; + } =20 // // Check the FmpPayloadHeader @@ -968,11 +978,20 @@ CheckTheImageInternal ( // // Evaluate dependency expression // - Private->DependenciesSatisfied =3D CheckFmpDependency (Private->Descript= or.ImageTypeId, Version, Dependencies, DependenciesSize); + Private->DependenciesSatisfied =3D CheckFmpDependency ( + Private->Descriptor.ImageTypeId, + Version, + Dependencies, + DependenciesSize, + &LocalLastAttemptStatus + ); if (!Private->DependenciesSatisfied) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check f= ailed.\n", mImageIdName)); *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; Status =3D EFI_SUCCESS; + if (LocalLastAttemptStatus !=3D LAST_ATTEMPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } goto cleanup; } =20 @@ -1184,7 +1203,7 @@ SetTheImage ( // // Get the dependency from Image. // - Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); + Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize, &LastAttemptStatus); =20 // // No functional error in CheckTheImage. Attempt to get the Version to diff --git a/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckL= ib.c b/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c index 02ed600e0e95..d1e3b6b93bc2 100644 --- a/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c +++ b/FmpDevicePkg/Library/FmpDependencyCheckLib/FmpDependencyCheckLib.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include =20 /** Check dependency for firmware update. @@ -25,6 +27,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. =20 @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. @@ -36,7 +42,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_STATUS Status; @@ -44,6 +51,7 @@ CheckFmpDependency ( UINTN Index; EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp; UINTN ImageInfoSize; + UINT32 LocalLastAttemptStatus; UINT32 *DescriptorVer; UINT8 FmpImageInfoCount; UINTN *DescriptorSize; @@ -55,14 +63,15 @@ CheckFmpDependency ( UINTN FmpVersionsCount; BOOLEAN IsSatisfied; =20 - FmpImageInfoBuf =3D NULL; - DescriptorVer =3D NULL; - DescriptorSize =3D NULL; - NumberOfFmpInstance =3D 0; - FmpVersions =3D NULL; - FmpVersionsCount =3D 0; - IsSatisfied =3D TRUE; - PackageVersionName =3D NULL; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_SUCCESS; + FmpImageInfoBuf =3D NULL; + DescriptorVer =3D NULL; + DescriptorSize =3D NULL; + NumberOfFmpInstance =3D 0; + FmpVersions =3D NULL; + FmpVersionsCount =3D 0; + IsSatisfied =3D TRUE; + PackageVersionName =3D NULL; =20 // // Get ImageDescriptors of all FMP instances, and archive them for depen= dency evaluation. @@ -77,30 +86,35 @@ CheckFmpDependency ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "CheckFmpDependency: Get Firmware Management Prot= ocol failed. (%r)", Status)); IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 FmpImageInfoBuf =3D AllocateZeroPool (sizeof(EFI_FIRMWARE_IMAGE_DESCRIPT= OR *) * NumberOfFmpInstance); if (FmpImageInfoBuf =3D=3D NULL) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 DescriptorVer =3D AllocateZeroPool (sizeof(UINT32) * NumberOfFmpInstance= ); if (DescriptorVer =3D=3D NULL ) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 DescriptorSize =3D AllocateZeroPool (sizeof(UINTN) * NumberOfFmpInstance= ); if (DescriptorSize =3D=3D NULL ) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 FmpVersions =3D AllocateZeroPool (sizeof(FMP_DEPEX_CHECK_VERSION_DATA) *= NumberOfFmpInstance); if (FmpVersions =3D=3D NULL) { IsSatisfied =3D FALSE; + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_MEMORY= _ALLOCATION_FAILED; goto cleanup; } =20 @@ -164,7 +178,7 @@ CheckFmpDependency ( // Evaluate firmware image's depex, against the version of other Fmp ins= tances. // if (Dependencies !=3D NULL) { - IsSatisfied =3D EvaluateDependency (Dependencies, DependenciesSize, Fm= pVersions, FmpVersionsCount); + IsSatisfied =3D EvaluateDependency (Dependencies, DependenciesSize, Fm= pVersions, FmpVersionsCount, &LocalLastAttemptStatus); } =20 if (!IsSatisfied) { @@ -194,5 +208,9 @@ CheckFmpDependency ( FreePool (FmpVersions); } =20 + if (LastAttemptStatus !=3D NULL && LocalLastAttemptStatus !=3D LAST_ATTE= MPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } + return IsSatisfied; } diff --git a/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCh= eckLibNull.c b/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependency= CheckLibNull.c index 55e9af22909d..8937fb56d919 100644 --- a/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibN= ull.c +++ b/FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibN= ull.c @@ -1,6 +1,7 @@ /** @file Null instance of FmpDependencyCheckLib. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -16,7 +17,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. - + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. =20 @@ -27,7 +31,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { return TRUE; diff --git a/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c b/Fmp= DevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c index 5ef25d2415cf..2045570b0628 100644 --- a/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c +++ b/FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include =20 // // Define the initial size of the dependency expression evaluation stack @@ -203,6 +205,10 @@ Pop ( parameter is optional and can be set to = NULL. @param[in] FmpVersionsCount Element count of the array. When FmpVers= ions is NULL, FmpVersionsCount must be 0. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE Dependency expressions evaluate to TRUE. @retval FALSE Dependency expressions evaluate to FALSE. @@ -211,10 +217,11 @@ Pop ( BOOLEAN EFIAPI EvaluateDependency ( - IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN UINTN DependenciesSize, - IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions OPTIONAL, - IN UINTN FmpVersionsCount + IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, + IN UINTN DependenciesSize, + IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions, OPTIONAL + IN UINTN FmpVersionsCount, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_STATUS Status; @@ -224,6 +231,9 @@ EvaluateDependency ( DEPEX_ELEMENT Element2; GUID ImageTypeId; UINT32 Version; + UINT32 LocalLastAttemptStatus; + + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_SUCCESS; =20 // // Check if parameter is valid. @@ -249,6 +259,7 @@ EvaluateDependency ( case EFI_FMP_DEP_PUSH_GUID: if (Iterator + sizeof (EFI_GUID) >=3D (UINT8 *) Dependencies->Depend= encies + DependenciesSize) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: GUID extends beyond end = of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_GU= ID_BEYOND_DEPEX; goto Error; } =20 @@ -259,6 +270,7 @@ EvaluateDependency ( if(CompareGuid (&FmpVersions[Index].ImageTypeId, &ImageTypeId)){ Status =3D Push (FmpVersions[Index].Version, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERRO= R_PUSH_FAILURE; goto Error; } break; @@ -266,18 +278,21 @@ EvaluateDependency ( } if (Index =3D=3D FmpVersionsCount) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: %g is not found!\n", &Im= ageTypeId)); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_FM= P_NOT_FOUND; goto Error; } break; case EFI_FMP_DEP_PUSH_VERSION: if (Iterator + sizeof (UINT32) >=3D (UINT8 *) Dependencies->Dependen= cies + DependenciesSize ) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: VERSION extends beyond e= nd of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_VE= RSION_BEYOND_DEPEX; goto Error; } =20 Version =3D *(UINT32 *) (Iterator + 1); Status =3D Push (Version, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } Iterator =3D Iterator + sizeof (UINT32); @@ -286,154 +301,191 @@ EvaluateDependency ( Iterator +=3D AsciiStrnLenS ((CHAR8 *) Iterator, DependenciesSize - = (Iterator - Dependencies->Dependencies)); if (Iterator =3D=3D (UINT8 *) Dependencies->Dependencies + Dependenc= iesSize) { DEBUG ((DEBUG_ERROR, "EvaluateDependency: STRING extends beyond en= d of dependency expression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_VE= RSION_STR_BEYOND_DEPEX; goto Error; } break; case EFI_FMP_DEP_AND: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (Element1.Value.Boolean & Element2.Value.Boolean, Bo= oleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_OR: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop(&Element2, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (Element1.Value.Boolean | Element2.Value.Boolean, Bo= oleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_NOT: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Push (!(Element1.Value.Boolean), BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_TRUE: Status =3D Push (TRUE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_FALSE: Status =3D Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_EQ: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version =3D=3D Element2.Value.Version) ? = Push (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_GT: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version > Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_GTE: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version >=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_LT: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus=3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_POP= _FAILURE; goto Error; } Status =3D (Element1.Value.Version < Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_LTE: Status =3D Pop (&Element1, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D Pop (&Element2, VersionType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } Status =3D (Element1.Value.Version <=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PU= SH_FAILURE; goto Error; } break; case EFI_FMP_DEP_END: Status =3D Pop (&Element1, BooleanType); if (EFI_ERROR (Status)) { + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_PO= P_FAILURE; goto Error; } return Element1.Value.Boolean; default: DEBUG ((DEBUG_ERROR, "EvaluateDependency: Unknown Opcode - %02x!\n",= *Iterator)); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_UNKN= OWN_OPCODE; goto Error; } Iterator++; } =20 DEBUG ((DEBUG_ERROR, "EvaluateDependency: No EFI_FMP_DEP_END Opcode in e= xpression!\n")); + LocalLastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_NO_END_O= PCODE; =20 Error: + if (LastAttemptStatus !=3D NULL && LocalLastAttemptStatus !=3D LAST_ATTE= MPT_STATUS_SUCCESS) { + *LastAttemptStatus =3D LocalLastAttemptStatus; + } + return FALSE; } =20 /** Validate the dependency expression and output its size. =20 - @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. + @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. + @param[in] MaxDepexSize Max size of the dependency. + @param[out] DepexSize Size of dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE The dependency expression is valid. @retval FALSE The dependency expression is invalid. @@ -444,7 +496,8 @@ EFIAPI ValidateDependency ( IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, IN UINTN MaxDepexSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { UINT8 *Depex; @@ -489,20 +542,30 @@ ValidateDependency ( } return TRUE; default: + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_UNKNOW= N_OPCODE; + } return FALSE; } } =20 + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_NO_END_OP= CODE; + } + return FALSE; } =20 /** Get dependency from firmware image. =20 - @param[in] Image Points to the firmware image. - @param[in] ImageSize Size, in bytes, of the firmware image. - @param[out] DepexSize Size, in bytes, of the dependency. - + @param[in] Image Points to the firmware image. + @param[in] ImageSize Size, in bytes, of the firmware image. + @param[out] DepexSize Size, in bytes, of the dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. @retval The pointer to dependency. @retval Null =20 @@ -512,7 +575,8 @@ EFIAPI GetImageDependency ( IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN UINTN ImageSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ) { EFI_FIRMWARE_IMAGE_DEP *Depex; @@ -530,6 +594,9 @@ GetImageDependency ( // // Pointer overflow. Invalid image. // + if (LastAttemptStatus !=3D NULL) { + *LastAttemptStatus =3D LAST_ATTEMPT_STATUS_DEPENDENCY_ERROR_GET_DEPE= X_FAILURE; + } return NULL; } =20 @@ -539,7 +606,7 @@ GetImageDependency ( // // Validate the dependency and get the size of dependency // - if (ValidateDependency (Depex, MaxDepexSize, DepexSize)) { + if (ValidateDependency (Depex, MaxDepexSize, DepexSize, LastAttemptStatu= s)) { return Depex; } =20 diff --git a/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDe= pendencyUnitTest.c b/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/Ev= aluateDependencyUnitTest.c index f8ccdd906f29..92a1ac815d51 100644 --- a/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependenc= yUnitTest.c +++ b/FmpDevicePkg/Test/UnitTest/Library/FmpDependencyLib/EvaluateDependenc= yUnitTest.c @@ -1,6 +1,7 @@ /** @file Unit tests of EvaluateDependency API in FmpDependencyLib. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -162,6 +163,7 @@ EvaluateDependencyTest ( { BASIC_TEST_CONTEXT *TestContext; BOOLEAN EvaluationResult; + UINT32 LastAttemptStatus; =20 TestContext =3D (BASIC_TEST_CONTEXT *)Context; =20 @@ -169,8 +171,9 @@ EvaluateDependencyTest ( (EFI_FIRMWARE_IMAGE_DEP *)TestContext->Dependencies= , TestContext->DependenciesSize, mFmpVersions, - sizeof(mFmpVersions)/sizeof(FMP_DEPEX_CHECK_VERSION= _DATA) - ); + sizeof(mFmpVersions)/sizeof(FMP_DEPEX_CHECK_VERSION= _DATA), + &LastAttemptStatus + ); =20 UT_ASSERT_EQUAL (EvaluationResult, TestContext->ExpectedResult); =20 diff --git a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h b/FmpDevi= cePkg/Include/Library/FmpDependencyCheckLib.h index ec380c4947bd..708cbb06ba74 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h @@ -2,6 +2,7 @@ Fmp Capsule Dependency check functions for Firmware Management Protocol = based firmware updates. =20 + Copyright (c) Microsoft Corporation.
Copyright (c) 2020, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -21,6 +22,10 @@ @param[in] Version New version. @param[in] Dependencies Fmp dependency. @param[in] DependenciesSize Size, in bytes, of the Fmp dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hold= s the + last attempt status to report back to the= caller. + A function error code may not always be a= ccompanied + by a last attempt status code. =20 @retval TRUE Dependencies are satisfied. @retval FALSE Dependencies are unsatisfied or dependency check fails. @@ -32,7 +37,8 @@ CheckFmpDependency ( IN EFI_GUID ImageTypeId, IN UINT32 Version, IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, OPTIONAL - IN UINT32 DependenciesSize + IN UINT32 DependenciesSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 #endif diff --git a/FmpDevicePkg/Include/Library/FmpDependencyLib.h b/FmpDevicePkg= /Include/Library/FmpDependencyLib.h index c732903425b4..b8e9c4341165 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyLib.h @@ -26,9 +26,13 @@ typedef struct { /** Validate the dependency expression and output its size. =20 - @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. + @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. + @param[in] MaxDepexSize Max size of the dependency. + @param[out] DepexSize Size of dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE The dependency expression is valid. @retval FALSE The dependency expression is invalid. @@ -39,16 +43,20 @@ EFIAPI ValidateDependency ( IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, IN UINTN MaxDepexSize, - OUT UINT32 *DepexSize + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 /** Get dependency from firmware image. =20 - @param[in] Image Points to the firmware image. - @param[in] ImageSize Size, in bytes, of the firmware image. - @param[out] DepexSize Size, in bytes, of the dependency. - + @param[in] Image Points to the firmware image. + @param[in] ImageSize Size, in bytes, of the firmware image. + @param[out] DepexSize Size, in bytes, of the dependency. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. @retval The pointer to dependency. @retval Null =20 @@ -56,9 +64,10 @@ ValidateDependency ( EFI_FIRMWARE_IMAGE_DEP* EFIAPI GetImageDependency ( - IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, - IN UINTN ImageSize, - OUT UINT32 *DepexSize + IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, + IN UINTN ImageSize, + OUT UINT32 *DepexSize, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 /** @@ -73,6 +82,10 @@ GetImageDependency ( parameter is optional and can be set to = NULL. @param[in] FmpVersionsCount Element count of the array. When FmpVers= ions is NULL, FmpVersionsCount must be 0. + @param[out] LastAttemptStatus An optional pointer to a UINT32 that hol= ds the + last attempt status to report back to th= e caller. + A function error code may not always be = accompanied + by a last attempt status code. =20 @retval TRUE Dependency expressions evaluate to TRUE. @retval FALSE Dependency expressions evaluate to FALSE. @@ -81,10 +94,11 @@ GetImageDependency ( BOOLEAN EFIAPI EvaluateDependency ( - IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN UINTN DependenciesSize, - IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions OPTIONAL, - IN UINTN FmpVersionsCount + IN EFI_FIRMWARE_IMAGE_DEP *Dependencies, + IN UINTN DependenciesSize, + IN FMP_DEPEX_CHECK_VERSION_DATA *FmpVersions, OPTIONAL + IN UINTN FmpVersionsCount, + OUT UINT32 *LastAttemptStatus OPTIONAL ); =20 #endif --=20 2.28.0.windows.1