X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFdfParser.py;h=4183f318b75b9369e0c7743e58b44940ec5ab2e1;hp=72fb3dc56e22bab0107195945b0844ad69a13c62;hb=cfbe3c3500a64e218e7d357dacb18d8b95eddfec;hpb=df81077f77f91b43f32f70e06950b86e20f711da diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 72fb3dc56e..4183f318b7 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -1,7 +1,7 @@ ## @file # parse FDF file # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.
# # This program and the accompanying materials @@ -42,6 +42,7 @@ import ComponentStatement import OptionRom import OptRomInfStatement import OptRomFileStatement +import string from GenFdsGlobalVariable import GenFdsGlobalVariable from Common.BuildToolError import * @@ -52,11 +53,15 @@ import Common.GlobalData as GlobalData from Common.Expression import * from Common import GlobalData from Common.String import ReplaceMacro - +import uuid from Common.Misc import tdict - +from Common.MultipleWorkspace import MultipleWorkspace as mws import Common.LongFilePathOs as os 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' @@ -133,21 +138,6 @@ class Warning (Exception): def __str__(self): return self.Message -## The MACRO class that used to record macro value data when parsing include file -# -# -class MacroProfile : - ## The constructor - # - # @param self The object pointer - # @param FileName The file that to be parsed - # - def __init__(self, FileName, Line): - self.FileName = FileName - self.DefinedAtLine = Line - self.MacroName = None - self.MacroValue = None - ## The Include file content class that used to record file data when parsing include file # # May raise Exception when opening file. @@ -165,6 +155,10 @@ class IncludeFileProfile : fsock = open(FileName, "rb", 0) try: self.FileLinesList = fsock.readlines() + for index, line in enumerate(self.FileLinesList): + if not line.endswith('\n'): + self.FileLinesList[index] += '\n' + finally: fsock.close() @@ -231,6 +225,7 @@ class FileProfile : self.PcdDict = {} self.InfList = [] + self.InfDict = {'ArchTBD':[]} # ECC will use this Dict and List information self.PcdFileLineDict = {} self.InfFileLineList = [] @@ -617,27 +612,46 @@ class FdfParser: def PreprocessIncludeFile(self): # nested include support Processed = False + MacroDict = {} while self.__GetNextToken(): - if self.__Token == '!include': + if self.__Token == 'DEFINE': + if not self.__GetNextToken(): + raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber) + Macro = self.__Token + if not self.__IsToken( "="): + raise Warning("expected '='", self.FileName, self.CurrentLineNumber) + Value = self.__GetExpression() + MacroDict[Macro] = Value + + elif self.__Token == '!include': Processed = True IncludeLine = self.CurrentLineNumber IncludeOffset = self.CurrentOffsetWithinLine - len('!include') if not self.__GetNextToken(): raise Warning("expected include file name", self.FileName, self.CurrentLineNumber) IncFileName = self.__Token - __IncludeMacros = {} - for Macro in ['WORKSPACE', 'ECP_SOURCE', 'EFI_SOURCE', 'EDK_SOURCE']: + PreIndex = 0 + StartPos = IncFileName.find('$(', PreIndex) + EndPos = IncFileName.find(')', StartPos+2) + while StartPos != -1 and EndPos != -1: + Macro = IncFileName[StartPos+2 : EndPos] MacroVal = self.__GetMacroValue(Macro) - if MacroVal: - __IncludeMacros[Macro] = MacroVal + if not MacroVal: + if Macro in MacroDict: + MacroVal = MacroDict[Macro] + if MacroVal is not None: + IncFileName = IncFileName.replace('$(' + Macro + ')', MacroVal, 1) + if MacroVal.find('$(') != -1: + PreIndex = StartPos + else: + PreIndex = StartPos + len(MacroVal) + else: + raise Warning("The Macro %s is not defined" %Macro, self.FileName, self.CurrentLineNumber) + StartPos = IncFileName.find('$(', PreIndex) + EndPos = IncFileName.find(')', StartPos+2) - try: - IncludedFile = NormPath(ReplaceMacro(IncFileName, __IncludeMacros, RaiseError=True)) - except: - raise Warning("only these system environment variables are permitted to start the path of the included file: " - "$(WORKSPACE), $(ECP_SOURCE), $(EFI_SOURCE), $(EDK_SOURCE)", - self.FileName, self.CurrentLineNumber) + IncludedFile = NormPath(IncFileName) # # First search the include file under the same directory as FDF file # @@ -674,7 +688,7 @@ class FdfParser: # list index of the insertion, note that line number is 'CurrentLine + 1' InsertAtLine = CurrentLine ParentProfile = GetParentAtLine (CurrentLine) - if ParentProfile != None: + if ParentProfile is not None: ParentProfile.IncludeFileList.insert(0, IncFileProfile) IncFileProfile.Level = ParentProfile.Level + 1 IncFileProfile.InsertStartLineNumber = InsertAtLine + 1 @@ -750,7 +764,7 @@ class FdfParser: while StartPos != -1 and EndPos != -1 and self.__Token not in ['!ifdef', '!ifndef', '!if', '!elseif']: MacroName = CurLine[StartPos+2 : EndPos] MacorValue = self.__GetMacroValue(MacroName) - if MacorValue != None: + if MacorValue is not None: CurLine = CurLine.replace('$(' + MacroName + ')', MacorValue, 1) if MacorValue.find('$(') != -1: PreIndex = StartPos @@ -899,6 +913,13 @@ class FdfParser: MacroDict.update(GlobalData.gGlobalDefines) MacroDict.update(GlobalData.gCommandLineDefines) + if GlobalData.BuildOptionPcd: + for Item in GlobalData.BuildOptionPcd: + if type(Item) is tuple: + continue + PcdName, TmpValue = Item.split("=") + TmpValue = BuildOptionValue(TmpValue, {}) + MacroDict[PcdName.strip()] = TmpValue # Highest priority return MacroDict @@ -1116,13 +1137,29 @@ class FdfParser: 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() 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 + ## __UndoToken() method # # Go back one token unit in file buffer @@ -1156,32 +1193,13 @@ class FdfParser: 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 @@ -1362,25 +1380,10 @@ class FdfParser: try: self.Preprocess() - while self.__GetFd(): - pass - - while self.__GetFv(): - pass - - while self.__GetFmp(): - pass - - while self.__GetCapsule(): - pass - - while self.__GetVtf(): - pass - - while self.__GetRule(): - pass - - while self.__GetOptionRom(): + # + # 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: @@ -1388,7 +1391,7 @@ class FdfParser: #'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \ # At this point, the closest parent would be the included file itself Profile = GetParentAtLine(X.OriginalLineNumber) - if Profile != None: + if Profile is not None: X.Message += ' near line %d, column %d: %s' \ % (X.LineNumber, 0, Profile.FileLinesList[X.LineNumber-1]) else: @@ -1516,7 +1519,7 @@ class FdfParser: while self.__GetTokenStatements(FdObj): pass for Attr in ("BaseAddress", "Size", "ErasePolarity"): - if getattr(FdObj, Attr) == None: + if getattr(FdObj, Attr) is None: self.__GetNextToken() raise Warning("Keyword %s missing" % Attr, self.FileName, self.CurrentLineNumber) @@ -1671,7 +1674,7 @@ class FdfParser: IsBlock = True Item = Obj.BlockSizeList[-1] - if Item[0] == None or Item[1] == None: + if Item[0] is None or Item[1] is None: raise Warning("expected block statement", self.FileName, self.CurrentLineNumber) return IsBlock @@ -1839,7 +1842,7 @@ class FdfParser: # def __GetRegionLayout(self, Fd): Offset = self.__CalcRegionExpr() - if Offset == None: + if Offset is None: return False RegionObj = Region.Region() @@ -1850,7 +1853,7 @@ class FdfParser: raise Warning("expected '|'", self.FileName, self.CurrentLineNumber) Size = self.__CalcRegionExpr() - if Size == None: + if Size is None: raise Warning("expected Region Size", self.FileName, self.CurrentLineNumber) RegionObj.Size = Size @@ -1942,7 +1945,7 @@ class FdfParser: raise Warning("expected FV name", self.FileName, self.CurrentLineNumber) RegionObj.RegionType = "FV" - RegionObj.RegionDataList.append(self.__Token) + RegionObj.RegionDataList.append((self.__Token).upper()) while self.__IsKeyword( "FV"): @@ -1952,7 +1955,7 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("expected FV name", self.FileName, self.CurrentLineNumber) - RegionObj.RegionDataList.append(self.__Token) + RegionObj.RegionDataList.append((self.__Token).upper()) ## __GetRegionCapType() method # @@ -2280,7 +2283,7 @@ class FdfParser: "WRITE_DISABLED_CAP", "WRITE_STATUS", "READ_ENABLED_CAP", \ "READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK_CAP", \ "READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \ - "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT"): + "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT", "FvUsedSizeEnable"): self.__UndoToken() return False @@ -2334,7 +2337,7 @@ class FdfParser: def __GetFvExtEntryStatement(self, FvObj): - if not self.__IsKeyword( "FV_EXT_ENTRY"): + if not (self.__IsKeyword( "FV_EXT_ENTRY") or self.__IsKeyword( "FV_EXT_ENTRY_TYPE")): return False if not self.__IsKeyword ("TYPE"): @@ -2455,6 +2458,8 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("expected INF file path", self.FileName, self.CurrentLineNumber) ffsInf.InfFileName = self.__Token + if not ffsInf.InfFileName.endswith('.inf'): + raise Warning("expected .inf file path", self.FileName, self.CurrentLineNumber) ffsInf.CurrentLineNum = self.CurrentLineNumber ffsInf.CurrentLineContent = self.__CurrentLine() @@ -2472,6 +2477,13 @@ class FdfParser: self.Profile.InfList.append(ffsInf.InfFileName) FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber) self.Profile.InfFileLineList.append(FileLineTuple) + if ffsInf.UseArch: + if ffsInf.UseArch not in self.Profile.InfDict: + self.Profile.InfDict[ffsInf.UseArch] = [ffsInf.InfFileName] + else: + self.Profile.InfDict[ffsInf.UseArch].append(ffsInf.InfFileName) + else: + self.Profile.InfDict['ArchTBD'].append(ffsInf.InfFileName) if self.__IsToken('|'): if self.__IsKeyword('RELOCS_STRIPPED'): @@ -2729,9 +2741,12 @@ 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"): + 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 + #For FFS, Auto is default option same to "" + if not self.__Token == "Auto": + AlignValue = self.__Token if not self.__GetNextToken(): raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber) @@ -2764,12 +2779,11 @@ class FdfParser: 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\"", self.FileName, self.CurrentLineNumber) FfsFileObj.KeyStringList.append(self.__Token) @@ -2786,7 +2800,8 @@ class FdfParser: FfsFileObj.CheckSum = True if self.__GetAlignment(): - if self.__Token not in ("Auto", "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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) #For FFS, Auto is default option same to "" if not self.__Token == "Auto": @@ -2857,7 +2872,8 @@ class FdfParser: AlignValue = None if self.__GetAlignment(): - if self.__Token not in ("Auto", "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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -2936,7 +2952,7 @@ class FdfParser: FvImageSectionObj = FvImageSection.FvImageSection() FvImageSectionObj.Alignment = AlignValue - if FvObj != None: + if FvObj is not None: FvImageSectionObj.Fv = FvObj FvImageSectionObj.FvName = None else: @@ -3146,7 +3162,8 @@ class FdfParser: AlignValue = None 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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -3179,7 +3196,7 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("The FMP payload section is empty!", self.FileName, self.CurrentLineNumber) - FmpKeyList = ['IMAGE_HEADER_INIT_VERSION', 'IMAGE_TYPE_ID', 'IMAGE_INDEX', 'HARDWARE_INSTANCE'] + FmpKeyList = ['IMAGE_HEADER_INIT_VERSION', 'IMAGE_TYPE_ID', 'IMAGE_INDEX', 'HARDWARE_INSTANCE', 'CERTIFICATE_GUID', 'MONOTONIC_COUNT'] while self.__Token in FmpKeyList: Name = self.__Token FmpKeyList.remove(Name) @@ -3187,32 +3204,52 @@ class FdfParser: raise Warning("expected '='", self.FileName, self.CurrentLineNumber) if Name == 'IMAGE_TYPE_ID': if not self.__GetNextGuid(): - raise Warning("expected GUID value for IMAGE_TYPE_ID", self.FileName, self.CurrentLineNumber) + raise Warning("expected GUID value for IMAGE_TYPE_ID.", self.FileName, self.CurrentLineNumber) FmpData.ImageTypeId = self.__Token + elif Name == 'CERTIFICATE_GUID': + if not self.__GetNextGuid(): + raise Warning("expected GUID value for CERTIFICATE_GUID.", self.FileName, self.CurrentLineNumber) + FmpData.Certificate_Guid = self.__Token + if uuid.UUID(FmpData.Certificate_Guid) != EFI_CERT_TYPE_RSA2048_SHA256_GUID and uuid.UUID(FmpData.Certificate_Guid) != EFI_CERT_TYPE_PKCS7_GUID: + raise Warning("Only support EFI_CERT_TYPE_RSA2048_SHA256_GUID or EFI_CERT_TYPE_PKCS7_GUID for CERTIFICATE_GUID.", self.FileName, self.CurrentLineNumber) else: if not self.__GetNextToken(): raise Warning("expected value of %s" % Name, self.FileName, self.CurrentLineNumber) Value = self.__Token if Name == 'IMAGE_HEADER_INIT_VERSION': - FmpData.Version = Value + if self.__Verify(Name, Value, 'UINT8'): + FmpData.Version = Value elif Name == 'IMAGE_INDEX': - FmpData.ImageIndex = Value + if self.__Verify(Name, Value, 'UINT8'): + FmpData.ImageIndex = Value elif Name == 'HARDWARE_INSTANCE': - FmpData.HardwareInstance = Value + if self.__Verify(Name, Value, 'UINT8'): + FmpData.HardwareInstance = Value + elif Name == 'MONOTONIC_COUNT': + if self.__Verify(Name, Value, 'UINT64'): + FmpData.MonotonicCount = Value + if FmpData.MonotonicCount.upper().startswith('0X'): + FmpData.MonotonicCount = (long)(FmpData.MonotonicCount, 16) + else: + FmpData.MonotonicCount = (long)(FmpData.MonotonicCount) if not self.__GetNextToken(): break else: self.__UndoToken() - if FmpKeyList: - raise Warning("Missing keywords %s in FMP payload section" % ', '.join(FmpKeyList), self.FileName, self.CurrentLineNumber) - ImageFile = self.__ParseRawFileStatement() - if not ImageFile: - raise Warning("Missing image file in FMP payload section", self.FileName, self.CurrentLineNumber) - FmpData.ImageFile = ImageFile - VendorCodeFile = self.__ParseRawFileStatement() - if VendorCodeFile: - FmpData.VendorCodeFile = VendorCodeFile + if (FmpData.MonotonicCount and not FmpData.Certificate_Guid) or (not FmpData.MonotonicCount and FmpData.Certificate_Guid): + EdkLogger.error("FdfParser", FORMAT_INVALID, "CERTIFICATE_GUID and MONOTONIC_COUNT must be work as a pair.") + + # Only the IMAGE_TYPE_ID is required item + if FmpKeyList and 'IMAGE_TYPE_ID' in FmpKeyList: + raise Warning("Missing keywords IMAGE_TYPE_ID in FMP payload section.", self.FileName, self.CurrentLineNumber) + # get the Image file and Vendor code file + self.__GetFMPCapsuleData(FmpData) + if not FmpData.ImageFile: + raise Warning("Missing image file in FMP payload section.", self.FileName, self.CurrentLineNumber) + # check whether more than one Vendor code file + if len(FmpData.VendorCodeFile) > 1: + raise Warning("At most one Image file and one Vendor code file are allowed in FMP payload section.", self.FileName, self.CurrentLineNumber) self.Profile.FmpPayloadDict[FmpUiName] = FmpData return True @@ -3344,6 +3381,22 @@ class FdfParser: if not (IsInf or IsFile or IsFv or IsFd or IsAnyFile or IsAfile or IsFmp): break + ## __GetFMPCapsuleData() method + # + # Get capsule data for FMP capsule + # + # @param self The object pointer + # @param Obj for whom capsule data are got + # + def __GetFMPCapsuleData(self, Obj): + + while True: + IsFv = self.__GetFvStatement(Obj, True) + IsFd = self.__GetFdStatement(Obj, True) + IsAnyFile = self.__GetAnyFileStatement(Obj, True) + if not (IsFv or IsFd or IsAnyFile): + break + ## __GetFvStatement() method # # Get FV for capsule @@ -3353,7 +3406,7 @@ class FdfParser: # @retval True Successfully find a FV statement # @retval False Not able to find a FV statement # - def __GetFvStatement(self, CapsuleObj): + def __GetFvStatement(self, CapsuleObj, FMPCapsule = False): if not self.__IsKeyword("FV"): return False @@ -3369,7 +3422,13 @@ class FdfParser: CapsuleFv = CapsuleData.CapsuleFv() CapsuleFv.FvName = self.__Token - CapsuleObj.CapsuleDataList.append(CapsuleFv) + if FMPCapsule: + if not CapsuleObj.ImageFile: + CapsuleObj.ImageFile.append(CapsuleFv) + else: + CapsuleObj.VendorCodeFile.append(CapsuleFv) + else: + CapsuleObj.CapsuleDataList.append(CapsuleFv) return True ## __GetFdStatement() method @@ -3381,7 +3440,7 @@ class FdfParser: # @retval True Successfully find a FD statement # @retval False Not able to find a FD statement # - def __GetFdStatement(self, CapsuleObj): + def __GetFdStatement(self, CapsuleObj, FMPCapsule = False): if not self.__IsKeyword("FD"): return False @@ -3397,7 +3456,13 @@ class FdfParser: CapsuleFd = CapsuleData.CapsuleFd() CapsuleFd.FdName = self.__Token - CapsuleObj.CapsuleDataList.append(CapsuleFd) + if FMPCapsule: + if not CapsuleObj.ImageFile: + CapsuleObj.ImageFile.append(CapsuleFd) + else: + CapsuleObj.VendorCodeFile.append(CapsuleFd) + else: + CapsuleObj.CapsuleDataList.append(CapsuleFd) return True def __GetFmpStatement(self, CapsuleObj): @@ -3435,9 +3500,11 @@ class FdfParser: raise Warning("expected File name", self.FileName, self.CurrentLineNumber) AnyFileName = self.__Token - AnyFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(AnyFileName) - if not os.path.exists(AnyFileName): - raise Warning("File %s not exists"%AnyFileName, self.FileName, self.CurrentLineNumber) + self.__VerifyFile(AnyFileName) + + if not os.path.isabs(AnyFileName): + AnyFileName = mws.join(GenFdsGlobalVariable.WorkSpaceDir, AnyFileName) + return AnyFileName ## __GetAnyFileStatement() method @@ -3449,14 +3516,20 @@ class FdfParser: # @retval True Successfully find a Anyfile statement # @retval False Not able to find a AnyFile statement # - def __GetAnyFileStatement(self, CapsuleObj): + def __GetAnyFileStatement(self, CapsuleObj, FMPCapsule = False): AnyFileName = self.__ParseRawFileStatement() if not AnyFileName: return False CapsuleAnyFile = CapsuleData.CapsuleAnyFile() CapsuleAnyFile.FileName = AnyFileName - CapsuleObj.CapsuleDataList.append(CapsuleAnyFile) + if FMPCapsule: + if not CapsuleObj.ImageFile: + CapsuleObj.ImageFile.append(CapsuleAnyFile) + else: + CapsuleObj.VendorCodeFile.append(CapsuleAnyFile) + else: + CapsuleObj.CapsuleDataList.append(CapsuleAnyFile) return True ## __GetAfileStatement() method @@ -3580,7 +3653,7 @@ class FdfParser: "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"): + "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"): raise Warning("Unknown Module type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) return self.__Token @@ -3597,8 +3670,7 @@ class FdfParser: 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: @@ -3624,7 +3696,7 @@ class FdfParser: 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"): + "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"): raise Warning("Unknown FV type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) if not self.__IsToken("="): @@ -3655,12 +3727,11 @@ class FdfParser: 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\"", self.FileName, self.CurrentLineNumber) KeyStringList.append(self.__Token) @@ -3681,7 +3752,8 @@ class FdfParser: AlignValue = "" if self.__GetAlignment(): - if self.__Token not in ("Auto", "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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) #For FFS, Auto is default option same to "" if not self.__Token == "Auto": @@ -3696,7 +3768,7 @@ class FdfParser: Rule.CheckSum = CheckSum Rule.Fixed = Fixed Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc while True: @@ -3730,7 +3802,8 @@ class FdfParser: SectAlignment = "" if self.__GetAlignment(): - if self.__Token not in ("Auto", "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 '%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) @@ -3751,7 +3824,7 @@ class FdfParser: Rule.CheckSum = CheckSum Rule.Fixed = Fixed Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc Rule.FileExtension = Ext Rule.FileName = self.__Token @@ -3809,7 +3882,8 @@ class FdfParser: 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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) FvImageSectionObj.Alignment = self.__Token @@ -3876,7 +3950,8 @@ 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"): + 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) @@ -3888,7 +3963,7 @@ class FdfParser: 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" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) else: raise Warning("Section type %s could not have reloc strip flag" % EfiSectionObj.SectionType, self.FileName, self.CurrentLineNumber) @@ -4201,7 +4276,7 @@ class FdfParser: raise Warning("expected Component type", 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 '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) CompStatementObj.CompType = self.__Token @@ -4215,7 +4290,7 @@ class FdfParser: raise Warning("expected Component version", self.FileName, self.CurrentLineNumber) Pattern = re.compile('-$|[0-9a-fA-F]{1,2}\.[0-9a-fA-F]{1,2}$', re.DOTALL) - if Pattern.match(self.__Token) == None: + if Pattern.match(self.__Token) is None: raise Warning("Unknown version format '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) CompStatementObj.CompVer = self.__Token @@ -4352,6 +4427,13 @@ class FdfParser: self.Profile.InfList.append(ffsInf.InfFileName) FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber) self.Profile.InfFileLineList.append(FileLineTuple) + if ffsInf.UseArch: + if ffsInf.UseArch not in self.Profile.InfDict: + self.Profile.InfDict[ffsInf.UseArch] = [ffsInf.InfFileName] + else: + self.Profile.InfDict[ffsInf.UseArch].append(ffsInf.InfFileName) + else: + self.Profile.InfDict['ArchTBD'].append(ffsInf.InfFileName) self.__GetOptRomOverrides (ffsInf) @@ -4472,7 +4554,7 @@ class FdfParser: for elementRegionData in elementRegion.RegionDataList: if elementRegionData.endswith(".cap"): continue - if elementRegionData != None and elementRegionData.upper() not in CapList: + if elementRegionData is not None and elementRegionData.upper() not in CapList: CapList.append(elementRegionData.upper()) return CapList @@ -4488,15 +4570,15 @@ class FdfParser: def __GetReferencedFdCapTuple(self, CapObj, RefFdList = [], RefFvList = []): for CapsuleDataObj in CapObj.CapsuleDataList : - if hasattr(CapsuleDataObj, 'FvName') and CapsuleDataObj.FvName != None and CapsuleDataObj.FvName.upper() not in RefFvList: + if hasattr(CapsuleDataObj, 'FvName') and CapsuleDataObj.FvName is not None and CapsuleDataObj.FvName.upper() not in RefFvList: RefFvList.append (CapsuleDataObj.FvName.upper()) - elif hasattr(CapsuleDataObj, 'FdName') and CapsuleDataObj.FdName != None and CapsuleDataObj.FdName.upper() not in RefFdList: + elif hasattr(CapsuleDataObj, 'FdName') and CapsuleDataObj.FdName is not None and CapsuleDataObj.FdName.upper() not in RefFdList: RefFdList.append (CapsuleDataObj.FdName.upper()) - elif CapsuleDataObj.Ffs != None: + elif CapsuleDataObj.Ffs is not None: if isinstance(CapsuleDataObj.Ffs, FfsFileStatement.FileStatement): - if CapsuleDataObj.Ffs.FvName != None and CapsuleDataObj.Ffs.FvName.upper() not in RefFvList: + if CapsuleDataObj.Ffs.FvName is not None and CapsuleDataObj.Ffs.FvName.upper() not in RefFvList: RefFvList.append(CapsuleDataObj.Ffs.FvName.upper()) - elif CapsuleDataObj.Ffs.FdName != None and CapsuleDataObj.Ffs.FdName.upper() not in RefFdList: + elif CapsuleDataObj.Ffs.FdName is not None and CapsuleDataObj.Ffs.FdName.upper() not in RefFdList: RefFdList.append(CapsuleDataObj.Ffs.FdName.upper()) else: self.__GetReferencedFdFvTupleFromSection(CapsuleDataObj.Ffs, RefFdList, RefFvList) @@ -4519,7 +4601,7 @@ class FdfParser: for elementRegionData in elementRegion.RegionDataList: if elementRegionData.endswith(".fv"): continue - 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 @@ -4536,9 +4618,9 @@ class FdfParser: 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) @@ -4559,9 +4641,9 @@ class FdfParser: 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) @@ -4698,6 +4780,10 @@ class FdfParser: return False + def GetAllIncludedFile (self): + global AllIncludeFileList + return AllIncludeFileList + if __name__ == "__main__": import sys try: