From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.9708.1586753930212388296 for ; Sun, 12 Apr 2020 21:58:50 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: bob.c.feng@intel.com) IronPort-SDR: aj3ttvytoM1NaQUsu2nqhSeqcebzlWP2nYWhCTb5dTHVuklAansbGwK2EKH5jAGPKLSfA3w0QV YFDNnGXE5VNA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 21:58:49 -0700 IronPort-SDR: EvXnbH0LYXmFMR/GxvYKthMfyQEqDSS/BkfTjHrcAHpdW2DDo0PJ+N5uebdtE9Vyspxhc5n2wh CtS2zYVY3nGg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="252777366" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga003.jf.intel.com with ESMTP; 12 Apr 2020 21:58:49 -0700 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 12 Apr 2020 21:58:49 -0700 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) by SHSMSX603.ccr.corp.intel.com (10.109.6.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 13 Apr 2020 12:58:46 +0800 Received: from shsmsx601.ccr.corp.intel.com ([10.109.6.141]) by SHSMSX601.ccr.corp.intel.com ([10.109.6.141]) with mapi id 15.01.1713.004; Mon, 13 Apr 2020 12:58:46 +0800 From: "Bob Feng" To: "Fan, ZhijuX" , "devel@edk2.groups.io" CC: "Gao, Liming" Subject: Re: [PATCH V4] BaseTools:Add the spare space FV image size checker Thread-Topic: [PATCH V4] BaseTools:Add the spare space FV image size checker Thread-Index: AQHWEUA56BgLxRxehU6F4kB4NZzGFKh2fdZQ Date: Mon, 13 Apr 2020 04:58:46 +0000 Message-ID: References: <20200413030347.12244-1-zhijux.fan@intel.com> In-Reply-To: <20200413030347.12244-1-zhijux.fan@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Fan, ZhijuX=20 Sent: Monday, April 13, 2020 11:04 AM To: devel@edk2.groups.io Cc: Gao, Liming ; Feng, Bob C ;= Fan, ZhijuX Subject: [PATCH V4] BaseTools:Add the spare space FV image size checker REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2654 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 ne= w checker for the the spare FV space. When the spare FV space is less than the specified threshold, build tool wi= ll report the error. This checker is the optional. It can be enabled by -D FV_SPARE_SPACE_THRESHOLD=3D10000. Macro is the value of the spare space threshold size. It can be decimal or hex format. If it is enabled, BaseTools will check eve= ry 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 --- Determine the value of Threshold and FvDir BaseTools/Source/Python/Common/BuildToolError.py | 2 + BaseTools/Source/Python/build/build.py | 47 ++++++++++ 2 files changed, 49 insertions(+) diff --git a/BaseTools/Source/Python/Common/BuildToolError.py b/BaseTools/S= ource/Python/Common/BuildToolError.py index ecc83d0f48..21549683cd 100644 --- a/BaseTools/Source/Python/Common/BuildToolError.py +++ b/BaseTools/Source/Python/Common/BuildToolError.py @@ -64,6 +64,8 @@ COMMAND_FAILURE =3D 0x7000 =20 PERMISSION_FAILURE =3D 0x8000 =20 +FV_FREESIZE_ERROR =3D 0x9000 + CODE_ERROR =3D 0xC0DE =20 AUTOGEN_ERROR =3D 0xF000 diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index bec848a7b2..c19be67254 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 Ordered= Dict, defaultdict =20 @@ -1413,6 +1414,9 @@ class Build(): if Target =3D=3D 'fds': if GenFdsApi(AutoGenObject.GenFdsCommandDict, self.Db): EdkLogger.error("build", COMMAND_FAILURE) + Threshold =3D self.GetFreeSizeThreshold() + if Threshold: + self.CheckFreeSizeThreshold(Threshold,=20 + AutoGenObject.FvDir) return True =20 # run @@ -2311,6 +2315,9 @@ class Build(): GenFdsStart =3D time.time() if GenFdsApi(Wa.GenFdsCommandDict, self.Db): EdkLogger.error("build", COMMAND_FAILURE) + Threshold =3D self.GetFreeSizeThreshold() + if Threshold: + self.CheckFreeSizeThreshold(Threshold,=20 + Wa.FvDir) =20 # # Create MAP file for all platform FVs after GenFd= s. @@ -2322,6 +2329,46 @@ class Build(): # self._SaveMapFile(MapBuffer, Wa) self.CreateGuidedSectionToolsFile(Wa) + + ## GetFreeSizeThreshold() + # + # @retval int Threshold value + # + def GetFreeSizeThreshold(self): + Threshold =3D None + Threshold_Str =3D GlobalData.gCommandLineDefines.get('FV_SPARE_SPA= CE_THRESHOLD') + if Threshold_Str: + try: + if Threshold_Str.lower().startswith('0x'): + Threshold =3D int(Threshold_Str, 16) + else: + Threshold =3D int(Threshold_Str) + except: + EdkLogger.warn("build", 'incorrect value for FV_SPARE_SPAC= E_THRESHOLD %s. It can be decimal or hex format' % Threshold_Str) + return Threshold + + def CheckFreeSizeThreshold(self, Threshold=3DNone, FvDir=3DNone): + if not isinstance(Threshold, int): + return + if not isinstance(FvDir, str) or not FvDir: + return + FdfParserObject =3D GlobalData.gFdfParser + FvRegionNameList =3D [FvName for FvName in FdfParserObject.Profile= .FvDict if FdfParserObject.Profile.FvDict[FvName].FvRegionInFD] + for FvName in FdfParserObject.Profile.FvDict: + if FvName in FvRegionNameList: + FvSpaceInfoFileName =3D os.path.join(FvDir, FvName.upper()= + '.Fv.map') + if os.path.exists(FvSpaceInfoFileName): + FileLinesList =3D getlines(FvSpaceInfoFileName) + for Line in FileLinesList: + NameValue =3D Line.split('=3D') + if len(NameValue) =3D=3D 2 and NameValue[0].strip(= ) =3D=3D 'EFI_FV_SPACE_SIZE': + FreeSizeValue =3D int(NameValue[1].strip(), 0) + if FreeSizeValue < Threshold: + EdkLogger.error("build", FV_FREESIZE_ERROR= , + 'Freespace value %d of %s = FV is smaller than threshold, The value of FV_SPARE_SPACE_THRESHOLD is %d' = % ( + FreeSizeValue, FvName,= Threshold)) + break + ## Generate GuidedSectionTools.txt in the FV directories. # def CreateGuidedSectionToolsFile(self,Wa): -- 2.14.1.windows.1