X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fpcd%2Fentity%2FToken.java;h=edcbd80aa2aeed8597163a22faf41f6a94e15e74;hb=3534cbb7a33fd3a65d3f9a442f2d6298cae2ce95;hp=5931b8bceb5d15f09f091cef1178cc076241c3a6;hpb=32648c62db4a98cdc7d16cd3d53dc3c76dd1e110;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java index 5931b8bceb..edcbd80aa2 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java @@ -15,11 +15,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ package org.tianocore.build.pcd.entity; +import java.math.BigInteger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; -import org.tianocore.build.pcd.action.ActionMessage; +import org.tianocore.build.pcd.exception.EntityException; /** This class is to descript a PCD token object. The information of a token mainly comes from MSA, SPD and setting produced by platform developer. @@ -61,34 +64,27 @@ public class Token { /// /// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in - /// platform token space. - /// tokenNumber is defined in SPD, FPD. + /// platform token space. For Dynamic, dynamicEx type, this number will be re-adjust by + /// PCD run-time database autogen tools. /// public int tokenNumber; /// - /// The token space name assigned by platform. For Non-DynamicEx driver this value is same. - /// assignedtokenSpaceName is defined in FPD. - /// - public UUID assignedtokenSpaceName; + /// This token number is retrieved from FPD file for DynamicEx type. + /// + public int dynamicExTokenNumber; /// - /// The token number assigned by platform. The number indiect the offset of this token in platform - /// token space. - /// AssgiendtokenNumber is defined in FPD. - /// - public int assignedtokenNumber; + /// All supported PCD type, this value can be retrieved from SPD + /// Currently, only record all PCD type for this token in FPD file. + /// + public List supportedPcdType; /// - /// pcdType is the PCD item type defined by platform developer. - /// - public PCD_TYPE pcdType; - - /// - /// PCDtype is set by platform developer. It is final PCD type of this token. - /// SupportedPcdType is defined in SPD. - /// - public PCD_TYPE[] supportedpcdType; + /// If the token's item type is Dynamic or DynamicEx type, isDynamicPCD + /// is true. + /// + public boolean isDynamicPCD; /// /// datumSize is to descript the fix size or max size for this token. @@ -98,144 +94,84 @@ public class Token { /// /// datum type is to descript what type can be expressed by a PCD token. - /// datumType is defined in SPD. + /// For same PCD used in different module, the datum type should be unique. + /// So it belong memeber to Token class. /// public DATUM_TYPE datumType; - /// - /// Isplatform is to descript whether this token is defined in platform level. - /// If token is belong to platform level. The value can be different for every - /// module. All are determined by platform developer. - /// - public boolean isPlatform; - - /// - /// hiiEnabled is to indicate whether the token support Hii functionality. - /// hiiEnabled is defined in FPD. - /// - public boolean hiiEnabled; - - /// - /// variableName is valid only when this token support Hii functionality. variableName - /// indicates the value of token is associated with what variable. - /// variableName is defined in FPD. - /// - public String variableName; - - /// - /// variableGuid is the GUID this token associated with. - /// variableGuid is defined in FPD. - /// - public UUID variableGuid; - - /// - /// Variable offset indicate the associated variable's offset in NV storage. - /// variableOffset is defined in FPD. - /// - public int variableOffset; - - /// - /// skuEnabled is to indicate whether the token support Sku functionality. - /// skuEnabled is defined in FPD. - /// - public boolean skuEnabled; - - /// - /// skuDataArrayEnabled is to indicate wheter use the skuData array or default value. - /// - public boolean skuDataArrayEnabled; - /// /// skuData contains all value for SkuNumber of token. - /// skuData is defined in FPD. + /// This field is for Dynamic or DynamicEx type PCD, /// public List skuData; - /// - /// maxSkuCount indicate the max count of sku data. - /// maxSkuCount is defined in FPD. - /// - public int maxSkuCount; - - /// - /// SkuId is the id of current selected SKU. - /// SkuId is defined in FPD. - /// - public int skuId; - - /// - /// datum is the value set by platform developer. - /// datum is defined in FPD. - /// - public Object datum; - - /// - /// Default value of this token. - /// This default value is defined in SPD level. - /// - public Object defaultValue; - - /// - /// BUGBUG: fix comment - /// vpdEnabled is defined in FPD. - /// - public boolean vpdEnabled; - - /// - /// BUGBUG: fix comment - /// vpdOffset is defined in FPD. - /// - public long vpdOffset; - - /// - /// producers array record all module private information who produce this PCD token. - /// - public List producers; - /// /// consumers array record all module private information who consume this PCD token. /// - public List consumers; + public Map consumers; - /** - Constructure function. - - Initialize the value of token. - - @param cName The cName of this token - @param tokenSpaceName The tokenSpaceName of this token, it is a GUID. - @param assignedtokenSpaceName The assignedtokenSpaceName of this token, it is a GUID. - - **/ - public Token(String cName, UUID tokenSpaceName, UUID assignedtokenSpaceName) { + public Token(String cName, UUID tokenSpaceName) { UUID nullUUID = new UUID(0, 0); this.cName = cName; - this.tokenSpaceName =(tokenSpaceName == null) ? nullUUID : tokenSpaceName; - this.assignedtokenSpaceName =(assignedtokenSpaceName == null) ? nullUUID : assignedtokenSpaceName; + this.tokenSpaceName = (tokenSpaceName == null) ? nullUUID : tokenSpaceName; this.tokenNumber = 0; - this.assignedtokenNumber = 0; - this.pcdType = PCD_TYPE.UNKNOWN; - this.supportedpcdType = null; - this.isPlatform = false; this.datumType = DATUM_TYPE.UNKNOWN; this.datumSize = -1; - this.defaultValue = null; - this.datum = null; - this.hiiEnabled = false; - this.variableGuid = null; - this.variableName = ""; - this.variableOffset = -1; - this.skuEnabled = false; - this.skuDataArrayEnabled = false; - this.skuId = -1; - this.maxSkuCount = -1; this.skuData = new ArrayList(); - this.vpdEnabled = false; - this.vpdOffset = -1; - this.producers = new ArrayList(); - this.consumers = new ArrayList(); + this.consumers = new HashMap(); + this.supportedPcdType = new ArrayList(); + } + + /** + updateSupportPcdType + + SupportPcdType should be gotten from SPD file actually, but now it just + record all PCD type for this token in FPD file. + + @param pcdType new PCD type found in FPD file for this token. + **/ + public void updateSupportPcdType(PCD_TYPE pcdType) { + int index = 0; + boolean found = false; + for (index = 0; index < this.supportedPcdType.size(); index ++) { + if (this.supportedPcdType.get(index) == pcdType) { + found = true; + break; + } + } + if (!found) { + this.supportedPcdType.add(pcdType); + } + } + + /** + Judge whether pcdType is belong to dynamic type. Dynamic type includes + DYNAMIC and DYNAMIC_EX. + + @param pcdType + + @return boolean + */ + public static boolean isDynamic(PCD_TYPE pcdType) { + if ((pcdType == PCD_TYPE.DYNAMIC ) || + (pcdType == PCD_TYPE.DYNAMIC_EX)) { + return true; + } + + return false; + } + + public boolean isDynamicEx() { + + for (int i = 0; i < supportedPcdType.size(); i++) { + if (supportedPcdType.get(i) == PCD_TYPE.DYNAMIC_EX) { + return true; + } + } + + return false; } /** @@ -247,19 +183,49 @@ public class Token { @return primary key for this token in token database. **/ - public static String getPrimaryKeyString(String cName, UUID tokenSpaceName, - UUID platformtokenSpaceName) { + public static String getPrimaryKeyString(String cName, UUID tokenSpaceName) { UUID nullUUID = new UUID(0, 0); - if (platformtokenSpaceName == nullUUID) { - return cName + "_" + tokenSpaceName.toString().replace('-', '_'); + if (tokenSpaceName == null) { + return cName + "_" + nullUUID.toString().replace('-', '_'); } else { - return cName + "_" + platformtokenSpaceName.toString().replace('-', '_'); + return cName + "_" + tokenSpaceName.toString().replace('-', '_'); + } + } + + /** + If skudata list contains more than one data, then Sku mechanism is enable. + + @return boolean + */ + public boolean isSkuEnable() { + if (this.skuData.size() > 1) { + return true; + } + return false; + } + + public boolean isHiiEnable() { + if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) { + return true; + } + return false; + } + + public boolean isVpdEnable() { + if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) { + return true; } + return false; } + /** + Get the token primary key in token database. + + @return String + */ public String getPrimaryKeyString () { - return cName + "_" + tokenSpaceName.toString().replace('-', '_'); + return Token.getPrimaryKeyString(cName, tokenSpaceName); } /** @@ -302,99 +268,52 @@ public class Token { @retval TRUE - Success to add usage instance. @retval FALSE - Fail to add usage instance **/ - public boolean addUsageInstance(UsageInstance usageInstance) { - if (usageInstance.usage == PCD_USAGE.UNKNOWN) { - return false; + public boolean addUsageInstance(UsageInstance usageInstance) + throws EntityException { + String exceptionStr; + + if (isUsageInstanceExist(usageInstance.moduleName, + usageInstance.moduleGUID, + usageInstance.packageName, + usageInstance.packageGUID, + usageInstance.arch, + usageInstance.version)) { + exceptionStr = String.format("PCD %s for module %s has already exist in database, Please check all PCD build entries "+ + "in modules PcdPeim in to make sure no duplicated definitions!", + usageInstance.parentToken.cName, + usageInstance.moduleName); + throw new EntityException(exceptionStr); } - if ((usageInstance.usage == PCD_USAGE.ALWAYS_PRODUCED) || - (usageInstance.usage == PCD_USAGE.SOMETIMES_PRODUCED)) { - producers.add(usageInstance); - } else { - consumers.add(usageInstance); - } + consumers.put(usageInstance.getPrimaryKey(), usageInstance); return true; } /** - Judge whether exist an usage instance for this token - - @param moduleName Use xmlFilePath as keyword to search the usage instance - - @retval PCD_USAGE - if UsageInstance exists. - @retval UNKNOWN - if UsageInstance does not exist, return UNKONW. - **/ - public PCD_USAGE isUsageInstanceExist(String moduleName) { - int index; - UsageInstance usageInstance; - - if (moduleName == null) { - ActionMessage.warning(this, "Error parameter for isUsageInstanceExist() function!"); - return PCD_USAGE.UNKNOWN; - } - - if (moduleName.length() == 0) { - return PCD_USAGE.UNKNOWN; - } - - // - // Searching the usage instance in module's producer and consumer according to - // module's name. - // - for (index = 0; index < producers.size(); index ++) { - usageInstance =(UsageInstance)producers.get(index); - if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) { - return usageInstance.usage; - } - } - - for (index = 0; index < consumers.size(); index ++) { - usageInstance =(UsageInstance)consumers.get(index); - if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) { - return usageInstance.usage; - } - } - return PCD_USAGE.UNKNOWN; - } - - /** - Get usage instance according to a MSA file name - - @param moduleName The file path string of MSA file. - - @return usage instance object. - **/ - public UsageInstance getUsageInstance(String moduleName) { - int usageIndex; - UsageInstance usageInstance; - - if (moduleName == null) { - ActionMessage.warning(this, "Error parameter for isUsageInstanceExist() function!"); - return null; - } - - if (moduleName.length() == 0) { - return null; - } - - if (producers.size() != 0) { - for (usageIndex = 0; usageIndex < producers.size(); usageIndex ++) { - usageInstance =(UsageInstance)producers.get(usageIndex); - if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) { - return usageInstance; - } - } - } - - if (consumers.size() != 0) { - for (usageIndex = 0; usageIndex < consumers.size(); usageIndex ++) { - usageInstance =(UsageInstance)consumers.get(usageIndex); - if (usageInstance.moduleName.equalsIgnoreCase(moduleName)) { - return usageInstance; - } - } - } - return null; + Judge whether exist an usage instance for this token + + @param moduleName the name of module + @param moduleGuid the GUID name of modules + @param packageName the name of package contains this module + @param packageGuid the GUID name of package contains this module + @param arch the architecture string + @param version the version string + + @return boolean whether exist an usage instance for this token. + */ + public boolean isUsageInstanceExist(String moduleName, + UUID moduleGuid, + String packageName, + UUID packageGuid, + String arch, + String version) { + String keyStr = UsageInstance.getPrimaryKey(moduleName, + moduleGuid, + packageName, + packageGuid, + arch, + version); + return (consumers.get(keyStr) != null); } /** @@ -576,6 +495,7 @@ public class Token { @return string of datum type. **/ + public static String getAutogendatumTypeString(DATUM_TYPE datumType) { switch (datumType) { case UINT8: @@ -639,32 +559,164 @@ public class Token { return uuid; } + public DynamicTokenValue getDefaultSku() { + DynamicTokenValue dynamicData; + int index; + for (index = 0; index < this.skuData.size(); index ++) { + if (skuData.get(index).id == 0) { + return skuData.get(index).value; + } + } + + return null; + } + + public int getSkuIdCount () { + return this.skuData.size(); + } + + + /** + Get default value for a token, For HII type, HiiDefaultValue of default + SKU 0 will be returned; For Default type, the defaultvalue of default SKU + 0 will be returned. + + @return String + */ + public String getDynamicDefaultValue() { + DynamicTokenValue dynamicData = getDefaultSku(); + if (hasDefaultValue()) { + switch (dynamicData.type) { + case HII_TYPE: + return dynamicData.hiiDefaultValue; + case DEFAULT_TYPE: + return dynamicData.value; + } + } + + return null; + } + // // BugBug: We need change this algorithm accordingly when schema is updated // to support no default value. // public boolean hasDefaultValue () { + int value = 0; + boolean isInteger = true; + DynamicTokenValue dynamicValue = null; - if (hiiEnabled) { + if (isSkuEnable()) { return true; } + + if (this.isDynamicPCD) { + dynamicValue = getDefaultSku(); + switch (dynamicValue.type) { + case HII_TYPE: + return true; + case VPD_TYPE: + return true; + case DEFAULT_TYPE: + return !isValidNullValue(dynamicValue.value); + } + } - if (vpdEnabled) { - return true; + return false; + } + + public boolean isValidNullValue(String judgedValue) { + int intValue; + String subStr; + BigInteger bigIntValue; + + switch (datumType) { + case UINT8: + case UINT16: + case UINT32: + if (judgedValue.length() > 2) { + if ((judgedValue.charAt(0) == '0') && + ((judgedValue.charAt(1) == 'x') || (judgedValue.charAt(1) == 'X'))){ + subStr = judgedValue.substring(2, judgedValue.length()); + bigIntValue = new BigInteger(subStr, 16); + } else { + bigIntValue = new BigInteger(judgedValue); + } + } else { + bigIntValue = new BigInteger(judgedValue); + } + if (bigIntValue.bitCount() == 0) { + return true; + } + break; + case UINT64: + if (judgedValue.length() > 2){ + if ((judgedValue.charAt(0) == '0') && + ((judgedValue.charAt(1) == 'x') || + (judgedValue.charAt(1) == 'X'))) { + bigIntValue = new BigInteger(judgedValue.substring(2, judgedValue.length()), 16); + if (bigIntValue.bitCount() == 0) { + return true; + } + } else { + bigIntValue = new BigInteger(judgedValue); + if (bigIntValue.bitCount() == 0) { + return true; + } + } + } else { + bigIntValue = new BigInteger(judgedValue); + if (bigIntValue.bitCount() == 0) { + return true; + } + } + break; + case BOOLEAN: + if (judgedValue.equalsIgnoreCase("false")) { + return true; + } + break; + case POINTER: + if (judgedValue.equalsIgnoreCase("") || + judgedValue.equalsIgnoreCase("\"\"") || + judgedValue.equalsIgnoreCase("L\"\"") || + (judgedValue.length() == 0) || + judgedValue.equalsIgnoreCase("{}")) { + return true; + } } + return false; + } - if (datum.toString().compareTo("NoDefault") == 0) { + /** + Judege whether current value is UNICODE string type. + @return boolean + */ + public boolean isUnicodeStringType () { + String str = getDynamicDefaultValue(); + + if (str == null) { return false; } - return true; + if (datumType == Token.DATUM_TYPE.POINTER && + str.startsWith("L\"") && + str.endsWith("\"")) { + return true; + } + + return false; } + + public boolean isASCIIStringType () { + String str = getDynamicDefaultValue(); - public boolean isStringType () { - String str = datum.toString(); + if (str == null) { + return false; + } if (datumType == Token.DATUM_TYPE.POINTER && - str.startsWith("L\"") && + str.startsWith("\"") && str.endsWith("\"")) { return true; } @@ -672,8 +724,25 @@ public class Token { return false; } + public boolean isByteStreamType () { + String str = getDynamicDefaultValue(); + + if (str == null) { + return false; + } + + if (datumType == Token.DATUM_TYPE.POINTER && + str.startsWith("{") && + str.endsWith("}")) { + return true; + } + + return false; + + } + public String getStringTypeString () { - return datum.toString().substring(2, datum.toString().length() - 1); + return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1); } }