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 protocl list which records in module or library surface area and
86 /// it's dependence on library instance surface area.
88 private Set
<String
> mProtocolList
= new HashSet
<String
>();
91 /// The Ppi list which recorded in module or library surface area and its
92 /// dependency on library instance surface area.
94 private Set
<String
> mPpiList
= new HashSet
<String
>();
97 /// The Guid list which recoreded in module or library surface area and it's
98 /// dependence on library instance surface area.
100 private Set
<String
> mGuidList
= new HashSet
<String
>();
103 /// The dependence package list which recoreded in module or library surface
104 /// area and it's dependence on library instance surface area.
106 private List
<PackageIdentification
> mDepPkgList
= new LinkedList
<PackageIdentification
>();
109 /// For non library module, add its library instance's construct and destructor to
110 /// list. String[0] recode LibConstructor name, String[1] recode Lib instance
113 private List
<String
[]> libConstructList
= new ArrayList
<String
[]>();
114 private List
<String
[]> libDestructList
= new ArrayList
<String
[]>();
117 /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack
119 private List
<String
> setVirtalAddList
= new ArrayList
<String
>();
120 private List
<String
> exitBootServiceList
= new ArrayList
<String
>();
122 private StringBuffer functionDeclarations
= new StringBuffer(10240);
123 private StringBuffer globalDeclarations
= new StringBuffer(10240);
126 // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable
128 private boolean componentNamePcd
= false;
129 private boolean driverDiagnostPcd
= false;
132 // Instance of SurfaceAreaQuery
134 private SurfaceAreaQuery saq
= null;
136 private ModuleIdentification parentId
= null;
141 This function mainly initialize some member variable.
144 Absolute path of FV directory.
146 Output path of AutoGen file.
148 Module identification.
152 public AutoGen(String fvDir
, String outputPath
, ModuleIdentification moduleId
, String arch
, SurfaceAreaQuery saq
, ModuleIdentification parentId
) {
153 this.outputPath
= outputPath
;
154 this.moduleId
= moduleId
;
158 this.parentId
= parentId
;
164 This function save the content in stringBuffer to file.
169 The content of AutoGen file in buffer.
174 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
176 File autoGenH
= new File(fileName
);
179 // if the file exists, compare their content
181 if (autoGenH
.exists()) {
182 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
184 FileReader fIn
= new FileReader(autoGenH
);
185 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
187 } catch (IOException e
) {
188 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
191 + " is exist, but can't be open!!");
196 // if we got the same file, don't re-generate it to prevent
197 // sources depending on it from re-building
199 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
205 FileWriter fOut
= new FileWriter(autoGenH
);
206 fOut
.write(fileBuffer
.toString());
209 } catch (IOException e
) {
210 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
213 + " can't be create!!");
222 This function call libGenAutoGen or moduleGenAutogen function, which
223 dependence on generate library autogen or module autogen.
225 @throws BuildException
226 Failed to creat AutoGen.c & AutoGen.h.
228 public void genAutogen() throws EdkException
{
230 // If outputPath do not exist, create it.
232 File path
= new File(outputPath
);
236 // Check current is library or not, then call the corresponding
239 if (this.moduleId
.isLibrary()) {
247 moduleGenAutogen function
249 This function generates AutoGen.c & AutoGen.h for module.
251 @throws BuildException
252 Faile to create module AutoGen.c & AutoGen.h.
254 void moduleGenAutogen() throws EdkException
{
255 setPcdComponentName();
256 setPcdDriverDiagnostic();
257 collectLibInstanceInfo();
263 libGenAutogen function
265 This function generates AutoGen.c & AutoGen.h for library.
267 @throws BuildException
268 Faile to create library AutoGen.c & AutoGen.h
270 void libGenAutogen() throws EdkException
{
278 This function generates AutoGen.h for module.
280 @throws BuildException
281 Failed to generate AutoGen.h.
283 void moduleGenAutogenH() throws EdkException
{
285 Set
<String
> libClassIncludeH
;
287 // List<String> headerFileList;
288 List
<String
> headerFileList
;
290 StringBuffer fileBuffer
= new StringBuffer(8192);
293 // Write Autogen.h header notation
295 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
298 // Add #ifndef ${BaseName}_AUTOGENH
299 // #def ${BseeName}_AUTOGENH
301 fileBuffer
.append(CommonDefinition
.IFNDEF
302 + CommonDefinition
.AUTOGENH
303 + this.moduleId
.getGuid().replaceAll("-", "_")
304 + ToolDefinitions
.LINE_SEPARATOR
);
305 fileBuffer
.append(CommonDefinition
.DEFINE
306 + CommonDefinition
.AUTOGENH
307 + this.moduleId
.getGuid().replaceAll("-", "_")
308 + ToolDefinitions
.LINE_SEPARATOR
309 + ToolDefinitions
.LINE_SEPARATOR
);
312 // Write the specification version and release version at the begine
313 // of autogen.h file.
314 // Note: the specification version and release version should
315 // be got from module surface area instead of hard code by it's
318 moduleType
= saq
.getModuleType();
321 // Add "extern int __make_me_compile_correctly;" at begin of
324 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
327 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
329 String
[] specList
= saq
.getExternSpecificaiton();
330 for (int i
= 0; i
< specList
.length
; i
++) {
331 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
]
335 // Write consumed package's mdouleInfo related .h file to autogen.h
337 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
338 // .getDependencePkg(this.arch);
339 PackageIdentification
[] consumedPkgIdList
= saq
.getDependencePkg(this.arch
);
340 if (consumedPkgIdList
!= null) {
341 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
342 item
= headerFileList
.iterator();
343 while (item
.hasNext()) {
344 fileBuffer
.append(item
.next().toString());
349 // Write library class's related *.h file to autogen.h.
351 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
, null);
352 if (libClassList
.length
> 0) {
353 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
354 item
= libClassIncludeH
.iterator();
355 while (item
.hasNext()) {
356 fileBuffer
.append(item
.next().toString());
360 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
, null);
361 if (libClassList
.length
> 0) {
362 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
363 item
= libClassIncludeH
.iterator();
364 while (item
.hasNext()) {
365 fileBuffer
.append(item
.next().toString());
368 fileBuffer
.append("\r\n");
371 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
372 // {DEST_DIR_DRBUG}/FlashMap.h
374 if (saq
.isHaveTianoR8FlashMap()) {
375 fileBuffer
.append(CommonDefinition
.INCLUDE
);
376 fileBuffer
.append(" <");
377 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
378 copyFlashMapHToDebugDir();
381 // Write PCD autogen information to AutoGen.h.
383 if (this.myPcdAutogen
!= null) {
384 fileBuffer
.append("\r\n");
385 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
388 fileBuffer
.append(globalDeclarations
);
389 fileBuffer
.append(functionDeclarations
);
391 // Append the #endif at AutoGen.h
393 fileBuffer
.append("#endif\r\n");
396 // Save string buffer content in AutoGen.h.
398 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
399 throw new AutoGenException("Failed to generate AutoGen.h !!!");
406 This function generates AutoGen.c for module.
408 @throws BuildException
409 Failed to generate AutoGen.c.
411 void moduleGenAutogenC() throws EdkException
{
413 StringBuffer fileBuffer
= new StringBuffer(8192);
415 // Write Autogen.c header notation
417 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
420 // Get the native MSA file infomation. Since before call autogen,
421 // the MSA native <Externs> information were overrided. So before
422 // process <Externs> it should be set the DOC as the Native MSA info.
424 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
428 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
432 ExternsDriverBindingToAutoGenC(fileBuffer
);
435 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
438 ExternCallBackToAutoGenC(fileBuffer
);
441 // Write EntryPoint to autgoGen.c
443 String
[] entryPointList
= saq
.getModuleEntryPointArray();
444 String
[] unloadImageList
= saq
.getModuleUnloadImageArray();
445 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
),
446 CommonDefinition
.remDupString(unloadImageList
),
449 pcdDriverType
= saq
.getPcdDriverType();
452 // Restore the DOC which include the FPD module info.
457 // Write Guid to autogen.c
459 String guid
= CommonDefinition
.formatGuidName(saq
.getModuleGuid());
460 if (this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
461 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");
463 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
467 throw new AutoGenException("Guid value must set!\n");
471 // Formate Guid as ANSI c form.Example:
472 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
476 fileBuffer
.append(guid
);
477 fileBuffer
.append("};\r\n");
480 // Generate library instance consumed protocol, guid, ppi, pcd list.
481 // Save those to this.protocolList, this.ppiList, this.pcdList,
482 // this.guidList. Write Consumed library constructor and desconstuct to
485 LibInstanceToAutogenC(fileBuffer
);
488 // Get module dependent Package identification.
490 PackageIdentification
[] packages
= saq
.getDependencePkg(this.arch
);
491 for (int i
= 0; i
< packages
.length
; i
++) {
492 if (!this.mDepPkgList
.contains(packages
[i
])) {
493 this.mDepPkgList
.add(packages
[i
]);
499 // Write consumed ppi, guid, protocol to autogen.c
501 ProtocolGuidToAutogenC(fileBuffer
);
502 PpiGuidToAutogenC(fileBuffer
);
503 GuidGuidToAutogenC(fileBuffer
);
508 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
515 this.myPcdAutogen
.execute();
516 if (this.myPcdAutogen
!= null) {
517 fileBuffer
.append("\r\n");
518 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
521 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
522 throw new AutoGenException("Failed to generate AutoGen.c !!!");
530 This function generates AutoGen.h for library.
532 @throws BuildException
533 Failed to generate AutoGen.c.
535 void libGenAutogenH() throws EdkException
{
537 Set
<String
> libClassIncludeH
;
539 List
<String
> headerFileList
;
541 StringBuffer fileBuffer
= new StringBuffer(10240);
544 // Write Autogen.h header notation
546 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
549 // Add #ifndef ${BaseName}_AUTOGENH
550 // #def ${BseeName}_AUTOGENH
552 fileBuffer
.append(CommonDefinition
.IFNDEF
553 + CommonDefinition
.AUTOGENH
554 + this.moduleId
.getGuid().replaceAll("-", "_")
555 + ToolDefinitions
.LINE_SEPARATOR
);
556 fileBuffer
.append(CommonDefinition
.DEFINE
557 + CommonDefinition
.AUTOGENH
558 + this.moduleId
.getGuid().replaceAll("-", "_")
559 + ToolDefinitions
.LINE_SEPARATOR
560 + ToolDefinitions
.LINE_SEPARATOR
);
563 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
564 // to autogen.h file.
565 // Note: the specification version and release version should
566 // be get from module surface area instead of hard code.
568 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
569 String
[] specList
= saq
.getExternSpecificaiton();
570 for (int i
= 0; i
< specList
.length
; i
++) {
571 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
] + "\r\n");
573 // fileBuffer.append(CommonDefinition.autoGenHLine1);
574 // fileBuffer.append(CommonDefinition.autoGenHLine2);
577 // Write consumed package's mdouleInfo related *.h file to autogen.h.
579 moduleType
= saq
.getModuleType();
580 PackageIdentification
[] cosumedPkglist
= saq
.getDependencePkg(this.arch
);
581 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
582 item
= headerFileList
.iterator();
583 while (item
.hasNext()) {
584 fileBuffer
.append(item
.next().toString());
587 // Write library class's related *.h file to autogen.h
589 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
, null);
590 if (libClassList
!= null) {
591 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
592 item
= libClassIncludeH
.iterator();
593 while (item
.hasNext()) {
594 fileBuffer
.append(item
.next().toString());
598 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
, null);
599 if (libClassList
!= null) {
600 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
601 item
= libClassIncludeH
.iterator();
602 while (item
.hasNext()) {
603 fileBuffer
.append(item
.next().toString());
606 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
609 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
610 // {DEST_DIR_DRBUG}/FlashMap.h
612 if (saq
.isHaveTianoR8FlashMap()) {
613 fileBuffer
.append(CommonDefinition
.INCLUDE
);
614 fileBuffer
.append(" <");
615 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
616 copyFlashMapHToDebugDir();
620 // Write PCD information to library AutoGen.h.
622 if (this.myPcdAutogen
!= null) {
623 fileBuffer
.append("\r\n");
624 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
627 // generate function prototype for constructor and destructor
629 LibConstructorToAutogenH(moduleType
);
630 LibDestructorToAutogenH(moduleType
);
631 ExternCallBackToAutoGenH(moduleType
);
632 fileBuffer
.append(functionDeclarations
);
634 // Append the #endif at AutoGen.h
636 fileBuffer
.append("#endif\r\n");
638 // Save content of string buffer to AutoGen.h file.
640 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
641 throw new AutoGenException("Failed to generate AutoGen.h !!!");
648 This function generates AutoGen.h for library.
650 @throws BuildException
651 Failed to generate AutoGen.c.
653 void libGenAutogenC() throws EdkException
{
654 StringBuffer fileBuffer
= new StringBuffer(10240);
657 // Write Autogen.c header notation
659 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
661 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
662 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
667 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
670 saq
.getModulePcdEntryNameArray(this.arch
),
673 this.myPcdAutogen
.execute();
674 if (this.myPcdAutogen
!= null) {
675 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
676 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
681 LibraryClassToAutogenH
683 This function returns *.h files declared by library classes which are
684 consumed or produced by current build module or library.
687 List of library class which consumed or produce by current
688 build module or library.
689 @return includeStrList List of *.h file.
691 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
)
692 throws EdkException
{
693 Set
<String
> includeStrList
= new LinkedHashSet
<String
>();
694 String includeName
[];
698 // Get include file from GlobalData's SPDTable according to
699 // library class name.
701 for (int i
= 0; i
< libClassList
.length
; i
++) {
702 includeName
= GlobalData
.getLibraryClassHeaderFiles(
703 saq
.getDependencePkg(this.arch
),
705 if (includeName
== null) {
706 throw new AutoGenException("Can not find library class ["
707 + libClassList
[i
] + "] declaration in any SPD package. ");
709 for (int j
= 0; j
< includeName
.length
; j
++) {
710 String includeNameStr
= includeName
[j
];
711 if (includeNameStr
!= null) {
712 str
= CommonDefinition
.INCLUDE
+ " " + "<";
713 str
= str
+ includeNameStr
+ ">\r\n";
714 includeStrList
.add(str
);
715 includeNameStr
= null;
719 return includeStrList
;
725 This function add include file in AutoGen.h file.
727 @param packageNameList
728 List of module depended package.
733 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
734 String moduleType
) throws AutoGenException
{
736 List
<String
> includeStrList
= new LinkedList
<String
>();
738 String includeStr
= "";
741 // Get include file from moduleInfo file
743 for (int i
= 0; i
< packageNameList
.length
; i
++) {
744 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
746 if (pkgHeader
== null) {
747 throw new AutoGenException("Can not find package ["
749 + "] declaration in any SPD package. ");
750 } else if (!pkgHeader
.equalsIgnoreCase("")) {
751 includeStr
= CommonDefinition
.INCLUDE
+ " <" + pkgHeader
+ ">\r\n";
752 includeStrList
.add(includeStr
);
756 return includeStrList
;
762 This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
763 information in mas to AutoGen.c
765 @param entryPointList
768 String buffer fo AutoGen.c.
771 void EntryPointToAutoGen(String
[] entryPointList
, String
[] unloadImageList
, StringBuffer fileBuffer
)
772 throws EdkException
{
774 String typeStr
= saq
.getModuleType();
775 String debugStr
= "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";
776 int unloadImageCount
= 0;
777 int entryPointCount
= 0;
780 // The parameters and return value of entryPoint is difference
781 // for difference module type.
783 switch (CommonDefinition
.getModuleType(typeStr
)) {
785 case CommonDefinition
.ModuleTypePeiCore
:
786 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
787 throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");
789 functionDeclarations
.append("EFI_STATUS\r\n");
790 functionDeclarations
.append("EFIAPI\r\n");
791 functionDeclarations
.append(entryPointList
[0]);
792 functionDeclarations
.append(" (\r\n");
793 functionDeclarations
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
794 functionDeclarations
.append(" IN VOID *OldCoreData\r\n");
795 functionDeclarations
.append(" );\r\n\r\n");
797 fileBuffer
.append("EFI_STATUS\r\n");
798 fileBuffer
.append("EFIAPI\r\n");
799 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
800 fileBuffer
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
801 fileBuffer
.append(" IN VOID *OldCoreData\r\n");
802 fileBuffer
.append(" )\r\n\r\n");
803 fileBuffer
.append("{\r\n");
804 fileBuffer
.append(" return ");
805 fileBuffer
.append(entryPointList
[0]);
806 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
807 fileBuffer
.append("}\r\n\r\n");
811 case CommonDefinition
.ModuleTypeDxeCore
:
812 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
813 if (entryPointList
== null || entryPointList
.length
!= 1) {
814 throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");
816 functionDeclarations
.append("VOID\r\n");
817 functionDeclarations
.append("EFIAPI\r\n");
818 functionDeclarations
.append(entryPointList
[0]);
819 functionDeclarations
.append(" (\r\n");
820 functionDeclarations
.append(" IN VOID *HobStart\r\n");
821 functionDeclarations
.append(" );\r\n\r\n");
823 fileBuffer
.append("VOID\r\n");
824 fileBuffer
.append("EFIAPI\r\n");
825 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
826 fileBuffer
.append(" IN VOID *HobStart\r\n");
827 fileBuffer
.append(" )\r\n\r\n");
828 fileBuffer
.append("{\r\n");
829 fileBuffer
.append(" ");
830 fileBuffer
.append(entryPointList
[0]);
831 fileBuffer
.append(" (HobStart);\r\n");
832 fileBuffer
.append("}\r\n\r\n");
836 case CommonDefinition
.ModuleTypePeim
:
838 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
839 if (entryPointList
== null || entryPointList
.length
== 0) {
840 fileBuffer
.append("EFI_STATUS\r\n");
841 fileBuffer
.append("EFIAPI\r\n");
842 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
843 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
844 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
845 fileBuffer
.append(" )\r\n\r\n");
846 fileBuffer
.append("{\r\n");
847 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
848 fileBuffer
.append("}\r\n\r\n");
851 for (int i
= 0; i
< entryPointList
.length
; i
++) {
852 functionDeclarations
.append("EFI_STATUS\r\n");
853 functionDeclarations
.append("EFIAPI\r\n");
854 functionDeclarations
.append(entryPointList
[i
]);
855 functionDeclarations
.append(" (\r\n");
856 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
857 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
858 functionDeclarations
.append(" );\r\n");
862 fileBuffer
.append("EFI_STATUS\r\n");
863 fileBuffer
.append("EFIAPI\r\n");
864 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
865 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
866 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
867 fileBuffer
.append(" )\r\n\r\n");
868 fileBuffer
.append("{\r\n");
869 if (entryPointCount
== 1) {
870 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
871 fileBuffer
.append(" return ");
872 fileBuffer
.append(entryPointList
[0]);
873 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
875 fileBuffer
.append(" EFI_STATUS Status;\r\n");
876 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
877 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
878 for (int i
= 0; i
< entryPointList
.length
; i
++) {
879 if (!entryPointList
[i
].equals("")) {
880 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
881 fileBuffer
.append(" Status = ");
882 fileBuffer
.append(entryPointList
[i
]);
883 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
884 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
885 fileBuffer
.append(" CombinedStatus = Status;\r\n");
886 fileBuffer
.append(" }\r\n\r\n");
891 fileBuffer
.append(" return CombinedStatus;\r\n");
893 fileBuffer
.append("}\r\n\r\n");
896 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
899 // If entryPoint is null, create an empty ProcessModuleEntryPointList
902 if (entryPointList
== null || entryPointList
.length
== 0) {
903 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
904 fileBuffer
.append(Integer
.toString(entryPointCount
));
905 fileBuffer
.append(";\r\n");
906 fileBuffer
.append("EFI_STATUS\r\n");
907 fileBuffer
.append("EFIAPI\r\n");
908 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
909 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
910 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
911 fileBuffer
.append(" )\r\n\r\n");
912 fileBuffer
.append("{\r\n");
913 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
914 fileBuffer
.append("}\r\n\r\n");
917 for (int i
= 0; i
< entryPointList
.length
; i
++) {
918 functionDeclarations
.append("EFI_STATUS\r\n");
919 functionDeclarations
.append("EFIAPI\r\n");
920 functionDeclarations
.append(entryPointList
[i
]);
921 functionDeclarations
.append(" (\r\n");
922 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
923 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
924 functionDeclarations
.append(" );\r\n");
927 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
928 fileBuffer
.append(Integer
.toString(entryPointCount
));
929 fileBuffer
.append(";\r\n");
930 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
931 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
933 fileBuffer
.append("EFI_STATUS\r\n");
934 fileBuffer
.append("EFIAPI\r\n");
935 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
936 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
937 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
938 fileBuffer
.append(" )\r\n\r\n");
939 fileBuffer
.append("{\r\n");
941 for (int i
= 0; i
< entryPointList
.length
; i
++) {
942 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
943 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
944 fileBuffer
.append(" ExitDriver (");
945 fileBuffer
.append(entryPointList
[i
]);
946 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
947 fileBuffer
.append(" ASSERT (FALSE);\r\n");
948 fileBuffer
.append(" }\r\n");
950 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
951 fileBuffer
.append("}\r\n\r\n");
953 fileBuffer
.append("VOID\r\n");
954 fileBuffer
.append("EFIAPI\r\n");
955 fileBuffer
.append("ExitDriver (\r\n");
956 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
957 fileBuffer
.append(" )\r\n\r\n");
958 fileBuffer
.append("{\r\n");
959 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
960 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
961 fileBuffer
.append(" }\r\n");
962 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
963 fileBuffer
.append(" ASSERT (FALSE);\r\n");
964 fileBuffer
.append("}\r\n\r\n");
969 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
972 unloadImageCount
= 0;
973 if (unloadImageList
!= null) {
974 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
975 functionDeclarations
.append("EFI_STATUS\r\n");
976 functionDeclarations
.append(unloadImageList
[i
]);
977 functionDeclarations
.append(" (\r\n");
978 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
979 functionDeclarations
.append(" );\r\n");
984 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
985 fileBuffer
.append(Integer
.toString(unloadImageCount
));
986 fileBuffer
.append(";\r\n\r\n");
988 fileBuffer
.append("EFI_STATUS\r\n");
989 fileBuffer
.append("EFIAPI\r\n");
990 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
991 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
992 fileBuffer
.append(" )\r\n");
993 fileBuffer
.append("{\r\n");
995 if (unloadImageCount
== 0) {
996 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
997 } else if (unloadImageCount
== 1) {
998 fileBuffer
.append(" return ");
999 fileBuffer
.append(unloadImageList
[0]);
1000 fileBuffer
.append("(ImageHandle);\r\n");
1002 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1003 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1004 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1006 fileBuffer
.append(" Status = ");
1007 fileBuffer
.append(unloadImageList
[i
]);
1008 fileBuffer
.append("(ImageHandle);\r\n");
1010 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1011 fileBuffer
.append(" ");
1012 fileBuffer
.append(unloadImageList
[i
]);
1013 fileBuffer
.append("(ImageHandle);\r\n");
1014 fileBuffer
.append(" } else {\r\n");
1015 fileBuffer
.append(" Status = ");
1016 fileBuffer
.append(unloadImageList
[i
]);
1017 fileBuffer
.append("(ImageHandle);\r\n");
1018 fileBuffer
.append(" }\r\n");
1021 fileBuffer
.append(" return Status;\r\n");
1023 fileBuffer
.append("}\r\n\r\n");
1026 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1027 case CommonDefinition
.ModuleTypeDxeDriver
:
1028 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1029 case CommonDefinition
.ModuleTypeUefiDriver
:
1030 case CommonDefinition
.ModuleTypeUefiApplication
:
1031 entryPointCount
= 0;
1032 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1034 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1036 if (entryPointList
== null || entryPointList
.length
== 0) {
1037 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1038 fileBuffer
.append("EFI_STATUS\r\n");
1039 fileBuffer
.append("EFIAPI\r\n");
1040 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1041 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1042 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1043 fileBuffer
.append(" )\r\n\r\n");
1044 fileBuffer
.append("{\r\n");
1045 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1046 fileBuffer
.append("}\r\n");
1049 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1050 functionDeclarations
.append("EFI_STATUS\r\n");
1051 functionDeclarations
.append("EFIAPI\r\n");
1052 functionDeclarations
.append(entryPointList
[i
]);
1053 functionDeclarations
.append(" (\r\n");
1054 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1055 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1056 functionDeclarations
.append(" );\r\n");
1060 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1061 fileBuffer
.append(Integer
.toString(entryPointCount
));
1062 fileBuffer
.append(";\r\n");
1063 if (entryPointCount
> 1) {
1064 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1065 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1067 fileBuffer
.append("\r\n");
1069 fileBuffer
.append("EFI_STATUS\r\n");
1070 fileBuffer
.append("EFIAPI\r\n");
1071 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1072 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1073 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1074 fileBuffer
.append(" )\r\n\r\n");
1075 fileBuffer
.append("{\r\n");
1077 if (entryPointCount
== 1) {
1078 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
1079 fileBuffer
.append(" return ");
1080 fileBuffer
.append(entryPointList
[0]);
1081 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1083 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1084 if (!entryPointList
[i
].equals("")) {
1085 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1086 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
1087 fileBuffer
.append(" ExitDriver (");
1088 fileBuffer
.append(entryPointList
[i
]);
1089 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1090 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1091 fileBuffer
.append(" }\r\n");
1096 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1098 fileBuffer
.append("}\r\n\r\n");
1100 fileBuffer
.append("VOID\r\n");
1101 fileBuffer
.append("EFIAPI\r\n");
1102 fileBuffer
.append("ExitDriver (\r\n");
1103 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1104 fileBuffer
.append(" )\r\n\r\n");
1105 fileBuffer
.append("{\r\n");
1106 if (entryPointCount
<= 1) {
1107 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1108 fileBuffer
.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1109 fileBuffer
.append(" }\r\n");
1111 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1113 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1114 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1115 fileBuffer
.append(" }\r\n");
1116 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1117 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1119 fileBuffer
.append("}\r\n\r\n");
1123 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1125 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1127 // Remover duplicate unload entry point.
1129 //entryPointList = CommonDefinition.remDupString(entryPointList);
1130 //entryPointCount = 0;
1131 unloadImageCount
= 0;
1132 if (unloadImageList
!= null) {
1133 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1134 functionDeclarations
.append("EFI_STATUS\r\n");
1135 functionDeclarations
.append("EFIAPI\r\n");
1136 functionDeclarations
.append(unloadImageList
[i
]);
1137 functionDeclarations
.append(" (\r\n");
1138 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
1139 functionDeclarations
.append(" );\r\n");
1144 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1145 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1146 fileBuffer
.append(";\r\n\r\n");
1148 fileBuffer
.append("EFI_STATUS\r\n");
1149 fileBuffer
.append("EFIAPI\r\n");
1150 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1151 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1152 fileBuffer
.append(" )\r\n");
1153 fileBuffer
.append("{\r\n");
1155 if (unloadImageCount
== 0) {
1156 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1157 } else if (unloadImageCount
== 1) {
1158 fileBuffer
.append(" return ");
1159 fileBuffer
.append(unloadImageList
[0]);
1160 fileBuffer
.append("(ImageHandle);\r\n");
1162 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1163 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1164 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1166 fileBuffer
.append(" Status = ");
1167 fileBuffer
.append(unloadImageList
[i
]);
1168 fileBuffer
.append("(ImageHandle);\r\n");
1170 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1171 fileBuffer
.append(" ");
1172 fileBuffer
.append(unloadImageList
[i
]);
1173 fileBuffer
.append("(ImageHandle);\r\n");
1174 fileBuffer
.append(" } else {\r\n");
1175 fileBuffer
.append(" Status = ");
1176 fileBuffer
.append(unloadImageList
[i
]);
1177 fileBuffer
.append("(ImageHandle);\r\n");
1178 fileBuffer
.append(" }\r\n");
1181 fileBuffer
.append(" return Status;\r\n");
1183 fileBuffer
.append("}\r\n\r\n");
1191 This function gets GUIDs from SPD file accrodeing to <PPIs> information
1192 and write those GUIDs to AutoGen.c.
1195 String Buffer for Autogen.c file.
1196 @throws BuildException
1197 Guid must set value!
1199 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1200 String
[] cNameGuid
= null;
1203 // Get the all PPI adn PPI Notify from MSA file,
1204 // then add those PPI ,and PPI Notify name to list.
1207 String
[] ppiList
= saq
.getPpiArray(this.arch
);
1208 for (int i
= 0; i
< ppiList
.length
; i
++) {
1209 this.mPpiList
.add(ppiList
[i
]);
1212 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
1213 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1214 this.mPpiList
.add(ppiNotifyList
[i
]);
1218 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1220 Iterator ppiIterator
= this.mPpiList
.iterator();
1221 String ppiKeyWord
= null;
1222 while (ppiIterator
.hasNext()) {
1223 ppiKeyWord
= ppiIterator
.next().toString();
1224 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1225 if (cNameGuid
!= null) {
1226 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1227 fileBuffer
.append(cNameGuid
[0]);
1228 fileBuffer
.append(" = { ");
1229 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1230 fileBuffer
.append(" } ;");
1233 // If can't find Ppi GUID declaration in every package
1235 throw new AutoGenException("Can not find Ppi GUID ["
1236 + ppiKeyWord
+ "] declaration in any SPD package!");
1242 ProtocolGuidToAutogenc
1244 This function gets GUIDs from SPD file accrodeing to <Protocol>
1245 information and write those GUIDs to AutoGen.c.
1248 String Buffer for Autogen.c file.
1249 @throws BuildException
1250 Protocol name must set.
1252 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1253 String
[] cNameGuid
= null;
1255 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
1258 // Add result to Autogen global list.
1260 for (int i
= 0; i
< protocolList
.length
; i
++) {
1261 this.mProtocolList
.add(protocolList
[i
]);
1264 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
1266 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1267 this.mProtocolList
.add(protocolNotifyList
[i
]);
1271 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1273 Iterator protocolIterator
= this.mProtocolList
.iterator();
1274 String protocolKeyWord
= null;
1277 while (protocolIterator
.hasNext()) {
1278 protocolKeyWord
= protocolIterator
.next().toString();
1279 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1280 if (cNameGuid
!= null) {
1281 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1282 fileBuffer
.append(cNameGuid
[0]);
1283 fileBuffer
.append(" = { ");
1284 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1285 fileBuffer
.append(" } ;");
1288 // If can't find protocol GUID declaration in every package
1290 throw new AutoGenException("Can not find protocol Guid ["
1291 + protocolKeyWord
+ "] declaration in any SPD package!");
1299 This function gets GUIDs from SPD file accrodeing to <Guids> information
1300 and write those GUIDs to AutoGen.c.
1303 String Buffer for Autogen.c file.
1306 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1307 String
[] cNameGuid
= null;
1308 String guidKeyWord
= null;
1310 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
1312 for (int i
= 0; i
< guidList
.length
; i
++) {
1313 this.mGuidList
.add(guidList
[i
]);
1317 Iterator guidIterator
= this.mGuidList
.iterator();
1318 while (guidIterator
.hasNext()) {
1319 guidKeyWord
= guidIterator
.next().toString();
1320 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1322 if (cNameGuid
!= null) {
1323 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1324 fileBuffer
.append(cNameGuid
[0]);
1325 fileBuffer
.append(" = { ");
1326 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1327 fileBuffer
.append("} ;");
1330 // If can't find GUID declaration in every package
1332 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1333 + "] declaration in any SPD package. ");
1340 LibInstanceToAutogenC
1342 This function adds dependent library instance to autogen.c,which
1343 includeing library's constructor, destructor, and library dependent ppi,
1344 protocol, guid, pcd information.
1347 String buffer for AutoGen.c
1348 @throws BuildException
1350 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1351 String moduleType
= this.moduleId
.getModuleType();
1353 // Add library constructor to AutoGen.c
1355 LibConstructorToAutogenC(libConstructList
, moduleType
, fileBuffer
);
1357 // Add library destructor to AutoGen.c
1359 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
);
1363 LibConstructorToAutogenH
1365 This function writes library constructor declarations AutoGen.h. The library
1366 constructor's parameter and return value depend on module type.
1368 @param libInstanceList
1369 List of library construct name.
1373 String buffer for AutoGen.c
1376 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1377 boolean isFirst
= true;
1380 // If not yet parse this library instance's constructor
1381 // element,parse it.
1383 String libConstructName
= saq
.getLibConstructorName();
1384 if (libConstructName
== null) {
1389 // The library constructor's parameter and return value depend on
1392 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1393 functionDeclarations
.append("RETURN_STATUS\r\n");
1394 functionDeclarations
.append("EFIAPI\r\n");
1395 functionDeclarations
.append(libConstructName
);
1396 functionDeclarations
.append(" (\r\n");
1397 functionDeclarations
.append(" VOID\r\n");
1398 functionDeclarations
.append(" );\r\n");
1400 switch (CommonDefinition
.getModuleType(moduleType
)) {
1401 case CommonDefinition
.ModuleTypeBase
:
1402 functionDeclarations
.append("RETURN_STATUS\r\n");
1403 functionDeclarations
.append("EFIAPI\r\n");
1404 functionDeclarations
.append(libConstructName
);
1405 functionDeclarations
.append(" (\r\n");
1406 functionDeclarations
.append(" VOID\r\n");
1407 functionDeclarations
.append(" );\r\n");
1410 case CommonDefinition
.ModuleTypePeiCore
:
1411 case CommonDefinition
.ModuleTypePeim
:
1412 functionDeclarations
.append("EFI_STATUS\r\n");
1413 functionDeclarations
.append("EFIAPI\r\n");
1414 functionDeclarations
.append(libConstructName
);
1415 functionDeclarations
.append(" (\r\n");
1416 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1417 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1418 functionDeclarations
.append(" );\r\n");
1421 case CommonDefinition
.ModuleTypeDxeCore
:
1422 case CommonDefinition
.ModuleTypeDxeDriver
:
1423 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1424 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1425 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1426 case CommonDefinition
.ModuleTypeUefiDriver
:
1427 case CommonDefinition
.ModuleTypeUefiApplication
:
1428 functionDeclarations
.append("EFI_STATUS\r\n");
1429 functionDeclarations
.append("EFIAPI\r\n");
1430 functionDeclarations
.append(libConstructName
);
1431 functionDeclarations
.append(" (\r\n");
1432 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1433 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1434 functionDeclarations
.append(" );\r\n");
1442 LibDestructorToAutogenH
1444 This function writes library destructor declarations AutoGen.h. The library
1445 destructor's parameter and return value depend on module type.
1447 @param libInstanceList
1448 List of library destructor name.
1452 String buffer for AutoGen.c
1455 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1456 boolean isFirst
= true;
1457 String libDestructName
= saq
.getLibDestructorName();
1458 if (libDestructName
== null) {
1462 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1463 functionDeclarations
.append("RETURN_STATUS\r\n");
1464 functionDeclarations
.append("EFIAPI\r\n");
1465 functionDeclarations
.append(libDestructName
);
1466 functionDeclarations
.append(" (\r\n");
1467 functionDeclarations
.append(" VOID\r\n");
1468 functionDeclarations
.append(" );\r\n");
1470 switch (CommonDefinition
.getModuleType(moduleType
)) {
1471 case CommonDefinition
.ModuleTypeBase
:
1472 functionDeclarations
.append("RETURN_STATUS\r\n");
1473 functionDeclarations
.append("EFIAPI\r\n");
1474 functionDeclarations
.append(libDestructName
);
1475 functionDeclarations
.append(" (\r\n");
1476 functionDeclarations
.append(" VOID\r\n");
1477 functionDeclarations
.append(" );\r\n");
1479 case CommonDefinition
.ModuleTypePeiCore
:
1480 case CommonDefinition
.ModuleTypePeim
:
1481 functionDeclarations
.append("EFI_STATUS\r\n");
1482 functionDeclarations
.append("EFIAPI\r\n");
1483 functionDeclarations
.append(libDestructName
);
1484 functionDeclarations
.append(" (\r\n");
1485 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1486 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1487 functionDeclarations
.append(" );\r\n");
1489 case CommonDefinition
.ModuleTypeDxeCore
:
1490 case CommonDefinition
.ModuleTypeDxeDriver
:
1491 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1492 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1493 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1494 case CommonDefinition
.ModuleTypeUefiDriver
:
1495 case CommonDefinition
.ModuleTypeUefiApplication
:
1496 functionDeclarations
.append("EFI_STATUS\r\n");
1497 functionDeclarations
.append("EFIAPI\r\n");
1498 functionDeclarations
.append(libDestructName
);
1499 functionDeclarations
.append(" (\r\n");
1500 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1501 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1502 functionDeclarations
.append(" );\r\n");
1509 LibConstructorToAutogenc
1511 This function writes library constructor list to AutoGen.c. The library
1512 constructor's parameter and return value depend on module type.
1514 @param libInstanceList
1515 List of library construct name.
1519 String buffer for AutoGen.c
1522 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1523 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1524 boolean isFirst
= true;
1527 // The library constructor's parameter and return value depend on
1530 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1531 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1532 functionDeclarations
.append("RETURN_STATUS\r\n");
1533 functionDeclarations
.append("EFIAPI\r\n");
1534 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1535 functionDeclarations
.append(" (\r\n");
1536 functionDeclarations
.append(" VOID\r\n");
1537 functionDeclarations
.append(" );\r\n");
1539 switch (CommonDefinition
.getModuleType(moduleType
)) {
1540 case CommonDefinition
.ModuleTypeBase
:
1541 functionDeclarations
.append("RETURN_STATUS\r\n");
1542 functionDeclarations
.append("EFIAPI\r\n");
1543 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1544 functionDeclarations
.append(" (\r\n");
1545 functionDeclarations
.append(" VOID\r\n");
1546 functionDeclarations
.append(" );\r\n");
1549 case CommonDefinition
.ModuleTypePeiCore
:
1550 case CommonDefinition
.ModuleTypePeim
:
1551 functionDeclarations
.append("EFI_STATUS\r\n");
1552 functionDeclarations
.append("EFIAPI\r\n");
1553 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1554 functionDeclarations
.append(" (\r\n");
1555 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1556 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1557 functionDeclarations
.append(" );\r\n");
1560 case CommonDefinition
.ModuleTypeDxeCore
:
1561 case CommonDefinition
.ModuleTypeDxeDriver
:
1562 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1563 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1564 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1565 case CommonDefinition
.ModuleTypeUefiDriver
:
1566 case CommonDefinition
.ModuleTypeUefiApplication
:
1567 functionDeclarations
.append("EFI_STATUS\r\n");
1568 functionDeclarations
.append("EFIAPI\r\n");
1569 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1570 functionDeclarations
.append(" (\r\n");
1571 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1572 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1573 functionDeclarations
.append(" );\r\n");
1581 // Add ProcessLibraryConstructorList in AutoGen.c
1583 fileBuffer
.append("VOID\r\n");
1584 fileBuffer
.append("EFIAPI\r\n");
1585 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1586 switch (CommonDefinition
.getModuleType(moduleType
)) {
1587 case CommonDefinition
.ModuleTypeBase
:
1588 fileBuffer
.append(" VOID\r\n");
1591 case CommonDefinition
.ModuleTypePeiCore
:
1592 case CommonDefinition
.ModuleTypePeim
:
1593 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1595 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1598 case CommonDefinition
.ModuleTypeDxeCore
:
1599 case CommonDefinition
.ModuleTypeDxeDriver
:
1600 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1601 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1602 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1603 case CommonDefinition
.ModuleTypeUefiDriver
:
1604 case CommonDefinition
.ModuleTypeUefiApplication
:
1605 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1606 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1610 fileBuffer
.append(" )\r\n");
1611 fileBuffer
.append("{\r\n");
1613 // If no constructor function, return EFI_SUCCESS.
1615 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1617 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1618 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1619 fileBuffer
.append("\r\n");
1622 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1623 fileBuffer
.append(" Status = ");
1624 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1625 fileBuffer
.append("();\r\n");
1627 switch (CommonDefinition
.getModuleType(moduleType
)) {
1628 case CommonDefinition
.ModuleTypeBase
:
1629 fileBuffer
.append(" Status = ");
1630 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1631 fileBuffer
.append("();\r\n");
1633 case CommonDefinition
.ModuleTypePeiCore
:
1634 case CommonDefinition
.ModuleTypePeim
:
1635 fileBuffer
.append(" Status = ");
1636 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1637 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1639 case CommonDefinition
.ModuleTypeDxeCore
:
1640 case CommonDefinition
.ModuleTypeDxeDriver
:
1641 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1642 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1643 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1644 case CommonDefinition
.ModuleTypeUefiDriver
:
1645 case CommonDefinition
.ModuleTypeUefiApplication
:
1646 fileBuffer
.append(" Status = ");
1647 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1648 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1651 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1655 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1657 fileBuffer
.append("}\r\n");
1661 LibDestructorToAutogenc
1663 This function writes library destructor list to AutoGen.c. The library
1664 destructor's parameter and return value depend on module type.
1666 @param libInstanceList
1667 List of library destructor name.
1671 String buffer for AutoGen.c
1674 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1675 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1676 boolean isFirst
= true;
1677 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1678 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1679 functionDeclarations
.append("RETURN_STATUS\r\n");
1680 functionDeclarations
.append("EFIAPI\r\n");
1681 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1682 functionDeclarations
.append(" (\r\n");
1683 functionDeclarations
.append(" VOID\r\n");
1684 functionDeclarations
.append(" );\r\n");
1686 switch (CommonDefinition
.getModuleType(moduleType
)) {
1687 case CommonDefinition
.ModuleTypeBase
:
1688 functionDeclarations
.append("RETURN_STATUS\r\n");
1689 functionDeclarations
.append("EFIAPI\r\n");
1690 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1691 functionDeclarations
.append(" (\r\n");
1692 functionDeclarations
.append(" VOID\r\n");
1693 functionDeclarations
.append(" );\r\n");
1695 case CommonDefinition
.ModuleTypePeiCore
:
1696 case CommonDefinition
.ModuleTypePeim
:
1697 functionDeclarations
.append("EFI_STATUS\r\n");
1698 functionDeclarations
.append("EFIAPI\r\n");
1699 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1700 functionDeclarations
.append(" (\r\n");
1701 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1702 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1703 functionDeclarations
.append(" );\r\n");
1705 case CommonDefinition
.ModuleTypeDxeCore
:
1706 case CommonDefinition
.ModuleTypeDxeDriver
:
1707 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1708 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1709 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1710 case CommonDefinition
.ModuleTypeUefiDriver
:
1711 case CommonDefinition
.ModuleTypeUefiApplication
:
1712 functionDeclarations
.append("EFI_STATUS\r\n");
1713 functionDeclarations
.append("EFIAPI\r\n");
1714 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1715 functionDeclarations
.append(" (\r\n");
1716 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1717 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1718 functionDeclarations
.append(" );\r\n");
1725 // Write ProcessLibraryDestructor list to autogen.c
1727 switch (CommonDefinition
.getModuleType(moduleType
)) {
1728 case CommonDefinition
.ModuleTypeBase
:
1729 case CommonDefinition
.ModuleTypePeiCore
:
1730 case CommonDefinition
.ModuleTypePeim
:
1732 case CommonDefinition
.ModuleTypeDxeCore
:
1733 case CommonDefinition
.ModuleTypeDxeDriver
:
1734 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1735 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1736 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1737 case CommonDefinition
.ModuleTypeUefiDriver
:
1738 case CommonDefinition
.ModuleTypeUefiApplication
:
1739 fileBuffer
.append("VOID\r\n");
1740 fileBuffer
.append("EFIAPI\r\n");
1741 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1742 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1743 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1744 fileBuffer
.append(" )\r\n");
1745 fileBuffer
.append("{\r\n");
1747 // If no library destructor function, return EFI_SUCCESS.
1750 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1752 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1753 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1754 fileBuffer
.append("\r\n");
1757 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1758 fileBuffer
.append(" Status = ");
1759 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1760 fileBuffer
.append("();\r\n");
1761 fileBuffer
.append(" VOID\r\n");
1763 fileBuffer
.append(" Status = ");
1764 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1765 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1766 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1769 fileBuffer
.append("}\r\n");
1775 ExternsDriverBindingToAutoGenC
1777 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1778 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1781 String buffer for AutoGen.c
1783 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1784 throws EdkException
{
1786 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1787 // The second dimension is include following element: DriverBinding,
1788 // ComponentName, DriverConfiguration, DriverDiag;
1790 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1799 // Write driver binding protocol extern to autogen.c
1801 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1802 if (driverBindingGroup
[i
][0] != null) {
1803 globalDeclarations
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1804 globalDeclarations
.append(driverBindingGroup
[i
][0]);
1805 globalDeclarations
.append(";\r\n");
1810 // Write component name protocol extern to autogen.c
1812 if (!componentNamePcd
) {
1813 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1814 if (driverBindingGroup
[i
][1]!= null) {
1815 if (driverBindingGroup
[i
][0] != null) {
1817 globalDeclarations
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1818 globalDeclarations
.append(driverBindingGroup
[i
][1]);
1819 globalDeclarations
.append(";\r\n");
1821 throw new AutoGenException("DriverBinding can't be empty!!");
1828 // Write driver configration protocol extern to autogen.c
1830 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1831 if (driverBindingGroup
[i
][2] != null) {
1832 if (driverBindingGroup
[i
][0] != null) {
1834 globalDeclarations
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1835 globalDeclarations
.append(driverBindingGroup
[i
][2]);
1836 globalDeclarations
.append(";\r\n");
1838 throw new AutoGenException("DriverBinding can't be empty!!");
1844 // Write driver dignastic protocol extern to autogen.c
1846 if (!driverDiagnostPcd
) {
1847 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1848 if (driverBindingGroup
[i
][3] != null) {
1849 if (driverBindingGroup
[i
][0] != null) {
1851 globalDeclarations
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1852 globalDeclarations
.append(driverBindingGroup
[i
][3]);
1853 globalDeclarations
.append(";\r\n");
1855 throw new AutoGenException("DriverBinding can't be empty!!");
1863 // Write driver module protocol bitmask.
1865 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1866 fileBuffer
.append(Integer
.toString(BitMask
));
1867 fileBuffer
.append(";\r\n");
1870 // Write driver module protocol list entry
1872 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1874 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1875 fileBuffer
.append(";\r\n");
1878 // Write drive module protocol list to autogen.c
1880 if (driverBindingGroup
.length
> 0) {
1881 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1885 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1887 fileBuffer
.append(",");
1892 fileBuffer
.append("\r\n {\r\n");
1893 fileBuffer
.append(" &");
1894 fileBuffer
.append(driverBindingGroup
[i
][0]);
1895 fileBuffer
.append(", \r\n");
1900 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1901 fileBuffer
.append(" &");
1902 fileBuffer
.append(driverBindingGroup
[i
][1]);
1903 fileBuffer
.append(", \r\n");
1905 fileBuffer
.append(" NULL, \r\n");
1909 // DriverConfiguration
1911 if (driverBindingGroup
[i
][2] != null) {
1912 fileBuffer
.append(" &");
1913 fileBuffer
.append(driverBindingGroup
[i
][2]);
1914 fileBuffer
.append(", \r\n");
1916 fileBuffer
.append(" NULL, \r\n");
1922 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1923 fileBuffer
.append(" &");
1924 fileBuffer
.append(driverBindingGroup
[i
][3]);
1925 fileBuffer
.append(", \r\n");
1927 fileBuffer
.append(" NULL, \r\n");
1929 fileBuffer
.append(" }");
1932 if (driverBindingGroup
.length
> 0) {
1933 fileBuffer
.append("\r\n};\r\n");
1938 ExternCallBackToAutoGenC
1940 This function adds <SetVirtualAddressMapCallBack> and
1941 <ExitBootServicesCallBack> infomation to AutoGen.c
1944 String buffer for AutoGen.c
1945 @throws BuildException
1947 void ExternCallBackToAutoGenH(String moduleType
)
1948 throws EdkException
{
1950 // Collect module's <SetVirtualAddressMapCallBack> and
1951 // <ExitBootServiceCallBack> and add to setVirtualAddList
1952 // exitBootServiceList.
1954 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1955 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1957 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1958 // and <ExitBootServicesCallBack>
1960 switch (CommonDefinition
.getModuleType(moduleType
)) {
1961 case CommonDefinition
.ModuleTypeDxeDriver
:
1962 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1963 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1964 case CommonDefinition
.ModuleTypeUefiDriver
:
1965 case CommonDefinition
.ModuleTypeUefiApplication
:
1967 // Write SetVirtualAddressMap function definition.
1969 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1970 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1973 functionDeclarations
.append("VOID\r\n");
1974 functionDeclarations
.append("EFIAPI\r\n");
1975 functionDeclarations
.append(setVirtuals
[i
]);
1976 functionDeclarations
.append(" (\r\n");
1977 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1978 functionDeclarations
.append(" IN VOID *Context\r\n");
1979 functionDeclarations
.append(" );\r\n\r\n");
1983 // Write DriverExitBootServices function definition.
1985 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1986 if (exitBoots
[i
].equalsIgnoreCase("")) {
1990 functionDeclarations
.append("VOID\r\n");
1991 functionDeclarations
.append("EFIAPI\r\n");
1992 functionDeclarations
.append(exitBoots
[i
]);
1993 functionDeclarations
.append(" (\r\n");
1994 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1995 functionDeclarations
.append(" IN VOID *Context\r\n");
1996 functionDeclarations
.append(" );\r\n\r\n");
2005 ExternCallBackToAutoGenC
2007 This function adds <SetVirtualAddressMapCallBack> and
2008 <ExitBootServicesCallBack> infomation to AutoGen.c
2011 String buffer for AutoGen.c
2012 @throws BuildException
2014 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
2015 throws EdkException
{
2017 // Collect module's <SetVirtualAddressMapCallBack> and
2018 // <ExitBootServiceCallBack> and add to setVirtualAddList
2019 // exitBootServiceList.
2021 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2022 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
2023 if (setVirtuals
!= null) {
2024 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2025 this.setVirtalAddList
.add(setVirtuals
[j
]);
2028 if (exitBoots
!= null) {
2029 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2030 this.exitBootServiceList
.add(exitBoots
[k
]);
2034 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
2035 // and <ExitBootServicesCallBack>
2037 String moduleType
= this.moduleId
.getModuleType();
2038 switch (CommonDefinition
.getModuleType(moduleType
)) {
2039 case CommonDefinition
.ModuleTypeDxeDriver
:
2040 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
2041 case CommonDefinition
.ModuleTypeDxeSalDriver
:
2042 case CommonDefinition
.ModuleTypeUefiDriver
:
2043 case CommonDefinition
.ModuleTypeUefiApplication
:
2045 // If moduleType is one of above, call setVirtualAddressToAutogenC,
2046 // and setExitBootServiceToAutogenC.
2048 setVirtualAddressToAutogenC(fileBuffer
);
2049 setExitBootServiceToAutogenC(fileBuffer
);
2057 copyFlashMapHToDebugDir
2059 This function is to copy the falshmap.h to debug directory and change
2060 its name to TianoR8FlashMap.h
2065 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2067 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
2068 int size
= (int)inFile
.length();
2069 byte[] buffer
= new byte[size
];
2070 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
2072 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2075 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2076 if (inFile
.exists()) {
2078 FileInputStream fis
= new FileInputStream (inFile
);
2080 FileOutputStream fos
= new FileOutputStream(outFile
);
2084 } catch (IOException e
) {
2085 throw new AutoGenException("The file, flashMap.h can't be open!");
2089 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2095 This function first order the library instances, then collect
2096 library instance 's PPI, Protocol, GUID,
2097 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2098 Destructor, Constructor.
2103 private void collectLibInstanceInfo() throws EdkException
{
2106 String moduleType
= moduleId
.getModuleType();
2107 String libConstructName
= null;
2108 String libDestructName
= null;
2109 String libModuleType
= null;
2110 String
[] setVirtuals
= null;
2111 String
[] exitBoots
= null;
2113 ModuleIdentification
[] libraryIdList
= saq
.getLibraryInstance(this.arch
);
2114 if (libraryIdList
.length
<= 0) {
2118 // Reorder library instance sequence.
2120 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
2121 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
2123 // Process library instance one by one.
2125 for (int i
= 0; i
< orderList
.size(); i
++) {
2127 // Get library instance basename.
2129 ModuleIdentification libInstanceId
= orderList
.get(i
);
2135 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2138 // check if the library instance support current module
2140 String
[] libraryClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
,
2144 if (libraryClassList
.length
<= 0) {
2145 throw new EdkException("Library instance " + libInstanceId
.getName()
2146 + " doesn't support module type " + moduleType
);
2149 // Get <PPis>, <Protocols>, <Guids> list of this library
2152 String
[] ppiList
= saq
.getPpiArray(this.arch
);
2153 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
2154 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
2155 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
2156 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
2157 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2160 // Add those ppi, protocol, guid in global ppi,
2164 for (index
= 0; index
< ppiList
.length
; index
++) {
2165 this.mPpiList
.add(ppiList
[index
]);
2168 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2169 this.mPpiList
.add(ppiNotifyList
[index
]);
2172 for (index
= 0; index
< protocolList
.length
; index
++) {
2173 this.mProtocolList
.add(protocolList
[index
]);
2176 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2177 this.mProtocolList
.add(protocolNotifyList
[index
]);
2180 for (index
= 0; index
< guidList
.length
; index
++) {
2181 this.mGuidList
.add(guidList
[index
]);
2183 for (index
= 0; index
< pkgList
.length
; index
++) {
2184 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2185 this.mDepPkgList
.add(pkgList
[index
]);
2190 // If not yet parse this library instance's constructor
2191 // element,parse it.
2193 libConstructName
= saq
.getLibConstructorName();
2194 libDestructName
= saq
.getLibDestructorName();
2195 libModuleType
= saq
.getModuleType();
2198 // Collect SetVirtualAddressMapCallBack and
2199 // ExitBootServiceCallBack.
2201 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2202 exitBoots
= saq
.getExitBootServicesCallBackArray();
2203 if (setVirtuals
!= null) {
2204 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2205 this.setVirtalAddList
.add(setVirtuals
[j
]);
2208 if (exitBoots
!= null) {
2209 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2210 this.exitBootServiceList
.add(exitBoots
[k
]);
2215 // Add dependent library instance constructor function.
2217 if (libConstructName
!= null) {
2218 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2221 // Add dependent library instance destructor fuction.
2223 if (libDestructName
!= null) {
2224 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2229 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2231 // Entry point lib for these module types needs to know the count
2234 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2237 // If the list is not valid or has no entries set count to zero else
2238 // set count to the number of valid entries
2242 if (this.setVirtalAddList
!= null) {
2243 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2244 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2251 fileBuffer
.append(Integer
.toString(Count
));
2252 fileBuffer
.append(";\r\n\r\n");
2253 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2255 // No data so make a NULL list
2257 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2258 fileBuffer
.append(" NULL\r\n");
2259 fileBuffer
.append("};\r\n\r\n");
2262 // Write SetVirtualAddressMap function definition.
2264 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2265 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2268 functionDeclarations
.append("VOID\r\n");
2269 functionDeclarations
.append("EFIAPI\r\n");
2270 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2271 functionDeclarations
.append(" (\r\n");
2272 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2273 functionDeclarations
.append(" IN VOID *Context\r\n");
2274 functionDeclarations
.append(" );\r\n\r\n");
2278 // Write SetVirtualAddressMap entry point array.
2280 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2281 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2282 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2287 fileBuffer
.append("\r\n ");
2289 fileBuffer
.append(",\r\n ");
2292 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2295 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2297 fileBuffer
.append(",\r\n NULL");
2298 fileBuffer
.append("\r\n};\r\n\r\n");
2303 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2305 // Entry point lib for these module types needs to know the count.
2307 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2310 // If the list is not valid or has no entries set count to zero else
2311 // set count to the number of valid entries.
2315 if (this.exitBootServiceList
!= null) {
2316 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2317 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2323 fileBuffer
.append(Integer
.toString(Count
));
2324 fileBuffer
.append(";\r\n\r\n");
2326 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2328 // No data so make a NULL list.
2330 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2331 fileBuffer
.append(" NULL\r\n");
2332 fileBuffer
.append("};\r\n\r\n");
2335 // Write DriverExitBootServices function definition.
2337 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2338 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2342 functionDeclarations
.append("VOID\r\n");
2343 functionDeclarations
.append("EFIAPI\r\n");
2344 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2345 functionDeclarations
.append(" (\r\n");
2346 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2347 functionDeclarations
.append(" IN VOID *Context\r\n");
2348 functionDeclarations
.append(" );\r\n\r\n");
2352 // Write DriverExitBootServices entry point array.
2354 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2355 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2356 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2361 fileBuffer
.append("\r\n ");
2363 fileBuffer
.append(",\r\n ");
2365 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2368 fileBuffer
.append(",\r\n NULL");
2369 fileBuffer
.append("\r\n};\r\n\r\n");
2375 Get the Pcd Value of ComponentName to
2376 decide whether need to disable the componentName.
2379 public void setPcdComponentName (){
2380 String pcdValue
= null;
2381 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2382 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2383 this.componentNamePcd
= true;
2388 setPcdDriverDiagnostic
2390 Get the Pcd Value of DriverDiagnostic to
2391 decide whether need to disable DriverDiagnostic.
2394 public void setPcdDriverDiagnostic (){
2395 String pcdValue
= null;
2396 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2397 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2398 this.driverDiagnostPcd
= true;