]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Eot/Parser.py
BaseTools/Ecc/EOT: Add Python 3 support on ECC and EOT tools.
[mirror_edk2.git] / BaseTools / Source / Python / Eot / Parser.py
index e01a9770befbc7d3340d79c41e153b67571184ae..04afa8f2b8f47268b11132535b3c179ea605a7a2 100644 (file)
@@ -2,7 +2,7 @@
 # This file is used to define common parsing related functions used in parsing\r
 # Inf/Dsc/Makefile process\r
 #\r
-# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, 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
@@ -25,6 +25,32 @@ from . import EotGlobalData
 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
 #  Pre process a file\r