2010-09-06 04:01:57 +02:00
|
|
|
## @file
|
|
|
|
# Intel Binary Product Data Generation Tool (Intel BPDG).
|
2018-07-05 11:40:04 +02:00
|
|
|
# This tool provide a simple process for the creation of a binary file containing read-only
|
|
|
|
# configuration data for EDK II platforms that contain Dynamic and DynamicEx PCDs described
|
|
|
|
# in VPD sections. It also provide an option for specifying an alternate name for a mapping
|
|
|
|
# file of PCD layout for use during the build when the platform integrator selects to use
|
2010-09-06 04:01:57 +02:00
|
|
|
# automatic offset calculation.
|
|
|
|
#
|
2018-07-05 11:40:04 +02:00
|
|
|
# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
|
2010-09-06 04:01:57 +02:00
|
|
|
#
|
2019-04-04 01:03:11 +02:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
2010-09-06 04:01:57 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
##
|
|
|
|
# Import Modules
|
|
|
|
#
|
2018-10-15 02:27:53 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import absolute_import
|
2014-08-15 05:06:48 +02:00
|
|
|
import Common.LongFilePathOs as os
|
2010-09-06 04:01:57 +02:00
|
|
|
import sys
|
|
|
|
import encodings.ascii
|
|
|
|
|
|
|
|
from optparse import OptionParser
|
|
|
|
from Common import EdkLogger
|
|
|
|
from Common.BuildToolError import *
|
2011-09-18 14:17:25 +02:00
|
|
|
from Common.BuildVersion import gBUILD_VERSION
|
2010-09-06 04:01:57 +02:00
|
|
|
|
2018-07-13 12:18:39 +02:00
|
|
|
from . import StringTable as st
|
|
|
|
from . import GenVpd
|
2010-09-06 04:01:57 +02:00
|
|
|
|
|
|
|
PROJECT_NAME = st.LBL_BPDG_LONG_UNI
|
2016-03-09 02:42:06 +01:00
|
|
|
VERSION = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)
|
2010-09-06 04:01:57 +02:00
|
|
|
|
|
|
|
## Tool entrance method
|
|
|
|
#
|
|
|
|
# This method mainly dispatch specific methods per the command line options.
|
|
|
|
# If no error found, return zero value so the caller of this tool can know
|
|
|
|
# if it's executed successfully or not.
|
|
|
|
#
|
|
|
|
# @retval 0 Tool was successful
|
|
|
|
# @retval 1 Tool failed
|
|
|
|
#
|
|
|
|
def main():
|
|
|
|
global Options, Args
|
2018-07-05 11:40:04 +02:00
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
# Initialize log system
|
2018-07-05 11:40:04 +02:00
|
|
|
EdkLogger.Initialize()
|
2010-10-11 08:26:52 +02:00
|
|
|
Options, Args = MyOptionParser()
|
2018-07-05 11:40:04 +02:00
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
ReturnCode = 0
|
2018-07-05 11:40:04 +02:00
|
|
|
|
2010-10-11 08:26:52 +02:00
|
|
|
if Options.opt_verbose:
|
2010-09-06 04:01:57 +02:00
|
|
|
EdkLogger.SetLevel(EdkLogger.VERBOSE)
|
|
|
|
elif Options.opt_quiet:
|
|
|
|
EdkLogger.SetLevel(EdkLogger.QUIET)
|
2018-03-26 22:25:43 +02:00
|
|
|
elif Options.debug_level is not None:
|
2018-07-05 11:40:04 +02:00
|
|
|
EdkLogger.SetLevel(Options.debug_level + 1)
|
2010-09-06 04:01:57 +02:00
|
|
|
else:
|
|
|
|
EdkLogger.SetLevel(EdkLogger.INFO)
|
2018-07-05 11:40:04 +02:00
|
|
|
|
2018-03-26 22:25:43 +02:00
|
|
|
if Options.bin_filename is None:
|
2018-07-05 11:40:04 +02:00
|
|
|
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")
|
2018-03-26 22:25:43 +02:00
|
|
|
if Options.filename is None:
|
2018-07-05 11:40:04 +02:00
|
|
|
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")
|
2010-09-06 04:01:57 +02:00
|
|
|
|
|
|
|
Force = False
|
2018-03-26 22:25:43 +02:00
|
|
|
if Options.opt_force is not None:
|
2010-09-06 04:01:57 +02:00
|
|
|
Force = True
|
|
|
|
|
2018-03-26 22:25:43 +02:00
|
|
|
if (Args[0] is not None) :
|
2010-10-11 08:26:52 +02:00
|
|
|
StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)
|
2010-09-06 04:01:57 +02:00
|
|
|
else :
|
|
|
|
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",
|
2018-07-05 11:40:04 +02:00
|
|
|
None)
|
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
return ReturnCode
|
2010-10-11 08:26:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Parse command line options
|
|
|
|
#
|
|
|
|
# Using standard Python module optparse to parse command line option of this tool.
|
|
|
|
#
|
|
|
|
# @retval options A optparse.Values object containing the parsed options
|
|
|
|
# @retval args Target of BPDG command
|
2018-07-05 11:40:04 +02:00
|
|
|
#
|
|
|
|
def MyOptionParser():
|
2010-09-06 04:01:57 +02:00
|
|
|
#
|
|
|
|
# Process command line firstly.
|
|
|
|
#
|
2016-03-09 02:42:06 +01:00
|
|
|
parser = OptionParser(version="%s - Version %s" % (PROJECT_NAME, VERSION),
|
2010-09-06 04:01:57 +02:00
|
|
|
description='',
|
|
|
|
prog='BPDG',
|
|
|
|
usage=st.LBL_BPDG_USAGE
|
|
|
|
)
|
|
|
|
parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',
|
|
|
|
help=st.MSG_OPTION_DEBUG_LEVEL)
|
|
|
|
parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',
|
|
|
|
help=st.MSG_OPTION_VERBOSE)
|
|
|
|
parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,
|
|
|
|
help=st.MSG_OPTION_QUIET)
|
2010-10-11 08:26:52 +02:00
|
|
|
parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',
|
2010-09-06 04:01:57 +02:00
|
|
|
help=st.MSG_OPTION_VPD_FILENAME)
|
|
|
|
parser.add_option('-m', '--map-filename', action='store', dest='filename',
|
2018-07-05 11:40:04 +02:00
|
|
|
help=st.MSG_OPTION_MAP_FILENAME)
|
2010-09-06 04:01:57 +02:00
|
|
|
parser.add_option('-f', '--force', action='store_true', dest='opt_force',
|
2018-07-05 11:40:04 +02:00
|
|
|
help=st.MSG_OPTION_FORCE)
|
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if len(args) == 0:
|
|
|
|
EdkLogger.info("Please specify the filename.txt file which contain the VPD pcd info!")
|
|
|
|
EdkLogger.info(parser.usage)
|
|
|
|
sys.exit(1)
|
|
|
|
return options, args
|
2010-10-11 08:26:52 +02:00
|
|
|
|
|
|
|
|
2018-07-05 11:40:04 +02:00
|
|
|
## Start BPDG and call the main functions
|
2010-10-11 08:26:52 +02:00
|
|
|
#
|
|
|
|
# This method mainly focus on call GenVPD class member functions to complete
|
|
|
|
# BPDG's target. It will process VpdFile override, and provide the interface file
|
|
|
|
# information.
|
|
|
|
#
|
|
|
|
# @Param InputFileName The filename include the vpd type pcd information
|
|
|
|
# @param MapFileName The filename of map file that stores vpd type pcd information.
|
|
|
|
# This file will be generated by the BPDG tool after fix the offset
|
|
|
|
# and adjust the offset to make the pcd data aligned.
|
|
|
|
# @param VpdFileName The filename of Vpd file that hold vpd pcd information.
|
|
|
|
# @param Force Override the exist Vpdfile or not.
|
|
|
|
#
|
|
|
|
def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):
|
2010-09-06 04:01:57 +02:00
|
|
|
if os.path.exists(VpdFileName) and not Force:
|
2018-06-25 12:31:26 +02:00
|
|
|
print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)
|
2010-09-06 04:01:57 +02:00
|
|
|
choice = sys.stdin.readline()
|
|
|
|
if choice.strip().lower() not in ['y', 'yes', '']:
|
|
|
|
return
|
2018-07-05 11:40:04 +02:00
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)
|
2018-07-05 11:40:04 +02:00
|
|
|
|
|
|
|
EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))
|
2010-09-06 04:01:57 +02:00
|
|
|
EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))
|
2018-07-05 11:40:04 +02:00
|
|
|
EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))
|
|
|
|
|
2010-09-06 04:01:57 +02:00
|
|
|
GenVPD.ParserInputFile()
|
|
|
|
GenVPD.FormatFileLine()
|
|
|
|
GenVPD.FixVpdOffset()
|
|
|
|
GenVPD.GenerateVpdFile(MapFileName, VpdFileName)
|
2018-07-05 11:40:04 +02:00
|
|
|
|
|
|
|
EdkLogger.info("- Vpd pcd fixed done! -")
|
2010-09-06 04:01:57 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-10-25 07:51:01 +02:00
|
|
|
try:
|
|
|
|
r = main()
|
|
|
|
except FatalError as e:
|
|
|
|
r = e
|
2010-09-06 04:01:57 +02:00
|
|
|
## 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)
|
|
|
|
|
2018-07-05 11:40:04 +02:00
|
|
|
|