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

2023-11-29 Thread Nate DeSimone
Pushed as d02c09d

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Nate DeSimone
Sent: Monday, November 27, 2023 5:04 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel ; Gao, Liming 
; Dong, Eric 
Subject: [edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv 
Tools for Python 3.x

PatchFv tools now run on Python 3.x

Cc: Chasel Chiu 
Cc: Liming Gao 
Cc: Eric Dong 
Signed-off-by: Nate DeSimone 
---
 .../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.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights 
+reserved.
 # 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   "
+print("usage: PatchBfv   ")
 return 0
 
 fileChecker.fdName = sys.argv[1]
diff --git 

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

2023-11-27 Thread Chiu, Chasel


Reviewed-by: Chasel Chiu 

Thanks,
Chasel


> -Original Message-
> From: Desimone, Nathaniel L 
> Sent: Monday, November 27, 2023 5:04 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel ; Gao, Liming
> ; Dong, Eric 
> Subject: [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for
> Python 3.x
> 
> PatchFv tools now run on Python 3.x
> 
> Cc: Chasel Chiu 
> Cc: Liming Gao 
> Cc: Eric Dong 
> Signed-off-by: Nate DeSimone 
> ---
>  .../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.
> +# Copyright (c) 2017 - 2023, Intel Corporation. All rights
> +reserved.
>  # 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
> 
>