]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
370008c91897191178404fd30a96e7e6704d8b50
2 # process FD generation
4 # Copyright (c) 2007, Intel Corporation
6 # All rights reserved. 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.
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 GenFdsGlobalVariable
.InfLogger("Fd File Name:%s" %self
.FdUiName
)
57 for item
in self
.BlockSizeList
:
58 Offset
= Offset
+ item
[0] * item
[1]
59 if Offset
!= self
.Size
:
60 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
61 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
62 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
63 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
65 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
68 FdBuffer
= StringIO
.StringIO('')
69 PreviousRegionStart
= -1
70 PreviousRegionSize
= 1
71 for RegionObj
in self
.RegionList
:
72 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
73 EdkLogger
.error("GenFds", GENFDS_ERROR
,
74 '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.'\
75 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
76 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
77 EdkLogger
.error("GenFds", GENFDS_ERROR
,
78 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
79 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
80 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
81 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
82 PadRegion
= Region
.Region()
83 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
84 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
85 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
86 PreviousRegionStart
= RegionObj
.Offset
87 PreviousRegionSize
= RegionObj
.Size
89 # Call each region's AddToBuffer function
91 if PreviousRegionSize
> self
.Size
:
92 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s size too small' % self
.FdUiName
)
93 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
94 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFds
.ImageBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
96 # Create a empty Fd file
98 GenFdsGlobalVariable
.VerboseLogger ('Create an empty Fd file')
99 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
,self
.FdUiName
+ '.fd')
101 # Write the buffer contents to Fd file
103 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
104 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
106 GenFds
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
111 # @param self The object pointer
113 def GenVtfFile (self
) :
115 # Get this Fd's all Fv name
119 for RegionObj
in self
.RegionList
:
120 if RegionObj
.RegionType
== 'FV':
121 if len(RegionObj
.RegionDataList
) == 1:
122 RegionData
= RegionObj
.RegionDataList
[0]
123 FvList
.append(RegionData
.upper())
124 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
125 RegionObj
.Offset
, RegionObj
.Size
)
127 Offset
= RegionObj
.Offset
128 for RegionData
in RegionObj
.RegionDataList
:
129 FvList
.append(RegionData
.upper())
130 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
131 if len(FvObj
.BlockSizeList
) < 1:
132 EdkLogger
.error("GenFds", GENFDS_ERROR
,
133 'FV.%s must point out FVs blocksize and Fv BlockNum' \
137 for blockStatement
in FvObj
.BlockSizeList
:
138 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
139 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
141 Offset
= Offset
+ Size
143 # Check whether this Fd need VTF
146 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
147 compLocList
= VtfObj
.GetFvList()
148 if set(compLocList
).issubset(FvList
):
152 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
154 ## generate flash map file
156 # @param self The object pointer
158 def GenFlashMap (self
):