]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
BaseTools: Report Fd File Path in build log
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fd.py
1 ## @file
2 # process FD generation
3 #
4 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
5 #
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
10 #
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.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Region
19 import Fv
20 import Common.LongFilePathOs as os
21 import StringIO
22 import sys
23 from struct import *
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
31 ## generate FD
32 #
33 #
34 class FD(FDClassObject):
35 ## The constructor
36 #
37 # @param self The object pointer
38 #
39 def __init__(self):
40 FDClassObject.__init__(self)
41
42 ## GenFd() method
43 #
44 # Generate FD
45 #
46 # @retval string Generated FD file name
47 #
48 def GenFd (self):
49 if self.FdUiName.upper() + 'fd' in GenFds.ImageBinDict.keys():
50 return GenFds.ImageBinDict[self.FdUiName.upper() + 'fd']
51
52 #
53 # Print Information
54 #
55 FdFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.FdUiName + '.fd')
56 GenFdsGlobalVariable.InfLogger("Fd File Name:%s (%s)" %(self.FdUiName, FdFileName))
57
58 Offset = 0x00
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)
66
67 GenFdsGlobalVariable.VerboseLogger('################### Gen VTF ####################')
68 self.GenVtfFile()
69
70 TempFdBuffer = StringIO.StringIO('')
71 PreviousRegionStart = -1
72 PreviousRegionSize = 1
73
74 for RegionObj in self.RegionList :
75 if RegionObj.RegionType == 'CAPSULE':
76 continue
77 if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:
78 pass
79 elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):
80 pass
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
89 #
90 # Call each region's AddToBuffer function
91 #
92 if PreviousRegionSize > self.Size:
93 pass
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)
96
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
117 #
118 # Verify current region fits within allocated FD section Size
119 #
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))
124 #
125 # Call each region's AddToBuffer function
126 #
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)
129 #
130 # Write the buffer contents to Fd file
131 #
132 GenFdsGlobalVariable.VerboseLogger('Write the buffer contents to Fd file')
133 SaveFileOnChange(FdFileName, FdBuffer.getvalue())
134 FdBuffer.close();
135 GenFds.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName
136 return FdFileName
137
138 ## generate VTF
139 #
140 # @param self The object pointer
141 #
142 def GenVtfFile (self) :
143 #
144 # Get this Fd's all Fv name
145 #
146 FvAddDict ={}
147 FvList = []
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)
155 else:
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' \
163 % FvObj.UiFvName)
164 else:
165 Size = 0
166 for blockStatement in FvObj.BlockSizeList:
167 Size = Size + blockStatement[0] * blockStatement[1]
168 FvAddDict[RegionData.upper()] = (int(self.BaseAddress,16) + \
169 Offset, Size)
170 Offset = Offset + Size
171 #
172 # Check whether this Fd need VTF
173 #
174 Flag = False
175 for VtfObj in GenFdsGlobalVariable.FdfParser.Profile.VtfList:
176 compLocList = VtfObj.GetFvList()
177 if set(compLocList).issubset(FvList):
178 Flag = True
179 break
180 if Flag == True:
181 self.vtfRawDict = VtfObj.GenVtf(FvAddDict)
182
183 ## generate flash map file
184 #
185 # @param self The object pointer
186 #
187 def GenFlashMap (self):
188 pass
189
190
191
192
193
194
195
196