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