]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
a. Enhanced toolchain setting UI for ModuleSa build options and global build options.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
index ce9682e2d456ca5fee36c0820e559edfd986c82d..9e2f955599a4130847bee90aac003e4b48a78ad6 100644 (file)
@@ -57,10 +57,11 @@ import org.tianocore.LicenseDocument;
 import org.tianocore.PlatformHeaderDocument;\r
 import org.tianocore.SkuInfoDocument;\r
 import org.tianocore.UserDefinedAntTasksDocument;\r
-import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;\r
+import org.tianocore.UserExtensionsDocument;\r
+import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;\r
 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
-import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r
-import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r
+import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
+import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
 \r
 /**\r
  This class processes fpd file contents such as add remove xml elements. \r
@@ -88,6 +89,8 @@ public class FpdFileContents {
     \r
     private HashMap<String, ArrayList<String>> dynPcdMap = null;\r
     \r
+    private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();\r
+    \r
     /**\r
      * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.\r
      */\r
@@ -102,13 +105,13 @@ public class FpdFileContents {
           }\r
           ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();\r
           while (li.hasNext()) {\r
-              ModuleSADocument.ModuleSA msa = li.next();\r
-              if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {\r
+              ModuleSADocument.ModuleSA moduleSa = li.next();\r
+              if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {\r
                   continue;\r
               }\r
-              String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +\r
-               " " + msa.getPackageGuid() + " " + msa.getPackageVersion() + " " + listToString(msa.getSupArchList());\r
-              List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();\r
+              String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() +\r
+               " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());\r
+              List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();\r
               ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();\r
               while (lpi.hasNext()) {\r
                   PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();\r
@@ -181,6 +184,32 @@ public class FpdFileContents {
         return fpdFrameworkModules;\r
     }\r
     \r
+    public void getFrameworkModuleGuid (String fvName, Vector<String> vGuid) {\r
+        if (getFrameworkModulesCount() == 0){\r
+            return;\r
+        }\r
+        \r
+        ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
+        while(li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();\r
+            if (moduleSa.getModuleSaBuildOptions() == null) {\r
+                continue;\r
+            }\r
+            String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+            if (fvBinding == null) {\r
+                continue;\r
+            }\r
+            \r
+            String[] fvNames = fvBinding.split(" ");\r
+            for (int i = 0; i < fvNames.length; ++i) {\r
+                if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {\r
+                    vGuid.add(moduleSa.getModuleGuid());\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+    }\r
+    \r
     public int getFrameworkModulesCount() {\r
         if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
             removeElement(getfpdFrameworkModules());\r
@@ -198,13 +227,13 @@ public class FpdFileContents {
         ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
         int i = 0;\r
         while(li.hasNext()) {\r
-            ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
-            saa[i][0] = msa.getModuleGuid();\r
-            saa[i][1] = msa.getModuleVersion();\r
+            ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();\r
+            saa[i][0] = moduleSa.getModuleGuid();\r
+            saa[i][1] = moduleSa.getModuleVersion();\r
             \r
-            saa[i][2] = msa.getPackageGuid();\r
-            saa[i][3] = msa.getPackageVersion();\r
-            saa[i][4] = listToString(msa.getSupArchList());\r
+            saa[i][2] = moduleSa.getPackageGuid();\r
+            saa[i][3] = moduleSa.getPackageVersion();\r
+            saa[i][4] = listToString(moduleSa.getSupArchList());\r
             ++i;\r
         }\r
     }\r
@@ -230,32 +259,32 @@ public class FpdFileContents {
         }\r
         ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
         while(li.hasNext()) {\r
-            ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
-            if (msa.getModuleGuid().equalsIgnoreCase(s[0]) && msa.getPackageGuid().equalsIgnoreCase(s[2])) {\r
-                if (msa.getModuleVersion() != null) {\r
-                    if (!msa.getModuleVersion().equals(s[1])) {\r
+            ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();\r
+            if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {\r
+                if (moduleSa.getModuleVersion() != null) {\r
+                    if (!moduleSa.getModuleVersion().equals(s[1])) {\r
                         continue;\r
                     }\r
                 }\r
-                if (msa.getPackageVersion() != null) {\r
-                    if (!msa.getPackageVersion().equals(s[3])) {\r
+                if (moduleSa.getPackageVersion() != null) {\r
+                    if (!moduleSa.getPackageVersion().equals(s[3])) {\r
                         continue;\r
                     }\r
                 }\r
                 //ToDo add arch check for s[4]\r
-                if (msa.getSupArchList() != null) {\r
-                    if (!listToString(msa.getSupArchList()).equals(s[4])) {\r
+                if (moduleSa.getSupArchList() != null) {\r
+                    if (!listToString(moduleSa.getSupArchList()).equals(s[4])) {\r
                         continue;\r
                     }\r
                 }\r
-                return msa;\r
+                return moduleSa;\r
             }\r
         }\r
         return null;\r
     }\r
     \r
     private ModuleSADocument.ModuleSA getModuleSA(int i) {\r
-        ModuleSADocument.ModuleSA msa = null;\r
+        ModuleSADocument.ModuleSA moduleSa = null;\r
         if (fpdRoot.getFrameworkModules() == null) {\r
             return null;\r
         }\r
@@ -264,10 +293,10 @@ public class FpdFileContents {
             for (int j = 0; j < i; ++j) {\r
                 cursor.toNextSibling();\r
             }\r
-            msa = (ModuleSADocument.ModuleSA)cursor.getObject();\r
+            moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();\r
         }\r
         cursor.dispose();\r
-        return msa;\r
+        return moduleSa;\r
     }\r
     \r
     public void removeModuleSA(int i) {\r
@@ -311,6 +340,103 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
+    public boolean adjustPcd (int seqModuleSa) throws Exception {\r
+        boolean dataModified = false;\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
+        int pcdCount = getPcdDataCount(seqModuleSa);\r
+        String[][] saaModuleSaPcd = new String[pcdCount][7];\r
+        getPcdData(seqModuleSa, saaModuleSaPcd);\r
+        String mg = moduleSa.getModuleGuid();\r
+        String mv = moduleSa.getModuleVersion();\r
+        String pg = moduleSa.getPackageGuid();\r
+        String pv = moduleSa.getPackageVersion();\r
+        String arch = listToString(moduleSa.getSupArchList());\r
+        //\r
+        // delete pcd in ModuleSA but not in MSA files any longer.\r
+        //\r
+        String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;\r
+        int libCount = getLibraryInstancesCount(moduleKey);\r
+        String[][] saaLib = new String[libCount][5];\r
+        getLibraryInstances(moduleKey, saaLib);\r
+        ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
+        Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();\r
+        vMi.add(mi);\r
+        try {\r
+    nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {\r
+                if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], mi)){\r
+                    continue;\r
+                }\r
+                for (int j = 0; j < saaLib.length; ++j) {\r
+                    String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];\r
+                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);\r
+                    vMi.add(libMi);\r
+                    if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], libMi)) {\r
+                        continue nextPcd;\r
+                    }\r
+                }\r
+                removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);\r
+                dataModified = true;\r
+            }\r
+        }\r
+        catch (Exception e) {\r
+            \r
+        }\r
+        //\r
+        // add new Pcd from MSA file to ModuleSA.\r
+        //\r
+        try {\r
+       \r
+            for (int i = 0; i < vMi.size(); ++i) {\r
+                ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile\r
+                                                                                                                          .getModuleXmlObject(vMi\r
+                                                                                                                                                 .get(i));\r
+                if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {\r
+                    continue;\r
+                }\r
+                ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();\r
+     msaPcdIter:while (li.hasNext()) {\r
+                    PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();\r
+                    ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());\r
+                    if (al != null) {\r
+                        for (int j = 0; j < al.size(); ++j) {\r
+                            if (al.get(j).contains(moduleKey)) {\r
+                                continue msaPcdIter;\r
+                            }\r
+                        }\r
+                    }\r
+                    \r
+                    Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
+                    m.put("ModuleSurfaceArea", msa);\r
+                    SurfaceAreaQuery.setDoc(m);\r
+                    PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));\r
+                    PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
+                    if (spdPcd == null) {\r
+                        //\r
+                        // ToDo Error \r
+                        //\r
+                        throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "\r
+                                                  + mi.getName());\r
+                    }\r
+                    //\r
+                    // AddItem to ModuleSA PcdBuildDefinitions\r
+                    //\r
+                    String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()\r
+                                                                        : msaPcd.getDefaultValue();\r
+\r
+                    genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),\r
+                               msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);\r
+                    dataModified = true;\r
+                 }\r
+\r
+            }\r
+        }\r
+        catch (Exception e){\r
+           throw e;\r
+        }\r
+        \r
+        return dataModified;\r
+    }\r
+    \r
     private void maintainDynPcdMap(String pcdKey, String moduleInfo) {\r
         \r
         ArrayList<String> al = dynPcdMap.get(pcdKey);\r
@@ -331,6 +457,7 @@ public class FpdFileContents {
         }\r
 \r
         if (al.size() == 0) {\r
+            defaultPcdValue.remove(pcdKey);\r
             dynPcdMap.remove(pcdKey);\r
             String[] s1 = pcdKey.split(" ");\r
             removeDynamicPcdBuildData(s1[0], s1[1]);\r
@@ -340,7 +467,7 @@ public class FpdFileContents {
     //\r
     // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
     //\r
-    public int getPcdDataCount(int i){\r
+    public int getPcdDataCount (int i){\r
         ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
         \r
         if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
@@ -350,7 +477,7 @@ public class FpdFileContents {
         \r
     }\r
     \r
-    public void getPcdData(int i, String[][] saa) {\r
+    public void getPcdData (int i, String[][] saa) {\r
         ModuleSADocument.ModuleSA msa = getModuleSA(i);\r
         \r
         if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
@@ -370,13 +497,46 @@ public class FpdFileContents {
         }\r
     }\r
     \r
-    public void updatePcdData(String key, String cName, String tsGuid, String itemType, String maxSize, String value){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
-        if (msa == null || msa.getPcdBuildDefinition() == null){\r
+    public void removePcdData (int seqModuleSa, String cName, String tsGuid) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
+        if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){\r
+            return;\r
+        }\r
+        \r
+        String mg = moduleSa.getModuleGuid();\r
+        String mv = moduleSa.getModuleVersion();\r
+        String pg = moduleSa.getPackageGuid();\r
+        String pv = moduleSa.getPackageVersion();\r
+        String arch = listToString(moduleSa.getSupArchList());\r
+        String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;\r
+        \r
+        XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();\r
+        if (cursor.toFirstChild()){\r
+            \r
+            do {\r
+                PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
+                if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
+                    maintainDynPcdMap(cName + " " + tsGuid, moduleKey);\r
+                    if (getPcdDataCount(seqModuleSa) == 1) {\r
+                        cursor.toParent();\r
+                    }\r
+                    cursor.removeXml();\r
+                    break;\r
+                }\r
+            }\r
+            while(cursor.toNextSibling());\r
+            \r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);\r
+        if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){\r
             return;\r
         }\r
         \r
-        XmlCursor cursor = msa.getPcdBuildDefinition().newCursor();\r
+        XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();\r
         if (cursor.toFirstChild()){\r
             do {\r
                 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
@@ -386,6 +546,7 @@ public class FpdFileContents {
                         pcdData.setMaxDatumSize(new Integer(maxSize));\r
                     }\r
                     pcdData.setValue(value);\r
+                    defaultPcdValue.put(cName + " " + tsGuid, value);\r
                     break;\r
                 }\r
             }\r
@@ -400,10 +561,10 @@ public class FpdFileContents {
      * @param sa Results: HelpText, Original item type.\r
      * @return\r
      */\r
-    public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String[] sa) throws Exception{\r
+    public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{\r
         try {\r
            \r
-            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
+            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);\r
             if (msa.getPcdCoded() == null) {\r
                 return false;\r
             }\r
@@ -411,7 +572,7 @@ public class FpdFileContents {
             Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
             m.put("ModuleSurfaceArea", msa);\r
             SurfaceAreaQuery.setDoc(m);\r
-            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r
+            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
             //\r
             // First look through MSA pcd entries.\r
             //\r
@@ -422,6 +583,9 @@ public class FpdFileContents {
                 if (!msaPcd.getCName().equals(cName)) {\r
                     continue;\r
                 }\r
+                if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {\r
+                    continue;\r
+                }\r
                 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
                 if (spdPcd == null) {\r
                     //\r
@@ -453,7 +617,7 @@ public class FpdFileContents {
      */\r
     public void removePcdData(String moduleKey, ModuleIdentification consumer) {\r
         try {\r
-            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(consumer);\r
+            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);\r
             if (msa.getPcdCoded() == null) {\r
                 return;\r
             }\r
@@ -467,25 +631,18 @@ public class FpdFileContents {
                 if (moduleSA.getPcdBuildDefinition() != null) {\r
                     XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();\r
                     if (cursor.toFirstChild()) {\r
-                        PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor\r
-                                                                                                                                                      .getObject();\r
-                        if (msaPcd.getCName().equals(pcdData.getCName())\r
-                            && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {\r
-\r
-                            maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey);\r
-                            cursor.removeXml();\r
-                            break;\r
-                        }\r
-                        while (cursor.toNextSibling()) {\r
-                            pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor.getObject();\r
+                        do {\r
+                            PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor\r
+                                                                                                                                                          .getObject();\r
                             if (msaPcd.getCName().equals(pcdData.getCName())\r
                                 && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {\r
+\r
                                 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),\r
                                                   moduleKey);\r
                                 cursor.removeXml();\r
                                 break;\r
                             }\r
-                        }\r
+                        } while (cursor.toNextSibling());\r
                     }\r
                     cursor.dispose();\r
                 }\r
@@ -564,14 +721,14 @@ public class FpdFileContents {
         String mn = libMi.getName();\r
         String mg = libMi.getGuid();\r
         String mv = libMi.getVersion();\r
-        String pn = libMi.getPackage().getName();\r
-        String pg = libMi.getPackage().getGuid();\r
-        String pv = libMi.getPackage().getVersion();\r
+        String pn = libMi.getPackageId().getName();\r
+        String pg = libMi.getPackageId().getGuid();\r
+        String pv = libMi.getPackageId().getVersion();\r
         LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();\r
         XmlCursor cursor = instance.newCursor();\r
         try{\r
             String comment = "Pkg: " + pn + " Mod: " + mn \r
-                + " Path: " + GlobalData.getMsaFile(libMi).getPath();\r
+                + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
             cursor.insertComment(comment);\r
         }\r
         catch (Exception e){\r
@@ -589,31 +746,169 @@ public class FpdFileContents {
     }\r
     \r
     public String getFvBinding(String moduleKey){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
-        if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
+        return getFvBinding (moduleSa);\r
+    }\r
+    \r
+    public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {\r
             return null;\r
         }\r
-        return msa.getModuleSaBuildOptions().getFvBinding();\r
+        return moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+    }\r
+    \r
+    public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {\r
+        if (moduleSa == null ) {\r
+            return;\r
+        }\r
+        if (fvBinding == null || fvBinding.length() == 0) {\r
+            if(moduleSa.getModuleSaBuildOptions() != null){\r
+                moduleSa.getModuleSaBuildOptions().unsetFvBinding();\r
+            }\r
+        }\r
+        else {\r
+            if(moduleSa.getModuleSaBuildOptions() == null){\r
+                moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);\r
+                return;\r
+            }\r
+            moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding);\r
+        }\r
     }\r
     \r
     public void setFvBinding(String moduleKey, String fvBinding){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
-        if (msa == null ) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
+        setFvBinding (moduleSa, fvBinding);\r
+    }\r
+    \r
+    private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {\r
+            return -1;\r
+        }\r
+        \r
+        String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+        String[] fvNamesArray = fvNameList.split(" ");\r
+        int occursAt = -1;\r
+        for (int i = 0; i < fvNamesArray.length; ++i) {\r
+            if (fvNamesArray[i].equals(fvName)) {\r
+                occursAt = i;\r
+                break;\r
+            }\r
+        }\r
+        return occursAt;\r
+    }\r
+    \r
+    public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {\r
             return;\r
         }\r
-        if(msa.getModuleSaBuildOptions() == null){\r
-            msa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);\r
+        \r
+        String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+        String[] fvNamesArray = fvNameList.split(" ");\r
+        int occursAt = -1;\r
+        for (int i = 0; i < fvNamesArray.length; ++i) {\r
+            if (fvNamesArray[i].equals(fvName)) {\r
+                occursAt = i;\r
+                break;\r
+            }\r
+        }\r
+        // jump over where the input fvName occurs in the original Fv list.\r
+        if (occursAt != -1) {\r
+            String newFvNameList = " ";\r
+            for (int i = 0; i < fvNamesArray.length; ++i) {\r
+                if (i == occursAt) {\r
+                    continue;\r
+                }\r
+                newFvNameList += fvNamesArray[i];\r
+            }\r
+            setFvBinding (moduleSa, newFvNameList.trim());\r
+        }\r
+\r
+    }\r
+    \r
+    /**\r
+     * @param fvName The FV name that to be removed from FvBinding List.\r
+     */\r
+    public void removeFvBindingAll (String fvName) {\r
+        if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
+            removeElement(getfpdFrameworkModules());\r
+            fpdFrameworkModules = null;\r
+            return;\r
+        }\r
+        \r
+        Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();\r
+        while (li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = li.next();\r
+            removeFvBinding (moduleSa, fvName); \r
+        }\r
+    }\r
+    \r
+    public void appendFvBindingAll (String fvName) {\r
+        if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
+            removeElement(getfpdFrameworkModules());\r
+            fpdFrameworkModules = null;\r
             return;\r
         }\r
-        msa.getModuleSaBuildOptions().setFvBinding(fvBinding);\r
+        \r
+        Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();\r
+        while (li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = li.next();\r
+            appendFvBinding (moduleSa, fvName); \r
+        }\r
+    }\r
+    \r
+    public void appendFvBindingFor (String oldFvName, String newFvName) {\r
+        if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
+            removeElement(getfpdFrameworkModules());\r
+            fpdFrameworkModules = null;\r
+            return;\r
+        }\r
+        \r
+        Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();\r
+        while (li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = li.next();\r
+            String fvBinding = getFvBinding (moduleSa);\r
+            if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {\r
+                appendFvBinding (moduleSa, newFvName); \r
+            }\r
+        }\r
+    }\r
+    \r
+    public void appendFvBinding (String moduleKey, String fvName) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
+        appendFvBinding (moduleSa, fvName);\r
+    }\r
+    \r
+    public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {\r
+        if (moduleSa == null) {\r
+            return;\r
+        }\r
+        \r
+        if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {\r
+            setFvBinding(moduleSa, fvName);\r
+            return;\r
+        }\r
+        \r
+        String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+        String newFvNameList = fvNameList + " " + fvName;\r
+        setFvBinding (moduleSa, newFvNameList.trim());\r
+    }\r
+    \r
+    public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) {\r
+        Vector<Object> vSupArchs = new Vector<Object>();\r
+        getPlatformDefsSupportedArchs(vSupArchs);\r
+        String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion();\r
+        for (int i = 0; i < vSupArchs.size(); ++i) {\r
+            String moduleKey = moduleInfo + " " + vSupArchs.get(i);\r
+            appendFvBinding (moduleKey, fvName);\r
+        }\r
     }\r
     \r
     public String getFfsFileNameGuid(String moduleKey){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
-        if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {\r
             return null;\r
         }\r
-        return msa.getModuleSaBuildOptions().getFfsFileNameGuid();\r
+        return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid();\r
     }\r
     \r
     public void setFfsFileNameGuid(String moduleKey, String fileGuid){\r
@@ -659,6 +954,19 @@ public class FpdFileContents {
         msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);\r
     }\r
     \r
+    public void setModuleSAForceDebug(int i, boolean dbgEnable) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);\r
+        moduleSa.setForceDebug(dbgEnable);\r
+    }\r
+    \r
+    public boolean getModuleSAForceDebug (int i) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);\r
+        if (moduleSa.getForceDebug() == true) {\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+    \r
     public void getModuleSAOptions(String moduleKey, String[][] saa) {\r
         ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
         if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null\r
@@ -680,7 +988,9 @@ public class FpdFileContents {
             \r
             if (opt.getSupArchList() != null){\r
                 saa[i][4] = listToString(opt.getSupArchList());\r
-\r
+            }\r
+            else {\r
+                saa[i][4] = "";\r
             }\r
             \r
             saa[i][5] = opt.getStringValue();\r
@@ -755,7 +1065,7 @@ public class FpdFileContents {
                 moduleSa = genModuleSA(mi, arch);\r
             }\r
             \r
-            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
+            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);\r
             if (msa.getPcdCoded() == null) {\r
                 return;\r
             }\r
@@ -763,7 +1073,7 @@ public class FpdFileContents {
             Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
             m.put("ModuleSurfaceArea", msa);\r
             SurfaceAreaQuery.setDoc(m);\r
-            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r
+            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
             //\r
             // Implementing InitializePlatformPcdBuildDefinitions\r
             //\r
@@ -776,7 +1086,7 @@ public class FpdFileContents {
                     //\r
                     // ToDo Error \r
                     //\r
-                    throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());\r
+                    throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());\r
                 }\r
                 //\r
                 // AddItem to ModuleSA PcdBuildDefinitions\r
@@ -788,7 +1098,7 @@ public class FpdFileContents {
             \r
         }\r
         catch (Exception e){\r
-            e.printStackTrace();\r
+            \r
             throw e; \r
         }\r
         \r
@@ -796,12 +1106,10 @@ public class FpdFileContents {
     \r
     private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {\r
         \r
-        Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
         PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;\r
         for (int i = 0; i < depPkgs.length; ++i) {\r
-            m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));\r
-            SurfaceAreaQuery.setDoc(m);\r
-            XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();\r
+\r
+            XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);\r
             if (xo == null) {\r
                 continue;\r
             }\r
@@ -825,12 +1133,12 @@ public class FpdFileContents {
     }\r
     \r
     private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {\r
-        PackageIdentification pi = GlobalData.getPackageForModule(mi);\r
+        PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);\r
         ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();\r
         XmlCursor cursor = msa.newCursor();\r
         try{\r
-            String comment = "Mod: " + mi.getName() + " Type: " + mi.getModuleType() + " Path: "\r
-                            + GlobalData.getMsaFile(mi).getPath();\r
+            String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "\r
+                            + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
             cursor.insertComment(comment);\r
         }\r
         catch(Exception e){\r
@@ -865,39 +1173,18 @@ public class FpdFileContents {
         if (pcdConsumer == null) {\r
             pcdConsumer = new ArrayList<String>();\r
         }\r
+        //\r
+        // Using existing Pcd type, if this pcd already exists in other ModuleSA\r
+        //\r
+        if (pcdConsumer.size() > 0) {\r
+            String[] valPart = pcdConsumer.get(0).split(" ");\r
+            itemType = valPart[5];\r
+        }\r
         String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r
         + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())\r
         + " " + itemType;\r
         pcdConsumer.add(listValue);\r
         dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);\r
-        //\r
-        // Special dynamic type, if this pcd already exists in other ModuleSA\r
-        //\r
-        if (itemType.equals("DYNAMIC")) {\r
-            \r
-            ListIterator li = pcdConsumer.listIterator();\r
-            while(li.hasNext()) {\r
-                String value = li.next().toString();\r
-                String[] valuePart= value.split(" ");\r
-                if (!valuePart[4].equals("DYNAMIC")) {\r
-                    //ToDo error for same pcd, other type than dynamic\r
-                    pcdConsumer.remove(listValue);\r
-                    throw new PcdItemTypeConflictException(value);\r
-                }\r
-            }\r
-        }\r
-        else {\r
-            ListIterator li = pcdConsumer.listIterator();\r
-            while(li.hasNext()) {\r
-                String value = li.next().toString();\r
-                String[] valuePart= value.split(" ");\r
-                if (valuePart[4].equals("DYNAMIC")) {\r
-                    //ToDo error for same pcd, other type than non-dynamic\r
-                    pcdConsumer.remove(listValue);\r
-                    throw new PcdItemTypeConflictException(value);\r
-                }\r
-            }\r
-        }\r
         \r
         PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();\r
         fpdPcd.setCName(cName);\r
@@ -906,6 +1193,51 @@ public class FpdFileContents {
         fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
         fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));\r
         \r
+        if (defaultVal != null){\r
+            fpdPcd.setValue(defaultVal);\r
+        }\r
+        else {\r
+            if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r
+                fpdPcd.setValue("0");\r
+            }\r
+            if (dataType.equals("BOOLEAN")){\r
+                fpdPcd.setValue("FALSE");\r
+            }\r
+            if (dataType.equals("VOID*")) {\r
+                fpdPcd.setValue("");\r
+            }\r
+        }\r
+        //\r
+        // Using existing pcd value, if this pcd already exists in other moduleSa.\r
+        //\r
+        if (defaultPcdValue.get(cName + " " + tsGuid) == null) {\r
+            defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());\r
+        }\r
+        else {\r
+            fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));\r
+        }\r
+        \r
+        if (dataType.equals("UINT8")){\r
+            fpdPcd.setMaxDatumSize(1);\r
+        }\r
+        if (dataType.equals("UINT16")) {\r
+            fpdPcd.setMaxDatumSize(2);\r
+        }\r
+        if (dataType.equals("UINT32")) {\r
+            fpdPcd.setMaxDatumSize(4);\r
+        }\r
+        if (dataType.equals("UINT64")){\r
+            fpdPcd.setMaxDatumSize(8);\r
+        }\r
+        if (dataType.equals("BOOLEAN")){\r
+            fpdPcd.setMaxDatumSize(1);\r
+        }\r
+        if (dataType.equals("VOID*")) {\r
+            int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r
+            fpdPcd.setMaxDatumSize(maxSize);\r
+        }\r
+        \r
+        \r
         if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {\r
             ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);\r
             //\r
@@ -916,41 +1248,7 @@ public class FpdFileContents {
                 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);\r
             }\r
         }\r
-        else {\r
-            if (defaultVal != null){\r
-                fpdPcd.setValue(defaultVal);\r
-            }\r
-            else {\r
-                if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r
-                    fpdPcd.setValue("0");\r
-                }\r
-                if (dataType.equals("BOOLEAN")){\r
-                    fpdPcd.setValue("false");\r
-                }\r
-                if (dataType.equals("VOID*")) {\r
-                    fpdPcd.setValue("");\r
-                }\r
-            }\r
-            if (dataType.equals("UINT8")){\r
-                fpdPcd.setMaxDatumSize(1);\r
-            }\r
-            if (dataType.equals("UINT16")) {\r
-                fpdPcd.setMaxDatumSize(2);\r
-            }\r
-            if (dataType.equals("UINT32")) {\r
-                fpdPcd.setMaxDatumSize(4);\r
-            }\r
-            if (dataType.equals("UINT64")){\r
-                fpdPcd.setMaxDatumSize(8);\r
-            }\r
-            if (dataType.equals("BOOLEAN")){\r
-                fpdPcd.setMaxDatumSize(1);\r
-            }\r
-            if (dataType.equals("VOID*")) {\r
-                int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r
-                fpdPcd.setMaxDatumSize(maxSize);\r
-            }\r
-        }\r
+        \r
     }\r
     \r
     public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{\r
@@ -1004,7 +1302,7 @@ public class FpdFileContents {
                 \r
                 if (value > 0xFF) {\r
 //                   "[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
-//                   "it is byte array in fact. But the element of %s exceed the byte range",\r
+//                   "it must be a byte array. But the element of %s exceed the byte range",\r
                     throw new PcdValueMalFormed (datum);                               \r
                 }\r
             }\r
@@ -1030,7 +1328,7 @@ public class FpdFileContents {
     \r
     private ArrayList<String> LookupPlatformPcdData(String pcdKey) {\r
         \r
-        return dynPcdMap.get("pcdKey");\r
+        return dynPcdMap.get(pcdKey);\r
     }\r
     \r
     public int getDynamicPcdBuildDataCount() {\r
@@ -1131,11 +1429,11 @@ public class FpdFileContents {
                 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = \r
                     (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
                 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
-                    cursor.removeXml();\r
-                    if (getDynamicPcdBuildDataCount() == 0) {\r
+                    \r
+                    if (getDynamicPcdBuildDataCount() == 1) {\r
                         cursor.toParent();\r
-                        cursor.removeXml();\r
                     }\r
+                    cursor.removeXml();\r
                     cursor.dispose();\r
                     return;\r
                 }\r
@@ -1357,6 +1655,153 @@ public class FpdFileContents {
         return fpdBuildOpts;\r
     }\r
     \r
+    public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {\r
+        QName elementFvName = new QName (xmlNs, "FvName");\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        QName elementInfFileName = new QName(xmlNs, "InfFileName");\r
+        QName elementModule = new QName(xmlNs, "Module");\r
+        \r
+        UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();\r
+        userExts.setUserID("IMAGES");\r
+        userExts.setIdentifier(new BigInteger("1"));\r
+        XmlCursor cursor = userExts.newCursor();\r
+        cursor.toEndToken();\r
+        \r
+        cursor.beginElement(elementFvName);\r
+        cursor.insertChars(fvName);\r
+        cursor.toNextToken();\r
+        \r
+        cursor.beginElement(elementInfFileName);\r
+        cursor.insertChars(fvName + ".inf");\r
+        cursor.toNextToken();\r
+        \r
+        cursor.beginElement(elementIncludeModules);\r
+        for (int i = 0; i < includeModules.size(); ++i) {\r
+            cursor.beginElement(elementModule);\r
+            cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);\r
+            cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]);\r
+            cursor.toEndToken();\r
+            cursor.toNextToken();\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    public int getUserExtsIncModCount (String fvName) {\r
+        if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
+            return -1;\r
+        }\r
+        ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        while (li.hasNext()) {\r
+            UserExtensionsDocument.UserExtensions ues = li.next();\r
+            if (!ues.getUserID().equals("IMAGES")) {\r
+                continue;\r
+            }\r
+            XmlCursor cursor = ues.newCursor();\r
+            cursor.toFirstChild();\r
+            String elementName = cursor.getTextValue();\r
+            if (elementName.equals(fvName)) {\r
+                cursor.toNextSibling(elementIncludeModules);\r
+                if (cursor.toFirstChild()) {\r
+                    int i = 1;\r
+                    for (i = 1; cursor.toNextSibling(); ++i);\r
+                    cursor.dispose();\r
+                    return i;\r
+                }\r
+                cursor.dispose();\r
+                return 0;\r
+            }\r
+            cursor.dispose();\r
+        }\r
+        return -1;\r
+    }\r
+    \r
+    public void getUserExtsIncMods(String fvName, String[][] saa) {\r
+        if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
+            return;\r
+        }\r
+        \r
+        XmlCursor cursor = getfpdBuildOpts().newCursor();\r
+        QName elementUserExts = new QName (xmlNs, "UserExtensions");\r
+        QName attribUserId = new QName ("UserID");\r
+        QName elementFvName = new QName (xmlNs, "FvName");\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        QName attribModuleGuid = new QName("ModuleGuid");\r
+        QName attribBaseName = new QName("BaseName");\r
+        \r
+        if (cursor.toChild(elementUserExts)) {\r
+            do {\r
+                cursor.push();\r
+                if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {\r
+                    cursor.toChild(elementFvName);\r
+                    String elementName = cursor.getTextValue();\r
+                    if (elementName.equals(fvName)) {\r
+                        cursor.toNextSibling(elementIncludeModules);\r
+                        if (cursor.toFirstChild()) {\r
+                            int i = 0;\r
+                            do {\r
+                                saa[i][0] = cursor.getAttributeText(attribModuleGuid);\r
+                                saa[i][1] = cursor.getAttributeText(attribBaseName);\r
+                                ++i;\r
+                            }while (cursor.toNextSibling());\r
+                        }\r
+                        break;\r
+                    }\r
+                }\r
+                cursor.pop();\r
+            }while (cursor.toNextSibling(elementUserExts));\r
+        }\r
+        cursor.dispose();\r
+        \r
+    }\r
+    \r
+    public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {\r
+        if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
+            return;\r
+        }\r
+        ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
+        while (li.hasNext()) {\r
+            UserExtensionsDocument.UserExtensions ues = li.next();\r
+            if (!ues.getUserID().equals("IMAGES")) {\r
+                continue;\r
+            }\r
+            XmlCursor cursor = ues.newCursor();\r
+            cursor.toFirstChild();\r
+            String elementName = cursor.getTextValue();\r
+            if (elementName.equals(oldFvName)) {\r
+                cursor.setTextValue(newFvName);\r
+            }\r
+            cursor.dispose();\r
+        }\r
+        \r
+    }\r
+    \r
+    public void removeBuildOptionsUserExtensions (String fvName) {\r
+        if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
+            return;\r
+        }\r
+        \r
+        ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
+        while (li.hasNext()) {\r
+            UserExtensionsDocument.UserExtensions ues = li.next();\r
+            if (!ues.getUserID().equals("IMAGES")) {\r
+                continue;\r
+            }\r
+            XmlCursor cursor = ues.newCursor();\r
+            cursor.toFirstChild();\r
+            String elementName = cursor.getTextValue();\r
+            if (elementName.equals(fvName)) {\r
+                cursor.toParent();\r
+                cursor.removeXml();\r
+                cursor.dispose();\r
+                return;\r
+            }\r
+            cursor.dispose();\r
+        }\r
+        \r
+    }\r
+    \r
+    \r
     public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r
         UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
         if (udats == null) {\r
@@ -2145,6 +2590,43 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {\r
+        FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
+        if (fis == null || fis.getFvImageList() == null) {\r
+            return;\r
+        }\r
+        \r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            if (fi.getType().toString().equals("ImageName")) {\r
+                vImageNames.addAll(fi.getFvImageNamesList());\r
+                return;\r
+            }\r
+        }\r
+    }\r
+    \r
+    public void AddFvImageFvImageNames (String[] fvNames) {\r
+        FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
+        if (fis == null || fis.getFvImageList() == null) {\r
+            genFvImagesFvImage (fvNames, "ImageName", null);\r
+            return;\r
+        }\r
+        \r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            if (fi.getType().toString().equals("ImageName")) {\r
+                for (int i = 0; i < fvNames.length; ++i) {\r
+                    fi.addFvImageNames(fvNames[i]);\r
+                }\r
+                return;\r
+            }\r
+        }\r
+        genFvImagesFvImage (fvNames, "ImageName", null);\r
+        \r
+    }\r
+    \r
     public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
       \r
         FvImagesDocument.FvImages fis = null;\r
@@ -2204,6 +2686,52 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
+    /**\r
+     * @param oldFvName\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
+    public void updateFvImageNameAll (String oldFvName, String newFvName) {\r
+        if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
+            return;\r
+        }\r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            updateFvImageNamesInFvImage (fi, oldFvName, newFvName);\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * @param fi\r
+     * @param oldFvName The FV Name to be replaced.\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
+    public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {\r
+        QName qFvImageNames = new QName(xmlNs, "FvImageNames");\r
+        XmlCursor cursor = fi.newCursor();\r
+        \r
+        if (cursor.toChild(qFvImageNames)) {\r
+            do {\r
+                if (cursor.getTextValue().equals(oldFvName)){\r
+                    if (newFvName != null) {\r
+                        cursor.setTextValue(newFvName);\r
+                    }\r
+                    else {\r
+                        if (fi.getFvImageNamesList().size() == 1) {\r
+                            removeElement(fi);\r
+                            break;\r
+                        }\r
+                        else {\r
+                            cursor.removeXml();\r
+                        }\r
+                    }\r
+                }\r
+            }while (cursor.toNextSibling(qFvImageNames));\r
+        }\r
+        \r
+        cursor.dispose();\r
+    }\r
+    \r
     public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
            \r
         XmlObject o = getfpdFlash().getFvImages();\r
@@ -2244,18 +2772,50 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
-    public int getFvImagesFvImageCount() {\r
+    public int getFvImagesFvImageCount(String type) {\r
         \r
         if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
             return 0;\r
         }\r
-        return getfpdFlash().getFvImages().getFvImageList().size();\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        int i = 0;\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            \r
+            ++i;\r
+        }\r
+        \r
+        return i;\r
     }\r
     \r
-    /**Only Get Fv image setting - name and type.\r
+    public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();\r
+        if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
+            return vFvImage;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (fi.getFvImageNamesList().contains(fvName)) {\r
+                vFvImage.add(fi);\r
+            }\r
+        }\r
+        \r
+        return vFvImage;\r
+    }\r
+    /**\r
      * @param saa\r
+     * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.\r
      */\r
-    public void getFvImagesFvImages(String[][] saa) {\r
+    public void getFvImagesFvImages(String[][] saa, String type) {\r
     \r
         if (getfpdFlash().getFvImages() == null) {\r
             return;\r
@@ -2268,6 +2828,9 @@ public class FpdFileContents {
         int i = 0;\r
         while(li.hasNext()) {\r
             FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
             //\r
             // get FvImageNames array, space separated\r
             //\r
@@ -2286,6 +2849,108 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    /**Add name-value pair to FvImage element with type.\r
+     * @param fvName FV name to add name-value pair.\r
+     * @param type FvImage attribute.\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (!fi.getFvImageNamesList().contains(fvName)) {\r
+                continue;\r
+            }\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+    }\r
+    \r
+    /**Add to all FvImage elements with type, the name-value pair.\r
+     * @param type\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedFvImageNameValue (String type, String name, String value) {\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+    }\r
+    \r
+    /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.\r
+     * @param fi\r
+     * @param name\r
+     * @param value\r
+     * @param newName\r
+     */\r
+    public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {\r
+        if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+            return;\r
+        }\r
+        \r
+        XmlCursor cursor = fi.getFvImageOptions().newCursor();\r
+        if (cursor.toFirstChild()) {\r
+            do {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();\r
+                if (nv.getName().equals(name)) {\r
+                    nv.setValue(value);\r
+                    if (newName != null) {\r
+                        nv.setName(newName);\r
+                    }\r
+                    cursor.dispose();\r
+                    return;\r
+                }\r
+            }while (cursor.toNextSibling());\r
+        }\r
+        \r
+        FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();\r
+        nv.setName(name);\r
+        nv.setValue(value);\r
+        if (newName != null) {\r
+            nv.setName(newName);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");\r
+        for (int i = 0; i < vFvImage.size(); ++i) {\r
+            FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);\r
+            if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+                continue;\r
+            }\r
+\r
+            ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()\r
+                                                                                            .getNameValueList()\r
+                                                                                            .listIterator();\r
+            while (li.hasNext()) {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
+                m.put(nv.getName(), nv.getValue());\r
+            }\r
+        }\r
+    }\r
     /**Get FvImage Options for FvImage i\r
      * @param i the ith FvImage\r
      */\r
@@ -2320,7 +2985,7 @@ public class FpdFileContents {
         if (fpdHdr == null) {\r
             fpdHdr = fpdRoot.addNewPlatformHeader();\r
         }\r
-        genPlatformDefsSkuInfo("0", "DEFAULT");\r
+        \r
         return fpdHdr;\r
     }\r
     \r
@@ -2464,8 +3129,9 @@ class PcdItemTypeConflictException extends Exception {
     private static final long serialVersionUID = 1L;\r
     private String details = null;\r
     \r
-    PcdItemTypeConflictException(String info){\r
-        details = info;\r
+    PcdItemTypeConflictException(String pcdName, String info){\r
+        ModuleIdentification mi = WorkspaceProfile.getModuleId(info);\r
+        details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();\r
     }\r
     \r
     public String getMessage() {\r
@@ -2482,7 +3148,7 @@ class PcdDeclNotFound extends Exception {
     private String details = null;\r
     \r
     PcdDeclNotFound(String info) {\r
-        details = info;\r
+        details = "PcdDeclNotFound: " + info;\r
     }\r
     \r
     public String getMessage() {\r
@@ -2499,7 +3165,7 @@ class PcdValueMalFormed extends Exception {
     private String details = null;\r
     \r
     PcdValueMalFormed(String info) {\r
-        details = info;\r
+        details = "PcdValueMalFormed: " + info;\r
     }\r
     \r
     public String getMessage() {\r