]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/BPDG/BPDG.py
BaseTools: Fix BPDG tool print traceback info issue
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / BPDG.py
CommitLineData
111be80f 1## @file\r
2# Intel Binary Product Data Generation Tool (Intel BPDG).\r
f7496d71
LG
3# This tool provide a simple process for the creation of a binary file containing read-only\r
4# configuration data for EDK II platforms that contain Dynamic and DynamicEx PCDs described\r
5# in VPD sections. It also provide an option for specifying an alternate name for a mapping\r
6# file of PCD layout for use during the build when the platform integrator selects to use\r
111be80f 7# automatic offset calculation.\r
8#\r
f7496d71 9# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
111be80f 10#\r
11# This program and the accompanying materials\r
12# are licensed and made available under the terms and conditions of the BSD License\r
13# which accompanies this distribution. The full text of the license may be found at\r
14# http://opensource.org/licenses/bsd-license.php\r
15#\r
16# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18#\r
19\r
20##\r
21# Import Modules\r
22#\r
1ccc4d89
LG
23from __future__ import print_function\r
24from __future__ import absolute_import\r
1be2ed90 25import Common.LongFilePathOs as os\r
111be80f 26import sys\r
27import encodings.ascii\r
28\r
29from optparse import OptionParser\r
111be80f 30from Common import EdkLogger\r
31from Common.BuildToolError import *\r
b36d134f 32from Common.BuildVersion import gBUILD_VERSION\r
111be80f 33\r
72a836c0
GL
34from . import StringTable as st\r
35from . import GenVpd\r
111be80f 36\r
37PROJECT_NAME = st.LBL_BPDG_LONG_UNI\r
45258285 38VERSION = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)\r
111be80f 39\r
40## Tool entrance method\r
41#\r
42# This method mainly dispatch specific methods per the command line options.\r
43# If no error found, return zero value so the caller of this tool can know\r
44# if it's executed successfully or not.\r
45#\r
46# @retval 0 Tool was successful\r
47# @retval 1 Tool failed\r
48#\r
49def main():\r
50 global Options, Args\r
f7496d71 51\r
111be80f 52 # Initialize log system\r
f7496d71 53 EdkLogger.Initialize()\r
08dd311f 54 Options, Args = MyOptionParser()\r
f7496d71 55\r
111be80f 56 ReturnCode = 0\r
f7496d71 57\r
08dd311f 58 if Options.opt_verbose:\r
111be80f 59 EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
60 elif Options.opt_quiet:\r
61 EdkLogger.SetLevel(EdkLogger.QUIET)\r
4231a819 62 elif Options.debug_level is not None:\r
f7496d71 63 EdkLogger.SetLevel(Options.debug_level + 1)\r
111be80f 64 else:\r
65 EdkLogger.SetLevel(EdkLogger.INFO)\r
f7496d71 66\r
4231a819 67 if Options.bin_filename is None:\r
f7496d71 68 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")\r
4231a819 69 if Options.filename is None:\r
f7496d71 70 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")\r
111be80f 71\r
72 Force = False\r
4231a819 73 if Options.opt_force is not None:\r
111be80f 74 Force = True\r
75\r
4231a819 76 if (Args[0] is not None) :\r
08dd311f 77 StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)\r
111be80f 78 else :\r
79 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",\r
f7496d71
LG
80 None)\r
81\r
111be80f 82 return ReturnCode\r
08dd311f
LG
83\r
84\r
85## Parse command line options\r
86#\r
87# Using standard Python module optparse to parse command line option of this tool.\r
88#\r
89# @retval options A optparse.Values object containing the parsed options\r
90# @retval args Target of BPDG command\r
f7496d71
LG
91#\r
92def MyOptionParser():\r
111be80f 93 #\r
94 # Process command line firstly.\r
95 #\r
45258285 96 parser = OptionParser(version="%s - Version %s" % (PROJECT_NAME, VERSION),\r
111be80f 97 description='',\r
98 prog='BPDG',\r
99 usage=st.LBL_BPDG_USAGE\r
100 )\r
101 parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',\r
102 help=st.MSG_OPTION_DEBUG_LEVEL)\r
103 parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',\r
104 help=st.MSG_OPTION_VERBOSE)\r
111be80f 105 parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,\r
106 help=st.MSG_OPTION_QUIET)\r
08dd311f 107 parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',\r
111be80f 108 help=st.MSG_OPTION_VPD_FILENAME)\r
109 parser.add_option('-m', '--map-filename', action='store', dest='filename',\r
f7496d71 110 help=st.MSG_OPTION_MAP_FILENAME)\r
111be80f 111 parser.add_option('-f', '--force', action='store_true', dest='opt_force',\r
f7496d71
LG
112 help=st.MSG_OPTION_FORCE)\r
113\r
111be80f 114 (options, args) = parser.parse_args()\r
115 if len(args) == 0:\r
116 EdkLogger.info("Please specify the filename.txt file which contain the VPD pcd info!")\r
117 EdkLogger.info(parser.usage)\r
118 sys.exit(1)\r
119 return options, args\r
08dd311f
LG
120\r
121\r
f7496d71 122## Start BPDG and call the main functions\r
08dd311f
LG
123#\r
124# This method mainly focus on call GenVPD class member functions to complete\r
125# BPDG's target. It will process VpdFile override, and provide the interface file\r
126# information.\r
127#\r
128# @Param InputFileName The filename include the vpd type pcd information\r
129# @param MapFileName The filename of map file that stores vpd type pcd information.\r
130# This file will be generated by the BPDG tool after fix the offset\r
131# and adjust the offset to make the pcd data aligned.\r
132# @param VpdFileName The filename of Vpd file that hold vpd pcd information.\r
133# @param Force Override the exist Vpdfile or not.\r
134#\r
135def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):\r
111be80f 136 if os.path.exists(VpdFileName) and not Force:\r
72443dd2 137 print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)\r
111be80f 138 choice = sys.stdin.readline()\r
139 if choice.strip().lower() not in ['y', 'yes', '']:\r
140 return\r
f7496d71 141\r
111be80f 142 GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)\r
f7496d71
LG
143\r
144 EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))\r
111be80f 145 EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))\r
f7496d71
LG
146 EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))\r
147\r
111be80f 148 GenVPD.ParserInputFile()\r
149 GenVPD.FormatFileLine()\r
150 GenVPD.FixVpdOffset()\r
151 GenVPD.GenerateVpdFile(MapFileName, VpdFileName)\r
f7496d71
LG
152\r
153 EdkLogger.info("- Vpd pcd fixed done! -")\r
111be80f 154\r
155if __name__ == '__main__':\r
b28d406b
FY
156 try:\r
157 r = main()\r
158 except FatalError as e:\r
159 r = e\r
111be80f 160 ## 0-127 is a safe return range, and 1 is a standard default error\r
161 if r < 0 or r > 127: r = 1\r
162 sys.exit(r)\r
163\r
f7496d71 164\r