2 import AprioriSection
\r
3 from GenFdsGlobalVariable import GenFdsGlobalVariable
\r
11 self.UiFvName = None
\r
12 self.CreateFileName = None
\r
13 # 3-tuple list (blockSize, numBlocks, pcd)
\r
14 self.BlockSizeList = []
\r
15 # DefineVarDict[var] = value
\r
16 self.DefineVarDict = {}
\r
17 # SetVarDict[var] = value
\r
18 self.SetVarDict = {}
\r
19 self.FvAlignment = None
\r
20 # FvAttributeDict[attribute] = TRUE/FALSE (1/0)
\r
21 self.FvAttributeDict = {}
\r
22 ## self.FvAttributeset = None
\r
23 ## self.FvAttributeClear = None
\r
24 self.AprioriSection = None
\r
27 self.FvInfFile = None
\r
28 self.BaseAddress = None
\r
31 # Generate Fv and add it to the Buffer
\r
33 def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None) :
\r
34 self.__InitialInf__(BaseAddress, BlockSize, BlockNum, ErasePloarity, VtfDict)
\r
36 # First Process the Apriori section
\r
38 if not (self.AprioriSection == None):
\r
39 FileNameList = self.AprioriSection.GenFfs ()
\r
41 # Add Apriori section included Ffs file name to Inf file
\r
43 for Ffs in FileNameList :
\r
44 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
48 # Process Modules in FfsList
\r
50 for FfsFile in self.FfsList :
\r
51 FileName = FfsFile.GenFfs()
\r
52 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
56 self.FvInfFile.close()
\r
61 FvOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName)
\r
62 FvOutputFile = FvOutputFile + '.Fv'
\r
63 cmd = 'GenFv -i ' + \
\r
64 self.InfFileName + \
\r
71 GenFdsGlobalVariable.CallExternalTool(cmd, "GenFv Failed!")
\r
73 # Write the Fv contents to Buffer
\r
75 fv = open ( FvOutputFile,'r+b')
\r
77 print "Generate %s Fv Successful" %self.UiFvName
\r
79 Buffer.write(fv.read())
\r
83 def __InitialInf__ (self, BaseAddress = None, BlockSize= None, BlockNum = None, ErasePloarity='1', VtfDict=None) :
\r
84 self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
\r
85 self.UiFvName + '.inf')
\r
86 self.FvInfFile = open (self.InfFileName, 'w+')
\r
91 self.FvInfFile.writelines("[options]" + T_CHAR_LF)
\r
92 if BaseAddress != None :
\r
93 self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \
\r
97 if BlockSize != None and BlockNum != None:
\r
98 self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
\r
99 '0x%x' %BlockSize + \
\r
101 self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
\r
102 ' 0x%x' %BlockNum + \
\r
105 for BlockSize in self.BlockSizeList :
\r
106 self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
\r
107 '0x%x' %BlockSize[0] + \
\r
110 self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
\r
111 ' 0x%x' %BlockSize[1] + \
\r
118 self.FvInfFile.writelines("[attributes]" + T_CHAR_LF)
\r
120 self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \
\r
121 ' %s' %ErasePloarity + \
\r
123 if not (self.FvAttributeDict == None):
\r
124 for FvAttribute in self.FvAttributeDict.keys() :
\r
125 self.FvInfFile.writelines("EFI_" + \
\r
128 self.FvAttributeDict[FvAttribute] + \
\r
130 if self.FvAlignment != None:
\r
131 self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \
\r
132 self.FvAlignment.strip() + \
\r
139 self.FvInfFile.writelines("[files]" + T_CHAR_LF)
\r
140 if VtfDict != None and self.UiFvName in VtfDict.keys():
\r
141 self.FvInfFile.writelines("EFI_FILE_NAME = " + \
\r
142 VtfDict.get(self.UiFvName) + \
\r