]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/BPDG/BPDG.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / BPDG.py
... / ...
CommitLineData
1## @file\r
2# Intel Binary Product Data Generation Tool (Intel BPDG).\r
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
7# automatic offset calculation.\r
8#\r
9# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
10#\r
11# SPDX-License-Identifier: BSD-2-Clause-Patent\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
17from __future__ import print_function\r
18from __future__ import absolute_import\r
19import Common.LongFilePathOs as os\r
20import sys\r
21import encodings.ascii\r
22\r
23from optparse import OptionParser\r
24from Common import EdkLogger\r
25from Common.BuildToolError import *\r
26from Common.BuildVersion import gBUILD_VERSION\r
27\r
28from . import StringTable as st\r
29from . import GenVpd\r
30\r
31PROJECT_NAME = st.LBL_BPDG_LONG_UNI\r
32VERSION = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)\r
33\r
34## Tool entrance method\r
35#\r
36# This method mainly dispatch specific methods per the command line options.\r
37# If no error found, return zero value so the caller of this tool can know\r
38# if it's executed successfully or not.\r
39#\r
40# @retval 0 Tool was successful\r
41# @retval 1 Tool failed\r
42#\r
43def main():\r
44 global Options, Args\r
45\r
46 # Initialize log system\r
47 EdkLogger.Initialize()\r
48 Options, Args = MyOptionParser()\r
49\r
50 ReturnCode = 0\r
51\r
52 if Options.opt_verbose:\r
53 EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
54 elif Options.opt_quiet:\r
55 EdkLogger.SetLevel(EdkLogger.QUIET)\r
56 elif Options.debug_level is not None:\r
57 EdkLogger.SetLevel(Options.debug_level + 1)\r
58 else:\r
59 EdkLogger.SetLevel(EdkLogger.INFO)\r
60\r
61 if Options.bin_filename is None:\r
62 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")\r
63 if Options.filename is None:\r
64 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")\r
65\r
66 Force = False\r
67 if Options.opt_force is not None:\r
68 Force = True\r
69\r
70 if (Args[0] is not None) :\r
71 StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)\r
72 else :\r
73 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",\r
74 None)\r
75\r
76 return ReturnCode\r
77\r
78\r
79## Parse command line options\r
80#\r
81# Using standard Python module optparse to parse command line option of this tool.\r
82#\r
83# @retval options A optparse.Values object containing the parsed options\r
84# @retval args Target of BPDG command\r
85#\r
86def MyOptionParser():\r
87 #\r
88 # Process command line firstly.\r
89 #\r
90 parser = OptionParser(version="%s - Version %s" % (PROJECT_NAME, VERSION),\r
91 description='',\r
92 prog='BPDG',\r
93 usage=st.LBL_BPDG_USAGE\r
94 )\r
95 parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',\r
96 help=st.MSG_OPTION_DEBUG_LEVEL)\r
97 parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',\r
98 help=st.MSG_OPTION_VERBOSE)\r
99 parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,\r
100 help=st.MSG_OPTION_QUIET)\r
101 parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',\r
102 help=st.MSG_OPTION_VPD_FILENAME)\r
103 parser.add_option('-m', '--map-filename', action='store', dest='filename',\r
104 help=st.MSG_OPTION_MAP_FILENAME)\r
105 parser.add_option('-f', '--force', action='store_true', dest='opt_force',\r
106 help=st.MSG_OPTION_FORCE)\r
107\r
108 (options, args) = parser.parse_args()\r
109 if len(args) == 0:\r
110 EdkLogger.info("Please specify the filename.txt file which contain the VPD pcd info!")\r
111 EdkLogger.info(parser.usage)\r
112 sys.exit(1)\r
113 return options, args\r
114\r
115\r
116## Start BPDG and call the main functions\r
117#\r
118# This method mainly focus on call GenVPD class member functions to complete\r
119# BPDG's target. It will process VpdFile override, and provide the interface file\r
120# information.\r
121#\r
122# @Param InputFileName The filename include the vpd type pcd information\r
123# @param MapFileName The filename of map file that stores vpd type pcd information.\r
124# This file will be generated by the BPDG tool after fix the offset\r
125# and adjust the offset to make the pcd data aligned.\r
126# @param VpdFileName The filename of Vpd file that hold vpd pcd information.\r
127# @param Force Override the exist Vpdfile or not.\r
128#\r
129def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):\r
130 if os.path.exists(VpdFileName) and not Force:\r
131 print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)\r
132 choice = sys.stdin.readline()\r
133 if choice.strip().lower() not in ['y', 'yes', '']:\r
134 return\r
135\r
136 GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)\r
137\r
138 EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))\r
139 EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))\r
140 EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))\r
141\r
142 GenVPD.ParserInputFile()\r
143 GenVPD.FormatFileLine()\r
144 GenVPD.FixVpdOffset()\r
145 GenVPD.GenerateVpdFile(MapFileName, VpdFileName)\r
146\r
147 EdkLogger.info("- Vpd pcd fixed done! -")\r
148\r
149if __name__ == '__main__':\r
150 try:\r
151 r = main()\r
152 except FatalError as e:\r
153 r = e\r
154 ## 0-127 is a safe return range, and 1 is a standard default error\r
155 if r < 0 or r > 127: r = 1\r
156 sys.exit(r)\r
157\r
158\r