From: Feng, Bob C Date: Wed, 23 Jan 2019 01:29:52 +0000 (+0800) Subject: BaseTools:ord() don't match in py2 and py3 X-Git-Tag: edk2-stable201903~208 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=7fa0e68afd658bda001aaccf616837a4a493a385 BaseTools:ord() don't match in py2 and py3 In python2, the FvHeaderBuffer Type is a str In python3, the FvHeaderBuffer Type is a bytes Cc: Bob Feng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan Tested-by: Laszlo Ersek Tested-by: Ard Biesheuvel Reviewed-by: Liming Gao Reviewed-by: Bob Feng --- diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py index 535b86ab5e..7ea931e1b5 100644 --- a/BaseTools/Source/Python/GenFds/FvImageSection.py +++ b/BaseTools/Source/Python/GenFds/FvImageSection.py @@ -71,7 +71,10 @@ class FvImageSection(FvImageSectionClassObject): # PI FvHeader is 0x48 byte FvHeaderBuffer = FvFileObj.read(0x48) # FV alignment position. - FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F) + if isinstance(FvHeaderBuffer[0x2E], str): + FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F) + else: + FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F) FvFileObj.close() if FvAlignmentValue > MaxFvAlignment: MaxFvAlignment = FvAlignmentValue @@ -121,7 +124,10 @@ class FvImageSection(FvImageSectionClassObject): # PI FvHeader is 0x48 byte FvHeaderBuffer = FvFileObj.read(0x48) # FV alignment position. - FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F) + if isinstance(FvHeaderBuffer[0x2E], str): + FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F) + else: + FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F) # FvAlignmentValue is larger than or equal to 1K if FvAlignmentValue >= 0x400: if FvAlignmentValue >= 0x100000: