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