]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fv.py
2 # process FV generation
4 # Copyright (c) 2007, Intel Corporation
6 # All rights reserved. This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 from GenFdsGlobalVariable
import GenFdsGlobalVariable
26 from GenFds
import GenFds
27 from CommonDataClass
.FdfClass
import FvClassObject
28 from Common
.Misc
import SaveFileOnChange
35 class FV (FvClassObject
):
38 # @param self The object pointer
41 FvClassObject
.__init
__(self
)
43 self
.FvAddressFile
= None
44 self
.BaseAddress
= None
45 self
.InfFileName
= None
46 self
.FvAddressFileName
= None
50 # Generate Fv and add it to the Buffer
52 # @param self The object pointer
53 # @param Buffer The buffer generated FV data will be put
54 # @param BaseAddress base address of FV
55 # @param BlockSize block size of FV
56 # @param BlockNum How many blocks in FV
57 # @param ErasePolarity Flash erase polarity
58 # @param VtfDict VTF objects
59 # @param MacroDict macro value pair
60 # @retval string Generated FV file path
62 def AddToBuffer (self
, Buffer
, BaseAddress
=None, BlockSize
= None, BlockNum
=None, ErasePloarity
='1', VtfDict
=None, MacroDict
= {}) :
64 if self
.UiFvName
.upper() in GenFds
.FvBinDict
.keys():
65 return GenFds
.FvBinDict
[self
.UiFvName
.upper()]
67 GenFdsGlobalVariable
.InfLogger( "\nGenerating %s FV ..." %self
.UiFvName
)
69 self
.__InitializeInf
__(BaseAddress
, BlockSize
, BlockNum
, ErasePloarity
, VtfDict
)
71 # First Process the Apriori section
73 MacroDict
.update(self
.DefineVarDict
)
75 GenFdsGlobalVariable
.VerboseLogger('First generate Apriori file !')
77 for AprSection
in self
.AprioriSectionList
:
78 FileName
= AprSection
.GenFfs (self
.UiFvName
, MacroDict
)
79 FfsFileList
.append(FileName
)
80 # Add Apriori file name to Inf file
81 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
85 # Process Modules in FfsList
86 for FfsFile
in self
.FfsList
:
87 FileName
= FfsFile
.GenFfs(MacroDict
)
88 FfsFileList
.append(FileName
)
89 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
93 SaveFileOnChange(self
.InfFileName
, self
.FvInfFile
.getvalue(), False)
94 self
.FvInfFile
.close()
98 FvOutputFile
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.UiFvName
)
99 FvOutputFile
= FvOutputFile
+ '.Fv'
100 # BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)
101 if self
.CreateFileName
!= None:
102 FvOutputFile
= self
.CreateFileName
104 FvInfoFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, self
.UiFvName
+ '.inf')
105 shutil
.copy(GenFdsGlobalVariable
.FvAddressFileName
, FvInfoFileName
)
106 GenFdsGlobalVariable
.GenerateFirmwareVolume(
109 AddressFile
=FvInfoFileName
,
114 # Write the Fv contents to Buffer
116 FvFileObj
= open ( FvOutputFile
,'r+b')
118 GenFdsGlobalVariable
.InfLogger( "\nGenerate %s FV Successfully" %self
.UiFvName
)
119 GenFdsGlobalVariable
.SharpCounter
= 0
121 Buffer
.write(FvFileObj
.read())
123 GenFds
.FvBinDict
[self
.UiFvName
.upper()] = FvOutputFile
126 ## __InitializeInf__()
128 # Initilize the inf file to create FV
130 # @param self The object pointer
131 # @param BaseAddress base address of FV
132 # @param BlockSize block size of FV
133 # @param BlockNum How many blocks in FV
134 # @param ErasePolarity Flash erase polarity
135 # @param VtfDict VTF objects
137 def __InitializeInf__ (self
, BaseAddress
= None, BlockSize
= None, BlockNum
= None, ErasePloarity
='1', VtfDict
=None) :
141 self
.InfFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
,
142 self
.UiFvName
+ '.inf')
143 self
.FvInfFile
= StringIO
.StringIO()
148 self
.FvInfFile
.writelines("[options]" + T_CHAR_LF
)
149 if BaseAddress
!= None :
150 self
.FvInfFile
.writelines("EFI_BASE_ADDRESS = " + \
154 if BlockSize
!= None:
155 self
.FvInfFile
.writelines("EFI_BLOCK_SIZE = " + \
156 '0x%X' %BlockSize
+ \
159 self
.FvInfFile
.writelines("EFI_NUM_BLOCKS = " + \
160 ' 0x%X' %BlockNum
+ \
163 for BlockSize
in self
.BlockSizeList
:
164 if BlockSize
[0] != None:
165 self
.FvInfFile
.writelines("EFI_BLOCK_SIZE = " + \
166 '0x%X' %BlockSize
[0] + \
169 if BlockSize
[1] != None:
170 self
.FvInfFile
.writelines("EFI_NUM_BLOCKS = " + \
171 ' 0x%X' %BlockSize
[1] + \
174 if self
.BsBaseAddress
!= None:
175 self
.FvInfFile
.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \
176 '0x%X' %self
.BsBaseAddress
)
177 if self
.RtBaseAddress
!= None:
178 self
.FvInfFile
.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \
179 '0x%X' %self
.RtBaseAddress
)
183 self
.FvInfFile
.writelines("[attributes]" + T_CHAR_LF
)
185 self
.FvInfFile
.writelines("EFI_ERASE_POLARITY = " + \
186 ' %s' %ErasePloarity
+ \
188 if not (self
.FvAttributeDict
== None):
189 for FvAttribute
in self
.FvAttributeDict
.keys() :
190 self
.FvInfFile
.writelines("EFI_" + \
193 self
.FvAttributeDict
[FvAttribute
] + \
195 if self
.FvAlignment
!= None:
196 self
.FvInfFile
.writelines("EFI_FVB2_ALIGNMENT_" + \
197 self
.FvAlignment
.strip() + \
201 if self
.FvNameGuid
!= None:
202 self
.FvInfFile
.writelines("EFI_FVNAME_GUID" + \
203 " = %s" % self
.FvNameGuid
+ \
209 self
.FvInfFile
.writelines("[files]" + T_CHAR_LF
)
210 if VtfDict
!= None and self
.UiFvName
in VtfDict
.keys():
211 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
212 VtfDict
.get(self
.UiFvName
) + \