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");
1110 fileBuffer
.append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1112 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1113 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1114 fileBuffer
.append(" }\r\n");
1115 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1116 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1118 fileBuffer
.append("}\r\n\r\n");
1122 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1124 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1126 // Remover duplicate unload entry point.
1128 //entryPointList = CommonDefinition.remDupString(entryPointList);
1129 //entryPointCount = 0;
1130 unloadImageCount
= 0;
1131 if (unloadImageList
!= null) {
1132 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1133 functionDeclarations
.append("EFI_STATUS\r\n");
1134 functionDeclarations
.append("EFIAPI\r\n");
1135 functionDeclarations
.append(unloadImageList
[i
]);
1136 functionDeclarations
.append(" (\r\n");
1137 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle\r\n");
1138 functionDeclarations
.append(" );\r\n");
1143 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1144 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1145 fileBuffer
.append(";\r\n\r\n");
1147 fileBuffer
.append("EFI_STATUS\r\n");
1148 fileBuffer
.append("EFIAPI\r\n");
1149 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1150 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1151 fileBuffer
.append(" )\r\n");
1152 fileBuffer
.append("{\r\n");
1154 if (unloadImageCount
== 0) {
1155 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1156 } else if (unloadImageCount
== 1) {
1157 fileBuffer
.append(" return ");
1158 fileBuffer
.append(unloadImageList
[0]);
1159 fileBuffer
.append("(ImageHandle);\r\n");
1161 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1162 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1163 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1165 fileBuffer
.append(" Status = ");
1166 fileBuffer
.append(unloadImageList
[i
]);
1167 fileBuffer
.append("(ImageHandle);\r\n");
1169 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1170 fileBuffer
.append(" ");
1171 fileBuffer
.append(unloadImageList
[i
]);
1172 fileBuffer
.append("(ImageHandle);\r\n");
1173 fileBuffer
.append(" } else {\r\n");
1174 fileBuffer
.append(" Status = ");
1175 fileBuffer
.append(unloadImageList
[i
]);
1176 fileBuffer
.append("(ImageHandle);\r\n");
1177 fileBuffer
.append(" }\r\n");
1180 fileBuffer
.append(" return Status;\r\n");
1182 fileBuffer
.append("}\r\n\r\n");
1190 This function gets GUIDs from SPD file accrodeing to <PPIs> information
1191 and write those GUIDs to AutoGen.c.
1194 String Buffer for Autogen.c file.
1195 @throws BuildException
1196 Guid must set value!
1198 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1199 String
[] cNameGuid
= null;
1202 // Get the all PPI adn PPI Notify from MSA file,
1203 // then add those PPI ,and PPI Notify name to list.
1206 String
[] ppiList
= saq
.getPpiArray(this.arch
);
1207 for (int i
= 0; i
< ppiList
.length
; i
++) {
1208 this.mPpiList
.add(ppiList
[i
]);
1211 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
1212 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1213 this.mPpiList
.add(ppiNotifyList
[i
]);
1217 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1219 Iterator ppiIterator
= this.mPpiList
.iterator();
1220 String ppiKeyWord
= null;
1221 while (ppiIterator
.hasNext()) {
1222 ppiKeyWord
= ppiIterator
.next().toString();
1223 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1224 if (cNameGuid
!= null) {
1225 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1226 fileBuffer
.append(cNameGuid
[0]);
1227 fileBuffer
.append(" = { ");
1228 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1229 fileBuffer
.append(" } ;");
1232 // If can't find Ppi GUID declaration in every package
1234 throw new AutoGenException("Can not find Ppi GUID ["
1235 + ppiKeyWord
+ "] declaration in any SPD package!");
1241 ProtocolGuidToAutogenc
1243 This function gets GUIDs from SPD file accrodeing to <Protocol>
1244 information and write those GUIDs to AutoGen.c.
1247 String Buffer for Autogen.c file.
1248 @throws BuildException
1249 Protocol name must set.
1251 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1252 String
[] cNameGuid
= null;
1254 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
1257 // Add result to Autogen global list.
1259 for (int i
= 0; i
< protocolList
.length
; i
++) {
1260 this.mProtocolList
.add(protocolList
[i
]);
1263 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
1265 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1266 this.mProtocolList
.add(protocolNotifyList
[i
]);
1270 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1272 Iterator protocolIterator
= this.mProtocolList
.iterator();
1273 String protocolKeyWord
= null;
1276 while (protocolIterator
.hasNext()) {
1277 protocolKeyWord
= protocolIterator
.next().toString();
1278 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1279 if (cNameGuid
!= null) {
1280 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1281 fileBuffer
.append(cNameGuid
[0]);
1282 fileBuffer
.append(" = { ");
1283 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1284 fileBuffer
.append(" } ;");
1287 // If can't find protocol GUID declaration in every package
1289 throw new AutoGenException("Can not find protocol Guid ["
1290 + protocolKeyWord
+ "] declaration in any SPD package!");
1298 This function gets GUIDs from SPD file accrodeing to <Guids> information
1299 and write those GUIDs to AutoGen.c.
1302 String Buffer for Autogen.c file.
1305 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1306 String
[] cNameGuid
= null;
1307 String guidKeyWord
= null;
1309 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
1311 for (int i
= 0; i
< guidList
.length
; i
++) {
1312 this.mGuidList
.add(guidList
[i
]);
1316 Iterator guidIterator
= this.mGuidList
.iterator();
1317 while (guidIterator
.hasNext()) {
1318 guidKeyWord
= guidIterator
.next().toString();
1319 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1321 if (cNameGuid
!= null) {
1322 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1323 fileBuffer
.append(cNameGuid
[0]);
1324 fileBuffer
.append(" = { ");
1325 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1326 fileBuffer
.append("} ;");
1329 // If can't find GUID declaration in every package
1331 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1332 + "] declaration in any SPD package. ");
1339 LibInstanceToAutogenC
1341 This function adds dependent library instance to autogen.c,which
1342 includeing library's constructor, destructor, and library dependent ppi,
1343 protocol, guid, pcd information.
1346 String buffer for AutoGen.c
1347 @throws BuildException
1349 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1350 String moduleType
= this.moduleId
.getModuleType();
1352 // Add library constructor to AutoGen.c
1354 LibConstructorToAutogenC(libConstructList
, moduleType
, fileBuffer
);
1356 // Add library destructor to AutoGen.c
1358 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
);
1362 LibConstructorToAutogenH
1364 This function writes library constructor declarations AutoGen.h. The library
1365 constructor's parameter and return value depend on module type.
1367 @param libInstanceList
1368 List of library construct name.
1372 String buffer for AutoGen.c
1375 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1376 boolean isFirst
= true;
1379 // If not yet parse this library instance's constructor
1380 // element,parse it.
1382 String libConstructName
= saq
.getLibConstructorName();
1383 if (libConstructName
== null) {
1388 // The library constructor's parameter and return value depend on
1391 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1392 functionDeclarations
.append("RETURN_STATUS\r\n");
1393 functionDeclarations
.append("EFIAPI\r\n");
1394 functionDeclarations
.append(libConstructName
);
1395 functionDeclarations
.append(" (\r\n");
1396 functionDeclarations
.append(" VOID\r\n");
1397 functionDeclarations
.append(" );\r\n");
1399 switch (CommonDefinition
.getModuleType(moduleType
)) {
1400 case CommonDefinition
.ModuleTypeBase
:
1401 functionDeclarations
.append("RETURN_STATUS\r\n");
1402 functionDeclarations
.append("EFIAPI\r\n");
1403 functionDeclarations
.append(libConstructName
);
1404 functionDeclarations
.append(" (\r\n");
1405 functionDeclarations
.append(" VOID\r\n");
1406 functionDeclarations
.append(" );\r\n");
1409 case CommonDefinition
.ModuleTypePeiCore
:
1410 case CommonDefinition
.ModuleTypePeim
:
1411 functionDeclarations
.append("EFI_STATUS\r\n");
1412 functionDeclarations
.append("EFIAPI\r\n");
1413 functionDeclarations
.append(libConstructName
);
1414 functionDeclarations
.append(" (\r\n");
1415 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1416 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1417 functionDeclarations
.append(" );\r\n");
1420 case CommonDefinition
.ModuleTypeDxeCore
:
1421 case CommonDefinition
.ModuleTypeDxeDriver
:
1422 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1423 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1424 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1425 case CommonDefinition
.ModuleTypeUefiDriver
:
1426 case CommonDefinition
.ModuleTypeUefiApplication
:
1427 functionDeclarations
.append("EFI_STATUS\r\n");
1428 functionDeclarations
.append("EFIAPI\r\n");
1429 functionDeclarations
.append(libConstructName
);
1430 functionDeclarations
.append(" (\r\n");
1431 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1432 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1433 functionDeclarations
.append(" );\r\n");
1441 LibDestructorToAutogenH
1443 This function writes library destructor declarations AutoGen.h. The library
1444 destructor's parameter and return value depend on module type.
1446 @param libInstanceList
1447 List of library destructor name.
1451 String buffer for AutoGen.c
1454 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1455 boolean isFirst
= true;
1456 String libDestructName
= saq
.getLibDestructorName();
1457 if (libDestructName
== null) {
1461 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1462 functionDeclarations
.append("RETURN_STATUS\r\n");
1463 functionDeclarations
.append("EFIAPI\r\n");
1464 functionDeclarations
.append(libDestructName
);
1465 functionDeclarations
.append(" (\r\n");
1466 functionDeclarations
.append(" VOID\r\n");
1467 functionDeclarations
.append(" );\r\n");
1469 switch (CommonDefinition
.getModuleType(moduleType
)) {
1470 case CommonDefinition
.ModuleTypeBase
:
1471 functionDeclarations
.append("RETURN_STATUS\r\n");
1472 functionDeclarations
.append("EFIAPI\r\n");
1473 functionDeclarations
.append(libDestructName
);
1474 functionDeclarations
.append(" (\r\n");
1475 functionDeclarations
.append(" VOID\r\n");
1476 functionDeclarations
.append(" );\r\n");
1478 case CommonDefinition
.ModuleTypePeiCore
:
1479 case CommonDefinition
.ModuleTypePeim
:
1480 functionDeclarations
.append("EFI_STATUS\r\n");
1481 functionDeclarations
.append("EFIAPI\r\n");
1482 functionDeclarations
.append(libDestructName
);
1483 functionDeclarations
.append(" (\r\n");
1484 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1485 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1486 functionDeclarations
.append(" );\r\n");
1488 case CommonDefinition
.ModuleTypeDxeCore
:
1489 case CommonDefinition
.ModuleTypeDxeDriver
:
1490 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1491 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1492 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1493 case CommonDefinition
.ModuleTypeUefiDriver
:
1494 case CommonDefinition
.ModuleTypeUefiApplication
:
1495 functionDeclarations
.append("EFI_STATUS\r\n");
1496 functionDeclarations
.append("EFIAPI\r\n");
1497 functionDeclarations
.append(libDestructName
);
1498 functionDeclarations
.append(" (\r\n");
1499 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1500 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1501 functionDeclarations
.append(" );\r\n");
1508 LibConstructorToAutogenc
1510 This function writes library constructor list to AutoGen.c. The library
1511 constructor's parameter and return value depend on module type.
1513 @param libInstanceList
1514 List of library construct name.
1518 String buffer for AutoGen.c
1521 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1522 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1523 boolean isFirst
= true;
1526 // The library constructor's parameter and return value depend on
1529 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1530 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1531 functionDeclarations
.append("RETURN_STATUS\r\n");
1532 functionDeclarations
.append("EFIAPI\r\n");
1533 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1534 functionDeclarations
.append(" (\r\n");
1535 functionDeclarations
.append(" VOID\r\n");
1536 functionDeclarations
.append(" );\r\n");
1538 switch (CommonDefinition
.getModuleType(moduleType
)) {
1539 case CommonDefinition
.ModuleTypeBase
:
1540 functionDeclarations
.append("RETURN_STATUS\r\n");
1541 functionDeclarations
.append("EFIAPI\r\n");
1542 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1543 functionDeclarations
.append(" (\r\n");
1544 functionDeclarations
.append(" VOID\r\n");
1545 functionDeclarations
.append(" );\r\n");
1548 case CommonDefinition
.ModuleTypePeiCore
:
1549 case CommonDefinition
.ModuleTypePeim
:
1550 functionDeclarations
.append("EFI_STATUS\r\n");
1551 functionDeclarations
.append("EFIAPI\r\n");
1552 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1553 functionDeclarations
.append(" (\r\n");
1554 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1555 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1556 functionDeclarations
.append(" );\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 functionDeclarations
.append("EFI_STATUS\r\n");
1567 functionDeclarations
.append("EFIAPI\r\n");
1568 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1569 functionDeclarations
.append(" (\r\n");
1570 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1571 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1572 functionDeclarations
.append(" );\r\n");
1580 // Add ProcessLibraryConstructorList in AutoGen.c
1582 fileBuffer
.append("VOID\r\n");
1583 fileBuffer
.append("EFIAPI\r\n");
1584 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1585 switch (CommonDefinition
.getModuleType(moduleType
)) {
1586 case CommonDefinition
.ModuleTypeBase
:
1587 fileBuffer
.append(" VOID\r\n");
1590 case CommonDefinition
.ModuleTypePeiCore
:
1591 case CommonDefinition
.ModuleTypePeim
:
1592 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1593 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1596 case CommonDefinition
.ModuleTypeDxeCore
:
1597 case CommonDefinition
.ModuleTypeDxeDriver
:
1598 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1599 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1600 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1601 case CommonDefinition
.ModuleTypeUefiDriver
:
1602 case CommonDefinition
.ModuleTypeUefiApplication
:
1603 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1604 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1608 fileBuffer
.append(" )\r\n");
1609 fileBuffer
.append("{\r\n");
1611 // If no constructor function, return EFI_SUCCESS.
1613 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1615 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1616 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1617 fileBuffer
.append("\r\n");
1620 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1621 fileBuffer
.append(" Status = ");
1622 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1623 fileBuffer
.append("();\r\n");
1625 switch (CommonDefinition
.getModuleType(moduleType
)) {
1626 case CommonDefinition
.ModuleTypeBase
:
1627 fileBuffer
.append(" Status = ");
1628 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1629 fileBuffer
.append("();\r\n");
1631 case CommonDefinition
.ModuleTypePeiCore
:
1632 case CommonDefinition
.ModuleTypePeim
:
1633 fileBuffer
.append(" Status = ");
1634 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1635 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1637 case CommonDefinition
.ModuleTypeDxeCore
:
1638 case CommonDefinition
.ModuleTypeDxeDriver
:
1639 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1640 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1641 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1642 case CommonDefinition
.ModuleTypeUefiDriver
:
1643 case CommonDefinition
.ModuleTypeUefiApplication
:
1644 fileBuffer
.append(" Status = ");
1645 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1646 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1649 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1653 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1655 fileBuffer
.append("}\r\n");
1659 LibDestructorToAutogenc
1661 This function writes library destructor list to AutoGen.c. The library
1662 destructor's parameter and return value depend on module type.
1664 @param libInstanceList
1665 List of library destructor name.
1669 String buffer for AutoGen.c
1672 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1673 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1674 boolean isFirst
= true;
1675 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1676 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1677 functionDeclarations
.append("RETURN_STATUS\r\n");
1678 functionDeclarations
.append("EFIAPI\r\n");
1679 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1680 functionDeclarations
.append(" (\r\n");
1681 functionDeclarations
.append(" VOID\r\n");
1682 functionDeclarations
.append(" );\r\n");
1684 switch (CommonDefinition
.getModuleType(moduleType
)) {
1685 case CommonDefinition
.ModuleTypeBase
:
1686 functionDeclarations
.append("RETURN_STATUS\r\n");
1687 functionDeclarations
.append("EFIAPI\r\n");
1688 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1689 functionDeclarations
.append(" (\r\n");
1690 functionDeclarations
.append(" VOID\r\n");
1691 functionDeclarations
.append(" );\r\n");
1693 case CommonDefinition
.ModuleTypePeiCore
:
1694 case CommonDefinition
.ModuleTypePeim
:
1695 functionDeclarations
.append("EFI_STATUS\r\n");
1696 functionDeclarations
.append("EFIAPI\r\n");
1697 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1698 functionDeclarations
.append(" (\r\n");
1699 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1700 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1701 functionDeclarations
.append(" );\r\n");
1703 case CommonDefinition
.ModuleTypeDxeCore
:
1704 case CommonDefinition
.ModuleTypeDxeDriver
:
1705 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1706 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1707 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1708 case CommonDefinition
.ModuleTypeUefiDriver
:
1709 case CommonDefinition
.ModuleTypeUefiApplication
:
1710 functionDeclarations
.append("EFI_STATUS\r\n");
1711 functionDeclarations
.append("EFIAPI\r\n");
1712 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1713 functionDeclarations
.append(" (\r\n");
1714 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1715 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1716 functionDeclarations
.append(" );\r\n");
1723 // Write ProcessLibraryDestructor list to autogen.c
1725 switch (CommonDefinition
.getModuleType(moduleType
)) {
1726 case CommonDefinition
.ModuleTypeBase
:
1727 case CommonDefinition
.ModuleTypePeiCore
:
1728 case CommonDefinition
.ModuleTypePeim
:
1730 case CommonDefinition
.ModuleTypeDxeCore
:
1731 case CommonDefinition
.ModuleTypeDxeDriver
:
1732 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1733 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1734 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1735 case CommonDefinition
.ModuleTypeUefiDriver
:
1736 case CommonDefinition
.ModuleTypeUefiApplication
:
1737 fileBuffer
.append("VOID\r\n");
1738 fileBuffer
.append("EFIAPI\r\n");
1739 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1740 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1741 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1742 fileBuffer
.append(" )\r\n");
1743 fileBuffer
.append("{\r\n");
1745 // If no library destructor function, return EFI_SUCCESS.
1748 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1750 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1751 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1752 fileBuffer
.append("\r\n");
1755 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1756 fileBuffer
.append(" Status = ");
1757 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1758 fileBuffer
.append("();\r\n");
1759 fileBuffer
.append(" VOID\r\n");
1761 fileBuffer
.append(" Status = ");
1762 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1763 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1764 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1767 fileBuffer
.append("}\r\n");
1773 ExternsDriverBindingToAutoGenC
1775 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1776 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1779 String buffer for AutoGen.c
1781 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1782 throws EdkException
{
1784 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1785 // The second dimension is include following element: DriverBinding,
1786 // ComponentName, DriverConfiguration, DriverDiag;
1788 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1797 // Write driver binding protocol extern to autogen.c
1799 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1800 if (driverBindingGroup
[i
][0] != null) {
1801 globalDeclarations
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1802 globalDeclarations
.append(driverBindingGroup
[i
][0]);
1803 globalDeclarations
.append(";\r\n");
1808 // Write component name protocol extern to autogen.c
1810 if (!componentNamePcd
) {
1811 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1812 if (driverBindingGroup
[i
][1]!= null) {
1813 if (driverBindingGroup
[i
][0] != null) {
1815 globalDeclarations
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1816 globalDeclarations
.append(driverBindingGroup
[i
][1]);
1817 globalDeclarations
.append(";\r\n");
1819 throw new AutoGenException("DriverBinding can't be empty!!");
1826 // Write driver configration protocol extern to autogen.c
1828 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1829 if (driverBindingGroup
[i
][2] != null) {
1830 if (driverBindingGroup
[i
][0] != null) {
1832 globalDeclarations
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1833 globalDeclarations
.append(driverBindingGroup
[i
][2]);
1834 globalDeclarations
.append(";\r\n");
1836 throw new AutoGenException("DriverBinding can't be empty!!");
1842 // Write driver dignastic protocol extern to autogen.c
1844 if (!driverDiagnostPcd
) {
1845 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1846 if (driverBindingGroup
[i
][3] != null) {
1847 if (driverBindingGroup
[i
][0] != null) {
1849 globalDeclarations
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1850 globalDeclarations
.append(driverBindingGroup
[i
][3]);
1851 globalDeclarations
.append(";\r\n");
1853 throw new AutoGenException("DriverBinding can't be empty!!");
1861 // Write driver module protocol bitmask.
1863 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1864 fileBuffer
.append(Integer
.toString(BitMask
));
1865 fileBuffer
.append(";\r\n");
1868 // Write driver module protocol list entry
1870 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1872 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1873 fileBuffer
.append(";\r\n");
1876 // Write drive module protocol list to autogen.c
1878 if (driverBindingGroup
.length
> 0) {
1879 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1883 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1885 fileBuffer
.append(",");
1890 fileBuffer
.append("\r\n {\r\n");
1891 fileBuffer
.append(" &");
1892 fileBuffer
.append(driverBindingGroup
[i
][0]);
1893 fileBuffer
.append(", \r\n");
1898 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1899 fileBuffer
.append(" &");
1900 fileBuffer
.append(driverBindingGroup
[i
][1]);
1901 fileBuffer
.append(", \r\n");
1903 fileBuffer
.append(" NULL, \r\n");
1907 // DriverConfiguration
1909 if (driverBindingGroup
[i
][2] != null) {
1910 fileBuffer
.append(" &");
1911 fileBuffer
.append(driverBindingGroup
[i
][2]);
1912 fileBuffer
.append(", \r\n");
1914 fileBuffer
.append(" NULL, \r\n");
1920 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1921 fileBuffer
.append(" &");
1922 fileBuffer
.append(driverBindingGroup
[i
][3]);
1923 fileBuffer
.append(", \r\n");
1925 fileBuffer
.append(" NULL, \r\n");
1927 fileBuffer
.append(" }");
1930 if (driverBindingGroup
.length
> 0) {
1931 fileBuffer
.append("\r\n};\r\n");
1936 ExternCallBackToAutoGenC
1938 This function adds <SetVirtualAddressMapCallBack> and
1939 <ExitBootServicesCallBack> infomation to AutoGen.c
1942 String buffer for AutoGen.c
1943 @throws BuildException
1945 void ExternCallBackToAutoGenH(String moduleType
)
1946 throws EdkException
{
1948 // Collect module's <SetVirtualAddressMapCallBack> and
1949 // <ExitBootServiceCallBack> and add to setVirtualAddList
1950 // exitBootServiceList.
1952 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1953 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1955 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1956 // and <ExitBootServicesCallBack>
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 // Write SetVirtualAddressMap function definition.
1967 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1968 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1971 functionDeclarations
.append("VOID\r\n");
1972 functionDeclarations
.append("EFIAPI\r\n");
1973 functionDeclarations
.append(setVirtuals
[i
]);
1974 functionDeclarations
.append(" (\r\n");
1975 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1976 functionDeclarations
.append(" IN VOID *Context\r\n");
1977 functionDeclarations
.append(" );\r\n\r\n");
1981 // Write DriverExitBootServices function definition.
1983 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1984 if (exitBoots
[i
].equalsIgnoreCase("")) {
1988 functionDeclarations
.append("VOID\r\n");
1989 functionDeclarations
.append("EFIAPI\r\n");
1990 functionDeclarations
.append(exitBoots
[i
]);
1991 functionDeclarations
.append(" (\r\n");
1992 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1993 functionDeclarations
.append(" IN VOID *Context\r\n");
1994 functionDeclarations
.append(" );\r\n\r\n");
2003 ExternCallBackToAutoGenC
2005 This function adds <SetVirtualAddressMapCallBack> and
2006 <ExitBootServicesCallBack> infomation to AutoGen.c
2009 String buffer for AutoGen.c
2010 @throws BuildException
2012 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
2013 throws EdkException
{
2015 // Collect module's <SetVirtualAddressMapCallBack> and
2016 // <ExitBootServiceCallBack> and add to setVirtualAddList
2017 // exitBootServiceList.
2019 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2020 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
2021 if (setVirtuals
!= null) {
2022 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2023 this.setVirtalAddList
.add(setVirtuals
[j
]);
2026 if (exitBoots
!= null) {
2027 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2028 this.exitBootServiceList
.add(exitBoots
[k
]);
2032 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
2033 // and <ExitBootServicesCallBack>
2035 String moduleType
= this.moduleId
.getModuleType();
2036 switch (CommonDefinition
.getModuleType(moduleType
)) {
2037 case CommonDefinition
.ModuleTypeDxeDriver
:
2038 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
2039 case CommonDefinition
.ModuleTypeDxeSalDriver
:
2040 case CommonDefinition
.ModuleTypeUefiDriver
:
2041 case CommonDefinition
.ModuleTypeUefiApplication
:
2043 // If moduleType is one of above, call setVirtualAddressToAutogenC,
2044 // and setExitBootServiceToAutogenC.
2046 setVirtualAddressToAutogenC(fileBuffer
);
2047 setExitBootServiceToAutogenC(fileBuffer
);
2055 copyFlashMapHToDebugDir
2057 This function is to copy the falshmap.h to debug directory and change
2058 its name to TianoR8FlashMap.h
2063 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2065 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
2066 int size
= (int)inFile
.length();
2067 byte[] buffer
= new byte[size
];
2068 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
2070 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2073 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2074 if (inFile
.exists()) {
2076 FileInputStream fis
= new FileInputStream (inFile
);
2078 FileOutputStream fos
= new FileOutputStream(outFile
);
2082 } catch (IOException e
) {
2083 throw new AutoGenException("The file, flashMap.h can't be open!");
2087 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2093 This function first order the library instances, then collect
2094 library instance 's PPI, Protocol, GUID,
2095 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2096 Destructor, Constructor.
2101 private void collectLibInstanceInfo() throws EdkException
{
2104 String moduleType
= moduleId
.getModuleType();
2105 String libConstructName
= null;
2106 String libDestructName
= null;
2107 String libModuleType
= null;
2108 String
[] setVirtuals
= null;
2109 String
[] exitBoots
= null;
2111 ModuleIdentification
[] libraryIdList
= saq
.getLibraryInstance(this.arch
);
2112 if (libraryIdList
.length
<= 0) {
2116 // Reorder library instance sequence.
2118 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
2119 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
2121 // Process library instance one by one.
2123 for (int i
= 0; i
< orderList
.size(); i
++) {
2125 // Get library instance basename.
2127 ModuleIdentification libInstanceId
= orderList
.get(i
);
2133 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2136 // check if the library instance support current module
2138 String
[] libraryClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
,
2142 if (libraryClassList
.length
<= 0) {
2143 throw new EdkException("Library instance " + libInstanceId
.getName()
2144 + " doesn't support module type " + moduleType
);
2147 // Get <PPis>, <Protocols>, <Guids> list of this library
2150 String
[] ppiList
= saq
.getPpiArray(this.arch
);
2151 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
2152 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
2153 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
2154 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
2155 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2158 // Add those ppi, protocol, guid in global ppi,
2162 for (index
= 0; index
< ppiList
.length
; index
++) {
2163 this.mPpiList
.add(ppiList
[index
]);
2166 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2167 this.mPpiList
.add(ppiNotifyList
[index
]);
2170 for (index
= 0; index
< protocolList
.length
; index
++) {
2171 this.mProtocolList
.add(protocolList
[index
]);
2174 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2175 this.mProtocolList
.add(protocolNotifyList
[index
]);
2178 for (index
= 0; index
< guidList
.length
; index
++) {
2179 this.mGuidList
.add(guidList
[index
]);
2181 for (index
= 0; index
< pkgList
.length
; index
++) {
2182 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2183 this.mDepPkgList
.add(pkgList
[index
]);
2188 // If not yet parse this library instance's constructor
2189 // element,parse it.
2191 libConstructName
= saq
.getLibConstructorName();
2192 libDestructName
= saq
.getLibDestructorName();
2193 libModuleType
= saq
.getModuleType();
2196 // Collect SetVirtualAddressMapCallBack and
2197 // ExitBootServiceCallBack.
2199 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2200 exitBoots
= saq
.getExitBootServicesCallBackArray();
2201 if (setVirtuals
!= null) {
2202 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2203 this.setVirtalAddList
.add(setVirtuals
[j
]);
2206 if (exitBoots
!= null) {
2207 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2208 this.exitBootServiceList
.add(exitBoots
[k
]);
2213 // Add dependent library instance constructor function.
2215 if (libConstructName
!= null) {
2216 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2219 // Add dependent library instance destructor fuction.
2221 if (libDestructName
!= null) {
2222 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2227 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2229 // Entry point lib for these module types needs to know the count
2232 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2235 // If the list is not valid or has no entries set count to zero else
2236 // set count to the number of valid entries
2240 if (this.setVirtalAddList
!= null) {
2241 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2242 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2249 fileBuffer
.append(Integer
.toString(Count
));
2250 fileBuffer
.append(";\r\n\r\n");
2251 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2253 // No data so make a NULL list
2255 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2256 fileBuffer
.append(" NULL\r\n");
2257 fileBuffer
.append("};\r\n\r\n");
2260 // Write SetVirtualAddressMap function definition.
2262 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2263 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2266 functionDeclarations
.append("VOID\r\n");
2267 functionDeclarations
.append("EFIAPI\r\n");
2268 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2269 functionDeclarations
.append(" (\r\n");
2270 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2271 functionDeclarations
.append(" IN VOID *Context\r\n");
2272 functionDeclarations
.append(" );\r\n\r\n");
2276 // Write SetVirtualAddressMap entry point array.
2278 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2279 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2280 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2285 fileBuffer
.append("\r\n ");
2287 fileBuffer
.append(",\r\n ");
2290 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2293 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2295 fileBuffer
.append(",\r\n NULL");
2296 fileBuffer
.append("\r\n};\r\n\r\n");
2301 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2303 // Entry point lib for these module types needs to know the count.
2305 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2308 // If the list is not valid or has no entries set count to zero else
2309 // set count to the number of valid entries.
2313 if (this.exitBootServiceList
!= null) {
2314 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2315 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2321 fileBuffer
.append(Integer
.toString(Count
));
2322 fileBuffer
.append(";\r\n\r\n");
2324 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2326 // No data so make a NULL list.
2328 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2329 fileBuffer
.append(" NULL\r\n");
2330 fileBuffer
.append("};\r\n\r\n");
2333 // Write DriverExitBootServices function definition.
2335 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2336 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2340 functionDeclarations
.append("VOID\r\n");
2341 functionDeclarations
.append("EFIAPI\r\n");
2342 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2343 functionDeclarations
.append(" (\r\n");
2344 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2345 functionDeclarations
.append(" IN VOID *Context\r\n");
2346 functionDeclarations
.append(" );\r\n\r\n");
2350 // Write DriverExitBootServices entry point array.
2352 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2353 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2354 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2359 fileBuffer
.append("\r\n ");
2361 fileBuffer
.append(",\r\n ");
2363 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2366 fileBuffer
.append(",\r\n NULL");
2367 fileBuffer
.append("\r\n};\r\n\r\n");
2373 Get the Pcd Value of ComponentName to
2374 decide whether need to disable the componentName.
2377 public void setPcdComponentName (){
2378 String pcdValue
= null;
2379 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2380 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2381 this.componentNamePcd
= true;
2386 setPcdDriverDiagnostic
2388 Get the Pcd Value of DriverDiagnostic to
2389 decide whether need to disable DriverDiagnostic.
2392 public void setPcdDriverDiagnostic (){
2393 String pcdValue
= null;
2394 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2395 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2396 this.driverDiagnostPcd
= true;