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