From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web10.3465.1635815807771630728 for ; Mon, 01 Nov 2021 18:16:48 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: byosoft.com.cn, ip: 58.240.74.242, mailfrom: gaoliming@byosoft.com.cn) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Tue, 02 Nov 2021 09:16:45 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Jian J Wang'" , "'Guomin Jiang'" References: <00a801d7cc68$50cebc70$f26c3550$@byosoft.com.cn> In-Reply-To: Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIXSBNZGVNb2R1bGVQa2cvRHhlQ2Fwc3VsZUxpYkZtcDogQWRkIHJ1bnRpbWUgU2V0SW1hZ2Ugc3VwcG9ydA==?= Date: Tue, 2 Nov 2021 09:16:45 +0800 Message-ID: <002c01d7cf87$4db94100$e92bc300$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQGSw+bLO15ASmQRcQPL/nMzpUPusgLyZ9l1AW2jyHasVoYJ4A== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Bob: Thanks for your detail. PcdRuntimeFmpCapsuleImageTypeIdGuid is edk2 imple= mentation solution. Have you the proposal on how to update UEFI spec to sup= port runtime FMP protocol? Thanks Liming > -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io = =E4=BB=A3=E8=A1=A8 Bob Morgan > via groups.io > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2021=E5=B9=B410=E6=9C=8830=E6=97=A5= 1:59 > =E6=94=B6=E4=BB=B6=E4=BA=BA: gaoliming ; devel@= edk2.groups.io > =E6=8A=84=E9=80=81: 'Jian J Wang' ; 'Guomin Jiang' > > =E4=B8=BB=E9=A2=98: Re: [edk2-devel] [PATCH] MdeModulePkg/DxeCapsuleLibFm= p: Add > runtime SetImage support >=20 > Hi Liming, See inline below. >=20 > > -----Original Message----- > > From: gaoliming > > Sent: Thursday, October 28, 2021 7:57 PM > > To: devel@edk2.groups.io; Bob Morgan > > Cc: 'Jian J Wang' ; 'Guomin Jiang' > > > > Subject: =E5=9B=9E=E5=A4=8D: [edk2-devel] [PATCH] MdeModulePkg/DxeCapsu= leLibFmp: > > Add runtime SetImage support > > > > External email: Use caution opening links or attachments > > > > > > Bob: > > I think this patch needs to work together with the changes of > > FmpDevicePkg: Add support for runtime FmpDxe driver. >=20 > Yes, this patch adds support to process FMP capsules at runtime if the > capsule=E2=80=99s UpdateImageTypeId is supported by a runtime-capable Fmp= Dxe > driver (e.g. using the FmpDevicePkg patch you mentioned). The > PcdSupportProcessCapsuleAtRuntime PCD must be TRUE and the capsule=E2=80= =99s > CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag must be FALSE. > > > > Capsule is runtime service. If it consumes FMP to do update, FMP serv= ice > > can support runtime. But, how does Capsule know whether FMP protocol > > supports runtime or not? >=20 > Right, this patch requires an implementation to list the FMP ImageTypeId > GUIDs supported by any runtime-capable FmpDxe drivers in the new > PcdRuntimeFmpCapsuleImageTypeIdGuid array PCD. This PCD is used by > the new InitializeRuntimeFmpArrays() function during > DxeRuntimeCapsuleLib initialization to find the FMP instances that suppor= t > those ImageTypeIds and save their > EFI_FIRMWARE_MANAGEMENT_PROTOCOL protocol structure pointers for > runtime use during capsule processing. >=20 > When ProcessFmpCapsuleImage() executes its step =E2=80=982. Route payload= to right > FMP instance=E2=80=99, it detects runtime execution and uses the saved > runtime-capable FMP protocol structure pointer if its ImageTypeId matches > that of the capsule being processed. >=20 > I hope that helps. Please let me know if additional clarification is nee= ded. >=20 > Thanks, > -bob > > > > Thanks > > Liming > > > -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > > > =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io =E4=BB=A3=E8=A1=A8 Bob > Morgan > > via > > > groups.io > > > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2021=E5=B9=B410=E6=9C=8820=E6= =97=A5 4:11 > > > =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io > > > =E6=8A=84=E9=80=81: Bob Morgan ; Jian J Wang > > ; > > > Liming Gao ; Guomin Jiang > > > > > > =E4=B8=BB=E9=A2=98: [edk2-devel] [PATCH] MdeModulePkg/DxeCapsuleLibFm= p: Add > > runtime > > > SetImage support > > > > > > Adds optional support for processing FMP capusle images after > > > ExitBootServices() if the ImageTypeIdGuid is mentioned in the new > > > PcdRuntimeFmpCapsuleImageTypeIdGuid list. > > > > > > Cc: Jian J Wang > > > Cc: Liming Gao > > > Cc: Guomin Jiang > > > Signed-off-by: Bob Morgan > > > --- > > > .../Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 81 +++++++++--- > > > .../DxeCapsuleLibFmp/DxeCapsuleRuntime.c | 119 > > > ++++++++++++++++++ > > > .../DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf | 4 + > > > MdeModulePkg/MdeModulePkg.dec | 7 +- > > > 4 files changed, 192 insertions(+), 19 deletions(-) > > > > > > diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > > > b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > > > index 90942135d7..0000f91c6a 100644 > > > --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > > > +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > > > @@ -10,6 +10,7 @@ > > > ValidateFmpCapsule(), and DisplayCapsuleImage() receives untrusted > > > input and > > > performs basic validation. > > > > > > + Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
> > > Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.=
> > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > @@ -41,6 +42,11 @@ > > > #include > > > #include > > > > > > +BOOLEAN (EFIAPI *mLibAtRuntimeFunction) (VOID) > =3D > > > NULL; > > > +EFI_FIRMWARE_MANAGEMENT_PROTOCOL *mRuntimeFmp > > > =3D NULL; > > > +VOID > **mRuntimeFmpProtocolArray > > > =3D NULL; > > > +EFI_GUID *mRuntimeFmpGuidArray > > > =3D NULL; > > > + > > > EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable =3D > NULL; > > > BOOLEAN mIsVirtualAddrConverted =3D > FALSE; > > > > > > @@ -551,6 +557,11 @@ DumpAllFmpInfo ( > > > UINT32 > PackageVersion; > > > CHAR16 > > > *PackageVersionName; > > > > > > + // Dump not supported at runtime. > > > + if ((mLibAtRuntimeFunction !=3D NULL) && mLibAtRuntimeFunction ())= { > > > + return; > > > + } > > > + > > > Status =3D gBS->LocateHandleBuffer ( > > > ByProtocol, > > > &gEfiFirmwareManagementProtocolGuid, > > > @@ -906,25 +917,35 @@ SetFmpImageData ( > > > CHAR16 > *AbortReason; > > > EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS > > > ProgressCallback; > > > > > > - Status =3D gBS->HandleProtocol( > > > - Handle, > > > - &gEfiFirmwareManagementProtocolGuid, > > > - (VOID **)&Fmp > > > - ); > > > - if (EFI_ERROR(Status)) { > > > - return Status; > > > - } > > > + // If not using optional runtime support, get FMP protocol for > > > + given > > > Handle. > > > + // Otherwise, use the one saved by ProcessFmpCapsuleImage(). > > > + if ((mLibAtRuntimeFunction =3D=3D NULL) || !mLibAtRuntimeFunction = ()) { > > > + Status =3D gBS->HandleProtocol( > > > + Handle, > > > + &gEfiFirmwareManagementProtocolGuid, > > > + (VOID **)&Fmp > > > + ); > > > + if (EFI_ERROR(Status)) { > > > + return Status; > > > + } > > > > > > - // > > > - // Lookup Firmware Management Progress Protocol before SetImage() > > > is called > > > - // This is an optional protocol that may not be present on Handle. > > > - // > > > - Status =3D gBS->HandleProtocol ( > > > - Handle, > > > - > &gEdkiiFirmwareManagementProgressProtocolGuid, > > > - (VOID **)&mFmpProgress > > > - ); > > > - if (EFI_ERROR (Status)) { > > > + // > > > + // Lookup Firmware Management Progress Protocol before > SetImage() > > > is called > > > + // This is an optional protocol that may not be present on Handl= e. > > > + // > > > + Status =3D gBS->HandleProtocol ( > > > + Handle, > > > + > > > &gEdkiiFirmwareManagementProgressProtocolGuid, > > > + (VOID **)&mFmpProgress > > > + ); > > > + if (EFI_ERROR (Status)) { > > > + mFmpProgress =3D NULL; > > > + } > > > + } else { > > > + if (mRuntimeFmp =3D=3D NULL) { > > > + return EFI_UNSUPPORTED; > > > + } > > > + Fmp =3D mRuntimeFmp; > > > mFmpProgress =3D NULL; > > > } > > > > > > @@ -1259,6 +1280,30 @@ ProcessFmpCapsuleImage ( > > > UpdateHardwareInstance =3D > > > ImageHeader->UpdateHardwareInstance; > > > } > > > > > > + // Optional runtime FMP SetImage processing sequence > > > + if ((mLibAtRuntimeFunction !=3D NULL) && mLibAtRuntimeFunction (= ) > && > > > + (mRuntimeFmpProtocolArray !=3D NULL)) { > > > + mRuntimeFmp =3D NULL; > > > + Index2 =3D 0; > > > + while (mRuntimeFmpProtocolArray[Index2] !=3D NULL) { > > > + if (CompareGuid (&ImageHeader->UpdateImageTypeId, > > > + &mRuntimeFmpGuidArray[Index2])) { > > > + mRuntimeFmp =3D > (EFI_FIRMWARE_MANAGEMENT_PROTOCOL > > > *) > > > + mRuntimeFmpProtocolArray[Index2]; > > > + break; > > > + } > > > + Index2++; > > > + } > > > + > > > + Status =3D SetFmpImageData (NULL, > > > + ImageHeader, > > > + Index - > > > FmpCapsuleHeader->EmbeddedDriverCount); > > > + if (EFI_ERROR (Status)) { > > > + return Status; > > > + } > > > + continue; > > > + } > > > + > > > Status =3D GetFmpHandleBufferByType ( > > > &ImageHeader->UpdateImageTypeId, > > > UpdateHardwareInstance, diff --git > > > a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c > > > b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c > > > index f94044a409..6feb6dab79 100644 > > > --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c > > > +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c > > > @@ -1,6 +1,7 @@ > > > /** @file > > > Capsule library runtime support. > > > > > > + Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
> > > Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.=
> > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > @@ -19,7 +20,11 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > +extern BOOLEAN (EFIAPI > *mLibAtRuntimeFunction) > > > (VOID); > > > +extern VOID **mRuntimeFmpProtocolArray; > > > +extern EFI_GUID *mRuntimeFmpGuidArray; > > > extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable; > > > extern BOOLEAN mIsVirtualAddrConverted; > > > EFI_EVENT > > > mDxeRuntimeCapsuleLibVirtualAddressChangeEvent =3D NULL; @@ -40,9 > > > +45,121 @@ DxeCapsuleLibVirtualAddressChangeEvent ( > > > ) > > > { > > > gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable); > > > + > > > + if (mRuntimeFmpProtocolArray !=3D NULL) { > > > + VOID **FmpArrayEntry; > > > + > > > + FmpArrayEntry =3D mRuntimeFmpProtocolArray; > > > + while (*FmpArrayEntry !=3D NULL) { > > > + EfiConvertPointer (0x0, (VOID **) FmpArrayEntry); > > > + FmpArrayEntry++; > > > + } > > > + EfiConvertPointer (0x0, (VOID **) > &mRuntimeFmpProtocolArray); } > > > + if (mRuntimeFmpGuidArray !=3D NULL) { > > > + EfiConvertPointer (0x0, (VOID **) &mRuntimeFmpGuidArray); } > if > > > + (mLibAtRuntimeFunction !=3D NULL ) { > > > + EfiConvertPointer (0x0, (VOID **) &mLibAtRuntimeFunction); } > > > + > > > mIsVirtualAddrConverted =3D TRUE; > > > } > > > > > > +/** > > > + Initialize optional runtime FMP arrays to support FMP SetImage > > > processing > > > + after ExitBootServices() is called. > > > + > > > + The ImageTypeIdGuids of runtime-capable FMP protocol drivers are > > > extracted > > > + from the PcdRuntimeFmpCapsuleImageTypeIdGuid list and their > > > + protocol structure pointers are saved in the > > > + mRuntimeFmpProtocolArray for use > > > during > > > + UpdateCapsule() processing. UpdateHardwareInstance is not > supported. > > > + > > > +**/ > > > +STATIC > > > +VOID > > > +EFIAPI > > > +InitializeRuntimeFmpArrays ( > > > + VOID > > > + ) > > > +{ > > > + EFI_GUID *Guid; > > > + UINTN NumHandles; > > > + EFI_HANDLE *HandleBuffer; > > > + EFI_STATUS Status; > > > + UINTN Count; > > > + UINTN Index; > > > + UINTN FmpArrayIndex; > > > + > > > + EFI_STATUS > > > + GetFmpHandleBufferByType ( > > > + IN EFI_GUID > *UpdateImageTypeId, > > > + IN UINT64 > > > UpdateHardwareInstance, > > > + OUT UINTN *NoHandles, > > > OPTIONAL > > > + OUT EFI_HANDLE **HandleBuf, > > > OPTIONAL > > > + OUT BOOLEAN > **ResetRequiredBuf > > > OPTIONAL > > > + ); > > > + > > > + Count =3D PcdGetSize (PcdRuntimeFmpCapsuleImageTypeIdGuid) / > sizeof > > > (GUID); > > > + if (Count =3D=3D 0) { > > > + return; > > > + } > > > + > > > + // mRuntimeFmpProtocolArray is a NULL-terminated list of FMP > > > + protocol > > > pointers > > > + mRuntimeFmpProtocolArray =3D (VOID **) > > > + AllocateRuntimeZeroPool ((Count + 1) * sizeof (VOID *)); if > > > + (mRuntimeFmpProtocolArray =3D=3D NULL) { > > > + DEBUG ((DEBUG_ERROR, "Error allocating > > > mRuntimeFmpProtocolArray\n")); > > > + return; > > > + } > > > + mRuntimeFmpGuidArray =3D (EFI_GUID *) > > > + AllocateRuntimeZeroPool (Count * sizeof (EFI_GUID)); if > > > + (mRuntimeFmpGuidArray =3D=3D NULL) { > > > + DEBUG ((DEBUG_ERROR, "Error allocating > mRuntimeFmpGuidArray")); > > > + FreePool (mRuntimeFmpProtocolArray); > > > + return; > > > + } > > > + > > > + // For each runtime ImageTypeIdGuid in the PCD, save its GUID and > > > + FMP > > > protocol > > > + FmpArrayIndex =3D 0; > > > + Guid =3D PcdGetPtr (PcdRuntimeFmpCapsuleImageTypeIdGuid); > > > + for (Index =3D 0; Index < Count; Index++, Guid++) { > > > + mRuntimeFmpGuidArray[FmpArrayIndex] =3D *Guid; > > > + HandleBuffer =3D NULL; > > > + Status =3D GetFmpHandleBufferByType (Guid, > > > + 0, > > > + &NumHandles, > > > + &HandleBuffer, > > > + NULL); > > > + if (EFI_ERROR (Status)) { > > > + DEBUG ((DEBUG_ERROR, > > > + "Error finding FMP handle for runtime > > > ImageTypeIdGuid=3D%g: %r\n", > > > + Guid, Status)); > > > + continue; > > > + } > > > + > > > + if (NumHandles > 1) { > > > + DEBUG ((DEBUG_ERROR, > > > + "FMP runtime ImageTypeIdGuid=3D%g returned %u > handles, > > > only 1 supported\n", > > > + Guid, NumHandles)); > > > + } > > > + Status =3D gBS->HandleProtocol (HandleBuffer[0], > > > + > > > &gEfiFirmwareManagementProtocolGuid, > > > + > > > &mRuntimeFmpProtocolArray[FmpArrayIndex]); > > > + FreePool (HandleBuffer); > > > + if (EFI_ERROR(Status)) { > > > + DEBUG ((DEBUG_ERROR, > > > + "Error getting FMP protocol for runtime > > > ImageTypeIdGuid=3D%g: %r\n", > > > + Guid, Status)); > > > + continue; > > > + } > > > + > > > + FmpArrayIndex++; > > > + } > > > + > > > + mLibAtRuntimeFunction =3D EfiAtRuntime; } > > > + > > > /** > > > Notify function for event group > EFI_EVENT_GROUP_READY_TO_BOOT. > > > > > > @@ -93,6 +210,8 @@ DxeCapsuleLibReadyToBootEventNotify ( > > > // > > > mEsrtTable->FwResourceCountMax =3D > mEsrtTable->FwResourceCount; > > > } > > > + > > > + InitializeRuntimeFmpArrays (); > > > } > > > > > > /** > > > diff --git > > > a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf > > > b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf > > > index bf56f4623f..7b3f5e04f8 100644 > > > --- > > a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf > > > +++ > > b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf > > > @@ -49,6 +49,7 @@ > > > PrintLib > > > HobLib > > > BmpSupportLib > > > + PcdLib > > > > > > > > > [Protocols] > > > @@ -70,5 +71,8 @@ > > > gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event > > > gEdkiiCapsuleOnDiskNameGuid ## > > > SOMETIMES_CONSUMES ## GUID > > > > > > +[Pcd] > > > + > > > > > gEfiMdeModulePkgTokenSpaceGuid.PcdRuntimeFmpCapsuleImageTypeIdG > > ui > > > d > > > + > > > [Depex] > > > gEfiVariableWriteArchProtocolGuid > > > diff --git a/MdeModulePkg/MdeModulePkg.dec > > > b/MdeModulePkg/MdeModulePkg.dec index 133e04ee86..869aa892f7 > > 100644 > > > --- a/MdeModulePkg/MdeModulePkg.dec > > > +++ b/MdeModulePkg/MdeModulePkg.dec > > > @@ -3,7 +3,7 @@ > > > # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs an= d > > > library classes) # and libraries instances, which are used for those > > > modules. > > > # > > > -# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. > > > +# Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights > > > +reserved.
> > > # Copyright (c) 2007 - 2021, Intel Corporation. All rights > > > reserved.
# Copyright (c) 2016, Linaro Ltd. All rights > > > reserved.
# (C) Copyright 2016 - 2019 Hewlett Packard Enterprise > > > Development LP
@@ -2020,6 +2020,11 @@ > > > # @Prompt Capsule On Disk Temp Relocation file name in PEI phase > > > > > > > > gEfiMdeModulePkgTokenSpaceGuid.PcdCoDRelocationFileName|L"Cod.tmp > > "| > > > VOID*|0x30001048 > > > > > > + ## This PCD holds a list of GUIDs for the ImageTypeId to indicate > > > + the # FMP is runtime capable. > > > + # @Prompt A list of runtime-capable FMP ImageTypeId GUIDs > > > + > > > > > gEfiMdeModulePkgTokenSpaceGuid.PcdRuntimeFmpCapsuleImageTypeIdG > > ui > > > d|{0x0}|VOID*|0x30001049 > > > + > > > ## This PCD hold a list GUIDs for the ImageTypeId to indicate the > > > # FMP capsule is a system FMP. > > > # @Prompt A list of system FMP ImageTypeId GUIDs > > > -- > > > 2.17.1 > > > > > > > > > > > > > > > > > > > >=20 >=20 >=20 >=20 >=20