]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
2 # process FD generation
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
6 # 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.
20 import Common
.LongFilePathOs
as os
24 from GenFdsGlobalVariable
import GenFdsGlobalVariable
25 from CommonDataClass
.FdfClass
import FDClassObject
26 from Common
import EdkLogger
27 from Common
.BuildToolError
import *
28 from Common
.Misc
import SaveFileOnChange
29 from GenFds
import GenFds
34 class FD(FDClassObject
):
37 # @param self The object pointer
40 FDClassObject
.__init
__(self
)
46 # @retval string Generated FD file name
49 if self
.FdUiName
.upper() + 'fd' in GenFds
.ImageBinDict
.keys():
50 return GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd']
55 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.FdUiName
+ '.fd')
56 GenFdsGlobalVariable
.InfLogger("Fd File Name:%s (%s)" %(self
.FdUiName
, FdFileName
))
59 for item
in self
.BlockSizeList
:
60 Offset
= Offset
+ item
[0] * item
[1]
61 if Offset
!= self
.Size
:
62 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
63 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
64 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
65 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
67 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
70 HasCapsuleRegion
= False
71 for RegionObj
in self
.RegionList
:
72 if RegionObj
.RegionType
== 'CAPSULE':
73 HasCapsuleRegion
= True
76 TempFdBuffer
= StringIO
.StringIO('')
77 PreviousRegionStart
= -1
78 PreviousRegionSize
= 1
80 for RegionObj
in self
.RegionList
:
81 if RegionObj
.RegionType
== 'CAPSULE':
83 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
85 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
87 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
88 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
89 PadRegion
= Region
.Region()
90 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
91 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
92 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
93 PreviousRegionStart
= RegionObj
.Offset
94 PreviousRegionSize
= RegionObj
.Size
96 # Call each region's AddToBuffer function
98 if PreviousRegionSize
> self
.Size
:
100 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
101 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
103 FdBuffer
= StringIO
.StringIO('')
104 PreviousRegionStart
= -1
105 PreviousRegionSize
= 1
106 for RegionObj
in self
.RegionList
:
107 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
108 EdkLogger
.error("GenFds", GENFDS_ERROR
,
109 'Region offset 0x%X in wrong order with Region starting from 0x%X, size 0x%X\nRegions in FDF must have offsets appear in ascending order.'\
110 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
111 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
112 EdkLogger
.error("GenFds", GENFDS_ERROR
,
113 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
114 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
115 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
116 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
117 PadRegion
= Region
.Region()
118 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
119 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
120 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
121 PreviousRegionStart
= RegionObj
.Offset
122 PreviousRegionSize
= RegionObj
.Size
124 # Verify current region fits within allocated FD section Size
126 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
127 EdkLogger
.error("GenFds", GENFDS_ERROR
,
128 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
129 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
131 # Call each region's AddToBuffer function
133 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
134 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
136 # Write the buffer contents to Fd file
138 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
139 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
141 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
146 # @param self The object pointer
148 def GenVtfFile (self
) :
150 # Get this Fd's all Fv name
154 for RegionObj
in self
.RegionList
:
155 if RegionObj
.RegionType
== 'FV':
156 if len(RegionObj
.RegionDataList
) == 1:
157 RegionData
= RegionObj
.RegionDataList
[0]
158 FvList
.append(RegionData
.upper())
159 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
160 RegionObj
.Offset
, RegionObj
.Size
)
162 Offset
= RegionObj
.Offset
163 for RegionData
in RegionObj
.RegionDataList
:
164 FvList
.append(RegionData
.upper())
165 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
166 if len(FvObj
.BlockSizeList
) < 1:
167 EdkLogger
.error("GenFds", GENFDS_ERROR
,
168 'FV.%s must point out FVs blocksize and Fv BlockNum' \
172 for blockStatement
in FvObj
.BlockSizeList
:
173 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
174 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
176 Offset
= Offset
+ Size
178 # Check whether this Fd need VTF
181 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
182 compLocList
= VtfObj
.GetFvList()
183 if set(compLocList
).issubset(FvList
):
187 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
189 ## generate flash map file
191 # @param self The object pointer
193 def GenFlashMap (self
):