**/ \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
\r
/** This class is to descript a PCD token object. The information of a token mainly \r
\r
///\r
/// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in\r
- /// platform token space.\r
- /// tokenNumber is defined in SPD, FPD.\r
+ /// platform token space. For Dynamic, dynamicEx type, this number will be re-adjust by\r
+ /// PCD run-time database autogen tools.\r
+ ///\r
+ public long tokenNumber;\r
+\r
///\r
- public int tokenNumber;\r
+ /// This token number is retrieved from FPD file for DynamicEx type. \r
+ /// \r
+ public long dynamicExTokenNumber;\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
\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
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
+ public boolean isDynamicEx() {\r
+ \r
+ for (int i = 0; i < supportedPcdType.size(); i++) {\r
+ if (supportedPcdType.get(i) == PCD_TYPE.DYNAMIC_EX) {\r
+ return true;\r
+ }\r
+ }\r
+ \r
+ return false;\r
}\r
\r
/**\r
}\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
+ public boolean isHiiEnable() {\r
+ if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ public boolean isVpdEnable() {\r
+ if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
/**\r
Get the token primary key in token database.\r
\r
usageInstance.arch,\r
usageInstance.version)) {\r
exceptionStr = String.format("PCD %s for module %s has already exist in database, Please check all PCD build entries "+\r
- "in modules PcdPeim in <ModuleSA> to make sure no duplicated definitions!",\r
+ "in modules %s in <ModuleSA> to make sure no duplicated definitions!",\r
usageInstance.parentToken.cName,\r
+ usageInstance.moduleName,\r
usageInstance.moduleName);\r
throw new EntityException(exceptionStr);\r
}\r
\r
@return string of datum type.\r
**/\r
+\r
public static String getAutogendatumTypeString(DATUM_TYPE datumType) {\r
switch (datumType) {\r
case UINT8:\r
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
+ public int getSkuIdCount () {\r
+ return this.skuData.size();\r
+ }\r
+\r
+ private void getCurrentSizeFromDefaultValue (String str, ArrayList<Integer> al) {\r
+ if (isValidNullValue(str)) {\r
+ al.add(new Integer(0));\r
+ } else {\r
+ //\r
+ // isValidNullValue has already make sure that str here\r
+ // always contain a valid default value of the following 3\r
+ // cases:\r
+ // 1) "Hello world" //Assci string\r
+ // 2) L"Hello" //Unicode string\r
+ // 3) {0x01, 0x02, 0x03} //Byte stream\r
+ //\r
+ if (str.startsWith("\"")) {\r
+ al.add(new Integer(str.length() - 2));\r
+ } else if (str.startsWith("L\"")){\r
+ //\r
+ // Unicode is 2 bytes each.\r
+ //\r
+ al.add(new Integer((str.length() - 3) * 2));\r
+ } else if (str.startsWith("{")) {\r
+ //\r
+ // We count the number of "," in the string.\r
+ // The number of byte is one plus the number of \r
+ // comma.\r
+ //\r
+ String str2 = str;\r
+ \r
+ int cnt = 0;\r
+ int pos = 0;\r
+ pos = str2.indexOf(",", 0);\r
+ while (pos != -1) {\r
+ cnt++;\r
+ pos++;\r
+ pos = str2.indexOf(",", pos);\r
+ }\r
+ cnt++;\r
+ al.add(new Integer(cnt));\r
+ }\r
+ }\r
+ }\r
+ //\r
+ // This method can be used to get the MAX and current size\r
+ // for pointer type dynamic(ex) PCD entry\r
+ //\r
+ public ArrayList<Integer> getPointerTypeSize () {\r
+ ArrayList<Integer> al = new ArrayList<Integer>();\r
+ \r
+ //\r
+ // For VPD_enabled and HII_enabled, we can only return the MAX size.\r
+ // For the default DATA type dynamic PCD entry, we will return\r
+ // the MAX size and current size for each SKU_ID.\r
+ //\r
+ al.add(new Integer(this.datumSize));\r
+ \r
+ if (!this.isVpdEnable()) {\r
+ int idx;\r
+ if (this.isHiiEnable()){\r
+ for (idx = 0; idx < this.skuData.size(); idx++) {\r
+ String str = this.skuData.get(idx).value.hiiDefaultValue;\r
+ getCurrentSizeFromDefaultValue(str, al);\r
+ }\r
+ } else {\r
+ for (idx = 0; idx < this.skuData.size(); idx++) {\r
+ String str = this.skuData.get(idx).value.value;\r
+ getCurrentSizeFromDefaultValue(str, al);\r
+ }\r
+ }\r
+ }\r
+ \r
+ return al;\r
+ }\r
+\r
+ /**\r
+ Get default value for a token, For HII type, HiiDefaultValue of default\r
+ SKU 0 will be returned; For Default type, the defaultvalue of default SKU\r
+ 0 will be returned.\r
+ \r
+ @return String\r
+ */\r
+ public String getDynamicDefaultValue() {\r
+ DynamicTokenValue dynamicData = getDefaultSku();\r
+ if (hasDefaultValue()) {\r
+ switch (dynamicData.type) {\r
+ case DEFAULT_TYPE:\r
+ return dynamicData.value;\r
+ }\r
+ }\r
+\r
+ return null;\r
+ }\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
+ int value = 0;\r
+ boolean isInteger = true;\r
+ DynamicTokenValue dynamicValue = null;\r
\r
- if (hiiEnabled) {\r
+ if (isSkuEnable()) {\r
return true;\r
}\r
+ \r
+ if (this.isDynamicPCD) {\r
+ dynamicValue = getDefaultSku();\r
+ switch (dynamicValue.type) {\r
+ case HII_TYPE:\r
+ return true;\r
+ case VPD_TYPE:\r
+ return true;\r
+ case DEFAULT_TYPE:\r
+ return !isValidNullValue(dynamicValue.value);\r
+ }\r
+ }\r
\r
- if (vpdEnabled) {\r
- return true;\r
+ return false;\r
+ }\r
+\r
+ public boolean isValidNullValue(String judgedValue) {\r
+ String subStr;\r
+ BigInteger bigIntValue;\r
+\r
+ switch (datumType) {\r
+ case UINT8:\r
+ case UINT16:\r
+ case UINT32:\r
+ if (judgedValue.length() > 2) {\r
+ if ((judgedValue.charAt(0) == '0') && \r
+ ((judgedValue.charAt(1) == 'x') || (judgedValue.charAt(1) == 'X'))){\r
+ subStr = judgedValue.substring(2, judgedValue.length());\r
+ bigIntValue = new BigInteger(subStr, 16);\r
+ } else {\r
+ bigIntValue = new BigInteger(judgedValue);\r
+ }\r
+ } else {\r
+ bigIntValue = new BigInteger(judgedValue);\r
+ }\r
+ if (bigIntValue.bitCount() == 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 isHiiDefaultValueUnicodeStringType() {\r
+ DynamicTokenValue dynamicData = getDefaultSku();\r
+ \r
+ if (dynamicData == null)\r
+ return false;\r
+ \r
+ return dynamicData.hiiDefaultValue.startsWith("L\"")\r
+ && dynamicData.hiiDefaultValue.endsWith("\"");\r
+ }\r
+ \r
+ public boolean isHiiDefaultValueASCIIStringType() {\r
+ DynamicTokenValue dynamicData = getDefaultSku();\r
+ \r
+ if (dynamicData == null)\r
+ return false;\r
+ \r
+ return dynamicData.hiiDefaultValue.startsWith("\"")\r
+ && dynamicData.hiiDefaultValue.endsWith("\"");\r
+ }\r
+ \r
+ /**\r
+ Judege whether current value is UNICODE string type.\r
+ @return boolean\r
+ */\r
+ public boolean isUnicodeStringType () {\r
+ String str = getDynamicDefaultValue();\r
\r
- if (datum.toString().compareTo("NoDefault") == 0) {\r
+ if (str == null) {\r
return false;\r
}\r
\r
- return true;\r
+ if (datumType == Token.DATUM_TYPE.POINTER &&\r
+ str.startsWith("L\"") && \r
+ str.endsWith("\"")) {\r
+ return true;\r
+ }\r
+\r
+ return false;\r
}\r
+ \r
+ public boolean isASCIIStringType () {\r
+ String str = getDynamicDefaultValue();\r
\r
- public boolean isStringType () {\r
- String str = datum.toString();\r
+ if (str == null) {\r
+ return false;\r
+ }\r
\r
if (datumType == Token.DATUM_TYPE.POINTER &&\r
- str.startsWith("L\"") && \r
+ str.startsWith("\"") && \r
str.endsWith("\"")) {\r
return true;\r
}\r
return false;\r
}\r
\r
+ public boolean isByteStreamType () {\r
+ String str = getDynamicDefaultValue();\r
+\r
+ if (str == null) {\r
+ return false;\r
+ }\r
+\r
+ if (datumType == Token.DATUM_TYPE.POINTER &&\r
+ str.startsWith("{") && \r
+ str.endsWith("}")) {\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+ \r
+ }\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