]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FdfParser.py
ShellPkg: Add NULL pointer check.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index b86c196067251ac31669158f60060c47d8363389..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
@@ -2716,14 +2725,13 @@ class FdfParser:
     #\r
     def __GetRAWData(self, FfsFileObj, MacroDict = {}):\r
         FfsFileObj.FileName = []\r
-        FfsFileObj.Alignment = []\r
-        AlignDict = {"Auto":1, "8":8, "16":16, "32":32, "64":64, "128":128, "512":512, "1K":1024, "4K":4096, "32K":32768, "64K":65536}\r
+        FfsFileObj.SubAlignment = []\r
         while True:\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
                     raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
-                AlignValue = AlignValue = AlignDict[self.__Token]\r
+                AlignValue = self.__Token\r
             if not self.__GetNextToken():\r
                 raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
 \r
@@ -2731,20 +2739,18 @@ class FdfParser:
             if FileName == '}':\r
                 self.__UndoToken()\r
                 raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
-            elif not os.path.isfile(FileName):\r
-                raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
 \r
             self.__VerifyFile(FileName)\r
             File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
             FfsFileObj.FileName.append(File.Path)\r
-            FfsFileObj.Alignment.append(AlignValue)\r
+            FfsFileObj.SubAlignment.append(AlignValue)\r
 \r
             if self.__IsToken( "}"):\r
                 self.__UndoToken()\r
                 break\r
 \r
-        if len(FfsFileObj.Alignment) == 1:\r
-            FfsFileObj.Alignment = FfsFileObj.Alignment[0]\r
+        if len(FfsFileObj.SubAlignment) == 1:\r
+            FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0]\r
         if len(FfsFileObj.FileName) == 1:\r
             FfsFileObj.FileName = FfsFileObj.FileName[0]\r
 \r
@@ -3154,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
@@ -3226,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
@@ -3397,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
@@ -3510,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
@@ -3589,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
@@ -4087,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
@@ -4294,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