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 - 2016, Intel Corporation. All rights reserved.<BR>
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
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.
23 from __future__
import print_function
24 import Common
.LongFilePathOs
as os
26 import encodings
.ascii
28 from optparse
import OptionParser
29 from Common
import EdkLogger
30 from Common
.BuildToolError
import *
31 from Common
.BuildVersion
import gBUILD_VERSION
33 import StringTable
as st
36 PROJECT_NAME
= st
.LBL_BPDG_LONG_UNI
37 VERSION
= (st
.LBL_BPDG_VERSION
+ " Build " + gBUILD_VERSION
)
39 ## Tool entrance method
41 # This method mainly dispatch specific methods per the command line options.
42 # If no error found, return zero value so the caller of this tool can know
43 # if it's executed successfully or not.
45 # @retval 0 Tool was successful
46 # @retval 1 Tool failed
51 # Initialize log system
52 EdkLogger
.Initialize()
53 Options
, Args
= MyOptionParser()
57 if Options
.opt_verbose
:
58 EdkLogger
.SetLevel(EdkLogger
.VERBOSE
)
59 elif Options
.opt_quiet
:
60 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
61 elif Options
.debug_level
is not None:
62 EdkLogger
.SetLevel(Options
.debug_level
+ 1)
64 EdkLogger
.SetLevel(EdkLogger
.INFO
)
66 if Options
.bin_filename
is None:
67 EdkLogger
.error("BPDG", ATTRIBUTE_NOT_AVAILABLE
, "Please use the -o option to specify the file name for the VPD binary file")
68 if Options
.filename
is None:
69 EdkLogger
.error("BPDG", ATTRIBUTE_NOT_AVAILABLE
, "Please use the -m option to specify the file name for the mapping file")
72 if Options
.opt_force
is not None:
75 if (Args
[0] is not None) :
76 StartBpdg(Args
[0], Options
.filename
, Options
.bin_filename
, Force
)
78 EdkLogger
.error("BPDG", ATTRIBUTE_NOT_AVAILABLE
, "Please specify the file which contain the VPD pcd info.",
84 ## Parse command line options
86 # Using standard Python module optparse to parse command line option of this tool.
88 # @retval options A optparse.Values object containing the parsed options
89 # @retval args Target of BPDG command
93 # Process command line firstly.
95 parser
= OptionParser(version
="%s - Version %s" % (PROJECT_NAME
, VERSION
),
98 usage
=st
.LBL_BPDG_USAGE
100 parser
.add_option('-d', '--debug', action
='store', type="int", dest
='debug_level',
101 help=st
.MSG_OPTION_DEBUG_LEVEL
)
102 parser
.add_option('-v', '--verbose', action
='store_true', dest
='opt_verbose',
103 help=st
.MSG_OPTION_VERBOSE
)
104 parser
.add_option('-q', '--quiet', action
='store_true', dest
='opt_quiet', default
=False,
105 help=st
.MSG_OPTION_QUIET
)
106 parser
.add_option('-o', '--vpd-filename', action
='store', dest
='bin_filename',
107 help=st
.MSG_OPTION_VPD_FILENAME
)
108 parser
.add_option('-m', '--map-filename', action
='store', dest
='filename',
109 help=st
.MSG_OPTION_MAP_FILENAME
)
110 parser
.add_option('-f', '--force', action
='store_true', dest
='opt_force',
111 help=st
.MSG_OPTION_FORCE
)
113 (options
, args
) = parser
.parse_args()
115 EdkLogger
.info("Please specify the filename.txt file which contain the VPD pcd info!")
116 EdkLogger
.info(parser
.usage
)
121 ## Start BPDG and call the main functions
123 # This method mainly focus on call GenVPD class member functions to complete
124 # BPDG's target. It will process VpdFile override, and provide the interface file
127 # @Param InputFileName The filename include the vpd type pcd information
128 # @param MapFileName The filename of map file that stores vpd type pcd information.
129 # This file will be generated by the BPDG tool after fix the offset
130 # and adjust the offset to make the pcd data aligned.
131 # @param VpdFileName The filename of Vpd file that hold vpd pcd information.
132 # @param Force Override the exist Vpdfile or not.
134 def StartBpdg(InputFileName
, MapFileName
, VpdFileName
, Force
):
135 if os
.path
.exists(VpdFileName
) and not Force
:
136 print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName
)
137 choice
= sys
.stdin
.readline()
138 if choice
.strip().lower() not in ['y', 'yes', '']:
141 GenVPD
= GenVpd
.GenVPD (InputFileName
, MapFileName
, VpdFileName
)
143 EdkLogger
.info('%-24s = %s' % ("VPD input data file: ", InputFileName
))
144 EdkLogger
.info('%-24s = %s' % ("VPD output map file: ", MapFileName
))
145 EdkLogger
.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName
))
147 GenVPD
.ParserInputFile()
148 GenVPD
.FormatFileLine()
149 GenVPD
.FixVpdOffset()
150 GenVPD
.GenerateVpdFile(MapFileName
, VpdFileName
)
152 EdkLogger
.info("- Vpd pcd fixed done! -")
154 if __name__
== '__main__':
156 ## 0-127 is a safe return range, and 1 is a standard default error
157 if r
< 0 or r
> 127: r
= 1