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
433 if (!moduleId
.getModuleType().equalsIgnoreCase("UEFI_APPLICATION")) {
434 ExternsDriverBindingToAutoGenC(fileBuffer
);
438 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
441 ExternCallBackToAutoGenC(fileBuffer
);
444 // Write EntryPoint to autgoGen.c
446 String
[] entryPointList
= saq
.getModuleEntryPointArray();
447 String
[] unloadImageList
= saq
.getModuleUnloadImageArray();
448 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
),
449 CommonDefinition
.remDupString(unloadImageList
),
452 pcdDriverType
= saq
.getPcdDriverType();
455 // Restore the DOC which include the FPD module info.
460 // Write Guid to autogen.c
462 String guid
= CommonDefinition
.formatGuidName(saq
.getModuleGuid());
463 if (this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
464 globalDeclarations
.append("extern GUID gEfiCallerIdGuid;\r\n");
465 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");
466 } else if (!this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_USER_DEFINED
)) {
467 globalDeclarations
.append("extern EFI_GUID gEfiCallerIdGuid;\r\n");
468 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
472 throw new AutoGenException("Guid value must set!\n");
476 // Formate Guid as ANSI c form.Example:
477 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
481 fileBuffer
.append(guid
);
482 fileBuffer
.append("};\r\n");
485 // Generate library instance consumed protocol, guid, ppi, pcd list.
486 // Save those to this.protocolList, this.ppiList, this.pcdList,
487 // this.guidList. Write Consumed library constructor and desconstuct to
490 LibInstanceToAutogenC(fileBuffer
);
493 // Get module dependent Package identification.
495 PackageIdentification
[] packages
= saq
.getDependencePkg(this.arch
);
496 for (int i
= 0; i
< packages
.length
; i
++) {
497 if (!this.mDepPkgList
.contains(packages
[i
])) {
498 this.mDepPkgList
.add(packages
[i
]);
504 // Write consumed ppi, guid, protocol, etc to autogen.c
506 CNameToAutogenC(fileBuffer
);
511 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
518 this.myPcdAutogen
.execute();
519 if (this.myPcdAutogen
!= null) {
520 fileBuffer
.append("\r\n");
521 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
524 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
525 throw new AutoGenException("Failed to generate AutoGen.c !!!");
533 This function generates AutoGen.h for library.
535 @throws BuildException
536 Failed to generate AutoGen.c.
538 void libGenAutogenH() throws EdkException
{
540 Set
<String
> libClassIncludeH
;
542 List
<String
> headerFileList
;
544 StringBuffer fileBuffer
= new StringBuffer(10240);
547 // Write Autogen.h header notation
549 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
552 // Add #ifndef ${BaseName}_AUTOGENH
553 // #def ${BseeName}_AUTOGENH
555 fileBuffer
.append(CommonDefinition
.IFNDEF
556 + CommonDefinition
.AUTOGENH
557 + this.moduleId
.getGuid().replaceAll("-", "_")
558 + ToolDefinitions
.LINE_SEPARATOR
);
559 fileBuffer
.append(CommonDefinition
.DEFINE
560 + CommonDefinition
.AUTOGENH
561 + this.moduleId
.getGuid().replaceAll("-", "_")
562 + ToolDefinitions
.LINE_SEPARATOR
563 + ToolDefinitions
.LINE_SEPARATOR
);
566 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
567 // to autogen.h file.
568 // Note: the specification version and release version should
569 // be get from module surface area instead of hard code.
571 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
572 String
[] specList
= saq
.getExternSpecificaiton();
573 for (int i
= 0; i
< specList
.length
; i
++) {
574 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
] + "\r\n");
576 // fileBuffer.append(CommonDefinition.autoGenHLine1);
577 // fileBuffer.append(CommonDefinition.autoGenHLine2);
580 // Write consumed package's mdouleInfo related *.h file to autogen.h.
582 moduleType
= saq
.getModuleType();
583 PackageIdentification
[] cosumedPkglist
= saq
.getDependencePkg(this.arch
);
584 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
585 item
= headerFileList
.iterator();
586 while (item
.hasNext()) {
587 fileBuffer
.append(item
.next().toString());
590 // Write library class's related *.h file to autogen.h
592 List
<String
> libClasses
= new ArrayList
<String
>(100);
593 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
, null);
594 for (int i
= 0; i
< libClassList
.length
; ++i
) {
595 libClasses
.add(libClassList
[i
]);
598 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
, null);
599 for (int i
= 0; i
< libClassList
.length
; ++i
) {
600 libClasses
.add(libClassList
[i
]);
603 // Add AutoGen used library class
605 int moduleTypeId
= CommonDefinition
.getModuleType(moduleType
);
606 if (!libClasses
.contains("DebugLib") && moduleTypeId
!= CommonDefinition
.ModuleTypeUnknown
607 && moduleTypeId
!= CommonDefinition
.ModuleTypeBase
) {
608 libClasses
.add("DebugLib");
610 switch (moduleTypeId
) {
611 case CommonDefinition
.ModuleTypeDxeDriver
:
612 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
613 case CommonDefinition
.ModuleTypeDxeSalDriver
:
614 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
615 case CommonDefinition
.ModuleTypeUefiDriver
:
616 case CommonDefinition
.ModuleTypeUefiApplication
:
617 if (!libClasses
.contains("UefiBootServicesTableLib")) {
618 libClasses
.add("UefiBootServicesTableLib");
622 LibraryClassToAutogenH(fileBuffer
, libClasses
.toArray(new String
[libClasses
.size()]));
623 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
626 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
627 // {DEST_DIR_DRBUG}/FlashMap.h
629 if (saq
.isHaveTianoR8FlashMap()) {
630 fileBuffer
.append(CommonDefinition
.INCLUDE
);
631 fileBuffer
.append(" <");
632 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
633 copyFlashMapHToDebugDir();
637 // Write PCD information to library AutoGen.h.
639 if (this.myPcdAutogen
!= null) {
640 fileBuffer
.append("\r\n");
641 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
644 // generate function prototype for constructor and destructor
646 LibConstructorToAutogenH(moduleType
);
647 LibDestructorToAutogenH(moduleType
);
648 ExternCallBackToAutoGenH(moduleType
);
649 fileBuffer
.append(functionDeclarations
);
651 // Append the #endif at AutoGen.h
653 fileBuffer
.append("#endif\r\n");
655 // Save content of string buffer to AutoGen.h file.
657 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
658 throw new AutoGenException("Failed to generate AutoGen.h !!!");
665 This function generates AutoGen.h for library.
667 @throws BuildException
668 Failed to generate AutoGen.c.
670 void libGenAutogenC() throws EdkException
{
671 StringBuffer fileBuffer
= new StringBuffer(10240);
674 // Write Autogen.c header notation
676 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
678 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
679 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
684 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
687 saq
.getModulePcdEntryNameArray(this.arch
),
690 this.myPcdAutogen
.execute();
691 if (this.myPcdAutogen
!= null) {
692 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
693 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
698 LibraryClassToAutogenH
700 This function returns *.h files declared by library classes which are
701 consumed or produced by current build module or library.
704 List of library class which consumed or produce by current
705 build module or library.
706 @return includeStrList List of *.h file.
708 void LibraryClassToAutogenH(StringBuffer fileBuffer
, String
[] libClassList
)
709 throws EdkException
{
710 String includeName
[];
714 // Get include file from GlobalData's SPDTable according to
715 // library class name.
717 for (int i
= 0; i
< libClassList
.length
; i
++) {
718 includeName
= GlobalData
.getLibraryClassHeaderFiles(
719 saq
.getDependencePkg(this.arch
),
721 if (includeName
== null) {
722 throw new AutoGenException("Can not find library class ["
723 + libClassList
[i
] + "] declaration in any SPD package. ");
725 for (int j
= 0; j
< includeName
.length
; j
++) {
726 String includeNameStr
= includeName
[j
];
727 if (includeNameStr
!= null) {
728 fileBuffer
.append(CommonDefinition
.INCLUDE
);
729 fileBuffer
.append(" <");
730 fileBuffer
.append(includeNameStr
);
731 fileBuffer
.append(">\r\n");
732 includeNameStr
= null;
741 This function add include file in AutoGen.h file.
743 @param packageNameList
744 List of module depended package.
749 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
750 String moduleType
) throws AutoGenException
{
752 List
<String
> includeStrList
= new LinkedList
<String
>();
754 String includeStr
= "";
757 // Get include file from moduleInfo file
759 for (int i
= 0; i
< packageNameList
.length
; i
++) {
760 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
762 if (pkgHeader
== null) {
763 throw new AutoGenException("Can not find package ["
765 + "] declaration in any SPD package. ");
766 } else if (!pkgHeader
.equalsIgnoreCase("")) {
767 includeStr
= CommonDefinition
.INCLUDE
+ " <" + pkgHeader
+ ">\r\n";
768 includeStrList
.add(includeStr
);
772 return includeStrList
;
778 This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
779 information in mas to AutoGen.c
781 @param entryPointList
784 String buffer fo AutoGen.c.
787 void EntryPointToAutoGen(String
[] entryPointList
, String
[] unloadImageList
, StringBuffer fileBuffer
)
788 throws EdkException
{
790 String typeStr
= saq
.getModuleType();
791 String debugStr
= "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";
792 int unloadImageCount
= 0;
793 int entryPointCount
= 0;
796 // The parameters and return value of entryPoint is difference
797 // for difference module type.
799 switch (CommonDefinition
.getModuleType(typeStr
)) {
801 case CommonDefinition
.ModuleTypePeiCore
:
802 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
803 throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");
805 functionDeclarations
.append("EFI_STATUS\r\n");
806 functionDeclarations
.append("EFIAPI\r\n");
807 functionDeclarations
.append(entryPointList
[0]);
808 functionDeclarations
.append(" (\r\n");
809 functionDeclarations
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
810 functionDeclarations
.append(" IN VOID *OldCoreData\r\n");
811 functionDeclarations
.append(" );\r\n\r\n");
813 fileBuffer
.append("EFI_STATUS\r\n");
814 fileBuffer
.append("EFIAPI\r\n");
815 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
816 fileBuffer
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
817 fileBuffer
.append(" IN VOID *OldCoreData\r\n");
818 fileBuffer
.append(" )\r\n\r\n");
819 fileBuffer
.append("{\r\n");
820 fileBuffer
.append(" return ");
821 fileBuffer
.append(entryPointList
[0]);
822 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
823 fileBuffer
.append("}\r\n\r\n");
827 case CommonDefinition
.ModuleTypeDxeCore
:
828 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
829 if (entryPointList
== null || entryPointList
.length
!= 1) {
830 throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");
832 functionDeclarations
.append("VOID\r\n");
833 functionDeclarations
.append("EFIAPI\r\n");
834 functionDeclarations
.append(entryPointList
[0]);
835 functionDeclarations
.append(" (\r\n");
836 functionDeclarations
.append(" IN VOID *HobStart\r\n");
837 functionDeclarations
.append(" );\r\n\r\n");
839 fileBuffer
.append("VOID\r\n");
840 fileBuffer
.append("EFIAPI\r\n");
841 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
842 fileBuffer
.append(" IN VOID *HobStart\r\n");
843 fileBuffer
.append(" )\r\n\r\n");
844 fileBuffer
.append("{\r\n");
845 fileBuffer
.append(" ");
846 fileBuffer
.append(entryPointList
[0]);
847 fileBuffer
.append(" (HobStart);\r\n");
848 fileBuffer
.append("}\r\n\r\n");
852 case CommonDefinition
.ModuleTypePeim
:
854 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
855 if (entryPointList
== null || entryPointList
.length
== 0) {
856 fileBuffer
.append("EFI_STATUS\r\n");
857 fileBuffer
.append("EFIAPI\r\n");
858 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
859 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
860 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
861 fileBuffer
.append(" )\r\n\r\n");
862 fileBuffer
.append("{\r\n");
863 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
864 fileBuffer
.append("}\r\n\r\n");
867 for (int i
= 0; i
< entryPointList
.length
; i
++) {
868 functionDeclarations
.append("EFI_STATUS\r\n");
869 functionDeclarations
.append("EFIAPI\r\n");
870 functionDeclarations
.append(entryPointList
[i
]);
871 functionDeclarations
.append(" (\r\n");
872 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
873 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
874 functionDeclarations
.append(" );\r\n");
878 fileBuffer
.append("EFI_STATUS\r\n");
879 fileBuffer
.append("EFIAPI\r\n");
880 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
881 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
882 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
883 fileBuffer
.append(" )\r\n\r\n");
884 fileBuffer
.append("{\r\n");
885 if (entryPointCount
== 1) {
886 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
887 fileBuffer
.append(" return ");
888 fileBuffer
.append(entryPointList
[0]);
889 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
891 fileBuffer
.append(" EFI_STATUS Status;\r\n");
892 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
893 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
894 for (int i
= 0; i
< entryPointList
.length
; i
++) {
895 if (!entryPointList
[i
].equals("")) {
896 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
897 fileBuffer
.append(" Status = ");
898 fileBuffer
.append(entryPointList
[i
]);
899 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
900 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
901 fileBuffer
.append(" CombinedStatus = Status;\r\n");
902 fileBuffer
.append(" }\r\n\r\n");
907 fileBuffer
.append(" return CombinedStatus;\r\n");
909 fileBuffer
.append("}\r\n\r\n");
912 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
915 // If entryPoint is null, create an empty ProcessModuleEntryPointList
918 if (entryPointList
== null || entryPointList
.length
== 0) {
919 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
920 fileBuffer
.append(Integer
.toString(entryPointCount
));
921 fileBuffer
.append(";\r\n");
922 fileBuffer
.append("EFI_STATUS\r\n");
923 fileBuffer
.append("EFIAPI\r\n");
924 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
925 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
926 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
927 fileBuffer
.append(" )\r\n\r\n");
928 fileBuffer
.append("{\r\n");
929 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
930 fileBuffer
.append("}\r\n\r\n");
933 for (int i
= 0; i
< entryPointList
.length
; i
++) {
934 functionDeclarations
.append("EFI_STATUS\r\n");
935 functionDeclarations
.append("EFIAPI\r\n");
936 functionDeclarations
.append(entryPointList
[i
]);
937 functionDeclarations
.append(" (\r\n");
938 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
939 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
940 functionDeclarations
.append(" );\r\n");
943 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
944 fileBuffer
.append(Integer
.toString(entryPointCount
));
945 fileBuffer
.append(";\r\n");
946 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
947 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
949 fileBuffer
.append("EFI_STATUS\r\n");
950 fileBuffer
.append("EFIAPI\r\n");
951 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
952 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
953 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
954 fileBuffer
.append(" )\r\n\r\n");
955 fileBuffer
.append("{\r\n");
957 for (int i
= 0; i
< entryPointList
.length
; i
++) {
958 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
959 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
960 fileBuffer
.append(" ExitDriver (");
961 fileBuffer
.append(entryPointList
[i
]);
962 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
963 fileBuffer
.append(" ASSERT (FALSE);\r\n");
964 fileBuffer
.append(" }\r\n");
966 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
967 fileBuffer
.append("}\r\n\r\n");
969 fileBuffer
.append("VOID\r\n");
970 fileBuffer
.append("EFIAPI\r\n");
971 fileBuffer
.append("ExitDriver (\r\n");
972 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
973 fileBuffer
.append(" )\r\n\r\n");
974 fileBuffer
.append("{\r\n");
975 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
976 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
977 fileBuffer
.append(" }\r\n");
978 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
979 fileBuffer
.append(" ASSERT (FALSE);\r\n");
980 fileBuffer
.append("}\r\n\r\n");
985 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
988 unloadImageCount
= 0;
989 if (unloadImageList
!= null) {
990 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
991 functionDeclarations
.append("EFI_STATUS\r\n");
992 functionDeclarations
.append(unloadImageList
[i
]);
993 functionDeclarations
.append(" (\r\n");
994 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
995 functionDeclarations
.append(" );\r\n");
1000 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1001 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1002 fileBuffer
.append(";\r\n\r\n");
1004 fileBuffer
.append("EFI_STATUS\r\n");
1005 fileBuffer
.append("EFIAPI\r\n");
1006 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1007 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1008 fileBuffer
.append(" )\r\n");
1009 fileBuffer
.append("{\r\n");
1011 if (unloadImageCount
== 0) {
1012 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1013 } else if (unloadImageCount
== 1) {
1014 fileBuffer
.append(" return ");
1015 fileBuffer
.append(unloadImageList
[0]);
1016 fileBuffer
.append("(ImageHandle);\r\n");
1018 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1019 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1020 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1022 fileBuffer
.append(" Status = ");
1023 fileBuffer
.append(unloadImageList
[i
]);
1024 fileBuffer
.append("(ImageHandle);\r\n");
1026 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1027 fileBuffer
.append(" ");
1028 fileBuffer
.append(unloadImageList
[i
]);
1029 fileBuffer
.append("(ImageHandle);\r\n");
1030 fileBuffer
.append(" } else {\r\n");
1031 fileBuffer
.append(" Status = ");
1032 fileBuffer
.append(unloadImageList
[i
]);
1033 fileBuffer
.append("(ImageHandle);\r\n");
1034 fileBuffer
.append(" }\r\n");
1037 fileBuffer
.append(" return Status;\r\n");
1039 fileBuffer
.append("}\r\n\r\n");
1042 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1043 case CommonDefinition
.ModuleTypeDxeDriver
:
1044 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1045 case CommonDefinition
.ModuleTypeUefiDriver
:
1046 case CommonDefinition
.ModuleTypeUefiApplication
:
1047 entryPointCount
= 0;
1048 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1050 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1052 if (entryPointList
== null || entryPointList
.length
== 0) {
1053 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1054 fileBuffer
.append("EFI_STATUS\r\n");
1055 fileBuffer
.append("EFIAPI\r\n");
1056 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1057 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1058 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1059 fileBuffer
.append(" )\r\n\r\n");
1060 fileBuffer
.append("{\r\n");
1061 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1062 fileBuffer
.append("}\r\n");
1065 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1066 functionDeclarations
.append("EFI_STATUS\r\n");
1067 functionDeclarations
.append("EFIAPI\r\n");
1068 functionDeclarations
.append(entryPointList
[i
]);
1069 functionDeclarations
.append(" (\r\n");
1070 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1071 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1072 functionDeclarations
.append(" );\r\n");
1076 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1077 fileBuffer
.append(Integer
.toString(entryPointCount
));
1078 fileBuffer
.append(";\r\n");
1079 if (entryPointCount
> 1) {
1080 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1081 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1083 fileBuffer
.append("\r\n");
1085 fileBuffer
.append("EFI_STATUS\r\n");
1086 fileBuffer
.append("EFIAPI\r\n");
1087 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1088 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1089 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1090 fileBuffer
.append(" )\r\n\r\n");
1091 fileBuffer
.append("{\r\n");
1093 if (entryPointCount
== 1) {
1094 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
1095 fileBuffer
.append(" return ");
1096 fileBuffer
.append(entryPointList
[0]);
1097 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1099 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1100 if (!entryPointList
[i
].equals("")) {
1101 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1102 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
1103 if (CommonDefinition
.getModuleType(typeStr
) == CommonDefinition
.ModuleTypeUefiApplication
) {
1104 fileBuffer
.append(" Exit (");
1106 fileBuffer
.append(" ExitDriver (");
1108 fileBuffer
.append(entryPointList
[i
]);
1109 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1110 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1111 fileBuffer
.append(" }\r\n");
1116 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1118 fileBuffer
.append("}\r\n\r\n");
1120 if (CommonDefinition
.getModuleType(typeStr
) != CommonDefinition
.ModuleTypeUefiApplication
) {
1121 fileBuffer
.append("VOID\r\n");
1122 fileBuffer
.append("EFIAPI\r\n");
1123 fileBuffer
.append("ExitDriver (\r\n");
1124 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1125 fileBuffer
.append(" )\r\n\r\n");
1126 fileBuffer
.append("{\r\n");
1127 if (entryPointCount
<= 1) {
1128 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1129 fileBuffer
.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1130 fileBuffer
.append(" }\r\n");
1131 fileBuffer
.append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1133 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1134 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1135 fileBuffer
.append(" }\r\n");
1136 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1137 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1139 fileBuffer
.append("}\r\n\r\n");
1143 if (CommonDefinition
.getModuleType(typeStr
) == CommonDefinition
.ModuleTypeUefiApplication
) {
1147 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1149 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1151 // Remover duplicate unload entry point.
1153 //entryPointList = CommonDefinition.remDupString(entryPointList);
1154 //entryPointCount = 0;
1155 unloadImageCount
= 0;
1156 if (unloadImageList
!= null) {
1157 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1158 functionDeclarations
.append("EFI_STATUS\r\n");
1159 functionDeclarations
.append("EFIAPI\r\n");
1160 functionDeclarations
.append(unloadImageList
[i
]);
1161 functionDeclarations
.append(" (\r\n");
1162 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
1163 functionDeclarations
.append(" );\r\n");
1168 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1169 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1170 fileBuffer
.append(";\r\n\r\n");
1172 fileBuffer
.append("EFI_STATUS\r\n");
1173 fileBuffer
.append("EFIAPI\r\n");
1174 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1175 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1176 fileBuffer
.append(" )\r\n");
1177 fileBuffer
.append("{\r\n");
1179 if (unloadImageCount
== 0) {
1180 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1181 } else if (unloadImageCount
== 1) {
1182 fileBuffer
.append(" return ");
1183 fileBuffer
.append(unloadImageList
[0]);
1184 fileBuffer
.append("(ImageHandle);\r\n");
1186 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1187 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1188 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1190 fileBuffer
.append(" Status = ");
1191 fileBuffer
.append(unloadImageList
[i
]);
1192 fileBuffer
.append("(ImageHandle);\r\n");
1194 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1195 fileBuffer
.append(" ");
1196 fileBuffer
.append(unloadImageList
[i
]);
1197 fileBuffer
.append("(ImageHandle);\r\n");
1198 fileBuffer
.append(" } else {\r\n");
1199 fileBuffer
.append(" Status = ");
1200 fileBuffer
.append(unloadImageList
[i
]);
1201 fileBuffer
.append("(ImageHandle);\r\n");
1202 fileBuffer
.append(" }\r\n");
1205 fileBuffer
.append(" return Status;\r\n");
1207 fileBuffer
.append("}\r\n\r\n");
1215 This function gets GUIDs from SPD file accrodeing to <Protocols> <Ppis>
1216 <Guids> information and write those GUIDs to AutoGen.c.
1219 String Buffer for Autogen.c file.
1222 void CNameToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1223 String
[] cNameGuid
= null;
1224 String guidKeyWord
= null;
1226 String
[] cnameList
= saq
.getCNameArray(this.arch
);
1227 for (int i
= 0; i
< cnameList
.length
; i
++) {
1228 this.mGuidCNameList
.add(cnameList
[i
]);
1232 Iterator guidIterator
= this.mGuidCNameList
.iterator();
1233 while (guidIterator
.hasNext()) {
1234 guidKeyWord
= guidIterator
.next().toString();
1235 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1236 if (cNameGuid
== null) {
1237 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, guidKeyWord
);
1238 if (cNameGuid
== null) {
1239 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, guidKeyWord
);
1240 if (cNameGuid
== null) {
1242 // If can't find GUID declaration in every package, stop the build
1244 EdkLog
.log(EdkLog
.EDK_INFO
,"WARN: Can not find Guid [" + guidKeyWord
+ "] declaration in any SPD file.");
1246 //throw new AutoGenException("Can not find Guid [" + guidKeyWord
1247 // + "] declaration in any SPD package. ");
1252 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1253 fileBuffer
.append(cNameGuid
[0]);
1254 fileBuffer
.append(" = { ");
1255 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1256 fileBuffer
.append("} ;");
1261 LibInstanceToAutogenC
1263 This function adds dependent library instance to autogen.c,which
1264 includeing library's constructor, destructor, and library dependent ppi,
1265 protocol, guid, pcd information.
1268 String buffer for AutoGen.c
1269 @throws BuildException
1271 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1272 String moduleType
= this.moduleId
.getModuleType();
1274 // Add library constructor to AutoGen.c
1276 LibConstructorToAutogenC(libConstructList
, moduleType
, fileBuffer
);
1278 // Add library destructor to AutoGen.c
1280 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
);
1284 LibConstructorToAutogenH
1286 This function writes library constructor declarations AutoGen.h. The library
1287 constructor's parameter and return value depend on module type.
1289 @param libInstanceList
1290 List of library construct name.
1294 String buffer for AutoGen.c
1297 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1298 boolean isFirst
= true;
1301 // If not yet parse this library instance's constructor
1302 // element,parse it.
1304 String libConstructName
= saq
.getLibConstructorName();
1305 if (libConstructName
== null) {
1310 // The library constructor's parameter and return value depend on
1313 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1314 functionDeclarations
.append("RETURN_STATUS\r\n");
1315 functionDeclarations
.append("EFIAPI\r\n");
1316 functionDeclarations
.append(libConstructName
);
1317 functionDeclarations
.append(" (\r\n");
1318 functionDeclarations
.append(" VOID\r\n");
1319 functionDeclarations
.append(" );\r\n");
1321 switch (CommonDefinition
.getModuleType(moduleType
)) {
1322 case CommonDefinition
.ModuleTypeBase
:
1323 functionDeclarations
.append("RETURN_STATUS\r\n");
1324 functionDeclarations
.append("EFIAPI\r\n");
1325 functionDeclarations
.append(libConstructName
);
1326 functionDeclarations
.append(" (\r\n");
1327 functionDeclarations
.append(" VOID\r\n");
1328 functionDeclarations
.append(" );\r\n");
1331 case CommonDefinition
.ModuleTypePeiCore
:
1332 case CommonDefinition
.ModuleTypePeim
:
1333 functionDeclarations
.append("EFI_STATUS\r\n");
1334 functionDeclarations
.append("EFIAPI\r\n");
1335 functionDeclarations
.append(libConstructName
);
1336 functionDeclarations
.append(" (\r\n");
1337 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1338 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1339 functionDeclarations
.append(" );\r\n");
1342 case CommonDefinition
.ModuleTypeDxeCore
:
1343 case CommonDefinition
.ModuleTypeDxeDriver
:
1344 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1345 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1346 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1347 case CommonDefinition
.ModuleTypeUefiDriver
:
1348 case CommonDefinition
.ModuleTypeUefiApplication
:
1349 functionDeclarations
.append("EFI_STATUS\r\n");
1350 functionDeclarations
.append("EFIAPI\r\n");
1351 functionDeclarations
.append(libConstructName
);
1352 functionDeclarations
.append(" (\r\n");
1353 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1354 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1355 functionDeclarations
.append(" );\r\n");
1363 LibDestructorToAutogenH
1365 This function writes library destructor declarations AutoGen.h. The library
1366 destructor's parameter and return value depend on module type.
1368 @param libInstanceList
1369 List of library destructor name.
1373 String buffer for AutoGen.c
1376 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1377 boolean isFirst
= true;
1378 String libDestructName
= saq
.getLibDestructorName();
1379 if (libDestructName
== null) {
1383 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1384 functionDeclarations
.append("RETURN_STATUS\r\n");
1385 functionDeclarations
.append("EFIAPI\r\n");
1386 functionDeclarations
.append(libDestructName
);
1387 functionDeclarations
.append(" (\r\n");
1388 functionDeclarations
.append(" VOID\r\n");
1389 functionDeclarations
.append(" );\r\n");
1391 switch (CommonDefinition
.getModuleType(moduleType
)) {
1392 case CommonDefinition
.ModuleTypeBase
:
1393 functionDeclarations
.append("RETURN_STATUS\r\n");
1394 functionDeclarations
.append("EFIAPI\r\n");
1395 functionDeclarations
.append(libDestructName
);
1396 functionDeclarations
.append(" (\r\n");
1397 functionDeclarations
.append(" VOID\r\n");
1398 functionDeclarations
.append(" );\r\n");
1400 case CommonDefinition
.ModuleTypePeiCore
:
1401 case CommonDefinition
.ModuleTypePeim
:
1402 functionDeclarations
.append("EFI_STATUS\r\n");
1403 functionDeclarations
.append("EFIAPI\r\n");
1404 functionDeclarations
.append(libDestructName
);
1405 functionDeclarations
.append(" (\r\n");
1406 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1407 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1408 functionDeclarations
.append(" );\r\n");
1410 case CommonDefinition
.ModuleTypeDxeCore
:
1411 case CommonDefinition
.ModuleTypeDxeDriver
:
1412 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1413 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1414 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1415 case CommonDefinition
.ModuleTypeUefiDriver
:
1416 case CommonDefinition
.ModuleTypeUefiApplication
:
1417 functionDeclarations
.append("EFI_STATUS\r\n");
1418 functionDeclarations
.append("EFIAPI\r\n");
1419 functionDeclarations
.append(libDestructName
);
1420 functionDeclarations
.append(" (\r\n");
1421 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1422 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1423 functionDeclarations
.append(" );\r\n");
1430 LibConstructorToAutogenc
1432 This function writes library constructor list to AutoGen.c. The library
1433 constructor's parameter and return value depend on module type.
1435 @param libInstanceList
1436 List of library construct name.
1440 String buffer for AutoGen.c
1443 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1444 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1445 boolean isFirst
= true;
1448 // The library constructor's parameter and return value depend on
1451 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1452 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1453 functionDeclarations
.append("RETURN_STATUS\r\n");
1454 functionDeclarations
.append("EFIAPI\r\n");
1455 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1456 functionDeclarations
.append(" (\r\n");
1457 functionDeclarations
.append(" VOID\r\n");
1458 functionDeclarations
.append(" );\r\n");
1460 switch (CommonDefinition
.getModuleType(moduleType
)) {
1461 case CommonDefinition
.ModuleTypeBase
:
1462 functionDeclarations
.append("RETURN_STATUS\r\n");
1463 functionDeclarations
.append("EFIAPI\r\n");
1464 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1465 functionDeclarations
.append(" (\r\n");
1466 functionDeclarations
.append(" VOID\r\n");
1467 functionDeclarations
.append(" );\r\n");
1470 case CommonDefinition
.ModuleTypePeiCore
:
1471 case CommonDefinition
.ModuleTypePeim
:
1472 functionDeclarations
.append("EFI_STATUS\r\n");
1473 functionDeclarations
.append("EFIAPI\r\n");
1474 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1475 functionDeclarations
.append(" (\r\n");
1476 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1477 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1478 functionDeclarations
.append(" );\r\n");
1481 case CommonDefinition
.ModuleTypeDxeCore
:
1482 case CommonDefinition
.ModuleTypeDxeDriver
:
1483 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1484 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1485 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1486 case CommonDefinition
.ModuleTypeUefiDriver
:
1487 case CommonDefinition
.ModuleTypeUefiApplication
:
1488 functionDeclarations
.append("EFI_STATUS\r\n");
1489 functionDeclarations
.append("EFIAPI\r\n");
1490 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1491 functionDeclarations
.append(" (\r\n");
1492 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1493 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1494 functionDeclarations
.append(" );\r\n");
1502 // Add ProcessLibraryConstructorList in AutoGen.c
1504 fileBuffer
.append("VOID\r\n");
1505 fileBuffer
.append("EFIAPI\r\n");
1506 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1507 switch (CommonDefinition
.getModuleType(moduleType
)) {
1508 case CommonDefinition
.ModuleTypeBase
:
1509 fileBuffer
.append(" VOID\r\n");
1512 case CommonDefinition
.ModuleTypePeiCore
:
1513 case CommonDefinition
.ModuleTypePeim
:
1514 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1515 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1518 case CommonDefinition
.ModuleTypeDxeCore
:
1519 case CommonDefinition
.ModuleTypeDxeDriver
:
1520 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1521 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1522 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1523 case CommonDefinition
.ModuleTypeUefiDriver
:
1524 case CommonDefinition
.ModuleTypeUefiApplication
:
1525 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1526 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1530 fileBuffer
.append(" )\r\n");
1531 fileBuffer
.append("{\r\n");
1533 // If no constructor function, return EFI_SUCCESS.
1535 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1537 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1538 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1539 fileBuffer
.append("\r\n");
1542 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1543 fileBuffer
.append(" Status = ");
1544 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1545 fileBuffer
.append("();\r\n");
1547 switch (CommonDefinition
.getModuleType(moduleType
)) {
1548 case CommonDefinition
.ModuleTypeBase
:
1549 fileBuffer
.append(" Status = ");
1550 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1551 fileBuffer
.append("();\r\n");
1553 case CommonDefinition
.ModuleTypePeiCore
:
1554 case CommonDefinition
.ModuleTypePeim
:
1555 fileBuffer
.append(" Status = ");
1556 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1557 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1559 case CommonDefinition
.ModuleTypeDxeCore
:
1560 case CommonDefinition
.ModuleTypeDxeDriver
:
1561 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1562 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1563 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1564 case CommonDefinition
.ModuleTypeUefiDriver
:
1565 case CommonDefinition
.ModuleTypeUefiApplication
:
1566 fileBuffer
.append(" Status = ");
1567 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1568 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1571 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1575 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1577 fileBuffer
.append("}\r\n");
1581 LibDestructorToAutogenc
1583 This function writes library destructor list to AutoGen.c. The library
1584 destructor's parameter and return value depend on module type.
1586 @param libInstanceList
1587 List of library destructor name.
1591 String buffer for AutoGen.c
1594 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1595 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1596 boolean isFirst
= true;
1597 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1598 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1599 functionDeclarations
.append("RETURN_STATUS\r\n");
1600 functionDeclarations
.append("EFIAPI\r\n");
1601 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1602 functionDeclarations
.append(" (\r\n");
1603 functionDeclarations
.append(" VOID\r\n");
1604 functionDeclarations
.append(" );\r\n");
1606 switch (CommonDefinition
.getModuleType(moduleType
)) {
1607 case CommonDefinition
.ModuleTypeBase
:
1608 functionDeclarations
.append("RETURN_STATUS\r\n");
1609 functionDeclarations
.append("EFIAPI\r\n");
1610 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1611 functionDeclarations
.append(" (\r\n");
1612 functionDeclarations
.append(" VOID\r\n");
1613 functionDeclarations
.append(" );\r\n");
1615 case CommonDefinition
.ModuleTypePeiCore
:
1616 case CommonDefinition
.ModuleTypePeim
:
1617 functionDeclarations
.append("EFI_STATUS\r\n");
1618 functionDeclarations
.append("EFIAPI\r\n");
1619 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1620 functionDeclarations
.append(" (\r\n");
1621 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1622 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1623 functionDeclarations
.append(" );\r\n");
1625 case CommonDefinition
.ModuleTypeDxeCore
:
1626 case CommonDefinition
.ModuleTypeDxeDriver
:
1627 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1628 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1629 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1630 case CommonDefinition
.ModuleTypeUefiDriver
:
1631 case CommonDefinition
.ModuleTypeUefiApplication
:
1632 functionDeclarations
.append("EFI_STATUS\r\n");
1633 functionDeclarations
.append("EFIAPI\r\n");
1634 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1635 functionDeclarations
.append(" (\r\n");
1636 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1637 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1638 functionDeclarations
.append(" );\r\n");
1645 // Write ProcessLibraryDestructor list to autogen.c
1647 switch (CommonDefinition
.getModuleType(moduleType
)) {
1648 case CommonDefinition
.ModuleTypeBase
:
1649 case CommonDefinition
.ModuleTypePeiCore
:
1650 case CommonDefinition
.ModuleTypePeim
:
1652 case CommonDefinition
.ModuleTypeDxeCore
:
1653 case CommonDefinition
.ModuleTypeDxeDriver
:
1654 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1655 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1656 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1657 case CommonDefinition
.ModuleTypeUefiDriver
:
1658 case CommonDefinition
.ModuleTypeUefiApplication
:
1659 fileBuffer
.append("VOID\r\n");
1660 fileBuffer
.append("EFIAPI\r\n");
1661 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1662 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1663 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1664 fileBuffer
.append(" )\r\n");
1665 fileBuffer
.append("{\r\n");
1667 // If no library destructor function, return EFI_SUCCESS.
1670 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1672 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1673 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1674 fileBuffer
.append("\r\n");
1677 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1678 fileBuffer
.append(" Status = ");
1679 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1680 fileBuffer
.append("();\r\n");
1681 fileBuffer
.append(" VOID\r\n");
1683 fileBuffer
.append(" Status = ");
1684 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1685 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1686 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1689 fileBuffer
.append("}\r\n");
1695 ExternsDriverBindingToAutoGenC
1697 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1698 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1701 String buffer for AutoGen.c
1703 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1704 throws EdkException
{
1706 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1707 // The second dimension is include following element: DriverBinding,
1708 // ComponentName, DriverConfiguration, DriverDiag;
1710 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1719 // Write driver binding protocol extern to autogen.c
1721 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1722 if (driverBindingGroup
[i
][0] != null) {
1723 globalDeclarations
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1724 globalDeclarations
.append(driverBindingGroup
[i
][0]);
1725 globalDeclarations
.append(";\r\n");
1730 // Write component name protocol extern to autogen.c
1732 if (!componentNamePcd
) {
1733 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1734 if (driverBindingGroup
[i
][1]!= null) {
1735 if (driverBindingGroup
[i
][0] != null) {
1737 globalDeclarations
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1738 globalDeclarations
.append(driverBindingGroup
[i
][1]);
1739 globalDeclarations
.append(";\r\n");
1741 throw new AutoGenException("DriverBinding can't be empty!!");
1748 // Write driver configration protocol extern to autogen.c
1750 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1751 if (driverBindingGroup
[i
][2] != null) {
1752 if (driverBindingGroup
[i
][0] != null) {
1754 globalDeclarations
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1755 globalDeclarations
.append(driverBindingGroup
[i
][2]);
1756 globalDeclarations
.append(";\r\n");
1758 throw new AutoGenException("DriverBinding can't be empty!!");
1764 // Write driver dignastic protocol extern to autogen.c
1766 if (!driverDiagnostPcd
) {
1767 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1768 if (driverBindingGroup
[i
][3] != null) {
1769 if (driverBindingGroup
[i
][0] != null) {
1771 globalDeclarations
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1772 globalDeclarations
.append(driverBindingGroup
[i
][3]);
1773 globalDeclarations
.append(";\r\n");
1775 throw new AutoGenException("DriverBinding can't be empty!!");
1783 // Write driver module protocol bitmask.
1785 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1786 fileBuffer
.append(Integer
.toString(BitMask
));
1787 fileBuffer
.append(";\r\n");
1790 // Write driver module protocol list entry
1792 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1794 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1795 fileBuffer
.append(";\r\n");
1798 // Write drive module protocol list to autogen.c
1800 if (driverBindingGroup
.length
> 0) {
1801 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1805 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1807 fileBuffer
.append(",");
1812 fileBuffer
.append("\r\n {\r\n");
1813 fileBuffer
.append(" &");
1814 fileBuffer
.append(driverBindingGroup
[i
][0]);
1815 fileBuffer
.append(", \r\n");
1820 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1821 fileBuffer
.append(" &");
1822 fileBuffer
.append(driverBindingGroup
[i
][1]);
1823 fileBuffer
.append(", \r\n");
1825 fileBuffer
.append(" NULL, \r\n");
1829 // DriverConfiguration
1831 if (driverBindingGroup
[i
][2] != null) {
1832 fileBuffer
.append(" &");
1833 fileBuffer
.append(driverBindingGroup
[i
][2]);
1834 fileBuffer
.append(", \r\n");
1836 fileBuffer
.append(" NULL, \r\n");
1842 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1843 fileBuffer
.append(" &");
1844 fileBuffer
.append(driverBindingGroup
[i
][3]);
1845 fileBuffer
.append(", \r\n");
1847 fileBuffer
.append(" NULL, \r\n");
1849 fileBuffer
.append(" }");
1852 if (driverBindingGroup
.length
> 0) {
1853 fileBuffer
.append("\r\n};\r\n");
1858 ExternCallBackToAutoGenC
1860 This function adds <SetVirtualAddressMapCallBack> and
1861 <ExitBootServicesCallBack> infomation to AutoGen.c
1864 String buffer for AutoGen.c
1865 @throws BuildException
1867 void ExternCallBackToAutoGenH(String moduleType
)
1868 throws EdkException
{
1870 // Collect module's <SetVirtualAddressMapCallBack> and
1871 // <ExitBootServiceCallBack> and add to setVirtualAddList
1872 // exitBootServiceList.
1874 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1875 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1877 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1878 // and <ExitBootServicesCallBack>
1880 switch (CommonDefinition
.getModuleType(moduleType
)) {
1881 case CommonDefinition
.ModuleTypeDxeDriver
:
1882 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1883 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1884 case CommonDefinition
.ModuleTypeUefiDriver
:
1885 case CommonDefinition
.ModuleTypeUefiApplication
:
1887 // Write SetVirtualAddressMap function definition.
1889 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1890 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1893 functionDeclarations
.append("VOID\r\n");
1894 functionDeclarations
.append("EFIAPI\r\n");
1895 functionDeclarations
.append(setVirtuals
[i
]);
1896 functionDeclarations
.append(" (\r\n");
1897 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1898 functionDeclarations
.append(" IN VOID *Context\r\n");
1899 functionDeclarations
.append(" );\r\n\r\n");
1903 // Write DriverExitBootServices function definition.
1905 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1906 if (exitBoots
[i
].equalsIgnoreCase("")) {
1910 functionDeclarations
.append("VOID\r\n");
1911 functionDeclarations
.append("EFIAPI\r\n");
1912 functionDeclarations
.append(exitBoots
[i
]);
1913 functionDeclarations
.append(" (\r\n");
1914 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1915 functionDeclarations
.append(" IN VOID *Context\r\n");
1916 functionDeclarations
.append(" );\r\n\r\n");
1925 ExternCallBackToAutoGenC
1927 This function adds <SetVirtualAddressMapCallBack> and
1928 <ExitBootServicesCallBack> infomation to AutoGen.c
1931 String buffer for AutoGen.c
1932 @throws BuildException
1934 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1935 throws EdkException
{
1937 // Collect module's <SetVirtualAddressMapCallBack> and
1938 // <ExitBootServiceCallBack> and add to setVirtualAddList
1939 // exitBootServiceList.
1941 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1942 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1943 if (setVirtuals
!= null) {
1944 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
1945 this.setVirtalAddList
.add(setVirtuals
[j
]);
1948 if (exitBoots
!= null) {
1949 for (int k
= 0; k
< exitBoots
.length
; k
++) {
1950 this.exitBootServiceList
.add(exitBoots
[k
]);
1954 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1955 // and <ExitBootServicesCallBack>
1957 String moduleType
= this.moduleId
.getModuleType();
1958 switch (CommonDefinition
.getModuleType(moduleType
)) {
1959 case CommonDefinition
.ModuleTypeDxeDriver
:
1960 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1961 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1962 case CommonDefinition
.ModuleTypeUefiDriver
:
1963 case CommonDefinition
.ModuleTypeUefiApplication
:
1965 // If moduleType is one of above, call setVirtualAddressToAutogenC,
1966 // and setExitBootServiceToAutogenC.
1968 setVirtualAddressToAutogenC(fileBuffer
);
1969 setExitBootServiceToAutogenC(fileBuffer
);
1977 copyFlashMapHToDebugDir
1979 This function is to copy the falshmap.h to debug directory and change
1980 its name to TianoR8FlashMap.h
1985 private void copyFlashMapHToDebugDir() throws AutoGenException
{
1987 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
1988 int size
= (int)inFile
.length();
1989 byte[] buffer
= new byte[size
];
1990 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
1992 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
1995 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
1996 if (inFile
.exists()) {
1998 FileInputStream fis
= new FileInputStream (inFile
);
2000 FileOutputStream fos
= new FileOutputStream(outFile
);
2004 } catch (IOException e
) {
2005 throw new AutoGenException("The file, flashMap.h can't be open!");
2009 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2015 This function first order the library instances, then collect
2016 library instance 's PPI, Protocol, GUID,
2017 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2018 Destructor, Constructor.
2023 private void collectLibInstanceInfo() throws EdkException
{
2026 String moduleType
= moduleId
.getModuleType();
2027 String libConstructName
= null;
2028 String libDestructName
= null;
2029 String libModuleType
= null;
2030 String
[] setVirtuals
= null;
2031 String
[] exitBoots
= null;
2033 ModuleIdentification
[] libraryIdList
= saq
.getLibraryInstance(this.arch
);
2034 if (libraryIdList
.length
<= 0) {
2038 // Reorder library instance sequence.
2040 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
2041 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
2043 // Process library instance one by one.
2045 for (int i
= 0; i
< orderList
.size(); i
++) {
2047 // Get library instance basename.
2049 ModuleIdentification libInstanceId
= orderList
.get(i
);
2055 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2058 // check if the library instance support current module
2060 String
[] libraryClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
,
2064 if (libraryClassList
.length
<= 0) {
2065 throw new EdkException("Library instance " + libInstanceId
.getName()
2066 + " doesn't support module type " + moduleType
);
2069 // Get CName list from <PPis>, <Protocols>, <Guids>, etc. of this library
2072 String
[] guidCNameList
= saq
.getCNameArray(this.arch
);
2073 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2076 // Add those ppi, protocol, guid in global ppi,
2080 for (index
= 0; index
< guidCNameList
.length
; index
++) {
2081 this.mGuidCNameList
.add(guidCNameList
[index
]);
2084 for (index
= 0; index
< pkgList
.length
; index
++) {
2085 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2086 this.mDepPkgList
.add(pkgList
[index
]);
2091 // If not yet parse this library instance's constructor
2092 // element,parse it.
2094 libConstructName
= saq
.getLibConstructorName();
2095 libDestructName
= saq
.getLibDestructorName();
2096 libModuleType
= saq
.getModuleType();
2099 // Collect SetVirtualAddressMapCallBack and
2100 // ExitBootServiceCallBack.
2102 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2103 exitBoots
= saq
.getExitBootServicesCallBackArray();
2104 if (setVirtuals
!= null) {
2105 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2106 this.setVirtalAddList
.add(setVirtuals
[j
]);
2109 if (exitBoots
!= null) {
2110 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2111 this.exitBootServiceList
.add(exitBoots
[k
]);
2116 // Add dependent library instance constructor function.
2118 if (libConstructName
!= null) {
2119 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2122 // Add dependent library instance destructor fuction.
2124 if (libDestructName
!= null) {
2125 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2130 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2132 // Entry point lib for these module types needs to know the count
2135 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2138 // If the list is not valid or has no entries set count to zero else
2139 // set count to the number of valid entries
2143 if (this.setVirtalAddList
!= null) {
2144 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2145 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2152 fileBuffer
.append(Integer
.toString(Count
));
2153 fileBuffer
.append(";\r\n\r\n");
2154 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2156 // No data so make a NULL list
2158 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2159 fileBuffer
.append(" NULL\r\n");
2160 fileBuffer
.append("};\r\n\r\n");
2163 // Write SetVirtualAddressMap function definition.
2165 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2166 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2169 functionDeclarations
.append("VOID\r\n");
2170 functionDeclarations
.append("EFIAPI\r\n");
2171 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2172 functionDeclarations
.append(" (\r\n");
2173 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2174 functionDeclarations
.append(" IN VOID *Context\r\n");
2175 functionDeclarations
.append(" );\r\n\r\n");
2179 // Write SetVirtualAddressMap entry point array.
2181 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2182 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2183 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2188 fileBuffer
.append("\r\n ");
2190 fileBuffer
.append(",\r\n ");
2193 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2196 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2198 fileBuffer
.append(",\r\n NULL");
2199 fileBuffer
.append("\r\n};\r\n\r\n");
2204 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2206 // Entry point lib for these module types needs to know the count.
2208 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2211 // If the list is not valid or has no entries set count to zero else
2212 // set count to the number of valid entries.
2216 if (this.exitBootServiceList
!= null) {
2217 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2218 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2224 fileBuffer
.append(Integer
.toString(Count
));
2225 fileBuffer
.append(";\r\n\r\n");
2227 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2229 // No data so make a NULL list.
2231 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2232 fileBuffer
.append(" NULL\r\n");
2233 fileBuffer
.append("};\r\n\r\n");
2236 // Write DriverExitBootServices function definition.
2238 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2239 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2243 functionDeclarations
.append("VOID\r\n");
2244 functionDeclarations
.append("EFIAPI\r\n");
2245 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2246 functionDeclarations
.append(" (\r\n");
2247 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2248 functionDeclarations
.append(" IN VOID *Context\r\n");
2249 functionDeclarations
.append(" );\r\n\r\n");
2253 // Write DriverExitBootServices entry point array.
2255 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2256 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2257 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2262 fileBuffer
.append("\r\n ");
2264 fileBuffer
.append(",\r\n ");
2266 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2269 fileBuffer
.append(",\r\n NULL");
2270 fileBuffer
.append("\r\n};\r\n\r\n");
2276 Get the Pcd Value of ComponentName to
2277 decide whether need to disable the componentName.
2280 public void setPcdComponentName (){
2281 String pcdValue
= null;
2282 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2283 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2284 this.componentNamePcd
= true;
2289 setPcdDriverDiagnostic
2291 Get the Pcd Value of DriverDiagnostic to
2292 decide whether need to disable DriverDiagnostic.
2295 public void setPcdDriverDiagnostic (){
2296 String pcdValue
= null;
2297 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2298 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2299 this.driverDiagnostPcd
= true;