]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | AutoGen class.\r | |
3 | \r | |
4 | This class is to generate Autogen.h and Autogen.c according to module surface area\r | |
5 | or library surface area.\r | |
ff225cbb | 6 | \r |
878ddf1f | 7 | Copyright (c) 2006, Intel Corporation\r |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
ff225cbb | 12 | \r |
878ddf1f | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | package org.tianocore.build.autogen;\r | |
19 | \r | |
878ddf1f | 20 | import java.io.File;\r |
73b4e31a | 21 | import java.io.FileInputStream;\r |
22 | import java.io.FileOutputStream;\r | |
878ddf1f | 23 | import java.io.FileReader;\r |
24 | import java.io.FileWriter;\r | |
cb4d97bd | 25 | import java.io.IOException;\r |
878ddf1f | 26 | import java.util.ArrayList;\r |
a29c47e0 | 27 | import java.util.HashSet;\r |
28 | import java.util.Iterator;\r | |
893cea14 | 29 | import java.util.LinkedHashSet;\r |
136adffc | 30 | import java.util.LinkedList;\r |
878ddf1f | 31 | import java.util.List;\r |
32 | import java.util.Map;\r | |
a29c47e0 | 33 | import java.util.Set;\r |
878ddf1f | 34 | \r |
73b4e31a | 35 | import org.apache.tools.ant.BuildException;\r |
36 | import org.apache.xmlbeans.XmlObject;\r | |
73b4e31a | 37 | import org.tianocore.build.exception.*;\r |
38 | import org.tianocore.build.global.GlobalData;\r | |
73b4e31a | 39 | import org.tianocore.build.global.SurfaceAreaQuery;\r |
40 | import org.tianocore.build.id.ModuleIdentification;\r | |
41 | import org.tianocore.build.id.PackageIdentification;\r | |
42 | import org.tianocore.build.pcd.action.PCDAutoGenAction;\r | |
ff225cbb | 43 | import org.tianocore.common.logger.EdkLog;\r |
cb4d97bd | 44 | import org.tianocore.common.definitions.ToolDefinitions;\r |
892b0e7a | 45 | import org.tianocore.common.exception.EdkException;\r |
73b4e31a | 46 | \r |
878ddf1f | 47 | /**\r |
cb4d97bd | 48 | This class is to generate Autogen.h and Autogen.c according to module surface\r |
49 | area or library surface area.\r | |
50 | **/\r | |
878ddf1f | 51 | public class AutoGen {\r |
5f907e4a | 52 | ///\r |
53 | /// The output path of Autogen.h and Autogen.c\r | |
54 | ///\r | |
55 | private String outputPath;\r | |
56 | \r | |
ff225cbb | 57 | ///\r |
58 | /// The name of FV directory\r | |
59 | ///\r | |
73b4e31a | 60 | private String fvDir;\r |
5f907e4a | 61 | \r |
62 | ///\r | |
63 | /// The base name of module or library.\r | |
64 | ///\r | |
65 | private ModuleIdentification moduleId;\r | |
66 | \r | |
67 | ///\r | |
68 | /// The build architecture\r | |
69 | ///\r | |
70 | private String arch;\r | |
71 | \r | |
72 | ///\r | |
73 | /// PcdAutogen instance which is used to manage how to generate the PCD\r | |
74 | /// information.\r | |
75 | ///\r | |
76 | private PCDAutoGenAction myPcdAutogen;\r | |
77 | \r | |
78 | ///\r | |
79 | /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER\r | |
80 | /// \r | |
81 | private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r | |
82 | \r | |
83 | ///\r | |
84 | /// The protocl list which records in module or library surface area and\r | |
85 | /// it's dependence on library instance surface area.\r | |
86 | ///\r | |
87 | private Set<String> mProtocolList = new HashSet<String>();\r | |
88 | \r | |
89 | ///\r | |
90 | /// The Ppi list which recorded in module or library surface area and its\r | |
91 | /// dependency on library instance surface area.\r | |
92 | ///\r | |
93 | private Set<String> mPpiList = new HashSet<String>();\r | |
94 | \r | |
95 | ///\r | |
96 | /// The Guid list which recoreded in module or library surface area and it's\r | |
97 | /// dependence on library instance surface area.\r | |
98 | ///\r | |
99 | private Set<String> mGuidList = new HashSet<String>();\r | |
ff225cbb | 100 | \r |
cb4d97bd | 101 | ///\r |
102 | /// The dependence package list which recoreded in module or library surface\r | |
103 | /// area and it's dependence on library instance surface area.\r | |
104 | ///\r | |
136adffc | 105 | private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();\r |
2336382f | 106 | \r |
cb4d97bd | 107 | ///\r |
108 | /// For non library module, add its library instance's construct and destructor to\r | |
109 | /// list.\r | |
110 | ///\r | |
5f907e4a | 111 | private List<String> libConstructList = new ArrayList<String>();\r |
112 | private List<String> libDestructList = new ArrayList<String>();\r | |
113 | \r | |
cb4d97bd | 114 | ///\r |
115 | /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r | |
116 | ///\r | |
5f907e4a | 117 | private List<String> setVirtalAddList = new ArrayList<String>();\r |
118 | private List<String> exitBootServiceList = new ArrayList<String>();\r | |
119 | \r | |
83fba802 | 120 | private SurfaceAreaQuery saq = null;\r |
5f907e4a | 121 | \r |
122 | /**\r | |
cb4d97bd | 123 | Construct function\r |
124 | \r | |
125 | This function mainly initialize some member variable.\r | |
126 | \r | |
127 | @param fvDir\r | |
128 | Absolute path of FV directory.\r | |
129 | @param outputPath\r | |
130 | Output path of AutoGen file.\r | |
131 | @param moduleId\r | |
132 | Module identification.\r | |
133 | @param arch\r | |
134 | Target architecture.\r | |
135 | **/\r | |
83fba802 | 136 | public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq) {\r |
5f907e4a | 137 | this.outputPath = outputPath;\r |
138 | this.moduleId = moduleId;\r | |
139 | this.arch = arch;\r | |
73b4e31a | 140 | this.fvDir = fvDir;\r |
83fba802 | 141 | this.saq = saq;\r |
5f907e4a | 142 | }\r |
143 | \r | |
144 | /**\r | |
cb4d97bd | 145 | saveFile function\r |
146 | \r | |
147 | This function save the content in stringBuffer to file.\r | |
148 | \r | |
149 | @param fileName\r | |
150 | The name of file.\r | |
151 | @param fileBuffer\r | |
152 | The content of AutoGen file in buffer.\r | |
153 | @return boolean \r | |
154 | "true" successful\r | |
155 | "false" failed\r | |
156 | **/\r | |
5f907e4a | 157 | private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r |
cb4d97bd | 158 | \r |
159 | File autoGenH = new File(fileName);\r | |
5f907e4a | 160 | \r |
161 | //\r | |
162 | // if the file exists, compare their content\r | |
163 | //\r | |
cb4d97bd | 164 | if (autoGenH.exists()) {\r |
165 | char[] oldFileBuffer = new char[(int) autoGenH.length()];\r | |
166 | try {\r | |
167 | FileReader fIn = new FileReader(autoGenH);\r | |
168 | fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r | |
5f907e4a | 169 | fIn.close();\r |
cb4d97bd | 170 | } catch (IOException e) {\r |
171 | EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r | |
172 | + "'s " \r | |
173 | + fileName \r | |
174 | + " is exist, but can't be open!!");\r | |
175 | return false;\r | |
176 | }\r | |
5f907e4a | 177 | \r |
cb4d97bd | 178 | //\r |
179 | // if we got the same file, don't re-generate it to prevent\r | |
180 | // sources depending on it from re-building\r | |
181 | //\r | |
182 | if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r | |
183 | return true;\r | |
5f907e4a | 184 | }\r |
cb4d97bd | 185 | }\r |
186 | \r | |
187 | try {\r | |
188 | FileWriter fOut = new FileWriter(autoGenH);\r | |
5f907e4a | 189 | fOut.write(fileBuffer.toString());\r |
cb4d97bd | 190 | fOut.flush();\r |
5f907e4a | 191 | fOut.close();\r |
cb4d97bd | 192 | } catch (IOException e) {\r |
193 | EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r | |
194 | + "'s " \r | |
195 | + fileName \r | |
196 | + " can't be create!!");\r | |
197 | return false;\r | |
198 | } \r | |
5f907e4a | 199 | return true;\r |
200 | }\r | |
201 | \r | |
202 | /**\r | |
cb4d97bd | 203 | genAutogen function\r |
204 | \r | |
205 | This function call libGenAutoGen or moduleGenAutogen function, which\r | |
206 | dependence on generate library autogen or module autogen.\r | |
207 | \r | |
208 | @throws BuildException\r | |
209 | Failed to creat AutoGen.c & AutoGen.h.\r | |
210 | **/\r | |
5f907e4a | 211 | public void genAutogen() throws BuildException {\r |
212 | try {\r | |
213 | //\r | |
214 | // If outputPath do not exist, create it.\r | |
215 | //\r | |
216 | File path = new File(outputPath);\r | |
217 | path.mkdirs();\r | |
218 | \r | |
219 | //\r | |
220 | // Check current is library or not, then call the corresponding\r | |
221 | // function.\r | |
222 | //\r | |
223 | if (this.moduleId.isLibrary()) {\r | |
224 | libGenAutogen();\r | |
225 | } else {\r | |
226 | moduleGenAutogen();\r | |
227 | }\r | |
228 | \r | |
229 | } catch (Exception e) {\r | |
230 | throw new BuildException(\r | |
231 | "Failed to create AutoGen.c & AutoGen.h!\n"\r | |
232 | + e.getMessage());\r | |
233 | }\r | |
234 | }\r | |
235 | \r | |
236 | /**\r | |
cb4d97bd | 237 | moduleGenAutogen function\r |
238 | \r | |
239 | This function generates AutoGen.c & AutoGen.h for module.\r | |
240 | \r | |
241 | @throws BuildException\r | |
242 | Faile to create module AutoGen.c & AutoGen.h.\r | |
243 | **/\r | |
5f907e4a | 244 | void moduleGenAutogen() throws BuildException {\r |
245 | \r | |
246 | try {\r | |
247 | collectLibInstanceInfo();\r | |
248 | moduleGenAutogenC();\r | |
249 | moduleGenAutogenH();\r | |
250 | } catch (Exception e) {\r | |
251 | throw new BuildException(\r | |
252 | "Faile to create module AutoGen.c & AutoGen.h!\n"\r | |
253 | + e.getMessage());\r | |
254 | }\r | |
255 | }\r | |
256 | \r | |
257 | /**\r | |
cb4d97bd | 258 | libGenAutogen function\r |
259 | \r | |
260 | This function generates AutoGen.c & AutoGen.h for library.\r | |
261 | \r | |
262 | @throws BuildException\r | |
263 | Faile to create library AutoGen.c & AutoGen.h\r | |
264 | **/\r | |
5f907e4a | 265 | void libGenAutogen() throws BuildException {\r |
266 | try {\r | |
267 | libGenAutogenC();\r | |
268 | libGenAutogenH();\r | |
269 | } catch (Exception e) {\r | |
270 | throw new BuildException(\r | |
271 | "Failed to create library AutoGen.c & AutoGen.h!\n"\r | |
272 | + e.getMessage());\r | |
273 | }\r | |
274 | }\r | |
275 | \r | |
276 | /**\r | |
cb4d97bd | 277 | moduleGenAutogenH\r |
278 | \r | |
279 | This function generates AutoGen.h for module.\r | |
280 | \r | |
281 | @throws BuildException\r | |
282 | Failed to generate AutoGen.h.\r | |
283 | **/\r | |
892b0e7a | 284 | void moduleGenAutogenH() throws EdkException, AutoGenException {\r |
5f907e4a | 285 | \r |
286 | Set<String> libClassIncludeH;\r | |
287 | String moduleType;\r | |
288 | // List<String> headerFileList;\r | |
289 | List<String> headerFileList;\r | |
290 | Iterator item;\r | |
291 | StringBuffer fileBuffer = new StringBuffer(8192);\r | |
292 | \r | |
293 | //\r | |
294 | // Write Autogen.h header notation\r | |
295 | //\r | |
cb4d97bd | 296 | fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r |
5f907e4a | 297 | \r |
298 | //\r | |
299 | // Add #ifndef ${BaseName}_AUTOGENH\r | |
300 | // #def ${BseeName}_AUTOGENH\r | |
301 | //\r | |
cb4d97bd | 302 | fileBuffer.append(CommonDefinition.IFNDEF \r |
303 | + CommonDefinition.AUTOGENH\r | |
304 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
305 | + ToolDefinitions.LINE_SEPARATOR);\r | |
306 | fileBuffer.append(CommonDefinition.DEFINE \r | |
307 | + CommonDefinition.AUTOGENH\r | |
308 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
309 | + ToolDefinitions.LINE_SEPARATOR \r | |
310 | + ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 311 | \r |
312 | //\r | |
313 | // Write the specification version and release version at the begine\r | |
314 | // of autogen.h file.\r | |
315 | // Note: the specification version and release version should\r | |
316 | // be got from module surface area instead of hard code by it's\r | |
317 | // moduleType.\r | |
318 | //\r | |
83fba802 | 319 | moduleType = saq.getModuleType();\r |
5f907e4a | 320 | \r |
321 | //\r | |
322 | // Add "extern int __make_me_compile_correctly;" at begin of\r | |
323 | // AutoGen.h.\r | |
324 | //\r | |
cb4d97bd | 325 | fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r |
136adffc | 326 | \r |
327 | //\r | |
328 | // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.\r | |
878ddf1f | 329 | //\r |
83fba802 | 330 | String[] specList = saq.getExternSpecificaiton();\r |
136adffc | 331 | for (int i = 0; i < specList.length; i++) {\r |
cb4d97bd | 332 | fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r |
5f907e4a | 333 | + "\r\n");\r |
334 | }\r | |
335 | //\r | |
336 | // Write consumed package's mdouleInfo related .h file to autogen.h\r | |
337 | //\r | |
338 | // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r | |
339 | // .getDependencePkg(this.arch);\r | |
83fba802 | 340 | PackageIdentification[] consumedPkgIdList = saq.getDependencePkg(this.arch);\r |
5f907e4a | 341 | if (consumedPkgIdList != null) {\r |
342 | headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r | |
343 | item = headerFileList.iterator();\r | |
344 | while (item.hasNext()) {\r | |
345 | fileBuffer.append(item.next().toString());\r | |
346 | }\r | |
347 | }\r | |
348 | \r | |
349 | //\r | |
350 | // Write library class's related *.h file to autogen.h.\r | |
351 | //\r | |
83fba802 | 352 | String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED,this.arch);\r |
5f907e4a | 353 | if (libClassList != null) {\r |
354 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
355 | item = libClassIncludeH.iterator();\r | |
356 | while (item.hasNext()) {\r | |
357 | fileBuffer.append(item.next().toString());\r | |
358 | }\r | |
878ddf1f | 359 | }\r |
5f907e4a | 360 | \r |
83fba802 | 361 | libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch);\r |
5f907e4a | 362 | if (libClassList != null) {\r |
363 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
364 | item = libClassIncludeH.iterator();\r | |
365 | while (item.hasNext()) {\r | |
366 | fileBuffer.append(item.next().toString());\r | |
367 | }\r | |
368 | }\r | |
369 | fileBuffer.append("\r\n");\r | |
136adffc | 370 | \r |
73b4e31a | 371 | //\r |
ff225cbb | 372 | // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r |
73b4e31a | 373 | // {DEST_DIR_DRBUG}/FlashMap.h\r |
ff225cbb | 374 | //\r |
83fba802 | 375 | if (saq.isHaveTianoR8FlashMap()) {\r |
cb4d97bd | 376 | fileBuffer.append(CommonDefinition.INCLUDE);\r |
73b4e31a | 377 | fileBuffer.append(" <");\r |
cb4d97bd | 378 | fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r |
73b4e31a | 379 | copyFlashMapHToDebugDir();\r |
380 | }\r | |
381 | \r | |
5f907e4a | 382 | // Write PCD autogen information to AutoGen.h.\r |
383 | //\r | |
384 | if (this.myPcdAutogen != null) {\r | |
136adffc | 385 | fileBuffer.append("\r\n");\r |
11eb278a | 386 | fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r |
5f907e4a | 387 | }\r |
388 | \r | |
389 | //\r | |
390 | // Append the #endif at AutoGen.h\r | |
391 | //\r | |
392 | fileBuffer.append("#endif\r\n");\r | |
393 | \r | |
394 | //\r | |
395 | // Save string buffer content in AutoGen.h.\r | |
396 | //\r | |
397 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r | |
398 | throw new BuildException("Failed to generate AutoGen.h !!!");\r | |
399 | }\r | |
400 | }\r | |
401 | \r | |
402 | /**\r | |
cb4d97bd | 403 | moduleGenAutogenC\r |
404 | \r | |
405 | This function generates AutoGen.c for module.\r | |
406 | \r | |
407 | @throws BuildException\r | |
408 | Failed to generate AutoGen.c.\r | |
409 | **/\r | |
892b0e7a | 410 | void moduleGenAutogenC() throws EdkException, AutoGenException {\r |
5f907e4a | 411 | \r |
412 | StringBuffer fileBuffer = new StringBuffer(8192);\r | |
413 | //\r | |
414 | // Write Autogen.c header notation\r | |
415 | //\r | |
cb4d97bd | 416 | fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r |
5f907e4a | 417 | \r |
418 | //\r | |
419 | // Write #include <AutoGen.h> at beginning of AutoGen.c\r | |
420 | //\r | |
cb4d97bd | 421 | fileBuffer.append(CommonDefinition.INCLUDEAUTOGENH);\r |
5f907e4a | 422 | \r |
423 | //\r | |
424 | // Get the native MSA file infomation. Since before call autogen,\r | |
425 | // the MSA native <Externs> information were overrided. So before\r | |
426 | // process <Externs> it should be set the DOC as the Native MSA info.\r | |
427 | //\r | |
428 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);\r | |
83fba802 | 429 | saq.push(doc);\r |
5f907e4a | 430 | //\r |
431 | // Write <Extern>\r | |
432 | // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r | |
433 | // to AutoGen.c\r | |
434 | //\r | |
435 | \r | |
436 | ExternsDriverBindingToAutoGenC(fileBuffer);\r | |
437 | \r | |
438 | //\r | |
439 | // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r | |
440 | // to Autogen.c\r | |
441 | //\r | |
442 | ExternCallBackToAutoGenC(fileBuffer);\r | |
443 | \r | |
444 | //\r | |
445 | // Write EntryPoint to autgoGen.c\r | |
446 | //\r | |
83fba802 | 447 | String[] entryPointList = saq.getModuleEntryPointArray();\r |
448 | String[] unloadImageList = saq.getModuleUnloadImageArray();\r | |
cb4d97bd | 449 | EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), \r |
450 | CommonDefinition.remDupString(unloadImageList),\r | |
451 | fileBuffer);\r | |
5f907e4a | 452 | \r |
83fba802 | 453 | pcdDriverType = saq.getPcdDriverType();\r |
5f907e4a | 454 | \r |
455 | //\r | |
456 | // Restore the DOC which include the FPD module info.\r | |
457 | //\r | |
83fba802 | 458 | saq.pop();\r |
5f907e4a | 459 | \r |
460 | //\r | |
461 | // Write Guid to autogen.c\r | |
462 | //\r | |
83fba802 | 463 | String guid = CommonDefinition.formatGuidName(saq.getModuleGuid());\r |
5f907e4a | 464 | \r |
465 | fileBuffer\r | |
466 | .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r | |
467 | if (guid == null) {\r | |
468 | throw new AutoGenException("Guid value must set!\n");\r | |
469 | }\r | |
470 | \r | |
471 | //\r | |
472 | // Formate Guid as ANSI c form.Example:\r | |
473 | // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r | |
474 | // 0xf0}}\r | |
475 | //\r | |
476 | \r | |
477 | fileBuffer.append(guid);\r | |
478 | fileBuffer.append("};\r\n");\r | |
479 | \r | |
480 | //\r | |
481 | // Generate library instance consumed protocol, guid, ppi, pcd list.\r | |
482 | // Save those to this.protocolList, this.ppiList, this.pcdList,\r | |
483 | // this.guidList. Write Consumed library constructor and desconstuct to\r | |
484 | // autogen.c\r | |
485 | //\r | |
136adffc | 486 | LibInstanceToAutogenC(fileBuffer);\r |
ff225cbb | 487 | \r |
878ddf1f | 488 | //\r |
136adffc | 489 | // Get module dependent Package identification.\r |
878ddf1f | 490 | //\r |
83fba802 | 491 | PackageIdentification[] packages = saq.getDependencePkg(this.arch);\r |
5f907e4a | 492 | for (int i = 0; i < packages.length; i++) {\r |
493 | if (!this.mDepPkgList.contains(packages[i])) {\r | |
136adffc | 494 | this.mDepPkgList.add(packages[i]);\r |
878ddf1f | 495 | }\r |
ff225cbb | 496 | \r |
136adffc | 497 | }\r |
ff225cbb | 498 | \r |
5f907e4a | 499 | //\r |
500 | // Write consumed ppi, guid, protocol to autogen.c\r | |
501 | //\r | |
502 | ProtocolGuidToAutogenC(fileBuffer);\r | |
503 | PpiGuidToAutogenC(fileBuffer);\r | |
504 | GuidGuidToAutogenC(fileBuffer);\r | |
ff225cbb | 505 | \r |
5f907e4a | 506 | //\r |
507 | // Call pcd autogen.\r | |
508 | //\r | |
509 | this.myPcdAutogen = new PCDAutoGenAction(moduleId, \r | |
510 | arch, \r | |
511 | false, \r | |
512 | null,\r | |
513 | pcdDriverType);\r | |
514 | try {\r | |
515 | this.myPcdAutogen.execute();\r | |
516 | } catch (Exception exp) {\r | |
517 | throw new PcdAutogenException (exp.getMessage());\r | |
518 | }\r | |
519 | \r | |
520 | if (this.myPcdAutogen != null) {\r | |
521 | fileBuffer.append("\r\n");\r | |
11eb278a | 522 | fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r |
5f907e4a | 523 | }\r |
524 | \r | |
525 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r | |
526 | throw new BuildException("Failed to generate AutoGen.c !!!");\r | |
527 | }\r | |
528 | \r | |
529 | }\r | |
530 | \r | |
531 | /**\r | |
cb4d97bd | 532 | libGenAutogenH\r |
533 | \r | |
534 | This function generates AutoGen.h for library.\r | |
535 | \r | |
536 | @throws BuildException\r | |
537 | Failed to generate AutoGen.c.\r | |
538 | **/\r | |
892b0e7a | 539 | void libGenAutogenH() throws EdkException, AutoGenException {\r |
5f907e4a | 540 | \r |
541 | Set<String> libClassIncludeH;\r | |
542 | String moduleType;\r | |
543 | List<String> headerFileList;\r | |
544 | Iterator item;\r | |
545 | StringBuffer fileBuffer = new StringBuffer(10240);\r | |
546 | \r | |
547 | //\r | |
548 | // Write Autogen.h header notation\r | |
549 | //\r | |
cb4d97bd | 550 | fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r |
5f907e4a | 551 | \r |
552 | //\r | |
553 | // Add #ifndef ${BaseName}_AUTOGENH\r | |
554 | // #def ${BseeName}_AUTOGENH\r | |
555 | //\r | |
cb4d97bd | 556 | fileBuffer.append(CommonDefinition.IFNDEF \r |
557 | + CommonDefinition.AUTOGENH\r | |
558 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
559 | + ToolDefinitions.LINE_SEPARATOR);\r | |
560 | fileBuffer.append(CommonDefinition.DEFINE \r | |
561 | + CommonDefinition.AUTOGENH\r | |
562 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
563 | + ToolDefinitions.LINE_SEPARATOR \r | |
564 | + ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 565 | \r |
566 | //\r | |
567 | // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r | |
568 | // to autogen.h file.\r | |
569 | // Note: the specification version and release version should\r | |
570 | // be get from module surface area instead of hard code.\r | |
571 | //\r | |
cb4d97bd | 572 | fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r |
83fba802 | 573 | String[] specList = saq.getExternSpecificaiton();\r |
5f907e4a | 574 | for (int i = 0; i < specList.length; i++) {\r |
cb4d97bd | 575 | fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r |
5f907e4a | 576 | + "\r\n");\r |
577 | }\r | |
578 | // fileBuffer.append(CommonDefinition.autoGenHLine1);\r | |
579 | // fileBuffer.append(CommonDefinition.autoGenHLine2);\r | |
580 | \r | |
581 | //\r | |
582 | // Write consumed package's mdouleInfo related *.h file to autogen.h.\r | |
583 | //\r | |
83fba802 | 584 | moduleType = saq.getModuleType();\r |
585 | PackageIdentification[] cosumedPkglist = saq\r | |
5f907e4a | 586 | .getDependencePkg(this.arch);\r |
587 | headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r | |
588 | item = headerFileList.iterator();\r | |
589 | while (item.hasNext()) {\r | |
590 | fileBuffer.append(item.next().toString());\r | |
591 | }\r | |
592 | //\r | |
593 | // Write library class's related *.h file to autogen.h\r | |
594 | //\r | |
83fba802 | 595 | String[] libClassList = saq\r |
cb4d97bd | 596 | .getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch);\r |
5f907e4a | 597 | if (libClassList != null) {\r |
598 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
599 | item = libClassIncludeH.iterator();\r | |
600 | while (item.hasNext()) {\r | |
601 | fileBuffer.append(item.next().toString());\r | |
602 | }\r | |
603 | }\r | |
604 | \r | |
83fba802 | 605 | libClassList = saq\r |
cb4d97bd | 606 | .getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch);\r |
5f907e4a | 607 | if (libClassList != null) {\r |
608 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
609 | item = libClassIncludeH.iterator();\r | |
610 | while (item.hasNext()) {\r | |
611 | fileBuffer.append(item.next().toString());\r | |
612 | }\r | |
613 | }\r | |
cb4d97bd | 614 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
136adffc | 615 | \r |
73b4e31a | 616 | //\r |
ff225cbb | 617 | // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r |
73b4e31a | 618 | // {DEST_DIR_DRBUG}/FlashMap.h\r |
ff225cbb | 619 | //\r |
83fba802 | 620 | if (saq.isHaveTianoR8FlashMap()) {\r |
cb4d97bd | 621 | fileBuffer.append(CommonDefinition.INCLUDE);\r |
73b4e31a | 622 | fileBuffer.append(" <");\r |
cb4d97bd | 623 | fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r |
73b4e31a | 624 | copyFlashMapHToDebugDir();\r |
625 | }\r | |
626 | \r | |
5f907e4a | 627 | //\r |
628 | // Write PCD information to library AutoGen.h.\r | |
629 | //\r | |
630 | if (this.myPcdAutogen != null) {\r | |
136adffc | 631 | fileBuffer.append("\r\n");\r |
11eb278a | 632 | fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r |
5f907e4a | 633 | }\r |
634 | \r | |
635 | //\r | |
636 | // Append the #endif at AutoGen.h\r | |
637 | //\r | |
638 | fileBuffer.append("#endif\r\n");\r | |
639 | \r | |
640 | //\r | |
641 | // Save content of string buffer to AutoGen.h file.\r | |
642 | //\r | |
643 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r | |
644 | throw new BuildException("Failed to generate AutoGen.h !!!");\r | |
645 | }\r | |
646 | }\r | |
647 | \r | |
648 | /**\r | |
cb4d97bd | 649 | libGenAutogenC\r |
650 | \r | |
651 | This function generates AutoGen.h for library.\r | |
652 | \r | |
653 | @throws BuildException\r | |
654 | Failed to generate AutoGen.c.\r | |
655 | **/\r | |
5f907e4a | 656 | void libGenAutogenC() throws BuildException, PcdAutogenException {\r |
657 | StringBuffer fileBuffer = new StringBuffer(10240);\r | |
658 | \r | |
659 | //\r | |
660 | // Write Autogen.c header notation\r | |
661 | //\r | |
cb4d97bd | 662 | fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r |
5f907e4a | 663 | \r |
cb4d97bd | 664 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
665 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 666 | \r |
667 | //\r | |
668 | // Call pcd autogen.\r | |
669 | //\r | |
670 | this.myPcdAutogen = new PCDAutoGenAction(moduleId,\r | |
671 | arch,\r | |
672 | true,\r | |
83fba802 | 673 | saq.getModulePcdEntryNameArray(),\r |
5f907e4a | 674 | pcdDriverType);\r |
675 | try {\r | |
676 | this.myPcdAutogen.execute();\r | |
677 | } catch (Exception e) {\r | |
678 | throw new PcdAutogenException(e.getMessage());\r | |
679 | }\r | |
680 | \r | |
681 | if (this.myPcdAutogen != null) {\r | |
cb4d97bd | 682 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
11eb278a | 683 | fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r |
5f907e4a | 684 | }\r |
685 | \r | |
686 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r | |
687 | throw new BuildException("Failed to generate AutoGen.c !!!");\r | |
688 | }\r | |
689 | }\r | |
690 | \r | |
691 | /**\r | |
cb4d97bd | 692 | LibraryClassToAutogenH\r |
693 | \r | |
694 | This function returns *.h files declared by library classes which are\r | |
695 | consumed or produced by current build module or library.\r | |
696 | \r | |
697 | @param libClassList\r | |
698 | List of library class which consumed or produce by current\r | |
699 | build module or library.\r | |
700 | @return includeStrList List of *.h file.\r | |
701 | **/\r | |
5f907e4a | 702 | Set<String> LibraryClassToAutogenH(String[] libClassList)\r |
892b0e7a | 703 | throws EdkException, AutoGenException {\r |
cb4d97bd | 704 | Set<String> includeStrList = new LinkedHashSet<String>();\r |
705 | String includeName[];\r | |
5f907e4a | 706 | String str = "";\r |
707 | \r | |
708 | //\r | |
709 | // Get include file from GlobalData's SPDTable according to\r | |
710 | // library class name.\r | |
711 | //\r | |
5f907e4a | 712 | for (int i = 0; i < libClassList.length; i++) {\r |
cb4d97bd | 713 | includeName = GlobalData.getLibraryClassHeaderFiles(\r |
83fba802 | 714 | saq.getDependencePkg(this.arch),\r |
5f907e4a | 715 | libClassList[i]);\r |
cb4d97bd | 716 | if (includeName == null) {\r |
5f907e4a | 717 | throw new AutoGenException("Can not find library class ["\r |
718 | + libClassList[i] + "] declaration in any SPD package. ");\r | |
719 | }\r | |
cb4d97bd | 720 | for (int j = 0; j < includeName.length; j++) {\r |
721 | String includeNameStr = includeName[j];\r | |
5f907e4a | 722 | if (includeNameStr != null) {\r |
cb4d97bd | 723 | str = CommonDefinition.INCLUDE + " " + "<";\r |
5f907e4a | 724 | str = str + includeNameStr + ">\r\n";\r |
cb4d97bd | 725 | includeStrList.add(str);\r |
5f907e4a | 726 | includeNameStr = null;\r |
878ddf1f | 727 | }\r |
5f907e4a | 728 | }\r |
729 | }\r | |
cb4d97bd | 730 | return includeStrList;\r |
5f907e4a | 731 | }\r |
732 | \r | |
733 | /**\r | |
cb4d97bd | 734 | IncludesToAutogenH\r |
735 | \r | |
736 | This function add include file in AutoGen.h file.\r | |
737 | \r | |
738 | @param packageNameList\r | |
739 | List of module depended package.\r | |
740 | @param moduleType\r | |
741 | Module type.\r | |
742 | @return\r | |
743 | **/\r | |
5f907e4a | 744 | List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r |
745 | String moduleType) throws AutoGenException {\r | |
746 | \r | |
747 | List<String> includeStrList = new LinkedList<String>();\r | |
748 | String pkgHeader;\r | |
749 | String includeStr = "";\r | |
750 | \r | |
751 | //\r | |
752 | // Get include file from moduleInfo file\r | |
753 | //\r | |
754 | for (int i = 0; i < packageNameList.length; i++) {\r | |
755 | pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r | |
756 | moduleType);\r | |
757 | if (pkgHeader == null) {\r | |
758 | throw new AutoGenException("Can not find package ["\r | |
759 | + packageNameList[i]\r | |
760 | + "] declaration in any SPD package. ");\r | |
761 | } else if (!pkgHeader.equalsIgnoreCase("")) {\r | |
cb4d97bd | 762 | includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader\r |
5f907e4a | 763 | + ">\r\n";\r |
764 | includeStrList.add(includeStr);\r | |
765 | }\r | |
766 | }\r | |
767 | \r | |
768 | return includeStrList;\r | |
769 | }\r | |
770 | \r | |
771 | /**\r | |
cb4d97bd | 772 | EntryPointToAutoGen\r |
773 | \r | |
774 | This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r | |
775 | information in mas to AutoGen.c\r | |
776 | \r | |
777 | @param entryPointList\r | |
778 | List of entry point.\r | |
779 | @param fileBuffer\r | |
780 | String buffer fo AutoGen.c.\r | |
781 | @throws Exception\r | |
782 | **/\r | |
783 | void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer)\r | |
5f907e4a | 784 | throws BuildException {\r |
785 | \r | |
83fba802 | 786 | String typeStr = saq.getModuleType();\r |
cb4d97bd | 787 | int unloadImageCount = 0;\r |
788 | int entryPointCount = 0;\r | |
5f907e4a | 789 | \r |
790 | //\r | |
791 | // The parameters and return value of entryPoint is difference\r | |
792 | // for difference module type.\r | |
793 | //\r | |
794 | switch (CommonDefinition.getModuleType(typeStr)) {\r | |
795 | \r | |
796 | case CommonDefinition.ModuleTypePeiCore:\r | |
797 | if (entryPointList == null ||entryPointList.length != 1 ) {\r | |
798 | throw new BuildException(\r | |
799 | "Module type = 'PEI_CORE', can have only one module entry point!");\r | |
800 | } else {\r | |
801 | fileBuffer.append("EFI_STATUS\r\n");\r | |
802 | fileBuffer.append("EFIAPI\r\n");\r | |
803 | fileBuffer.append(entryPointList[0]);\r | |
804 | fileBuffer.append(" (\r\n");\r | |
136adffc | 805 | fileBuffer\r |
5f907e4a | 806 | .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r |
136adffc | 807 | fileBuffer\r |
5f907e4a | 808 | .append(" IN VOID *OldCoreData\r\n");\r |
809 | fileBuffer.append(" );\r\n\r\n");\r | |
136adffc | 810 | \r |
811 | fileBuffer.append("EFI_STATUS\r\n");\r | |
812 | fileBuffer.append("EFIAPI\r\n");\r | |
813 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
5f907e4a | 814 | fileBuffer\r |
815 | .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r | |
816 | fileBuffer\r | |
817 | .append(" IN VOID *OldCoreData\r\n");\r | |
136adffc | 818 | fileBuffer.append(" )\r\n\r\n");\r |
819 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 820 | fileBuffer.append(" return ");\r |
821 | fileBuffer.append(entryPointList[0]);\r | |
822 | fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r | |
823 | fileBuffer.append("}\r\n\r\n");\r | |
824 | }\r | |
825 | break;\r | |
878ddf1f | 826 | \r |
5f907e4a | 827 | case CommonDefinition.ModuleTypeDxeCore:\r |
828 | fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r | |
829 | if (entryPointList == null || entryPointList.length != 1) {\r | |
830 | throw new BuildException(\r | |
831 | "Module type = 'DXE_CORE', can have only one module entry point!");\r | |
832 | } else {\r | |
ff225cbb | 833 | \r |
5f907e4a | 834 | fileBuffer.append("VOID\r\n");\r |
835 | fileBuffer.append("EFIAPI\r\n");\r | |
836 | fileBuffer.append(entryPointList[0]);\r | |
837 | fileBuffer.append(" (\n");\r | |
838 | fileBuffer.append(" IN VOID *HobStart\r\n");\r | |
839 | fileBuffer.append(" );\r\n\r\n");\r | |
840 | \r | |
841 | fileBuffer.append("VOID\r\n");\r | |
842 | fileBuffer.append("EFIAPI\r\n");\r | |
843 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
844 | fileBuffer.append(" IN VOID *HobStart\r\n");\r | |
845 | fileBuffer.append(" )\r\n\r\n");\r | |
846 | fileBuffer.append("{\r\n");\r | |
847 | fileBuffer.append(" ");\r | |
848 | fileBuffer.append(entryPointList[0]);\r | |
849 | fileBuffer.append(" (HobStart);\r\n");\r | |
850 | fileBuffer.append("}\r\n\r\n");\r | |
851 | }\r | |
852 | break;\r | |
853 | \r | |
854 | case CommonDefinition.ModuleTypePeim:\r | |
cb4d97bd | 855 | entryPointCount = 0;\r |
5f907e4a | 856 | fileBuffer\r |
857 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r | |
858 | if (entryPointList == null || entryPointList.length == 0) {\r | |
859 | fileBuffer.append("EFI_STATUS\r\n");\r | |
860 | fileBuffer.append("EFIAPI\r\n");\r | |
861 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
862 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
863 | fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
864 | fileBuffer.append(" )\r\n\r\n");\r | |
865 | fileBuffer.append("{\r\n");\r | |
866 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
867 | fileBuffer.append("}\r\n\r\n");\r | |
868 | break;\r | |
869 | }\r | |
870 | for (int i = 0; i < entryPointList.length; i++) {\r | |
871 | fileBuffer.append("EFI_STATUS\r\n");\r | |
872 | fileBuffer.append("EFIAPI\r\n");\r | |
873 | fileBuffer.append(entryPointList[i]);\r | |
874 | fileBuffer.append(" (\r\n");\r | |
875 | fileBuffer\r | |
876 | .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
877 | fileBuffer\r | |
878 | .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
879 | fileBuffer.append(" );\r\n");\r | |
880 | entryPointCount++;\r | |
881 | \r | |
882 | }\r | |
883 | \r | |
884 | fileBuffer.append("EFI_STATUS\r\n");\r | |
885 | fileBuffer.append("EFIAPI\r\n");\r | |
886 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
887 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
888 | fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
889 | fileBuffer.append(" )\r\n\r\n");\r | |
890 | fileBuffer.append("{\r\n");\r | |
891 | if (entryPointCount == 1) {\r | |
892 | fileBuffer.append(" return ");\r | |
893 | fileBuffer.append(entryPointList[0]);\r | |
894 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r | |
895 | } else {\r | |
896 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r | |
897 | fileBuffer.append(" EFI_STATUS CombinedStatus;\r\n\r\n");\r | |
898 | fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r | |
899 | for (int i = 0; i < entryPointList.length; i++) {\r | |
900 | if (!entryPointList[i].equals("")) {\r | |
901 | fileBuffer.append(" Status = ");\r | |
902 | fileBuffer.append(entryPointList[i]);\r | |
903 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r | |
904 | fileBuffer\r | |
905 | .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r | |
906 | fileBuffer.append(" CombinedStatus = Status;\r\n");\r | |
907 | fileBuffer.append(" }\r\n\r\n");\r | |
908 | } else {\r | |
909 | break;\r | |
910 | }\r | |
911 | }\r | |
912 | fileBuffer.append(" return CombinedStatus;\r\n");\r | |
913 | }\r | |
914 | fileBuffer.append("}\r\n\r\n");\r | |
915 | break;\r | |
916 | \r | |
917 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
918 | entryPointCount = 0;\r | |
919 | //\r | |
920 | // If entryPoint is null, create an empty ProcessModuleEntryPointList\r | |
921 | // function.\r | |
922 | //\r | |
923 | if (entryPointList == null || entryPointList.length == 0) {\r | |
924 | fileBuffer\r | |
925 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r | |
926 | fileBuffer.append(Integer.toString(entryPointCount));\r | |
927 | fileBuffer.append(";\r\n");\r | |
928 | fileBuffer.append("EFI_STATUS\r\n");\r | |
929 | fileBuffer.append("EFIAPI\r\n");\r | |
930 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
931 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
932 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
933 | fileBuffer.append(" )\r\n\r\n");\r | |
934 | fileBuffer.append("{\r\n");\r | |
935 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
936 | fileBuffer.append("}\r\n\r\n");\r | |
937 | \r | |
938 | } else {\r | |
939 | for (int i = 0; i < entryPointList.length; i++) {\r | |
940 | fileBuffer.append("EFI_STATUS\r\n");\r | |
941 | fileBuffer.append("EFIAPI\r\n");\r | |
942 | fileBuffer.append(entryPointList[i]);\r | |
943 | fileBuffer.append(" (\r\n");\r | |
944 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
945 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
946 | fileBuffer.append(" );\r\n");\r | |
947 | entryPointCount++;\r | |
948 | }\r | |
949 | fileBuffer\r | |
950 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r | |
951 | fileBuffer.append(Integer.toString(entryPointCount));\r | |
952 | fileBuffer.append(";\r\n");\r | |
953 | fileBuffer\r | |
954 | .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r | |
955 | fileBuffer\r | |
956 | .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r | |
957 | \r | |
958 | fileBuffer.append("EFI_STATUS\r\n");\r | |
959 | fileBuffer.append("EFIAPI\r\n");\r | |
960 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
961 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
962 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
963 | fileBuffer.append(" )\r\n\r\n");\r | |
964 | fileBuffer.append("{\r\n");\r | |
965 | \r | |
966 | \r | |
967 | for (int i = 0; i < entryPointList.length; i++) {\r | |
968 | fileBuffer\r | |
969 | .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r | |
970 | fileBuffer.append(" ExitDriver (");\r | |
971 | fileBuffer.append(entryPointList[i]);\r | |
972 | fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r | |
136adffc | 973 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r |
974 | fileBuffer.append(" }\r\n");\r | |
ff225cbb | 975 | \r |
136adffc | 976 | }\r |
977 | fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r | |
978 | fileBuffer.append("}\r\n\r\n");\r | |
979 | \r | |
980 | fileBuffer.append("VOID\r\n");\r | |
981 | fileBuffer.append("EFIAPI\r\n");\r | |
982 | fileBuffer.append("ExitDriver (\r\n");\r | |
983 | fileBuffer.append(" IN EFI_STATUS Status\n");\r | |
984 | fileBuffer.append(" )\r\n\r\n");\r | |
985 | fileBuffer.append("{\r\n");\r | |
986 | fileBuffer\r | |
5f907e4a | 987 | .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r |
136adffc | 988 | fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r |
989 | fileBuffer.append(" }\r\n");\r | |
990 | fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r | |
991 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
992 | fileBuffer.append("}\r\n\r\n");\r | |
ff225cbb | 993 | \r |
136adffc | 994 | }\r |
ff225cbb | 995 | \r |
996 | \r | |
5f907e4a | 997 | //\r |
998 | // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r | |
999 | //\r | |
cb4d97bd | 1000 | //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r |
1001 | //entryPointList = CommonDefinition.remDupString(entryPointList);\r | |
1002 | //entryPointCount = 0;\r | |
136adffc | 1003 | \r |
cb4d97bd | 1004 | unloadImageCount = 0;\r |
1005 | if (unloadImageList != null) {\r | |
1006 | for (int i = 0; i < unloadImageList.length; i++) {\r | |
a84091c4 | 1007 | fileBuffer.append("EFI_STATUS\r\n");\r |
1008 | fileBuffer.append("EFIAPI\r\n");\r | |
cb4d97bd | 1009 | fileBuffer.append(unloadImageList[i]);\r |
a84091c4 | 1010 | fileBuffer.append(" (\r\n");\r |
1011 | fileBuffer\r | |
5f907e4a | 1012 | .append(" IN EFI_HANDLE ImageHandle\r\n");\r |
a84091c4 | 1013 | fileBuffer.append(" );\r\n");\r |
cb4d97bd | 1014 | unloadImageCount++;\r |
a84091c4 | 1015 | }\r |
5f907e4a | 1016 | }\r |
136adffc | 1017 | \r |
a84091c4 | 1018 | fileBuffer\r |
5f907e4a | 1019 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r |
cb4d97bd | 1020 | fileBuffer.append(Integer.toString(unloadImageCount));\r |
5f907e4a | 1021 | fileBuffer.append(";\r\n\r\n");\r |
1022 | \r | |
1023 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1024 | fileBuffer.append("EFIAPI\r\n");\r | |
1025 | fileBuffer.append("ProcessModuleUnloadList (\r\n");\r | |
1026 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
1027 | fileBuffer.append(" )\r\n");\r | |
1028 | fileBuffer.append("{\r\n");\r | |
1029 | \r | |
cb4d97bd | 1030 | if (unloadImageCount == 0) {\r |
5f907e4a | 1031 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r |
cb4d97bd | 1032 | } else if (unloadImageCount == 1) {\r |
5f907e4a | 1033 | fileBuffer.append(" return ");\r |
cb4d97bd | 1034 | fileBuffer.append(unloadImageList[0]);\r |
5f907e4a | 1035 | fileBuffer.append("(ImageHandle);\r\n");\r |
1036 | } else {\r | |
1037 | fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r | |
1038 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r | |
cb4d97bd | 1039 | for (int i = 0; i < unloadImageList.length; i++) {\r |
5f907e4a | 1040 | if (i == 0) {\r |
136adffc | 1041 | fileBuffer.append(" Status = ");\r |
cb4d97bd | 1042 | fileBuffer.append(unloadImageList[i]);\r |
136adffc | 1043 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1044 | } else {\r |
878ddf1f | 1045 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r |
1046 | fileBuffer.append(" ");\r | |
cb4d97bd | 1047 | fileBuffer.append(unloadImageList[i]);\r |
878ddf1f | 1048 | fileBuffer.append("(ImageHandle);\r\n");\r |
1049 | fileBuffer.append(" } else {\r\n");\r | |
1050 | fileBuffer.append(" Status = ");\r | |
cb4d97bd | 1051 | fileBuffer.append(unloadImageList[i]);\r |
878ddf1f | 1052 | fileBuffer.append("(ImageHandle);\r\n");\r |
1053 | fileBuffer.append(" }\r\n");\r | |
878ddf1f | 1054 | }\r |
5f907e4a | 1055 | }\r |
1056 | fileBuffer.append(" return Status;\r\n");\r | |
1057 | }\r | |
1058 | fileBuffer.append("}\r\n\r\n");\r | |
1059 | break;\r | |
1060 | \r | |
1061 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1062 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1063 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1064 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1065 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1066 | entryPointCount = 0;\r | |
1067 | fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r | |
136adffc | 1068 | //\r |
1069 | // If entry point is null, create a empty ProcessModuleEntryPointList function.\r | |
1070 | //\r | |
5f907e4a | 1071 | if (entryPointList == null || entryPointList.length == 0) {\r |
a29c47e0 | 1072 | fileBuffer\r |
136adffc | 1073 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");\r |
5f907e4a | 1074 | fileBuffer.append("EFI_STATUS\r\n");\r |
1075 | fileBuffer.append("EFIAPI\r\n");\r | |
1076 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
1077 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1078 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1079 | fileBuffer.append(" )\r\n\r\n");\r | |
1080 | fileBuffer.append("{\r\n");\r | |
1081 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
1082 | fileBuffer.append("}\r\n");\r | |
1083 | \r | |
1084 | } else {\r | |
136adffc | 1085 | for (int i = 0; i < entryPointList.length; i++) {\r |
ff225cbb | 1086 | \r |
136adffc | 1087 | fileBuffer.append("EFI_STATUS\r\n");\r |
1088 | fileBuffer.append("EFIAPI\r\n");\r | |
1089 | fileBuffer.append(entryPointList[i]);\r | |
1090 | fileBuffer.append(" (\r\n");\r | |
47f2f011 | 1091 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r |
1092 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
136adffc | 1093 | fileBuffer.append(" );\r\n");\r |
1094 | entryPointCount++;\r | |
878ddf1f | 1095 | }\r |
1096 | \r | |
878ddf1f | 1097 | fileBuffer\r |
5f907e4a | 1098 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r |
136adffc | 1099 | fileBuffer.append(Integer.toString(entryPointCount));\r |
878ddf1f | 1100 | fileBuffer.append(";\r\n");\r |
136adffc | 1101 | if (entryPointCount > 1) {\r |
1102 | fileBuffer\r | |
5f907e4a | 1103 | .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r |
136adffc | 1104 | fileBuffer\r |
5f907e4a | 1105 | .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r |
136adffc | 1106 | }\r |
1107 | fileBuffer.append("\n");\r | |
878ddf1f | 1108 | \r |
136adffc | 1109 | fileBuffer.append("EFI_STATUS\r\n");\r |
1110 | fileBuffer.append("EFIAPI\r\n");\r | |
1111 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
25832ed3 | 1112 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r |
1113 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
136adffc | 1114 | fileBuffer.append(" )\r\n\r\n");\r |
1115 | fileBuffer.append("{\r\n");\r | |
878ddf1f | 1116 | \r |
136adffc | 1117 | if (entryPointCount == 1) {\r |
1118 | fileBuffer.append(" return (");\r | |
1119 | fileBuffer.append(entryPointList[0]);\r | |
1120 | fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r | |
1121 | } else {\r | |
1122 | for (int i = 0; i < entryPointList.length; i++) {\r | |
1123 | if (!entryPointList[i].equals("")) {\r | |
1124 | fileBuffer\r | |
5f907e4a | 1125 | .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r |
136adffc | 1126 | fileBuffer.append(" ExitDriver (");\r |
1127 | fileBuffer.append(entryPointList[i]);\r | |
1128 | fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r | |
1129 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
1130 | fileBuffer.append(" }\r\n");\r | |
1131 | } else {\r | |
1132 | break;\r | |
1133 | }\r | |
878ddf1f | 1134 | }\r |
136adffc | 1135 | fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r |
878ddf1f | 1136 | }\r |
136adffc | 1137 | fileBuffer.append("}\r\n\r\n");\r |
878ddf1f | 1138 | \r |
2336382f | 1139 | fileBuffer.append("VOID\r\n");\r |
1140 | fileBuffer.append("EFIAPI\r\n");\r | |
136adffc | 1141 | fileBuffer.append("ExitDriver (\r\n");\r |
2336382f | 1142 | fileBuffer.append(" IN EFI_STATUS Status\r\n");\r |
136adffc | 1143 | fileBuffer.append(" )\r\n\r\n");\r |
1144 | fileBuffer.append("{\r\n");\r | |
1145 | if (entryPointCount <= 1) {\r | |
1146 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r | |
1147 | fileBuffer\r | |
5f907e4a | 1148 | .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r |
136adffc | 1149 | fileBuffer.append(" }\r\n");\r |
1150 | fileBuffer\r | |
5f907e4a | 1151 | .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r |
878ddf1f | 1152 | } else {\r |
136adffc | 1153 | fileBuffer\r |
5f907e4a | 1154 | .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r |
136adffc | 1155 | fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r |
1156 | fileBuffer.append(" }\r\n");\r | |
1157 | fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r | |
1158 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
878ddf1f | 1159 | }\r |
136adffc | 1160 | fileBuffer.append("}\r\n\r\n");\r |
878ddf1f | 1161 | \r |
878ddf1f | 1162 | }\r |
ff225cbb | 1163 | \r |
5f907e4a | 1164 | //\r |
1165 | // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r | |
1166 | //\r | |
cb4d97bd | 1167 | //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r |
878ddf1f | 1168 | //\r |
136adffc | 1169 | // Remover duplicate unload entry point.\r |
878ddf1f | 1170 | //\r |
cb4d97bd | 1171 | //entryPointList = CommonDefinition.remDupString(entryPointList);\r |
1172 | //entryPointCount = 0;\r | |
1173 | unloadImageCount = 0;\r | |
1174 | if (unloadImageList != null) {\r | |
1175 | for (int i = 0; i < unloadImageList.length; i++) {\r | |
a84091c4 | 1176 | fileBuffer.append("EFI_STATUS\r\n");\r |
1177 | fileBuffer.append("EFIAPI\r\n");\r | |
cb4d97bd | 1178 | fileBuffer.append(unloadImageList[i]);\r |
a84091c4 | 1179 | fileBuffer.append(" (\r\n");\r |
1180 | fileBuffer\r | |
5f907e4a | 1181 | .append(" IN EFI_HANDLE ImageHandle\r\n");\r |
a84091c4 | 1182 | fileBuffer.append(" );\r\n");\r |
cb4d97bd | 1183 | unloadImageCount++;\r |
5f907e4a | 1184 | }\r |
1185 | }\r | |
1186 | \r | |
1187 | fileBuffer\r | |
1188 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r | |
cb4d97bd | 1189 | fileBuffer.append(Integer.toString(unloadImageCount));\r |
5f907e4a | 1190 | fileBuffer.append(";\r\n\r\n");\r |
1191 | \r | |
1192 | fileBuffer.append("EFI_STATUS\n");\r | |
1193 | fileBuffer.append("EFIAPI\r\n");\r | |
1194 | fileBuffer.append("ProcessModuleUnloadList (\r\n");\r | |
1195 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
1196 | fileBuffer.append(" )\r\n");\r | |
1197 | fileBuffer.append("{\r\n");\r | |
1198 | \r | |
cb4d97bd | 1199 | if (unloadImageCount == 0) {\r |
5f907e4a | 1200 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r |
cb4d97bd | 1201 | } else if (unloadImageCount == 1) {\r |
5f907e4a | 1202 | fileBuffer.append(" return ");\r |
cb4d97bd | 1203 | fileBuffer.append(unloadImageList[0]);\r |
5f907e4a | 1204 | fileBuffer.append("(ImageHandle);\r\n");\r |
1205 | } else {\r | |
1206 | fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r | |
1207 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r | |
cb4d97bd | 1208 | for (int i = 0; i < unloadImageList.length; i++) {\r |
25832ed3 | 1209 | if (i == 0) {\r |
1210 | fileBuffer.append(" Status = ");\r | |
cb4d97bd | 1211 | fileBuffer.append(unloadImageList[i]);\r |
25832ed3 | 1212 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1213 | } else {\r |
25832ed3 | 1214 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r |
5f907e4a | 1215 | fileBuffer.append(" ");\r |
cb4d97bd | 1216 | fileBuffer.append(unloadImageList[i]);\r |
5f907e4a | 1217 | fileBuffer.append("(ImageHandle);\r\n");\r |
1218 | fileBuffer.append(" } else {\r\n");\r | |
1219 | fileBuffer.append(" Status = ");\r | |
cb4d97bd | 1220 | fileBuffer.append(unloadImageList[i]);\r |
5f907e4a | 1221 | fileBuffer.append("(ImageHandle);\r\n");\r |
1222 | fileBuffer.append(" }\r\n");\r | |
25832ed3 | 1223 | }\r |
5f907e4a | 1224 | }\r |
1225 | fileBuffer.append(" return Status;\r\n");\r | |
1226 | }\r | |
1227 | fileBuffer.append("}\r\n\r\n");\r | |
1228 | break;\r | |
1229 | }\r | |
1230 | }\r | |
1231 | \r | |
1232 | /**\r | |
cb4d97bd | 1233 | PpiGuidToAutogenc\r |
1234 | \r | |
1235 | This function gets GUIDs from SPD file accrodeing to <PPIs> information\r | |
1236 | and write those GUIDs to AutoGen.c.\r | |
1237 | \r | |
1238 | @param fileBuffer\r | |
1239 | String Buffer for Autogen.c file.\r | |
1240 | @throws BuildException\r | |
1241 | Guid must set value!\r | |
1242 | **/\r | |
5f907e4a | 1243 | void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r |
1244 | String[] cNameGuid = null;\r | |
1245 | \r | |
1246 | //\r | |
1247 | // Get the all PPI adn PPI Notify from MSA file,\r | |
1248 | // then add those PPI ,and PPI Notify name to list.\r | |
1249 | //\r | |
1250 | \r | |
83fba802 | 1251 | String[] ppiList = saq.getPpiArray(this.arch);\r |
5f907e4a | 1252 | for (int i = 0; i < ppiList.length; i++) {\r |
1253 | this.mPpiList.add(ppiList[i]);\r | |
1254 | }\r | |
1255 | \r | |
83fba802 | 1256 | String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r |
5f907e4a | 1257 | for (int i = 0; i < ppiNotifyList.length; i++) {\r |
1258 | this.mPpiList.add(ppiNotifyList[i]);\r | |
1259 | }\r | |
1260 | \r | |
1261 | //\r | |
1262 | // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r | |
1263 | //\r | |
1264 | Iterator ppiIterator = this.mPpiList.iterator();\r | |
1265 | String ppiKeyWord = null;\r | |
1266 | while (ppiIterator.hasNext()) {\r | |
1267 | ppiKeyWord = ppiIterator.next().toString();\r | |
1268 | cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r | |
1269 | if (cNameGuid != null) {\r | |
1270 | fileBuffer\r | |
1271 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r | |
1272 | fileBuffer.append(cNameGuid[0]);\r | |
1273 | fileBuffer.append(" = { ");\r | |
1274 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1275 | fileBuffer.append(" } ;");\r | |
1276 | } else {\r | |
1277 | //\r | |
1278 | // If can't find Ppi GUID declaration in every package\r | |
1279 | //\r | |
1280 | throw new AutoGenException("Can not find Ppi GUID ["\r | |
1281 | + ppiKeyWord + "] declaration in any SPD package!");\r | |
1282 | }\r | |
1283 | }\r | |
1284 | }\r | |
1285 | \r | |
1286 | /**\r | |
cb4d97bd | 1287 | ProtocolGuidToAutogenc\r |
1288 | \r | |
1289 | This function gets GUIDs from SPD file accrodeing to <Protocol>\r | |
1290 | information and write those GUIDs to AutoGen.c.\r | |
1291 | \r | |
1292 | @param fileBuffer\r | |
1293 | String Buffer for Autogen.c file.\r | |
1294 | @throws BuildException\r | |
1295 | Protocol name must set.\r | |
1296 | **/\r | |
5f907e4a | 1297 | void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r |
1298 | String[] cNameGuid = null;\r | |
1299 | \r | |
83fba802 | 1300 | String[] protocolList = saq.getProtocolArray(this.arch);\r |
5f907e4a | 1301 | \r |
1302 | //\r | |
1303 | // Add result to Autogen global list.\r | |
1304 | //\r | |
1305 | for (int i = 0; i < protocolList.length; i++) {\r | |
1306 | this.mProtocolList.add(protocolList[i]);\r | |
1307 | }\r | |
1308 | \r | |
83fba802 | 1309 | String[] protocolNotifyList = saq\r |
5f907e4a | 1310 | .getProtocolNotifyArray(this.arch);\r |
1311 | \r | |
1312 | for (int i = 0; i < protocolNotifyList.length; i++) {\r | |
1313 | this.mProtocolList.add(protocolNotifyList[i]);\r | |
1314 | }\r | |
1315 | \r | |
1316 | //\r | |
1317 | // Get the NAME and GUID from dependence SPD and write to Autogen.c\r | |
1318 | //\r | |
1319 | Iterator protocolIterator = this.mProtocolList.iterator();\r | |
1320 | String protocolKeyWord = null;\r | |
1321 | \r | |
1322 | \r | |
1323 | while (protocolIterator.hasNext()) {\r | |
1324 | protocolKeyWord = protocolIterator.next().toString();\r | |
1325 | cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r | |
1326 | if (cNameGuid != null) {\r | |
1327 | fileBuffer\r | |
1328 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r | |
1329 | fileBuffer.append(cNameGuid[0]);\r | |
1330 | fileBuffer.append(" = { ");\r | |
1331 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1332 | fileBuffer.append(" } ;");\r | |
1333 | } else {\r | |
1334 | //\r | |
1335 | // If can't find protocol GUID declaration in every package\r | |
1336 | //\r | |
1337 | throw new BuildException("Can not find protocol Guid ["\r | |
1338 | + protocolKeyWord + "] declaration in any SPD package!");\r | |
1339 | }\r | |
1340 | }\r | |
1341 | }\r | |
1342 | \r | |
1343 | /**\r | |
cb4d97bd | 1344 | GuidGuidToAutogenc\r |
1345 | \r | |
1346 | This function gets GUIDs from SPD file accrodeing to <Guids> information\r | |
1347 | and write those GUIDs to AutoGen.c.\r | |
1348 | \r | |
1349 | @param fileBuffer\r | |
1350 | String Buffer for Autogen.c file.\r | |
1351 | \r | |
1352 | **/\r | |
5f907e4a | 1353 | void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r |
1354 | String[] cNameGuid = null;\r | |
1355 | String guidKeyWord = null;\r | |
1356 | \r | |
83fba802 | 1357 | String[] guidList = saq.getGuidEntryArray(this.arch);\r |
5f907e4a | 1358 | \r |
1359 | for (int i = 0; i < guidList.length; i++) {\r | |
1360 | this.mGuidList.add(guidList[i]);\r | |
1361 | }\r | |
1362 | \r | |
1363 | \r | |
1364 | Iterator guidIterator = this.mGuidList.iterator();\r | |
1365 | while (guidIterator.hasNext()) {\r | |
1366 | guidKeyWord = guidIterator.next().toString();\r | |
1367 | cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r | |
1368 | \r | |
1369 | if (cNameGuid != null) {\r | |
1370 | fileBuffer\r | |
1371 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r | |
1372 | fileBuffer.append(cNameGuid[0]);\r | |
1373 | fileBuffer.append(" = { ");\r | |
1374 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1375 | fileBuffer.append("} ;");\r | |
1376 | } else {\r | |
1377 | //\r | |
1378 | // If can't find GUID declaration in every package\r | |
1379 | //\r | |
1380 | throw new AutoGenException("Can not find Guid [" + guidKeyWord\r | |
1381 | + "] declaration in any SPD package. ");\r | |
1382 | }\r | |
1383 | \r | |
1384 | }\r | |
1385 | }\r | |
1386 | \r | |
1387 | /**\r | |
cb4d97bd | 1388 | LibInstanceToAutogenC\r |
1389 | \r | |
1390 | This function adds dependent library instance to autogen.c,which\r | |
1391 | includeing library's constructor, destructor, and library dependent ppi,\r | |
1392 | protocol, guid, pcd information.\r | |
1393 | \r | |
1394 | @param fileBuffer\r | |
1395 | String buffer for AutoGen.c\r | |
1396 | @throws BuildException\r | |
1397 | **/\r | |
5f907e4a | 1398 | void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r |
1399 | try {\r | |
2336382f | 1400 | String moduleType = this.moduleId.getModuleType();\r |
5f907e4a | 1401 | //\r |
1402 | // Add library constructor to AutoGen.c\r | |
1403 | //\r | |
1404 | LibConstructorToAutogenC(libConstructList, moduleType,\r | |
1405 | fileBuffer/* autogenC */);\r | |
1406 | //\r | |
1407 | // Add library destructor to AutoGen.c\r | |
1408 | //\r | |
1409 | LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r | |
1410 | } catch (Exception e) {\r | |
1411 | throw new BuildException(e.getMessage());\r | |
1412 | }\r | |
1413 | }\r | |
1414 | \r | |
1415 | /**\r | |
cb4d97bd | 1416 | LibConstructorToAutogenc\r |
1417 | \r | |
1418 | This function writes library constructor list to AutoGen.c. The library\r | |
1419 | constructor's parameter and return value depend on module type.\r | |
1420 | \r | |
1421 | @param libInstanceList\r | |
1422 | List of library construct name.\r | |
1423 | @param moduleType\r | |
1424 | Module type.\r | |
1425 | @param fileBuffer\r | |
1426 | String buffer for AutoGen.c\r | |
1427 | @throws Exception\r | |
1428 | **/\r | |
5f907e4a | 1429 | void LibConstructorToAutogenC(List<String> libInstanceList,\r |
1430 | String moduleType, StringBuffer fileBuffer) throws Exception {\r | |
1431 | boolean isFirst = true;\r | |
1432 | \r | |
1433 | //\r | |
1434 | // The library constructor's parameter and return value depend on\r | |
1435 | // module type.\r | |
1436 | //\r | |
1437 | for (int i = 0; i < libInstanceList.size(); i++) {\r | |
1438 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1439 | case CommonDefinition.ModuleTypeBase:\r | |
1440 | fileBuffer.append("RETURN_STATUS\r\n");\r | |
1441 | fileBuffer.append("EFIAPI\r\n");\r | |
1442 | fileBuffer.append(libInstanceList.get(i));\r | |
1443 | fileBuffer.append(" (\r\n");\r | |
1444 | fileBuffer.append(" VOID\r\n");\r | |
1445 | fileBuffer.append(" );\r\n");\r | |
1446 | break;\r | |
1447 | \r | |
1448 | case CommonDefinition.ModuleTypePeiCore:\r | |
1449 | case CommonDefinition.ModuleTypePeim:\r | |
1450 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1451 | fileBuffer.append("EFIAPI\r\n");\r | |
1452 | fileBuffer.append(libInstanceList.get(i));\r | |
1453 | fileBuffer.append(" (\r\n");\r | |
1454 | fileBuffer\r | |
1455 | .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1456 | fileBuffer\r | |
1457 | .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1458 | fileBuffer.append(" );\r\n");\r | |
1459 | break;\r | |
1460 | \r | |
1461 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1462 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1463 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1464 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1465 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1466 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1467 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1468 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1469 | fileBuffer.append("EFIAPI\r\n");\r | |
1470 | fileBuffer.append(libInstanceList.get(i));\r | |
1471 | fileBuffer.append(" (\r\n");\r | |
1472 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1473 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1474 | fileBuffer.append(" );\r\n");\r | |
1475 | break;\r | |
1476 | }\r | |
1477 | }\r | |
1478 | \r | |
1479 | //\r | |
1480 | // Add ProcessLibraryConstructorList in AutoGen.c\r | |
1481 | //\r | |
1482 | fileBuffer.append("VOID\r\n");\r | |
1483 | fileBuffer.append("EFIAPI\r\n");\r | |
1484 | fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r | |
1485 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1486 | case CommonDefinition.ModuleTypeBase:\r | |
1487 | fileBuffer.append(" VOID\r\n");\r | |
1488 | break;\r | |
1489 | \r | |
1490 | case CommonDefinition.ModuleTypePeiCore:\r | |
1491 | case CommonDefinition.ModuleTypePeim:\r | |
1492 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1493 | fileBuffer\r | |
1494 | .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1495 | break;\r | |
1496 | \r | |
1497 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1498 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1499 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1500 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1501 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1502 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1503 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1504 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1505 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1506 | break;\r | |
1507 | }\r | |
1508 | \r | |
1509 | fileBuffer.append(" )\r\n");\r | |
1510 | fileBuffer.append("{\r\n");\r | |
136adffc | 1511 | //\r |
1512 | // If no constructor function, return EFI_SUCCESS.\r | |
1513 | //\r | |
1514 | //if (libInstanceList.size() == 0){\r | |
1515 | // fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
1516 | //}\r | |
5f907e4a | 1517 | for (int i = 0; i < libInstanceList.size(); i++) {\r |
1518 | if (isFirst) {\r | |
1519 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r | |
136adffc | 1520 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r |
5f907e4a | 1521 | fileBuffer.append("\r\n");\r |
1522 | isFirst = false;\r | |
1523 | }\r | |
1524 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1525 | case CommonDefinition.ModuleTypeBase:\r | |
1526 | fileBuffer.append(" Status = ");\r | |
1527 | fileBuffer.append(libInstanceList.get(i));\r | |
1528 | fileBuffer.append("();\r\n");\r | |
1529 | fileBuffer.append(" VOID\r\n");\r | |
1530 | break;\r | |
1531 | case CommonDefinition.ModuleTypePeiCore:\r | |
1532 | case CommonDefinition.ModuleTypePeim:\r | |
1533 | fileBuffer.append(" Status = ");\r | |
1534 | fileBuffer.append(libInstanceList.get(i));\r | |
1535 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r | |
1536 | break;\r | |
1537 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1538 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1539 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1540 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1541 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1542 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1543 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1544 | fileBuffer.append(" Status = ");\r | |
1545 | fileBuffer.append(libInstanceList.get(i));\r | |
1546 | fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r | |
1547 | break;\r | |
136adffc | 1548 | default:\r |
391dbbb1 | 1549 | EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r |
5f907e4a | 1550 | }\r |
1551 | fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r | |
1552 | }\r | |
1553 | fileBuffer.append("}\r\n");\r | |
1554 | }\r | |
1555 | \r | |
1556 | /**\r | |
cb4d97bd | 1557 | LibDestructorToAutogenc\r |
1558 | \r | |
1559 | This function writes library destructor list to AutoGen.c. The library\r | |
1560 | destructor's parameter and return value depend on module type.\r | |
1561 | \r | |
1562 | @param libInstanceList\r | |
1563 | List of library destructor name.\r | |
1564 | @param moduleType\r | |
1565 | Module type.\r | |
1566 | @param fileBuffer\r | |
1567 | String buffer for AutoGen.c\r | |
1568 | @throws Exception\r | |
1569 | **/\r | |
5f907e4a | 1570 | void LibDestructorToAutogenC(List<String> libInstanceList,\r |
1571 | String moduleType, StringBuffer fileBuffer) throws Exception {\r | |
1572 | boolean isFirst = true;\r | |
1573 | for (int i = 0; i < libInstanceList.size(); i++) {\r | |
1574 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1575 | case CommonDefinition.ModuleTypeBase:\r | |
1576 | fileBuffer.append("RETURN_STATUS\r\n");\r | |
1577 | fileBuffer.append("EFIAPI\r\n");\r | |
1578 | fileBuffer.append(libInstanceList.get(i));\r | |
1579 | fileBuffer.append(" (\r\n");\r | |
1580 | fileBuffer.append(" VOID\r\n");\r | |
1581 | fileBuffer.append(" );\r\n");\r | |
1582 | break;\r | |
1583 | case CommonDefinition.ModuleTypePeiCore:\r | |
1584 | case CommonDefinition.ModuleTypePeim:\r | |
1585 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1586 | fileBuffer.append("EFIAPI\r\n");\r | |
1587 | fileBuffer.append(libInstanceList.get(i));\r | |
1588 | fileBuffer.append(" (\r\n");\r | |
1589 | fileBuffer\r | |
1590 | .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1591 | fileBuffer\r | |
1592 | .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1593 | fileBuffer.append(" );\r\n");\r | |
1594 | break;\r | |
1595 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1596 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1597 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1598 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1599 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1600 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1601 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1602 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1603 | fileBuffer.append("EFIAPI\r\n");\r | |
1604 | fileBuffer.append(libInstanceList.get(i));\r | |
1605 | fileBuffer.append(" (\r\n");\r | |
1606 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1607 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1608 | fileBuffer.append(" );\r\n");\r | |
1609 | break;\r | |
1610 | }\r | |
1611 | }\r | |
1612 | \r | |
1613 | //\r | |
1614 | // Write ProcessLibraryDestructor list to autogen.c\r | |
1615 | //\r | |
1616 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1617 | case CommonDefinition.ModuleTypeBase:\r | |
1618 | case CommonDefinition.ModuleTypePeiCore:\r | |
1619 | case CommonDefinition.ModuleTypePeim:\r | |
1620 | break;\r | |
1621 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1622 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1623 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1624 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1625 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1626 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1627 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1628 | fileBuffer.append("VOID\r\n");\r | |
1629 | fileBuffer.append("EFIAPI\r\n");\r | |
1630 | fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r | |
1631 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1632 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1633 | fileBuffer.append(" )\r\n");\r | |
1634 | fileBuffer.append("{\r\n");\r | |
878ddf1f | 1635 | //\r |
136adffc | 1636 | // If no library destructor function, return EFI_SUCCESS.\r |
878ddf1f | 1637 | //\r |
ff225cbb | 1638 | \r |
5f907e4a | 1639 | for (int i = 0; i < libInstanceList.size(); i++) {\r |
1640 | if (isFirst) {\r | |
1641 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r | |
136adffc | 1642 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r |
5f907e4a | 1643 | fileBuffer.append("\r\n");\r |
1644 | isFirst = false;\r | |
1645 | }\r | |
1646 | fileBuffer.append(" Status = ");\r | |
1647 | fileBuffer.append(libInstanceList.get(i));\r | |
1648 | fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r | |
1649 | fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r | |
1650 | }\r | |
1651 | fileBuffer.append("}\r\n");\r | |
1652 | break;\r | |
1653 | }\r | |
1654 | }\r | |
1655 | \r | |
1656 | /**\r | |
cb4d97bd | 1657 | ExternsDriverBindingToAutoGenC\r |
1658 | \r | |
1659 | This function is to write DRIVER_BINDING, COMPONENT_NAME,\r | |
1660 | DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r | |
1661 | \r | |
1662 | @param fileBuffer\r | |
1663 | String buffer for AutoGen.c\r | |
1664 | **/\r | |
5f907e4a | 1665 | void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r |
1666 | throws BuildException {\r | |
1667 | \r | |
1668 | //\r | |
1669 | // Check what <extern> contains. And the number of following elements\r | |
1670 | // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r | |
1671 | // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r | |
1672 | //\r | |
1673 | \r | |
83fba802 | 1674 | String[] drvBindList = saq.getDriverBindingArray();\r |
5f907e4a | 1675 | \r |
1676 | //\r | |
1677 | // If component name protocol,component configuration protocol,\r | |
1678 | // component diagnostic protocol is not null or empty, check\r | |
1679 | // if every one have the same number of the driver binding protocol.\r | |
1680 | //\r | |
1681 | if (drvBindList == null || drvBindList.length == 0) {\r | |
1682 | return;\r | |
1683 | }\r | |
1684 | \r | |
83fba802 | 1685 | String[] compNamList = saq.getComponentNameArray();\r |
1686 | String[] compConfList = saq.getDriverConfigArray();\r | |
1687 | String[] compDiagList = saq.getDriverDiagArray();\r | |
5f907e4a | 1688 | \r |
1689 | int BitMask = 0;\r | |
1690 | \r | |
1691 | //\r | |
1692 | // Write driver binding protocol extern to autogen.c\r | |
1693 | //\r | |
1694 | for (int i = 0; i < drvBindList.length; i++) {\r | |
1695 | fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r | |
1696 | fileBuffer.append(drvBindList[i]);\r | |
1697 | fileBuffer.append(";\r\n");\r | |
1698 | }\r | |
1699 | \r | |
1700 | //\r | |
1701 | // Write component name protocol extern to autogen.c\r | |
1702 | //\r | |
1703 | if (compNamList != null && compNamList.length != 0) {\r | |
1704 | if (drvBindList.length != compNamList.length) {\r | |
1705 | throw new BuildException(\r | |
1706 | "Different number of Driver Binding and Component Name protocols!");\r | |
1707 | }\r | |
1708 | \r | |
1709 | BitMask |= 0x01;\r | |
1710 | for (int i = 0; i < compNamList.length; i++) {\r | |
1711 | fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r | |
1712 | fileBuffer.append(compNamList[i]);\r | |
1713 | fileBuffer.append(";\r\n");\r | |
1714 | }\r | |
1715 | }\r | |
1716 | \r | |
1717 | //\r | |
1718 | // Write driver configration protocol extern to autogen.c\r | |
1719 | //\r | |
1720 | if (compConfList != null && compConfList.length != 0) {\r | |
1721 | if (drvBindList.length != compConfList.length) {\r | |
1722 | throw new BuildException(\r | |
1723 | "Different number of Driver Binding and Driver Configuration protocols!");\r | |
1724 | }\r | |
1725 | \r | |
1726 | BitMask |= 0x02;\r | |
1727 | for (int i = 0; i < compConfList.length; i++) {\r | |
1728 | fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r | |
1729 | fileBuffer.append(compConfList[i]);\r | |
1730 | fileBuffer.append(";\r\n");\r | |
1731 | }\r | |
1732 | }\r | |
1733 | \r | |
1734 | //\r | |
1735 | // Write driver dignastic protocol extern to autogen.c\r | |
1736 | //\r | |
1737 | if (compDiagList != null && compDiagList.length != 0) {\r | |
1738 | if (drvBindList.length != compDiagList.length) {\r | |
1739 | throw new BuildException(\r | |
1740 | "Different number of Driver Binding and Driver Diagnosis protocols!");\r | |
1741 | }\r | |
1742 | \r | |
1743 | BitMask |= 0x04;\r | |
1744 | for (int i = 0; i < compDiagList.length; i++) {\r | |
1745 | fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r | |
1746 | fileBuffer.append(compDiagList[i]);\r | |
1747 | fileBuffer.append(";\r\n");\r | |
1748 | }\r | |
1749 | }\r | |
1750 | \r | |
1751 | //\r | |
1752 | // Write driver module protocol bitmask.\r | |
1753 | //\r | |
1754 | fileBuffer\r | |
1755 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");\r | |
1756 | fileBuffer.append(Integer.toString(BitMask));\r | |
1757 | fileBuffer.append(";\r\n");\r | |
1758 | \r | |
1759 | //\r | |
1760 | // Write driver module protocol list entry\r | |
1761 | //\r | |
1762 | fileBuffer\r | |
1763 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");\r | |
1764 | \r | |
1765 | fileBuffer.append(Integer.toString(drvBindList.length));\r | |
1766 | fileBuffer.append(";\r\n");\r | |
1767 | \r | |
1768 | //\r | |
1769 | // Write drive module protocol list to autogen.c\r | |
1770 | //\r | |
1771 | fileBuffer\r | |
1772 | .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");\r | |
1773 | for (int i = 0; i < drvBindList.length; i++) {\r | |
1774 | if (i != 0) {\r | |
1775 | fileBuffer.append(",");\r | |
1776 | }\r | |
1777 | fileBuffer.append("\r\n {\r\n");\r | |
1778 | fileBuffer.append(" &");\r | |
1779 | fileBuffer.append(drvBindList[i]);\r | |
1780 | fileBuffer.append(", \r\n");\r | |
1781 | \r | |
1782 | if (compNamList != null) {\r | |
1783 | fileBuffer.append(" &");\r | |
1784 | fileBuffer.append(compNamList[i]);\r | |
1785 | fileBuffer.append(", \r\n");\r | |
1786 | } else {\r | |
1787 | fileBuffer.append(" NULL, \r\n");\r | |
1788 | }\r | |
1789 | \r | |
1790 | if (compConfList != null) {\r | |
1791 | fileBuffer.append(" &");\r | |
1792 | fileBuffer.append(compConfList[i]);\r | |
1793 | fileBuffer.append(", \r\n");\r | |
1794 | } else {\r | |
1795 | fileBuffer.append(" NULL, \r\n");\r | |
1796 | }\r | |
1797 | \r | |
1798 | if (compDiagList != null) {\r | |
1799 | fileBuffer.append(" &");\r | |
1800 | fileBuffer.append(compDiagList[i]);\r | |
1801 | fileBuffer.append(", \r\n");\r | |
1802 | } else {\r | |
1803 | fileBuffer.append(" NULL, \r\n");\r | |
1804 | }\r | |
1805 | fileBuffer.append(" }");\r | |
1806 | }\r | |
1807 | fileBuffer.append("\r\n};\r\n");\r | |
1808 | }\r | |
1809 | \r | |
1810 | /**\r | |
cb4d97bd | 1811 | ExternCallBackToAutoGenC\r |
1812 | \r | |
1813 | This function adds <SetVirtualAddressMapCallBack> and\r | |
1814 | <ExitBootServicesCallBack> infomation to AutoGen.c\r | |
1815 | \r | |
1816 | @param fileBuffer\r | |
1817 | String buffer for AutoGen.c\r | |
1818 | @throws BuildException\r | |
1819 | **/\r | |
5f907e4a | 1820 | void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r |
1821 | throws BuildException {\r | |
1822 | //\r | |
1823 | // Collect module's <SetVirtualAddressMapCallBack> and\r | |
1824 | // <ExitBootServiceCallBack> and add to setVirtualAddList\r | |
1825 | // exitBootServiceList.\r | |
1826 | //\r | |
83fba802 | 1827 | String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r |
1828 | String[] exitBoots = saq.getExitBootServicesCallBackArray();\r | |
a2733a33 | 1829 | if (setVirtuals != null) {\r |
1830 | for (int j = 0; j < setVirtuals.length; j++) {\r | |
5f907e4a | 1831 | this.setVirtalAddList.add(setVirtuals[j]);\r |
1832 | }\r | |
1833 | }\r | |
1834 | if (exitBoots != null) {\r | |
1835 | for (int k = 0; k < exitBoots.length; k++) {\r | |
1836 | this.exitBootServiceList.add(exitBoots[k]);\r | |
1837 | }\r | |
1838 | }\r | |
1839 | //\r | |
1840 | // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r | |
1841 | // and <ExitBootServicesCallBack>\r | |
1842 | //\r | |
1843 | String moduleType = this.moduleId.getModuleType();\r | |
5f907e4a | 1844 | switch (CommonDefinition.getModuleType(moduleType)) {\r |
1845 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1846 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1847 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1848 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
c60019f6 | 1849 | case CommonDefinition.ModuleTypeUefiApplication:\r |
1850 | //\r | |
1851 | // If moduleType is one of above, call setVirtualAddressToAutogenC,\r | |
1852 | // and setExitBootServiceToAutogenC.\r | |
1853 | // \r | |
1854 | setVirtualAddressToAutogenC(fileBuffer);\r | |
1855 | setExitBootServiceToAutogenC(fileBuffer);\r | |
5f907e4a | 1856 | break;\r |
1857 | default:\r | |
1858 | break;\r | |
1859 | }\r | |
5f907e4a | 1860 | }\r |
878ddf1f | 1861 | \r |
cb4d97bd | 1862 | /**\r |
1863 | copyFlashMapHToDebugDir\r | |
1864 | \r | |
1865 | This function is to copy the falshmap.h to debug directory and change \r | |
1866 | its name to TianoR8FlashMap.h\r | |
1867 | \r | |
1868 | @param \r | |
1869 | @return\r | |
1870 | **/\r | |
73b4e31a | 1871 | private void copyFlashMapHToDebugDir() throws AutoGenException{\r |
ff225cbb | 1872 | \r |
cb4d97bd | 1873 | File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH);\r |
73b4e31a | 1874 | int size = (int)inFile.length();\r |
1875 | byte[] buffer = new byte[size];\r | |
cb4d97bd | 1876 | File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH);\r |
5f907e4a | 1877 | //\r |
1878 | // If TianoR8FlashMap.h existed and the flashMap.h don't change,\r | |
1879 | // do nothing.\r | |
1880 | //\r | |
31a9215c | 1881 | if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r |
5f907e4a | 1882 | try {\r |
31a9215c | 1883 | if (inFile.exists()) {\r |
1884 | FileInputStream fis = new FileInputStream (inFile);\r | |
1885 | fis.read(buffer);\r | |
1886 | FileOutputStream fos = new FileOutputStream(outFile);\r | |
1887 | fos.write(buffer);\r | |
1888 | fis.close();\r | |
1889 | fos.close();\r | |
5f907e4a | 1890 | } else {\r |
391dbbb1 | 1891 | throw new AutoGenException("The file, flashMap.h doesn't exist!");\r |
31a9215c | 1892 | }\r |
5f907e4a | 1893 | } catch (Exception e) {\r |
31a9215c | 1894 | throw new AutoGenException(e.getMessage());\r |
73b4e31a | 1895 | }\r |
5f907e4a | 1896 | }\r |
73b4e31a | 1897 | }\r |
ff225cbb | 1898 | \r |
2336382f | 1899 | /**\r |
cb4d97bd | 1900 | This function first order the library instances, then collect\r |
1901 | library instance 's PPI, Protocol, GUID,\r | |
1902 | SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r | |
1903 | Destructor, Constructor.\r | |
1904 | \r | |
1905 | @param\r | |
1906 | @return \r | |
5f907e4a | 1907 | **/\r |
892b0e7a | 1908 | private void collectLibInstanceInfo() throws EdkException{\r |
5f907e4a | 1909 | int index;\r |
1910 | \r | |
5f907e4a | 1911 | String libConstructName = null;\r |
1912 | String libDestructName = null;\r | |
1913 | String[] setVirtuals = null;\r | |
1914 | String[] exitBoots = null;\r | |
1915 | \r | |
83fba802 | 1916 | ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r |
5f907e4a | 1917 | try {\r |
1918 | if (libraryIdList != null) {\r | |
1919 | //\r | |
1920 | // Reorder library instance sequence.\r | |
1921 | //\r | |
1922 | AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r | |
1923 | this.arch);\r | |
1924 | List<ModuleIdentification> orderList = libOrder\r | |
1925 | .orderLibInstance();\r | |
1926 | \r | |
1927 | if (orderList != null) {\r | |
1928 | //\r | |
1929 | // Process library instance one by one.\r | |
1930 | //\r | |
1931 | for (int i = 0; i < orderList.size(); i++) {\r | |
1932 | \r | |
1933 | //\r | |
1934 | // Get library instance basename.\r | |
1935 | //\r | |
1936 | ModuleIdentification libInstanceId = orderList.get(i);\r | |
1937 | \r | |
1938 | //\r | |
1939 | // Get override map\r | |
1940 | //\r | |
1941 | \r | |
bd481440 | 1942 | Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r |
83fba802 | 1943 | saq.push(libDoc);\r |
5f907e4a | 1944 | //\r |
1945 | // Get <PPis>, <Protocols>, <Guids> list of this library\r | |
1946 | // instance.\r | |
1947 | //\r | |
83fba802 | 1948 | String[] ppiList = saq.getPpiArray(this.arch);\r |
1949 | String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r | |
1950 | String[] protocolList = saq.getProtocolArray(this.arch);\r | |
1951 | String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r | |
1952 | String[] guidList = saq.getGuidEntryArray(this.arch);\r | |
1953 | PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r | |
5f907e4a | 1954 | \r |
1955 | //\r | |
1956 | // Add those ppi, protocol, guid in global ppi,\r | |
1957 | // protocol, guid\r | |
1958 | // list.\r | |
1959 | //\r | |
1960 | for (index = 0; index < ppiList.length; index++) {\r | |
1961 | this.mPpiList.add(ppiList[index]);\r | |
1962 | }\r | |
1963 | \r | |
1964 | for (index = 0; index < ppiNotifyList.length; index++) {\r | |
1965 | this.mPpiList.add(ppiNotifyList[index]);\r | |
1966 | }\r | |
1967 | \r | |
1968 | for (index = 0; index < protocolList.length; index++) {\r | |
1969 | this.mProtocolList.add(protocolList[index]);\r | |
1970 | }\r | |
1971 | \r | |
1972 | for (index = 0; index < protocolNotifyList.length; index++) {\r | |
1973 | this.mProtocolList.add(protocolNotifyList[index]);\r | |
1974 | }\r | |
1975 | \r | |
1976 | for (index = 0; index < guidList.length; index++) {\r | |
1977 | this.mGuidList.add(guidList[index]);\r | |
1978 | }\r | |
1979 | for (index = 0; index < pkgList.length; index++) {\r | |
1980 | if (!this.mDepPkgList.contains(pkgList[index])) {\r | |
1981 | this.mDepPkgList.add(pkgList[index]);\r | |
1982 | }\r | |
1983 | }\r | |
ca844f36 | 1984 | \r |
5f907e4a | 1985 | //\r |
1986 | // If not yet parse this library instance's constructor\r | |
1987 | // element,parse it.\r | |
1988 | //\r | |
83fba802 | 1989 | libConstructName = saq.getLibConstructorName();\r |
1990 | libDestructName = saq.getLibDestructorName();\r | |
5f907e4a | 1991 | \r |
1992 | //\r | |
1993 | // Collect SetVirtualAddressMapCallBack and\r | |
1994 | // ExitBootServiceCallBack.\r | |
1995 | //\r | |
83fba802 | 1996 | setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r |
1997 | exitBoots = saq.getExitBootServicesCallBackArray();\r | |
2336382f | 1998 | if (setVirtuals != null) {\r |
1999 | for (int j = 0; j < setVirtuals.length; j++) {\r | |
5f907e4a | 2000 | this.setVirtalAddList.add(setVirtuals[j]);\r |
2001 | }\r | |
2002 | }\r | |
2003 | if (exitBoots != null) {\r | |
2004 | for (int k = 0; k < exitBoots.length; k++) {\r | |
2005 | this.exitBootServiceList.add(exitBoots[k]);\r | |
2006 | }\r | |
2007 | }\r | |
83fba802 | 2008 | saq.pop();\r |
5f907e4a | 2009 | //\r |
2010 | // Add dependent library instance constructor function.\r | |
2011 | //\r | |
2012 | if (libConstructName != null) {\r | |
2013 | this.libConstructList.add(libConstructName);\r | |
2014 | }\r | |
2015 | //\r | |
2016 | // Add dependent library instance destructor fuction.\r | |
2017 | //\r | |
2018 | if (libDestructName != null) {\r | |
2019 | this.libDestructList.add(libDestructName);\r | |
2020 | }\r | |
2021 | }\r | |
2022 | }\r | |
2023 | \r | |
2024 | }\r | |
2025 | \r | |
2026 | } catch (Exception e) {\r | |
2027 | System.out.println(e.getMessage());\r | |
2028 | System.out.println("Collect library instance failed!");\r | |
2029 | }\r | |
2030 | }\r | |
c60019f6 | 2031 | private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r |
2032 | //\r | |
2033 | // Entry point lib for these module types needs to know the count\r | |
2034 | // of entryPoint.\r | |
2035 | //\r | |
2036 | fileBuffer\r | |
2037 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r | |
2038 | \r | |
2039 | //\r | |
2040 | // If the list is not valid or has no entries set count to zero else\r | |
2041 | // set count to the number of valid entries\r | |
2042 | //\r | |
2043 | int Count = 0;\r | |
2044 | int i = 0;\r | |
2045 | if (this.setVirtalAddList != null) {\r | |
2046 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r | |
2047 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2048 | break;\r | |
2049 | }\r | |
2050 | }\r | |
2051 | Count = i;\r | |
2052 | }\r | |
2053 | \r | |
2054 | fileBuffer.append(Integer.toString(Count));\r | |
2055 | fileBuffer.append(";\r\n\r\n");\r | |
2056 | if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r | |
2057 | //\r | |
2058 | // No data so make a NULL list\r | |
2059 | //\r | |
2060 | fileBuffer\r | |
2061 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r | |
2062 | fileBuffer.append(" NULL\r\n");\r | |
2063 | fileBuffer.append("};\r\n\r\n");\r | |
2064 | } else {\r | |
2065 | //\r | |
2066 | // Write SetVirtualAddressMap function definition.\r | |
2067 | //\r | |
2068 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r | |
2069 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2070 | break;\r | |
2071 | }\r | |
2072 | fileBuffer.append("VOID\r\n");\r | |
2073 | fileBuffer.append("EFIAPI\r\n");\r | |
2074 | fileBuffer.append(this.setVirtalAddList.get(i));\r | |
2075 | fileBuffer.append(" (\r\n");\r | |
2076 | fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r | |
2077 | fileBuffer.append(" IN VOID *Context\r\n");\r | |
2078 | fileBuffer.append(" );\r\n\r\n");\r | |
2079 | }\r | |
2080 | \r | |
2081 | //\r | |
2082 | // Write SetVirtualAddressMap entry point array.\r | |
2083 | //\r | |
2084 | fileBuffer\r | |
2085 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r | |
2086 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r | |
2087 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2088 | break;\r | |
2089 | }\r | |
2090 | \r | |
2091 | if (i == 0) {\r | |
2092 | fileBuffer.append("\r\n ");\r | |
2093 | } else {\r | |
2094 | fileBuffer.append(",\r\n ");\r | |
2095 | }\r | |
2096 | \r | |
2097 | fileBuffer.append(this.setVirtalAddList.get(i));\r | |
2098 | }\r | |
2099 | //\r | |
2100 | // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.\r | |
2101 | //\r | |
2102 | fileBuffer.append(",\r\n NULL");\r | |
2103 | fileBuffer.append("\r\n};\r\n\r\n");\r | |
2104 | }\r | |
2105 | }\r | |
2106 | \r | |
2107 | \r | |
2108 | private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){\r | |
2109 | //\r | |
2110 | // Entry point lib for these module types needs to know the count.\r | |
2111 | //\r | |
2112 | fileBuffer\r | |
2113 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");\r | |
2114 | \r | |
2115 | //\r | |
2116 | // If the list is not valid or has no entries set count to zero else\r | |
2117 | // set count to the number of valid entries.\r | |
2118 | //\r | |
2119 | int Count = 0;\r | |
2120 | int i = 0; \r | |
2121 | if (this.exitBootServiceList != null) {\r | |
2122 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r | |
2123 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2124 | break;\r | |
2125 | }\r | |
2126 | }\r | |
2127 | Count = i;\r | |
2128 | }\r | |
2129 | fileBuffer.append(Integer.toString(Count));\r | |
2130 | fileBuffer.append(";\r\n\r\n");\r | |
2131 | \r | |
2132 | if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r | |
2133 | // \r | |
2134 | // No data so make a NULL list.\r | |
2135 | //\r | |
2136 | fileBuffer\r | |
2137 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r | |
2138 | fileBuffer.append(" NULL\r\n");\r | |
2139 | fileBuffer.append("};\r\n\r\n");\r | |
2140 | } else {\r | |
2141 | //\r | |
2142 | // Write DriverExitBootServices function definition.\r | |
2143 | //\r | |
2144 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r | |
2145 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2146 | break;\r | |
2147 | }\r | |
2148 | \r | |
2149 | fileBuffer.append("VOID\r\n");\r | |
2150 | fileBuffer.append("EFIAPI\r\n");\r | |
2151 | fileBuffer.append(this.exitBootServiceList.get(i));\r | |
2152 | fileBuffer.append(" (\r\n");\r | |
2153 | fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r | |
2154 | fileBuffer.append(" IN VOID *Context\r\n");\r | |
2155 | fileBuffer.append(" );\r\n\r\n");\r | |
2156 | }\r | |
2157 | \r | |
2158 | //\r | |
2159 | // Write DriverExitBootServices entry point array.\r | |
2160 | //\r | |
2161 | fileBuffer\r | |
2162 | .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r | |
2163 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r | |
2164 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2165 | break;\r | |
2166 | }\r | |
2167 | \r | |
2168 | if (i == 0) {\r | |
2169 | fileBuffer.append("\r\n ");\r | |
2170 | } else {\r | |
2171 | fileBuffer.append(",\r\n ");\r | |
2172 | }\r | |
2173 | fileBuffer.append(this.exitBootServiceList.get(i));\r | |
2174 | }\r | |
2175 | \r | |
2176 | fileBuffer.append(",\r\n NULL");\r | |
2177 | fileBuffer.append("\r\n};\r\n\r\n");\r | |
2178 | }\r | |
2179 | \r | |
2180 | }\r | |
2181 | \r | |
2336382f | 2182 | }\r |