## @file\r
# parse FDF file\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
\r
import CommonDataClass.FdfClass\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+from Common.RangeExpression import RangeExpression\r
+from Common.GlobalData import *\r
\r
##define T_CHAR_SPACE ' '\r
##define T_CHAR_NULL '\0'\r
# All Macro values when parsing file, not replace existing Macro\r
AllMacroList = []\r
\r
+FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
+\r
def GetRealFileLine (File, Line):\r
\r
InsertedLines = 0\r
# @param File The FDF name\r
# @param Line The Line number that error occurs\r
#\r
- def __init__(self, Str, File = None, Line = None):\r
- \r
+ def __init__(self, Str, File=None, Line=None):\r
+\r
FileLineTuple = GetRealFileLine(File, Line)\r
self.FileName = FileLineTuple[0]\r
self.LineNumber = FileLineTuple[1]\r
if Profile.FileName == File and Profile.MacroName == Name and Profile.DefinedAtLine <= Line:\r
Value = Profile.MacroValue\r
\r
- if Value != None:\r
+ if Value is not None:\r
Str = Str.replace('$(' + Name + ')', Value)\r
MacroEnd = MacroStart + len(Value) \r
\r
else:\r
raise Warning("Macro not complete At Line ", self.FileName, self.CurrentLineNumber)\r
return Str\r
- \r
- def __ReplaceFragment(self, StartPos, EndPos, Value = ' '):\r
+\r
+ def __ReplaceFragment(self, StartPos, EndPos, Value=' '):\r
if StartPos[0] == EndPos[0]:\r
Offset = StartPos[1]\r
while Offset <= EndPos[1]:\r
IncFileName = self.__Token\r
if not os.path.isabs(IncFileName):\r
if IncFileName.startswith('$(WORKSPACE)'):\r
- Str = IncFileName.replace('$(WORKSPACE)', os.environ.get('WORKSPACE'))\r
+ Str = mws.handleWsMacro(IncFileName)\r
+ Str = Str.replace('$(WORKSPACE)', os.environ.get('WORKSPACE'))\r
if os.path.exists(Str):\r
if not os.path.isabs(Str):\r
Str = os.path.abspath(Str)\r
# file is in the same dir with FDF file\r
FullFdf = self.FileName\r
if not os.path.isabs(self.FileName):\r
- FullFdf = os.path.join(os.environ.get('WORKSPACE'), self.FileName)\r
+ FullFdf = mws.join(os.environ.get('WORKSPACE'), self.FileName)\r
\r
IncFileName = os.path.join(os.path.dirname(FullFdf), IncFileName)\r
\r
FileLineTuple = GetRealFileLine(self.FileName, Line)\r
if Name in InputMacroDict:\r
MacroValue = InputMacroDict[Name]\r
- if Op == None:\r
- if Value == 'Bool' and MacroValue == None or MacroValue.upper() == 'FALSE':\r
+ if Op is None:\r
+ if Value == 'Bool' and MacroValue is None or MacroValue.upper() == 'FALSE':\r
return False\r
return True\r
elif Op == '!=':\r
else:\r
return False\r
else:\r
- if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue != None and MacroValue.isdigit())):\r
+ if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue is not None and MacroValue.isdigit())):\r
InputVal = long(Value, 0)\r
MacroVal = long(MacroValue, 0)\r
if Op == '>':\r
\r
for Profile in AllMacroList:\r
if Profile.FileName == FileLineTuple[0] and Profile.MacroName == Name and Profile.DefinedAtLine <= FileLineTuple[1]:\r
- if Op == None:\r
- if Value == 'Bool' and Profile.MacroValue == None or Profile.MacroValue.upper() == 'FALSE':\r
+ if Op is None:\r
+ if Value == 'Bool' and Profile.MacroValue is None or Profile.MacroValue.upper() == 'FALSE':\r
return False\r
return True\r
elif Op == '!=':\r
else:\r
return False\r
else:\r
- if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue != None and Profile.MacroValue.isdigit())):\r
+ if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue is not None and Profile.MacroValue.isdigit())):\r
InputVal = long(Value, 0)\r
MacroVal = long(Profile.MacroValue, 0)\r
if Op == '>':\r
\r
if not self.__GetNextToken():\r
return False\r
- 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}')\r
- if p.match(self.__Token) != None:\r
+ if gGuidPattern.match(self.__Token) is not None:\r
return True\r
else:\r
self.__UndoToken()\r
pass\r
\r
for Item in Obj.BlockSizeList:\r
- if Item[0] == None or Item[1] == None:\r
+ if Item[0] is None or Item[1] is None:\r
raise Warning("expected block statement for Fd Section", self.FileName, self.CurrentLineNumber)\r
\r
return True\r
\r
AlignValue = None\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
AlignValue = self.__Token\r
\r
\r
FvImageSectionObj = CommonDataClass.FdfClass.FvImageSectionClassObject()\r
FvImageSectionObj.Alignment = AlignValue\r
- if FvObj != None:\r
+ if FvObj is not None:\r
FvImageSectionObj.Fv = FvObj\r
FvImageSectionObj.FvName = None\r
else:\r
\r
AlignValue = None\r
if self.__GetAlignment():\r
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
AlignValue = self.__Token\r
\r
"DXE_SMM_DRIVER", "DXE_RUNTIME_DRIVER", \\r
"UEFI_DRIVER", "UEFI_APPLICATION", "USER_DEFINED", "DEFAULT", "BASE", \\r
"SECURITY_CORE", "COMBINED_PEIM_DRIVER", "PIC_PEIM", "RELOCATABLE_PEIM", \\r
- "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE"):\r
+ "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"):\r
raise Warning("Unknown Module type At line ", self.FileName, self.CurrentLineNumber)\r
return self.__Token\r
\r
\r
Ext = ""\r
if self.__GetNextToken():\r
- Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
- if Pattern.match(self.__Token):\r
+ if FileExtensionPattern.match(self.__Token):\r
Ext = self.__Token \r
return '.' + Ext \r
else:\r
\r
Type = self.__Token.strip().upper()\r
if Type not in ("RAW", "FREEFORM", "SEC", "PEI_CORE", "PEIM",\\r
- "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE"):\r
+ "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE", "MM_STANDALONE"):\r
raise Warning("Unknown FV type At line ", self.FileName, self.CurrentLineNumber)\r
\r
if not self.__IsToken("="):\r
\r
AlignValue = ""\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber)\r
AlignValue = self.__Token\r
\r
Rule.CheckSum = CheckSum\r
Rule.Fixed = Fixed\r
Rule.KeyStringList = KeyStringList\r
- if KeepReloc != None:\r
+ if KeepReloc is not None:\r
Rule.KeepReloc = KeepReloc\r
\r
while True:\r
Rule.Fixed = Fixed\r
Rule.FileExtension = Ext\r
Rule.KeyStringList = KeyStringList\r
- if KeepReloc != None:\r
+ if KeepReloc is not None:\r
Rule.KeepReloc = KeepReloc\r
\r
return Rule\r
CheckSum = True\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber)\r
if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):\r
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
Rule.Fixed = Fixed\r
Rule.FileName = self.__Token\r
Rule.KeyStringList = KeyStringList\r
- if KeepReloc != None:\r
+ if KeepReloc is not None:\r
Rule.KeepReloc = KeepReloc\r
return Rule\r
\r
FvImageSectionObj.FvFileType = self.__Token\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber)\r
FvImageSectionObj.Alignment = self.__Token\r
\r
EfiSectionObj.BuildNum = self.__Token\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"):\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'):\r
raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
EfiSectionObj.KeepReloc = False\r
else:\r
EfiSectionObj.KeepReloc = True\r
- if Obj.KeepReloc != None and Obj.KeepReloc != EfiSectionObj.KeepReloc:\r
+ if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc:\r
raise Warning("Section type %s has reloc strip flag conflict with Rule At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
else:\r
raise Warning("Section type %s could not have reloc strip flag At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
raise Warning("expected Component version At Line ", self.FileName, self.CurrentLineNumber)\r
\r
Pattern = re.compile('-$|[0-9]{0,1}[0-9]{1}\.[0-9]{0,1}[0-9]{1}')\r
- if Pattern.match(self.__Token) == None:\r
+ if Pattern.match(self.__Token) is None:\r
raise Warning("Unknown version format At line ", self.FileName, self.CurrentLineNumber)\r
CompStatementObj.CompVer = self.__Token\r
\r
for elementRegion in FdObj.RegionList:\r
if elementRegion.RegionType == 'FV':\r
for elementRegionData in elementRegion.RegionDataList:\r
- if elementRegionData != None and elementRegionData.upper() not in FvList:\r
+ if elementRegionData is not None and elementRegionData.upper() not in FvList:\r
FvList.append(elementRegionData.upper())\r
return FvList\r
\r
\r
for FfsObj in FvObj.FfsList:\r
if isinstance(FfsObj, FfsFileStatement.FileStatement):\r
- if FfsObj.FvName != None and FfsObj.FvName.upper() not in RefFvList:\r
+ if FfsObj.FvName is not None and FfsObj.FvName.upper() not in RefFvList:\r
RefFvList.append(FfsObj.FvName.upper())\r
- elif FfsObj.FdName != None and FfsObj.FdName.upper() not in RefFdList:\r
+ elif FfsObj.FdName is not None and FfsObj.FdName.upper() not in RefFdList:\r
RefFdList.append(FfsObj.FdName.upper())\r
else:\r
self.__GetReferencedFdFvTupleFromSection(FfsObj, RefFdList, RefFvList) \r
while SectionStack != []:\r
SectionObj = SectionStack.pop()\r
if isinstance(SectionObj, FvImageSection.FvImageSection):\r
- if SectionObj.FvName != None and SectionObj.FvName.upper() not in FvList:\r
+ if SectionObj.FvName is not None and SectionObj.FvName.upper() not in FvList:\r
FvList.append(SectionObj.FvName.upper())\r
- if SectionObj.Fv != None and SectionObj.Fv.UiFvName != None and SectionObj.Fv.UiFvName.upper() not in FvList:\r
+ if SectionObj.Fv is not None and SectionObj.Fv.UiFvName is not None and SectionObj.Fv.UiFvName.upper() not in FvList:\r
FvList.append(SectionObj.Fv.UiFvName.upper())\r
self.__GetReferencedFdFvTuple(SectionObj.Fv, FdList, FvList)\r
\r