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....@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong....@intel.com>
---
 BaseTools/Source/Python/GenFds/FdfParser.py | 60 ++++++++++++++++-------------
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py 
b/BaseTools/Source/Python/GenFds/FdfParser.py
index 28af09b..72fb3dc 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -53,11 +53,10 @@ from Common.Expression import *
 from Common import GlobalData
 from Common.String import ReplaceMacro
 
 from Common.Misc import tdict
 
-import re
 import Common.LongFilePathOs as os
 from Common.LongFilePathSupport import OpenLongFilePath as open
 
 ##define T_CHAR_SPACE                ' '
 ##define T_CHAR_NULL                 '\0'
@@ -104,11 +103,11 @@ def GetRealFileLine (File, Line):
     InsertedLines = 0
     for Profile in AllIncludeFileList:
         if Profile.IsLineInFile(Line):
             return Profile.GetLineInFile(Line)
         elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:
-           InsertedLines += Profile.GetTotalLines()
+            InsertedLines += Profile.GetTotalLines()
 
     return (File, Line - InsertedLines)
 
 ## The exception class that used to report error messages when parsing FDF
 #
@@ -179,11 +178,11 @@ class IncludeFileProfile :
     
     def GetTotalLines(self):
         TotalLines = self.InsertAdjust + len(self.FileLinesList)
 
         for Profile in self.IncludeFileList:
-          TotalLines += Profile.GetTotalLines()
+            TotalLines += Profile.GetTotalLines()
 
         return TotalLines
 
     def IsLineInFile(self, Line):
         if Line >= self.InsertStartLineNumber and Line < 
self.InsertStartLineNumber + self.GetTotalLines():
@@ -1396,10 +1395,24 @@ class FdfParser:
                 FileLineTuple = GetRealFileLine(self.FileName, 
self.CurrentLineNumber)
                 X.Message += ' near line %d, column %d: %s' \
                 % (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, 
self.Profile.FileLinesList[self.CurrentLineNumber - 
1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))
             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
     #
     #   Get Defines section contents and store its data into AllMacrosList
     #
     #   @param  self        The object pointer
@@ -1411,13 +1424,11 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         if S.startswith("[") and not S.startswith("[DEFINES"):
-            if 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."):
-                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.SectionParser(S)
             self.__UndoToken()
             return False
 
         self.__UndoToken()
         if not self.__IsToken("[DEFINES", True):
@@ -2106,13 +2117,11 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         if S.startswith("[") and not S.startswith("[FV."):
-            if not S.startswith('[FMPPAYLOAD.') and not 
S.startswith("[CAPSULE.") \
-                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.SectionParser(S)
             self.__UndoToken()
             return False
 
         self.__UndoToken()
         if not self.__IsToken("[FV.", True):
@@ -3149,13 +3158,12 @@ class FdfParser:
 
     def __GetFmp(self):
         if not self.__GetNextToken():
             return False
         S = self.__Token.upper()
-        if not S.startswith("[FMPPAYLOAD."):
-            if not S.startswith("[CAPSULE.") 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.], [FmpPayload.], [Capsule.], 
[VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)
+        if S.startswith("[") and not S.startswith("[FMPPAYLOAD."):
+            self.SectionParser(S)
             self.__UndoToken()
             return False
 
         self.__UndoToken()
         self.__SkipToToken("[FMPPAYLOAD.", True)
@@ -3221,12 +3229,11 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         if S.startswith("[") and not S.startswith("[CAPSULE."):
-            if 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.SectionParser(S)
             self.__UndoToken()
             return False
 
         self.__UndoToken()
         if not self.__IsToken("[CAPSULE.", True):
@@ -3392,22 +3399,23 @@ class FdfParser:
         CapsuleFd.FdName = self.__Token
         CapsuleObj.CapsuleDataList.append(CapsuleFd)
         return True
 
     def __GetFmpStatement(self, CapsuleObj):
-        if not self.__IsKeyword("FMP"):
-            return False
+        if not self.__IsKeyword("FMP_PAYLOAD"):
+            if not self.__IsKeyword("FMP"):
+                return False
 
-        if not self.__IsKeyword("PAYLOAD"):
-            self.__UndoToken()
-            return False
+            if not self.__IsKeyword("PAYLOAD"):
+                self.__UndoToken()
+                return False
 
         if not self.__IsToken("="):
             raise Warning("expected '='", self.FileName, 
self.CurrentLineNumber)
 
         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()
         if Payload not in self.Profile.FmpPayloadDict:
             raise Warning("This FMP Payload does not exist: %s" % 
self.__Token, self.FileName, self.CurrentLineNumber)
         CapsuleObj.FmpPayloadList.append(self.Profile.FmpPayloadDict[Payload])
         return True
@@ -3505,12 +3513,11 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         if S.startswith("[") and not S.startswith("[RULE."):
-            if 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()
         if not self.__IsToken("[Rule.", True):
             FileLineTuple = GetRealFileLine(self.FileName, 
self.CurrentLineNumber)
@@ -3584,11 +3591,11 @@ class FdfParser:
     #   @param  self        The object pointer
     #   @retval string      file name extension
     #
     def __GetFileExtension(self):
         if not self.__IsToken("."):
-                raise Warning("expected '.'", self.FileName, 
self.CurrentLineNumber)
+            raise Warning("expected '.'", self.FileName, 
self.CurrentLineNumber)
 
         Ext = ""
         if self.__GetNextToken():
             Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')
             if Pattern.match(self.__Token):
@@ -4082,12 +4089,11 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         if S.startswith("[") and not S.startswith("[VTF."):
-            if 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.SectionParser(S)
             self.__UndoToken()
             return False
 
         self.__UndoToken()
         if not self.__IsToken("[VTF.", True):
@@ -4289,11 +4295,13 @@ class FdfParser:
         if not self.__GetNextToken():
             return False
 
         S = self.__Token.upper()
         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()
         if not self.__IsToken("[OptionRom.", True):
             raise Warning("Unknown Keyword '%s'" % self.__Token, 
self.FileName, self.CurrentLineNumber)
 
-- 
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to