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