BaseTools: Clean up source files
1. Do not use tab characters 2. No trailing white space in one line 3. All files must end with CRLF Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
@ -31,10 +31,10 @@ _FORMAT_CHAR = {1: 'B',
|
||||
|
||||
## The VPD PCD data structure for store and process each VPD PCD entry.
|
||||
#
|
||||
# This class contain method to format and pack pcd's value.
|
||||
# This class contain method to format and pack pcd's value.
|
||||
#
|
||||
class PcdEntry:
|
||||
def __init__(self, PcdCName, SkuId,PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None,
|
||||
def __init__(self, PcdCName, SkuId,PcdOffset, PcdSize, PcdValue, Lineno=None, FileName=None, PcdUnpackValue=None,
|
||||
PcdBinOffset=None, PcdBinSize=None, Alignment=None):
|
||||
self.PcdCName = PcdCName.strip()
|
||||
self.SkuId = SkuId.strip()
|
||||
@ -47,7 +47,7 @@ class PcdEntry:
|
||||
self.PcdBinOffset = PcdBinOffset
|
||||
self.PcdBinSize = PcdBinSize
|
||||
self.Alignment = Alignment
|
||||
|
||||
|
||||
if self.PcdValue == '' :
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
"Invalid PCD format(Name: %s File: %s line: %s) , no Value specified!" % (self.PcdCName, self.FileName, self.Lineno))
|
||||
@ -63,13 +63,13 @@ class PcdEntry:
|
||||
self._GenOffsetValue ()
|
||||
|
||||
## Analyze the string value to judge the PCD's datum type equal 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.
|
||||
#
|
||||
# @retval False PCD's datum type is not Boolean.
|
||||
#
|
||||
def _IsBoolean(self, ValueString, Size):
|
||||
if (Size == "1"):
|
||||
if ValueString.upper() in ["TRUE", "FALSE"]:
|
||||
@ -80,10 +80,10 @@ class PcdEntry:
|
||||
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:
|
||||
@ -96,10 +96,10 @@ class PcdEntry:
|
||||
"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" or ValueString in ["1", "0x1", "0x01"]:
|
||||
try:
|
||||
@ -115,10 +115,10 @@ class PcdEntry:
|
||||
"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:
|
||||
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,
|
||||
@ -170,7 +170,7 @@ class PcdEntry:
|
||||
# 3: {bytearray}, only support byte-array.
|
||||
#
|
||||
# @param ValueString The Integer type string for pack.
|
||||
#
|
||||
#
|
||||
def _PackPtrValue(self, ValueString, Size):
|
||||
if ValueString.startswith('L"') or ValueString.startswith("L'"):
|
||||
self._PackUnicode(ValueString, Size)
|
||||
@ -183,9 +183,9 @@ class PcdEntry:
|
||||
"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,
|
||||
@ -198,7 +198,7 @@ class PcdEntry:
|
||||
QuotedFlag = False
|
||||
|
||||
ValueString = ValueString[1:-1]
|
||||
# No null-terminator in 'string'
|
||||
# No null-terminator in 'string'
|
||||
if (QuotedFlag and len(ValueString) + 1 > Size) or (not QuotedFlag and len(ValueString) > Size):
|
||||
EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,
|
||||
"PCD value string %s is exceed to size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))
|
||||
@ -209,9 +209,9 @@ class PcdEntry:
|
||||
"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))
|
||||
@ -261,7 +261,7 @@ class PcdEntry:
|
||||
self.PcdValue = ReturnArray.tolist()
|
||||
|
||||
## Pack a unicode PCD value into byte array.
|
||||
#
|
||||
#
|
||||
# A unicode string for a PCD should be in format as L""/L''.
|
||||
#
|
||||
def _PackUnicode(self, UnicodeString, Size):
|
||||
@ -271,7 +271,7 @@ class PcdEntry:
|
||||
|
||||
QuotedFlag = True
|
||||
if UnicodeString.startswith("L'"):
|
||||
QuotedFlag = False
|
||||
QuotedFlag = False
|
||||
UnicodeString = UnicodeString[2:-1]
|
||||
|
||||
# No null-terminator in L'string'
|
||||
@ -304,7 +304,7 @@ class PcdEntry:
|
||||
# 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
|
||||
#
|
||||
@ -334,9 +334,9 @@ class GenVPD :
|
||||
EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % InputFileName, None)
|
||||
|
||||
##
|
||||
# Parser the input file which is generated by the build tool. Convert the value of each pcd's
|
||||
# Parser the input file which is generated by the build tool. Convert the value of each pcd's
|
||||
# from string to it's real format. Also remove the useless line in the input file.
|
||||
#
|
||||
#
|
||||
def ParserInputFile (self):
|
||||
count = 0
|
||||
for line in self.FileLinesList:
|
||||
@ -390,7 +390,7 @@ class GenVPD :
|
||||
#
|
||||
# After remove the useless line, if there are no data remain in the file line list,
|
||||
# Report warning messages to user's.
|
||||
#
|
||||
#
|
||||
if len(self.FileLinesList) == 0 :
|
||||
EdkLogger.warn('BPDG', BuildToolError.RESOURCE_NOT_AVAILABLE,
|
||||
"There are no VPD type pcds defined in DSC file, Please check it.")
|
||||
@ -480,14 +480,14 @@ class GenVPD :
|
||||
continue
|
||||
|
||||
##
|
||||
# This function used to create a clean list only contain useful information and reorganized to make it
|
||||
# This function used to create a clean list only contain useful information and reorganized to make it
|
||||
# easy to be sorted
|
||||
#
|
||||
def FormatFileLine (self) :
|
||||
|
||||
for eachPcd in self.FileLinesList :
|
||||
if eachPcd.PcdOffset != '*' :
|
||||
# Use pcd's Offset value as key, and pcd's Value as value
|
||||
# Use pcd's Offset value as key, and pcd's Value as value
|
||||
self.PcdFixedOffsetSizeList.append(eachPcd)
|
||||
else :
|
||||
# Use pcd's CName as key, and pcd's Size as value
|
||||
@ -497,11 +497,11 @@ class GenVPD :
|
||||
##
|
||||
# This function is use to fix the offset value which the not specified in the map file.
|
||||
# Usually it use the star (meaning any offset) character in the offset field
|
||||
#
|
||||
#
|
||||
def FixVpdOffset (self):
|
||||
# At first, the offset should start at 0
|
||||
# Sort fixed offset list in order to find out where has free spaces for the pcd's offset
|
||||
# value is "*" to insert into.
|
||||
# value is "*" to insert into.
|
||||
|
||||
self.PcdFixedOffsetSizeList.sort(lambda x, y: cmp(x.PcdBinOffset, y.PcdBinOffset))
|
||||
|
||||
@ -530,57 +530,57 @@ class GenVPD :
|
||||
Pcd.PcdBinOffset = NowOffset
|
||||
Pcd.PcdOffset = str(hex(Pcd.PcdBinOffset))
|
||||
NowOffset += Pcd.PcdOccupySize
|
||||
|
||||
|
||||
self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList
|
||||
return
|
||||
|
||||
# Check the offset of VPD type pcd's offset start from 0.
|
||||
# Check the offset of VPD type pcd's offset start from 0.
|
||||
if self.PcdFixedOffsetSizeList[0].PcdBinOffset != 0 :
|
||||
EdkLogger.warn("BPDG", "The offset of VPD type pcd should start with 0, please check it.",
|
||||
None)
|
||||
|
||||
# Judge whether the offset in fixed pcd offset list is overlapped or not.
|
||||
lenOfList = len(self.PcdFixedOffsetSizeList)
|
||||
count = 0
|
||||
count = 0
|
||||
while (count < lenOfList - 1) :
|
||||
PcdNow = self.PcdFixedOffsetSizeList[count]
|
||||
PcdNext = self.PcdFixedOffsetSizeList[count+1]
|
||||
# Two pcd's offset is same
|
||||
# Two pcd's offset is same
|
||||
if PcdNow.PcdBinOffset == PcdNext.PcdBinOffset :
|
||||
EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,
|
||||
"The offset of %s at line: %s is same with %s at line: %s in file %s" % \
|
||||
(PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),
|
||||
None)
|
||||
|
||||
# Overlapped
|
||||
# Overlapped
|
||||
if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize > PcdNext.PcdBinOffset :
|
||||
EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,
|
||||
"The offset of %s at line: %s is overlapped with %s at line: %s in file %s" % \
|
||||
(PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),
|
||||
None)
|
||||
|
||||
# Has free space, raise a warning message
|
||||
# Has free space, raise a warning message
|
||||
if PcdNow.PcdBinOffset + PcdNow.PcdOccupySize < PcdNext.PcdBinOffset :
|
||||
EdkLogger.warn("BPDG", BuildToolError.ATTRIBUTE_GET_FAILURE,
|
||||
"The offsets have free space of between %s at line: %s and %s at line: %s in file %s" % \
|
||||
(PcdNow.PcdCName, PcdNow.Lineno, PcdNext.PcdCName, PcdNext.Lineno, PcdNext.FileName),
|
||||
None)
|
||||
count += 1
|
||||
|
||||
|
||||
LastOffset = self.PcdFixedOffsetSizeList[0].PcdBinOffset
|
||||
FixOffsetSizeListCount = 0
|
||||
lenOfList = len(self.PcdFixedOffsetSizeList)
|
||||
lenOfUnfixedList = len(self.PcdUnknownOffsetList)
|
||||
|
||||
|
||||
##
|
||||
# Insert the un-fixed offset pcd's list into fixed offset pcd's list if has free space between those pcds.
|
||||
#
|
||||
# Insert the un-fixed offset pcd's list into fixed offset pcd's list if has free space between those pcds.
|
||||
#
|
||||
while (FixOffsetSizeListCount < lenOfList) :
|
||||
|
||||
eachFixedPcd = self.PcdFixedOffsetSizeList[FixOffsetSizeListCount]
|
||||
|
||||
eachFixedPcd = self.PcdFixedOffsetSizeList[FixOffsetSizeListCount]
|
||||
NowOffset = eachFixedPcd.PcdBinOffset
|
||||
|
||||
# Has free space
|
||||
|
||||
# Has free space
|
||||
if LastOffset < NowOffset :
|
||||
if lenOfUnfixedList != 0 :
|
||||
countOfUnfixedList = 0
|
||||
@ -598,42 +598,42 @@ class GenVPD :
|
||||
eachUnfixedPcd.PcdBinOffset = LastOffset
|
||||
# Insert this pcd into fixed offset pcd list.
|
||||
self.PcdFixedOffsetSizeList.insert(FixOffsetSizeListCount, eachUnfixedPcd)
|
||||
|
||||
|
||||
# Delete the item's offset that has been fixed and added into fixed offset list
|
||||
self.PcdUnknownOffsetList.pop(countOfUnfixedList)
|
||||
|
||||
|
||||
# After item added, should enlarge the length of fixed pcd offset list
|
||||
lenOfList += 1
|
||||
lenOfList += 1
|
||||
FixOffsetSizeListCount += 1
|
||||
|
||||
|
||||
# Decrease the un-fixed pcd offset list's length
|
||||
lenOfUnfixedList -= 1
|
||||
|
||||
# Modify the last offset value
|
||||
LastOffset += needFixPcdSize
|
||||
|
||||
# Modify the last offset value
|
||||
LastOffset += needFixPcdSize
|
||||
else :
|
||||
# It can not insert into those two pcds, need to check still has other space can store it.
|
||||
LastOffset = NowOffset + self.PcdFixedOffsetSizeList[FixOffsetSizeListCount].PcdOccupySize
|
||||
FixOffsetSizeListCount += 1
|
||||
break
|
||||
|
||||
|
||||
# Set the FixOffsetSizeListCount = lenOfList for quit the loop
|
||||
else :
|
||||
FixOffsetSizeListCount = lenOfList
|
||||
|
||||
# No free space, smoothly connect with previous pcd.
|
||||
FixOffsetSizeListCount = lenOfList
|
||||
|
||||
# No free space, smoothly connect with previous pcd.
|
||||
elif LastOffset == NowOffset :
|
||||
LastOffset = NowOffset + eachFixedPcd.PcdOccupySize
|
||||
FixOffsetSizeListCount += 1
|
||||
# Usually it will not enter into this thunk, if so, means it overlapped.
|
||||
# Usually it will not enter into this thunk, if so, means it overlapped.
|
||||
else :
|
||||
EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_NOT_AVAILABLE,
|
||||
"The offset value definition has overlapped at pcd: %s, it's offset is: %s, in file: %s line: %s" % \
|
||||
(eachFixedPcd.PcdCName, eachFixedPcd.PcdOffset, eachFixedPcd.InputFileName, eachFixedPcd.Lineno),
|
||||
None)
|
||||
FixOffsetSizeListCount += 1
|
||||
|
||||
# Continue to process the un-fixed offset pcd's list, add this time, just append them behind the fixed pcd's offset list.
|
||||
|
||||
# Continue to process the un-fixed offset pcd's list, add this time, just append them behind the fixed pcd's offset list.
|
||||
lenOfUnfixedList = len(self.PcdUnknownOffsetList)
|
||||
lenOfList = len(self.PcdFixedOffsetSizeList)
|
||||
while (lenOfUnfixedList > 0) :
|
||||
@ -641,23 +641,23 @@ class GenVPD :
|
||||
# The last pcd instance
|
||||
LastPcd = self.PcdFixedOffsetSizeList[lenOfList-1]
|
||||
NeedFixPcd = self.PcdUnknownOffsetList[0]
|
||||
|
||||
|
||||
NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize
|
||||
if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:
|
||||
NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
|
||||
|
||||
NeedFixPcd.PcdOffset = str(hex(NeedFixPcd.PcdBinOffset))
|
||||
|
||||
|
||||
# Insert this pcd into fixed offset pcd list's tail.
|
||||
self.PcdFixedOffsetSizeList.insert(lenOfList, NeedFixPcd)
|
||||
# Delete the item's offset that has been fixed and added into fixed offset list
|
||||
self.PcdUnknownOffsetList.pop(0)
|
||||
|
||||
|
||||
lenOfList += 1
|
||||
lenOfUnfixedList -= 1
|
||||
lenOfUnfixedList -= 1
|
||||
##
|
||||
# Write the final data into output files.
|
||||
#
|
||||
#
|
||||
def GenerateVpdFile (self, MapFileName, BinFileName):
|
||||
#Open an VPD file to process
|
||||
|
||||
@ -705,4 +705,4 @@ class GenVPD :
|
||||
fStringIO.close ()
|
||||
fVpdFile.close ()
|
||||
fMapFile.close ()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user