From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.7335.1586331794420341431 for ; Wed, 08 Apr 2020 00:43:14 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: zhijux.fan@intel.com) IronPort-SDR: uduUPYRNnDyzH/fZWH1tnI39X/Gs/LrVKRifU8SWshtO6gj0rSBtVcessEOylouaLUbE7XZDme 3q0hMnglSvjw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2020 00:43:13 -0700 IronPort-SDR: qJq6kXyhTopLTV6+sV5Mxw8vTRdvifR61GzgAapRbfWtZbNyCUoOQXps0Pj4e3XwRHHnq//XG2 vchkUMQYeoag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,357,1580803200"; d="scan'208";a="240222823" Received: from zhijufax-mobl.ccr.corp.intel.com ([10.238.4.120]) by orsmga007.jf.intel.com with ESMTP; 08 Apr 2020 00:43:12 -0700 From: "Fan, ZhijuX" To: devel@edk2.groups.io Cc: Liming Gao , Bob Feng , "Zhiju . Fan" Subject: [PATCH V3] BaseTools:Add the spare space FV image size checker Date: Wed, 8 Apr 2020 15:21:14 +0800 Message-Id: <20200408072114.9848-1-zhijux.fan@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2654 If FV is placed in FD region, its FV image size is fixed. When FV image size exceeds it, it will trig the build break. To alert the developer to adjust FV image size earlier, I request to add new checker for the the spare FV space. When the spare FV space is less than the specified threshold, build tool will report the error. This checker is the optional. It can be enabled by -D FV_SPARE_SPACE_THRESHOLD=10000. Macro is the value of the spare space threshold size. It can be decimal or hex format. If it is enabled, BaseTools will check every FV with the fixed size. If FV doesn't meet with the size requirement, Build tool will report error message to say there is no enough spare space. Cc: Liming Gao Cc: Bob Feng Signed-off-by: Zhiju.Fan --- move the functions into build.py from GenFds.py BaseTools/Source/Python/Common/BuildToolError.py | 2 ++ BaseTools/Source/Python/build/build.py | 44 +++++++++++ 2 files changed, 46 insertions(+) diff --git a/BaseTools/Source/Python/Common/BuildToolError.py b/BaseTools/Source/Python/Common/BuildToolError.py index ecc83d0f48bd..21549683cd19 100644 --- a/BaseTools/Source/Python/Common/BuildToolError.py +++ b/BaseTools/Source/Python/Common/BuildToolError.py @@ -64,6 +64,8 @@ COMMAND_FAILURE = 0x7000 PERMISSION_FAILURE = 0x8000 +FV_FREESIZE_ERROR = 0x9000 + CODE_ERROR = 0xC0DE AUTOGEN_ERROR = 0xF000 diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index bec848a7b2e3..3faa11199f5f 100755 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -25,6 +25,7 @@ import traceback import multiprocessing from threading import Thread,Event,BoundedSemaphore import threading +from linecache import getlines from subprocess import Popen,PIPE, STDOUT from collections import OrderedDict, defaultdict @@ -61,6 +62,7 @@ from AutoGen.ModuleAutoGenHelper import WorkSpaceInfo, PlatformInfo from GenFds.FdfParser import FdfParser from AutoGen.IncludesAutoGen import IncludesAutoGen from GenFds.GenFds import resetFdsGlobalVariable +from GenFds.GenFdsGlobalVariable import GenFdsGlobalVariable ## standard targets of build command gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run'] @@ -1413,6 +1415,9 @@ class Build(): if Target == 'fds': if GenFdsApi(AutoGenObject.GenFdsCommandDict, self.Db): EdkLogger.error("build", COMMAND_FAILURE) + Threshold = self.GetFreeSizeThreshold() + if Threshold: + self.CheckFreeSizeThreshold(Threshold, AutoGenObject.FvDir) return True # run @@ -2311,6 +2316,9 @@ class Build(): GenFdsStart = time.time() if GenFdsApi(Wa.GenFdsCommandDict, self.Db): EdkLogger.error("build", COMMAND_FAILURE) + Threshold = self.GetFreeSizeThreshold() + if Threshold: + self.CheckFreeSizeThreshold(Threshold, Wa.FvDir) # # Create MAP file for all platform FVs after GenFds. @@ -2322,6 +2330,42 @@ class Build(): # self._SaveMapFile(MapBuffer, Wa) self.CreateGuidedSectionToolsFile(Wa) + + ## GetFreeSizeThreshold() + # + # @retval int Threshold value + # + def GetFreeSizeThreshold(self): + Threshold = None + Threshold_Str = GlobalData.gCommandLineDefines.get('FV_SPARE_SPACE_THRESHOLD') + if Threshold_Str: + try: + if Threshold_Str.lower().startswith('0x'): + Threshold = int(Threshold_Str, 16) + else: + Threshold = int(Threshold_Str) + except: + EdkLogger.warn("build", 'incorrect value for FV_SPARE_SPACE_THRESHOLD %s. It can be decimal or hex format' % Threshold_Str) + return Threshold + + ## CheckFreeSizeThreshold() + def CheckFreeSizeThreshold(self, Threshold=None, FvDir=None): + FdfParserObject = GlobalData.gFdfParser + FvRegionNameList = [FvName for FvName in FdfParserObject.Profile.FvDict if FdfParserObject.Profile.FvDict[FvName].FvRegionInFD] + for FvName in FdfParserObject.Profile.FvDict: + if FvName in FvRegionNameList: + FvSpaceInfoFileName = os.path.join(FvDir, FvName.upper() + '.Fv.map') + if os.path.exists(FvSpaceInfoFileName): + FileLinesList = getlines(FvSpaceInfoFileName) + for Line in FileLinesList: + NameValue = Line.split('=') + if len(NameValue) == 2 and NameValue[0].strip() == 'EFI_FV_SPACE_SIZE': + FreeSizeValue = int(NameValue[1].strip(), 0) + if FreeSizeValue < Threshold: + EdkLogger.error("build", FV_FREESIZE_ERROR, + 'Freespace of %s FV is smaller than threshold, The value of FV_SPARE_SPACE_THRESHOLD is %d' % ( + FvName, Threshold)) + ## Generate GuidedSectionTools.txt in the FV directories. # def CreateGuidedSectionToolsFile(self,Wa): -- 2.14.1.windows.1