X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFdfParser.py;h=a106253527c4c97c15d16f46c73b0ae4c524d6d8;hb=b491aa95ab9e2e831f658bb74bf9ed67bff082ac;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..a106253527 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -52,6 +52,7 @@ from Common.String import NormPath import Common.GlobalData as GlobalData from Common.Expression import * from Common import GlobalData +from Common.DataType import * from Common.String import ReplaceMacro import uuid from Common.Misc import tdict @@ -61,7 +62,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 +85,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 +512,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 +521,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 +707,8 @@ class FdfParser: # Preprocess done. self.Rewind() - def __GetIfListCurrentItemStat(self, IfList): + @staticmethod + def __GetIfListCurrentItemStat(IfList): if len(IfList) == 0: return True @@ -883,7 +887,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) @@ -1128,7 +1132,8 @@ class FdfParser: self.__UndoToken() return False - def __Verify(self, Name, Value, Scope): + @staticmethod + def __Verify(Name, Value, Scope): if Scope in ['UINT64', 'UINT8']: ValueNumber = 0 try: @@ -2155,7 +2160,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 +2215,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 @@ -2422,7 +2425,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 +2488,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 @@ -2625,13 +2627,12 @@ 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): + @staticmethod + def __FileCouldHaveRelocFlag (FileType): if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'): return True else: @@ -2641,13 +2642,12 @@ 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): + @staticmethod + def __SectionCouldHaveRelocFlag (SectionType): if SectionType in ('TE', 'PE32'): return True else: @@ -2927,7 +2927,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 @@ -3202,16 +3202,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) @@ -3402,7 +3402,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 +3436,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() @@ -3587,7 +3587,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_LIST_FULL: raise Warning("Unknown Arch '%s'" % Arch, self.FileName, self.CurrentLineNumber) ModuleType = self.__GetModuleType() @@ -3986,12 +3986,12 @@ 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): + @staticmethod + def __RuleSectionCouldBeOptional(SectionType): if SectionType in ("DXE_DEPEX", "UI", "VERSION", "PEI_DEPEX", "RAW", "SMM_DEPEX"): return True else: @@ -4001,12 +4001,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,12 +4016,12 @@ 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): + @staticmethod + def __RuleSectionCouldHaveString(SectionType): if SectionType in ("UI", "VERSION"): return True else: @@ -4532,7 +4532,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,7 +4579,7 @@ 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': @@ -4648,7 +4648,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 +4658,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 @@ -4697,7 +4697,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 +4711,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 @@ -4756,7 +4756,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