diff mbox

[edk2,1/2] BaseTools/GenFds: factor out Region.PadBuffer() method

Message ID 1468252514-9533-2-git-send-email-lersek@redhat.com
State Accepted
Commit 5588565f4845d8138888f436218bc8334c0be54f
Headers show

Commit Message

Laszlo Ersek July 11, 2016, 3:55 p.m. UTC
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>

---
 BaseTools/Source/Python/GenFds/Region.py | 58 ++++++++------------
 1 file changed, 24 insertions(+), 34 deletions(-)

-- 
1.8.3.1


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

Patch

diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 6015e24e25a5..6769b39ba7e8 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -39,6 +39,25 @@  class Region(RegionClassObject):
         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()
     #
     #   Add region data to the Buffer
@@ -135,13 +154,7 @@  class Region(RegionClassObject):
             #
             # Pad the left buffer
             #
-            if Size > 0:
-                if (ErasePolarity == '1') :
-                    PadData = 0xFF
-                else :
-                    PadData = 0
-                for i in range(0, Size):
-                    Buffer.write(pack('B', PadData))
+            self.PadBuffer(Buffer, ErasePolarity, Size)
 
         if self.RegionType == 'CAPSULE':
             #
@@ -194,13 +207,7 @@  class Region(RegionClassObject):
             #
             # Pad the left buffer
             #
-            if Size > 0:
-                if (ErasePolarity == '1') :
-                    PadData = 0xFF
-                else :
-                    PadData = 0
-                for i in range(0, Size):
-                    Buffer.write(pack('B', PadData))
+            self.PadBuffer(Buffer, ErasePolarity, Size)
 
         if self.RegionType in ('FILE', 'INF'):
             for RegionData in self.RegionDataList:
@@ -232,13 +239,7 @@  class Region(RegionClassObject):
             #
             # Pad the left buffer
             #
-            if Size > 0:
-                if (ErasePolarity == '1') :
-                    PadData = 0xFF
-                else :
-                    PadData = 0
-                for i in range(0, Size):
-                    Buffer.write(pack('B', PadData))
+            self.PadBuffer(Buffer, ErasePolarity, Size)
 
         if self.RegionType == 'DATA' :
             GenFdsGlobalVariable.InfLogger('   Region Name = DATA')
@@ -255,22 +256,11 @@  class Region(RegionClassObject):
             #
             # Pad the left buffer
             #
-            if Size > 0:
-                if (ErasePolarity == '1') :
-                    PadData = 0xFF
-                else :
-                    PadData = 0
-                for i in range(0, Size):
-                    Buffer.write(pack('B', PadData))
+            self.PadBuffer(Buffer, ErasePolarity, Size)
 
         if self.RegionType == None:
             GenFdsGlobalVariable.InfLogger('   Region Name = None')
-            if (ErasePolarity == '1') :
-                PadData = 0xFF
-            else :
-                PadData = 0
-            for i in range(0, Size):
-                Buffer.write(pack('B', PadData))
+            self.PadBuffer(Buffer, ErasePolarity, Size)
 
     def GetFvAlignValue(self, Str):
         AlignValue = 1