GenFds add feature of display FV space information.
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 11 Aug 2008 09:16:57 +0000 (09:16 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 11 Aug 2008 09:16:57 +0000 (09:16 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1297 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/GenFds/Fv.py
Source/Python/GenFds/GenFds.py

index eb03d1b..36c9c31 100644 (file)
@@ -20,6 +20,7 @@ import AprioriSection
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from GenFds import GenFds\r
 import os\r
+import shutil\r
 import subprocess\r
 from CommonDataClass.FdfClass import FvClassObject\r
 \r
@@ -60,6 +61,8 @@ class FV (FvClassObject):
         if self.UiFvName.upper() in GenFds.FvBinDict.keys():\r
             return GenFds.FvBinDict[self.UiFvName.upper()]\r
 \r
+        GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV ..." %self.UiFvName)\r
+\r
         self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)\r
         #\r
         # First Process the Apriori section\r
@@ -92,10 +95,13 @@ class FV (FvClassObject):
         # BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)\r
         if self.CreateFileName != None:\r
             FvOutputFile = self.CreateFileName\r
+        \r
+        FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r
+        shutil.copy(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)\r
         GenFdsGlobalVariable.GenerateFirmwareVolume(\r
                                 FvOutputFile,\r
                                 [self.InfFileName],\r
-                                AddressFile=GenFdsGlobalVariable.FvAddressFileName\r
+                                AddressFile=FvInfoFileName\r
                                 )\r
 \r
         #\r
@@ -103,7 +109,7 @@ class FV (FvClassObject):
         #\r
         FvFileObj = open ( FvOutputFile,'r+b')\r
 \r
-        GenFdsGlobalVariable.InfLogger( "\nGenerate %s Fv Successfully" %self.UiFvName)\r
+        GenFdsGlobalVariable.InfLogger( "\nGenerate %s FV Successfully" %self.UiFvName)\r
         GenFdsGlobalVariable.SharpCounter = 0\r
 \r
         Buffer.write(FvFileObj.read())\r
index b9a7074..1d51ea0 100644 (file)
@@ -18,6 +18,7 @@
 from optparse import OptionParser
 import sys
 import os
+import linecache
 import FdfParser
 from Common import BuildToolError
 from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -203,6 +204,10 @@ def main():
 
         """Call GenFds"""
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)
+        
+        """Display FV space info."""
+        GenFds.DisplayFvSpaceInfo(FdfParserObj)
+        
     except FdfParser.Warning, X:
         EdkLogger.error(X.ToolName, BuildToolError.FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False)
         ReturnCode = BuildToolError.FORMAT_INVALID
@@ -337,9 +342,51 @@ class GenFds :
                                     return ElementRegion.BlockSizeOfRegion(ElementFd.BlockSizeList)
             return 0x10000
 
+    
+    def DisplayFvSpaceInfo(FdfParser):
+        
+        FvSpaceInfoList = []
+        MaxFvNameLength = 0
+        for FvName in FdfParser.Profile.FvDict:
+            if len(FvName) > MaxFvNameLength:
+                MaxFvNameLength = len(FvName)
+            FvSpaceInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, FvName.upper() + '.inf')
+            if os.path.exists(FvSpaceInfoFileName):
+                FileLinesList = linecache.getlines(FvSpaceInfoFileName)
+                TotalFound = False
+                Total = ''
+                UsedFound = False
+                Used = ''
+                FreeFound = False
+                Free = ''
+                for Line in FileLinesList:
+                    NameValue = Line.split('=')
+                    if len(NameValue) == 2:
+                        if NameValue[0].strip() == 'EFI_FV_TOTAL_SIZE':
+                            TotalFound = True
+                            Total = NameValue[1].strip()
+                        if NameValue[0].strip() == 'EFI_FV_TAKEN_SIZE':
+                            UsedFound = True
+                            Used = NameValue[1].strip()
+                        if NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':
+                            FreeFound = True
+                            Free = NameValue[1].strip()
+                
+                if TotalFound and UsedFound and FreeFound:
+                    FvSpaceInfoList.append((FvName, Total, Used, Free))
+                
+        GenFdsGlobalVariable.InfLogger('\nFV Space Information')
+        for FvSpaceInfo in FvSpaceInfoList:
+            Name = FvSpaceInfo[0]
+            TotalSizeValue = long(FvSpaceInfo[1], 0)
+            UsedSizeValue = long(FvSpaceInfo[2], 0)
+            FreeSizeValue = long(FvSpaceInfo[3], 0)
+            GenFdsGlobalVariable.InfLogger(Name + ' ' + '[' + str((UsedSizeValue+0.0)/TotalSizeValue)[0:4].lstrip('0.') + '%Full] ' + str(TotalSizeValue) + ' total, ' + str(UsedSizeValue) + ' used, ' + str(FreeSizeValue) + ' free')
+
     ##Define GenFd as static function
     GenFd = staticmethod(GenFd)
     GetFvBlockSize = staticmethod(GetFvBlockSize)
+    DisplayFvSpaceInfo = staticmethod(DisplayFvSpaceInfo)
 
 if __name__ == '__main__':
     sys.exit(main())