1## @file 2# process VTF 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# 18from GenFdsGlobalVariable import GenFdsGlobalVariable 19import Common.LongFilePathOs as os 20from CommonDataClass.FdfClass import VtfClassObject 21from Common.LongFilePathSupport import OpenLongFilePath as open 22T_CHAR_LF = '\n' 23 24## generate VTF 25# 26# 27class Vtf (VtfClassObject): 28 29 ## The constructor 30 # 31 # @param self The object pointer 32 # 33 def __init__(self): 34 VtfClassObject.__init__(self) 35 36 ## GenVtf() method 37 # 38 # Generate VTF 39 # 40 # @param self The object pointer 41 # @param FdAddressDict dictionary contains FV name and its base address 42 # @retval Dict FV and corresponding VTF file name 43 # 44 def GenVtf(self, FdAddressDict) : 45 self.GenBsfInf() 46 OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.Vtf') 47 BaseAddArg = self.GetBaseAddressArg(FdAddressDict) 48 OutputArg, VtfRawDict = self.GenOutputArg() 49 50 Cmd = ( 51 'GenVtf', 52 ) + OutputArg + ( 53 '-f', self.BsfInfName, 54 ) + BaseAddArg 55 56 GenFdsGlobalVariable.CallExternalTool(Cmd, "GenFv -Vtf Failed!") 57 GenFdsGlobalVariable.SharpCounter = 0 58 59 return VtfRawDict 60 61 ## GenBsfInf() method 62 # 63 # Generate inf used to generate VTF 64 # 65 # @param self The object pointer 66 # 67 def GenBsfInf (self): 68 FvList = self.GetFvList() 69 self.BsfInfName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.inf') 70 BsfInf = open(self.BsfInfName, 'w+') 71 if self.ResetBin != None: 72 BsfInf.writelines ("[OPTIONS]" + T_CHAR_LF) 73 BsfInf.writelines ("IA32_RST_BIN" + \ 74 " = " + \ 75 GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.ResetBin)) + \ 76 T_CHAR_LF) 77 BsfInf.writelines (T_CHAR_LF) 78 79 BsfInf.writelines ("[COMPONENTS]" + T_CHAR_LF) 80 81 for ComponentObj in self.ComponentStatementList : 82 BsfInf.writelines ("COMP_NAME" + \ 83 " = " + \ 84 ComponentObj.CompName + \ 85 T_CHAR_LF) 86 if ComponentObj.CompLoc.upper() == 'NONE': 87 BsfInf.writelines ("COMP_LOC" + \ 88 " = " + \ 89 'N' + \ 90 T_CHAR_LF) 91 92 elif ComponentObj.FilePos != None: 93 BsfInf.writelines ("COMP_LOC" + \ 94 " = " + \ 95 ComponentObj.FilePos + \ 96 T_CHAR_LF) 97 else: 98 Index = FvList.index(ComponentObj.CompLoc.upper()) 99 if Index == 0: 100 BsfInf.writelines ("COMP_LOC" + \ 101 " = " + \ 102 'F' + \ 103 T_CHAR_LF) 104 elif Index == 1: 105 BsfInf.writelines ("COMP_LOC" + \ 106 " = " + \ 107 'S' + \ 108 T_CHAR_LF) 109 110 BsfInf.writelines ("COMP_TYPE" + \ 111 " = " + \ 112 ComponentObj.CompType + \ 113 T_CHAR_LF) 114 BsfInf.writelines ("COMP_VER" + \ 115 " = " + \ 116 ComponentObj.CompVer + \ 117 T_CHAR_LF) 118 BsfInf.writelines ("COMP_CS" + \ 119 " = " + \ 120 ComponentObj.CompCs + \ 121 T_CHAR_LF) 122 123 BinPath = ComponentObj.CompBin 124 if BinPath != '-': 125 BinPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(BinPath)) 126 BsfInf.writelines ("COMP_BIN" + \ 127 " = " + \ 128 BinPath + \ 129 T_CHAR_LF) 130 131 SymPath = ComponentObj.CompSym 132 if SymPath != '-': 133 SymPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(SymPath)) 134 BsfInf.writelines ("COMP_SYM" + \ 135 " = " + \ 136 SymPath + \ 137 T_CHAR_LF) 138 BsfInf.writelines ("COMP_SIZE" + \ 139 " = " + \ 140 ComponentObj.CompSize + \ 141 T_CHAR_LF) 142 BsfInf.writelines (T_CHAR_LF) 143 144 BsfInf.close() 145 146 ## GenFvList() method 147 # 148 # Get FV list referenced by VTF components 149 # 150 # @param self The object pointer 151 # 152 def GetFvList(self): 153 FvList = [] 154 for component in self.ComponentStatementList : 155 if component.CompLoc.upper() != 'NONE' and not (component.CompLoc.upper() in FvList): 156 FvList.append(component.CompLoc.upper()) 157 158 return FvList 159 160 ## GetBaseAddressArg() method 161 # 162 # Get base address arguments for GenVtf 163 # 164 # @param self The object pointer 165 # 166 def GetBaseAddressArg(self, FdAddressDict): 167 FvList = self.GetFvList() 168 CmdStr = tuple() 169 for i in FvList: 170 (BaseAddress, Size) = FdAddressDict.get(i) 171 CmdStr += ( 172 '-r', '0x%x' % BaseAddress, 173 '-s', '0x%x' % Size, 174 ) 175 return CmdStr 176 177 ## GenOutputArg() method 178 # 179 # Get output arguments for GenVtf 180 # 181 # @param self The object pointer 182 # 183 def GenOutputArg(self): 184 FvVtfDict = {} 185 OutputFileName = '' 186 FvList = self.GetFvList() 187 Index = 0 188 Arg = tuple() 189 for FvObj in FvList: 190 Index = Index + 1 191 OutputFileName = 'Vtf%d.raw' % Index 192 OutputFileName = os.path.join(GenFdsGlobalVariable.FvDir, OutputFileName) 193 Arg += ('-o', OutputFileName) 194 FvVtfDict[FvObj.upper()] = OutputFileName 195 196 return Arg, FvVtfDict 197 198