]>
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
30 from Common
.DataType
import BINARY_FILE_TYPE_FV
35 class FD(FDClassObject
):
38 # @param self The object pointer
41 FDClassObject
.__init
__(self
)
47 # @retval string Generated FD file name
49 def GenFd (self
, Flag
= False):
50 if self
.FdUiName
.upper() + 'fd' in GenFds
.ImageBinDict
:
51 return GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd']
56 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.FdUiName
+ '.fd')
58 GenFdsGlobalVariable
.InfLogger("\nFd File Name:%s (%s)" %(self
.FdUiName
, FdFileName
))
61 for item
in self
.BlockSizeList
:
62 Offset
= Offset
+ item
[0] * item
[1]
63 if Offset
!= self
.Size
:
64 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
65 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
66 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
67 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
69 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
72 HasCapsuleRegion
= False
73 for RegionObj
in self
.RegionList
:
74 if RegionObj
.RegionType
== 'CAPSULE':
75 HasCapsuleRegion
= True
78 TempFdBuffer
= StringIO
.StringIO('')
79 PreviousRegionStart
= -1
80 PreviousRegionSize
= 1
82 for RegionObj
in self
.RegionList
:
83 if RegionObj
.RegionType
== 'CAPSULE':
85 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
87 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
89 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
91 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
92 PadRegion
= Region
.Region()
93 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
94 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
96 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
97 PreviousRegionStart
= RegionObj
.Offset
98 PreviousRegionSize
= RegionObj
.Size
100 # Call each region's AddToBuffer function
102 if PreviousRegionSize
> self
.Size
:
104 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
105 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
107 FdBuffer
= StringIO
.StringIO('')
108 PreviousRegionStart
= -1
109 PreviousRegionSize
= 1
110 for RegionObj
in self
.RegionList
:
111 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
112 EdkLogger
.error("GenFds", GENFDS_ERROR
,
113 '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.'\
114 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
115 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
116 EdkLogger
.error("GenFds", GENFDS_ERROR
,
117 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
118 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
119 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
121 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
122 PadRegion
= Region
.Region()
123 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
124 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
126 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
127 PreviousRegionStart
= RegionObj
.Offset
128 PreviousRegionSize
= RegionObj
.Size
130 # Verify current region fits within allocated FD section Size
132 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
133 EdkLogger
.error("GenFds", GENFDS_ERROR
,
134 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
135 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
137 # Call each region's AddToBuffer function
139 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
140 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
, Flag
=Flag
)
142 # Write the buffer contents to Fd file
144 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
146 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
148 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
153 # @param self The object pointer
155 def GenVtfFile (self
) :
157 # Get this Fd's all Fv name
161 for RegionObj
in self
.RegionList
:
162 if RegionObj
.RegionType
== BINARY_FILE_TYPE_FV
:
163 if len(RegionObj
.RegionDataList
) == 1:
164 RegionData
= RegionObj
.RegionDataList
[0]
165 FvList
.append(RegionData
.upper())
166 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
, 16) + \
167 RegionObj
.Offset
, RegionObj
.Size
)
169 Offset
= RegionObj
.Offset
170 for RegionData
in RegionObj
.RegionDataList
:
171 FvList
.append(RegionData
.upper())
172 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
173 if len(FvObj
.BlockSizeList
) < 1:
174 EdkLogger
.error("GenFds", GENFDS_ERROR
,
175 'FV.%s must point out FVs blocksize and Fv BlockNum' \
179 for blockStatement
in FvObj
.BlockSizeList
:
180 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
181 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
, 16) + \
183 Offset
= Offset
+ Size
185 # Check whether this Fd need VTF
188 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
189 compLocList
= VtfObj
.GetFvList()
190 if set(compLocList
).issubset(FvList
):
194 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
196 ## generate flash map file
198 # @param self The object pointer
200 def GenFlashMap (self
):