]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
BaseTools: Fix the Keyword error for <ExtendedFvEntry> in FDF File
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fd.py
1 ## @file
2 # process FD generation
3 #
4 # Copyright (c) 2007 - 2017, 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 HasCapsuleRegion = False
71 for RegionObj in self.RegionList:
72 if RegionObj.RegionType == 'CAPSULE':
73 HasCapsuleRegion = True
74 break
75 if HasCapsuleRegion:
76 TempFdBuffer = StringIO.StringIO('')
77 PreviousRegionStart = -1
78 PreviousRegionSize = 1
79
80 for RegionObj in self.RegionList :
81 if RegionObj.RegionType == 'CAPSULE':
82 continue
83 if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:
84 pass
85 elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):
86 pass
87 elif RegionObj.Offset > PreviousRegionStart + PreviousRegionSize:
88 GenFdsGlobalVariable.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart + PreviousRegionSize, RegionObj.Offset - (PreviousRegionStart + PreviousRegionSize)))
89 PadRegion = Region.Region()
90 PadRegion.Offset = PreviousRegionStart + PreviousRegionSize
91 PadRegion.Size = RegionObj.Offset - PadRegion.Offset
92 PadRegion.AddToBuffer(TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
93 PreviousRegionStart = RegionObj.Offset
94 PreviousRegionSize = RegionObj.Size
95 #
96 # Call each region's AddToBuffer function
97 #
98 if PreviousRegionSize > self.Size:
99 pass
100 GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')
101 RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
102
103 FdBuffer = StringIO.StringIO('')
104 PreviousRegionStart = -1
105 PreviousRegionSize = 1
106 for RegionObj in self.RegionList :
107 if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:
108 EdkLogger.error("GenFds", GENFDS_ERROR,
109 '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.'\
110 % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))
111 elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):
112 EdkLogger.error("GenFds", GENFDS_ERROR,
113 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
114 % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))
115 elif RegionObj.Offset > PreviousRegionStart + PreviousRegionSize:
116 GenFdsGlobalVariable.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart + PreviousRegionSize, RegionObj.Offset - (PreviousRegionStart + PreviousRegionSize)))
117 PadRegion = Region.Region()
118 PadRegion.Offset = PreviousRegionStart + PreviousRegionSize
119 PadRegion.Size = RegionObj.Offset - PadRegion.Offset
120 PadRegion.AddToBuffer(FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
121 PreviousRegionStart = RegionObj.Offset
122 PreviousRegionSize = RegionObj.Size
123 #
124 # Verify current region fits within allocated FD section Size
125 #
126 if PreviousRegionStart + PreviousRegionSize > self.Size:
127 EdkLogger.error("GenFds", GENFDS_ERROR,
128 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
129 % (self.FdUiName, PreviousRegionStart, PreviousRegionSize))
130 #
131 # Call each region's AddToBuffer function
132 #
133 GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')
134 RegionObj.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
135 #
136 # Write the buffer contents to Fd file
137 #
138 GenFdsGlobalVariable.VerboseLogger('Write the buffer contents to Fd file')
139 SaveFileOnChange(FdFileName, FdBuffer.getvalue())
140 FdBuffer.close();
141 GenFds.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName
142 return FdFileName
143
144 ## generate VTF
145 #
146 # @param self The object pointer
147 #
148 def GenVtfFile (self) :
149 #
150 # Get this Fd's all Fv name
151 #
152 FvAddDict ={}
153 FvList = []
154 for RegionObj in self.RegionList:
155 if RegionObj.RegionType == 'FV':
156 if len(RegionObj.RegionDataList) == 1:
157 RegionData = RegionObj.RegionDataList[0]
158 FvList.append(RegionData.upper())
159 FvAddDict[RegionData.upper()] = (int(self.BaseAddress,16) + \
160 RegionObj.Offset, RegionObj.Size)
161 else:
162 Offset = RegionObj.Offset
163 for RegionData in RegionObj.RegionDataList:
164 FvList.append(RegionData.upper())
165 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper())
166 if len(FvObj.BlockSizeList) < 1:
167 EdkLogger.error("GenFds", GENFDS_ERROR,
168 'FV.%s must point out FVs blocksize and Fv BlockNum' \
169 % FvObj.UiFvName)
170 else:
171 Size = 0
172 for blockStatement in FvObj.BlockSizeList:
173 Size = Size + blockStatement[0] * blockStatement[1]
174 FvAddDict[RegionData.upper()] = (int(self.BaseAddress,16) + \
175 Offset, Size)
176 Offset = Offset + Size
177 #
178 # Check whether this Fd need VTF
179 #
180 Flag = False
181 for VtfObj in GenFdsGlobalVariable.FdfParser.Profile.VtfList:
182 compLocList = VtfObj.GetFvList()
183 if set(compLocList).issubset(FvList):
184 Flag = True
185 break
186 if Flag == True:
187 self.vtfRawDict = VtfObj.GenVtf(FvAddDict)
188
189 ## generate flash map file
190 #
191 # @param self The object pointer
192 #
193 def GenFlashMap (self):
194 pass
195
196
197
198
199
200
201
202