]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
53318c9ea5c0104172b92d5d0d8977a8f897fc1a
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.
18 from __future__
import absolute_import
21 import Common
.LongFilePathOs
as os
22 from io
import BytesIO
25 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
26 from CommonDataClass
.FdfClass
import FDClassObject
27 from Common
import EdkLogger
28 from Common
.BuildToolError
import *
29 from Common
.Misc
import SaveFileOnChange
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 from .GenFds
import GenFds
51 if self
.FdUiName
.upper() + 'fd' in GenFds
.ImageBinDict
:
52 return GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd']
57 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.FdUiName
+ '.fd')
59 GenFdsGlobalVariable
.InfLogger("\nFd File Name:%s (%s)" %(self
.FdUiName
, FdFileName
))
62 for item
in self
.BlockSizeList
:
63 Offset
= Offset
+ item
[0] * item
[1]
64 if Offset
!= self
.Size
:
65 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
66 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
67 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
68 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
70 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
73 HasCapsuleRegion
= False
74 for RegionObj
in self
.RegionList
:
75 if RegionObj
.RegionType
== 'CAPSULE':
76 HasCapsuleRegion
= True
79 TempFdBuffer
= BytesIO('')
80 PreviousRegionStart
= -1
81 PreviousRegionSize
= 1
83 for RegionObj
in self
.RegionList
:
84 if RegionObj
.RegionType
== 'CAPSULE':
86 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
88 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
90 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
92 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
93 PadRegion
= Region
.Region()
94 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
95 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
97 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
98 PreviousRegionStart
= RegionObj
.Offset
99 PreviousRegionSize
= RegionObj
.Size
101 # Call each region's AddToBuffer function
103 if PreviousRegionSize
> self
.Size
:
105 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
106 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
108 FdBuffer
= BytesIO('')
109 PreviousRegionStart
= -1
110 PreviousRegionSize
= 1
111 for RegionObj
in self
.RegionList
:
112 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
113 EdkLogger
.error("GenFds", GENFDS_ERROR
,
114 '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.'\
115 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
116 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
117 EdkLogger
.error("GenFds", GENFDS_ERROR
,
118 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
119 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
120 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
122 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
123 PadRegion
= Region
.Region()
124 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
125 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
127 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
128 PreviousRegionStart
= RegionObj
.Offset
129 PreviousRegionSize
= RegionObj
.Size
131 # Verify current region fits within allocated FD section Size
133 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
134 EdkLogger
.error("GenFds", GENFDS_ERROR
,
135 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
136 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
138 # Call each region's AddToBuffer function
140 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
141 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
, Flag
=Flag
)
143 # Write the buffer contents to Fd file
145 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
147 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
149 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
154 # @param self The object pointer
156 def GenVtfFile (self
) :
158 # Get this Fd's all Fv name
162 for RegionObj
in self
.RegionList
:
163 if RegionObj
.RegionType
== BINARY_FILE_TYPE_FV
:
164 if len(RegionObj
.RegionDataList
) == 1:
165 RegionData
= RegionObj
.RegionDataList
[0]
166 FvList
.append(RegionData
.upper())
167 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
, 16) + \
168 RegionObj
.Offset
, RegionObj
.Size
)
170 Offset
= RegionObj
.Offset
171 for RegionData
in RegionObj
.RegionDataList
:
172 FvList
.append(RegionData
.upper())
173 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
174 if len(FvObj
.BlockSizeList
) < 1:
175 EdkLogger
.error("GenFds", GENFDS_ERROR
,
176 'FV.%s must point out FVs blocksize and Fv BlockNum' \
180 for blockStatement
in FvObj
.BlockSizeList
:
181 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
182 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
, 16) + \
184 Offset
= Offset
+ Size
186 # Check whether this Fd need VTF
189 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
190 compLocList
= VtfObj
.GetFvList()
191 if set(compLocList
).issubset(FvList
):
195 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
197 ## generate flash map file
199 # @param self The object pointer
201 def GenFlashMap (self
):