From 7fa0e68afd658bda001aaccf616837a4a493a385 Mon Sep 17 00:00:00 2001 From: "Feng, Bob C" Date: Wed, 23 Jan 2019 09:29:52 +0800 Subject: [PATCH] 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 --- BaseTools/Source/Python/GenFds/FvImageSection.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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: -- 2.39.2