]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Modify PCD tool according to final PCD schema modification.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / CollectPCDAction.java
index 4001558ef697092f2c897a3a32b84cc74923c07b..4057c417e44783e1e10771b860ae36766d101673 100644 (file)
@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.pcd.action;\r
 \r
-import java.io.BufferedReader;\r
+import java.io.BufferedReader;                                                    \r
 import java.io.File;\r
 import java.io.FileReader;\r
 import java.io.IOException;\r
@@ -31,20 +31,21 @@ import java.util.UUID;
 \r
 import org.apache.xmlbeans.XmlException;\r
 import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData;\r
 import org.tianocore.FrameworkModulesDocument;\r
 import org.tianocore.FrameworkPlatformDescriptionDocument;\r
 import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription;\r
 import org.tianocore.ModuleSADocument;\r
 import org.tianocore.ModuleSADocument.ModuleSA;\r
 import org.tianocore.PackageSurfaceAreaDocument;\r
-import org.tianocore.PcdBuildDeclarationsDocument.PcdBuildDeclarations.PcdBuildData;\r
-import org.tianocore.PcdBuildDeclarationsDocument.PcdBuildDeclarations.PcdBuildData.SkuData;\r
-import org.tianocore.PcdDefinitionsDocument.PcdDefinitions;\r
-import org.tianocore.PcdDynamicBuildDeclarationsDocument.PcdDynamicBuildDeclarations;\r
-import org.tianocore.build.autogen.CommonDefinition;\r
+import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.pcd.action.ActionMessage;\r
+import org.tianocore.build.pcd.entity.DynamicTokenValue;\r
 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.pcd.entity.SkuInstance;\r
 import org.tianocore.build.pcd.entity.Token;\r
@@ -421,8 +422,8 @@ class SkuIdTable {
 \r
         int index;\r
 \r
-        Integer [] skuIds = new Integer[token.maxSkuCount + 1];\r
-        skuIds[0] = new Integer(token.maxSkuCount);\r
+        Integer [] skuIds = new Integer[token.skuData.size() + 1];\r
+        skuIds[0] = new Integer(token.skuData.size());\r
         for (index = 1; index < skuIds.length; index++) {\r
             skuIds[index] = new Integer(token.skuData.get(index - 1).id);\r
         }\r
@@ -516,15 +517,15 @@ class LocalTokenNumberTable {
             str += " | PCD_TYPE_STRING";\r
         }\r
 \r
-        if (token.skuEnabled) {\r
+        if (token.isSkuEnable()) {\r
             str += " | PCD_TYPE_SKU_ENABLED";\r
         }\r
 \r
-        if (token.hiiEnabled) {\r
+        if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
             str += " | PCD_TYPE_HII";\r
         }\r
 \r
-        if (token.vpdEnabled) {\r
+        if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
             str += " | PCD_TYPE_VPD";\r
         }\r
         \r
@@ -723,11 +724,11 @@ class PcdDatabase {
     }\r
 \r
     private int getAlignmentSize (Token token) {\r
-        if (token.hiiEnabled) {\r
+        if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
             return 2;\r
         }\r
 \r
-        if (token.vpdEnabled) {\r
+        if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
             return 4;\r
         }\r
 \r
@@ -760,7 +761,8 @@ class PcdDatabase {
         return hString;\r
     }\r
 \r
-     public void genCode () {\r
+     public void genCode () \r
+        throws EntityException {\r
 \r
         final String newLine                        = "\r\n";\r
         final String declNewLine                    = ";\r\n";\r
@@ -924,7 +926,8 @@ class PcdDatabase {
         return str;\r
     }\r
 \r
-    private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken) {\r
+    private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken) \r
+        throws EntityException {\r
 \r
         HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();\r
 \r
@@ -936,7 +939,7 @@ class PcdDatabase {
         for (int index = 0; index < alToken.size(); index++) {\r
             Token token = alToken.get(index);\r
 \r
-            if (token.skuEnabled) {\r
+            if (token.isSkuEnable()) {\r
                 //\r
                 // BugBug: Schema only support Data type now\r
                 //\r
@@ -955,10 +958,10 @@ class PcdDatabase {
                 }\r
 \r
             } else {\r
-                if (token.hiiEnabled) {\r
+                if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
                     decl.add(getVariableEnableTypeDeclaration(token));\r
                     inst.add(getVariableEnableInstantiation(token));\r
-                } else if (token.vpdEnabled) {\r
+                } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
                     decl.add(getVpdEnableTypeDeclaration(token));\r
                     inst.add(getVpdEnableTypeInstantiation(token));\r
                 } else if (token.isStringType()) {\r
@@ -1011,10 +1014,10 @@ class PcdDatabase {
         } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
             typeStr = "BOOLEAN %s_%s[%d];\r\n";\r
         } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
-            return String.format("UINT8 %s_s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
+            return String.format("UINT8 %s_%s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());\r
         } \r
 \r
-        return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.maxSkuCount);\r
+        return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.skuData.size());\r
 \r
     }\r
 \r
@@ -1022,12 +1025,12 @@ class PcdDatabase {
         String str = "";\r
 \r
         if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
-            return String.format("UINT8 %s_s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
+            return String.format("UINT8 %s_%s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());\r
         } else {\r
             str = "{ ";\r
-            for (int idx = 0; idx < token.maxSkuCount; idx++) {\r
+            for (int idx = 0; idx < token.skuData.size(); idx++) {\r
                 str += token.skuData.get(idx).toString();\r
-                if (idx != token.maxSkuCount - 1) {\r
+                if (idx != token.skuData.size() - 1) {\r
                     str += ", ";\r
                 }\r
             }\r
@@ -1041,9 +1044,9 @@ class PcdDatabase {
     private String getDataTypeInstantiation (Token token) {\r
 \r
         if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
-            return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
+            return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());\r
         } else {\r
-            return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
+            return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());\r
         }\r
     }\r
 \r
@@ -1075,7 +1078,7 @@ class PcdDatabase {
     }\r
 \r
     private String getVpdEnableTypeInstantiation (Token token) {\r
-        return String.format("{ %d } /* %s */", token.vpdOffset,\r
+        return String.format("{ %s } /* %s */", token.getDefaultSku().vpdOffset,\r
                                                 token.getPrimaryKeyString());\r
     }\r
 \r
@@ -1093,10 +1096,14 @@ class PcdDatabase {
       return String.format("VARIABLE_HEAD  %s", token.getPrimaryKeyString());\r
     }\r
 \r
-    private String getVariableEnableInstantiation (Token token) {\r
-        return String.format("{ %d, %d, %d } /* %s */", guidTable.add(token.variableGuid, token.getPrimaryKeyString()),\r
-                                                        stringTable.add(token.variableName, token),\r
-                                                        token.variableOffset, \r
+    private String getVariableEnableInstantiation (Token token) \r
+        throws EntityException {\r
+        //\r
+        // Need scott fix\r
+        // \r
+        return String.format("{ %d, %d, %s } /* %s */", guidTable.add(token.getDefaultSku().variableGuid, token.getPrimaryKeyString()),\r
+                                                        stringTable.add(token.getDefaultSku().getStringOfVariableName(), token),\r
+                                                        token.getDefaultSku().variableOffset, \r
                                                         token.getPrimaryKeyString());\r
     }\r
 \r
@@ -1287,7 +1294,6 @@ public class CollectPCDAction {
         // memory database.\r
         //\r
         createTokenInDBFromFPD();\r
-\r
         \r
         //\r
         // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
@@ -1436,25 +1442,29 @@ public class CollectPCDAction {
         int                                 index             = 0;\r
         int                                 index2            = 0;\r
         int                                 pcdIndex          = 0;\r
-        List<PcdBuildData>                  pcdBuildDataArray = new ArrayList<PcdBuildData>();\r
-        PcdBuildData                        pcdBuildData      = null;\r
+        List<PcdBuildDefinition.PcdData>    pcdBuildDataArray = new ArrayList<PcdBuildDefinition.PcdData>();\r
+        PcdBuildDefinition.PcdData          pcdBuildData      = null;\r
         Token                               token             = null;\r
-        UUID                                nullUUID          = new UUID(0,0);\r
-        UUID                                platformTokenSpace= nullUUID;\r
         SkuInstance                         skuInstance       = null;\r
         int                                 skuIndex          = 0;\r
         List<ModuleInfo>                    modules           = null;\r
         String                              primaryKey        = null;\r
-        PcdBuildData.SkuData[]              skuDataArray      = null;\r
         String                              exceptionString   = null;\r
         UsageInstance                       usageInstance     = null;\r
         String                              primaryKey1       = null;\r
         String                              primaryKey2       = null;\r
         boolean                             isDuplicate       = false;\r
-        java.util.List<java.lang.String>    tokenGuidStringArray = null;\r
+        Token.PCD_TYPE                      pcdType           = Token.PCD_TYPE.UNKNOWN;\r
+        Token.DATUM_TYPE                    datumType         = Token.DATUM_TYPE.UNKNOWN;\r
+        int                                 tokenNumber       = 0;\r
+        String                              moduleName        = null;\r
+        String                              datum             = null;\r
+        int                                 maxDatumSize      = 0;\r
 \r
         //\r
-        // Get all <ModuleSA> from FPD file.\r
+        // ----------------------------------------------\r
+        // 1), Get all <ModuleSA> from FPD file.\r
+        // ----------------------------------------------\r
         // \r
         modules = getComponentsFromFPD();\r
 \r
@@ -1463,7 +1473,9 @@ public class CollectPCDAction {
         }\r
 \r
         //\r
-        // Loop all modules to process <PcdBuildDeclarations> for each module.\r
+        // -------------------------------------------------------------------\r
+        // 2), Loop all modules to process <PcdBuildDeclarations> for each module.\r
+        // -------------------------------------------------------------------\r
         // \r
         for (index = 0; index < modules.size(); index ++) {\r
             isDuplicate =  false;\r
@@ -1494,52 +1506,122 @@ public class CollectPCDAction {
                 continue;\r
             }\r
 \r
-            if (modules.get(index).module.getPcdBuildDeclarations() == null) {\r
-                continue;\r
-            }\r
-            pcdBuildDataArray = modules.get(index).module.getPcdBuildDeclarations().getPcdBuildDataList();\r
-            if (pcdBuildDataArray == null) {\r
+           //\r
+           // It is legal for a module does not contains ANY pcd build definitions.\r
+           // \r
+           if (modules.get(index).module.getPcdBuildDefinition() == null) {\r
                 continue;\r
-            }\r
-            if (pcdBuildDataArray.size() == 0) {\r
-                continue;\r
-            }\r
+           }\r
+    \r
+            pcdBuildDataArray = modules.get(index).module.getPcdBuildDefinition().getPcdDataList();\r
+\r
+            moduleName = modules.get(index).module.getModuleName();\r
 \r
             //\r
-            // Loop all Pcd entry for a module and add it into memory database.\r
+            // ----------------------------------------------------------------------\r
+            // 2.1), Loop all Pcd entry for a module and add it into memory database.\r
+            // ----------------------------------------------------------------------\r
             // \r
             for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
                 pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
                 primaryKey   = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
                                                          translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
+                pcdType      = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
+                datumType    = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
+                tokenNumber  = Integer.decode(pcdBuildData.getToken().toString());\r
+                datum        = pcdBuildData.getValue();\r
+                maxDatumSize = pcdBuildData.getMaxDatumSize();\r
 \r
+                //\r
+                // -------------------------------------------------------------------------------------------\r
+                // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule\r
+                // -------------------------------------------------------------------------------------------\r
+                // \r
+                if (!Token.isDynamic(pcdType)) {\r
+                     //\r
+                     // Value is required.\r
+                     // \r
+                     if (datum == null) {\r
+                         exceptionString = String.format("There is no value for PCD entry %s in module %s!",\r
+                                                         pcdBuildData.getCName(),\r
+                                                         moduleName);\r
+                         throw new EntityException(exceptionString);\r
+                     }\r
+\r
+                     //\r
+                     // Check whether the datum size is matched datum type.\r
+                     // \r
+                     if ((exceptionString = verifyDatumSize(pcdBuildData.getCName(), \r
+                                                            moduleName,\r
+                                                            maxDatumSize, \r
+                                                            datumType)) != null) {\r
+                         throw new EntityException(exceptionString);\r
+                     }\r
+                }\r
 \r
+                //\r
+                // ---------------------------------------------------------------------------------\r
+                // 2.1.2), Create token or update token information for current anaylized PCD data.\r
+                // ---------------------------------------------------------------------------------\r
+                // \r
                 if (dbManager.isTokenInDatabase(primaryKey)) {\r
                     //\r
                     // If the token is already exist in database, do some necessary checking\r
                     // and add a usage instance into this token in database\r
                     // \r
                     token = dbManager.getTokenByKey(primaryKey);\r
+    \r
+                    //\r
+                    // checking for DatumType, DatumType should be unique for one PCD used in different\r
+                    // modules.\r
+                    // \r
+                    if (token.datumType != datumType) {\r
+                        exceptionString = String.format("The datum type of PCD entry %s is %s, which is different with  %s defined in before!",\r
+                                                        pcdBuildData.getCName(), \r
+                                                        pcdBuildData.getDatumType().toString(), \r
+                                                        Token.getStringOfdatumType(token.datumType));\r
+                        throw new EntityException(exceptionString);\r
+                    }\r
 \r
                     //\r
-                    // Checking for DatumSize\r
+                    // Check token number is valid\r
                     // \r
-                    if (token.datumSize != pcdBuildData.getDatumSize()) {\r
-                        exceptionString = String.format("The datum size of PCD entry %s is %d, which is different with %d defined in before!",\r
-                                                        pcdBuildData.getCName(),  pcdBuildData.getDatumSize(), token.datumSize);\r
+                    if (tokenNumber != token.tokenNumber) {\r
+                        exceptionString = String.format("The token number of PCD entry %s in module %s is different with same PCD entry in other modules!",\r
+                                                        pcdBuildData.getCName(),\r
+                                                        moduleName);\r
                         throw new EntityException(exceptionString);\r
                     }\r
 \r
                     //\r
-                    // checking for DatumType\r
+                    // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.\r
                     // \r
-                    if (token.datumType != Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString())) {\r
-                        exceptionString = String.format("The datum type of PCD entry %s is %s, which is different with  %s defined in before!",\r
-                                                        pcdBuildData.getCName(), \r
-                                                        pcdBuildData.getDatumType().toString(), \r
-                                                        Token.getStringOfdatumType(token.datumType));\r
+                    if (token.isDynamicPCD != Token.isDynamic(pcdType)) {\r
+                        exceptionString = String.format("For PCD entry %s in module %s, you define dynamic or non-dynamic PCD type which"+\r
+                                                        "is different with others module's",\r
+                                                        token.cName,\r
+                                                        moduleName);\r
                         throw new EntityException(exceptionString);\r
                     }\r
+\r
+                    if (token.isDynamicPCD) {\r
+                        //\r
+                        // Check datum is equal the datum in dynamic information.\r
+                        // For dynamic PCD, you can do not write <Value> in sperated every <PcdBuildDefinition> in different <ModuleSA>,\r
+                        // But if you write, the <Value> must be same as the value in <DynamicPcdBuildDefinitions>.\r
+                        // \r
+                        if (!token.isSkuEnable() && \r
+                            (token.skuData.get(0).value.type == DynamicTokenValue.VALUE_TYPE.DEFAULT_TYPE)) {\r
+                            if (!datum.equalsIgnoreCase(token.skuData.get(0).value.value)) {\r
+                                exceptionString = String.format("For dynamic PCD %s in module %s, the datum in <ModuleSA> is "+\r
+                                                                "not equal to the datum in <DynamicPcdBuildDefinitions>, it is "+\r
+                                                                "illega! You can choose no <Value> in <ModuleSA>!",\r
+                                                                token.cName,\r
+                                                                moduleName);\r
+                            }\r
+                        }\r
+                    }\r
+                    \r
                 } else {\r
                     //\r
                     // If the token is not in database, create a new token instance and add\r
@@ -1547,71 +1629,73 @@ public class CollectPCDAction {
                     // \r
                     token = new Token(pcdBuildData.getCName(), \r
                                       translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
-\r
-                    token.datum         = pcdBuildData.getDefaultValue();\r
-                    token.pcdType       = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
-                    token.datumType     = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
-                    token.datumSize     = pcdBuildData.getDatumSize();\r
-                    token.skuId         = Integer.decode(pcdBuildData.getSkuId());\r
-\r
-                    if (pcdBuildData.getToken() == null) {\r
-                        exceptionString = String.format("In FPD file, No <TokenNumber> defined for PCD entry %s in module %s",\r
-                                                        token.cName,\r
-                                                        modules.get(index).module.getModuleName());\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-                    token.tokenNumber = Integer.decode(pcdBuildData.getToken().getStringValue());\r
-\r
-                    if ((token.pcdType == Token.PCD_TYPE.DYNAMIC) ||\r
-                        (token.pcdType == Token.PCD_TYPE.DYNAMIC_EX)) {\r
-                        updateDynamicInformation(modules.get(index).module.getModuleName(),  token);\r
+    \r
+                    token.datumType     = datumType;\r
+                    token.tokenNumber   = tokenNumber;\r
+                    token.isDynamicPCD  = Token.isDynamic(pcdType);\r
+                    token.datumSize     = maxDatumSize;\r
+                    \r
+                    if (token.isDynamicPCD) {\r
+                        //\r
+                        // For Dynamic and Dynamic Ex type, need find the dynamic information\r
+                        // in <DynamicPcdBuildDefinition> section in FPD file.\r
+                        // \r
+                        updateDynamicInformation(moduleName, \r
+                                                 token,\r
+                                                 datum,\r
+                                                 maxDatumSize);\r
                     }\r
-\r
+    \r
                     dbManager.addTokenToDatabase(primaryKey, token);\r
                 }\r
 \r
                 //\r
-                // Create an usage instance for this token\r
+                // -----------------------------------------------------------------------------------\r
+                // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.\r
+                // -----------------------------------------------------------------------------------\r
+                // \r
+                token.updateSupportPcdType(pcdType);\r
+\r
+                //\r
+                // ------------------------------------------------\r
+                // 2.1.4), Create an usage instance for this token.\r
+                // ------------------------------------------------\r
                 // \r
                 usageInstance = new UsageInstance(token, \r
-                                                  Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()),\r
-                                                  modules.get(index).module.getModuleName(), \r
+                                                  moduleName, \r
                                                   translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()),\r
                                                   modules.get(index).module.getPackageName(),\r
                                                   translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()),\r
                                                   modules.get(index).type, \r
-                                                  Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()),\r
+                                                  pcdType,\r
                                                   modules.get(index).module.getArch().toString(), \r
                                                   null,\r
-                                                  pcdBuildData.getDefaultValue());\r
+                                                  datum,\r
+                                                  maxDatumSize);\r
                 token.addUsageInstance(usageInstance);\r
             }\r
         }\r
     }\r
 \r
     /**\r
-       Update dynamic information for PCD entry.\r
+       Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
        \r
-       Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in\r
-       FPD file.\r
+       This function should be implemented in GlobalData in future.\r
        \r
-       @param moduleName\r
-       @param token\r
+       @param token         The token instance which has hold module's PCD information\r
+       @param moduleName    The name of module who will use this Dynamic PCD.\r
        \r
-       @return Token\r
-    **/\r
-    private Token updateDynamicInformation(String moduleName, Token token) \r
+       @return DynamicPcdBuildDefinitions.PcdBuildData\r
+     */\r
+    /***/\r
+    private DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFPD(Token     token,\r
+                                                                          String    moduleName)\r
         throws EntityException {\r
-        PcdDynamicBuildDeclarations                pcdDynamicBuildDescriptions = null;\r
-        \r
-        boolean                                    isFound                     = false;            \r
-        int                                        index                       = 0;\r
-        String                                     primaryKey                  = null;\r
-        SkuInstance                                skuInstance                 = null;\r
-        int                                        skuIndex                    = 0;\r
-        String                                     exceptionString             = null;\r
-        PcdDynamicBuildDeclarations.PcdBuildData.SkuData[] skuDataArray             = null;\r
-        List<PcdDynamicBuildDeclarations.PcdBuildData>     pcdDynamicBuildDataArray = null;\r
+        int    index             = 0;\r
+        String exceptionString   = null;\r
+        String dynamicPrimaryKey = null;\r
+        DynamicPcdBuildDefinitions                    dynamicPcdBuildDefinitions = null;\r
+        List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray   = null;\r
 \r
         //\r
         // If FPD document is not be opened, open and initialize it.\r
@@ -1626,109 +1710,238 @@ public class CollectPCDAction {
             }\r
         }\r
 \r
-        pcdDynamicBuildDescriptions = fpdDocInstance.getFrameworkPlatformDescription().getPcdDynamicBuildDeclarations();\r
-        if (pcdDynamicBuildDescriptions == null) {\r
-            throw new EntityException(String.format("There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
-                                                    "PCD entry %s in module %s!",\r
-                                                    token.cName,\r
-                                                    moduleName));\r
+        dynamicPcdBuildDefinitions = fpdDocInstance.getFrameworkPlatformDescription().getDynamicPcdBuildDefinitions();\r
+        if (dynamicPcdBuildDefinitions == null) {\r
+            exceptionString = String.format("There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
+                                            "PCD entry %s in module %s!",\r
+                                            token.cName,\r
+                                            moduleName);\r
+            throw new EntityException(exceptionString);\r
         }\r
 \r
-        pcdDynamicBuildDataArray    = pcdDynamicBuildDescriptions.getPcdBuildDataList();\r
-        if (pcdDynamicBuildDataArray == null) {\r
-            throw new EntityException(String.format("There are no PcdDynamicBuildData in <PcdDynamicBuildDeclaration> section but contains Dynamic type"+\r
-                                                    "PCD entry %s in module %s.!",\r
-                                                    token.cName,\r
-                                                    moduleName));\r
+        dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
+        for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
+            dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
+                                                          translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid()));\r
+            if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
+                return dynamicPcdBuildDataArray.get(index);\r
+            }\r
         }\r
 \r
-        isFound = false;\r
-        for (index = 0; index < pcdDynamicBuildDataArray.size(); index ++) {\r
-            if (pcdDynamicBuildDataArray.get(index).getTokenSpaceGuidList().size() != 0) {\r
-                primaryKey = Token.getPrimaryKeyString(pcdDynamicBuildDataArray.get(index).getCName(), \r
-                                                       translateSchemaStringToUUID(pcdDynamicBuildDataArray.get(index).getTokenSpaceGuidList().get(0)));\r
-            } else {\r
-                primaryKey = Token.getPrimaryKeyString(pcdDynamicBuildDataArray.get(index).getCName(), \r
-                                                       translateSchemaStringToUUID(null));\r
+        return null;\r
+    }\r
+\r
+    /**\r
+       Verify the maxDatumSize for a PCD data is matched to Datum type.\r
+       \r
+       @param token             The token instance\r
+       @param moduleName        The module name who use this PCD data.\r
+       @param maxDatumSize      The value of max datum size in FPD file\r
+       @param datumType         The datum type\r
+       \r
+       @return String           if is unmatched, set the exception information\r
+                                as return value, otherwice is null.\r
+    **/\r
+    private String verifyDatumSize(String           cName, \r
+                                   String           moduleName,\r
+                                   int              maxDatumSize, \r
+                                   Token.DATUM_TYPE datumType) {\r
+        String exceptionString = null;\r
+        switch (datumType) {\r
+        case UINT8:\r
+            if (maxDatumSize != 1) {\r
+                exceptionString = String.format("In FPD file, the datum type of PCD data %s in module %s "+\r
+                                                "is UINT8, but datum size is %d, they are not matched!",\r
+                                                cName,\r
+                                                moduleName,\r
+                                                maxDatumSize);\r
+            }\r
+            break;\r
+        case UINT16:\r
+            if (maxDatumSize != 2) {\r
+                exceptionString = String.format("In FPD file, the datum type of PCD data %s in module %s "+\r
+                                                "is UINT16, but datum size is %d, they are not matched!",\r
+                                                cName,\r
+                                                moduleName,\r
+                                                maxDatumSize);\r
+            }\r
+            break;\r
+        case UINT32:\r
+            if (maxDatumSize != 4) {\r
+                exceptionString = String.format("In FPD file, the datum type of PCD data %s in module %s "+\r
+                                                "is UINT32, but datum size is %d, they are not matched!",\r
+                                                cName,\r
+                                                moduleName,\r
+                                                maxDatumSize);\r
             }\r
+            break;\r
+        case UINT64:\r
+            if (maxDatumSize != 8) {\r
+                exceptionString = String.format("In FPD file, the datum type of PCD data %s in module %s "+\r
+                                                "is UINT64, but datum size is %d, they are not matched!",\r
+                                                cName,\r
+                                                moduleName,\r
+                                                maxDatumSize);\r
+            }\r
+            break;\r
+        case BOOLEAN:\r
+            if (maxDatumSize != 1) {\r
+                exceptionString = String.format("In FPD file, the datum type of PCD data %s in module %s "+\r
+                                                "is BOOLEAN, but datum size is %d, they are not matched!",\r
+                                                cName,\r
+                                                moduleName,\r
+                                                maxDatumSize);\r
+            }\r
+            break;\r
+        }\r
 \r
-            if (primaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
-                isFound = true;\r
+        return exceptionString;\r
+    }\r
 \r
-                //\r
-                // For Hii related value\r
-                // \r
-                token.hiiEnabled    = pcdDynamicBuildDataArray.get(index).getHiiEnable();\r
-                if (token.hiiEnabled) {\r
-                    token.variableGuid      = Token.getGUIDFromSchemaObject(pcdDynamicBuildDataArray.get(index).getVariableGuid());\r
-                    if (token.variableGuid == null) {\r
-                        throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
-                                                                "but no <VariableGuid> is found! Please fix the FPD file!",\r
-                                                                token.cName));\r
+    /**\r
+       Update dynamic information for PCD entry.\r
+       \r
+       Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in\r
+       FPD file.\r
+       \r
+       @param moduleName        The name of the module who use this PCD\r
+       @param token             The token instance\r
+       @param datum             The <datum> in module's PCD information\r
+       @param maxDatumSize      The <maxDatumSize> in module's PCD information\r
+       \r
+       @return Token\r
+     */\r
+    private Token updateDynamicInformation(String   moduleName, \r
+                                           Token    token,\r
+                                           String   datum,\r
+                                           int      maxDatumSize) \r
+        throws EntityException {\r
+        int                 index           = 0;\r
+        int                 offset;\r
+        String              exceptionString = null;\r
+        DynamicTokenValue   dynamicValue;\r
+        SkuInstance         skuInstance     = null;\r
+        String              temp;\r
+        boolean             hasSkuId0       = false;\r
+\r
+        List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo>   skuInfoList = null;\r
+        DynamicPcdBuildDefinitions.PcdBuildData                 dynamicInfo = null;\r
+\r
+        dynamicInfo = getDynamicInfoFromFPD(token, moduleName);\r
+        if (dynamicInfo == null) {\r
+            exceptionString = String.format("For Dynamic PCD %s used by module %s, "+\r
+                                            "there is no dynamic information in <DynamicPcdBuildDefinitions> "+\r
+                                            "in FPD file, but it is required!",\r
+                                            token.cName,\r
+                                            moduleName);\r
+            throw new EntityException(exceptionString);\r
+        }\r
 \r
-                    }\r
-                    token.variableName      = pcdDynamicBuildDataArray.get(index).getVariableName();\r
-                    if (token.variableName == null) {\r
-                        throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
-                                                                "but no <VariableName> is found! Please fix the FPD file!",\r
-                                                                token.cName));\r
-                    }\r
+        skuInfoList = dynamicInfo.getSkuInfoList();\r
 \r
-                    if (pcdDynamicBuildDataArray.get(index).getDataOffset() == null) {\r
-                        throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
-                                                                "but no <DataOffset> is found! Please fix the FPD file!",\r
-                                                                token.cName));\r
-                    }\r
-                    token.variableOffset    = Integer.decode(pcdDynamicBuildDataArray.get(index).getDataOffset());\r
-                }\r
+        //\r
+        // Loop all sku data \r
+        // \r
+        for (index = 0; index < skuInfoList.size(); index ++) {\r
+            skuInstance = new SkuInstance();\r
+            //\r
+            // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.\r
+            // \r
+            temp = skuInfoList.get(index).getSkuId().toString();\r
+            skuInstance.id = Integer.decode(temp);\r
 \r
-                //\r
-                // For Vpd related value\r
-                // \r
-                token.vpdEnabled    = pcdDynamicBuildDataArray.get(index).getVpdEnable();\r
-                if (token.vpdEnabled) {\r
-                    if (pcdDynamicBuildDataArray.get(index).getDataOffset() == null) {\r
-                        throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, VpdEnable is true" +\r
-                                                                "but no <DataOffset> is found! Please fix the FPD file!",\r
-                                                                token.cName));\r
-                    }\r
-                    token.vpdOffset         = Integer.decode(pcdDynamicBuildDataArray.get(index).getDataOffset());\r
-                }\r
+            if (skuInstance.id == 0) {\r
+                hasSkuId0 = true;\r
+            }\r
+            //\r
+            // Judge whether is DefaultGroup at first, because most case is DefautlGroup.\r
+            // \r
+            if (skuInfoList.get(index).getValue() != null) {\r
+                skuInstance.value.setValue(skuInfoList.get(index).getValue());\r
+                token.skuData.add(skuInstance);\r
 \r
                 //\r
-                // For SkuData\r
+                // Judege wether is same of datum between module's information\r
+                // and dynamic information.\r
                 // \r
-                token.skuEnabled    = pcdDynamicBuildDataArray.get(index).getSkuEnable();\r
-                if (token.skuEnabled) {\r
-                    skuDataArray      = (PcdDynamicBuildDeclarations.PcdBuildData.SkuData[])pcdDynamicBuildDataArray.get(index).getSkuDataList().toArray();\r
-                    token.maxSkuCount = Integer.decode(pcdDynamicBuildDataArray.get(index).getMaxSku());\r
-                    if (skuDataArray == null) {\r
-                        exceptionString = String.format("In FPD file, the <SkuEnable> is true for PCD entry %s in module %s, But no any sku data.",\r
-                                                        token.cName, moduleName);\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-                    if (token.maxSkuCount != pcdDynamicBuildDataArray.get(index).sizeOfSkuDataArray()) {\r
-                        exceptionString = String.format("In FPD file, <MaxSku> is not equal to the size of <SkuDataArray> for PCD entry %s in module %s",\r
-                                                        token.cName, moduleName);\r
+                if (datum != null) {\r
+                    if ((skuInstance.id == 0)                                   &&\r
+                        !datum.equalsIgnoreCase(skuInfoList.get(index).getValue())) {\r
+                        exceptionString = String.format("For dynamic PCD %s, module %s give <datum> as %s which is different with "+\r
+                                                        "Sku 0's <datum> %s defined in <DynamicPcdBuildDefinitions>! Please sync them at first!",\r
+                                                        token.cName,\r
+                                                        datum,\r
+                                                        skuInfoList.get(index).getValue());\r
                         throw new EntityException(exceptionString);\r
                     }\r
+                }\r
+                continue;\r
+            }\r
 \r
-                    for (skuIndex = 0; skuIndex < pcdDynamicBuildDataArray.get(index).sizeOfSkuDataArray(); skuIndex ++) {\r
-                        skuInstance = new SkuInstance(skuDataArray[skuIndex].getId(),\r
-                                                      skuDataArray[skuIndex].getValue());\r
-                        token.skuData.add(skuInstance);\r
-                    }\r
+            //\r
+            // Judge whether is HII group case.\r
+            // \r
+            if (skuInfoList.get(index).getVariableName() != null) {\r
+                exceptionString = null;\r
+                if (skuInfoList.get(index).getVariableGuid() == null) {\r
+                    exceptionString = String.format("For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+                                                    "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",\r
+                                                    token.cName,\r
+                                                    index);\r
+                                                    \r
+                }\r
+\r
+                if (skuInfoList.get(index).getVariableOffset() == null) {\r
+                    exceptionString = String.format("For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+                                                    "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",\r
+                                                    token.cName,\r
+                                                    index);\r
+                }\r
+\r
+                if (skuInfoList.get(index).getHiiDefaultValue() == null) {\r
+                    exceptionString = String.format("For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
+                                                    "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",\r
+                                                    token.cName,\r
+                                                    index);\r
                 }\r
-                break;\r
+\r
+                if (exceptionString != null) {\r
+                    throw new EntityException(exceptionString);\r
+                }\r
+                offset = Integer.decode(skuInfoList.get(index).getVariableOffset());\r
+                if (offset > 0xFFFF) {\r
+                    throw new EntityException(String.format("For dynamic PCD %s ,  the variable offset defined in sku %d data "+\r
+                                                            "exceed 64K, it is not allowed!",\r
+                                                            token.cName,\r
+                                                            index));\r
+                }\r
+\r
+                skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(),\r
+                                             translateSchemaStringToUUID(skuInfoList.get(index).getVariableGuid().toString()),\r
+                                             skuInfoList.get(index).getVariableOffset(),\r
+                                             skuInfoList.get(index).getHiiDefaultValue());\r
+                token.skuData.add(skuInstance);\r
+                continue;\r
             }\r
-        }\r
-        if (!isFound) {\r
-            exceptionString = String.format("In FPD file, No dynamic PCD data for PCD entry %s in module %s",\r
-                                            token.cName,\r
-                                            moduleName);\r
+\r
+            if (skuInfoList.get(index).getVpdOffset() != null) {\r
+                skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());\r
+                token.skuData.add(skuInstance);\r
+                continue;\r
+            }\r
+\r
+            exceptionString = String.format("For dynamic PCD %s, the dynamic info must "+\r
+                                            "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",\r
+                                            token.cName);\r
             throw new EntityException(exceptionString);\r
         }\r
 \r
+        if (!hasSkuId0) {\r
+            exceptionString = String.format("For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+\r
+                                            "no sku id = 0 data, which is required for every dynamic PCD",\r
+                                            token.cName);\r
+        }\r
+\r
         return token;\r
     }\r
 \r
@@ -1764,6 +1977,11 @@ public class CollectPCDAction {
             return null;\r
         }\r
 \r
+        if (uuidString.equals("0") ||\r
+            uuidString.equalsIgnoreCase("0x0")) {\r
+            return new UUID(0, 0);\r
+        }\r
+\r
         //\r
         // If the UUID schema string is GuidArrayType type then need translate \r
         // to GuidNamingConvention type at first.\r
@@ -1848,11 +2066,11 @@ public class CollectPCDAction {
     **/\r
     public static void main(String argv[]) throws EntityException {\r
         CollectPCDAction ca = new CollectPCDAction();\r
-        ca.setWorkspacePath("M:/ForPcd/edk2");\r
-        ca.setFPDFilePath("M:/ForPcd/edk2/EdkNt32Pkg/Nt32.fpd");\r
+        ca.setWorkspacePath("m:/tianocore/edk2");\r
+        ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
         ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            "M:/ForPcd/edk2");\r
+                            "m:/tianocore/edk2");\r
         ca.execute();\r
     }\r
 }\r