2 import AprioriSection
\r
3 from GenFdsGlobalVariable import GenFdsGlobalVariable
\r
6 from CommonDataClass.FdfClassObject import FvClassObject
\r
10 class FV (FvClassObject):
\r
12 ## self.UiFvName = None
\r
13 ## self.CreateFileName = None
\r
14 ## # 3-tuple list (blockSize, numBlocks, pcd)
\r
15 ## self.BlockSizeList = []
\r
16 ## # DefineVarDict[var] = value
\r
17 ## self.DefineVarDict = {}
\r
18 ## # SetVarDict[var] = value
\r
19 ## self.SetVarDict = {}
\r
20 ## self.FvAlignment = None
\r
21 ## # FvAttributeDict[attribute] = TRUE/FALSE (1/0)
\r
22 ## self.FvAttributeDict = {}
\r
23 #### self.FvAttributeset = None
\r
24 #### self.FvAttributeClear = None
\r
25 ## self.AprioriSection = None
\r
26 ## self.FfsList = []
\r
27 FvClassObject.__init__(self)
\r
28 self.FvInfFile = None
\r
29 self.BaseAddress = None
\r
32 # Generate Fv and add it to the Buffer
\r
34 def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None) :
\r
35 self.__InitialInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)
\r
37 # First Process the Apriori section
\r
39 if not (self.AprioriSection == None):
\r
40 FileNameList = self.AprioriSection.GenFfs ()
\r
42 # Add Apriori section included Ffs file name to Inf file
\r
44 for Ffs in FileNameList :
\r
45 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
49 # Process Modules in FfsList
\r
51 for FfsFile in self.FfsList :
\r
52 FileName = FfsFile.GenFfs()
\r
53 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
57 self.FvInfFile.close()
\r
62 FvOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName)
\r
63 FvOutputFile = FvOutputFile + '.Fv'
\r
64 cmd = 'GenFv -i ' + \
\r
65 self.InfFileName + \
\r
72 GenFdsGlobalVariable.CallExternalTool(cmd, "GenFv Failed!")
\r
74 # Write the Fv contents to Buffer
\r
76 fv = open ( FvOutputFile,'r+b')
\r
78 print "Generate %s Fv Successful" %self.UiFvName
\r
80 Buffer.write(fv.read())
\r
84 def __InitialInf__ (self, BaseAddress = None, BlockSize= None, BlockNum = None, ErasePloarity='1', VtfDict=None) :
\r
85 self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
\r
86 self.UiFvName + '.inf')
\r
87 self.FvInfFile = open (self.InfFileName, 'w+')
\r
92 self.FvInfFile.writelines("[options]" + T_CHAR_LF)
\r
93 if BaseAddress != None :
\r
94 self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \
\r
98 if BlockSize != None and BlockNum != None:
\r
99 self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
\r
100 '0x%x' %BlockSize + \
\r
102 self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
\r
103 ' 0x%x' %BlockNum + \
\r
106 for BlockSize in self.BlockSizeList :
\r
107 self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
\r
108 '0x%x' %BlockSize[0] + \
\r
111 self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
\r
112 ' 0x%x' %BlockSize[1] + \
\r
119 self.FvInfFile.writelines("[attributes]" + T_CHAR_LF)
\r
121 self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \
\r
122 ' %s' %ErasePloarity + \
\r
124 if not (self.FvAttributeDict == None):
\r
125 for FvAttribute in self.FvAttributeDict.keys() :
\r
126 self.FvInfFile.writelines("EFI_" + \
\r
129 self.FvAttributeDict[FvAttribute] + \
\r
131 if self.FvAlignment != None:
\r
132 self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \
\r
133 self.FvAlignment.strip() + \
\r
140 self.FvInfFile.writelines("[files]" + T_CHAR_LF)
\r
141 if VtfDict != None and self.UiFvName in VtfDict.keys():
\r
142 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
143 VtfDict.get(self.UiFvName) + \
\r