From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 4DBAB21107165 for ; Thu, 30 Aug 2018 03:00:51 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2018 03:00:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,306,1531810800"; d="scan'208";a="81483488" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 30 Aug 2018 03:00:32 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 30 Aug 2018 02:59:15 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 30 Aug 2018 02:59:14 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.143]) with mapi id 14.03.0319.002; Thu, 30 Aug 2018 17:59:13 +0800 From: "Zeng, Star" To: "Gao, Liming" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Zeng, Star" Thread-Topic: [PATCH 2/2] MdeModulePkg DxeCore: Handle multiple FV images in one FV file Thread-Index: AQHUP3v32dYuP0DNxUWZfKFunyhdO6TXieoAgACG7QA= Date: Thu, 30 Aug 2018 09:59:12 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BBB3B88@shsmsx102.ccr.corp.intel.com> References: <1535535466-62348-1-git-send-email-star.zeng@intel.com> <1535535466-62348-3-git-send-email-star.zeng@intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E2EB604@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E2EB604@SHSMSX104.ccr.corp.intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 2/2] MdeModulePkg DxeCore: Handle multiple FV images in one FV file X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2018 10:00:52 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Oh, yes, agree. I should update description. Thanks, Star -----Original Message----- From: Gao, Liming=20 Sent: Thursday, August 30, 2018 5:55 PM To: Zeng, Star ; edk2-devel@lists.01.org Cc: Yao, Jiewen Subject: RE: [PATCH 2/2] MdeModulePkg DxeCore: Handle multiple FV images in= one FV file Star: You change the parameter name in the function. Please also update the fun= ction description to match the function implementation.=20 Thanks Liming >-----Original Message----- >From: Zeng, Star >Sent: Wednesday, August 29, 2018 5:38 PM >To: edk2-devel@lists.01.org >Cc: Zeng, Star ; Gao, Liming=20 >; Yao, Jiewen >Subject: [PATCH 2/2] MdeModulePkg DxeCore: Handle multiple FV images in=20 >one FV file > >REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1131 > >PI spec and BaseTools supports to generate multiple FV images in one FV=20 >file. >This patch is to update DxeCore to handle the case. > >Cc: Liming Gao >Cc: Jiewen Yao >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Star Zeng >--- > MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 241 ++++++++++++++- >----------- > 1 file changed, 128 insertions(+), 113 deletions(-) > >diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c >b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c >index f72c47a9e54c..086a590ef4e3 100644 >--- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c >+++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c >@@ -184,14 +184,13 @@ CoreAddToDriverList ( > ); > > /** >- Get the driver from the FV through driver name, and produce a FVB=20 >protocol on FvHandle. >+ Get Fv image(s) from the FV through file name, and produce FVB=20 >+ protocol >for every Fv image(s). > > @param Fv The FIRMWARE_VOLUME protocol installed on= the FV. > @param FvHandle The handle which FVB protocol installed o= n. > @param DriverName The driver guid specified. > > @retval EFI_OUT_OF_RESOURCES No enough memory or other resource. >- @retval EFI_VOLUME_CORRUPTED Corrupted volume. > @retval EFI_SUCCESS Function successfully returned. > > **/ >@@ -199,7 +198,7 @@ EFI_STATUS > CoreProcessFvImageFile ( > IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, > IN EFI_HANDLE FvHandle, >- IN EFI_GUID *DriverName >+ IN EFI_GUID *FileName > ); > > >@@ -1004,14 +1003,13 @@ GetFvUsedSize ( } > > /** >- Get the driver from the FV through driver name, and produce a FVB=20 >protocol on FvHandle. >+ Get Fv image(s) from the FV through file name, and produce FVB=20 >+ protocol >for every Fv image(s). > > @param Fv The FIRMWARE_VOLUME protocol installed on= the FV. > @param FvHandle The handle which FVB protocol installed o= n. > @param DriverName The driver guid specified. > > @retval EFI_OUT_OF_RESOURCES No enough memory or other resource. >- @retval EFI_VOLUME_CORRUPTED Corrupted volume. > @retval EFI_SUCCESS Function successfully returned. > > **/ >@@ -1019,7 +1017,7 @@ EFI_STATUS > CoreProcessFvImageFile ( > IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, > IN EFI_HANDLE FvHandle, >- IN EFI_GUID *DriverName >+ IN EFI_GUID *FileName > ) > { > EFI_STATUS Status; >@@ -1033,141 +1031,158 @@ CoreProcessFvImageFile ( > EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath; > UINT32 FvUsedSize; > UINT8 EraseByte; >+ UINTN Index; > > // >- // Read the first (and only the first) firmware volume section >+ // Read firmware volume section(s) > // > SectionType =3D EFI_SECTION_FIRMWARE_VOLUME_IMAGE; >- FvHeader =3D NULL; >- FvAlignment =3D 0; >- Buffer =3D NULL; >- BufferSize =3D 0; >- AlignedBuffer =3D NULL; >- Status =3D Fv->ReadSection ( >- Fv, >- DriverName, >- SectionType, >- 0, >- &Buffer, >- &BufferSize, >- &AuthenticationStatus >- ); >- if (!EFI_ERROR (Status)) { >- // >- // Evaluate the authentication status of the Firmware Volume through >- // Security Architectural Protocol >- // >- if (gSecurity !=3D NULL) { >- FvFileDevicePath =3D CoreFvToDevicePath (Fv, FvHandle, DriverName); >- Status =3D gSecurity->FileAuthenticationState ( >- gSecurity, >- AuthenticationStatus, >- FvFileDevicePath >- ); >- if (FvFileDevicePath !=3D NULL) { >- FreePool (FvFileDevicePath); >- } > >- if (Status !=3D EFI_SUCCESS) { >- // >- // Security check failed. The firmware volume should not be used = for any >purpose. >- // >- if (Buffer !=3D NULL) { >- FreePool (Buffer); >+ Index =3D 0; >+ do { >+ FvHeader =3D NULL; >+ FvAlignment =3D 0; >+ Buffer =3D NULL; >+ BufferSize =3D 0; >+ AlignedBuffer =3D NULL; >+ Status =3D Fv->ReadSection ( >+ Fv, >+ FileName, >+ SectionType, >+ Index, >+ &Buffer, >+ &BufferSize, >+ &AuthenticationStatus >+ ); >+ if (!EFI_ERROR (Status)) { >+ // >+ // Evaluate the authentication status of the Firmware Volume throug= h >+ // Security Architectural Protocol >+ // >+ if (gSecurity !=3D NULL) { >+ FvFileDevicePath =3D CoreFvToDevicePath (Fv, FvHandle, FileName); >+ Status =3D gSecurity->FileAuthenticationState ( >+ gSecurity, >+ AuthenticationStatus, >+ FvFileDevicePath >+ ); >+ if (FvFileDevicePath !=3D NULL) { >+ FreePool (FvFileDevicePath); >+ } >+ >+ if (Status !=3D EFI_SUCCESS) { >+ // >+ // Security check failed. The firmware volume should not be=20 >+ used for >any purpose. >+ // >+ if (Buffer !=3D NULL) { >+ FreePool (Buffer); >+ } >+ break; > } >- return Status; > } >- } > >- // >- // FvImage should be at its required alignment. >- // >- FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) Buffer; >- // >- // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the >first byte of the volume >- // can be aligned on any power-of-two boundary. A weakly aligned volu= me >can not be moved from >- // its initial linked location and maintain its alignment. >- // >- if ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_WEAK_ALIGNMENT) !=3D EFI_FVB2_WEAK_ALIGNMENT) { > // >- // Get FvHeader alignment >+ // FvImage should be at its required alignment. > // >- FvAlignment =3D 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_ALIGNMENT) >> 16); >+ FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) Buffer; > // >- // FvAlignment must be greater than or equal to 8 bytes of the mini= mum >FFS alignment value. >+ // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then=20 >+ the >first byte of the volume >+ // can be aligned on any power-of-two boundary. A weakly aligned >volume can not be moved from >+ // its initial linked location and maintain its alignment. > // >- if (FvAlignment < 8) { >- FvAlignment =3D 8; >- } >+ if ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_WEAK_ALIGNMENT) !=3D EFI_FVB2_WEAK_ALIGNMENT) { >+ // >+ // Get FvHeader alignment >+ // >+ FvAlignment =3D 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_ALIGNMENT) >> 16); >+ // >+ // FvAlignment must be greater than or equal to 8 bytes of the=20 >+ minimum >FFS alignment value. >+ // >+ if (FvAlignment < 8) { >+ FvAlignment =3D 8; >+ } > >- DEBUG (( >- DEBUG_INFO, >- "%a() FV at 0x%x, FvAlignment required is 0x%x\n", >- __FUNCTION__, >- FvHeader, >- FvAlignment >- )); >+ DEBUG (( >+ DEBUG_INFO, >+ "%a() FV at 0x%x, FvAlignment required is 0x%x\n", >+ __FUNCTION__, >+ FvHeader, >+ FvAlignment >+ )); > >- // >- // Check FvImage alignment. >- // >- if ((UINTN) FvHeader % FvAlignment !=3D 0) { > // >- // Allocate the aligned buffer for the FvImage. >+ // Check FvImage alignment. > // >- AlignedBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES (Buffer= Size), >(UINTN) FvAlignment); >- if (AlignedBuffer =3D=3D NULL) { >- FreePool (Buffer); >- return EFI_OUT_OF_RESOURCES; >- } else { >+ if ((UINTN) FvHeader % FvAlignment !=3D 0) { > // >- // Move FvImage into the aligned buffer and release the origina= l buffer. >+ // Allocate the aligned buffer for the FvImage. > // >- if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { >+ AlignedBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES >(BufferSize), (UINTN) FvAlignment); >+ if (AlignedBuffer =3D=3D NULL) { >+ FreePool (Buffer); >+ Status =3D EFI_OUT_OF_RESOURCES; >+ break; >+ } else { > // >- // Copy the used bytes and fill the rest with the erase value= . >+ // Move FvImage into the aligned buffer and release the=20 >+ original >buffer. > // >- CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize); >- SetMem ( >- (UINT8 *) AlignedBuffer + FvUsedSize, >- (UINTN) (BufferSize - FvUsedSize), >- EraseByte >- ); >- } else { >- CopyMem (AlignedBuffer, Buffer, BufferSize); >+ if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { >+ // >+ // Copy the used bytes and fill the rest with the erase val= ue. >+ // >+ CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize); >+ SetMem ( >+ (UINT8 *) AlignedBuffer + FvUsedSize, >+ (UINTN) (BufferSize - FvUsedSize), >+ EraseByte >+ ); >+ } else { >+ CopyMem (AlignedBuffer, Buffer, BufferSize); >+ } >+ FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; >+ FreePool (Buffer); >+ Buffer =3D NULL; > } >- FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; >- CoreFreePool (Buffer); >- Buffer =3D NULL; > } > } >+ // >+ // Produce a FVB protocol for the file >+ // >+ Status =3D ProduceFVBProtocolOnBuffer ( >+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >+ (UINT64)BufferSize, >+ FvHandle, >+ AuthenticationStatus, >+ NULL >+ ); > } >- // >- // Produce a FVB protocol for the file >- // >- Status =3D ProduceFVBProtocolOnBuffer ( >- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >- (UINT64)BufferSize, >- FvHandle, >- AuthenticationStatus, >- NULL >- ); >- } > >- if (EFI_ERROR (Status)) { >- // >- // ReadSection or Produce FVB failed, Free data buffer >- // >- if (Buffer !=3D NULL) { >- FreePool (Buffer); >- } >+ if (EFI_ERROR (Status)) { >+ // >+ // ReadSection or Produce FVB failed, Free data buffer >+ // >+ if (Buffer !=3D NULL) { >+ FreePool (Buffer); >+ } >+ >+ if (AlignedBuffer !=3D NULL) { >+ FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize)); >+ } > >- if (AlignedBuffer !=3D NULL) { >- FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize)); >+ break; >+ } else { >+ Index++; > } >- } >+ } while (TRUE); > >- return Status; >+ if (Index > 0) { >+ // >+ // At least one FvImage has been processed successfully. >+ // >+ return EFI_SUCCESS; >+ } else { >+ return Status; >+ } > } > > >-- >2.7.0.windows.1