]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Eot/Parser.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / Eot / Parser.py
index 9ef71a958769dc17050bb2b7c8faac8ff016772f..f204051d01f763af94ec0f694197d8595211bcc8 100644 (file)
@@ -2,26 +2,48 @@
 # This file is used to define common parsing related functions used in parsing\r
 # Inf/Dsc/Makefile process\r
 #\r
-# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\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
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
 # Import Modules\r
 #\r
-import os, re\r
+from __future__ import absolute_import\r
+import Common.LongFilePathOs as os, re\r
 import Common.EdkLogger as EdkLogger\r
 from Common.DataType import *\r
 from CommonDataClass.DataClass import *\r
-from Common.String import CleanString, GetSplitValueList, ReplaceMacro\r
-import EotGlobalData\r
-from Common.Misc import sdict\r
+from Common.StringUtils import CleanString, GetSplitValueList, ReplaceMacro\r
+from . import EotGlobalData\r
+from Common.StringUtils import GetSplitList\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
+\r
+import subprocess\r
+\r
+## DeCompress\r
+#\r
+# Call external decompress tool to decompress the fv section\r
+#\r
+def DeCompress(Method, Input):\r
+    # Write the input to a temp file\r
+    open('_Temp.bin', 'wb').write(Input)\r
+    cmd = ''\r
+    if Method == 'Lzma':\r
+        cmd = r'LzmaCompress -o _New.bin -d _Temp.bin'\r
+    if Method == 'Efi':\r
+        cmd = r'TianoCompress -d --uefi -o _New.bin _Temp.bin'\r
+    if Method == 'Framework':\r
+        cmd = r'TianoCompress -d -o _New.bin _Temp.bin'\r
+\r
+    # Call tool to create the decompressed output file\r
+    Process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\r
+    Process.communicate()[0]\r
+\r
+    # Return the beffer of New.bin\r
+    if os.path.exists('_New.bin'):\r
+        return open('_New.bin', 'rb').read()\r
+\r
 \r
 ## PreProcess() method\r
 #\r
@@ -34,7 +56,7 @@ from Common.Misc import sdict
 #  @param  MergeMultipleLines: Switch for if merge multiple lines\r
 #  @param  LineNo: Default line no\r
 #\r
-#  @return Lines: The file contents after remvoing comments\r
+#  @return Lines: The file contents after removing comments\r
 #\r
 def PreProcess(Filename, MergeMultipleLines = True, LineNo = -1):\r
     Lines = []\r
@@ -49,11 +71,11 @@ def PreProcess(Filename, MergeMultipleLines = True, LineNo = -1):
     for Line in open(Filename, 'r'):\r
         Line = Line.strip()\r
         # Remove comment block\r
-        if Line.find(TAB_COMMENT_R8_START) > -1:\r
-            ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0]\r
+        if Line.find(TAB_COMMENT_EDK_START) > -1:\r
+            ReservedLine = GetSplitList(Line, TAB_COMMENT_EDK_START, 1)[0]\r
             IsFindBlockComment = True\r
-        if Line.find(TAB_COMMENT_R8_END) > -1:\r
-            Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1]\r
+        if Line.find(TAB_COMMENT_EDK_END) > -1:\r
+            Line = ReservedLine + GetSplitList(Line, TAB_COMMENT_EDK_END, 1)[1]\r
             ReservedLine = ''\r
             IsFindBlockComment = False\r
         if IsFindBlockComment:\r
@@ -621,7 +643,7 @@ def SearchProtocols(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMod
 #  @param ItemMode: Mode of item\r
 #\r
 def SearchFunctionCalling(Table, SourceFileID, SourceFileFullPath, ItemType, ItemMode):\r
-    LibraryList = sdict()\r
+    LibraryList = {}\r
     Db = EotGlobalData.gDb.TblReport\r
     Parameters, ItemName, GuidName, GuidMacro, GuidValue, BelongsToFunction = [], '', '', '', '', ''\r
     if ItemType == 'Protocol' and ItemMode == 'Produced':\r
@@ -729,7 +751,7 @@ def GetParameter(Parameter, Index = 1):
 #  @return: The name of parameter\r
 #\r
 def GetParameterName(Parameter):\r
-    if type(Parameter) == type('') and Parameter.startswith('&'):\r
+    if isinstance(Parameter, type('')) and Parameter.startswith('&'):\r
         return Parameter[1:].replace('{', '').replace('}', '').replace('\r', '').replace('\n', '').strip()\r
     else:\r
         return Parameter.strip()\r
@@ -742,7 +764,7 @@ def GetParameterName(Parameter):
 #  @param Table: Table to be searched\r
 #  @param Key: The keyword\r
 #\r
-#  @return Value: The value of the the keyword\r
+#  @return Value: The value of the keyword\r
 #\r
 def FindKeyValue(Db, Table, Key):\r
     SqlCommand = """select Value from %s where Name = '%s' and (Model = %s or Model = %s)""" % (Table, Key, MODEL_IDENTIFIER_VARIABLE, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)\r