]>
Commit | Line | Data |
---|---|---|
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 |
2e351cbe | 11 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
111be80f | 12 | #\r |
13 | \r | |
14 | ##\r | |
15 | # Import Modules\r | |
16 | #\r | |
1ccc4d89 LG |
17 | from __future__ import print_function\r |
18 | from __future__ import absolute_import\r | |
1be2ed90 | 19 | import Common.LongFilePathOs as os\r |
111be80f | 20 | import sys\r |
21 | import encodings.ascii\r | |
22 | \r | |
23 | from optparse import OptionParser\r | |
111be80f | 24 | from Common import EdkLogger\r |
25 | from Common.BuildToolError import *\r | |
b36d134f | 26 | from Common.BuildVersion import gBUILD_VERSION\r |
111be80f | 27 | \r |
72a836c0 GL |
28 | from . import StringTable as st\r |
29 | from . import GenVpd\r | |
111be80f | 30 | \r |
31 | PROJECT_NAME = st.LBL_BPDG_LONG_UNI\r | |
45258285 | 32 | VERSION = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)\r |
111be80f | 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 | |
43 | def main():\r | |
44 | global Options, Args\r | |
f7496d71 | 45 | \r |
111be80f | 46 | # Initialize log system\r |
f7496d71 | 47 | EdkLogger.Initialize()\r |
08dd311f | 48 | Options, Args = MyOptionParser()\r |
f7496d71 | 49 | \r |
111be80f | 50 | ReturnCode = 0\r |
f7496d71 | 51 | \r |
08dd311f | 52 | if Options.opt_verbose:\r |
111be80f | 53 | EdkLogger.SetLevel(EdkLogger.VERBOSE)\r |
54 | elif Options.opt_quiet:\r | |
55 | EdkLogger.SetLevel(EdkLogger.QUIET)\r | |
4231a819 | 56 | elif Options.debug_level is not None:\r |
f7496d71 | 57 | EdkLogger.SetLevel(Options.debug_level + 1)\r |
111be80f | 58 | else:\r |
59 | EdkLogger.SetLevel(EdkLogger.INFO)\r | |
f7496d71 | 60 | \r |
4231a819 | 61 | if Options.bin_filename is None:\r |
f7496d71 | 62 | EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")\r |
4231a819 | 63 | if Options.filename is None:\r |
f7496d71 | 64 | EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")\r |
111be80f | 65 | \r |
66 | Force = False\r | |
4231a819 | 67 | if Options.opt_force is not None:\r |
111be80f | 68 | Force = True\r |
69 | \r | |
4231a819 | 70 | if (Args[0] is not None) :\r |
08dd311f | 71 | StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)\r |
111be80f | 72 | else :\r |
73 | EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",\r | |
f7496d71 LG |
74 | None)\r |
75 | \r | |
111be80f | 76 | return ReturnCode\r |
08dd311f LG |
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 | |
f7496d71 LG |
85 | #\r |
86 | def MyOptionParser():\r | |
111be80f | 87 | #\r |
88 | # Process command line firstly.\r | |
89 | #\r | |
45258285 | 90 | parser = OptionParser(version="%s - Version %s" % (PROJECT_NAME, VERSION),\r |
111be80f | 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 | |
111be80f | 99 | parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,\r |
100 | help=st.MSG_OPTION_QUIET)\r | |
08dd311f | 101 | parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',\r |
111be80f | 102 | help=st.MSG_OPTION_VPD_FILENAME)\r |
103 | parser.add_option('-m', '--map-filename', action='store', dest='filename',\r | |
f7496d71 | 104 | help=st.MSG_OPTION_MAP_FILENAME)\r |
111be80f | 105 | parser.add_option('-f', '--force', action='store_true', dest='opt_force',\r |
f7496d71 LG |
106 | help=st.MSG_OPTION_FORCE)\r |
107 | \r | |
111be80f | 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 | |
08dd311f LG |
114 | \r |
115 | \r | |
f7496d71 | 116 | ## Start BPDG and call the main functions\r |
08dd311f LG |
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 | |
129 | def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):\r | |
111be80f | 130 | if os.path.exists(VpdFileName) and not Force:\r |
72443dd2 | 131 | print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)\r |
111be80f | 132 | choice = sys.stdin.readline()\r |
133 | if choice.strip().lower() not in ['y', 'yes', '']:\r | |
134 | return\r | |
f7496d71 | 135 | \r |
111be80f | 136 | GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)\r |
f7496d71 LG |
137 | \r |
138 | EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))\r | |
111be80f | 139 | EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))\r |
f7496d71 LG |
140 | EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))\r |
141 | \r | |
111be80f | 142 | GenVPD.ParserInputFile()\r |
143 | GenVPD.FormatFileLine()\r | |
144 | GenVPD.FixVpdOffset()\r | |
145 | GenVPD.GenerateVpdFile(MapFileName, VpdFileName)\r | |
f7496d71 LG |
146 | \r |
147 | EdkLogger.info("- Vpd pcd fixed done! -")\r | |
111be80f | 148 | \r |
149 | if __name__ == '__main__':\r | |
b28d406b FY |
150 | try:\r |
151 | r = main()\r | |
152 | except FatalError as e:\r | |
153 | r = e\r | |
111be80f | 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 | |
f7496d71 | 158 | \r |