BaseTools/GenFds: factor out Region.PadBuffer() method

The same logic is used in five places; factor it out to a common method.

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Laszlo Ersek 2016-07-11 16:17:23 +02:00
parent 0f65154396
commit 5588565f48
1 changed files with 24 additions and 34 deletions

View File

@ -39,6 +39,25 @@ class Region(RegionClassObject):
RegionClassObject.__init__(self) RegionClassObject.__init__(self)
## PadBuffer()
#
# Add padding bytes to the Buffer
#
# @param Buffer The buffer the generated region data will be put
# in
# @param ErasePolarity Flash erase polarity
# @param Size Number of padding bytes requested
#
def PadBuffer(self, Buffer, ErasePolarity, Size):
if Size > 0:
if (ErasePolarity == '1') :
PadData = 0xFF
else:
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
## AddToBuffer() ## AddToBuffer()
# #
# Add region data to the Buffer # Add region data to the Buffer
@ -135,13 +154,7 @@ class Region(RegionClassObject):
# #
# Pad the left buffer # Pad the left buffer
# #
if Size > 0: self.PadBuffer(Buffer, ErasePolarity, Size)
if (ErasePolarity == '1') :
PadData = 0xFF
else :
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
if self.RegionType == 'CAPSULE': if self.RegionType == 'CAPSULE':
# #
@ -194,13 +207,7 @@ class Region(RegionClassObject):
# #
# Pad the left buffer # Pad the left buffer
# #
if Size > 0: self.PadBuffer(Buffer, ErasePolarity, Size)
if (ErasePolarity == '1') :
PadData = 0xFF
else :
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
if self.RegionType in ('FILE', 'INF'): if self.RegionType in ('FILE', 'INF'):
for RegionData in self.RegionDataList: for RegionData in self.RegionDataList:
@ -232,13 +239,7 @@ class Region(RegionClassObject):
# #
# Pad the left buffer # Pad the left buffer
# #
if Size > 0: self.PadBuffer(Buffer, ErasePolarity, Size)
if (ErasePolarity == '1') :
PadData = 0xFF
else :
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
if self.RegionType == 'DATA' : if self.RegionType == 'DATA' :
GenFdsGlobalVariable.InfLogger(' Region Name = DATA') GenFdsGlobalVariable.InfLogger(' Region Name = DATA')
@ -255,22 +256,11 @@ class Region(RegionClassObject):
# #
# Pad the left buffer # Pad the left buffer
# #
if Size > 0: self.PadBuffer(Buffer, ErasePolarity, Size)
if (ErasePolarity == '1') :
PadData = 0xFF
else :
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
if self.RegionType == None: if self.RegionType == None:
GenFdsGlobalVariable.InfLogger(' Region Name = None') GenFdsGlobalVariable.InfLogger(' Region Name = None')
if (ErasePolarity == '1') : self.PadBuffer(Buffer, ErasePolarity, Size)
PadData = 0xFF
else :
PadData = 0
for i in range(0, Size):
Buffer.write(pack('B', PadData))
def GetFvAlignValue(self, Str): def GetFvAlignValue(self, Str):
AlignValue = 1 AlignValue = 1