3 from GenFdsGlobalVariable import GenFdsGlobalVariable
\r
8 import RuleSimpleFile
\r
9 import RuleComplexFile
\r
10 from CommonDataClass.FdfClassObject import FfsInfStatementClassObject
\r
12 #from String import *
\r
14 class FfsInfStatement(FfsInfStatementClassObject):
\r
16 ## Ffs.Ffs.__init__(self)
\r
20 ## self.InfFileName = None
\r
21 ## self.BuildNum = ''
\r
22 ## self.KeyStringList = []
\r
23 FfsInfStatementClassObject.__init__(self)
\r
25 def __infParse__(self):
\r
27 # Get the InfClass object
\r
29 ## for item in GenFdsGlobalVariable.WorkSpace.InfDatabase:
\r
31 self.InfFileName = os.path.normpath(self.InfFileName)
\r
32 Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName]
\r
34 # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath
\r
36 self.BaseName = Inf.Defines.DefinesDictionary['BASE_NAME'][0]
\r
37 self.ModuleGuid = Inf.Defines.DefinesDictionary['FILE_GUID'][0]
\r
38 self.ModuleType = Inf.Defines.DefinesDictionary['MODULE_TYPE'][0]
\r
39 self.VersionString = Inf.Defines.DefinesDictionary['VERSION_STRING'][0]
\r
40 print "BaseName : %s" %self.BaseName
\r
41 print "ModuleGuid : %s" %self.ModuleGuid
\r
42 print "ModuleType : %s" %self.ModuleType
\r
43 print "VersionString : %s" %self.VersionString
\r
44 print "InfFileName :" , self.InfFileName
\r
46 # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\
\r
49 self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \
\r
50 self.ModuleGuid + self.BaseName)
\r
51 if not os.path.exists(self.OutputPath) :
\r
52 os.makedirs(self.OutputPath)
\r
54 self.InfOutputPath = self.__GetEFIOutPutPath__()
\r
55 print "ModuelEFIPath: " ,self.InfOutputPath
\r
59 # Parse Inf file get Module related information
\r
61 print " Begion parsing INf file : %s" %self.InfFileName
\r
63 """ Replace $(WORKSPACE) to None!"""
\r
64 self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')
\r
65 if self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :
\r
66 self.InfFileName = self.InfFileName[1:]
\r
71 # Get the rule of how to generate Ffs file
\r
73 Rule = self.__GetRule__()
\r
75 FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]
\r
77 # For the rule only has simpleFile
\r
79 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :
\r
80 SectionOutput = self.__GenSimpleFileSection__(Rule)
\r
81 FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutput)
\r
84 # For Rule has ComplexFile
\r
86 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):
\r
88 InputSectList = self.__GenComplexFileSection__(Rule)
\r
89 FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList)
\r
93 def __ExtendMarco__ (self, String):
\r
95 '$(INF_OUTPUT)' : self.InfOutputPath,
\r
96 '$(MODULE_NAME)' : self.BaseName,
\r
97 '$(BUILD_NUMBER)': self.BuildNum,
\r
98 '$(INF_VERSION)' : self.VersionString,
\r
99 '$(NAMED_GUID)' : self.ModuleGuid,
\r
100 '$(WORKSPACE)' : GenFdsGlobalVariable.WorkSpaceDir
\r
102 if String == None :
\r
104 for Marco in MarcoDict.keys():
\r
105 if String.find(Marco) >= 0 :
\r
106 String = String.replace (Marco, MarcoDict[Marco])
\r
109 def __GetRule__ (self) :
\r
110 currentArchList = self.__GetCurrentArch__()
\r
112 #for item in GenFdsGlobalVariable.FdfParser.profile.RuleDict :
\r
114 for currentArch in currentArchList:
\r
115 RuleName = 'RULE' + \
\r
117 currentArch.upper() + \
\r
119 self.ModuleType.upper()
\r
120 if self.Rule != None:
\r
121 RuleName = RuleName + \
\r
125 Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)
\r
127 print "Want To Find Rule Name is : " + RuleName
\r
130 RuleName = 'RULE' + \
\r
134 self.ModuleType.upper()
\r
135 if self.Rule != None:
\r
136 RuleName = RuleName + \
\r
140 Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)
\r
142 print "Want To Find Rule Name is : " + RuleName
\r
146 print 'Dont Find Related Rule, Using Default Rule !!!'
\r
147 if GenFdsGlobalVariable.DefaultRule == None:
\r
148 raise Exception ("Default Rule doesn't exist!!")
\r
150 return GenFdsGlobalVariable.DefaultRule
\r
152 def __GetCurrentArch__(self):
\r
153 targetArchList = GenFdsGlobalVariable.ArchList
\r
154 if len(targetArchList) == 0:
\r
155 targetArchList = GenFdsGlobalVariable.WorkSpace.SupArchList
\r
157 targetArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)
\r
159 #activePlatform = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary.get('ACTIVE_PLATFORM')[0]
\r
161 if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IA32').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):
\r
162 dscArchList.append ('IA32')
\r
163 if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('X64').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):
\r
164 dscArchList.append ('X64')
\r
165 if self.InfFileName in (GenFdsGlobalVariable.WorkSpace.Build.get('IPF').PlatformDatabase[GenFdsGlobalVariable.ActivePlatform].Modules):
\r
166 dscArchList.append ('IPF')
\r
168 curArchList = set (targetArchList) & set (dscArchList)
\r
169 print "Valid target architecture(s) is", " ".join(curArchList)
\r
172 def __GetEFIOutPutPath__(self):
\r
175 (ModulePath, fileName) = os.path.split(self.InfFileName)
\r
176 index = fileName.find('.')
\r
177 fileName = fileName[0:index]
\r
179 curArchList = self.__GetCurrentArch__()
\r
180 if len(curArchList) > 1 :
\r
181 for Key in self.KeyStringList:
\r
182 Target, Tag, Arch = Key.split('_')
\r
183 ArchList = set (ArchList) & Arch
\r
184 if len(ArchList) == 1:
\r
186 elif len(ArchList) > 1:
\r
187 raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)
\r
189 raise Exception("Don't find legal Arch in Module %s !" %self.InfFileNames)
\r
190 elif len(curArchList) == 1 :
\r
191 Arch = curArchList.pop()
\r
193 OutputPath = os.path.join(GenFdsGlobalVariable.OuputDir,
\r
200 OutputPath = os.path.realpath(OutputPath)
\r
203 def __GenSimpleFileSection__(self, Rule):
\r
205 # Prepare the parameter of GenSection
\r
207 GenSecInputFile = self.__ExtendMarco__(Rule.FileName)
\r
209 SectionType = Rule.SectionType
\r
211 GenSecOutputFile= self.__ExtendMarco__(Rule.NameGuid) + \
\r
212 Ffs.Ffs.SectionSuffix[SectionType]
\r
214 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)
\r
216 genSectionCmd = 'GenSec -o ' + \
\r
219 Section.Section.SectionType[SectionType] + \
\r
225 print genSectionCmd
\r
226 GenFdsGlobalVariable.CallExternalTool(genSectionCmd, "Gensection Failed!")
\r
229 def __GenSimpleFileFfs__(self, Rule, InputFile):
\r
231 # Prepare the parameter of GenFfs
\r
233 (FileType,Fixed, CheckSum, Alignment) = self.__GetGenFfsComParamter__(Rule)
\r
235 FfsOutput = self.OutputPath + \
\r
237 self.__ExtendMarco__(Rule.NameGuid) + \
\r
240 print self.__ExtendMarco__(Rule.NameGuid)
\r
241 InputSection = ' -i ' + \
\r
245 GenFfsCmd = 'GenFfs ' + \
\r
259 GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed!")
\r
262 def __GenComplexFileSection__(self, Rule):
\r
264 for Sect in Rule.SectionList:
\r
265 #print 'GenSection: %s %s :' %(self.OutputPath ,self.ModuleGuid)
\r
267 if Rule.KeyStringList != []:
\r
268 secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, Rule.KeyStringList, self)
\r
270 secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)
\r
272 SectFiles = SectFiles + \
\r
276 SectFiles = SectFiles + \
\r
281 def __GenComplexFileFfs__(self, Rule, InputFile):
\r
283 (FileType,Fixed, CheckSum, Alignment) = self.__GetGenFfsComParamter__(Rule)
\r
285 FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')
\r
286 GenFfsCmd = 'GenFfs ' + \
\r
292 self.ModuleGuid + \
\r
298 GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed !")
\r
301 def __GetGenFfsComParamter__(self, Rule):
\r
302 FileType = ' -t ' + \
\r
303 Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]
\r
304 print "Rule.Fixed = ", Rule.Fixed
\r
305 if Rule.Fixed != False:
\r
309 if Rule.CheckSum != False:
\r
314 if Rule.Alignment != None and Rule.Alignment != '':
\r
315 Alignment = ' -a %s' %Rule.Alignment
\r
319 return FileType, Fixed, CheckSum, Alignment