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