X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFdfParser.py;h=6b4f724f6d9ca6aec7828a606855874be9a1b004;hb=df29fd130abcc3094b8c5d842e4bfadd91cbf0e8;hp=0427b80b246048a9714d70fb24f89504578afeb3;hpb=95cc4962167572089a99be324574094ba22415ad;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 0427b80b24..6b4f724f6d 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 @@ -511,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(',') @@ -520,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 # @@ -886,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) @@ -913,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: @@ -921,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 @@ -930,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] @@ -938,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] @@ -1131,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 # @@ -1181,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 @@ -1200,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() @@ -1368,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 @@ -1448,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 @@ -1848,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. @@ -1879,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) @@ -1923,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) @@ -1932,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) @@ -2158,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 @@ -2335,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) @@ -2343,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': @@ -2377,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': @@ -2387,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) @@ -2423,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 @@ -2486,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 @@ -2534,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(): @@ -2632,7 +2637,7 @@ class FdfParser: # @staticmethod def __FileCouldHaveRelocFlag (FileType): - if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'): + if FileType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, 'PEI_DXE_COMBO'): return True else: return False @@ -2647,7 +2652,7 @@ class FdfParser: # @staticmethod def __SectionCouldHaveRelocFlag (SectionType): - if SectionType in ('TE', 'PE32'): + if SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32): return True else: return False @@ -2680,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(): @@ -2887,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( "="): @@ -2926,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 @@ -2971,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 @@ -3201,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) @@ -3392,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("="): @@ -3401,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() @@ -3435,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,7 +3545,7 @@ class FdfParser: 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"', \ + 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): @@ -3586,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() @@ -3632,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 @@ -3679,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("="): @@ -3773,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) @@ -3789,7 +3794,7 @@ class FdfParser: 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 @@ -3830,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 @@ -3861,8 +3866,8 @@ 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(): @@ -3874,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() @@ -3937,7 +3942,7 @@ class FdfParser: 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 @@ -3956,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() @@ -3991,7 +3996,7 @@ class FdfParser: # @staticmethod def __RuleSectionCouldBeOptional(SectionType): - if SectionType in ("DXE_DEPEX", "UI", "VERSION", "PEI_DEPEX", "RAW", "SMM_DEPEX"): + 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 @@ -4021,7 +4026,7 @@ class FdfParser: # @staticmethod def __RuleSectionCouldHaveString(SectionType): - if SectionType in ("UI", "VERSION"): + if SectionType in (BINARY_FILE_TYPE_UI, "VERSION"): return True else: return False @@ -4038,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 @@ -4500,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 @@ -4531,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': @@ -4578,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 @@ -4647,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) @@ -4657,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 @@ -4696,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. # @@ -4710,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 @@ -4755,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 @@ -4772,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!")