Skip to content

Commit

Permalink
GenFds add feature of display FV space information.
Browse files Browse the repository at this point in the history
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1297 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
jlin16 committed Aug 11, 2008
1 parent 788ae70 commit 3a0c0ed
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/Python/GenFds/Fv.py
Expand Up @@ -20,6 +20,7 @@
from GenFdsGlobalVariable import GenFdsGlobalVariable
from GenFds import GenFds
import os
import shutil
import subprocess
from CommonDataClass.FdfClass import FvClassObject

Expand Down Expand Up @@ -60,6 +61,8 @@ def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None,
if self.UiFvName.upper() in GenFds.FvBinDict.keys():
return GenFds.FvBinDict[self.UiFvName.upper()]

GenFdsGlobalVariable.InfLogger( "\nGenerating %s FV ..." %self.UiFvName)

self.__InitializeInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)
#
# First Process the Apriori section
Expand Down Expand Up @@ -92,18 +95,21 @@ def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None,
# BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)
if self.CreateFileName != None:
FvOutputFile = self.CreateFileName

FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')
shutil.copy(GenFdsGlobalVariable.FvAddressFileName, FvInfoFileName)
GenFdsGlobalVariable.GenerateFirmwareVolume(
FvOutputFile,
[self.InfFileName],
AddressFile=GenFdsGlobalVariable.FvAddressFileName
AddressFile=FvInfoFileName
)

#
# Write the Fv contents to Buffer
#
FvFileObj = open ( FvOutputFile,'r+b')

GenFdsGlobalVariable.InfLogger( "\nGenerate %s Fv Successfully" %self.UiFvName)
GenFdsGlobalVariable.InfLogger( "\nGenerate %s FV Successfully" %self.UiFvName)
GenFdsGlobalVariable.SharpCounter = 0

Buffer.write(FvFileObj.read())
Expand Down
47 changes: 47 additions & 0 deletions Source/Python/GenFds/GenFds.py
Expand Up @@ -18,6 +18,7 @@
from optparse import OptionParser
import sys
import os
import linecache
import FdfParser
from Common import BuildToolError
from GenFdsGlobalVariable import GenFdsGlobalVariable
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -337,9 +342,51 @@ def GetFvBlockSize(FvObj):
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())
Expand Down

0 comments on commit 3a0c0ed

Please sign in to comment.