From nobody Sun May 5 07:33:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1522115194568765.290849467986; Mon, 26 Mar 2018 18:46:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B2616224AE8CF; Mon, 26 Mar 2018 18:39:55 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 6011321F85E71 for ; Mon, 26 Mar 2018 18:39:53 -0700 (PDT) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2018 18:46:29 -0700 Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga007.fm.intel.com with ESMTP; 26 Mar 2018 18:46:29 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 26 Mar 2018 18:46:29 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 26 Mar 2018 18:46:28 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.80]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.108]) with mapi id 14.03.0319.002; Tue, 27 Mar 2018 09:46:26 +0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,366,1517904000"; d="dat'59?scan'59,208,59";a="27228927" From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools: argument genfds-multi-thread create GenSec command issue Thread-Index: AdPE2xOxdraCCfEGQ3WeTlmRuGP2WQ== Date: Tue, 27 Mar 2018 01:46:26 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC483834E@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC483834E@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: [edk2] [PATCH] 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: , Cc: "Gao, Liming" Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 fb5bc5e992..fdffc44f0e 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 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel