From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: liming.gao@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Tue, 18 Jun 2019 06:14:59 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2019 06:14:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,389,1557212400"; d="scan'208";a="150269155" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga007.jf.intel.com with ESMTP; 18 Jun 2019 06:14:58 -0700 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 18 Jun 2019 06:14:57 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 18 Jun 2019 06:14:56 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.185]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.76]) with mapi id 14.03.0439.000; Tue, 18 Jun 2019 21:14:55 +0800 From: "Liming Gao" To: "Kinney, Michael D" , "Fan, ZhijuX" , "devel@edk2.groups.io" CC: "Feng, Bob C" , "Zhang, Shenglei" Subject: Re: [PATCH V2] BaseTools/GenBiosId: Add a new tool GenBiosId Thread-Topic: [PATCH V2] BaseTools/GenBiosId: Add a new tool GenBiosId Thread-Index: AdUk+vLr4sxSnH91SPaTu3pqAnspYAANWAlwACnU3eA= Date: Tue, 18 Jun 2019 13:14:54 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E483191@SHSMSX104.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWM0OTBmN2EtNmIxYy00ZmIzLWI5ODgtNjFhMmQyNTYyZTM2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoic2FpYTJON0VrVlFnbFd1VFpWN1wvdGw5bUpBTlV5T0RqXC9wbTF1U1h5U0VubDNodjVGMkt0dktZTnV3R2VLSHBsIn0= dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mike: I agree this suggestion. How about introduce -ot option for text file to = include this string? Thanks Liming > -----Original Message----- > From: Kinney, Michael D > Sent: Tuesday, June 18, 2019 1:18 AM > To: Fan, ZhijuX ; devel@edk2.groups.io; Kinney, Mic= hael D > Cc: Gao, Liming ; Feng, Bob C ; Zhang, Shenglei > Subject: RE: [PATCH V2] BaseTools/GenBiosId: Add a new tool GenBiosId >=20 > We would like to move to Python based tools for > everything with no requirements to use batch files > or shell scripts. >=20 > Do we really need the -ob --batch flag? I looks > like the feature it provides is a text string of the > BIOSID. Can't we send that to stdout or just put > that text string in an output file without using > any batch file or shell script specific syntax? >=20 > Thanks, >=20 > Mike >=20 >=20 >=20 > > -----Original Message----- > > From: Fan, ZhijuX > > Sent: Monday, June 17, 2019 3:54 AM > > To: devel@edk2.groups.io > > Cc: Gao, Liming ; Feng, Bob C > > ; Zhang, Shenglei > > ; Kinney, Michael D > > > > Subject: [PATCH V2] BaseTools/GenBiosId: Add a new tool > > GenBiosId > > > > GenBiosId is a tool to generate the BIOS ID binary file > > which uses the data from the configuration file. > > https://bugzilla.tianocore.org/show_bug.cgi?id=3D1846 > > > > v2:v1 is a tool of C type and v2 is python type. > > > > Cc: Bob Feng > > Cc: Liming Gao > > Signed-off-by: Shenglei Zhang > > --- > > BaseTools/BinWrappers/PosixLike/GenBiosId | 14 > > +++ > > BaseTools/BinWrappers/WindowsLike/GenBiosId.bat | 3 + > > BaseTools/Source/Python/GenBiosId/BiosId.env | 27 > > ++++++ > > BaseTools/Source/Python/GenBiosId/GenBiosId.py | 118 > > ++++++++++++++++++++++++ > > 4 files changed, 162 insertions(+) > > create mode 100644 > > BaseTools/BinWrappers/PosixLike/GenBiosId > > create mode 100644 > > BaseTools/BinWrappers/WindowsLike/GenBiosId.bat > > create mode 100644 > > BaseTools/Source/Python/GenBiosId/BiosId.env > > create mode 100644 > > BaseTools/Source/Python/GenBiosId/GenBiosId.py > > > > diff --git a/BaseTools/BinWrappers/PosixLike/GenBiosId > > b/BaseTools/BinWrappers/PosixLike/GenBiosId > > new file mode 100644 > > index 0000000000..1dd28e9662 > > --- /dev/null > > +++ b/BaseTools/BinWrappers/PosixLike/GenBiosId > > @@ -0,0 +1,14 @@ > > +#!/usr/bin/env bash > > +#python `dirname $0`/RunToolFromSource.py `basename $0` > > $* > > + > > +# If a ${PYTHON_COMMAND} command is available, use it in > > preference to > > +python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; > > then > > + python_exe=3D${PYTHON_COMMAND} > > +fi > > + > > +full_cmd=3D${BASH_SOURCE:-$0} # see > > +http://mywiki.wooledge.org/BashFAQ/028 for a discussion > > of why $0 is > > +not a good choice here dir=3D$(dirname "$full_cmd") > > exe=3D$(basename > > +"$full_cmd") > > + > > +export > > PYTHONPATH=3D"$dir/../../Source/Python${PYTHONPATH:+:"$PYTH > > ONPATH"}" > > +exec "${python_exe:-python}" > > "$dir/../../Source/Python/$exe/$exe.py" "$@" > > diff --git > > a/BaseTools/BinWrappers/WindowsLike/GenBiosId.bat > > b/BaseTools/BinWrappers/WindowsLike/GenBiosId.bat > > new file mode 100644 > > index 0000000000..e1f61382c8 > > --- /dev/null > > +++ b/BaseTools/BinWrappers/WindowsLike/GenBiosId.bat > > @@ -0,0 +1,3 @@ > > +@setlocal > > +@set ToolName=3D%~n0% > > +@%PYTHON_COMMAND% > > +%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py > > %* > > diff --git a/BaseTools/Source/Python/GenBiosId/BiosId.env > > b/BaseTools/Source/Python/GenBiosId/BiosId.env > > new file mode 100644 > > index 0000000000..e1e913da76 > > --- /dev/null > > +++ b/BaseTools/Source/Python/GenBiosId/BiosId.env > > @@ -0,0 +1,27 @@ > > +## @file > > +# This file is used to define the BIOS ID parameters of > > the build. > > +# This file is processed by GenBiosId. > > +# Here, it is just a template and can be customized by > > user. > > +# > > +# BIOS ID string format: > > +# > > $(BOARD_ID)$(BOARD_REV).$(BOARD_EXT).$(VERSION_MAJOR).$(B > > UILD_TYPE)$(VERSION_MINOR).YYMMDDHHMM > > +# All fields must have a fixed length. YYMMDDHHMM is > > UTC time. > > +# Example: "EMLATOR1.000.0001.D01.1906141517" > > +# > > +# If DATE is specified for YYMMDD and TIME is specified > > for HHMM like > > +below, # GenBiosId will use the value of DATE and TIME > > to fill > > +YYMMDDHHMM, # otherwise GenBiosId will fill YYMMDDHHMM > > with current UTC time of the build machine. > > +# DATE =3D 190614 > > +# TIME =3D 1517 > > +# > > +# Copyright (c) 2019, Intel Corporation. All rights > > reserved.
# > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ## > > [config] > > +BOARD_ID =3D EMLATOR > > +BOARD_REV =3D 1 > > +BOARD_EXT =3D 000 > > +BUILD_TYPE =3D D > > +VERSION_MAJOR =3D 0001 > > +VERSION_MINOR =3D 01 > > diff --git > > a/BaseTools/Source/Python/GenBiosId/GenBiosId.py > > b/BaseTools/Source/Python/GenBiosId/GenBiosId.py > > new file mode 100644 > > index 0000000000..8259b17afd > > --- /dev/null > > +++ b/BaseTools/Source/Python/GenBiosId/GenBiosId.py > > @@ -0,0 +1,118 @@ > > +## @file > > +# Trim files preprocessed by compiler > > +# > > +# Copyright (c) 2019, Intel Corporation. All rights > > reserved.
# > > +SPDX-License-Identifier: BSD-2-Clause-Patent # > > + > > +## > > +# Import Modules > > +# > > +import Common.LongFilePathOs as os > > +import sys > > +import struct > > +import time > > +import datetime > > +import argparse > > +try: > > + from configparser import ConfigParser > > +except: > > + from ConfigParser import ConfigParser from > > Common.BuildToolError > > +import * from Common.Misc import * from Common.DataType > > import * from > > +Common.BuildVersion import gBUILD_VERSION import > > Common.EdkLogger as > > +EdkLogger from Common.LongFilePathSupport import > > OpenLongFilePath as > > +open > > + > > +_BIOS_Signature =3D "$IBIOSI$" > > +_SectionKeyName =3D '__name__' > > +_SectionName =3D 'config' > > + > > +__prog__ =3D 'GenBiosld' > > +__description__ =3D 'Trim files preprocessed by compiler' > > +__copyright__ =3D 'Copyright (c) 2019, Intel Corporation. > > All rights reserved.
' > > +__version__ =3D '%s Version %s' % (__prog__, '0.1 ') > > + > > +_ConfigItem =3D { > > + "BOARD_ID" : {'Value' : '', 'Length' : 7}, > > + "BOARD_REV" : {'Value' : '', 'Length' : 1}, > > + "BOARD_EXT" : { 'Value' : '', 'Length' : 3}, > > + "BUILD_TYPE" : {'Value' : '', 'Length' :1}, > > + "VERSION_MAJOR" : {'Value' : '0000', 'Length' : 4}, > > + "VERSION_MINOR" : {'Value' : '00', 'Length' : 2}, > > + > > +} > > + > > + > > +_Usage =3D "Usage: GenBiosId -i Configfile -o OutputFile > > [-ob OutputBatchFile]" > > +_ConfigSectionNotDefine =3D "Not support the config file > > format, need config section" > > +_ConfigLenInvalid =3D "Config item %s length is invalid" > > +_ConfigItemInvalid =3D "Item %s is invalid" > > + > > +def Main(): > > + parser =3D argparse.ArgumentParser(prog=3D__prog__, > > + > > description=3D__description__ + __copyright__ + _Usage, > > + > > conflict_handler=3D'resolve') > > + parser.add_argument('-v', '--version', > > action=3D'version', version=3D__version__, > > + help=3D"show program's version > > number and exit") > > + parser.add_argument('-i', '--int', > > metavar=3D'FILENAME', dest=3D'InputFile', help=3D"Input Config > > file") > > + parser.add_argument('-o', '--out', > > metavar=3D'FILENAME', dest=3D'OutputFile', help=3D"Output > > file") > > + parser.add_argument('-ob', '--batch', > > metavar=3D'FILENAME', dest=3D'OutputBatchFile', > > help=3D"OutputBatch file") > > + Options =3D parser.parse_args() > > + try: > > + EdkLogger.Initialize() > > + if len(sys.argv) !=3D5 and not (len(sys.argv) =3D=3D 7 > > and Options.OutputBatchFile): > > + EdkLogger.error("GenBiosId", OPTION_MISSING, > > ExtraData=3D_Usage) > > + elif not Options.InputFile or not > > Options.OutputFile: > > + EdkLogger.error("GenBiosId", OPTION_MISSING, > > ExtraData=3D_Usage) > > + except FatalError as X: > > + return 1 > > + InputFile =3D Options.InputFile > > + OutputFile =3D Options.OutputFile > > + OutputBatchFile =3D Options.OutputBatchFile > > + if not os.path.exists(InputFile): > > + EdkLogger.error("GenBiosId", FILE_NOT_FOUND, > > ExtraData=3D"Input file not found") > > + cf =3D ConfigParser() > > + cf.optionxform =3D str > > + cf.read(InputFile) > > + if _SectionName not in cf._sections: > > + EdkLogger.error("GenBiosId", > > FORMAT_NOT_SUPPORTED, ExtraData=3D_ConfigSectionNotDefine) > > + for Item in cf._sections[_SectionName]: > > + if Item =3D=3D _SectionKeyName: > > + continue > > + if Item not in _ConfigItem: > > + EdkLogger.error("GenBiosId", FORMAT_INVALID, > > ExtraData=3D_ConfigItemInvalid % Item) > > + _ConfigItem[Item]['Value'] =3D > > cf._sections[_SectionName][Item] > > + if len(_ConfigItem[Item]['Value']) !=3D > > _ConfigItem[Item]['Length']: > > + EdkLogger.error("GenBiosId", FORMAT_INVALID, > > ExtraData=3D_ConfigLenInvalid % Item) > > + for Item in _ConfigItem: > > + if not _ConfigItem[Item]['Value']: > > + EdkLogger.error("GenBiosId", > > FORMAT_UNKNOWN_ERROR, ExtraData=3D"Item %s is missing" % > > Item) > > + utcnow =3D datetime.datetime.utcnow() > > + TimeStamp =3D time.strftime("%y%m%d%H%M", > > utcnow.timetuple()) > > + > > + Id_Str =3D _ConfigItem['BOARD_ID']['Value'] + > > _ConfigItem['BOARD_REV']['Value'] + '.' + > > _ConfigItem['BOARD_EXT']['Value'] + '.' + > > _ConfigItem['VERSION_MAJOR']['Value'] + \ > > + '.' + _ConfigItem["BUILD_TYPE"]['Value'] + > > _ConfigItem['VERSION_MINOR']['Value'] + '.' + TimeStamp > > + with open(OutputFile, 'wb') as FdOut: > > + for i in _BIOS_Signature: > > + FdOut.write(struct.pack('B', ord(i))) > > + > > + for i in Id_Str: > > + FdOut.write(struct.pack('H', ord(i))) > > + > > + FdOut.write(struct.pack('H', 0x00)) > > + if OutputBatchFile: > > + with open(OutputBatchFile, 'w') as FdOut: > > + if sys.platform.startswith('win'): > > + Id_Str =3D 'SET BIOS_ID=3D' + Id_Str > > + else: > > + Id_Str =3D 'export BIOS_ID=3D' + Id_Str > > + FdOut.write(Id_Str) > > + return 0 > > + > > +if __name__ =3D=3D '__main__': > > + r =3D Main() > > + ## 0-127 is a safe return range, and 1 is a standard > > default error > > + if r < 0 or r > 127: r =3D 1 > > + sys.exit(r) > > -- > > 2.14.1.windows.1