X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FFdfParserLite.py;h=806fdd8aa5bb487cdbb23da1ffc5ecea51927e44;hp=5099ed611c9f062aa2938673b8086d26fd7ffb4e;hb=4d603daa3a2276d98ac6749d1db8e327ff7c1f5f;hpb=fd171542e0aa89ac12a09d79608173f48019b14b diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py index 5099ed611c..806fdd8aa5 100644 --- a/BaseTools/Source/Python/Common/FdfParserLite.py +++ b/BaseTools/Source/Python/Common/FdfParserLite.py @@ -1,9 +1,9 @@ ## @file # parse FDF file # -# Copyright (c) 2007, Intel Corporation +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# -# All rights reserved. This program and the accompanying materials +# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at # http://opensource.org/licenses/bsd-license.php @@ -16,9 +16,12 @@ # Import Modules # import re -import os +import Common.LongFilePathOs as os import CommonDataClass.FdfClass +from Common.LongFilePathSupport import OpenLongFilePath as open +from Common.MultipleWorkspace import MultipleWorkspace as mws +from Common.RangeExpression import RangeExpression ##define T_CHAR_SPACE ' ' ##define T_CHAR_NULL '\0' @@ -44,6 +47,8 @@ InputMacroDict = {} # All Macro values when parsing file, not replace existing Macro AllMacroList = [] +FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') + def GetRealFileLine (File, Line): InsertedLines = 0 @@ -67,8 +72,8 @@ class Warning (Exception): # @param File The FDF name # @param Line The Line number that error occurs # - def __init__(self, Str, File = None, Line = None): - + def __init__(self, Str, File=None, Line=None): + FileLineTuple = GetRealFileLine(File, Line) self.FileName = FileLineTuple[0] self.LineNumber = FileLineTuple[1] @@ -357,8 +362,8 @@ class FdfParser(object): else: raise Warning("Macro not complete At Line ", self.FileName, self.CurrentLineNumber) return Str - - def __ReplaceFragment(self, StartPos, EndPos, Value = ' '): + + def __ReplaceFragment(self, StartPos, EndPos, Value=' '): if StartPos[0] == EndPos[0]: Offset = StartPos[1] while Offset <= EndPos[1]: @@ -383,7 +388,22 @@ class FdfParser(object): while Offset <= EndPos[1]: self.Profile.FileLinesList[EndPos[0]][Offset] = Value Offset += 1 - + + + def __GetMacroName(self): + if not self.__GetNextToken(): + raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber) + MacroName = self.__Token + NotFlag = False + if MacroName.startswith('!'): + NotFlag = True + MacroName = MacroName[1:].strip() + + if not MacroName.startswith('$(') or not MacroName.endswith(')'): + raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName}, + self.FileName, self.CurrentLineNumber) + MacroName = MacroName[2:-1] + return MacroName, NotFlag ## PreprocessFile() method # @@ -469,7 +489,8 @@ class FdfParser(object): IncFileName = self.__Token if not os.path.isabs(IncFileName): if IncFileName.startswith('$(WORKSPACE)'): - Str = IncFileName.replace('$(WORKSPACE)', os.environ.get('WORKSPACE')) + Str = mws.handleWsMacro(IncFileName) + Str = Str.replace('$(WORKSPACE)', os.environ.get('WORKSPACE')) if os.path.exists(Str): if not os.path.isabs(Str): Str = os.path.abspath(Str) @@ -478,7 +499,7 @@ class FdfParser(object): # file is in the same dir with FDF file FullFdf = self.FileName if not os.path.isabs(self.FileName): - FullFdf = os.path.join(os.environ.get('WORKSPACE'), self.FileName) + FullFdf = mws.join(os.environ.get('WORKSPACE'), self.FileName) IncFileName = os.path.join(os.path.dirname(FullFdf), IncFileName) @@ -554,14 +575,7 @@ class FdfParser(object): IfList.append([IfStartPos, None, None]) CondLabel = self.__Token - if not self.__GetNextToken(): - raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber) - MacroName = self.__Token - NotFlag = False - if MacroName.startswith('!'): - NotFlag = True - MacroName = MacroName[1:] - + MacroName, NotFlag = self.__GetMacroName() NotDefineFlag = False if CondLabel == '!ifndef': NotDefineFlag = True @@ -615,14 +629,7 @@ class FdfParser(object): self.__WipeOffArea.append((IfList[-1][0], ElseStartPos)) IfList[-1] = [ElseStartPos, True, IfList[-1][2]] if self.__Token == '!elseif': - if not self.__GetNextToken(): - raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber) - MacroName = self.__Token - NotFlag = False - if MacroName.startswith('!'): - NotFlag = True - MacroName = MacroName[1:] - + MacroName, NotFlag = self.__GetMacroName() if not self.__GetNextOp(): raise Warning("expected !endif At Line ", self.FileName, self.CurrentLineNumber) @@ -927,8 +934,7 @@ class FdfParser(object): if not self.__GetNextToken(): return False - p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}') - if p.match(self.__Token) != None: + if RangeExpression.RegGuidPattern.match(self.__Token) != None: return True else: self.__UndoToken() @@ -1439,10 +1445,17 @@ class FdfParser(object): def __GetBlockStatements(self, Obj): if not self.__GetBlockStatement(Obj): - raise Warning("expected block statement At Line ", self.FileName, self.CurrentLineNumber) - + #set default block size is 1 + Obj.BlockSizeList.append((1, Obj.Size, None)) + return True + while self.__GetBlockStatement(Obj): pass + + for Item in Obj.BlockSizeList: + if Item[0] == None or Item[1] == None: + raise Warning("expected block statement for Fd Section", self.FileName, self.CurrentLineNumber) + return True ## __GetBlockStatement() method @@ -1752,8 +1765,8 @@ class FdfParser(object): if not self.__GetNextHexNumber(): raise Warning("expected Hex byte At Line ", self.FileName, self.CurrentLineNumber) - if len(self.__Token) > 4: - raise Warning("Hex byte(must be 2 digits) too long At Line ", self.FileName, self.CurrentLineNumber) + if len(self.__Token) > 18: + raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber) DataString = self.__Token DataString += "," @@ -1784,8 +1797,8 @@ class FdfParser(object): if not self.__GetNextHexNumber(): raise Warning("expected Hex byte At Line ", self.FileName, self.CurrentLineNumber) - if len(self.__Token) > 4: - raise Warning("Hex byte(must be 2 digits) too long At Line ", self.FileName, self.CurrentLineNumber) + if len(self.__Token) > 18: + raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber) DataString = self.__Token DataString += "," @@ -2329,6 +2342,9 @@ class FdfParser(object): AlignValue = None if self.__GetAlignment(): + 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 BuildNum = None @@ -2342,6 +2358,8 @@ class FdfParser(object): BuildNum = self.__Token if self.__IsKeyword( "VERSION"): + if AlignValue == 'Auto': + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) if not self.__IsToken( "="): raise Warning("expected '=' At Line ", self.FileName, self.CurrentLineNumber) if not self.__GetNextToken(): @@ -2356,6 +2374,8 @@ class FdfParser(object): Obj.SectionList.append(VerSectionObj) elif self.__IsKeyword( "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( "="): raise Warning("expected '=' At Line ", self.FileName, self.CurrentLineNumber) if not self.__GetNextToken(): @@ -2369,6 +2389,8 @@ class FdfParser(object): Obj.SectionList.append(UiSectionObj) elif self.__IsKeyword( "FV_IMAGE"): + if AlignValue == 'Auto': + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) if not self.__IsToken( "="): raise Warning("expected '=' At Line ", self.FileName, self.CurrentLineNumber) if not self.__GetNextWord(): @@ -2408,7 +2430,9 @@ class FdfParser(object): Obj.SectionList.append(FvImageSectionObj) - elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP"): + elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP") or self.__IsKeyword("SMM_DEPEX_EXP"): + if AlignValue == 'Auto': + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) DepexSectionObj = CommonDataClass.FdfClass.DepexSectionClassObject() DepexSectionObj.Alignment = AlignValue DepexSectionObj.DepexType = self.__Token @@ -2436,6 +2460,8 @@ class FdfParser(object): if self.__Token not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\ "UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "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'): + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) # DataSection DataSectionObj = CommonDataClass.FdfClass.DataSectionClassObject() DataSectionObj.Alignment = AlignValue @@ -2585,6 +2611,9 @@ class FdfParser(object): AlignValue = None if self.__GetAlignment(): + 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 if not self.__GetCglSection(FfsFileObj, AlignValue): @@ -2747,7 +2776,7 @@ class FdfParser(object): raise Warning("expected '.' At Line ", self.FileName, self.CurrentLineNumber) Arch = self.__SkippedChars.rstrip(".") - if Arch.upper() not in ("IA32", "X64", "IPF", "EBC", "ARM", "COMMON"): + if Arch.upper() not in ("IA32", "X64", "IPF", "EBC", "ARM", "AARCH64", "COMMON"): raise Warning("Unknown Arch '%s'" % Arch, self.FileName, self.CurrentLineNumber) ModuleType = self.__GetModuleType() @@ -2798,7 +2827,7 @@ class FdfParser(object): "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_DRIVER", "SMM_CORE"): + "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"): raise Warning("Unknown Module type At line ", self.FileName, self.CurrentLineNumber) return self.__Token @@ -2815,8 +2844,7 @@ class FdfParser(object): Ext = "" if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') - if Pattern.match(self.__Token): + if FileExtensionPattern.match(self.__Token): Ext = self.__Token return '.' + Ext else: @@ -2842,7 +2870,7 @@ class FdfParser(object): 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_DXE_COMBO", "SMM", "SMM_CORE"): + "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE", "MM_STANDALONE"): raise Warning("Unknown FV type At line ", self.FileName, self.CurrentLineNumber) if not self.__IsToken("="): @@ -2899,7 +2927,8 @@ class FdfParser(object): AlignValue = "" if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + 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 At Line ", self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -2963,8 +2992,11 @@ class FdfParser(object): CheckSum = True if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + 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 At Line ", self.FileName, self.CurrentLineNumber) + if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'): + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) AlignValue = self.__Token if not self.__GetNextToken(): @@ -3035,18 +3067,11 @@ class FdfParser(object): FvImageSectionObj.FvFileType = self.__Token if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + 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 At Line ", self.FileName, self.CurrentLineNumber) FvImageSectionObj.Alignment = self.__Token - if self.__IsKeyword("FV"): - FvImageSectionObj.FvFileType = self.__Token - - if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): - raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber) - FvImageSectionObj.Alignment = self.__Token - if self.__IsToken('|'): FvImageSectionObj.FvFileExtension = self.__GetFileExtension() elif self.__GetNextToken(): @@ -3110,6 +3135,11 @@ class FdfParser(object): EfiSectionObj.BuildNum = self.__Token if self.__GetAlignment(): + 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'): + raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) EfiSectionObj.Alignment = self.__Token if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'): @@ -3221,8 +3251,8 @@ class FdfParser(object): elif SectionType == "RAW": if FileType not in ("BIN", "SEC_BIN", "RAW", "ASL", "ACPI"): raise Warning("Incorrect section file type At Line ", self.FileName, self.CurrentLineNumber) - elif SectionType == "DXE_DEPEX": - if FileType not in ("DXE_DEPEX", "SEC_DXE_DEPEX"): + elif SectionType == "DXE_DEPEX" or SectionType == "SMM_DEPEX": + if FileType not in ("DXE_DEPEX", "SEC_DXE_DEPEX", "SMM_DEPEX"): raise Warning("Incorrect section file type At Line ", self.FileName, self.CurrentLineNumber) elif SectionType == "UI": if FileType not in ("UI", "SEC_UI"): @@ -3336,7 +3366,7 @@ class FdfParser(object): raise Warning("expected '.' At Line ", self.FileName, self.CurrentLineNumber) Arch = self.__SkippedChars.rstrip(".").upper() - if Arch not in ("IA32", "X64", "IPF", "ARM"): + if Arch not in ("IA32", "X64", "IPF", "ARM", "AARCH64"): raise Warning("Unknown Arch At line ", self.FileName, self.CurrentLineNumber) if not self.__GetNextWord(): @@ -3350,7 +3380,7 @@ class FdfParser(object): if self.__IsToken(","): if not self.__GetNextWord(): raise Warning("expected Arch list At Line ", self.FileName, self.CurrentLineNumber) - if self.__Token.upper() not in ("IA32", "X64", "IPF", "ARM"): + if self.__Token.upper() not in ("IA32", "X64", "IPF", "ARM", "AARCH64"): raise Warning("Unknown Arch At line ", self.FileName, self.CurrentLineNumber) VtfObj.ArchList = self.__Token.upper() @@ -3627,7 +3657,14 @@ class FdfParser(object): return CycleRefExists if __name__ == "__main__": - parser = FdfParser("..\LakeportX64Pkg.fdf") + import sys + try: + test_file = sys.argv[1] + except IndexError, v: + print "Usage: %s filename" % sys.argv[0] + sys.exit(1) + + parser = FdfParser(test_file) try: parser.ParseFile() parser.CycleReferenceCheck()