]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools:Make BaseTools support new rules to generate RAW FFS FILE
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index 3bcfd2d42a46a51036680160fb8fb2261eb8377f..fb5fd85e0a825ebf3341e2ca706af9b0b37b57c3 100644 (file)
@@ -4,13 +4,7 @@
 #  Copyright (c) 2007 - 2018, 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
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution.  The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
@@ -159,7 +153,7 @@ class IncludeFileProfile:
         self.FileName = FileName\r
         self.FileLinesList = []\r
         try:\r
-            with open(FileName, "rb", 0) as fsock:\r
+            with open(FileName, "r") as fsock:\r
                 self.FileLinesList = fsock.readlines()\r
                 for index, line in enumerate(self.FileLinesList):\r
                     if not line.endswith(TAB_LINE_BREAK):\r
@@ -213,7 +207,7 @@ class FileProfile:
     def __init__(self, FileName):\r
         self.FileLinesList = []\r
         try:\r
-            with open(FileName, "rb", 0) as fsock:\r
+            with open(FileName, "r") as fsock:\r
                 self.FileLinesList = fsock.readlines()\r
 \r
         except:\r
@@ -716,13 +710,13 @@ class FdfParser:
                     EndPos = CurLine.find(')', StartPos+2)\r
                     while StartPos != -1 and EndPos != -1 and self._Token not in {TAB_IF_DEF, TAB_IF_N_DEF, TAB_IF, TAB_ELSE_IF}:\r
                         MacroName = CurLine[StartPos+2: EndPos]\r
-                        MacorValue = self._GetMacroValue(MacroName)\r
-                        if MacorValue is not None:\r
-                            CurLine = CurLine.replace('$(' + MacroName + ')', MacorValue, 1)\r
-                            if MacorValue.find('$(') != -1:\r
+                        MacroValue = self._GetMacroValue(MacroName)\r
+                        if MacroValue is not None:\r
+                            CurLine = CurLine.replace('$(' + MacroName + ')', MacroValue, 1)\r
+                            if MacroValue.find('$(') != -1:\r
                                 PreIndex = StartPos\r
                             else:\r
-                                PreIndex = StartPos + len(MacorValue)\r
+                                PreIndex = StartPos + len(MacroValue)\r
                         else:\r
                             PreIndex = EndPos + 1\r
                         StartPos = CurLine.find('$(', PreIndex)\r
@@ -1037,7 +1031,7 @@ class FdfParser:
 \r
     ## _GetNextToken() method\r
     #\r
-    #   Get next token unit before a seperator\r
+    #   Get next token unit before a separator\r
     #   If found, the string value is put into self._Token\r
     #\r
     #   @param  self        The object pointer\r
@@ -1054,12 +1048,12 @@ class FdfParser:
         StartLine = self.CurrentLineNumber\r
         while StartLine == self.CurrentLineNumber:\r
             TempChar = self._CurrentChar()\r
-            # Try to find the end char that is not a space and not in seperator tuple.\r
+            # Try to find the end char that is not a space and not in separator tuple.\r
             # That is, when we got a space or any char in the tuple, we got the end of token.\r
             if not str(TempChar).isspace() and TempChar not in SEPARATORS:\r
                 self._GetOneChar()\r
-            # if we happen to meet a seperator as the first char, we must proceed to get it.\r
-            # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
+            # if we happen to meet a separator as the first char, we must proceed to get it.\r
+            # That is, we get a token that is a separator char. normally it is the boundary of other tokens.\r
             elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPARATORS:\r
                 self._GetOneChar()\r
                 break\r
@@ -1081,7 +1075,7 @@ class FdfParser:
 \r
     ## _GetNextGuid() method\r
     #\r
-    #   Get next token unit before a seperator\r
+    #   Get next token unit before a separator\r
     #   If found, the GUID string is put into self._Token\r
     #\r
     #   @param  self        The object pointer\r
@@ -1133,13 +1127,13 @@ class FdfParser:
         while CurrentLine == self.CurrentLineNumber:\r
 \r
             TempChar = self._CurrentChar()\r
-            # Try to find the end char that is not a space and not in seperator tuple.\r
+            # Try to find the end char that is not a space and not in separator tuple.\r
             # That is, when we got a space or any char in the tuple, we got the end of token.\r
             if not str(TempChar).isspace() and not TempChar in SEPARATORS:\r
                 if not self._UndoOneChar():\r
                     return\r
-            # if we happen to meet a seperator as the first char, we must proceed to get it.\r
-            # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
+            # if we happen to meet a separator as the first char, we must proceed to get it.\r
+            # That is, we get a token that is a separator char. normally it is the boundary of other tokens.\r
             elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPARATORS:\r
                 return\r
             else:\r
@@ -1149,7 +1143,7 @@ class FdfParser:
 \r
     ## _GetNextHexNumber() method\r
     #\r
-    #   Get next HEX data before a seperator\r
+    #   Get next HEX data before a separator\r
     #   If found, the HEX data is put into self._Token\r
     #\r
     #   @param  self        The object pointer\r
@@ -1167,7 +1161,7 @@ class FdfParser:
 \r
     ## _GetNextDecimalNumber() method\r
     #\r
-    #   Get next decimal data before a seperator\r
+    #   Get next decimal data before a separator\r
     #   If found, the decimal data is put into self._Token\r
     #\r
     #   @param  self        The object pointer\r
@@ -1562,7 +1556,7 @@ class FdfParser:
                 self.SetPcdLocalation(pcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
-            Obj.Size = long(Size, 0)\r
+            Obj.Size = int(Size, 0)\r
             return True\r
 \r
         if self._IsKeyword("ErasePolarity"):\r
@@ -1597,7 +1591,7 @@ class FdfParser:
             if not self._GetNextDecimalNumber() and not self._GetNextHexNumber():\r
                 raise Warning.Expected("address", self.FileName, self.CurrentLineNumber)\r
 \r
-            BsAddress = long(self._Token, 0)\r
+            BsAddress = int(self._Token, 0)\r
             Obj.BsBaseAddress = BsAddress\r
 \r
         if self._IsKeyword("RtBaseAddress"):\r
@@ -1607,7 +1601,7 @@ class FdfParser:
             if not self._GetNextDecimalNumber() and not self._GetNextHexNumber():\r
                 raise Warning.Expected("address", self.FileName, self.CurrentLineNumber)\r
 \r
-            RtAddress = long(self._Token, 0)\r
+            RtAddress = int(self._Token, 0)\r
             Obj.RtBaseAddress = RtAddress\r
 \r
     ## _GetBlockStatements() method\r
@@ -1655,7 +1649,7 @@ class FdfParser:
             self.SetPcdLocalation(PcdPair)\r
             FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
-        BlockSize = long(BlockSize, 0)\r
+        BlockSize = int(BlockSize, 0)\r
 \r
         BlockNumber = None\r
         if self._IsKeyword("NumBlocks"):\r
@@ -1665,7 +1659,7 @@ class FdfParser:
             if not self._GetNextDecimalNumber() and not self._GetNextHexNumber():\r
                 raise Warning.Expected("block numbers", self.FileName, self.CurrentLineNumber)\r
 \r
-            BlockNumber = long(self._Token, 0)\r
+            BlockNumber = int(self._Token, 0)\r
 \r
         Obj.BlockSizeList.append((BlockSize, BlockNumber, BlockSizePcd))\r
         return True\r
@@ -1774,7 +1768,7 @@ class FdfParser:
             Expr += CurCh\r
             self._GetOneChar()\r
         try:\r
-            return long(\r
+            return int(\r
                 ValueExpression(Expr,\r
                                 self._CollectMacroPcd()\r
                                 )(True), 0)\r
@@ -1822,7 +1816,7 @@ class FdfParser:
                            RegionOffsetPcdPattern.match(self._CurrentLine()[self.CurrentOffsetWithinLine:]))\r
             if IsRegionPcd:\r
                 RegionObj.PcdOffset = self._GetNextPcdSettings()\r
-                self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + long(theFd.BaseAddress, 0))\r
+                self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + int(theFd.BaseAddress, 0))\r
                 self.SetPcdLocalation(RegionObj.PcdOffset)\r
                 self._PcdDict['%s.%s' % (RegionObj.PcdOffset[1], RegionObj.PcdOffset[0])] = "0x%x" % RegionObj.Offset\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
@@ -3134,9 +3128,9 @@ class FdfParser:
                     if FdfParser._Verify(Name, Value, 'UINT64'):\r
                         FmpData.MonotonicCount = Value\r
                         if FmpData.MonotonicCount.upper().startswith('0X'):\r
-                            FmpData.MonotonicCount = (long)(FmpData.MonotonicCount, 16)\r
+                            FmpData.MonotonicCount = int(FmpData.MonotonicCount, 16)\r
                         else:\r
-                            FmpData.MonotonicCount = (long)(FmpData.MonotonicCount)\r
+                            FmpData.MonotonicCount = int(FmpData.MonotonicCount)\r
             if not self._GetNextToken():\r
                 break\r
         else:\r
@@ -3611,7 +3605,12 @@ class FdfParser:
 \r
         if not self._IsKeyword("$(NAMED_GUID)"):\r
             if not self._GetNextWord():\r
-                raise Warning.Expected("$(NAMED_GUID)", self.FileName, self.CurrentLineNumber)\r
+                NamedGuid = self._CurrentLine()[self.CurrentOffsetWithinLine:].split()[0].strip()\r
+                if GlobalData.gGuidPatternEnd.match(NamedGuid):\r
+                    self.CurrentOffsetWithinLine += len(NamedGuid)\r
+                    self._Token = NamedGuid\r
+                else:\r
+                    raise Warning.Expected("$(NAMED_GUID)", self.FileName, self.CurrentLineNumber)\r
             if self._Token == 'PCD':\r
                 if not self._IsToken("("):\r
                     raise Warning.Expected("'('", self.FileName, self.CurrentLineNumber)\r
@@ -3750,8 +3749,19 @@ class FdfParser:
     #\r
     def _GetEfiSection(self, Obj):\r
         OldPos = self.GetFileBufferPos()\r
+        EfiSectionObj = EfiSection()\r
         if not self._GetNextWord():\r
-            return False\r
+            CurrentLine = self._CurrentLine()[self.CurrentOffsetWithinLine:].split()[0].strip()\r
+            if self._Token == '{' and Obj.FvFileType == "RAW" and TAB_SPLIT in CurrentLine:\r
+                if self._IsToken(TAB_VALUE_SPLIT):\r
+                    EfiSectionObj.FileExtension = self._GetFileExtension()\r
+                elif self._GetNextToken():\r
+                    EfiSectionObj.FileName = self._Token\r
+                EfiSectionObj.SectionType = BINARY_FILE_TYPE_RAW\r
+                Obj.SectionList.append(EfiSectionObj)\r
+                return True\r
+            else:\r
+                return False\r
         SectionName = self._Token\r
 \r
         if SectionName not in {\r
@@ -3817,7 +3827,6 @@ class FdfParser:
             Obj.SectionList.append(FvImageSectionObj)\r
             return True\r
 \r
-        EfiSectionObj = EfiSection()\r
         EfiSectionObj.SectionType = SectionName\r
 \r
         if not self._GetNextToken():\r