From: Zhijux Fan <zhijux....@intel.com>

PEP 238 -- Changing the Division Operator
x/y to return a reasonable approximation of the mathematical result
    of the division ("true division")
x//y to return the floor ("floor division")

Cc: Bob Feng <bob.c.f...@intel.com>
Cc: Liming Gao <liming....@intel.com>
Cc: Yonghong Zhu <yonghong....@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux....@intel.com>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py             |  2 +-
 BaseTools/Source/Python/AutoGen/GenC.py                |  8 ++++----
 BaseTools/Source/Python/BPDG/GenVpd.py                 |  8 ++++----
 BaseTools/Source/Python/Common/Expression.py           |  9 ++++++++-
 BaseTools/Source/Python/Common/Misc.py                 |  6 +++---
 BaseTools/Source/Python/GenFds/DataSection.py          |  4 ++--
 BaseTools/Source/Python/GenFds/EfiSection.py           |  4 ++--
 BaseTools/Source/Python/GenFds/FfsInfStatement.py      |  8 ++++----
 BaseTools/Source/Python/GenFds/Fv.py                   |  4 ++--
 BaseTools/Source/Python/GenFds/FvImageSection.py       | 10 +++++-----
 BaseTools/Source/Python/GenFds/GenFds.py               |  2 +-
 BaseTools/Source/Python/GenFds/Region.py               |  4 ++--
 BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py |  4 ++--
 BaseTools/Source/Python/build/build.py                 | 18 +++++++++---------
 14 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index f9ce17cf77..5f0da5a815 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -3812,11 +3812,11 @@ class ModuleAutoGen(AutoGen):
                             else:
                                 NewValue = NewValue + '0x%02x' % 
(ord(PcdValue[Index]) % 0x100) + ', '
                         Padding = '0x00, '
                         if Unicode:
                             Padding = Padding * 2
-                            ArraySize = ArraySize / 2
+                            ArraySize = ArraySize // 2
                         if ArraySize < (len(PcdValue) + 1):
                             if Pcd.MaxSizeUserSet:
                                 EdkLogger.error("build", AUTOGEN_ERROR,
                                             "The maximum size of VOID* type 
PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, 
TokenCName)
                                             )
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py 
b/BaseTools/Source/Python/AutoGen/GenC.py
index 915ba2e235..e46942a3e2 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1051,21 +1051,21 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                     if Unicode:
                         NewValue = NewValue + str(ord(Value[Index]) % 0x10000) 
+ ', '
                     else:
                         NewValue = NewValue + str(ord(Value[Index]) % 0x100) + 
', '
                 if Unicode:
-                    ArraySize = ArraySize / 2
+                    ArraySize = ArraySize // 2
                 Value = NewValue + '0 }'
             if ArraySize < ValueSize:
                 if Pcd.MaxSizeUserSet:
                     EdkLogger.error("build", AUTOGEN_ERROR,
                                 "The maximum size of VOID* type PCD '%s.%s' is 
less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
                                 ExtraData="[%s]" % str(Info))
                 else:
                     ArraySize = Pcd.GetPcdSize()
                     if Unicode:
-                        ArraySize = ArraySize / 2
+                        ArraySize = ArraySize // 2
             Array = '[%d]' % ArraySize
         #
         # skip casting for fixed at build since it breaks ARM assembly.
         # Long term we need PCD macros that work in assembly
         #
@@ -1904,20 +1904,20 @@ def BmpImageDecoder(File, Buffer, PaletteIndex, 
TransParent):
         if TransParent:
             ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)
         else:
             ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)
         ImageBuffer += pack('B', PaletteIndex)
-        Width = (BmpHeader.biWidth + 7)/8
+        Width = (BmpHeader.biWidth + 7)//8
         if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
             PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : 
BmpHeader.bfOffBits]
     elif BmpHeader.biBitCount == 4:
         if TransParent:
             ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)
         else:
             ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)
         ImageBuffer += pack('B', PaletteIndex)
-        Width = (BmpHeader.biWidth + 1)/2
+        Width = (BmpHeader.biWidth + 1)//2
         if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
             PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : 
BmpHeader.bfOffBits]
     elif BmpHeader.biBitCount == 8:
         if TransParent:
             ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py 
b/BaseTools/Source/Python/BPDG/GenVpd.py
index 71fcfc5ac3..b4a2dd25a2 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -429,11 +429,11 @@ class GenVPD :
                             EdkLogger.warn("BPDG", "The offset value of PCD %s 
is not 8-byte aligned!" %(PCD.PcdCName), File=self.InputFileName)
                         else:
                             EdkLogger.error("BPDG", 
BuildToolError.FORMAT_INVALID, 'The offset value of PCD %s should be %s-byte 
aligned.' % (PCD.PcdCName, Alignment))
                 else:
                     if PCD.PcdOccupySize % Alignment != 0:
-                        PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 
1) * Alignment
+                        PCD.PcdOccupySize = (PCD.PcdOccupySize // Alignment + 
1) * Alignment
 
                 PackSize = PCD.PcdOccupySize
                 if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):
                     PCD._PackBooleanValue(PCD.PcdValue)
                     self.FileLinesList[count] = PCD
@@ -507,11 +507,11 @@ class GenVPD :
         if (len(self.PcdFixedOffsetSizeList) == 0) and 
(len(self.PcdUnknownOffsetList) != 0) :
             # The offset start from 0
             NowOffset = 0
             for Pcd in self.PcdUnknownOffsetList :
                 if NowOffset % Pcd.Alignment != 0:
-                    NowOffset = (NowOffset/ Pcd.Alignment + 1) * Pcd.Alignment
+                    NowOffset = (NowOffset// Pcd.Alignment + 1) * Pcd.Alignment
                 Pcd.PcdBinOffset = NowOffset
                 Pcd.PcdOffset    = str(hex(Pcd.PcdBinOffset))
                 NowOffset       += Pcd.PcdOccupySize
 
             self.PcdFixedOffsetSizeList = self.PcdUnknownOffsetList
@@ -571,11 +571,11 @@ class GenVPD :
                         eachUnfixedPcd      = 
self.PcdUnknownOffsetList[countOfUnfixedList]
                         needFixPcdSize      = eachUnfixedPcd.PcdOccupySize
                         # Not been fixed
                         if eachUnfixedPcd.PcdOffset == TAB_STAR :
                             if LastOffset % eachUnfixedPcd.Alignment != 0:
-                                LastOffset = (LastOffset / 
eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment
+                                LastOffset = (LastOffset // 
eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment
                             # The offset un-fixed pcd can write into this free 
space
                             if needFixPcdSize <= (NowOffset - LastOffset) :
                                 # Change the offset value of un-fixed pcd
                                 eachUnfixedPcd.PcdOffset    = 
str(hex(LastOffset))
                                 eachUnfixedPcd.PcdBinOffset = LastOffset
@@ -625,11 +625,11 @@ class GenVPD :
             LastPcd    = self.PcdFixedOffsetSizeList[lenOfList-1]
             NeedFixPcd = self.PcdUnknownOffsetList[0]
 
             NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + 
LastPcd.PcdOccupySize
             if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:
-                NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / 
NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
+                NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset // 
NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment
 
             NeedFixPcd.PcdOffset    = str(hex(NeedFixPcd.PcdBinOffset))
 
             # Insert this pcd into fixed offset pcd list's tail.
             self.PcdFixedOffsetSizeList.insert(lenOfList, NeedFixPcd)
diff --git a/BaseTools/Source/Python/Common/Expression.py 
b/BaseTools/Source/Python/Common/Expression.py
index 19ea13b7fb..0c7e25b445 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -437,10 +437,17 @@ class ValueExpression(BaseExpression):
                 if Val:
                     Val = Val2
                 else:
                     Val = Val3
                 continue
+            #
+            # PEP 238 -- Changing the Division Operator
+            # x/y to return a reasonable approximation of the mathematical 
result of the division ("true division")
+            # x//y to return the floor ("floor division")
+            #
+            if Op == '/':
+                Op = '//'
             try:
                 Val = self.Eval(Op, Val, EvalFunc())
             except WrnExpression as Warn:
                 self._WarnExcept = Warn
                 Val = Warn.result
@@ -910,11 +917,11 @@ class ValueExpressionEx(ValueExpression):
                         TmpValue = int(PcdValue)
                         TmpList = []
                         if TmpValue.bit_length() == 0:
                             PcdValue = '{0x00}'
                         else:
-                            for I in range((TmpValue.bit_length() + 7) / 8):
+                            for I in range((TmpValue.bit_length() + 7) // 8):
                                 TmpList.append('0x%02x' % ((TmpValue >> I * 8) 
& 0xff))
                             PcdValue = '{' + ', '.join(TmpList) + '}'
                     except:
                         if PcdValue.strip().startswith('{'):
                             PcdValueList = 
SplitPcdValueString(PcdValue.strip()[1:-1])
diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index 4c7eb449ca..1bc3ba60ea 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1088,11 +1088,11 @@ def ParseDevPathValue (Value):
 
 def ParseFieldValue (Value):
     if "{CODE(" in Value:
         return Value, len(Value.split(","))
     if isinstance(Value, type(0)):
-        return Value, (Value.bit_length() + 7) / 8
+        return Value, (Value.bit_length() + 7) // 8
     if not isinstance(Value, type('')):
         raise BadExpression('Type %s is %s' %(Value, type(Value)))
     Value = Value.strip()
     if Value.startswith(TAB_UINT8) and Value.endswith(')'):
         Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])
@@ -1209,16 +1209,16 @@ def ParseFieldValue (Value):
             Value = int(Value, 16)
         except:
             raise BadExpression("invalid hex value: %s" % Value)
         if Value == 0:
             return 0, 1
-        return Value, (Value.bit_length() + 7) / 8
+        return Value, (Value.bit_length() + 7) // 8
     if Value[0].isdigit():
         Value = int(Value, 10)
         if Value == 0:
             return 0, 1
-        return Value, (Value.bit_length() + 7) / 8
+        return Value, (Value.bit_length() + 7) // 8
     if Value.lower() == 'true':
         return 1, 1
     if Value.lower() == 'false':
         return 0, 1
     return Value, 1
diff --git a/BaseTools/Source/Python/GenFds/DataSection.py 
b/BaseTools/Source/Python/GenFds/DataSection.py
index 28f9b931ca..989e33c43f 100644
--- a/BaseTools/Source/Python/GenFds/DataSection.py
+++ b/BaseTools/Source/Python/GenFds/DataSection.py
@@ -86,13 +86,13 @@ class DataSection (DataSectionClassObject):
         if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, 
BINARY_FILE_TYPE_PE32):
             ImageObj = PeImageClass (Filename)
             if ImageObj.SectionAlignment < 0x400:
                 self.Alignment = str (ImageObj.SectionAlignment)
             elif ImageObj.SectionAlignment < 0x100000:
-                self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
+                self.Alignment = str (ImageObj.SectionAlignment // 0x400) + 'K'
             else:
-                self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 
'M'
+                self.Alignment = str (ImageObj.SectionAlignment // 0x100000) + 
'M'
 
         NoStrip = True
         if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
             if self.KeepReloc is not None:
                 NoStrip = self.KeepReloc
diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py 
b/BaseTools/Source/Python/GenFds/EfiSection.py
index 0be176ec8a..dfb2470874 100644
--- a/BaseTools/Source/Python/GenFds/EfiSection.py
+++ b/BaseTools/Source/Python/GenFds/EfiSection.py
@@ -246,13 +246,13 @@ class EfiSection (EfiSectionClassObject):
                     if self.Alignment == 'Auto' and (SectionType == 
BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
                         ImageObj = PeImageClass (File)
                         if ImageObj.SectionAlignment < 0x400:
                             Align = str (ImageObj.SectionAlignment)
                         elif ImageObj.SectionAlignment < 0x100000:
-                            Align = str (ImageObj.SectionAlignment / 0x400) + 
'K'
+                            Align = str (ImageObj.SectionAlignment // 0x400) + 
'K'
                         else:
-                            Align = str (ImageObj.SectionAlignment / 0x100000) 
+ 'M'
+                            Align = str (ImageObj.SectionAlignment // 
0x100000) + 'M'
 
                     if File[(len(File)-4):] == '.efi':
                         MapFile = File.replace('.efi', '.map')
                         CopyMapFile = os.path.join(OutputPath, ModuleName + 
'.map')
                         if IsMakefile:
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py 
b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 4dda3cf787..a7298a6daf 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -770,13 +770,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
                 if self.Alignment == 'Auto' and (SectionType == 
BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
                     ImageObj = PeImageClass (File)
                     if ImageObj.SectionAlignment < 0x400:
                         self.Alignment = str (ImageObj.SectionAlignment)
                     elif ImageObj.SectionAlignment < 0x100000:
-                        self.Alignment = str (ImageObj.SectionAlignment / 
0x400) + 'K'
+                        self.Alignment = str (ImageObj.SectionAlignment // 
0x400) + 'K'
                     else:
-                        self.Alignment = str (ImageObj.SectionAlignment / 
0x100000) + 'M'
+                        self.Alignment = str (ImageObj.SectionAlignment // 
0x100000) + 'M'
 
                 if not NoStrip:
                     FileBeforeStrip = os.path.join(self.OutputPath, ModuleName 
+ '.reloc')
                     if not os.path.exists(FileBeforeStrip) or \
                            (os.path.getmtime(File) > 
os.path.getmtime(FileBeforeStrip)):
@@ -812,13 +812,13 @@ class FfsInfStatement(FfsInfStatementClassObject):
             if self.Alignment == 'Auto' and (SectionType == 
BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE):
                 ImageObj = PeImageClass (GenSecInputFile)
                 if ImageObj.SectionAlignment < 0x400:
                     self.Alignment = str (ImageObj.SectionAlignment)
                 elif ImageObj.SectionAlignment < 0x100000:
-                    self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 
'K'
+                    self.Alignment = str (ImageObj.SectionAlignment // 0x400) 
+ 'K'
                 else:
-                    self.Alignment = str (ImageObj.SectionAlignment / 
0x100000) + 'M'
+                    self.Alignment = str (ImageObj.SectionAlignment // 
0x100000) + 'M'
 
             if not NoStrip:
                 FileBeforeStrip = os.path.join(self.OutputPath, ModuleName + 
'.reloc')
                 if not os.path.exists(FileBeforeStrip) or \
                        (os.path.getmtime(GenSecInputFile) > 
os.path.getmtime(FileBeforeStrip)):
diff --git a/BaseTools/Source/Python/GenFds/Fv.py 
b/BaseTools/Source/Python/GenFds/Fv.py
index bd5c259348..b141d44dc4 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -220,13 +220,13 @@ class FV (object):
                         if FvAlignmentValue >= 0x100000:
                             if FvAlignmentValue >= 0x1000000:
                             #The max alignment supported by FFS is 16M.
                                 self.FvAlignment = "16M"
                             else:
-                                self.FvAlignment = str(FvAlignmentValue / 
0x100000) + "M"
+                                self.FvAlignment = str(FvAlignmentValue // 
0x100000) + "M"
                         else:
-                            self.FvAlignment = str(FvAlignmentValue / 0x400) + 
"K"
+                            self.FvAlignment = str(FvAlignmentValue // 0x400) 
+ "K"
                     else:
                         # FvAlignmentValue is less than 1K
                         self.FvAlignment = str (FvAlignmentValue)
                     FvFileObj.close()
                     GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 
'fv'] = FvOutputFile
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py 
b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 7f277ddef2..535b86ab5e 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -69,11 +69,11 @@ 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)
+                    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"))
@@ -85,13 +85,13 @@ class FvImageSection(FvImageSectionClassObject):
                 if MaxFvAlignment >= 0x100000:
                     #The max alignment supported by FFS is 16M.
                     if MaxFvAlignment >= 0x1000000:
                         self.Alignment = "16M"
                     else:
-                        self.Alignment = str(MaxFvAlignment / 0x100000) + "M"
+                        self.Alignment = str(MaxFvAlignment // 0x100000) + "M"
                 else:
-                    self.Alignment = str (MaxFvAlignment / 0x400) + "K"
+                    self.Alignment = str (MaxFvAlignment // 0x400) + "K"
             else:
                 # MaxFvAlignment is less than 1K
                 self.Alignment = str (MaxFvAlignment)
 
             return OutputFileList, self.Alignment
@@ -127,13 +127,13 @@ class FvImageSection(FvImageSectionClassObject):
                             if FvAlignmentValue >= 0x100000:
                                 #The max alignment supported by FFS is 16M.
                                 if FvAlignmentValue >= 0x1000000:
                                     self.Alignment = "16M"
                                 else:
-                                    self.Alignment = str(FvAlignmentValue / 
0x100000) + "M"
+                                    self.Alignment = str(FvAlignmentValue // 
0x100000) + "M"
                             else:
-                                self.Alignment = str (FvAlignmentValue / 
0x400) + "K"
+                                self.Alignment = str (FvAlignmentValue // 
0x400) + "K"
                         else:
                             # FvAlignmentValue is less than 1K
                             self.Alignment = str (FvAlignmentValue)
                         FvFileObj.close()
                     else:
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py 
b/BaseTools/Source/Python/GenFds/GenFds.py
index f1ce527f88..2efb2edd9a 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -749,11 +749,11 @@ class GenFds(object):
                             for File in MatchDict['.ui']:
                                 with open(os.path.join(FfsPath[0], File), 
'rb') as F:
                                     F.read()
                                     length = F.tell()
                                     F.seek(4)
-                                    TmpStr = unpack('%dh' % ((length - 4) / 
2), F.read())
+                                    TmpStr = unpack('%dh' % ((length - 4) // 
2), F.read())
                                     Name = ''.join(chr(c) for c in TmpStr[:-1])
                         else:
                             FileList = []
                             if 'fv.sec.txt' in MatchDict:
                                 FileList = MatchDict['fv.sec.txt']
diff --git a/BaseTools/Source/Python/GenFds/Region.py 
b/BaseTools/Source/Python/GenFds/Region.py
index acc9dea413..83363276d2 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -298,20 +298,20 @@ class Region(object):
                 continue
             # region located in current blocks
             else:
                 # region ended within current blocks
                 if self.Offset + self.Size <= End:
-                    ExpectedList.append((BlockSize, (RemindingSize + BlockSize 
- 1) / BlockSize))
+                    ExpectedList.append((BlockSize, (RemindingSize + BlockSize 
- 1) // BlockSize))
                     break
                 # region not ended yet
                 else:
                     # region not started in middle of current blocks
                     if self.Offset <= Start:
                         UsedBlockNum = BlockNum
                     # region started in middle of current blocks
                     else:
-                        UsedBlockNum = (End - self.Offset) / BlockSize
+                        UsedBlockNum = (End - self.Offset) // BlockSize
                     Start = End
                     ExpectedList.append((BlockSize, UsedBlockNum))
                     RemindingSize -= BlockSize * UsedBlockNum
 
         if FvObj.BlockSizeList == []:
diff --git a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py 
b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
index 8e243aea96..0be5eba492 100644
--- a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
+++ b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
@@ -131,11 +131,11 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, 
ValueString, MaxSize=0):
         #
         # Set PCD value into binary data
         #
         for Index in range(ValueLength):
             ByteList[ValueOffset + Index] = ValueNumber % 0x100
-            ValueNumber = ValueNumber / 0x100
+            ValueNumber = ValueNumber // 0x100
     elif TypeName == TAB_VOID:
         ValueString = SavedStr
         if ValueString.startswith('L"'):
             #
             # Patch Unicode String
@@ -146,11 +146,11 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, 
ValueString, MaxSize=0):
                 # Reserve zero as unicode tail
                 #
                 if Index + 2 >= ValueLength:
                     break
                 #
-                # Set string value one by one
+                # Set string value one by one/ 0x100
                 #
                 ByteList[ValueOffset + Index] = ord(ByteString)
                 Index = Index + 2
         elif ValueString.startswith("{") and ValueString.endswith("}"):
             #
diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index b7aefc9ae7..e4dc9664f6 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -699,11 +699,11 @@ class PeImageInfo():
         self.Guid             = Guid
         self.Arch             = Arch
         self.OutputDir        = OutputDir
         self.DebugDir         = DebugDir
         self.Image            = ImageClass
-        self.Image.Size       = (self.Image.Size / 0x1000 + 1) * 0x1000
+        self.Image.Size       = (self.Image.Size // 0x1000 + 1) * 0x1000
 
 ## The class implementing the EDK2 build process
 #
 #   The build process includes:
 #       1. Load configuration from target.txt and tools_def.txt in 
$(WORKSPACE)/Conf
@@ -1617,25 +1617,25 @@ class Build():
             # Patch real PCD value by PatchPcdValue tool
             #
             for PcdInfo in PcdTable:
                 ReturnValue = 0
                 if PcdInfo[0] == 
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str 
(PeiSize / 0x1000))
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str 
(PeiSize // 0x1000))
                 elif PcdInfo[0] == 
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str 
(BtSize / 0x1000))
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str 
(BtSize // 0x1000))
                 elif PcdInfo[0] == 
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, 
str (RtSize / 0x1000))
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, 
str (RtSize // 0x1000))
                 elif PcdInfo[0] == 
TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:
-                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str 
(SmmSize / 0x1000))
+                    ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, 
PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str 
(SmmSize // 0x1000))
                 if ReturnValue != 0:
                     EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD 
value failed", ExtraData=ErrorInfo)
 
-        MapBuffer.write('PEI_CODE_PAGE_NUMBER      = 0x%x\n' % (PeiSize / 
0x1000))
-        MapBuffer.write('BOOT_CODE_PAGE_NUMBER     = 0x%x\n' % (BtSize / 
0x1000))
-        MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER  = 0x%x\n' % (RtSize / 
0x1000))
+        MapBuffer.write('PEI_CODE_PAGE_NUMBER      = 0x%x\n' % (PeiSize // 
0x1000))
+        MapBuffer.write('BOOT_CODE_PAGE_NUMBER     = 0x%x\n' % (BtSize // 
0x1000))
+        MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER  = 0x%x\n' % (RtSize // 
0x1000))
         if len (SmmModuleList) > 0:
-            MapBuffer.write('SMM_CODE_PAGE_NUMBER      = 0x%x\n' % (SmmSize / 
0x1000))
+            MapBuffer.write('SMM_CODE_PAGE_NUMBER      = 0x%x\n' % (SmmSize // 
0x1000))
 
         PeiBaseAddr = TopMemoryAddress - RtSize - BtSize
         BtBaseAddr  = TopMemoryAddress - RtSize
         RtBaseAddr  = TopMemoryAddress - ReservedRuntimeMemorySize
 
-- 
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