]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
370008c91897191178404fd30a96e7e6704d8b50
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Fd.py
1 ## @file
2 # process FD generation
3 #
4 # Copyright (c) 2007, Intel Corporation
5 #
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
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 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 GenFdsGlobalVariable.InfLogger("Fd File Name:%s" %self.FdUiName)
56 Offset = 0x00
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)
64
65 GenFdsGlobalVariable.VerboseLogger('################### Gen VTF ####################')
66 self.GenVtfFile()
67
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
88 #
89 # Call each region's AddToBuffer function
90 #
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)
95 #
96 # Create a empty Fd file
97 #
98 GenFdsGlobalVariable.VerboseLogger ('Create an empty Fd file')
99 FdFileName = os.path.join(GenFdsGlobalVariable.FvDir,self.FdUiName + '.fd')
100 #
101 # Write the buffer contents to Fd file
102 #
103 GenFdsGlobalVariable.VerboseLogger('Write the buffer contents to Fd file')
104 SaveFileOnChange(FdFileName, FdBuffer.getvalue())
105 FdBuffer.close();
106 GenFds.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName
107 return FdFileName
108
109 ## generate VTF
110 #
111 # @param self The object pointer
112 #
113 def GenVtfFile (self) :
114 #
115 # Get this Fd's all Fv name
116 #
117 FvAddDict ={}
118 FvList = []
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)
126 else:
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' \
134 % FvObj.UiFvName)
135 else:
136 Size = 0
137 for blockStatement in FvObj.BlockSizeList:
138 Size = Size + blockStatement[0] * blockStatement[1]
139 FvAddDict[RegionData.upper()] = (int(self.BaseAddress,16) + \
140 Offset, Size)
141 Offset = Offset + Size
142 #
143 # Check whether this Fd need VTF
144 #
145 Flag = False
146 for VtfObj in GenFdsGlobalVariable.FdfParser.Profile.VtfList:
147 compLocList = VtfObj.GetFvList()
148 if set(compLocList).issubset(FvList):
149 Flag = True
150 break
151 if Flag == True:
152 self.vtfRawDict = VtfObj.GenVtf(FvAddDict)
153
154 ## generate flash map file
155 #
156 # @param self The object pointer
157 #
158 def GenFlashMap (self):
159 pass
160
161
162
163
164
165
166
167