From nobody Wed Dec 25 13:11:11 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 1510648053488906.3271472709198; Tue, 14 Nov 2017 00:27:33 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CB4A1220D4C16; Tue, 14 Nov 2017 00:23:24 -0800 (PST) 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 64F3B220D4C0F for ; Tue, 14 Nov 2017 00:23:23 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2017 00:27:30 -0800 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.121]) by orsmga002.jf.intel.com with ESMTP; 14 Nov 2017 00:27:29 -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=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,393,1505804400"; d="scan'208";a="7398743" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Tue, 14 Nov 2017 16:27:11 +0800 Message-Id: <1510648032-7924-3-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 In-Reply-To: <1510648032-7924-1-git-send-email-yonghong.zhu@intel.com> References: <1510648032-7924-1-git-send-email-yonghong.zhu@intel.com> Subject: [edk2] [Patch 2/3 V2] BaseTools: Update Trim to generate VfrBinOffset Binary 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: , Cc: Liming Gao MIME-Version: 1.0 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" Its usage is "Trim --Vfr-Uni-Offset -o $(OUTPUT_DIR)(+)$(MODULE_NAME)VfrOffset.sec --ModuleName=3D$(MODULE_NAME) --DebugDir=3D$(DEBUG_DIR)" Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao --- BaseTools/Source/Python/Trim/Trim.py | 81 ++++++++++++++++++++++++++++++++= ++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python= /Trim/Trim.py index 9ccc027..d1e40b0 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -1,9 +1,9 @@ ## @file # Trim files preprocessed by compiler # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at # http://opensource.org/licenses/bsd-license.php # @@ -15,10 +15,11 @@ # Import Modules # import Common.LongFilePathOs as os import sys import re +import StringIO =20 from optparse import OptionParser from optparse import make_option from Common.BuildToolError import * from Common.Misc import * @@ -27,11 +28,11 @@ import Common.EdkLogger as EdkLogger from Common.LongFilePathSupport import OpenLongFilePath as open =20 # Version and Copyright __version_number__ =3D ("0.10" + " " + gBUILD_VERSION) __version__ =3D "%prog Version " + __version_number__ -__copyright__ =3D "Copyright (c) 2007-2016, Intel Corporation. All rights = reserved." +__copyright__ =3D "Copyright (c) 2007-2017, Intel Corporation. All rights = reserved." =20 ## Regular expression for matching Line Control directive like "#line xxx" gLineControlDirective =3D re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*= )"') ## Regular expression for matching "typedef struct" gTypedefPattern =3D re.compile("^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re= .MULTILINE) @@ -428,10 +429,72 @@ def TrimAslFile(Source, Target, IncludePathFile): EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=3DTarget) =20 f.writelines(Lines) f.close() =20 +def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): + VfrNameList =3D [] + if os.path.isdir(DebugDir): + for CurrentDir, Dirs, Files in os.walk(DebugDir): + for FileName in Files: + Name, Ext =3D os.path.splitext(FileName) + if Ext =3D=3D '.lst': + VfrNameList.append (Name + 'Bin') + + VfrNameList.append (ModuleName + 'Strings') + + EfiFileName =3D os.path.join(DebugDir, ModuleName + '.efi') + MapFileName =3D os.path.join(DebugDir, ModuleName + '.map') + VfrUniOffsetList =3D GetVariableOffset(MapFileName, EfiFileName, VfrNa= meList) + + if not VfrUniOffsetList: + return + + try: + fInputfile =3D open(OutputFile, "wb+", 0) + except: + EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %= s" %OutputFile, None) + + # Use a instance of StringIO to cache data + fStringIO =3D StringIO.StringIO('') + + for Item in VfrUniOffsetList: + if (Item[0].find("Strings") !=3D -1): + # + # UNI offset in image. + # GUID + Offset + # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89= , 0xfc, 0x6, 0x66 } } + # + UniGuid =3D [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0= x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66] + UniGuid =3D [chr(ItemGuid) for ItemGuid in UniGuid] + fStringIO.write(''.join(UniGuid)) + UniValue =3D pack ('Q', int (Item[1], 16)) + fStringIO.write (UniValue) + else: + # + # VFR binary offset in image. + # GUID + Offset + # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46,= 0xda, 0x6, 0xa2 } }; + # + VfrGuid =3D [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0= xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2] + VfrGuid =3D [chr(ItemGuid) for ItemGuid in VfrGuid] + fStringIO.write(''.join(VfrGuid)) + type (Item[1]) + VfrValue =3D pack ('Q', int (Item[1], 16)) + fStringIO.write (VfrValue) + + # + # write data into file. + # + try : + fInputfile.write (fStringIO.getvalue()) + except: + EdkLogger.error("Trim", FILE_WRITE_FAILURE, "Write data to file %s= failed, please check whether the file been locked or using by other applic= ations." %OutputFile, None) + + fStringIO.close () + fInputfile.close () + ## Trim EDK source code file(s) # # # @param Source File or directory to be trimmed # @param Target File or directory to store the trimmed content @@ -533,10 +596,12 @@ def Options(): OptionList =3D [ make_option("-s", "--source-code", dest=3D"FileType", const=3D"Sou= rceCode", action=3D"store_const", help=3D"The input file is preprocessed source co= de, including C or assembly code"), make_option("-r", "--vfr-file", dest=3D"FileType", const=3D"Vfr", = action=3D"store_const", help=3D"The input file is preprocessed VFR file"= ), + make_option("--Vfr-Uni-Offset", dest=3D"FileType", const=3D"VfrOff= setBin", action=3D"store_const", + help=3D"The input file is EFI image"), make_option("-a", "--asl-file", dest=3D"FileType", const=3D"Asl", = action=3D"store_const", help=3D"The input file is ASL file"), make_option("-8", "--Edk-source-code", dest=3D"FileType", const=3D= "EdkSourceCode", action=3D"store_const", help=3D"The input file is source code for Edk to= be trimmed for ECP"), =20 @@ -547,30 +612,38 @@ def Options(): help=3D"Remove postfix of long number"), make_option("-i", "--include-path-file", dest=3D"IncludePathFile", help=3D"The input file is include path list to s= earch for ASL include file"), make_option("-o", "--output", dest=3D"OutputFile", help=3D"File to store the trimmed content"), + make_option("--ModuleName", dest=3D"ModuleName", help=3D"The modul= e's BASE_NAME"), + make_option("--DebugDir", dest=3D"DebugDir", + help=3D"Debug Output directory to store the outp= ut files"), make_option("-v", "--verbose", dest=3D"LogLevel", action=3D"store_= const", const=3DEdkLogger.VERBOSE, help=3D"Run verbosely"), make_option("-d", "--debug", dest=3D"LogLevel", type=3D"int", help=3D"Run with debug information"), make_option("-q", "--quiet", dest=3D"LogLevel", action=3D"store_co= nst", const=3DEdkLogger.QUIET, help=3D"Run quietly"), make_option("-?", action=3D"help", help=3D"show this help message = and exit"), ] =20 # use clearer usage to override default usage message - UsageString =3D "%prog [-s|-r|-a] [-c] [-v|-d |-q] [-i ] [-o ] " + UsageString =3D "%prog [-s|-r|-a|--Vfr-Uni-Offset] [-c] [-v|-d |-q] [-i ] [-o ] [--ModuleName ] [--DebugDir ] []" =20 Parser =3D OptionParser(description=3D__copyright__, version=3D__versi= on__, option_list=3DOptionList, usage=3DUsageString) Parser.set_defaults(FileType=3D"Vfr") Parser.set_defaults(ConvertHex=3DFalse) Parser.set_defaults(LogLevel=3DEdkLogger.INFO) =20 Options, Args =3D Parser.parse_args() =20 # error check + if Options.FileType =3D=3D 'VfrOffsetBin': + if len(Args) =3D=3D 0: + return Options, '' + elif len(Args) > 1: + EdkLogger.error("Trim", OPTION_NOT_SUPPORTED, ExtraData=3DPars= er.get_usage()) if len(Args) =3D=3D 0: EdkLogger.error("Trim", OPTION_MISSING, ExtraData=3DParser.get_usa= ge()) if len(Args) > 1: EdkLogger.error("Trim", OPTION_NOT_SUPPORTED, ExtraData=3DParser.g= et_usage()) =20 @@ -606,10 +679,12 @@ def Main(): if CommandOptions.OutputFile =3D=3D None: CommandOptions.OutputFile =3D os.path.splitext(InputFile)[= 0] + '.iii' TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptio= ns.IncludePathFile) elif CommandOptions.FileType =3D=3D "EdkSourceCode": TrimEdkSources(InputFile, CommandOptions.OutputFile) + elif CommandOptions.FileType =3D=3D "VfrOffsetBin": + GenerateVfrBinSec(CommandOptions.ModuleName, CommandOptions.De= bugDir, CommandOptions.OutputFile) else : if CommandOptions.OutputFile =3D=3D None: CommandOptions.OutputFile =3D os.path.splitext(InputFile)[= 0] + '.iii' TrimPreprocessedFile(InputFile, CommandOptions.OutputFile, Com= mandOptions.ConvertHex, CommandOptions.TrimLong) except FatalError, X: --=20 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel