X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FFdfParserLite.py;h=0e35eb484b9a0370953a2d8a7cfa961e1bb8242b;hp=59006fa5c51a89ac4ff3493a645942d4e7f2c737;hb=cfbe3c3500a64e218e7d357dacb18d8b95eddfec;hpb=30fdf1140b8d1ce93f3821d986fa165552023440 diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py index 59006fa5c5..0e35eb484b 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,14 @@ # 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 +from Common.GlobalData import * +import string ##define T_CHAR_SPACE ' ' ##define T_CHAR_NULL '\0' @@ -44,6 +49,9 @@ InputMacroDict = {} # All Macro values when parsing file, not replace existing Macro AllMacroList = [] +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\)|\*)') + def GetRealFileLine (File, Line): InsertedLines = 0 @@ -67,8 +75,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] @@ -350,15 +358,15 @@ class FdfParser(object): if Profile.FileName == File and Profile.MacroName == Name and Profile.DefinedAtLine <= Line: Value = Profile.MacroValue - if Value != None: + if Value is not None: Str = Str.replace('$(' + Name + ')', Value) MacroEnd = MacroStart + len(Value) 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 +391,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 +492,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 +502,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 +578,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 +632,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) @@ -671,8 +681,8 @@ class FdfParser(object): FileLineTuple = GetRealFileLine(self.FileName, Line) if Name in InputMacroDict: MacroValue = InputMacroDict[Name] - if Op == None: - if Value == 'Bool' and MacroValue == None or MacroValue.upper() == 'FALSE': + if Op is None: + if Value == 'Bool' and MacroValue is None or MacroValue.upper() == 'FALSE': return False return True elif Op == '!=': @@ -686,7 +696,7 @@ class FdfParser(object): else: return False else: - if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue != None and MacroValue.isdigit())): + if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue is not None and MacroValue.isdigit())): InputVal = long(Value, 0) MacroVal = long(MacroValue, 0) if Op == '>': @@ -716,8 +726,8 @@ class FdfParser(object): for Profile in AllMacroList: if Profile.FileName == FileLineTuple[0] and Profile.MacroName == Name and Profile.DefinedAtLine <= FileLineTuple[1]: - if Op == None: - if Value == 'Bool' and Profile.MacroValue == None or Profile.MacroValue.upper() == 'FALSE': + if Op is None: + if Value == 'Bool' and Profile.MacroValue is None or Profile.MacroValue.upper() == 'FALSE': return False return True elif Op == '!=': @@ -731,7 +741,7 @@ class FdfParser(object): else: return False else: - if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue != None and Profile.MacroValue.isdigit())): + if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue is not None and Profile.MacroValue.isdigit())): InputVal = long(Value, 0) MacroVal = long(Profile.MacroValue, 0) if Op == '>': @@ -927,8 +937,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 gGuidPattern.match(self.__Token) is not None: return True else: self.__UndoToken() @@ -967,32 +976,13 @@ class FdfParser(object): self.__GetOneChar() - ## __HexDigit() method - # - # Whether char input is a Hex data bit - # - # @param self The object pointer - # @param TempChar The char to test - # @retval True The char is a Hex data bit - # @retval False The char is NOT a Hex data bit - # - def __HexDigit(self, TempChar): - if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \ - or (TempChar >= '0' and TempChar <= '9'): - return True - else: - return False - def __IsHex(self, HexStr): if not HexStr.upper().startswith("0X"): return False if len(self.__Token) <= 2: return False - charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)] - if len(charList) == 0: - return True - else: - 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 @@ -1439,10 +1429,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] is None or Item[1] is None: + raise Warning("expected block statement for Fd Section", self.FileName, self.CurrentLineNumber) + return True ## __GetBlockStatement() method @@ -1599,7 +1596,7 @@ class FdfParser(object): if not self.__GetNextWord(): return True - if not self.__Token in ("SET", "FV", "FILE", "DATA"): + if not self.__Token in ("SET", "FV", "FILE", "DATA", "CAPSULE"): self.__UndoToken() RegionObj.PcdOffset = self.__GetNextPcdName() self.Profile.PcdDict[RegionObj.PcdOffset] = RegionObj.Offset + long(Fd.BaseAddress, 0) @@ -1620,10 +1617,14 @@ class FdfParser(object): if not self.__GetNextWord(): return True - if self.__Token == "FV": + elif self.__Token == "FV": self.__UndoToken() self.__GetRegionFvType( RegionObj) + elif self.__Token == "CAPSULE": + self.__UndoToken() + self.__GetRegionCapType( RegionObj) + elif self.__Token == "FILE": self.__UndoToken() self.__GetRegionFileType( RegionObj) @@ -1664,7 +1665,38 @@ class FdfParser(object): raise Warning("expected FV name At Line ", self.FileName, self.CurrentLineNumber) RegionObj.RegionDataList.append(self.__Token) - + + ## __GetRegionCapType() method + # + # Get region capsule data for region + # + # @param self The object pointer + # @param RegionObj for whom region data is got + # + def __GetRegionCapType(self, RegionObj): + + if not self.__IsKeyword("CAPSULE"): + raise Warning("expected Keyword 'CAPSULE' at line", self.FileName, self.CurrentLineNumber) + + if not self.__IsToken("="): + raise Warning("expected '=' at line", self.FileName, self.CurrentLineNumber) + + if not self.__GetNextToken(): + raise Warning("expected CAPSULE name at line", self.FileName, self.CurrentLineNumber) + + RegionObj.RegionType = "CAPSULE" + RegionObj.RegionDataList.append(self.__Token) + + while self.__IsKeyword("CAPSULE"): + + if not self.__IsToken("="): + raise Warning("expected '=' at line", self.FileName, self.CurrentLineNumber) + + if not self.__GetNextToken(): + raise Warning("expected CAPSULE name at line", self.FileName, self.CurrentLineNumber) + + RegionObj.RegionDataList.append(self.__Token) + ## __GetRegionFileType() method # # Get region file data for region @@ -1717,8 +1749,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 += "," @@ -1749,8 +1781,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 += "," @@ -2045,8 +2077,7 @@ class FdfParser(object): if self.__GetNextToken(): - p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if p.match(self.__Token): + if TokenFindPattern.match(self.__Token): FfsInfObj.KeyStringList.append(self.__Token) if not self.__IsToken(","): return @@ -2055,7 +2086,7 @@ class FdfParser(object): return while self.__GetNextToken(): - if not p.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) FfsInfObj.KeyStringList.append(self.__Token) @@ -2203,12 +2234,11 @@ class FdfParser(object): def __GetFileOpts(self, FfsFileObj): if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if Pattern.match(self.__Token): + if TokenFindPattern.match(self.__Token): FfsFileObj.KeyStringList.append(self.__Token) if self.__IsToken(","): while self.__GetNextToken(): - if not Pattern.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) FfsFileObj.KeyStringList.append(self.__Token) @@ -2294,6 +2324,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 @@ -2307,6 +2340,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(): @@ -2321,6 +2356,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(): @@ -2334,6 +2371,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(): @@ -2365,7 +2404,7 @@ class FdfParser(object): FvImageSectionObj = CommonDataClass.FdfClass.FvImageSectionClassObject() FvImageSectionObj.Alignment = AlignValue - if FvObj != None: + if FvObj is not None: FvImageSectionObj.Fv = FvObj FvImageSectionObj.FvName = None else: @@ -2373,7 +2412,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 @@ -2401,6 +2442,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 @@ -2550,6 +2593,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): @@ -2712,8 +2758,8 @@ 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"): - raise Warning("Unknown Arch At line ", self.FileName, self.CurrentLineNumber) + 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() @@ -2763,7 +2809,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"): + "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 @@ -2780,8 +2826,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: @@ -2803,11 +2848,11 @@ class FdfParser(object): raise Warning("expected FILE At Line ", self.FileName, self.CurrentLineNumber) if not self.__GetNextWord(): - raise Warning("expected FV type At Line ", self.FileName, self.CurrentLineNumber) + raise Warning("expected FFS type At Line ", 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"): + "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("="): @@ -2838,12 +2883,11 @@ class FdfParser(object): KeyStringList = [] if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if Pattern.match(self.__Token): + if TokenFindPattern.match(self.__Token): KeyStringList.append(self.__Token) if self.__IsToken(","): while self.__GetNextToken(): - if not Pattern.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) KeyStringList.append(self.__Token) @@ -2864,7 +2908,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 @@ -2877,7 +2922,7 @@ class FdfParser(object): Rule.CheckSum = CheckSum Rule.Fixed = Fixed Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc while True: @@ -2904,7 +2949,7 @@ class FdfParser(object): Rule.Fixed = Fixed Rule.FileExtension = Ext Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc return Rule @@ -2928,8 +2973,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(): @@ -2944,7 +2992,7 @@ class FdfParser(object): Rule.Fixed = Fixed Rule.FileName = self.__Token Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc return Rule @@ -3000,18 +3048,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(): @@ -3075,6 +3116,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'): @@ -3083,7 +3129,7 @@ class FdfParser(object): EfiSectionObj.KeepReloc = False else: EfiSectionObj.KeepReloc = True - if Obj.KeepReloc != None and Obj.KeepReloc != EfiSectionObj.KeepReloc: + if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc: raise Warning("Section type %s has reloc strip flag conflict with Rule At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber) else: raise Warning("Section type %s could not have reloc strip flag At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber) @@ -3186,8 +3232,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"): @@ -3301,7 +3347,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(): @@ -3315,7 +3361,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() @@ -3391,7 +3437,7 @@ class FdfParser(object): raise Warning("expected Component type At Line ", self.FileName, self.CurrentLineNumber) if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"): if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \ - not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]): + not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits: raise Warning("Unknown location type At line ", self.FileName, self.CurrentLineNumber) CompStatementObj.CompType = self.__Token @@ -3405,7 +3451,7 @@ class FdfParser(object): raise Warning("expected Component version At Line ", self.FileName, self.CurrentLineNumber) Pattern = re.compile('-$|[0-9]{0,1}[0-9]{1}\.[0-9]{0,1}[0-9]{1}') - if Pattern.match(self.__Token) == None: + if Pattern.match(self.__Token) is None: raise Warning("Unknown version format At line ", self.FileName, self.CurrentLineNumber) CompStatementObj.CompVer = self.__Token @@ -3478,7 +3524,7 @@ class FdfParser(object): for elementRegion in FdObj.RegionList: if elementRegion.RegionType == 'FV': for elementRegionData in elementRegion.RegionDataList: - if elementRegionData != None and elementRegionData.upper() not in FvList: + if elementRegionData is not None and elementRegionData.upper() not in FvList: FvList.append(elementRegionData.upper()) return FvList @@ -3495,9 +3541,9 @@ class FdfParser(object): for FfsObj in FvObj.FfsList: if isinstance(FfsObj, FfsFileStatement.FileStatement): - if FfsObj.FvName != None and FfsObj.FvName.upper() not in RefFvList: + if FfsObj.FvName is not None and FfsObj.FvName.upper() not in RefFvList: RefFvList.append(FfsObj.FvName.upper()) - elif FfsObj.FdName != None and FfsObj.FdName.upper() not in RefFdList: + elif FfsObj.FdName is not None and FfsObj.FdName.upper() not in RefFdList: RefFdList.append(FfsObj.FdName.upper()) else: self.__GetReferencedFdFvTupleFromSection(FfsObj, RefFdList, RefFvList) @@ -3518,9 +3564,9 @@ class FdfParser(object): while SectionStack != []: SectionObj = SectionStack.pop() if isinstance(SectionObj, FvImageSection.FvImageSection): - if SectionObj.FvName != None and SectionObj.FvName.upper() not in FvList: + if SectionObj.FvName is not None and SectionObj.FvName.upper() not in FvList: FvList.append(SectionObj.FvName.upper()) - if SectionObj.Fv != None and SectionObj.Fv.UiFvName != None and SectionObj.Fv.UiFvName.upper() not in FvList: + if SectionObj.Fv is not None and SectionObj.Fv.UiFvName is not None and SectionObj.Fv.UiFvName.upper() not in FvList: FvList.append(SectionObj.Fv.UiFvName.upper()) self.__GetReferencedFdFvTuple(SectionObj.Fv, FdList, FvList) @@ -3592,7 +3638,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()