public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Zhang, Shenglei" <shenglei.zhang@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "Fan, ZhijuX" <zhijux.fan@intel.com>,
	"Feng, Bob C" <bob.c.feng@intel.com>,
	"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [edk2-devel] [PATCH] BaseTools/GenBiosId: Add a new tool GenBiosId
Date: Fri, 14 Jun 2019 15:06:37 +0000	[thread overview]
Message-ID: <E92EE9817A31E24EB0585FDF735412F5B9D3F0F8@ORSMSX113.amr.corp.intel.com> (raw)
In-Reply-To: <20190614073855.14788-1-shenglei.zhang@intel.com>

Thank you for converting to Python.

Please use python argparse module to parse arguments and make
sure the tool supports the standard EDK II tool command line
arguments.  BinToPcd is a good example:

https://github.com/tianocore/edk2/blob/master/BaseTools/Scripts/BinToPcd.py

Mike

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io]
> On Behalf Of Zhang, Shenglei
> Sent: Friday, June 14, 2019 12:39 AM
> To: devel@edk2.groups.io
> Cc: Fan, ZhijuX <zhijux.fan@intel.com>; Feng, Bob C
> <bob.c.feng@intel.com>; Gao, Liming
> <liming.gao@intel.com>
> Subject: [edk2-devel] [PATCH] BaseTools/GenBiosId: Add a
> new tool GenBiosId
> 
> From: "Fan, Zhiju" <zhijux.fan@intel.com>
> 
> 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=1846
> 
> v2:v1 is a tool of C type and v2 is python type.
> 
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
>  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/BinWrappers/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
> +python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1;
> then
> +    python_exe=${PYTHON_COMMAND}
> +fi
> +
> +full_cmd=${BASH_SOURCE:-$0} # see
> +http://mywiki.wooledge.org/BashFAQ/028 for a discussion
> of why $0 is
> +not a good choice here dir=$(dirname "$full_cmd")
> exe=$(basename
> +"$full_cmd")
> +
> +export
> PYTHONPATH="$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 000000000000..9616cd893bec
> --- /dev/null
> +++ b/BaseTools/BinWrappers/WindowsLike/GenBiosId.bat
> @@ -0,0 +1,3 @@
> +@setlocal
> +@set ToolName=%~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 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).$(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          = 190614
> +#    TIME          = 1517
> +#
> +#  Copyright (c) 2019, Intel Corporation. All rights
> reserved.<BR> #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> [config]
> +BOARD_ID      = EMLATOR
> +BOARD_REV     = 1
> +BOARD_EXT     = 000
> +BUILD_TYPE    = D
> +VERSION_MAJOR = 0001
> +VERSION_MINOR = 01
> diff --git
> a/BaseTools/Source/Python/GenBiosId/GenBiosId.py
> b/BaseTools/Source/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.<BR> #
> +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 = "$IBIOSI$"
> +_SectionKeyName = '__name__'
> +_SectionName = 'config'
> +
> +_ConfigItem = {
> +    "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 = "Usage: GenBiosId -i Configfile -o OutputFile
> [-ob OutputBatchFile]"
> +_ConfigSectionNotDefine = "Not support the config file
> format, need config section"
> +_ConfigLenInvalid = "Config item %s length is invalid"
> +_ConfigItemInvalid = "Item %s is invalid"
> +
> +def Main():
> +    try:
> +        EdkLogger.Initialize()
> +        if len(sys.argv) !=5 and len(sys.argv) != 7:
> +            EdkLogger.error("GenBiosId", OPTION_MISSING,
> ExtraData=_Usage)
> +    except FatalError as X:
> +        return 1
> +    InputFile = ''
> +    OutputFile = ''
> +    OutputBatchFile = ''
> +    for Index, Item in enumerate(sys.argv):
> +        if '-i' == Item:
> +            InputFile = sys.argv[Index + 1]
> +        if '-o' == Item:
> +            OutputFile = sys.argv[Index + 1]
> +        if '-ob' == Item:
> +            OutputBatchFile = sys.argv[Index + 1]
> +    if not os.path.exists(InputFile):
> +        EdkLogger.error("GenBiosId", FILE_NOT_FOUND,
> ExtraData="Input file not found")
> +    cf = ConfigParser()
> +    cf.optionxform = str
> +    cf.read(InputFile)
> +    if _SectionName not in cf._sections:
> +        EdkLogger.error("GenBiosId",
> FORMAT_NOT_SUPPORTED, ExtraData=_ConfigSectionNotDefine)
> +    for Item in cf._sections[_SectionName]:
> +        if Item == _SectionKeyName:
> +            continue
> +        if Item not in _ConfigItem:
> +            EdkLogger.error("GenBiosId", FORMAT_INVALID,
> ExtraData=_ConfigItemInvalid % Item)
> +        _ConfigItem[Item]['Value'] =
> cf._sections[_SectionName][Item]
> +        if len(_ConfigItem[Item]['Value']) !=
> _ConfigItem[Item]['Length']:
> +            EdkLogger.error("GenBiosId", FORMAT_INVALID,
> ExtraData=_ConfigLenInvalid % Item)
> +    for Item in _ConfigItem:
> +        if not _ConfigItem[Item]['Value']:
> +            EdkLogger.error("GenBiosId",
> FORMAT_UNKNOWN_ERROR, ExtraData="Item %s is missing" %
> Item)
> +    utcnow = datetime.datetime.utcnow()
> +    TimeStamp = time.strftime("%y%m%d%H%M",
> utcnow.timetuple())
> +
> +    Id_Str = _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 = 'SET BIOS_ID=' + Id_Str
> +            else:
> +                Id_Str = 'export BIOS_ID=' + Id_Str
> +            FdOut.write(Id_Str)
> +    return 0
> +
> +if __name__ == '__main__':
> +    r = Main()
> +    ## 0-127 is a safe return range, and 1 is a standard
> default error
> +    if r < 0 or r > 127: r = 1
> +    sys.exit(r)
> --
> 2.18.0.windows.1
> 
> 
> 


  reply	other threads:[~2019-06-14 15:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14  7:38 [PATCH] BaseTools/GenBiosId: Add a new tool GenBiosId Zhang, Shenglei
2019-06-14 15:06 ` Michael D Kinney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-05-28  1:32 Zhang, Shenglei
2019-05-28 16:48 ` [edk2-devel] " Michael D Kinney
2019-05-31  6:36   ` Zhang, Shenglei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E92EE9817A31E24EB0585FDF735412F5B9D3F0F8@ORSMSX113.amr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox