]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Update FMP Capsule support to follow FDF spec
authorYonghong Zhu <yonghong.zhu@intel.com>
Thu, 21 Apr 2016 06:50:30 +0000 (14:50 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 27 Apr 2016 01:39:15 +0000 (09:39 +0800)
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>
BaseTools/Source/Python/GenFds/FdfParser.py

index 28af09b982005c419738912a702c933774b88576..72fb3dc56e22bab0107195945b0844ad69a13c62 100644 (file)
@@ -55,7 +55,6 @@ from Common.String import ReplaceMacro
 \r
 from Common.Misc import tdict\r
 \r
-import re\r
 import Common.LongFilePathOs as os\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
@@ -106,7 +105,7 @@ def GetRealFileLine (File, Line):
         if Profile.IsLineInFile(Line):\r
             return Profile.GetLineInFile(Line)\r
         elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:\r
-           InsertedLines += Profile.GetTotalLines()\r
+            InsertedLines += Profile.GetTotalLines()\r
 \r
     return (File, Line - InsertedLines)\r
 \r
@@ -181,7 +180,7 @@ class IncludeFileProfile :
         TotalLines = self.InsertAdjust + len(self.FileLinesList)\r
 \r
         for Profile in self.IncludeFileList:\r
-          TotalLines += Profile.GetTotalLines()\r
+            TotalLines += Profile.GetTotalLines()\r
 \r
         return TotalLines\r
 \r
@@ -1398,6 +1397,20 @@ class FdfParser:
                 % (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))\r
             raise\r
 \r
+    ## SectionParser() method\r
+    #\r
+    #   Parse the file section info\r
+    #   Exception will be raised if syntax error found\r
+    #\r
+    #   @param  self          The object pointer\r
+    #   @param  section       The section string\r
+\r
+    def SectionParser(self, section):\r
+        S = section.upper()\r
+        if not S.startswith("[DEFINES") and not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
+            and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM.") and not S.startswith('[FMPPAYLOAD.'):\r
+            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)\r
+\r
     ## __GetDefines() method\r
     #\r
     #   Get Defines section contents and store its data into AllMacrosList\r
@@ -1413,9 +1426,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[DEFINES"):\r
-            if not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
-                and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
-                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)\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -2108,9 +2119,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[FV."):\r
-            if not S.startswith('[FMPPAYLOAD.') and not S.startswith("[CAPSULE.") \\r
-                and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
-                raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -3151,9 +3160,8 @@ class FdfParser:
         if not self.__GetNextToken():\r
             return False\r
         S = self.__Token.upper()\r
-        if not S.startswith("[FMPPAYLOAD."):\r
-            if not S.startswith("[CAPSULE.") and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
-                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)\r
+        if S.startswith("[") and not S.startswith("[FMPPAYLOAD."):\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -3223,8 +3231,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[CAPSULE."):\r
-            if not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
-                raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -3394,18 +3401,19 @@ class FdfParser:
         return True\r
 \r
     def __GetFmpStatement(self, CapsuleObj):\r
-        if not self.__IsKeyword("FMP"):\r
-            return False\r
+        if not self.__IsKeyword("FMP_PAYLOAD"):\r
+            if not self.__IsKeyword("FMP"):\r
+                return False\r
 \r
-        if not self.__IsKeyword("PAYLOAD"):\r
-            self.__UndoToken()\r
-            return False\r
+            if not self.__IsKeyword("PAYLOAD"):\r
+                self.__UndoToken()\r
+                return False\r
 \r
         if not self.__IsToken("="):\r
             raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
 \r
         if not self.__GetNextToken():\r
-            raise Warning("expected payload name after FMP PAYLOAD =", self.FileName, self.CurrentLineNumber)\r
+            raise Warning("expected payload name after FMP_PAYLOAD =", self.FileName, self.CurrentLineNumber)\r
         Payload = self.__Token.upper()\r
         if Payload not in self.Profile.FmpPayloadDict:\r
             raise Warning("This FMP Payload does not exist: %s" % self.__Token, self.FileName, self.CurrentLineNumber)\r
@@ -3507,8 +3515,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[RULE."):\r
-            if not S.startswith("[OPTIONROM."):\r
-                raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
         self.__UndoToken()\r
@@ -3586,7 +3593,7 @@ class FdfParser:
     #\r
     def __GetFileExtension(self):\r
         if not self.__IsToken("."):\r
-                raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)\r
+            raise Warning("expected '.'", self.FileName, self.CurrentLineNumber)\r
 \r
         Ext = ""\r
         if self.__GetNextToken():\r
@@ -4084,8 +4091,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[VTF."):\r
-            if not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
-                raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+            self.SectionParser(S)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -4291,7 +4297,9 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[OPTIONROM."):\r
-            raise Warning("Unknown section or section appear sequence error (The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.])", self.FileName, self.CurrentLineNumber)\r
+            self.SectionParser(S)\r
+            self.__UndoToken()\r
+            return False\r
         \r
         self.__UndoToken()\r
         if not self.__IsToken("[OptionRom.", True):\r