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.120; helo=mga04.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 EC9E922618174 for ; Tue, 10 Apr 2018 23:33:21 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2018 23:33:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,434,1517904000"; d="scan'208";a="219489678" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2018 23:33:20 -0700 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 10 Apr 2018 23:33:20 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 10 Apr 2018 23:33:20 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.151]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.197]) with mapi id 14.03.0319.002; Wed, 11 Apr 2018 14:33:19 +0800 From: "Zhu, Yonghong" To: "Feng, YunhuaX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH 2/3] BaseTools: argument genfds-multi-thread create GenSec command issue Thread-Index: AdPQaL3gSEDuD6mDR721Otx4Xyh0awA7nLGA Date: Wed, 11 Apr 2018 06:33:19 +0000 Message-ID: References: <47C64442C08CCD4089DC43B6B5E46BC484BAA5@shsmsx102.ccr.corp.intel.com> In-Reply-To: <47C64442C08CCD4089DC43B6B5E46BC484BAA5@shsmsx102.ccr.corp.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 2/3] BaseTools: argument genfds-multi-thread create GenSec command issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Apr 2018 06:33:22 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -----Original Message----- From: Feng, YunhuaX=20 Sent: Tuesday, April 10, 2018 9:11 AM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong ; Gao, Liming Subject: [PATCH 2/3] BaseTools: argument genfds-multi-thread create GenSec = command issue Issue: genfds-multi-thread create makefile before section file generation, so it get alignment is zero from empty file. It is incorrect. solution: GenSec get section alignment from input file when the input alignment is zero. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/C/GenSec/GenSec.c | 133 +++++++++++++++++++++++++++++++++= ++-- 1 file changed, 126 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec= /GenSec.c index 56767d5a9b..9f592742e1 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -9,10 +9,16 @@ http://opensource.org/licenses/bsd-license.php = =20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, = =20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. =20 =20 **/ +#ifndef __GNUC__ +#include +#include +#include +#include +#endif =20 #include #include #include #include @@ -25,10 +31,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #include "CommonLib.h" #include "Compress.h" #include "Crc32.h" #include "EfiUtilityMsgs.h" #include "ParseInf.h" +#include "FvLib.h" +#include "PeCoffLib.h" =20 // // GenSec Tool Information // #define UTILITY_NAME "GenSec" @@ -183,12 +191,13 @@ Returns: fprintf (stdout, " -j Number, --buildnumber Number\n\ Number is an integer value between 0 and 65535\n\ used in Ver section.\n"); fprintf (stdout, " --sectionalign SectionAlign\n\ SectionAlign points to section alignment, which su= pport\n\ - the alignment scope 1~16M. It is specified in same= \n\ - order that the section file is input.\n"); + the alignment scope 0~16M. If SectionAlign is spec= ified\n\ + as 0, tool get alignment value from SectionFile.It= is\n\ + specified in same order that the section file=20 + is input.\n"); fprintf (stdout, " --dummy dummyfile\n\ compare dummpyfile with input_file to decide wheth= er\n\ need to set PROCESSING_REQUIRED attribute.\n"); fprintf (stdout, " -v, --verbose Turn on verbose output with in= formational messages.\n"); fprintf (stdout, " -q, --quiet Disable all messages except ke= y message and fatal error\n"); @@ -983,10 +992,107 @@ Returns: *OutFileBuffer =3D FileBuffer; =20 return EFI_SUCCESS; } =20 +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=20 + 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 File= Offset + + Buffer - A pointer to the buffer to read the data into. + + Returns: + + EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the=20 + 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; + *Alignment =3D 0; + + 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 ret= urn status is %x", InFile, (int) Status); + return Status; + } + *Alignment =3D ImageContext.SectionAlignment; + // Free the allocated memory resource + if (PeFileBuffer !=3D NULL) { + free (PeFileBuffer); + PeFileBuffer =3D NULL; + } + return EFI_SUCCESS; +} + int main ( int argc, char *argv[] ) @@ -1267,15 +1373,18 @@ Returns: Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!")= ; goto Finish; } memset (&(InputFileAlign[InputFileNum]), 1, (MAXIMUM_INPUT_FILE_NU= M * sizeof (UINT32))); } - =20 - Status =3D StringtoAlignment (argv[1], &(InputFileAlign[InputFileAli= gnNum])); - if (EFI_ERROR (Status)) { - Error (NULL, 0, 1003, "Invalid option value", "%s =3D %s", argv[0]= , argv[1]); - goto Finish; + if (stricmp(argv[1], "0") =3D=3D 0) { + InputFileAlign[InputFileAlignNum] =3D 0; + } else { + Status =3D StringtoAlignment (argv[1], &(InputFileAlign[InputFileA= lignNum])); + if (EFI_ERROR (Status)) { + Error (NULL, 0, 1003, "Invalid option value", "%s =3D %s", argv[= 0], argv[1]); + goto Finish; + } } argc -=3D 2; argv +=3D 2; InputFileAlignNum ++; continue; @@ -1314,10 +1423,20 @@ Returns: =20 if (InputFileAlignNum > 0 && InputFileAlignNum !=3D InputFileNum) { Error (NULL, 0, 1003, "Invalid option", "section alignment must be set= for each section"); goto Finish; } + for (Index =3D 0; Index < InputFileAlignNum; Index++) { + if (InputFileAlign[Index] =3D=3D 0) { + Status =3D GetAlignmentFromFile(InputFileName[Index], &(InputFileAli= gn[Index])); + if (EFI_ERROR(Status)) { + Error (NULL, 0, 1003, "Fail to get Alignment from %s", InputFileNa= me[InputFileNum]); + goto Finish; + } + } + } =20 VerboseMsg ("%s tool start.", UTILITY_NAME); =20 if (DummyFileName !=3D NULL) { // -- 2.12.2.windows.2