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