Sync EDKII BaseTools to BaseTools project r2065.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10915 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -25,7 +25,6 @@ import sys
|
||||
import encodings.ascii
|
||||
|
||||
from optparse import OptionParser
|
||||
from encodings import gbk
|
||||
from Common import EdkLogger
|
||||
from Common.BuildToolError import *
|
||||
|
||||
@ -49,13 +48,11 @@ def main():
|
||||
|
||||
# Initialize log system
|
||||
EdkLogger.Initialize()
|
||||
Options, Args = myOptionParser()
|
||||
Options, Args = MyOptionParser()
|
||||
|
||||
ReturnCode = 0
|
||||
|
||||
if Options.opt_slient:
|
||||
EdkLogger.SetLevel(EdkLogger.ERROR)
|
||||
elif Options.opt_verbose:
|
||||
if Options.opt_verbose:
|
||||
EdkLogger.SetLevel(EdkLogger.VERBOSE)
|
||||
elif Options.opt_quiet:
|
||||
EdkLogger.SetLevel(EdkLogger.QUIET)
|
||||
@ -64,7 +61,7 @@ def main():
|
||||
else:
|
||||
EdkLogger.SetLevel(EdkLogger.INFO)
|
||||
|
||||
if Options.vpd_filename == None:
|
||||
if Options.bin_filename == None:
|
||||
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -o option to specify the file name for the VPD binary file")
|
||||
if Options.filename == None:
|
||||
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please use the -m option to specify the file name for the mapping file")
|
||||
@ -74,14 +71,22 @@ def main():
|
||||
Force = True
|
||||
|
||||
if (Args[0] != None) :
|
||||
startBPDG(Args[0], Options.filename, Options.vpd_filename, Force)
|
||||
StartBpdg(Args[0], Options.filename, Options.bin_filename, Force)
|
||||
else :
|
||||
EdkLogger.error("BPDG", ATTRIBUTE_NOT_AVAILABLE, "Please specify the file which contain the VPD pcd info.",
|
||||
None)
|
||||
|
||||
return ReturnCode
|
||||
|
||||
def myOptionParser():
|
||||
|
||||
|
||||
## Parse command line options
|
||||
#
|
||||
# Using standard Python module optparse to parse command line option of this tool.
|
||||
#
|
||||
# @retval options A optparse.Values object containing the parsed options
|
||||
# @retval args Target of BPDG command
|
||||
#
|
||||
def MyOptionParser():
|
||||
#
|
||||
# Process command line firstly.
|
||||
#
|
||||
@ -94,11 +99,9 @@ def myOptionParser():
|
||||
help=st.MSG_OPTION_DEBUG_LEVEL)
|
||||
parser.add_option('-v', '--verbose', action='store_true', dest='opt_verbose',
|
||||
help=st.MSG_OPTION_VERBOSE)
|
||||
parser.add_option('-s', '--silent', action='store_true', dest='opt_slient', default=False,
|
||||
help=st.MSG_OPTION_SILENT)
|
||||
parser.add_option('-q', '--quiet', action='store_true', dest='opt_quiet', default=False,
|
||||
help=st.MSG_OPTION_QUIET)
|
||||
parser.add_option('-o', '--vpd-filename', action='store', dest='vpd_filename',
|
||||
parser.add_option('-o', '--vpd-filename', action='store', dest='bin_filename',
|
||||
help=st.MSG_OPTION_VPD_FILENAME)
|
||||
parser.add_option('-m', '--map-filename', action='store', dest='filename',
|
||||
help=st.MSG_OPTION_MAP_FILENAME)
|
||||
@ -111,8 +114,22 @@ def myOptionParser():
|
||||
EdkLogger.info(parser.usage)
|
||||
sys.exit(1)
|
||||
return options, args
|
||||
|
||||
def startBPDG(InputFileName, MapFileName, VpdFileName, Force):
|
||||
|
||||
|
||||
## Start BPDG and call the main functions
|
||||
#
|
||||
# This method mainly focus on call GenVPD class member functions to complete
|
||||
# BPDG's target. It will process VpdFile override, and provide the interface file
|
||||
# information.
|
||||
#
|
||||
# @Param InputFileName The filename include the vpd type pcd information
|
||||
# @param MapFileName The filename of map file that stores vpd type pcd information.
|
||||
# This file will be generated by the BPDG tool after fix the offset
|
||||
# and adjust the offset to make the pcd data aligned.
|
||||
# @param VpdFileName The filename of Vpd file that hold vpd pcd information.
|
||||
# @param Force Override the exist Vpdfile or not.
|
||||
#
|
||||
def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):
|
||||
if os.path.exists(VpdFileName) and not Force:
|
||||
print "\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName
|
||||
choice = sys.stdin.readline()
|
||||
|
@ -28,6 +28,10 @@ _FORMAT_CHAR = {1: 'B',
|
||||
8: 'Q'
|
||||
}
|
||||
|
||||
## The VPD PCD data structure for store and process each VPD PCD entry.
|
||||
#
|
||||
# This class contain method to format and pack pcd's value.
|
||||
#
|
||||
class PcdEntry:
|
||||
def __init__(self, PcdCName, PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None,
|
||||
PcdBinOffset=None, PcdBinSize=None):
|
||||
@ -54,12 +58,29 @@ class PcdEntry:
|
||||
"Invalid PCD format(Name: %s File: %s Line: %s), no PcdSize specified!" %(self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
self._GenOffsetValue ()
|
||||
|
||||
## Analyze the string value to judge the PCD's datum type euqal to Boolean or not.
|
||||
#
|
||||
# @param ValueString PCD's value
|
||||
# @param Size PCD's size
|
||||
#
|
||||
# @retval True PCD's datum type is Boolean
|
||||
# @retval False PCD's datum type is not Boolean.
|
||||
#
|
||||
def _IsBoolean(self, ValueString, Size):
|
||||
if (Size == "1"):
|
||||
if ValueString.upper() in ["TRUE", "FALSE"]:
|
||||
return True
|
||||
elif ValueString in ["0", "1", "0x0", "0x1", "0x00", "0x01"]:
|
||||
return True
|
||||
|
||||
def _IsBoolean(self, ValueString):
|
||||
if ValueString.upper() in ["TRUE", "FALSE"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
## Convert the PCD's value from string to integer.
|
||||
#
|
||||
# This function will try to convert the Offset value form string to integer
|
||||
# for both hexadecimal and decimal.
|
||||
#
|
||||
def _GenOffsetValue(self):
|
||||
if self.PcdOffset != "*" :
|
||||
try:
|
||||
@ -70,9 +91,14 @@ class PcdEntry:
|
||||
except:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid offset value %s for PCD %s (File: %s Line: %s)" % (self.PcdOffset, self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
|
||||
## Pack Boolean type VPD PCD's value form string to binary type.
|
||||
#
|
||||
# @param ValueString The boolean type string for pack.
|
||||
#
|
||||
#
|
||||
def _PackBooleanValue(self, ValueString):
|
||||
if ValueString.upper() == "TRUE":
|
||||
if ValueString.upper() == "TRUE" or ValueString in ["1", "0x1", "0x01"]:
|
||||
try:
|
||||
self.PcdValue = pack(_FORMAT_CHAR[1], 1)
|
||||
except:
|
||||
@ -83,18 +109,65 @@ class PcdEntry:
|
||||
self.PcdValue = pack(_FORMAT_CHAR[1], 0)
|
||||
except:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
## Pack Integer type VPD PCD's value form string to binary type.
|
||||
#
|
||||
# @param ValueString The Integer type string for pack.
|
||||
#
|
||||
#
|
||||
def _PackIntValue(self, IntValue, Size):
|
||||
if Size not in _FORMAT_CHAR.keys():
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
if Size == 1:
|
||||
if IntValue < 0:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"PCD can't be set to negative value %d for PCD %s in UINT8 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif IntValue >= 0x100:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Too large PCD value %d for datum type UINT8 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif Size == 2:
|
||||
if IntValue < 0:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"PCD can't be set to negative value %d for PCD %s in UINT16 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif IntValue >= 0x10000:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Too large PCD value %d for datum type UINT16 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif Size == 4:
|
||||
if IntValue < 0:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"PCD can't be set to negative value %d for PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif IntValue >= 0x100000000:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Too large PCD value %d for datum type UINT32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif Size == 8:
|
||||
if IntValue < 0:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"PCD can't be set to negative value %d for PCD %s in UINT32 datum type(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
elif IntValue >= 0x10000000000000000:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Too large PCD value %d for datum type UINT32 for PCD %s(File: %s Line: %s)." % (IntValue, self.PcdCName, self.FileName, self.Lineno))
|
||||
else:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
try:
|
||||
self.PcdValue = pack(_FORMAT_CHAR[Size], IntValue)
|
||||
except:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
|
||||
## Pack VOID* type VPD PCD's value form string to binary type.
|
||||
#
|
||||
# The VOID* type of string divided into 3 sub-type:
|
||||
# 1: L"String", Unicode type string.
|
||||
# 2: "String", Ascii type string.
|
||||
# 3: {bytearray}, only support byte-array.
|
||||
#
|
||||
# @param ValueString The Integer type string for pack.
|
||||
#
|
||||
def _PackPtrValue(self, ValueString, Size):
|
||||
if ValueString.startswith('L"'):
|
||||
self._PackUnicode(ValueString, Size)
|
||||
@ -105,7 +178,11 @@ class PcdEntry:
|
||||
else:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid VOID* type PCD %s value %s (File: %s Line: %s)" % (self.PcdCName, ValueString, self.FileName, self.Lineno))
|
||||
|
||||
|
||||
## Pack an Ascii PCD value.
|
||||
#
|
||||
# An Ascii string for a PCD should be in format as "".
|
||||
#
|
||||
def _PackString(self, ValueString, Size):
|
||||
if (Size < 0):
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
@ -123,8 +200,12 @@ class PcdEntry:
|
||||
self.PcdValue= pack('%ds' % Size, ValueString)
|
||||
except:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))
|
||||
|
||||
## Pack a byte-array PCD value.
|
||||
#
|
||||
# A byte-array for a PCD should be in format as {0x01, 0x02, ...}.
|
||||
#
|
||||
def _PackByteArray(self, ValueString, Size):
|
||||
if (Size < 0):
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid parameter Size %s of PCD %s!(File: %s Line: %s)" % (self.PcdBinSize, self.PcdCName, self.FileName, self.Lineno))
|
||||
@ -206,9 +287,18 @@ class PcdEntry:
|
||||
ReturnArray.append(0)
|
||||
|
||||
self.PcdValue = ReturnArray.tolist()
|
||||
|
||||
class GenVPD :
|
||||
|
||||
|
||||
|
||||
|
||||
## The class implementing the BPDG VPD PCD offset fix process
|
||||
#
|
||||
# The VPD PCD offset fix process includes:
|
||||
# 1. Parse the input guided.txt file and store it in the data structure;
|
||||
# 2. Format the input file data to remove unused lines;
|
||||
# 3. Fixed offset if needed;
|
||||
# 4. Generate output file, including guided.map and guided.bin file;
|
||||
#
|
||||
class GenVPD :
|
||||
## Constructor of DscBuildData
|
||||
#
|
||||
# Initialize object of GenVPD
|
||||
@ -310,7 +400,7 @@ class GenVPD :
|
||||
except:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid PCD size value %s at file: %s line: %s" % (PCD.PcdSize, self.InputFileName, PCD.Lineno))
|
||||
|
||||
if PCD._IsBoolean(PCD.PcdValue):
|
||||
if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):
|
||||
PCD._PackBooleanValue(PCD.PcdValue)
|
||||
self.FileLinesList[count] = PCD
|
||||
count += 1
|
||||
|
@ -55,7 +55,7 @@ Intel(r) Binary Product Data Generation Tool (Intel(r) BPDG)
|
||||
Copyright (c) 2010 Intel Corporation All Rights Reserved.
|
||||
|
||||
Required Flags:
|
||||
-o VPD_FILENAME, --vpd-filename=VPD_FILENAME
|
||||
-o BIN_FILENAME, --vpd-filename=BIN_FILENAME
|
||||
Specify the file name for the VPD binary file
|
||||
-m FILENAME, --map-filename=FILENAME
|
||||
Generate file name for consumption during the build that contains
|
||||
@ -67,11 +67,10 @@ Required Flags:
|
||||
MSG_OPTION_HELP = ("Show this help message and exit.")
|
||||
MSG_OPTION_DEBUG_LEVEL = ("Print DEBUG statements, where DEBUG_LEVEL is 0-9.")
|
||||
MSG_OPTION_VERBOSE = ("Print informational statements.")
|
||||
MSG_OPTION_SILENT = ("Only the exit code will be returned, all informational and error messages will not be displayed.")
|
||||
MSG_OPTION_QUIET = ("Returns the exit code and will display only error messages.")
|
||||
MSG_OPTION_VPD_FILENAME = ("Specify the file name for the VPD binary file.")
|
||||
MSG_OPTION_MAP_FILENAME = ("Generate file name for consumption during the build that contains the mapping of Pcd name, offset, datum size and value derived from the input file and any automatic calculations.")
|
||||
MSG_OPTION_FORCE = ("Disable prompting the user for overwriting files as well as for missing input content.")
|
||||
MSG_OPTION_FORCE = ("Will force overwriting existing output files rather than returning an error message.")
|
||||
|
||||
ERR_INVALID_DEBUG_LEVEL = ("Invalid level for debug message. Only "
|
||||
"'DEBUG', 'INFO', 'WARNING', 'ERROR', "
|
||||
|
Reference in New Issue
Block a user