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);
125 // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable
127 private boolean componentNamePcd
= false;
128 private boolean driverDiagnostPcd
= false;
131 // Instance of SurfaceAreaQuery
133 private SurfaceAreaQuery saq
= null;
135 private ModuleIdentification parentId
= null;
140 This function mainly initialize some member variable.
143 Absolute path of FV directory.
145 Output path of AutoGen file.
147 Module identification.
151 public AutoGen(String fvDir
, String outputPath
, ModuleIdentification moduleId
, String arch
, SurfaceAreaQuery saq
, ModuleIdentification parentId
) {
152 this.outputPath
= outputPath
;
153 this.moduleId
= moduleId
;
157 this.parentId
= parentId
;
163 This function save the content in stringBuffer to file.
168 The content of AutoGen file in buffer.
173 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
175 File autoGenH
= new File(fileName
);
178 // if the file exists, compare their content
180 if (autoGenH
.exists()) {
181 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
183 FileReader fIn
= new FileReader(autoGenH
);
184 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
186 } catch (IOException e
) {
187 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
190 + " is exist, but can't be open!!");
195 // if we got the same file, don't re-generate it to prevent
196 // sources depending on it from re-building
198 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
204 FileWriter fOut
= new FileWriter(autoGenH
);
205 fOut
.write(fileBuffer
.toString());
208 } catch (IOException e
) {
209 EdkLog
.log(EdkLog
.EDK_INFO
, this.moduleId
.getName()
212 + " can't be create!!");
221 This function call libGenAutoGen or moduleGenAutogen function, which
222 dependence on generate library autogen or module autogen.
224 @throws BuildException
225 Failed to creat AutoGen.c & AutoGen.h.
227 public void genAutogen() throws EdkException
{
229 // If outputPath do not exist, create it.
231 File path
= new File(outputPath
);
235 // Check current is library or not, then call the corresponding
238 if (this.moduleId
.isLibrary()) {
246 moduleGenAutogen function
248 This function generates AutoGen.c & AutoGen.h for module.
250 @throws BuildException
251 Faile to create module AutoGen.c & AutoGen.h.
253 void moduleGenAutogen() throws EdkException
{
254 setPcdComponentName();
255 setPcdDriverDiagnostic();
256 collectLibInstanceInfo();
262 libGenAutogen function
264 This function generates AutoGen.c & AutoGen.h for library.
266 @throws BuildException
267 Faile to create library AutoGen.c & AutoGen.h
269 void libGenAutogen() throws EdkException
{
277 This function generates AutoGen.h for module.
279 @throws BuildException
280 Failed to generate AutoGen.h.
282 void moduleGenAutogenH() throws EdkException
{
284 Set
<String
> libClassIncludeH
;
286 // List<String> headerFileList;
287 List
<String
> headerFileList
;
289 StringBuffer fileBuffer
= new StringBuffer(8192);
292 // Write Autogen.h header notation
294 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
297 // Add #ifndef ${BaseName}_AUTOGENH
298 // #def ${BseeName}_AUTOGENH
300 fileBuffer
.append(CommonDefinition
.IFNDEF
301 + CommonDefinition
.AUTOGENH
302 + this.moduleId
.getGuid().replaceAll("-", "_")
303 + ToolDefinitions
.LINE_SEPARATOR
);
304 fileBuffer
.append(CommonDefinition
.DEFINE
305 + CommonDefinition
.AUTOGENH
306 + this.moduleId
.getGuid().replaceAll("-", "_")
307 + ToolDefinitions
.LINE_SEPARATOR
308 + ToolDefinitions
.LINE_SEPARATOR
);
311 // Write the specification version and release version at the begine
312 // of autogen.h file.
313 // Note: the specification version and release version should
314 // be got from module surface area instead of hard code by it's
317 moduleType
= saq
.getModuleType();
320 // Add "extern int __make_me_compile_correctly;" at begin of
323 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
326 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
328 String
[] specList
= saq
.getExternSpecificaiton();
329 for (int i
= 0; i
< specList
.length
; i
++) {
330 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
]
334 // Write consumed package's mdouleInfo related .h file to autogen.h
336 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
337 // .getDependencePkg(this.arch);
338 PackageIdentification
[] consumedPkgIdList
= saq
.getDependencePkg(this.arch
);
339 if (consumedPkgIdList
!= null) {
340 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
341 item
= headerFileList
.iterator();
342 while (item
.hasNext()) {
343 fileBuffer
.append(item
.next().toString());
348 // Write library class's related *.h file to autogen.h.
350 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
,this.arch
);
351 if (libClassList
!= null) {
352 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
353 item
= libClassIncludeH
.iterator();
354 while (item
.hasNext()) {
355 fileBuffer
.append(item
.next().toString());
359 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
);
360 if (libClassList
!= null) {
361 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
362 item
= libClassIncludeH
.iterator();
363 while (item
.hasNext()) {
364 fileBuffer
.append(item
.next().toString());
367 fileBuffer
.append("\r\n");
370 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
371 // {DEST_DIR_DRBUG}/FlashMap.h
373 if (saq
.isHaveTianoR8FlashMap()) {
374 fileBuffer
.append(CommonDefinition
.INCLUDE
);
375 fileBuffer
.append(" <");
376 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
377 copyFlashMapHToDebugDir();
380 // Write PCD autogen information to AutoGen.h.
382 if (this.myPcdAutogen
!= null) {
383 fileBuffer
.append("\r\n");
384 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
387 fileBuffer
.append(functionDeclarations
);
389 // Append the #endif at AutoGen.h
391 fileBuffer
.append("#endif\r\n");
394 // Save string buffer content in AutoGen.h.
396 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
397 throw new AutoGenException("Failed to generate AutoGen.h !!!");
404 This function generates AutoGen.c for module.
406 @throws BuildException
407 Failed to generate AutoGen.c.
409 void moduleGenAutogenC() throws EdkException
{
411 StringBuffer fileBuffer
= new StringBuffer(8192);
413 // Write Autogen.c header notation
415 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
418 // Get the native MSA file infomation. Since before call autogen,
419 // the MSA native <Externs> information were overrided. So before
420 // process <Externs> it should be set the DOC as the Native MSA info.
422 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
426 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
430 ExternsDriverBindingToAutoGenC(fileBuffer
);
433 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
436 ExternCallBackToAutoGenC(fileBuffer
);
439 // Write EntryPoint to autgoGen.c
441 String
[] entryPointList
= saq
.getModuleEntryPointArray();
442 String
[] unloadImageList
= saq
.getModuleUnloadImageArray();
443 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
),
444 CommonDefinition
.remDupString(unloadImageList
),
447 pcdDriverType
= saq
.getPcdDriverType();
450 // Restore the DOC which include the FPD module info.
455 // Write Guid to autogen.c
457 String guid
= CommonDefinition
.formatGuidName(saq
.getModuleGuid());
458 if (this.moduleId
.getModuleType().equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
459 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");
461 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
465 throw new AutoGenException("Guid value must set!\n");
469 // Formate Guid as ANSI c form.Example:
470 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
474 fileBuffer
.append(guid
);
475 fileBuffer
.append("};\r\n");
478 // Generate library instance consumed protocol, guid, ppi, pcd list.
479 // Save those to this.protocolList, this.ppiList, this.pcdList,
480 // this.guidList. Write Consumed library constructor and desconstuct to
483 LibInstanceToAutogenC(fileBuffer
);
486 // Get module dependent Package identification.
488 PackageIdentification
[] packages
= saq
.getDependencePkg(this.arch
);
489 for (int i
= 0; i
< packages
.length
; i
++) {
490 if (!this.mDepPkgList
.contains(packages
[i
])) {
491 this.mDepPkgList
.add(packages
[i
]);
497 // Write consumed ppi, guid, protocol to autogen.c
499 ProtocolGuidToAutogenC(fileBuffer
);
500 PpiGuidToAutogenC(fileBuffer
);
501 GuidGuidToAutogenC(fileBuffer
);
506 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
513 this.myPcdAutogen
.execute();
514 if (this.myPcdAutogen
!= null) {
515 fileBuffer
.append("\r\n");
516 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
519 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
520 throw new AutoGenException("Failed to generate AutoGen.c !!!");
528 This function generates AutoGen.h for library.
530 @throws BuildException
531 Failed to generate AutoGen.c.
533 void libGenAutogenH() throws EdkException
{
535 Set
<String
> libClassIncludeH
;
537 List
<String
> headerFileList
;
539 StringBuffer fileBuffer
= new StringBuffer(10240);
542 // Write Autogen.h header notation
544 fileBuffer
.append(CommonDefinition
.AUTOGENHNOTATION
);
547 // Add #ifndef ${BaseName}_AUTOGENH
548 // #def ${BseeName}_AUTOGENH
550 fileBuffer
.append(CommonDefinition
.IFNDEF
551 + CommonDefinition
.AUTOGENH
552 + this.moduleId
.getGuid().replaceAll("-", "_")
553 + ToolDefinitions
.LINE_SEPARATOR
);
554 fileBuffer
.append(CommonDefinition
.DEFINE
555 + CommonDefinition
.AUTOGENH
556 + this.moduleId
.getGuid().replaceAll("-", "_")
557 + ToolDefinitions
.LINE_SEPARATOR
558 + ToolDefinitions
.LINE_SEPARATOR
);
561 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
562 // to autogen.h file.
563 // Note: the specification version and release version should
564 // be get from module surface area instead of hard code.
566 fileBuffer
.append(CommonDefinition
.AUTOGENHBEGIN
);
567 String
[] specList
= saq
.getExternSpecificaiton();
568 for (int i
= 0; i
< specList
.length
; i
++) {
569 fileBuffer
.append(CommonDefinition
.DEFINE
+ specList
[i
] + "\r\n");
571 // fileBuffer.append(CommonDefinition.autoGenHLine1);
572 // fileBuffer.append(CommonDefinition.autoGenHLine2);
575 // Write consumed package's mdouleInfo related *.h file to autogen.h.
577 moduleType
= saq
.getModuleType();
578 PackageIdentification
[] cosumedPkglist
= saq
.getDependencePkg(this.arch
);
579 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
580 item
= headerFileList
.iterator();
581 while (item
.hasNext()) {
582 fileBuffer
.append(item
.next().toString());
585 // Write library class's related *.h file to autogen.h
587 String
[] libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSCONSUMED
, this.arch
);
588 if (libClassList
!= null) {
589 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
590 item
= libClassIncludeH
.iterator();
591 while (item
.hasNext()) {
592 fileBuffer
.append(item
.next().toString());
596 libClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
, this.arch
);
597 if (libClassList
!= null) {
598 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
599 item
= libClassIncludeH
.iterator();
600 while (item
.hasNext()) {
601 fileBuffer
.append(item
.next().toString());
604 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
607 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
608 // {DEST_DIR_DRBUG}/FlashMap.h
610 if (saq
.isHaveTianoR8FlashMap()) {
611 fileBuffer
.append(CommonDefinition
.INCLUDE
);
612 fileBuffer
.append(" <");
613 fileBuffer
.append(CommonDefinition
.TIANOR8PLASHMAPH
+ ">\r\n");
614 copyFlashMapHToDebugDir();
618 // Write PCD information to library AutoGen.h.
620 if (this.myPcdAutogen
!= null) {
621 fileBuffer
.append("\r\n");
622 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
625 // generate function prototype for constructor and destructor
627 LibConstructorToAutogenH(moduleType
);
628 LibDestructorToAutogenH(moduleType
);
629 ExternCallBackToAutoGenH(moduleType
);
630 fileBuffer
.append(functionDeclarations
);
632 // Append the #endif at AutoGen.h
634 fileBuffer
.append("#endif\r\n");
636 // Save content of string buffer to AutoGen.h file.
638 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
639 throw new AutoGenException("Failed to generate AutoGen.h !!!");
646 This function generates AutoGen.h for library.
648 @throws BuildException
649 Failed to generate AutoGen.c.
651 void libGenAutogenC() throws EdkException
{
652 StringBuffer fileBuffer
= new StringBuffer(10240);
655 // Write Autogen.c header notation
657 fileBuffer
.append(CommonDefinition
.AUTOGENCNOTATION
);
659 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
660 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
665 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
668 saq
.getModulePcdEntryNameArray(this.arch
),
671 this.myPcdAutogen
.execute();
672 if (this.myPcdAutogen
!= null) {
673 fileBuffer
.append(ToolDefinitions
.LINE_SEPARATOR
);
674 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
677 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
678 throw new AutoGenException("Failed to generate AutoGen.c !!!");
683 LibraryClassToAutogenH
685 This function returns *.h files declared by library classes which are
686 consumed or produced by current build module or library.
689 List of library class which consumed or produce by current
690 build module or library.
691 @return includeStrList List of *.h file.
693 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
)
694 throws EdkException
{
695 Set
<String
> includeStrList
= new LinkedHashSet
<String
>();
696 String includeName
[];
700 // Get include file from GlobalData's SPDTable according to
701 // library class name.
703 for (int i
= 0; i
< libClassList
.length
; i
++) {
704 includeName
= GlobalData
.getLibraryClassHeaderFiles(
705 saq
.getDependencePkg(this.arch
),
707 if (includeName
== null) {
708 throw new AutoGenException("Can not find library class ["
709 + libClassList
[i
] + "] declaration in any SPD package. ");
711 for (int j
= 0; j
< includeName
.length
; j
++) {
712 String includeNameStr
= includeName
[j
];
713 if (includeNameStr
!= null) {
714 str
= CommonDefinition
.INCLUDE
+ " " + "<";
715 str
= str
+ includeNameStr
+ ">\r\n";
716 includeStrList
.add(str
);
717 includeNameStr
= null;
721 return includeStrList
;
727 This function add include file in AutoGen.h file.
729 @param packageNameList
730 List of module depended package.
735 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
736 String moduleType
) throws AutoGenException
{
738 List
<String
> includeStrList
= new LinkedList
<String
>();
740 String includeStr
= "";
743 // Get include file from moduleInfo file
745 for (int i
= 0; i
< packageNameList
.length
; i
++) {
746 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
748 if (pkgHeader
== null) {
749 throw new AutoGenException("Can not find package ["
751 + "] declaration in any SPD package. ");
752 } else if (!pkgHeader
.equalsIgnoreCase("")) {
753 includeStr
= CommonDefinition
.INCLUDE
+ " <" + pkgHeader
+ ">\r\n";
754 includeStrList
.add(includeStr
);
758 return includeStrList
;
764 This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
765 information in mas to AutoGen.c
767 @param entryPointList
770 String buffer fo AutoGen.c.
773 void EntryPointToAutoGen(String
[] entryPointList
, String
[] unloadImageList
, StringBuffer fileBuffer
)
774 throws EdkException
{
776 String typeStr
= saq
.getModuleType();
777 String debugStr
= "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";
778 int unloadImageCount
= 0;
779 int entryPointCount
= 0;
782 // The parameters and return value of entryPoint is difference
783 // for difference module type.
785 switch (CommonDefinition
.getModuleType(typeStr
)) {
787 case CommonDefinition
.ModuleTypePeiCore
:
788 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
789 throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");
791 fileBuffer
.append("EFI_STATUS\r\n");
792 fileBuffer
.append("EFIAPI\r\n");
793 fileBuffer
.append(entryPointList
[0]);
794 fileBuffer
.append(" (\r\n");
795 fileBuffer
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
796 fileBuffer
.append(" IN VOID *OldCoreData\r\n");
797 fileBuffer
.append(" );\r\n\r\n");
799 fileBuffer
.append("EFI_STATUS\r\n");
800 fileBuffer
.append("EFIAPI\r\n");
801 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
802 fileBuffer
.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
803 fileBuffer
.append(" IN VOID *OldCoreData\r\n");
804 fileBuffer
.append(" )\r\n\r\n");
805 fileBuffer
.append("{\r\n");
806 fileBuffer
.append(" return ");
807 fileBuffer
.append(entryPointList
[0]);
808 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
809 fileBuffer
.append("}\r\n\r\n");
813 case CommonDefinition
.ModuleTypeDxeCore
:
814 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
815 if (entryPointList
== null || entryPointList
.length
!= 1) {
816 throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");
818 fileBuffer
.append("VOID\r\n");
819 fileBuffer
.append("EFIAPI\r\n");
820 fileBuffer
.append(entryPointList
[0]);
821 fileBuffer
.append(" (\r\n");
822 fileBuffer
.append(" IN VOID *HobStart\r\n");
823 fileBuffer
.append(" );\r\n\r\n");
825 fileBuffer
.append("VOID\r\n");
826 fileBuffer
.append("EFIAPI\r\n");
827 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
828 fileBuffer
.append(" IN VOID *HobStart\r\n");
829 fileBuffer
.append(" )\r\n\r\n");
830 fileBuffer
.append("{\r\n");
831 fileBuffer
.append(" ");
832 fileBuffer
.append(entryPointList
[0]);
833 fileBuffer
.append(" (HobStart);\r\n");
834 fileBuffer
.append("}\r\n\r\n");
838 case CommonDefinition
.ModuleTypePeim
:
840 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
841 if (entryPointList
== null || entryPointList
.length
== 0) {
842 fileBuffer
.append("EFI_STATUS\r\n");
843 fileBuffer
.append("EFIAPI\r\n");
844 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
845 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
846 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
847 fileBuffer
.append(" )\r\n\r\n");
848 fileBuffer
.append("{\r\n");
849 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
850 fileBuffer
.append("}\r\n\r\n");
853 for (int i
= 0; i
< entryPointList
.length
; i
++) {
854 fileBuffer
.append("EFI_STATUS\r\n");
855 fileBuffer
.append("EFIAPI\r\n");
856 fileBuffer
.append(entryPointList
[i
]);
857 fileBuffer
.append(" (\r\n");
858 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
859 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
860 fileBuffer
.append(" );\r\n");
864 fileBuffer
.append("EFI_STATUS\r\n");
865 fileBuffer
.append("EFIAPI\r\n");
866 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
867 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
868 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
869 fileBuffer
.append(" )\r\n\r\n");
870 fileBuffer
.append("{\r\n");
871 if (entryPointCount
== 1) {
872 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
873 fileBuffer
.append(" return ");
874 fileBuffer
.append(entryPointList
[0]);
875 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
877 fileBuffer
.append(" EFI_STATUS Status;\r\n");
878 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
879 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
880 for (int i
= 0; i
< entryPointList
.length
; i
++) {
881 if (!entryPointList
[i
].equals("")) {
882 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
883 fileBuffer
.append(" Status = ");
884 fileBuffer
.append(entryPointList
[i
]);
885 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
886 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
887 fileBuffer
.append(" CombinedStatus = Status;\r\n");
888 fileBuffer
.append(" }\r\n\r\n");
893 fileBuffer
.append(" return CombinedStatus;\r\n");
895 fileBuffer
.append("}\r\n\r\n");
898 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
901 // If entryPoint is null, create an empty ProcessModuleEntryPointList
904 if (entryPointList
== null || entryPointList
.length
== 0) {
905 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
906 fileBuffer
.append(Integer
.toString(entryPointCount
));
907 fileBuffer
.append(";\r\n");
908 fileBuffer
.append("EFI_STATUS\r\n");
909 fileBuffer
.append("EFIAPI\r\n");
910 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
911 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
912 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
913 fileBuffer
.append(" )\r\n\r\n");
914 fileBuffer
.append("{\r\n");
915 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
916 fileBuffer
.append("}\r\n\r\n");
919 for (int i
= 0; i
< entryPointList
.length
; i
++) {
920 fileBuffer
.append("EFI_STATUS\r\n");
921 fileBuffer
.append("EFIAPI\r\n");
922 fileBuffer
.append(entryPointList
[i
]);
923 fileBuffer
.append(" (\r\n");
924 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
925 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
926 fileBuffer
.append(" );\r\n");
929 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
930 fileBuffer
.append(Integer
.toString(entryPointCount
));
931 fileBuffer
.append(";\r\n");
932 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
933 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
935 fileBuffer
.append("EFI_STATUS\r\n");
936 fileBuffer
.append("EFIAPI\r\n");
937 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
938 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
939 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
940 fileBuffer
.append(" )\r\n\r\n");
941 fileBuffer
.append("{\r\n");
943 for (int i
= 0; i
< entryPointList
.length
; i
++) {
944 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
945 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
946 fileBuffer
.append(" ExitDriver (");
947 fileBuffer
.append(entryPointList
[i
]);
948 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
949 fileBuffer
.append(" ASSERT (FALSE);\r\n");
950 fileBuffer
.append(" }\r\n");
952 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
953 fileBuffer
.append("}\r\n\r\n");
955 fileBuffer
.append("VOID\r\n");
956 fileBuffer
.append("EFIAPI\r\n");
957 fileBuffer
.append("ExitDriver (\r\n");
958 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
959 fileBuffer
.append(" )\r\n\r\n");
960 fileBuffer
.append("{\r\n");
961 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
962 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
963 fileBuffer
.append(" }\r\n");
964 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
965 fileBuffer
.append(" ASSERT (FALSE);\r\n");
966 fileBuffer
.append("}\r\n\r\n");
971 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
974 unloadImageCount
= 0;
975 if (unloadImageList
!= null) {
976 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
977 fileBuffer
.append("EFI_STATUS\r\n");
978 fileBuffer
.append(unloadImageList
[i
]);
979 fileBuffer
.append(" (\r\n");
980 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
981 fileBuffer
.append(" );\r\n");
986 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
987 fileBuffer
.append(Integer
.toString(unloadImageCount
));
988 fileBuffer
.append(";\r\n\r\n");
990 fileBuffer
.append("EFI_STATUS\r\n");
991 fileBuffer
.append("EFIAPI\r\n");
992 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
993 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
994 fileBuffer
.append(" )\r\n");
995 fileBuffer
.append("{\r\n");
997 if (unloadImageCount
== 0) {
998 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
999 } else if (unloadImageCount
== 1) {
1000 fileBuffer
.append(" return ");
1001 fileBuffer
.append(unloadImageList
[0]);
1002 fileBuffer
.append("(ImageHandle);\r\n");
1004 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1005 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1006 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1008 fileBuffer
.append(" Status = ");
1009 fileBuffer
.append(unloadImageList
[i
]);
1010 fileBuffer
.append("(ImageHandle);\r\n");
1012 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1013 fileBuffer
.append(" ");
1014 fileBuffer
.append(unloadImageList
[i
]);
1015 fileBuffer
.append("(ImageHandle);\r\n");
1016 fileBuffer
.append(" } else {\r\n");
1017 fileBuffer
.append(" Status = ");
1018 fileBuffer
.append(unloadImageList
[i
]);
1019 fileBuffer
.append("(ImageHandle);\r\n");
1020 fileBuffer
.append(" }\r\n");
1023 fileBuffer
.append(" return Status;\r\n");
1025 fileBuffer
.append("}\r\n\r\n");
1028 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1029 case CommonDefinition
.ModuleTypeDxeDriver
:
1030 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1031 case CommonDefinition
.ModuleTypeUefiDriver
:
1032 case CommonDefinition
.ModuleTypeUefiApplication
:
1033 entryPointCount
= 0;
1034 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1036 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1038 if (entryPointList
== null || entryPointList
.length
== 0) {
1039 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1040 fileBuffer
.append("EFI_STATUS\r\n");
1041 fileBuffer
.append("EFIAPI\r\n");
1042 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1043 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1044 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1045 fileBuffer
.append(" )\r\n\r\n");
1046 fileBuffer
.append("{\r\n");
1047 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1048 fileBuffer
.append("}\r\n");
1051 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1052 fileBuffer
.append("EFI_STATUS\r\n");
1053 fileBuffer
.append("EFIAPI\r\n");
1054 fileBuffer
.append(entryPointList
[i
]);
1055 fileBuffer
.append(" (\r\n");
1056 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1057 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1058 fileBuffer
.append(" );\r\n");
1062 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1063 fileBuffer
.append(Integer
.toString(entryPointCount
));
1064 fileBuffer
.append(";\r\n");
1065 if (entryPointCount
> 1) {
1066 fileBuffer
.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1067 fileBuffer
.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1069 fileBuffer
.append("\r\n");
1071 fileBuffer
.append("EFI_STATUS\r\n");
1072 fileBuffer
.append("EFIAPI\r\n");
1073 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1074 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1075 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1076 fileBuffer
.append(" )\r\n\r\n");
1077 fileBuffer
.append("{\r\n");
1079 if (entryPointCount
== 1) {
1080 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[0], entryPointList
[0]));
1081 fileBuffer
.append(" return ");
1082 fileBuffer
.append(entryPointList
[0]);
1083 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1085 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1086 if (!entryPointList
[i
].equals("")) {
1087 fileBuffer
.append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1088 fileBuffer
.append(String
.format(" " + debugStr
, entryPointList
[i
], entryPointList
[i
]));
1089 fileBuffer
.append(" ExitDriver (");
1090 fileBuffer
.append(entryPointList
[i
]);
1091 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1092 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1093 fileBuffer
.append(" }\r\n");
1098 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1100 fileBuffer
.append("}\r\n\r\n");
1102 fileBuffer
.append("VOID\r\n");
1103 fileBuffer
.append("EFIAPI\r\n");
1104 fileBuffer
.append("ExitDriver (\r\n");
1105 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1106 fileBuffer
.append(" )\r\n\r\n");
1107 fileBuffer
.append("{\r\n");
1108 if (entryPointCount
<= 1) {
1109 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1110 fileBuffer
.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1111 fileBuffer
.append(" }\r\n");
1113 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1115 fileBuffer
.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1116 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1117 fileBuffer
.append(" }\r\n");
1118 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1119 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1121 fileBuffer
.append("}\r\n\r\n");
1125 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1127 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1129 // Remover duplicate unload entry point.
1131 //entryPointList = CommonDefinition.remDupString(entryPointList);
1132 //entryPointCount = 0;
1133 unloadImageCount
= 0;
1134 if (unloadImageList
!= null) {
1135 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1136 fileBuffer
.append("EFI_STATUS\r\n");
1137 fileBuffer
.append("EFIAPI\r\n");
1138 fileBuffer
.append(unloadImageList
[i
]);
1139 fileBuffer
.append(" (\r\n");
1140 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1141 fileBuffer
.append(" );\r\n");
1146 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1147 fileBuffer
.append(Integer
.toString(unloadImageCount
));
1148 fileBuffer
.append(";\r\n\r\n");
1150 fileBuffer
.append("EFI_STATUS\r\n");
1151 fileBuffer
.append("EFIAPI\r\n");
1152 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1153 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1154 fileBuffer
.append(" )\r\n");
1155 fileBuffer
.append("{\r\n");
1157 if (unloadImageCount
== 0) {
1158 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1159 } else if (unloadImageCount
== 1) {
1160 fileBuffer
.append(" return ");
1161 fileBuffer
.append(unloadImageList
[0]);
1162 fileBuffer
.append("(ImageHandle);\r\n");
1164 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1165 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1166 for (int i
= 0; i
< unloadImageList
.length
; i
++) {
1168 fileBuffer
.append(" Status = ");
1169 fileBuffer
.append(unloadImageList
[i
]);
1170 fileBuffer
.append("(ImageHandle);\r\n");
1172 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1173 fileBuffer
.append(" ");
1174 fileBuffer
.append(unloadImageList
[i
]);
1175 fileBuffer
.append("(ImageHandle);\r\n");
1176 fileBuffer
.append(" } else {\r\n");
1177 fileBuffer
.append(" Status = ");
1178 fileBuffer
.append(unloadImageList
[i
]);
1179 fileBuffer
.append("(ImageHandle);\r\n");
1180 fileBuffer
.append(" }\r\n");
1183 fileBuffer
.append(" return Status;\r\n");
1185 fileBuffer
.append("}\r\n\r\n");
1193 This function gets GUIDs from SPD file accrodeing to <PPIs> information
1194 and write those GUIDs to AutoGen.c.
1197 String Buffer for Autogen.c file.
1198 @throws BuildException
1199 Guid must set value!
1201 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1202 String
[] cNameGuid
= null;
1205 // Get the all PPI adn PPI Notify from MSA file,
1206 // then add those PPI ,and PPI Notify name to list.
1209 String
[] ppiList
= saq
.getPpiArray(this.arch
);
1210 for (int i
= 0; i
< ppiList
.length
; i
++) {
1211 this.mPpiList
.add(ppiList
[i
]);
1214 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
1215 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1216 this.mPpiList
.add(ppiNotifyList
[i
]);
1220 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1222 Iterator ppiIterator
= this.mPpiList
.iterator();
1223 String ppiKeyWord
= null;
1224 while (ppiIterator
.hasNext()) {
1225 ppiKeyWord
= ppiIterator
.next().toString();
1226 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1227 if (cNameGuid
!= null) {
1228 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1229 fileBuffer
.append(cNameGuid
[0]);
1230 fileBuffer
.append(" = { ");
1231 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1232 fileBuffer
.append(" } ;");
1235 // If can't find Ppi GUID declaration in every package
1237 throw new AutoGenException("Can not find Ppi GUID ["
1238 + ppiKeyWord
+ "] declaration in any SPD package!");
1244 ProtocolGuidToAutogenc
1246 This function gets GUIDs from SPD file accrodeing to <Protocol>
1247 information and write those GUIDs to AutoGen.c.
1250 String Buffer for Autogen.c file.
1251 @throws BuildException
1252 Protocol name must set.
1254 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1255 String
[] cNameGuid
= null;
1257 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
1260 // Add result to Autogen global list.
1262 for (int i
= 0; i
< protocolList
.length
; i
++) {
1263 this.mProtocolList
.add(protocolList
[i
]);
1266 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
1268 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1269 this.mProtocolList
.add(protocolNotifyList
[i
]);
1273 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1275 Iterator protocolIterator
= this.mProtocolList
.iterator();
1276 String protocolKeyWord
= null;
1279 while (protocolIterator
.hasNext()) {
1280 protocolKeyWord
= protocolIterator
.next().toString();
1281 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1282 if (cNameGuid
!= null) {
1283 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1284 fileBuffer
.append(cNameGuid
[0]);
1285 fileBuffer
.append(" = { ");
1286 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1287 fileBuffer
.append(" } ;");
1290 // If can't find protocol GUID declaration in every package
1292 throw new AutoGenException("Can not find protocol Guid ["
1293 + protocolKeyWord
+ "] declaration in any SPD package!");
1301 This function gets GUIDs from SPD file accrodeing to <Guids> information
1302 and write those GUIDs to AutoGen.c.
1305 String Buffer for Autogen.c file.
1308 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1309 String
[] cNameGuid
= null;
1310 String guidKeyWord
= null;
1312 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
1314 for (int i
= 0; i
< guidList
.length
; i
++) {
1315 this.mGuidList
.add(guidList
[i
]);
1319 Iterator guidIterator
= this.mGuidList
.iterator();
1320 while (guidIterator
.hasNext()) {
1321 guidKeyWord
= guidIterator
.next().toString();
1322 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1324 if (cNameGuid
!= null) {
1325 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1326 fileBuffer
.append(cNameGuid
[0]);
1327 fileBuffer
.append(" = { ");
1328 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1329 fileBuffer
.append("} ;");
1332 // If can't find GUID declaration in every package
1334 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1335 + "] declaration in any SPD package. ");
1342 LibInstanceToAutogenC
1344 This function adds dependent library instance to autogen.c,which
1345 includeing library's constructor, destructor, and library dependent ppi,
1346 protocol, guid, pcd information.
1349 String buffer for AutoGen.c
1350 @throws BuildException
1352 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws EdkException
{
1353 String moduleType
= this.moduleId
.getModuleType();
1355 // Add library constructor to AutoGen.c
1357 LibConstructorToAutogenC(libConstructList
, moduleType
,
1358 fileBuffer
/* autogenC */);
1360 // Add library destructor to AutoGen.c
1362 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
/* autogenC */);
1366 LibConstructorToAutogenH
1368 This function writes library constructor declarations AutoGen.h. The library
1369 constructor's parameter and return value depend on module type.
1371 @param libInstanceList
1372 List of library construct name.
1376 String buffer for AutoGen.c
1379 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1380 boolean isFirst
= true;
1383 // If not yet parse this library instance's constructor
1384 // element,parse it.
1386 String libConstructName
= saq
.getLibConstructorName();
1387 if (libConstructName
== null) {
1392 // The library constructor's parameter and return value depend on
1395 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1396 functionDeclarations
.append("RETURN_STATUS\r\n");
1397 functionDeclarations
.append("EFIAPI\r\n");
1398 functionDeclarations
.append(libConstructName
);
1399 functionDeclarations
.append(" (\r\n");
1400 functionDeclarations
.append(" VOID\r\n");
1401 functionDeclarations
.append(" );\r\n");
1403 switch (CommonDefinition
.getModuleType(moduleType
)) {
1404 case CommonDefinition
.ModuleTypeBase
:
1405 functionDeclarations
.append("RETURN_STATUS\r\n");
1406 functionDeclarations
.append("EFIAPI\r\n");
1407 functionDeclarations
.append(libConstructName
);
1408 functionDeclarations
.append(" (\r\n");
1409 functionDeclarations
.append(" VOID\r\n");
1410 functionDeclarations
.append(" );\r\n");
1413 case CommonDefinition
.ModuleTypePeiCore
:
1414 case CommonDefinition
.ModuleTypePeim
:
1415 functionDeclarations
.append("EFI_STATUS\r\n");
1416 functionDeclarations
.append("EFIAPI\r\n");
1417 functionDeclarations
.append(libConstructName
);
1418 functionDeclarations
.append(" (\r\n");
1419 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1420 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1421 functionDeclarations
.append(" );\r\n");
1424 case CommonDefinition
.ModuleTypeDxeCore
:
1425 case CommonDefinition
.ModuleTypeDxeDriver
:
1426 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1427 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1428 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1429 case CommonDefinition
.ModuleTypeUefiDriver
:
1430 case CommonDefinition
.ModuleTypeUefiApplication
:
1431 functionDeclarations
.append("EFI_STATUS\r\n");
1432 functionDeclarations
.append("EFIAPI\r\n");
1433 functionDeclarations
.append(libConstructName
);
1434 functionDeclarations
.append(" (\r\n");
1435 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1436 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1437 functionDeclarations
.append(" );\r\n");
1445 LibDestructorToAutogenH
1447 This function writes library destructor declarations AutoGen.h. The library
1448 destructor's parameter and return value depend on module type.
1450 @param libInstanceList
1451 List of library destructor name.
1455 String buffer for AutoGen.c
1458 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1459 boolean isFirst
= true;
1460 String libDestructName
= saq
.getLibDestructorName();
1461 if (libDestructName
== null) {
1465 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1466 functionDeclarations
.append("RETURN_STATUS\r\n");
1467 functionDeclarations
.append("EFIAPI\r\n");
1468 functionDeclarations
.append(libDestructName
);
1469 functionDeclarations
.append(" (\r\n");
1470 functionDeclarations
.append(" VOID\r\n");
1471 functionDeclarations
.append(" );\r\n");
1473 switch (CommonDefinition
.getModuleType(moduleType
)) {
1474 case CommonDefinition
.ModuleTypeBase
:
1475 functionDeclarations
.append("RETURN_STATUS\r\n");
1476 functionDeclarations
.append("EFIAPI\r\n");
1477 functionDeclarations
.append(libDestructName
);
1478 functionDeclarations
.append(" (\r\n");
1479 functionDeclarations
.append(" VOID\r\n");
1480 functionDeclarations
.append(" );\r\n");
1482 case CommonDefinition
.ModuleTypePeiCore
:
1483 case CommonDefinition
.ModuleTypePeim
:
1484 functionDeclarations
.append("EFI_STATUS\r\n");
1485 functionDeclarations
.append("EFIAPI\r\n");
1486 functionDeclarations
.append(libDestructName
);
1487 functionDeclarations
.append(" (\r\n");
1488 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1489 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1490 functionDeclarations
.append(" );\r\n");
1492 case CommonDefinition
.ModuleTypeDxeCore
:
1493 case CommonDefinition
.ModuleTypeDxeDriver
:
1494 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1495 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1496 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1497 case CommonDefinition
.ModuleTypeUefiDriver
:
1498 case CommonDefinition
.ModuleTypeUefiApplication
:
1499 functionDeclarations
.append("EFI_STATUS\r\n");
1500 functionDeclarations
.append("EFIAPI\r\n");
1501 functionDeclarations
.append(libDestructName
);
1502 functionDeclarations
.append(" (\r\n");
1503 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1504 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1505 functionDeclarations
.append(" );\r\n");
1512 LibConstructorToAutogenc
1514 This function writes library constructor list to AutoGen.c. The library
1515 constructor's parameter and return value depend on module type.
1517 @param libInstanceList
1518 List of library construct name.
1522 String buffer for AutoGen.c
1525 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1526 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1527 boolean isFirst
= true;
1530 // The library constructor's parameter and return value depend on
1533 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1534 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1535 functionDeclarations
.append("RETURN_STATUS\r\n");
1536 functionDeclarations
.append("EFIAPI\r\n");
1537 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1538 functionDeclarations
.append(" (\r\n");
1539 functionDeclarations
.append(" VOID\r\n");
1540 functionDeclarations
.append(" );\r\n");
1542 switch (CommonDefinition
.getModuleType(moduleType
)) {
1543 case CommonDefinition
.ModuleTypeBase
:
1544 functionDeclarations
.append("RETURN_STATUS\r\n");
1545 functionDeclarations
.append("EFIAPI\r\n");
1546 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1547 functionDeclarations
.append(" (\r\n");
1548 functionDeclarations
.append(" VOID\r\n");
1549 functionDeclarations
.append(" );\r\n");
1552 case CommonDefinition
.ModuleTypePeiCore
:
1553 case CommonDefinition
.ModuleTypePeim
:
1554 functionDeclarations
.append("EFI_STATUS\r\n");
1555 functionDeclarations
.append("EFIAPI\r\n");
1556 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1557 functionDeclarations
.append(" (\r\n");
1558 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1559 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1560 functionDeclarations
.append(" );\r\n");
1563 case CommonDefinition
.ModuleTypeDxeCore
:
1564 case CommonDefinition
.ModuleTypeDxeDriver
:
1565 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1566 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1567 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1568 case CommonDefinition
.ModuleTypeUefiDriver
:
1569 case CommonDefinition
.ModuleTypeUefiApplication
:
1570 functionDeclarations
.append("EFI_STATUS\r\n");
1571 functionDeclarations
.append("EFIAPI\r\n");
1572 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1573 functionDeclarations
.append(" (\r\n");
1574 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1575 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1576 functionDeclarations
.append(" );\r\n");
1584 // Add ProcessLibraryConstructorList in AutoGen.c
1586 fileBuffer
.append("VOID\r\n");
1587 fileBuffer
.append("EFIAPI\r\n");
1588 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1589 switch (CommonDefinition
.getModuleType(moduleType
)) {
1590 case CommonDefinition
.ModuleTypeBase
:
1591 fileBuffer
.append(" VOID\r\n");
1594 case CommonDefinition
.ModuleTypePeiCore
:
1595 case CommonDefinition
.ModuleTypePeim
:
1596 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1598 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1601 case CommonDefinition
.ModuleTypeDxeCore
:
1602 case CommonDefinition
.ModuleTypeDxeDriver
:
1603 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1604 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1605 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1606 case CommonDefinition
.ModuleTypeUefiDriver
:
1607 case CommonDefinition
.ModuleTypeUefiApplication
:
1608 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1609 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1613 fileBuffer
.append(" )\r\n");
1614 fileBuffer
.append("{\r\n");
1616 // If no constructor function, return EFI_SUCCESS.
1618 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1620 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1621 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1622 fileBuffer
.append("\r\n");
1625 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1626 fileBuffer
.append(" Status = ");
1627 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1628 fileBuffer
.append("();\r\n");
1630 switch (CommonDefinition
.getModuleType(moduleType
)) {
1631 case CommonDefinition
.ModuleTypeBase
:
1632 fileBuffer
.append(" Status = ");
1633 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1634 fileBuffer
.append("();\r\n");
1636 case CommonDefinition
.ModuleTypePeiCore
:
1637 case CommonDefinition
.ModuleTypePeim
:
1638 fileBuffer
.append(" Status = ");
1639 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1640 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1642 case CommonDefinition
.ModuleTypeDxeCore
:
1643 case CommonDefinition
.ModuleTypeDxeDriver
:
1644 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1645 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1646 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1647 case CommonDefinition
.ModuleTypeUefiDriver
:
1648 case CommonDefinition
.ModuleTypeUefiApplication
:
1649 fileBuffer
.append(" Status = ");
1650 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1651 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1654 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1658 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1660 fileBuffer
.append("}\r\n");
1664 LibDestructorToAutogenc
1666 This function writes library destructor list to AutoGen.c. The library
1667 destructor's parameter and return value depend on module type.
1669 @param libInstanceList
1670 List of library destructor name.
1674 String buffer for AutoGen.c
1677 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1678 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1679 boolean isFirst
= true;
1680 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1681 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1682 functionDeclarations
.append("RETURN_STATUS\r\n");
1683 functionDeclarations
.append("EFIAPI\r\n");
1684 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1685 functionDeclarations
.append(" (\r\n");
1686 functionDeclarations
.append(" VOID\r\n");
1687 functionDeclarations
.append(" );\r\n");
1689 switch (CommonDefinition
.getModuleType(moduleType
)) {
1690 case CommonDefinition
.ModuleTypeBase
:
1691 functionDeclarations
.append("RETURN_STATUS\r\n");
1692 functionDeclarations
.append("EFIAPI\r\n");
1693 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1694 functionDeclarations
.append(" (\r\n");
1695 functionDeclarations
.append(" VOID\r\n");
1696 functionDeclarations
.append(" );\r\n");
1698 case CommonDefinition
.ModuleTypePeiCore
:
1699 case CommonDefinition
.ModuleTypePeim
:
1700 functionDeclarations
.append("EFI_STATUS\r\n");
1701 functionDeclarations
.append("EFIAPI\r\n");
1702 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1703 functionDeclarations
.append(" (\r\n");
1704 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1705 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1706 functionDeclarations
.append(" );\r\n");
1708 case CommonDefinition
.ModuleTypeDxeCore
:
1709 case CommonDefinition
.ModuleTypeDxeDriver
:
1710 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1711 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1712 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1713 case CommonDefinition
.ModuleTypeUefiDriver
:
1714 case CommonDefinition
.ModuleTypeUefiApplication
:
1715 functionDeclarations
.append("EFI_STATUS\r\n");
1716 functionDeclarations
.append("EFIAPI\r\n");
1717 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1718 functionDeclarations
.append(" (\r\n");
1719 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1720 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1721 functionDeclarations
.append(" );\r\n");
1728 // Write ProcessLibraryDestructor list to autogen.c
1730 switch (CommonDefinition
.getModuleType(moduleType
)) {
1731 case CommonDefinition
.ModuleTypeBase
:
1732 case CommonDefinition
.ModuleTypePeiCore
:
1733 case CommonDefinition
.ModuleTypePeim
:
1735 case CommonDefinition
.ModuleTypeDxeCore
:
1736 case CommonDefinition
.ModuleTypeDxeDriver
:
1737 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1738 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1739 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1740 case CommonDefinition
.ModuleTypeUefiDriver
:
1741 case CommonDefinition
.ModuleTypeUefiApplication
:
1742 fileBuffer
.append("VOID\r\n");
1743 fileBuffer
.append("EFIAPI\r\n");
1744 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1745 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1746 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1747 fileBuffer
.append(" )\r\n");
1748 fileBuffer
.append("{\r\n");
1750 // If no library destructor function, return EFI_SUCCESS.
1753 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1755 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1756 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1757 fileBuffer
.append("\r\n");
1760 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1761 fileBuffer
.append(" Status = ");
1762 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1763 fileBuffer
.append("();\r\n");
1764 fileBuffer
.append(" VOID\r\n");
1766 fileBuffer
.append(" Status = ");
1767 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1768 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1769 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1772 fileBuffer
.append("}\r\n");
1778 ExternsDriverBindingToAutoGenC
1780 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1781 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1784 String buffer for AutoGen.c
1786 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1787 throws EdkException
{
1789 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1790 // The second dimension is include following element: DriverBinding,
1791 // ComponentName, DriverConfiguration, DriverDiag;
1793 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1802 // Write driver binding protocol extern to autogen.c
1804 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1805 if (driverBindingGroup
[i
][0] != null) {
1806 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1807 fileBuffer
.append(driverBindingGroup
[i
][0]);
1808 fileBuffer
.append(";\r\n");
1813 // Write component name protocol extern to autogen.c
1815 if (!componentNamePcd
) {
1816 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1817 if (driverBindingGroup
[i
][1]!= null) {
1818 if (driverBindingGroup
[i
][0] != null) {
1820 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1821 fileBuffer
.append(driverBindingGroup
[i
][1]);
1822 fileBuffer
.append(";\r\n");
1824 throw new AutoGenException("DriverBinding can't be empty!!");
1831 // Write driver configration protocol extern to autogen.c
1833 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1834 if (driverBindingGroup
[i
][2] != null) {
1835 if (driverBindingGroup
[i
][0] != null) {
1837 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1838 fileBuffer
.append(driverBindingGroup
[i
][2]);
1839 fileBuffer
.append(";\r\n");
1841 throw new AutoGenException("DriverBinding can't be empty!!");
1847 // Write driver dignastic protocol extern to autogen.c
1849 if (!driverDiagnostPcd
) {
1850 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1851 if (driverBindingGroup
[i
][3] != null) {
1852 if (driverBindingGroup
[i
][0] != null) {
1854 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1855 fileBuffer
.append(driverBindingGroup
[i
][3]);
1856 fileBuffer
.append(";\r\n");
1858 throw new AutoGenException("DriverBinding can't be empty!!");
1866 // Write driver module protocol bitmask.
1868 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1869 fileBuffer
.append(Integer
.toString(BitMask
));
1870 fileBuffer
.append(";\r\n");
1873 // Write driver module protocol list entry
1875 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1877 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1878 fileBuffer
.append(";\r\n");
1881 // Write drive module protocol list to autogen.c
1883 if (driverBindingGroup
.length
> 0) {
1884 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1888 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1890 fileBuffer
.append(",");
1895 fileBuffer
.append("\r\n {\r\n");
1896 fileBuffer
.append(" &");
1897 fileBuffer
.append(driverBindingGroup
[i
][0]);
1898 fileBuffer
.append(", \r\n");
1903 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1904 fileBuffer
.append(" &");
1905 fileBuffer
.append(driverBindingGroup
[i
][1]);
1906 fileBuffer
.append(", \r\n");
1908 fileBuffer
.append(" NULL, \r\n");
1912 // DriverConfiguration
1914 if (driverBindingGroup
[i
][2] != null) {
1915 fileBuffer
.append(" &");
1916 fileBuffer
.append(driverBindingGroup
[i
][2]);
1917 fileBuffer
.append(", \r\n");
1919 fileBuffer
.append(" NULL, \r\n");
1925 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1926 fileBuffer
.append(" &");
1927 fileBuffer
.append(driverBindingGroup
[i
][3]);
1928 fileBuffer
.append(", \r\n");
1930 fileBuffer
.append(" NULL, \r\n");
1932 fileBuffer
.append(" }");
1935 if (driverBindingGroup
.length
> 0) {
1936 fileBuffer
.append("\r\n};\r\n");
1941 ExternCallBackToAutoGenC
1943 This function adds <SetVirtualAddressMapCallBack> and
1944 <ExitBootServicesCallBack> infomation to AutoGen.c
1947 String buffer for AutoGen.c
1948 @throws BuildException
1950 void ExternCallBackToAutoGenH(String moduleType
)
1951 throws EdkException
{
1953 // Collect module's <SetVirtualAddressMapCallBack> and
1954 // <ExitBootServiceCallBack> and add to setVirtualAddList
1955 // exitBootServiceList.
1957 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1958 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1960 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1961 // and <ExitBootServicesCallBack>
1963 switch (CommonDefinition
.getModuleType(moduleType
)) {
1964 case CommonDefinition
.ModuleTypeDxeDriver
:
1965 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1966 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1967 case CommonDefinition
.ModuleTypeUefiDriver
:
1968 case CommonDefinition
.ModuleTypeUefiApplication
:
1970 // Write SetVirtualAddressMap function definition.
1972 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1973 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1976 functionDeclarations
.append("VOID\r\n");
1977 functionDeclarations
.append("EFIAPI\r\n");
1978 functionDeclarations
.append(setVirtuals
[i
]);
1979 functionDeclarations
.append(" (\r\n");
1980 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1981 functionDeclarations
.append(" IN VOID *Context\r\n");
1982 functionDeclarations
.append(" );\r\n\r\n");
1986 // Write DriverExitBootServices function definition.
1988 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1989 if (exitBoots
[i
].equalsIgnoreCase("")) {
1993 functionDeclarations
.append("VOID\r\n");
1994 functionDeclarations
.append("EFIAPI\r\n");
1995 functionDeclarations
.append(exitBoots
[i
]);
1996 functionDeclarations
.append(" (\r\n");
1997 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1998 functionDeclarations
.append(" IN VOID *Context\r\n");
1999 functionDeclarations
.append(" );\r\n\r\n");
2008 ExternCallBackToAutoGenC
2010 This function adds <SetVirtualAddressMapCallBack> and
2011 <ExitBootServicesCallBack> infomation to AutoGen.c
2014 String buffer for AutoGen.c
2015 @throws BuildException
2017 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
2018 throws EdkException
{
2020 // Collect module's <SetVirtualAddressMapCallBack> and
2021 // <ExitBootServiceCallBack> and add to setVirtualAddList
2022 // exitBootServiceList.
2024 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2025 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
2026 if (setVirtuals
!= null) {
2027 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2028 this.setVirtalAddList
.add(setVirtuals
[j
]);
2031 if (exitBoots
!= null) {
2032 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2033 this.exitBootServiceList
.add(exitBoots
[k
]);
2037 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
2038 // and <ExitBootServicesCallBack>
2040 String moduleType
= this.moduleId
.getModuleType();
2041 switch (CommonDefinition
.getModuleType(moduleType
)) {
2042 case CommonDefinition
.ModuleTypeDxeDriver
:
2043 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
2044 case CommonDefinition
.ModuleTypeDxeSalDriver
:
2045 case CommonDefinition
.ModuleTypeUefiDriver
:
2046 case CommonDefinition
.ModuleTypeUefiApplication
:
2048 // If moduleType is one of above, call setVirtualAddressToAutogenC,
2049 // and setExitBootServiceToAutogenC.
2051 setVirtualAddressToAutogenC(fileBuffer
);
2052 setExitBootServiceToAutogenC(fileBuffer
);
2060 copyFlashMapHToDebugDir
2062 This function is to copy the falshmap.h to debug directory and change
2063 its name to TianoR8FlashMap.h
2068 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2070 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
2071 int size
= (int)inFile
.length();
2072 byte[] buffer
= new byte[size
];
2073 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
2075 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2078 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2079 if (inFile
.exists()) {
2081 FileInputStream fis
= new FileInputStream (inFile
);
2083 FileOutputStream fos
= new FileOutputStream(outFile
);
2087 } catch (IOException e
) {
2088 throw new AutoGenException("The file, flashMap.h can't be open!");
2092 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2098 This function first order the library instances, then collect
2099 library instance 's PPI, Protocol, GUID,
2100 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2101 Destructor, Constructor.
2106 private void collectLibInstanceInfo() throws EdkException
{
2109 String libConstructName
= null;
2110 String libDestructName
= null;
2111 String libModuleType
= null;
2112 String
[] setVirtuals
= null;
2113 String
[] exitBoots
= null;
2115 ModuleIdentification
[] libraryIdList
= saq
.getLibraryInstance(this.arch
);
2117 if (libraryIdList
!= null) {
2119 // Reorder library instance sequence.
2121 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
,
2123 List
<ModuleIdentification
> orderList
= libOrder
2124 .orderLibInstance();
2126 if (orderList
!= null) {
2128 // Process library instance one by one.
2130 for (int i
= 0; i
< orderList
.size(); i
++) {
2132 // Get library instance basename.
2134 ModuleIdentification libInstanceId
= orderList
.get(i
);
2140 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2143 // Get <PPis>, <Protocols>, <Guids> list of this library
2146 String
[] ppiList
= saq
.getPpiArray(this.arch
);
2147 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
2148 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
2149 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
2150 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
2151 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2154 // Add those ppi, protocol, guid in global ppi,
2158 for (index
= 0; index
< ppiList
.length
; index
++) {
2159 this.mPpiList
.add(ppiList
[index
]);
2162 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2163 this.mPpiList
.add(ppiNotifyList
[index
]);
2166 for (index
= 0; index
< protocolList
.length
; index
++) {
2167 this.mProtocolList
.add(protocolList
[index
]);
2170 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2171 this.mProtocolList
.add(protocolNotifyList
[index
]);
2174 for (index
= 0; index
< guidList
.length
; index
++) {
2175 this.mGuidList
.add(guidList
[index
]);
2177 for (index
= 0; index
< pkgList
.length
; index
++) {
2178 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2179 this.mDepPkgList
.add(pkgList
[index
]);
2184 // If not yet parse this library instance's constructor
2185 // element,parse it.
2187 libConstructName
= saq
.getLibConstructorName();
2188 libDestructName
= saq
.getLibDestructorName();
2189 libModuleType
= saq
.getModuleType();
2192 // Collect SetVirtualAddressMapCallBack and
2193 // ExitBootServiceCallBack.
2195 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2196 exitBoots
= saq
.getExitBootServicesCallBackArray();
2197 if (setVirtuals
!= null) {
2198 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2199 this.setVirtalAddList
.add(setVirtuals
[j
]);
2202 if (exitBoots
!= null) {
2203 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2204 this.exitBootServiceList
.add(exitBoots
[k
]);
2209 // Add dependent library instance constructor function.
2211 if (libConstructName
!= null) {
2212 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2215 // Add dependent library instance destructor fuction.
2217 if (libDestructName
!= null) {
2218 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2225 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2227 // Entry point lib for these module types needs to know the count
2230 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2233 // If the list is not valid or has no entries set count to zero else
2234 // set count to the number of valid entries
2238 if (this.setVirtalAddList
!= null) {
2239 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2240 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2247 fileBuffer
.append(Integer
.toString(Count
));
2248 fileBuffer
.append(";\r\n\r\n");
2249 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2251 // No data so make a NULL list
2253 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2254 fileBuffer
.append(" NULL\r\n");
2255 fileBuffer
.append("};\r\n\r\n");
2258 // Write SetVirtualAddressMap function definition.
2260 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2261 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2264 functionDeclarations
.append("VOID\r\n");
2265 functionDeclarations
.append("EFIAPI\r\n");
2266 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2267 functionDeclarations
.append(" (\r\n");
2268 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2269 functionDeclarations
.append(" IN VOID *Context\r\n");
2270 functionDeclarations
.append(" );\r\n\r\n");
2274 // Write SetVirtualAddressMap entry point array.
2276 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2277 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2278 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2283 fileBuffer
.append("\r\n ");
2285 fileBuffer
.append(",\r\n ");
2288 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2291 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2293 fileBuffer
.append(",\r\n NULL");
2294 fileBuffer
.append("\r\n};\r\n\r\n");
2299 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2301 // Entry point lib for these module types needs to know the count.
2303 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2306 // If the list is not valid or has no entries set count to zero else
2307 // set count to the number of valid entries.
2311 if (this.exitBootServiceList
!= null) {
2312 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2313 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2319 fileBuffer
.append(Integer
.toString(Count
));
2320 fileBuffer
.append(";\r\n\r\n");
2322 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2324 // No data so make a NULL list.
2326 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2327 fileBuffer
.append(" NULL\r\n");
2328 fileBuffer
.append("};\r\n\r\n");
2331 // Write DriverExitBootServices function definition.
2333 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2334 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2338 functionDeclarations
.append("VOID\r\n");
2339 functionDeclarations
.append("EFIAPI\r\n");
2340 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2341 functionDeclarations
.append(" (\r\n");
2342 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2343 functionDeclarations
.append(" IN VOID *Context\r\n");
2344 functionDeclarations
.append(" );\r\n\r\n");
2348 // Write DriverExitBootServices entry point array.
2350 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2351 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2352 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2357 fileBuffer
.append("\r\n ");
2359 fileBuffer
.append(",\r\n ");
2361 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2364 fileBuffer
.append(",\r\n NULL");
2365 fileBuffer
.append("\r\n};\r\n\r\n");
2371 Get the Pcd Value of ComponentName to
2372 decide whether need to disable the componentName.
2375 public void setPcdComponentName (){
2376 String pcdValue
= null;
2377 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2378 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2379 this.componentNamePcd
= true;
2384 setPcdDriverDiagnostic
2386 Get the Pcd Value of DriverDiagnostic to
2387 decide whether need to disable DriverDiagnostic.
2390 public void setPcdDriverDiagnostic (){
2391 String pcdValue
= null;
2392 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2393 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2394 this.driverDiagnostPcd
= true;