]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
2 # process FD generation
4 # Copyright (c) 2007 - 2018, 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
48 def GenFd (self
, Flag
= False):
49 if self
.FdUiName
.upper() + 'fd' in GenFds
.ImageBinDict
:
50 return GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd']
55 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.FdUiName
+ '.fd')
57 GenFdsGlobalVariable
.InfLogger("\nFd File Name:%s (%s)" %(self
.FdUiName
, FdFileName
))
60 for item
in self
.BlockSizeList
:
61 Offset
= Offset
+ item
[0] * item
[1]
62 if Offset
!= self
.Size
:
63 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
64 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
65 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
66 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
68 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
71 HasCapsuleRegion
= False
72 for RegionObj
in self
.RegionList
:
73 if RegionObj
.RegionType
== 'CAPSULE':
74 HasCapsuleRegion
= True
77 TempFdBuffer
= StringIO
.StringIO('')
78 PreviousRegionStart
= -1
79 PreviousRegionSize
= 1
81 for RegionObj
in self
.RegionList
:
82 if RegionObj
.RegionType
== 'CAPSULE':
84 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
86 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
88 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
90 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
91 PadRegion
= Region
.Region()
92 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
93 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
95 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
96 PreviousRegionStart
= RegionObj
.Offset
97 PreviousRegionSize
= RegionObj
.Size
99 # Call each region's AddToBuffer function
101 if PreviousRegionSize
> self
.Size
:
103 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
104 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
106 FdBuffer
= StringIO
.StringIO('')
107 PreviousRegionStart
= -1
108 PreviousRegionSize
= 1
109 for RegionObj
in self
.RegionList
:
110 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
111 EdkLogger
.error("GenFds", GENFDS_ERROR
,
112 '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.'\
113 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
114 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
115 EdkLogger
.error("GenFds", GENFDS_ERROR
,
116 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
117 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
118 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
120 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
121 PadRegion
= Region
.Region()
122 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
123 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
125 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
126 PreviousRegionStart
= RegionObj
.Offset
127 PreviousRegionSize
= RegionObj
.Size
129 # Verify current region fits within allocated FD section Size
131 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
132 EdkLogger
.error("GenFds", GENFDS_ERROR
,
133 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
134 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
136 # Call each region's AddToBuffer function
138 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
139 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
,Flag
=Flag
)
141 # Write the buffer contents to Fd file
143 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
145 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
147 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
152 # @param self The object pointer
154 def GenVtfFile (self
) :
156 # Get this Fd's all Fv name
160 for RegionObj
in self
.RegionList
:
161 if RegionObj
.RegionType
== 'FV':
162 if len(RegionObj
.RegionDataList
) == 1:
163 RegionData
= RegionObj
.RegionDataList
[0]
164 FvList
.append(RegionData
.upper())
165 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
166 RegionObj
.Offset
, RegionObj
.Size
)
168 Offset
= RegionObj
.Offset
169 for RegionData
in RegionObj
.RegionDataList
:
170 FvList
.append(RegionData
.upper())
171 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
172 if len(FvObj
.BlockSizeList
) < 1:
173 EdkLogger
.error("GenFds", GENFDS_ERROR
,
174 'FV.%s must point out FVs blocksize and Fv BlockNum' \
178 for blockStatement
in FvObj
.BlockSizeList
:
179 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
180 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
182 Offset
= Offset
+ Size
184 # Check whether this Fd need VTF
187 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
188 compLocList
= VtfObj
.GetFvList()
189 if set(compLocList
).issubset(FvList
):
193 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
195 ## generate flash map file
197 # @param self The object pointer
199 def GenFlashMap (self
):