[edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for Python 3.x

Nate DeSimone posted 1 patch 5 months ago
Failed in applying to current master (apply log)
.../MinPlatformPkg/Tools/PatchFv/PatchBfv.py  | 35 ++++----
.../Tools/PatchFv/PatchBinFv.py               | 69 ++++++++--------
.../Tools/PatchFv/RebaseBinFv.py              | 82 +++++++++----------
3 files changed, 92 insertions(+), 94 deletions(-)
[edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for Python 3.x
Posted by Nate DeSimone 5 months ago
PatchFv tools now run on Python 3.x

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../MinPlatformPkg/Tools/PatchFv/PatchBfv.py  | 35 ++++----
 .../Tools/PatchFv/PatchBinFv.py               | 69 ++++++++--------
 .../Tools/PatchFv/RebaseBinFv.py              | 82 +++++++++----------
 3 files changed, 92 insertions(+), 94 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
index 1312bfc328..f05480b91f 100644
--- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
+++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
@@ -1,6 +1,6 @@
 ## @ PatchBfv.py
 #
-# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -11,8 +11,7 @@ import sys
 import time
 import shutil
 import struct
-import binascii
-from   ctypes import *
+from ctypes import *
 
 class FileChecker:
     def __init__(self):
@@ -21,17 +20,17 @@ class FileChecker:
         self.pcd = ["", "", ""]
 
     def PrintPcd(self):
-        print "PCD: " + self.pcd[0] + "|" + self.pcd[1] + "(" + self.pcd[2] + ")"
+        print("PCD: {0}|{1}({2})".format(*(self.pcd)))
 
     def ProcessReport(self):
         try :
             file = open(self.reportFile)
         except Exception:
-            print "fail to open " + self.reportFile
+            print("fail to open " + self.reportFile)
             return
         try:
             file.seek(0)
-            print "checking - " + self.pcd[0]
+            print("checking - " + self.pcd[0])
             ValuePair = self.GetPcdFromReport (file, self.pcd[0])
             self.pcd[1] = ValuePair[0]
             self.pcd[2] = ValuePair[1]
@@ -42,12 +41,12 @@ class FileChecker:
 
     def PatchFd(self):
         fileName = self.fdName
-        print "patching BFV - " + fileName
+        print("patching BFV - " + fileName)
 
         try :
             file = open(fileName, "rb")
         except Exception:
-            print "fail to open " + fileName
+            print("fail to open " + fileName)
             return
         try:
             buffer = file.read()
@@ -57,7 +56,7 @@ class FileChecker:
             offset = -4
 
             l = struct.pack("L", int(self.pcd[1],16))
-            print "  [" + hex(offset) + "] " + binascii.hexlify(data[-4:]) + " <= " + binascii.hexlify(l)
+            print("  [" + hex(offset) + "] " + bytes(data[-4:]).hex() + " <= " + bytes(l).hex())
             data[-4:] = l
 
             file = open(fileName, "wb")
@@ -77,36 +76,36 @@ class FileChecker:
 
             newline = line[:-1]
 
-            if (cmp (newline, TargetPkg) == 0):
+            if newline == TargetPkg:
                 FoundPkg = True
                 continue
 
-            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp (newline[0], "0") != 0)):
+            if newline == "" or (newline[0] != " " and newline[0] != "0"):
                 FoundPkg = False
 
             if (FoundPkg == True) :
                 newline = newline.strip()
                 splitLine = newline.split(" ", 2)
-                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0) :
-                    if (cmp (splitLine[1], TargetPcd) == 0):
-                        print "found - " + TargetPkg + "." + TargetPcd
+                if splitLine[0] == "*F" or splitLine[0] == "*P":
+                    if splitLine[1] == TargetPcd:
+                        print("found - " + TargetPkg + "." + TargetPcd)
 
                         splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
-                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH") == 0):
+                        if splitLine[0] == "FIXED" or splitLine[0] == "PATCH":
                             SplitLine = splitLine[1].strip()[1:].split(")", 1)
                             Type = SplitLine[0]
                             Value = SplitLine[1].strip()[1:].strip().split()[0]
-                            print "  Type - (" + Type + "), Value - (" + Value + ")"
+                            print("  Type - (" + Type + "), Value - (" + Value + ")")
                             return [Value, Type]
         return ["", ""]
-            
+
 def main():
     global FileChecker
 
     fileChecker = FileChecker()
 
     if (len(sys.argv) != 4) :
-        print "usage: PatchBfv <FdFile> <ReportFile> <BfvPcdName>"
+        print("usage: PatchBfv <FdFile> <ReportFile> <BfvPcdName>")
         return 0
 
     fileChecker.fdName = sys.argv[1]
diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
index b98c951b45..78576a3029 100644
--- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
+++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
@@ -1,6 +1,6 @@
 ## @ PatchBinFv.py
 #
-# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -11,7 +11,6 @@ import sys
 import time
 import shutil
 import struct
-import binascii
 from   ctypes import *
 
 class FileChecker:
@@ -30,20 +29,20 @@ class FileChecker:
     def IsSyncSection(self, line):
         name = self.GetSectionName(line)
         for sectionName in self.SyncSectionList:
-            if (cmp (sectionName, name) == 0) :
+            if sectionName == name:
                 return True
         return False
 
     def PrintPcdList(self, pcdList):
         for pcd in pcdList:
-            print "PCD: " + pcd[0] + "|" + pcd[1] + "|" + pcd[2] + " <== " + pcd[3] + "(" + pcd[4] + ")"
+            print(("PCD: {0} | {1} | {2} <== {3}({4})".format(*pcd)))
 
     def GetInfFileGuid(self, fileName):
         guid = ""
         try :
             file = open(fileName)
         except Exception:
-            print "fail to open " + fileName
+            print("fail to open " + fileName)
             return
         try:
             while 1:
@@ -53,7 +52,7 @@ class FileChecker:
 
                 newline = line[:-1]
 
-                if cmp (line[:11], "  FILE_GUID") == 0:
+                if line[:11] == "  FILE_GUID":
                     splitLine = line.split("=")
                     templine = splitLine[1]
                     guid = templine[1:1+36]
@@ -66,7 +65,7 @@ class FileChecker:
         try :
             file = open(fileName)
         except Exception:
-            print "fail to open " + fileName
+            print("fail to open " + fileName)
             return
         try:
             while 1:
@@ -76,23 +75,23 @@ class FileChecker:
 
                 newline = line[:-1]
 
-                if cmp (line[0], "#") == 0:
+                if line[0] == "#":
                     continue
 
 
-                if cmp (line[0], "[") == 0:
+                if line[0] == "[":
                     SyncToDest = self.IsSyncSection(line)
                     PatchOffset = False
 
-                if (cmp (self.GetSectionName(line), "PatchPcd") == 0) :
+                if (self.GetSectionName(line) == "PatchPcd"):
                     PatchOffset = True
                     continue
 
                 if SyncToDest == True :
                     line = line.strip()
-                    if (cmp (line, "") == 0) :
+                    if line == "":
                         continue
-                    if (cmp (line[0], "#") == 0) :
+                    if line[0] == "#":
                         continue
 
                     splitLine = line.split(" ")
@@ -108,9 +107,9 @@ class FileChecker:
 
     def ProcessFvInf(self, fvName):
         sourceFileName = os.path.join(self.sourceRoot,fvName,self.target,fvName+".inf")
-        print "\nprocessing - " + sourceFileName
+        print("\nprocessing - " + sourceFileName)
         fileGuid = self.GetInfFileGuid (sourceFileName)
-        print "FV NAME GUID - " + fileGuid
+        print("FV NAME GUID - " + fileGuid)
 
         self.InfPcdList = []
         self.ParseInfFile(sourceFileName)
@@ -122,12 +121,12 @@ class FileChecker:
         try :
             file = open(self.reportFile)
         except Exception:
-            print "fail to open " + self.reportFile
+            print("fail to open " + self.reportFile)
             return
         try:
             for pcd in self.InfPcdList:
                 file.seek(0)
-                print "checking - " + pcd[0]
+                print("checking - " + pcd[0])
                 ValuePair = self.GetPcdFromReport (file, pcd[0])
                 pcd[3] = ValuePair[0]
                 pcd[4] = ValuePair[1]
@@ -138,12 +137,12 @@ class FileChecker:
 
     def PatchFv(self, fvName):
         sourceFileName = os.path.join(self.sourceRoot,fvName,self.target,fvName+".Fv")
-        print "patching - " + sourceFileName
+        print("patching - " + sourceFileName)
 
         try :
             file = open(sourceFileName, "rb")
         except Exception:
-            print "fail to open " + sourceFileName
+            print("fail to open " + sourceFileName)
             return
         try:
             buffer = file.read()
@@ -152,21 +151,21 @@ class FileChecker:
 
             for pcd in self.InfPcdList:
                 offset = int(pcd[2], 16)
-                if (cmp (pcd[4], "BOOLEAN") == 0) or (cmp (pcd[4], "UINT8") == 0):
+                if (pcd[4] == "BOOLEAN") or (pcd[4] == "UINT8"):
                     b = struct.pack("B", int(pcd[3],16))
-                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+1]) + " <= " + binascii.hexlify(b)
+                    print("  [" + hex(offset) + "] " + bytes(data[offset:offset+1]).hex() + " <= " + bytes(b).hex())
                     data[offset:offset+1] = b
-                elif (cmp (pcd[4], "UINT16") == 0):
+                elif (pcd[4] == "UINT16"):
                     h = struct.pack("H", int(pcd[3],16))
-                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+2]) + " <= " + binascii.hexlify(h)
+                    print("  [" + hex(offset) + "] " + bytes(data[offset:offset+2]).hex() + " <= " + bytes(h).hex())
                     data[offset:offset+2] = h
-                elif (cmp (pcd[4], "UINT32") == 0):
+                elif (pcd[4] == "UINT32"):
                     l = struct.pack("I", int(pcd[3],16))
-                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+4]) + " <= " + binascii.hexlify(l)
+                    print("  [" + hex(offset) + "] " + bytes(data[offset:offset+4]).hex() + " <= " + bytes(l).hex())
                     data[offset:offset+4] = l
-                elif (cmp (pcd[4], "UINT64") == 0):
+                elif (pcd[4] == "UINT64"):
                     q = struct.pack("Q", int(pcd[3],16))
-                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+8]) + " <= " + binascii.hexlify(q)
+                    print("  [" + hex(offset) + "] " + bytes(data[offset:offset+8]).hex() + " <= " + bytes(q).hex())
                     data[offset:offset+8] = q
             file = open(sourceFileName, "wb")
             file.write(data)
@@ -185,36 +184,36 @@ class FileChecker:
 
             newline = line[:-1]
 
-            if (cmp (newline, TargetPkg) == 0):
+            if (newline == TargetPkg):
                 FoundPkg = True
                 continue
 
-            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp (newline[0], "0") != 0)):
+            if (newline == "") or ((newline[0] != " ") and (newline[0] != "0")):
                 FoundPkg = False
 
             if (FoundPkg == True) :
                 newline = newline.strip()
                 splitLine = newline.split(" ", 2)
-                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0):
-                    if (cmp (splitLine[1], TargetPcd) == 0):
-                        print "found - " + TargetPkg + "." + TargetPcd
+                if (splitLine[0] == "*F") or (splitLine[0] == "*P"):
+                    if (splitLine[1] == TargetPcd):
+                        print("found - " + TargetPkg + "." + TargetPcd)
 
                         splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
-                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH") == 0):
+                        if (splitLine[0] == "FIXED") or (splitLine[0] == "PATCH"):
                             SplitLine = splitLine[1].strip()[1:].split(")", 1)
                             Type = SplitLine[0]
                             Value = SplitLine[1].strip()[1:].strip().split()[0]
-                            print "  Type - (" + Type + "), Value - (" + Value + ")"
+                            print("  Type - (" + Type + "), Value - (" + Value + ")")
                             return [Value, Type]
         return ["", ""]
-            
+
 def main():
     global FileChecker
 
     fileChecker = FileChecker()
 
     if (len(sys.argv) != 5) :
-        print "usage: PatchBinFv <Target> <SourceRoot> <ReportFile> <FvName>"
+        print("usage: PatchBinFv <Target> <SourceRoot> <ReportFile> <FvName>")
         return 0
 
     fileChecker.target = sys.argv[1]
diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
index 149630e4ef..2cea491f41 100644
--- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
+++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
@@ -1,6 +1,6 @@
 ## @ PatchBinFv.py
 #
-# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 
@@ -10,8 +10,8 @@ import sys
 import time
 import shutil
 import struct
-import binascii
-from   ctypes import *
+from ctypes import *
+from functools import reduce
 
 class GUID(Structure):
     _fields_ = [
@@ -380,9 +380,9 @@ class PeTeImage:
     def __init__(self, offset, data):
         self.Offset    = offset
         tehdr          = EFI_TE_IMAGE_HEADER.from_buffer (data, 0)
-        if   tehdr.Signature == 'VZ': # TE image
+        if tehdr.Signature == b'VZ': # TE image
             self.TeHdr   = tehdr
-        elif tehdr.Signature == 'MZ': # PE32 image
+        elif tehdr.Signature == b'MZ': # PE32 image
             self.TeHdr   = None
             self.DosHdr  = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0)
             self.PeHdr   = EFI_IMAGE_NT_HEADERS32.from_buffer (data, self.DosHdr.e_lfanew)
@@ -397,7 +397,7 @@ class PeTeImage:
         self.RelocList = []
 
     def IsTeImage(self):
-        return  self.TeHdr is not None
+        return self.TeHdr is not None
 
     def ParseReloc(self):
         if self.IsTeImage():
@@ -415,7 +415,7 @@ class PeTeImage:
             offset += sizeof(blkhdr)
             # Read relocation type,offset pairs
             rlen  = blkhdr.BlockSize - sizeof(PE_RELOC_BLOCK_HEADER)
-            rnum  = rlen/sizeof(c_uint16)
+            rnum  = rlen // sizeof(c_uint16)
             rdata = (c_uint16 * rnum).from_buffer(self.Data, offset)
             for each in rdata:
                 roff  = each & 0xfff
@@ -532,21 +532,21 @@ class FileChecker:
     def IsSyncSection(self, line):
         name = self.GetSectionName(line)
         for sectionName in self.SyncSectionList:
-            if (cmp (sectionName, name) == 0) :
+            if sectionName == name:
                 return True
         return False
 
     def PrintRebasePcd(self, pcd):
-        print "PCD: " + pcd[0] + "|" + pcd[3] + " <== " + pcd[1] + "(" + pcd[2] + ")"
+        print("PCD: {0} | {3} <== {1}({2})".format(*pcd))
 
     def RebaseFv(self, fvName, rebasePcd):
         sourceFileName = os.path.join(self.sourceRoot,fvName,self.target,fvName+".Fv")
-        print "rebasing(FV) - " + sourceFileName
+        print("rebasing(FV) - " + sourceFileName)
 
         try :
             file = open(sourceFileName, "rb")
         except Exception:
-            print "fail to open " + sourceFileName
+            print("fail to open " + sourceFileName)
             return
         try:
             buffer = file.read()
@@ -554,15 +554,15 @@ class FileChecker:
             file.close()
 
             FvHeader = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (data, 0)
-            print "HeaderLength    - " + hex(FvHeader.HeaderLength)
-            print "ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset)
+            print("HeaderLength    - " + hex(FvHeader.HeaderLength))
+            print("ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset))
 
             if (FvHeader.ExtHeaderOffset == 0):
                 Offset = FvHeader.HeaderLength
             else:
                 FvExHeader = EFI_FIRMWARE_VOLUME_EXT_HEADER.from_buffer(data, FvHeader.ExtHeaderOffset)
-                print "  FvName  - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (FvExHeader.FvName.Guid1, FvExHeader.FvName.Guid2, FvExHeader.FvName.Guid3, FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1], FvExHeader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3], FvExHeader.FvName.Guid4[4], FvExHeader.FvName.Guid4[5], FvExHeader.FvName.Guid4[6], FvExHeader.FvName.Guid4[7])
-                print "  ExtHeaderSize - " + hex(FvExHeader.ExtHeaderSize)
+                print("  FvName  - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (FvExHeader.FvName.Guid1, FvExHeader.FvName.Guid2, FvExHeader.FvName.Guid3, FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1], FvExHeader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3], FvExHeader.FvName.Guid4[4], FvExHeader.FvName.Guid4[5], FvExHeader.FvName.Guid4[6], FvExHeader.FvName.Guid4[7]))
+                print("  ExtHeaderSize - " + hex(FvExHeader.ExtHeaderSize))
                 Offset = FvHeader.ExtHeaderOffset + FvExHeader.ExtHeaderSize
             Offset = (Offset + 0x7) & ~0x7
 
@@ -576,20 +576,20 @@ class FileChecker:
                 if (FfsHeader.Type == 0xFF) or (FfsHeader.Type == EFI_FV_FILETYPE_FFS_PAD) :
                     Offset = (FfsOffset + FfsSize + 7) & ~0x7
                     continue
-                print "Ffs - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (FfsHeader.Name.Guid1, FfsHeader.Name.Guid2, FfsHeader.Name.Guid3, FfsHeader.Name.Guid4[0], FfsHeader.Name.Guid4[1], FfsHeader.Name.Guid4[2], FfsHeader.Name.Guid4[3], FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5], FfsHeader.Name.Guid4[6], FfsHeader.Name.Guid4[7])
+                print("Ffs - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (FfsHeader.Name.Guid1, FfsHeader.Name.Guid2, FfsHeader.Name.Guid3, FfsHeader.Name.Guid4[0], FfsHeader.Name.Guid4[1], FfsHeader.Name.Guid4[2], FfsHeader.Name.Guid4[3], FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5], FfsHeader.Name.Guid4[6], FfsHeader.Name.Guid4[7]))
                 Offset = Offset + sizeof(EFI_FFS_FILE_HEADER)
                 while (Offset < FfsOffset + FfsSize) :
                     SectionHeader = EFI_COMMON_SECTION_HEADER.from_buffer (data, Offset)
                     #print "  Section - " + hex(Offset)
                     if (SectionHeader.Type == EFI_SECTION_PE32) or (SectionHeader.Type == EFI_SECTION_TE) :
                         PeOffset = Offset + sizeof(EFI_COMMON_SECTION_HEADER)
-                        print "    PE - " + hex(PeOffset) + "(" + binascii.hexlify(data[PeOffset:PeOffset+2]) + ")"
+                        print("    PE - " + hex(PeOffset) + "(" + bytes(data[PeOffset:PeOffset+2]).hex() + ")")
 
                         newbase = int(rebasePcd[1],16)
                         oldbase = int(rebasePcd[3],16)
 
                         delta = newbase - oldbase
-                        print "    delta - " + hex(delta) + "(" + hex(oldbase) + " <== " + hex(newbase) + ")"
+                        print("    delta - " + hex(delta) + "(" + hex(oldbase) + " <== " + hex(newbase) + ")")
 
                         PeLength = FfsSize-sizeof(EFI_FFS_FILE_HEADER);
 
@@ -618,26 +618,26 @@ class FileChecker:
 
             newline = line[:-1].replace('\r','')
 
-            if (cmp (newline, TargetPkg) == 0):
+            if newline == TargetPkg:
                 FoundPkg = True
                 continue
 
-            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp (newline[0], "0") != 0)):
+            if newline == "" or (newline[0] != " " and newline[0] != "0"):
                 FoundPkg = False
 
             if (FoundPkg == True) :
                 newline = newline.strip()
                 splitLine = newline.split(" ", 2)
-                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0):
-                    if (cmp (splitLine[1], TargetPcd) == 0):
-                        print "found - " + TargetPkg + "." + TargetPcd
+                if (splitLine[0] == "*F") or (splitLine[0] == "*P"):
+                    if splitLine[1] == TargetPcd:
+                        print("found - " + TargetPkg + "." + TargetPcd)
 
                         splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
-                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH") == 0):
+                        if splitLine[0] == "FIXED" or splitLine[0] == "PATCH":
                             SplitLine = splitLine[1].strip()[1:].split(")", 1)
                             Type = SplitLine[0]
                             Value = SplitLine[1].strip()[1:].strip().split()[0]
-                            print "  Type - (" + Type + "), Value - (" + Value + ")"
+                            print("  Type - (" + Type + "), Value - (" + Value + ")")
                             return [Value, Type]
         return ["", ""]
 
@@ -648,7 +648,7 @@ class FileChecker:
         try :
             file = open(fileName)
         except Exception:
-            print "fail to open " + fileName
+            print("fail to open " + fileName)
             return
         try:
             while 1:
@@ -658,21 +658,21 @@ class FileChecker:
 
                 newline = line[:-1].replace('\r','')
 
-                if cmp (newline, "") == 0:
+                if newline == "":
                     continue
 
-                if cmp (newline, "#![Pcd]") == 0:
+                if newline == "#![Pcd]":
                     ParseBase = True
                     continue
 
                 if ParseBase == True :
-                    if (cmp (line[0:2], "#!") != 0) :
+                    if line[0:2] != "#!":
                         ParseBase = False
                         continue
                     newline = newline[2:].strip()
 
                     splitLine = newline.split("|")
-                    if cmp (PcdName, splitLine[0]) == 0:
+                    if PcdName == splitLine[0]:
                         Value = splitLine[1]
         finally:
             file.close()
@@ -681,11 +681,11 @@ class FileChecker:
 
     def SetNewFvBase (self, fvName, PcdName, OldFvBase, NewFvBase):
         fileName = os.path.join(self.sourceRoot,fvName,self.target,fvName+".inf")
-        print "update - " + fileName
+        print("update - " + fileName)
         try :
             file = open(fileName, "r")
         except Exception:
-            print "fail to open " + fileName
+            print("fail to open " + fileName)
             return
         try:
             lines = file.readlines()
@@ -699,23 +699,23 @@ class FileChecker:
 
                 newline = line[:-1].strip()
 
-                if cmp (newline, "") == 0:
+                if newline == "":
                     continue
 
-                if cmp (newline, "#![Pcd]") == 0:
+                if newline == "#![Pcd]":
                     ParseBase = True
                     continue
 
                 if ParseBase == True :
-                    if (cmp (line[0:2], "#!") != 0) :
+                    if line[0:2] != "#!":
                         ParseBase = False
                         continue
                     newline = newline[2:].strip()
 
                     splitLine = newline.split("|")
-                    if cmp (PcdName, splitLine[0]) == 0:
-                        if cmp (OldFvBase, splitLine[1]) != 0:
-                            print "ERROR: OldFvBase mismatch!"
+                    if PcdName == splitLine[0]:
+                        if OldFvBase != splitLine[1]:
+                            print("ERROR: OldFvBase mismatch!")
                         else:
                             lines[index] = "#!  " + PcdName + "|" + NewFvBase + "\n"
                             break
@@ -730,11 +730,11 @@ class FileChecker:
         try :
             file = open(self.reportFile)
         except Exception:
-            print "fail to open " + self.reportFile
+            print("fail to open " + self.reportFile)
             return
         try:
             file.seek(0)
-            print "checking - " + self.RebasePcd[0]
+            print("checking - " + self.RebasePcd[0])
             ValuePair = self.GetPcdFromReport (file, self.RebasePcd[0])
             self.RebasePcd[1] = ValuePair[0]
             self.RebasePcd[2] = ValuePair[1]
@@ -747,7 +747,7 @@ def main():
     fileChecker = FileChecker()
 
     if (len(sys.argv) != 6) :
-        print "usage: RebaseBinFv <Target> <SourceRoot> <ReportFile> <FvName> <RebasePcdName>"
+        print("usage: RebaseBinFv <Target> <SourceRoot> <ReportFile> <FvName> <RebasePcdName>")
         return 0
 
     fileChecker.target       = sys.argv[1]
-- 
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111773): https://edk2.groups.io/g/devel/message/111773
Mute This Topic: https://groups.io/mt/102842751/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for Python 3.x
Posted by Chiu, Chasel 5 months ago
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Thanks,
Chasel


> -----Original Message-----
> From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>
> Sent: Monday, November 27, 2023 5:04 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for
> Python 3.x
> 
> PatchFv tools now run on Python 3.x
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> ---
>  .../MinPlatformPkg/Tools/PatchFv/PatchBfv.py  | 35 ++++----
>  .../Tools/PatchFv/PatchBinFv.py               | 69 ++++++++--------
>  .../Tools/PatchFv/RebaseBinFv.py              | 82 +++++++++----------
>  3 files changed, 92 insertions(+), 94 deletions(-)
> 
> diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
> b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
> index 1312bfc328..f05480b91f 100644
> --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
> +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
> @@ -1,6 +1,6 @@
>  ## @ PatchBfv.py
>  #
> -# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2023, Intel Corporation. All rights
> +reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -11,8 +11,7 @@
> import sys  import time  import shutil  import struct -import binascii
> -from   ctypes import *
> +from ctypes import *
> 
>  class FileChecker:
>      def __init__(self):
> @@ -21,17 +20,17 @@ class FileChecker:
>          self.pcd = ["", "", ""]
> 
>      def PrintPcd(self):
> -        print "PCD: " + self.pcd[0] + "|" + self.pcd[1] + "(" + self.pcd[2] + ")"
> +        print("PCD: {0}|{1}({2})".format(*(self.pcd)))
> 
>      def ProcessReport(self):
>          try :
>              file = open(self.reportFile)
>          except Exception:
> -            print "fail to open " + self.reportFile
> +            print("fail to open " + self.reportFile)
>              return
>          try:
>              file.seek(0)
> -            print "checking - " + self.pcd[0]
> +            print("checking - " + self.pcd[0])
>              ValuePair = self.GetPcdFromReport (file, self.pcd[0])
>              self.pcd[1] = ValuePair[0]
>              self.pcd[2] = ValuePair[1]
> @@ -42,12 +41,12 @@ class FileChecker:
> 
>      def PatchFd(self):
>          fileName = self.fdName
> -        print "patching BFV - " + fileName
> +        print("patching BFV - " + fileName)
> 
>          try :
>              file = open(fileName, "rb")
>          except Exception:
> -            print "fail to open " + fileName
> +            print("fail to open " + fileName)
>              return
>          try:
>              buffer = file.read()
> @@ -57,7 +56,7 @@ class FileChecker:
>              offset = -4
> 
>              l = struct.pack("L", int(self.pcd[1],16))
> -            print "  [" + hex(offset) + "] " + binascii.hexlify(data[-4:]) + " <= " +
> binascii.hexlify(l)
> +            print("  [" + hex(offset) + "] " + bytes(data[-4:]).hex() +
> + " <= " + bytes(l).hex())
>              data[-4:] = l
> 
>              file = open(fileName, "wb") @@ -77,36 +76,36 @@ class FileChecker:
> 
>              newline = line[:-1]
> 
> -            if (cmp (newline, TargetPkg) == 0):
> +            if newline == TargetPkg:
>                  FoundPkg = True
>                  continue
> 
> -            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp
> (newline[0], "0") != 0)):
> +            if newline == "" or (newline[0] != " " and newline[0] != "0"):
>                  FoundPkg = False
> 
>              if (FoundPkg == True) :
>                  newline = newline.strip()
>                  splitLine = newline.split(" ", 2)
> -                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0) :
> -                    if (cmp (splitLine[1], TargetPcd) == 0):
> -                        print "found - " + TargetPkg + "." + TargetPcd
> +                if splitLine[0] == "*F" or splitLine[0] == "*P":
> +                    if splitLine[1] == TargetPcd:
> +                        print("found - " + TargetPkg + "." + TargetPcd)
> 
>                          splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
> -                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH")
> == 0):
> +                        if splitLine[0] == "FIXED" or splitLine[0] == "PATCH":
>                              SplitLine = splitLine[1].strip()[1:].split(")", 1)
>                              Type = SplitLine[0]
>                              Value = SplitLine[1].strip()[1:].strip().split()[0]
> -                            print "  Type - (" + Type + "), Value - (" + Value + ")"
> +                            print("  Type - (" + Type + "), Value - ("
> + + Value + ")")
>                              return [Value, Type]
>          return ["", ""]
> -
> +
>  def main():
>      global FileChecker
> 
>      fileChecker = FileChecker()
> 
>      if (len(sys.argv) != 4) :
> -        print "usage: PatchBfv <FdFile> <ReportFile> <BfvPcdName>"
> +        print("usage: PatchBfv <FdFile> <ReportFile> <BfvPcdName>")
>          return 0
> 
>      fileChecker.fdName = sys.argv[1]
> diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
> b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
> index b98c951b45..78576a3029 100644
> --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
> +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py
> @@ -1,6 +1,6 @@
>  ## @ PatchBinFv.py
>  #
> -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2023, Intel Corporation. All rights
> +reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -11,7 +11,6 @@
> import sys  import time  import shutil  import struct -import binascii
>  from   ctypes import *
> 
>  class FileChecker:
> @@ -30,20 +29,20 @@ class FileChecker:
>      def IsSyncSection(self, line):
>          name = self.GetSectionName(line)
>          for sectionName in self.SyncSectionList:
> -            if (cmp (sectionName, name) == 0) :
> +            if sectionName == name:
>                  return True
>          return False
> 
>      def PrintPcdList(self, pcdList):
>          for pcd in pcdList:
> -            print "PCD: " + pcd[0] + "|" + pcd[1] + "|" + pcd[2] + " <== " + pcd[3] + "("
> + pcd[4] + ")"
> +            print(("PCD: {0} | {1} | {2} <== {3}({4})".format(*pcd)))
> 
>      def GetInfFileGuid(self, fileName):
>          guid = ""
>          try :
>              file = open(fileName)
>          except Exception:
> -            print "fail to open " + fileName
> +            print("fail to open " + fileName)
>              return
>          try:
>              while 1:
> @@ -53,7 +52,7 @@ class FileChecker:
> 
>                  newline = line[:-1]
> 
> -                if cmp (line[:11], "  FILE_GUID") == 0:
> +                if line[:11] == "  FILE_GUID":
>                      splitLine = line.split("=")
>                      templine = splitLine[1]
>                      guid = templine[1:1+36] @@ -66,7 +65,7 @@ class FileChecker:
>          try :
>              file = open(fileName)
>          except Exception:
> -            print "fail to open " + fileName
> +            print("fail to open " + fileName)
>              return
>          try:
>              while 1:
> @@ -76,23 +75,23 @@ class FileChecker:
> 
>                  newline = line[:-1]
> 
> -                if cmp (line[0], "#") == 0:
> +                if line[0] == "#":
>                      continue
> 
> 
> -                if cmp (line[0], "[") == 0:
> +                if line[0] == "[":
>                      SyncToDest = self.IsSyncSection(line)
>                      PatchOffset = False
> 
> -                if (cmp (self.GetSectionName(line), "PatchPcd") == 0) :
> +                if (self.GetSectionName(line) == "PatchPcd"):
>                      PatchOffset = True
>                      continue
> 
>                  if SyncToDest == True :
>                      line = line.strip()
> -                    if (cmp (line, "") == 0) :
> +                    if line == "":
>                          continue
> -                    if (cmp (line[0], "#") == 0) :
> +                    if line[0] == "#":
>                          continue
> 
>                      splitLine = line.split(" ") @@ -108,9 +107,9 @@ class FileChecker:
> 
>      def ProcessFvInf(self, fvName):
>          sourceFileName =
> os.path.join(self.sourceRoot,fvName,self.target,fvName+".inf")
> -        print "\nprocessing - " + sourceFileName
> +        print("\nprocessing - " + sourceFileName)
>          fileGuid = self.GetInfFileGuid (sourceFileName)
> -        print "FV NAME GUID - " + fileGuid
> +        print("FV NAME GUID - " + fileGuid)
> 
>          self.InfPcdList = []
>          self.ParseInfFile(sourceFileName) @@ -122,12 +121,12 @@ class
> FileChecker:
>          try :
>              file = open(self.reportFile)
>          except Exception:
> -            print "fail to open " + self.reportFile
> +            print("fail to open " + self.reportFile)
>              return
>          try:
>              for pcd in self.InfPcdList:
>                  file.seek(0)
> -                print "checking - " + pcd[0]
> +                print("checking - " + pcd[0])
>                  ValuePair = self.GetPcdFromReport (file, pcd[0])
>                  pcd[3] = ValuePair[0]
>                  pcd[4] = ValuePair[1]
> @@ -138,12 +137,12 @@ class FileChecker:
> 
>      def PatchFv(self, fvName):
>          sourceFileName =
> os.path.join(self.sourceRoot,fvName,self.target,fvName+".Fv")
> -        print "patching - " + sourceFileName
> +        print("patching - " + sourceFileName)
> 
>          try :
>              file = open(sourceFileName, "rb")
>          except Exception:
> -            print "fail to open " + sourceFileName
> +            print("fail to open " + sourceFileName)
>              return
>          try:
>              buffer = file.read()
> @@ -152,21 +151,21 @@ class FileChecker:
> 
>              for pcd in self.InfPcdList:
>                  offset = int(pcd[2], 16)
> -                if (cmp (pcd[4], "BOOLEAN") == 0) or (cmp (pcd[4], "UINT8") == 0):
> +                if (pcd[4] == "BOOLEAN") or (pcd[4] == "UINT8"):
>                      b = struct.pack("B", int(pcd[3],16))
> -                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+1]) +
> " <= " + binascii.hexlify(b)
> +                    print("  [" + hex(offset) + "] " +
> + bytes(data[offset:offset+1]).hex() + " <= " + bytes(b).hex())
>                      data[offset:offset+1] = b
> -                elif (cmp (pcd[4], "UINT16") == 0):
> +                elif (pcd[4] == "UINT16"):
>                      h = struct.pack("H", int(pcd[3],16))
> -                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+2]) +
> " <= " + binascii.hexlify(h)
> +                    print("  [" + hex(offset) + "] " +
> + bytes(data[offset:offset+2]).hex() + " <= " + bytes(h).hex())
>                      data[offset:offset+2] = h
> -                elif (cmp (pcd[4], "UINT32") == 0):
> +                elif (pcd[4] == "UINT32"):
>                      l = struct.pack("I", int(pcd[3],16))
> -                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+4]) +
> " <= " + binascii.hexlify(l)
> +                    print("  [" + hex(offset) + "] " +
> + bytes(data[offset:offset+4]).hex() + " <= " + bytes(l).hex())
>                      data[offset:offset+4] = l
> -                elif (cmp (pcd[4], "UINT64") == 0):
> +                elif (pcd[4] == "UINT64"):
>                      q = struct.pack("Q", int(pcd[3],16))
> -                    print "  [" + hex(offset) + "] " + binascii.hexlify(data[offset:offset+8]) +
> " <= " + binascii.hexlify(q)
> +                    print("  [" + hex(offset) + "] " +
> + bytes(data[offset:offset+8]).hex() + " <= " + bytes(q).hex())
>                      data[offset:offset+8] = q
>              file = open(sourceFileName, "wb")
>              file.write(data)
> @@ -185,36 +184,36 @@ class FileChecker:
> 
>              newline = line[:-1]
> 
> -            if (cmp (newline, TargetPkg) == 0):
> +            if (newline == TargetPkg):
>                  FoundPkg = True
>                  continue
> 
> -            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp
> (newline[0], "0") != 0)):
> +            if (newline == "") or ((newline[0] != " ") and (newline[0] != "0")):
>                  FoundPkg = False
> 
>              if (FoundPkg == True) :
>                  newline = newline.strip()
>                  splitLine = newline.split(" ", 2)
> -                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0):
> -                    if (cmp (splitLine[1], TargetPcd) == 0):
> -                        print "found - " + TargetPkg + "." + TargetPcd
> +                if (splitLine[0] == "*F") or (splitLine[0] == "*P"):
> +                    if (splitLine[1] == TargetPcd):
> +                        print("found - " + TargetPkg + "." + TargetPcd)
> 
>                          splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
> -                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH")
> == 0):
> +                        if (splitLine[0] == "FIXED") or (splitLine[0] == "PATCH"):
>                              SplitLine = splitLine[1].strip()[1:].split(")", 1)
>                              Type = SplitLine[0]
>                              Value = SplitLine[1].strip()[1:].strip().split()[0]
> -                            print "  Type - (" + Type + "), Value - (" + Value + ")"
> +                            print("  Type - (" + Type + "), Value - ("
> + + Value + ")")
>                              return [Value, Type]
>          return ["", ""]
> -
> +
>  def main():
>      global FileChecker
> 
>      fileChecker = FileChecker()
> 
>      if (len(sys.argv) != 5) :
> -        print "usage: PatchBinFv <Target> <SourceRoot> <ReportFile> <FvName>"
> +        print("usage: PatchBinFv <Target> <SourceRoot> <ReportFile>
> + <FvName>")
>          return 0
> 
>      fileChecker.target = sys.argv[1]
> diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
> b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
> index 149630e4ef..2cea491f41 100644
> --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
> +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py
> @@ -1,6 +1,6 @@
>  ## @ PatchBinFv.py
>  #
> -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2023, Intel Corporation. All rights
> +reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  #
> 
> @@ -10,8 +10,8 @@ import sys
>  import time
>  import shutil
>  import struct
> -import binascii
> -from   ctypes import *
> +from ctypes import *
> +from functools import reduce
> 
>  class GUID(Structure):
>      _fields_ = [
> @@ -380,9 +380,9 @@ class PeTeImage:
>      def __init__(self, offset, data):
>          self.Offset    = offset
>          tehdr          = EFI_TE_IMAGE_HEADER.from_buffer (data, 0)
> -        if   tehdr.Signature == 'VZ': # TE image
> +        if tehdr.Signature == b'VZ': # TE image
>              self.TeHdr   = tehdr
> -        elif tehdr.Signature == 'MZ': # PE32 image
> +        elif tehdr.Signature == b'MZ': # PE32 image
>              self.TeHdr   = None
>              self.DosHdr  = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0)
>              self.PeHdr   = EFI_IMAGE_NT_HEADERS32.from_buffer (data,
> self.DosHdr.e_lfanew)
> @@ -397,7 +397,7 @@ class PeTeImage:
>          self.RelocList = []
> 
>      def IsTeImage(self):
> -        return  self.TeHdr is not None
> +        return self.TeHdr is not None
> 
>      def ParseReloc(self):
>          if self.IsTeImage():
> @@ -415,7 +415,7 @@ class PeTeImage:
>              offset += sizeof(blkhdr)
>              # Read relocation type,offset pairs
>              rlen  = blkhdr.BlockSize - sizeof(PE_RELOC_BLOCK_HEADER)
> -            rnum  = rlen/sizeof(c_uint16)
> +            rnum  = rlen // sizeof(c_uint16)
>              rdata = (c_uint16 * rnum).from_buffer(self.Data, offset)
>              for each in rdata:
>                  roff  = each & 0xfff
> @@ -532,21 +532,21 @@ class FileChecker:
>      def IsSyncSection(self, line):
>          name = self.GetSectionName(line)
>          for sectionName in self.SyncSectionList:
> -            if (cmp (sectionName, name) == 0) :
> +            if sectionName == name:
>                  return True
>          return False
> 
>      def PrintRebasePcd(self, pcd):
> -        print "PCD: " + pcd[0] + "|" + pcd[3] + " <== " + pcd[1] + "(" + pcd[2] + ")"
> +        print("PCD: {0} | {3} <== {1}({2})".format(*pcd))
> 
>      def RebaseFv(self, fvName, rebasePcd):
>          sourceFileName =
> os.path.join(self.sourceRoot,fvName,self.target,fvName+".Fv")
> -        print "rebasing(FV) - " + sourceFileName
> +        print("rebasing(FV) - " + sourceFileName)
> 
>          try :
>              file = open(sourceFileName, "rb")
>          except Exception:
> -            print "fail to open " + sourceFileName
> +            print("fail to open " + sourceFileName)
>              return
>          try:
>              buffer = file.read()
> @@ -554,15 +554,15 @@ class FileChecker:
>              file.close()
> 
>              FvHeader = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (data, 0)
> -            print "HeaderLength    - " + hex(FvHeader.HeaderLength)
> -            print "ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset)
> +            print("HeaderLength    - " + hex(FvHeader.HeaderLength))
> +            print("ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset))
> 
>              if (FvHeader.ExtHeaderOffset == 0):
>                  Offset = FvHeader.HeaderLength
>              else:
>                  FvExHeader =
> EFI_FIRMWARE_VOLUME_EXT_HEADER.from_buffer(data,
> FvHeader.ExtHeaderOffset)
> -                print "  FvName  - %08x-%04x-%04x-%02x%02x-
> %02x%02x%02x%02x%02x%02x" % (FvExHeader.FvName.Guid1,
> FvExHeader.FvName.Guid2, FvExHeader.FvName.Guid3,
> FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1],
> FvExHeader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3],
> FvExHeader.FvName.Guid4[4], FvExHeader.FvName.Guid4[5],
> FvExHeader.FvName.Guid4[6], FvExHeader.FvName.Guid4[7])
> -                print "  ExtHeaderSize - " + hex(FvExHeader.ExtHeaderSize)
> +                print("  FvName  - %08x-%04x-%04x-%02x%02x-
> %02x%02x%02x%02x%02x%02x" % (FvExHeader.FvName.Guid1,
> FvExHeader.FvName.Guid2, FvExHeader.FvName.Guid3,
> FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1],
> FvExHeader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3],
> FvExHeader.FvName.Guid4[4], FvExHeader.FvName.Guid4[5],
> FvExHeader.FvName.Guid4[6], FvExHeader.FvName.Guid4[7]))
> +                print("  ExtHeaderSize - " +
> + hex(FvExHeader.ExtHeaderSize))
>                  Offset = FvHeader.ExtHeaderOffset + FvExHeader.ExtHeaderSize
>              Offset = (Offset + 0x7) & ~0x7
> 
> @@ -576,20 +576,20 @@ class FileChecker:
>                  if (FfsHeader.Type == 0xFF) or (FfsHeader.Type ==
> EFI_FV_FILETYPE_FFS_PAD) :
>                      Offset = (FfsOffset + FfsSize + 7) & ~0x7
>                      continue
> -                print "Ffs - %08x-%04x-%04x-%02x%02x-
> %02x%02x%02x%02x%02x%02x" % (FfsHeader.Name.Guid1,
> FfsHeader.Name.Guid2, FfsHeader.Name.Guid3, FfsHeader.Name.Guid4[0],
> FfsHeader.Name.Guid4[1], FfsHeader.Name.Guid4[2], FfsHeader.Name.Guid4[3],
> FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5], FfsHeader.Name.Guid4[6],
> FfsHeader.Name.Guid4[7])
> +                print("Ffs -
> + %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" %
> + (FfsHeader.Name.Guid1, FfsHeader.Name.Guid2, FfsHeader.Name.Guid3,
> + FfsHeader.Name.Guid4[0], FfsHeader.Name.Guid4[1],
> + FfsHeader.Name.Guid4[2], FfsHeader.Name.Guid4[3],
> + FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5],
> + FfsHeader.Name.Guid4[6], FfsHeader.Name.Guid4[7]))
>                  Offset = Offset + sizeof(EFI_FFS_FILE_HEADER)
>                  while (Offset < FfsOffset + FfsSize) :
>                      SectionHeader = EFI_COMMON_SECTION_HEADER.from_buffer
> (data, Offset)
>                      #print "  Section - " + hex(Offset)
>                      if (SectionHeader.Type == EFI_SECTION_PE32) or (SectionHeader.Type
> == EFI_SECTION_TE) :
>                          PeOffset = Offset + sizeof(EFI_COMMON_SECTION_HEADER)
> -                        print "    PE - " + hex(PeOffset) + "(" +
> binascii.hexlify(data[PeOffset:PeOffset+2]) + ")"
> +                        print("    PE - " + hex(PeOffset) + "(" +
> bytes(data[PeOffset:PeOffset+2]).hex() + ")")
> 
>                          newbase = int(rebasePcd[1],16)
>                          oldbase = int(rebasePcd[3],16)
> 
>                          delta = newbase - oldbase
> -                        print "    delta - " + hex(delta) + "(" + hex(oldbase) + " <== " +
> hex(newbase) + ")"
> +                        print("    delta - " + hex(delta) + "(" + hex(oldbase) + " <== " +
> hex(newbase) + ")")
> 
>                          PeLength = FfsSize-sizeof(EFI_FFS_FILE_HEADER);
> 
> @@ -618,26 +618,26 @@ class FileChecker:
> 
>              newline = line[:-1].replace('\r','')
> 
> -            if (cmp (newline, TargetPkg) == 0):
> +            if newline == TargetPkg:
>                  FoundPkg = True
>                  continue
> 
> -            if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp
> (newline[0], "0") != 0)):
> +            if newline == "" or (newline[0] != " " and newline[0] != "0"):
>                  FoundPkg = False
> 
>              if (FoundPkg == True) :
>                  newline = newline.strip()
>                  splitLine = newline.split(" ", 2)
> -                if (cmp (splitLine[0], "*F") == 0) or (cmp (splitLine[0], "*P") == 0):
> -                    if (cmp (splitLine[1], TargetPcd) == 0):
> -                        print "found - " + TargetPkg + "." + TargetPcd
> +                if (splitLine[0] == "*F") or (splitLine[0] == "*P"):
> +                    if splitLine[1] == TargetPcd:
> +                        print("found - " + TargetPkg + "." + TargetPcd)
> 
>                          splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
> -                        if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH")
> == 0):
> +                        if splitLine[0] == "FIXED" or splitLine[0] == "PATCH":
>                              SplitLine = splitLine[1].strip()[1:].split(")", 1)
>                              Type = SplitLine[0]
>                              Value = SplitLine[1].strip()[1:].strip().split()[0]
> -                            print "  Type - (" + Type + "), Value - (" + Value + ")"
> +                            print("  Type - (" + Type + "), Value - ("
> + + Value + ")")
>                              return [Value, Type]
>          return ["", ""]
> 
> @@ -648,7 +648,7 @@ class FileChecker:
>          try :
>              file = open(fileName)
>          except Exception:
> -            print "fail to open " + fileName
> +            print("fail to open " + fileName)
>              return
>          try:
>              while 1:
> @@ -658,21 +658,21 @@ class FileChecker:
> 
>                  newline = line[:-1].replace('\r','')
> 
> -                if cmp (newline, "") == 0:
> +                if newline == "":
>                      continue
> 
> -                if cmp (newline, "#![Pcd]") == 0:
> +                if newline == "#![Pcd]":
>                      ParseBase = True
>                      continue
> 
>                  if ParseBase == True :
> -                    if (cmp (line[0:2], "#!") != 0) :
> +                    if line[0:2] != "#!":
>                          ParseBase = False
>                          continue
>                      newline = newline[2:].strip()
> 
>                      splitLine = newline.split("|")
> -                    if cmp (PcdName, splitLine[0]) == 0:
> +                    if PcdName == splitLine[0]:
>                          Value = splitLine[1]
>          finally:
>              file.close()
> @@ -681,11 +681,11 @@ class FileChecker:
> 
>      def SetNewFvBase (self, fvName, PcdName, OldFvBase, NewFvBase):
>          fileName = os.path.join(self.sourceRoot,fvName,self.target,fvName+".inf")
> -        print "update - " + fileName
> +        print("update - " + fileName)
>          try :
>              file = open(fileName, "r")
>          except Exception:
> -            print "fail to open " + fileName
> +            print("fail to open " + fileName)
>              return
>          try:
>              lines = file.readlines()
> @@ -699,23 +699,23 @@ class FileChecker:
> 
>                  newline = line[:-1].strip()
> 
> -                if cmp (newline, "") == 0:
> +                if newline == "":
>                      continue
> 
> -                if cmp (newline, "#![Pcd]") == 0:
> +                if newline == "#![Pcd]":
>                      ParseBase = True
>                      continue
> 
>                  if ParseBase == True :
> -                    if (cmp (line[0:2], "#!") != 0) :
> +                    if line[0:2] != "#!":
>                          ParseBase = False
>                          continue
>                      newline = newline[2:].strip()
> 
>                      splitLine = newline.split("|")
> -                    if cmp (PcdName, splitLine[0]) == 0:
> -                        if cmp (OldFvBase, splitLine[1]) != 0:
> -                            print "ERROR: OldFvBase mismatch!"
> +                    if PcdName == splitLine[0]:
> +                        if OldFvBase != splitLine[1]:
> +                            print("ERROR: OldFvBase mismatch!")
>                          else:
>                              lines[index] = "#!  " + PcdName + "|" + NewFvBase + "\n"
>                              break
> @@ -730,11 +730,11 @@ class FileChecker:
>          try :
>              file = open(self.reportFile)
>          except Exception:
> -            print "fail to open " + self.reportFile
> +            print("fail to open " + self.reportFile)
>              return
>          try:
>              file.seek(0)
> -            print "checking - " + self.RebasePcd[0]
> +            print("checking - " + self.RebasePcd[0])
>              ValuePair = self.GetPcdFromReport (file, self.RebasePcd[0])
>              self.RebasePcd[1] = ValuePair[0]
>              self.RebasePcd[2] = ValuePair[1] @@ -747,7 +747,7 @@ def main():
>      fileChecker = FileChecker()
> 
>      if (len(sys.argv) != 6) :
> -        print "usage: RebaseBinFv <Target> <SourceRoot> <ReportFile> <FvName>
> <RebasePcdName>"
> +        print("usage: RebaseBinFv <Target> <SourceRoot> <ReportFile>
> + <FvName> <RebasePcdName>")
>          return 0
> 
>      fileChecker.target       = sys.argv[1]
> --
> 2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111787): https://edk2.groups.io/g/devel/message/111787
Mute This Topic: https://groups.io/mt/102842751/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-