From patchwork Mon Jul 11 15:55:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 71742 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp23842qga; Mon, 11 Jul 2016 08:55:22 -0700 (PDT) X-Received: by 10.66.181.139 with SMTP id dw11mr27003289pac.2.1468252522461; Mon, 11 Jul 2016 08:55:22 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id ty5si13127pab.69.2016.07.11.08.55.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 08:55:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2D6E61A1FB3; Mon, 11 Jul 2016 08:56:06 -0700 (PDT) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3E1EA1A1FAC for ; Mon, 11 Jul 2016 08:56:05 -0700 (PDT) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DBC246202; Mon, 11 Jul 2016 15:55:20 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-91.phx2.redhat.com [10.3.116.91]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6BFtHHu022101; Mon, 11 Jul 2016 11:55:19 -0400 From: Laszlo Ersek To: edk2-devel-01 Date: Mon, 11 Jul 2016 17:55:13 +0200 Message-Id: <1468252514-9533-2-git-send-email-lersek@redhat.com> In-Reply-To: <1468252514-9533-1-git-send-email-lersek@redhat.com> References: <1468252514-9533-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 11 Jul 2016 15:55:20 +0000 (UTC) Subject: [edk2] [PATCH 1/2] BaseTools/GenFds: factor out Region.PadBuffer() method X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The same logic is used in five places; factor it out to a common method. Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- 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 --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