]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/BPDG/BPDG.py
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.
9 # Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
11 # SPDX-License-Identifier: BSD-2-Clause-Patent
17 from __future__
import print_function
18 from __future__
import absolute_import
19 import Common
.LongFilePathOs
as os
21 import encodings
.ascii
23 from optparse
import OptionParser
24 from Common
import EdkLogger
25 from Common
.BuildToolError
import *
26 from Common
.BuildVersion
import gBUILD_VERSION
28 from . import StringTable
as st
31 PROJECT_NAME
= st
.LBL_BPDG_LONG_UNI
32 VERSION
= (st
.LBL_BPDG_VERSION
+ " Build " + gBUILD_VERSION
)
34 ## Tool entrance method
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.
40 # @retval 0 Tool was successful
41 # @retval 1 Tool failed
46 # Initialize log system
47 EdkLogger
.Initialize()
48 Options
, Args
= MyOptionParser()
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)
59 EdkLogger
.SetLevel(EdkLogger
.INFO
)
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")
67 if Options
.opt_force
is not None:
70 if (Args
[0] is not None) :
71 StartBpdg(Args
[0], Options
.filename
, Options
.bin_filename
, Force
)
73 EdkLogger
.error("BPDG", ATTRIBUTE_NOT_AVAILABLE
, "Please specify the file which contain the VPD pcd info.",
79 ## Parse command line options
81 # Using standard Python module optparse to parse command line option of this tool.
83 # @retval options A optparse.Values object containing the parsed options
84 # @retval args Target of BPDG command
88 # Process command line firstly.
90 parser
= OptionParser(version
="%s - Version %s" % (PROJECT_NAME
, VERSION
),
93 usage
=st
.LBL_BPDG_USAGE
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
)
108 (options
, args
) = parser
.parse_args()
110 EdkLogger
.info("Please specify the filename.txt file which contain the VPD pcd info!")
111 EdkLogger
.info(parser
.usage
)
116 ## Start BPDG and call the main functions
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
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.
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', '']:
136 GenVPD
= GenVpd
.GenVPD (InputFileName
, MapFileName
, VpdFileName
)
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
))
142 GenVPD
.ParserInputFile()
143 GenVPD
.FormatFileLine()
144 GenVPD
.FixVpdOffset()
145 GenVPD
.GenerateVpdFile(MapFileName
, VpdFileName
)
147 EdkLogger
.info("- Vpd pcd fixed done! -")
149 if __name__
== '__main__':
152 except FatalError
as 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