]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/BPDG/BPDG.py
f50e6f7d2299dea3f60465255907dd135594e9f9
[mirror_edk2.git] / BaseTools / Source / Python / BPDG / BPDG.py
1 ## @file
2 # Intel Binary Product Data Generation Tool (Intel BPDG).
3 # This tool provide a simple process for the creation of a binary file containing read-only
4 # configuration data for EDK II platforms that contain Dynamic and DynamicEx PCDs described
5 # in VPD sections. It also provide an option for specifying an alternate name for a mapping
6 # file of PCD layout for use during the build when the platform integrator selects to use
7 # automatic offset calculation.
8 #
9 # Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
10 #
11 # This program and the accompanying materials
12 # are licensed and made available under the terms and conditions of the BSD License
13 # which accompanies this distribution. The full text of the license may be found at
14 # http://opensource.org/licenses/bsd-license.php
15 #
16 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #
19
20 ##
21 # Import Modules
22 #
23 import os
24 import sys
25 import encodings.ascii
26
27 from optparse import OptionParser
28 from Common import EdkLogger
29 from Common.BuildToolError import *
30
31 import StringTable as st
32 import GenVpd
33
34 PROJECT_NAME = st.LBL_BPDG_LONG_UNI
35 VERSION = st.LBL_BPDG_VERSION
36
37 ## Tool entrance method
38 #
39 # This method mainly dispatch specific methods per the command line options.
40 # If no error found, return zero value so the caller of this tool can know
41 # if it's executed successfully or not.
42 #
43 # @retval 0 Tool was successful
44 # @retval 1 Tool failed
45 #
46 def main():
47 global Options, Args
48
49 # Initialize log system
50 EdkLogger.Initialize()
51 Options, Args = MyOptionParser()
52
53 ReturnCode = 0
54
55 if Options.opt_verbose:
56 EdkLogger.SetLevel(EdkLogger.VERBOSE)
57 elif Options.opt_quiet:
58 EdkLogger.SetLevel(EdkLogger.QUIET)
59 elif Options.debug_level != None:
60 EdkLogger.SetLevel(Options.debug_level + 1)
61 else:
62 EdkLogger.SetLevel(EdkLogger.INFO)
63
64 if Options.bin_filename == None:
65 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")
66 if Options.filename == None:
67 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")
68
69 Force = False
70 if Options.opt_force != None:
71 Force = True
72
73 if (Args[0] != None) :
74 StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)
75 else :
76 EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",
77 None)
78
79 return ReturnCode
80
81
82 ## Parse command line options
83 #
84 # Using standard Python module optparse to parse command line option of this tool.
85 #
86 # @retval options A optparse.Values object containing the parsed options
87 # @retval args Target of BPDG command
88 #
89 def MyOptionParser():
90 #
91 # Process command line firstly.
92 #
93 parser = OptionParser(version="%s - Version %s\n" % (PROJECT_NAME, VERSION),
94 description='',
95 prog='BPDG',
96 usage=st.LBL_BPDG_USAGE
97 )
98 parser.add_option('-d', '--debug', action='store', type="int", dest='debug_level',
99 help=st.MSG_OPTION_DEBUG_LEVEL)
100 parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',
101 help=st.MSG_OPTION_VERBOSE)
102 parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,
103 help=st.MSG_OPTION_QUIET)
104 parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',
105 help=st.MSG_OPTION_VPD_FILENAME)
106 parser.add_option('-m', '--map-filename', action='store', dest='filename',
107 help=st.MSG_OPTION_MAP_FILENAME)
108 parser.add_option('-f', '--force', action='store_true', dest='opt_force',
109 help=st.MSG_OPTION_FORCE)
110
111 (options, args) = parser.parse_args()
112 if len(args) == 0:
113 EdkLogger.info("Please specify the filename.txt file which contain the VPD pcd info!")
114 EdkLogger.info(parser.usage)
115 sys.exit(1)
116 return options, args
117
118
119 ## Start BPDG and call the main functions
120 #
121 # This method mainly focus on call GenVPD class member functions to complete
122 # BPDG's target. It will process VpdFile override, and provide the interface file
123 # information.
124 #
125 # @Param InputFileName The filename include the vpd type pcd information
126 # @param MapFileName The filename of map file that stores vpd type pcd information.
127 # This file will be generated by the BPDG tool after fix the offset
128 # and adjust the offset to make the pcd data aligned.
129 # @param VpdFileName The filename of Vpd file that hold vpd pcd information.
130 # @param Force Override the exist Vpdfile or not.
131 #
132 def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):
133 if os.path.exists(VpdFileName) and not Force:
134 print "\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName
135 choice = sys.stdin.readline()
136 if choice.strip().lower() not in ['y', 'yes', '']:
137 return
138
139 GenVPD = GenVpd.GenVPD (InputFileName, MapFileName, VpdFileName)
140
141 EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))
142 EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))
143 EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))
144
145 GenVPD.ParserInputFile()
146 GenVPD.FormatFileLine()
147 GenVPD.FixVpdOffset()
148 GenVPD.GenerateVpdFile(MapFileName, VpdFileName)
149
150 EdkLogger.info("- Vpd pcd fixed done! -")
151
152 if __name__ == '__main__':
153 r = main()
154 ## 0-127 is a safe return range, and 1 is a standard default error
155 if r < 0 or r > 127: r = 1
156 sys.exit(r)
157
158