]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fv.py
23ec58200b1ebcdf00878d35ed8b6eab23839d57
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
47 self
.CapsuleName
= None
51 # Generate Fv and add it to the Buffer
53 # @param self The object pointer
54 # @param Buffer The buffer generated FV data will be put
55 # @param BaseAddress base address of FV
56 # @param BlockSize block size of FV
57 # @param BlockNum How many blocks in FV
58 # @param ErasePolarity Flash erase polarity
59 # @param VtfDict VTF objects
60 # @param MacroDict macro value pair
61 # @retval string Generated FV file path
63 def AddToBuffer (self
, Buffer
, BaseAddress
=None, BlockSize
= None, BlockNum
=None, ErasePloarity
='1', VtfDict
=None, MacroDict
= {}) :
65 if self
.UiFvName
.upper() + 'fv' in GenFds
.ImageBinDict
.keys():
66 return GenFds
.ImageBinDict
[self
.UiFvName
.upper() + 'fv']
69 # Check whether FV in Capsule is in FD flash region.
70 # If yes, return error. Doesn't support FV in Capsule image is also in FD flash region.
72 if self
.CapsuleName
!= None:
73 for FdName
in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
74 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[FdName
]
75 for RegionObj
in FdObj
.RegionList
:
76 if RegionObj
.RegionType
== 'FV':
77 for RegionData
in RegionObj
.RegionDataList
:
78 if RegionData
.endswith(".fv"):
80 elif RegionData
.upper() + 'fv' in GenFds
.ImageBinDict
.keys():
82 elif self
.UiFvName
.upper() == RegionData
.upper():
83 GenFdsGlobalVariable
.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self
.CapsuleName
, self
.UiFvName
.upper()))
85 GenFdsGlobalVariable
.InfLogger( "\nGenerating %s FV" %self
.UiFvName
)
87 self
.__InitializeInf
__(BaseAddress
, BlockSize
, BlockNum
, ErasePloarity
, VtfDict
)
89 # First Process the Apriori section
91 MacroDict
.update(self
.DefineVarDict
)
93 GenFdsGlobalVariable
.VerboseLogger('First generate Apriori file !')
95 for AprSection
in self
.AprioriSectionList
:
96 FileName
= AprSection
.GenFfs (self
.UiFvName
, MacroDict
)
97 FfsFileList
.append(FileName
)
98 # Add Apriori file name to Inf file
99 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
103 # Process Modules in FfsList
104 for FfsFile
in self
.FfsList
:
105 FileName
= FfsFile
.GenFfs(MacroDict
)
106 FfsFileList
.append(FileName
)
107 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
111 SaveFileOnChange(self
.InfFileName
, self
.FvInfFile
.getvalue(), False)
112 self
.FvInfFile
.close()
116 FvOutputFile
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.UiFvName
)
117 FvOutputFile
= FvOutputFile
+ '.Fv'
118 # BUGBUG: FvOutputFile could be specified from FDF file (FV section, CreateFile statement)
119 if self
.CreateFileName
!= None:
120 FvOutputFile
= self
.CreateFileName
122 FvInfoFileName
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, self
.UiFvName
+ '.inf')
123 shutil
.copy(GenFdsGlobalVariable
.FvAddressFileName
, FvInfoFileName
)
124 GenFdsGlobalVariable
.GenerateFirmwareVolume(
127 AddressFile
=FvInfoFileName
,
132 # Write the Fv contents to Buffer
134 FvFileObj
= open ( FvOutputFile
,'r+b')
136 GenFdsGlobalVariable
.VerboseLogger( "\nGenerate %s FV Successfully" %self
.UiFvName
)
137 GenFdsGlobalVariable
.SharpCounter
= 0
139 Buffer
.write(FvFileObj
.read())
141 GenFds
.ImageBinDict
[self
.UiFvName
.upper() + 'fv'] = FvOutputFile
144 ## __InitializeInf__()
146 # Initilize the inf file to create FV
148 # @param self The object pointer
149 # @param BaseAddress base address of FV
150 # @param BlockSize block size of FV
151 # @param BlockNum How many blocks in FV
152 # @param ErasePolarity Flash erase polarity
153 # @param VtfDict VTF objects
155 def __InitializeInf__ (self
, BaseAddress
= None, BlockSize
= None, BlockNum
= None, ErasePloarity
='1', VtfDict
=None) :
159 self
.InfFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
,
160 self
.UiFvName
+ '.inf')
161 self
.FvInfFile
= StringIO
.StringIO()
166 self
.FvInfFile
.writelines("[options]" + T_CHAR_LF
)
167 if BaseAddress
!= None :
168 self
.FvInfFile
.writelines("EFI_BASE_ADDRESS = " + \
172 if BlockSize
!= None:
173 self
.FvInfFile
.writelines("EFI_BLOCK_SIZE = " + \
174 '0x%X' %BlockSize
+ \
177 self
.FvInfFile
.writelines("EFI_NUM_BLOCKS = " + \
178 ' 0x%X' %BlockNum
+ \
181 for BlockSize
in self
.BlockSizeList
:
182 if BlockSize
[0] != None:
183 self
.FvInfFile
.writelines("EFI_BLOCK_SIZE = " + \
184 '0x%X' %BlockSize
[0] + \
187 if BlockSize
[1] != None:
188 self
.FvInfFile
.writelines("EFI_NUM_BLOCKS = " + \
189 ' 0x%X' %BlockSize
[1] + \
192 if self
.BsBaseAddress
!= None:
193 self
.FvInfFile
.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \
194 '0x%X' %self
.BsBaseAddress
)
195 if self
.RtBaseAddress
!= None:
196 self
.FvInfFile
.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \
197 '0x%X' %self
.RtBaseAddress
)
201 self
.FvInfFile
.writelines("[attributes]" + T_CHAR_LF
)
203 self
.FvInfFile
.writelines("EFI_ERASE_POLARITY = " + \
204 ' %s' %ErasePloarity
+ \
206 if not (self
.FvAttributeDict
== None):
207 for FvAttribute
in self
.FvAttributeDict
.keys() :
208 self
.FvInfFile
.writelines("EFI_" + \
211 self
.FvAttributeDict
[FvAttribute
] + \
213 if self
.FvAlignment
!= None:
214 self
.FvInfFile
.writelines("EFI_FVB2_ALIGNMENT_" + \
215 self
.FvAlignment
.strip() + \
219 if self
.FvNameGuid
!= None:
220 self
.FvInfFile
.writelines("EFI_FVNAME_GUID" + \
221 " = %s" % self
.FvNameGuid
+ \
227 self
.FvInfFile
.writelines("[files]" + T_CHAR_LF
)
228 if VtfDict
!= None and self
.UiFvName
in VtfDict
.keys():
229 self
.FvInfFile
.writelines("EFI_FILE_NAME = " + \
230 VtfDict
.get(self
.UiFvName
) + \