summaryrefslogtreecommitdiff
path: root/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
diff options
context:
space:
mode:
Diffstat (limited to 'Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py')
-rw-r--r--Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py126
1 files changed, 126 insertions, 0 deletions
diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
new file mode 100644
index 0000000000..73c18c5d27
--- /dev/null
+++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py
@@ -0,0 +1,126 @@
+## @ PatchBfv.py
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available under
+# the terms and conditions of the BSD License that accompanies this distribution.
+# The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+import os
+import re
+import sys
+import time
+import shutil
+import struct
+import binascii
+from ctypes import *
+
+class FileChecker:
+ def __init__(self):
+ self.fdName = ""
+ self.reportFile = ""
+ self.pcd = ["", "", ""]
+
+ def PrintPcd(self):
+ print "PCD: " + self.pcd[0] + "|" + self.pcd[1] + "(" + self.pcd[2] + ")"
+
+ def ProcessReport(self):
+ try :
+ file = open(self.reportFile)
+ except Exception:
+ print "fail to open " + self.reportFile
+ return
+ try:
+ file.seek(0)
+ print "checking - " + self.pcd[0]
+ ValuePair = self.GetPcdFromReport (file, self.pcd[0])
+ self.pcd[1] = ValuePair[0]
+ self.pcd[2] = ValuePair[1]
+ finally:
+ file.close()
+
+ self.PrintPcd()
+
+ def PatchFd(self):
+ fileName = self.fdName
+ print "patching BFV - " + fileName
+
+ try :
+ file = open(fileName, "rb")
+ except Exception:
+ print "fail to open " + fileName
+ return
+ try:
+ buffer = file.read()
+ data = bytearray(buffer)
+ file.close()
+
+ offset = -4
+
+ l = struct.pack("L", int(self.pcd[1],16))
+ print " [" + hex(offset) + "] " + binascii.hexlify(data[-4:]) + " <= " + binascii.hexlify(l)
+ data[-4:] = l
+
+ file = open(fileName, "wb")
+ file.write(data[0:])
+ finally:
+ file.close()
+
+ def GetPcdFromReport(self, file, pcd):
+ FoundPkg = False
+ pcdSplit = pcd.split(".")
+ TargetPkg = pcdSplit[0]
+ TargetPcd = pcdSplit[1]
+ while 1:
+ line = file.readline()
+ if not line:
+ break
+
+ newline = line[:-1]
+
+ if (cmp (newline, TargetPkg) == 0):
+ FoundPkg = True
+ continue
+
+ if (cmp (newline, "") == 0) or ((cmp (newline[0], " ") != 0) and (cmp (newline[0], "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
+
+ splitLine = splitLine[2].strip()[1:].strip().split(" ", 1)
+ if (cmp (splitLine[0], "FIXED") == 0) or (cmp (splitLine[0], "PATCH") == 0):
+ SplitLine = splitLine[1].strip()[1:].split(")", 1)
+ Type = SplitLine[0]
+ Value = SplitLine[1].strip()[1:].strip()
+ 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>"
+ return 0
+
+ fileChecker.fdName = sys.argv[1]
+ fileChecker.reportFile = sys.argv[2]
+ fileChecker.pcd[0] = sys.argv[3]
+
+ fileChecker.ProcessReport ()
+ fileChecker.PatchFd ()
+
+if __name__ == '__main__':
+ sys.exit(main())