From nobody Mon Apr 29 06:45:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+42420+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42420+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1560497939; cv=none; d=zoho.com; s=zohoarc; b=lcbBt+t03MZy2PWU91wJhPxEPX//YdcvS+8m3O8e9+G9aov3bd1VyUi5P7B8HWldqp/wNrSj2Rr/xRjm42LWdLTIwJ0FWFlqpeEcUmTTdiRXyUUW5xTgbI1pPq5LXqX97Hp3j5jZ+ptuOnHhLpgSjpDLOrbI2uKKIBiH0S4i2nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560497939; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=ZnrGGBzHT+qGBQaoALaGPzdg8Dv91XHsw1OhiqKtuFg=; b=FGmU/gmxuqjQZKhST/ilyOUm28dgrx4aSGFClVCX4Se1r9oz8wNAh4ao9wh/7UxtwqQikrk9YQhYIhxeLp2cqAYmjwWGI+QucFppGZfHfKdLlFVNBGV/GyIbhVPzZ4ycNR8duoXE3cQuV7jD77SWY0INTvFYm28aN/mVbadX3Ak= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42420+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1560497939320574.4422221047189; Fri, 14 Jun 2019 00:38:59 -0700 (PDT) Return-Path: X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by groups.io with SMTP; Fri, 14 Jun 2019 00:38:58 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2019 00:38:58 -0700 X-ExtLoop1: 1 X-Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga005.fm.intel.com with ESMTP; 14 Jun 2019 00:38:57 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: "Fan, Zhiju" , Bob Feng , Liming Gao Subject: [edk2-devel] [PATCH] BaseTools/GenBiosId: Add a new tool GenBiosId Date: Fri, 14 Jun 2019 15:38:55 +0800 Message-Id: <20190614073855.14788-1-shenglei.zhang@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,shenglei.zhang@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1560497938; bh=uz5q1rZsTAY/GE5Aaupyi11s3BS4LEZssN2+PKHaing=; h=Cc:Date:From:Reply-To:Subject:To; b=X+RsYR9K3CoVy4KvyVrCj/ZwF8uBQMpoqK1txCPZwflSJKk157+HzgwlcYWWZklX9SN YLzDS7EsNFma+q3E/9by7FEEPtpO6NmCz88DJSJgJYI9Hv+wDXwUmuEzRjiOG2/eMgxwS jjVUEWSyMrZ4YnQc/hGeNXkzNqaIdH49KNM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Fan, Zhiju" 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 +++ .../BinWrappers/WindowsLike/GenBiosId.bat | 3 + BaseTools/Source/Python/GenBiosId/BiosId.env | 27 +++++ .../Source/Python/GenBiosId/GenBiosId.py | 108 ++++++++++++++++++ 4 files changed, 152 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/BinWrapp= ers/PosixLike/GenBiosId new file mode 100644 index 000000000000..9fb68299e4c6 --- /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 pyt= hon +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:+:"$PYTHONPATH"}" +exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@" diff --git a/BaseTools/BinWrappers/WindowsLike/GenBiosId.bat b/BaseTools/Bi= nWrappers/WindowsLike/GenBiosId.bat new file mode 100644 index 000000000000..9616cd893bec --- /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/Sourc= e/Python/GenBiosId/BiosId.env new file mode 100644 index 000000000000..92805e3cb78c --- /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).$(BUILD_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 bel= ow, +# GenBiosId will use the value of DATE and TIME to fill YYMMDDHHMM, +# otherwise GenBiosId will fill YYMMDDHHMM with current UTC time of the b= uild 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/Sou= rce/Python/GenBiosId/GenBiosId.py new file mode 100644 index 000000000000..1be99f4a5931 --- /dev/null +++ b/BaseTools/Source/Python/GenBiosId/GenBiosId.py @@ -0,0 +1,108 @@ +## @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 +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' + +_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 OutputBatchF= ile]" +_ConfigSectionNotDefine =3D "Not support the config file format, need conf= ig section" +_ConfigLenInvalid =3D "Config item %s length is invalid" +_ConfigItemInvalid =3D "Item %s is invalid" + +def Main(): + try: + EdkLogger.Initialize() + if len(sys.argv) !=3D5 and len(sys.argv) !=3D 7: + EdkLogger.error("GenBiosId", OPTION_MISSING, ExtraData=3D_Usag= e) + except FatalError as X: + return 1 + InputFile =3D '' + OutputFile =3D '' + OutputBatchFile =3D '' + for Index, Item in enumerate(sys.argv): + if '-i' =3D=3D Item: + InputFile =3D sys.argv[Index + 1] + if '-o' =3D=3D Item: + OutputFile =3D sys.argv[Index + 1] + if '-ob' =3D=3D Item: + OutputBatchFile =3D sys.argv[Index + 1] + if not os.path.exists(InputFile): + EdkLogger.error("GenBiosId", FILE_NOT_FOUND, ExtraData=3D"Input fi= le 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_Co= nfigSectionNotDefine) + for Item in cf._sections[_SectionName]: + if Item =3D=3D _SectionKeyName: + continue + if Item not in _ConfigItem: + EdkLogger.error("GenBiosId", FORMAT_INVALID, ExtraData=3D_Conf= igItemInvalid % 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_Conf= igLenInvalid % 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['VE= RSION_MAJOR']['Value'] + \ + '.' + _ConfigItem["BUILD_TYPE"]['Value'] + _ConfigItem['VERSI= ON_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) --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#42420): https://edk2.groups.io/g/devel/message/42420 Mute This Topic: https://groups.io/mt/32061587/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-