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