X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fpcd%2Faction%2FCollectPCDAction.java;h=dc60cc6eb75ae1d5e29cfaf68ce43e055bacfc4c;hb=5a2a95923dd196b09a9c5dcf96ff4293426611e4;hp=fe09be2b9ab136c8297cf413a8cba2c0431a322a;hpb=7db4ab705a654e2202b083968e92d5b552007d6b;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index fe09be2b9a..dc60cc6eb7 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -21,6 +21,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -33,8 +34,8 @@ import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.DynamicPcdBuildDefinitionsDocument; import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions; -import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo; import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData; +import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo; import org.tianocore.FrameworkModulesDocument; import org.tianocore.FrameworkPlatformDescriptionDocument; import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription; @@ -513,7 +514,7 @@ class LocalTokenNumberTable { str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString()); - if (token.isStringType()) { + if (token.isUnicodeStringType()) { str += " | PCD_TYPE_STRING"; } @@ -732,7 +733,7 @@ class PcdDatabase { return 4; } - if (token.isStringType()) { + if (token.isUnicodeStringType()) { return 2; } @@ -964,7 +965,7 @@ class PcdDatabase { } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) { decl.add(getVpdEnableTypeDeclaration(token)); inst.add(getVpdEnableTypeInstantiation(token)); - } else if (token.isStringType()) { + } else if (token.isUnicodeStringType()) { decl.add(getStringTypeDeclaration(token)); inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token)); } @@ -1485,15 +1486,15 @@ public class CollectPCDAction { // , It is work around code. // primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).module.getModuleName(), - translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()), - modules.get(index).module.getPackageName(), - translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()), + null, + null, + null, modules.get(index).module.getArch().toString(), null); primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(), - translateSchemaStringToUUID(modules.get(index2).module.getModuleGuid()), - modules.get(index2).module.getPackageName(), - translateSchemaStringToUUID(modules.get(index2).module.getPackageGuid()), + null, + null, + null, modules.get(index2).module.getArch().toString(), null); if (primaryKey1.equalsIgnoreCase(primaryKey2)) { @@ -1529,9 +1530,33 @@ public class CollectPCDAction { pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()); datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString()); tokenNumber = Integer.decode(pcdBuildData.getToken().toString()); - datum = pcdBuildData.getValue(); + if (pcdBuildData.getValue() != null) { + datum = pcdBuildData.getValue().toString(); + } else { + datum = null; + } maxDatumSize = pcdBuildData.getMaxDatumSize(); + if ((pcdType == Token.PCD_TYPE.FEATURE_FLAG) && + (datumType != Token.DATUM_TYPE.BOOLEAN)){ + exceptionString = String.format("[FPD file error] For PCD %s in module %s, the PCD type is FEATRUE_FLAG but "+ + "datum type of this PCD entry is not BOOLEAN!", + pcdBuildData.getCName(), + moduleName); + throw new EntityException(exceptionString); + } + + // + // Check is exist? In future, because all schema verification will tools + // will check that, following checking code could be removed. + // + if (pcdBuildData.getTokenSpaceGuid() == null) { + exceptionString = String.format("[FPD file error] There is no for PCD %s in module %s! This is required!", + pcdBuildData.getCName(), + moduleName); + throw new EntityException(exceptionString); + } + // // ------------------------------------------------------------------------------------------- // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule @@ -1551,10 +1576,11 @@ public class CollectPCDAction { // // Check whether the datum size is matched datum type. // - if ((exceptionString = verifyDatumSize(pcdBuildData.getCName(), - moduleName, - maxDatumSize, - datumType)) != null) { + if ((exceptionString = verifyDatum(pcdBuildData.getCName(), + moduleName, + datum, + datumType, + maxDatumSize)) != null) { throw new EntityException(exceptionString); } } @@ -1676,9 +1702,9 @@ public class CollectPCDAction { // usageInstance = new UsageInstance(token, moduleName, - translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()), - modules.get(index).module.getPackageName(), - translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()), + null, + null, + null, modules.get(index).type, pcdType, modules.get(index).module.getArch().toString(), @@ -1690,6 +1716,331 @@ public class CollectPCDAction { } } + /** + Verify the datum value according its datum size and datum type, this + function maybe moved to FPD verification tools in future. + + @param cName + @param moduleName + @param datum + @param datumType + @param maxDatumSize + + @return String + */ + /***/ + public String verifyDatum(String cName, + String moduleName, + String datum, + Token.DATUM_TYPE datumType, + int maxDatumSize) { + String exceptionString = null; + int value; + BigInteger value64; + String subStr; + int index; + + if (moduleName == null) { + moduleName = "section "; + } else { + moduleName = "module " + moduleName; + } + + if (maxDatumSize == 0) { + exceptionString = String.format("[FPD file error] You maybe miss for PCD %s in %s", + cName, + moduleName); + return exceptionString; + } + + switch (datumType) { + case UINT8: + if (maxDatumSize != 1) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is UINT8, but datum size is %d, they are not matched!", + cName, + moduleName, + maxDatumSize); + return exceptionString; + } + + if (datum != null) { + try { + value = Integer.decode(datum); + } catch (NumberFormatException nfeExp) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+ + "digital format of UINT8", + cName, + moduleName); + return exceptionString; + } + if (value > 0xFF) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+ + " the max size of UINT8 - 0xFF", + cName, + moduleName, + datum); + return exceptionString; + } + } + break; + case UINT16: + if (maxDatumSize != 2) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is UINT16, but datum size is %d, they are not matched!", + cName, + moduleName, + maxDatumSize); + return exceptionString; + } + if (datum != null) { + try { + value = Integer.decode(datum); + } catch (NumberFormatException nfeExp) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+ + "not valid digital of UINT16", + cName, + moduleName); + return exceptionString; + } + if (value > 0xFFFF) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+ + "which exceed the range of UINT16 - 0xFFFF", + cName, + moduleName, + datum); + return exceptionString; + } + } + break; + case UINT32: + if (maxDatumSize != 4) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is UINT32, but datum size is %d, they are not matched!", + cName, + moduleName, + maxDatumSize); + return exceptionString; + } + + if (datum != null) { + try { + if (datum.length() > 2) { + if ((datum.charAt(0) == '0') && + ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){ + subStr = datum.substring(2, datum.length()); + value64 = new BigInteger(subStr, 16); + } else { + value64 = new BigInteger(datum); + } + } else { + value64 = new BigInteger(datum); + } + } catch (NumberFormatException nfeExp) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+ + "valid digital of UINT32", + cName, + moduleName); + return exceptionString; + } + + if (value64.bitLength() > 32) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+ + "exceed the range of UINT32 - 0xFFFFFFFF", + cName, + moduleName, + datum); + return exceptionString; + } + } + break; + case UINT64: + if (maxDatumSize != 8) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is UINT64, but datum size is %d, they are not matched!", + cName, + moduleName, + maxDatumSize); + return exceptionString; + } + + if (datum != null) { + try { + if (datum.length() > 2) { + if ((datum.charAt(0) == '0') && + ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){ + subStr = datum.substring(2, datum.length()); + value64 = new BigInteger(subStr, 16); + } else { + value64 = new BigInteger(datum); + } + } else { + value64 = new BigInteger(datum); + } + } catch (NumberFormatException nfeExp) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+ + " digital of UINT64", + cName, + moduleName); + return exceptionString; + } + + if (value64.bitLength() > 64) { + exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+ + "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF", + cName, + moduleName, + datum); + return exceptionString; + } + } + break; + case BOOLEAN: + if (maxDatumSize != 1) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is BOOLEAN, but datum size is %d, they are not matched!", + cName, + moduleName, + maxDatumSize); + return exceptionString; + } + + if (datum != null) { + if (!(datum.equalsIgnoreCase("TRUE") || + datum.equalsIgnoreCase("FALSE"))) { + exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ + "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'", + cName, + moduleName); + return exceptionString; + } + + } + break; + case POINTER: + if (datum == null) { + break; + } + + char ch = datum.charAt(0); + int start, end; + String strValue; + // + // For void* type PCD, only three datum is support: + // 1) Unicode: string with start char is "L" + // 2) Ansci: String start char is "" + // 3) byte array: String start char "{" + // + if (ch == 'L') { + start = datum.indexOf('\"'); + end = datum.lastIndexOf('\"'); + if ((start > end) || + (end > datum.length())|| + ((start == end) && (datum.length() > 0))) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+ + "a UNICODE string because start with L\", but format maybe"+ + "is not right, correct UNICODE string is L\"...\"!", + cName, + moduleName); + return exceptionString; + } + + strValue = datum.substring(start + 1, end); + if ((strValue.length() * 2) > maxDatumSize) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+ + "a UNICODE string, but the datum size is %d exceed to : %d", + cName, + moduleName, + strValue.length() * 2, + maxDatumSize); + return exceptionString; + } + } else if (ch == '\"'){ + start = datum.indexOf('\"'); + end = datum.lastIndexOf('\"'); + if ((start > end) || + (end > datum.length())|| + ((start == end) && (datum.length() > 0))) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+ + "a ANSCII string because start with \", but format maybe"+ + "is not right, correct ANSIC string is \"...\"!", + cName, + moduleName); + return exceptionString; + } + strValue = datum.substring(start + 1, end); + if ((strValue.length()) > maxDatumSize) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+ + "a ANSCI string, but the datum size is %d which exceed to : %d", + cName, + moduleName, + strValue.length(), + maxDatumSize); + return exceptionString; + } + } else if (ch =='{') { + String[] strValueArray; + + start = datum.indexOf('{'); + end = datum.lastIndexOf('}'); + strValue = datum.substring(start + 1, end); + strValue = strValue.trim(); + if (strValue.length() == 0) { + break; + } + strValueArray = strValue.split(","); + for (index = 0; index < strValueArray.length; index ++) { + try{ + value = Integer.decode(strValueArray[index].trim()); + } catch (NumberFormatException nfeEx) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+ + "it is byte array in fact. For every byte in array should be a valid"+ + "byte digital, but element %s is not a valid byte digital!", + cName, + moduleName, + strValueArray[index]); + return exceptionString; + } + if (value > 0xFF) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+ + "it is byte array in fact. But the element of %s exceed the byte range", + cName, + moduleName, + strValueArray[index]); + return exceptionString; + } + } + + if (strValueArray.length > maxDatumSize) { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+ + "array, but the number of bytes is %d which exceed to : %d!", + cName, + moduleName, + strValueArray.length, + maxDatumSize); + return exceptionString; + } + } else { + exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+ + "1) UNICODE string: like L\"xxxx\";\r\n"+ + "2) ANSIC string: like \"xxx\";\r\n"+ + "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+ + "But the datum in seems does not following above format!", + cName, + moduleName); + return exceptionString; + } + break; + default: + exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+ + "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN", + cName, + moduleName); + return exceptionString; + } + return null; + } + /** Get dynamic information for a dynamic PCD from seciton in FPD file. @@ -1734,6 +2085,16 @@ public class CollectPCDAction { dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList(); for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) { + // + // Check is exist? In future, because all schema verification will tools + // will check that, following checking code could be removed. + // + if (dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid() == null) { + exceptionString = String.format("[FPD file error] There is no for PCD %s in ! This is required!", + dynamicPcdBuildDataArray.get(index).getCName()); + throw new EntityException(exceptionString); + } + dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(), translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid())); if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) { @@ -1744,81 +2105,6 @@ public class CollectPCDAction { return null; } - /** - Verify the maxDatumSize for a PCD data is matched to Datum type. - - @param token The token instance - @param moduleName The module name who use this PCD data. - @param maxDatumSize The value of max datum size in FPD file - @param datumType The datum type - - @return String if is unmatched, set the exception information - as return value, otherwice is null. - **/ - private String verifyDatumSize(String cName, - String moduleName, - int maxDatumSize, - Token.DATUM_TYPE datumType) { - String exceptionString = null; - - if (maxDatumSize == 0) { - exceptionString = String.format("[FPD file error] You maybe miss for PCD %s in module %s", - cName, - moduleName); - return exceptionString; - } - - switch (datumType) { - case UINT8: - if (maxDatumSize != 1) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+ - "is UINT8, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - } - break; - case UINT16: - if (maxDatumSize != 2) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+ - "is UINT16, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - } - break; - case UINT32: - if (maxDatumSize != 4) { - exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+ - "is UINT32, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - } - break; - case UINT64: - if (maxDatumSize != 8) { - exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+ - "is UINT64, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - } - break; - case BOOLEAN: - if (maxDatumSize != 1) { - exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+ - "is BOOLEAN, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - } - break; - } - - return exceptionString; - } - /** Update dynamic information for PCD entry. @@ -1844,6 +2130,10 @@ public class CollectPCDAction { SkuInstance skuInstance = null; String temp; boolean hasSkuId0 = false; + Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN; + int tokenNumber = 0; + String hiiDefaultValue = null; + String[] variableGuidString = null; List skuInfoList = null; DynamicPcdBuildDefinitions.PcdBuildData dynamicInfo = null; @@ -1860,7 +2150,11 @@ public class CollectPCDAction { token.datumSize = dynamicInfo.getMaxDatumSize(); - exceptionString = verifyDatumSize(token.cName, moduleName, token.datumSize, token.datumType); + exceptionString = verifyDatum(token.cName, + moduleName, + null, + token.datumType, + token.datumSize); if (exceptionString != null) { throw new EntityException(exceptionString); } @@ -1875,6 +2169,21 @@ public class CollectPCDAction { dynamicInfo.getMaxDatumSize()); throw new EntityException(exceptionString); } + tokenNumber = Integer.decode(dynamicInfo.getToken().toString()); + if (tokenNumber != token.tokenNumber) { + exceptionString = String.format("[FPD file error] For dynamic PCD %s, the token number in module %s is 0x%x, but"+ + "in , the token number is 0x%x, they are not match!", + token.cName, + moduleName, + token.tokenNumber, + tokenNumber); + throw new EntityException(exceptionString); + } + + pcdType = Token.getpcdTypeFromString(dynamicInfo.getItemType().toString()); + if (pcdType == Token.PCD_TYPE.DYNAMIC_EX) { + token.dynamicExTokenNumber = tokenNumber; + } skuInfoList = dynamicInfo.getSkuInfoList(); @@ -1895,7 +2204,15 @@ public class CollectPCDAction { // Judge whether is DefaultGroup at first, because most case is DefautlGroup. // if (skuInfoList.get(index).getValue() != null) { - skuInstance.value.setValue(skuInfoList.get(index).getValue()); + skuInstance.value.setValue(skuInfoList.get(index).getValue().toString()); + if ((exceptionString = verifyDatum(token.cName, + null, + skuInfoList.get(index).getValue().toString(), + token.datumType, + token.datumSize)) != null) { + throw new EntityException(exceptionString); + } + token.skuData.add(skuInstance); // @@ -1904,8 +2221,8 @@ public class CollectPCDAction { // if (datum != null) { if ((skuInstance.id == 0) && - !datum.equalsIgnoreCase(skuInfoList.get(index).getValue())) { - exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module is " + datum.toString() + " but the "+ + !datum.toString().equalsIgnoreCase(skuInfoList.get(index).getValue().toString())) { + exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module " + moduleName + " is " + datum.toString() + " but the "+ "value of sku 0 data in is " + skuInstance.value.value + ". They are must be same!"+ " or you could not define value for a dynamic PCD in every !"; throw new EntityException(exceptionString); @@ -1924,7 +2241,9 @@ public class CollectPCDAction { "file, who use HII, but there is no defined for Sku %d data!", token.cName, index); - + if (exceptionString != null) { + throw new EntityException(exceptionString); + } } if (skuInfoList.get(index).getVariableOffset() == null) { @@ -1932,6 +2251,9 @@ public class CollectPCDAction { "file, who use HII, but there is no defined for Sku %d data!", token.cName, index); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } } if (skuInfoList.get(index).getHiiDefaultValue() == null) { @@ -1939,11 +2261,25 @@ public class CollectPCDAction { "file, who use HII, but there is no defined for Sku %d data!", token.cName, index); + if (exceptionString != null) { + throw new EntityException(exceptionString); + } + } + + if (skuInfoList.get(index).getHiiDefaultValue() != null) { + hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString(); + } else { + hiiDefaultValue = null; } - if (exceptionString != null) { + if ((exceptionString = verifyDatum(token.cName, + null, + hiiDefaultValue, + token.datumType, + token.datumSize)) != null) { throw new EntityException(exceptionString); } + offset = Integer.decode(skuInfoList.get(index).getVariableOffset()); if (offset > 0xFFFF) { throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+ @@ -1952,10 +2288,20 @@ public class CollectPCDAction { index)); } + // + // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file. + // + variableGuidString = GlobalData.getGuidInfoGuid(skuInfoList.get(index).getVariableGuid().toString()); + if (variableGuidString == null) { + throw new EntityException(String.format("[GUID Error] For dynamic PCD %s, the variable guid %s can be found in all SPD file!", + token.cName, + skuInfoList.get(index).getVariableGuid().toString())); + } + skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(), - translateSchemaStringToUUID(skuInfoList.get(index).getVariableGuid().toString()), + translateSchemaStringToUUID(variableGuidString[1]), skuInfoList.get(index).getVariableOffset(), - skuInfoList.get(index).getHiiDefaultValue()); + skuInfoList.get(index).getHiiDefaultValue().toString()); token.skuData.add(skuInstance); continue; } @@ -2019,6 +2365,9 @@ public class CollectPCDAction { return new UUID(0, 0); } + uuidString = uuidString.replaceAll("\\{", ""); + uuidString = uuidString.replaceAll("\\}", ""); + // // If the UUID schema string is GuidArrayType type then need translate // to GuidNamingConvention type at first.