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