X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFdfParser.py;h=74785e0a93fea036809820272a9763467211d8c2;hb=ccaa7754a29728df0a7485932aab4909f6be116a;hp=5dbcb96bbd834b204481096e8407457954f9ddc4;hpb=231fdbb2107a2b359042626263317d8e494165dd;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 5dbcb96bbd..74785e0a93 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -16,6 +16,7 @@
##
# Import Modules
#
+from __future__ import print_function
import re
import Fd
@@ -48,11 +49,12 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
from Common.BuildToolError import *
from Common import EdkLogger
from Common.Misc import PathClass
-from Common.String import NormPath
+from Common.StringUtils import NormPath
import Common.GlobalData as GlobalData
from Common.Expression import *
from Common import GlobalData
-from Common.String import ReplaceMacro
+from Common.DataType import *
+from Common.StringUtils import ReplaceMacro
import uuid
from Common.Misc import tdict
from Common.MultipleWorkspace import MultipleWorkspace as mws
@@ -61,7 +63,6 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
from Capsule import EFI_CERT_TYPE_PKCS7_GUID
from Capsule import EFI_CERT_TYPE_RSA2048_SHA256_GUID
from Common.RangeExpression import RangeExpression
-from Common.FdfParserLite import FileExtensionPattern,TokenFindPattern
##define T_CHAR_SPACE ' '
##define T_CHAR_NULL '\0'
@@ -85,6 +86,9 @@ RegionSizePattern = re.compile("\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P\w+\.\w+)\s*\|\s*(?P\w+\.\w+)\s*")
RegionOffsetPcdPattern = re.compile("\s*(?P\w+\.\w+)\s*$")
ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P\w+\.\w+)\s*")
+BaseAddrValuePattern = re.compile('^0[xX][0-9a-fA-F]+')
+FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')
+TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
AllIncludeFileList = []
@@ -509,8 +513,8 @@ class FdfParser:
if Item == '' or Item == 'RULE':
return
- if Item == 'DEFINES':
- self.__CurSection = ['COMMON', 'COMMON', 'COMMON']
+ if Item == TAB_COMMON_DEFINES.upper():
+ self.__CurSection = [TAB_COMMON, TAB_COMMON, TAB_COMMON]
elif Item == 'VTF' and len(ItemList) == 3:
UiName = ItemList[2]
Pos = UiName.find(',')
@@ -518,9 +522,9 @@ class FdfParser:
UiName = UiName[:Pos]
self.__CurSection = ['VTF', UiName, ItemList[1]]
elif len(ItemList) > 1:
- self.__CurSection = [ItemList[0], ItemList[1], 'COMMON']
+ self.__CurSection = [ItemList[0], ItemList[1], TAB_COMMON]
elif len(ItemList) > 0:
- self.__CurSection = [ItemList[0], 'DUMMY', 'COMMON']
+ self.__CurSection = [ItemList[0], 'DUMMY', TAB_COMMON]
## PreprocessFile() method
#
@@ -704,7 +708,8 @@ class FdfParser:
# Preprocess done.
self.Rewind()
- def __GetIfListCurrentItemStat(self, IfList):
+ @staticmethod
+ def __GetIfListCurrentItemStat(IfList):
if len(IfList) == 0:
return True
@@ -883,7 +888,7 @@ class FdfParser:
if self.__CurSection:
# Defines macro
- ScopeMacro = self.__MacroDict['COMMON', 'COMMON', 'COMMON']
+ ScopeMacro = self.__MacroDict[TAB_COMMON, TAB_COMMON, TAB_COMMON]
if ScopeMacro:
MacroDict.update(ScopeMacro)
@@ -910,7 +915,6 @@ class FdfParser:
return MacroDict
def __EvaluateConditional(self, Expression, Line, Op = None, Value = None):
- FileLineTuple = GetRealFileLine(self.FileName, Line)
MacroPcdDict = self.__CollectMacroPcd()
if Op == 'eval':
try:
@@ -918,7 +922,7 @@ class FdfParser:
return ValueExpression(Expression, MacroPcdDict)(True)
else:
return ValueExpression(Expression, MacroPcdDict)()
- except WrnExpression, Excpt:
+ except WrnExpression as Excpt:
#
# Catch expression evaluation warning here. We need to report
# the precise number of line and return the evaluation result
@@ -927,7 +931,7 @@ class FdfParser:
File=self.FileName, ExtraData=self.__CurrentLine(),
Line=Line)
return Excpt.result
- except Exception, Excpt:
+ except Exception as Excpt:
if hasattr(Excpt, 'Pcd'):
if Excpt.Pcd in GlobalData.gPlatformOtherPcds:
Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]
@@ -935,12 +939,12 @@ class FdfParser:
" it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
" of the DSC file (%s), and it is currently defined in this section:"
" %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]),
- *FileLineTuple)
+ self.FileName, Line)
else:
raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']),
- *FileLineTuple)
+ self.FileName, Line)
else:
- raise Warning(str(Excpt), *FileLineTuple)
+ raise Warning(str(Excpt), self.FileName, Line)
else:
if Expression.startswith('$(') and Expression[-1] == ')':
Expression = Expression[2:-1]
@@ -1128,22 +1132,22 @@ class FdfParser:
self.__UndoToken()
return False
- def __Verify(self, Name, Value, Scope):
- if Scope in ['UINT64', 'UINT8']:
- ValueNumber = 0
- try:
- ValueNumber = int (Value, 0)
- except:
- EdkLogger.error("FdfParser", FORMAT_INVALID, "The value is not valid dec or hex number for %s." % Name)
- if ValueNumber < 0:
- EdkLogger.error("FdfParser", FORMAT_INVALID, "The value can't be set to negative value for %s." % Name)
- if Scope == 'UINT64':
- if ValueNumber >= 0x10000000000000000:
- EdkLogger.error("FdfParser", FORMAT_INVALID, "Too large value for %s." % Name)
- if Scope == 'UINT8':
- if ValueNumber >= 0x100:
- EdkLogger.error("FdfParser", FORMAT_INVALID, "Too large value for %s." % Name)
- return True
+ @staticmethod
+ def __Verify(Name, Value, Scope):
+ # value verification only applies to numeric values.
+ if Scope not in TAB_PCD_NUMERIC_TYPES:
+ return
+
+ ValueNumber = 0
+ try:
+ ValueNumber = int(Value, 0)
+ except:
+ EdkLogger.error("FdfParser", FORMAT_INVALID, "The value is not valid dec or hex number for %s." % Name)
+ if ValueNumber < 0:
+ EdkLogger.error("FdfParser", FORMAT_INVALID, "The value can't be set to negative value for %s." % Name)
+ if ValueNumber > MAX_VAL_TYPE[Scope]:
+ EdkLogger.error("FdfParser", FORMAT_INVALID, "Too large value for %s." % Name)
+ return True
## __UndoToken() method
#
@@ -1178,13 +1182,6 @@ class FdfParser:
self.__GetOneChar()
- def __IsHex(self, HexStr):
- if not HexStr.upper().startswith("0X"):
- return False
- if len(self.__Token) <= 2:
- return False
- return True if all(x in string.hexdigits for x in HexStr[2:]) else False
-
## __GetNextHexNumber() method
#
# Get next HEX data before a seperator
@@ -1197,7 +1194,7 @@ class FdfParser:
def __GetNextHexNumber(self):
if not self.__GetNextToken():
return False
- if self.__IsHex(self.__Token):
+ if gHexPatternAll.match(self.__Token):
return True
else:
self.__UndoToken()
@@ -1365,13 +1362,14 @@ class FdfParser:
try:
self.Preprocess()
+ self.__GetError()
#
# Keep processing sections of the FDF until no new sections or a syntax error is found
#
while self.__GetFd() or self.__GetFv() or self.__GetFmp() or self.__GetCapsule() or self.__GetVtf() or self.__GetRule() or self.__GetOptionRom():
pass
- except Warning, X:
+ except Warning as X:
self.__UndoToken()
#'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \
# At this point, the closest parent would be the included file itself
@@ -1445,6 +1443,17 @@ class FdfParser:
return False
+ ##__GetError() method
+ def __GetError(self):
+ #save the Current information
+ CurrentLine = self.CurrentLineNumber
+ CurrentOffset = self.CurrentOffsetWithinLine
+ while self.__GetNextToken():
+ if self.__Token == TAB_ERROR:
+ EdkLogger.error('FdfParser', ERROR_STATEMENT, self.__CurrentLine().replace(TAB_ERROR, '', 1), File=self.FileName, Line=self.CurrentLineNumber)
+ self.CurrentLineNumber = CurrentLine
+ self.CurrentOffsetWithinLine = CurrentOffset
+
## __GetFd() method
#
# Get FD section contents and store its data into FD dictionary of self.Profile
@@ -1811,7 +1820,7 @@ class FdfParser:
return long(
ValueExpression(Expr,
self.__CollectMacroPcd()
- )(True),0)
+ )(True), 0)
except Exception:
self.SetFileBufferPos(StartPos)
return None
@@ -1845,7 +1854,7 @@ class FdfParser:
if not self.__GetNextWord():
return True
- if not self.__Token in ("SET", "FV", "FILE", "DATA", "CAPSULE", "INF"):
+ if not self.__Token in ("SET", BINARY_FILE_TYPE_FV, "FILE", "DATA", "CAPSULE", "INF"):
#
# If next token is a word which is not a valid FV type, it might be part of [PcdOffset[|PcdSize]]
# Or it might be next region's offset described by an expression which starts with a PCD.
@@ -1876,7 +1885,7 @@ class FdfParser:
if not self.__GetNextWord():
return True
- elif self.__Token == "FV":
+ elif self.__Token == BINARY_FILE_TYPE_FV:
self.__UndoToken()
self.__GetRegionFvType( RegionObj)
@@ -1920,8 +1929,8 @@ class FdfParser:
#
def __GetRegionFvType(self, RegionObj):
- if not self.__IsKeyword( "FV"):
- raise Warning("expected Keyword 'FV'", self.FileName, self.CurrentLineNumber)
+ if not self.__IsKeyword( BINARY_FILE_TYPE_FV):
+ raise Warning("expected Keyword BINARY_FILE_TYPE_FV", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
@@ -1929,10 +1938,10 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)
- RegionObj.RegionType = "FV"
+ RegionObj.RegionType = BINARY_FILE_TYPE_FV
RegionObj.RegionDataList.append((self.__Token).upper())
- while self.__IsKeyword( "FV"):
+ while self.__IsKeyword( BINARY_FILE_TYPE_FV):
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
@@ -2155,7 +2164,7 @@ class FdfParser:
self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())
while True:
- isInf = self.__GetInfStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())
+ isInf = self.__GetInfStatement(FvObj)
isFile = self.__GetFileStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())
if not isInf and not isFile:
break
@@ -2210,9 +2219,7 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber)
- IsValidBaseAddrValue = re.compile('^0[x|X][0-9a-fA-F]+')
-
- if not IsValidBaseAddrValue.match(self.__Token.upper()):
+ if not BaseAddrValuePattern.match(self.__Token.upper()):
raise Warning("Unknown FV base address value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
Obj.FvBaseAddress = self.__Token
return True
@@ -2334,7 +2341,7 @@ class FdfParser:
if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():
raise Warning("expected Hex FV extension entry type value At Line ", self.FileName, self.CurrentLineNumber)
- FvObj.FvExtEntryTypeValue += [self.__Token]
+ FvObj.FvExtEntryTypeValue.append(self.__Token)
if not self.__IsToken( "{"):
raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)
@@ -2342,7 +2349,7 @@ class FdfParser:
if not self.__IsKeyword ("FILE") and not self.__IsKeyword ("DATA"):
raise Warning("expected 'FILE' or 'DATA'", self.FileName, self.CurrentLineNumber)
- FvObj.FvExtEntryType += [self.__Token]
+ FvObj.FvExtEntryType.append(self.__Token)
if self.__Token == 'DATA':
@@ -2376,7 +2383,7 @@ class FdfParser:
raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)
DataString = DataString.rstrip(",")
- FvObj.FvExtEntryData += [DataString]
+ FvObj.FvExtEntryData.append(DataString)
if self.__Token == 'FILE':
@@ -2386,7 +2393,7 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected FV Extension Entry file path At Line ", self.FileName, self.CurrentLineNumber)
- FvObj.FvExtEntryData += [self.__Token]
+ FvObj.FvExtEntryData.append(self.__Token)
if not self.__IsToken( "}"):
raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)
@@ -2422,7 +2429,7 @@ class FdfParser:
MacroDict.update(AprSectionObj.DefineVarDict)
while True:
- IsInf = self.__GetInfStatement( AprSectionObj, MacroDict = MacroDict)
+ IsInf = self.__GetInfStatement(AprSectionObj)
IsFile = self.__GetFileStatement( AprSectionObj)
if not IsInf and not IsFile:
break
@@ -2485,11 +2492,10 @@ class FdfParser:
#
# @param self The object pointer
# @param Obj for whom inf statement is got
- # @param MacroDict dictionary used to replace macro
# @retval True Successfully find inf statement
# @retval False Not able to find inf statement
#
- def __GetInfStatement(self, Obj, ForCapsule=False, MacroDict={}):
+ def __GetInfStatement(self, Obj, ForCapsule=False):
ffsInf = self.__ParseInfStatement()
if not ffsInf:
return False
@@ -2533,7 +2539,7 @@ class FdfParser:
if self.__GetStringData():
FfsInfObj.Version = self.__Token
- if self.__IsKeyword( "UI"):
+ if self.__IsKeyword( BINARY_FILE_TYPE_UI):
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
@@ -2625,14 +2631,13 @@ class FdfParser:
#
# Check whether reloc strip flag can be set for a file type.
#
- # @param self The object pointer
# @param FileType The file type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
-
- def __FileCouldHaveRelocFlag (self, FileType):
- if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'):
+ @staticmethod
+ def __FileCouldHaveRelocFlag (FileType):
+ if FileType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, 'PEI_DXE_COMBO'):
return True
else:
return False
@@ -2641,14 +2646,13 @@ class FdfParser:
#
# Check whether reloc strip flag can be set for a section type.
#
- # @param self The object pointer
# @param SectionType The section type to check with
# @retval True This type could have relocation strip flag
# @retval False No way to have it
#
-
- def __SectionCouldHaveRelocFlag (self, SectionType):
- if SectionType in ('TE', 'PE32'):
+ @staticmethod
+ def __SectionCouldHaveRelocFlag (SectionType):
+ if SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
return True
else:
return False
@@ -2681,7 +2685,7 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected File name or section data", self.FileName, self.CurrentLineNumber)
- if self.__Token == "FV":
+ if self.__Token == BINARY_FILE_TYPE_FV:
if not self.__IsToken( "="):
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
if not self.__GetNextToken():
@@ -2726,7 +2730,7 @@ class FdfParser:
while True:
AlignValue = None
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
#For FFS, Auto is default option same to ""
@@ -2785,7 +2789,7 @@ class FdfParser:
FfsFileObj.CheckSum = True
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
#For FFS, Auto is default option same to ""
@@ -2857,7 +2861,7 @@ class FdfParser:
AlignValue = None
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
AlignValue = self.__Token
@@ -2888,7 +2892,7 @@ class FdfParser:
VerSectionObj.FileName = self.__Token
Obj.SectionList.append(VerSectionObj)
- elif self.__IsKeyword( "UI"):
+ elif self.__IsKeyword( BINARY_FILE_TYPE_UI):
if AlignValue == 'Auto':
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
if not self.__IsToken( "="):
@@ -2927,7 +2931,7 @@ class FdfParser:
self.__GetAprioriSection(FvObj, MacroDict.copy())
while True:
- IsInf = self.__GetInfStatement(FvObj, MacroDict.copy())
+ IsInf = self.__GetInfStatement(FvObj)
IsFile = self.__GetFileStatement(FvObj, MacroDict.copy())
if not IsInf and not IsFile:
break
@@ -2972,10 +2976,10 @@ class FdfParser:
self.SetFileBufferPos(OldPos)
return False
- if self.__Token not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
- "UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "SMM_DEPEX"):
+ if self.__Token not in ("COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
+ BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, "SUBTYPE_GUID", BINARY_FILE_TYPE_SMM_DEPEX):
raise Warning("Unknown section type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- if AlignValue == 'Auto'and (not self.__Token == 'PE32') and (not self.__Token == 'TE'):
+ if AlignValue == 'Auto'and (not self.__Token == BINARY_FILE_TYPE_PE32) and (not self.__Token == BINARY_FILE_TYPE_TE):
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
# DataSection
@@ -3147,7 +3151,7 @@ class FdfParser:
AlignValue = None
if self.__GetAlignment():
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
AlignValue = self.__Token
@@ -3202,16 +3206,16 @@ class FdfParser:
raise Warning("expected value of %s" % Name, self.FileName, self.CurrentLineNumber)
Value = self.__Token
if Name == 'IMAGE_HEADER_INIT_VERSION':
- if self.__Verify(Name, Value, 'UINT8'):
+ if FdfParser.__Verify(Name, Value, 'UINT8'):
FmpData.Version = Value
elif Name == 'IMAGE_INDEX':
- if self.__Verify(Name, Value, 'UINT8'):
+ if FdfParser.__Verify(Name, Value, 'UINT8'):
FmpData.ImageIndex = Value
elif Name == 'HARDWARE_INSTANCE':
- if self.__Verify(Name, Value, 'UINT8'):
+ if FdfParser.__Verify(Name, Value, 'UINT8'):
FmpData.HardwareInstance = Value
elif Name == 'MONOTONIC_COUNT':
- if self.__Verify(Name, Value, 'UINT64'):
+ if FdfParser.__Verify(Name, Value, 'UINT64'):
FmpData.MonotonicCount = Value
if FmpData.MonotonicCount.upper().startswith('0X'):
FmpData.MonotonicCount = (long)(FmpData.MonotonicCount, 16)
@@ -3393,7 +3397,7 @@ class FdfParser:
#
def __GetFvStatement(self, CapsuleObj, FMPCapsule = False):
- if not self.__IsKeyword("FV"):
+ if not self.__IsKeyword(BINARY_FILE_TYPE_FV):
return False
if not self.__IsToken("="):
@@ -3402,7 +3406,7 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)
- if self.__Token.upper() not in self.Profile.FvDict.keys():
+ if self.__Token.upper() not in self.Profile.FvDict:
raise Warning("FV name does not exist", self.FileName, self.CurrentLineNumber)
CapsuleFv = CapsuleData.CapsuleFv()
@@ -3436,7 +3440,7 @@ class FdfParser:
if not self.__GetNextToken():
raise Warning("expected FD name", self.FileName, self.CurrentLineNumber)
- if self.__Token.upper() not in self.Profile.FdDict.keys():
+ if self.__Token.upper() not in self.Profile.FdDict:
raise Warning("FD name does not exist", self.FileName, self.CurrentLineNumber)
CapsuleFd = CapsuleData.CapsuleFd()
@@ -3540,8 +3544,8 @@ class FdfParser:
AfileName = self.__Token
AfileBaseName = os.path.basename(AfileName)
- if os.path.splitext(AfileBaseName)[1] not in [".bin",".BIN",".Bin",".dat",".DAT",".Dat",".data",".DATA",".Data"]:
- raise Warning('invalid binary file type, should be one of "bin","BIN","Bin","dat","DAT","Dat","data","DATA","Data"', \
+ if os.path.splitext(AfileBaseName)[1] not in [".bin", ".BIN", ".Bin", ".dat", ".DAT", ".Dat", ".data", ".DATA", ".Data"]:
+ raise Warning('invalid binary file type, should be one of "bin",BINARY_FILE_TYPE_BIN,"Bin","dat","DAT","Dat","data","DATA","Data"', \
self.FileName, self.CurrentLineNumber)
if not os.path.isabs(AfileName):
@@ -3587,7 +3591,7 @@ class FdfParser:
raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)
Arch = self.__SkippedChars.rstrip(".")
- if Arch.upper() not in ("IA32", "X64", "IPF", "EBC", "ARM", "AARCH64", "COMMON"):
+ if Arch.upper() not in ARCH_SET_FULL:
raise Warning("Unknown Arch '%s'" % Arch, self.FileName, self.CurrentLineNumber)
ModuleType = self.__GetModuleType()
@@ -3633,12 +3637,12 @@ class FdfParser:
if not self.__GetNextWord():
raise Warning("expected Module type", self.FileName, self.CurrentLineNumber)
- if self.__Token.upper() not in ("SEC", "PEI_CORE", "PEIM", "DXE_CORE", \
- "DXE_DRIVER", "DXE_SAL_DRIVER", \
- "DXE_SMM_DRIVER", "DXE_RUNTIME_DRIVER", \
- "UEFI_DRIVER", "UEFI_APPLICATION", "USER_DEFINED", "DEFAULT", "BASE", \
- "SECURITY_CORE", "COMBINED_PEIM_DRIVER", "PIC_PEIM", "RELOCATABLE_PEIM", \
- "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"):
+ if self.__Token.upper() not in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_DXE_CORE, \
+ SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, \
+ SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, \
+ SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_USER_DEFINED, "DEFAULT", SUP_MODULE_BASE, \
+ EDK_COMPONENT_TYPE_SECURITY_CORE, EDK_COMPONENT_TYPE_COMBINED_PEIM_DRIVER, EDK_COMPONENT_TYPE_PIC_PEIM, EDK_COMPONENT_TYPE_RELOCATABLE_PEIM, \
+ "PE32_PEIM", EDK_COMPONENT_TYPE_BS_DRIVER, EDK_COMPONENT_TYPE_RT_DRIVER, EDK_COMPONENT_TYPE_SAL_RT_DRIVER, EDK_COMPONENT_TYPE_APPLICATION, "ACPITABLE", SUP_MODULE_SMM_CORE, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE):
raise Warning("Unknown Module type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
return self.__Token
@@ -3680,8 +3684,8 @@ class FdfParser:
raise Warning("expected FFS type", self.FileName, self.CurrentLineNumber)
Type = self.__Token.strip().upper()
- if Type not in ("RAW", "FREEFORM", "SEC", "PEI_CORE", "PEIM",\
- "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"):
+ if Type not in ("RAW", "FREEFORM", SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM,\
+ "PEI_DXE_COMBO", "DRIVER", SUP_MODULE_DXE_CORE, EDK_COMPONENT_TYPE_APPLICATION, "FV_IMAGE", "SMM", SUP_MODULE_SMM_CORE, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE):
raise Warning("Unknown FV type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
if not self.__IsToken("="):
@@ -3737,7 +3741,7 @@ class FdfParser:
AlignValue = ""
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
#For FFS, Auto is default option same to ""
@@ -3774,8 +3778,8 @@ class FdfParser:
SectionName = self.__Token
- if SectionName not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
- "UI", "PEI_DEPEX", "VERSION", "SUBTYPE_GUID", "SMM_DEPEX"):
+ if SectionName not in ("COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
+ BINARY_FILE_TYPE_UI, BINARY_FILE_TYPE_PEI_DEPEX, "VERSION", "SUBTYPE_GUID", BINARY_FILE_TYPE_SMM_DEPEX):
raise Warning("Unknown leaf section name '%s'" % SectionName, self.FileName, self.CurrentLineNumber)
@@ -3787,10 +3791,10 @@ class FdfParser:
SectAlignment = ""
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):
+ if self.__Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
SectAlignment = self.__Token
@@ -3831,8 +3835,8 @@ class FdfParser:
return False
SectionName = self.__Token
- if SectionName not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
- "UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
+ if SectionName not in ("COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
+ BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, BINARY_FILE_TYPE_GUID, BINARY_FILE_TYPE_SMM_DEPEX):
self.__UndoToken()
return False
@@ -3862,12 +3866,12 @@ class FdfParser:
FvImageSectionObj.FvName = None
else:
- if not self.__IsKeyword("FV"):
- raise Warning("expected 'FV'", self.FileName, self.CurrentLineNumber)
+ if not self.__IsKeyword(BINARY_FILE_TYPE_FV):
+ raise Warning("expected BINARY_FILE_TYPE_FV", self.FileName, self.CurrentLineNumber)
FvImageSectionObj.FvFileType = self.__Token
if self.__GetAlignment():
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
FvImageSectionObj.Alignment = self.__Token
@@ -3875,8 +3879,8 @@ class FdfParser:
if self.__IsToken('|'):
FvImageSectionObj.FvFileExtension = self.__GetFileExtension()
elif self.__GetNextToken():
- if self.__Token not in ("}", "COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
- "UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
+ if self.__Token not in ("}", "COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
+ BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, BINARY_FILE_TYPE_GUID, BINARY_FILE_TYPE_SMM_DEPEX):
FvImageSectionObj.FvFileName = self.__Token
else:
self.__UndoToken()
@@ -3935,10 +3939,10 @@ class FdfParser:
EfiSectionObj.BuildNum = self.__Token
if self.__GetAlignment():
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
- if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):
+ if self.__Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)
EfiSectionObj.Alignment = self.__Token
@@ -3957,8 +3961,8 @@ class FdfParser:
if self.__IsToken('|'):
EfiSectionObj.FileExtension = self.__GetFileExtension()
elif self.__GetNextToken():
- if self.__Token not in ("}", "COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\
- "UI", "VERSION", "PEI_DEPEX", "GUID", "SMM_DEPEX"):
+ if self.__Token not in ("}", "COMPAT16", BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_TE, "FV_IMAGE", "RAW", BINARY_FILE_TYPE_DXE_DEPEX,\
+ BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, BINARY_FILE_TYPE_GUID, BINARY_FILE_TYPE_SMM_DEPEX):
if self.__Token.startswith('PCD'):
self.__UndoToken()
@@ -3986,13 +3990,13 @@ class FdfParser:
#
# Get whether a section could be optional
#
- # @param self The object pointer
# @param SectionType The section type to check
# @retval True section could be optional
# @retval False section never optional
#
- def __RuleSectionCouldBeOptional(self, SectionType):
- if SectionType in ("DXE_DEPEX", "UI", "VERSION", "PEI_DEPEX", "RAW", "SMM_DEPEX"):
+ @staticmethod
+ def __RuleSectionCouldBeOptional(SectionType):
+ if SectionType in (BINARY_FILE_TYPE_DXE_DEPEX, BINARY_FILE_TYPE_UI, "VERSION", BINARY_FILE_TYPE_PEI_DEPEX, "RAW", BINARY_FILE_TYPE_SMM_DEPEX):
return True
else:
return False
@@ -4001,12 +4005,12 @@ class FdfParser:
#
# Get whether a section could have build number information
#
- # @param self The object pointer
# @param SectionType The section type to check
# @retval True section could have build number information
# @retval False section never have build number information
#
- def __RuleSectionCouldHaveBuildNum(self, SectionType):
+ @staticmethod
+ def __RuleSectionCouldHaveBuildNum(SectionType):
if SectionType in ("VERSION"):
return True
else:
@@ -4016,13 +4020,13 @@ class FdfParser:
#
# Get whether a section could have string
#
- # @param self The object pointer
# @param SectionType The section type to check
# @retval True section could have string
# @retval False section never have string
#
- def __RuleSectionCouldHaveString(self, SectionType):
- if SectionType in ("UI", "VERSION"):
+ @staticmethod
+ def __RuleSectionCouldHaveString(SectionType):
+ if SectionType in (BINARY_FILE_TYPE_UI, "VERSION"):
return True
else:
return False
@@ -4039,32 +4043,32 @@ class FdfParser:
if SectionType == "COMPAT16":
if FileType not in ("COMPAT16", "SEC_COMPAT16"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "PE32":
- if FileType not in ("PE32", "SEC_PE32"):
+ elif SectionType == BINARY_FILE_TYPE_PE32:
+ if FileType not in (BINARY_FILE_TYPE_PE32, "SEC_PE32"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "PIC":
- if FileType not in ("PIC", "PIC"):
+ elif SectionType == BINARY_FILE_TYPE_PIC:
+ if FileType not in (BINARY_FILE_TYPE_PIC, BINARY_FILE_TYPE_PIC):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "TE":
- if FileType not in ("TE", "SEC_TE"):
+ elif SectionType == BINARY_FILE_TYPE_TE:
+ if FileType not in (BINARY_FILE_TYPE_TE, "SEC_TE"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
elif SectionType == "RAW":
- if FileType not in ("BIN", "SEC_BIN", "RAW", "ASL", "ACPI"):
+ if FileType not in (BINARY_FILE_TYPE_BIN, "SEC_BIN", "RAW", "ASL", "ACPI"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "DXE_DEPEX" or SectionType == "SMM_DEPEX":
- if FileType not in ("DXE_DEPEX", "SEC_DXE_DEPEX", "SMM_DEPEX"):
+ elif SectionType == BINARY_FILE_TYPE_DXE_DEPEX or SectionType == BINARY_FILE_TYPE_SMM_DEPEX:
+ if FileType not in (BINARY_FILE_TYPE_DXE_DEPEX, "SEC_DXE_DEPEX", BINARY_FILE_TYPE_SMM_DEPEX):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "UI":
- if FileType not in ("UI", "SEC_UI"):
+ elif SectionType == BINARY_FILE_TYPE_UI:
+ if FileType not in (BINARY_FILE_TYPE_UI, "SEC_UI"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
elif SectionType == "VERSION":
if FileType not in ("VERSION", "SEC_VERSION"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "PEI_DEPEX":
- if FileType not in ("PEI_DEPEX", "SEC_PEI_DEPEX"):
+ elif SectionType == BINARY_FILE_TYPE_PEI_DEPEX:
+ if FileType not in (BINARY_FILE_TYPE_PEI_DEPEX, "SEC_PEI_DEPEX"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
- elif SectionType == "GUID":
- if FileType not in ("PE32", "SEC_GUID"):
+ elif SectionType == BINARY_FILE_TYPE_GUID:
+ if FileType not in (BINARY_FILE_TYPE_PE32, "SEC_GUID"):
raise Warning("Incorrect section file type '%s'" % FileType, self.FileName, self.CurrentLineNumber)
## __GetRuleEncapsulationSection() method
@@ -4501,7 +4505,7 @@ class FdfParser:
FfsFileObj = OptRomFileStatement.OptRomFileStatement()
- if not self.__IsKeyword("EFI") and not self.__IsKeyword("BIN"):
+ if not self.__IsKeyword("EFI") and not self.__IsKeyword(BINARY_FILE_TYPE_BIN):
raise Warning("expected Binary type (EFI/BIN)", self.FileName, self.CurrentLineNumber)
FfsFileObj.FileType = self.__Token
@@ -4532,7 +4536,7 @@ class FdfParser:
def __GetCapInFd (self, FdName):
CapList = []
- if FdName.upper() in self.Profile.FdDict.keys():
+ if FdName.upper() in self.Profile.FdDict:
FdObj = self.Profile.FdDict[FdName.upper()]
for elementRegion in FdObj.RegionList:
if elementRegion.RegionType == 'CAPSULE':
@@ -4579,10 +4583,10 @@ class FdfParser:
def __GetFvInFd (self, FdName):
FvList = []
- if FdName.upper() in self.Profile.FdDict.keys():
+ if FdName.upper() in self.Profile.FdDict:
FdObj = self.Profile.FdDict[FdName.upper()]
for elementRegion in FdObj.RegionList:
- if elementRegion.RegionType == 'FV':
+ if elementRegion.RegionType == BINARY_FILE_TYPE_FV:
for elementRegionData in elementRegion.RegionDataList:
if elementRegionData.endswith(".fv"):
continue
@@ -4648,7 +4652,7 @@ class FdfParser:
# Check the cycle between FV and FD image
#
MaxLength = len (self.Profile.FvDict)
- for FvName in self.Profile.FvDict.keys():
+ for FvName in self.Profile.FvDict:
LogStr = "\nCycle Reference Checking for FV: %s\n" % FvName
RefFvStack = []
RefFvStack.append(FvName)
@@ -4658,7 +4662,7 @@ class FdfParser:
while RefFvStack != [] and Index < MaxLength:
Index = Index + 1
FvNameFromStack = RefFvStack.pop()
- if FvNameFromStack.upper() in self.Profile.FvDict.keys():
+ if FvNameFromStack.upper() in self.Profile.FvDict:
FvObj = self.Profile.FvDict[FvNameFromStack.upper()]
else:
continue
@@ -4675,7 +4679,7 @@ class FdfParser:
FvInFdList = self.__GetFvInFd(RefFdName)
if FvInFdList != []:
for FvNameInFd in FvInFdList:
- LogStr += "FD %s contains FV %s\n" % (RefFdName,FvNameInFd)
+ LogStr += "FD %s contains FV %s\n" % (RefFdName, FvNameInFd)
if FvNameInFd not in RefFvStack:
RefFvStack.append(FvNameInFd)
@@ -4697,7 +4701,7 @@ class FdfParser:
# Check the cycle between Capsule and FD image
#
MaxLength = len (self.Profile.CapsuleDict)
- for CapName in self.Profile.CapsuleDict.keys():
+ for CapName in self.Profile.CapsuleDict:
#
# Capsule image to be checked.
#
@@ -4711,7 +4715,7 @@ class FdfParser:
while RefCapStack != [] and Index < MaxLength:
Index = Index + 1
CapNameFromStack = RefCapStack.pop()
- if CapNameFromStack.upper() in self.Profile.CapsuleDict.keys():
+ if CapNameFromStack.upper() in self.Profile.CapsuleDict:
CapObj = self.Profile.CapsuleDict[CapNameFromStack.upper()]
else:
continue
@@ -4731,7 +4735,7 @@ class FdfParser:
CapInFdList = self.__GetCapInFd(RefFdName)
if CapInFdList != []:
for CapNameInFd in CapInFdList:
- LogStr += "FD %s contains Capsule %s\n" % (RefFdName,CapNameInFd)
+ LogStr += "FD %s contains Capsule %s\n" % (RefFdName, CapNameInFd)
if CapNameInFd not in RefCapStack:
RefCapStack.append(CapNameInFd)
@@ -4742,7 +4746,7 @@ class FdfParser:
FvInFdList = self.__GetFvInFd(RefFdName)
if FvInFdList != []:
for FvNameInFd in FvInFdList:
- LogStr += "FD %s contains FV %s\n" % (RefFdName,FvNameInFd)
+ LogStr += "FD %s contains FV %s\n" % (RefFdName, FvNameInFd)
if FvNameInFd not in RefFvList:
RefFvList.append(FvNameInFd)
@@ -4756,7 +4760,7 @@ class FdfParser:
if RefFvName in FvAnalyzedList:
continue
LogStr += "Capsule %s contains FV %s\n" % (CapNameFromStack, RefFvName)
- if RefFvName.upper() in self.Profile.FvDict.keys():
+ if RefFvName.upper() in self.Profile.FvDict:
FvObj = self.Profile.FvDict[RefFvName.upper()]
else:
continue
@@ -4773,16 +4777,16 @@ if __name__ == "__main__":
import sys
try:
test_file = sys.argv[1]
- except IndexError, v:
- print "Usage: %s filename" % sys.argv[0]
+ except IndexError as v:
+ print("Usage: %s filename" % sys.argv[0])
sys.exit(1)
parser = FdfParser(test_file)
try:
parser.ParseFile()
parser.CycleReferenceCheck()
- except Warning, X:
- print str(X)
+ except Warning as X:
+ print(str(X))
else:
- print "Success!"
+ print("Success!")