]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
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
33 class FD(FDClassObject
):
36 # @param self The object pointer
39 FDClassObject
.__init
__(self
)
45 # @param self The object pointer
46 # @param FvBinDict dictionary contains generated FV name and its file name
47 # @retval string Generated FD file name
49 def GenFd (self
, FvBinDict
):
53 GenFdsGlobalVariable
.InfLogger("Fd File Name:%s" %self
.FdUiName
)
55 for item
in self
.BlockSizeList
:
56 Offset
= Offset
+ item
[0] * item
[1]
57 if Offset
!= self
.Size
:
58 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
59 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
60 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
61 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
63 GenFdsGlobalVariable
.VerboseLogger('################### Gen VTF ####################')
66 FdBuffer
= StringIO
.StringIO('')
67 PreviousRegionStart
= -1
68 PreviousRegionSize
= 1
69 for RegionObj
in self
.RegionList
:
70 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
71 EdkLogger
.error("GenFds", GENFDS_ERROR
,
72 '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.'\
73 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
74 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
75 EdkLogger
.error("GenFds", GENFDS_ERROR
,
76 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
77 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
78 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
79 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
80 PadRegion
= Region
.Region()
81 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
82 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
83 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, FvBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
84 PreviousRegionStart
= RegionObj
.Offset
85 PreviousRegionSize
= RegionObj
.Size
87 # Call each region's AddToBuffer function
89 if PreviousRegionSize
> self
.Size
:
90 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s size too small' % self
.FdUiName
)
91 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
92 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, FvBinDict
, self
.vtfRawDict
, self
.DefineVarDict
)
94 # Create a empty Fd file
96 GenFdsGlobalVariable
.VerboseLogger ('Create an empty Fd file')
97 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
,
98 self
.FdUiName
+ '.fd')
99 #FdFile = open(FdFileName, 'wb')
102 # Write the buffer contents to Fd file
104 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
105 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
106 #FdFile.write(FdBuffer.getvalue());
113 # @param self The object pointer
115 def GenVtfFile (self
) :
117 # Get this Fd's all Fv name
121 for RegionObj
in self
.RegionList
:
122 if RegionObj
.RegionType
== 'FV':
123 if len(RegionObj
.RegionDataList
) == 1:
124 RegionData
= RegionObj
.RegionDataList
[0]
125 FvList
.append(RegionData
.upper())
126 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
127 RegionObj
.Offset
, RegionObj
.Size
)
129 Offset
= RegionObj
.Offset
130 for RegionData
in RegionObj
.RegionDataList
:
131 FvList
.append(RegionData
.upper())
132 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(RegionData
.upper())
133 if len(FvObj
.BlockSizeList
) < 1:
134 EdkLogger
.error("GenFds", GENFDS_ERROR
,
135 'FV.%s must point out FVs blocksize and Fv BlockNum' \
139 for blockStatement
in FvObj
.BlockSizeList
:
140 Size
= Size
+ blockStatement
[0] * blockStatement
[1]
141 FvAddDict
[RegionData
.upper()] = (int(self
.BaseAddress
,16) + \
143 Offset
= Offset
+ Size
145 # Check whether this Fd need VTF
148 for VtfObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.VtfList
:
149 compLocList
= VtfObj
.GetFvList()
150 if set(compLocList
).issubset(FvList
):
154 self
.vtfRawDict
= VtfObj
.GenVtf(FvAddDict
)
156 ## generate flash map file
158 # @param self The object pointer
160 def GenFlashMap (self
):