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.88; helo=mga01.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 A92AC21107165 for ; Thu, 30 Aug 2018 03:04:03 -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 fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2018 03:04:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,306,1531810800"; d="scan'208";a="81484376" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 30 Aug 2018 03:02:48 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 30 Aug 2018 03:02:18 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 30 Aug 2018 03:02:17 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.143]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.185]) with mapi id 14.03.0319.002; Thu, 30 Aug 2018 18:02:15 +0800 From: "Gao, Liming" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" Thread-Topic: [PATCH 1/2] MdeModulePkg PeiCore: Handle multiple FV images in one FV file Thread-Index: AQHUP3v2By5cKaTrpUS96FeZ6VYQjaTYEg7g Date: Thu, 30 Aug 2018 10:02:14 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E2EB61E@SHSMSX104.ccr.corp.intel.com> References: <1535535466-62348-1-git-send-email-star.zeng@intel.com> <1535535466-62348-2-git-send-email-star.zeng@intel.com> In-Reply-To: <1535535466-62348-2-git-send-email-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/2] MdeModulePkg PeiCore: 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:04:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: Zeng, Star >Sent: Wednesday, August 29, 2018 5:38 PM >To: edk2-devel@lists.01.org >Cc: Zeng, Star ; Gao, Liming ; >Yao, Jiewen >Subject: [PATCH 1/2] MdeModulePkg PeiCore: Handle multiple FV images in >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 file. >This patch is to update PeiCore to handle the case. > >Cc: Liming Gao >Cc: Jiewen Yao >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Star Zeng >--- > MdeModulePkg/Core/Pei/FwVol/FwVol.c | 267 +++++++++++++++++++----- >------------ > MdeModulePkg/Core/Pei/PeiMain.h | 2 +- > 2 files changed, 145 insertions(+), 124 deletions(-) > >diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c >b/MdeModulePkg/Core/Pei/FwVol/FwVol.c >index 65c485549718..7ea503a10fb5 100644 >--- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c >+++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c >@@ -1358,7 +1358,7 @@ GetFvUsedSize ( > } > > /** >- Get Fv image from the FV type file, then install FV INFO(2) ppi, Build = FV hob. >+ Get Fv image(s) from the FV type file, then install FV INFO(2) ppi, Bui= ld FV(2, >3) hob. > > @param PrivateData PeiCore's private data structure > @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent >Fv image that contain this Fv image. >@@ -1391,6 +1391,7 @@ ProcessFvFile ( > UINT32 AuthenticationStatus; > UINT32 FvUsedSize; > UINT8 EraseByte; >+ UINTN Index; > > // > // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has >already >@@ -1412,144 +1413,164 @@ ProcessFvFile ( > ParentFvPpi =3D ParentFvCoreHandle->FvPpi; > > // >- // Find FvImage in FvFile >+ // Find FvImage(s) in FvFile > // >- AuthenticationStatus =3D 0; >- if ((ParentFvPpi->Signature =3D=3D >EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) && >- (ParentFvPpi->Revision =3D=3D EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)= ) >{ >- Status =3D ParentFvPpi->FindSectionByType2 ( >- ParentFvPpi, >- EFI_SECTION_FIRMWARE_VOLUME_IMAGE, >- 0, >- ParentFvFileHandle, >- (VOID **)&FvHeader, >- &AuthenticationStatus >- ); >- } else { >- Status =3D ParentFvPpi->FindSectionByType ( >- ParentFvPpi, >- EFI_SECTION_FIRMWARE_VOLUME_IMAGE, >- ParentFvFileHandle, >- (VOID **)&FvHeader >- ); >- } >- if (EFI_ERROR (Status)) { >- return Status; >- } >- >- Status =3D VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandle, >AuthenticationStatus); >- if (Status =3D=3D EFI_SECURITY_VIOLATION) { >- return Status; >- } >- >- // >- // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the firs= t >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 ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_WEAK_ALIGNMENT) !=3D EFI_FVB2_WEAK_ALIGNMENT) { >- // >- // FvAlignment must be greater than or equal to 8 bytes of the minimu= m >FFS alignment value. >- // >- FvAlignment =3D 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_ALIGNMENT) >> 16); >- if (FvAlignment < 8) { >- FvAlignment =3D 8; >+ Index =3D 0; >+ do { >+ AuthenticationStatus =3D 0; >+ if ((ParentFvPpi->Signature =3D=3D >EFI_PEI_FIRMWARE_VOLUME_PPI_SIGNATURE) && >+ (ParentFvPpi->Revision =3D=3D >EFI_PEI_FIRMWARE_VOLUME_PPI_REVISION)) { >+ Status =3D ParentFvPpi->FindSectionByType2 ( >+ ParentFvPpi, >+ EFI_SECTION_FIRMWARE_VOLUME_IMAGE, >+ Index, >+ ParentFvFileHandle, >+ (VOID **)&FvHeader, >+ &AuthenticationStatus >+ ); >+ } else { >+ // >+ // Old FvPpi has no parameter to input SearchInstance, >+ // only one instance is supported. >+ // >+ if (Index > 0) { >+ break; >+ } >+ Status =3D ParentFvPpi->FindSectionByType ( >+ ParentFvPpi, >+ EFI_SECTION_FIRMWARE_VOLUME_IMAGE, >+ ParentFvFileHandle, >+ (VOID **)&FvHeader >+ ); >+ } >+ if (EFI_ERROR (Status)) { >+ break; > } > >- DEBUG (( >- DEBUG_INFO, >- "%a() FV at 0x%x, FvAlignment required is 0x%x\n", >- __FUNCTION__, >- FvHeader, >- FvAlignment >- )); >+ Status =3D VerifyPeim (PrivateData, ParentFvHandle, ParentFvFileHandl= e, >AuthenticationStatus); >+ if (Status =3D=3D EFI_SECURITY_VIOLATION) { >+ break; >+ } > > // >- // Check FvImage alignment. >+ // 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 ((UINTN) FvHeader % FvAlignment !=3D 0) { >- FvLength =3D ReadUnaligned64 (&FvHeader->FvLength); >- NewFvBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) >FvLength), FvAlignment); >- if (NewFvBuffer =3D=3D NULL) { >- return EFI_OUT_OF_RESOURCES; >+ if ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_WEAK_ALIGNMENT) !=3D EFI_FVB2_WEAK_ALIGNMENT) { >+ // >+ // FvAlignment must be greater than or equal to 8 bytes of the mini= mum >FFS alignment value. >+ // >+ FvAlignment =3D 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & >EFI_FVB2_ALIGNMENT) >> 16); >+ if (FvAlignment < 8) { >+ FvAlignment =3D 8; > } >- if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { >- // >- // Copy the used bytes and fill the rest with the erase value. >- // >- CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize); >- SetMem ( >- (UINT8 *) NewFvBuffer + FvUsedSize, >- (UINTN) (FvLength - FvUsedSize), >- EraseByte >- ); >- } else { >- CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength); >+ >+ 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) { >+ FvLength =3D ReadUnaligned64 (&FvHeader->FvLength); >+ NewFvBuffer =3D AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) >FvLength), FvAlignment); >+ if (NewFvBuffer =3D=3D NULL) { >+ Status =3D EFI_OUT_OF_RESOURCES; >+ break; >+ } >+ if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) { >+ // >+ // Copy the used bytes and fill the rest with the erase value. >+ // >+ CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize); >+ SetMem ( >+ (UINT8 *) NewFvBuffer + FvUsedSize, >+ (UINTN) (FvLength - FvUsedSize), >+ EraseByte >+ ); >+ } else { >+ CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength); >+ } >+ FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer; > } >- FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer; > } >- } > >- Status =3D ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, >&ParentFvImageInfo); >- ASSERT_EFI_ERROR (Status); >+ Status =3D ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle, >&ParentFvImageInfo); >+ ASSERT_EFI_ERROR (Status); > >- Status =3D ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, >&FileInfo); >- ASSERT_EFI_ERROR (Status); >- >- // >- // Install FvInfo(2) Ppi >- // NOTE: FvInfo2 must be installed before FvInfo so that recursive >processing of encapsulated >- // FVs inherit the proper AuthenticationStatus. >- // >- PeiServicesInstallFvInfo2Ppi( >- &FvHeader->FileSystemGuid, >- (VOID**)FvHeader, >- (UINT32)FvHeader->FvLength, >- &ParentFvImageInfo.FvName, >- &FileInfo.FileName, >- AuthenticationStatus >- ); >+ Status =3D ParentFvPpi->GetFileInfo (ParentFvPpi, ParentFvFileHandle, >&FileInfo); >+ ASSERT_EFI_ERROR (Status); > >- PeiServicesInstallFvInfoPpi ( >- &FvHeader->FileSystemGuid, >- (VOID**) FvHeader, >- (UINT32) FvHeader->FvLength, >- &ParentFvImageInfo.FvName, >- &FileInfo.FileName >- ); >+ // >+ // Install FvInfo(2) Ppi >+ // NOTE: FvInfo2 must be installed before FvInfo so that recursive >processing of encapsulated >+ // FVs inherit the proper AuthenticationStatus. >+ // >+ PeiServicesInstallFvInfo2Ppi( >+ &FvHeader->FileSystemGuid, >+ (VOID**)FvHeader, >+ (UINT32)FvHeader->FvLength, >+ &ParentFvImageInfo.FvName, >+ &FileInfo.FileName, >+ AuthenticationStatus >+ ); >+ >+ PeiServicesInstallFvInfoPpi ( >+ &FvHeader->FileSystemGuid, >+ (VOID**) FvHeader, >+ (UINT32) FvHeader->FvLength, >+ &ParentFvImageInfo.FvName, >+ &FileInfo.FileName >+ ); > >- // >- // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phas= e >- // >- BuildFvHob ( >- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >- FvHeader->FvLength >- ); >+ // >+ // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE >phase >+ // >+ BuildFvHob ( >+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >+ FvHeader->FvLength >+ ); > >- // >- // Makes the encapsulated volume show up in DXE phase to skip processin= g >of >- // encapsulated file again. >- // >- BuildFv2Hob ( >- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >- FvHeader->FvLength, >- &ParentFvImageInfo.FvName, >- &FileInfo.FileName >- ); >+ // >+ // Makes the encapsulated volume show up in DXE phase to skip >processing of >+ // encapsulated file again. >+ // >+ BuildFv2Hob ( >+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >+ FvHeader->FvLength, >+ &ParentFvImageInfo.FvName, >+ &FileInfo.FileName >+ ); > >- // >- // Build FV3 HOB with authentication status to be propagated to DXE. >- // >- BuildFv3Hob ( >- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >- FvHeader->FvLength, >- AuthenticationStatus, >- TRUE, >- &ParentFvImageInfo.FvName, >- &FileInfo.FileName >- ); >+ // >+ // Build FV3 HOB with authentication status to be propagated to DXE. >+ // >+ BuildFv3Hob ( >+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader, >+ FvHeader->FvLength, >+ AuthenticationStatus, >+ TRUE, >+ &ParentFvImageInfo.FvName, >+ &FileInfo.FileName >+ ); >+ >+ Index++; >+ } while (TRUE); > >- return EFI_SUCCESS; >+ if (Index > 0) { >+ // >+ // At least one FvImage has been processed successfully. >+ // >+ return EFI_SUCCESS; >+ } else { >+ return Status; >+ } > } > > /** >diff --git a/MdeModulePkg/Core/Pei/PeiMain.h >b/MdeModulePkg/Core/Pei/PeiMain.h >index e2f8cd9c7758..6469436b8f79 100644 >--- a/MdeModulePkg/Core/Pei/PeiMain.h >+++ b/MdeModulePkg/Core/Pei/PeiMain.h >@@ -1258,7 +1258,7 @@ SecurityPpiNotifyCallback ( > ); > > /** >- Get Fv image from the FV type file, then install FV INFO(2) ppi, Build = FV hob. >+ Get Fv image(s) from the FV type file, then install FV INFO(2) ppi, Bui= ld FV(2, >3) hob. > > @param PrivateData PeiCore's private data structure > @param ParentFvCoreHandle Pointer of EFI_CORE_FV_HANDLE to parent >Fv image that contain this Fv image. >-- >2.7.0.windows.1