]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/GuidSection.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GuidSection.py
1 ## @file
2 # process GUIDed section 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 Section
19 import subprocess
20 from Ffs import Ffs
21 import os
22 from GenFdsGlobalVariable import GenFdsGlobalVariable
23 from CommonDataClass.FdfClass import GuidSectionClassObject
24 from Common import ToolDefClassObject
25 import sys
26 from Common import EdkLogger
27 from Common.BuildToolError import *
28
29 ## generate GUIDed section
30 #
31 #
32 class GuidSection(GuidSectionClassObject) :
33
34 ## The constructor
35 #
36 # @param self The object pointer
37 #
38 def __init__(self):
39 GuidSectionClassObject.__init__(self)
40
41 ## GenSection() method
42 #
43 # Generate GUIDed section
44 #
45 # @param self The object pointer
46 # @param OutputPath Where to place output file
47 # @param ModuleName Which module this section belongs to
48 # @param SecNum Index of section
49 # @param KeyStringList Filter for inputs of section generation
50 # @param FfsInf FfsInfStatement object that contains this section data
51 # @param Dict dictionary contains macro and its value
52 # @retval tuple (Generated file name, section alignment)
53 #
54 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):
55 #
56 # Generate all section
57 #
58 self.KeyStringList = KeyStringList
59 self.CurrentArchList = GenFdsGlobalVariable.ArchList
60 if FfsInf != None:
61 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)
62 self.NameGuid = FfsInf.__ExtendMacro__(self.NameGuid)
63 self.SectionType = FfsInf.__ExtendMacro__(self.SectionType)
64 self.CurrentArchList = [FfsInf.CurrentArch]
65
66 SectFile = tuple()
67 Index = 0
68 for Sect in self.SectionList:
69 Index = Index + 1
70 SecIndex = '%s.%d' %(SecNum,Index)
71 ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList,FfsInf, Dict)
72 if ReturnSectList != []:
73 for file in ReturnSectList:
74 SectFile += (file,)
75
76
77 OutputFile = OutputPath + \
78 os.sep + \
79 ModuleName + \
80 'SEC' + \
81 SecNum + \
82 Ffs.SectionSuffix['GUIDED']
83 OutputFile = os.path.normpath(OutputFile)
84
85 ExternalTool = None
86 if self.NameGuid != None:
87 ExternalTool = self.__FindExtendTool__()
88 #
89 # If not have GUID , call default
90 # GENCRC32 section
91 #
92 if self.NameGuid == None :
93 GenFdsGlobalVariable.VerboseLogger( "Use GenSection function Generate CRC32 Section")
94 GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType])
95 OutputFileList = []
96 OutputFileList.append(OutputFile)
97 return OutputFileList, self.Alignment
98 #or GUID not in External Tool List
99 elif ExternalTool == None:
100 EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid)
101 else:
102 #
103 # Call GenSection with DUMMY section type.
104 #
105 GenFdsGlobalVariable.GenerateSection(OutputFile+".dummy", SectFile)
106 #
107 # Use external tool process the Output
108 #
109 InputFile = OutputFile+".dummy"
110 TempFile = OutputPath + \
111 os.sep + \
112 ModuleName + \
113 'SEC' + \
114 SecNum + \
115 '.tmp'
116 TempFile = os.path.normpath(TempFile)
117
118 ExternalToolCmd = (
119 ExternalTool,
120 '-e',
121 '-o', TempFile,
122 InputFile,
123 )
124
125 #
126 # Call external tool
127 #
128 GenFdsGlobalVariable.GuidTool(TempFile, [InputFile], ExternalTool, '-e')
129
130 #
131 # Call Gensection Add Secntion Header
132 #
133 Attribute = None
134 if self.ProcessRequired == True:
135 Attribute = 'PROCSSING_REQUIRED'
136 if self.AuthStatusValid == True:
137 Attribute = 'AUTH_STATUS_VALID'
138 GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],
139 Guid=self.NameGuid, GuidAttr=Attribute)
140 OutputFileList = []
141 OutputFileList.append(OutputFile)
142 return OutputFileList, self.Alignment
143
144 ## __FindExtendTool()
145 #
146 # Find location of tools to process section data
147 #
148 # @param self The object pointer
149 #
150 def __FindExtendTool__(self):
151 # if user not specify filter, try to deduce it from global data.
152 if self.KeyStringList == None or self.KeyStringList == []:
153 Target = GenFdsGlobalVariable.TargetName
154 ToolChain = GenFdsGlobalVariable.ToolChainTag
155 ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).ToolsDefTxtDatabase
156 if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:
157 EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)
158 self.KeyStringList = [Target+'_'+ToolChain+'_'+self.CurrentArchList[0]]
159 for Arch in self.CurrentArchList:
160 if Target+'_'+ToolChain+'_'+Arch not in self.KeyStringList:
161 self.KeyStringList.append(Target+'_'+ToolChain+'_'+Arch)
162
163 ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.WorkSpaceDir).ToolsDefTxtDictionary
164 ToolPathTmp = None
165 for ToolDef in ToolDefinition.items():
166 if self.NameGuid == ToolDef[1]:
167 KeyList = ToolDef[0].split('_')
168 Key = KeyList[0] + \
169 '_' + \
170 KeyList[1] + \
171 '_' + \
172 KeyList[2]
173 if Key in self.KeyStringList and KeyList[4] == 'GUID':
174
175 ToolPath = ToolDefinition.get( Key + \
176 '_' + \
177 KeyList[3] + \
178 '_' + \
179 'PATH')
180 if ToolPathTmp == None:
181 ToolPathTmp = ToolPath
182 else:
183 if ToolPathTmp != ToolPath:
184 EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))
185
186
187 return ToolPathTmp
188
189
190