]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools:Add the spare space FV image size checker
authorFan, Zhiju <zhijux.fan@intel.com>
Mon, 20 Apr 2020 01:20:52 +0000 (09:20 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 23 Apr 2020 01:29:34 +0000 (01:29 +0000)
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 <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/Common/BuildToolError.py
BaseTools/Source/Python/build/build.py

index ecc83d0f48bdb6bd0a41242fe21c8c9c6f4a994b..21549683cd19d45a73275386db23cfb3f293b9db 100644 (file)
@@ -64,6 +64,8 @@ COMMAND_FAILURE = 0x7000
 \r
 PERMISSION_FAILURE = 0x8000\r
 \r
+FV_FREESIZE_ERROR = 0x9000\r
+\r
 CODE_ERROR = 0xC0DE\r
 \r
 AUTOGEN_ERROR = 0xF000\r
index bec848a7b2e3e8a019581e7c8f943e9fcda7cc84..ed3a3b978da1e0717530656fdafc81c263169cca 100755 (executable)
@@ -25,6 +25,7 @@ import traceback
 import multiprocessing\r
 from threading import Thread,Event,BoundedSemaphore\r
 import threading\r
+from linecache import getlines\r
 from subprocess import Popen,PIPE, STDOUT\r
 from collections import OrderedDict, defaultdict\r
 \r
@@ -1413,6 +1414,9 @@ class Build():
         if Target == 'fds':\r
             if GenFdsApi(AutoGenObject.GenFdsCommandDict, self.Db):\r
                 EdkLogger.error("build", COMMAND_FAILURE)\r
+            Threshold = self.GetFreeSizeThreshold()\r
+            if Threshold:\r
+                self.CheckFreeSizeThreshold(Threshold, AutoGenObject.FvDir)\r
             return True\r
 \r
         # run\r
@@ -2311,6 +2315,9 @@ class Build():
                         GenFdsStart = time.time()\r
                         if GenFdsApi(Wa.GenFdsCommandDict, self.Db):\r
                             EdkLogger.error("build", COMMAND_FAILURE)\r
+                        Threshold = self.GetFreeSizeThreshold()\r
+                        if Threshold:\r
+                            self.CheckFreeSizeThreshold(Threshold, Wa.FvDir)\r
 \r
                         #\r
                         # Create MAP file for all platform FVs after GenFds.\r
@@ -2322,6 +2329,46 @@ class Build():
                     #\r
                     self._SaveMapFile(MapBuffer, Wa)\r
                 self.CreateGuidedSectionToolsFile(Wa)\r
+\r
+    ## GetFreeSizeThreshold()\r
+    #\r
+    #   @retval int             Threshold value\r
+    #\r
+    def GetFreeSizeThreshold(self):\r
+        Threshold = None\r
+        Threshold_Str = GlobalData.gCommandLineDefines.get('FV_SPARE_SPACE_THRESHOLD')\r
+        if Threshold_Str:\r
+            try:\r
+                if Threshold_Str.lower().startswith('0x'):\r
+                    Threshold = int(Threshold_Str, 16)\r
+                else:\r
+                    Threshold = int(Threshold_Str)\r
+            except:\r
+                EdkLogger.warn("build", 'incorrect value for FV_SPARE_SPACE_THRESHOLD %s.Only decimal or hex format is allowed.' % Threshold_Str)\r
+        return Threshold\r
+\r
+    def CheckFreeSizeThreshold(self, Threshold=None, FvDir=None):\r
+        if not isinstance(Threshold, int):\r
+            return\r
+        if not isinstance(FvDir, str) or not FvDir:\r
+            return\r
+        FdfParserObject = GlobalData.gFdfParser\r
+        FvRegionNameList = [FvName for FvName in FdfParserObject.Profile.FvDict if FdfParserObject.Profile.FvDict[FvName].FvRegionInFD]\r
+        for FvName in FdfParserObject.Profile.FvDict:\r
+            if FvName in FvRegionNameList:\r
+                FvSpaceInfoFileName = os.path.join(FvDir, FvName.upper() + '.Fv.map')\r
+                if os.path.exists(FvSpaceInfoFileName):\r
+                    FileLinesList = getlines(FvSpaceInfoFileName)\r
+                    for Line in FileLinesList:\r
+                        NameValue = Line.split('=')\r
+                        if len(NameValue) == 2 and NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':\r
+                            FreeSizeValue = int(NameValue[1].strip(), 0)\r
+                            if FreeSizeValue < Threshold:\r
+                                EdkLogger.error("build", FV_FREESIZE_ERROR,\r
+                                                '%s FV free space %d is not enough to meet with the required spare space %d set by -D FV_SPARE_SPACE_THRESHOLD option.' % (\r
+                                                    FvName, FreeSizeValue, Threshold))\r
+                            break\r
+\r
     ## Generate GuidedSectionTools.txt in the FV directories.\r
     #\r
     def CreateGuidedSectionToolsFile(self,Wa):\r