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 E192121EA15D8 for ; Tue, 10 Oct 2017 22:10:39 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2017 22:14:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,360,1503385200"; d="scan'208";a="1180780848" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga001.jf.intel.com with ESMTP; 10 Oct 2017 22:14:07 -0700 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 10 Oct 2017 22:14:06 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 10 Oct 2017 22:14:05 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.152]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.159]) with mapi id 14.03.0319.002; Wed, 11 Oct 2017 13:14:03 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [Patch 1/3] BaseTools: GenFfs support to get alignment value from SectionFile Thread-Index: AQHTOMI52RafizMJckSK3slYmoOoTaLeLecQ Date: Wed, 11 Oct 2017 05:14:02 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E169C27@SHSMSX104.ccr.corp.intel.com> References: <1506648164-5624-1-git-send-email-yonghong.zhu@intel.com> <1506648164-5624-2-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1506648164-5624-2-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 1/3] BaseTools: GenFfs support to get alignment value from SectionFile 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: Wed, 11 Oct 2017 05:10:40 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable PeFileBuffer should free in the end of the function. >-----Original Message----- >From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >Yonghong Zhu >Sent: Friday, September 29, 2017 9:23 AM >To: edk2-devel@lists.01.org >Cc: Gao, Liming >Subject: [edk2] [Patch 1/3] BaseTools: GenFfs support to get alignment val= ue >from SectionFile > >Update GenFfs tool to get alignment value from SectionFile when use >the new option -n 0. > >Cc: Liming Gao >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Yonghong Zhu >--- > BaseTools/Source/C/GenFfs/GenFfs.c | 127 >++++++++++++++++++++++++++++++++++++- > 1 file changed, 125 insertions(+), 2 deletions(-) > >diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c >b/BaseTools/Source/C/GenFfs/GenFfs.c >index cb16f38..26a3c88 100644 >--- a/BaseTools/Source/C/GenFfs/GenFfs.c >+++ b/BaseTools/Source/C/GenFfs/GenFfs.c >@@ -10,10 +10,17 @@ http://opensource.org/licenses/bsd-license.php > THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS >OR IMPLIED. > > **/ > >+#ifndef __GNUC__ >+#include >+#include >+#include >+#include >+#endif >+ > #include > #include > #include > > #include >@@ -22,10 +29,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY >KIND, EITHER EXPRESS OR IMPLIED. > #include > > #include "CommonLib.h" > #include "ParseInf.h" > #include "EfiUtilityMsgs.h" >+#include "FvLib.h" >+#include "PeCoffLib.h" > > #define UTILITY_NAME "GenFfs" > #define UTILITY_MAJOR_VERSION 0 > #define UTILITY_MINOR_VERSION 1 > >@@ -151,11 +160,12 @@ Returns: > 128K,256K,512K,1M,2M,4M,8M,16M\n"); > fprintf (stdout, " -i SectionFile, --sectionfile SectionFile\n\ > Section file will be contained in this FFS file.\= n"); > fprintf (stdout, " -n SectionAlign, --sectionalign SectionAlign\n\ > SectionAlign points to section alignment, which s= upport\n\ >- the alignment scope 1~16M. It is specified togeth= er\n\ >+ the alignment scope 0~16M. If SectionAlign is spe= cified as 0, >tool\n\ >+ get alignment value from SectionFile. It is speci= fied together\n\ > with sectionfile to point its alignment in FFS fi= le.\n"); > fprintf (stdout, " -v, --verbose Turn on verbose output with >informational messages.\n"); > fprintf (stdout, " -q, --quiet Disable all messages except k= ey message >and fatal error\n"); > fprintf (stdout, " -d, --debug level Enable debug messages, at inp= ut debug >level.\n"); > fprintf (stdout, " --version Show program's version number= and >exit.\n"); >@@ -455,10 +465,101 @@ Returns: > *BufferLength =3D Size; > return EFI_SUCCESS; > } > } > >+EFI_STATUS >+FfsRebaseImageRead ( >+ IN VOID *FileHandle, >+ IN UINTN FileOffset, >+ IN OUT UINT32 *ReadSize, >+ OUT VOID *Buffer >+ ) >+ /*++ >+ >+ Routine Description: >+ >+ Support routine for the PE/COFF Loader that reads a buffer from a >PE/COFF file >+ >+ Arguments: >+ >+ FileHandle - The handle to the PE/COFF file >+ >+ FileOffset - The offset, in bytes, into the file to read >+ >+ ReadSize - The number of bytes to read from the file starting at Fil= eOffset >+ >+ Buffer - A pointer to the buffer to read the data into. >+ >+ Returns: >+ >+ EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the >PE/COFF file starting at FileOffset >+ >+ --*/ >+{ >+ CHAR8 *Destination8; >+ CHAR8 *Source8; >+ UINT32 Length; >+ >+ Destination8 =3D Buffer; >+ Source8 =3D (CHAR8 *) ((UINTN) FileHandle + FileOffset); >+ Length =3D *ReadSize; >+ while (Length--) { >+ *(Destination8++) =3D *(Source8++); >+ } >+ >+ return EFI_SUCCESS; >+} >+ >+STATIC >+EFI_STATUS >+GetAlignmentFromFile(char *InFile, UINT32 *Alignment) >+ /*++ >+ InFile is input file for getting alignment >+ return the alignment >+ --*/ >+{ >+ FILE *InFileHandle; >+ UINT8 *PeFileBuffer; >+ UINTN PeFileSize; >+ UINT32 CurSecHdrSize; >+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; >+ EFI_COMMON_SECTION_HEADER *CommonHeader; >+ EFI_STATUS Status; >+ >+ InFileHandle =3D NULL; >+ PeFileBuffer =3D NULL; >+ >+ memset (&ImageContext, 0, sizeof (ImageContext)); >+ >+ InFileHandle =3D fopen(LongFilePath(InFile), "rb"); >+ if (InFileHandle =3D=3D NULL){ >+ Error (NULL, 0, 0001, "Error opening file", InFile); >+ return EFI_ABORTED; >+ } >+ PeFileSize =3D _filelength (fileno(InFileHandle)); >+ PeFileBuffer =3D (UINT8 *) malloc (PeFileSize); >+ if (PeFileBuffer =3D=3D NULL) { >+ fclose (InFileHandle); >+ Error(NULL, 0, 4001, "Resource", "memory cannot be allocated of %s", >InFileHandle); >+ return EFI_OUT_OF_RESOURCES; >+ } >+ fread (PeFileBuffer, sizeof (UINT8), PeFileSize, InFileHandle); >+ fclose (InFileHandle); >+ CommonHeader =3D (EFI_COMMON_SECTION_HEADER *) PeFileBuffer; >+ CurSecHdrSize =3D GetSectionHeaderLength(CommonHeader); >+ ImageContext.Handle =3D (VOID *) ((UINTN)PeFileBuffer + CurSecHdrSize); >+ ImageContext.ImageRead =3D >(PE_COFF_LOADER_READ_FILE)FfsRebaseImageRead; >+ Status =3D PeCoffLoaderGetImageInfo(&ImageContext); >+ if (EFI_ERROR (Status)) { >+ Error (NULL, 0, 3000, "Invalid PeImage", "The input file is %s and re= turn >status is %x", InFile, (int) Status); >+ return Status; >+ } >+ *Alignment =3D ImageContext.SectionAlignment; >+ return EFI_SUCCESS; >+} >+ > int > main ( > int argc, > CHAR8 *argv[] > ) >@@ -495,10 +596,12 @@ Returns: > FILE *FfsFile; > UINT32 Index; > UINT64 LogLevel; > UINT8 PeSectionNum; > UINT32 HeaderSize; >+ UINT32 Alignment; >+ CHAR8 AlignmentBuffer[8]; > > // > // Init local variables > // > LogLevel =3D 0; >@@ -688,11 +791,31 @@ Returns: > > // > // Section File alignment requirement > // > if ((stricmp (argv[0], "-n") =3D=3D 0) || (stricmp (argv[0], "--sec= tionalign") =3D=3D 0)) >{ >- Status =3D StringtoAlignment (argv[1], &(InputFileAlign[InputFile= Num])); >+ if ((argv[1] !=3D NULL) && (stricmp("0", argv[1]) =3D=3D 0)) { >+ Status =3D GetAlignmentFromFile(InputFileName[InputFileNum], >&Alignment); >+ if (EFI_ERROR(Status)) { >+ Error (NULL, 0, 1003, "Fail to get Alignment from %s", >InputFileName[InputFileNum]); >+ goto Finish; >+ } >+ if (Alignment < 0x400){ >+ sprintf (AlignmentBuffer, "%d", Alignment); >+ } >+ else if (Alignment >=3D 0x400) { >+ if (Alignment >=3D 0x100000) { >+ sprintf (AlignmentBuffer, "%dM", Alignment/0x100000); >+ } else { >+ sprintf (AlignmentBuffer, "%dK", Alignment/0x400); >+ } >+ } >+ Status =3D StringtoAlignment (AlignmentBuffer, >&(InputFileAlign[InputFileNum])); >+ } >+ else { >+ Status =3D StringtoAlignment (argv[1], &(InputFileAlign[InputFi= leNum])); >+ } > if (EFI_ERROR (Status)) { > Error (NULL, 0, 1003, "Invalid option value", "%s =3D %s", argv= [0], argv[1]); > goto Finish; > } > argc -=3D 2; >-- >2.6.1.windows.1 > >_______________________________________________ >edk2-devel mailing list >edk2-devel@lists.01.org >https://lists.01.org/mailman/listinfo/edk2-devel