From nobody Sat Feb 7 08:13:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+59268+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59268+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1589283258; cv=none; d=zohomail.com; s=zohoarc; b=DI4Sey6tMbv2AdMC62jEyOpLGndpmGulVHN+9S+Pcg/ePNSVGejHmUlTIbgQrudQ1ny9tQzvJlPEavk+8/7Fk+KDJ7ZXbxGUNxeVylIdmtBomSIkQZrZAUGJBtDHbawuWzdoKZjpboZZa9tWpZP+mpGXYHWBFi9tkE6BmMSf2qA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589283258; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=NYRIRnr+a2DwZTEE9poYm8kzq4R0g3D1uU3Dt0cgohk=; b=HAgmXL0idivaTtiXC5g6+hZIx2VSI9oU89YdVSMlkZhDAvihfDO+FYMjyS4m7JfBc5NafXWhOdRY2Opb3cmwndK0g71pNvYYnPPlKxKZpxytjoZ0RppFV7VDD4kEjDau/nwUzh1tJKSXQUnxH3cO3e5tsdhtD2u266OtMNOAyw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+59268+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1589283258542659.1679747668136; Tue, 12 May 2020 04:34:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WHupYY1788612x334f14nLVx; Tue, 12 May 2020 04:34:18 -0700 X-Received: from mga04.intel.com (mga04.intel.com []) by mx.groups.io with SMTP id smtpd.web11.3781.1589283253207481555 for ; Tue, 12 May 2020 04:34:17 -0700 IronPort-SDR: 1myYEMiHDpj42rkPzP6UpaTEh5YLW5HJ7Pu4uj4wP8YAt4SfmxOLD7WBNl1n2DQuVSB3DCRxXW sYXs6Mw9XsjQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2020 04:34:17 -0700 IronPort-SDR: DBI8LdnGpbA/1h+1cN1yUoSNtSkpeOyGH85KWwh93K23Eqdz8IysRUjypECEdM8wWw0RZboT++ mmEadYZq/QRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,383,1583222400"; d="scan'208";a="265474263" X-Received: from shwdeopenpsi174.ccr.corp.intel.com ([10.239.157.39]) by orsmga006.jf.intel.com with ESMTP; 12 May 2020 04:34:15 -0700 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Sean Brogan Subject: [edk2-devel] [PATCH V2 5/5] FmpDevicePkg/FmpDxe: Use new Fmp dependency libraries Date: Tue, 12 May 2020 19:33:51 +0800 Message-Id: <20200512113351.8224-6-wei6.xu@intel.com> In-Reply-To: <20200512113351.8224-1-wei6.xu@intel.com> References: <20200512113351.8224-1-wei6.xu@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,wei6.xu@intel.com X-Gm-Message-State: UqMjaSUk1db50zLQ70Qo8pY9x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589283258; bh=D0ktX9TEpy9YI2rsUBAnE/uuQn0Ry47WVijp4ELJRX8=; h=Cc:Date:From:Reply-To:Subject:To; b=CvT9aAcYjV4l1M/v4fHPDcmvwcjeBplCEJRtafk1VlBP2YApcKQPN3TOeQqIeepQR5M GHG3UiaO0712nQ7G2lCxA+6chIrsvRiY/pjU+093+2ktikXUYToFiuanEfaS+wRJDfQEO M89qnGW6DT3qOKPznZpf1vCY7CvWoTdfMhI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2696 Remove the orginal Fmp Capsule Dependency implement, and use new FmpDependencyLib, FmpDependencyCheckLib and FmpDependencyDeviceLib APIs instead. A platform can perform the dependency check in a platform specific manner by implementing its own FmpDependencyCheckLib. Cc: Michael D Kinney Cc: Liming Gao Cc: Sean Brogan Signed-off-by: Wei6 Xu --- FmpDevicePkg/FmpDxe/Dependency.c | 679 ----------------------------------= ---- FmpDevicePkg/FmpDxe/Dependency.h | 63 ---- FmpDevicePkg/FmpDxe/FmpDxe.c | 255 +++----------- FmpDevicePkg/FmpDxe/FmpDxe.h | 4 + FmpDevicePkg/FmpDxe/FmpDxe.inf | 5 +- FmpDevicePkg/FmpDxe/FmpDxeLib.inf | 5 +- 6 files changed, 63 insertions(+), 948 deletions(-) delete mode 100644 FmpDevicePkg/FmpDxe/Dependency.c delete mode 100644 FmpDevicePkg/FmpDxe/Dependency.h diff --git a/FmpDevicePkg/FmpDxe/Dependency.c b/FmpDevicePkg/FmpDxe/Depende= ncy.c deleted file mode 100644 index 65c23989c6..0000000000 --- a/FmpDevicePkg/FmpDxe/Dependency.c +++ /dev/null @@ -1,679 +0,0 @@ -/** @file - Supports Capsule Dependency Expression. - - Copyright (c) 2020, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ -#include "FmpDxe.h" -#include "Dependency.h" - -// -// Define the initial size of the dependency expression evaluation stack -// -#define DEPEX_STACK_SIZE_INCREMENT 0x1000 - -// -// Type of stack element -// -typedef enum { - BooleanType, - VersionType -} ELEMENT_TYPE; - -// -// Value of stack element -// -typedef union { - BOOLEAN Boolean; - UINT32 Version; -} ELEMENT_VALUE; - -// -// Stack element used to evaluate dependency expressions -// -typedef struct { - ELEMENT_VALUE Value; - ELEMENT_TYPE Type; -} DEPEX_ELEMENT; - -// -// Global variable used to support dependency evaluation -// -UINTN mNumberOfFmpInstance =3D 0; -EFI_FIRMWARE_IMAGE_DESCRIPTOR **mFmpImageInfoBuf =3D NULL; - -// -// Indicates the status of dependency check, default value is DEPENDENCIES= _SATISFIED. -// -UINT8 mDependenciesCheckStatus =3D DEPENDENCIES_SATISFIED; - -// -// Global stack used to evaluate dependency expressions -// -DEPEX_ELEMENT *mDepexEvaluationStack =3D NULL; -DEPEX_ELEMENT *mDepexEvaluationStackEnd =3D NULL; -DEPEX_ELEMENT *mDepexEvaluationStackPointer =3D NULL; - -/** - Grow size of the Depex stack - - @retval EFI_SUCCESS Stack successfully growed. - @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow = the stack. - -**/ -EFI_STATUS -GrowDepexStack ( - VOID - ) -{ - DEPEX_ELEMENT *NewStack; - UINTN Size; - - Size =3D DEPEX_STACK_SIZE_INCREMENT; - if (mDepexEvaluationStack !=3D NULL) { - Size =3D Size + (mDepexEvaluationStackEnd - mDepexEvaluationStack); - } - - NewStack =3D AllocatePool (Size * sizeof (DEPEX_ELEMENT)); - if (NewStack =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - if (mDepexEvaluationStack !=3D NULL) { - // - // Copy to Old Stack to the New Stack - // - CopyMem ( - NewStack, - mDepexEvaluationStack, - (mDepexEvaluationStackEnd - mDepexEvaluationStack) * sizeof (DEPEX_E= LEMENT) - ); - - // - // Free The Old Stack - // - FreePool (mDepexEvaluationStack); - } - - // - // Make the Stack pointer point to the old data in the new stack - // - mDepexEvaluationStackPointer =3D NewStack + (mDepexEvaluationStackPointe= r - mDepexEvaluationStack); - mDepexEvaluationStack =3D NewStack; - mDepexEvaluationStackEnd =3D NewStack + Size; - - return EFI_SUCCESS; -} - -/** - Push an element onto the Stack. - - @param[in] Value Value to push. - @param[in] Type Element Type - - @retval EFI_SUCCESS The value was pushed onto the stack. - @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow= the stack. - @retval EFI_INVALID_PARAMETER Wrong stack element type. - -**/ -EFI_STATUS -Push ( - IN UINT32 Value, - IN UINTN Type - ) -{ - EFI_STATUS Status; - DEPEX_ELEMENT Element; - - // - // Check Type - // - if (Type !=3D BooleanType && Type !=3D VersionType) { - return EFI_INVALID_PARAMETER; - } - - // - // Check for a stack overflow condition - // - if (mDepexEvaluationStackPointer =3D=3D mDepexEvaluationStackEnd) { - // - // Grow the stack - // - Status =3D GrowDepexStack (); - if (EFI_ERROR (Status)) { - return Status; - } - } - - Element.Value.Version =3D Value; - Element.Type =3D Type; - - // - // Push the item onto the stack - // - *mDepexEvaluationStackPointer =3D Element; - mDepexEvaluationStackPointer++; - - return EFI_SUCCESS; -} - - -/** - Pop an element from the stack. - - @param[out] Element Element to pop. - @param[in] Type Type of element. - - @retval EFI_SUCCESS The value was popped onto the stack. - @retval EFI_ACCESS_DENIED The pop operation underflowed the stack. - @retval EFI_INVALID_PARAMETER Type is mismatched. - -**/ -EFI_STATUS -Pop ( - OUT DEPEX_ELEMENT *Element, - IN ELEMENT_TYPE Type - ) -{ - // - // Check for a stack underflow condition - // - if (mDepexEvaluationStackPointer =3D=3D mDepexEvaluationStack) { - return EFI_ACCESS_DENIED; - } - - // - // Pop the item off the stack - // - mDepexEvaluationStackPointer--; - *Element =3D *mDepexEvaluationStackPointer; - if ((*Element).Type !=3D Type) { - return EFI_INVALID_PARAMETER; - } - return EFI_SUCCESS; -} - -/** - Evaluate the dependencies. - - @param[in] Dependencies Dependency expressions. - @param[in] DependenciesSize Size of Dependency expressions. - - @retval TRUE Dependency expressions evaluate to TRUE. - @retval FALSE Dependency expressions evaluate to FALSE. - -**/ -BOOLEAN -EvaluateDependencies ( - IN CONST EFI_FIRMWARE_IMAGE_DEP * Dependencies, - IN CONST UINTN DependenciesSize - ) -{ - EFI_STATUS Status; - UINT8 *Iterator; - UINT8 Index; - DEPEX_ELEMENT Element1; - DEPEX_ELEMENT Element2; - GUID ImageTypeId; - UINT32 Version; - - if (Dependencies =3D=3D NULL || DependenciesSize =3D=3D 0) { - return FALSE; - } - - // - // Clean out memory leaks in Depex Boolean stack. Leaks are only caused = by - // incorrectly formed DEPEX expressions - // - mDepexEvaluationStackPointer =3D mDepexEvaluationStack; - - Iterator =3D (UINT8 *) Dependencies->Dependencies; - while (Iterator < (UINT8 *) Dependencies->Dependencies + DependenciesSiz= e) { - switch (*Iterator) - { - case EFI_FMP_DEP_PUSH_GUID: - if (Iterator + sizeof (EFI_GUID) >=3D (UINT8 *) Dependencies->Depend= encies + DependenciesSize) { - Status =3D EFI_INVALID_PARAMETER; - goto Error; - } - - CopyGuid (&ImageTypeId, (EFI_GUID *) (Iterator + 1)); - Iterator =3D Iterator + sizeof (EFI_GUID); - - for (Index =3D 0; Index < mNumberOfFmpInstance; Index ++){ - if (mFmpImageInfoBuf[Index] =3D=3D NULL) { - continue; - } - if(CompareGuid (&mFmpImageInfoBuf[Index]->ImageTypeId, &ImageTypeI= d)){ - Status =3D Push (mFmpImageInfoBuf[Index]->Version, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - } - } - if (Index =3D=3D mNumberOfFmpInstance) { - Status =3D EFI_NOT_FOUND; - goto Error; - } - break; - case EFI_FMP_DEP_PUSH_VERSION: - if (Iterator + sizeof (UINT32) >=3D (UINT8 *) Dependencies->Dependen= cies + DependenciesSize ) { - Status =3D EFI_INVALID_PARAMETER; - goto Error; - } - - Version =3D *(UINT32 *) (Iterator + 1); - Status =3D Push (Version, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Iterator =3D Iterator + sizeof (UINT32); - break; - case EFI_FMP_DEP_VERSION_STR: - Iterator +=3D AsciiStrnLenS ((CHAR8 *) Iterator, DependenciesSize - = (Iterator - Dependencies->Dependencies)); - break; - case EFI_FMP_DEP_AND: - Status =3D Pop (&Element1, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Push (Element1.Value.Boolean & Element2.Value.Boolean, Bo= oleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_OR: - Status =3D Pop (&Element1, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop(&Element2, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Push (Element1.Value.Boolean | Element2.Value.Boolean, Bo= oleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_NOT: - Status =3D Pop (&Element1, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Push (!(Element1.Value.Boolean), BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_TRUE: - Status =3D Push (TRUE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_FALSE: - Status =3D Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_EQ: - Status =3D Pop (&Element1, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D (Element1.Value.Version =3D=3D Element2.Value.Version) ? = Push (TRUE, BooleanType) : Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_GT: - Status =3D Pop (&Element1, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D (Element1.Value.Version > Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_GTE: - Status =3D Pop (&Element1, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D (Element1.Value.Version >=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_LT: - Status =3D Pop (&Element1, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D (Element1.Value.Version < Element2.Value.Version) ? Push= (TRUE, BooleanType) : Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_LTE: - Status =3D Pop (&Element1, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D Pop (&Element2, VersionType); - if (EFI_ERROR (Status)) { - goto Error; - } - Status =3D (Element1.Value.Version <=3D Element2.Value.Version) ? Pu= sh (TRUE, BooleanType) : Push (FALSE, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - break; - case EFI_FMP_DEP_END: - Status =3D Pop (&Element1, BooleanType); - if (EFI_ERROR (Status)) { - goto Error; - } - return Element1.Value.Boolean; - default: - Status =3D EFI_INVALID_PARAMETER; - goto Error; - } - Iterator++; - } - -Error: - - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): EvaluateDependencies() - RESULT =3D FA= LSE (Status =3D %r)\n", mImageIdName, Status)); - return FALSE; -} - -/** - Validate the dependency expression and output its size. - - @param[in] ImageDepex Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. - - @retval TRUE The capsule is valid. - @retval FALSE The capsule is invalid. - -**/ -BOOLEAN -ValidateImageDepex ( - IN EFI_FIRMWARE_IMAGE_DEP *ImageDepex, - IN CONST UINTN MaxDepexSize, - OUT UINT32 *DepexSize - ) -{ - UINT8 *Depex; - - *DepexSize =3D 0; - Depex =3D ImageDepex->Dependencies; - while (Depex < ImageDepex->Dependencies + MaxDepexSize) { - switch (*Depex) - { - case EFI_FMP_DEP_PUSH_GUID: - Depex +=3D sizeof (EFI_GUID) + 1; - break; - case EFI_FMP_DEP_PUSH_VERSION: - Depex +=3D sizeof (UINT32) + 1; - break; - case EFI_FMP_DEP_VERSION_STR: - Depex +=3D AsciiStrnLenS ((CHAR8 *) Depex, ImageDepex->Dependencies = + MaxDepexSize - Depex) + 1; - break; - case EFI_FMP_DEP_AND: - case EFI_FMP_DEP_OR: - case EFI_FMP_DEP_NOT: - case EFI_FMP_DEP_TRUE: - case EFI_FMP_DEP_FALSE: - case EFI_FMP_DEP_EQ: - case EFI_FMP_DEP_GT: - case EFI_FMP_DEP_GTE: - case EFI_FMP_DEP_LT: - case EFI_FMP_DEP_LTE: - Depex +=3D 1; - break; - case EFI_FMP_DEP_END: - Depex +=3D 1; - *DepexSize =3D (UINT32)(Depex - ImageDepex->Dependencies); - return TRUE; - default: - return FALSE; - } - } - - return FALSE; -} - - -/** - Get the size of dependencies. Assume the dependencies is validated before - calling this function. - - @param[in] Dependencies Pointer to the EFI_FIRMWARE_IMAGE_DEP. - - @retval The size of dependencies. - -**/ -UINTN -GetDepexSize ( - IN CONST EFI_FIRMWARE_IMAGE_DEP *Dependencies - ) -{ - UINTN Index; - - if (Dependencies =3D=3D NULL) { - return 0; - } - - Index =3D 0; - while (Dependencies->Dependencies[Index] !=3D EFI_FMP_DEP_END) { - Index ++; - } - - return Index + 1; -} - -/** - Check dependency for firmware update. - - @param[in] ImageTypeId Image Type Id. - @param[in] Version New version. - @param[in] Dependencies The dependencies. - @param[in] DependenciesSize Size of the dependencies - @param[out] IsSatisfied Indicate the dependencies is satisfied = or not. - - @retval EFI_SUCCESS Dependency Evaluation is successful. - @retval Others Dependency Evaluation fails with unexpe= cted error. - -**/ -EFI_STATUS -EvaluateImageDependencies ( - IN CONST EFI_GUID ImageTypeId, - IN CONST UINT32 Version, - IN CONST EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN CONST UINT32 DependenciesSize, - OUT BOOLEAN *IsSatisfied - ) -{ - EFI_STATUS Status; - EFI_HANDLE *HandleBuffer; - UINTN Index; - EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp; - UINTN ImageInfoSize; - UINT32 FmpImageInfoDescriptorVer; - UINT8 FmpImageInfoCount; - UINTN DescriptorSize; - UINT32 PackageVersion; - CHAR16 *PackageVersionName; - UINTN DepexSize; - - *IsSatisfied =3D TRUE; - PackageVersionName =3D NULL; - - // - // Get ImageDescriptors of all FMP instances, and archive them for depex= evaluation. - // - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareManagementProtocolGuid, - NULL, - &mNumberOfFmpInstance, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return EFI_ABORTED; - } - - mFmpImageInfoBuf =3D AllocateZeroPool (sizeof(EFI_FIRMWARE_IMAGE_DESCRIP= TOR *) * mNumberOfFmpInstance); - if (mFmpImageInfoBuf =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - for (Index =3D 0; Index < mNumberOfFmpInstance; Index ++) { - Status =3D gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareManagementProtocolGuid, - (VOID **) &Fmp - ); - if (EFI_ERROR(Status)) { - continue; - } - - ImageInfoSize =3D 0; - Status =3D Fmp->GetImageInfo ( - Fmp, - &ImageInfoSize, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - ); - if (Status !=3D EFI_BUFFER_TOO_SMALL) { - continue; - } - - mFmpImageInfoBuf[Index] =3D AllocateZeroPool (ImageInfoSize); - if (mFmpImageInfoBuf[Index] =3D=3D NULL) { - continue; - } - - Status =3D Fmp->GetImageInfo ( - Fmp, - &ImageInfoSize, // ImageInfoSize - mFmpImageInfoBuf[Index], // ImageInfo - &FmpImageInfoDescriptorVer, // DescriptorVersion - &FmpImageInfoCount, // DescriptorCount - &DescriptorSize, // DescriptorSize - &PackageVersion, // PackageVersion - &PackageVersionName // PackageVersionName - ); - if (EFI_ERROR(Status)) { - FreePool (mFmpImageInfoBuf[Index]); - mFmpImageInfoBuf[Index] =3D NULL; - continue; - } - - if (PackageVersionName !=3D NULL) { - FreePool (PackageVersionName); - PackageVersionName =3D NULL; - } - } - - // - // Step 1 - Evaluate firmware image's depex, against the version of othe= r Fmp instances. - // - if (Dependencies !=3D NULL) { - *IsSatisfied =3D EvaluateDependencies (Dependencies, DependenciesSize); - } - - if (!*IsSatisfied) { - goto cleanup; - } - - // - // Step 2 - Evaluate the depex of all other Fmp instances, against the n= ew version in - // the firmware image. - // - - // - // Update the new version to mFmpImageInfoBuf. - // - for (Index =3D 0; Index < mNumberOfFmpInstance; Index ++) { - if (mFmpImageInfoBuf[Index] !=3D NULL) { - if (CompareGuid (&ImageTypeId, &mFmpImageInfoBuf[Index]->ImageTypeId= )) { - mFmpImageInfoBuf[Index]->Version =3D Version; - break; - } - } - } - - // - // Evaluate the Dependencies one by one. - // - for (Index =3D 0; Index < mNumberOfFmpInstance; Index ++) { - if (mFmpImageInfoBuf[Index] !=3D NULL) { - // - // Skip the Fmp instance to be "SetImage". - // - if (CompareGuid (&ImageTypeId, &mFmpImageInfoBuf[Index]->ImageTypeId= )) { - continue; - } - if ((mFmpImageInfoBuf[Index]->AttributesSupported & IMAGE_ATTRIBUTE_= DEPENDENCY) && - mFmpImageInfoBuf[Index]->Dependencies !=3D NULL) { - // - // Get the size of depex. - // Assume that the dependencies in EFI_FIRMWARE_IMAGE_DESCRIPTOR i= s validated when PopulateDescriptor(). - // - DepexSize =3D GetDepexSize (mFmpImageInfoBuf[Index]->Dependencies); - if (DepexSize > 0) { - *IsSatisfied =3D EvaluateDependencies (mFmpImageInfoBuf[Index]->= Dependencies, DepexSize); - if (!*IsSatisfied) { - break; - } - } - } - } - } - -cleanup: - if (mFmpImageInfoBuf !=3D NULL) { - for (Index =3D 0; Index < mNumberOfFmpInstance; Index ++) { - if (mFmpImageInfoBuf[Index] !=3D NULL) { - FreePool (mFmpImageInfoBuf[Index]); - } - } - FreePool (mFmpImageInfoBuf); - } - - return EFI_SUCCESS; -} diff --git a/FmpDevicePkg/FmpDxe/Dependency.h b/FmpDevicePkg/FmpDxe/Depende= ncy.h deleted file mode 100644 index badd2542d6..0000000000 --- a/FmpDevicePkg/FmpDxe/Dependency.h +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - Fmp Capsule Dependency support functions for Firmware Management Protoco= l based - firmware updates. - - Copyright (c) 2020, Intel Corporation. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef __DEPENDENCY_H__ -#define __DEPENDENCY_H__ - -#include -#include - -#define DEPENDENCIES_SATISFIED 0 -#define DEPENDENCIES_UNSATISFIED 1 -#define DEPENDENCIES_INVALID 2 - -extern UINT8 mDependenciesCheckStatus; - -/** - Validate the dependency expression and output its size. - - @param[in] ImageDepex Pointer to the EFI_FIRMWARE_IMAGE_DEP. - @param[in] MaxDepexSize Max size of the dependency. - @param[out] DepexSize Size of dependency. - - @retval TRUE The capsule is valid. - @retval FALSE The capsule is invalid. - -**/ -BOOLEAN -ValidateImageDepex ( - IN EFI_FIRMWARE_IMAGE_DEP *ImageDepex, - IN CONST UINTN MaxDepexSize, - OUT UINT32 *DepexSize - ); - -/** - Check dependency for firmware update. - - @param[in] ImageTypeId Image Type Id. - @param[in] Version New version. - @param[in] Dependencies The dependencies. - @param[in] DepexSize Size of the dependencies - @param[out] IsSatisfied Indicate the dependencies is satisfied = or not. - - @retval EFI_SUCCESS Dependency Evaluation is successful. - @retval Others Dependency Evaluation fails with unexpe= cted error. - -**/ -EFI_STATUS -EvaluateImageDependencies ( - IN CONST EFI_GUID ImageTypeId, - IN CONST UINT32 Version, - IN CONST EFI_FIRMWARE_IMAGE_DEP *Dependencies, - IN CONST UINT32 DepexSize, - OUT BOOLEAN *IsSatisfied - ); - -#endif diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c index 5b523291e4..20b0d1b9c8 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.c +++ b/FmpDevicePkg/FmpDxe/FmpDxe.c @@ -10,11 +10,10 @@ =20 **/ =20 #include "FmpDxe.h" #include "VariableSupport.h" -#include "Dependency.h" =20 /// /// FILE_GUID from FmpDxe.inf. When FmpDxe.inf is used in a platform, the /// FILE_GUID must always be overridden in the section to provide /// the ESRT GUID value associated with the updatable firmware image. A @@ -79,11 +78,12 @@ const FIRMWARE_MANAGEMENT_PRIVATE_DATA mFirmwareManage= mentPrivateDataTemplate =3D NULL, // FmpDeviceContext NULL, // VersionVariableName NULL, // LsvVariableName NULL, // LastAttemptStatusVariabl= eName NULL, // LastAttemptVersionVariab= leName - NULL // FmpStateVariableName + NULL, // FmpStateVariableName + TRUE // DependenciesSatisfied }; =20 /// /// GUID that is used to create event used to lock the firmware storage de= vice. /// @@ -274,17 +274,10 @@ VOID PopulateDescriptor ( FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private ) { EFI_STATUS Status; - VOID *Image; - UINTN ImageSize; - BOOLEAN IsDepexValid; - UINT32 DepexSize; - - Image =3D NULL; - ImageSize =3D 0; =20 if (Private->DescriptorPopulated) { return; } =20 @@ -385,50 +378,22 @@ PopulateDescriptor ( =20 Private->Descriptor.LastAttemptVersion =3D GetLastAttemptVersionFromVari= able (Private); Private->Descriptor.LastAttemptStatus =3D GetLastAttemptStatusFromVaria= ble (Private); =20 // - // Get the dependency from the FmpDeviceLib and populate it to the descr= iptor. + // Get the dependency from the FmpDependencyDeviceLib. // Private->Descriptor.Dependencies =3D NULL; =20 // // Check the attribute IMAGE_ATTRIBUTE_DEPENDENCY // - if (Private->Descriptor.AttributesSupported & IMAGE_ATTRIBUTE_DEPENDENCY= ) { - // - // The parameter "Image" of FmpDeviceGetImage() is extended to contain= the dependency. - // Get the dependency from the Image. - // - ImageSize =3D Private->Descriptor.Size; - Image =3D AllocatePool (ImageSize); - if (Image !=3D NULL) { - Status =3D FmpDeviceGetImage (Image, &ImageSize); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - FreePool (Image); - Image =3D AllocatePool (ImageSize); - if (Image !=3D NULL) { - Status =3D FmpDeviceGetImage (Image, &ImageSize); - } - } - } - if (!EFI_ERROR (Status) && Image !=3D NULL) { - IsDepexValid =3D ValidateImageDepex ((EFI_FIRMWARE_IMAGE_DEP *) Imag= e, ImageSize, &DepexSize); - if (IsDepexValid) { - Private->Descriptor.Dependencies =3D AllocatePool (DepexSize); - if (Private->Descriptor.Dependencies !=3D NULL) { - CopyMem (Private->Descriptor.Dependencies->Dependencies, Image, = DepexSize); - } - } - } + if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) { + Private->Descriptor.Dependencies =3D GetFmpDependency (NULL); } =20 Private->DescriptorPopulated =3D TRUE; - - if (Image !=3D NULL) { - FreePool (Image); - } } =20 /** Returns information about the current firmware image(s) of the device. =20 @@ -586,21 +551,16 @@ GetTheImage ( ) { EFI_STATUS Status; FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private; UINTN Size; - UINT8 *ImageBuffer; - UINTN ImageBufferSize; - UINT32 DepexSize; =20 if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) { return EFI_UNSUPPORTED; } =20 - Status =3D EFI_SUCCESS; - ImageBuffer =3D NULL; - DepexSize =3D 0; + Status =3D EFI_SUCCESS; =20 // // Retrieve the private context structure // Private =3D FIRMWARE_MANAGEMENT_PRIVATE_DATA_FROM_THIS (This); @@ -626,49 +586,12 @@ GetTheImage ( // Status =3D FmpDeviceGetSize (&Size); if (EFI_ERROR (Status)) { Size =3D 0; } - - // - // The parameter "Image" of FmpDeviceGetImage() is extended to contain t= he dependency. - // Get the Fmp Payload from the Image. - // - ImageBufferSize =3D Size; - ImageBuffer =3D AllocatePool (ImageBufferSize); - if (ImageBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - AllocatePool fails.\n",= mImageIdName)); - Status =3D EFI_NOT_FOUND; - goto cleanup; - } - Status =3D FmpDeviceGetImage (ImageBuffer, &ImageBufferSize); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - FreePool (ImageBuffer); - ImageBuffer =3D AllocatePool (ImageBufferSize); - if (ImageBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - AllocatePool fails.\n= ", mImageIdName)); - Status =3D EFI_NOT_FOUND; - goto cleanup; - } - Status =3D FmpDeviceGetImage (ImageBuffer, &ImageBufferSize); - } - if (EFI_ERROR (Status)) { - goto cleanup; - } - - // - // Check the attribute IMAGE_ATTRIBUTE_DEPENDENCY - // - if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) { - // - // Validate the dependency to get its size. - // - ValidateImageDepex ((EFI_FIRMWARE_IMAGE_DEP *) ImageBuffer, ImageBuffe= rSize, &DepexSize); - } - - if (*ImageSize < ImageBufferSize - DepexSize) { - *ImageSize =3D ImageBufferSize - DepexSize; + if (*ImageSize < Size) { + *ImageSize =3D Size; DEBUG ((DEBUG_VERBOSE, "FmpDxe(%s): GetImage() - ImageSize is to small= .\n", mImageIdName)); Status =3D EFI_BUFFER_TOO_SMALL; goto cleanup; } =20 @@ -676,57 +599,50 @@ GetTheImage ( DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - Image Pointer Parameter= is NULL.\n", mImageIdName)); Status =3D EFI_INVALID_PARAMETER; goto cleanup; } =20 - // - // Image is after the dependency expression. - // - *ImageSize =3D ImageBufferSize - DepexSize; - CopyMem (Image, ImageBuffer + DepexSize, *ImageSize); - Status =3D EFI_SUCCESS; - + Status =3D FmpDeviceGetImage (Image, ImageSize); cleanup: - if (ImageBuffer !=3D NULL) { - FreePool (ImageBuffer); - } =20 return Status; } =20 /** Helper function to safely retrieve the FMP header from within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure. =20 - @param[in] Image Pointer to the image. - @param[in] ImageSize Size of the image. + @param[in] Image Pointer to the image. + @param[in] ImageSize Size of the image. + @param[in] AdditionalHeaderSize Size of any headers that cannot be ca= lculated by this function. @param[out] PayloadSize =20 @retval !NULL Valid pointer to the header. @retval NULL Structure is bad and pointer cannot be found. =20 **/ VOID * GetFmpHeader ( IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN CONST UINTN ImageSize, + IN CONST UINTN AdditionalHeaderSize, OUT UINTN *PayloadSize ) { // // Check to make sure that operation can be safely performed. // - if (((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr= .dwLength) < (UINTN)Image || \ - ((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr= .dwLength) >=3D (UINTN)Image + ImageSize) { + if (((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr= .dwLength) + AdditionalHeaderSize < (UINTN)Image || \ + ((UINTN)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr= .dwLength) + AdditionalHeaderSize >=3D (UINTN)Image + ImageSize) { // // Pointer overflow. Invalid image. // return NULL; } =20 - *PayloadSize =3D ImageSize - (sizeof (Image->MonotonicCount) + Image->Au= thInfo.Hdr.dwLength); - return (VOID *)((UINT8 *)Image + sizeof (Image->MonotonicCount) + Image-= >AuthInfo.Hdr.dwLength); + *PayloadSize =3D ImageSize - (sizeof (Image->MonotonicCount) + Image->Au= thInfo.Hdr.dwLength + AdditionalHeaderSize); + return (VOID *)((UINT8 *)Image + sizeof (Image->MonotonicCount) + Image-= >AuthInfo.Hdr.dwLength + AdditionalHeaderSize); } =20 /** Helper function to safely calculate the size of all headers within an EFI_FIRMWARE_IMAGE_AUTHENTICATION structure. @@ -809,12 +725,10 @@ CheckTheImage ( UINTN PublicKeyDataLength; UINT8 *PublicKeyDataXdr; UINT8 *PublicKeyDataXdrEnd; EFI_FIRMWARE_IMAGE_DEP *Dependencies; UINT32 DependenciesSize; - BOOLEAN IsDepexValid; - BOOLEAN IsDepexSatisfied; =20 Status =3D EFI_SUCCESS; RawSize =3D 0; FmpPayloadHeader =3D NULL; FmpPayloadSize =3D 0; @@ -848,10 +762,15 @@ CheckTheImage ( // //Set to valid and then if any tests fail it will update this flag. // *ImageUpdatable =3D IMAGE_UPDATABLE_VALID; =20 + // + // Set to satisfied and then if dependency evaluates to false it will up= date this flag. + // + Private->DependenciesSatisfied =3D TRUE; + if (Image =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Pointer Paramet= er is NULL.\n", mImageIdName)); // // not sure if this is needed // @@ -933,49 +852,30 @@ CheckTheImage ( *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID_TYPE; Status =3D EFI_SUCCESS; goto cleanup; } =20 + // + // Get the dependency from Image. + // + Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); =20 // // Check the FmpPayloadHeader // - FmpPayloadHeader =3D GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *= )Image, ImageSize, &FmpPayloadSize ); + FmpPayloadHeader =3D GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *= )Image, ImageSize, DependenciesSize, &FmpPayloadSize ); if (FmpPayloadHeader =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpHeader faile= d.\n", mImageIdName)); Status =3D EFI_ABORTED; goto cleanup; } Status =3D GetFmpPayloadHeaderVersion (FmpPayloadHeader, FmpPayloadSize,= &Version); if (EFI_ERROR (Status)) { - // - // Check if there is dependency expression - // - IsDepexValid =3D ValidateImageDepex ((EFI_FIRMWARE_IMAGE_DEP*) FmpPayl= oadHeader, FmpPayloadSize, &DependenciesSize); - if (IsDepexValid && (DependenciesSize < FmpPayloadSize)) { - // - // Fmp payload is after dependency expression - // - Dependencies =3D (EFI_FIRMWARE_IMAGE_DEP*) FmpPayloadHeader; - FmpPayloadHeader =3D (UINT8 *) Dependencies + DependenciesSize; - FmpPayloadSize =3D FmpPayloadSize - DependenciesSize; - Status =3D GetFmpPayloadHeaderVersion (FmpPayloadHeader, FmpPayloadS= ize, &Version); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpPayloadH= eaderVersion failed %r.\n", mImageIdName, Status)); - *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; - Status =3D EFI_SUCCESS; - goto cleanup; - } - } else { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency is in= valid.\n", mImageIdName)); - mDependenciesCheckStatus =3D DEPENDENCIES_INVALID; - *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; - Status =3D EFI_SUCCESS; - goto cleanup; - } - } else { - DEBUG ((DEBUG_WARN, "FmpDxe(%s): CheckTheImage() - No dependency assoc= iated in image.\n", mImageIdName)); + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - GetFmpPayloadHeade= rVersion failed %r.\n", mImageIdName, Status)); + *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; + Status =3D EFI_SUCCESS; + goto cleanup; } =20 // // Check the lowest supported version // @@ -991,18 +891,13 @@ CheckTheImage ( } =20 // // Evaluate dependency expression // - Status =3D EvaluateImageDependencies (Private->Descriptor.ImageTypeId, V= ersion, Dependencies, DependenciesSize, &IsDepexSatisfied); - if (!IsDepexSatisfied || EFI_ERROR (Status)) { - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check= failed %r.\n", mImageIdName, Status)); - } else { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency is no= t satisfied.\n", mImageIdName)); - } - mDependenciesCheckStatus =3D DEPENDENCIES_UNSATISFIED; + Private->DependenciesSatisfied =3D CheckFmpDependency (Private->Descript= or.ImageTypeId, Version, Dependencies, DependenciesSize); + if (!Private->DependenciesSatisfied) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckTheImage() - Dependency check f= ailed.\n", mImageIdName)); *ImageUpdatable =3D IMAGE_UPDATABLE_INVALID; Status =3D EFI_SUCCESS; goto cleanup; } =20 @@ -1111,13 +1006,10 @@ SetTheImage ( UINT32 LastAttemptStatus; UINT32 Version; UINT32 LowestSupportedVersion; EFI_FIRMWARE_IMAGE_DEP *Dependencies; UINT32 DependenciesSize; - BOOLEAN IsDepexValid; - UINT8 *ImageBuffer; - UINTN ImageBufferSize; =20 Status =3D EFI_SUCCESS; Updateable =3D 0; BooleanValue =3D FALSE; FmpHeaderSize =3D 0; @@ -1126,12 +1018,10 @@ SetTheImage ( AllHeaderSize =3D 0; IncomingFwVersion =3D 0; LastAttemptStatus =3D LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; Dependencies =3D NULL; DependenciesSize =3D 0; - ImageBuffer =3D NULL; - ImageBufferSize =3D 0; =20 if (!FeaturePcdGet (PcdFmpDeviceStorageAccessEnable)) { return EFI_UNSUPPORTED; } =20 @@ -1159,15 +1049,10 @@ SetTheImage ( DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Device is already lo= cked. Can't update.\n", mImageIdName)); Status =3D EFI_UNSUPPORTED; goto cleanup; } =20 - // - // Set check status to satisfied before CheckTheImage() - // - mDependenciesCheckStatus =3D DEPENDENCIES_SATISFIED; - // // Call check image to verify the image // Status =3D CheckTheImage (This, ImageIndex, Image, ImageSize, &Updateabl= e); if (EFI_ERROR (Status)) { @@ -1176,36 +1061,26 @@ SetTheImage ( LastAttemptStatus =3D LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR; } goto cleanup; } =20 + // + // Get the dependency from Image. + // + Dependencies =3D GetImageDependency ((EFI_FIRMWARE_IMAGE_AUTHENTICATION = *)Image, ImageSize, &DependenciesSize); + // // No functional error in CheckTheImage. Attempt to get the Version to // support better error reporting. // - FmpHeader =3D GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image,= ImageSize, &FmpPayloadSize ); + FmpHeader =3D GetFmpHeader ( (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image,= ImageSize, DependenciesSize, &FmpPayloadSize ); if (FmpHeader =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetFmpHeader failed.= \n", mImageIdName)); Status =3D EFI_ABORTED; goto cleanup; } Status =3D GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &Incom= ingFwVersion); - if (EFI_ERROR (Status)) { - // - // Check if there is dependency expression - // - IsDepexValid =3D ValidateImageDepex ((EFI_FIRMWARE_IMAGE_DEP*) FmpHead= er, FmpPayloadSize, &DependenciesSize); - if (IsDepexValid && (DependenciesSize < FmpPayloadSize)) { - // - // Fmp payload is after dependency expression - // - Dependencies =3D (EFI_FIRMWARE_IMAGE_DEP*) FmpHeader; - FmpHeader =3D (UINT8 *) FmpHeader + DependenciesSize; - FmpPayloadSize =3D FmpPayloadSize - DependenciesSize; - Status =3D GetFmpPayloadHeaderVersion (FmpHeader, FmpPayloadSize, &I= ncomingFwVersion); - } - } if (!EFI_ERROR (Status)) { // // Set to actual value // SetLastAttemptVersionInVariable (Private, IncomingFwVersion); @@ -1216,14 +1091,12 @@ SetTheImage ( DEBUG ( (DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - Check The Image returned that the Image= was not valid for update. Updatable value =3D 0x%X.\n", mImageIdName, Updateable) ); - if (mDependenciesCheckStatus =3D=3D DEPENDENCIES_UNSATISFIED) { + if (Private->DependenciesSatisfied =3D=3D FALSE) { LastAttemptStatus =3D LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDEN= CIES; - } else if (mDependenciesCheckStatus =3D=3D DEPENDENCIES_INVALID) { - LastAttemptStatus =3D LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT; } Status =3D EFI_ABORTED; goto cleanup; } =20 @@ -1321,59 +1194,41 @@ SetTheImage ( DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - GetAllHeaderSize fai= led.\n", mImageIdName)); Status =3D EFI_ABORTED; goto cleanup; } =20 - // - // Check the attribute IMAGE_ATTRIBUTE_DEPENDENCY - // - if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) { - // - // To support saving dependency, extend param "Image" of FmpDeviceSetI= mage() to - // contain the dependency inside. FmpDeviceSetImage() is responsible f= or saving - // the dependency which can be used for future dependency check. - // - ImageBufferSize =3D DependenciesSize + ImageSize - AllHeaderSize; - ImageBuffer =3D AllocatePool (ImageBufferSize); - if (ImageBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - AllocatePool faile= d.\n", mImageIdName)); - Status =3D EFI_ABORTED; - goto cleanup; - } - CopyMem (ImageBuffer, Dependencies->Dependencies, DependenciesSize); - CopyMem (ImageBuffer + DependenciesSize, (UINT8 *)Image + AllHeaderSiz= e, ImageBufferSize - DependenciesSize); - } else { - ImageBufferSize =3D ImageSize - AllHeaderSize; - ImageBuffer =3D AllocateCopyPool(ImageBufferSize, (UINT8 *)Image + All= HeaderSize); - if (ImageBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - AllocatePool faile= d.\n", mImageIdName)); - Status =3D EFI_ABORTED; - goto cleanup; - } - } - // // Indicate that control is handed off to FmpDeviceLib // Progress (5); =20 // //Copy the requested image to the firmware using the FmpDeviceLib // Status =3D FmpDeviceSetImage ( - ImageBuffer, - ImageBufferSize, + (((UINT8 *)Image) + AllHeaderSize), + ImageSize - AllHeaderSize, VendorCode, FmpDxeProgress, IncomingFwVersion, AbortReason ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SetImage from FmpDevic= eLib failed. Status =3D %r.\n", mImageIdName, Status)); goto cleanup; } =20 + // + // Store the dependency + // + if (Private->Descriptor.AttributesSetting & IMAGE_ATTRIBUTE_DEPENDENCY) { + Status =3D SaveFmpDependency (Dependencies, DependenciesSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() SaveFmpDependency fr= om FmpDependencyCheckLib failed. (%r)\n", mImageIdName, Status)); + } + Status =3D EFI_SUCCESS; + } =20 // // Finished the update without error // Indicate that control has been returned from FmpDeviceLib // @@ -1396,14 +1251,10 @@ SetTheImage ( SetLowestSupportedVersionInVariable (Private, LowestSupportedVersion); =20 LastAttemptStatus =3D LAST_ATTEMPT_STATUS_SUCCESS; =20 cleanup: - if (ImageBuffer !=3D NULL) { - FreePool (ImageBuffer); - } - mProgressFunc =3D NULL; SetLastAttemptStatusInVariable (Private, LastAttemptStatus); =20 if (Progress !=3D NULL) { // diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.h b/FmpDevicePkg/FmpDxe/FmpDxe.h index 150f18b656..30754dea49 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.h +++ b/FmpDevicePkg/FmpDxe/FmpDxe.h @@ -26,10 +26,13 @@ #include #include #include #include #include +#include +#include +#include #include #include #include #include #include @@ -64,10 +67,11 @@ typedef struct { CHAR16 *VersionVariableName; CHAR16 *LsvVariableName; CHAR16 *LastAttemptStatusVariableN= ame; CHAR16 *LastAttemptVersionVariable= Name; CHAR16 *FmpStateVariableName; + BOOLEAN DependenciesSatisfied; } FIRMWARE_MANAGEMENT_PRIVATE_DATA; =20 /// /// /// diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.inf b/FmpDevicePkg/FmpDxe/FmpDxe.inf index 97b6518fa1..eeb904a091 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.inf +++ b/FmpDevicePkg/FmpDxe/FmpDxe.inf @@ -26,12 +26,10 @@ # =20 [Sources] FmpDxe.c FmpDxe.h - Dependency.c - Dependency.h DetectTestKey.c VariableSupport.h VariableSupport.c =20 [Packages] @@ -52,10 +50,13 @@ BaseCryptLib FmpAuthenticationLib FmpDeviceLib FmpPayloadHeaderLib CapsuleUpdatePolicyLib + FmpDependencyLib + FmpDependencyCheckLib + FmpDependencyDeviceLib =20 [Guids] gEfiEndOfDxeEventGroupGuid =20 [Protocols] diff --git a/FmpDevicePkg/FmpDxe/FmpDxeLib.inf b/FmpDevicePkg/FmpDxe/FmpDxe= Lib.inf index de005b6892..9a93b5e6ac 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxeLib.inf +++ b/FmpDevicePkg/FmpDxe/FmpDxeLib.inf @@ -27,12 +27,10 @@ # =20 [Sources] FmpDxe.c FmpDxe.h - Dependency.c - Dependency.h DetectTestKey.c VariableSupport.h VariableSupport.c =20 [Packages] @@ -52,10 +50,13 @@ BaseCryptLib FmpAuthenticationLib FmpDeviceLib FmpPayloadHeaderLib CapsuleUpdatePolicyLib + FmpDependencyLib + FmpDependencyCheckLib + FmpDependencyDeviceLib =20 [Guids] gEfiEndOfDxeEventGroupGuid =20 [Protocols] --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#59268): https://edk2.groups.io/g/devel/message/59268 Mute This Topic: https://groups.io/mt/74156366/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-