In python2, the FvHeaderBuffer Type is a str
In python3, the FvHeaderBuffer Type is a bytes

Cc: Bob Feng <bob.c.f...@intel.com>
Cc: Liming Gao <liming....@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux....@intel.com>
---
 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
@@ -69,11 +69,14 @@ class FvImageSection(FvImageSectionClassObject):
                     FvFileObj = open (FvFileName, 'rb')
                     FvFileObj.seek(0)
                     # 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
 
                 OutputFile = os.path.join(OutputPath, ModuleName + 
SUP_MODULE_SEC + Num + SectionSuffix.get("FV_IMAGE"))
@@ -119,11 +122,14 @@ class FvImageSection(FvImageSectionClassObject):
                         FvFileObj = open (FvFileName, 'rb')
                         FvFileObj.seek(0)
                         # 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:
                                 #The max alignment supported by FFS is 16M.
                                 if FvAlignmentValue >= 0x1000000:
-- 
2.20.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to