BaseTools: Handle the bytes and str difference
Deal with bytes and str is different, remove the unicode() Using utcfromtimestamp instead of fromtimestamp. Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
a09f4c91f7
commit
86e6cf98a8
@@ -51,7 +51,7 @@ class AprioriSection (AprioriSectionClassObject):
|
||||
def GenFfs (self, FvName, Dict = {}, IsMakefile = False):
|
||||
DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"
|
||||
PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"
|
||||
Buffer = BytesIO('')
|
||||
Buffer = BytesIO()
|
||||
AprioriFileGuid = DXE_GUID
|
||||
if self.AprioriType == "PEI":
|
||||
AprioriFileGuid = PEI_GUID
|
||||
|
@@ -21,6 +21,7 @@ from CommonDataClass.FdfClass import CapsuleClassObject
|
||||
import Common.LongFilePathOs as os
|
||||
import subprocess
|
||||
from io import BytesIO
|
||||
from io import StringIO
|
||||
from Common.Misc import SaveFileOnChange
|
||||
from Common.Misc import PackRegistryFormatGuid
|
||||
import uuid
|
||||
@@ -184,7 +185,7 @@ class Capsule (CapsuleClassObject) :
|
||||
#
|
||||
# The real capsule header structure is 28 bytes
|
||||
#
|
||||
Header.write('\x00'*(HdrSize-28))
|
||||
Header.write(b'\x00'*(HdrSize-28))
|
||||
Header.write(FwMgrHdr.getvalue())
|
||||
Header.write(Content.getvalue())
|
||||
#
|
||||
@@ -246,7 +247,7 @@ class Capsule (CapsuleClassObject) :
|
||||
def GenCapInf(self):
|
||||
self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
|
||||
self.UiCapsuleName + "_Cap" + '.inf')
|
||||
CapInfFile = BytesIO() #open (self.CapInfFileName , 'w+')
|
||||
CapInfFile = StringIO() #open (self.CapInfFileName , 'w+')
|
||||
|
||||
CapInfFile.writelines("[options]" + T_CHAR_LF)
|
||||
|
||||
|
@@ -82,7 +82,7 @@ class CapsuleFv (CapsuleData):
|
||||
if self.FvName.find('.fv') == -1:
|
||||
if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:
|
||||
FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()]
|
||||
FdBuffer = BytesIO('')
|
||||
FdBuffer = BytesIO()
|
||||
FvObj.CapsuleName = self.CapsuleName
|
||||
FvFile = FvObj.AddToBuffer(FdBuffer)
|
||||
FvObj.CapsuleName = None
|
||||
|
@@ -74,7 +74,7 @@ class FD(FDClassObject):
|
||||
HasCapsuleRegion = True
|
||||
break
|
||||
if HasCapsuleRegion:
|
||||
TempFdBuffer = BytesIO('')
|
||||
TempFdBuffer = BytesIO()
|
||||
PreviousRegionStart = -1
|
||||
PreviousRegionSize = 1
|
||||
|
||||
@@ -103,7 +103,7 @@ class FD(FDClassObject):
|
||||
GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')
|
||||
RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
|
||||
|
||||
FdBuffer = BytesIO('')
|
||||
FdBuffer = BytesIO()
|
||||
PreviousRegionStart = -1
|
||||
PreviousRegionSize = 1
|
||||
for RegionObj in self.RegionList :
|
||||
|
@@ -82,7 +82,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
Dict.update(self.DefineVarDict)
|
||||
SectionAlignments = None
|
||||
if self.FvName is not None :
|
||||
Buffer = BytesIO('')
|
||||
Buffer = BytesIO()
|
||||
if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict:
|
||||
EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))
|
||||
Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())
|
||||
@@ -99,7 +99,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
elif self.FileName is not None:
|
||||
if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':
|
||||
if isinstance(self.FileName, list) and isinstance(self.SubAlignment, list) and len(self.FileName) == len(self.SubAlignment):
|
||||
FileContent = ''
|
||||
FileContent = BytesIO()
|
||||
MaxAlignIndex = 0
|
||||
MaxAlignValue = 1
|
||||
for Index, File in enumerate(self.FileName):
|
||||
@@ -115,15 +115,15 @@ class FileStatement (FileStatementClassObject) :
|
||||
if AlignValue > MaxAlignValue:
|
||||
MaxAlignIndex = Index
|
||||
MaxAlignValue = AlignValue
|
||||
FileContent += Content
|
||||
if len(FileContent) % AlignValue != 0:
|
||||
FileContent.write(Content)
|
||||
if len(FileContent.getvalue()) % AlignValue != 0:
|
||||
Size = AlignValue - len(FileContent) % AlignValue
|
||||
for i in range(0, Size):
|
||||
FileContent += pack('B', 0xFF)
|
||||
FileContent.write(pack('B', 0xFF))
|
||||
|
||||
if FileContent:
|
||||
if FileContent.getvalue() != b'':
|
||||
OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')
|
||||
SaveFileOnChange(OutputRAWFile, FileContent, True)
|
||||
SaveFileOnChange(OutputRAWFile, FileContent.getvalue(), True)
|
||||
self.FileName = OutputRAWFile
|
||||
self.SubAlignment = self.SubAlignment[MaxAlignIndex]
|
||||
|
||||
|
@@ -1086,7 +1086,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):
|
||||
|
||||
# Use a instance of StringIO to cache data
|
||||
fStringIO = BytesIO('')
|
||||
fStringIO = BytesIO()
|
||||
|
||||
for Item in VfrUniOffsetList:
|
||||
if (Item[0].find("Strings") != -1):
|
||||
@@ -1096,8 +1096,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
# { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
|
||||
#
|
||||
UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
|
||||
UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]
|
||||
fStringIO.write(''.join(UniGuid))
|
||||
fStringIO.write(bytes(UniGuid))
|
||||
UniValue = pack ('Q', int (Item[1], 16))
|
||||
fStringIO.write (UniValue)
|
||||
else:
|
||||
@@ -1107,8 +1106,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
|
||||
# { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
|
||||
#
|
||||
VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
|
||||
VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]
|
||||
fStringIO.write(''.join(VfrGuid))
|
||||
fStringIO.write(bytes(VfrGuid))
|
||||
type (Item[1])
|
||||
VfrValue = pack ('Q', int (Item[1], 16))
|
||||
fStringIO.write (VfrValue)
|
||||
|
@@ -18,6 +18,7 @@
|
||||
import Common.LongFilePathOs as os
|
||||
import subprocess
|
||||
from io import BytesIO
|
||||
from io import StringIO
|
||||
from struct import *
|
||||
|
||||
from . import Ffs
|
||||
@@ -204,7 +205,7 @@ class FV (FvClassObject):
|
||||
# PI FvHeader is 0x48 byte
|
||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||
# FV alignment position.
|
||||
FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)
|
||||
FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)
|
||||
if FvAlignmentValue >= 0x400:
|
||||
if FvAlignmentValue >= 0x100000:
|
||||
if FvAlignmentValue >= 0x1000000:
|
||||
@@ -264,7 +265,7 @@ class FV (FvClassObject):
|
||||
#
|
||||
self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
|
||||
self.UiFvName + '.inf')
|
||||
self.FvInfFile = BytesIO()
|
||||
self.FvInfFile = StringIO()
|
||||
|
||||
#
|
||||
# Add [Options]
|
||||
@@ -339,7 +340,7 @@ class FV (FvClassObject):
|
||||
GenFdsGlobalVariable.ErrorLogger("FV Extension Header Entries declared for %s with no FvNameGuid declaration." % (self.UiFvName))
|
||||
else:
|
||||
TotalSize = 16 + 4
|
||||
Buffer = ''
|
||||
Buffer = bytearray()
|
||||
if self.UsedSizeEnable:
|
||||
TotalSize += (4 + 4)
|
||||
## define EFI_FV_EXT_TYPE_USED_SIZE_TYPE 0x03
|
||||
@@ -366,7 +367,7 @@ class FV (FvClassObject):
|
||||
#
|
||||
Buffer += (pack('HH', (FvUiLen + 16 + 4), 0x0002)
|
||||
+ PackGUID(Guid)
|
||||
+ self.UiFvName)
|
||||
+ bytes(self.UiFvName, 'utf-8'))
|
||||
|
||||
for Index in range (0, len(self.FvExtEntryType)):
|
||||
if self.FvExtEntryType[Index] == 'FILE':
|
||||
|
@@ -98,7 +98,7 @@ class FvImageSection(FvImageSectionClassObject):
|
||||
# Generate Fv
|
||||
#
|
||||
if self.FvName is not None:
|
||||
Buffer = BytesIO('')
|
||||
Buffer = BytesIO()
|
||||
Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
|
||||
if Fv is not None:
|
||||
self.Fv = Fv
|
||||
@@ -118,7 +118,7 @@ class FvImageSection(FvImageSectionClassObject):
|
||||
# PI FvHeader is 0x48 byte
|
||||
FvHeaderBuffer = FvFileObj.read(0x48)
|
||||
# FV alignment position.
|
||||
FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
|
||||
FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)
|
||||
# FvAlignmentValue is larger than or equal to 1K
|
||||
if FvAlignmentValue >= 0x400:
|
||||
if FvAlignmentValue >= 0x100000:
|
||||
|
@@ -27,6 +27,7 @@ from Workspace.BuildClassObject import PcdClassObject
|
||||
from . import RuleComplexFile
|
||||
from .EfiSection import EfiSection
|
||||
from io import BytesIO
|
||||
from io import StringIO
|
||||
import Common.TargetTxtClassObject as TargetTxtClassObject
|
||||
import Common.ToolDefClassObject as ToolDefClassObject
|
||||
from Common.DataType import *
|
||||
@@ -454,7 +455,7 @@ class GenFds :
|
||||
return
|
||||
elif GenFds.OnlyGenerateThisFv is None:
|
||||
for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():
|
||||
Buffer = BytesIO('')
|
||||
Buffer = BytesIO()
|
||||
FvObj.AddToBuffer(Buffer)
|
||||
Buffer.close()
|
||||
|
||||
@@ -600,7 +601,7 @@ class GenFds :
|
||||
|
||||
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
|
||||
GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")
|
||||
GuidXRefFile = BytesIO('')
|
||||
GuidXRefFile = StringIO('')
|
||||
PkgGuidDict = {}
|
||||
GuidDict = {}
|
||||
ModuleList = []
|
||||
|
@@ -720,8 +720,8 @@ class GenFdsGlobalVariable:
|
||||
return
|
||||
if PopenObject.returncode != 0 or GenFdsGlobalVariable.VerboseMode or GenFdsGlobalVariable.DebugLevel != -1:
|
||||
GenFdsGlobalVariable.InfLogger ("Return Value = %d" % PopenObject.returncode)
|
||||
GenFdsGlobalVariable.InfLogger (out)
|
||||
GenFdsGlobalVariable.InfLogger (error)
|
||||
GenFdsGlobalVariable.InfLogger (out.decode(encoding='utf-8',errors='ignore'))
|
||||
GenFdsGlobalVariable.InfLogger (error.decode(encoding='utf-8', errors='ignore'))
|
||||
if PopenObject.returncode != 0:
|
||||
print("###", cmd)
|
||||
EdkLogger.error("GenFds", COMMAND_FAILURE, errorMess)
|
||||
|
@@ -57,8 +57,8 @@ class Region(RegionClassObject):
|
||||
PadByte = pack('B', 0xFF)
|
||||
else:
|
||||
PadByte = pack('B', 0)
|
||||
PadData = ''.join(PadByte for i in range(0, Size))
|
||||
Buffer.write(PadData)
|
||||
for i in range(0, Size):
|
||||
Buffer.write(PadByte)
|
||||
|
||||
## AddToBuffer()
|
||||
#
|
||||
@@ -127,7 +127,7 @@ class Region(RegionClassObject):
|
||||
if self.FvAddress % FvAlignValue != 0:
|
||||
EdkLogger.error("GenFds", GENFDS_ERROR,
|
||||
"FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment))
|
||||
FvBuffer = BytesIO('')
|
||||
FvBuffer = BytesIO()
|
||||
FvBaseAddress = '0x%X' % self.FvAddress
|
||||
BlockSize = None
|
||||
BlockNum = None
|
||||
|
Reference in New Issue
Block a user