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=liming.gao@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 2738820945BB8 for ; Fri, 29 Sep 2017 00:17:03 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 29 Sep 2017 00:20:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,451,1500966000"; d="scan'208";a="140811352" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga002.jf.intel.com with ESMTP; 29 Sep 2017 00:20:17 -0700 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 29 Sep 2017 00:20:17 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 29 Sep 2017 00:20:17 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.152]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0319.002; Fri, 29 Sep 2017 15:20:15 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Feng, YunhuaX" Thread-Topic: [Patch V2] BaseTools: PI 1.6 to support FV extended header contain FV used size Thread-Index: AQHTOOKd1PBgL3VEr0KlKzorFB47oaLLc8oA Date: Fri, 29 Sep 2017 07:20:14 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E1668AD@SHSMSX104.ccr.corp.intel.com> References: <1506662392-7460-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1506662392-7460-1-git-send-email-yonghong.zhu@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 V2] BaseTools: PI 1.6 to support FV extended header contain FV used size X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Sep 2017 07:17:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Yonghong: Below logic is incorrect. Index is the byte offset, not date type offset.= So, you should set Index =3D sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER) as th= e first value, and use the below statement to access it.=20 (((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)(ExtHeader + Index)) =3D=3D> (((EFI_FIR= MWARE_VOLUME_EXT_ENTRY *)((UIN8 *) ExtHeader + Index)) =20 Thanks Liming >-----Original Message----- >From: Zhu, Yonghong >Sent: Friday, September 29, 2017 1:20 PM >To: edk2-devel@lists.01.org >Cc: Feng, YunhuaX ; Gao, Liming > >Subject: [Patch V2] BaseTools: PI 1.6 to support FV extended header contai= n >FV used size > >From: Yunhua Feng > >Per PI 1.6 we added an FV Extended Header entry that would contain the >size of the FV that was in use. > >Cc: Liming Gao >Cc: Yonghong Zhu >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Yunhua Feng >--- > BaseTools/Source/C/GenFv/GenFvInternalLib.c | 19 >++++++++++++++++--- > BaseTools/Source/C/Include/Common/PiFirmwareVolume.h | 6 ++++++ > BaseTools/Source/Python/GenFds/FdfParser.py | 2 +- > BaseTools/Source/Python/GenFds/Fv.py | 17 +++++++++++++++= +- > 4 files changed, 39 insertions(+), 5 deletions(-) > >diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c >b/BaseTools/Source/C/GenFv/GenFvInternalLib.c >index 01c862e..6a91858 100644 >--- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c >+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c >@@ -42,10 +42,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY >KIND, EITHER EXPRESS OR IMPLIED. > #define ARMT_UNCONDITIONAL_JUMP_INSTRUCTION 0xEB000000 > #define ARM64_UNCONDITIONAL_JUMP_INSTRUCTION 0x14000000 > > BOOLEAN mArm =3D FALSE; > STATIC UINT32 MaxFfsAlignment =3D 0; >+BOOLEAN VtfFileFlag =3D FALSE; > > EFI_GUID mEfiFirmwareVolumeTopFileGuid =3D >EFI_FFS_VOLUME_TOP_FILE_GUID; > EFI_GUID mFileGuidArray [MAX_NUMBER_OF_FILES_IN_FV]; > EFI_GUID mZeroGuid =3D {0x0, 0x0, 0x0, {0x0, 0= x0, 0x0, 0x0, 0x0, >0x0, 0x0, 0x0}}; > EFI_GUID mDefaultCapsuleGuid =3D {0x3B6686BD, 0x0D76, 0x= 4030, >{ 0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0 }}; >@@ -598,11 +599,13 @@ Returns: > { > EFI_FFS_FILE_HEADER *PadFile; > UINTN PadFileSize; > UINT32 NextFfsHeaderSize; > UINT32 CurFfsHeaderSize; >- >+ UINT32 Index; >+ >+ Index =3D 0; > CurFfsHeaderSize =3D sizeof (EFI_FFS_FILE_HEADER); > // > // Verify input parameters. > // > if (FvImage =3D=3D NULL) { >@@ -703,10 +706,22 @@ Returns: > > if (ExtHeader !=3D NULL) { > // > // Copy Fv Extension Header and Set Fv Extension header offset > // >+ if (ExtHeader->ExtHeaderSize > sizeof >(EFI_FIRMWARE_VOLUME_EXT_HEADER)) { >+ for (Index =3D 1; Index <=3D ExtHeader->ExtHeaderSize - >sizeof(EFI_FIRMWARE_VOLUME_EXT_HEADER);) { >+ if (((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)(ExtHeader + Index)) -> >ExtEntryType =3D=3D EFI_FV_EXT_TYPE_USED_SIZE_TYPE) { >+ if (VtfFileFlag) { >+ ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE >*)(ExtHeader + Index))->UsedSize =3D mFvTotalSize; >+ } else { >+ ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE >*)(ExtHeader + Index))->UsedSize =3D mFvTakenSize; >+ } >+ Index +=3D ((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)(ExtHeader + Index)= ) >-> ExtEntrySize; >+ } >+ } >+ } > memcpy ((UINT8 *)PadFile + CurFfsHeaderSize, ExtHeader, ExtHeader- >>ExtHeaderSize); > ((EFI_FIRMWARE_VOLUME_HEADER *) FvImage->FileImage)- >>ExtHeaderOffset =3D (UINT16) ((UINTN) ((UINT8 *)PadFile + CurFfsHeaderSiz= e) >- (UINTN) FvImage->FileImage); > // > // Make next file start at QWord Boundry > // >@@ -3057,16 +3072,14 @@ Returns: > UINTN FfsFileSize; > UINTN FvExtendHeaderSize; > UINT32 FfsAlignment; > UINT32 FfsHeaderSize; > EFI_FFS_FILE_HEADER FfsHeader; >- BOOLEAN VtfFileFlag; > UINTN VtfFileSize; > > FvExtendHeaderSize =3D 0; > VtfFileSize =3D 0; >- VtfFileFlag =3D FALSE; > fpin =3D NULL; > Index =3D 0; > > // > // Compute size for easy access later >diff --git a/BaseTools/Source/C/Include/Common/PiFirmwareVolume.h >b/BaseTools/Source/C/Include/Common/PiFirmwareVolume.h >index b5c2b03..c3089e8 100644 >--- a/BaseTools/Source/C/Include/Common/PiFirmwareVolume.h >+++ b/BaseTools/Source/C/Include/Common/PiFirmwareVolume.h >@@ -152,6 +152,12 @@ typedef struct { > // > // UINT8 Data[1]; > // > } EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE; > >+#define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03 >+typedef struct { >+ EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr; >+ UINT32 UsedSize; >+} EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE; >+ > #endif >diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py >b/BaseTools/Source/Python/GenFds/FdfParser.py >index 499d0a6..b95afc7 100644 >--- a/BaseTools/Source/Python/GenFds/FdfParser.py >+++ b/BaseTools/Source/Python/GenFds/FdfParser.py >@@ -2309,11 +2309,11 @@ class FdfParser: > if name not in ("ERASE_POLARITY", "MEMORY_MAPPED", \ > "STICKY_WRITE", "LOCK_CAP", "LOCK_STATUS", >"WRITE_ENABLED_CAP", \ > "WRITE_DISABLED_CAP", "WRITE_STATUS", >"READ_ENABLED_CAP", \ > "READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK= _CAP", \ > "READ_LOCK_STATUS", "WRITE_LOCK_CAP", >"WRITE_LOCK_STATUS", \ >- "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT"): >+ "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT", >"FvUsedSizeEnable"): > self.__UndoToken() > return False > > if not self.__IsToken( "=3D"): > raise Warning("expected '=3D'", self.FileName, self.Curre= ntLineNumber) >diff --git a/BaseTools/Source/Python/GenFds/Fv.py >b/BaseTools/Source/Python/GenFds/Fv.py >index 4b03adc..45f6696 100644 >--- a/BaseTools/Source/Python/GenFds/Fv.py >+++ b/BaseTools/Source/Python/GenFds/Fv.py >@@ -49,10 +49,11 @@ class FV (FvClassObject): > self.FvAddressFileName =3D None > self.CapsuleName =3D None > self.FvBaseAddress =3D None > self.FvForceRebase =3D None > self.FvRegionInFD =3D None >+ self.UsedSizeEnable =3D False > > ## AddToBuffer() > # > # Generate Fv and add it to the Buffer > # >@@ -305,10 +306,14 @@ class FV (FvClassObject): > self.FvInfFile.writelines("EFI_ERASE_POLARITY =3D " + \ > ' %s' %ErasePloarity + \ > T_CHAR_LF) > if not (self.FvAttributeDict =3D=3D None): > for FvAttribute in self.FvAttributeDict.keys() : >+ if FvAttribute =3D=3D "FvUsedSizeEnable": >+ if self.FvAttributeDict[FvAttribute].upper() in ('TRU= E', '1') : >+ self.UsedSizeEnable =3D True >+ continue > self.FvInfFile.writelines("EFI_" + \ > FvAttribute + \ > ' =3D ' + \ > self.FvAttributeDict[FvAttribut= e] + \ > T_CHAR_LF ) >@@ -320,16 +325,26 @@ class FV (FvClassObject): > > # > # Generate FV extension header file > # > if self.FvNameGuid =3D=3D None or self.FvNameGuid =3D=3D '': >- if len(self.FvExtEntryType) > 0: >+ if len(self.FvExtEntryType) > 0 or self.UsedSizeEnable: > GenFdsGlobalVariable.ErrorLogger("FV Extension Header Ent= ries >declared for %s with no FvNameGuid declaration." % (self.UiFvName)) > > if self.FvNameGuid <> None and self.FvNameGuid <> '': > TotalSize =3D 16 + 4 > Buffer =3D '' >+ if self.UsedSizeEnable: >+ TotalSize +=3D (4 + 4) >+ ## define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03 >+ #typedef struct >+ # { >+ # EFI_FIRMWARE_VOLUME_EXT_ENTRY Hdr; >+ # UINT32 UsedSize; >+ # } EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE; >+ Buffer +=3D pack('HHL', 8, 3, 0) >+ > if self.FvNameString =3D=3D 'TRUE': > # > # Create EXT entry for FV UI name > # This GUID is used: A67DF1FA-8DE8-4E98-AF09-4BDF2EFFBC7C > # >-- >2.6.1.windows.1