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