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.web10.12566.1586951365463431314 for ; Wed, 15 Apr 2020 04:49:25 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=UlLw1C6A; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: zhijux.fan@intel.com) IronPort-SDR: oHzjQ2esX74sjwvDGw01M5Js2ciaV2YTQxQQGMcF5YMqMtNam23aY6lHHaYC4D7Hw0r8td/LvM POfMcZkKAsJg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2020 04:49:24 -0700 IronPort-SDR: k6dMKI0bQ8/SZUOx5l1GmqgOFW5Kk2L6kercIXKn8s1iOIjsIwUhdCIz7OzzJCKb1UrUO68mnu mWGx1q2LIR1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,386,1580803200"; d="scan'208";a="271702921" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 15 Apr 2020 04:49:24 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Apr 2020 04:49:23 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 15 Apr 2020 04:49:22 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 15 Apr 2020 04:49:22 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 15 Apr 2020 04:49:22 -0700 Received: from CY4PR11MB1479.namprd11.prod.outlook.com (2603:10b6:910:5::9) by CY4PR11MB1544.namprd11.prod.outlook.com (2603:10b6:910:d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.15; Wed, 15 Apr 2020 11:49:21 +0000 Received: from CY4PR11MB1479.namprd11.prod.outlook.com ([fe80::bc01:878b:fa1a:82e0]) by CY4PR11MB1479.namprd11.prod.outlook.com ([fe80::bc01:878b:fa1a:82e0%7]) with mapi id 15.20.2921.024; Wed, 15 Apr 2020 11:49:21 +0000 From: "Fan, ZhijuX" To: "devel@edk2.groups.io" CC: "Gao, Liming" , "Feng, Bob C" Subject: [PATCH V6] BaseTools:Add the spare space FV image size checker Thread-Topic: [PATCH V6] BaseTools:Add the spare space FV image size checker Thread-Index: AdYTG+StwkWvx/K8QluZzoxQvzOdKw== Date: Wed, 15 Apr 2020 11:49:20 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGVmNmEwYjEtZDc3Mi00ZTNjLWJmYzgtMjgyZDg4MzhlZTI1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiUDh6ellURFhzK2ZsbmluTlBVNmw2RnNsbkhmXC9HajNYWU02bjVYZHowTjFvQUFRcHVwdmtyZ0dOZm04RndQMlYifQ== x-ctpclassification: CTP_NT authentication-results: spf=none (sender IP is ) smtp.mailfrom=zhijux.fan@intel.com; x-originating-ip: [192.55.52.219] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e190dfc3-a3a9-4652-cc05-08d7e133093f x-ms-traffictypediagnostic: CY4PR11MB1544: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2150; x-forefront-prvs: 0374433C81 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB1479.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10019020)(376002)(346002)(39860400002)(366004)(396003)(136003)(9686003)(316002)(64756008)(81156014)(6916009)(8676002)(66476007)(8936002)(66556008)(66446008)(86362001)(54906003)(52536014)(71200400001)(76116006)(2906002)(55016002)(26005)(66946007)(33656002)(186003)(478600001)(7696005)(107886003)(6506007)(5660300002)(4326008);DIR:OUT;SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Po8hWhEAgE+y+1r3BMtacl0vFdpN0gGuAPbz669wWWiGEoFRdNv/8Us7FJu4etvbRMeGIwJOM3+3YniHb4UPmFIvr4u+rA8stYHv0dvuytgJJipKfWpMSe5TU3OSg/VTNmijGnJsa7+quNi5sop4xFTClmcgqoJMn+xo8FHn5isrrwyhg4Jh+RMK1+WzjqPFrzf4mELqgcZ4KuLYYQlDed/o4jUmXcTq0XK8x89JUBrzDQpAr5Y5ALT38pa/5th6cz5NmmXsftr206dgbgFYDy5J3skXvnjHdAu3PxrFRbofVqL92XPhyd0Hempuowq4u0iAc2iQBz3qhFVlr/dTS9r0wU3+PjxyaiAjErX4zdotwGiSG2XC8Gp4YRIO0jhijoaesxvEiGZQYDZtA2lSNRTZn823I9ztVraE6aKMaR0jJvxzlrhIgoL4RKa7RmnXYNTGrUOeLA/O8jHUDV/jkHpzqzZ7FI9q4CZzN7/k5jK4QGdrLkkj6JHo+5hClwRGd4yUS++rIatnGpxkPqrXeQ== x-ms-exchange-antispam-messagedata: Rpj94rcYoUx6z2IZzkymWg3vd9tXEQ6qgjmsILJGJ+aqptlQTmoUIRJovoPuTdijpydDUrUQZAJmro0gEcDe7Swe98LPGv6p4Qh2RWDtTgVd37r3S2VaCFn+BynTKd4tdbp6zCVkfwrYZUsqlmOMcw== arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XILI5hylzEKIsc3Fi690rvWMfx3jZIG8dY+ezwNtBBDXHf2fZCQFA8ifq3AtfNf/+NKELTGqKpv4Lx/TSgJAQ8+p41+QlySezkAflDjGE/9VJHYXp28RSA7pL4vwjrUszhWE+PZd7XNCZFsXH1Rl1atjgyeoV9o0MUk2oND772KxnnIX8qxwgLoqAnHa4B42fGKMfeRbAXY+SqtodagnqrFqaZJ/KCTX7h3FCWRI1ZK+MMQwqJoPEaRPe7k9OXLACZvAtfB6wCDsj8OXWXTDT0jKTuKjomWe4bvwh/jBTiABw855ZUqNE5YE6NEQHKLvH7dsNBS7paFI2hwej1R5sw== arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0ZK7sDLRTXdeZdFwUf/iednIpjM3RAF1xaTA2ebmIwI=; b=N0qXTbzmNKsAlYodZHaNOAg20n0eNnsuMLLzG6bJ3NmgBBqaRzNVzTgvSMah5HKFaSaeoPI3i6rbajsKZt0sLhZ21Jetbu2TDNI7Wv5Cem8fmYM0RSC9JGfX0f0FGW4h9v+ODPrhTsx7uloOFmgVrO4RRDSeplV1NrY4Cgfqk3QZq2ZS8pJ5n0Br+sNS1i/QVUPx4poIyAHpaLl4ScF3kMBy9Gt3zZXgiAT7m6KnXvTKHK9C0yiMn7O7OKmwvxGv9U8TBkkMEo0j2SF7azykPCtkS3K1fx5xBULknPk/DOJaSHfnSPNciSNV2z2w8pKLhYPahP/fW0Z2DTQgFCGP8g== arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0ZK7sDLRTXdeZdFwUf/iednIpjM3RAF1xaTA2ebmIwI=; b=UlLw1C6A+1fW+LV6EJi8l4BrX+CnFwVyPBSjIMehLhEU8YoDWnq3ZcbZ/1NLFDJyPoaphyHg882+mT2a3tV53k/7pvtpI9v+T4g5knLoQZe+13/cxwN5zu3byhEt1xVxEw7TXZ8t+0V7W/rFtU2B09Q6b3qvs78bayabvoJVB0Y= x-ms-exchange-crosstenant-network-message-id: e190dfc3-a3a9-4652-cc05-08d7e133093f x-ms-exchange-crosstenant-originalarrivaltime: 15 Apr 2020 11:49:20.9033 (UTC) x-ms-exchange-crosstenant-fromentityheader: Hosted x-ms-exchange-crosstenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d x-ms-exchange-crosstenant-mailboxtype: HOSTED x-ms-exchange-crosstenant-userprincipalname: m4D1oNe7nvOJAhzerxtP3LdtfacBPSo09t0ih9lBuszlQd8EwBtFQywNIgCLlhijJ27XobTZo1z+5C4n9hGWcA== x-ms-exchange-transport-crosstenantheadersstamped: CY4PR11MB1544 MIME-Version: 1.0 Return-Path: zhijux.fan@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 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=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 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 --- changed the error message 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 ecc83d0f48bd..21549683cd19 100644 --- a/BaseTools/Source/Python/Common/BuildToolError.py +++ b/BaseTools/Source/Python/Common/BuildToolError.py @@ -64,6 +64,8 @@ COMMAND_FAILURE =3D 0x7000 PERMISSION_FAILURE =3D 0x8000 +FV_FREESIZE_ERROR =3D 0x9000 + CODE_ERROR =3D 0xC0DE AUTOGEN_ERROR =3D 0xF000 diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index bec848a7b2e3..68f5b8cabea3 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 @@ -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, AutoGenObject.FvDir= ) return True # 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, Wa.FvDi= r) # # 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.Only decimal or hex format is allowed.' % 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= , + 'the required spare space = in fv image size %d of %s FV exceeds the set spare space in fv image size %= d' % ( + FreeSizeValue, FvName,= Threshold)) + break + ## Generate GuidedSectionTools.txt in the FV directories. # def CreateGuidedSectionToolsFile(self,Wa): -- 2.14.1.windows.1