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
, null);
351 if (libClassList
.length
> 0) {
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
, null);
360 if (libClassList
.length
> 0) {
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
, null);
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
, null);
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
, fileBuffer
);
1359 // Add library destructor to AutoGen.c
1361 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
);
1365 LibConstructorToAutogenH
1367 This function writes library constructor declarations AutoGen.h. The library
1368 constructor's parameter and return value depend on module type.
1370 @param libInstanceList
1371 List of library construct name.
1375 String buffer for AutoGen.c
1378 void LibConstructorToAutogenH(String moduleType
) throws EdkException
{
1379 boolean isFirst
= true;
1382 // If not yet parse this library instance's constructor
1383 // element,parse it.
1385 String libConstructName
= saq
.getLibConstructorName();
1386 if (libConstructName
== null) {
1391 // The library constructor's parameter and return value depend on
1394 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1395 functionDeclarations
.append("RETURN_STATUS\r\n");
1396 functionDeclarations
.append("EFIAPI\r\n");
1397 functionDeclarations
.append(libConstructName
);
1398 functionDeclarations
.append(" (\r\n");
1399 functionDeclarations
.append(" VOID\r\n");
1400 functionDeclarations
.append(" );\r\n");
1402 switch (CommonDefinition
.getModuleType(moduleType
)) {
1403 case CommonDefinition
.ModuleTypeBase
:
1404 functionDeclarations
.append("RETURN_STATUS\r\n");
1405 functionDeclarations
.append("EFIAPI\r\n");
1406 functionDeclarations
.append(libConstructName
);
1407 functionDeclarations
.append(" (\r\n");
1408 functionDeclarations
.append(" VOID\r\n");
1409 functionDeclarations
.append(" );\r\n");
1412 case CommonDefinition
.ModuleTypePeiCore
:
1413 case CommonDefinition
.ModuleTypePeim
:
1414 functionDeclarations
.append("EFI_STATUS\r\n");
1415 functionDeclarations
.append("EFIAPI\r\n");
1416 functionDeclarations
.append(libConstructName
);
1417 functionDeclarations
.append(" (\r\n");
1418 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1419 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1420 functionDeclarations
.append(" );\r\n");
1423 case CommonDefinition
.ModuleTypeDxeCore
:
1424 case CommonDefinition
.ModuleTypeDxeDriver
:
1425 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1426 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1427 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1428 case CommonDefinition
.ModuleTypeUefiDriver
:
1429 case CommonDefinition
.ModuleTypeUefiApplication
:
1430 functionDeclarations
.append("EFI_STATUS\r\n");
1431 functionDeclarations
.append("EFIAPI\r\n");
1432 functionDeclarations
.append(libConstructName
);
1433 functionDeclarations
.append(" (\r\n");
1434 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1435 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1436 functionDeclarations
.append(" );\r\n");
1444 LibDestructorToAutogenH
1446 This function writes library destructor declarations AutoGen.h. The library
1447 destructor's parameter and return value depend on module type.
1449 @param libInstanceList
1450 List of library destructor name.
1454 String buffer for AutoGen.c
1457 void LibDestructorToAutogenH(String moduleType
) throws EdkException
{
1458 boolean isFirst
= true;
1459 String libDestructName
= saq
.getLibDestructorName();
1460 if (libDestructName
== null) {
1464 if (moduleType
.equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1465 functionDeclarations
.append("RETURN_STATUS\r\n");
1466 functionDeclarations
.append("EFIAPI\r\n");
1467 functionDeclarations
.append(libDestructName
);
1468 functionDeclarations
.append(" (\r\n");
1469 functionDeclarations
.append(" VOID\r\n");
1470 functionDeclarations
.append(" );\r\n");
1472 switch (CommonDefinition
.getModuleType(moduleType
)) {
1473 case CommonDefinition
.ModuleTypeBase
:
1474 functionDeclarations
.append("RETURN_STATUS\r\n");
1475 functionDeclarations
.append("EFIAPI\r\n");
1476 functionDeclarations
.append(libDestructName
);
1477 functionDeclarations
.append(" (\r\n");
1478 functionDeclarations
.append(" VOID\r\n");
1479 functionDeclarations
.append(" );\r\n");
1481 case CommonDefinition
.ModuleTypePeiCore
:
1482 case CommonDefinition
.ModuleTypePeim
:
1483 functionDeclarations
.append("EFI_STATUS\r\n");
1484 functionDeclarations
.append("EFIAPI\r\n");
1485 functionDeclarations
.append(libDestructName
);
1486 functionDeclarations
.append(" (\r\n");
1487 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1488 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1489 functionDeclarations
.append(" );\r\n");
1491 case CommonDefinition
.ModuleTypeDxeCore
:
1492 case CommonDefinition
.ModuleTypeDxeDriver
:
1493 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1494 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1495 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1496 case CommonDefinition
.ModuleTypeUefiDriver
:
1497 case CommonDefinition
.ModuleTypeUefiApplication
:
1498 functionDeclarations
.append("EFI_STATUS\r\n");
1499 functionDeclarations
.append("EFIAPI\r\n");
1500 functionDeclarations
.append(libDestructName
);
1501 functionDeclarations
.append(" (\r\n");
1502 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1503 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1504 functionDeclarations
.append(" );\r\n");
1511 LibConstructorToAutogenc
1513 This function writes library constructor list to AutoGen.c. The library
1514 constructor's parameter and return value depend on module type.
1516 @param libInstanceList
1517 List of library construct name.
1521 String buffer for AutoGen.c
1524 void LibConstructorToAutogenC(List
<String
[]> libInstanceList
,
1525 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1526 boolean isFirst
= true;
1529 // The library constructor's parameter and return value depend on
1532 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1533 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1534 functionDeclarations
.append("RETURN_STATUS\r\n");
1535 functionDeclarations
.append("EFIAPI\r\n");
1536 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1537 functionDeclarations
.append(" (\r\n");
1538 functionDeclarations
.append(" VOID\r\n");
1539 functionDeclarations
.append(" );\r\n");
1541 switch (CommonDefinition
.getModuleType(moduleType
)) {
1542 case CommonDefinition
.ModuleTypeBase
:
1543 functionDeclarations
.append("RETURN_STATUS\r\n");
1544 functionDeclarations
.append("EFIAPI\r\n");
1545 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1546 functionDeclarations
.append(" (\r\n");
1547 functionDeclarations
.append(" VOID\r\n");
1548 functionDeclarations
.append(" );\r\n");
1551 case CommonDefinition
.ModuleTypePeiCore
:
1552 case CommonDefinition
.ModuleTypePeim
:
1553 functionDeclarations
.append("EFI_STATUS\r\n");
1554 functionDeclarations
.append("EFIAPI\r\n");
1555 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1556 functionDeclarations
.append(" (\r\n");
1557 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1558 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1559 functionDeclarations
.append(" );\r\n");
1562 case CommonDefinition
.ModuleTypeDxeCore
:
1563 case CommonDefinition
.ModuleTypeDxeDriver
:
1564 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1565 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1566 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1567 case CommonDefinition
.ModuleTypeUefiDriver
:
1568 case CommonDefinition
.ModuleTypeUefiApplication
:
1569 functionDeclarations
.append("EFI_STATUS\r\n");
1570 functionDeclarations
.append("EFIAPI\r\n");
1571 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1572 functionDeclarations
.append(" (\r\n");
1573 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1574 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1575 functionDeclarations
.append(" );\r\n");
1583 // Add ProcessLibraryConstructorList in AutoGen.c
1585 fileBuffer
.append("VOID\r\n");
1586 fileBuffer
.append("EFIAPI\r\n");
1587 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1588 switch (CommonDefinition
.getModuleType(moduleType
)) {
1589 case CommonDefinition
.ModuleTypeBase
:
1590 fileBuffer
.append(" VOID\r\n");
1593 case CommonDefinition
.ModuleTypePeiCore
:
1594 case CommonDefinition
.ModuleTypePeim
:
1595 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1597 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1600 case CommonDefinition
.ModuleTypeDxeCore
:
1601 case CommonDefinition
.ModuleTypeDxeDriver
:
1602 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1603 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1604 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1605 case CommonDefinition
.ModuleTypeUefiDriver
:
1606 case CommonDefinition
.ModuleTypeUefiApplication
:
1607 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1608 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1612 fileBuffer
.append(" )\r\n");
1613 fileBuffer
.append("{\r\n");
1615 // If no constructor function, return EFI_SUCCESS.
1617 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1619 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1620 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1621 fileBuffer
.append("\r\n");
1624 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1625 fileBuffer
.append(" Status = ");
1626 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1627 fileBuffer
.append("();\r\n");
1629 switch (CommonDefinition
.getModuleType(moduleType
)) {
1630 case CommonDefinition
.ModuleTypeBase
:
1631 fileBuffer
.append(" Status = ");
1632 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1633 fileBuffer
.append("();\r\n");
1635 case CommonDefinition
.ModuleTypePeiCore
:
1636 case CommonDefinition
.ModuleTypePeim
:
1637 fileBuffer
.append(" Status = ");
1638 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1639 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1641 case CommonDefinition
.ModuleTypeDxeCore
:
1642 case CommonDefinition
.ModuleTypeDxeDriver
:
1643 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1644 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1645 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1646 case CommonDefinition
.ModuleTypeUefiDriver
:
1647 case CommonDefinition
.ModuleTypeUefiApplication
:
1648 fileBuffer
.append(" Status = ");
1649 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1650 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1653 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1657 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1659 fileBuffer
.append("}\r\n");
1663 LibDestructorToAutogenc
1665 This function writes library destructor list to AutoGen.c. The library
1666 destructor's parameter and return value depend on module type.
1668 @param libInstanceList
1669 List of library destructor name.
1673 String buffer for AutoGen.c
1676 void LibDestructorToAutogenC(List
<String
[]> libInstanceList
,
1677 String moduleType
, StringBuffer fileBuffer
) throws EdkException
{
1678 boolean isFirst
= true;
1679 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1680 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1681 functionDeclarations
.append("RETURN_STATUS\r\n");
1682 functionDeclarations
.append("EFIAPI\r\n");
1683 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1684 functionDeclarations
.append(" (\r\n");
1685 functionDeclarations
.append(" VOID\r\n");
1686 functionDeclarations
.append(" );\r\n");
1688 switch (CommonDefinition
.getModuleType(moduleType
)) {
1689 case CommonDefinition
.ModuleTypeBase
:
1690 functionDeclarations
.append("RETURN_STATUS\r\n");
1691 functionDeclarations
.append("EFIAPI\r\n");
1692 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1693 functionDeclarations
.append(" (\r\n");
1694 functionDeclarations
.append(" VOID\r\n");
1695 functionDeclarations
.append(" );\r\n");
1697 case CommonDefinition
.ModuleTypePeiCore
:
1698 case CommonDefinition
.ModuleTypePeim
:
1699 functionDeclarations
.append("EFI_STATUS\r\n");
1700 functionDeclarations
.append("EFIAPI\r\n");
1701 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1702 functionDeclarations
.append(" (\r\n");
1703 functionDeclarations
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1704 functionDeclarations
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1705 functionDeclarations
.append(" );\r\n");
1707 case CommonDefinition
.ModuleTypeDxeCore
:
1708 case CommonDefinition
.ModuleTypeDxeDriver
:
1709 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1710 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1711 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1712 case CommonDefinition
.ModuleTypeUefiDriver
:
1713 case CommonDefinition
.ModuleTypeUefiApplication
:
1714 functionDeclarations
.append("EFI_STATUS\r\n");
1715 functionDeclarations
.append("EFIAPI\r\n");
1716 functionDeclarations
.append(libInstanceList
.get(i
)[0]);
1717 functionDeclarations
.append(" (\r\n");
1718 functionDeclarations
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1719 functionDeclarations
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1720 functionDeclarations
.append(" );\r\n");
1727 // Write ProcessLibraryDestructor list to autogen.c
1729 switch (CommonDefinition
.getModuleType(moduleType
)) {
1730 case CommonDefinition
.ModuleTypeBase
:
1731 case CommonDefinition
.ModuleTypePeiCore
:
1732 case CommonDefinition
.ModuleTypePeim
:
1734 case CommonDefinition
.ModuleTypeDxeCore
:
1735 case CommonDefinition
.ModuleTypeDxeDriver
:
1736 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1737 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1738 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1739 case CommonDefinition
.ModuleTypeUefiDriver
:
1740 case CommonDefinition
.ModuleTypeUefiApplication
:
1741 fileBuffer
.append("VOID\r\n");
1742 fileBuffer
.append("EFIAPI\r\n");
1743 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1744 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1745 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1746 fileBuffer
.append(" )\r\n");
1747 fileBuffer
.append("{\r\n");
1749 // If no library destructor function, return EFI_SUCCESS.
1752 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1754 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1755 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1756 fileBuffer
.append("\r\n");
1759 if (libInstanceList
.get(i
)[1].equalsIgnoreCase(EdkDefinitions
.MODULE_TYPE_BASE
)) {
1760 fileBuffer
.append(" Status = ");
1761 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1762 fileBuffer
.append("();\r\n");
1763 fileBuffer
.append(" VOID\r\n");
1765 fileBuffer
.append(" Status = ");
1766 fileBuffer
.append(libInstanceList
.get(i
)[0]);
1767 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1768 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1771 fileBuffer
.append("}\r\n");
1777 ExternsDriverBindingToAutoGenC
1779 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1780 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1783 String buffer for AutoGen.c
1785 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1786 throws EdkException
{
1788 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.
1789 // The second dimension is include following element: DriverBinding,
1790 // ComponentName, DriverConfiguration, DriverDiag;
1792 String
[][] driverBindingGroup
= this.saq
.getExternProtocolGroup();
1801 // Write driver binding protocol extern to autogen.c
1803 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1804 if (driverBindingGroup
[i
][0] != null) {
1805 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1806 fileBuffer
.append(driverBindingGroup
[i
][0]);
1807 fileBuffer
.append(";\r\n");
1812 // Write component name protocol extern to autogen.c
1814 if (!componentNamePcd
) {
1815 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1816 if (driverBindingGroup
[i
][1]!= null) {
1817 if (driverBindingGroup
[i
][0] != null) {
1819 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1820 fileBuffer
.append(driverBindingGroup
[i
][1]);
1821 fileBuffer
.append(";\r\n");
1823 throw new AutoGenException("DriverBinding can't be empty!!");
1830 // Write driver configration protocol extern to autogen.c
1832 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1833 if (driverBindingGroup
[i
][2] != null) {
1834 if (driverBindingGroup
[i
][0] != null) {
1836 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1837 fileBuffer
.append(driverBindingGroup
[i
][2]);
1838 fileBuffer
.append(";\r\n");
1840 throw new AutoGenException("DriverBinding can't be empty!!");
1846 // Write driver dignastic protocol extern to autogen.c
1848 if (!driverDiagnostPcd
) {
1849 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1850 if (driverBindingGroup
[i
][3] != null) {
1851 if (driverBindingGroup
[i
][0] != null) {
1853 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1854 fileBuffer
.append(driverBindingGroup
[i
][3]);
1855 fileBuffer
.append(";\r\n");
1857 throw new AutoGenException("DriverBinding can't be empty!!");
1865 // Write driver module protocol bitmask.
1867 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1868 fileBuffer
.append(Integer
.toString(BitMask
));
1869 fileBuffer
.append(";\r\n");
1872 // Write driver module protocol list entry
1874 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1876 fileBuffer
.append(Integer
.toString(driverBindingGroup
.length
));
1877 fileBuffer
.append(";\r\n");
1880 // Write drive module protocol list to autogen.c
1882 if (driverBindingGroup
.length
> 0) {
1883 fileBuffer
.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1887 for (int i
= 0; i
< driverBindingGroup
.length
; i
++) {
1889 fileBuffer
.append(",");
1894 fileBuffer
.append("\r\n {\r\n");
1895 fileBuffer
.append(" &");
1896 fileBuffer
.append(driverBindingGroup
[i
][0]);
1897 fileBuffer
.append(", \r\n");
1902 if (driverBindingGroup
[i
][1] != null && componentNamePcd
!= true) {
1903 fileBuffer
.append(" &");
1904 fileBuffer
.append(driverBindingGroup
[i
][1]);
1905 fileBuffer
.append(", \r\n");
1907 fileBuffer
.append(" NULL, \r\n");
1911 // DriverConfiguration
1913 if (driverBindingGroup
[i
][2] != null) {
1914 fileBuffer
.append(" &");
1915 fileBuffer
.append(driverBindingGroup
[i
][2]);
1916 fileBuffer
.append(", \r\n");
1918 fileBuffer
.append(" NULL, \r\n");
1924 if (driverBindingGroup
[i
][3] != null && driverDiagnostPcd
!= true) {
1925 fileBuffer
.append(" &");
1926 fileBuffer
.append(driverBindingGroup
[i
][3]);
1927 fileBuffer
.append(", \r\n");
1929 fileBuffer
.append(" NULL, \r\n");
1931 fileBuffer
.append(" }");
1934 if (driverBindingGroup
.length
> 0) {
1935 fileBuffer
.append("\r\n};\r\n");
1940 ExternCallBackToAutoGenC
1942 This function adds <SetVirtualAddressMapCallBack> and
1943 <ExitBootServicesCallBack> infomation to AutoGen.c
1946 String buffer for AutoGen.c
1947 @throws BuildException
1949 void ExternCallBackToAutoGenH(String moduleType
)
1950 throws EdkException
{
1952 // Collect module's <SetVirtualAddressMapCallBack> and
1953 // <ExitBootServiceCallBack> and add to setVirtualAddList
1954 // exitBootServiceList.
1956 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
1957 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
1959 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1960 // and <ExitBootServicesCallBack>
1962 switch (CommonDefinition
.getModuleType(moduleType
)) {
1963 case CommonDefinition
.ModuleTypeDxeDriver
:
1964 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1965 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1966 case CommonDefinition
.ModuleTypeUefiDriver
:
1967 case CommonDefinition
.ModuleTypeUefiApplication
:
1969 // Write SetVirtualAddressMap function definition.
1971 for (int i
= 0; setVirtuals
!= null && i
< setVirtuals
.length
; i
++) {
1972 if (setVirtuals
[i
].equalsIgnoreCase("")) {
1975 functionDeclarations
.append("VOID\r\n");
1976 functionDeclarations
.append("EFIAPI\r\n");
1977 functionDeclarations
.append(setVirtuals
[i
]);
1978 functionDeclarations
.append(" (\r\n");
1979 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1980 functionDeclarations
.append(" IN VOID *Context\r\n");
1981 functionDeclarations
.append(" );\r\n\r\n");
1985 // Write DriverExitBootServices function definition.
1987 for (int i
= 0; exitBoots
!= null && i
< exitBoots
.length
; i
++) {
1988 if (exitBoots
[i
].equalsIgnoreCase("")) {
1992 functionDeclarations
.append("VOID\r\n");
1993 functionDeclarations
.append("EFIAPI\r\n");
1994 functionDeclarations
.append(exitBoots
[i
]);
1995 functionDeclarations
.append(" (\r\n");
1996 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
1997 functionDeclarations
.append(" IN VOID *Context\r\n");
1998 functionDeclarations
.append(" );\r\n\r\n");
2007 ExternCallBackToAutoGenC
2009 This function adds <SetVirtualAddressMapCallBack> and
2010 <ExitBootServicesCallBack> infomation to AutoGen.c
2013 String buffer for AutoGen.c
2014 @throws BuildException
2016 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
2017 throws EdkException
{
2019 // Collect module's <SetVirtualAddressMapCallBack> and
2020 // <ExitBootServiceCallBack> and add to setVirtualAddList
2021 // exitBootServiceList.
2023 String
[] setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2024 String
[] exitBoots
= saq
.getExitBootServicesCallBackArray();
2025 if (setVirtuals
!= null) {
2026 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2027 this.setVirtalAddList
.add(setVirtuals
[j
]);
2030 if (exitBoots
!= null) {
2031 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2032 this.exitBootServiceList
.add(exitBoots
[k
]);
2036 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
2037 // and <ExitBootServicesCallBack>
2039 String moduleType
= this.moduleId
.getModuleType();
2040 switch (CommonDefinition
.getModuleType(moduleType
)) {
2041 case CommonDefinition
.ModuleTypeDxeDriver
:
2042 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
2043 case CommonDefinition
.ModuleTypeDxeSalDriver
:
2044 case CommonDefinition
.ModuleTypeUefiDriver
:
2045 case CommonDefinition
.ModuleTypeUefiApplication
:
2047 // If moduleType is one of above, call setVirtualAddressToAutogenC,
2048 // and setExitBootServiceToAutogenC.
2050 setVirtualAddressToAutogenC(fileBuffer
);
2051 setExitBootServiceToAutogenC(fileBuffer
);
2059 copyFlashMapHToDebugDir
2061 This function is to copy the falshmap.h to debug directory and change
2062 its name to TianoR8FlashMap.h
2067 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2069 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.FLASHMAPH
);
2070 int size
= (int)inFile
.length();
2071 byte[] buffer
= new byte[size
];
2072 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.TIANOR8PLASHMAPH
);
2074 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2077 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2078 if (inFile
.exists()) {
2080 FileInputStream fis
= new FileInputStream (inFile
);
2082 FileOutputStream fos
= new FileOutputStream(outFile
);
2086 } catch (IOException e
) {
2087 throw new AutoGenException("The file, flashMap.h can't be open!");
2091 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2097 This function first order the library instances, then collect
2098 library instance 's PPI, Protocol, GUID,
2099 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2100 Destructor, Constructor.
2105 private void collectLibInstanceInfo() throws EdkException
{
2108 String moduleType
= moduleId
.getModuleType();
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
);
2116 if (libraryIdList
.length
<= 0) {
2120 // Reorder library instance sequence.
2122 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
2123 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
2125 // Process library instance one by one.
2127 for (int i
= 0; i
< orderList
.size(); i
++) {
2129 // Get library instance basename.
2131 ModuleIdentification libInstanceId
= orderList
.get(i
);
2137 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2140 // check if the library instance support current module
2142 String
[] libraryClassList
= saq
.getLibraryClasses(CommonDefinition
.ALWAYSPRODUCED
,
2146 if (libraryClassList
.length
<= 0) {
2147 throw new EdkException("Library instance " + libInstanceId
.getName()
2148 + " doesn't support module type " + moduleType
);
2151 // Get <PPis>, <Protocols>, <Guids> list of this library
2154 String
[] ppiList
= saq
.getPpiArray(this.arch
);
2155 String
[] ppiNotifyList
= saq
.getPpiNotifyArray(this.arch
);
2156 String
[] protocolList
= saq
.getProtocolArray(this.arch
);
2157 String
[] protocolNotifyList
= saq
.getProtocolNotifyArray(this.arch
);
2158 String
[] guidList
= saq
.getGuidEntryArray(this.arch
);
2159 PackageIdentification
[] pkgList
= saq
.getDependencePkg(this.arch
);
2162 // Add those ppi, protocol, guid in global ppi,
2166 for (index
= 0; index
< ppiList
.length
; index
++) {
2167 this.mPpiList
.add(ppiList
[index
]);
2170 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2171 this.mPpiList
.add(ppiNotifyList
[index
]);
2174 for (index
= 0; index
< protocolList
.length
; index
++) {
2175 this.mProtocolList
.add(protocolList
[index
]);
2178 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2179 this.mProtocolList
.add(protocolNotifyList
[index
]);
2182 for (index
= 0; index
< guidList
.length
; index
++) {
2183 this.mGuidList
.add(guidList
[index
]);
2185 for (index
= 0; index
< pkgList
.length
; index
++) {
2186 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2187 this.mDepPkgList
.add(pkgList
[index
]);
2192 // If not yet parse this library instance's constructor
2193 // element,parse it.
2195 libConstructName
= saq
.getLibConstructorName();
2196 libDestructName
= saq
.getLibDestructorName();
2197 libModuleType
= saq
.getModuleType();
2200 // Collect SetVirtualAddressMapCallBack and
2201 // ExitBootServiceCallBack.
2203 setVirtuals
= saq
.getSetVirtualAddressMapCallBackArray();
2204 exitBoots
= saq
.getExitBootServicesCallBackArray();
2205 if (setVirtuals
!= null) {
2206 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2207 this.setVirtalAddList
.add(setVirtuals
[j
]);
2210 if (exitBoots
!= null) {
2211 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2212 this.exitBootServiceList
.add(exitBoots
[k
]);
2217 // Add dependent library instance constructor function.
2219 if (libConstructName
!= null) {
2220 this.libConstructList
.add(new String
[] {libConstructName
, libModuleType
});
2223 // Add dependent library instance destructor fuction.
2225 if (libDestructName
!= null) {
2226 this.libDestructList
.add(new String
[] {libDestructName
, libModuleType
});
2231 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer
){
2233 // Entry point lib for these module types needs to know the count
2236 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
2239 // If the list is not valid or has no entries set count to zero else
2240 // set count to the number of valid entries
2244 if (this.setVirtalAddList
!= null) {
2245 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2246 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2253 fileBuffer
.append(Integer
.toString(Count
));
2254 fileBuffer
.append(";\r\n\r\n");
2255 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
2257 // No data so make a NULL list
2259 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
2260 fileBuffer
.append(" NULL\r\n");
2261 fileBuffer
.append("};\r\n\r\n");
2264 // Write SetVirtualAddressMap function definition.
2266 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2267 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2270 functionDeclarations
.append("VOID\r\n");
2271 functionDeclarations
.append("EFIAPI\r\n");
2272 functionDeclarations
.append(this.setVirtalAddList
.get(i
));
2273 functionDeclarations
.append(" (\r\n");
2274 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2275 functionDeclarations
.append(" IN VOID *Context\r\n");
2276 functionDeclarations
.append(" );\r\n\r\n");
2280 // Write SetVirtualAddressMap entry point array.
2282 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
2283 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
2284 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
2289 fileBuffer
.append("\r\n ");
2291 fileBuffer
.append(",\r\n ");
2294 fileBuffer
.append(this.setVirtalAddList
.get(i
));
2297 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.
2299 fileBuffer
.append(",\r\n NULL");
2300 fileBuffer
.append("\r\n};\r\n\r\n");
2305 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer
){
2307 // Entry point lib for these module types needs to know the count.
2309 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2312 // If the list is not valid or has no entries set count to zero else
2313 // set count to the number of valid entries.
2317 if (this.exitBootServiceList
!= null) {
2318 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2319 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2325 fileBuffer
.append(Integer
.toString(Count
));
2326 fileBuffer
.append(";\r\n\r\n");
2328 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
2330 // No data so make a NULL list.
2332 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2333 fileBuffer
.append(" NULL\r\n");
2334 fileBuffer
.append("};\r\n\r\n");
2337 // Write DriverExitBootServices function definition.
2339 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2340 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2344 functionDeclarations
.append("VOID\r\n");
2345 functionDeclarations
.append("EFIAPI\r\n");
2346 functionDeclarations
.append(this.exitBootServiceList
.get(i
));
2347 functionDeclarations
.append(" (\r\n");
2348 functionDeclarations
.append(" IN EFI_EVENT Event,\r\n");
2349 functionDeclarations
.append(" IN VOID *Context\r\n");
2350 functionDeclarations
.append(" );\r\n\r\n");
2354 // Write DriverExitBootServices entry point array.
2356 fileBuffer
.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2357 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
2358 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
2363 fileBuffer
.append("\r\n ");
2365 fileBuffer
.append(",\r\n ");
2367 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2370 fileBuffer
.append(",\r\n NULL");
2371 fileBuffer
.append("\r\n};\r\n\r\n");
2377 Get the Pcd Value of ComponentName to
2378 decide whether need to disable the componentName.
2381 public void setPcdComponentName (){
2382 String pcdValue
= null;
2383 pcdValue
= saq
.getPcdValueBycName("PcdComponentNameDisable");
2384 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2385 this.componentNamePcd
= true;
2390 setPcdDriverDiagnostic
2392 Get the Pcd Value of DriverDiagnostic to
2393 decide whether need to disable DriverDiagnostic.
2396 public void setPcdDriverDiagnostic (){
2397 String pcdValue
= null;
2398 pcdValue
= saq
.getPcdValueBycName("PcdDriverDiagnosticsDisable");
2399 if (pcdValue
!= null && pcdValue
.equalsIgnoreCase("true")) {
2400 this.driverDiagnostPcd
= true;