import java.io.File;\r
import java.io.FileReader;\r
import java.io.IOException;\r
+import java.math.BigInteger;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Comparator;\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.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo;\r
import org.tianocore.FrameworkModulesDocument;\r
import org.tianocore.FrameworkPlatformDescriptionDocument;\r
import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription;\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
+ if ((exceptionString = verifyDatum(pcdBuildData.getCName(), \r
+ moduleName,\r
+ datum,\r
+ datumType,\r
+ maxDatumSize)) != null) {\r
throw new EntityException(exceptionString);\r
}\r
}\r
}\r
}\r
\r
+ /**\r
+ Verify the datum value according its datum size and datum type, this\r
+ function maybe moved to FPD verification tools in future.\r
+ \r
+ @param cName\r
+ @param moduleName\r
+ @param datum\r
+ @param datumType\r
+ @param maxDatumSize\r
+ \r
+ @return String\r
+ */\r
+ /***/\r
+ public String verifyDatum(String cName,\r
+ String moduleName,\r
+ String datum, \r
+ Token.DATUM_TYPE datumType, \r
+ int maxDatumSize) {\r
+ String exceptionString = null;\r
+ int value;\r
+ BigInteger value64;\r
+ String subStr;\r
+\r
+ if (moduleName == null) {\r
+ moduleName = "section <DynamicPcdBuildDefinitions>";\r
+ } else {\r
+ moduleName = "module " + moduleName;\r
+ }\r
+\r
+ if (maxDatumSize == 0) {\r
+ exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+\r
+ switch (datumType) {\r
+ case UINT8:\r
+ if (maxDatumSize != 1) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is UINT8, but datum size is %d, they are not matched!",\r
+ cName,\r
+ moduleName,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (datum != null) {\r
+ try {\r
+ value = Integer.decode(datum);\r
+ } catch (NumberFormatException nfeExp) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+\r
+ "digital format of UINT8",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+ if (value > 0xFF) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+\r
+ " the max size of UINT8 - 0xFF",\r
+ cName, \r
+ moduleName,\r
+ datum);\r
+ return exceptionString;\r
+ }\r
+ }\r
+ break;\r
+ case UINT16:\r
+ if (maxDatumSize != 2) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is UINT16, but datum size is %d, they are not matched!",\r
+ cName,\r
+ moduleName,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+ if (datum != null) {\r
+ try {\r
+ value = Integer.decode(datum);\r
+ } catch (NumberFormatException nfeExp) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+\r
+ "not valid digital of UINT16",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+ if (value > 0xFFFF) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
+ "which exceed the range of UINT16 - 0xFFFF",\r
+ cName, \r
+ moduleName,\r
+ datum);\r
+ return exceptionString;\r
+ }\r
+ }\r
+ break;\r
+ case UINT32:\r
+ if (maxDatumSize != 4) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is UINT32, but datum size is %d, they are not matched!",\r
+ cName,\r
+ moduleName,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (datum != null) {\r
+ try {\r
+ if (datum.length() > 2) {\r
+ if ((datum.charAt(0) == '0') && \r
+ ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
+ subStr = datum.substring(2, datum.length());\r
+ value64 = new BigInteger(subStr, 16);\r
+ } else {\r
+ value64 = new BigInteger(datum);\r
+ }\r
+ } else {\r
+ value64 = new BigInteger(datum);\r
+ }\r
+ } catch (NumberFormatException nfeExp) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+\r
+ "valid digital of UINT32",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (value64.bitLength() > 32) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+\r
+ "exceed the range of UINT32 - 0xFFFFFFFF",\r
+ cName, \r
+ moduleName,\r
+ datum);\r
+ return exceptionString;\r
+ }\r
+ }\r
+ break;\r
+ case UINT64:\r
+ if (maxDatumSize != 8) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is UINT64, but datum size is %d, they are not matched!",\r
+ cName,\r
+ moduleName,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (datum != null) {\r
+ try {\r
+ if (datum.length() > 2) {\r
+ if ((datum.charAt(0) == '0') && \r
+ ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
+ subStr = datum.substring(2, datum.length());\r
+ value64 = new BigInteger(subStr, 16);\r
+ } else {\r
+ value64 = new BigInteger(datum);\r
+ }\r
+ } else {\r
+ value64 = new BigInteger(datum);\r
+ }\r
+ } catch (NumberFormatException nfeExp) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+\r
+ " digital of UINT64",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (value64.bitLength() > 64) {\r
+ exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
+ "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",\r
+ cName, \r
+ moduleName,\r
+ datum);\r
+ return exceptionString;\r
+ }\r
+ }\r
+ break;\r
+ case BOOLEAN:\r
+ if (maxDatumSize != 1) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is BOOLEAN, but datum size is %d, they are not matched!",\r
+ cName,\r
+ moduleName,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+\r
+ if (datum != null) {\r
+ if (!(datum.equalsIgnoreCase("TRUE") ||\r
+ datum.equalsIgnoreCase("FALSE"))) {\r
+ exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+ "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+\r
+ }\r
+ break;\r
+ case POINTER:\r
+ if (datum == null) {\r
+ break;\r
+ }\r
+\r
+ char ch = datum.charAt(0);\r
+ int start, end;\r
+ String strValue;\r
+ //\r
+ // For void* type PCD, only three datum is support:\r
+ // 1) Unicode: string with start char is "L"\r
+ // 2) Ansci: String start char is ""\r
+ // 3) byte array: String start char "{"\r
+ // \r
+ if (ch == 'L') {\r
+ start = datum.indexOf('\"');\r
+ end = datum.lastIndexOf('\"');\r
+ if ((start > end) || \r
+ (end > datum.length())||\r
+ ((start == end) && (datum.length() > 0))) {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+\r
+ "a UNICODE string because start with L\", but format maybe"+\r
+ "is not right, correct UNICODE string is L\"...\"!",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+\r
+ strValue = datum.substring(start + 1, end);\r
+ if ((strValue.length() * 2) > maxDatumSize) {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+\r
+ "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",\r
+ cName,\r
+ moduleName,\r
+ strValue.length() * 2, \r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+ } else if (ch == '\"'){\r
+ start = datum.indexOf('\"');\r
+ end = datum.lastIndexOf('\"');\r
+ if ((start > end) || \r
+ (end > datum.length())||\r
+ ((start == end) && (datum.length() > 0))) {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+\r
+ "a ANSCII string because start with \", but format maybe"+\r
+ "is not right, correct ANSIC string is \"...\"!",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+ strValue = datum.substring(start + 1, end);\r
+ if ((strValue.length()) > maxDatumSize) {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+\r
+ "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",\r
+ cName,\r
+ moduleName,\r
+ strValue.length(),\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+ } else if (ch =='{') {\r
+ String[] strValueArray;\r
+\r
+ start = datum.indexOf('{');\r
+ end = datum.lastIndexOf('}');\r
+ strValue = datum.substring(start, end);\r
+ strValueArray = strValue.split(",");\r
+ if (strValueArray.length > maxDatumSize) {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is byte"+\r
+ "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",\r
+ cName,\r
+ moduleName,\r
+ strValueArray.length,\r
+ maxDatumSize);\r
+ return exceptionString;\r
+ }\r
+ } else {\r
+ exceptionString = String.format("The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
+ "1) UNICODE string: like L\"xxxx\";\r\n"+\r
+ "2) ANSIC string: like \"xxx\";\r\n"+\r
+ "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
+ "But the datum in seems does not following above format!",\r
+ cName, \r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+ break;\r
+ default:\r
+ exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+\r
+ "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
+ }\r
+ return null;\r
+ }\r
+\r
/**\r
Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
\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
-\r
- if (maxDatumSize == 0) {\r
- exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in module %s",\r
- cName,\r
- moduleName);\r
- return exceptionString;\r
- }\r
-\r
- switch (datumType) {\r
- case UINT8:\r
- if (maxDatumSize != 1) {\r
- exceptionString = String.format("[FPD file error] 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("[FPD file error] 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("[FPD file error] 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("[FPD file error] 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("[FPD file error] 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
- return exceptionString;\r
- }\r
-\r
/**\r
Update dynamic information for PCD entry.\r
\r
\r
token.datumSize = dynamicInfo.getMaxDatumSize();\r
\r
- exceptionString = verifyDatumSize(token.cName, moduleName, token.datumSize, token.datumType);\r
+ exceptionString = verifyDatum(token.cName, \r
+ moduleName,\r
+ null, \r
+ token.datumType, \r
+ token.datumSize);\r
if (exceptionString != null) {\r
throw new EntityException(exceptionString);\r
}\r
// \r
if (skuInfoList.get(index).getValue() != null) {\r
skuInstance.value.setValue(skuInfoList.get(index).getValue());\r
+ if ((exceptionString = verifyDatum(token.cName, \r
+ null, \r
+ skuInfoList.get(index).getValue(), \r
+ token.datumType, \r
+ token.datumSize)) != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
token.skuData.add(skuInstance);\r
\r
//\r
if (datum != null) {\r
if ((skuInstance.id == 0) &&\r
!datum.equalsIgnoreCase(skuInfoList.get(index).getValue())) {\r
- exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module is " + datum.toString() + " but the "+\r
+ exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module " + moduleName + " is " + datum.toString() + " but the "+\r
"value of sku 0 data in <DynamicPcdBuildDefinition> is " + skuInstance.value.value + ". They are must be same!"+\r
" or you could not define value for a dynamic PCD in every <ModuleSA>!"; \r
throw new EntityException(exceptionString);\r
if (exceptionString != null) {\r
throw new EntityException(exceptionString);\r
}\r
+\r
+ if ((exceptionString = verifyDatum(token.cName, \r
+ null, \r
+ skuInfoList.get(index).getHiiDefaultValue(), \r
+ token.datumType, \r
+ token.datumSize)) != null) {\r
+ throw new EntityException(exceptionString);\r
+ }\r
+\r
offset = Integer.decode(skuInfoList.get(index).getVariableOffset());\r
if (offset > 0xFFFF) {\r
throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+\r
**/\r
public static void main(String argv[]) throws EntityException {\r
CollectPCDAction ca = new CollectPCDAction();\r
- ca.setWorkspacePath("m:/tianocore/edk2");\r
- ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");\r
+ ca.setWorkspacePath("m:/tianocore_latest/edk2");\r
+ ca.setFPDFilePath("m:/tianocore_latest/edk2/EdkNt32Pkg/Nt32.fpd");\r
ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
- "m:/tianocore/edk2");\r
+ "m:/tianocore_latest/edk2");\r
ca.execute();\r
}\r
}\r