]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/BPDG/BPDG.py
Add missing BPDG tool sources when sync to BaseTools r2042
[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, 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
28from encodings import gbk\r
29from Common import EdkLogger\r
30from Common.BuildToolError import *\r
31\r
32import StringTable as st\r
33import GenVpd\r
34\r
35PROJECT_NAME = st.LBL_BPDG_LONG_UNI\r
36VERSION = st.LBL_BPDG_VERSION\r
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
52 Options, Args = myOptionParser()\r
53 \r
54 ReturnCode = 0\r
55 \r
56 if Options.opt_slient:\r
57 EdkLogger.SetLevel(EdkLogger.ERROR)\r
58 elif Options.opt_verbose:\r
59 EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
60 elif Options.opt_quiet:\r
61 EdkLogger.SetLevel(EdkLogger.QUIET)\r
62 elif Options.debug_level != None:\r
63 EdkLogger.SetLevel(Options.debug_level + 1) \r
64 else:\r
65 EdkLogger.SetLevel(EdkLogger.INFO)\r
66 \r
67 if Options.vpd_filename == None:\r
68 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file") \r
69 if Options.filename == None:\r
70 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file") \r
71\r
72 Force = False\r
73 if Options.opt_force != None:\r
74 Force = True\r
75\r
76 if (Args[0] != None) :\r
77 startBPDG(Args[0], Options.filename, Options.vpd_filename, Force)\r
78 else :\r
79 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",\r
80 None) \r
81 \r
82 return ReturnCode\r
83 \r
84def myOptionParser(): \r
85 #\r
86 # Process command line firstly.\r
87 #\r
88 parser = OptionParser(version="%s - Version %s\n" % (PROJECT_NAME, VERSION),\r
89 description='',\r
90 prog='BPDG',\r
91 usage=st.LBL_BPDG_USAGE\r
92 )\r
93 parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',\r
94 help=st.MSG_OPTION_DEBUG_LEVEL)\r
95 parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',\r
96 help=st.MSG_OPTION_VERBOSE)\r
97 parser.add_option('-s', '--silent', action='store_true', dest='opt_slient', default=False,\r
98 help=st.MSG_OPTION_SILENT)\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='vpd_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
115def startBPDG(InputFileName, MapFileName, VpdFileName, Force):\r
116 if os.path.exists(VpdFileName) and not Force:\r
117 print "\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName\r
118 choice = sys.stdin.readline()\r
119 if choice.strip().lower() not in ['y', 'yes', '']:\r
120 return\r
121 \r
122 GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)\r
123 \r
124 EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName)) \r
125 EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))\r
126 EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName)) \r
127 \r
128 GenVPD.ParserInputFile()\r
129 GenVPD.FormatFileLine()\r
130 GenVPD.FixVpdOffset()\r
131 GenVPD.GenerateVpdFile(MapFileName, VpdFileName)\r
132 \r
133 EdkLogger.info("- Vpd pcd fixed done! -") \r
134\r
135if __name__ == '__main__':\r
136 r = main()\r
137 ## 0-127 is a safe return range, and 1 is a standard default error\r
138 if r < 0 or r > 127: r = 1\r
139 sys.exit(r)\r
140\r
141 \r