/edk2/BaseTools/Source/Python/GenFds/Vtf.py

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