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