From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 7C1772194D387 for ; Wed, 5 Sep 2018 14:50:52 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Sep 2018 14:50:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,334,1531810800"; d="scan'208";a="254833352" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga005.jf.intel.com with ESMTP; 05 Sep 2018 14:50:51 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Yonghong Zhu , Liming Gao , Bob C Feng Date: Wed, 5 Sep 2018 14:50:46 -0700 Message-Id: <88960c0e4eadbb9434eb56800a20ec83bbd355a9.1536184227.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: Subject: [PATCH v1 1/1] BaseTools: refactor to remove duplicate functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Sep 2018 21:50:52 -0000 Update GenFdsGlobalVariable GetAlignment to support G. replace use of local function in Region with updated shared function. Cc: Yonghong Zhu Cc: Liming Gao Cc: Bob C Feng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 11 +++++----- BaseTools/Source/Python/GenFds/Region.py | 21 +------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index eb106b574420..77873d36b98a 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -512,14 +512,15 @@ class GenFdsGlobalVariable: @staticmethod def GetAlignment (AlignString): - if AlignString is None: + if not AlignString: return 0 - if AlignString in ("1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K"): + if AlignString.endswith('K'): return int (AlignString.rstrip('K')) * 1024 - elif AlignString in ("1M", "2M", "4M", "8M", "16M"): + if AlignString.endswith('M'): return int (AlignString.rstrip('M')) * 1024 * 1024 - else: - return int (AlignString) + if AlignString.endswith('G'): + return int (AlignString.rstrip('G')) * 1024 * 1024 * 1024 + return int (AlignString) @staticmethod def GenerateFfs(Output, Input, Type, Guid, Fixed=False, CheckSum=False, Align=None, diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py index 7f94b3d66b55..5242b74c9e70 100644 --- a/BaseTools/Source/Python/GenFds/Region.py +++ b/BaseTools/Source/Python/GenFds/Region.py @@ -124,7 +124,7 @@ class Region(RegionClassObject): # self.BlockInfoOfRegion(BlockSizeList, FvObj) self.FvAddress = self.FvAddress + FvOffset - FvAlignValue = self.GetFvAlignValue(FvObj.FvAlignment) + FvAlignValue = GenFdsGlobalVariable.GetAlignment(FvObj.FvAlignment) if self.FvAddress % FvAlignValue != 0: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment)) @@ -277,25 +277,6 @@ class Region(RegionClassObject): GenFdsGlobalVariable.InfLogger(' Region Name = None') self.PadBuffer(Buffer, ErasePolarity, Size) - def GetFvAlignValue(self, Str): - AlignValue = 1 - Granu = 1 - Str = Str.strip().upper() - if Str.endswith('K'): - Granu = 1024 - Str = Str[:-1] - elif Str.endswith('M'): - Granu = 1024 * 1024 - Str = Str[:-1] - elif Str.endswith('G'): - Granu = 1024 * 1024 * 1024 - Str = Str[:-1] - else: - pass - - AlignValue = int(Str) * Granu - return AlignValue - ## BlockSizeOfRegion() # # @param BlockSizeList List of block information -- 2.16.2.windows.1