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.136; helo=mga12.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 8B56F2267F0F0 for ; Mon, 9 Apr 2018 18:10:45 -0700 (PDT) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Apr 2018 18:10:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,429,1517904000"; d="dat'59?scan'59,208,59";a="32101210" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga007.jf.intel.com with ESMTP; 09 Apr 2018 18:10:44 -0700 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 9 Apr 2018 18:10:44 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx123.amr.corp.intel.com (10.18.125.38) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 9 Apr 2018 18:10:43 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.184]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.239]) with mapi id 14.03.0319.002; Tue, 10 Apr 2018 09:10:41 +0800 From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" CC: "Zhu, Yonghong" , "Gao, Liming" Thread-Topic: [PATCH 2/3] BaseTools: argument genfds-multi-thread create GenSec command issue Thread-Index: AdPQaL3gSEDuD6mDR721Otx4Xyh0aw== Date: Tue, 10 Apr 2018 01:10:41 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC484BAA5@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC484BAA5@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.26 Subject: [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: Tue, 10 Apr 2018 01:10:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 is i= nput.\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 PE/C= OFF 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 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;=20 @@ -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) { // --=20 2.12.2.windows.2