3 from GenFdsGlobalVariable import GenFdsGlobalVariable
\r
8 import RuleSimpleFile
\r
9 import RuleComplexFile
\r
10 from Common.String import *
\r
12 class FfsInfStatement(Ffs.Ffs):
\r
14 Ffs.Ffs.__init__(self)
\r
18 self.InfFileName = None
\r
20 self.KeyStringList = []
\r
22 def __infParse__(self):
\r
24 # Get the InfClass object
\r
26 ## for item in GenFdsGlobalVariable.WorkSpace.InfDatabase:
\r
28 self.InfFileName = os.path.normpath(self.InfFileName)
\r
29 Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName]
\r
31 # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath
\r
33 self.BaseName = Inf.Defines.DefinesDictionary['BASE_NAME'][0]
\r
34 self.ModuleGuid = Inf.Defines.DefinesDictionary['FILE_GUID'][0]
\r
35 self.ModuleType = Inf.Defines.DefinesDictionary['MODULE_TYPE'][0]
\r
36 self.VersionString = Inf.Defines.DefinesDictionary['VERSION_STRING'][0]
\r
37 print "BaseName : %s" %self.BaseName
\r
38 print "ModuleGuid : %s" %self.ModuleGuid
\r
39 print "ModuleType : %s" %self.ModuleType
\r
40 print "VersionString : %s" %self.VersionString
\r
41 print "InfFileName :" , self.InfFileName
\r
43 # Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\
\r
46 self.OutputPath = os.path.join(GenFdsGlobalVariable.FfsDir, \
\r
47 self.ModuleGuid + self.BaseName)
\r
48 self.OutputPath = os.path.normcase(self.OutputPath)
\r
49 if not os.path.exists(self.OutputPath) :
\r
50 os.makedirs(self.OutputPath)
\r
52 self.InfOutputPath = self.__GetEFIOutPutPath__()
\r
53 print "ModuelEFIPath: " ,self.InfOutputPath
\r
57 # Parse Inf file get Module related information
\r
59 print " Begion parsing INf file : %s" %self.InfFileName
\r
61 """ Replace $(WORKSPACE) to None!"""
\r
62 self.InfFileName = self.InfFileName.replace('$(WORKSPACE)', '')
\r
63 if self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :
\r
64 self.InfFileName = self.InfFileName[1:]
\r
69 # Get the rule of how to generate Ffs file
\r
71 Rule = self.__GetRule__()
\r
73 FileType = Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]
\r
75 # For the rule only has simpleFile
\r
77 if isinstance (Rule, RuleSimpleFile.RuleSimpleFile) :
\r
78 SectionOutput = self.__GenSimpleFileSection__(Rule)
\r
79 FfsOutput = self.__GenSimpleFileFfs__(Rule, SectionOutput)
\r
82 # For Rule has ComplexFile
\r
84 elif isinstance(Rule, RuleComplexFile.RuleComplexFile):
\r
86 InputSectList = self.__GenComplexFileSection__(Rule)
\r
87 FfsOutput = self.__GenComplexFileFfs__(Rule, InputSectList)
\r
91 def __ExtendMarco__ (self, String):
\r
93 '$(INF_OUTPUT)' : self.InfOutputPath,
\r
94 '$(MODULE_NAME)' : self.BaseName,
\r
95 '$(BUILD_NUMBER)': self.BuildNum,
\r
96 '$(INF_VERSION)' : self.VersionString,
\r
97 '$(NAMED_GUID)' : self.ModuleGuid,
\r
98 '$(WORKSPACE)' : GenFdsGlobalVariable.WorkSpaceDir
\r
100 if String == None :
\r
102 for Marco in MarcoDict.keys():
\r
103 if String.find(Marco) >= 0 :
\r
104 String = String.replace (Marco, MarcoDict[Marco])
\r
107 def __GetRule__ (self) :
\r
108 currentArch = 'IA32'
\r
109 #for item in GenFdsGlobalVariable.FdfParser.profile.RuleDict :
\r
111 RuleName = 'RULE' + \
\r
115 self.ModuleType.upper()
\r
118 Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)
\r
120 RuleName = 'RULE' + \
\r
124 self.ModuleType.upper()
\r
126 Rule = GenFdsGlobalVariable.FdfParser.profile.RuleDict.get(RuleName)
\r
128 print 'Dont Find Related Rule, Using Default Rule !!!'
\r
129 if GenFdsGlobalVariable.DefaultRule == None:
\r
130 raise Exception ("Default Rule doesn't exist!!")
\r
131 return GenFdsGlobalVariable.DefaultRule
\r
132 print "Want To Find Rule Name is : " + RuleName
\r
135 def __GetEFIOutPutPath__(self):
\r
139 (ModulePath, fileName) = os.path.split(self.InfFileName)
\r
140 index = fileName.find('.')
\r
141 fileName = fileName[0:index]
\r
142 Platform = os.path.normpath(GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0])
\r
143 targetArchList = GenFdsGlobalVariable.WorkSpace.TargetTxt.TargetTxtDictionary["TARGET_ARCH"]
\r
144 if len(targetArchList) == 0:
\r
145 myArchList = GenFdsGlobalVariable.WorkSpace.SupArchList
\r
147 myArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(targetArchList)
\r
148 print "Valid target architecture(s) is", " ".join(myArchList)
\r
150 if len(myArchList) > 1 :
\r
151 for Key in self.KeyStringList:
\r
152 Target, Tag, Arch = Key.split('_')
\r
153 ArchList = set (ArchList) & Arch
\r
157 raise Exception("Module %s has too many bulid Arch !" %self.InfFileNames)
\r
158 elif len(myArchList) == 1 :
\r
159 Arch = myArchList.pop()
\r
161 OutputPath = os.path.join(GenFdsGlobalVariable.OuputDir,
\r
167 OutputPath = os.path.normcase(OutputPath)
\r
170 def __GenSimpleFileSection__(self, Rule):
\r
172 # Prepare the parameter of GenSection
\r
174 GenSecInputFile = self.__ExtendMarco__(Rule.FileName)
\r
176 SectionType = Rule.SectionType
\r
178 GenSecOutputFile= self.__ExtendMarco__(Rule.NameGuid) + \
\r
179 Ffs.Ffs.SectionSuffix[SectionType]
\r
181 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile)
\r
183 genSectionCmd = 'GenSec -o ' + \
\r
186 Section.Section.SectionType[SectionType] + \
\r
192 print genSectionCmd
\r
193 GenFdsGlobalVariable.CallExternalTool(genSectionCmd, "Gensection Failed!")
\r
196 def __GenSimpleFileFfs__(self, Rule, InputFile):
\r
198 # Prepare the parameter of GenFfs
\r
200 (FileType,Fixed, CheckSum, Alignment) = self.__GetGenFfsComParamter__(Rule)
\r
202 FfsOutput = self.OutputPath + \
\r
204 self.__ExtendMarco__(Rule.NameGuid) + \
\r
207 print self.__ExtendMarco__(Rule.NameGuid)
\r
208 InputSection = ' -i ' + \
\r
212 GenFfsCmd = 'GenFfs ' + \
\r
226 GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed!")
\r
229 def __GenComplexFileSection__(self, Rule):
\r
231 for Sect in Rule.SectionList:
\r
232 print 'GenSection: %s %s :' %(self.OutputPath ,self.ModuleGuid)
\r
234 secName, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, self.KeyStringList, self)
\r
236 SectFiles = SectFiles + \
\r
240 SectFiles = SectFiles + \
\r
245 def __GenComplexFileFfs__(self, Rule, InputFile):
\r
247 (FileType,Fixed, CheckSum, Alignment) = self.__GetGenFfsComParamter__(Rule)
\r
249 FfsOutput = os.path.join( self.OutputPath, self.ModuleGuid + '.ffs')
\r
250 GenFfsCmd = 'GenFfs ' + \
\r
256 self.ModuleGuid + \
\r
262 GenFdsGlobalVariable.CallExternalTool(GenFfsCmd, "GenFfs Failed !")
\r
265 def __GetGenFfsComParamter__(self, Rule):
\r
266 FileType = ' -t ' + \
\r
267 Ffs.Ffs.ModuleTypeToFileType[Rule.ModuleType]
\r
268 print "Rule.Fixed = ", Rule.Fixed
\r
269 if Rule.Fixed != False:
\r
273 if Rule.CheckSum != False:
\r
278 if Rule.Alignment != None and Rule.Alignment != '':
\r
279 Alignment = ' -a %s' %Rule.Alignment
\r
283 return FileType, Fixed, CheckSum, Alignment
\r