From nobody Wed Apr 24 14:34:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1532940869346508.7581303117878; Mon, 30 Jul 2018 01:54:29 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 54815210C515C; Mon, 30 Jul 2018 01:54:28 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 80CD6210C42D8 for ; Mon, 30 Jul 2018 01:54:26 -0700 (PDT) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2018 01:54:26 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga007.fm.intel.com with ESMTP; 30 Jul 2018 01:54:24 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,422,1526367600"; d="scan'208";a="58217378" From: Star Zeng To: edk2-devel@lists.01.org Date: Mon, 30 Jul 2018 16:54:24 +0800 Message-Id: <1532940864-29952-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg DxeCapsuleLib: Use Attr to know whether reset is required X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current DxeCapsuleLibFmp always do reset for FMP capsule. Actually, the code should use Attributes from FMP descriptor to know whether reset is required or not. Cc: Jiewen Yao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Jiewen.yao@intel.com --- .../Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 134 ++++++++++++++++-= ---- .../DxeCapsuleLibFmp/DxeCapsuleProcessLib.c | 40 ++++-- 2 files changed, 134 insertions(+), 40 deletions(-) diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeMod= ulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c index e88dab8c7642..d00d7d88ff7d 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c @@ -620,11 +620,14 @@ DumpAllFmpInfo ( =20 @param[in] UpdateImageTypeId Used to identify device firmware = targeted by this update. @param[in] UpdateHardwareInstance The HardwareInstance to target wi= th this update. - @param[in,out] NoHandles The number of handles returned in= Buffer. - @param[out] Buffer[out] A pointer to the buffer to return= the requested array of handles. - - @retval EFI_SUCCESS The array of handles was returned in Buff= er, and the number of - handles in Buffer was returned in NoHandl= es. + @param[out] NoHandles The number of handles returned in= HandleBuf. + @param[out] HandleBuf A pointer to the buffer to return= the requested array of handles. + @param[out] ResetRequiredBuf A pointer to the buffer to return= reset required flag for + the requested array of handles. + + @retval EFI_SUCCESS The array of handles and their reset requ= ired flag were returned in + HandleBuf and ResetRequiredBuf, and the n= umber of handles in HandleBuf + was returned in NoHandles. @retval EFI_NOT_FOUND No handles match the search. @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store = the matching results. **/ @@ -632,14 +635,16 @@ EFI_STATUS GetFmpHandleBufferByType ( IN EFI_GUID *UpdateImageTypeId, IN UINT64 UpdateHardwareInstance, - IN OUT UINTN *NoHandles, - OUT EFI_HANDLE **Buffer + OUT UINTN *NoHandles, OPTIONAL + OUT EFI_HANDLE **HandleBuf, OPTIONAL + OUT BOOLEAN **ResetRequiredBuf OPTIONAL ) { EFI_STATUS Status; EFI_HANDLE *HandleBuffer; UINTN NumberOfHandles; EFI_HANDLE *MatchedHandleBuffer; + BOOLEAN *MatchedResetRequiredBuffe= r; UINTN MatchedNumberOfHandles; EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp; UINTN Index; @@ -653,8 +658,15 @@ GetFmpHandleBufferByType ( UINTN Index2; EFI_FIRMWARE_IMAGE_DESCRIPTOR *TempFmpImageInfo; =20 - *NoHandles =3D 0; - *Buffer =3D NULL; + if (NoHandles !=3D NULL) { + *NoHandles =3D 0; + } + if (HandleBuf !=3D NULL) { + *HandleBuf =3D NULL; + } + if (ResetRequiredBuf !=3D NULL) { + *ResetRequiredBuf =3D NULL; + } =20 Status =3D gBS->LocateHandleBuffer ( ByProtocol, @@ -668,10 +680,26 @@ GetFmpHandleBufferByType ( } =20 MatchedNumberOfHandles =3D 0; - MatchedHandleBuffer =3D AllocateZeroPool (sizeof(EFI_HANDLE) * NumberOfH= andles); - if (MatchedHandleBuffer =3D=3D NULL) { - FreePool (HandleBuffer); - return EFI_OUT_OF_RESOURCES; + + MatchedHandleBuffer =3D NULL; + if (HandleBuf !=3D NULL) { + MatchedHandleBuffer =3D AllocateZeroPool (sizeof(EFI_HANDLE) * NumberO= fHandles); + if (MatchedHandleBuffer =3D=3D NULL) { + FreePool (HandleBuffer); + return EFI_OUT_OF_RESOURCES; + } + } + + MatchedResetRequiredBuffer =3D NULL; + if (ResetRequiredBuf !=3D NULL) { + MatchedResetRequiredBuffer =3D AllocateZeroPool (sizeof(BOOLEAN) * Num= berOfHandles); + if (MatchedResetRequiredBuffer =3D=3D NULL) { + if (MatchedHandleBuffer !=3D NULL) { + FreePool (MatchedHandleBuffer); + } + FreePool (HandleBuffer); + return EFI_OUT_OF_RESOURCES; + } } =20 for (Index =3D 0; Index < NumberOfHandles; Index++) { @@ -733,7 +761,15 @@ GetFmpHandleBufferByType ( if ((UpdateHardwareInstance =3D=3D 0) || ((FmpImageInfoDescriptorVer >=3D EFI_FIRMWARE_IMAGE_DESCRIPTOR= _VERSION) && (UpdateHardwareInstance =3D=3D TempFmpImageInfo->HardwareInst= ance))) { - MatchedHandleBuffer[MatchedNumberOfHandles] =3D HandleBuffer[Ind= ex]; + if (MatchedHandleBuffer !=3D NULL) { + MatchedHandleBuffer[MatchedNumberOfHandles] =3D HandleBuffer[I= ndex]; + } + if (MatchedResetRequiredBuffer !=3D NULL) { + MatchedResetRequiredBuffer[MatchedNumberOfHandles] =3D (((Temp= FmpImageInfo->AttributesSupported &=20 + IMAGE_ATT= RIBUTE_RESET_REQUIRED) !=3D 0) && + ((TempFmp= ImageInfo->AttributesSetting & + IMAGE_ATT= RIBUTE_RESET_REQUIRED) !=3D 0)); + } MatchedNumberOfHandles++; break; } @@ -749,8 +785,15 @@ GetFmpHandleBufferByType ( return EFI_NOT_FOUND; } =20 - *NoHandles =3D MatchedNumberOfHandles; - *Buffer =3D MatchedHandleBuffer; + if (NoHandles !=3D NULL) { + *NoHandles =3D MatchedNumberOfHandles; + } + if (HandleBuf !=3D NULL) { + *HandleBuf =3D MatchedHandleBuffer; + } + if (ResetRequiredBuf !=3D NULL) { + *ResetRequiredBuf =3D MatchedResetRequiredBuffer; + } =20 return EFI_SUCCESS; } @@ -1078,7 +1121,8 @@ RecordFmpCapsuleStatus ( =20 This function need support nested FMP capsule. =20 - @param[in] CapsuleHeader Points to a capsule header. + @param[in] CapsuleHeader Points to a capsule header. + @param[out] ResetRequired Indicates whether reset is required or= not. =20 @retval EFI_SUCESS Process Capsule Image successfully. @retval EFI_UNSUPPORTED Capsule image is not supported by the firm= ware. @@ -1088,7 +1132,8 @@ RecordFmpCapsuleStatus ( **/ EFI_STATUS ProcessFmpCapsuleImage ( - IN EFI_CAPSULE_HEADER *CapsuleHeader + IN EFI_CAPSULE_HEADER *CapsuleHeader, + OUT BOOLEAN *ResetRequired OPTIONAL ) { EFI_STATUS Status; @@ -1098,6 +1143,7 @@ ProcessFmpCapsuleImage ( UINT32 ItemNum; UINTN Index; EFI_HANDLE *HandleBuffer; + BOOLEAN *ResetRequiredBuffer; UINTN NumberOfHandles; UINTN DriverLen; UINT64 UpdateHardwareInstance; @@ -1106,7 +1152,7 @@ ProcessFmpCapsuleImage ( BOOLEAN Abort; =20 if (!IsFmpCapsuleGuid(&CapsuleHeader->CapsuleGuid)) { - return ProcessFmpCapsuleImage ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHe= ader + CapsuleHeader->HeaderSize)); + return ProcessFmpCapsuleImage ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHe= ader + CapsuleHeader->HeaderSize), ResetRequired); } =20 NotReady =3D FALSE; @@ -1176,7 +1222,8 @@ ProcessFmpCapsuleImage ( &ImageHeader->UpdateImageTypeId, UpdateHardwareInstance, &NumberOfHandles, - &HandleBuffer + &HandleBuffer, + &ResetRequiredBuffer ); if (EFI_ERROR(Status)) { NotReady =3D TRUE; @@ -1209,6 +1256,10 @@ ProcessFmpCapsuleImage ( ); if (Status !=3D EFI_SUCCESS) { Abort =3D TRUE; + } else { + if (ResetRequired !=3D NULL) { + *ResetRequired |=3D ResetRequiredBuffer[Index2]; + } } =20 RecordFmpCapsuleStatus ( @@ -1222,6 +1273,9 @@ ProcessFmpCapsuleImage ( if (HandleBuffer !=3D NULL) { FreePool(HandleBuffer); } + if (ResetRequiredBuffer !=3D NULL) { + FreePool(ResetRequiredBuffer); + } } =20 if (NotReady) { @@ -1256,8 +1310,6 @@ IsNestedFmpCapsule ( UINTN NestedCapsuleSize; ESRT_MANAGEMENT_PROTOCOL *EsrtProtocol; EFI_SYSTEM_RESOURCE_ENTRY Entry; - EFI_HANDLE *HandleBuffer; - UINTN NumberOfHandles; =20 EsrtGuidFound =3D FALSE; if (mIsVirtualAddrConverted) { @@ -1286,19 +1338,16 @@ IsNestedFmpCapsule ( // Check Firmware Management Protocols // if (!EsrtGuidFound) { - HandleBuffer =3D NULL; Status =3D GetFmpHandleBufferByType ( &CapsuleHeader->CapsuleGuid, 0, - &NumberOfHandles, - &HandleBuffer + NULL, + NULL, + NULL ); if (!EFI_ERROR(Status)) { EsrtGuidFound =3D TRUE; } - if (HandleBuffer !=3D NULL) { - FreePool (HandleBuffer); - } } } if (!EsrtGuidFound) { @@ -1386,6 +1435,7 @@ SupportCapsuleImage ( Caution: This function may receive untrusted input. =20 @param[in] CapsuleHeader Points to a capsule header. + @param[out] ResetRequired Indicates whether reset is required or= not. =20 @retval EFI_SUCESS Process Capsule Image successfully. @retval EFI_UNSUPPORTED Capsule image is not supported by the firm= ware. @@ -1394,8 +1444,9 @@ SupportCapsuleImage ( **/ EFI_STATUS EFIAPI -ProcessCapsuleImage ( - IN EFI_CAPSULE_HEADER *CapsuleHeader +ProcessThisCapsuleImage ( + IN EFI_CAPSULE_HEADER *CapsuleHeader, + OUT BOOLEAN *ResetRequired OPTIONAL ) { EFI_STATUS Status; @@ -1432,7 +1483,7 @@ ProcessCapsuleImage ( // Process EFI FMP Capsule // DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage ...\n")); - Status =3D ProcessFmpCapsuleImage(CapsuleHeader); + Status =3D ProcessFmpCapsuleImage(CapsuleHeader, ResetRequired); DEBUG((DEBUG_INFO, "ProcessFmpCapsuleImage - %r\n", Status)); =20 return Status; @@ -1442,6 +1493,27 @@ ProcessCapsuleImage ( } =20 /** + The firmware implements to process the capsule image. + + Caution: This function may receive untrusted input. + + @param[in] CapsuleHeader Points to a capsule header. + + @retval EFI_SUCESS Process Capsule Image successfully. + @retval EFI_UNSUPPORTED Capsule image is not supported by the firm= ware. + @retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted. + @retval EFI_OUT_OF_RESOURCES Not enough memory. +**/ +EFI_STATUS +EFIAPI +ProcessCapsuleImage ( + IN EFI_CAPSULE_HEADER *CapsuleHeader + ) +{ + return ProcessThisCapsuleImage (CapsuleHeader, NULL); +} + +/** Callback function executed when the EndOfDxe event group is signaled. =20 @param[in] Event Event whose notification function is being invoked. diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c b= /MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c index 26ca4e295f20..176dea196026 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c @@ -99,13 +99,33 @@ IsValidCapsuleHeader ( ); =20 extern BOOLEAN mDxeCapsuleLibEndOfDxe; -BOOLEAN mNeedReset; +BOOLEAN mNeedReset =3D FALSE; =20 VOID **mCapsulePtr; EFI_STATUS *mCapsuleStatusArray; UINT32 mCapsuleTotalNumber; =20 /** + The firmware implements to process the capsule image. + + Caution: This function may receive untrusted input. + + @param[in] CapsuleHeader Points to a capsule header. + @param[out] ResetRequired Indicates whether reset is required or= not. + + @retval EFI_SUCESS Process Capsule Image successfully. + @retval EFI_UNSUPPORTED Capsule image is not supported by the firm= ware. + @retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted. + @retval EFI_OUT_OF_RESOURCES Not enough memory. +**/ +EFI_STATUS +EFIAPI +ProcessThisCapsuleImage ( + IN EFI_CAPSULE_HEADER *CapsuleHeader, + OUT BOOLEAN *ResetRequired OPTIONAL + ); + +/** Function indicate the current completion progress of the firmware update. Platform may override with own specific progress function. =20 @@ -381,6 +401,7 @@ ProcessTheseCapsules ( UINT32 Index; ESRT_MANAGEMENT_PROTOCOL *EsrtManagement; UINT16 EmbeddedDriverCount; + BOOLEAN ResetRequired; =20 REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32(PcdStatus= CodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeProcessCapsulesBegin))); =20 @@ -416,11 +437,11 @@ ProcessTheseCapsules ( for (Index =3D 0; Index < mCapsuleTotalNumber; Index++) { CapsuleHeader =3D (EFI_CAPSULE_HEADER*) mCapsulePtr [Index]; if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid))= { - DEBUG ((DEBUG_INFO, "ProcessCapsuleImage (Ux) - 0x%x\n", CapsuleHead= er)); + DEBUG ((DEBUG_INFO, "ProcessThisCapsuleImage (Ux) - 0x%x\n", Capsule= Header)); DEBUG ((DEBUG_INFO, "Display logo capsule is found.\n")); - Status =3D ProcessCapsuleImage (CapsuleHeader); + Status =3D ProcessThisCapsuleImage (CapsuleHeader, NULL); mCapsuleStatusArray [Index] =3D EFI_SUCCESS; - DEBUG((DEBUG_INFO, "ProcessCapsuleImage (Ux) - %r\n", Status)); + DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage (Ux) - %r\n", Status)); break; } } @@ -454,10 +475,11 @@ ProcessTheseCapsules ( } =20 if ((!FirstRound) || (EmbeddedDriverCount =3D=3D 0)) { - DEBUG((DEBUG_INFO, "ProcessCapsuleImage - 0x%x\n", CapsuleHeader)); - Status =3D ProcessCapsuleImage (CapsuleHeader); + DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - 0x%x\n", CapsuleHead= er)); + ResetRequired =3D FALSE; + Status =3D ProcessThisCapsuleImage (CapsuleHeader, &ResetRequired); mCapsuleStatusArray [Index] =3D Status; - DEBUG((DEBUG_INFO, "ProcessCapsuleImage - %r\n", Status)); + DEBUG((DEBUG_INFO, "ProcessThisCapsuleImage - %r\n", Status)); =20 if (Status !=3D EFI_NOT_READY) { if (EFI_ERROR(Status)) { @@ -467,8 +489,8 @@ ProcessTheseCapsules ( REPORT_STATUS_CODE(EFI_PROGRESS_CODE, (EFI_SOFTWARE | PcdGet32= (PcdStatusCodeSubClassCapsule) | PcdGet32(PcdCapsuleStatusCodeUpdateFirmwar= eSuccess))); } =20 - if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsule= ProcessFlag)) !=3D 0 || - IsFmpCapsule(CapsuleHeader)) { + mNeedReset |=3D ResetRequired; + if ((CapsuleHeader->Flags & PcdGet16(PcdSystemRebootAfterCapsule= ProcessFlag)) !=3D 0) { mNeedReset =3D TRUE; } } --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel