]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
684b5cea88bef2aa4c976081131df64bd7b0c6ab
2 # process FD generation
4 # Copyright (c) 2007 - 2014, 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 TempFdBuffer
= StringIO
.StringIO('')
71 PreviousRegionStart
= -1
72 PreviousRegionSize
= 1
74 for RegionObj
in self
.RegionList
:
75 if RegionObj
.RegionType
== 'CAPSULE':
77 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
79 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
81 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
82 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
83 PadRegion
= Region
.Region()
84 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
85 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
86 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
87 PreviousRegionStart
= RegionObj
.Offset
88 PreviousRegionSize
= RegionObj
.Size
90 # Call each region's AddToBuffer function
92 if PreviousRegionSize
> self
.Size
:
94 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
95 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
97 FdBuffer
= StringIO
.StringIO('')
98 PreviousRegionStart
= -1
99 PreviousRegionSize
= 1
100 for RegionObj
in self
.RegionList
:
101 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
102 EdkLogger
.error("GenFds", GENFDS_ERROR
,
103 '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.'\
104 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
105 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
106 EdkLogger
.error("GenFds", GENFDS_ERROR
,
107 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
108 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
109 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
110 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
111 PadRegion
= Region
.Region()
112 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
113 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
114 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
115 PreviousRegionStart
= RegionObj
.Offset
116 PreviousRegionSize
= RegionObj
.Size
118 # Verify current region fits within allocated FD section Size
120 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
121 EdkLogger
.error("GenFds", GENFDS_ERROR
,
122 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
123 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
125 # Call each region's AddToBuffer function
127 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
128 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
130 # Write the buffer contents to Fd file
132 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
133 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
135 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
140 # @param self The object pointer
142 def GenVtfFile (self
) :
144 # Get this Fd's all Fv name
148 for RegionObj
in self
.RegionList
:
149 if RegionObj
.RegionType
== 'FV':
150 if len(RegionObj
.RegionDataList
) == 1:
151 RegionData
= RegionObj
.RegionDataList
[0]
152 FvList
.append(RegionData
.upper())
153 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
154 RegionObj
.Offset
, RegionObj
.Size
)
156 Offset
= RegionObj
.Offset
157 for RegionData
in RegionObj
.RegionDataList
:
158 FvList
.append(RegionData
.upper())
159 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
160 if len(FvObj
.BlockSizeList
) < 1:
161 EdkLogger
.error("GenFds", GENFDS_ERROR
,
162 'FV.%s must point out FVs blocksize and Fv BlockNum' \
166 for blockStatement
in FvObj
.BlockSizeList
:
167 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
168 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
170 Offset
= Offset
+ Size
172 # Check whether this Fd need VTF
175 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
176 compLocList
= VtfObj
.GetFvList()
177 if set(compLocList
).issubset(FvList
):
181 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
183 ## generate flash map file
185 # @param self The object pointer
187 def GenFlashMap (self
):