]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java
Add many datum and datum size checking in PCD building tools, These checking work...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / entity / Token.java
index 3136864872a7559034622b6f7d437297b2fe6725..f5765e1d408fa1e9b7ef2ffc8452235bed26f34d 100644 (file)
@@ -15,11 +15,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/  \r
 package org.tianocore.build.pcd.entity;\r
 \r
+import java.math.BigInteger;\r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
-import java.util.UUID;\r
 import java.util.Map;\r
-import java.util.HashMap;\r
+import java.util.UUID;\r
 \r
 import org.tianocore.build.pcd.action.ActionMessage;\r
 import org.tianocore.build.pcd.exception.EntityException;\r
@@ -70,9 +71,16 @@ public class Token {
     public int              tokenNumber;\r
 \r
     ///\r
-    /// pcdType is the PCD item type defined by platform developer.\r
+    /// All supported PCD type, this value can be retrieved from SPD\r
+    /// Currently, only record all PCD type for this token in FPD file.\r
+    /// \r
+    public List<PCD_TYPE>   supportedPcdType;\r
+\r
     ///\r
-    public PCD_TYPE         pcdType;\r
+    /// If the token's item type is Dynamic or DynamicEx type, isDynamicPCD\r
+    /// is true.\r
+    /// \r
+    public boolean          isDynamicPCD;\r
 \r
     ///\r
     /// datumSize is to descript the fix size or max size for this token. \r
@@ -82,77 +90,17 @@ public class Token {
 \r
     ///\r
     /// datum type is to descript what type can be expressed by a PCD token.\r
-    /// datumType is defined in SPD.\r
+    /// For same PCD used in different module, the datum type should be unique.\r
+    /// So it belong memeber to Token class.\r
     ///\r
     public DATUM_TYPE       datumType;\r
 \r
-    ///\r
-    /// hiiEnabled is to indicate whether the token support Hii functionality.\r
-    /// hiiEnabled is defined in FPD.\r
-    ///\r
-    public boolean          hiiEnabled;\r
-\r
-    ///\r
-    /// variableName is valid only when this token support Hii functionality. variableName\r
-    /// indicates the value of token is associated with what variable.\r
-    /// variableName is defined in FPD.\r
-    ///\r
-    public String           variableName;\r
-\r
-    ///\r
-    /// variableGuid is the GUID this token associated with.\r
-    /// variableGuid is defined in FPD.\r
-    ///\r
-    public UUID             variableGuid;\r
-\r
-    ///\r
-    /// Variable offset indicate the associated variable's offset in NV storage.\r
-    /// variableOffset is defined in FPD.\r
-    ///\r
-    public int              variableOffset;\r
-\r
-    ///\r
-    /// skuEnabled is to indicate whether the token support Sku functionality.\r
-    /// skuEnabled is defined in FPD.\r
-    ///\r
-    public boolean          skuEnabled;\r
-\r
     ///\r
     /// skuData contains all value for SkuNumber of token.\r
-    /// skuData is defined in FPD.\r
+    /// This field is for Dynamic or DynamicEx type PCD, \r
     ///\r
     public List<SkuInstance> skuData;\r
 \r
-    ///\r
-    /// maxSkuCount indicate the max count of sku data.\r
-    /// maxSkuCount is defined in FPD.\r
-    ///\r
-    public int              maxSkuCount;\r
-\r
-    ///\r
-    /// SkuId is the id of current selected SKU.\r
-    /// SkuId is defined in FPD.\r
-    ///\r
-    public int              skuId;\r
-\r
-    ///\r
-    /// datum is the value set by platform developer.\r
-    /// datum is defined in FPD.\r
-    ///\r
-    public Object           datum;\r
-\r
-    ///\r
-    /// BUGBUG: fix comment\r
-    /// vpdEnabled is defined in FPD.\r
-    ///\r
-    public boolean          vpdEnabled;\r
-\r
-    ///\r
-    /// BUGBUG: fix comment\r
-    /// vpdOffset is defined in FPD.\r
-    ///\r
-    public long             vpdOffset;\r
-\r
     ///\r
     /// consumers array record all module private information who consume this PCD token.\r
     ///\r
@@ -164,22 +112,51 @@ public class Token {
         this.cName                  = cName;\r
         this.tokenSpaceName         = (tokenSpaceName == null) ? nullUUID : tokenSpaceName;\r
         this.tokenNumber            = 0;\r
-        this.pcdType                = PCD_TYPE.UNKNOWN;\r
         this.datumType              = DATUM_TYPE.UNKNOWN;\r
         this.datumSize              = -1;\r
-        this.datum                  = null;\r
-        this.hiiEnabled             = false;\r
-        this.variableGuid           = null;\r
-        this.variableName           = "";\r
-        this.variableOffset         = -1;\r
-        this.skuEnabled             = false;\r
-        this.skuId                  = -1;\r
-        this.maxSkuCount            = -1;\r
         this.skuData                = new ArrayList<SkuInstance>();\r
-        this.vpdEnabled             = false;\r
-        this.vpdOffset              = -1;\r
 \r
         this.consumers              = new HashMap<String, UsageInstance>();\r
+        this.supportedPcdType       = new ArrayList<PCD_TYPE>();\r
+    }\r
+\r
+    /**\r
+      updateSupportPcdType\r
+      \r
+      SupportPcdType should be gotten from SPD file actually, but now it just\r
+      record all PCD type for this token in FPD file.\r
+      \r
+      @param pcdType    new PCD type found in FPD file for this token.\r
+    **/\r
+    public void updateSupportPcdType(PCD_TYPE pcdType) {\r
+        int     index = 0;\r
+        boolean found = false;\r
+        for (index = 0; index < this.supportedPcdType.size(); index ++) {\r
+            if (this.supportedPcdType.get(index) == pcdType) {\r
+                found = true;\r
+                break;\r
+            }\r
+        }\r
+        if (!found) {\r
+            this.supportedPcdType.add(pcdType);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Judge whether pcdType is belong to dynamic type. Dynamic type includes\r
+       DYNAMIC and DYNAMIC_EX.\r
+       \r
+       @param pcdType\r
+       \r
+       @return boolean\r
+     */\r
+    public static boolean isDynamic(PCD_TYPE pcdType) {\r
+        if ((pcdType == PCD_TYPE.DYNAMIC   ) ||\r
+            (pcdType == PCD_TYPE.DYNAMIC_EX)) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
     }\r
 \r
     /**\r
@@ -201,6 +178,18 @@ public class Token {
         }\r
     }\r
 \r
+    /**\r
+       If skudata list contains more than one data, then Sku mechanism is enable.\r
+       \r
+       @return boolean\r
+     */\r
+    public boolean isSkuEnable() {\r
+        if (this.skuData.size() > 1) {\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
     /**\r
        Get the token primary key in token database.\r
        \r
@@ -540,33 +529,100 @@ public class Token {
         return uuid;\r
     }\r
 \r
+    public DynamicTokenValue getDefaultSku() {\r
+        DynamicTokenValue dynamicData;\r
+        int               index;\r
+        for (index = 0; index < this.skuData.size(); index ++) {\r
+            if (skuData.get(index).id == 0) {\r
+                return skuData.get(index).value;\r
+            }\r
+        }\r
+\r
+        return null;\r
+    }\r
     //\r
     // BugBug: We need change this algorithm accordingly when schema is updated\r
     //          to support no default value.\r
     //\r
     public boolean hasDefaultValue () {\r
-\r
-        if (hiiEnabled) {\r
-            return true;\r
+        int               value         = 0;\r
+        boolean           isInteger     = true;\r
+        DynamicTokenValue dynamicValue  = null;\r
+\r
+        if (this.isDynamicPCD) {\r
+            dynamicValue = getDefaultSku();\r
+            switch (dynamicValue.type) {\r
+            case HII_TYPE:\r
+                return !isValidNullValue(dynamicValue.hiiDefaultValue);\r
+            case VPD_TYPE:\r
+                return false;\r
+            case DEFAULT_TYPE:\r
+                return !isValidNullValue(dynamicValue.value);\r
+            }\r
         }\r
 \r
-        if (vpdEnabled) {\r
-            return true;\r
-        }\r
+        return false;\r
+    }\r
 \r
-        if (datum.toString().compareTo("NoDefault") == 0) {\r
-            return false;\r
-        }\r
+    public boolean isValidNullValue(String judgedValue) {\r
+        int         intValue;\r
+        BigInteger  bigIntValue;\r
 \r
-        return true;\r
+        switch (datumType) {\r
+        case UINT8:\r
+        case UINT16:\r
+        case UINT32:\r
+            intValue = Integer.decode(judgedValue);\r
+            if (intValue == 0) {\r
+                return true;\r
+            }\r
+            break;\r
+        case UINT64:\r
+            if (judgedValue.length() > 2){\r
+                if ((judgedValue.charAt(0) == '0') && \r
+                    ((judgedValue.charAt(1) == 'x') ||\r
+                     (judgedValue.charAt(1) == 'X'))) {\r
+                    bigIntValue = new BigInteger(judgedValue.substring(2, judgedValue.length()),  16);\r
+                    if (bigIntValue.bitCount() == 0) {\r
+                        return true;\r
+                    }\r
+                } else {\r
+                    bigIntValue = new BigInteger(judgedValue);\r
+                    if (bigIntValue.bitCount() == 0) {\r
+                        return true;\r
+                    }\r
+                }\r
+            } else  {\r
+                bigIntValue = new BigInteger(judgedValue);\r
+                if (bigIntValue.bitCount() == 0) {\r
+                    return true;\r
+                }\r
+            }\r
+            break;\r
+        case BOOLEAN:\r
+            if (judgedValue.equalsIgnoreCase("false")) {\r
+                return true;\r
+            }\r
+            break;\r
+        case POINTER:\r
+            if (judgedValue.equalsIgnoreCase("")        ||\r
+                judgedValue.equalsIgnoreCase("\"\"")   ||\r
+                judgedValue.equalsIgnoreCase("L\"\"")   ||\r
+                (judgedValue.length() == 0)             ||\r
+                judgedValue.equalsIgnoreCase("{}")) {\r
+                return true;\r
+            }\r
+        }\r
+        return false;\r
     }\r
 \r
     public boolean isStringType () {\r
-        String str = datum.toString();\r
+        String str = getDefaultSku().value;\r
 \r
-        if (datumType == Token.DATUM_TYPE.POINTER &&\r
-            str.startsWith("L\"") && \r
-            str.endsWith("\"")) {\r
+        //\r
+        // BUGBUG: need scott confirmation.\r
+        // \r
+        if (datumType == Token.DATUM_TYPE.POINTER) {\r
             return true;\r
         }\r
 \r
@@ -574,7 +630,7 @@ public class Token {
     }\r
 \r
     public String getStringTypeString () {                       \r
-        return datum.toString().substring(2, datum.toString().length() - 1);\r
+        return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);\r
     }\r
 }\r
 \r