]> git.proxmox.com Git - mirror_edk2.git/commitdiff
New tool.
authorqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jun 2006 19:56:10 +0000 (19:56 +0000)
committerqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jun 2006 19:56:10 +0000 (19:56 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@692 6f19259b-4bc3-4df7-8a09-765794883524

23 files changed:
EdkNt32Pkg/EdkNt32Pkg.spd
EdkNt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.msa
EdkNt32Pkg/Nt32.fpd
Tools/Conf/BuildMacro.xml
Tools/Source/GenBuild/GenBuild.tasks
Tools/Source/GenBuild/org/tianocore/build/FileProcess.java
Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java
Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java
Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/ShowPCDDatabaseAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainKey.java
Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java

index bdf264d90b95f0a9bf9d28dd557089ea8782c92c..532ecea551216308bbf0b3b00efb373618cdfea1 100644 (file)
@@ -70,6 +70,7 @@
     <IncludePkgHeader ModuleType="DXE_SMM_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
     <IncludePkgHeader ModuleType="DXE_SAL_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
     <IncludePkgHeader ModuleType="UEFI_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
     <IncludePkgHeader ModuleType="DXE_SMM_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
     <IncludePkgHeader ModuleType="DXE_SAL_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
     <IncludePkgHeader ModuleType="UEFI_DRIVER">Include/WinNtDxe.h</IncludePkgHeader>\r
+    <IncludePkgHeader ModuleType="USER_DEFINED">Include/WinNtPeim.h</IncludePkgHeader>\r
   </PackageHeaders>\r
   <GuidDeclarations>\r
     <Entry Name="WinNtVirtualDisks">\r
   </PackageHeaders>\r
   <GuidDeclarations>\r
     <Entry Name="WinNtVirtualDisks">\r
index 3b3c5ee9be6dbcc8cbcecaea54e1cae15943aca3..e09d1618c0b01b83125c913e9136aebb822e1d64 100644 (file)
@@ -35,9 +35,9 @@
     <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
   </PackageDependencies>\r
   <PPIs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
     <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
   </PackageDependencies>\r
   <PPIs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
-    <Ppi Usage="ALWAYS_CONSUMED">\r
+    <!--<Ppi Usage="ALWAYS_CONSUMED">\r
       <PpiCName>PeCoffLoader</PpiCName>\r
       <PpiCName>PeCoffLoader</PpiCName>\r
-    </Ppi>\r
+    </Ppi>-->\r
   </PPIs>\r
   <Externs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
   </PPIs>\r
   <Externs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
index f1ed57c8cd853e1c75face78e4754823ea3ab01d..448beb5b674de5f1cb339ba58db2794c42b9d84c 100644 (file)
           <MaxDatumSize>4</MaxDatumSize>\r
           <Value>0x5678</Value>\r
         </PcdData>\r
           <MaxDatumSize>4</MaxDatumSize>\r
           <Value>0x5678</Value>\r
         </PcdData>\r
-        <PcdData ItemType="DYNAMIC">\r
-          <C_Name>PcdWinNtDynamicUINT32</C_Name>\r
-          <Token>0x0001000e</Token>\r
-          <TokenSpaceGuidCName>Fix_Me</TokenSpaceGuidCName>\r
-          <DatumType>UINT32</DatumType>\r
-          <MaxDatumSize>4</MaxDatumSize>\r
-          <Value>0x0</Value>\r
-        </PcdData>\r
       </PcdBuildDefinition>\r
       <ModuleSaBuildOptions>\r
         <FvBinding>FV_RECOVERY</FvBinding>\r
       </PcdBuildDefinition>\r
       <ModuleSaBuildOptions>\r
         <FvBinding>FV_RECOVERY</FvBinding>\r
         <Value>L"3000"</Value>\r
       </SkuInfo>\r
     </PcdBuildData>\r
         <Value>L"3000"</Value>\r
       </SkuInfo>\r
     </PcdBuildData>\r
-    <PcdBuildData ItemType="DYNAMIC">\r
-      <C_Name>PcdWinNtDynamicUINT32</C_Name>\r
-      <Token>0x0001000e</Token>\r
-      <TokenSpaceGuidCName>Fix_Me</TokenSpaceGuidCName>\r
-      <DatumType>UINT32</DatumType>\r
-      <MaxDatumSize>4</MaxDatumSize>\r
-      <SkuInfo>\r
-        <SkuId>0</SkuId>\r
-        <Value>0x0</Value>\r
-      </SkuInfo>\r
-    </PcdBuildData>\r
     <PcdBuildData ItemType="DYNAMIC">\r
       <C_Name>PcdKentTestDynamicUINT32</C_Name>\r
       <Token>0x0001000e</Token>\r
     <PcdBuildData ItemType="DYNAMIC">\r
       <C_Name>PcdKentTestDynamicUINT32</C_Name>\r
       <Token>0x0001000e</Token>\r
       <MaxDatumSize>4</MaxDatumSize>\r
       <SkuInfo>\r
         <SkuId>0</SkuId>\r
       <MaxDatumSize>4</MaxDatumSize>\r
       <SkuInfo>\r
         <SkuId>0</SkuId>\r
-        <VariableName>0x0062 0x006F 0x006F 0x0074 0x006D 0x006F 0x0064 0x0065</VariableName>\r
-        <VariableGuid>WinNPassThrough</VariableGuid>\r
-        <VariableOffset>0x123</VariableOffset>\r
-        <HiiDefaultValue>0x123</HiiDefaultValue>\r
+       <Value>0x2</Value>\r
       </SkuInfo>\r
     </PcdBuildData>\r
   </DynamicPcdBuildDefinitions>\r
       </SkuInfo>\r
     </PcdBuildData>\r
   </DynamicPcdBuildDefinitions>\r
index 7904180e925ec77584c5a7250e51c089e2f84a26..3c20e601d1765e737eaf7a033c1d24613246aeab 100644 (file)
@@ -493,7 +493,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
         </targetfiles>\r
 \r
         <sequential>\r
         </targetfiles>\r
 \r
         <sequential>\r
-          <vfrcompile createIfrBinFile="on" createListFile="on" outPutDir="${DEST_DIR_DEBUG}" vfrFile="${MODULE_DIR}/@{FILEPATH}/@{FILENAME}.@{FILEEXT}">\r
+          <vfrcompile createIfrBinFile="on" createListFile="on" outPutDir="${DEST_DIR_DEBUG}/@{FILEPATH}" vfrFile="${MODULE_DIR}/@{FILEPATH}/@{FILENAME}.@{FILEEXT}">\r
             <EXTRA.INC/>\r
           </vfrcompile>\r
     \r
             <EXTRA.INC/>\r
           </vfrcompile>\r
     \r
index c767cfb1dda0da96bd32cc9280e3821350158add..4d812e69f75cac9a6c4fc49c3de379e7e3b52c50 100644 (file)
@@ -1,11 +1,11 @@
 FPDParser          = org.tianocore.build.fpd.FpdParserTask\r
 bl                 = org.tianocore.build.global.VariableTask\r
 FPDParser          = org.tianocore.build.fpd.FpdParserTask\r
 bl                 = org.tianocore.build.global.VariableTask\r
-bf                 = org.tianocore.build.global.LibBuildFileGenerator\r
 GenBuild           = org.tianocore.build.GenBuildTask\r
 GenBuild           = org.tianocore.build.GenBuildTask\r
-ToolChainSetup     = org.tianocore.build.toolchain.ToolChainTask\r
-Expand             = org.tianocore.build.ExpandTask\r
-OutputDirSetup     = org.tianocore.build.OutputDirSetupTask\r
+FrameworkBuild     = org.tianocore.build.FrameworkBuildTask\r
 OnDependency       = org.tianocore.build.global.OnDependency\r
 OnDependency       = org.tianocore.build.global.OnDependency\r
+ToolChainSetup     = org.tianocore.build.toolchain.ToolChainTask\r
+OutputDirSetup     = org.tianocore.build.OutputDirSetup\r
 sourcefiles        = org.tianocore.build.global.DpFileList\r
 targetfiles        = org.tianocore.build.global.DpFileList\r
 file               = org.tianocore.build.global.DpFile\r
 sourcefiles        = org.tianocore.build.global.DpFileList\r
 targetfiles        = org.tianocore.build.global.DpFileList\r
 file               = org.tianocore.build.global.DpFile\r
+DefaultBuildFileGenerator = org.tianocore.build.tools.DefaultBuildFileGenerator\r
index e615802c009c5beed8610fdab7a82e79db26f85b..e0a0fff2d528efb5319151d5925047b47f521df9 100644 (file)
@@ -64,6 +64,7 @@ public class FileProcess {
                                           {".s", "", "ASM" },\r
                                           {".uni", "", "UNI" },\r
                                           {".vfr", "", "VFR" },\r
                                           {".s", "", "ASM" },\r
                                           {".uni", "", "UNI" },\r
                                           {".vfr", "", "VFR" },\r
+                                          {".Vfr", "", "VFR" },\r
                                           {".dxs", "", "DPX"},\r
                                           {".fv", "", "FV" },\r
                                           {".efi", "", "EFI" },\r
                                           {".dxs", "", "DPX"},\r
                                           {".fv", "", "FV" },\r
                                           {".efi", "", "EFI" },\r
index 0e807f8abbe07fc6c3bcc9671f24186413858bcd..9eb509bca3bfe97df3ec3278647c617e1a0e255e 100644 (file)
@@ -32,8 +32,9 @@ import org.apache.tools.ant.taskdefs.Ant;
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.build.autogen.AutoGen;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
+import org.tianocore.build.global.GenBuildLogger;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
@@ -42,6 +43,8 @@ import org.tianocore.build.id.ModuleIdentification;
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.tools.ModuleItem;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.tools.ModuleItem;\r
+import org.tianocore.exception.EdkException;\r
+import org.tianocore.logger.EdkLog;\r
 \r
 /**\r
   <p>\r
 \r
 /**\r
   <p>\r
@@ -115,7 +118,14 @@ public class GenBuildTask extends Ant {
               From module build, exception from module surface area invalid.\r
     **/\r
     public void execute() throws BuildException {\r
               From module build, exception from module surface area invalid.\r
     **/\r
     public void execute() throws BuildException {\r
-        try{\r
+       //\r
+        // set Logger\r
+        //\r
+        GenBuildLogger logger = new GenBuildLogger(getProject());\r
+        EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));\r
+        EdkLog.setLogger(logger);\r
+        // remove !!\r
+        try {\r
         pushProperties();\r
         //\r
         // Enable all specified properties\r
         pushProperties();\r
         //\r
         // Enable all specified properties\r
@@ -524,8 +534,9 @@ public class GenBuildTask extends Ant {
         //\r
         // AutoGen\r
         //\r
         //\r
         // AutoGen\r
         //\r
-//        AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId);\r
-//        autogen.genAutogen();\r
+        \r
+        AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());\r
+        autogen.genAutogen();\r
         \r
         \r
         //\r
         \r
         \r
         //\r
index 95875544b3592f9d5bb598dd771c5020fcc417b2..7de80e6c72ea4d1ed98727b6af70b2ebe7ccc73e 100644 (file)
@@ -26,8 +26,9 @@ import org.tianocore.GuidsDocument;
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.ProtocolsDocument;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.ProtocolsDocument;\r
-//import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
+import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
 import org.tianocore.build.exception.*;\r
 import org.tianocore.build.exception.*;\r
+import org.tianocore.logger.EdkLog;\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
@@ -37,6 +38,7 @@ import java.io.FileWriter;
 import java.util.ArrayList;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
 import java.util.ArrayList;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
+import java.util.LinkedList;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
@@ -46,1053 +48,968 @@ import java.util.Set;
  * area or library surface area.\r
  */\r
 public class AutoGen {\r
  * area or library surface area.\r
  */\r
 public class AutoGen {\r
-    // /\r
-    // / The output path of Autogen.h and Autogen.c\r
-    // /\r
-    private String outputPath;\r
-\r
-    // /\r
-    // / The base name of module or library.\r
-    // /\r
-    private ModuleIdentification moduleId;\r
-\r
-    // /\r
-    // / The build architecture\r
-    // /\r
-    private String arch;\r
-\r
-    // /\r
-    // / PcdAutogen instance which is used to manage how to generate the PCD\r
-    // / information.\r
-    // /\r
-//    private PCDAutoGenAction myPcdAutogen;\r
-\r
-    // /\r
-    // / The protocl list which records in module or library surface area and\r
-    // / it's dependence on library instance surface area.\r
-    // /\r
-    private Set<String> mProtocolList = new HashSet<String>();\r
-\r
-    // /\r
-    // / The Ppi list which recorded in module or library surface area and its\r
-    // / dependency on library instance surface area.\r
-    // /\r
-    private Set<String> mPpiList = new HashSet<String>();\r
-\r
-    // /\r
-    // / The Guid list which recoreded in module or library surface are and it's\r
-    // / dependence on library instance surface area.\r
-    // /\r
-    private Set<String> mGuidList = new HashSet<String>();\r
-\r
-    /**\r
-     * Construct function\r
-     * \r
-     * This function mainly initialize some member variable.\r
-     * \r
-     * @param outputPath\r
-     *            Output path of AutoGen file.\r
-     * @param baseName\r
-     *            Module base name.\r
-     * @param arch\r
-     *            Target architecture.\r
-     */\r
-    public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
-        this.outputPath = outputPath;\r
-        this.moduleId = moduleId;\r
-        this.arch = arch;\r
-\r
-    }\r
-\r
-    /**\r
-     * saveFile function\r
-     * \r
-     * This function save the content in stringBuffer to file.\r
-     * \r
-     * @param fileName\r
-     *            The name of file.\r
-     * @param fileBuffer\r
-     *            The content of AutoGen file in buffer.\r
-     * @return "true" successful, "false" failed.\r
-     */\r
-    private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
-        try {\r
-            File autoGenH = new File(fileName);\r
-\r
-            //\r
-            // if the file exists, compare their content\r
-            //\r
-            if (autoGenH.exists()) {\r
-                FileReader fIn = new FileReader(autoGenH);\r
-                char[] oldFileBuffer = new char[(int) autoGenH.length()];\r
-                fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r
-                fIn.close();\r
-\r
-                //\r
-                // if we got the same file, don't re-generate it to prevent\r
-                // sources depending on it from re-building\r
-                //\r
-                if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r
-                    return true;\r
-                }\r
-            }\r
-            FileWriter fOut = new FileWriter(autoGenH);\r
-            fOut.write(fileBuffer.toString());\r
-            fOut.close();\r
-        } catch (Exception e) {\r
-            return false;\r
-        }\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     * genAutogen function\r
-     * \r
-     * This function call libGenAutoGen or moduleGenAutogen function, which\r
-     * dependence on generate library autogen or module autogen.\r
-     * \r
-     * @throws BuildException\r
-     *             Failed to creat AutoGen.c & AutoGen.h.\r
-     */\r
-    public void genAutogen() throws BuildException {\r
-        try {\r
-            //\r
-            // If outputPath do not exist, create it.\r
-            //\r
-            File path = new File(outputPath);\r
-            path.mkdirs();\r
-\r
-            //\r
-            // Check current is library or not, then call the corresponding\r
-            // function.\r
-            //\r
-            if (this.moduleId.isLibrary()) {\r
-                libGenAutogen();\r
-            } else {\r
-                moduleGenAutogen();\r
-            }\r
-\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                    "Failed to create AutoGen.c & AutoGen.h!\n"\r
-                            + e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-     * moduleGenAutogen function\r
-     * \r
-     * This function generates AutoGen.c & AutoGen.h for module.\r
-     * \r
-     * @throws BuildException\r
-     *             Faile to create module AutoGen.c & AutoGen.h.\r
-     */\r
-    void moduleGenAutogen() throws BuildException {\r
-\r
-        try {\r
-            moduleGenAutogenC();\r
-            moduleGenAutogenH();\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                    "Faile to create module AutoGen.c & AutoGen.h!\n"\r
-                            + e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-     * libGenAutogen function\r
-     * \r
-     * This function generates AutoGen.c & AutoGen.h for library.\r
-     * \r
-     * @throws BuildException\r
-     *             Faile to create library AutoGen.c & AutoGen.h\r
-     */\r
-    void libGenAutogen() throws BuildException {\r
-        try {\r
-            libGenAutogenC();\r
-            libGenAutogenH();\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                    "Faile to create library AutoGen.c & AutoGen.h!\n"\r
-                            + e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-     * moduleGenAutogenH\r
-     * \r
-     * This function generates AutoGen.h for module.\r
-     * \r
-     * @throws BuildException\r
-     *             Failed to generate AutoGen.h.\r
-     */\r
-    void moduleGenAutogenH() throws AutoGenException {\r
-\r
-        Set<String> libClassIncludeH;\r
-        String moduleType;\r
-        // List<String> headerFileList;\r
-        Set<String> headerFileList;\r
-        Iterator item;\r
-        StringBuffer fileBuffer = new StringBuffer(8192);\r
-\r
-        //\r
-        // Write Autogen.h header notation\r
-        //\r
-        fileBuffer.append(CommonDefinition.autogenHNotation);\r
-\r
-        //\r
-        // Add #ifndef ${BaseName}_AUTOGENH\r
-        // #def ${BseeName}_AUTOGENH\r
-        //\r
-        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
-                + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
-                + "_AUTOGENH\r\n\r\n");\r
-\r
-        //\r
-        // Write the specification version and release version at the begine\r
-        // of autogen.h file.\r
-        // Note: the specification version and release version should\r
-        // be got from module surface area instead of hard code by it's\r
-        // moduleType.\r
-        //\r
-        moduleType = SurfaceAreaQuery.getModuleType();\r
-        switch (CommonDefinition.getModuleType(moduleType)) {\r
-        case CommonDefinition.ModuleTypeDxeCore:\r
-        case CommonDefinition.ModuleTypeDxeDriver:\r
-        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-        case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-        case CommonDefinition.ModuleTypeDxeSalDriver:\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-            break;\r
-        default:\r
-            fileBuffer.append(CommonDefinition.autoGenHVersionDefault);\r
-            break;\r
-        }\r
-        switch (CommonDefinition.getModuleType(moduleType)) {\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            fileBuffer.append(CommonDefinition.autoGenHReleaseDefault);\r
-            break;\r
-        default:\r
-            fileBuffer.append(CommonDefinition.autoGenHLine2);\r
-            break;\r
-        }\r
-\r
-        //\r
-        // Add "extern int __make_me_compile_correctly;" at begin of\r
-        // AutoGen.h.\r
-        //\r
-        fileBuffer.append(CommonDefinition.autoGenHbegin);\r
-\r
-        //\r
-        // Write consumed package's mdouleInfo related .h file to autogen.h\r
-        //\r
-//        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-//                .getDependencePkg(this.arch);\r
-        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery.getDependencePkg(null);\r
-        if (consumedPkgIdList != null) {\r
-            headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
-            item = headerFileList.iterator();\r
-            while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-            }\r
-        }\r
-\r
-        //\r
-        // Write library class's related *.h file to autogen.h.\r
-        //\r
-        String[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
-        if (libClassList != null) {\r
-            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            item = libClassIncludeH.iterator();\r
-            while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-            }\r
-        }\r
-\r
-        libClassList = SurfaceAreaQuery\r
-                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
-        if (libClassList != null) {\r
-            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            item = libClassIncludeH.iterator();\r
-            while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-            }\r
-        }\r
-        fileBuffer.append("\r\n");\r
-\r
-        //\r
-        // Write PCD autogen information to AutoGen.h.\r
-        //\r
-//        if (this.myPcdAutogen != null) {\r
-//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-//        }\r
-\r
-        //\r
-        // Append the #endif at AutoGen.h\r
-        //\r
-        fileBuffer.append("#endif\r\n");\r
-\r
-        //\r
-        // Save string buffer content in AutoGen.h.\r
-        //\r
-        if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.h !!!");\r
-        }\r
-    }\r
-\r
-    /**\r
-     * moduleGenAutogenC\r
-     * \r
-     * This function generates AutoGen.c for module.\r
-     * \r
-     * @throws BuildException\r
-     *             Failed to generate AutoGen.c.\r
-     */\r
-    void moduleGenAutogenC() throws AutoGenException {\r
-\r
-        StringBuffer fileBuffer = new StringBuffer(8192);\r
-        //\r
-        // Write Autogen.c header notation\r
-        //\r
-        fileBuffer.append(CommonDefinition.autogenCNotation);\r
-\r
-        //\r
-        // Write #include <AutoGen.h> at beginning of AutoGen.c\r
-        //\r
-        fileBuffer.append(CommonDefinition.includeAutogenH);\r
-\r
-        //\r
-        // Get the native MSA file infomation. Since before call autogen, \r
-        // the MSA native <Externs> information were overrided. So before \r
-        // process <Externs> it should be set the DOC as the Native MSA info.\r
-        //\r
-        Map<String, XmlObject> doc  = GlobalData.getNativeMsa(this.moduleId);\r
-        SurfaceAreaQuery.push(doc);\r
-        //\r
-        // Write <Extern> DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
-        // to AutoGen.c\r
-        //\r
-        \r
-        ExternsDriverBindingToAutoGenC(fileBuffer);\r
-\r
-        //\r
-        // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r
-        // to Autogen.c\r
-        //\r
-        ExternCallBackToAutoGenC(fileBuffer);\r
-\r
-        //\r
-        // Write EntryPoint to autgoGen.c\r
-        //\r
-        String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();\r
-        if (entryPointList != null) {\r
-            EntryPointToAutoGen(entryPointList, fileBuffer);\r
-        }\r
-\r
-        //\r
-        // Restore the DOC which include the FPD module info. \r
-        //\r
-        SurfaceAreaQuery.pop();\r
-        \r
-        //\r
-        // Write Guid to autogen.c\r
+       // /\r
+       // / The output path of Autogen.h and Autogen.c\r
+       // /\r
+       private String outputPath;\r
+\r
+       // /\r
+       // / The base name of module or library.\r
+       // /\r
+       private ModuleIdentification moduleId;\r
+\r
+       // /\r
+       // / The build architecture\r
+       // /\r
+       private String arch;\r
+\r
+       // /\r
+       // / PcdAutogen instance which is used to manage how to generate the PCD\r
+       // / information.\r
+       // /\r
+       private PCDAutoGenAction myPcdAutogen;\r
+\r
+       // /\r
+       // / The protocl list which records in module or library surface area and\r
+       // / it's dependence on library instance surface area.\r
+       // /\r
+       private Set<String> mProtocolList = new HashSet<String>();\r
+\r
+       // /\r
+       // / The Ppi list which recorded in module or library surface area and its\r
+       // / dependency on library instance surface area.\r
+       // /\r
+       private Set<String> mPpiList = new HashSet<String>();\r
+\r
+       // /\r
+       // / The Guid list which recoreded in module or library surface area and it's\r
+       // / dependence on library instance surface area.\r
+       // /\r
+       private Set<String> mGuidList = new HashSet<String>();\r
+    \r
+    //\r
+    // The dependence package list which recoreded in module or library surface\r
+    // area and it's dependence on library instance surface are.\r
+    //\r
+    private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();\r
+       /**\r
+        * Construct function\r
+        * \r
+        * This function mainly initialize some member variable.\r
+        * \r
+        * @param outputPath\r
+        *            Output path of AutoGen file.\r
+        * @param baseName\r
+        *            Module base name.\r
+        * @param arch\r
+        *            Target architecture.\r
+        */\r
+       public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
+               this.outputPath = outputPath;\r
+               this.moduleId = moduleId;\r
+               this.arch = arch;\r
+\r
+       }\r
+\r
+       /**\r
+        * saveFile function\r
+        * \r
+        * This function save the content in stringBuffer to file.\r
+        * \r
+        * @param fileName\r
+        *            The name of file.\r
+        * @param fileBuffer\r
+        *            The content of AutoGen file in buffer.\r
+        * @return "true" successful, "false" failed.\r
+        */\r
+       private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
+               try {\r
+                       File autoGenH = new File(fileName);\r
+\r
+                       //\r
+                       // if the file exists, compare their content\r
+                       //\r
+                       if (autoGenH.exists()) {\r
+                               FileReader fIn = new FileReader(autoGenH);\r
+                               char[] oldFileBuffer = new char[(int) autoGenH.length()];\r
+                               fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r
+                               fIn.close();\r
+\r
+                               //\r
+                               // if we got the same file, don't re-generate it to prevent\r
+                               // sources depending on it from re-building\r
+                               //\r
+                               if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r
+                                       return true;\r
+                               }\r
+                       }\r
+                       FileWriter fOut = new FileWriter(autoGenH);\r
+                       fOut.write(fileBuffer.toString());\r
+                       fOut.close();\r
+               } catch (Exception e) {\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * genAutogen function\r
+        * \r
+        * This function call libGenAutoGen or moduleGenAutogen function, which\r
+        * dependence on generate library autogen or module autogen.\r
+        * \r
+        * @throws BuildException\r
+        *             Failed to creat AutoGen.c & AutoGen.h.\r
+        */\r
+       public void genAutogen() throws BuildException {\r
+               try {\r
+                       //\r
+                       // If outputPath do not exist, create it.\r
+                       //\r
+                       File path = new File(outputPath);\r
+                       path.mkdirs();\r
+\r
+                       //\r
+                       // Check current is library or not, then call the corresponding\r
+                       // function.\r
+                       //\r
+                       if (this.moduleId.isLibrary()) {\r
+                               libGenAutogen();\r
+                       } else {\r
+                               moduleGenAutogen();\r
+                       }\r
+\r
+               } catch (Exception e) {\r
+                       throw new BuildException(\r
+                                       "Failed to create AutoGen.c & AutoGen.h!\n"\r
+                                                       + e.getMessage());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * moduleGenAutogen function\r
+        * \r
+        * This function generates AutoGen.c & AutoGen.h for module.\r
+        * \r
+        * @throws BuildException\r
+        *             Faile to create module AutoGen.c & AutoGen.h.\r
+        */\r
+       void moduleGenAutogen() throws BuildException {\r
+\r
+               try {\r
+                       moduleGenAutogenC();\r
+                       moduleGenAutogenH();\r
+               } catch (Exception e) {\r
+                       throw new BuildException(\r
+                                       "Faile to create module AutoGen.c & AutoGen.h!\n"\r
+                                                       + e.getMessage());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * libGenAutogen function\r
+        * \r
+        * This function generates AutoGen.c & AutoGen.h for library.\r
+        * \r
+        * @throws BuildException\r
+        *             Faile to create library AutoGen.c & AutoGen.h\r
+        */\r
+       void libGenAutogen() throws BuildException {\r
+               try {\r
+                       libGenAutogenC();\r
+                       libGenAutogenH();\r
+               } catch (Exception e) {\r
+                       throw new BuildException(\r
+                                       "Faile to create library AutoGen.c & AutoGen.h!\n"\r
+                                                       + e.getMessage());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * moduleGenAutogenH\r
+        * \r
+        * This function generates AutoGen.h for module.\r
+        * \r
+        * @throws BuildException\r
+        *             Failed to generate AutoGen.h.\r
+        */\r
+       void moduleGenAutogenH() throws AutoGenException {\r
+\r
+               Set<String> libClassIncludeH;\r
+               String moduleType;\r
+               // List<String> headerFileList;\r
+               List<String> headerFileList;\r
+               Iterator item;\r
+               StringBuffer fileBuffer = new StringBuffer(8192);\r
+\r
+               //\r
+               // Write Autogen.h header notation\r
+               //\r
+               fileBuffer.append(CommonDefinition.autogenHNotation);\r
+\r
+               //\r
+               // Add #ifndef ${BaseName}_AUTOGENH\r
+               // #def ${BseeName}_AUTOGENH\r
+               //\r
+               fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                               + "_AUTOGENH\r\n");\r
+               fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                               + "_AUTOGENH\r\n\r\n");\r
+\r
+               //\r
+               // Write the specification version and release version at the begine\r
+               // of autogen.h file.\r
+               // Note: the specification version and release version should\r
+               // be got from module surface area instead of hard code by it's\r
+               // moduleType.\r
+               //\r
+               moduleType = SurfaceAreaQuery.getModuleType();\r
+//             switch (CommonDefinition.getModuleType(moduleType)) {\r
+//             case CommonDefinition.ModuleTypeDxeCore:\r
+//             case CommonDefinition.ModuleTypeDxeDriver:\r
+//             case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+//             case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+//             case CommonDefinition.ModuleTypeDxeSalDriver:\r
+//             case CommonDefinition.ModuleTypeUefiDriver:\r
+//             case CommonDefinition.ModuleTypeUefiApplication:\r
+//                     fileBuffer.append(CommonDefinition.autoGenHLine1);\r
+//                     break;\r
+//             default:\r
+//                     fileBuffer.append(CommonDefinition.autoGenHVersionDefault);\r
+//                     break;\r
+//             }\r
+//             switch (CommonDefinition.getModuleType(moduleType)) {\r
+//             case CommonDefinition.ModuleTypeUefiDriver:\r
+//             case CommonDefinition.ModuleTypeUefiApplication:\r
+//                     fileBuffer.append(CommonDefinition.autoGenHReleaseDefault);\r
+//                     break;\r
+//             default:\r
+//                     fileBuffer.append(CommonDefinition.autoGenHLine2);\r
+//                     break;\r
+//             }\r
+\r
+               //\r
+               // Add "extern int __make_me_compile_correctly;" at begin of\r
+               // AutoGen.h.\r
+               //\r
+               fileBuffer.append(CommonDefinition.autoGenHbegin);\r
+\r
+        //\r
+        // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.\r
         //\r
         //\r
-        String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery.getModuleGuid());\r
-        \r
-        fileBuffer\r
-                .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
-        if (guid == null) {\r
-            throw new AutoGenException("Guid value must set!\n");\r
-        }\r
-\r
-        //\r
-        // Formate Guid as ANSI c form.Example:\r
-        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
-        // 0xf0}}\r
-        //\r
-\r
-        fileBuffer.append(guid);\r
-        fileBuffer.append("};\r\n");\r
-\r
-        //\r
-        // Generate library instance consumed protocol, guid, ppi, pcd list.\r
-        // Save those to this.protocolList, this.ppiList, this.pcdList,\r
-        // this.guidList. Write Consumed library constructor and desconstuct to\r
-        // autogen.c\r
-        //\r
-        LibInstanceToAutogenC(fileBuffer);\r
-\r
-        //\r
-        // Write consumed ppi, guid, protocol to autogen.c\r
-        //\r
-        ProtocolGuidToAutogenC(fileBuffer);\r
-        PpiGuidToAutogenC(fileBuffer);\r
-        GuidGuidToAutogenC(fileBuffer);\r
-\r
-        //\r
-        // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
-        // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
-        // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction.\r
-        // Note : when PCD image tool ready,\r
-        // isPCDEmulatedDriver parameter will be removed.\r
-        //\r
-//        try {\r
-//            this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),\r
-//                    moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
-//            this.myPcdAutogen.execute();\r
-//        } catch (Exception e) {\r
-//            throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
-//        }\r
-//\r
-//        if (this.myPcdAutogen != null) {\r
-//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-//        }\r
-\r
-        if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.c !!!");\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * libGenAutogenH\r
-     * \r
-     * This function generates AutoGen.h for library.\r
-     * \r
-     * @throws BuildException\r
-     *             Failed to generate AutoGen.c.\r
-     */\r
-    void libGenAutogenH() throws AutoGenException {\r
-\r
-        Set<String> libClassIncludeH;\r
-        String moduleType;\r
-        Set<String> headerFileList;\r
-        Iterator item;\r
-        StringBuffer fileBuffer = new StringBuffer(10240);\r
-\r
-        //\r
-        // Write Autogen.h header notation\r
-        //\r
-        fileBuffer.append(CommonDefinition.autogenHNotation);\r
-\r
-        //\r
-        // Add #ifndef ${BaseName}_AUTOGENH\r
-        // #def ${BseeName}_AUTOGENH\r
-        //\r
-        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
-                + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
-                + "_AUTOGENH\r\n\r\n");\r
-\r
-        //\r
-        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
-        // to autogen.h file.\r
-        // Note: the specification version and release version should\r
-        // be get from module surface area instead of hard code.\r
-        //\r
-        fileBuffer.append(CommonDefinition.autoGenHbegin);\r
         String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
         String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
-        for (int i = 0; i < specList.length; i++){\r
-            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i] + "\r\n");\r
-        }\r
-//        fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-//        fileBuffer.append(CommonDefinition.autoGenHLine2);\r
-\r
-        //\r
-        // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
-        // \r
-        moduleType = SurfaceAreaQuery.getModuleType();\r
-        PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
-                .getDependencePkg(this.arch);\r
-        headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
-        item = headerFileList.iterator();\r
-        while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-        }\r
-        //\r
-        // Write library class's related *.h file to autogen.h\r
-        //\r
-        String[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
-        if (libClassList != null) {\r
-            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            item = libClassIncludeH.iterator();\r
-            while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-            }\r
-        }\r
-\r
-        libClassList = SurfaceAreaQuery\r
-                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
-        if (libClassList != null) {\r
-            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            item = libClassIncludeH.iterator();\r
-            while (item.hasNext()){\r
-               fileBuffer.append(item.next().toString());\r
-            }\r
-        }\r
-        fileBuffer.append("\r\n");\r
-\r
-        //\r
-        // Write PCD information to library AutoGen.h.\r
-        //\r
-//        if (this.myPcdAutogen != null) {\r
-//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-//        }\r
-\r
-        //\r
-        // Append the #endif at AutoGen.h\r
-        //\r
-        fileBuffer.append("#endif\r\n");\r
-\r
-        //\r
-        // Save content of string buffer to AutoGen.h file.\r
-        //\r
-        if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.h !!!");\r
-        }\r
-    }\r
-\r
-    /**\r
-     * libGenAutogenC\r
-     * \r
-     * This function generates AutoGen.h for library.\r
-     * \r
-     * @throws BuildException\r
-     *             Failed to generate AutoGen.c.\r
-     */\r
-    void libGenAutogenC() throws BuildException {\r
-        StringBuffer fileBuffer = new StringBuffer(10240);\r
-\r
-        //\r
-        // Write Autogen.c header notation\r
-        //\r
-        fileBuffer.append(CommonDefinition.autogenCNotation);\r
-\r
-        fileBuffer.append(CommonDefinition.autoGenCLine1);\r
-        fileBuffer.append("\r\n");\r
-\r
-        //\r
-        // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
-        // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
-        // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction.\r
-        // Note : when PCD image tool ready,\r
-        // isPCDEmulatedDriver parameter will be removed.\r
-        //\r
-        try {\r
-//            this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
-//                    this.moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
-//            this.myPcdAutogen.execute();\r
-//             this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,);\r
-        } catch (Exception e) {\r
-            throw new BuildException(e.getMessage());\r
-        }\r
-\r
-//        if (this.myPcdAutogen != null) {\r
-//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-//        }\r
-\r
-        if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.c !!!");\r
-        }\r
-    }\r
-\r
-    /**\r
-     * LibraryClassToAutogenH\r
-     * \r
-     * This function returns *.h files declared by library classes which are\r
-     * consumed or produced by current build module or library.\r
-     * \r
-     * @param libClassList\r
-     *            List of library class which consumed or produce by current\r
-     *            build module or library.\r
-     * @return includeStrList List of *.h file.\r
-     */\r
-    Set<String> LibraryClassToAutogenH(String[] libClassList) throws AutoGenException{\r
-        Set<String> includStrList = new HashSet<String>();\r
-        String includerName[];\r
-        String str = "";\r
-\r
-        //\r
-        // Get include file from GlobalData's SPDTable according to\r
-        // library class name.\r
-        //\r
-\r
-        for (int i = 0; i < libClassList.length; i++) {\r
-            includerName = GlobalData.getLibraryClassHeaderFiles(\r
-                    SurfaceAreaQuery.getDependencePkg(this.arch),\r
-                    libClassList[i]);\r
-            if (includerName == null){\r
-                throw new AutoGenException("Can not find library class [" + libClassList[i] + "] declaration in every packages. ");\r
-            }\r
-            for (int j = 0; j < includerName.length; j++) {\r
-                String includeNameStr = includerName[j];\r
-                if (includeNameStr != null) {\r
-                    str = CommonDefinition.include + " " + "<";\r
-                    str = str + includeNameStr + ">\r\n";\r
-                    includStrList.add(str);\r
-                    includeNameStr = null;\r
-                }\r
-            }\r
-        }\r
-        return includStrList;\r
-    }\r
-\r
-    /**\r
-     * IncludesToAutogenH\r
-     * \r
-     * This function add include file in AutoGen.h file.\r
-     * \r
-     * @param packageNameList\r
-     *            List of module depended package.\r
-     * @param moduleType\r
-     *            Module type.\r
-     * @return\r
-     */\r
-    Set<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
-            String moduleType) throws AutoGenException{\r
-\r
-        Set<String> includeStrList = new HashSet<String>();\r
-        String pkgHeader;\r
-        String includeStr = "";\r
-\r
-        //\r
-        // Get include file from moduleInfo file\r
-        //\r
-        for (int i = 0; i < packageNameList.length; i++){\r
-//             pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i], moduleType);\r
-//            if (pkgHeader == null){\r
-//             throw new AutoGenException("Can not find package [" + packageNameList[i] + "] declaration in every packages. ");\r
-//            }else if (!pkgHeader.equalsIgnoreCase("")){\r
-//             includeStr = CommonDefinition.include + "<" + pkgHeader + ">\r\n";\r
-//                includeStrList.add(includeStr);\r
-//            }\r
+        for (int i = 0; i < specList.length; i++) {\r
+            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
+                    + "\r\n");\r
         }\r
         }\r
+               //\r
+               // Write consumed package's mdouleInfo related .h file to autogen.h\r
+               //\r
+               // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+               // .getDependencePkg(this.arch);\r
+               PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+                               .getDependencePkg(null);\r
+               if (consumedPkgIdList != null) {\r
+                       headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
+                       item = headerFileList.iterator();\r
+                       while (item.hasNext()) {\r
+                               fileBuffer.append(item.next().toString());\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Write library class's related *.h file to autogen.h.\r
+               //\r
+               String[] libClassList = SurfaceAreaQuery\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+               if (libClassList != null) {\r
+                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+                       item = libClassIncludeH.iterator();\r
+                       while (item.hasNext()) {\r
+                               fileBuffer.append(item.next().toString());\r
+                       }\r
+               }\r
+\r
+               libClassList = SurfaceAreaQuery\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+               if (libClassList != null) {\r
+                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+                       item = libClassIncludeH.iterator();\r
+                       while (item.hasNext()) {\r
+                               fileBuffer.append(item.next().toString());\r
+                       }\r
+               }\r
+               fileBuffer.append("\r\n");\r
+\r
+               //\r
+               // Write PCD autogen information to AutoGen.h.\r
+               //\r
+               if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+                       fileBuffer.append(this.myPcdAutogen.OutputH());\r
+               }\r
+\r
+               //\r
+               // Append the #endif at AutoGen.h\r
+               //\r
+               fileBuffer.append("#endif\r\n");\r
+\r
+               //\r
+               // Save string buffer content in AutoGen.h.\r
+               //\r
+               if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
+                       throw new BuildException("Failed to generate AutoGen.h !!!");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * moduleGenAutogenC\r
+        * \r
+        * This function generates AutoGen.c for module.\r
+        * \r
+        * @throws BuildException\r
+        *             Failed to generate AutoGen.c.\r
+        */\r
+       void moduleGenAutogenC() throws AutoGenException {\r
+\r
+               StringBuffer fileBuffer = new StringBuffer(8192);\r
+               //\r
+               // Write Autogen.c header notation\r
+               //\r
+               fileBuffer.append(CommonDefinition.autogenCNotation);\r
+\r
+               //\r
+               // Write #include <AutoGen.h> at beginning of AutoGen.c\r
+               //\r
+               fileBuffer.append(CommonDefinition.includeAutogenH);\r
+\r
+               //\r
+               // Get the native MSA file infomation. Since before call autogen,\r
+               // the MSA native <Externs> information were overrided. So before\r
+               // process <Externs> it should be set the DOC as the Native MSA info.\r
+               //\r
+               Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);\r
+               SurfaceAreaQuery.push(doc);\r
+               //\r
+               // Write <Extern>\r
+               // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
+               // to AutoGen.c\r
+               //\r
+\r
+               ExternsDriverBindingToAutoGenC(fileBuffer);\r
+\r
+               //\r
+               // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r
+               // to Autogen.c\r
+               //\r
+               ExternCallBackToAutoGenC(fileBuffer);\r
+\r
+               //\r
+               // Write EntryPoint to autgoGen.c\r
+               //\r
+               String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();\r
+               EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer);\r
+\r
+\r
+               //\r
+               // Restore the DOC which include the FPD module info.\r
+               //\r
+               SurfaceAreaQuery.pop();\r
+\r
+               //\r
+               // Write Guid to autogen.c\r
+               //\r
+               String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery\r
+                               .getModuleGuid());\r
+\r
+               fileBuffer\r
+                               .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
+               if (guid == null) {\r
+                       throw new AutoGenException("Guid value must set!\n");\r
+               }\r
+\r
+               //\r
+               // Formate Guid as ANSI c form.Example:\r
+               // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
+               // 0xf0}}\r
+               //\r
+\r
+               fileBuffer.append(guid);\r
+               fileBuffer.append("};\r\n");\r
+\r
+               //\r
+               // Generate library instance consumed protocol, guid, ppi, pcd list.\r
+               // Save those to this.protocolList, this.ppiList, this.pcdList,\r
+               // this.guidList. Write Consumed library constructor and desconstuct to\r
+               // autogen.c\r
+               //\r
+        LibInstanceToAutogenC(fileBuffer);\r
         \r
         \r
-        return includeStrList;\r
-    }\r
-\r
-    /**\r
-     * EntryPointToAutoGen\r
-     * \r
-     * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
-     * information in mas to AutoGen.c\r
-     * \r
-     * @param entryPointList\r
-     *            List of entry point.\r
-     * @param fileBuffer\r
-     *            String buffer fo AutoGen.c.\r
-     * @throws Exception\r
-     */\r
-    void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
-            throws BuildException {\r
-\r
-        String typeStr = SurfaceAreaQuery.getModuleType();\r
-\r
         //\r
         //\r
-        // The parameters and return value of entryPoint is difference\r
-        // for difference module type.\r
+        // Get module dependent Package identification.\r
         //\r
         //\r
-        switch (CommonDefinition.getModuleType(typeStr)) {\r
-\r
-        case CommonDefinition.ModuleTypePeiCore:\r
-            if (entryPointList.length != 1 || entryPointList[0].equals("")) {\r
-                throw new BuildException(\r
-                        "Module type = 'PEI_CORE', only have one module entry point!");\r
-            } else {\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer\r
-                        .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
-                fileBuffer\r
-                        .append("  IN VOID                        *OldCoreData\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
-\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-                fileBuffer\r
-                        .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
-                fileBuffer\r
-                        .append("  IN VOID                        *OldCoreData\r\n");\r
-                fileBuffer.append("  )\r\n\r\n");\r
-                fileBuffer.append("{\r\n");\r
-                fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
-                fileBuffer.append("}\r\n\r\n");\r
+        PackageIdentification[] packages = SurfaceAreaQuery.getDependencePkg(this.arch);\r
+        for (int i = 0; i < packages.length; i++){\r
+            if (!this.mDepPkgList.contains(packages[i])){\r
+                this.mDepPkgList.add(packages[i]);\r
             }\r
             }\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypeDxeCore:\r
-            fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
-            if (entryPointList.length != 1 || entryPointList[0].equals("")) {\r
-                throw new BuildException(\r
-                        "Module type = 'DXE_CORE', only have one module entry point!");\r
-            } else {\r
-\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (\n");\r
-                fileBuffer.append("  IN VOID  *HobStart\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
-\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-                fileBuffer.append("  IN VOID  *HobStart\r\n");\r
-                fileBuffer.append("  )\r\n\r\n");\r
-                fileBuffer.append("{\r\n");\r
-                fileBuffer.append("  ");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (HobStart);\r\n");\r
-                fileBuffer.append("}\r\n\r\n");\r
-            }\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypePeim:\r
-            int entryPointCount = 0;\r
-            fileBuffer\r
-                    .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
-            for (int i = 0; i < entryPointList.length; i++) {\r
-                if (!entryPointList[i].equals("")) {\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(entryPointList[i]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer\r
-                            .append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
-                    fileBuffer\r
-                            .append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
-                } else {\r
-                    break;\r
-                }\r
-            }\r
-\r
-            fileBuffer.append("EFI_STATUS\r\n");\r
-            fileBuffer.append("EFIAPI\r\n");\r
-            fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-            fileBuffer.append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
-            fileBuffer.append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
-            fileBuffer.append("  )\r\n\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            if (entryPointCount == 0) {\r
-                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
-                fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-            } else {\r
-                fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
-                fileBuffer.append("  EFI_STATUS  CombinedStatus;\r\n\r\n");\r
-                fileBuffer.append("  CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("  Status = ");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-                        fileBuffer\r
-                                .append("  if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
-                        fileBuffer.append("    CombinedStatus = Status;\r\n");\r
-                        fileBuffer.append("  }\r\n\r\n");\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-                fileBuffer.append("  return CombinedStatus;\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n\r\n");\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            entryPointCount = 0;\r
-            for (int i = 0; i < entryPointList.length; i++) {\r
-                if (!entryPointList[i].equals("")) {\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(entryPointList[i]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
-                    fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
-                } else {\r
-                    break;\r
-                }\r
-            }\r
-            fileBuffer\r
-                    .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
-            fileBuffer.append(";\r\n");\r
-            fileBuffer\r
-                    .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
-            fileBuffer\r
-                    .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
-\r
-            fileBuffer.append("EFI_STATUS\r\n");\r
-            fileBuffer.append("EFIAPI\r\n");\r
-            fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-            fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
-            fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-            fileBuffer.append("  )\r\n\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            for (int i = 0; i < entryPointList.length; i++) {\r
-                if (!entryPointList[i].equals("")) {\r
-                    fileBuffer\r
-                            .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
-                    fileBuffer.append("    ExitDriver (");\r
-                    fileBuffer.append(entryPointList[i]);\r
-                    fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
-                    fileBuffer.append("    ASSERT (FALSE);\r\n");\r
-                    fileBuffer.append("  }\r\n");\r
-                } else {\r
-                    break;\r
-                }\r
-            }\r
-            fileBuffer.append("  return mDriverEntryPointStatus;\r\n");\r
-            fileBuffer.append("}\r\n\r\n");\r
-\r
-            fileBuffer.append("VOID\r\n");\r
-            fileBuffer.append("EFIAPI\r\n");\r
-            fileBuffer.append("ExitDriver (\r\n");\r
-            fileBuffer.append("  IN EFI_STATUS  Status\n");\r
-            fileBuffer.append("  )\r\n\r\n");\r
-            fileBuffer.append("{\r\n");\r
-            fileBuffer\r
-                    .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
-            fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
-            fileBuffer.append("  }\r\n");\r
-            fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
-            fileBuffer.append("  ASSERT (FALSE);\r\n");\r
-            fileBuffer.append("}\r\n\r\n");\r
-\r
-            //\r
-            // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
-            //\r
-            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
-            entryPointCount = 0;\r
             \r
             \r
-            fileBuffer\r
-                    .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
-            fileBuffer.append(";\r\n\r\n");\r
-\r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("EFI_STATUS\r\n");\r
-                        fileBuffer.append("EFIAPI\r\n");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (\r\n");\r
-                        fileBuffer\r
-                                .append("  EFI_HANDLE        ImageHandle\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-\r
-            fileBuffer.append("EFI_STATUS\r\n");\r
-            fileBuffer.append("EFIAPI\r\n");\r
-            fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
-            fileBuffer.append("  EFI_HANDLE  ImageHandle\r\n");\r
-            fileBuffer.append("  )\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            if (entryPointCount == 0) {\r
-                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
-                fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append("(ImageHandle);\r\n");\r
-            } else {\r
-                fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
-                fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
-                        fileBuffer.append("    ");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append("(ImageHandle);\r\n");\r
-                        fileBuffer.append("  } else {\r\n");\r
-                        fileBuffer.append("    Status = ");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append("(ImageHandle);\r\n");\r
-                        fileBuffer.append("  }\r\n");\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-                fileBuffer.append("  return Status;\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n\r\n");\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-        case CommonDefinition.ModuleTypeDxeDriver:\r
-        case CommonDefinition.ModuleTypeDxeSalDriver:\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            entryPointCount = 0;\r
-            fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
-            for (int i = 0; i < entryPointList.length; i++) {\r
-                if (!entryPointList[i].equals("")) {\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(entryPointList[i]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
-                    fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
-                } else {\r
-                    break;\r
-                }\r
-            }\r
-\r
-            fileBuffer\r
-                    .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
-            fileBuffer.append(";\r\n");\r
-            if (entryPointCount > 1) {\r
-                fileBuffer\r
-                        .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
-                fileBuffer\r
-                        .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
-            }\r
-            fileBuffer.append("\n");\r
-\r
-            fileBuffer.append("EFI_STATUS\r\n");\r
-            fileBuffer.append("EFIAPI\r\n");\r
-            fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-            fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
-            fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-            fileBuffer.append("  )\r\n\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            if (entryPointCount == 0) {\r
-                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
-                fileBuffer.append("  return (");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
-            } else {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer\r
-                                .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
-                        fileBuffer.append("    ExitDriver (");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
-                        fileBuffer.append("    ASSERT (FALSE);\r\n");\r
-                        fileBuffer.append("  }\r\n");\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-                fileBuffer.append("  return mDriverEntryPointStatus;\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n\r\n");\r
-\r
-            fileBuffer.append("VOID\n");\r
-            fileBuffer.append("EFIAPI\n");\r
-            fileBuffer.append("ExitDriver (\r\n");\r
-            fileBuffer.append("  IN EFI_STATUS  Status\n");\r
-            fileBuffer.append("  )\r\n\r\n");\r
-            fileBuffer.append("{\r\n");\r
-            if (entryPointCount <= 1) {\r
-                fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
-                fileBuffer\r
-                        .append("    ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
-                fileBuffer.append("  }\r\n");\r
-                fileBuffer\r
-                        .append("  gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
-            } else {\r
-                fileBuffer\r
-                        .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
-                fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
-                fileBuffer.append("  }\r\n");\r
-                fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
-                fileBuffer.append("  ASSERT (FALSE);\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n\r\n");\r
-\r
-            //\r
-            // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
-            //\r
-            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
-            entryPointCount = 0;\r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("EFI_STATUS\r\n");\r
-                        fileBuffer.append("EFIAPI\r\n");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (\r\n");\r
-                        fileBuffer\r
-                                .append("  EFI_HANDLE        ImageHandle\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                        entryPointCount++;\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-\r
-            fileBuffer\r
-                    .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
-            fileBuffer.append(";\r\n\r\n");\r
-\r
-            if (entryPointList != null) {\r
+        }\r
+      \r
+               //\r
+               // Write consumed ppi, guid, protocol to autogen.c\r
+               //\r
+               ProtocolGuidToAutogenC(fileBuffer);\r
+               PpiGuidToAutogenC(fileBuffer);\r
+               GuidGuidToAutogenC(fileBuffer);\r
+\r
+               //\r
+               // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
+               // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
+               // PCD information has been collected in FPDParser task by\r
+               // CollectPCDAction.\r
+               // Note : when PCD image tool ready,\r
+               // isPCDEmulatedDriver parameter will be removed.\r
+               //\r
+                try {\r
+//              this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),\r
+//              moduleId.getGuid(), moduleId.getPackage().getName(), moduleId.getPackage().getGuid(),this.arch,moduleId.getVersion(),false, null);\r
+         this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),null,null,null, this.arch,null,false, null);\r
+                this.myPcdAutogen.execute();\r
+                } catch (Exception e) {\r
+                throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
+                }\r
+               \r
+               if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+                       fileBuffer.append(this.myPcdAutogen.OutputC());\r
+               }\r
+\r
+               if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
+                       throw new BuildException("Failed to generate AutoGen.c !!!");\r
+               }\r
+\r
+       }\r
+\r
+       /**\r
+        * libGenAutogenH\r
+        * \r
+        * This function generates AutoGen.h for library.\r
+        * \r
+        * @throws BuildException\r
+        *             Failed to generate AutoGen.c.\r
+        */\r
+       void libGenAutogenH() throws AutoGenException {\r
+\r
+               Set<String> libClassIncludeH;\r
+               String moduleType;\r
+               List<String> headerFileList;\r
+               Iterator item;\r
+               StringBuffer fileBuffer = new StringBuffer(10240);\r
+\r
+               //\r
+               // Write Autogen.h header notation\r
+               //\r
+               fileBuffer.append(CommonDefinition.autogenHNotation);\r
+\r
+               //\r
+               // Add #ifndef ${BaseName}_AUTOGENH\r
+               // #def ${BseeName}_AUTOGENH\r
+               //\r
+               fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                               + "_AUTOGENH\r\n");\r
+               fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                               + "_AUTOGENH\r\n\r\n");\r
+\r
+               //\r
+               // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
+               // to autogen.h file.\r
+               // Note: the specification version and release version should\r
+               // be get from module surface area instead of hard code.\r
+               //\r
+               fileBuffer.append(CommonDefinition.autoGenHbegin);\r
+               String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
+               for (int i = 0; i < specList.length; i++) {\r
+                       fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
+                                       + "\r\n");\r
+               }\r
+               // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
+               // fileBuffer.append(CommonDefinition.autoGenHLine2);\r
+\r
+               //\r
+               // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
+               // \r
+               moduleType = SurfaceAreaQuery.getModuleType();\r
+               PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
+                               .getDependencePkg(this.arch);\r
+               headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
+               item = headerFileList.iterator();\r
+               while (item.hasNext()) {\r
+                       fileBuffer.append(item.next().toString());\r
+               }\r
+               //\r
+               // Write library class's related *.h file to autogen.h\r
+               //\r
+               String[] libClassList = SurfaceAreaQuery\r
+                               .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
+               if (libClassList != null) {\r
+                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+                       item = libClassIncludeH.iterator();\r
+                       while (item.hasNext()) {\r
+                               fileBuffer.append(item.next().toString());\r
+                       }\r
+               }\r
+\r
+               libClassList = SurfaceAreaQuery\r
+                               .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
+               if (libClassList != null) {\r
+                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+                       item = libClassIncludeH.iterator();\r
+                       while (item.hasNext()) {\r
+                               fileBuffer.append(item.next().toString());\r
+                       }\r
+               }\r
+               fileBuffer.append("\r\n");\r
+\r
+               //\r
+               // Write PCD information to library AutoGen.h.\r
+               //\r
+               if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+                       fileBuffer.append(this.myPcdAutogen.OutputH());\r
+               }\r
+\r
+               //\r
+               // Append the #endif at AutoGen.h\r
+               //\r
+               fileBuffer.append("#endif\r\n");\r
+\r
+               //\r
+               // Save content of string buffer to AutoGen.h file.\r
+               //\r
+               if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
+                       throw new BuildException("Failed to generate AutoGen.h !!!");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * libGenAutogenC\r
+        * \r
+        * This function generates AutoGen.h for library.\r
+        * \r
+        * @throws BuildException\r
+        *             Failed to generate AutoGen.c.\r
+        */\r
+       void libGenAutogenC() throws BuildException {\r
+               StringBuffer fileBuffer = new StringBuffer(10240);\r
+\r
+               //\r
+               // Write Autogen.c header notation\r
+               //\r
+               fileBuffer.append(CommonDefinition.autogenCNotation);\r
+\r
+               fileBuffer.append(CommonDefinition.autoGenCLine1);\r
+               fileBuffer.append("\r\n");\r
+\r
+               //\r
+               // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
+               // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
+               // PCD information has been collected in FPDParser task by\r
+               // CollectPCDAction.\r
+               // Note : when PCD image tool ready,\r
+               // isPCDEmulatedDriver parameter will be removed.\r
+               //\r
+               try {\r
+//                      this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
+//                      this.moduleId.getGuid(),moduleId.getPackage().getName(),moduleId.getPackage().getGuid(), this.arch, moduleId.getVersion(),true, SurfaceAreaQuery.getModulePcdEntryNameArray());\r
+            this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
+                                                     null,\r
+                                                     null,\r
+                                                     null,\r
+                                                     this.arch,\r
+                                                     null,\r
+                                                     true, \r
+                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
+                     \r
+                       this.myPcdAutogen.execute();\r
+               } catch (Exception e) {\r
+                       throw new BuildException(e.getMessage());\r
+               }\r
+\r
+               if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+                       fileBuffer.append(this.myPcdAutogen.OutputC());\r
+               }\r
+\r
+               if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
+                       throw new BuildException("Failed to generate AutoGen.c !!!");\r
+               }\r
+       }\r
+\r
+       /**\r
+        * LibraryClassToAutogenH\r
+        * \r
+        * This function returns *.h files declared by library classes which are\r
+        * consumed or produced by current build module or library.\r
+        * \r
+        * @param libClassList\r
+        *            List of library class which consumed or produce by current\r
+        *            build module or library.\r
+        * @return includeStrList List of *.h file.\r
+        */\r
+       Set<String> LibraryClassToAutogenH(String[] libClassList)\r
+                       throws AutoGenException {\r
+               Set<String> includStrList = new HashSet<String>();\r
+               String includerName[];\r
+               String str = "";\r
+\r
+               //\r
+               // Get include file from GlobalData's SPDTable according to\r
+               // library class name.\r
+               //\r
+\r
+               for (int i = 0; i < libClassList.length; i++) {\r
+                       includerName = GlobalData.getLibraryClassHeaderFiles(\r
+                                       SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                                       libClassList[i]);\r
+                       if (includerName == null) {\r
+                               throw new AutoGenException("Can not find library class ["\r
+                                               + libClassList[i] + "] declaration in every packages. ");\r
+                       }\r
+                       for (int j = 0; j < includerName.length; j++) {\r
+                               String includeNameStr = includerName[j];\r
+                               if (includeNameStr != null) {\r
+                                       str = CommonDefinition.include + " " + "<";\r
+                                       str = str + includeNameStr + ">\r\n";\r
+                                       includStrList.add(str);\r
+                                       includeNameStr = null;\r
+                               }\r
+                       }\r
+               }\r
+               return includStrList;\r
+       }\r
+\r
+       /**\r
+        * IncludesToAutogenH\r
+        * \r
+        * This function add include file in AutoGen.h file.\r
+        * \r
+        * @param packageNameList\r
+        *            List of module depended package.\r
+        * @param moduleType\r
+        *            Module type.\r
+        * @return\r
+        */\r
+       List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
+                       String moduleType) throws AutoGenException {\r
+\r
+               List<String> includeStrList = new LinkedList<String>();\r
+               String pkgHeader;\r
+               String includeStr = "";\r
+\r
+               //\r
+               // Get include file from moduleInfo file\r
+               //\r
+               for (int i = 0; i < packageNameList.length; i++) {\r
+                       pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r
+                                       moduleType);\r
+                       if (pkgHeader == null) {\r
+                               throw new AutoGenException("Can not find package ["\r
+                                               + packageNameList[i]\r
+                                               + "] declaration in every packages. ");\r
+                       } else if (!pkgHeader.equalsIgnoreCase("")) {\r
+                               includeStr = CommonDefinition.include + " <" + pkgHeader\r
+                                               + ">\r\n";\r
+                               includeStrList.add(includeStr);\r
+                       }\r
+               }\r
+\r
+               return includeStrList;\r
+       }\r
+\r
+       /**\r
+        * EntryPointToAutoGen\r
+        * \r
+        * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
+        * information in mas to AutoGen.c\r
+        * \r
+        * @param entryPointList\r
+        *            List of entry point.\r
+        * @param fileBuffer\r
+        *            String buffer fo AutoGen.c.\r
+        * @throws Exception\r
+        */\r
+       void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
+                       throws BuildException {\r
+\r
+               String typeStr = SurfaceAreaQuery.getModuleType();\r
+\r
+               //\r
+               // The parameters and return value of entryPoint is difference\r
+               // for difference module type.\r
+               //\r
+               switch (CommonDefinition.getModuleType(typeStr)) {\r
+\r
+               case CommonDefinition.ModuleTypePeiCore:\r
+                       if (entryPointList == null ||entryPointList.length != 1 ) {\r
+                               throw new BuildException(\r
+                                               "Module type = 'PEI_CORE', only have one module entry point!");\r
+                       } else {\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN VOID                        *OldCoreData\r\n");\r
+                               fileBuffer.append("  );\r\n\r\n");\r
+\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN VOID                        *OldCoreData\r\n");\r
+                               fileBuffer.append("  )\r\n\r\n");\r
+                               fileBuffer.append("{\r\n");\r
+                               fileBuffer.append("  return ");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
+                               fileBuffer.append("}\r\n\r\n");\r
+                       }\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypeDxeCore:\r
+                       fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
+                       if (entryPointList == null || entryPointList.length != 1) {\r
+                               throw new BuildException(\r
+                                               "Module type = 'DXE_CORE', only have one module entry point!");\r
+                       } else {\r
+\r
+                               fileBuffer.append("VOID\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append(" (\n");\r
+                               fileBuffer.append("  IN VOID  *HobStart\r\n");\r
+                               fileBuffer.append("  );\r\n\r\n");\r
+\r
+                               fileBuffer.append("VOID\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                               fileBuffer.append("  IN VOID  *HobStart\r\n");\r
+                               fileBuffer.append("  )\r\n\r\n");\r
+                               fileBuffer.append("{\r\n");\r
+                               fileBuffer.append("  ");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append(" (HobStart);\r\n");\r
+                               fileBuffer.append("}\r\n\r\n");\r
+                       }\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypePeim:\r
+                       int entryPointCount = 0;\r
+                       fileBuffer\r
+                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
+                       if (entryPointList == null) {\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                               fileBuffer.append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
+                               fileBuffer.append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
+                               fileBuffer.append("  )\r\n\r\n");\r
+                               fileBuffer.append("{\r\n");\r
+                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                               fileBuffer.append("}\r\n\r\n");\r
+                               break;\r
+                       }\r
+                       for (int i = 0; i < entryPointList.length; i++) {\r
+                                       fileBuffer.append("EFI_STATUS\r\n");\r
+                                       fileBuffer.append("EFIAPI\r\n");\r
+                                       fileBuffer.append(entryPointList[i]);\r
+                                       fileBuffer.append(" (\r\n");\r
+                                       fileBuffer\r
+                                                       .append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
+                                       fileBuffer\r
+                                                       .append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
+                                       fileBuffer.append("  );\r\n");\r
+                                       entryPointCount++;\r
+                       \r
+                       }\r
+\r
+                       fileBuffer.append("EFI_STATUS\r\n");\r
+                       fileBuffer.append("EFIAPI\r\n");\r
+                       fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                       fileBuffer.append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
+                       fileBuffer.append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
+                       fileBuffer.append("  )\r\n\r\n");\r
+                       fileBuffer.append("{\r\n");\r
+            if (entryPointCount == 1) {\r
+                               fileBuffer.append("  return ");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+                       } else {\r
+                               fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
+                               fileBuffer.append("  EFI_STATUS  CombinedStatus;\r\n\r\n");\r
+                               fileBuffer.append("  CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                                       if (!entryPointList[i].equals("")) {\r
+                                               fileBuffer.append("  Status = ");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+                                               fileBuffer\r
+                                                               .append("  if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
+                                               fileBuffer.append("    CombinedStatus = Status;\r\n");\r
+                                               fileBuffer.append("  }\r\n\r\n");\r
+                                       } else {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               fileBuffer.append("  return CombinedStatus;\r\n");\r
+                       }\r
+                       fileBuffer.append("}\r\n\r\n");\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                       entryPointCount = 0;\r
+            //\r
+            // If entryPoint is null, create an empty ProcessModuleEntryPointList\r
+            // function.\r
+            //\r
+                       if (entryPointList == null || entryPointList.length == 0){\r
+                               fileBuffer\r
+                               .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
+                       fileBuffer.append(Integer.toString(entryPointCount));\r
+                       fileBuffer.append(";\r\n");\r
+                       fileBuffer\r
+                               .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                               fileBuffer\r
+                                               .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+               \r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                               fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                               fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                               fileBuffer.append("  )\r\n\r\n");\r
+                               fileBuffer.append("{\r\n");\r
+                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                               fileBuffer.append("}\r\n\r\n");\r
+                               break;\r
+                       } else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
                     if (!entryPointList[i].equals("")) {\r
                         fileBuffer.append("EFI_STATUS\r\n");\r
                         fileBuffer.append("EFIAPI\r\n");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append(" (\r\n");\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
                     if (!entryPointList[i].equals("")) {\r
                         fileBuffer.append("EFI_STATUS\r\n");\r
                         fileBuffer.append("EFIAPI\r\n");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append(" (\r\n");\r
-                        fileBuffer\r
-                                .append("  EFI_HANDLE        ImageHandle\r\n");\r
+                        fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                        fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
                         fileBuffer.append("  );\r\n");\r
                         fileBuffer.append("  );\r\n");\r
+                        entryPointCount++;\r
                     } else {\r
                         break;\r
                     }\r
                 }\r
                     } else {\r
                         break;\r
                     }\r
                 }\r
-            }\r
+                fileBuffer\r
+                        .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
+                fileBuffer.append(Integer.toString(entryPointCount));\r
+                fileBuffer.append(";\r\n");\r
+                fileBuffer\r
+                        .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                fileBuffer\r
+                        .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                fileBuffer.append("  )\r\n\r\n");\r
+                fileBuffer.append("{\r\n");\r
 \r
 \r
-            fileBuffer.append("EFI_STATUS\n");\r
-            fileBuffer.append("EFIAPI\n");\r
-            fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
-            fileBuffer.append("  EFI_HANDLE  ImageHandle\r\n");\r
-            fileBuffer.append("  )\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            if (entryPointCount == 0) {\r
-                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
-                fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append("(ImageHandle);\r\n");\r
-            } else {\r
-                fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
-                fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
+                \r
                 for (int i = 0; i < entryPointList.length; i++) {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
+                    fileBuffer\r
+                            .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
+                    fileBuffer.append("    ExitDriver (");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
+                    fileBuffer.append("    ASSERT (FALSE);\r\n");\r
+                    fileBuffer.append("  }\r\n");\r
+                \r
+                }\r
+                fileBuffer.append("  return mDriverEntryPointStatus;\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+\r
+                fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ExitDriver (\r\n");\r
+                fileBuffer.append("  IN EFI_STATUS  Status\n");\r
+                fileBuffer.append("  )\r\n\r\n");\r
+                fileBuffer.append("{\r\n");\r
+                fileBuffer\r
+                        .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
+                fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
+                fileBuffer.append("  }\r\n");\r
+                fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
+                fileBuffer.append("  ASSERT (FALSE);\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+    \r
+            }\r
+                \r
+                       \r
+                       //\r
+                       // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
+                       //\r
+                       entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
+            entryPointList = CommonDefinition.remDupString(entryPointList);\r
+                       entryPointCount = 0;\r
+\r
+                       fileBuffer\r
+                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+                       fileBuffer.append(Integer.toString(entryPointCount));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+\r
+                       if (entryPointList != null) {\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                                       if (!entryPointList[i].equals("")) {\r
+                                               fileBuffer.append("EFI_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer\r
+                                                               .append("  EFI_HANDLE        ImageHandle\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                       } else {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       fileBuffer.append("EFI_STATUS\r\n");\r
+                       fileBuffer.append("EFIAPI\r\n");\r
+                       fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
+                       fileBuffer.append("  EFI_HANDLE  ImageHandle\r\n");\r
+                       fileBuffer.append("  )\r\n");\r
+                       fileBuffer.append("{\r\n");\r
+\r
+                       if (entryPointCount == 0) {\r
+                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                       } else if (entryPointCount == 1) {\r
+                               fileBuffer.append("  return ");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append("(ImageHandle);\r\n");\r
+                       } else {\r
+                               fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
+                               fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                    if (i == 0){\r
+                        fileBuffer.append("     Status = ");\r
+                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append("(ImageHandle);\r\n");\r
+                    }else{\r
                         fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
                         fileBuffer.append("    ");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
                         fileBuffer.append("    ");\r
                         fileBuffer.append(entryPointList[i]);\r
@@ -1102,858 +1019,1071 @@ public class AutoGen {
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
                         fileBuffer.append("  }\r\n");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
                         fileBuffer.append("  }\r\n");\r
-                    } else {\r
-                        break;\r
                     }\r
                     }\r
-                }\r
-                fileBuffer.append("  return Status;\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n\r\n");\r
-            break;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * PpiGuidToAutogenc\r
-     * \r
-     * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
-     * and write those GUIDs to AutoGen.c.\r
-     * \r
-     * @param fileBuffer\r
-     *            String Buffer for Autogen.c file.\r
-     * @throws BuildException\r
-     *             Guid must set value!\r
-     */\r
-    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
-        String[] cNameGuid = null;\r
-\r
-        //\r
-        // Get the all PPI adn PPI Notify from MSA file,\r
-        // then add those PPI ,and PPI Notify name to list.\r
-        //\r
-        String[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
-        for (int i = 0; i < ppiList.length; i++) {\r
-            this.mPpiList.add(ppiList[i]);\r
-        }\r
-\r
-        String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(null);\r
-        for (int i = 0; i < ppiNotifyList.length; i++) {\r
-            this.mPpiList.add(ppiNotifyList[i]);\r
-        }\r
-\r
-        //\r
-        // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
-        //\r
-        Iterator ppiIterator = this.mPpiList.iterator();\r
-        String ppiKeyWord = null;\r
-        while (ppiIterator.hasNext()) {\r
-               ppiKeyWord = ppiIterator.next().toString();\r
-            cNameGuid = GlobalData\r
-                    .getPpiGuid(SurfaceAreaQuery.getDependencePkg(this.arch),\r
-                            ppiKeyWord);\r
-            if (cNameGuid != null) {\r
-                fileBuffer\r
-                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                fileBuffer.append(cNameGuid[0]);\r
-                fileBuffer.append(" =     { ");\r
-                fileBuffer.append(cNameGuid[1]);\r
-                fileBuffer.append(" } ;");\r
-            } else {\r
-               //\r
-                // If can't find Ppi GUID declaration in every package\r
-                //\r
-                throw new AutoGenException("Can not find Ppi GUID [" + ppiKeyWord + "] declaration in every packages. ");\r
-            }\r
-        }\r
-    }\r
-\r
-    /**\r
-     * ProtocolGuidToAutogenc\r
-     * \r
-     * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
-     * information and write those GUIDs to AutoGen.c.\r
-     * \r
-     * @param fileBuffer\r
-     *            String Buffer for Autogen.c file.\r
-     * @throws BuildException\r
-     *             Protocol name must set.\r
-     */\r
-    void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
-        String[] cNameGuid = null;\r
-\r
-        String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
-\r
-        //\r
-        // Add result to Autogen global list.\r
-        //\r
-        for (int i = 0; i < protocolList.length; i++) {\r
-            this.mProtocolList.add(protocolList[i]);\r
-        }\r
-\r
-        String[] protocolNotifyList = SurfaceAreaQuery\r
-                .getProtocolNotifyArray(this.arch);\r
-\r
-        for (int i = 0; i < protocolNotifyList.length; i++) {\r
-            this.mProtocolList.add(protocolNotifyList[i]);\r
-        }\r
-\r
-        //\r
-        // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
-        //\r
-        Iterator protocolIterator = this.mPpiList.iterator();\r
-        String protocolKeyWord = null;\r
-        while (protocolIterator.hasNext()) {\r
-               protocolKeyWord = protocolIterator.next().toString();\r
-            cNameGuid = GlobalData.getProtocolGuid(SurfaceAreaQuery\r
-                    .getDependencePkg(this.arch), protocolKeyWord);\r
-            if (cNameGuid != null) {\r
-                fileBuffer\r
-                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                fileBuffer.append(cNameGuid[0]);\r
-                fileBuffer.append(" =     { ");\r
-                fileBuffer.append(cNameGuid[1]);\r
-                fileBuffer.append(" } ;");\r
-            } else {\r
-               //\r
-                // If can't find protocol GUID declaration in every package\r
-                //\r
-                throw new BuildException("Can not find protocol Guid [" + cNameGuid + "] declaration in every packages. ");\r
-            }\r
-        }\r
-    }\r
-\r
-    /**\r
-     * GuidGuidToAutogenc\r
-     * \r
-     * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
-     * and write those GUIDs to AutoGen.c.\r
-     * \r
-     * @param fileBuffer\r
-     *            String Buffer for Autogen.c file.\r
-     * \r
-     */\r
-    void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
-        String[] cNameGuid = null;\r
-        String   guidKeyWord = null;\r
-\r
-        String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
-\r
-        for (int i = 0; i < guidList.length; i++) {\r
-            this.mGuidList.add(guidList[i]);\r
-        }\r
-\r
-        Iterator guidIterator = this.mGuidList.iterator();\r
-        while (guidIterator.hasNext()) {\r
-               guidKeyWord = guidIterator.next().toString();\r
-            cNameGuid = GlobalData.getGuid(SurfaceAreaQuery\r
-                    .getDependencePkg(this.arch), guidKeyWord);\r
-            \r
-            if (cNameGuid != null) {\r
+                               }\r
+                               fileBuffer.append("  return Status;\r\n");\r
+                       }\r
+                       fileBuffer.append("}\r\n\r\n");\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+               case CommonDefinition.ModuleTypeDxeDriver:\r
+               case CommonDefinition.ModuleTypeDxeSalDriver:\r
+               case CommonDefinition.ModuleTypeUefiDriver:\r
+               case CommonDefinition.ModuleTypeUefiApplication:\r
+                       entryPointCount = 0;\r
+                       fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
+            //\r
+            // If entry point is null, create a empty ProcessModuleEntryPointList function.\r
+            //\r
+                       if (entryPointList == null || entryPointList.length == 0){\r
                 fileBuffer\r
                 fileBuffer\r
-                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                fileBuffer.append(cNameGuid[0]);\r
-                fileBuffer.append(" =     { ");\r
-                fileBuffer.append(cNameGuid[1]);\r
-                fileBuffer.append("} ;");\r
-            }else {\r
-               //\r
-                // If can't find GUID declaration in every package\r
-                //\r
-                throw new AutoGenException("Can not find Guid [" + guidKeyWord + "] declaration in every packages. ");\r
-            }\r
-\r
-        }\r
-    }\r
-\r
-    /**\r
-     * LibInstanceToAutogenC\r
-     * \r
-     * This function adds dependent library instance to autogen.c,which\r
-     * includeing library's constructor, destructor, and library dependent ppi,\r
-     * protocol, guid, pcd information.\r
-     * \r
-     * @param fileBuffer\r
-     *            String buffer for AutoGen.c\r
-     * @throws BuildException\r
-     */\r
-    void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
-        int index;\r
-\r
-        String moduleType = SurfaceAreaQuery.getModuleType();\r
-        List<String> libConstructList = new ArrayList<String>();\r
-        List<String> libDestructList = new ArrayList<String>();\r
-\r
-        String libConstructName = null;\r
-        String libDestructName = null;\r
-        ModuleIdentification[] libraryIdList = SurfaceAreaQuery.getLibraryInstance(this.arch);\r
-\r
-        try {\r
-            if (libraryIdList != null) {\r
-                //\r
-                // Reorder library instance sequence.\r
-                //\r
-                AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch);\r
-                List<ModuleIdentification> orderList = libOrder.orderLibInstance();\r
-\r
-                if (orderList != null) {\r
-                    //\r
-                    // Process library instance one by one.\r
-                    //\r
-                    for (int i = 0; i < orderList.size(); i++) {\r
-\r
-                        //\r
-                        // Get library instance basename.\r
-                        //\r
-                        ModuleIdentification libInstanceId = orderList.get(i);\r
-\r
-                        //\r
-                        // Get override map\r
-                        //\r
-                        Map<String, XmlObject> libDoc = GlobalData\r
-                                .getDoc(libInstanceId, this.arch);\r
-                        SurfaceAreaQuery.push(libDoc);\r
-\r
-                        //\r
-                        // Get <PPis>, <Protocols>, <Guids> list of this library\r
-                        // instance.\r
-                        //\r
-                        String[] ppiList = SurfaceAreaQuery\r
-                                .getPpiArray(null);\r
-                        String[] ppiNotifyList = SurfaceAreaQuery\r
-                                .getPpiNotifyArray(null);\r
-                        String[] protocolList = SurfaceAreaQuery\r
-                                .getProtocolArray(null);\r
-                        String[] protocolNotifyList = SurfaceAreaQuery\r
-                                .getProtocolNotifyArray(null);\r
-                        String[] guidList = SurfaceAreaQuery\r
-                                .getGuidEntryArray(null);\r
-\r
-                        //\r
-                        // Add those ppi, protocol, guid in global ppi,\r
-                        // protocol, guid\r
-                        // list.\r
-                        //\r
-                        for (index = 0; index < ppiList.length; index++) {\r
-                            this.mPpiList.add(ppiList[index]);\r
-                        }\r
-                        \r
-                        for (index = 0; index < ppiNotifyList.length; index++) {\r
-                            this.mPpiList.add(ppiNotifyList[index]);\r
-                        }\r
-                        \r
-                        for (index = 0; index < protocolList.length; index++) {\r
-                            this.mProtocolList.add(protocolList[index]);\r
-                        }\r
-                        \r
-                        for (index = 0; index < protocolNotifyList.length; index++) {\r
-                            this.mProtocolList.add(protocolNotifyList[index]);\r
-                        }\r
-                        \r
-                        for (index = 0; index < guidList.length; index++) {\r
-                            this.mGuidList.add(guidList[index]);   \r
-                        }\r
-\r
-                        //\r
-                        // If not yet parse this library instance's constructor\r
-                        // element,parse it.\r
-                        //\r
-                        libConstructName = SurfaceAreaQuery\r
-                                    .getLibConstructorName();\r
-                        libDestructName = SurfaceAreaQuery\r
-                                    .getLibDestructorName();\r
-\r
-                        SurfaceAreaQuery.pop();\r
-                        //\r
-                        // Add dependent library instance constructor function.\r
-                        //\r
-                        if (libConstructName != null) {\r
-                            libConstructList.add(libConstructName);\r
-                        }\r
-                        //\r
-                        // Add dependent library instance destructor fuction.\r
-                        //\r
-                        if (libDestructName != null) {\r
-                            libDestructList.add(libDestructName);\r
-                        }\r
-                    }\r
-\r
+                .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = 0;\r\n");\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                               fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                               fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                               fileBuffer.append("  )\r\n\r\n");\r
+                               fileBuffer.append("{\r\n");\r
+                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                               fileBuffer.append("}\r\n");\r
+                               \r
+                       }else {\r
+                for (int i = 0; i < entryPointList.length; i++) {\r
+                    \r
+                    fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (\r\n");\r
+                    fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                    fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
                 }\r
 \r
                 }\r
 \r
-                //\r
-                // Add library constructor to AutoGen.c\r
-                //\r
-                LibConstructorToAutogenC(libConstructList, moduleType,\r
-                        fileBuffer/* autogenC */);\r
-                //\r
-                // Add library destructor to AutoGen.c\r
-                //\r
-                LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
-            }\r
-\r
-        } catch (Exception e) {\r
-            throw new BuildException(e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-     * LibConstructorToAutogenc\r
-     * \r
-     * This function writes library constructor list to AutoGen.c. The library\r
-     * constructor's parameter and return value depend on module type.\r
-     * \r
-     * @param libInstanceList\r
-     *            List of library construct name.\r
-     * @param moduleType\r
-     *            Module type.\r
-     * @param fileBuffer\r
-     *            String buffer for AutoGen.c\r
-     * @throws Exception\r
-     */\r
-    void LibConstructorToAutogenC(List<String> libInstanceList,\r
-            String moduleType, StringBuffer fileBuffer) throws Exception {\r
-        boolean isFirst = true;\r
-\r
-        //\r
-        // The library constructor's parameter and return value depend on\r
-        // module type.\r
-        //\r
-        for (int i = 0; i < libInstanceList.size(); i++) {\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
-                fileBuffer.append("RETURN_STATUS\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  VOID\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer\r
-                        .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                fileBuffer\r
-                        .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-\r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-            }\r
-        }\r
-\r
-        //\r
-        // Add ProcessLibraryConstructorList in AutoGen.c\r
-        //\r
-        fileBuffer.append("VOID\r\n");\r
-        fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
-        switch (CommonDefinition.getModuleType(moduleType)) {\r
-        case CommonDefinition.ModuleTypeBase:\r
-            fileBuffer.append("  VOID\r\n");\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypePeiCore:\r
-        case CommonDefinition.ModuleTypePeim:\r
-            fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-            fileBuffer\r
-                    .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-            break;\r
-\r
-        case CommonDefinition.ModuleTypeDxeCore:\r
-        case CommonDefinition.ModuleTypeDxeDriver:\r
-        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-        case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-        case CommonDefinition.ModuleTypeDxeSalDriver:\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-            fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-            break;\r
-        }\r
-\r
-        fileBuffer.append("  )\r\n");\r
-        fileBuffer.append("{\r\n");\r
-\r
-        for (int i = 0; i < libInstanceList.size(); i++) {\r
-            if (isFirst) {\r
-                fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
-                fileBuffer.append("\r\n");\r
-                isFirst = false;\r
-            }\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append("();\r\n");\r
-                fileBuffer.append("  VOID\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
-                break;\r
-            }\r
-            fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
-        }\r
-        fileBuffer.append("}\r\n");\r
-    }\r
-\r
-    /**\r
-     * LibDestructorToAutogenc\r
-     * \r
-     * This function writes library destructor list to AutoGen.c. The library\r
-     * destructor's parameter and return value depend on module type.\r
-     * \r
-     * @param libInstanceList\r
-     *            List of library destructor name.\r
-     * @param moduleType\r
-     *            Module type.\r
-     * @param fileBuffer\r
-     *            String buffer for AutoGen.c\r
-     * @throws Exception\r
-     */\r
-    void LibDestructorToAutogenC(List<String> libInstanceList,\r
-            String moduleType, StringBuffer fileBuffer) throws Exception {\r
-        boolean isFirst = true;\r
-        for (int i = 0; i < libInstanceList.size(); i++) {\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
-                fileBuffer.append("RETURN_STATUS\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  VOID\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
                 fileBuffer\r
                 fileBuffer\r
-                        .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                fileBuffer\r
-                        .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-            }\r
-        }\r
-\r
-        //\r
-        // Write ProcessLibraryDestructor list to autogen.c\r
-        //\r
-        switch (CommonDefinition.getModuleType(moduleType)) {\r
-        case CommonDefinition.ModuleTypeBase:\r
-        case CommonDefinition.ModuleTypePeiCore:\r
-        case CommonDefinition.ModuleTypePeim:\r
-            break;\r
-        case CommonDefinition.ModuleTypeDxeCore:\r
-        case CommonDefinition.ModuleTypeDxeDriver:\r
-        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-        case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-        case CommonDefinition.ModuleTypeDxeSalDriver:\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            fileBuffer.append("VOID\r\n");\r
-            fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
-            fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-            fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-            fileBuffer.append("  )\r\n");\r
-            fileBuffer.append("{\r\n");\r
-\r
-            for (int i = 0; i < libInstanceList.size(); i++) {\r
-                if (isFirst) {\r
-                    fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
-                    fileBuffer.append("\r\n");\r
-                    isFirst = false;\r
-                }\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
-                fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
-            }\r
-            fileBuffer.append("}\r\n");\r
-            break;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * ExternsDriverBindingToAutoGenC\r
-     * \r
-     * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
-     * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
-     * \r
-     * @param fileBuffer\r
-     *            String buffer for AutoGen.c\r
-     */\r
-    void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
-            throws BuildException {\r
-\r
-        //\r
-        // Check what <extern> contains. And the number of following elements\r
-        // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
-        // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
-        //\r
-\r
-        String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
-\r
-        //\r
-        // If component name protocol,component configuration protocol,\r
-        // component diagnostic protocol is not null or empty, check\r
-        // if every one have the same number of the driver binding protocol.\r
-        //\r
-        if (drvBindList == null || drvBindList.length == 0) {\r
-            return;\r
-        }\r
-\r
-        String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
-        String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
-        String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
-\r
-        int BitMask = 0;\r
-\r
-        //\r
-        // Write driver binding protocol extern to autogen.c\r
-        //\r
-        for (int i = 0; i < drvBindList.length; i++) {\r
-            fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
-            fileBuffer.append(drvBindList[i]);\r
-            fileBuffer.append(";\r\n");\r
-        }\r
-\r
-        //\r
-        // Write component name protocol extern to autogen.c\r
-        //\r
-        if (compNamList != null && compNamList.length != 0) {\r
-            if (drvBindList.length != compNamList.length) {\r
-                throw new BuildException(\r
-                        "Different number of Driver Binding and Component Name protocols!");\r
-            }\r
-\r
-            BitMask |= 0x01;\r
-            for (int i = 0; i < compNamList.length; i++) {\r
-                fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
-                fileBuffer.append(compNamList[i]);\r
-                fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
-\r
-        //\r
-        // Write driver configration protocol extern to autogen.c\r
-        //\r
-        if (compConfList != null && compConfList.length != 0) {\r
-            if (drvBindList.length != compConfList.length) {\r
-                throw new BuildException(\r
-                        "Different number of Driver Binding and Driver Configuration protocols!");\r
-            }\r
-\r
-            BitMask |= 0x02;\r
-            for (int i = 0; i < compConfList.length; i++) {\r
-                fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
-                fileBuffer.append(compConfList[i]);\r
-                fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
-\r
-        //\r
-        // Write driver dignastic protocol extern to autogen.c\r
-        //\r
-        if (compDiagList != null && compDiagList.length != 0) {\r
-            if (drvBindList.length != compDiagList.length) {\r
-                throw new BuildException(\r
-                        "Different number of Driver Binding and Driver Configuration protocols!");\r
-            }\r
-\r
-            BitMask |= 0x04;\r
-            for (int i = 0; i < compDiagList.length; i++) {\r
-                fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
-                fileBuffer.append(compDiagList[i]);\r
+                        .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = ");\r
+                fileBuffer.append(Integer.toString(entryPointCount));\r
                 fileBuffer.append(";\r\n");\r
                 fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
-\r
-        //\r
-        // Write driver module protocol bitmask.\r
-        //\r
-        fileBuffer\r
-                .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverModelProtocolBitmask = ");\r
-        fileBuffer.append(Integer.toString(BitMask));\r
-        fileBuffer.append(";\r\n");\r
-\r
-        //\r
-        // Write driver module protocol list entry\r
-        //\r
-        fileBuffer\r
-                .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN  _gDriverModelProtocolListEntries = ");\r
-\r
-        fileBuffer.append(Integer.toString(drvBindList.length));\r
-        fileBuffer.append(";\r\n");\r
-\r
-        //\r
-        // Write drive module protocol list to autogen.c\r
-        //\r
-        fileBuffer\r
-                .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {");\r
-        for (int i = 0; i < drvBindList.length; i++) {\r
-            if (i != 0) {\r
-                fileBuffer.append(",");\r
-            }\r
-            fileBuffer.append("\r\n {\r\n");\r
-            fileBuffer.append("  &");\r
-            fileBuffer.append(drvBindList[i]);\r
-            fileBuffer.append(", \r\n");\r
-\r
-            if (compNamList != null) {\r
-                fileBuffer.append("  &");\r
-                fileBuffer.append(compNamList[i]);\r
-                fileBuffer.append(", \r\n");\r
-            } else {\r
-                fileBuffer.append("  NULL, \r\n");\r
-            }\r
-\r
-            if (compConfList != null) {\r
-                fileBuffer.append("  &");\r
-                fileBuffer.append(compConfList[i]);\r
-                fileBuffer.append(", \r\n");\r
-            } else {\r
-                fileBuffer.append("  NULL, \r\n");\r
-            }\r
+                if (entryPointCount > 1) {\r
+                    fileBuffer\r
+                            .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                    fileBuffer\r
+                            .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
+                }\r
+                fileBuffer.append("\n");\r
 \r
 \r
-            if (compDiagList != null) {\r
-                fileBuffer.append("  &");\r
-                fileBuffer.append(compDiagList[i]);\r
-                fileBuffer.append(", \r\n");\r
-            } else {\r
-                fileBuffer.append("  NULL, \r\n");\r
-            }\r
-            fileBuffer.append("  }");\r
-        }\r
-        fileBuffer.append("\r\n};\r\n");\r
-    }\r
-\r
-    /**\r
-     * ExternCallBackToAutoGenC\r
-     * \r
-     * This function adds <SetVirtualAddressMapCallBack> and\r
-     * <ExitBootServicesCallBack> infomation to AutoGen.c\r
-     * \r
-     * @param fileBuffer\r
-     *            String buffer for AutoGen.c\r
-     * @throws BuildException\r
-     */\r
-    void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
-            throws BuildException {\r
-        String[] setVirtualList = SurfaceAreaQuery\r
-                .getSetVirtualAddressMapCallBackArray();\r
-        String[] exitBootList = SurfaceAreaQuery\r
-                .getExitBootServicesCallBackArray();\r
-        String moduleType = SurfaceAreaQuery.getModuleType();\r
-        boolean UefiOrDxeModule = false;\r
-        int Count = 0;\r
-        int i;\r
-\r
-        switch (CommonDefinition.getModuleType(moduleType)) {\r
-        case CommonDefinition.ModuleTypeDxeDriver:\r
-        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-        case CommonDefinition.ModuleTypeDxeSalDriver:\r
-        case CommonDefinition.ModuleTypeUefiDriver:\r
-        case CommonDefinition.ModuleTypeUefiApplication:\r
-            //\r
-            // Entry point lib for these module types needs to know the count\r
-            // of entryPoint.\r
-            //\r
-            UefiOrDxeModule = true;\r
-            fileBuffer\r
-                    .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                fileBuffer.append("  EFI_HANDLE        ImageHandle,\r\n");\r
+                fileBuffer.append("  EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                fileBuffer.append("  )\r\n\r\n");\r
+                fileBuffer.append("{\r\n");\r
 \r
 \r
-            //\r
-            // If the list is not valid or has no entries set count to zero else\r
-            // set count to the number of valid entries\r
-            //\r
-            Count = 0;\r
-            if (setVirtualList != null) {\r
-                for (i = 0; i < setVirtualList.length; i++) {\r
-                    if (setVirtualList[i].equalsIgnoreCase("")) {\r
-                        break;\r
+                if (entryPointCount == 1) {\r
+                    fileBuffer.append("  return (");\r
+                    fileBuffer.append(entryPointList[0]);\r
+                    fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
+                } else {\r
+                    for (int i = 0; i < entryPointList.length; i++) {\r
+                        if (!entryPointList[i].equals("")) {\r
+                            fileBuffer\r
+                                    .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
+                            fileBuffer.append("    ExitDriver (");\r
+                            fileBuffer.append(entryPointList[i]);\r
+                            fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
+                            fileBuffer.append("    ASSERT (FALSE);\r\n");\r
+                            fileBuffer.append("  }\r\n");\r
+                        } else {\r
+                            break;\r
+                        }\r
                     }\r
                     }\r
+                    fileBuffer.append("  return mDriverEntryPointStatus;\r\n");\r
                 }\r
                 }\r
-                Count = i;\r
-            }\r
-\r
-            fileBuffer.append(Integer.toString(Count));\r
-            fileBuffer.append(";\r\n\r\n");\r
-            break;\r
-        default:\r
-            break;\r
-        }\r
+                fileBuffer.append("}\r\n\r\n");\r
 \r
 \r
-        if (setVirtualList == null) {\r
-            if (UefiOrDxeModule) {\r
-                //\r
-                // No data so make a NULL list\r
-                //\r
-                fileBuffer\r
-                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
-                fileBuffer.append("  NULL\r\n");\r
-                fileBuffer.append("};\r\n\r\n");\r
-            }\r
-        } else {\r
-            //\r
-            // Write SetVirtualAddressMap function definition.\r
-            //\r
-            for (i = 0; i < setVirtualList.length; i++) {\r
-                if (setVirtualList[i].equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-                fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("VOID\n");\r
                 fileBuffer.append("EFIAPI\n");\r
                 fileBuffer.append("EFIAPI\n");\r
-                fileBuffer.append(setVirtualList[i]);\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
-                fileBuffer.append("  IN VOID       *Context\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
-            }\r
-\r
-            //\r
-            // Write SetVirtualAddressMap entry point array.\r
-            //\r
-            fileBuffer\r
-                    .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
-            for (i = 0; i < setVirtualList.length; i++) {\r
-                if (setVirtualList[i].equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-\r
-                if (i == 0) {\r
-                    fileBuffer.append("\r\n  ");\r
+                fileBuffer.append("ExitDriver (\r\n");\r
+                fileBuffer.append("  IN EFI_STATUS  Status\n");\r
+                fileBuffer.append("  )\r\n\r\n");\r
+                fileBuffer.append("{\r\n");\r
+                if (entryPointCount <= 1) {\r
+                    fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
+                    fileBuffer\r
+                            .append("    ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
+                    fileBuffer.append("  }\r\n");\r
+                    fileBuffer\r
+                            .append("  gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
                 } else {\r
                 } else {\r
-                    fileBuffer.append(",\r\n  ");\r
+                    fileBuffer\r
+                            .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
+                    fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
+                    fileBuffer.append("  }\r\n");\r
+                    fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
+                    fileBuffer.append("  ASSERT (FALSE);\r\n");\r
                 }\r
                 }\r
+                fileBuffer.append("}\r\n\r\n");\r
 \r
 \r
-                fileBuffer.append(setVirtualList[i]);\r
             }\r
             }\r
-            if (Count == 0) {\r
-                fileBuffer.append("\r\n  NULL");\r
-            }\r
-            fileBuffer.append("\r\n};\r\n\r\n");\r
-        }\r
-\r
-        if (UefiOrDxeModule) {\r
-            //\r
-            // Entry point lib for these module types needs to know the count.\r
-            //\r
-            fileBuffer\r
-                    .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverExitBootServicesEventCount = ");\r
-\r
+                       \r
+                       //\r
+                       // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
+                       //\r
+                       entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             //\r
             //\r
-            // If the list is not valid or has no entries set count to zero else\r
-            // set count to the number of valid entries.\r
+            // Remover duplicate unload entry point.\r
             //\r
             //\r
-            Count = 0;\r
-            if (exitBootList != null) {\r
-                if (setVirtualList != null) {\r
-                    for (i = 0; i < exitBootList.length; i++) {\r
-                        if (exitBootList[i].equalsIgnoreCase("")) {\r
-                            break;\r
+            entryPointList = CommonDefinition.remDupString(entryPointList);\r
+                       entryPointCount = 0;\r
+                       if (entryPointList != null) {\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                                       if (!entryPointList[i].equals("")) {\r
+                                               fileBuffer.append("EFI_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer\r
+                                                               .append("  EFI_HANDLE        ImageHandle\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                               entryPointCount++;\r
+                                       } else {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       fileBuffer\r
+                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+                       fileBuffer.append(Integer.toString(entryPointCount));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+\r
+                       if (entryPointList != null) {\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                                       if (!entryPointList[i].equals("")) {\r
+                                               fileBuffer.append("EFI_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer\r
+                                                               .append("  EFI_HANDLE        ImageHandle\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                       } else {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       fileBuffer.append("EFI_STATUS\n");\r
+                       fileBuffer.append("EFIAPI\r\n");\r
+                       fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
+                       fileBuffer.append("  EFI_HANDLE  ImageHandle\r\n");\r
+                       fileBuffer.append("  )\r\n");\r
+                       fileBuffer.append("{\r\n");\r
+\r
+                       if (entryPointCount == 0) {\r
+                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                       } else if (entryPointCount == 1) {\r
+                               fileBuffer.append("  return ");\r
+                               fileBuffer.append(entryPointList[0]);\r
+                               fileBuffer.append("(ImageHandle);\r\n");\r
+                       } else {\r
+                               fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
+                               fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
+                               for (int i = 0; i < entryPointList.length; i++) {\r
+                                       if (!entryPointList[i].equals("")) {\r
+                                               fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
+                                               fileBuffer.append("    ");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append("(ImageHandle);\r\n");\r
+                                               fileBuffer.append("  } else {\r\n");\r
+                                               fileBuffer.append("    Status = ");\r
+                                               fileBuffer.append(entryPointList[i]);\r
+                                               fileBuffer.append("(ImageHandle);\r\n");\r
+                                               fileBuffer.append("  }\r\n");\r
+                                       } else {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               fileBuffer.append("  return Status;\r\n");\r
+                       }\r
+                       fileBuffer.append("}\r\n\r\n");\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * PpiGuidToAutogenc\r
+        * \r
+        * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
+        * and write those GUIDs to AutoGen.c.\r
+        * \r
+        * @param fileBuffer\r
+        *            String Buffer for Autogen.c file.\r
+        * @throws BuildException\r
+        *             Guid must set value!\r
+        */\r
+       void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
+               String[] cNameGuid = null;\r
+\r
+               //\r
+               // Get the all PPI adn PPI Notify from MSA file,\r
+               // then add those PPI ,and PPI Notify name to list.\r
+               //\r
+               \r
+               String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
+               for (int i = 0; i < ppiList.length; i++) {\r
+                       this.mPpiList.add(ppiList[i]);\r
+               }\r
+\r
+               String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);\r
+               for (int i = 0; i < ppiNotifyList.length; i++) {\r
+                       this.mPpiList.add(ppiNotifyList[i]);\r
+               }\r
+\r
+               //\r
+               // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
+               //\r
+               Iterator ppiIterator = this.mPpiList.iterator();\r
+               String ppiKeyWord = null;\r
+               while (ppiIterator.hasNext()) {\r
+                       ppiKeyWord = ppiIterator.next().toString();\r
+                       cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r
+                       if (cNameGuid != null) {\r
+                               fileBuffer\r
+                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                               fileBuffer.append(cNameGuid[0]);\r
+                               fileBuffer.append(" =     { ");\r
+                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                               fileBuffer.append(" } ;");\r
+                       } else {\r
+                               //\r
+                               // If can't find Ppi GUID declaration in every package\r
+                               //\r
+                               throw new AutoGenException("Can not find Ppi GUID ["\r
+                                               + ppiKeyWord + "] declaration in every packages. ");\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * ProtocolGuidToAutogenc\r
+        * \r
+        * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
+        * information and write those GUIDs to AutoGen.c.\r
+        * \r
+        * @param fileBuffer\r
+        *            String Buffer for Autogen.c file.\r
+        * @throws BuildException\r
+        *             Protocol name must set.\r
+        */\r
+       void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+               String[] cNameGuid = null;\r
+\r
+               String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
+\r
+               //\r
+               // Add result to Autogen global list.\r
+               //\r
+               for (int i = 0; i < protocolList.length; i++) {\r
+                       this.mProtocolList.add(protocolList[i]);\r
+               }\r
+\r
+               String[] protocolNotifyList = SurfaceAreaQuery\r
+                               .getProtocolNotifyArray(this.arch);\r
+\r
+               for (int i = 0; i < protocolNotifyList.length; i++) {\r
+                       this.mProtocolList.add(protocolNotifyList[i]);\r
+               }\r
+\r
+               //\r
+               // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
+               //\r
+               Iterator protocolIterator = this.mProtocolList.iterator();\r
+               String protocolKeyWord = null;\r
+               \r
+      \r
+               while (protocolIterator.hasNext()) {\r
+                       protocolKeyWord = protocolIterator.next().toString();\r
+                       cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r
+                       if (cNameGuid != null) {\r
+                               fileBuffer\r
+                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                               fileBuffer.append(cNameGuid[0]);\r
+                               fileBuffer.append(" =     { ");\r
+                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                               fileBuffer.append(" } ;");\r
+                       } else {\r
+                               //\r
+                               // If can't find protocol GUID declaration in every package\r
+                               //\r
+                               throw new BuildException("Can not find protocol Guid ["\r
+                                               + protocolKeyWord + "] declaration in every packages. ");\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * GuidGuidToAutogenc\r
+        * \r
+        * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
+        * and write those GUIDs to AutoGen.c.\r
+        * \r
+        * @param fileBuffer\r
+        *            String Buffer for Autogen.c file.\r
+        * \r
+        */\r
+       void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
+               String[] cNameGuid = null;\r
+               String guidKeyWord = null;\r
+\r
+               String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
+\r
+               for (int i = 0; i < guidList.length; i++) {\r
+                       this.mGuidList.add(guidList[i]);\r
+               }\r
+\r
+\r
+               Iterator guidIterator = this.mGuidList.iterator();\r
+               while (guidIterator.hasNext()) {\r
+                       guidKeyWord = guidIterator.next().toString();\r
+                       cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r
+\r
+                       if (cNameGuid != null) {\r
+                               fileBuffer\r
+                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                               fileBuffer.append(cNameGuid[0]);\r
+                               fileBuffer.append(" =     { ");\r
+                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                               fileBuffer.append("} ;");\r
+                       } else {\r
+                               //\r
+                               // If can't find GUID declaration in every package\r
+                               //\r
+                               throw new AutoGenException("Can not find Guid [" + guidKeyWord\r
+                                               + "] declaration in every packages. ");\r
+                       }\r
+\r
+               }\r
+       }\r
+\r
+       /**\r
+        * LibInstanceToAutogenC\r
+        * \r
+        * This function adds dependent library instance to autogen.c,which\r
+        * includeing library's constructor, destructor, and library dependent ppi,\r
+        * protocol, guid, pcd information.\r
+        * \r
+        * @param fileBuffer\r
+        *            String buffer for AutoGen.c\r
+        * @throws BuildException\r
+        */\r
+       void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+               int index;\r
+\r
+               String moduleType = SurfaceAreaQuery.getModuleType();\r
+               List<String> libConstructList = new ArrayList<String>();\r
+               List<String> libDestructList = new ArrayList<String>();\r
+\r
+               String libConstructName = null;\r
+               String libDestructName = null;\r
+               ModuleIdentification[] libraryIdList = SurfaceAreaQuery\r
+                               .getLibraryInstance(this.arch);\r
+\r
+               try {\r
+                       if (libraryIdList != null) {\r
+                               //\r
+                               // Reorder library instance sequence.\r
+                               //\r
+                               AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
+                                               this.arch);\r
+                               List<ModuleIdentification> orderList = libOrder\r
+                                               .orderLibInstance();\r
+\r
+                               if (orderList != null) {\r
+                                       //\r
+                                       // Process library instance one by one.\r
+                                       //\r
+                                       for (int i = 0; i < orderList.size(); i++) {\r
+\r
+                                               //\r
+                                               // Get library instance basename.\r
+                                               //\r
+                                               ModuleIdentification libInstanceId = orderList.get(i);\r
+\r
+                                               //\r
+                                               // Get override map\r
+                                               //\r
+                                                \r
+                                               Map<String, XmlObject> libDoc = GlobalData.getDoc(\r
+                                                               libInstanceId, this.arch);\r
+                                               SurfaceAreaQuery.push(libDoc);\r
+\r
+                                               //\r
+                                               // Get <PPis>, <Protocols>, <Guids> list of this library\r
+                                               // instance.\r
+                                               //\r
+                                               String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
+                                               String[] ppiNotifyList = SurfaceAreaQuery\r
+                                                               .getPpiNotifyArray(this.arch);\r
+                                               String[] protocolList = SurfaceAreaQuery\r
+                                                               .getProtocolArray(this.arch);\r
+                                               String[] protocolNotifyList = SurfaceAreaQuery\r
+                                                               .getProtocolNotifyArray(this.arch);\r
+                                               String[] guidList = SurfaceAreaQuery\r
+                                                               .getGuidEntryArray(this.arch);\r
+                        PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);\r
+\r
+                                               //\r
+                                               // Add those ppi, protocol, guid in global ppi,\r
+                                               // protocol, guid\r
+                                               // list.\r
+                                               //\r
+                                               for (index = 0; index < ppiList.length; index++) {\r
+                                                       this.mPpiList.add(ppiList[index]);\r
+                                               }\r
+\r
+                                               for (index = 0; index < ppiNotifyList.length; index++) {\r
+                                                       this.mPpiList.add(ppiNotifyList[index]);\r
+                                               }\r
+\r
+                                               for (index = 0; index < protocolList.length; index++) {\r
+                                                       this.mProtocolList.add(protocolList[index]);\r
+                                               }\r
+\r
+                                               for (index = 0; index < protocolNotifyList.length; index++) {\r
+                                                       this.mProtocolList.add(protocolNotifyList[index]);\r
+                                               }\r
+\r
+                                               for (index = 0; index < guidList.length; index++) {\r
+                                                       this.mGuidList.add(guidList[index]);\r
+                                               }\r
+                        for (index = 0; index < pkgList.length; index++){\r
+                            if (!this.mDepPkgList.contains(pkgList[index])){\r
+                                this.mDepPkgList.add(pkgList[index]);\r
+                            }\r
                         }\r
                         }\r
-                    }\r
-                    Count = i;\r
-                }\r
-            }\r
-            fileBuffer.append(Integer.toString(Count));\r
-            fileBuffer.append(";\r\n\r\n");\r
-        }\r
-\r
-        if (exitBootList == null) {\r
-            if (UefiOrDxeModule) {\r
-                //\r
-                // No data so make a NULL list.\r
-                //\r
-                fileBuffer\r
-                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
-                fileBuffer.append("  NULL\r\n");\r
-                fileBuffer.append("};\r\n\r\n");\r
-            }\r
-        } else {\r
-            //\r
-            // Write DriverExitBootServices function definition.\r
-            //\r
-            for (i = 0; i < exitBootList.length; i++) {\r
-                if (exitBootList[i].equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\n");\r
-                fileBuffer.append(exitBootList[i]);\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
-                fileBuffer.append("  IN VOID       *Context\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
-            }\r
 \r
 \r
+                                               //\r
+                                               // If not yet parse this library instance's constructor\r
+                                               // element,parse it.\r
+                                               //\r
+                                               libConstructName = SurfaceAreaQuery\r
+                                                               .getLibConstructorName();\r
+                                               libDestructName = SurfaceAreaQuery\r
+                                                               .getLibDestructorName();\r
+\r
+                                               SurfaceAreaQuery.pop();\r
+                                               //\r
+                                               // Add dependent library instance constructor function.\r
+                                               //\r
+                                               if (libConstructName != null) {\r
+                                                       libConstructList.add(libConstructName);\r
+                                               }\r
+                                               //\r
+                                               // Add dependent library instance destructor fuction.\r
+                                               //\r
+                                               if (libDestructName != null) {\r
+                                                       libDestructList.add(libDestructName);\r
+                                               }\r
+                                       }\r
+\r
+                               }\r
+\r
+                               //\r
+                               // Add library constructor to AutoGen.c\r
+                               //\r
+                               LibConstructorToAutogenC(libConstructList, moduleType,\r
+                                               fileBuffer/* autogenC */);\r
+                               //\r
+                               // Add library destructor to AutoGen.c\r
+                               //\r
+                               LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
+                       }\r
+\r
+               } catch (Exception e) {\r
+                       throw new BuildException(e.getMessage());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * LibConstructorToAutogenc\r
+        * \r
+        * This function writes library constructor list to AutoGen.c. The library\r
+        * constructor's parameter and return value depend on module type.\r
+        * \r
+        * @param libInstanceList\r
+        *            List of library construct name.\r
+        * @param moduleType\r
+        *            Module type.\r
+        * @param fileBuffer\r
+        *            String buffer for AutoGen.c\r
+        * @throws Exception\r
+        */\r
+       void LibConstructorToAutogenC(List<String> libInstanceList,\r
+                       String moduleType, StringBuffer fileBuffer) throws Exception {\r
+               boolean isFirst = true;\r
+\r
+               //\r
+               // The library constructor's parameter and return value depend on\r
+               // module type.\r
+               //\r
+               for (int i = 0; i < libInstanceList.size(); i++) {\r
+                       switch (CommonDefinition.getModuleType(moduleType)) {\r
+                       case CommonDefinition.ModuleTypeBase:\r
+                               fileBuffer.append("RETURN_STATUS\r\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  VOID\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+\r
+                       case CommonDefinition.ModuleTypePeiCore:\r
+                       case CommonDefinition.ModuleTypePeim:\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+\r
+                       case CommonDefinition.ModuleTypeDxeCore:\r
+                       case CommonDefinition.ModuleTypeDxeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                       case CommonDefinition.ModuleTypeUefiDriver:\r
+                       case CommonDefinition.ModuleTypeUefiApplication:\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                               fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Add ProcessLibraryConstructorList in AutoGen.c\r
+               //\r
+               fileBuffer.append("VOID\r\n");\r
+               fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
+               switch (CommonDefinition.getModuleType(moduleType)) {\r
+               case CommonDefinition.ModuleTypeBase:\r
+                       fileBuffer.append("  VOID\r\n");\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypePeiCore:\r
+               case CommonDefinition.ModuleTypePeim:\r
+                       fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                       fileBuffer\r
+                                       .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                       break;\r
+\r
+               case CommonDefinition.ModuleTypeDxeCore:\r
+               case CommonDefinition.ModuleTypeDxeDriver:\r
+               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+               case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+               case CommonDefinition.ModuleTypeDxeSalDriver:\r
+               case CommonDefinition.ModuleTypeUefiDriver:\r
+               case CommonDefinition.ModuleTypeUefiApplication:\r
+                       fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                       fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                       break;\r
+               }\r
+\r
+               fileBuffer.append("  )\r\n");\r
+               fileBuffer.append("{\r\n");\r
+        //\r
+        // If no constructor function, return EFI_SUCCESS.\r
+        //\r
+        //if (libInstanceList.size() == 0){\r
+        //   fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+        //}\r
+               for (int i = 0; i < libInstanceList.size(); i++) {\r
+                       if (isFirst) {\r
+                               fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
+                fileBuffer.append("  Status = EFI_SUCCESS;\r\n");\r
+                               fileBuffer.append("\r\n");\r
+                               isFirst = false;\r
+                       }\r
+                       switch (CommonDefinition.getModuleType(moduleType)) {\r
+                       case CommonDefinition.ModuleTypeBase:\r
+                               fileBuffer.append("  Status = ");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append("();\r\n");\r
+                               fileBuffer.append("  VOID\r\n");\r
+                               break;\r
+                       case CommonDefinition.ModuleTypePeiCore:\r
+                       case CommonDefinition.ModuleTypePeim:\r
+                               fileBuffer.append("  Status = ");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+                               break;\r
+                       case CommonDefinition.ModuleTypeDxeCore:\r
+                       case CommonDefinition.ModuleTypeDxeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                       case CommonDefinition.ModuleTypeUefiDriver:\r
+                       case CommonDefinition.ModuleTypeUefiApplication:\r
+                               fileBuffer.append("  Status = ");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
+                               break;\r
+            default:\r
+                EdkLog.log(EdkLog.EDK_INFO,"Autogen don't know how to deal with module type -"+ moduleType + " !");\r
+                       }\r
+                       fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+               }\r
+               fileBuffer.append("}\r\n");\r
+       }\r
+\r
+       /**\r
+        * LibDestructorToAutogenc\r
+        * \r
+        * This function writes library destructor list to AutoGen.c. The library\r
+        * destructor's parameter and return value depend on module type.\r
+        * \r
+        * @param libInstanceList\r
+        *            List of library destructor name.\r
+        * @param moduleType\r
+        *            Module type.\r
+        * @param fileBuffer\r
+        *            String buffer for AutoGen.c\r
+        * @throws Exception\r
+        */\r
+       void LibDestructorToAutogenC(List<String> libInstanceList,\r
+                       String moduleType, StringBuffer fileBuffer) throws Exception {\r
+               boolean isFirst = true;\r
+               for (int i = 0; i < libInstanceList.size(); i++) {\r
+                       switch (CommonDefinition.getModuleType(moduleType)) {\r
+                       case CommonDefinition.ModuleTypeBase:\r
+                               fileBuffer.append("RETURN_STATUS\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  VOID\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+                       case CommonDefinition.ModuleTypePeiCore:\r
+                       case CommonDefinition.ModuleTypePeim:\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                               fileBuffer\r
+                                               .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+                       case CommonDefinition.ModuleTypeDxeCore:\r
+                       case CommonDefinition.ModuleTypeDxeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                       case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                       case CommonDefinition.ModuleTypeUefiDriver:\r
+                       case CommonDefinition.ModuleTypeUefiApplication:\r
+                               fileBuffer.append("EFI_STATUS\r\n");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                               fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                               fileBuffer.append("  );\r\n");\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Write ProcessLibraryDestructor list to autogen.c\r
+               //\r
+               switch (CommonDefinition.getModuleType(moduleType)) {\r
+               case CommonDefinition.ModuleTypeBase:\r
+               case CommonDefinition.ModuleTypePeiCore:\r
+               case CommonDefinition.ModuleTypePeim:\r
+                       break;\r
+               case CommonDefinition.ModuleTypeDxeCore:\r
+               case CommonDefinition.ModuleTypeDxeDriver:\r
+               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+               case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+               case CommonDefinition.ModuleTypeDxeSalDriver:\r
+               case CommonDefinition.ModuleTypeUefiDriver:\r
+               case CommonDefinition.ModuleTypeUefiApplication:\r
+                       fileBuffer.append("VOID\r\n");\r
+                       fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
+                       fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                       fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                       fileBuffer.append("  )\r\n");\r
+                       fileBuffer.append("{\r\n");\r
             //\r
             //\r
-            // Write DriverExitBootServices entry point array.\r
+            // If no library destructor function, return EFI_SUCCESS.\r
             //\r
             //\r
-            fileBuffer\r
-                    .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
-            for (i = 0; i < exitBootList.length; i++) {\r
-                if (exitBootList[i].equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-\r
-                if (i == 0) {\r
-                    fileBuffer.append("\r\n  ");\r
-                } else {\r
-                    fileBuffer.append(",\r\n  ");\r
-                }\r
-                fileBuffer.append(exitBootList[i]);\r
-            }\r
-            if (Count == 0) {\r
-                fileBuffer.append("\r\n  NULL");\r
-            }\r
-            fileBuffer.append("\r\n};\r\n\r\n");\r
-        }\r
-\r
-    }\r
+            \r
+                       for (int i = 0; i < libInstanceList.size(); i++) {\r
+                               if (isFirst) {\r
+                                       fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
+                    fileBuffer.append("  Status = EFI_SUCCESS;\r\n");\r
+                                       fileBuffer.append("\r\n");\r
+                                       isFirst = false;\r
+                               }\r
+                               fileBuffer.append("  Status = ");\r
+                               fileBuffer.append(libInstanceList.get(i));\r
+                               fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
+                               fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+                       }\r
+                       fileBuffer.append("}\r\n");\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * ExternsDriverBindingToAutoGenC\r
+        * \r
+        * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
+        * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
+        * \r
+        * @param fileBuffer\r
+        *            String buffer for AutoGen.c\r
+        */\r
+       void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
+                       throws BuildException {\r
+\r
+               //\r
+               // Check what <extern> contains. And the number of following elements\r
+               // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
+               // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
+               //\r
+\r
+               String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
+\r
+               //\r
+               // If component name protocol,component configuration protocol,\r
+               // component diagnostic protocol is not null or empty, check\r
+               // if every one have the same number of the driver binding protocol.\r
+               //\r
+               if (drvBindList == null || drvBindList.length == 0) {\r
+                       return;\r
+               }\r
+\r
+               String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
+               String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
+               String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
+\r
+               int BitMask = 0;\r
+\r
+               //\r
+               // Write driver binding protocol extern to autogen.c\r
+               //\r
+               for (int i = 0; i < drvBindList.length; i++) {\r
+                       fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
+                       fileBuffer.append(drvBindList[i]);\r
+                       fileBuffer.append(";\r\n");\r
+               }\r
+\r
+               //\r
+               // Write component name protocol extern to autogen.c\r
+               //\r
+               if (compNamList != null && compNamList.length != 0) {\r
+                       if (drvBindList.length != compNamList.length) {\r
+                               throw new BuildException(\r
+                                               "Different number of Driver Binding and Component Name protocols!");\r
+                       }\r
+\r
+                       BitMask |= 0x01;\r
+                       for (int i = 0; i < compNamList.length; i++) {\r
+                               fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
+                               fileBuffer.append(compNamList[i]);\r
+                               fileBuffer.append(";\r\n");\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Write driver configration protocol extern to autogen.c\r
+               //\r
+               if (compConfList != null && compConfList.length != 0) {\r
+                       if (drvBindList.length != compConfList.length) {\r
+                               throw new BuildException(\r
+                                               "Different number of Driver Binding and Driver Configuration protocols!");\r
+                       }\r
+\r
+                       BitMask |= 0x02;\r
+                       for (int i = 0; i < compConfList.length; i++) {\r
+                               fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
+                               fileBuffer.append(compConfList[i]);\r
+                               fileBuffer.append(";\r\n");\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Write driver dignastic protocol extern to autogen.c\r
+               //\r
+               if (compDiagList != null && compDiagList.length != 0) {\r
+                       if (drvBindList.length != compDiagList.length) {\r
+                               throw new BuildException(\r
+                                               "Different number of Driver Binding and Driver Configuration protocols!");\r
+                       }\r
+\r
+                       BitMask |= 0x04;\r
+                       for (int i = 0; i < compDiagList.length; i++) {\r
+                               fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
+                               fileBuffer.append(compDiagList[i]);\r
+                               fileBuffer.append(";\r\n");\r
+                       }\r
+               }\r
+\r
+               //\r
+               // Write driver module protocol bitmask.\r
+               //\r
+               fileBuffer\r
+                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverModelProtocolBitmask = ");\r
+               fileBuffer.append(Integer.toString(BitMask));\r
+               fileBuffer.append(";\r\n");\r
+\r
+               //\r
+               // Write driver module protocol list entry\r
+               //\r
+               fileBuffer\r
+                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN  _gDriverModelProtocolListEntries = ");\r
+\r
+               fileBuffer.append(Integer.toString(drvBindList.length));\r
+               fileBuffer.append(";\r\n");\r
+\r
+               //\r
+               // Write drive module protocol list to autogen.c\r
+               //\r
+               fileBuffer\r
+                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {");\r
+               for (int i = 0; i < drvBindList.length; i++) {\r
+                       if (i != 0) {\r
+                               fileBuffer.append(",");\r
+                       }\r
+                       fileBuffer.append("\r\n {\r\n");\r
+                       fileBuffer.append("  &");\r
+                       fileBuffer.append(drvBindList[i]);\r
+                       fileBuffer.append(", \r\n");\r
+\r
+                       if (compNamList != null) {\r
+                               fileBuffer.append("  &");\r
+                               fileBuffer.append(compNamList[i]);\r
+                               fileBuffer.append(", \r\n");\r
+                       } else {\r
+                               fileBuffer.append("  NULL, \r\n");\r
+                       }\r
+\r
+                       if (compConfList != null) {\r
+                               fileBuffer.append("  &");\r
+                               fileBuffer.append(compConfList[i]);\r
+                               fileBuffer.append(", \r\n");\r
+                       } else {\r
+                               fileBuffer.append("  NULL, \r\n");\r
+                       }\r
+\r
+                       if (compDiagList != null) {\r
+                               fileBuffer.append("  &");\r
+                               fileBuffer.append(compDiagList[i]);\r
+                               fileBuffer.append(", \r\n");\r
+                       } else {\r
+                               fileBuffer.append("  NULL, \r\n");\r
+                       }\r
+                       fileBuffer.append("  }");\r
+               }\r
+               fileBuffer.append("\r\n};\r\n");\r
+       }\r
+\r
+       /**\r
+        * ExternCallBackToAutoGenC\r
+        * \r
+        * This function adds <SetVirtualAddressMapCallBack> and\r
+        * <ExitBootServicesCallBack> infomation to AutoGen.c\r
+        * \r
+        * @param fileBuffer\r
+        *            String buffer for AutoGen.c\r
+        * @throws BuildException\r
+        */\r
+       void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
+                       throws BuildException {\r
+               String[] setVirtualList = SurfaceAreaQuery\r
+                               .getSetVirtualAddressMapCallBackArray();\r
+               String[] exitBootList = SurfaceAreaQuery\r
+                               .getExitBootServicesCallBackArray();\r
+               String moduleType = SurfaceAreaQuery.getModuleType();\r
+               boolean UefiOrDxeModule = false;\r
+               int Count = 0;\r
+               int i;\r
+\r
+               switch (CommonDefinition.getModuleType(moduleType)) {\r
+               case CommonDefinition.ModuleTypeDxeDriver:\r
+               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+               case CommonDefinition.ModuleTypeDxeSalDriver:\r
+               case CommonDefinition.ModuleTypeUefiDriver:\r
+               case CommonDefinition.ModuleTypeUefiApplication:\r
+                       //\r
+                       // Entry point lib for these module types needs to know the count\r
+                       // of entryPoint.\r
+                       //\r
+                       UefiOrDxeModule = true;\r
+                       fileBuffer\r
+                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
+\r
+                       //\r
+                       // If the list is not valid or has no entries set count to zero else\r
+                       // set count to the number of valid entries\r
+                       //\r
+                       Count = 0;\r
+                       if (setVirtualList != null) {\r
+                               for (i = 0; i < setVirtualList.length; i++) {\r
+                                       if (setVirtualList[i].equalsIgnoreCase("")) {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               Count = i;\r
+                       }\r
+\r
+                       fileBuffer.append(Integer.toString(Count));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+                       break;\r
+               default:\r
+                       break;\r
+               }\r
+\r
+               if (setVirtualList == null) {\r
+                       if (UefiOrDxeModule) {\r
+                               //\r
+                               // No data so make a NULL list\r
+                               //\r
+                               fileBuffer\r
+                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
+                               fileBuffer.append("  NULL\r\n");\r
+                               fileBuffer.append("};\r\n\r\n");\r
+                       }\r
+               } else {\r
+                       //\r
+                       // Write SetVirtualAddressMap function definition.\r
+                       //\r
+                       for (i = 0; i < setVirtualList.length; i++) {\r
+                               if (setVirtualList[i].equalsIgnoreCase("")) {\r
+                                       break;\r
+                               }\r
+                               fileBuffer.append("VOID\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append(setVirtualList[i]);\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
+                               fileBuffer.append("  IN VOID       *Context\r\n");\r
+                               fileBuffer.append("  );\r\n\r\n");\r
+                       }\r
+\r
+                       //\r
+                       // Write SetVirtualAddressMap entry point array.\r
+                       //\r
+                       fileBuffer\r
+                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
+                       for (i = 0; i < setVirtualList.length; i++) {\r
+                               if (setVirtualList[i].equalsIgnoreCase("")) {\r
+                                       break;\r
+                               }\r
+\r
+                               if (i == 0) {\r
+                                       fileBuffer.append("\r\n  ");\r
+                               } else {\r
+                                       fileBuffer.append(",\r\n  ");\r
+                               }\r
+\r
+                               fileBuffer.append(setVirtualList[i]);\r
+                       }\r
+                       //\r
+                       //  If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER\r
+                       //  UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of \r
+                       //  _gDriverSetVirtualAddressMapEvent list. \r
+                       //\r
+                       if (!UefiOrDxeModule) {\r
+                               fileBuffer.append(",\r\n  NULL");\r
+                       }\r
+                       fileBuffer.append("\r\n};\r\n\r\n");\r
+               }\r
+\r
+               if (UefiOrDxeModule) {\r
+                       //\r
+                       // Entry point lib for these module types needs to know the count.\r
+                       //\r
+                       fileBuffer\r
+                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverExitBootServicesEventCount = ");\r
+\r
+                       //\r
+                       // If the list is not valid or has no entries set count to zero else\r
+                       // set count to the number of valid entries.\r
+                       //\r
+                       Count = 0;\r
+                       if (exitBootList != null) {\r
+                               if (setVirtualList != null) {\r
+                                       for (i = 0; i < exitBootList.length; i++) {\r
+                                               if (exitBootList[i].equalsIgnoreCase("")) {\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       Count = i;\r
+                               }\r
+                       }\r
+                       fileBuffer.append(Integer.toString(Count));\r
+                       fileBuffer.append(";\r\n\r\n");\r
+               }\r
+\r
+               if (exitBootList == null) {\r
+                       if (UefiOrDxeModule) {\r
+                               //\r
+                               // No data so make a NULL list.\r
+                               //\r
+                               fileBuffer\r
+                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
+                               fileBuffer.append("  NULL\r\n");\r
+                               fileBuffer.append("};\r\n\r\n");\r
+                       }\r
+               } else {\r
+                       //\r
+                       // Write DriverExitBootServices function definition.\r
+                       //\r
+                       for (i = 0; i < exitBootList.length; i++) {\r
+                               if (exitBootList[i].equalsIgnoreCase("")) {\r
+                                       break;\r
+                               }\r
+\r
+                               fileBuffer.append("VOID\r\n");\r
+                               fileBuffer.append("EFIAPI\r\n");\r
+                               fileBuffer.append(exitBootList[i]);\r
+                               fileBuffer.append(" (\r\n");\r
+                               fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
+                               fileBuffer.append("  IN VOID       *Context\r\n");\r
+                               fileBuffer.append("  );\r\n\r\n");\r
+                       }\r
+\r
+                       //\r
+                       // Write DriverExitBootServices entry point array.\r
+                       //\r
+                       fileBuffer\r
+                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
+                       for (i = 0; i < exitBootList.length; i++) {\r
+                               if (exitBootList[i].equalsIgnoreCase("")) {\r
+                                       break;\r
+                               }\r
+\r
+                               if (i == 0) {\r
+                                       fileBuffer.append("\r\n  ");\r
+                               } else {\r
+                                       fileBuffer.append(",\r\n  ");\r
+                               }\r
+                               fileBuffer.append(exitBootList[i]);\r
+                       }\r
+                       if (!UefiOrDxeModule) {\r
+                               fileBuffer.append(",\r\n  NULL");\r
+                       }\r
+                       fileBuffer.append("\r\n};\r\n\r\n");\r
+               }\r
+\r
+       }\r
 \r
 }
\ No newline at end of file
 \r
 }
\ No newline at end of file
index f449cb3a7c7310fa73818444b29ee65ecc5ffc53..ad245edd172a11b7033a8ba515c9bd6a1c0ecd84 100644 (file)
  **/\r
 package org.tianocore.build.autogen;\r
 \r
  **/\r
 package org.tianocore.build.autogen;\r
 \r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+\r
 /**\r
   CommonDefinition\r
   \r
 /**\r
   CommonDefinition\r
   \r
@@ -149,7 +153,7 @@ public class CommonDefinition {
                     new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
                     new MyEnum("PEIM", ModuleTypePeim),\r
                     new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
                     new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
                     new MyEnum("PEIM", ModuleTypePeim),\r
                     new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
-                    new MyEnum("DXE_DRIVER", ModuleTypeDxeRuntimeDriver),\r
+                    new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
                     new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
                     new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
                     new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
                     new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
                     new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
                     new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
@@ -315,4 +319,32 @@ public class CommonDefinition {
         }\r
     }\r
     \r
         }\r
     }\r
     \r
+    /**\r
+     * Remove deuplicat string in list\r
+     * \r
+     * This function is to duplicat string in list\r
+     * \r
+     * @param String[]\r
+     *            String list.\r
+     * @return String[] String list which remove the duplicate string.\r
+     */\r
+    public static String[] remDupString (String[] orgList){\r
+        Set<String> strList = new HashSet<String>();\r
+        String[] desList ;\r
+        if (orgList == null){\r
+            return new String[0];\r
+        }\r
+        for (int i = 0; i < orgList.length; i++){\r
+            strList.add(orgList[i]);\r
+        }\r
+        desList = new String[strList.size()];\r
+        Iterator item = strList.iterator();\r
+        int index = 0;\r
+        while (item.hasNext()){\r
+            desList[index] = (String)item.next();\r
+            index++;\r
+        }\r
+        return desList;\r
+    }\r
+    \r
 }
\ No newline at end of file
 }
\ No newline at end of file
index ac75ca8f9d75c62c3d8a43a66857af9eba3e1663..7ae058059197b3a4fe3d5012f1a828e724f6e8c9 100644 (file)
@@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/   \r
 package org.tianocore.build.exception;\r
 \r
 **/   \r
 package org.tianocore.build.exception;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 \r
 /**\r
   The class handle the exception throwed by entity class.\r
 \r
 /**\r
   The class handle the exception throwed by entity class.\r
@@ -35,6 +35,6 @@ public class GenBuildException extends EdkException {
         super();\r
     }\r
     public GenBuildException(Exception e, String message){\r
         super();\r
     }\r
     public GenBuildException(Exception e, String message){\r
-//        super(e, message);\r
+        super(e, message);\r
     }\r
 }\r
     }\r
 }\r
index 3ab2fcf448e81f8134a9212cfea2c4805b6f3c86..2daa8716b235be1c787e858deb731b3d8a29cbf3 100644 (file)
@@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/   \r
 package org.tianocore.build.exception;\r
 \r
 **/   \r
 package org.tianocore.build.exception;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 \r
 /**\r
   The class handle the exception throwed by entity class.\r
 \r
 /**\r
   The class handle the exception throwed by entity class.\r
@@ -36,6 +36,6 @@ public class TianoToolsException extends EdkException {
     }\r
     \r
     public TianoToolsException (Exception e, String message){\r
     }\r
     \r
     public TianoToolsException (Exception e, String message){\r
-//        super(e, message);\r
+        super(e, message);\r
     }\r
 }\r
     }\r
 }\r
index 59bb47faa423f88b840c24218369a6c9ac661348..5d829c9f2258d4341a7752a6528c9b6ac235a7f3 100644 (file)
@@ -33,16 +33,19 @@ import org.apache.tools.ant.taskdefs.Ant;
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.OutputManager;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.pcd.action.ActionMessage;\r
+import org.tianocore.build.pcd.action.CollectPCDAction;\r
+import org.tianocore.build.pcd.exception.EntityException;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
+import org.tianocore.exception.EdkException;\r
 \r
 /**\r
   <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework\r
 \r
 /**\r
   <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework\r
@@ -145,6 +148,18 @@ public class FpdParserTask extends Task {
         //\r
         parseFpdFile();\r
         \r
         //\r
         parseFpdFile();\r
         \r
+        //\r
+        // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
+        //\r
+        try {\r
+            System.out.println("Begin PCD collecttion!");\r
+            CollectPCDAction ca = new CollectPCDAction();\r
+            ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);\r
+            System.out.println("End PCD collection!"); \r
+        } catch (Exception e){\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+        \r
         //\r
         // Prepare BUILD_DIR\r
         //\r
         //\r
         // Prepare BUILD_DIR\r
         //\r
@@ -187,6 +202,7 @@ public class FpdParserTask extends Task {
         //\r
         // Ant call ${PLATFORM}_build.xml\r
         //\r
         //\r
         // Ant call ${PLATFORM}_build.xml\r
         //\r
+        \r
         Ant ant = new Ant();\r
         ant.setProject(getProject());\r
         ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
         Ant ant = new Ant();\r
         ant.setProject(getProject());\r
         ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
@@ -391,7 +407,7 @@ public class FpdParserTask extends Task {
     **/\r
     private void parseModuleSAFiles() throws EdkException{\r
         Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
     **/\r
     private void parseModuleSAFiles() throws EdkException{\r
         Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
-        System.out.println("Nubmer: ##" + moduleSAs.size());\r
+\r
         //\r
         // For every Module lists in FPD file.\r
         //\r
         //\r
         // For every Module lists in FPD file.\r
         //\r
index 99cccc364cc3211317f79f2894155cffa89a2d40..e843362c290266e95a76acc0348752daa26b06b0 100644 (file)
@@ -21,20 +21,21 @@ import org.apache.xmlbeans.XmlObject;
 import org.tianocore.DbPathAndFilename;\r
 import org.tianocore.FrameworkDatabaseDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument;\r
 import org.tianocore.DbPathAndFilename;\r
 import org.tianocore.FrameworkDatabaseDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.PcdBuildDefinitionDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
-import org.tianocore.build.exception.EdkException;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainConfig;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainConfig;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
-//import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
-//import org.tianocore.logger.EdkLog;\r
+import org.tianocore.exception.EdkException;\r
+import org.tianocore.logger.EdkLog;\r
 \r
 import java.io.File;\r
 import java.util.HashMap;\r
 \r
 import java.io.File;\r
 import java.util.HashMap;\r
@@ -130,7 +131,7 @@ public class GlobalData {
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
 \r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
 \r
-//    private static final MemoryDatabasseManager pcdDbManager = new MemoryDatabaseManager();\r
+    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
 \r
     \r
 \r
 \r
     \r
 \r
@@ -341,7 +342,7 @@ public class GlobalData {
         //\r
         // First part: get the MSA files info\r
         //\r
         //\r
         // First part: get the MSA files info\r
         //\r
-        doc = getNativeMsa(moduleId);\r
+        doc.putAll(getNativeMsa(moduleId));\r
         \r
         //\r
         // Second part: put build options\r
         \r
         //\r
         // Second part: put build options\r
@@ -413,6 +414,7 @@ public class GlobalData {
             msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r
             msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r
             msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
             msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r
             msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r
             msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
+            msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r
             return msaMap;\r
         }\r
         catch (Exception ex){\r
             return msaMap;\r
         }\r
         catch (Exception ex){\r
@@ -507,15 +509,16 @@ public class GlobalData {
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getGuid(PackageIdentification[] packages, String name)\r
+    public static String[] getGuid(List<PackageIdentification> packages, String name)\r
             throws BuildException {\r
         if (packages == null) {\r
             // throw Exception or not????\r
             return new String[0];\r
         }\r
         String[] result = null;\r
             throws BuildException {\r
         if (packages == null) {\r
             // throw Exception or not????\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the GUID\r
             //\r
             //\r
             // If find one package defined the GUID\r
             //\r
@@ -523,20 +526,22 @@ public class GlobalData {
                 return result;\r
             }\r
         }\r
                 return result;\r
             }\r
         }\r
+\r
         return null;\r
     }\r
 \r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
         return null;\r
     }\r
 \r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getPpiGuid(PackageIdentification[] packages,\r
+    public static String[] getPpiGuid(List<PackageIdentification> packages,\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the Ppi GUID\r
             //\r
             //\r
             // If find one package defined the Ppi GUID\r
             //\r
@@ -551,18 +556,19 @@ public class GlobalData {
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getProtocolGuid(PackageIdentification[] packages,\r
+    public static String[] getProtocolGuid(List<PackageIdentification> packages,\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the protocol GUID\r
             //\r
             //\r
             // If find one package defined the protocol GUID\r
             //\r
-            if ((result = spd.getProtocol(name)) != null) {\r
+            if ((result = spd.getProtocol(name))!= null){\r
                 return result;\r
             }\r
         }\r
                 return result;\r
             }\r
         }\r
@@ -750,52 +756,61 @@ public class GlobalData {
     //\r
     // for PCD\r
     //\r
     //\r
     // for PCD\r
     //\r
-//    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
-//        return pcdDbManager;\r
-//    }\r
+    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
+        return pcdDbManager;\r
+    }\r
 \r
     //\r
 \r
     //\r
-    // For PCD\r
+    // For PCD get tokenSpaceGUid\r
     //\r
     //\r
-    /**\r
-     * \r
-     * @param guidName\r
-     * @return\r
-     */\r
-//    public synchronized static String[] getGuidInfoGuid(String guidName) {\r
-//        String[] cNameGuid = null;\r
-//        Set set = spdTable.keySet();\r
-//        Iterator iter = set.iterator();\r
-//\r
-//        while (iter.hasNext()) {\r
-//            Spd spd = (Spd) spdTable.get(iter.next());\r
-//            cNameGuid = spd.getGuidNameArray(guidName);\r
-//            if (cNameGuid != null) {\r
-//                break;\r
-//            }\r
-//        }\r
-//        return cNameGuid;\r
-//    }\r
+    public synchronized static String[] getGuidInfoFromCname(String cName){\r
+        String cNameGuid[] = null;\r
+        String guid = null;\r
+        Set set = spdTable.keySet();\r
+        Iterator iter = set.iterator();\r
+        \r
+        while (iter.hasNext()){\r
+            Spd spd = (Spd) spdTable.get(iter.next());\r
+            guid = spd.getGuidFromCname(cName);\r
+            if (guid != null){\r
+                cNameGuid[0] = new String(cName);\r
+                cNameGuid[1] = new String(guid);\r
+                break;\r
+            }\r
+        }\r
+        return cNameGuid;\r
+    }\r
 \r
     //\r
     // For PCD\r
     //\r
 \r
     //\r
     // For PCD\r
     //\r
-//    public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r
-//            String xmlObjectName) {\r
-//        Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
-//        Iterator item = fpdModuleSASet.iterator();\r
-//\r
-//        Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
-//        Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
-//        FpdModuleIdentification moduleId;\r
-//        while (item.hasNext()) {\r
-//            moduleId = (FpdModuleIdentification) item.next();\r
-//            SANode = fpdModuleSA.get(item.next());\r
-//            SAPcdBuildDef.put(moduleId,\r
-//                    (PcdBuildDefinitionDocument.PcdBuildDefinition) SANode\r
-//                            .get(xmlObjectName));\r
-//        }\r
-//        return SAPcdBuildDef;\r
-//    }\r
+    public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r
+            String xmlObjectName) {\r
+        Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
+        Iterator item = fpdModuleSASet.iterator();\r
+        \r
+\r
+        Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
+        Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
+        FpdModuleIdentification moduleId;\r
+        while (item.hasNext()) {\r
+            \r
+            moduleId = (FpdModuleIdentification) item.next();\r
+            SANode = fpdModuleSA.get(moduleId);\r
+            try{\r
+                if (SANode.get(xmlObjectName)!= null){\r
+                    SAPcdBuildDef.put(moduleId,\r
+                            (XmlObject) SANode\r
+                                    .get(xmlObjectName));\r
+\r
+                }\r
+                            \r
+                \r
+            } catch (Exception e){\r
+                EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r
+            }\r
+            }\r
+        return SAPcdBuildDef;\r
+    }\r
 }\r
 \r
 }\r
 \r
index ddc851dc70fce6a11aff4716550c31ef719c4dc0..3e09f58fba1864028d1476e45e336094c0dee665 100644 (file)
@@ -66,6 +66,12 @@ public class Spd {
     Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
 \r
     ///\r
     Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
 \r
     ///\r
+    /// Map of Guid info\r
+    /// Key: GuidCName\r
+    /// value: String Guid's GUID\r
+    ///\r
+    Map<String, String> guidCnameInfo = new HashMap<String, String>();\r
+    \r
     /// Map of library class and its exposed header file.\r
     /// Key : library class name\r
     /// value : library class corresponding header file\r
     /// Map of library class and its exposed header file.\r
     /// Key : library class name\r
     /// value : library class corresponding header file\r
@@ -140,7 +146,7 @@ public class Spd {
                 // Change path seperator to system-dependent path separator\r
                 //\r
                 File file = new File (header);\r
                 // Change path seperator to system-dependent path separator\r
                 //\r
                 File file = new File (header);\r
-                header = file.getParent();\r
+                header = file.getPath();\r
                 packageHeaderInfo.put(moduleType, header);\r
             }\r
             \r
                 packageHeaderInfo.put(moduleType, header);\r
             }\r
             \r
@@ -149,6 +155,17 @@ public class Spd {
             //\r
             guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());\r
             \r
             //\r
             guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());\r
             \r
+            //\r
+            // For Pcd get TokenSpaceGuid\r
+            //\r
+            Set<String> key = guidInfo.keySet();\r
+            Iterator item = key.iterator();\r
+            String [] nameValue = new String[2];\r
+            while(item.hasNext()){\r
+                nameValue = guidInfo.get(item.next());\r
+                guidCnameInfo.put(nameValue[0], nameValue[1]);\r
+            }\r
+            \r
             //\r
             // initialize PPI info\r
             //\r
             //\r
             // initialize PPI info\r
             //\r
@@ -220,6 +237,13 @@ public class Spd {
         return guidInfo.get(guidName);\r
     }\r
 \r
         return guidInfo.get(guidName);\r
     }\r
 \r
+    /**\r
+     * return Guid Value. \r
+     */\r
+    public String getGuidFromCname(String cName){\r
+        return guidCnameInfo.get(cName);\r
+    }\r
+    \r
     /**\r
      getLibClassInclude \r
      \r
     /**\r
      getLibClassInclude \r
      \r
@@ -246,17 +270,5 @@ public class Spd {
         return packageHeaderInfo.get(moduleType);\r
     }\r
     \r
         return packageHeaderInfo.get(moduleType);\r
     }\r
     \r
-    /**\r
-           getGuidNameArray\r
-    \r
-           This function is to get the GUID's CName and it's GUID according to\r
-           GUID's name\r
-    \r
-           @param   guidName     Name of GUID\r
-           @return               CName and GUID.\r
-         **/\r
-         public String[] getGuidNameArray(String guidName) {\r
-             return this.guidInfo.get(guidName);\r
-         }\r
 \r
 }\r
 \r
 }\r
index 5eb14d4a4521d1c701c05b4efb515b03b0084671..956033993d523ad95abc7978508404b28166efae 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.xmlbeans.XmlNormalizedString;
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.xmlbeans.XmlString;\r
 import org.tianocore.BuildOptionsDocument;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.xmlbeans.XmlString;\r
 import org.tianocore.BuildOptionsDocument;\r
+import org.tianocore.CNameType;\r
 import org.tianocore.DataIdDocument;\r
 import org.tianocore.ExternsDocument;\r
 import org.tianocore.FileNameConvention;\r
 import org.tianocore.DataIdDocument;\r
 import org.tianocore.ExternsDocument;\r
 import org.tianocore.FileNameConvention;\r
@@ -48,9 +49,11 @@ import org.tianocore.OptionDocument;
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.PackageDependenciesDocument;\r
 import org.tianocore.PackageHeadersDocument;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.PackageDependenciesDocument;\r
 import org.tianocore.PackageHeadersDocument;\r
+import org.tianocore.PcdCodedDocument;\r
 import org.tianocore.PlatformDefinitionsDocument;\r
 import org.tianocore.PpiDeclarationsDocument;\r
 import org.tianocore.ProtocolDeclarationsDocument;\r
 import org.tianocore.PlatformDefinitionsDocument;\r
 import org.tianocore.PpiDeclarationsDocument;\r
 import org.tianocore.ProtocolDeclarationsDocument;\r
+import org.tianocore.Sentence;\r
 import org.tianocore.SpdHeaderDocument;\r
 import org.tianocore.SupportedArchitectures;\r
 import org.tianocore.FilenameDocument.Filename;\r
 import org.tianocore.SpdHeaderDocument;\r
 import org.tianocore.SupportedArchitectures;\r
 import org.tianocore.FilenameDocument.Filename;\r
@@ -63,6 +66,7 @@ import org.tianocore.build.id.ModuleIdentification;
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
+import org.tianocore.logger.EdkLog;\r
 \r
 /**\r
  * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
 \r
 /**\r
  * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
@@ -624,8 +628,7 @@ public class SurfaceAreaQuery {
             String[] entryPoints = new String[returns.length];\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
             String[] entryPoints = new String[returns.length];\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
-                entryPoints[i] = ((XmlNormalizedString) returns[i])\r
-                        .getStringValue();\r
+                entryPoints[i] = ((CNameType) returns[i]).getStringValue();\r
             }\r
 \r
             return entryPoints;\r
             }\r
 \r
             return entryPoints;\r
@@ -689,7 +692,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            xPath = new String[] { "/Protocol[@SupArchList='" + arch + "']" };\r
+            xPath = new String[] { "/Protocol" };\r
         }\r
 \r
         Object[] returns = get("Protocols", xPath);\r
         }\r
 \r
         Object[] returns = get("Protocols", xPath);\r
@@ -700,7 +703,10 @@ public class SurfaceAreaQuery {
 \r
         String[] protocolArray = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
 \r
         String[] protocolArray = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
-            protocolArray[i] = protocolList[i].getProtocolCName();\r
+            List<String> archList = protocolList[i].getSupArchList();\r
+            if (archList == null || archList.contains(arch)){\r
+                protocolArray[i] = protocolList[i].getProtocolCName(); \r
+            }\r
         }\r
         return protocolArray;\r
     }\r
         }\r
         return protocolArray;\r
     }\r
@@ -720,8 +726,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            xPath = new String[] { "/ProtocolNotify[@SupArchList='" + arch\r
-                    + "']" };\r
+            xPath = new String[] { "/ProtocolNotify" };\r
         }\r
 \r
         Object[] returns = get("Protocols", xPath);\r
         }\r
 \r
         Object[] returns = get("Protocols", xPath);\r
@@ -731,7 +736,11 @@ public class SurfaceAreaQuery {
 \r
         String[] protocolNotifyList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
 \r
         String[] protocolNotifyList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
-            protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();\r
+            List<String> archList = ((ProtocolNotify) returns[i]).getSupArchList();\r
+            if (archList == null || archList.contains(arch)){\r
+                protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();\r
+            }\r
+            \r
         }\r
 \r
         return protocolNotifyList;\r
         }\r
 \r
         return protocolNotifyList;\r
@@ -790,7 +799,7 @@ public class SurfaceAreaQuery {
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
             String[] stringArray = new String[returns.length];\r
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
             String[] stringArray = new String[returns.length];\r
-            XmlNormalizedString[] doc = (XmlNormalizedString[]) returns;\r
+            CNameType[] doc = (CNameType[]) returns;\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 stringArray[i] = doc[i].getStringValue();\r
 \r
             for (int i = 0; i < returns.length; ++i) {\r
                 stringArray[i] = doc[i].getStringValue();\r
@@ -834,7 +843,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            xPath = new String[] { "/PpiNotify[@SupArchList='" + arch + "']" };\r
+            xPath = new String[] { "/PpiNotify" };\r
         }\r
 \r
         Object[] returns = get("PPIs", xPath);\r
         }\r
 \r
         Object[] returns = get("PPIs", xPath);\r
@@ -844,7 +853,11 @@ public class SurfaceAreaQuery {
 \r
         String[] ppiNotifyList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
 \r
         String[] ppiNotifyList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
-            ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();\r
+            List<String> archList = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getSupArchList();\r
+            if (archList == null || archList.contains(arch)){\r
+                ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();    \r
+            }\r
+            \r
         }\r
 \r
         return ppiNotifyList;\r
         }\r
 \r
         return ppiNotifyList;\r
@@ -869,7 +882,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            archXpath = "/PpiNotify[@SupArchList='" + arch + "']";\r
+            archXpath = "/PpiNotify";\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/PpiNotify[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/PpiNotify[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
@@ -906,7 +919,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            xPath = new String[] { "/Ppi[@SupArchList='" + arch + "']" };\r
+            xPath = new String[] { "/Ppi" };\r
         }\r
 \r
         Object[] returns = get("PPIs", xPath);\r
         }\r
 \r
         Object[] returns = get("PPIs", xPath);\r
@@ -916,7 +929,11 @@ public class SurfaceAreaQuery {
 \r
         String[] ppiList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
 \r
         String[] ppiList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
-            ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();\r
+            List<String> archList = ((PPIsDocument.PPIs.Ppi) returns[i]).getSupArchList();\r
+            if (archList == null || archList.contains(arch)){\r
+                ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();    \r
+            }\r
+            \r
         }\r
         return ppiList;\r
     }\r
         }\r
         return ppiList;\r
     }\r
@@ -940,7 +957,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            archXpath = "/Ppi[@SupArchList='" + arch + "']";\r
+            archXpath = "/Ppi";\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/Ppi[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/Ppi[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
@@ -975,9 +992,9 @@ public class SurfaceAreaQuery {
         String[] xPath;\r
 \r
         if (arch == null || arch.equals("")) {\r
         String[] xPath;\r
 \r
         if (arch == null || arch.equals("")) {\r
-            xPath = new String[] { "/GuidName" };\r
+            xPath = new String[] { "/GuidCNames" };\r
         } else {\r
         } else {\r
-            xPath = new String[] { "/GuidName[@SupArchList='" + arch + "']" };\r
+            xPath = new String[] { "/GuidCNames" };\r
         }\r
 \r
         Object[] returns = get("Guids", xPath);\r
         }\r
 \r
         Object[] returns = get("Guids", xPath);\r
@@ -986,7 +1003,11 @@ public class SurfaceAreaQuery {
         }\r
         String[] guidList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
         }\r
         String[] guidList = new String[returns.length];\r
         for (int i = 0; i < returns.length; i++) {\r
-            guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();\r
+            List<String> archList = ((GuidsDocument.Guids.GuidCNames) returns[i]).getSupArchList();\r
+            if (archList == null || archList.contains(arch)){\r
+                guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();    \r
+            }\r
+            \r
         }\r
         return guidList;\r
 \r
         }\r
         return guidList;\r
 \r
@@ -1009,7 +1030,7 @@ public class SurfaceAreaQuery {
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
         if (arch == null || arch.equals("")) {\r
             return new String[0];\r
         } else {\r
-            archXpath = "/GuidEntry[@SupArchList='" + arch + "']";\r
+            archXpath = "/GuidEntry";\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/GuidEntry[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
             if (usage != null && !usage.equals("")) {\r
                 usageXpath = "/GuidEntry[@Usage='" + arch + "']";\r
                 xPath = new String[] { archXpath, usageXpath };\r
@@ -1096,7 +1117,7 @@ public class SurfaceAreaQuery {
         String[] strings = new String[returns.length];\r
         for (int i = 0; i < returns.length; ++i) {\r
             // TBD\r
         String[] strings = new String[returns.length];\r
         for (int i = 0; i < returns.length; ++i) {\r
             // TBD\r
-            // strings[i] = ((CName) returns[i]).getStringValue();\r
+             strings[i] = ((CNameType) returns[i]).getStringValue();\r
         }\r
 \r
         return strings;\r
         }\r
 \r
         return strings;\r
@@ -1113,8 +1134,8 @@ public class SurfaceAreaQuery {
 \r
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
 \r
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
-            // CName constructor = (CName) returns[0];\r
-            // return constructor.getStringValue();\r
+            CNameType constructor = ((CNameType) returns[0]);\r
+            return constructor.getStringValue();\r
         }\r
 \r
         return null;\r
         }\r
 \r
         return null;\r
@@ -1131,8 +1152,11 @@ public class SurfaceAreaQuery {
 \r
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
 \r
         Object[] returns = get("Externs", xPath);\r
         if (returns != null && returns.length > 0) {\r
-            // CName destructor = (CName) returns[0];\r
-            // return destructor.getStringValue();\r
+            //\r
+            // Only support one Destructor function.\r
+            //\r
+             CNameType destructor = (CNameType) returns[0];\r
+             return destructor.getStringValue();\r
         }\r
 \r
         return null;\r
         }\r
 \r
         return null;\r
@@ -1646,9 +1670,8 @@ public class SurfaceAreaQuery {
 \r
         String[] specificationList = new String[queryResult.length];\r
         for (int i = 0; i < queryResult.length; i++) {\r
 \r
         String[] specificationList = new String[queryResult.length];\r
         for (int i = 0; i < queryResult.length; i++) {\r
-            // specificationList[i] = ((SpecificationDocument.Specification)\r
-            // queryResult[i])\r
-            // .getStringValue();\r
+             specificationList[i] = ((Sentence)queryResult[i])\r
+             .getStringValue();\r
         }\r
         return specificationList;\r
     }\r
         }\r
         return specificationList;\r
     }\r
@@ -1765,6 +1788,9 @@ public class SurfaceAreaQuery {
             guidPair[0] = entry.getCName();\r
             guidPair[1] = entry.getGuidValue();\r
             guidDeclMap.put(entry.getName(), guidPair);\r
             guidPair[0] = entry.getCName();\r
             guidPair[1] = entry.getGuidValue();\r
             guidDeclMap.put(entry.getName(), guidPair);\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[0]);\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[1]);\r
         }\r
         return guidDeclMap;\r
     }\r
         }\r
         return guidDeclMap;\r
     }\r
@@ -1793,6 +1819,9 @@ public class SurfaceAreaQuery {
             protocolPair[0] = entry.getCName();\r
             protocolPair[1] = entry.getGuidValue();\r
             protoclMap.put(entry.getName(), protocolPair);\r
             protocolPair[0] = entry.getCName();\r
             protocolPair[1] = entry.getGuidValue();\r
             protoclMap.put(entry.getName(), protocolPair);\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[0]);\r
+            EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[1]);\r
         }\r
         return protoclMap;\r
     }\r
         }\r
         return protoclMap;\r
     }\r
@@ -1885,4 +1914,29 @@ public class SurfaceAreaQuery {
         return new ModuleSADocument.ModuleSA[0];\r
 \r
     }\r
         return new ModuleSADocument.ModuleSA[0];\r
 \r
     }\r
+    /**\r
+    Get name array of PCD in a module. In one module, token space\r
+    is same, and token name should not be conflicted.\r
+    \r
+    @return String[]\r
+ **/\r
+ public static String[] getModulePcdEntryNameArray() {\r
+     PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries  = null;\r
+     String[]            results;\r
+     int                 index;\r
+     String[]            xPath       = new String[] {"/PcdEntry"};\r
+     Object[]         returns     = get ("PcdCoded", xPath);\r
+     \r
+     if (returns == null) {\r
+         return new String[0];\r
+     }\r
+     \r
+     pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;\r
+     results    = new String[pcdEntries.length];\r
+     \r
+     for (index = 0; index < pcdEntries.length; index ++) {\r
+         results[index] = pcdEntries[index].getCName();\r
+     }\r
+     return results;\r
+ }\r
 }\r
 }\r
index 25799463e3d50e515776fb48352aef6e4d52cd52..8c91b2fe16372b64e9a6612d6ae0cb793770809c 100644 (file)
@@ -23,20 +23,36 @@ import java.io.FileReader;
 import java.io.IOException;\r
 import java.math.BigInteger;\r
 import java.util.ArrayList;\r
 import java.io.IOException;\r
 import java.math.BigInteger;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
 import java.util.Comparator;\r
 import java.util.HashMap;\r
 import java.util.Comparator;\r
 import java.util.HashMap;\r
+import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
 import java.util.UUID;\r
 import java.util.UUID;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
 \r
 import org.apache.xmlbeans.XmlException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.apache.xmlbeans.XmlException;\r
 import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r
 import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
 import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo;\r
 import org.tianocore.FrameworkModulesDocument;\r
 import org.tianocore.FrameworkModulesDocument;\r
-import org.tianocore.FrameworkPlatformDescriptionDocument;\r
+import org.tianocore.PcdDeclarationsDocument;\r
+import org.tianocore.PlatformSurfaceAreaDocument;\r
+import org.tianocore.PcdBuildDefinitionDocument;\r
+import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
 import org.tianocore.ModuleSADocument;\r
 import org.tianocore.ModuleSADocument;\r
+import org.tianocore.ModuleSADocument.ModuleSA;\r
+import org.tianocore.PackageSurfaceAreaDocument;\r
 import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
 import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.pcd.action.ActionMessage;\r
 import org.tianocore.build.pcd.entity.DynamicTokenValue;\r
 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.pcd.action.ActionMessage;\r
 import org.tianocore.build.pcd.entity.DynamicTokenValue;\r
 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
@@ -44,6 +60,7 @@ import org.tianocore.build.pcd.entity.SkuInstance;
 import org.tianocore.build.pcd.entity.Token;\r
 import org.tianocore.build.pcd.entity.UsageInstance;\r
 import org.tianocore.build.pcd.exception.EntityException;\r
 import org.tianocore.build.pcd.entity.Token;\r
 import org.tianocore.build.pcd.entity.UsageInstance;\r
 import org.tianocore.build.pcd.exception.EntityException;\r
+import org.tianocore.logger.EdkLog;\r
 import org.tianocore.ModuleTypeDef;\r
 \r
 class CStructTypeDeclaration {\r
 import org.tianocore.ModuleTypeDef;\r
 \r
 class CStructTypeDeclaration {\r
@@ -407,6 +424,7 @@ class GuidTable {
 \r
         Output.add("/* GuidTable */");\r
         Output.add("{");\r
 \r
         Output.add("/* GuidTable */");\r
         Output.add("{");\r
+\r
         if (al.size() == 0) {\r
             Output.add("\t" + getUuidCString(new UUID(0, 0)));\r
         }\r
         if (al.size() == 0) {\r
             Output.add("\t" + getUuidCString(new UUID(0, 0)));\r
         }\r
@@ -1824,12 +1842,25 @@ class PcdDatabase {
 }\r
 \r
 class ModuleInfo {\r
 }\r
 \r
 class ModuleInfo {\r
-    public ModuleSADocument.ModuleSA module;\r
-    public ModuleTypeDef.Enum        type;\r
+    private String                  type;\r
+    private FpdModuleIdentification moduleId;\r
+    private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef;\r
+    \r
+    \r
 \r
 \r
-    public ModuleInfo (ModuleSADocument.ModuleSA module, ModuleTypeDef.Enum type) {\r
-        this.module = module;\r
+    public ModuleInfo (FpdModuleIdentification moduleId, String type, XmlObject pcdDef) {\r
+        this.moduleId = moduleId;\r
         this.type   = type;\r
         this.type   = type;\r
+        this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
+    }\r
+    public String getModuleType (){\r
+       return this.type;\r
+    }\r
+    public FpdModuleIdentification getModuleId (){\r
+       return this.moduleId;\r
+    }\r
+    public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){\r
+       return this.pcdBuildDef;\r
     }\r
 }\r
 \r
     }\r
 }\r
 \r
@@ -1851,8 +1882,11 @@ public class CollectPCDAction {
     private int                   originalMessageLevel;\r
 \r
     /// Cache the fpd docment instance for private usage.\r
     private int                   originalMessageLevel;\r
 \r
     /// Cache the fpd docment instance for private usage.\r
-    private FrameworkPlatformDescriptionDocument fpdDocInstance;\r
-\r
+    private PlatformSurfaceAreaDocument fpdDocInstance;\r
+    \r
+    /// xmlObject name\r
+    private static String xmlObjectName = "PcdBuildDefinition"; \r
+       \r
     /**\r
       Set WorkspacePath parameter for this action class.\r
 \r
     /**\r
       Set WorkspacePath parameter for this action class.\r
 \r
@@ -1919,7 +1953,7 @@ public class CollectPCDAction {
       @throws  EntityException Exception indicate failed to execute this action.\r
       \r
     **/\r
       @throws  EntityException Exception indicate failed to execute this action.\r
       \r
     **/\r
-    private void execute() throws EntityException {\r
+    public void execute() throws EntityException {\r
         //\r
         // Get memoryDatabaseManager instance from GlobalData.\r
         // The memoryDatabaseManager should be initialized for whatever build\r
         //\r
         // Get memoryDatabaseManager instance from GlobalData.\r
         // The memoryDatabaseManager should be initialized for whatever build\r
@@ -1988,14 +2022,13 @@ public class CollectPCDAction {
         List<ModuleInfo>            allModules  = new ArrayList<ModuleInfo>();\r
         ModuleInfo                  current     = null;\r
         int                         index       = 0;\r
         List<ModuleInfo>            allModules  = new ArrayList<ModuleInfo>();\r
         ModuleInfo                  current     = null;\r
         int                         index       = 0;\r
-        org.tianocore.Components    components  = null;\r
         FrameworkModulesDocument.FrameworkModules fModules = null;\r
         ModuleSADocument.ModuleSA[]               modules  = null;\r
         HashMap<String, XmlObject>                map      = new HashMap<String, XmlObject>();\r
 \r
         if (fpdDocInstance == null) {\r
             try {\r
         FrameworkModulesDocument.FrameworkModules fModules = null;\r
         ModuleSADocument.ModuleSA[]               modules  = null;\r
         HashMap<String, XmlObject>                map      = new HashMap<String, XmlObject>();\r
 \r
         if (fpdDocInstance == null) {\r
             try {\r
-                fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
             } catch(IOException ioE) {\r
                 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
             } catch(IOException ioE) {\r
                 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
@@ -2004,14 +2037,28 @@ public class CollectPCDAction {
 \r
         }\r
 \r
 \r
         }\r
 \r
-        map.put("FrameworkPlatformDescription", fpdDocInstance);\r
-        SurfaceAreaQuery.setDoc(map); \r
-        modules = SurfaceAreaQuery.getFpdModuleSAs();\r
-        for (index = 0; index < modules.length; index ++) {\r
-            SurfaceAreaQuery.setDoc(GlobalData.getDoc(modules[index].getModuleName()));\r
-            allModules.add(new ModuleInfo(modules[index], \r
-                                          ModuleTypeDef.Enum.forString(SurfaceAreaQuery.getModuleType())));\r
-        }\r
+        //map.put("FrameworkPlatformDescription", fpdDocInstance);\r
+        //SurfaceAreaQuery.setDoc(map); \r
+        Map<FpdModuleIdentification,XmlObject>pcdBuildDef = GlobalData.getFpdModuleSaXmlObject(CollectPCDAction.xmlObjectName);\r
+        Set<FpdModuleIdentification> pcdBuildKeySet = pcdBuildDef.keySet();\r
+        Iterator item = pcdBuildKeySet.iterator();\r
+        while (item.hasNext()){\r
+               FpdModuleIdentification id = (FpdModuleIdentification)item.next();\r
+            try {\r
+                allModules.add(new ModuleInfo(id, id.getModule().getModuleType(),pcdBuildDef.get(id)));    \r
+            } catch (Exception e){\r
+                System.out.println(e.getMessage());\r
+                //EdkLog.log(EdkLog.EDK_INFO,e.getMessage());\r
+            }\r
+               \r
+               \r
+        }\r
+//        //modules = SurfaceAreaQuery.getFpdModuleSAs();\r
+//        for (index = 0; index < modules.length; index ++) {\r
+//            //SurfaceAreaQuery.setDoc(GlobalData.getDoc(modules[index].getModuleName()));\r
+//            allModules.add(new ModuleInfo(modules[index], \r
+//                                          ModuleTypeDef.Enum.forString(SurfaceAreaQuery.getModuleType())));\r
+//        }\r
         \r
         return allModules;\r
     }\r
         \r
         return allModules;\r
     }\r
@@ -2049,7 +2096,8 @@ public class CollectPCDAction {
         String                              moduleName        = null;\r
         String                              datum             = null;\r
         int                                 maxDatumSize      = 0;\r
         String                              moduleName        = null;\r
         String                              datum             = null;\r
         int                                 maxDatumSize      = 0;\r
-\r
+        String                                                         tokenSpaceGuidString = null;\r
+        \r
         //\r
         // ----------------------------------------------\r
         // 1), Get all <ModuleSA> from FPD file.\r
         //\r
         // ----------------------------------------------\r
         // 1), Get all <ModuleSA> from FPD file.\r
@@ -2073,17 +2121,17 @@ public class CollectPCDAction {
                 // BUGBUG: For transition schema, we can *not* get module's version from \r
                 // <ModuleSAs>, It is work around code.\r
                 // \r
                 // BUGBUG: For transition schema, we can *not* get module's version from \r
                 // <ModuleSAs>, It is work around code.\r
                 // \r
-                primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).module.getModuleName(), \r
+                primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).getModuleId().getModule().getName(), \r
+                                                          null,\r
                                                           null,\r
                                                           null, \r
                                                           null,\r
                                                           null, \r
-                                                          null, \r
-                                                          modules.get(index).module.getArch().toString(),\r
+                                                          modules.get(index).getModuleId().getArch(),\r
                                                           null);\r
                                                           null);\r
-                primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(), \r
+                primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).getModuleId().getModule().getName(), \r
                                                           null, \r
                                                           null, \r
                                                           null, \r
                                                           null, \r
                                                           null, \r
                                                           null, \r
-                                                          modules.get(index2).module.getArch().toString(), \r
+                                                          modules.get(index2).getModuleId().getArch(), \r
                                                           null);\r
                 if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
                     isDuplicate = true;\r
                                                           null);\r
                 if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
                     isDuplicate = true;\r
@@ -2098,13 +2146,13 @@ public class CollectPCDAction {
            //\r
            // It is legal for a module does not contains ANY pcd build definitions.\r
            // \r
            //\r
            // It is legal for a module does not contains ANY pcd build definitions.\r
            // \r
-           if (modules.get(index).module.getPcdBuildDefinition() == null) {\r
+           if (modules.get(index).getPcdBuildDef() == null) {\r
                 continue;\r
            }\r
     \r
                 continue;\r
            }\r
     \r
-            pcdBuildDataArray = modules.get(index).module.getPcdBuildDefinition().getPcdDataList();\r
+            pcdBuildDataArray = modules.get(index).getPcdBuildDef().getPcdDataList();\r
 \r
 \r
-            moduleName = modules.get(index).module.getModuleName();\r
+            moduleName = modules.get(index).getModuleId().getModule().getName();\r
 \r
             //\r
             // ----------------------------------------------------------------------\r
 \r
             //\r
             // ----------------------------------------------------------------------\r
@@ -2112,13 +2160,14 @@ public class CollectPCDAction {
             // ----------------------------------------------------------------------\r
             // \r
             for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
             // ----------------------------------------------------------------------\r
             // \r
             for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
+               //tokenSpaceGuidString = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName())[1];\r
+                tokenSpaceGuidString = null;\r
                 pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
                 primaryKey   = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
                 pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
                 primaryKey   = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
-                                                         translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
+                                                         translateSchemaStringToUUID(tokenSpaceGuidString));\r
                 pcdType      = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
                 datumType    = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
                 tokenNumber  = Long.decode(pcdBuildData.getToken().toString());\r
                 pcdType      = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
                 datumType    = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
                 tokenNumber  = Long.decode(pcdBuildData.getToken().toString());\r
-                \r
                 if (pcdBuildData.getValue() != null) {\r
                     datum = pcdBuildData.getValue().toString();\r
                 } else {\r
                 if (pcdBuildData.getValue() != null) {\r
                     datum = pcdBuildData.getValue().toString();\r
                 } else {\r
@@ -2135,17 +2184,6 @@ public class CollectPCDAction {
                     throw new EntityException(exceptionString);\r
                 }\r
 \r
                     throw new EntityException(exceptionString);\r
                 }\r
 \r
-                //\r
-                // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools\r
-                // will check that, following checking code could be removed.\r
-                // \r
-                if (pcdBuildData.getTokenSpaceGuid() == null) {\r
-                    exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in module %s! This is required!",\r
-                                                    pcdBuildData.getCName(),\r
-                                                    moduleName);\r
-                    throw new EntityException(exceptionString);\r
-                }\r
-\r
                 //\r
                 // -------------------------------------------------------------------------------------------\r
                 // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule\r
                 //\r
                 // -------------------------------------------------------------------------------------------\r
                 // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule\r
@@ -2255,8 +2293,10 @@ public class CollectPCDAction {
                     // If the token is not in database, create a new token instance and add\r
                     // a usage instance into this token in database.\r
                     // \r
                     // If the token is not in database, create a new token instance and add\r
                     // a usage instance into this token in database.\r
                     // \r
+                       //String tokenSpaceString = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName())[1];\r
+                    String tokenSpaceString = null;\r
                     token = new Token(pcdBuildData.getCName(), \r
                     token = new Token(pcdBuildData.getCName(), \r
-                                      translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
+                                      translateSchemaStringToUUID(tokenSpaceString));\r
     \r
                     token.datumType     = datumType;\r
                     token.tokenNumber   = tokenNumber;\r
     \r
                     token.datumType     = datumType;\r
                     token.tokenNumber   = tokenNumber;\r
@@ -2294,9 +2334,9 @@ public class CollectPCDAction {
                                                   null,\r
                                                   null,\r
                                                   null,\r
                                                   null,\r
                                                   null,\r
                                                   null,\r
-                                                  modules.get(index).type\r
+                                                  CommonDefinition.getModuleType(modules.get(index).getModuleType())\r
                                                   pcdType,\r
                                                   pcdType,\r
-                                                  modules.get(index).module.getArch().toString(), \r
+                                                  modules.get(index).getModuleId().getArch(), \r
                                                   null,\r
                                                   datum,\r
                                                   maxDatumSize);\r
                                                   null,\r
                                                   datum,\r
                                                   maxDatumSize);\r
@@ -2655,15 +2695,15 @@ public class CollectPCDAction {
         // \r
         if (fpdDocInstance == null) {\r
             try {\r
         // \r
         if (fpdDocInstance == null) {\r
             try {\r
-                fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
             } catch(IOException ioE) {\r
                 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
                 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
             }\r
         }\r
             } catch(IOException ioE) {\r
                 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
                 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
             }\r
         }\r
-\r
-        dynamicPcdBuildDefinitions = fpdDocInstance.getFrameworkPlatformDescription().getDynamicPcdBuildDefinitions();\r
+        \r
+        dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
         if (dynamicPcdBuildDefinitions == null) {\r
             exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
                                             "PCD entry %s in module %s!",\r
         if (dynamicPcdBuildDefinitions == null) {\r
             exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
                                             "PCD entry %s in module %s!",\r
@@ -2674,18 +2714,10 @@ public class CollectPCDAction {
 \r
         dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
         for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
 \r
         dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
         for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
-            //\r
-            // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools\r
-            // will check that, following checking code could be removed.\r
-            // \r
-            if (dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid() == null) {\r
-                exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in <DynamicPcdBuildDefinitions>! This is required!",\r
-                                                dynamicPcdBuildDataArray.get(index).getCName());\r
-                throw new EntityException(exceptionString);\r
-            }\r
-\r
+            //String tokenSpaceGuidString = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName())[1];\r
+            String tokenSpaceGuidString = null;\r
             dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
             dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
-                                                          translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid()));\r
+                                                          translateSchemaStringToUUID(tokenSpaceGuidString));\r
             if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
                 return dynamicPcdBuildDataArray.get(index);\r
             }\r
             if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
                 return dynamicPcdBuildDataArray.get(index);\r
             }\r
@@ -2880,14 +2912,22 @@ public class CollectPCDAction {
                 //\r
                 // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.\r
                 // \r
                 //\r
                 // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.\r
                 // \r
-                variableGuidString = GlobalData.getGuidInfoGuid(skuInfoList.get(index).getVariableGuid().toString());\r
+                variableGuidString = GlobalData.getGuidInfoFromCname(skuInfoList.get(index).getVariableGuid().toString());\r
                 if (variableGuidString == null) {\r
                     throw new EntityException(String.format("[GUID Error] For dynamic PCD %s,  the variable guid %s can be found in all SPD file!",\r
                                                             token.cName, \r
                                                             skuInfoList.get(index).getVariableGuid().toString()));\r
                 }\r
                 if (variableGuidString == null) {\r
                     throw new EntityException(String.format("[GUID Error] For dynamic PCD %s,  the variable guid %s can be found in all SPD file!",\r
                                                             token.cName, \r
                                                             skuInfoList.get(index).getVariableGuid().toString()));\r
                 }\r
-\r
-                skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(),\r
+                String variableStr = skuInfoList.get(index).getVariableName();\r
+                Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");\r
+                Matcher matcher = pattern.matcher(variableStr);\r
+                List<String> varNameList = new ArrayList<String>();\r
+                while (matcher.find()){\r
+                       String str = variableStr.substring(matcher.start(),matcher.end());\r
+                       varNameList.add(str);\r
+                }\r
+                \r
+                skuInstance.value.setHiiData(varNameList,\r
                                              translateSchemaStringToUUID(variableGuidString[1]),\r
                                              skuInfoList.get(index).getVariableOffset(),\r
                                              skuInfoList.get(index).getHiiDefaultValue().toString());\r
                                              translateSchemaStringToUUID(variableGuidString[1]),\r
                                              skuInfoList.get(index).getVariableOffset(),\r
                                              skuInfoList.get(index).getHiiDefaultValue().toString());\r
@@ -3044,8 +3084,8 @@ public class CollectPCDAction {
         ca.setWorkspacePath("m:/tianocore/edk2");\r
         ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
         ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
         ca.setWorkspacePath("m:/tianocore/edk2");\r
         ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
         ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
-        GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            "m:/tianocore/edk2");\r
-        ca.execute();\r
+//        GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
+//                            "m:/tianocore/edk2");\r
+//        ca.execute();\r
     }\r
 }\r
     }\r
 }\r
index c363aab6a5340a7bd0b9670daa19e4e3c52adeb5..7365345c39c131b1da72f9404060bc5cf5b16f01 100644 (file)
@@ -19,11 +19,15 @@ package org.tianocore.build.pcd.action;
 import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
 import java.util.UUID;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
 import java.util.UUID;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
+import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.pcd.entity.Token;\r
 import org.tianocore.build.pcd.entity.UsageInstance;\r
 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.pcd.entity.Token;\r
 import org.tianocore.build.pcd.entity.UsageInstance;\r
@@ -167,36 +171,167 @@ public class PCDAutoGenAction extends BuildAction {
         return cAutoGenString;\r
     }\r
 \r
         return cAutoGenString;\r
     }\r
 \r
+//    /**\r
+//      Construct function\r
+//  \r
+//      This function mainly initialize some member variable.\r
+//     \r
+//      @param moduleName            Parameter of this action class.\r
+//      @param isEmulatedPCDDriver   Parameter of this action class.\r
+//    **/\r
+//    public PCDAutoGenAction(String   moduleName, \r
+//                            UUID     moduleGuid, \r
+//                            String   packageName,\r
+//                            UUID     packageGuid,\r
+//                            String   arch,\r
+//                            String   version,\r
+//                            boolean  isBuildUsedLibrary,\r
+//                            String[] pcdNameArray) {\r
+//        dbManager       = null;\r
+//        hAutoGenString  = "";\r
+//        cAutoGenString  = "";\r
+//\r
+//        setModuleName(moduleName);\r
+//        setModuleGuid(moduleGuid);\r
+//        setPackageName(packageName);\r
+//        setPackageGuid(packageGuid);\r
+//        setPcdNameArray(pcdNameArray);\r
+//        setArch(arch);\r
+//        setVersion(version);\r
+//        setIsBuildUsedLibrary(isBuildUsedLibrary);\r
+//    }\r
+\r
+    \r
     /**\r
     /**\r
-      Construct function\r
+    Construct function\r
+\r
+    This function mainly initialize some member variable.\r
+   \r
+    @param moduleName            Parameter of this action class.\r
+    @param isEmulatedPCDDriver   Parameter of this action class.\r
+  **/\r
+  public PCDAutoGenAction(String   moduleName, \r
+                          String   moduleGuidString, \r
+                          String   packageName,\r
+                          String   packageGuidString,\r
+                          String   arch,\r
+                          String   version,\r
+                          boolean  isBuildUsedLibrary,\r
+                          String[] pcdNameArray) \r
+       throws BuildActionException {\r
+      dbManager       = null;\r
+      hAutoGenString  = "";\r
+      cAutoGenString  = "";\r
+      try {\r
+      setModuleName(moduleName);\r
+      setModuleGuid(translateSchemaStringToUUID(moduleGuidString));\r
+      setPackageName(packageName);\r
+      setPackageGuid(translateSchemaStringToUUID(packageGuidString));\r
+      setPcdNameArray(pcdNameArray);\r
+      setArch(arch);\r
+      setVersion(version);\r
+      setIsBuildUsedLibrary(isBuildUsedLibrary);\r
+      \r
+      if (isBuildUsedLibrary) {\r
+          System.out.println("Build for library");\r
+          for (int index = 0; index < pcdNameArray.length; index ++) {\r
+              System.out.println(pcdNameArray[index]);\r
+          }\r
+      }\r
+      } catch (EntityException e){\r
+         throw new BuildActionException(e.getMessage());\r
+      }\r
+  }\r
+\r
+  /**\r
+  Translate the schema string to UUID instance.\r
+  \r
+  In schema, the string of UUID is defined as following two types string:\r
+   1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
+   )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
+  \r
+   2) GuidNamingConvention: pattern =\r
+   [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\r
+  \r
+  This function will convert string and create uuid instance.\r
+  \r
+  @param uuidString    UUID string in XML file\r
+  \r
+  @return UUID         UUID instance\r
+**/\r
+private UUID translateSchemaStringToUUID(String uuidString) \r
+   throws EntityException {\r
+   String      temp;\r
+   String[]    splitStringArray;\r
+   int         index;\r
+   int         chIndex;\r
+   int         chLen;\r
+\r
+   if (uuidString == null) {\r
+       return null;\r
+   }\r
+\r
+   if (uuidString.length() == 0) {\r
+       return null;\r
+   }\r
+\r
+   if (uuidString.equals("0") ||\r
+       uuidString.equalsIgnoreCase("0x0")) {\r
+       return new UUID(0, 0);\r
+   }\r
+\r
+   uuidString = uuidString.replaceAll("\\{", "");\r
+   uuidString = uuidString.replaceAll("\\}", "");\r
+\r
+   //\r
+   // If the UUID schema string is GuidArrayType type then need translate \r
+   // to GuidNamingConvention type at first.\r
+   // \r
+   if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
+       splitStringArray = uuidString.split("," );\r
+       if (splitStringArray.length != 11) {\r
+           throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);\r
+       }\r
+\r
+       //\r
+       // Remove blank space from these string and remove header string "0x"\r
+       // \r
+       for (index = 0; index < 11; index ++) {\r
+           splitStringArray[index] = splitStringArray[index].trim();\r
+           splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
+       }\r
+\r
+       //\r
+       // Add heading '0' to normalize the string length\r
+       // \r
+       for (index = 3; index < 11; index ++) {\r
+           chLen = splitStringArray[index].length();\r
+           for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
+               splitStringArray[index] = "0" + splitStringArray[index];\r
+           }\r
+       }\r
+\r
+       //\r
+       // construct the final GuidNamingConvention string\r
+       // \r
+       temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
+                            splitStringArray[0],\r
+                            splitStringArray[1],\r
+                            splitStringArray[2],\r
+                            splitStringArray[3],\r
+                            splitStringArray[4],\r
+                            splitStringArray[5],\r
+                            splitStringArray[6],\r
+                            splitStringArray[7],\r
+                            splitStringArray[8],\r
+                            splitStringArray[9],\r
+                            splitStringArray[10]);\r
+       uuidString = temp;\r
+   }\r
+\r
+   return UUID.fromString(uuidString);\r
+       }\r
   \r
   \r
-      This function mainly initialize some member variable.\r
-     \r
-      @param moduleName            Parameter of this action class.\r
-      @param isEmulatedPCDDriver   Parameter of this action class.\r
-    **/\r
-    public PCDAutoGenAction(String   moduleName, \r
-                            UUID     moduleGuid, \r
-                            String   packageName,\r
-                            UUID     packageGuid,\r
-                            String   arch,\r
-                            String   version,\r
-                            boolean  isBuildUsedLibrary,\r
-                            String[] pcdNameArray) {\r
-        dbManager       = null;\r
-        hAutoGenString  = "";\r
-        cAutoGenString  = "";\r
-\r
-        setModuleName(moduleName);\r
-        setModuleGuid(moduleGuid);\r
-        setPackageName(packageName);\r
-        setPackageGuid(packageGuid);\r
-        setPcdNameArray(pcdNameArray);\r
-        setArch(arch);\r
-        setVersion(version);\r
-        setIsBuildUsedLibrary(isBuildUsedLibrary);\r
-    }\r
-\r
     /**\r
       check the parameter for action class.\r
       \r
     /**\r
       check the parameter for action class.\r
       \r
@@ -265,12 +400,14 @@ public class PCDAutoGenAction extends BuildAction {
             dbManager.UsageInstanceContext = usageInstanceArray;\r
             dbManager.CurrentModuleName    = moduleName; \r
         } else {\r
             dbManager.UsageInstanceContext = usageInstanceArray;\r
             dbManager.CurrentModuleName    = moduleName; \r
         } else {\r
+            System.out.println(String.format("Generate %s 's library", dbManager.CurrentModuleName));\r
             usageContext = dbManager.UsageInstanceContext;\r
             //\r
             // For building MDE package, although all module are library, but PCD entries of \r
             // these library should be used to autogen.\r
             // \r
             if (usageContext == null) {\r
             usageContext = dbManager.UsageInstanceContext;\r
             //\r
             // For building MDE package, although all module are library, but PCD entries of \r
             // these library should be used to autogen.\r
             // \r
             if (usageContext == null) {\r
+                System.out.println("context is null");\r
                 usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r
                                                                                   moduleGuid,\r
                                                                                   packageName,\r
                 usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r
                                                                                   moduleGuid,\r
                                                                                   packageName,\r
@@ -279,6 +416,7 @@ public class PCDAutoGenAction extends BuildAction {
                                                                                   version);\r
             } else {\r
                 usageInstanceArray = new ArrayList<UsageInstance>();\r
                                                                                   version);\r
             } else {\r
                 usageInstanceArray = new ArrayList<UsageInstance>();\r
+                System.out.println("context is not null!");\r
                 //\r
                 // Remove PCD entries which are not belong to this library.\r
                 // \r
                 //\r
                 // Remove PCD entries which are not belong to this library.\r
                 // \r
@@ -289,6 +427,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
                     for (index2 = 0; index2 < pcdNameArray.length; index2 ++) {\r
                         if (pcdNameArray[index2].equalsIgnoreCase(usageContext.get(index).parentToken.cName)) {\r
 \r
                     for (index2 = 0; index2 < pcdNameArray.length; index2 ++) {\r
                         if (pcdNameArray[index2].equalsIgnoreCase(usageContext.get(index).parentToken.cName)) {\r
+                            System.out.println("Found! for PCD entry " + pcdNameArray[index2]);\r
                             usageInstanceArray.add(usageContext.get(index));\r
                             break;\r
                         }\r
                             usageInstanceArray.add(usageContext.get(index));\r
                             break;\r
                         }\r
@@ -404,7 +543,7 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         CollectPCDAction collectionAction = new CollectPCDAction();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
         //\r
         CollectPCDAction collectionAction = new CollectPCDAction();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            WorkSpace);\r
+                            WorkSpace,null);\r
 \r
         try {\r
             collectionAction.perform(WorkSpace, \r
 \r
         try {\r
             collectionAction.perform(WorkSpace, \r
@@ -417,18 +556,18 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
         //\r
         //\r
         // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
         //\r
-        PCDAutoGenAction autogenAction = new PCDAutoGenAction("PcdPeim",\r
-                                                              null,\r
-                                                              null,\r
-                                                              null,\r
-                                                              "IA32",\r
-                                                              null,\r
-                                                              true,\r
-                                                              nameArray);\r
-        autogenAction.execute();\r
-\r
-        System.out.println(autogenAction.OutputH());\r
-        System.out.println("WQWQWQWQWQ");\r
-        System.out.println(autogenAction.OutputC());\r
+//        PCDAutoGenAction autogenAction = new PCDAutoGenAction("MonoStatusCode",\r
+//                                                              null,\r
+//                                                              null,\r
+//                                                              null,\r
+//                                                              "IA32",\r
+//                                                              null,\r
+//                                                              false,\r
+//                                                              nameArray);\r
+//        autogenAction.execute();\r
+//\r
+//        System.out.println(autogenAction.OutputH());\r
+//        System.out.println("WQWQWQWQWQ");\r
+//        System.out.println(autogenAction.OutputC());\r
     }\r
 }\r
     }\r
 }\r
index 77e50203974e093d8ca81056eb6ce83f78002271..af07e55165b8dcc95975805f069bc7ad16143b89 100644 (file)
@@ -92,7 +92,7 @@ public class ShowPCDDatabaseAction extends UIAction {
         // Initialize global data.\r
         //\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
         // Initialize global data.\r
         //\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            workspacePath);\r
+                            workspacePath,null);\r
 \r
         //\r
         // Collect PCD information.\r
 \r
         //\r
         // Collect PCD information.\r
index d146e9db44053ec87e14b8018696914b076d7cf3..20a58ba5f5b6763673db3d6400a59d4000f0dff3 100644 (file)
@@ -20,6 +20,7 @@ package org.tianocore.build.pcd.entity;
 \r
 import java.util.UUID;\r
 import org.tianocore.ModuleTypeDef;\r
 \r
 import java.util.UUID;\r
 import org.tianocore.ModuleTypeDef;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
 import org.tianocore.build.pcd.exception.EntityException;\r
 \r
 /**\r
 import org.tianocore.build.pcd.exception.EntityException;\r
 \r
 /**\r
@@ -71,7 +72,7 @@ public class UsageInstance {
     ///\r
     /// The module type for this usage instance.\r
     ///\r
     ///\r
     /// The module type for this usage instance.\r
     ///\r
-    public ModuleTypeDef.Enum    moduleType;\r
+    public int              moduleType;\r
 \r
     ///\r
     /// The value of the PCD in this usage instance. \r
 \r
     ///\r
     /// The value of the PCD in this usage instance. \r
@@ -115,7 +116,7 @@ public class UsageInstance {
                           UUID              moduleGUID,\r
                           String            packageName,\r
                           UUID              packageGUID,\r
                           UUID              moduleGUID,\r
                           String            packageName,\r
                           UUID              packageGUID,\r
-                          ModuleTypeDef.Enum moduleType,\r
+                          int               moduleType,\r
                           Token.PCD_TYPE    modulePcdType,\r
                           String            arch,\r
                           String            version,\r
                           Token.PCD_TYPE    modulePcdType,\r
                           String            arch,\r
                           String            version,\r
@@ -178,8 +179,8 @@ public class UsageInstance {
        @return boolean\r
      */\r
     public boolean isPeiPhaseComponent() {\r
        @return boolean\r
      */\r
     public boolean isPeiPhaseComponent() {\r
-        if ((moduleType == ModuleTypeDef.PEI_CORE) ||\r
-            (moduleType == ModuleTypeDef.PEIM)) {\r
+        if ((moduleType == CommonDefinition.ModuleTypePeiCore) ||\r
+            (moduleType == CommonDefinition.ModuleTypePeim)) {\r
             return true;\r
         }\r
         return false;\r
             return true;\r
         }\r
         return false;\r
@@ -190,12 +191,12 @@ public class UsageInstance {
       // BugBug: May need confirmation on which type of module can\r
       //         make use of Dynamic(EX) PCD entry.\r
       //\r
       // BugBug: May need confirmation on which type of module can\r
       //         make use of Dynamic(EX) PCD entry.\r
       //\r
-      if ((moduleType == ModuleTypeDef.DXE_DRIVER) ||\r
-          (moduleType == ModuleTypeDef.DXE_RUNTIME_DRIVER) ||\r
-          (moduleType == ModuleTypeDef.DXE_SAL_DRIVER) ||\r
-          (moduleType == ModuleTypeDef.DXE_SMM_DRIVER) ||\r
-          (moduleType == ModuleTypeDef.UEFI_DRIVER) ||\r
-          (moduleType == ModuleTypeDef.UEFI_APPLICATION)\r
+      if ((moduleType == CommonDefinition.ModuleTypeDxeDriver) ||\r
+          (moduleType == CommonDefinition.ModuleTypeDxeRuntimeDriver) ||\r
+          (moduleType == CommonDefinition.ModuleTypeDxeSalDriver) ||\r
+          (moduleType == CommonDefinition.ModuleTypeDxeSmmDriver) ||\r
+          (moduleType == CommonDefinition.ModuleTypeUefiDriver) ||\r
+          (moduleType == CommonDefinition.ModuleTypeUefiApplication)\r
           ) {\r
           return true;\r
       }\r
           ) {\r
           return true;\r
       }\r
index 0472265d399f0194b103a2745521ee8cee9100b2..0097890648a8dd4e66df4f7d4d35eaa8adf59a8a 100644 (file)
@@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
 **/\r
 package org.tianocore.build.toolchain;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 \r
 import java.io.BufferedReader;\r
 import java.io.File;\r
 \r
 import java.io.BufferedReader;\r
 import java.io.File;\r
index 05d212434619a629425d8321b849117950b82d89..232046c5908944f0067b2ad5b0fcf886a0b39601 100644 (file)
@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build.toolchain;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 package org.tianocore.build.toolchain;\r
 \r
 import org.apache.tools.ant.BuildException;\r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
 \r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
 \r
index 4804f15a74e989b9b9d4ea071f65f3c1e564e7d2..ae13190e9790e14fb9e25620729d035825cfd074 100644 (file)
@@ -24,7 +24,7 @@ import java.util.HashMap;
 import java.util.Map;\r
 import java.util.TreeMap;\r
 \r
 import java.util.Map;\r
 import java.util.TreeMap;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 \r
 public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
 \r
 \r
 public class ToolChainKey implements java.io.Serializable, Comparable<ToolChainKey> {\r
 \r
index da34e7ec7e39e7314756615d6fc87d94da0d8a53..39034fd4b72a88d6fe0b141059f20258eeba7c4d 100644 (file)
@@ -22,7 +22,7 @@ import java.util.HashMap;
 import java.util.Map;\r
 import java.util.Set;\r
 \r
 import java.util.Map;\r
 import java.util.Set;\r
 \r
-import org.tianocore.build.exception.EdkException;\r
+import org.tianocore.exception.EdkException;\r
 \r
 public class ToolChainMap {\r
 \r
 \r
 public class ToolChainMap {\r
 \r