]> 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 788190567eef4366310fe8d502eb3cf0853db8f3..72fb3dc56e22bab0107195945b0844ad69a13c62 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # parse FDF file\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #  Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r
 #\r
 #  This program and the accompanying materials\r
@@ -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
@@ -2692,6 +2701,11 @@ class FdfParser:
         elif self.__Token in ("DEFINE", "APRIORI", "SECTION"):\r
             self.__UndoToken()\r
             self.__GetSectionData( FfsFileObj, MacroDict)\r
+\r
+        elif hasattr(FfsFileObj, 'FvFileType') and FfsFileObj.FvFileType == 'RAW':\r
+            self.__UndoToken()\r
+            self.__GetRAWData(FfsFileObj, MacroDict)\r
+\r
         else:\r
             FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
             FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
@@ -2701,6 +2715,45 @@ class FdfParser:
         if not self.__IsToken( "}"):\r
             raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
 \r
+    ## __GetRAWData() method\r
+    #\r
+    #   Get RAW data for FILE statement\r
+    #\r
+    #   @param  self         The object pointer\r
+    #   @param  FfsFileObj   for whom section is got\r
+    #   @param  MacroDict    dictionary used to replace macro\r
+    #\r
+    def __GetRAWData(self, FfsFileObj, MacroDict = {}):\r
+        FfsFileObj.FileName = []\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 = self.__Token\r
+            if not self.__GetNextToken():\r
+                raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+\r
+            FileName = self.__Token.replace('$(SPACE)', ' ')\r
+            if FileName == '}':\r
+                self.__UndoToken()\r
+                raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
+\r
+            self.__VerifyFile(FileName)\r
+            File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
+            FfsFileObj.FileName.append(File.Path)\r
+            FfsFileObj.SubAlignment.append(AlignValue)\r
+\r
+            if self.__IsToken( "}"):\r
+                self.__UndoToken()\r
+                break\r
+\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
     ## __GetFileOpts() method\r
     #\r
     #   Get options for FILE statement\r
@@ -3107,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
@@ -3179,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
@@ -3350,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
@@ -3463,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
@@ -3542,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
@@ -4040,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
@@ -4247,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