X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fautogen%2FAutoGen.java;h=0d757b923b1c4b769096326b074db54482fdbf83;hb=214b0d1914b48d651b25e58f321ddb77a46903b8;hp=28e72af699600781ba5d12fc33255b95eedfa663;hpb=bd4814401e1277f19fa1498dbd187dca68923b47;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java index 28e72af699..0d757b923b 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java +++ b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java @@ -22,6 +22,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -33,24 +34,21 @@ import java.util.Set; import org.apache.tools.ant.BuildException; import org.apache.xmlbeans.XmlObject; -import org.tianocore.GuidsDocument; -import org.tianocore.LibraryClassDocument.LibraryClass; -import org.tianocore.PPIsDocument; -import org.tianocore.ProtocolsDocument; -import org.tianocore.build.exception.*; +import org.tianocore.build.exception.AutoGenException; import org.tianocore.build.global.GlobalData; -import org.tianocore.build.global.Spd; import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PackageIdentification; import org.tianocore.build.pcd.action.PCDAutoGenAction; - +import org.tianocore.common.definitions.ToolDefinitions; +import org.tianocore.common.definitions.EdkDefinitions; +import org.tianocore.common.exception.EdkException; import org.tianocore.common.logger.EdkLog; /** - * This class is to generate Autogen.h and Autogen.c according to module surface - * area or library surface area. - */ + This class is to generate Autogen.h and Autogen.c according to module surface + area or library surface area. +**/ public class AutoGen { /// /// The output path of Autogen.h and Autogen.c @@ -83,11 +81,6 @@ public class AutoGen { /// private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType; - /// - /// Judge whether this module's library instance use PcdLib library class - /// - private boolean isModuleLibraryInstanceUsePcd; - /// /// The protocl list which records in module or library surface area and /// it's dependence on library instance surface area. @@ -106,170 +99,180 @@ public class AutoGen { /// private Set mGuidList = new HashSet(); - // - // The dependence package list which recoreded in module or library surface - // area and it's dependence on library instance surface are. - // + /// + /// The dependence package list which recoreded in module or library surface + /// area and it's dependence on library instance surface area. + /// private List mDepPkgList = new LinkedList(); - // - // For non library module, add its library instance's construct and destructor to - // list. - // - private List libConstructList = new ArrayList(); - private List libDestructList = new ArrayList(); + /// + /// For non library module, add its library instance's construct and destructor to + /// list. String[0] recode LibConstructor name, String[1] recode Lib instance + /// module type. + /// + private List libConstructList = new ArrayList(); + private List libDestructList = new ArrayList(); - // - // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack - // + /// + /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack + /// private List setVirtalAddList = new ArrayList(); private List exitBootServiceList = new ArrayList(); + private SurfaceAreaQuery saq = null; + + private ModuleIdentification parentId = null; /** - * Construct function - * - * This function mainly initialize some member variable. - * - * @param outputPath - * Output path of AutoGen file. - * @param baseName - * Module base name. - * @param arch - * Target architecture. - */ - public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch) { + Construct function + + This function mainly initialize some member variable. + + @param fvDir + Absolute path of FV directory. + @param outputPath + Output path of AutoGen file. + @param moduleId + Module identification. + @param arch + Target architecture. + **/ + public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq, ModuleIdentification parentId) { this.outputPath = outputPath; this.moduleId = moduleId; this.arch = arch; this.fvDir = fvDir; - + this.saq = saq; + this.parentId = parentId; } /** - * saveFile function - * - * This function save the content in stringBuffer to file. - * - * @param fileName - * The name of file. - * @param fileBuffer - * The content of AutoGen file in buffer. - * @return "true" successful, "false" failed. - */ + saveFile function + + This function save the content in stringBuffer to file. + + @param fileName + The name of file. + @param fileBuffer + The content of AutoGen file in buffer. + @return boolean + "true" successful + "false" failed + **/ private boolean saveFile(String fileName, StringBuffer fileBuffer) { - try { - File autoGenH = new File(fileName); + + File autoGenH = new File(fileName); // // if the file exists, compare their content // - if (autoGenH.exists()) { - FileReader fIn = new FileReader(autoGenH); - char[] oldFileBuffer = new char[(int) autoGenH.length()]; - fIn.read(oldFileBuffer, 0, (int) autoGenH.length()); + if (autoGenH.exists()) { + char[] oldFileBuffer = new char[(int) autoGenH.length()]; + try { + FileReader fIn = new FileReader(autoGenH); + fIn.read(oldFileBuffer, 0, (int) autoGenH.length()); fIn.close(); + } catch (IOException e) { + EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() + + "'s " + + fileName + + " is exist, but can't be open!!"); + return false; + } - // - // if we got the same file, don't re-generate it to prevent - // sources depending on it from re-building - // - if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) { - return true; - } + // + // if we got the same file, don't re-generate it to prevent + // sources depending on it from re-building + // + if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) { + return true; } - FileWriter fOut = new FileWriter(autoGenH); + } + + try { + FileWriter fOut = new FileWriter(autoGenH); fOut.write(fileBuffer.toString()); + fOut.flush(); fOut.close(); - } catch (Exception e) { - return false; - } + } catch (IOException e) { + EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() + + "'s " + + fileName + + " can't be create!!"); + return false; + } return true; } /** - * genAutogen function - * - * This function call libGenAutoGen or moduleGenAutogen function, which - * dependence on generate library autogen or module autogen. - * - * @throws BuildException - * Failed to creat AutoGen.c & AutoGen.h. - */ - public void genAutogen() throws BuildException { + genAutogen function + + This function call libGenAutoGen or moduleGenAutogen function, which + dependence on generate library autogen or module autogen. + + @throws BuildException + Failed to creat AutoGen.c & AutoGen.h. + **/ + public void genAutogen() throws EdkException { try { // // If outputPath do not exist, create it. // File path = new File(outputPath); path.mkdirs(); - - // - // Check current is library or not, then call the corresponding - // function. - // - if (this.moduleId.isLibrary()) { - libGenAutogen(); - } else { - moduleGenAutogen(); - } - - } catch (Exception e) { - throw new BuildException( - "Failed to create AutoGen.c & AutoGen.h!\n" - + e.getMessage()); + } catch (Exception e) { + throw new AutoGenException( + "Failed to create " + + outputPath + " directory"); } + + // + // Check current is library or not, then call the corresponding + // function. + // + if (this.moduleId.isLibrary()) { + libGenAutogen(); + } else { + moduleGenAutogen(); + } } /** - * moduleGenAutogen function - * - * This function generates AutoGen.c & AutoGen.h for module. - * - * @throws BuildException - * Faile to create module AutoGen.c & AutoGen.h. - */ - void moduleGenAutogen() throws BuildException { - - try { - collectLibInstanceInfo(); - moduleGenAutogenC(); - moduleGenAutogenH(); - } catch (Exception e) { - throw new BuildException( - "Faile to create module AutoGen.c & AutoGen.h!\n" - + e.getMessage()); - } + moduleGenAutogen function + + This function generates AutoGen.c & AutoGen.h for module. + + @throws BuildException + Faile to create module AutoGen.c & AutoGen.h. + **/ + void moduleGenAutogen() throws EdkException { + collectLibInstanceInfo(); + moduleGenAutogenC(); + moduleGenAutogenH(); } /** - * libGenAutogen function - * - * This function generates AutoGen.c & AutoGen.h for library. - * - * @throws BuildException - * Faile to create library AutoGen.c & AutoGen.h - */ - void libGenAutogen() throws BuildException { - try { - libGenAutogenC(); - libGenAutogenH(); - } catch (Exception e) { - throw new BuildException( - "Failed to create library AutoGen.c & AutoGen.h!\n" - + e.getMessage()); - } + libGenAutogen function + + This function generates AutoGen.c & AutoGen.h for library. + + @throws BuildException + Faile to create library AutoGen.c & AutoGen.h + **/ + void libGenAutogen() throws EdkException { + libGenAutogenC(); + libGenAutogenH(); } /** - * moduleGenAutogenH - * - * This function generates AutoGen.h for module. - * - * @throws BuildException - * Failed to generate AutoGen.h. - */ - void moduleGenAutogenH() throws AutoGenException { + moduleGenAutogenH + + This function generates AutoGen.h for module. + + @throws BuildException + Failed to generate AutoGen.h. + **/ + void moduleGenAutogenH() throws EdkException { Set libClassIncludeH; String moduleType; @@ -281,14 +284,21 @@ public class AutoGen { // // Write Autogen.h header notation // - fileBuffer.append(CommonDefinition.autogenHNotation); + fileBuffer.append(CommonDefinition.AUTOGENHNOTATION); // // Add #ifndef ${BaseName}_AUTOGENH // #def ${BseeName}_AUTOGENH // - fileBuffer.append("#ifndef " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n"); - fileBuffer.append("#define " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n"); + fileBuffer.append(CommonDefinition.IFNDEF + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR); + fileBuffer.append(CommonDefinition.DEFINE + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR + + ToolDefinitions.LINE_SEPARATOR); // // Write the specification version and release version at the begine @@ -297,20 +307,20 @@ public class AutoGen { // be got from module surface area instead of hard code by it's // moduleType. // - moduleType = SurfaceAreaQuery.getModuleType(); + moduleType = saq.getModuleType(); // // Add "extern int __make_me_compile_correctly;" at begin of // AutoGen.h. // - fileBuffer.append(CommonDefinition.autoGenHbegin); + fileBuffer.append(CommonDefinition.AUTOGENHBEGIN); // // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION. // - String[] specList = SurfaceAreaQuery.getExternSpecificaiton(); + String[] specList = saq.getExternSpecificaiton(); for (int i = 0; i < specList.length; i++) { - fileBuffer.append(CommonDefinition.marcDefineStr + specList[i] + fileBuffer.append(CommonDefinition.DEFINE + specList[i] + "\r\n"); } // @@ -318,8 +328,7 @@ public class AutoGen { // // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery // .getDependencePkg(this.arch); - PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery - .getDependencePkg(this.arch); + PackageIdentification[] consumedPkgIdList = saq.getDependencePkg(this.arch); if (consumedPkgIdList != null) { headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType); item = headerFileList.iterator(); @@ -331,30 +340,7 @@ public class AutoGen { // // Write library class's related *.h file to autogen.h. // - String[] libClassList = SurfaceAreaQuery - .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch); - boolean isModuleConsumePcdLib = false; - List libClassArray = new ArrayList(); - for (int index = 0; index < libClassList.length; index++) { - libClassArray.add(libClassList[index]); - // - // Search all library class of a module for PcdLib - // - if (libClassList[index].equalsIgnoreCase(CommonDefinition.pcdLibName)) { - isModuleConsumePcdLib = true; - } - } - - // - // If module do not use PCD but module's library use PCD. - // - if (!isModuleConsumePcdLib && this.isModuleLibraryInstanceUsePcd) { - libClassArray.add(CommonDefinition.pcdLibName); - } - - libClassList = new String[libClassArray.size()]; - libClassArray.toArray(libClassList); - + String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED,this.arch); if (libClassList != null) { libClassIncludeH = LibraryClassToAutogenH(libClassList); item = libClassIncludeH.iterator(); @@ -363,8 +349,7 @@ public class AutoGen { } } - libClassList = SurfaceAreaQuery - .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch); + libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch); if (libClassList != null) { libClassIncludeH = LibraryClassToAutogenH(libClassList); item = libClassIncludeH.iterator(); @@ -378,10 +363,10 @@ public class AutoGen { // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to // {DEST_DIR_DRBUG}/FlashMap.h // - if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) { - fileBuffer.append(CommonDefinition.include); + if (saq.isHaveTianoR8FlashMap()) { + fileBuffer.append(CommonDefinition.INCLUDE); fileBuffer.append(" <"); - fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n"); + fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n"); copyFlashMapHToDebugDir(); } @@ -401,30 +386,30 @@ public class AutoGen { // Save string buffer content in AutoGen.h. // if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.h !!!"); + throw new AutoGenException("Failed to generate AutoGen.h !!!"); } } /** - * moduleGenAutogenC - * - * This function generates AutoGen.c for module. - * - * @throws BuildException - * Failed to generate AutoGen.c. - */ - void moduleGenAutogenC() throws AutoGenException { + moduleGenAutogenC + + This function generates AutoGen.c for module. + + @throws BuildException + Failed to generate AutoGen.c. + **/ + void moduleGenAutogenC() throws EdkException { StringBuffer fileBuffer = new StringBuffer(8192); // // Write Autogen.c header notation // - fileBuffer.append(CommonDefinition.autogenCNotation); + fileBuffer.append(CommonDefinition.AUTOGENCNOTATION); // // Write #include at beginning of AutoGen.c // - fileBuffer.append(CommonDefinition.includeAutogenH); + fileBuffer.append(CommonDefinition.INCLUDEAUTOGENH); // // Get the native MSA file infomation. Since before call autogen, @@ -432,7 +417,7 @@ public class AutoGen { // process it should be set the DOC as the Native MSA info. // Map doc = GlobalData.getNativeMsa(this.moduleId); - SurfaceAreaQuery.push(doc); + saq.push(doc); // // Write // DriverBinding/ComponentName/DriverConfiguration/DriverDialog @@ -450,24 +435,31 @@ public class AutoGen { // // Write EntryPoint to autgoGen.c // - String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray(); - EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer); + String[] entryPointList = saq.getModuleEntryPointArray(); + String[] unloadImageList = saq.getModuleUnloadImageArray(); + EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), + CommonDefinition.remDupString(unloadImageList), + fileBuffer); - pcdDriverType = SurfaceAreaQuery.getPcdDriverType(); + pcdDriverType = saq.getPcdDriverType(); // // Restore the DOC which include the FPD module info. // - SurfaceAreaQuery.pop(); + saq.pop(); // // Write Guid to autogen.c // - String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery - .getModuleGuid()); - - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {"); + String guid = CommonDefinition.formatGuidName(saq.getModuleGuid()); + if (this.moduleId.getModuleType().equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + fileBuffer + .append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {"); + } else { + fileBuffer + .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {"); + } + if (guid == null) { throw new AutoGenException("Guid value must set!\n"); } @@ -492,7 +484,7 @@ public class AutoGen { // // Get module dependent Package identification. // - PackageIdentification[] packages = SurfaceAreaQuery.getDependencePkg(this.arch); + PackageIdentification[] packages = saq.getDependencePkg(this.arch); for (int i = 0; i < packages.length; i++) { if (!this.mDepPkgList.contains(packages[i])) { this.mDepPkgList.add(packages[i]); @@ -514,33 +506,30 @@ public class AutoGen { arch, false, null, - pcdDriverType); - try { - this.myPcdAutogen.execute(); - } catch (Exception exp) { - throw new PcdAutogenException (exp.getMessage()); - } - + pcdDriverType, + parentId); + + this.myPcdAutogen.execute(); if (this.myPcdAutogen != null) { fileBuffer.append("\r\n"); fileBuffer.append(this.myPcdAutogen.getCAutoGenString()); } if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.c !!!"); + throw new AutoGenException("Failed to generate AutoGen.c !!!"); } } /** - * libGenAutogenH - * - * This function generates AutoGen.h for library. - * - * @throws BuildException - * Failed to generate AutoGen.c. - */ - void libGenAutogenH() throws AutoGenException { + libGenAutogenH + + This function generates AutoGen.h for library. + + @throws BuildException + Failed to generate AutoGen.c. + **/ + void libGenAutogenH() throws EdkException { Set libClassIncludeH; String moduleType; @@ -551,14 +540,21 @@ public class AutoGen { // // Write Autogen.h header notation // - fileBuffer.append(CommonDefinition.autogenHNotation); + fileBuffer.append(CommonDefinition.AUTOGENHNOTATION); // // Add #ifndef ${BaseName}_AUTOGENH // #def ${BseeName}_AUTOGENH // - fileBuffer.append("#ifndef " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n"); - fileBuffer.append("#define " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n"); + fileBuffer.append(CommonDefinition.IFNDEF + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR); + fileBuffer.append(CommonDefinition.DEFINE + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR + + ToolDefinitions.LINE_SEPARATOR); // // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION @@ -566,10 +562,10 @@ public class AutoGen { // Note: the specification version and release version should // be get from module surface area instead of hard code. // - fileBuffer.append(CommonDefinition.autoGenHbegin); - String[] specList = SurfaceAreaQuery.getExternSpecificaiton(); + fileBuffer.append(CommonDefinition.AUTOGENHBEGIN); + String[] specList = saq.getExternSpecificaiton(); for (int i = 0; i < specList.length; i++) { - fileBuffer.append(CommonDefinition.marcDefineStr + specList[i] + fileBuffer.append(CommonDefinition.DEFINE + specList[i] + "\r\n"); } // fileBuffer.append(CommonDefinition.autoGenHLine1); @@ -578,8 +574,8 @@ public class AutoGen { // // Write consumed package's mdouleInfo related *.h file to autogen.h. // - moduleType = SurfaceAreaQuery.getModuleType(); - PackageIdentification[] cosumedPkglist = SurfaceAreaQuery + moduleType = saq.getModuleType(); + PackageIdentification[] cosumedPkglist = saq .getDependencePkg(this.arch); headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType); item = headerFileList.iterator(); @@ -589,8 +585,8 @@ public class AutoGen { // // Write library class's related *.h file to autogen.h // - String[] libClassList = SurfaceAreaQuery - .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch); + String[] libClassList = saq + .getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch); if (libClassList != null) { libClassIncludeH = LibraryClassToAutogenH(libClassList); item = libClassIncludeH.iterator(); @@ -599,8 +595,8 @@ public class AutoGen { } } - libClassList = SurfaceAreaQuery - .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch); + libClassList = saq + .getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch); if (libClassList != null) { libClassIncludeH = LibraryClassToAutogenH(libClassList); item = libClassIncludeH.iterator(); @@ -608,16 +604,16 @@ public class AutoGen { fileBuffer.append(item.next().toString()); } } - fileBuffer.append("\r\n"); + fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); // // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to // {DEST_DIR_DRBUG}/FlashMap.h // - if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) { - fileBuffer.append(CommonDefinition.include); + if (saq.isHaveTianoR8FlashMap()) { + fileBuffer.append(CommonDefinition.INCLUDE); fileBuffer.append(" <"); - fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n"); + fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n"); copyFlashMapHToDebugDir(); } @@ -638,28 +634,28 @@ public class AutoGen { // Save content of string buffer to AutoGen.h file. // if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.h !!!"); + throw new AutoGenException("Failed to generate AutoGen.h !!!"); } } /** - * libGenAutogenC - * - * This function generates AutoGen.h for library. - * - * @throws BuildException - * Failed to generate AutoGen.c. - */ - void libGenAutogenC() throws BuildException, PcdAutogenException { + libGenAutogenC + + This function generates AutoGen.h for library. + + @throws BuildException + Failed to generate AutoGen.c. + **/ + void libGenAutogenC() throws EdkException { StringBuffer fileBuffer = new StringBuffer(10240); // // Write Autogen.c header notation // - fileBuffer.append(CommonDefinition.autogenCNotation); + fileBuffer.append(CommonDefinition.AUTOGENCNOTATION); - fileBuffer.append(CommonDefinition.autoGenCLine1); - fileBuffer.append("\r\n"); + fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); + fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); // // Call pcd autogen. @@ -667,39 +663,35 @@ public class AutoGen { this.myPcdAutogen = new PCDAutoGenAction(moduleId, arch, true, - SurfaceAreaQuery.getModulePcdEntryNameArray(), - pcdDriverType); - try { - this.myPcdAutogen.execute(); - } catch (Exception e) { - throw new PcdAutogenException(e.getMessage()); - } - + saq.getModulePcdEntryNameArray(), + pcdDriverType, + parentId); + this.myPcdAutogen.execute(); if (this.myPcdAutogen != null) { - fileBuffer.append("\r\n"); + fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); fileBuffer.append(this.myPcdAutogen.getCAutoGenString()); } if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.c !!!"); + throw new AutoGenException("Failed to generate AutoGen.c !!!"); } } /** - * LibraryClassToAutogenH - * - * This function returns *.h files declared by library classes which are - * consumed or produced by current build module or library. - * - * @param libClassList - * List of library class which consumed or produce by current - * build module or library. - * @return includeStrList List of *.h file. - */ + LibraryClassToAutogenH + + This function returns *.h files declared by library classes which are + consumed or produced by current build module or library. + + @param libClassList + List of library class which consumed or produce by current + build module or library. + @return includeStrList List of *.h file. + **/ Set LibraryClassToAutogenH(String[] libClassList) - throws AutoGenException { - Set includStrList = new LinkedHashSet(); - String includerName[]; + throws EdkException { + Set includeStrList = new LinkedHashSet(); + String includeName[]; String str = ""; // @@ -707,37 +699,37 @@ public class AutoGen { // library class name. // for (int i = 0; i < libClassList.length; i++) { - includerName = GlobalData.getLibraryClassHeaderFiles( - SurfaceAreaQuery.getDependencePkg(this.arch), + includeName = GlobalData.getLibraryClassHeaderFiles( + saq.getDependencePkg(this.arch), libClassList[i]); - if (includerName == null) { + if (includeName == null) { throw new AutoGenException("Can not find library class [" + libClassList[i] + "] declaration in any SPD package. "); } - for (int j = 0; j < includerName.length; j++) { - String includeNameStr = includerName[j]; + for (int j = 0; j < includeName.length; j++) { + String includeNameStr = includeName[j]; if (includeNameStr != null) { - str = CommonDefinition.include + " " + "<"; + str = CommonDefinition.INCLUDE + " " + "<"; str = str + includeNameStr + ">\r\n"; - includStrList.add(str); + includeStrList.add(str); includeNameStr = null; } } } - return includStrList; + return includeStrList; } /** - * IncludesToAutogenH - * - * This function add include file in AutoGen.h file. - * - * @param packageNameList - * List of module depended package. - * @param moduleType - * Module type. - * @return - */ + IncludesToAutogenH + + This function add include file in AutoGen.h file. + + @param packageNameList + List of module depended package. + @param moduleType + Module type. + @return + **/ List depPkgToAutogenH(PackageIdentification[] packageNameList, String moduleType) throws AutoGenException { @@ -756,7 +748,7 @@ public class AutoGen { + packageNameList[i] + "] declaration in any SPD package. "); } else if (!pkgHeader.equalsIgnoreCase("")) { - includeStr = CommonDefinition.include + " <" + pkgHeader + includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader + ">\r\n"; includeStrList.add(includeStr); } @@ -766,21 +758,23 @@ public class AutoGen { } /** - * EntryPointToAutoGen - * - * This function convert & - * information in mas to AutoGen.c - * - * @param entryPointList - * List of entry point. - * @param fileBuffer - * String buffer fo AutoGen.c. - * @throws Exception - */ - void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer) - throws BuildException { - - String typeStr = SurfaceAreaQuery.getModuleType(); + EntryPointToAutoGen + + This function convert & + information in mas to AutoGen.c + + @param entryPointList + List of entry point. + @param fileBuffer + String buffer fo AutoGen.c. + @throws Exception + **/ + void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer) + throws EdkException { + + String typeStr = saq.getModuleType(); + int unloadImageCount = 0; + int entryPointCount = 0; // // The parameters and return value of entryPoint is difference @@ -790,11 +784,10 @@ public class AutoGen { case CommonDefinition.ModuleTypePeiCore: if (entryPointList == null ||entryPointList.length != 1 ) { - throw new BuildException( + throw new AutoGenException( "Module type = 'PEI_CORE', can have only one module entry point!"); } else { fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); fileBuffer.append(entryPointList[0]); fileBuffer.append(" (\r\n"); fileBuffer @@ -822,12 +815,11 @@ public class AutoGen { case CommonDefinition.ModuleTypeDxeCore: fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n"); if (entryPointList == null || entryPointList.length != 1) { - throw new BuildException( + throw new AutoGenException( "Module type = 'DXE_CORE', can have only one module entry point!"); } else { fileBuffer.append("VOID\r\n"); - fileBuffer.append("EFIAPI\r\n"); fileBuffer.append(entryPointList[0]); fileBuffer.append(" (\n"); fileBuffer.append(" IN VOID *HobStart\r\n"); @@ -847,7 +839,7 @@ public class AutoGen { break; case CommonDefinition.ModuleTypePeim: - int entryPointCount = 0; + entryPointCount = 0; fileBuffer .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n"); if (entryPointList == null || entryPointList.length == 0) { @@ -864,7 +856,6 @@ public class AutoGen { } for (int i = 0; i < entryPointList.length; i++) { fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); fileBuffer.append(entryPointList[i]); fileBuffer.append(" (\r\n"); fileBuffer @@ -933,7 +924,6 @@ public class AutoGen { } else { for (int i = 0; i < entryPointList.length; i++) { fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); fileBuffer.append(entryPointList[i]); fileBuffer.append(" (\r\n"); fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); @@ -992,26 +982,26 @@ public class AutoGen { // // Add "ModuleUnloadImage" for DxeSmmDriver module type; // - entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray(); - entryPointList = CommonDefinition.remDupString(entryPointList); - entryPointCount = 0; + //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray(); + //entryPointList = CommonDefinition.remDupString(entryPointList); + //entryPointCount = 0; - if (entryPointList != null) { - for (int i = 0; i < entryPointList.length; i++) { + unloadImageCount = 0; + if (unloadImageList != null) { + for (int i = 0; i < unloadImageList.length; i++) { fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append(" (\r\n"); fileBuffer .append(" IN EFI_HANDLE ImageHandle\r\n"); fileBuffer.append(" );\r\n"); - entryPointCount++; + unloadImageCount++; } } fileBuffer .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); - fileBuffer.append(Integer.toString(entryPointCount)); + fileBuffer.append(Integer.toString(unloadImageCount)); fileBuffer.append(";\r\n\r\n"); fileBuffer.append("EFI_STATUS\r\n"); @@ -1021,28 +1011,28 @@ public class AutoGen { fileBuffer.append(" )\r\n"); fileBuffer.append("{\r\n"); - if (entryPointCount == 0) { + if (unloadImageCount == 0) { fileBuffer.append(" return EFI_SUCCESS;\r\n"); - } else if (entryPointCount == 1) { + } else if (unloadImageCount == 1) { fileBuffer.append(" return "); - fileBuffer.append(entryPointList[0]); + fileBuffer.append(unloadImageList[0]); fileBuffer.append("(ImageHandle);\r\n"); } else { fileBuffer.append(" EFI_STATUS Status;\r\n\r\n"); fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n"); - for (int i = 0; i < entryPointList.length; i++) { + for (int i = 0; i < unloadImageList.length; i++) { if (i == 0) { fileBuffer.append(" Status = "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); } else { fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n"); fileBuffer.append(" "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); fileBuffer.append(" } else {\r\n"); fileBuffer.append(" Status = "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); fileBuffer.append(" }\r\n"); } @@ -1079,7 +1069,6 @@ public class AutoGen { for (int i = 0; i < entryPointList.length; i++) { fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); fileBuffer.append(entryPointList[i]); fileBuffer.append(" (\r\n"); fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); @@ -1158,28 +1147,29 @@ public class AutoGen { // // Add ModuleUnloadImage for DxeDriver and UefiDriver module type. // - entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray(); + //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray(); // // Remover duplicate unload entry point. // - entryPointList = CommonDefinition.remDupString(entryPointList); - entryPointCount = 0; - if (entryPointList != null) { - for (int i = 0; i < entryPointList.length; i++) { + //entryPointList = CommonDefinition.remDupString(entryPointList); + //entryPointCount = 0; + unloadImageCount = 0; + if (unloadImageList != null) { + for (int i = 0; i < unloadImageList.length; i++) { fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append(" (\r\n"); fileBuffer .append(" IN EFI_HANDLE ImageHandle\r\n"); fileBuffer.append(" );\r\n"); - entryPointCount++; + unloadImageCount++; } } fileBuffer .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); - fileBuffer.append(Integer.toString(entryPointCount)); + fileBuffer.append(Integer.toString(unloadImageCount)); fileBuffer.append(";\r\n\r\n"); fileBuffer.append("EFI_STATUS\n"); @@ -1189,28 +1179,28 @@ public class AutoGen { fileBuffer.append(" )\r\n"); fileBuffer.append("{\r\n"); - if (entryPointCount == 0) { + if (unloadImageCount == 0) { fileBuffer.append(" return EFI_SUCCESS;\r\n"); - } else if (entryPointCount == 1) { + } else if (unloadImageCount == 1) { fileBuffer.append(" return "); - fileBuffer.append(entryPointList[0]); + fileBuffer.append(unloadImageList[0]); fileBuffer.append("(ImageHandle);\r\n"); } else { fileBuffer.append(" EFI_STATUS Status;\r\n\r\n"); fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n"); - for (int i = 0; i < entryPointList.length; i++) { + for (int i = 0; i < unloadImageList.length; i++) { if (i == 0) { fileBuffer.append(" Status = "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); } else { fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n"); fileBuffer.append(" "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); fileBuffer.append(" } else {\r\n"); fileBuffer.append(" Status = "); - fileBuffer.append(entryPointList[i]); + fileBuffer.append(unloadImageList[i]); fileBuffer.append("(ImageHandle);\r\n"); fileBuffer.append(" }\r\n"); } @@ -1223,16 +1213,16 @@ public class AutoGen { } /** - * PpiGuidToAutogenc - * - * This function gets GUIDs from SPD file accrodeing to information - * and write those GUIDs to AutoGen.c. - * - * @param fileBuffer - * String Buffer for Autogen.c file. - * @throws BuildException - * Guid must set value! - */ + PpiGuidToAutogenc + + This function gets GUIDs from SPD file accrodeing to information + and write those GUIDs to AutoGen.c. + + @param fileBuffer + String Buffer for Autogen.c file. + @throws BuildException + Guid must set value! + **/ void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException { String[] cNameGuid = null; @@ -1241,12 +1231,12 @@ public class AutoGen { // then add those PPI ,and PPI Notify name to list. // - String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch); + String[] ppiList = saq.getPpiArray(this.arch); for (int i = 0; i < ppiList.length; i++) { this.mPpiList.add(ppiList[i]); } - String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch); + String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); for (int i = 0; i < ppiNotifyList.length; i++) { this.mPpiList.add(ppiNotifyList[i]); } @@ -1277,20 +1267,20 @@ public class AutoGen { } /** - * ProtocolGuidToAutogenc - * - * This function gets GUIDs from SPD file accrodeing to - * information and write those GUIDs to AutoGen.c. - * - * @param fileBuffer - * String Buffer for Autogen.c file. - * @throws BuildException - * Protocol name must set. - */ - void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException { + ProtocolGuidToAutogenc + + This function gets GUIDs from SPD file accrodeing to + information and write those GUIDs to AutoGen.c. + + @param fileBuffer + String Buffer for Autogen.c file. + @throws BuildException + Protocol name must set. + **/ + void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException { String[] cNameGuid = null; - String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch); + String[] protocolList = saq.getProtocolArray(this.arch); // // Add result to Autogen global list. @@ -1299,7 +1289,7 @@ public class AutoGen { this.mProtocolList.add(protocolList[i]); } - String[] protocolNotifyList = SurfaceAreaQuery + String[] protocolNotifyList = saq .getProtocolNotifyArray(this.arch); for (int i = 0; i < protocolNotifyList.length; i++) { @@ -1327,27 +1317,27 @@ public class AutoGen { // // If can't find protocol GUID declaration in every package // - throw new BuildException("Can not find protocol Guid [" + throw new AutoGenException("Can not find protocol Guid [" + protocolKeyWord + "] declaration in any SPD package!"); } } } /** - * GuidGuidToAutogenc - * - * This function gets GUIDs from SPD file accrodeing to information - * and write those GUIDs to AutoGen.c. - * - * @param fileBuffer - * String Buffer for Autogen.c file. - * - */ + GuidGuidToAutogenc + + This function gets GUIDs from SPD file accrodeing to information + and write those GUIDs to AutoGen.c. + + @param fileBuffer + String Buffer for Autogen.c file. + + **/ void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException { String[] cNameGuid = null; String guidKeyWord = null; - String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch); + String[] guidList = saq.getGuidEntryArray(this.arch); for (int i = 0; i < guidList.length; i++) { this.mGuidList.add(guidList[i]); @@ -1378,49 +1368,45 @@ public class AutoGen { } /** - * LibInstanceToAutogenC - * - * This function adds dependent library instance to autogen.c,which - * includeing library's constructor, destructor, and library dependent ppi, - * protocol, guid, pcd information. - * - * @param fileBuffer - * String buffer for AutoGen.c - * @throws BuildException - */ - void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException { - try { - String moduleType = this.moduleId.getModuleType(); - // - // Add library constructor to AutoGen.c - // - LibConstructorToAutogenC(libConstructList, moduleType, - fileBuffer/* autogenC */); - // - // Add library destructor to AutoGen.c - // - LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */); - } catch (Exception e) { - throw new BuildException(e.getMessage()); - } + LibInstanceToAutogenC + + This function adds dependent library instance to autogen.c,which + includeing library's constructor, destructor, and library dependent ppi, + protocol, guid, pcd information. + + @param fileBuffer + String buffer for AutoGen.c + @throws BuildException + **/ + void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException { + String moduleType = this.moduleId.getModuleType(); + // + // Add library constructor to AutoGen.c + // + LibConstructorToAutogenC(libConstructList, moduleType, + fileBuffer/* autogenC */); + // + // Add library destructor to AutoGen.c + // + LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */); } /** - * LibConstructorToAutogenc - * - * This function writes library constructor list to AutoGen.c. The library - * constructor's parameter and return value depend on module type. - * - * @param libInstanceList - * List of library construct name. - * @param moduleType - * Module type. - * @param fileBuffer - * String buffer for AutoGen.c - * @throws Exception - */ - void LibConstructorToAutogenC(List libInstanceList, - String moduleType, StringBuffer fileBuffer) throws Exception { + LibConstructorToAutogenc + + This function writes library constructor list to AutoGen.c. The library + constructor's parameter and return value depend on module type. + + @param libInstanceList + List of library construct name. + @param moduleType + Module type. + @param fileBuffer + String buffer for AutoGen.c + @throws Exception + **/ + void LibConstructorToAutogenC(List libInstanceList, + String moduleType, StringBuffer fileBuffer) throws EdkException { boolean isFirst = true; // @@ -1428,44 +1414,54 @@ public class AutoGen { // module type. // for (int i = 0; i < libInstanceList.size(); i++) { - switch (CommonDefinition.getModuleType(moduleType)) { - case CommonDefinition.ModuleTypeBase: - fileBuffer.append("RETURN_STATUS\r\n"); + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + fileBuffer.append("RETURN_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); + fileBuffer.append(libInstanceList.get(i)[0]); fileBuffer.append(" (\r\n"); fileBuffer.append(" VOID\r\n"); fileBuffer.append(" );\r\n"); - break; - - case CommonDefinition.ModuleTypePeiCore: - case CommonDefinition.ModuleTypePeim: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); - fileBuffer.append(" );\r\n"); - break; + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + fileBuffer.append("RETURN_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer.append(" VOID\r\n"); + fileBuffer.append(" );\r\n"); + break; - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); - break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + fileBuffer.append("EFI_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer + .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + fileBuffer + .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + fileBuffer.append(" );\r\n"); + break; + + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + fileBuffer.append("EFI_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); + fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + fileBuffer.append(" );\r\n"); + break; + + } } } @@ -1514,32 +1510,38 @@ public class AutoGen { fileBuffer.append("\r\n"); isFirst = false; } - switch (CommonDefinition.getModuleType(moduleType)) { - case CommonDefinition.ModuleTypeBase: + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)); + fileBuffer.append(libInstanceList.get(i)[0]); fileBuffer.append("();\r\n"); - fileBuffer.append(" VOID\r\n"); - break; - case CommonDefinition.ModuleTypePeiCore: - case CommonDefinition.ModuleTypePeim: - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); - break; - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (ImageHandle, SystemTable);\r\n"); - break; - default: - EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!"); + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append("();\r\n"); + break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); + break; + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (ImageHandle, SystemTable);\r\n"); + break; + default: + EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!"); + } + } fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); } @@ -1547,59 +1549,68 @@ public class AutoGen { } /** - * LibDestructorToAutogenc - * - * This function writes library destructor list to AutoGen.c. The library - * destructor's parameter and return value depend on module type. - * - * @param libInstanceList - * List of library destructor name. - * @param moduleType - * Module type. - * @param fileBuffer - * String buffer for AutoGen.c - * @throws Exception - */ - void LibDestructorToAutogenC(List libInstanceList, - String moduleType, StringBuffer fileBuffer) throws Exception { + LibDestructorToAutogenc + + This function writes library destructor list to AutoGen.c. The library + destructor's parameter and return value depend on module type. + + @param libInstanceList + List of library destructor name. + @param moduleType + Module type. + @param fileBuffer + String buffer for AutoGen.c + @throws Exception + **/ + void LibDestructorToAutogenC(List libInstanceList, + String moduleType, StringBuffer fileBuffer) throws EdkException { boolean isFirst = true; for (int i = 0; i < libInstanceList.size(); i++) { - switch (CommonDefinition.getModuleType(moduleType)) { - case CommonDefinition.ModuleTypeBase: + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { fileBuffer.append("RETURN_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); + fileBuffer.append(libInstanceList.get(i)[0]); fileBuffer.append(" (\r\n"); fileBuffer.append(" VOID\r\n"); fileBuffer.append(" );\r\n"); - break; - case CommonDefinition.ModuleTypePeiCore: - case CommonDefinition.ModuleTypePeim: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); - fileBuffer.append(" );\r\n"); - break; - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); - break; + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + fileBuffer.append("RETURN_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer.append(" VOID\r\n"); + fileBuffer.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + fileBuffer.append("EFI_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer + .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + fileBuffer + .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + fileBuffer.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + fileBuffer.append("EFI_STATUS\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (\r\n"); + fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); + fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + fileBuffer.append(" );\r\n"); + break; + } } } @@ -1636,10 +1647,17 @@ public class AutoGen { fileBuffer.append("\r\n"); isFirst = false; } - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)); - fileBuffer.append("(ImageHandle, SystemTable);\r\n"); - fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append("();\r\n"); + fileBuffer.append(" VOID\r\n"); + } else { + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append("(ImageHandle, SystemTable);\r\n"); + fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); + } } fileBuffer.append("}\r\n"); break; @@ -1647,100 +1665,88 @@ public class AutoGen { } /** - * ExternsDriverBindingToAutoGenC - * - * This function is to write DRIVER_BINDING, COMPONENT_NAME, - * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c. - * - * @param fileBuffer - * String buffer for AutoGen.c - */ + ExternsDriverBindingToAutoGenC + + This function is to write DRIVER_BINDING, COMPONENT_NAME, + DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c. + + @param fileBuffer + String buffer for AutoGen.c + **/ void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer) - throws BuildException { + throws EdkException { // - // Check what contains. And the number of following elements - // under should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME - // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC - // - - String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray(); + // Get the arry of extern. The driverBindingGroup is a 2 dimension array. + // The second dimension is include following element: DriverBinding, + // ComponentName, DriverConfiguration, DriverDiag; + // + String[][] driverBindingGroup = this.saq.getExternProtocolGroup(); // - // If component name protocol,component configuration protocol, - // component diagnostic protocol is not null or empty, check - // if every one have the same number of the driver binding protocol. - // - if (drvBindList == null || drvBindList.length == 0) { - return; - } - - String[] compNamList = SurfaceAreaQuery.getComponentNameArray(); - String[] compConfList = SurfaceAreaQuery.getDriverConfigArray(); - String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray(); - + // inital BitMask; + // int BitMask = 0; // // Write driver binding protocol extern to autogen.c // - for (int i = 0; i < drvBindList.length; i++) { - fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL "); - fileBuffer.append(drvBindList[i]); - fileBuffer.append(";\r\n"); + for (int i = 0; i < driverBindingGroup.length; i++) { + if (driverBindingGroup[i][0] != null) { + fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL "); + fileBuffer.append(driverBindingGroup[i][0]); + fileBuffer.append(";\r\n"); + } } // // Write component name protocol extern to autogen.c // - if (compNamList != null && compNamList.length != 0) { - if (drvBindList.length != compNamList.length) { - throw new BuildException( - "Different number of Driver Binding and Component Name protocols!"); - } - - BitMask |= 0x01; - for (int i = 0; i < compNamList.length; i++) { - fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL "); - fileBuffer.append(compNamList[i]); - fileBuffer.append(";\r\n"); - } - } + for (int i = 0; i < driverBindingGroup.length; i++) { + if (driverBindingGroup[i][1]!= null) { + if (driverBindingGroup[i][0] != null) { + BitMask |= 0x01; + fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL "); + fileBuffer.append(driverBindingGroup[i][1]); + fileBuffer.append(";\r\n"); + } else { + throw new AutoGenException("DriverBinding can't be empty!!"); + } + } + } // // Write driver configration protocol extern to autogen.c // - if (compConfList != null && compConfList.length != 0) { - if (drvBindList.length != compConfList.length) { - throw new BuildException( - "Different number of Driver Binding and Driver Configuration protocols!"); - } - - BitMask |= 0x02; - for (int i = 0; i < compConfList.length; i++) { - fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL "); - fileBuffer.append(compConfList[i]); - fileBuffer.append(";\r\n"); - } - } - + for (int i = 0; i < driverBindingGroup.length; i++) { + if (driverBindingGroup[i][2] != null) { + if (driverBindingGroup[i][0] != null) { + BitMask |= 0x02; + fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL "); + fileBuffer.append(driverBindingGroup[i][2]); + fileBuffer.append(";\r\n"); + } else { + throw new AutoGenException("DriverBinding can't be empty!!"); + } + } + } + // // Write driver dignastic protocol extern to autogen.c // - if (compDiagList != null && compDiagList.length != 0) { - if (drvBindList.length != compDiagList.length) { - throw new BuildException( - "Different number of Driver Binding and Driver Diagnosis protocols!"); - } - - BitMask |= 0x04; - for (int i = 0; i < compDiagList.length; i++) { - fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL "); - fileBuffer.append(compDiagList[i]); - fileBuffer.append(";\r\n"); - } - } - + for (int i = 0; i < driverBindingGroup.length; i++) { + if (driverBindingGroup[i][3] != null) { + if (driverBindingGroup[i][0] != null) { + BitMask |= 0x04; + fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL "); + fileBuffer.append(driverBindingGroup[i][3]); + fileBuffer.append(";\r\n"); + } else { + throw new AutoGenException("DriverBinding can't be empty!!"); + } + } + } + // // Write driver module protocol bitmask. // @@ -1755,70 +1761,79 @@ public class AutoGen { fileBuffer .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = "); - fileBuffer.append(Integer.toString(drvBindList.length)); + fileBuffer.append(Integer.toString(driverBindingGroup.length)); fileBuffer.append(";\r\n"); // // Write drive module protocol list to autogen.c // - fileBuffer + if (driverBindingGroup.length > 0) { + fileBuffer .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {"); - for (int i = 0; i < drvBindList.length; i++) { + } + + + for (int i = 0; i < driverBindingGroup.length; i++) { if (i != 0) { fileBuffer.append(","); } - fileBuffer.append("\r\n {\r\n"); + + fileBuffer.append("\r\n {\r\n"); fileBuffer.append(" &"); - fileBuffer.append(drvBindList[i]); + fileBuffer.append(driverBindingGroup[i][0]); fileBuffer.append(", \r\n"); + - if (compNamList != null) { + if (driverBindingGroup[i][1] != null) { fileBuffer.append(" &"); - fileBuffer.append(compNamList[i]); + fileBuffer.append(driverBindingGroup[i][1]); fileBuffer.append(", \r\n"); } else { fileBuffer.append(" NULL, \r\n"); } - if (compConfList != null) { + if (driverBindingGroup[i][2] != null) { fileBuffer.append(" &"); - fileBuffer.append(compConfList[i]); + fileBuffer.append(driverBindingGroup[i][2]); fileBuffer.append(", \r\n"); } else { fileBuffer.append(" NULL, \r\n"); } - if (compDiagList != null) { + if (driverBindingGroup[i][3] != null) { fileBuffer.append(" &"); - fileBuffer.append(compDiagList[i]); + fileBuffer.append(driverBindingGroup[i][3]); fileBuffer.append(", \r\n"); } else { fileBuffer.append(" NULL, \r\n"); } fileBuffer.append(" }"); } - fileBuffer.append("\r\n};\r\n"); + + if (driverBindingGroup.length > 0) { + fileBuffer.append("\r\n};\r\n"); + } } /** - * ExternCallBackToAutoGenC - * - * This function adds and - * infomation to AutoGen.c - * - * @param fileBuffer - * String buffer for AutoGen.c - * @throws BuildException - */ + ExternCallBackToAutoGenC + + This function adds and + infomation to AutoGen.c + + @param fileBuffer + String buffer for AutoGen.c + @throws BuildException + **/ void ExternCallBackToAutoGenC(StringBuffer fileBuffer) - throws BuildException { + throws EdkException { // // Collect module's and // and add to setVirtualAddList // exitBootServiceList. // - String[] setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray(); - String[] exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray(); + String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); + String[] exitBoots = saq.getExitBootServicesCallBackArray(); if (setVirtuals != null) { for (int j = 0; j < setVirtuals.length; j++) { this.setVirtalAddList.add(setVirtuals[j]); @@ -1834,28 +1849,205 @@ public class AutoGen { // and // String moduleType = this.moduleId.getModuleType(); - boolean UefiOrDxeModule = false; - int Count = 0; - int i; switch (CommonDefinition.getModuleType(moduleType)) { case CommonDefinition.ModuleTypeDxeDriver: case CommonDefinition.ModuleTypeDxeRuntimeDriver: case CommonDefinition.ModuleTypeDxeSalDriver: case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - // - // Entry point lib for these module types needs to know the count - // of entryPoint. - // - UefiOrDxeModule = true; - fileBuffer + case CommonDefinition.ModuleTypeUefiApplication: + // + // If moduleType is one of above, call setVirtualAddressToAutogenC, + // and setExitBootServiceToAutogenC. + // + setVirtualAddressToAutogenC(fileBuffer); + setExitBootServiceToAutogenC(fileBuffer); + break; + default: + break; + } + } + + /** + copyFlashMapHToDebugDir + + This function is to copy the falshmap.h to debug directory and change + its name to TianoR8FlashMap.h + + @param + @return + **/ + private void copyFlashMapHToDebugDir() throws AutoGenException{ + + File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH); + int size = (int)inFile.length(); + byte[] buffer = new byte[size]; + File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH); + // + // If TianoR8FlashMap.h existed and the flashMap.h don't change, + // do nothing. + // + if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) { + if (inFile.exists()) { + try{ + FileInputStream fis = new FileInputStream (inFile); + fis.read(buffer); + FileOutputStream fos = new FileOutputStream(outFile); + fos.write(buffer); + fis.close(); + fos.close(); + } catch (IOException e){ + throw new AutoGenException("The file, flashMap.h can't be open!"); + } + + } else { + throw new AutoGenException("The file, flashMap.h doesn't exist!"); + } + } + } + + /** + This function first order the library instances, then collect + library instance 's PPI, Protocol, GUID, + SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and + Destructor, Constructor. + + @param + @return + **/ + private void collectLibInstanceInfo() throws EdkException{ + int index; + + String libConstructName = null; + String libDestructName = null; + String libModuleType = null; + String[] setVirtuals = null; + String[] exitBoots = null; + + ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch); + + if (libraryIdList != null) { + // + // Reorder library instance sequence. + // + AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, + this.arch); + List orderList = libOrder + .orderLibInstance(); + + if (orderList != null) { + // + // Process library instance one by one. + // + for (int i = 0; i < orderList.size(); i++) { + + // + // Get library instance basename. + // + ModuleIdentification libInstanceId = orderList.get(i); + + // + // Get override map + // + + Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); + saq.push(libDoc); + // + // Get , , list of this library + // instance. + // + String[] ppiList = saq.getPpiArray(this.arch); + String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); + String[] protocolList = saq.getProtocolArray(this.arch); + String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch); + String[] guidList = saq.getGuidEntryArray(this.arch); + PackageIdentification[] pkgList = saq.getDependencePkg(this.arch); + + // + // Add those ppi, protocol, guid in global ppi, + // protocol, guid + // list. + // + for (index = 0; index < ppiList.length; index++) { + this.mPpiList.add(ppiList[index]); + } + + for (index = 0; index < ppiNotifyList.length; index++) { + this.mPpiList.add(ppiNotifyList[index]); + } + + for (index = 0; index < protocolList.length; index++) { + this.mProtocolList.add(protocolList[index]); + } + + for (index = 0; index < protocolNotifyList.length; index++) { + this.mProtocolList.add(protocolNotifyList[index]); + } + + for (index = 0; index < guidList.length; index++) { + this.mGuidList.add(guidList[index]); + } + for (index = 0; index < pkgList.length; index++) { + if (!this.mDepPkgList.contains(pkgList[index])) { + this.mDepPkgList.add(pkgList[index]); + } + } + + // + // If not yet parse this library instance's constructor + // element,parse it. + // + libConstructName = saq.getLibConstructorName(); + libDestructName = saq.getLibDestructorName(); + libModuleType = saq.getModuleType(); + + // + // Collect SetVirtualAddressMapCallBack and + // ExitBootServiceCallBack. + // + setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); + exitBoots = saq.getExitBootServicesCallBackArray(); + if (setVirtuals != null) { + for (int j = 0; j < setVirtuals.length; j++) { + this.setVirtalAddList.add(setVirtuals[j]); + } + } + if (exitBoots != null) { + for (int k = 0; k < exitBoots.length; k++) { + this.exitBootServiceList.add(exitBoots[k]); + } + } + saq.pop(); + // + // Add dependent library instance constructor function. + // + if (libConstructName != null) { + this.libConstructList.add(new String[] {libConstructName, libModuleType}); + } + // + // Add dependent library instance destructor fuction. + // + if (libDestructName != null) { + this.libDestructList.add(new String[] {libDestructName, libModuleType}); + } + } + } + + } + } + private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){ + // + // Entry point lib for these module types needs to know the count + // of entryPoint. + // + fileBuffer .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = "); // // If the list is not valid or has no entries set count to zero else // set count to the number of valid entries // - Count = 0; + int Count = 0; + int i = 0; if (this.setVirtalAddList != null) { for (i = 0; i < this.setVirtalAddList.size(); i++) { if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { @@ -1867,13 +2059,7 @@ public class AutoGen { fileBuffer.append(Integer.toString(Count)); fileBuffer.append(";\r\n\r\n"); - break; - default: - break; - } - - if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) { - if (UefiOrDxeModule) { + if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) { // // No data so make a NULL list // @@ -1881,87 +2067,82 @@ public class AutoGen { .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n"); fileBuffer.append(" NULL\r\n"); fileBuffer.append("};\r\n\r\n"); - } - } else { - // - // Write SetVirtualAddressMap function definition. - // - for (i = 0; i < this.setVirtalAddList.size(); i++) { - if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { - break; - } - fileBuffer.append("VOID\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(this.setVirtalAddList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_EVENT Event,\r\n"); - fileBuffer.append(" IN VOID *Context\r\n"); - fileBuffer.append(" );\r\n\r\n"); - } + } else { + // + // Write SetVirtualAddressMap function definition. + // + for (i = 0; i < this.setVirtalAddList.size(); i++) { + if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { + break; + } + fileBuffer.append("VOID\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append(this.setVirtalAddList.get(i)); + fileBuffer.append(" (\r\n"); + fileBuffer.append(" IN EFI_EVENT Event,\r\n"); + fileBuffer.append(" IN VOID *Context\r\n"); + fileBuffer.append(" );\r\n\r\n"); + } - // - // Write SetVirtualAddressMap entry point array. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {"); - for (i = 0; i < this.setVirtalAddList.size(); i++) { - if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { - break; - } + // + // Write SetVirtualAddressMap entry point array. + // + fileBuffer + .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {"); + for (i = 0; i < this.setVirtalAddList.size(); i++) { + if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { + break; + } - if (i == 0) { - fileBuffer.append("\r\n "); - } else { - fileBuffer.append(",\r\n "); - } + if (i == 0) { + fileBuffer.append("\r\n "); + } else { + fileBuffer.append(",\r\n "); + } - fileBuffer.append(this.setVirtalAddList.get(i)); - } - // - // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER - // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of - // _gDriverSetVirtualAddressMapEvent list. - // - if (!UefiOrDxeModule) { + fileBuffer.append(this.setVirtalAddList.get(i)); + } + // + // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list. + // fileBuffer.append(",\r\n NULL"); - } - fileBuffer.append("\r\n};\r\n\r\n"); - } + fileBuffer.append("\r\n};\r\n\r\n"); + } + } - if (UefiOrDxeModule) { - // - // Entry point lib for these module types needs to know the count. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = "); - // - // If the list is not valid or has no entries set count to zero else - // set count to the number of valid entries. - // - Count = 0; - if (this.exitBootServiceList != null) { - for (i = 0; i < this.exitBootServiceList.size(); i++) { - if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { - break; - } + private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){ + // + // Entry point lib for these module types needs to know the count. + // + fileBuffer + .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = "); + + // + // If the list is not valid or has no entries set count to zero else + // set count to the number of valid entries. + // + int Count = 0; + int i = 0; + if (this.exitBootServiceList != null) { + for (i = 0; i < this.exitBootServiceList.size(); i++) { + if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { + break; } - Count = i; } - fileBuffer.append(Integer.toString(Count)); - fileBuffer.append(";\r\n\r\n"); + Count = i; } + fileBuffer.append(Integer.toString(Count)); + fileBuffer.append(";\r\n\r\n"); - if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) { - if (UefiOrDxeModule) { - // - // No data so make a NULL list. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n"); - fileBuffer.append(" NULL\r\n"); - fileBuffer.append("};\r\n\r\n"); - } + if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) { + // + // No data so make a NULL list. + // + fileBuffer + .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n"); + fileBuffer.append(" NULL\r\n"); + fileBuffer.append("};\r\n\r\n"); } else { // // Write DriverExitBootServices function definition. @@ -1997,185 +2178,11 @@ public class AutoGen { } fileBuffer.append(this.exitBootServiceList.get(i)); } - if (!UefiOrDxeModule) { - fileBuffer.append(",\r\n NULL"); - } + + fileBuffer.append(",\r\n NULL"); fileBuffer.append("\r\n};\r\n\r\n"); } - } - - private void copyFlashMapHToDebugDir() throws AutoGenException{ - - File inFile = new File(fvDir + File.separatorChar + CommonDefinition.flashMapH); - int size = (int)inFile.length(); - byte[] buffer = new byte[size]; - File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.tianoR8FlashMapH); - // - // If TianoR8FlashMap.h existed and the flashMap.h don't change, - // do nothing. - // - if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) { - try { - if (inFile.exists()) { - FileInputStream fis = new FileInputStream (inFile); - fis.read(buffer); - FileOutputStream fos = new FileOutputStream(outFile); - fos.write(buffer); - fis.close(); - fos.close(); - } else { - throw new AutoGenException("The file, flashMap.h doesn't exist!"); - } - } catch (Exception e) { - throw new AutoGenException(e.getMessage()); - } - } - } - - /** - *This function first order the library instances, then collect - *library instance 's PPI, Protocol, GUID, - *SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and - *Destructor, Constructor. - * - **/ - private void collectLibInstanceInfo(){ - int index; - - String moduleType = SurfaceAreaQuery.getModuleType(); - String libConstructName = null; - String libDestructName = null; - String[] setVirtuals = null; - String[] exitBoots = null; - - ModuleIdentification[] libraryIdList = SurfaceAreaQuery - .getLibraryInstance(this.arch); - try { - if (libraryIdList != null) { - // - // Reorder library instance sequence. - // - AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, - this.arch); - List orderList = libOrder - .orderLibInstance(); - - if (orderList != null) { - // - // Process library instance one by one. - // - for (int i = 0; i < orderList.size(); i++) { - - // - // Get library instance basename. - // - ModuleIdentification libInstanceId = orderList.get(i); - - // - // Get override map - // - - Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); - SurfaceAreaQuery.push(libDoc); - // - // Get , , list of this library - // instance. - // - String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch); - String[] ppiNotifyList = SurfaceAreaQuery - .getPpiNotifyArray(this.arch); - String[] protocolList = SurfaceAreaQuery - .getProtocolArray(this.arch); - String[] protocolNotifyList = SurfaceAreaQuery - .getProtocolNotifyArray(this.arch); - String[] guidList = SurfaceAreaQuery - .getGuidEntryArray(this.arch); - String[] libraryClassList = SurfaceAreaQuery.getLibraryClasses( - CommonDefinition.AlwaysConsumed, - this.arch); - PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch); - - // - // Add those ppi, protocol, guid in global ppi, - // protocol, guid - // list. - // - for (index = 0; index < ppiList.length; index++) { - this.mPpiList.add(ppiList[index]); - } - - for (index = 0; index < ppiNotifyList.length; index++) { - this.mPpiList.add(ppiNotifyList[index]); - } - - for (index = 0; index < protocolList.length; index++) { - this.mProtocolList.add(protocolList[index]); - } - - for (index = 0; index < protocolNotifyList.length; index++) { - this.mProtocolList.add(protocolNotifyList[index]); - } - - for (index = 0; index < guidList.length; index++) { - this.mGuidList.add(guidList[index]); - } - for (index = 0; index < pkgList.length; index++) { - if (!this.mDepPkgList.contains(pkgList[index])) { - this.mDepPkgList.add(pkgList[index]); - } - } - for (index = 0; index < libraryClassList.length; index++) { - if (libraryClassList[index].equalsIgnoreCase(CommonDefinition.pcdLibName)) { - this.isModuleLibraryInstanceUsePcd = true; - } - } - // - // If not yet parse this library instance's constructor - // element,parse it. - // - libConstructName = SurfaceAreaQuery - .getLibConstructorName(); - libDestructName = SurfaceAreaQuery - .getLibDestructorName(); - - // - // Collect SetVirtualAddressMapCallBack and - // ExitBootServiceCallBack. - // - setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray(); - exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray(); - if (setVirtuals != null) { - for (int j = 0; j < setVirtuals.length; j++) { - this.setVirtalAddList.add(setVirtuals[j]); - } - } - if (exitBoots != null) { - for (int k = 0; k < exitBoots.length; k++) { - this.exitBootServiceList.add(exitBoots[k]); - } - } - SurfaceAreaQuery.pop(); - // - // Add dependent library instance constructor function. - // - if (libConstructName != null) { - this.libConstructList.add(libConstructName); - } - // - // Add dependent library instance destructor fuction. - // - if (libDestructName != null) { - this.libDestructList.add(libDestructName); - } - } - } - - } + } - } catch (Exception e) { - System.out.println(e.getMessage()); - System.out.println("Collect library instance failed!"); - } - } }