]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
Check In tool source code based on Build tool project revision r1655.
[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
30 ## generate FD
31 #
32 #
33 class FD(FDClassObject):
34 ## The constructor
35 #
36 # @param self The object pointer
37 #
38 def __init__(self):
39 FDClassObject.__init__(self)
40
41 ## GenFd() method
42 #
43 # Generate FD
44 #
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
48 #
49 def GenFd (self, FvBinDict):
50 #
51 # Print Information
52 #
53 GenFdsGlobalVariable.InfLogger("Fd File Name:%s" %self.FdUiName)
54 Offset = 0x00
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)
62
63 GenFdsGlobalVariable.VerboseLogger('################### Gen VTF ####################')
64 self.GenVtfFile()
65
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
86 #
87 # Call each region's AddToBuffer function
88 #
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)
93 #
94 # Create a empty Fd file
95 #
96 GenFdsGlobalVariable.VerboseLogger ('Create an empty Fd file')
97 FdFileName = os.path.join(GenFdsGlobalVariable.FvDir,
98 self.FdUiName + '.fd')
99 #FdFile = open(FdFileName, 'wb')
100
101 #
102 # Write the buffer contents to Fd file
103 #
104 GenFdsGlobalVariable.VerboseLogger('Write the buffer contents to Fd file')
105 SaveFileOnChange(FdFileName, FdBuffer.getvalue())
106 #FdFile.write(FdBuffer.getvalue());
107 #FdFile.close();
108 FdBuffer.close();
109 return FdFileName
110
111 ## generate VTF
112 #
113 # @param self The object pointer
114 #
115 def GenVtfFile (self) :
116 #
117 # Get this Fd's all Fv name
118 #
119 FvAddDict ={}
120 FvList = []
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)
128 else:
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' \
136 % FvObj.UiFvName)
137 else:
138 Size = 0
139 for blockStatement in FvObj.BlockSizeList:
140 Size = Size + blockStatement[0] * blockStatement[1]
141 FvAddDict[RegionData.upper()] = (int(self.BaseAddress,16) + \
142 Offset, Size)
143 Offset = Offset + Size
144 #
145 # Check whether this Fd need VTF
146 #
147 Flag = False
148 for VtfObj in GenFdsGlobalVariable.FdfParser.Profile.VtfList:
149 compLocList = VtfObj.GetFvList()
150 if set(compLocList).issubset(FvList):
151 Flag = True
152 break
153 if Flag == True:
154 self.vtfRawDict = VtfObj.GenVtf(FvAddDict)
155
156 ## generate flash map file
157 #
158 # @param self The object pointer
159 #
160 def GenFlashMap (self):
161 pass
162
163
164
165
166
167
168
169