]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Update GlobalData, SPD, SurfaceAreaQuery to using EdkException.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index dea679b407856861bb2cf034fb30bc943f4a95ac..117b6bfe17944810f2348f9d38310d78ab853c29 100644 (file)
@@ -22,6 +22,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;\r
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
+import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
@@ -39,13 +40,14 @@ import org.tianocore.build.global.SurfaceAreaQuery;
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
-\r
 import org.tianocore.common.logger.EdkLog;\r
+import org.tianocore.common.definitions.ToolDefinitions;\r
+import org.tianocore.common.exception.EdkException;\r
 \r
 /**\r
* This class is to generate Autogen.h and Autogen.c according to module surface\r
* area or library surface area.\r
- */\r
+  This class is to generate Autogen.h and Autogen.c according to module surface\r
+  area or library surface area.\r
+**/\r
 public class AutoGen {\r
     ///\r
     /// The output path of Autogen.h and Autogen.c\r
@@ -96,96 +98,116 @@ public class AutoGen {
     ///\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
+    ///\r
+    /// The dependence package list which recoreded in module or library surface\r
+    /// area and it's dependence on library instance surface area.\r
+    ///\r
     private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();\r
 \r
-    //\r
-    //  For non library module, add its library instance's construct and destructor to\r
-    //  list.\r
-    //\r
+    ///\r
+    ///  For non library module, add its library instance's construct and destructor to\r
+    ///  list.\r
+    ///\r
     private List<String> libConstructList = new ArrayList<String>();\r
     private List<String> libDestructList = new ArrayList<String>();\r
 \r
-    //\r
-    // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r
-    //\r
+    ///\r
+    /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r
+    ///\r
     private List<String> setVirtalAddList = new ArrayList<String>();\r
     private List<String> exitBootServiceList = new ArrayList<String>();\r
 \r
+    private SurfaceAreaQuery saq = null;\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 fvDir, String outputPath, ModuleIdentification moduleId, String arch) {\r
+      Construct function\r
+     \r
+      This function mainly initialize some member variable.\r
+      \r
+      @param fvDir\r
+                 Absolute path of FV directory.\r
+      @param outputPath\r
+                 Output path of AutoGen file.\r
+      @param moduleId\r
+                 Module identification.\r
+      @param arch\r
+                 Target architecture.\r
+    **/\r
+    public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq) {\r
         this.outputPath = outputPath;\r
         this.moduleId = moduleId;\r
         this.arch = arch;\r
         this.fvDir = fvDir;\r
-\r
+        this.saq = saq;\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
+      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 boolean           \r
+                 "true"  successful\r
+                 "false" failed\r
+    **/\r
     private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
-        try {\r
-            File autoGenH = new File(fileName);\r
+        \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
+        if (autoGenH.exists()) {\r
+            char[] oldFileBuffer = new char[(int) autoGenH.length()];\r
+                       try {\r
+                               FileReader fIn = new FileReader(autoGenH);\r
+                               fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r
                 fIn.close();\r
+                       } catch (IOException e) {\r
+                               EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r
+                                                               + "'s " \r
+                                                               + fileName \r
+                                                               + " is exist, but can't be open!!");\r
+                               return false;\r
+                       }\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
+            // 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
-            FileWriter fOut = new FileWriter(autoGenH);\r
+        }\r
+        \r
+               try {\r
+                       FileWriter fOut = new FileWriter(autoGenH);\r
             fOut.write(fileBuffer.toString());\r
+                       fOut.flush();\r
             fOut.close();\r
-        } catch (Exception e) {\r
-            return false;\r
-        }\r
+               } catch (IOException e) {\r
+                       EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r
+                                                               + "'s " \r
+                                                               + fileName \r
+                                                               + " can't be create!!");\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
+      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
@@ -212,13 +234,13 @@ public class AutoGen {
     }\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
+      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
@@ -233,13 +255,13 @@ public class AutoGen {
     }\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
+      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
@@ -252,14 +274,14 @@ public class AutoGen {
     }\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
+      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 EdkException, AutoGenException {\r
 \r
         Set<String> libClassIncludeH;\r
         String moduleType;\r
@@ -271,14 +293,21 @@ public class AutoGen {
         //\r
         // Write Autogen.h header notation\r
         //\r
-        fileBuffer.append(CommonDefinition.autogenHNotation);\r
+        fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r
 \r
         //\r
         // Add #ifndef ${BaseName}_AUTOGENH\r
         // #def ${BseeName}_AUTOGENH\r
         //\r
-        fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n");\r
-        fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n");\r
+        fileBuffer.append(CommonDefinition.IFNDEF \r
+                                     + CommonDefinition.AUTOGENH\r
+                                     + this.moduleId.getGuid().replaceAll("-", "_") \r
+                                     + ToolDefinitions.LINE_SEPARATOR);\r
+        fileBuffer.append(CommonDefinition.DEFINE \r
+                                     + CommonDefinition.AUTOGENH\r
+                                     + this.moduleId.getGuid().replaceAll("-", "_") \r
+                                     + ToolDefinitions.LINE_SEPARATOR \r
+                                     + ToolDefinitions.LINE_SEPARATOR);\r
 \r
         //\r
         // Write the specification version and release version at the begine\r
@@ -287,20 +316,20 @@ public class AutoGen {
         // be got from module surface area instead of hard code by it's\r
         // moduleType.\r
         //\r
-        moduleType = SurfaceAreaQuery.getModuleType();\r
+        moduleType = saq.getModuleType();\r
 \r
         //\r
         // Add "extern int __make_me_compile_correctly;" at begin of\r
         // AutoGen.h.\r
         //\r
-        fileBuffer.append(CommonDefinition.autoGenHbegin);\r
+        fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r
 \r
         //\r
         // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.\r
         //\r
-        String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
+        String[] specList = saq.getExternSpecificaiton();\r
         for (int i = 0; i < specList.length; i++) {\r
-            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
+            fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r
                               + "\r\n");\r
         }\r
         //\r
@@ -308,8 +337,7 @@ public class AutoGen {
         //\r
         // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
         // .getDependencePkg(this.arch);\r
-        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-                                                    .getDependencePkg(this.arch);\r
+        PackageIdentification[] consumedPkgIdList = saq.getDependencePkg(this.arch);\r
         if (consumedPkgIdList != null) {\r
             headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
             item = headerFileList.iterator();\r
@@ -321,8 +349,7 @@ public class AutoGen {
         //\r
         // Write library class's related *.h file to autogen.h.\r
         //\r
-        String[] libClassList = SurfaceAreaQuery\r
-                                .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch);\r
+        String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED,this.arch);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
             item = libClassIncludeH.iterator();\r
@@ -331,8 +358,7 @@ public class AutoGen {
             }\r
         }\r
 \r
-        libClassList = SurfaceAreaQuery\r
-                       .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
+        libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
             item = libClassIncludeH.iterator();\r
@@ -346,10 +372,10 @@ public class AutoGen {
         //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r
         // {DEST_DIR_DRBUG}/FlashMap.h\r
         //\r
-        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
-            fileBuffer.append(CommonDefinition.include);\r
+        if (saq.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.INCLUDE);\r
             fileBuffer.append("  <");\r
-            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r
             copyFlashMapHToDebugDir();\r
         }\r
 \r
@@ -374,25 +400,25 @@ public class AutoGen {
     }\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
+      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 EdkException, AutoGenException {\r
 \r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         //\r
         // Write Autogen.c header notation\r
         //\r
-        fileBuffer.append(CommonDefinition.autogenCNotation);\r
+        fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r
 \r
         //\r
         // Write #include <AutoGen.h> at beginning of AutoGen.c\r
         //\r
-        fileBuffer.append(CommonDefinition.includeAutogenH);\r
+        fileBuffer.append(CommonDefinition.INCLUDEAUTOGENH);\r
 \r
         //\r
         // Get the native MSA file infomation. Since before call autogen,\r
@@ -400,7 +426,7 @@ public class AutoGen {
         // 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
+        saq.push(doc);\r
         //\r
         // Write <Extern>\r
         // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
@@ -418,21 +444,23 @@ public class AutoGen {
         //\r
         // Write EntryPoint to autgoGen.c\r
         //\r
-        String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();\r
-        EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer);\r
+        String[] entryPointList = saq.getModuleEntryPointArray();\r
+               String[] unloadImageList = saq.getModuleUnloadImageArray();\r
+        EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), \r
+                                       CommonDefinition.remDupString(unloadImageList),\r
+                                       fileBuffer);\r
 \r
-        pcdDriverType = SurfaceAreaQuery.getPcdDriverType();\r
+        pcdDriverType = saq.getPcdDriverType();\r
 \r
         //\r
         // Restore the DOC which include the FPD module info.\r
         //\r
-        SurfaceAreaQuery.pop();\r
+        saq.pop();\r
 \r
         //\r
         // Write Guid to autogen.c\r
         //\r
-        String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery\r
-                                                      .getModuleGuid());\r
+        String guid = CommonDefinition.formatGuidName(saq.getModuleGuid());\r
 \r
         fileBuffer\r
         .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
@@ -460,7 +488,7 @@ public class AutoGen {
         //\r
         // Get module dependent Package identification.\r
         //\r
-        PackageIdentification[] packages = SurfaceAreaQuery.getDependencePkg(this.arch);\r
+        PackageIdentification[] packages = saq.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
@@ -501,14 +529,14 @@ public class AutoGen {
     }\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
+      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 EdkException, AutoGenException {\r
 \r
         Set<String> libClassIncludeH;\r
         String moduleType;\r
@@ -519,14 +547,21 @@ public class AutoGen {
         //\r
         // Write Autogen.h header notation\r
         //\r
-        fileBuffer.append(CommonDefinition.autogenHNotation);\r
+        fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r
 \r
         //\r
         // Add #ifndef ${BaseName}_AUTOGENH\r
         // #def ${BseeName}_AUTOGENH\r
         //\r
-        fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n");\r
-        fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n");\r
+        fileBuffer.append(CommonDefinition.IFNDEF \r
+                                     + CommonDefinition.AUTOGENH\r
+                                     + this.moduleId.getGuid().replaceAll("-", "_") \r
+                                     + ToolDefinitions.LINE_SEPARATOR);\r
+        fileBuffer.append(CommonDefinition.DEFINE \r
+                                     + CommonDefinition.AUTOGENH\r
+                                     + this.moduleId.getGuid().replaceAll("-", "_") \r
+                                     + ToolDefinitions.LINE_SEPARATOR \r
+                                     + ToolDefinitions.LINE_SEPARATOR);\r
 \r
         //\r
         // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
@@ -534,10 +569,10 @@ public class AutoGen {
         // 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
+        fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r
+        String[] specList = saq.getExternSpecificaiton();\r
         for (int i = 0; i < specList.length; i++) {\r
-            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
+            fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r
                               + "\r\n");\r
         }\r
         // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
@@ -546,8 +581,8 @@ public class AutoGen {
         //\r
         // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
         //\r
-        moduleType = SurfaceAreaQuery.getModuleType();\r
-        PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
+        moduleType = saq.getModuleType();\r
+        PackageIdentification[] cosumedPkglist = saq\r
                                                  .getDependencePkg(this.arch);\r
         headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
         item = headerFileList.iterator();\r
@@ -557,8 +592,8 @@ public class AutoGen {
         //\r
         // Write library class's related *.h file to autogen.h\r
         //\r
-        String[] libClassList = SurfaceAreaQuery\r
-                                .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch);\r
+        String[] libClassList = saq\r
+                                .getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
             item = libClassIncludeH.iterator();\r
@@ -567,8 +602,8 @@ public class AutoGen {
             }\r
         }\r
 \r
-        libClassList = SurfaceAreaQuery\r
-                       .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
+        libClassList = saq\r
+                       .getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
             item = libClassIncludeH.iterator();\r
@@ -576,16 +611,16 @@ public class AutoGen {
                 fileBuffer.append(item.next().toString());\r
             }\r
         }\r
-        fileBuffer.append("\r\n");\r
+        fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
 \r
         //\r
         //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r
         // {DEST_DIR_DRBUG}/FlashMap.h\r
         //\r
-        if (SurfaceAreaQuery.isHaveTianoR8FlashMap()) {\r
-            fileBuffer.append(CommonDefinition.include);\r
+        if (saq.isHaveTianoR8FlashMap()) {\r
+            fileBuffer.append(CommonDefinition.INCLUDE);\r
             fileBuffer.append("  <");\r
-            fileBuffer.append(CommonDefinition.tianoR8FlashMapH + ">\r\n");\r
+            fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r
             copyFlashMapHToDebugDir();\r
         }\r
 \r
@@ -611,23 +646,23 @@ public class AutoGen {
     }\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
+      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, PcdAutogenException {\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
         // Write Autogen.c header notation\r
         //\r
-        fileBuffer.append(CommonDefinition.autogenCNotation);\r
+        fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r
 \r
-        fileBuffer.append(CommonDefinition.autoGenCLine1);\r
-        fileBuffer.append("\r\n");\r
+        fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
+        fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
 \r
         //\r
         // Call pcd autogen.\r
@@ -635,7 +670,7 @@ public class AutoGen {
         this.myPcdAutogen = new PCDAutoGenAction(moduleId,\r
                                                  arch,\r
                                                  true,\r
-                                                 SurfaceAreaQuery.getModulePcdEntryNameArray(),\r
+                                                 saq.getModulePcdEntryNameArray(),\r
                                                  pcdDriverType);\r
         try {\r
             this.myPcdAutogen.execute();\r
@@ -644,7 +679,7 @@ public class AutoGen {
         }\r
 \r
         if (this.myPcdAutogen != null) {\r
-            fileBuffer.append("\r\n");\r
+            fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
             fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r
         }\r
 \r
@@ -654,20 +689,20 @@ public class AutoGen {
     }\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
+      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 LinkedHashSet<String>();\r
-        String includerName[];\r
+    throws EdkException, AutoGenException {\r
+        Set<String> includeStrList = new LinkedHashSet<String>();\r
+        String includeName[];\r
         String str = "";\r
 \r
         //\r
@@ -675,37 +710,37 @@ public class AutoGen {
         // library class name.\r
         //\r
         for (int i = 0; i < libClassList.length; i++) {\r
-            includerName = GlobalData.getLibraryClassHeaderFiles(\r
-                                                                SurfaceAreaQuery.getDependencePkg(this.arch),\r
+            includeName = GlobalData.getLibraryClassHeaderFiles(\r
+                            saq.getDependencePkg(this.arch),\r
                                                                 libClassList[i]);\r
-            if (includerName == null) {\r
+            if (includeName == null) {\r
                 throw new AutoGenException("Can not find library class ["\r
                                            + libClassList[i] + "] declaration in any SPD package. ");\r
             }\r
-            for (int j = 0; j < includerName.length; j++) {\r
-                String includeNameStr = includerName[j];\r
+            for (int j = 0; j < includeName.length; j++) {\r
+                String includeNameStr = includeName[j];\r
                 if (includeNameStr != null) {\r
-                    str = CommonDefinition.include + " " + "<";\r
+                    str = CommonDefinition.INCLUDE + " " + "<";\r
                     str = str + includeNameStr + ">\r\n";\r
-                    includStrList.add(str);\r
+                    includeStrList.add(str);\r
                     includeNameStr = null;\r
                 }\r
             }\r
         }\r
-        return includStrList;\r
+        return includeStrList;\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
+      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
@@ -724,7 +759,7 @@ public class AutoGen {
                                            + packageNameList[i]\r
                                            + "] declaration in any SPD package. ");\r
             } else if (!pkgHeader.equalsIgnoreCase("")) {\r
-                includeStr = CommonDefinition.include + " <" + pkgHeader\r
+                includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader\r
                              + ">\r\n";\r
                 includeStrList.add(includeStr);\r
             }\r
@@ -734,21 +769,23 @@ public class AutoGen {
     }\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
+      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, String[] unloadImageList, StringBuffer fileBuffer)\r
     throws BuildException {\r
 \r
-        String typeStr = SurfaceAreaQuery.getModuleType();\r
+        String typeStr = saq.getModuleType();\r
+               int unloadImageCount = 0;\r
+        int entryPointCount  = 0;\r
 \r
         //\r
         // The parameters and return value of entryPoint is difference\r
@@ -815,7 +852,7 @@ public class AutoGen {
             break;\r
 \r
         case CommonDefinition.ModuleTypePeim:\r
-            int entryPointCount = 0;\r
+            entryPointCount = 0;\r
             fileBuffer\r
             .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
             if (entryPointList == null || entryPointList.length == 0) {\r
@@ -960,26 +997,27 @@ public class AutoGen {
             //\r
             // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
             //\r
-            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
-            entryPointList = CommonDefinition.remDupString(entryPointList);\r
-            entryPointCount = 0;\r
+            //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
+            //entryPointList = CommonDefinition.remDupString(entryPointList);\r
+            //entryPointCount = 0;\r
 \r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
+                       unloadImageCount = 0;\r
+            if (unloadImageList != null) {\r
+                for (int i = 0; i < unloadImageList.length; i++) {\r
                     fileBuffer.append("EFI_STATUS\r\n");\r
                     fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(unloadImageList[i]);\r
                     fileBuffer.append(" (\r\n");\r
                     fileBuffer\r
                     .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
                     fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
+                    unloadImageCount++;\r
                 }\r
             }\r
 \r
             fileBuffer\r
             .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
+            fileBuffer.append(Integer.toString(unloadImageCount));\r
             fileBuffer.append(";\r\n\r\n");\r
 \r
             fileBuffer.append("EFI_STATUS\r\n");\r
@@ -989,28 +1027,28 @@ public class AutoGen {
             fileBuffer.append("  )\r\n");\r
             fileBuffer.append("{\r\n");\r
 \r
-            if (entryPointCount == 0) {\r
+            if (unloadImageCount == 0) {\r
                 fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
+            } else if (unloadImageCount == 1) {\r
                 fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(unloadImageList[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
+                for (int i = 0; i < unloadImageList.length; i++) {\r
                     if (i == 0) {\r
                         fileBuffer.append("     Status = ");\r
-                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append(unloadImageList[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(unloadImageList[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(unloadImageList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
                         fileBuffer.append("  }\r\n");\r
                     }\r
@@ -1126,28 +1164,29 @@ public class AutoGen {
             //\r
             // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
             //\r
-            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
+            //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             //\r
             // Remover duplicate unload entry point.\r
             //\r
-            entryPointList = CommonDefinition.remDupString(entryPointList);\r
-            entryPointCount = 0;\r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
+            //entryPointList = CommonDefinition.remDupString(entryPointList);\r
+            //entryPointCount = 0;\r
+                       unloadImageCount = 0;\r
+            if (unloadImageList != null) {\r
+                for (int i = 0; i < unloadImageList.length; i++) {\r
                     fileBuffer.append("EFI_STATUS\r\n");\r
                     fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(unloadImageList[i]);\r
                     fileBuffer.append(" (\r\n");\r
                     fileBuffer\r
                     .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
                     fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
+                    unloadImageCount++;\r
                 }\r
             }\r
 \r
             fileBuffer\r
             .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-            fileBuffer.append(Integer.toString(entryPointCount));\r
+            fileBuffer.append(Integer.toString(unloadImageCount));\r
             fileBuffer.append(";\r\n\r\n");\r
 \r
             fileBuffer.append("EFI_STATUS\n");\r
@@ -1157,28 +1196,28 @@ public class AutoGen {
             fileBuffer.append("  )\r\n");\r
             fileBuffer.append("{\r\n");\r
 \r
-            if (entryPointCount == 0) {\r
+            if (unloadImageCount == 0) {\r
                 fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-            } else if (entryPointCount == 1) {\r
+            } else if (unloadImageCount == 1) {\r
                 fileBuffer.append("  return ");\r
-                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(unloadImageList[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
+                for (int i = 0; i < unloadImageList.length; i++) {\r
                     if (i == 0) {\r
                         fileBuffer.append("  Status = ");\r
-                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append(unloadImageList[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(unloadImageList[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(unloadImageList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
                         fileBuffer.append("  }\r\n");\r
                     }\r
@@ -1191,16 +1230,16 @@ public class AutoGen {
     }\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
+      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
@@ -1209,12 +1248,12 @@ public class AutoGen {
         // then add those PPI ,and PPI Notify name to list.\r
         //\r
 \r
-        String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
+        String[] ppiList = saq.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
+        String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
         for (int i = 0; i < ppiNotifyList.length; i++) {\r
             this.mPpiList.add(ppiNotifyList[i]);\r
         }\r
@@ -1245,20 +1284,20 @@ public class AutoGen {
     }\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
+      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
+        String[] protocolList = saq.getProtocolArray(this.arch);\r
 \r
         //\r
         // Add result to Autogen global list.\r
@@ -1267,7 +1306,7 @@ public class AutoGen {
             this.mProtocolList.add(protocolList[i]);\r
         }\r
 \r
-        String[] protocolNotifyList = SurfaceAreaQuery\r
+        String[] protocolNotifyList = saq\r
                                       .getProtocolNotifyArray(this.arch);\r
 \r
         for (int i = 0; i < protocolNotifyList.length; i++) {\r
@@ -1302,20 +1341,20 @@ public class AutoGen {
     }\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
+      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
+        String[] guidList = saq.getGuidEntryArray(this.arch);\r
 \r
         for (int i = 0; i < guidList.length; i++) {\r
             this.mGuidList.add(guidList[i]);\r
@@ -1346,16 +1385,16 @@ public class AutoGen {
     }\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
+      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
         try {\r
             String moduleType = this.moduleId.getModuleType();\r
@@ -1374,19 +1413,19 @@ public class AutoGen {
     }\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
+      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
@@ -1515,19 +1554,19 @@ public class AutoGen {
     }\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
+      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
@@ -1615,14 +1654,14 @@ public class AutoGen {
     }\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
+      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
@@ -1632,7 +1671,7 @@ public class AutoGen {
         // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
         //\r
 \r
-        String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
+        String[] drvBindList = saq.getDriverBindingArray();\r
 \r
         //\r
         // If component name protocol,component configuration protocol,\r
@@ -1643,9 +1682,9 @@ public class AutoGen {
             return;\r
         }\r
 \r
-        String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
-        String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
-        String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
+        String[] compNamList = saq.getComponentNameArray();\r
+        String[] compConfList = saq.getDriverConfigArray();\r
+        String[] compDiagList = saq.getDriverDiagArray();\r
 \r
         int BitMask = 0;\r
 \r
@@ -1769,15 +1808,15 @@ public class AutoGen {
     }\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
+      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
         //\r
@@ -1785,8 +1824,8 @@ public class AutoGen {
         // <ExitBootServiceCallBack> and add to setVirtualAddList\r
         //  exitBootServiceList.\r
         //\r
-        String[] setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray();\r
-        String[] exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray();\r
+        String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
+        String[] exitBoots = saq.getExitBootServicesCallBackArray();\r
         if (setVirtuals != null) {\r
             for (int j = 0; j < setVirtuals.length; j++) {\r
                 this.setVirtalAddList.add(setVirtuals[j]);\r
@@ -1802,183 +1841,39 @@ public class AutoGen {
         //  and <ExitBootServicesCallBack>\r
         //\r
         String moduleType = this.moduleId.getModuleType();\r
-        boolean UefiOrDxeModule = false;\r
-        int Count = 0;\r
-        int i;\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 (this.setVirtalAddList != null) {\r
-                for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
-                    if (this.setVirtalAddList.get(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
+               case CommonDefinition.ModuleTypeUefiApplication:\r
+                       //\r
+                       //  If moduleType is one of above, call setVirtualAddressToAutogenC,\r
+                       //  and setExitBootServiceToAutogenC.\r
+                       // \r
+            setVirtualAddressToAutogenC(fileBuffer);\r
+                       setExitBootServiceToAutogenC(fileBuffer);\r
             break;\r
         default:\r
             break;\r
         }\r
-\r
-        if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\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 < this.setVirtalAddList.size(); i++) {\r
-                if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(this.setVirtalAddList.get(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 < this.setVirtalAddList.size(); i++) {\r
-                if (this.setVirtalAddList.get(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(this.setVirtalAddList.get(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 (this.exitBootServiceList != null) {\r
-                for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
-                    if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
-                        break;\r
-                    }\r
-                }\r
-                Count = i;\r
-            }\r
-            fileBuffer.append(Integer.toString(Count));\r
-            fileBuffer.append(";\r\n\r\n");\r
-        }\r
-\r
-        if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\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 < this.exitBootServiceList.size(); i++) {\r
-                if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
-                    break;\r
-                }\r
-\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(this.exitBootServiceList.get(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 < this.exitBootServiceList.size(); i++) {\r
-                if (this.exitBootServiceList.get(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(this.exitBootServiceList.get(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
+    /**\r
+      copyFlashMapHToDebugDir\r
+      \r
+      This function is to copy the falshmap.h to debug directory and change \r
+      its name to TianoR8FlashMap.h\r
+      \r
+      @param \r
+      @return\r
+    **/\r
     private void copyFlashMapHToDebugDir() throws  AutoGenException{\r
 \r
-        File inFile = new File(fvDir + File.separatorChar + CommonDefinition.flashMapH);\r
+        File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH);\r
         int size = (int)inFile.length();\r
         byte[] buffer = new byte[size];\r
-        File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.tianoR8FlashMapH);\r
+        File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH);\r
         //\r
         //  If TianoR8FlashMap.h existed and the flashMap.h don't change,\r
         //  do nothing.\r
@@ -2002,13 +1897,15 @@ public class AutoGen {
     }\r
 \r
     /**\r
-    *This function first order the library instances, then collect\r
-    *library instance 's PPI, Protocol, GUID,\r
-    *SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r
-    *Destructor, Constructor.\r
-    *\r
+      This function first order the library instances, then collect\r
+      library instance 's PPI, Protocol, GUID,\r
+      SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r
+      Destructor, Constructor.\r
+      \r
+      @param\r
+      @return    \r
     **/\r
-    private void collectLibInstanceInfo(){\r
+    private void collectLibInstanceInfo() throws EdkException{\r
         int index;\r
 \r
         String libConstructName = null;\r
@@ -2016,8 +1913,7 @@ public class AutoGen {
         String[] setVirtuals = null;\r
         String[] exitBoots = null;\r
 \r
-        ModuleIdentification[] libraryIdList = SurfaceAreaQuery\r
-                                               .getLibraryInstance(this.arch);\r
+        ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r
         try {\r
             if (libraryIdList != null) {\r
                 //\r
@@ -2044,21 +1940,17 @@ public class AutoGen {
                         //\r
 \r
                         Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r
-                        SurfaceAreaQuery.push(libDoc);\r
+                        saq.push(libDoc);\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
+                        String[] ppiList = saq.getPpiArray(this.arch);\r
+                        String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
+                        String[] protocolList = saq.getProtocolArray(this.arch);\r
+                        String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r
+                        String[] guidList = saq.getGuidEntryArray(this.arch);\r
+                        PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r
 \r
                         //\r
                         // Add those ppi, protocol, guid in global ppi,\r
@@ -2094,17 +1986,15 @@ public class AutoGen {
                         // 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
+                        libConstructName = saq.getLibConstructorName();\r
+                        libDestructName = saq.getLibDestructorName();\r
 \r
                         //\r
                         // Collect SetVirtualAddressMapCallBack and\r
                         // ExitBootServiceCallBack.\r
                         //\r
-                        setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray();\r
-                        exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray();\r
+                        setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
+                        exitBoots = saq.getExitBootServicesCallBackArray();\r
                         if (setVirtuals != null) {\r
                             for (int j = 0; j < setVirtuals.length; j++) {\r
                                 this.setVirtalAddList.add(setVirtuals[j]);\r
@@ -2115,7 +2005,7 @@ public class AutoGen {
                                 this.exitBootServiceList.add(exitBoots[k]);\r
                             }\r
                         }\r
-                        SurfaceAreaQuery.pop();\r
+                        saq.pop();\r
                         //\r
                         // Add dependent library instance constructor function.\r
                         //\r
@@ -2138,4 +2028,155 @@ public class AutoGen {
             System.out.println("Collect library instance failed!");\r
         }\r
     }\r
+       private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r
+        //\r
+        // Entry point lib for these module types needs to know the count\r
+        // of entryPoint.\r
+        //\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
+            int Count = 0;\r
+                       int i = 0;\r
+            if (this.setVirtalAddList != null) {\r
+                for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
+                    if (this.setVirtalAddList.get(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
+            if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\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
+            } else {\r
+                //\r
+                // Write SetVirtualAddressMap function definition.\r
+                //\r
+                for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
+                    if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
+                        break;\r
+                    }\r
+                    fileBuffer.append("VOID\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(this.setVirtalAddList.get(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 < this.setVirtalAddList.size(); i++) {\r
+                    if (this.setVirtalAddList.get(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(this.setVirtalAddList.get(i));\r
+                }\r
+                //\r
+                // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.\r
+                //\r
+                fileBuffer.append(",\r\n  NULL");\r
+                fileBuffer.append("\r\n};\r\n\r\n");\r
+                       }\r
+       }\r
+\r
+\r
+       private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){\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
+        int Count = 0;\r
+               int i = 0; \r
+        if (this.exitBootServiceList != null) {\r
+            for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
+                if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
+                    break;\r
+                }\r
+            }\r
+            Count = i;\r
+        }\r
+        fileBuffer.append(Integer.toString(Count));\r
+        fileBuffer.append(";\r\n\r\n");\r
+\r
+               if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\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
+        } else {\r
+            //\r
+            // Write DriverExitBootServices function definition.\r
+            //\r
+            for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
+                if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
+                    break;\r
+                }\r
+\r
+                fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append(this.exitBootServiceList.get(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 < this.exitBootServiceList.size(); i++) {\r
+                if (this.exitBootServiceList.get(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(this.exitBootServiceList.get(i));\r
+            }\r
+            \r
+            fileBuffer.append(",\r\n  NULL");\r
+            fileBuffer.append("\r\n};\r\n\r\n");\r
+        }\r
+\r
+       }\r
+\r
 }\r