BaseTools: Update FMP Capsule support to follow FDF spec
Current the FMP Capsule feature is supported, but its format has a little different with FDF spec. so this patch 1) Align the FMP Capsule with FDF spec. 2) fix some style issue, eg: Tab. 3) Add a SectionParser function to check the section header info since this method is used in 7 places. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -55,7 +55,6 @@ from Common.String import ReplaceMacro
|
|||||||
|
|
||||||
from Common.Misc import tdict
|
from Common.Misc import tdict
|
||||||
|
|
||||||
import re
|
|
||||||
import Common.LongFilePathOs as os
|
import Common.LongFilePathOs as os
|
||||||
from Common.LongFilePathSupport import OpenLongFilePath as open
|
from Common.LongFilePathSupport import OpenLongFilePath as open
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ def GetRealFileLine (File, Line):
|
|||||||
if Profile.IsLineInFile(Line):
|
if Profile.IsLineInFile(Line):
|
||||||
return Profile.GetLineInFile(Line)
|
return Profile.GetLineInFile(Line)
|
||||||
elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:
|
elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:
|
||||||
InsertedLines += Profile.GetTotalLines()
|
InsertedLines += Profile.GetTotalLines()
|
||||||
|
|
||||||
return (File, Line - InsertedLines)
|
return (File, Line - InsertedLines)
|
||||||
|
|
||||||
@ -181,7 +180,7 @@ class IncludeFileProfile :
|
|||||||
TotalLines = self.InsertAdjust + len(self.FileLinesList)
|
TotalLines = self.InsertAdjust + len(self.FileLinesList)
|
||||||
|
|
||||||
for Profile in self.IncludeFileList:
|
for Profile in self.IncludeFileList:
|
||||||
TotalLines += Profile.GetTotalLines()
|
TotalLines += Profile.GetTotalLines()
|
||||||
|
|
||||||
return TotalLines
|
return TotalLines
|
||||||
|
|
||||||
@ -1398,6 +1397,20 @@ class FdfParser:
|
|||||||
% (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))
|
% (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
## SectionParser() method
|
||||||
|
#
|
||||||
|
# Parse the file section info
|
||||||
|
# Exception will be raised if syntax error found
|
||||||
|
#
|
||||||
|
# @param self The object pointer
|
||||||
|
# @param section The section string
|
||||||
|
|
||||||
|
def SectionParser(self, section):
|
||||||
|
S = section.upper()
|
||||||
|
if not S.startswith("[DEFINES") and not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \
|
||||||
|
and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM.") and not S.startswith('[FMPPAYLOAD.'):
|
||||||
|
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.], [FMPPAYLOAD.])", self.FileName, self.CurrentLineNumber)
|
||||||
|
|
||||||
## __GetDefines() method
|
## __GetDefines() method
|
||||||
#
|
#
|
||||||
# Get Defines section contents and store its data into AllMacrosList
|
# Get Defines section contents and store its data into AllMacrosList
|
||||||
@ -1413,9 +1426,7 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[DEFINES"):
|
if S.startswith("[") and not S.startswith("[DEFINES"):
|
||||||
if not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \
|
self.SectionParser(S)
|
||||||
and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
|
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -2108,9 +2119,7 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[FV."):
|
if S.startswith("[") and not S.startswith("[FV."):
|
||||||
if not S.startswith('[FMPPAYLOAD.') and not S.startswith("[CAPSULE.") \
|
self.SectionParser(S)
|
||||||
and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
|
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -3151,9 +3160,8 @@ class FdfParser:
|
|||||||
if not self.__GetNextToken():
|
if not self.__GetNextToken():
|
||||||
return False
|
return False
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if not S.startswith("[FMPPAYLOAD."):
|
if S.startswith("[") and not S.startswith("[FMPPAYLOAD."):
|
||||||
if not S.startswith("[CAPSULE.") and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
|
self.SectionParser(S)
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [FmpPayload.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -3223,8 +3231,7 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[CAPSULE."):
|
if S.startswith("[") and not S.startswith("[CAPSULE."):
|
||||||
if not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
|
self.SectionParser(S)
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -3394,18 +3401,19 @@ class FdfParser:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def __GetFmpStatement(self, CapsuleObj):
|
def __GetFmpStatement(self, CapsuleObj):
|
||||||
if not self.__IsKeyword("FMP"):
|
if not self.__IsKeyword("FMP_PAYLOAD"):
|
||||||
return False
|
if not self.__IsKeyword("FMP"):
|
||||||
|
return False
|
||||||
|
|
||||||
if not self.__IsKeyword("PAYLOAD"):
|
if not self.__IsKeyword("PAYLOAD"):
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not self.__IsToken("="):
|
if not self.__IsToken("="):
|
||||||
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
|
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
|
||||||
|
|
||||||
if not self.__GetNextToken():
|
if not self.__GetNextToken():
|
||||||
raise Warning("expected payload name after FMP PAYLOAD =", self.FileName, self.CurrentLineNumber)
|
raise Warning("expected payload name after FMP_PAYLOAD =", self.FileName, self.CurrentLineNumber)
|
||||||
Payload = self.__Token.upper()
|
Payload = self.__Token.upper()
|
||||||
if Payload not in self.Profile.FmpPayloadDict:
|
if Payload not in self.Profile.FmpPayloadDict:
|
||||||
raise Warning("This FMP Payload does not exist: %s" % self.__Token, self.FileName, self.CurrentLineNumber)
|
raise Warning("This FMP Payload does not exist: %s" % self.__Token, self.FileName, self.CurrentLineNumber)
|
||||||
@ -3507,8 +3515,7 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[RULE."):
|
if S.startswith("[") and not S.startswith("[RULE."):
|
||||||
if not S.startswith("[OPTIONROM."):
|
self.SectionParser(S)
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
@ -3586,7 +3593,7 @@ class FdfParser:
|
|||||||
#
|
#
|
||||||
def __GetFileExtension(self):
|
def __GetFileExtension(self):
|
||||||
if not self.__IsToken("."):
|
if not self.__IsToken("."):
|
||||||
raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)
|
raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)
|
||||||
|
|
||||||
Ext = ""
|
Ext = ""
|
||||||
if self.__GetNextToken():
|
if self.__GetNextToken():
|
||||||
@ -4084,8 +4091,7 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[VTF."):
|
if S.startswith("[") and not S.startswith("[VTF."):
|
||||||
if not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
|
self.SectionParser(S)
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -4291,7 +4297,9 @@ class FdfParser:
|
|||||||
|
|
||||||
S = self.__Token.upper()
|
S = self.__Token.upper()
|
||||||
if S.startswith("[") and not S.startswith("[OPTIONROM."):
|
if S.startswith("[") and not S.startswith("[OPTIONROM."):
|
||||||
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
|
self.SectionParser(S)
|
||||||
|
self.__UndoToken()
|
||||||
|
return False
|
||||||
|
|
||||||
self.__UndoToken()
|
self.__UndoToken()
|
||||||
if not self.__IsToken("[OptionRom.", True):
|
if not self.__IsToken("[OptionRom.", True):
|
||||||
|
Reference in New Issue
Block a user