IntelFsp2Pkg: FSP Python scripts to support 3.x.

https://bugzilla.tianocore.org/show_bug.cgi?id=1930

Updated FSP Python scripts to support both 2.x and
3.x.

Test:
  . Verified with Python 2.7.12 and 3.6.6.
  . Verified tool result is the same before the change.
  . Both py -2 and py -3 built binary can boot.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
This commit is contained in:
Chasel Chiu
2019-06-21 08:43:22 +08:00
parent 2603fce126
commit c3f0829b34
3 changed files with 109 additions and 62 deletions

View File

@ -1,6 +1,6 @@
## @ GenCfgOpt.py ## @ GenCfgOpt.py
# #
# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
## ##
@ -10,6 +10,7 @@ import re
import sys import sys
import struct import struct
from datetime import date from datetime import date
from functools import reduce
# Generated file copyright header # Generated file copyright header
@ -90,11 +91,11 @@ class CLogicalExpression:
self.string = '' self.string = ''
def errExit(self, err = ''): def errExit(self, err = ''):
print "ERROR: Express parsing for:" print ("ERROR: Express parsing for:")
print " %s" % self.string print (" %s" % self.string)
print " %s^" % (' ' * self.index) print (" %s^" % (' ' * self.index))
if err: if err:
print "INFO : %s" % err print ("INFO : %s" % err)
raise SystemExit raise SystemExit
def getNonNumber (self, n1, n2): def getNonNumber (self, n1, n2):
@ -338,15 +339,15 @@ EndList
else: else:
Error = 0 Error = 0
if self.Debug: if self.Debug:
print "INFO : Macro dictionary:" print ("INFO : Macro dictionary:")
for Each in self._MacroDict: for Each in self._MacroDict:
print " $(%s) = [ %s ]" % (Each , self._MacroDict[Each]) print (" $(%s) = [ %s ]" % (Each , self._MacroDict[Each]))
return Error return Error
def EvaulateIfdef (self, Macro): def EvaulateIfdef (self, Macro):
Result = Macro in self._MacroDict Result = Macro in self._MacroDict
if self.Debug: if self.Debug:
print "INFO : Eval Ifdef [%s] : %s" % (Macro, Result) print ("INFO : Eval Ifdef [%s] : %s" % (Macro, Result))
return Result return Result
def ExpandMacros (self, Input): def ExpandMacros (self, Input):
@ -359,7 +360,7 @@ EndList
Line = Line.replace(Each, self._MacroDict[Variable]) Line = Line.replace(Each, self._MacroDict[Variable])
else: else:
if self.Debug: if self.Debug:
print "WARN : %s is not defined" % Each print ("WARN : %s is not defined" % Each)
Line = Line.replace(Each, Each[2:-1]) Line = Line.replace(Each, Each[2:-1])
return Line return Line
@ -372,7 +373,7 @@ EndList
Line = Line.replace(PcdName, self._PcdsDict[PcdName]) Line = Line.replace(PcdName, self._PcdsDict[PcdName])
else: else:
if self.Debug: if self.Debug:
print "WARN : %s is not defined" % PcdName print ("WARN : %s is not defined" % PcdName)
return Line return Line
def EvaluateExpress (self, Expr): def EvaluateExpress (self, Expr):
@ -381,7 +382,7 @@ EndList
LogExpr = CLogicalExpression() LogExpr = CLogicalExpression()
Result = LogExpr.evaluateExpress (ExpExpr) Result = LogExpr.evaluateExpress (ExpExpr)
if self.Debug: if self.Debug:
print "INFO : Eval Express [%s] : %s" % (Expr, Result) print ("INFO : Eval Express [%s] : %s" % (Expr, Result))
return Result return Result
def FormatListValue(self, ConfigDict): def FormatListValue(self, ConfigDict):
@ -406,7 +407,7 @@ EndList
bytearray = [] bytearray = []
for each in dataarray: for each in dataarray:
value = each value = each
for loop in xrange(unit): for loop in range(int(unit)):
bytearray.append("0x%02X" % (value & 0xFF)) bytearray.append("0x%02X" % (value & 0xFF))
value = value >> 8 value = value >> 8
newvalue = '{' + ','.join(bytearray) + '}' newvalue = '{' + ','.join(bytearray) + '}'
@ -548,7 +549,7 @@ EndList
if Match: if Match:
self._MacroDict[Match.group(1)] = Match.group(2) self._MacroDict[Match.group(1)] = Match.group(2)
if self.Debug: if self.Debug:
print "INFO : DEFINE %s = [ %s ]" % (Match.group(1), Match.group(2)) print ("INFO : DEFINE %s = [ %s ]" % (Match.group(1), Match.group(2)))
elif IsPcdSect: elif IsPcdSect:
#gSiPkgTokenSpaceGuid.PcdTxtEnable|FALSE #gSiPkgTokenSpaceGuid.PcdTxtEnable|FALSE
#gSiPkgTokenSpaceGuid.PcdOverclockEnable|TRUE #gSiPkgTokenSpaceGuid.PcdOverclockEnable|TRUE
@ -556,7 +557,7 @@ EndList
if Match: if Match:
self._PcdsDict[Match.group(1)] = Match.group(2) self._PcdsDict[Match.group(1)] = Match.group(2)
if self.Debug: if self.Debug:
print "INFO : PCD %s = [ %s ]" % (Match.group(1), Match.group(2)) print ("INFO : PCD %s = [ %s ]" % (Match.group(1), Match.group(2)))
i = 0 i = 0
while i < len(BuildOptionPcd): while i < len(BuildOptionPcd):
Match = re.match("\s*([\w\.]+)\s*\=\s*(\w+)", BuildOptionPcd[i]) Match = re.match("\s*([\w\.]+)\s*\=\s*(\w+)", BuildOptionPcd[i])
@ -774,7 +775,7 @@ EndList
bitsvalue = bitsvalue[::-1] bitsvalue = bitsvalue[::-1]
bitslen = len(bitsvalue) bitslen = len(bitsvalue)
if start > bitslen or end > bitslen: if start > bitslen or end > bitslen:
print "Invalid bits offset [%d,%d] for %s" % (start, end, subitem['name']) print ("Invalid bits offset [%d,%d] for %s" % (start, end, subitem['name']))
raise SystemExit raise SystemExit
return hex(int(bitsvalue[start:end][::-1], 2)) return hex(int(bitsvalue[start:end][::-1], 2))
@ -1031,7 +1032,7 @@ EndList
if Match and Match.group(3) == 'END': if Match and Match.group(3) == 'END':
if (StructName != Match.group(1)) or (VariableName != Match.group(2)): if (StructName != Match.group(1)) or (VariableName != Match.group(2)):
print "Unmatched struct name '%s' and '%s' !" % (StructName, Match.group(1)) print ("Unmatched struct name '%s' and '%s' !" % (StructName, Match.group(1)))
else: else:
if IsUpdHdrDefined != True or IsUpdHeader != True: if IsUpdHdrDefined != True or IsUpdHeader != True:
NewTextBody.append ('} %s;\n\n' % StructName) NewTextBody.append ('} %s;\n\n' % StructName)
@ -1464,11 +1465,11 @@ EndList
def Usage(): def Usage():
print "GenCfgOpt Version 0.53" print ("GenCfgOpt Version 0.54")
print "Usage:" print ("Usage:")
print " GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [-D Macros]" print (" GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [-D Macros]")
print " GenCfgOpt HEADER PlatformDscFile BuildFvDir InputHFile [-D Macros]" print (" GenCfgOpt HEADER PlatformDscFile BuildFvDir InputHFile [-D Macros]")
print " GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]" print (" GenCfgOpt GENBSF PlatformDscFile BuildFvDir BsfOutFile [-D Macros]")
def Main(): def Main():
# #
@ -1489,7 +1490,7 @@ def Main():
else: else:
DscFile = sys.argv[2] DscFile = sys.argv[2]
if not os.path.exists(DscFile): if not os.path.exists(DscFile):
print "ERROR: Cannot open DSC file '%s' !" % DscFile print ("ERROR: Cannot open DSC file '%s' !" % DscFile)
return 2 return 2
OutFile = '' OutFile = ''
@ -1501,7 +1502,7 @@ def Main():
Start = 5 Start = 5
if argc > Start: if argc > Start:
if GenCfgOpt.ParseMacros(sys.argv[Start:]) != 0: if GenCfgOpt.ParseMacros(sys.argv[Start:]) != 0:
print "ERROR: Macro parsing failed !" print ("ERROR: Macro parsing failed !")
return 3 return 3
FvDir = sys.argv[3] FvDir = sys.argv[3]
@ -1509,11 +1510,11 @@ def Main():
os.makedirs(FvDir) os.makedirs(FvDir)
if GenCfgOpt.ParseDscFile(DscFile, FvDir) != 0: if GenCfgOpt.ParseDscFile(DscFile, FvDir) != 0:
print "ERROR: %s !" % GenCfgOpt.Error print ("ERROR: %s !" % GenCfgOpt.Error)
return 5 return 5
if GenCfgOpt.UpdateSubRegionDefaultValue() != 0: if GenCfgOpt.UpdateSubRegionDefaultValue() != 0:
print "ERROR: %s !" % GenCfgOpt.Error print ("ERROR: %s !" % GenCfgOpt.Error)
return 7 return 7
if sys.argv[1] == "UPDTXT": if sys.argv[1] == "UPDTXT":
@ -1521,23 +1522,23 @@ def Main():
if Ret != 0: if Ret != 0:
# No change is detected # No change is detected
if Ret == 256: if Ret == 256:
print "INFO: %s !" % (GenCfgOpt.Error) print ("INFO: %s !" % (GenCfgOpt.Error))
else : else :
print "ERROR: %s !" % (GenCfgOpt.Error) print ("ERROR: %s !" % (GenCfgOpt.Error))
return Ret return Ret
elif sys.argv[1] == "HEADER": elif sys.argv[1] == "HEADER":
if GenCfgOpt.CreateHeaderFile(OutFile) != 0: if GenCfgOpt.CreateHeaderFile(OutFile) != 0:
print "ERROR: %s !" % GenCfgOpt.Error print ("ERROR: %s !" % GenCfgOpt.Error)
return 8 return 8
elif sys.argv[1] == "GENBSF": elif sys.argv[1] == "GENBSF":
if GenCfgOpt.GenerateBsfFile(OutFile) != 0: if GenCfgOpt.GenerateBsfFile(OutFile) != 0:
print "ERROR: %s !" % GenCfgOpt.Error print ("ERROR: %s !" % GenCfgOpt.Error)
return 9 return 9
else: else:
if argc < 5: if argc < 5:
Usage() Usage()
return 1 return 1
print "ERROR: Unknown command '%s' !" % sys.argv[1] print ("ERROR: Unknown command '%s' !" % sys.argv[1])
Usage() Usage()
return 1 return 1
return 0 return 0

View File

@ -1,6 +1,6 @@
## @ PatchFv.py ## @ PatchFv.py
# #
# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
## ##
@ -25,7 +25,10 @@ def readDataFromFile (binfile, offset, len=1):
if (offval & 0x80000000): if (offval & 0x80000000):
offval = fsize - (0xFFFFFFFF - offval + 1) offval = fsize - (0xFFFFFFFF - offval + 1)
fd.seek(offval) fd.seek(offval)
if sys.version_info[0] < 3:
bytearray = [ord(b) for b in fd.read(len)] bytearray = [ord(b) for b in fd.read(len)]
else:
bytearray = [b for b in fd.read(len)]
value = 0 value = 0
idx = len - 1 idx = len - 1
while idx >= 0: while idx >= 0:
@ -45,7 +48,7 @@ def IsFspHeaderValid (binfile):
fd = open (binfile, "rb") fd = open (binfile, "rb")
bindat = fd.read(0x200) # only read first 0x200 bytes bindat = fd.read(0x200) # only read first 0x200 bytes
fd.close() fd.close()
HeaderList = ['FSPH' , 'FSPP' , 'FSPE'] # Check 'FSPH', 'FSPP', and 'FSPE' in the FSP header HeaderList = [b'FSPH' , b'FSPP' , b'FSPE'] # Check 'FSPH', 'FSPP', and 'FSPE' in the FSP header
OffsetList = [] OffsetList = []
for each in HeaderList: for each in HeaderList:
if each in bindat: if each in bindat:
@ -55,7 +58,10 @@ def IsFspHeaderValid (binfile):
OffsetList.append(idx) OffsetList.append(idx)
if not OffsetList[0] or not OffsetList[1]: # If 'FSPH' or 'FSPP' is missing, it will return false if not OffsetList[0] or not OffsetList[1]: # If 'FSPH' or 'FSPP' is missing, it will return false
return False return False
if sys.version_info[0] < 3:
Revision = ord(bindat[OffsetList[0] + 0x0B]) Revision = ord(bindat[OffsetList[0] + 0x0B])
else:
Revision = bindat[OffsetList[0] + 0x0B]
# #
# if revision is bigger than 1, it means it is FSP v1.1 or greater revision, which must contain 'FSPE'. # if revision is bigger than 1, it means it is FSP v1.1 or greater revision, which must contain 'FSPE'.
# #
@ -86,7 +92,10 @@ def patchDataInFile (binfile, offset, value, len=1):
value = value >> 8 value = value >> 8
idx = idx + 1 idx = idx + 1
fd.seek(offval) fd.seek(offval)
if sys.version_info[0] < 3:
fd.write("".join(chr(b) for b in bytearray)) fd.write("".join(chr(b) for b in bytearray))
else:
fd.write(bytes(bytearray))
fd.close() fd.close()
return len return len
@ -791,7 +800,7 @@ class Symbols:
# retval ret # retval ret
# #
def getSymbols(self, value): def getSymbols(self, value):
if self.dictSymbolAddress.has_key(value): if value in self.dictSymbolAddress:
# Module:Function # Module:Function
ret = int (self.dictSymbolAddress[value], 16) ret = int (self.dictSymbolAddress[value], 16)
else: else:
@ -827,8 +836,9 @@ class Symbols:
# #
# Print out the usage # Print out the usage
# #
def usage(): def Usage():
print "Usage: \n\tPatchFv FvBuildDir [FvFileBaseNames:]FdFileBaseNameToPatch \"Offset, Value\"" print ("PatchFv Version 0.50")
print ("Usage: \n\tPatchFv FvBuildDir [FvFileBaseNames:]FdFileBaseNameToPatch \"Offset, Value\"")
def main(): def main():
# #
@ -847,7 +857,7 @@ def main():
# If it fails to create dictionaries, then return an error. # If it fails to create dictionaries, then return an error.
# #
if symTables.createDicts(sys.argv[1], sys.argv[2]) != 0: if symTables.createDicts(sys.argv[1], sys.argv[2]) != 0:
print "ERROR: Failed to create symbol dictionary!!" print ("ERROR: Failed to create symbol dictionary!!")
return 2 return 2
# #
@ -907,7 +917,7 @@ def main():
if ret: if ret:
raise Exception ("Patch failed for offset 0x%08X" % offset) raise Exception ("Patch failed for offset 0x%08X" % offset)
else: else:
print "Patched offset 0x%08X:[%08X] with value 0x%08X # %s" % (offset, oldvalue, value, comment) print ("Patched offset 0x%08X:[%08X] with value 0x%08X # %s" % (offset, oldvalue, value, comment))
elif command == "COPY": elif command == "COPY":
# #
@ -928,13 +938,13 @@ def main():
if ret: if ret:
raise Exception ("Copy failed from offset 0x%08X to offset 0x%08X!" % (src, dest)) raise Exception ("Copy failed from offset 0x%08X to offset 0x%08X!" % (src, dest))
else : else :
print "Copied %d bytes from offset 0x%08X ~ offset 0x%08X # %s" % (clen, src, dest, comment) print ("Copied %d bytes from offset 0x%08X ~ offset 0x%08X # %s" % (clen, src, dest, comment))
else: else:
raise Exception ("Unknown command %s!" % command) raise Exception ("Unknown command %s!" % command)
return 0 return 0
except Exception as (ex): except Exception as ex:
print "ERROR: %s" % ex print ("ERROR: %s" % ex)
return 1 return 1
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -12,6 +12,7 @@ import copy
import struct import struct
import argparse import argparse
from ctypes import * from ctypes import *
from functools import reduce
""" """
This utility supports some operations for Intel FSP 1.x/2.x image. This utility supports some operations for Intel FSP 1.x/2.x image.
@ -340,6 +341,31 @@ def Bytes2Val (bytes):
def Val2Bytes (value, blen): def Val2Bytes (value, blen):
return [(value>>(i*8) & 0xff) for i in range(blen)] return [(value>>(i*8) & 0xff) for i in range(blen)]
def IsIntegerType (val):
if sys.version_info[0] < 3:
if type(val) in (int, long):
return True
else:
if type(val) is int:
return True
return False
def IsStrType (val):
if sys.version_info[0] < 3:
if type(val) is str:
return True
else:
if type(val) is bytes:
return True
return False
def HandleNameStr (val):
if sys.version_info[0] < 3:
rep = "0x%X ('%s')" % (Bytes2Val (bytearray (val)), val)
else:
rep = "0x%X ('%s')" % (Bytes2Val (bytearray (val)), str (val, 'utf-8'))
return rep
def OutputStruct (obj, indent = 0, plen = 0): def OutputStruct (obj, indent = 0, plen = 0):
if indent: if indent:
body = '' body = ''
@ -361,15 +387,19 @@ def OutputStruct (obj, indent = 0, plen = 0):
body += OutputStruct (val, indent + 1) body += OutputStruct (val, indent + 1)
plen -= sizeof(val) plen -= sizeof(val)
else: else:
if type(val) is str: if IsStrType (val):
rep = "0x%X ('%s')" % (Bytes2Val(bytearray(val)), val) rep = HandleNameStr (val)
elif type(val) in (int, long): elif IsIntegerType (val):
rep = '0x%X' % val rep = '0x%X' % val
elif isinstance(val, c_uint24): elif isinstance(val, c_uint24):
rep = '0x%X' % val.get_value() rep = '0x%X' % val.get_value()
elif 'c_ubyte_Array' in str(type(val)): elif 'c_ubyte_Array' in str(type(val)):
if sizeof(val) == 16: if sizeof(val) == 16:
rep = str(uuid.UUID(bytes = str(bytearray(val)))).upper() if sys.version_info[0] < 3:
rep = str(bytearray(val))
else:
rep = bytes(val)
rep = str(uuid.UUID(bytes_le = rep)).upper()
else: else:
res = ['0x%02X'%i for i in bytearray(val)] res = ['0x%02X'%i for i in bytearray(val)]
rep = '[%s]' % (','.join(res)) rep = '[%s]' % (','.join(res))
@ -487,7 +517,7 @@ class FirmwareDevice:
self.FvList = [] self.FvList = []
while offset < fdsize: while offset < fdsize:
fvh = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FdData, offset) fvh = EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FdData, offset)
if '_FVH' != fvh.Signature: if b'_FVH' != fvh.Signature:
raise Exception("ERROR: Invalid FV header !") raise Exception("ERROR: Invalid FV header !")
fv = FirmwareVolume (offset, self.FdData[offset:offset + fvh.FvLength]) fv = FirmwareVolume (offset, self.FdData[offset:offset + fvh.FvLength])
fv.ParseFv () fv.ParseFv ()
@ -524,7 +554,7 @@ class FirmwareDevice:
fspoffset = fv.Offset fspoffset = fv.Offset
offset = fspoffset + fihoffset offset = fspoffset + fihoffset
fih = FSP_INFORMATION_HEADER.from_buffer (self.FdData, offset) fih = FSP_INFORMATION_HEADER.from_buffer (self.FdData, offset)
if 'FSPH' != fih.Signature: if b'FSPH' != fih.Signature:
continue continue
offset += fih.HeaderLength offset += fih.HeaderLength
@ -532,7 +562,7 @@ class FirmwareDevice:
plist = [] plist = []
while True: while True:
fch = FSP_COMMON_HEADER.from_buffer (self.FdData, offset) fch = FSP_COMMON_HEADER.from_buffer (self.FdData, offset)
if 'FSPP' != fch.Signature: if b'FSPP' != fch.Signature:
offset += fch.HeaderLength offset += fch.HeaderLength
offset = AlignPtr(offset, 4) offset = AlignPtr(offset, 4)
else: else:
@ -557,9 +587,9 @@ class PeTeImage:
def __init__(self, offset, data): def __init__(self, offset, data):
self.Offset = offset self.Offset = offset
tehdr = EFI_TE_IMAGE_HEADER.from_buffer (data, 0) 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 self.TeHdr = tehdr
elif tehdr.Signature == 'MZ': # PE image elif tehdr.Signature == b'MZ': # PE image
self.TeHdr = None self.TeHdr = None
self.DosHdr = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0) self.DosHdr = EFI_IMAGE_DOS_HEADER.from_buffer (data, 0)
self.PeHdr = EFI_IMAGE_NT_HEADERS32.from_buffer (data, self.DosHdr.e_lfanew) self.PeHdr = EFI_IMAGE_NT_HEADERS32.from_buffer (data, self.DosHdr.e_lfanew)
@ -604,7 +634,7 @@ class PeTeImage:
offset += sizeof(blkhdr) offset += sizeof(blkhdr)
# Read relocation type,offset pairs # Read relocation type,offset pairs
rlen = blkhdr.BlockSize - sizeof(PE_RELOC_BLOCK_HEADER) rlen = blkhdr.BlockSize - sizeof(PE_RELOC_BLOCK_HEADER)
rnum = rlen/sizeof(c_uint16) rnum = int (rlen/sizeof(c_uint16))
rdata = (c_uint16 * rnum).from_buffer(self.Data, offset) rdata = (c_uint16 * rnum).from_buffer(self.Data, offset)
for each in rdata: for each in rdata:
roff = each & 0xfff roff = each & 0xfff
@ -666,8 +696,11 @@ def ShowFspInfo (fspfile):
if not name: if not name:
name = '\xff' * 16 name = '\xff' * 16
else: else:
if sys.version_info[0] < 3:
name = str(bytearray(name)) name = str(bytearray(name))
guid = uuid.UUID(bytes = name) else:
name = bytes(name)
guid = uuid.UUID(bytes_le = name)
print ("FV%d:" % idx) print ("FV%d:" % idx)
print (" GUID : %s" % str(guid).upper()) print (" GUID : %s" % str(guid).upper())
print (" Offset : 0x%08X" % fv.Offset) print (" Offset : 0x%08X" % fv.Offset)
@ -695,7 +728,10 @@ def GenFspHdr (fspfile, outdir, hfile):
for fsp in fd.FspList: for fsp in fd.FspList:
fih = fsp.Fih fih = fsp.Fih
if firstfv: if firstfv:
if sys.version_info[0] < 3:
hfsp.write("#define FSP_IMAGE_ID 0x%016X /* '%s' */\n" % (Bytes2Val(bytearray(fih.ImageId)), fih.ImageId)) hfsp.write("#define FSP_IMAGE_ID 0x%016X /* '%s' */\n" % (Bytes2Val(bytearray(fih.ImageId)), fih.ImageId))
else:
hfsp.write("#define FSP_IMAGE_ID 0x%016X /* '%s' */\n" % (Bytes2Val(bytearray(fih.ImageId)), str (fih.ImageId, 'utf-8')))
hfsp.write("#define FSP_IMAGE_REV 0x%08X \n\n" % fih.ImageRevision) hfsp.write("#define FSP_IMAGE_REV 0x%08X \n\n" % fih.ImageRevision)
firstfv = False firstfv = False
fv = fd.FvList[fsp.FvIdxList[0]] fv = fd.FvList[fsp.FvIdxList[0]]
@ -733,7 +769,7 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
numcomp = len(FspComponent) numcomp = len(FspComponent)
baselist = FspBase baselist = FspBase
if numcomp != len(baselist): if numcomp != len(baselist):
print "ERROR: Required number of base does not match number of FSP component !" print ("ERROR: Required number of base does not match number of FSP component !")
return return
newfspbin = fd.FdData[:] newfspbin = fd.FdData[:]
@ -753,7 +789,7 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
break break
if not found: if not found:
print "ERROR: Could not find FSP_%c component to rebase !" % fspcomp.upper() print ("ERROR: Could not find FSP_%c component to rebase !" % fspcomp.upper())
return return
fspbase = baselist[idx] fspbase = baselist[idx]
@ -763,7 +799,7 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
newbase = int(fspbase) newbase = int(fspbase)
oldbase = fsp.Fih.ImageBase oldbase = fsp.Fih.ImageBase
delta = newbase - oldbase delta = newbase - oldbase
print "Rebase FSP-%c from 0x%08X to 0x%08X:" % (ftype.upper(),oldbase,newbase) print ("Rebase FSP-%c from 0x%08X to 0x%08X:" % (ftype.upper(),oldbase,newbase))
imglist = [] imglist = []
for fvidx in fsp.FvIdxList: for fvidx in fsp.FvIdxList:
@ -782,12 +818,12 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, OutputFile):
pcount += img.Rebase(delta, newfspbin) pcount += img.Rebase(delta, newfspbin)
fcount += 1 fcount += 1
print " Patched %d entries in %d TE/PE32 images." % (pcount, fcount) print (" Patched %d entries in %d TE/PE32 images." % (pcount, fcount))
(count, applied) = fsp.Patch(delta, newfspbin) (count, applied) = fsp.Patch(delta, newfspbin)
print " Patched %d entries using FSP patch table." % applied print (" Patched %d entries using FSP patch table." % applied)
if count != applied: if count != applied:
print " %d invalid entries are ignored !" % (count - applied) print (" %d invalid entries are ignored !" % (count - applied))
if OutputFile == '': if OutputFile == '':
filename = os.path.basename(FspBinary) filename = os.path.basename(FspBinary)