4 This class is to generate Autogen.h and Autogen.c according to module surface area
5 or library surface area.
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
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.
18 package org
.tianocore
.build
.autogen
;
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
;
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
;
49 This class is to generate Autogen.h and Autogen.c according to module surface
50 area or library surface area.
52 public class AutoGen
{
54 /// The output path of Autogen.h and Autogen.c
56 private String outputPath
;
59 /// The name of FV directory
64 /// The base name of module or library.
66 private ModuleIdentification moduleId
;
69 /// The build architecture
74 /// PcdAutogen instance which is used to manage how to generate the PCD
77 private PCDAutoGenAction myPcdAutogen
;
80 /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER
82 private CommonDefinition
.PCD_DRIVER_TYPE pcdDriverType
;
85 /// The Guid CName list which recoreded in module or library surface area
86 /// and it's dependence on library instance surface area.
88 private Set
<String
> mGuidCNameList
= new HashSet
<String
>();
91 /// The dependence package list which recoreded in module or library surface
92 /// area and it's dependence on library instance surface area.
94 private List
<PackageIdentification
> mDepPkgList
= new LinkedList
<PackageIdentification
>();
97 /// For non library module, add its library instance's construct and destructor to
98 /// list. String[0] recode LibConstructor name, String[1] recode Lib instance
101 private List
<String
[]> libConstructList
= new ArrayList
<String
[]>();
102 private List
<String
[]> libDestructList
= new ArrayList
<String
[]>();
105 /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack
107 private List
<String
> setVirtalAddList
= new ArrayList
<String
>();
108 private List
<String
> exitBootServiceList
= new ArrayList
<String
>();
110 private StringBuffer functionDeclarations
= new StringBuffer(10240);
111 private StringBuffer globalDeclarations
= new StringBuffer(10240);
114 // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable
116 private boolean componentNamePcd
= false;
117 private boolean driverDiagnostPcd
= false;
120 // Instance of SurfaceAreaQuery
122 private SurfaceAreaQuery saq
= null;
124 private ModuleIdentification parentId
= null;
129 This function mainly initialize some member variable.
132 Absolute path of FV directory.
134 Output path of AutoGen file.
136 Module identification.
140 public AutoGen(String fvDir
, String outputPath
, ModuleIdentification moduleId
, String arch
, SurfaceAreaQuery saq
, ModuleIdentification parentId
) {
141 this.outputPath
= outputPath
;
142 this.moduleId
= moduleId
;
146 this.parentId
= parentId
;
152 This function save the content in stringBuffer to file.
157 The content of AutoGen file in buffer.
162 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
164 File autoGenH
= new File(fileName
);
167 // if the file exists, compare their content
169 if (autoGenH
.exists()) {
170 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
172 FileReader fIn
= new FileReader(autoGenH
);
173 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
175 } catch (IOException e
) {
176 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
179 + " is exist, but can't be open!!");
184 // if we got the same file, don't re-generate it to prevent
185 // sources depending on it from re-building
187 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
193 FileWriter fOut
= new FileWriter(autoGenH
);
194 fOut
.write(fileBuffer
.toString());
197 } catch (IOException e
) {
198 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
201 + " can't be create!!");
210 This function call libGenAutoGen or moduleGenAutogen function, which
211 dependence on generate library autogen or module autogen.
213 @throws BuildException
214 Failed to creat AutoGen.c & AutoGen.h.
216 public void genAutogen() throws EdkException
{
218 // If outputPath do not exist, create it.
220 File path
= new File(outputPath
);
224 // Check current is library or not, then call the corresponding
227 if (this.moduleId
.isLibrary()) {
235 moduleGenAutogen function
237 This function generates AutoGen.c & AutoGen.h for module.
239 @throws BuildException
240 Faile to create module AutoGen.c & AutoGen.h.
242 void moduleGenAutogen() throws EdkException
{
243 setPcdComponentName();
244 setPcdDriverDiagnostic();
245 collectLibInstanceInfo();
251 libGenAutogen function
253 This function generates AutoGen.c & AutoGen.h for library.
255 @throws BuildException
256 Faile to create library AutoGen.c & AutoGen.h
258 void libGenAutogen() throws EdkException
{
266 This function generates AutoGen.h for module.
268 @throws BuildException
269 Failed to generate AutoGen.h.
271 void moduleGenAutogenH() throws EdkException
{
273 Set
<String
> libClassIncludeH
;
275 // List<String> headerFileList;
276 List
<String
> headerFileList
;
278 StringBuffer fileBuffer
= new StringBuffer(8192);
281 // Write Autogen.h header notation
283 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
286 // Add #ifndef ${BaseName}_AUTOGENH
287 // #def ${BseeName}_AUTOGENH
289 fileBuffer
.append(CommonDefinition
.IFNDEF
290 + CommonDefinition
.AUTOGENH
291 + this.moduleId
.getGuid().replaceAll("-", "_")
292 + ToolDefinitions
.LINE_SEPARATOR
);
293 fileBuffer
.append(CommonDefinition
.DEFINE
294 + CommonDefinition
.AUTOGENH
295 + this.moduleId
.getGuid().replaceAll("-", "_")
296 + ToolDefinitions
.LINE_SEPARATOR
297 + ToolDefinitions
.LINE_SEPARATOR
);
300 // Write the specification version and release version at the begine
301 // of autogen.h file.
302 // Note: the specification version and release version should
303 // be got from module surface area instead of hard code by it's
306 moduleType
= saq
.getModuleType();
309 // Add "extern int __make_me_compile_correctly;" at begin of
312 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
315 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
317 String
[] specList
= saq
.getExternSpecificaiton();
318 for (int i
= 0; i
< specList
.length
; i
++) {
319 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
]
323 // Write consumed package's mdouleInfo related .h file to autogen.h
325 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
326 // .getDependencePkg(this.arch);
327 PackageIdentification
[] consumedPkgIdList
= saq
.getDependencePkg(this.arch
);
328 if (consumedPkgIdList
!= null) {
329 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
330 item
= headerFileList
.iterator();
331 while (item
.hasNext()) {
332 fileBuffer
.append(item
.next().toString());
337 // Write library class's related *.h file to autogen.h.
339 List
<String
> libClasses
= new ArrayList
<String
>(100);
340 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
, null);
341 for (int i
= 0; i
< libClassList
.length
; ++i
) {
342 libClasses
.add(libClassList
[i
]);
345 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
, null);
346 for (int i
= 0; i
< libClassList
.length
; ++i
) {
347 libClasses
.add(libClassList
[i
]);
350 // Add AutoGen used library class
352 int moduleTypeId
= CommonDefinition
.getModuleType(moduleType
);
353 if (!libClasses
.contains("DebugLib") && moduleTypeId
!= CommonDefinition
.ModuleTypeUnknown
354 && moduleTypeId
!= CommonDefinition
.ModuleTypeBase
) {
355 libClasses
.add("DebugLib");
357 switch (moduleTypeId
) {
358 case CommonDefinition
.ModuleTypeDxeDriver
:
359 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
360 case CommonDefinition
.ModuleTypeDxeSalDriver
:
361 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
362 case CommonDefinition
.ModuleTypeUefiDriver
:
363 case CommonDefinition
.ModuleTypeUefiApplication
:
364 if (!libClasses
.contains("UefiBootServicesTableLib")) {
365 libClasses
.add("UefiBootServicesTableLib");
369 LibraryClassToAutogenH(fileBuffer
, libClasses
.toArray(new String
[libClasses
.size()]));
370 fileBuffer
.append("\r\n");
373 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
374 // {DEST_DIR_DRBUG}/FlashMap.h
376 if (saq
.isHaveTianoR8FlashMap()) {
377 fileBuffer
.append(CommonDefinition
.INCLUDE
);
378 fileBuffer
.append(" <");
379 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
380 copyFlashMapHToDebugDir();
383 // Write PCD autogen information to AutoGen.h.
385 if (this.myPcdAutogen
!= null) {
386 fileBuffer
.append("\r\n");
387 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
390 fileBuffer
.append(globalDeclarations
);
391 fileBuffer
.append(functionDeclarations
);
393 // Append the #endif at AutoGen.h
395 fileBuffer
.append("#endif\r\n");
398 // Save string buffer content in AutoGen.h.
400 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
401 throw new AutoGenException("Failed to generate AutoGen.h !!!");
408 This function generates AutoGen.c for module.
410 @throws BuildException
411 Failed to generate AutoGen.c.
413 void moduleGenAutogenC() throws EdkException
{
415 StringBuffer fileBuffer
= new StringBuffer(8192);
417 // Write Autogen.c header notation
419 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
422 // Get the native MSA file infomation. Since before call autogen,
423 // the MSA native <Externs> information were overrided. So before
424 // process <Externs> it should be set the DOC as the Native MSA info.
426 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
430 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
434 ExternsDriverBindingToAutoGenC(fileBuffer
);
437 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
440 ExternCallBackToAutoGenC(fileBuffer
);
443 // Write EntryPoint to autgoGen.c
445 String
[] entryPointList
= saq
.getModuleEntryPointArray();
446 String
[] unloadImageList
= saq
.getModuleUnloadImageArray();
447 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
),
448 CommonDefinition
.remDupString(unloadImageList
),
451 pcdDriverType
= saq
.getPcdDriverType();
454 // Restore the DOC which include the FPD module info.
459 // Write Guid to autogen.c
461 String guid
= CommonDefinition
.formatGuidName(saq
.getModuleGuid());
462 if (this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
463 globalDeclarations
.append("extern GUID gEfiCallerIdGuid;\r\n");
464 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");
465 } else if (!this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_USER_DEFINED
)) {
466 globalDeclarations
.append("extern EFI_GUID gEfiCallerIdGuid;\r\n");
467 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
471 throw new AutoGenException("Guid value must set!\n");
475 // Formate Guid as ANSI c form.Example:
476 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
480 fileBuffer
.append(guid
);
481 fileBuffer
.append("};\r\n");
484 // Generate library instance consumed protocol, guid, ppi, pcd list.
485 // Save those to this.protocolList, this.ppiList, this.pcdList,
486 // this.guidList. Write Consumed library constructor and desconstuct to
489 LibInstanceToAutogenC(fileBuffer
);
492 // Get module dependent Package identification.
494 PackageIdentification
[] packages
= saq
.getDependencePkg(this.arch
);
495 for (int i
= 0; i
< packages
.length
; i
++) {
496 if (!this.mDepPkgList
.contains(packages
[i
])) {
497 this.mDepPkgList
.add(packages
[i
]);
503 // Write consumed ppi, guid, protocol, etc to autogen.c
505 CNameToAutogenC(fileBuffer
);
510 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
517 this.myPcdAutogen
.execute();
518 if (this.myPcdAutogen
!= null) {
519 fileBuffer
.append("\r\n");
520 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
523 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
524 throw new AutoGenException("Failed to generate AutoGen.c !!!");
532 This function generates AutoGen.h for library.
534 @throws BuildException
535 Failed to generate AutoGen.c.
537 void libGenAutogenH() throws EdkException
{
539 Set
<String
> libClassIncludeH
;
541 List
<String
> headerFileList
;
543 StringBuffer fileBuffer
= new StringBuffer(10240);
546 // Write Autogen.h header notation
548 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
551 // Add #ifndef ${BaseName}_AUTOGENH
552 // #def ${BseeName}_AUTOGENH
554 fileBuffer
.append(CommonDefinition
.IFNDEF
555 + CommonDefinition
.AUTOGENH
556 + this.moduleId
.getGuid().replaceAll("-", "_")
557 + ToolDefinitions
.LINE_SEPARATOR
);
558 fileBuffer
.append(CommonDefinition
.DEFINE
559 + CommonDefinition
.AUTOGENH
560 + this.moduleId
.getGuid().replaceAll("-", "_")
561 + ToolDefinitions
.LINE_SEPARATOR
562 + ToolDefinitions
.LINE_SEPARATOR
);
565 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
566 // to autogen.h file.
567 // Note: the specification version and release version should
568 // be get from module surface area instead of hard code.
570 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
571 String
[] specList
= saq
.getExternSpecificaiton();
572 for (int i
= 0; i
< specList
.length
; i
++) {
573 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
] + "\r\n");
575 // fileBuffer.append(CommonDefinition.autoGenHLine1);
576 // fileBuffer.append(CommonDefinition.autoGenHLine2);
579 // Write consumed package's mdouleInfo related *.h file to autogen.h.
581 moduleType
= saq
.getModuleType();
582 PackageIdentification
[] cosumedPkglist
= saq
.getDependencePkg(this.arch
);
583 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
584 item
= headerFileList
.iterator();
585 while (item
.hasNext()) {
586 fileBuffer
.append(item
.next().toString());
589 // Write library class's related *.h file to autogen.h
591 List
<String
> libClasses
= new ArrayList
<String
>(100);
592 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
, null);
593 for (int i
= 0; i
< libClassList
.length
; ++i
) {
594 libClasses
.add(libClassList
[i
]);
597 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
, null);
598 for (int i
= 0; i
< libClassList
.length
; ++i
) {
599 libClasses
.add(libClassList
[i
]);
602 // Add AutoGen used library class
604 int moduleTypeId
= CommonDefinition
.getModuleType(moduleType
);
605 if (!libClasses
.contains("DebugLib") && moduleTypeId
!= CommonDefinition
.ModuleTypeUnknown
606 && moduleTypeId
!= CommonDefinition
.ModuleTypeBase
) {
607 libClasses
.add("DebugLib");
609 switch (moduleTypeId
) {
610 case CommonDefinition
.ModuleTypeDxeDriver
:
611 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
612 case CommonDefinition
.ModuleTypeDxeSalDriver
:
613 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
614 case CommonDefinition
.ModuleTypeUefiDriver
:
615 case CommonDefinition
.ModuleTypeUefiApplication
:
616 if (!libClasses
.contains("UefiBootServicesTableLib")) {
617 libClasses
.add("UefiBootServicesTableLib");
621 LibraryClassToAutogenH(fileBuffer
, libClasses
.toArray(new String
[libClasses
.size()]));
622 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
625 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
626 // {DEST_DIR_DRBUG}/FlashMap.h
628 if (saq
.isHaveTianoR8FlashMap()) {
629 fileBuffer
.append(CommonDefinition
.INCLUDE
);
630 fileBuffer
.append(" <");
631 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
632 copyFlashMapHToDebugDir();
636 // Write PCD information to library AutoGen.h.
638 if (this.myPcdAutogen
!= null) {
639 fileBuffer
.append("\r\n");
640 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
643 // generate function prototype for constructor and destructor
645 LibConstructorToAutogenH(moduleType
);
646 LibDestructorToAutogenH(moduleType
);
647 ExternCallBackToAutoGenH(moduleType
);
648 fileBuffer
.append(functionDeclarations
);
650 // Append the #endif at AutoGen.h
652 fileBuffer
.append("#endif\r\n");
654 // Save content of string buffer to AutoGen.h file.
656 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
657 throw new AutoGenException("Failed to generate AutoGen.h !!!");
664 This function generates AutoGen.h for library.
666 @throws BuildException
667 Failed to generate AutoGen.c.
669 void libGenAutogenC() throws EdkException
{
670 StringBuffer fileBuffer
= new StringBuffer(10240);
673 // Write Autogen.c header notation
675 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
677 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
678 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
683 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
686 saq
.getModulePcdEntryNameArray(this.arch
),
689 this.myPcdAutogen
.execute();
690 if (this.myPcdAutogen
!= null) {
691 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
692 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
697 LibraryClassToAutogenH
699 This function returns *.h files declared by library classes which are
700 consumed or produced by current build module or library.
703 List of library class which consumed or produce by current
704 build module or library.
705 @return includeStrList List of *.h file.
707 void LibraryClassToAutogenH(StringBuffer fileBuffer
, String
[] libClassList
)
708 throws EdkException
{
709 String includeName
[];
713 // Get include file from GlobalData's SPDTable according to
714 // library class name.
716 for (int i
= 0; i
< libClassList
.length
; i
++) {
717 includeName
= GlobalData
.getLibraryClassHeaderFiles(
718 saq
.getDependencePkg(this.arch
),
720 if (includeName
== null) {
721 throw new AutoGenException("Can not find library class ["
722 + libClassList
[i
] + "] declaration in any SPD package. ");
724 for (int j
= 0; j
< includeName
.length
; j
++) {
725 String includeNameStr
= includeName
[j
];
726 if (includeNameStr
!= null) {
727 fileBuffer
.append(CommonDefinition
.INCLUDE
);
728 fileBuffer
.append(" <");
729 fileBuffer
.append(includeNameStr
);
730 fileBuffer
.append(">\r\n");
731 includeNameStr
= null;
740 This function add include file in AutoGen.h file.
742 @param packageNameList
743 List of module depended package.
748 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
749 String moduleType
) throws AutoGenException
{
751 List
<String
> includeStrList
= new LinkedList
<String
>();
753 String includeStr
= "";
756 // Get include file from moduleInfo file
758 for (int i
= 0; i
< packageNameList
.length
; i
++) {
759 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
761 if (pkgHeader
== null) {
762 throw new AutoGenException("Can not find package ["
764 + "] declaration in any SPD package. ");
765 } else if (!pkgHeader
.equalsIgnoreCase("")) {
766 includeStr
= CommonDefinition
.INCLUDE
+ " <" + pkgHeader
+ ">\r\n";
767 includeStrList
.add(includeStr
);
771 return includeStrList
;
777 This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
778 information in mas to AutoGen.c
780 @param entryPointList
783 String buffer fo AutoGen.c.
786 void EntryPointToAutoGen(String
[] entryPointList
, String
[] unloadImageList
, StringBuffer fileBuffer
)
787 throws EdkException
{
789 String typeStr
= saq
.getModuleType();
790 String debugStr
= "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";
791 int unloadImageCount
= 0;
792 int entryPointCount
= 0;
795 // The parameters and return value of entryPoint is difference
796 // for difference module type.
798 switch (CommonDefinition
.getModuleType(typeStr
)) {
800 case CommonDefinition
.ModuleTypePeiCore
:
801 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
802 throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");
804 functionDeclarations
.append("EFI_STATUS\r\n");
805 functionDeclarations
.append("EFIAPI\r\n");
806 functionDeclarations
.append(entryPointList
[0]);
807 functionDeclarations
.append(" (\r\n");
808 functionDeclarations
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
809 functionDeclarations
.append(" IN VOID *OldCoreData\r\n");
810 functionDeclarations
.append(" );\r\n\r\n");
812 fileBuffer
.append("EFI_STATUS\r\n");
813 fileBuffer
.append("EFIAPI\r\n");
814 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
815 fileBuffer
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
816 fileBuffer
.append(" IN VOID *OldCoreData\r\n");
817 fileBuffer
.append(" )\r\n\r\n");
818 fileBuffer
.append("{\r\n");
819 fileBuffer
.append(" return ");
820 fileBuffer
.append(entryPointList
[0]);
821 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
822 fileBuffer
.append("}\r\n\r\n");
826 case CommonDefinition
.ModuleTypeDxeCore
:
827 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
828 if (entryPointList
== null || entryPointList
.length
!= 1) {
829 throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");
831 functionDeclarations
.append("VOID\r\n");
832 functionDeclarations
.append("EFIAPI\r\n");
833 functionDeclarations
.append(entryPointList
[0]);
834 functionDeclarations
.append(" (\r\n");
835 functionDeclarations
.append(" IN VOID *HobStart\r\n");
836 functionDeclarations
.append(" );\r\n\r\n");
838 fileBuffer
.append("VOID\r\n");
839 fileBuffer
.append("EFIAPI\r\n");
840 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
841 fileBuffer
.append(" IN VOID *HobStart\r\n");
842 fileBuffer
.append(" )\r\n\r\n");
843 fileBuffer
.append("{\r\n");
844 fileBuffer
.append(" ");
845 fileBuffer
.append(entryPointList
[0]);
846 fileBuffer
.append(" (HobStart);\r\n");
847 fileBuffer
.append("}\r\n\r\n");
851 case CommonDefinition
.ModuleTypePeim
:
853 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
854 if (entryPointList
== null || entryPointList
.length
== 0) {
855 fileBuffer
.append("EFI_STATUS\r\n");
856 fileBuffer
.append("EFIAPI\r\n");
857 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
858 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
859 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
860 fileBuffer
.append(" )\r\n\r\n");
861 fileBuffer
.append("{\r\n");
862 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
863 fileBuffer
.append("}\r\n\r\n");
866 for (int i
= 0; i
< entryPointList
.length
; i
++) {
867 functionDeclarations
.append("EFI_STATUS\r\n");
868 functionDeclarations
.append("EFIAPI\r\n");
869 functionDeclarations
.append(entryPointList
[i
]);
870 functionDeclarations
.append(" (\r\n");
871 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
872 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
873 functionDeclarations
.append(" );\r\n");
877 fileBuffer
.append("EFI_STATUS\r\n");
878 fileBuffer
.append("EFIAPI\r\n");
879 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
880 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
881 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
882 fileBuffer
.append(" )\r\n\r\n");
883 fileBuffer
.append("{\r\n");
884 if (entryPointCount
== 1) {
885 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
886 fileBuffer
.append(" return ");
887 fileBuffer
.append(entryPointList
[0]);
888 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
890 fileBuffer
.append(" EFI_STATUS Status;\r\n");
891 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
892 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
893 for (int i
= 0; i
< entryPointList
.length
; i
++) {
894 if (!entryPointList
[i
].equals("")) {
895 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
896 fileBuffer
.append(" Status = ");
897 fileBuffer
.append(entryPointList
[i
]);
898 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
899 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
900 fileBuffer
.append(" CombinedStatus = Status;\r\n");
901 fileBuffer
.append(" }\r\n\r\n");
906 fileBuffer
.append(" return CombinedStatus;\r\n");
908 fileBuffer
.append("}\r\n\r\n");
911 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
914 // If entryPoint is null, create an empty ProcessModuleEntryPointList
917 if (entryPointList
== null || entryPointList
.length
== 0) {
918 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
919 fileBuffer
.append(Integer
.toString(entryPointCount
));
920 fileBuffer
.append(";\r\n");
921 fileBuffer
.append("EFI_STATUS\r\n");
922 fileBuffer
.append("EFIAPI\r\n");
923 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
924 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
925 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
926 fileBuffer
.append(" )\r\n\r\n");
927 fileBuffer
.append("{\r\n");
928 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
929 fileBuffer
.append("}\r\n\r\n");
932 for (int i
= 0; i
< entryPointList
.length
; i
++) {
933 functionDeclarations
.append("EFI_STATUS\r\n");
934 functionDeclarations
.append("EFIAPI\r\n");
935 functionDeclarations
.append(entryPointList
[i
]);
936 functionDeclarations
.append(" (\r\n");
937 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
938 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
939 functionDeclarations
.append(" );\r\n");
942 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
943 fileBuffer
.append(Integer
.toString(entryPointCount
));
944 fileBuffer
.append(";\r\n");
945 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
946 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
948 fileBuffer
.append("EFI_STATUS\r\n");
949 fileBuffer
.append("EFIAPI\r\n");
950 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
951 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
952 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
953 fileBuffer
.append(" )\r\n\r\n");
954 fileBuffer
.append("{\r\n");
956 for (int i
= 0; i
< entryPointList
.length
; i
++) {
957 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
958 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
959 fileBuffer
.append(" ExitDriver (");
960 fileBuffer
.append(entryPointList
[i
]);
961 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
962 fileBuffer
.append(" ASSERT (FALSE);\r\n");
963 fileBuffer
.append(" }\r\n");
965 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
966 fileBuffer
.append("}\r\n\r\n");
968 fileBuffer
.append("VOID\r\n");
969 fileBuffer
.append("EFIAPI\r\n");
970 fileBuffer
.append("ExitDriver (\r\n");
971 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
972 fileBuffer
.append(" )\r\n\r\n");
973 fileBuffer
.append("{\r\n");
974 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
975 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
976 fileBuffer
.append(" }\r\n");
977 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
978 fileBuffer
.append(" ASSERT (FALSE);\r\n");
979 fileBuffer
.append("}\r\n\r\n");
984 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
987 unloadImageCount
= 0;
988 if (unloadImageList
!= null) {
989 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
990 functionDeclarations
.append("EFI_STATUS\r\n");
991 functionDeclarations
.append(unloadImageList
[i
]);
992 functionDeclarations
.append(" (\r\n");
993 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
994 functionDeclarations
.append(" );\r\n");
999 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1000 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1001 fileBuffer
.append(";\r\n\r\n");
1003 fileBuffer
.append("EFI_STATUS\r\n");
1004 fileBuffer
.append("EFIAPI\r\n");
1005 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1006 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1007 fileBuffer
.append(" )\r\n");
1008 fileBuffer
.append("{\r\n");
1010 if (unloadImageCount
== 0) {
1011 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1012 } else if (unloadImageCount
== 1) {
1013 fileBuffer
.append(" return ");
1014 fileBuffer
.append(unloadImageList
[0]);
1015 fileBuffer
.append("(ImageHandle);\r\n");
1017 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1018 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1019 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1021 fileBuffer
.append(" Status = ");
1022 fileBuffer
.append(unloadImageList
[i
]);
1023 fileBuffer
.append("(ImageHandle);\r\n");
1025 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1026 fileBuffer
.append(" ");
1027 fileBuffer
.append(unloadImageList
[i
]);
1028 fileBuffer
.append("(ImageHandle);\r\n");
1029 fileBuffer
.append(" } else {\r\n");
1030 fileBuffer
.append(" Status = ");
1031 fileBuffer
.append(unloadImageList
[i
]);
1032 fileBuffer
.append("(ImageHandle);\r\n");
1033 fileBuffer
.append(" }\r\n");
1036 fileBuffer
.append(" return Status;\r\n");
1038 fileBuffer
.append("}\r\n\r\n");
1041 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1042 case CommonDefinition
.ModuleTypeDxeDriver
:
1043 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1044 case CommonDefinition
.ModuleTypeUefiDriver
:
1045 case CommonDefinition
.ModuleTypeUefiApplication
:
1046 entryPointCount
= 0;
1047 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1049 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1051 if (entryPointList
== null || entryPointList
.length
== 0) {
1052 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1053 fileBuffer
.append("EFI_STATUS\r\n");
1054 fileBuffer
.append("EFIAPI\r\n");
1055 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1056 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1057 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1058 fileBuffer
.append(" )\r\n\r\n");
1059 fileBuffer
.append("{\r\n");
1060 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1061 fileBuffer
.append("}\r\n");
1064 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1065 functionDeclarations
.append("EFI_STATUS\r\n");
1066 functionDeclarations
.append("EFIAPI\r\n");
1067 functionDeclarations
.append(entryPointList
[i
]);
1068 functionDeclarations
.append(" (\r\n");
1069 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1070 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1071 functionDeclarations
.append(" );\r\n");
1075 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1076 fileBuffer
.append(Integer
.toString(entryPointCount
));
1077 fileBuffer
.append(";\r\n");
1078 if (entryPointCount
> 1) {
1079 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1080 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1082 fileBuffer
.append("\r\n");
1084 fileBuffer
.append("EFI_STATUS\r\n");
1085 fileBuffer
.append("EFIAPI\r\n");
1086 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1087 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1088 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1089 fileBuffer
.append(" )\r\n\r\n");
1090 fileBuffer
.append("{\r\n");
1092 if (entryPointCount
== 1) {
1093 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
1094 fileBuffer
.append(" return ");
1095 fileBuffer
.append(entryPointList
[0]);
1096 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1098 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1099 if (!entryPointList
[i
].equals("")) {
1100 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1101 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
1102 fileBuffer
.append(" ExitDriver (");
1103 fileBuffer
.append(entryPointList
[i
]);
1104 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1105 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1106 fileBuffer
.append(" }\r\n");
1111 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1113 fileBuffer
.append("}\r\n\r\n");
1115 fileBuffer
.append("VOID\r\n");
1116 fileBuffer
.append("EFIAPI\r\n");
1117 fileBuffer
.append("ExitDriver (\r\n");
1118 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1119 fileBuffer
.append(" )\r\n\r\n");
1120 fileBuffer
.append("{\r\n");
1121 if (entryPointCount
<= 1) {
1122 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1123 fileBuffer
.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1124 fileBuffer
.append(" }\r\n");
1125 fileBuffer
.append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1127 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1128 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1129 fileBuffer
.append(" }\r\n");
1130 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1131 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1133 fileBuffer
.append("}\r\n\r\n");
1137 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1139 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1141 // Remover duplicate unload entry point.
1143 //entryPointList = CommonDefinition.remDupString(entryPointList);
1144 //entryPointCount = 0;
1145 unloadImageCount
= 0;
1146 if (unloadImageList
!= null) {
1147 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1148 functionDeclarations
.append("EFI_STATUS\r\n");
1149 functionDeclarations
.append("EFIAPI\r\n");
1150 functionDeclarations
.append(unloadImageList
[i
]);
1151 functionDeclarations
.append(" (\r\n");
1152 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
1153 functionDeclarations
.append(" );\r\n");
1158 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1159 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1160 fileBuffer
.append(";\r\n\r\n");
1162 fileBuffer
.append("EFI_STATUS\r\n");
1163 fileBuffer
.append("EFIAPI\r\n");
1164 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1165 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1166 fileBuffer
.append(" )\r\n");
1167 fileBuffer
.append("{\r\n");
1169 if (unloadImageCount
== 0) {
1170 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1171 } else if (unloadImageCount
== 1) {
1172 fileBuffer
.append(" return ");
1173 fileBuffer
.append(unloadImageList
[0]);
1174 fileBuffer
.append("(ImageHandle);\r\n");
1176 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1177 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1178 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1180 fileBuffer
.append(" Status = ");
1181 fileBuffer
.append(unloadImageList
[i
]);
1182 fileBuffer
.append("(ImageHandle);\r\n");
1184 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1185 fileBuffer
.append(" ");
1186 fileBuffer
.append(unloadImageList
[i
]);
1187 fileBuffer
.append("(ImageHandle);\r\n");
1188 fileBuffer
.append(" } else {\r\n");
1189 fileBuffer
.append(" Status = ");
1190 fileBuffer
.append(unloadImageList
[i
]);
1191 fileBuffer
.append("(ImageHandle);\r\n");
1192 fileBuffer
.append(" }\r\n");
1195 fileBuffer
.append(" return Status;\r\n");
1197 fileBuffer
.append("}\r\n\r\n");
1205 This function gets GUIDs from SPD file accrodeing to <Protocols> <Ppis>
1206 <Guids> information and write those GUIDs to AutoGen.c.
1209 String Buffer for Autogen.c file.
1212 void CNameToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1213 String
[] cNameGuid
= null;
1214 String guidKeyWord
= null;
1216 String
[] cnameList
= saq
.getCNameArray(this.arch
);
1217 for (int i
= 0; i
< cnameList
.length
; i
++) {
1218 this.mGuidCNameList
.add(cnameList
[i
]);
1222 Iterator guidIterator
= this.mGuidCNameList
.iterator();
1223 while (guidIterator
.hasNext()) {
1224 guidKeyWord
= guidIterator
.next().toString();
1225 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1226 if (cNameGuid
== null) {
1227 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, guidKeyWord
);
1228 if (cNameGuid
== null) {
1229 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, guidKeyWord
);
1230 if (cNameGuid
== null) {
1232 // If can't find GUID declaration in every package, stop the build
1234 EdkLog
.log(EdkLog
.EDK_INFO
,"WARN: Can not find Guid [" + guidKeyWord
+ "] declaration in any SPD file.");
1236 //throw new AutoGenException("Can not find Guid [" + guidKeyWord
1237 // + "] declaration in any SPD package. ");
1242 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1243 fileBuffer
.append(cNameGuid
[0]);
1244 fileBuffer
.append(" = { ");
1245 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1246 fileBuffer
.append("} ;");
1251 LibInstanceToAutogenC
1253 This function adds dependent library instance to autogen.c,which
1254 includeing library's constructor, destructor, and library dependent ppi,
1255 protocol, guid, pcd information.
1258 String buffer for AutoGen.c
1259 @throws BuildException
1261 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1262 String moduleType
= this.moduleId
.getModuleType();
1264 // Add library constructor to AutoGen.c
1266 LibConstructorToAutogenC(libConstructList
, moduleType
, fileBuffer
);
1268 // Add library destructor to AutoGen.c
1270 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
);
1274 LibConstructorToAutogenH
1276 This function writes library constructor declarations AutoGen.h. The library
1277 constructor's parameter and return value depend on module type.
1279 @param libInstanceList
1280 List of library construct name.
1284 String buffer for AutoGen.c
1287 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1288 boolean isFirst
= true;
1291 // If not yet parse this library instance's constructor
1292 // element,parse it.
1294 String libConstructName
= saq
.getLibConstructorName();
1295 if (libConstructName
== null) {
1300 // The library constructor's parameter and return value depend on
1303 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1304 functionDeclarations
.append("RETURN_STATUS\r\n");
1305 functionDeclarations
.append("EFIAPI\r\n");
1306 functionDeclarations
.append(libConstructName
);
1307 functionDeclarations
.append(" (\r\n");
1308 functionDeclarations
.append(" VOID\r\n");
1309 functionDeclarations
.append(" );\r\n");
1311 switch (CommonDefinition
.getModuleType(moduleType
)) {
1312 case CommonDefinition
.ModuleTypeBase
:
1313 functionDeclarations
.append("RETURN_STATUS\r\n");
1314 functionDeclarations
.append("EFIAPI\r\n");
1315 functionDeclarations
.append(libConstructName
);
1316 functionDeclarations
.append(" (\r\n");
1317 functionDeclarations
.append(" VOID\r\n");
1318 functionDeclarations
.append(" );\r\n");
1321 case CommonDefinition
.ModuleTypePeiCore
:
1322 case CommonDefinition
.ModuleTypePeim
:
1323 functionDeclarations
.append("EFI_STATUS\r\n");
1324 functionDeclarations
.append("EFIAPI\r\n");
1325 functionDeclarations
.append(libConstructName
);
1326 functionDeclarations
.append(" (\r\n");
1327 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1328 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1329 functionDeclarations
.append(" );\r\n");
1332 case CommonDefinition
.ModuleTypeDxeCore
:
1333 case CommonDefinition
.ModuleTypeDxeDriver
:
1334 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1335 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1336 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1337 case CommonDefinition
.ModuleTypeUefiDriver
:
1338 case CommonDefinition
.ModuleTypeUefiApplication
:
1339 functionDeclarations
.append("EFI_STATUS\r\n");
1340 functionDeclarations
.append("EFIAPI\r\n");
1341 functionDeclarations
.append(libConstructName
);
1342 functionDeclarations
.append(" (\r\n");
1343 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1344 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1345 functionDeclarations
.append(" );\r\n");
1353 LibDestructorToAutogenH
1355 This function writes library destructor declarations AutoGen.h. The library
1356 destructor's parameter and return value depend on module type.
1358 @param libInstanceList
1359 List of library destructor name.
1363 String buffer for AutoGen.c
1366 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1367 boolean isFirst
= true;
1368 String libDestructName
= saq
.getLibDestructorName();
1369 if (libDestructName
== null) {
1373 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1374 functionDeclarations
.append("RETURN_STATUS\r\n");
1375 functionDeclarations
.append("EFIAPI\r\n");
1376 functionDeclarations
.append(libDestructName
);
1377 functionDeclarations
.append(" (\r\n");
1378 functionDeclarations
.append(" VOID\r\n");
1379 functionDeclarations
.append(" );\r\n");
1381 switch (CommonDefinition
.getModuleType(moduleType
)) {
1382 case CommonDefinition
.ModuleTypeBase
:
1383 functionDeclarations
.append("RETURN_STATUS\r\n");
1384 functionDeclarations
.append("EFIAPI\r\n");
1385 functionDeclarations
.append(libDestructName
);
1386 functionDeclarations
.append(" (\r\n");
1387 functionDeclarations
.append(" VOID\r\n");
1388 functionDeclarations
.append(" );\r\n");
1390 case CommonDefinition
.ModuleTypePeiCore
:
1391 case CommonDefinition
.ModuleTypePeim
:
1392 functionDeclarations
.append("EFI_STATUS\r\n");
1393 functionDeclarations
.append("EFIAPI\r\n");
1394 functionDeclarations
.append(libDestructName
);
1395 functionDeclarations
.append(" (\r\n");
1396 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1397 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1398 functionDeclarations
.append(" );\r\n");
1400 case CommonDefinition
.ModuleTypeDxeCore
:
1401 case CommonDefinition
.ModuleTypeDxeDriver
:
1402 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1403 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1404 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1405 case CommonDefinition
.ModuleTypeUefiDriver
:
1406 case CommonDefinition
.ModuleTypeUefiApplication
:
1407 functionDeclarations
.append("EFI_STATUS\r\n");
1408 functionDeclarations
.append("EFIAPI\r\n");
1409 functionDeclarations
.append(libDestructName
);
1410 functionDeclarations
.append(" (\r\n");
1411 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1412 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1413 functionDeclarations
.append(" );\r\n");
1420 LibConstructorToAutogenc
1422 This function writes library constructor list to AutoGen.c. The library
1423 constructor's parameter and return value depend on module type.
1425 @param libInstanceList
1426 List of library construct name.
1430 String buffer for AutoGen.c
1433 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1434 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1435 boolean isFirst
= true;
1438 // The library constructor's parameter and return value depend on
1441 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1442 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1443 functionDeclarations
.append("RETURN_STATUS\r\n");
1444 functionDeclarations
.append("EFIAPI\r\n");
1445 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1446 functionDeclarations
.append(" (\r\n");
1447 functionDeclarations
.append(" VOID\r\n");
1448 functionDeclarations
.append(" );\r\n");
1450 switch (CommonDefinition
.getModuleType(moduleType
)) {
1451 case CommonDefinition
.ModuleTypeBase
:
1452 functionDeclarations
.append("RETURN_STATUS\r\n");
1453 functionDeclarations
.append("EFIAPI\r\n");
1454 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1455 functionDeclarations
.append(" (\r\n");
1456 functionDeclarations
.append(" VOID\r\n");
1457 functionDeclarations
.append(" );\r\n");
1460 case CommonDefinition
.ModuleTypePeiCore
:
1461 case CommonDefinition
.ModuleTypePeim
:
1462 functionDeclarations
.append("EFI_STATUS\r\n");
1463 functionDeclarations
.append("EFIAPI\r\n");
1464 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1465 functionDeclarations
.append(" (\r\n");
1466 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1467 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1468 functionDeclarations
.append(" );\r\n");
1471 case CommonDefinition
.ModuleTypeDxeCore
:
1472 case CommonDefinition
.ModuleTypeDxeDriver
:
1473 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1474 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1475 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1476 case CommonDefinition
.ModuleTypeUefiDriver
:
1477 case CommonDefinition
.ModuleTypeUefiApplication
:
1478 functionDeclarations
.append("EFI_STATUS\r\n");
1479 functionDeclarations
.append("EFIAPI\r\n");
1480 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1481 functionDeclarations
.append(" (\r\n");
1482 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1483 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1484 functionDeclarations
.append(" );\r\n");
1492 // Add ProcessLibraryConstructorList in AutoGen.c
1494 fileBuffer
.append("VOID\r\n");
1495 fileBuffer
.append("EFIAPI\r\n");
1496 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1497 switch (CommonDefinition
.getModuleType(moduleType
)) {
1498 case CommonDefinition
.ModuleTypeBase
:
1499 fileBuffer
.append(" VOID\r\n");
1502 case CommonDefinition
.ModuleTypePeiCore
:
1503 case CommonDefinition
.ModuleTypePeim
:
1504 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1505 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
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(" IN EFI_HANDLE ImageHandle,\r\n");
1516 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1520 fileBuffer
.append(" )\r\n");
1521 fileBuffer
.append("{\r\n");
1523 // If no constructor function, return EFI_SUCCESS.
1525 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1527 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1528 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1529 fileBuffer
.append("\r\n");
1532 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1533 fileBuffer
.append(" Status = ");
1534 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1535 fileBuffer
.append("();\r\n");
1537 switch (CommonDefinition
.getModuleType(moduleType
)) {
1538 case CommonDefinition
.ModuleTypeBase
:
1539 fileBuffer
.append(" Status = ");
1540 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1541 fileBuffer
.append("();\r\n");
1543 case CommonDefinition
.ModuleTypePeiCore
:
1544 case CommonDefinition
.ModuleTypePeim
:
1545 fileBuffer
.append(" Status = ");
1546 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1547 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1549 case CommonDefinition
.ModuleTypeDxeCore
:
1550 case CommonDefinition
.ModuleTypeDxeDriver
:
1551 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1552 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1553 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1554 case CommonDefinition
.ModuleTypeUefiDriver
:
1555 case CommonDefinition
.ModuleTypeUefiApplication
:
1556 fileBuffer
.append(" Status = ");
1557 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1558 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1561 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1565 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1567 fileBuffer
.append("}\r\n");
1571 LibDestructorToAutogenc
1573 This function writes library destructor list to AutoGen.c. The library
1574 destructor's parameter and return value depend on module type.
1576 @param libInstanceList
1577 List of library destructor name.
1581 String buffer for AutoGen.c
1584 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1585 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1586 boolean isFirst
= true;
1587 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1588 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1589 functionDeclarations
.append("RETURN_STATUS\r\n");
1590 functionDeclarations
.append("EFIAPI\r\n");
1591 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1592 functionDeclarations
.append(" (\r\n");
1593 functionDeclarations
.append(" VOID\r\n");
1594 functionDeclarations
.append(" );\r\n");
1596 switch (CommonDefinition
.getModuleType(moduleType
)) {
1597 case CommonDefinition
.ModuleTypeBase
:
1598 functionDeclarations
.append("RETURN_STATUS\r\n");
1599 functionDeclarations
.append("EFIAPI\r\n");
1600 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1601 functionDeclarations
.append(" (\r\n");
1602 functionDeclarations
.append(" VOID\r\n");
1603 functionDeclarations
.append(" );\r\n");
1605 case CommonDefinition
.ModuleTypePeiCore
:
1606 case CommonDefinition
.ModuleTypePeim
:
1607 functionDeclarations
.append("EFI_STATUS\r\n");
1608 functionDeclarations
.append("EFIAPI\r\n");
1609 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1610 functionDeclarations
.append(" (\r\n");
1611 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1612 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1613 functionDeclarations
.append(" );\r\n");
1615 case CommonDefinition
.ModuleTypeDxeCore
:
1616 case CommonDefinition
.ModuleTypeDxeDriver
:
1617 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1618 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1619 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1620 case CommonDefinition
.ModuleTypeUefiDriver
:
1621 case CommonDefinition
.ModuleTypeUefiApplication
:
1622 functionDeclarations
.append("EFI_STATUS\r\n");
1623 functionDeclarations
.append("EFIAPI\r\n");
1624 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1625 functionDeclarations
.append(" (\r\n");
1626 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1627 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1628 functionDeclarations
.append(" );\r\n");
1635 // Write ProcessLibraryDestructor list to autogen.c
1637 switch (CommonDefinition
.getModuleType(moduleType
)) {
1638 case CommonDefinition
.ModuleTypeBase
:
1639 case CommonDefinition
.ModuleTypePeiCore
:
1640 case CommonDefinition
.ModuleTypePeim
:
1642 case CommonDefinition
.ModuleTypeDxeCore
:
1643 case CommonDefinition
.ModuleTypeDxeDriver
:
1644 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1645 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1646 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1647 case CommonDefinition
.ModuleTypeUefiDriver
:
1648 case CommonDefinition
.ModuleTypeUefiApplication
:
1649 fileBuffer
.append("VOID\r\n");
1650 fileBuffer
.append("EFIAPI\r\n");
1651 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1652 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1653 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1654 fileBuffer
.append(" )\r\n");
1655 fileBuffer
.append("{\r\n");
1657 // If no library destructor function, return EFI_SUCCESS.
1660 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1662 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1663 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1664 fileBuffer
.append("\r\n");
1667 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1668 fileBuffer
.append(" Status = ");
1669 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1670 fileBuffer
.append("();\r\n");
1671 fileBuffer
.append(" VOID\r\n");
1673 fileBuffer
.append(" Status = ");
1674 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1675 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1676 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1679 fileBuffer
.append("}\r\n");
1685 ExternsDriverBindingToAutoGenC
1687 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1688 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1691 String buffer for AutoGen.c
1693 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1694 throws EdkException
{
1696 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1697 // The second dimension is include following element: DriverBinding,
1698 // ComponentName, DriverConfiguration, DriverDiag;
1700 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1709 // Write driver binding protocol extern to autogen.c
1711 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1712 if (driverBindingGroup
[i
][0] != null) {
1713 globalDeclarations
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1714 globalDeclarations
.append(driverBindingGroup
[i
][0]);
1715 globalDeclarations
.append(";\r\n");
1720 // Write component name protocol extern to autogen.c
1722 if (!componentNamePcd
) {
1723 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1724 if (driverBindingGroup
[i
][1]!= null) {
1725 if (driverBindingGroup
[i
][0] != null) {
1727 globalDeclarations
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1728 globalDeclarations
.append(driverBindingGroup
[i
][1]);
1729 globalDeclarations
.append(";\r\n");
1731 throw new AutoGenException("DriverBinding can't be empty!!");
1738 // Write driver configration protocol extern to autogen.c
1740 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1741 if (driverBindingGroup
[i
][2] != null) {
1742 if (driverBindingGroup
[i
][0] != null) {
1744 globalDeclarations
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1745 globalDeclarations
.append(driverBindingGroup
[i
][2]);
1746 globalDeclarations
.append(";\r\n");
1748 throw new AutoGenException("DriverBinding can't be empty!!");
1754 // Write driver dignastic protocol extern to autogen.c
1756 if (!driverDiagnostPcd
) {
1757 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1758 if (driverBindingGroup
[i
][3] != null) {
1759 if (driverBindingGroup
[i
][0] != null) {
1761 globalDeclarations
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1762 globalDeclarations
.append(driverBindingGroup
[i
][3]);
1763 globalDeclarations
.append(";\r\n");
1765 throw new AutoGenException("DriverBinding can't be empty!!");
1773 // Write driver module protocol bitmask.
1775 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1776 fileBuffer
.append(Integer
.toString(BitMask
));
1777 fileBuffer
.append(";\r\n");
1780 // Write driver module protocol list entry
1782 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1784 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1785 fileBuffer
.append(";\r\n");
1788 // Write drive module protocol list to autogen.c
1790 if (driverBindingGroup
.length
> 0) {
1791 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1795 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1797 fileBuffer
.append(",");
1802 fileBuffer
.append("\r\n {\r\n");
1803 fileBuffer
.append(" &");
1804 fileBuffer
.append(driverBindingGroup
[i
][0]);
1805 fileBuffer
.append(", \r\n");
1810 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1811 fileBuffer
.append(" &");
1812 fileBuffer
.append(driverBindingGroup
[i
][1]);
1813 fileBuffer
.append(", \r\n");
1815 fileBuffer
.append(" NULL, \r\n");
1819 // DriverConfiguration
1821 if (driverBindingGroup
[i
][2] != null) {
1822 fileBuffer
.append(" &");
1823 fileBuffer
.append(driverBindingGroup
[i
][2]);
1824 fileBuffer
.append(", \r\n");
1826 fileBuffer
.append(" NULL, \r\n");
1832 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1833 fileBuffer
.append(" &");
1834 fileBuffer
.append(driverBindingGroup
[i
][3]);
1835 fileBuffer
.append(", \r\n");
1837 fileBuffer
.append(" NULL, \r\n");
1839 fileBuffer
.append(" }");
1842 if (driverBindingGroup
.length
> 0) {
1843 fileBuffer
.append("\r\n};\r\n");
1848 ExternCallBackToAutoGenC
1850 This function adds <SetVirtualAddressMapCallBack> and
1851 <ExitBootServicesCallBack> infomation to AutoGen.c
1854 String buffer for AutoGen.c
1855 @throws BuildException
1857 void ExternCallBackToAutoGenH(String moduleType
)
1858 throws EdkException
{
1860 // Collect module's <SetVirtualAddressMapCallBack> and
1861 // <ExitBootServiceCallBack> and add to setVirtualAddList
1862 // exitBootServiceList.
1864 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1865 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1867 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1868 // and <ExitBootServicesCallBack>
1870 switch (CommonDefinition
.getModuleType(moduleType
)) {
1871 case CommonDefinition
.ModuleTypeDxeDriver
:
1872 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1873 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1874 case CommonDefinition
.ModuleTypeUefiDriver
:
1875 case CommonDefinition
.ModuleTypeUefiApplication
:
1877 // Write SetVirtualAddressMap function definition.
1879 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1880 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1883 functionDeclarations
.append("VOID\r\n");
1884 functionDeclarations
.append("EFIAPI\r\n");
1885 functionDeclarations
.append(setVirtuals
[i
]);
1886 functionDeclarations
.append(" (\r\n");
1887 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1888 functionDeclarations
.append(" IN VOID *Context\r\n");
1889 functionDeclarations
.append(" );\r\n\r\n");
1893 // Write DriverExitBootServices function definition.
1895 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1896 if (exitBoots
[i
].equalsIgnoreCase("")) {
1900 functionDeclarations
.append("VOID\r\n");
1901 functionDeclarations
.append("EFIAPI\r\n");
1902 functionDeclarations
.append(exitBoots
[i
]);
1903 functionDeclarations
.append(" (\r\n");
1904 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1905 functionDeclarations
.append(" IN VOID *Context\r\n");
1906 functionDeclarations
.append(" );\r\n\r\n");
1915 ExternCallBackToAutoGenC
1917 This function adds <SetVirtualAddressMapCallBack> and
1918 <ExitBootServicesCallBack> infomation to AutoGen.c
1921 String buffer for AutoGen.c
1922 @throws BuildException
1924 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1925 throws EdkException
{
1927 // Collect module's <SetVirtualAddressMapCallBack> and
1928 // <ExitBootServiceCallBack> and add to setVirtualAddList
1929 // exitBootServiceList.
1931 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1932 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1933 if (setVirtuals
!= null) {
1934 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
1935 this.setVirtalAddList
.add(setVirtuals
[j
]);
1938 if (exitBoots
!= null) {
1939 for (int k
= 0; k
< exitBoots
.length
; k
++) {
1940 this.exitBootServiceList
.add(exitBoots
[k
]);
1944 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1945 // and <ExitBootServicesCallBack>
1947 String moduleType
= this.moduleId
.getModuleType();
1948 switch (CommonDefinition
.getModuleType(moduleType
)) {
1949 case CommonDefinition
.ModuleTypeDxeDriver
:
1950 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1951 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1952 case CommonDefinition
.ModuleTypeUefiDriver
:
1953 case CommonDefinition
.ModuleTypeUefiApplication
:
1955 // If moduleType is one of above, call setVirtualAddressToAutogenC,
1956 // and setExitBootServiceToAutogenC.
1958 setVirtualAddressToAutogenC(fileBuffer
);
1959 setExitBootServiceToAutogenC(fileBuffer
);
1967 copyFlashMapHToDebugDir
1969 This function is to copy the falshmap.h to debug directory and change
1970 its name to TianoR8FlashMap.h
1975 private void copyFlashMapHToDebugDir() throws AutoGenException
{
1977 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
1978 int size
= (int)inFile
.length();
1979 byte[] buffer
= new byte[size
];
1980 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
1982 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
1985 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
1986 if (inFile
.exists()) {
1988 FileInputStream fis
= new FileInputStream (inFile
);
1990 FileOutputStream fos
= new FileOutputStream(outFile
);
1994 } catch (IOException e
) {
1995 throw new AutoGenException("The file, flashMap.h can't be open!");
1999 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2005 This function first order the library instances, then collect
2006 library instance 's PPI, Protocol, GUID,
2007 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2008 Destructor, Constructor.
2013 private void collectLibInstanceInfo() throws EdkException
{
2016 String moduleType
= moduleId
.getModuleType();
2017 String libConstructName
= null;
2018 String libDestructName
= null;
2019 String libModuleType
= null;
2020 String
[] setVirtuals
= null;
2021 String
[] exitBoots
= null;
2023 ModuleIdentification
[] libraryIdList
= saq
.getLibraryInstance(this.arch
);
2024 if (libraryIdList
.length
<= 0) {
2028 // Reorder library instance sequence.
2030 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
2031 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
2033 // Process library instance one by one.
2035 for (int i
= 0; i
< orderList
.size(); i
++) {
2037 // Get library instance basename.
2039 ModuleIdentification libInstanceId
= orderList
.get(i
);
2045 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2048 // check if the library instance support current module
2050 String
[] libraryClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
,
2054 if (libraryClassList
.length
<= 0) {
2055 throw new EdkException("Library instance " + libInstanceId
.getName()
2056 + " doesn't support module type " + moduleType
);
2059 // Get CName list from <PPis>, <Protocols>, <Guids>, etc. of this library
2062 String
[] guidCNameList
= saq
.getCNameArray(this.arch
);
2063 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2066 // Add those ppi, protocol, guid in global ppi,
2070 for (index
= 0; index
< guidCNameList
.length
; index
++) {
2071 this.mGuidCNameList
.add(guidCNameList
[index
]);
2074 for (index
= 0; index
< pkgList
.length
; index
++) {
2075 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2076 this.mDepPkgList
.add(pkgList
[index
]);
2081 // If not yet parse this library instance's constructor
2082 // element,parse it.
2084 libConstructName
= saq
.getLibConstructorName();
2085 libDestructName
= saq
.getLibDestructorName();
2086 libModuleType
= saq
.getModuleType();
2089 // Collect SetVirtualAddressMapCallBack and
2090 // ExitBootServiceCallBack.
2092 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2093 exitBoots
= saq
.getExitBootServicesCallBackArray();
2094 if (setVirtuals
!= null) {
2095 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2096 this.setVirtalAddList
.add(setVirtuals
[j
]);
2099 if (exitBoots
!= null) {
2100 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2101 this.exitBootServiceList
.add(exitBoots
[k
]);
2106 // Add dependent library instance constructor function.
2108 if (libConstructName
!= null) {
2109 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2112 // Add dependent library instance destructor fuction.
2114 if (libDestructName
!= null) {
2115 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2120 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2122 // Entry point lib for these module types needs to know the count
2125 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2128 // If the list is not valid or has no entries set count to zero else
2129 // set count to the number of valid entries
2133 if (this.setVirtalAddList
!= null) {
2134 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2135 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2142 fileBuffer
.append(Integer
.toString(Count
));
2143 fileBuffer
.append(";\r\n\r\n");
2144 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2146 // No data so make a NULL list
2148 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2149 fileBuffer
.append(" NULL\r\n");
2150 fileBuffer
.append("};\r\n\r\n");
2153 // Write SetVirtualAddressMap function definition.
2155 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2156 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2159 functionDeclarations
.append("VOID\r\n");
2160 functionDeclarations
.append("EFIAPI\r\n");
2161 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2162 functionDeclarations
.append(" (\r\n");
2163 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2164 functionDeclarations
.append(" IN VOID *Context\r\n");
2165 functionDeclarations
.append(" );\r\n\r\n");
2169 // Write SetVirtualAddressMap entry point array.
2171 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2172 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2173 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2178 fileBuffer
.append("\r\n ");
2180 fileBuffer
.append(",\r\n ");
2183 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2186 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2188 fileBuffer
.append(",\r\n NULL");
2189 fileBuffer
.append("\r\n};\r\n\r\n");
2194 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2196 // Entry point lib for these module types needs to know the count.
2198 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2201 // If the list is not valid or has no entries set count to zero else
2202 // set count to the number of valid entries.
2206 if (this.exitBootServiceList
!= null) {
2207 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2208 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2214 fileBuffer
.append(Integer
.toString(Count
));
2215 fileBuffer
.append(";\r\n\r\n");
2217 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2219 // No data so make a NULL list.
2221 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2222 fileBuffer
.append(" NULL\r\n");
2223 fileBuffer
.append("};\r\n\r\n");
2226 // Write DriverExitBootServices function definition.
2228 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2229 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2233 functionDeclarations
.append("VOID\r\n");
2234 functionDeclarations
.append("EFIAPI\r\n");
2235 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2236 functionDeclarations
.append(" (\r\n");
2237 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2238 functionDeclarations
.append(" IN VOID *Context\r\n");
2239 functionDeclarations
.append(" );\r\n\r\n");
2243 // Write DriverExitBootServices entry point array.
2245 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2246 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2247 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2252 fileBuffer
.append("\r\n ");
2254 fileBuffer
.append(",\r\n ");
2256 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2259 fileBuffer
.append(",\r\n NULL");
2260 fileBuffer
.append("\r\n};\r\n\r\n");
2266 Get the Pcd Value of ComponentName to
2267 decide whether need to disable the componentName.
2270 public void setPcdComponentName (){
2271 String pcdValue
= null;
2272 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2273 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2274 this.componentNamePcd
= true;
2279 setPcdDriverDiagnostic
2281 Get the Pcd Value of DriverDiagnostic to
2282 decide whether need to disable DriverDiagnostic.
2285 public void setPcdDriverDiagnostic (){
2286 String pcdValue
= null;
2287 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2288 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2289 this.driverDiagnostPcd
= true;