summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/PcdTools
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Java/Source/PcdTools')
-rw-r--r--Tools/Java/Source/PcdTools/PcdTools.msa45
-rw-r--r--Tools/Java/Source/PcdTools/build.xml52
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java61
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/action/PlatformPcdPreprocessAction.java992
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java353
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java162
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java313
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/ModulePcdInfoFromFpd.java48
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java50
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/Token.java960
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java105
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java512
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java33
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java31
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/PlatformPcdPreprocessException.java36
-rw-r--r--Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/UIException.java31
16 files changed, 3784 insertions, 0 deletions
diff --git a/Tools/Java/Source/PcdTools/PcdTools.msa b/Tools/Java/Source/PcdTools/PcdTools.msa
new file mode 100644
index 0000000000..3b47a92cbd
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/PcdTools.msa
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" >
+ <MsaHeader>
+ <ModuleName>PcdTools</ModuleName>
+ <ModuleType>TOOL</ModuleType>
+ <GuidValue>95506773-88f3-475a-91a1-14ce0c847353</GuidValue>
+ <Version>2.0</Version>
+ <Abstract>This is the EFI/Tiano PCD Tool Resources Module</Abstract>
+ <Description>
+ This Module provdes the entity, action and exception package for PCD
+ tools, This package will be shared for building tools or wizard tools.
+ </Description>
+ <Copyright>Copyright 2005-2006, Intel Corporation</Copyright>
+ <License>
+All rights reserved.
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the
+BSD License which accompanies this distribution. The full text of the
+license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ </License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>NULL</OutputFileBasename>
+ </ModuleDefinitions>
+ <SourceFiles>
+ <Filename>build.xml</Filename>
+ <Filename>org/tianocore/pcd/action/ActionMessage.java</Filename>
+ <Filename>org/tianocore/pcd/action/BuildAction.java</Filename>
+ <Filename>org/tianocore/pcd/entity/DynamicTokenValue.java</Filename>
+ <Filename>org/tianocore/pcd/entity/MemoryDatabaseManager.java</Filename>
+ <Filename>org/tianocore/pcd/entity/SkuInstance.java</Filename>
+ <Filename>org/tianocore/pcd/entity/Token.java</Filename>
+ <Filename>org/tianocore/pcd/entity/UsageInstance.java</Filename>
+ <Filename>org/tianocore/pcd/exception/BuildActionException.java</Filename>
+ <Filename>org/tianocore/pcd/exception/EntityException.java</Filename>
+ <Filename>org/tianocore/pcd/exception/UIException.java</Filename>
+ </SourceFiles>
+</ModuleSurfaceArea>
diff --git a/Tools/Java/Source/PcdTools/build.xml b/Tools/Java/Source/PcdTools/build.xml
new file mode 100644
index 0000000000..c47032e9f5
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/build.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+-->
+<project name="PcdTools" default="PcdTools" basedir=".">
+
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>
+ <property environment="env"/>
+ <property name="WORKSPACE" value="${env.WORKSPACE}"/>
+ <path id="classpath">
+ <fileset dir="${WORKSPACE}/Tools/Jars" includes="SurfaceArea.jar"/>
+ <fileset dir="${WORKSPACE}/Tools/Jars" includes="Common.jar"/>
+ <fileset dir="${env.XMLBEANS_HOME}/lib" includes="*.jar"/>
+ </path>
+ <property name="buildDir" value="build"/>
+ <property name="installLocation" value="${WORKSPACE}/Tools/Jars"/>
+ <target name="PcdTools" depends="install"/>
+ <target name="source">
+ <mkdir dir="${buildDir}"/>
+ <javac srcdir="." destdir="${buildDir}">
+ <classpath refid="classpath"/>
+ <compilerarg value="-Xlint"/>
+ </javac>
+ </target>
+ <target name="clean">
+ <delete dir="${buildDir}"/>
+ </target>
+ <target name="cleanall">
+ <delete dir="${buildDir}"/>
+ <delete file="${installLocation}/PcdTools.jar"/>
+ <if>
+ <available file="${installLocation}/PcdTools.jar"/>
+ <then>
+ <echo message="You must manually remove the file: ${installLocation}/PcdTools.jar"/>
+ <echo message="Java has already loaded the file, and cannot remove it within ANT!"/>
+ </then>
+ </if>
+ </target>
+ <target name="install" depends="source">
+ <jar destfile="${installLocation}/PcdTools.jar"
+ basedir="${buildDir}"
+ includes="**"
+ />
+ </target>
+</project>
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java
new file mode 100644
index 0000000000..9d30a76bdc
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java
@@ -0,0 +1,61 @@
+/** @file
+ BuildAction class.
+
+ BuildAction is the parent class for all action related to ant Task. This class will
+ define some common utility functionality, such as logMsg, warningMsg..etc.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.action;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.tianocore.pcd.exception.BuildActionException;
+
+/** BuildAction is the parent class for all action related to ant Task. This class will
+ define some common utility functionality, such as logMsg, warningMsg..etc.
+**/
+public abstract class BuildAction extends Task {
+ ///
+ /// Original message level before this action. This value will
+ /// be restored when quit this action.
+ ///
+ private int originalMessageLevel;
+
+ /**
+ checkParameter function check all parameter valid.
+
+ This function will be overrided by child class.
+ **/
+ public abstract void checkParameter() throws BuildActionException;
+
+ /**
+ performAction is to execute the detail action.
+
+ This function will be overrided by child class.
+ **/
+ public abstract void performAction() throws BuildActionException;
+
+ /**
+ execute function is the main flow for all build action class.
+
+ This workflow will be:
+ 1) Check paramet of this action.
+ 2) Perform the child class action function.
+ 3) Restore the message level.
+
+ @throws BuildActionException
+ **/
+ public void execute() throws BuildActionException {
+ checkParameter();
+ performAction();
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/PlatformPcdPreprocessAction.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/PlatformPcdPreprocessAction.java
new file mode 100644
index 0000000000..ee91f2a8e8
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/action/PlatformPcdPreprocessAction.java
@@ -0,0 +1,992 @@
+/** @file
+ PlatformPcdPreprocessAction class.
+
+ The abstract parent class PlatformPcdPreprocessAction, This class is to collect platform's
+ pcd build information from fpd file.
+ This class will be extended by building tools and wizard tools.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.action;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;
+import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;
+import org.tianocore.pcd.entity.*;
+import org.tianocore.pcd.entity.Token;
+import org.tianocore.pcd.entity.MemoryDatabaseManager;
+import org.tianocore.pcd.exception.PlatformPcdPreprocessException;
+
+/**
+ The abstract parent class PlatformPcdPreprocessAction, This class is to collect platform's
+ pcd build information from fpd file.
+ This class will be extended by building tools and wizard tools.
+
+**/
+public abstract class PlatformPcdPreprocessAction {
+ ///
+ /// PCD memory database
+ ///
+ private MemoryDatabaseManager pcdDbManager;
+
+ ///
+ /// Errors string when perform preprocess
+ ///
+ private String errorString;
+
+ ///
+ /// the count of errors when perform preprocess
+ ///
+ private int errorCount;
+
+ /**
+ Default contructor function
+ **/
+ public PlatformPcdPreprocessAction() {
+ pcdDbManager = null;
+ errorString = null;
+ errorCount = 0;
+ }
+
+ /**
+ Set parameter pcdDbManager
+
+ @param pcdDbManager
+ **/
+ public void setPcdDbManager(MemoryDatabaseManager pcdDbManager) {
+ this.pcdDbManager = pcdDbManager;
+ }
+
+ /**
+ Get parameter pcdDbManager
+
+ @return MemoryDatabaseManager
+ **/
+ public MemoryDatabaseManager getPcdDbManager() {
+ return pcdDbManager;
+ }
+
+ /**
+ Abstract function: retrieve module information from FPD file.
+
+ In building environement, this function will be implementated by FpdParserTask.
+
+ @return List<ModulePcdInfoFromFpd> the component array.
+ @throws PlatformPcdPreprocessException get all modules in <ModuleSA> in FPD file.
+
+ **/
+ public abstract List<ModulePcdInfoFromFpd> getComponentsFromFpd()
+ throws PlatformPcdPreprocessException;
+
+ /**
+ Abstract function to get GUID string from SPD file.
+
+ In building evnironment, this function will be implementated by GlobaData.
+
+ @param guidCName the CName of GUID
+
+ @return String Guid information from SPD file.
+ @throws PlatformPcdPreprocessException
+ Fail to get Guid information from SPD file.
+ **/
+ public abstract String getGuidInfoFromSpd(String guidCName) throws PlatformPcdPreprocessException;
+
+ /**
+ Abstract function: Verification the PCD data.
+
+ In different environment, such as building environment and wizard environment,
+ it has different implementation according to optimization.
+
+ @param cName The token name
+ @param moduleName The module who use this PCD token
+ @param datum The PCD's datum
+ @param datumType The PCD's datum type
+ @param maxDatumSize The max size for PCD's Datum.
+
+ @return String exception strings.
+
+ **/
+ public abstract String verifyDatum(String cName, String moduleName, String datum,
+ Token.DATUM_TYPE datumType, int maxDatumSize);
+
+ /**
+ Abstract function: Get dynamic information for a token
+
+ @param token
+ @param moduleName
+
+ @return DynamicPcdBuildDefinitions.PcdBuildData
+ **/
+ public abstract DynamicPcdBuildDefinitions.PcdBuildData
+ getDynamicInfoFromFpd(Token token,
+ String moduleName)
+ throws PlatformPcdPreprocessException;
+
+ /**
+ Abstract function: Get all dynamic PCD information from FPD file.
+
+ @return List<DynamicPcdBuildDefinitions.PcdBuildData> All DYNAMIC PCD list in <DynamicPcdBuildDefinitions> in FPD file.
+ @throws PlatformPcdPreprocessBuildException Failure to get dynamic information list.
+
+ **/
+ public abstract List<DynamicPcdBuildDefinitions.PcdBuildData>
+ getAllDynamicPcdInfoFromFpd()
+ throws PlatformPcdPreprocessException;
+
+ /**
+ Return the error string after preprocess
+
+ @return String error string
+ **/
+ public String getErrorString() {
+ return errorString;
+ }
+
+ public void putError(String error) {
+ if (errorString == null) {
+ errorString = "### ERROR[" + errorCount + "] ###\r\n" + error + "\r\n";
+ } else {
+ errorString += "### ERROR[" + errorCount + "] ###\r\n" + error + "\r\n";
+ }
+
+ errorCount++;
+ }
+
+ /**
+ Collect all PCD information from FPD file into PCD memory database.
+
+ **/
+ public void initPcdMemoryDbWithPlatformInfo()
+ throws PlatformPcdPreprocessException {
+ int index;
+ int pcdIndex;
+ List<PcdBuildDefinition.PcdData> pcdBuildDataArray = new ArrayList<PcdBuildDefinition.PcdData>();
+ PcdBuildDefinition.PcdData pcdBuildData;
+ Token token = null;
+ List<ModulePcdInfoFromFpd> modules;
+ String primaryKey;
+ String exceptionString;
+ UsageInstance usageInstance;
+ Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;
+ Token.DATUM_TYPE datumType = Token.DATUM_TYPE.UNKNOWN;
+ long tokenNumber;
+ String moduleName;
+ String datum;
+ int maxDatumSize;
+ String tokenSpaceStrRet;
+ ModulePcdInfoFromFpd curModule;
+
+ //
+ // ----------------------------------------------
+ // 1), Get all <ModuleSA> from FPD file.
+ // ----------------------------------------------
+ //
+ modules = getComponentsFromFpd();
+
+ if (modules == null) {
+ throw new PlatformPcdPreprocessException(
+ "No modules found in the FPD file.\nPlease check whether there are elements in <FrameworkModules> in the FPD file!");
+ }
+
+ //
+ // -------------------------------------------------------------------
+ // 2), Loop all modules to process <PcdBuildDeclarations> for each module.
+ // -------------------------------------------------------------------
+ //
+ for (index = 0; index < modules.size(); index++) {
+ curModule = modules.get(index);
+
+ //
+ // It is legal for a module does not contains ANY pcd build definitions.
+ //
+ if (curModule.pcdBuildDefinition == null) {
+ continue;
+ }
+
+ pcdBuildDataArray = curModule.pcdBuildDefinition.getPcdDataList();
+ moduleName = curModule.usageId.moduleName;
+
+ //
+ // ----------------------------------------------------------------------
+ // 2.1), Loop all Pcd entry for a module and add it into memory database.
+ // ----------------------------------------------------------------------
+ //
+ for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex++) {
+ pcdBuildData = pcdBuildDataArray.get(pcdIndex);
+
+ tokenSpaceStrRet = getGuidInfoFromSpd(pcdBuildData.getTokenSpaceGuidCName());
+
+ if (tokenSpaceStrRet == null) {
+ putError("Failed to get Token Space Guid for token " + pcdBuildData.getCName() +
+ " from any SPD file. You must have an <GuidDeclaration> for this Token Space Guid!");
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), tokenSpaceStrRet);
+ pcdType = Token.getPcdTypeFromString(pcdBuildData.getItemType().toString());
+ datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());
+ tokenNumber = Long.decode(pcdBuildData.getToken().toString());
+ 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("In FPD file, for PCD %s in module %s, the PCD type is FEATURE_FLAG but "+
+ "datum type for this PCD entry is not BOOLEAN!",
+ pcdBuildData.getCName(),
+ moduleName);
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ //
+ // -------------------------------------------------------------------------------------------
+ // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule
+ // -------------------------------------------------------------------------------------------
+ //
+ if (!Token.isDynamic(pcdType)) {
+ //
+ // Value is required.
+ //
+ if (datum == null) {
+ exceptionString = String.format("In the FPD file, there is no value for PCD entry %s in module %s!",
+ pcdBuildData.getCName(),
+ moduleName);
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ //
+ // Check whether the datum size is matched datum type.
+ //
+ if ((exceptionString = verifyDatum(pcdBuildData.getCName(),
+ moduleName,
+ datum,
+ datumType,
+ maxDatumSize)) != null) {
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+ }
+
+ //
+ // ---------------------------------------------------------------------------------
+ // 2.1.2), Create token or update token information for current anaylized PCD data.
+ // ---------------------------------------------------------------------------------
+ //
+ if (pcdDbManager.isTokenInDatabase(primaryKey)) {
+ //
+ // If the token is already exist in database, do some necessary checking
+ // and add a usage instance into this token in database
+ //
+ token = pcdDbManager.getTokenByKey(primaryKey);
+
+ //
+ // checking for DatumType, DatumType should be unique for one PCD used in different
+ // modules.
+ //
+ if (token.datumType != datumType) {
+ exceptionString = String.format("In the FPD file, the datum type of the PCD entry %s is %s, which is different from %s which was previously defined!",
+ pcdBuildData.getCName(),
+ pcdBuildData.getDatumType().toString(),
+ Token.getStringOfdatumType(token.datumType));
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ //
+ // Check token number is valid
+ //
+ if (tokenNumber != token.tokenNumber) {
+ exceptionString = String.format("In the FPD file, the token number of PCD entry %s in module %s is different from the same PCD entry in other modules!",
+ pcdBuildData.getCName(),
+ moduleName);
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ //
+ // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.
+ //
+ if (token.isDynamicPCD != Token.isDynamic(pcdType)) {
+ exceptionString = String.format("In the FPD file, for PCD entry %s in module %s, you defined dynamic or non-dynamic PCD type which"+
+ " is different from other module's definition.",
+ token.cName,
+ moduleName);
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ if (token.isDynamicPCD) {
+ if ((maxDatumSize != 0) &&
+ (maxDatumSize != token.datumSize)){
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in module %s, the max datum size is %d which "+
+ "is different than <MaxDatumSize> %d defined in <DynamicPcdBuildDefinitions>!",
+ token.cName,
+ moduleName,
+ maxDatumSize,
+ token.datumSize);
+ putError(exceptionString);
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+ }
+
+ } else {
+ //
+ // If the token is not in database, create a new token instance and add
+ // a usage instance into this token in database.
+ //
+ tokenSpaceStrRet = getGuidInfoFromSpd(pcdBuildData.getTokenSpaceGuidCName());
+
+ if (tokenSpaceStrRet == null) {
+ putError("Failed to get the Token Space Guid for token" + token.cName +
+ " from any SPD file. You must have a <GuidDeclaration> for this Token Space Guid!");
+ //
+ // Do not break preprocess, continues to analysis.
+ // All errors will be summary to be shown.
+ //
+ continue;
+ }
+
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet);
+
+ token.datumType = datumType;
+ token.tokenNumber = tokenNumber;
+ token.isDynamicPCD = Token.isDynamic(pcdType);
+ token.datumSize = maxDatumSize;
+
+ if (token.isDynamicPCD) {
+ //
+ // For Dynamic and Dynamic Ex type, need find the dynamic information
+ // in <DynamicPcdBuildDefinition> section in FPD file.
+ //
+ if (null == updateDynamicInformation(moduleName,
+ token,
+ datum,
+ maxDatumSize)) {
+ continue;
+ }
+ }
+
+ pcdDbManager.addTokenToDatabase(primaryKey, token);
+ }
+
+ //
+ // -----------------------------------------------------------------------------------
+ // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.
+ // -----------------------------------------------------------------------------------
+ //
+ token.updateSupportPcdType(pcdType);
+
+ //
+ // ------------------------------------------------
+ // 2.1.4), Create an usage instance for this token.
+ // ------------------------------------------------
+ //
+ usageInstance = new UsageInstance(token,
+ curModule.usageId,
+ pcdType,
+ datum,
+ maxDatumSize);
+ if (!token.addUsageInstance(usageInstance)) {
+ putError(String.format("PCD %s for module %s(%s) already exists in the database.\nPlease check all PCD build entries "+
+ "in the %s module's <ModuleSA> section to make sure there are no duplicated definitions in the FPD file!",
+ token.cName,
+ curModule.usageId.moduleGuid,
+ moduleName,
+ moduleName));
+ continue;
+ }
+ }
+ }
+
+ //
+ // ------------------------------------------------
+ // 3), Add unreference dynamic_Ex pcd token into Pcd database.
+ // ------------------------------------------------
+ //
+ List<Token> tokenArray = getUnreferencedDynamicPcd();
+ if (tokenArray != null) {
+ for (index = 0; index < tokenArray.size(); index++) {
+ pcdDbManager.addTokenToDatabase(tokenArray.get(index).getPrimaryKeyString(),
+ tokenArray.get(index));
+ }
+ }
+ }
+
+ /**
+ Update dynamic information for PCD entry.
+
+ Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in
+ FPD file.
+
+ @param moduleName The name of the module who use this PCD
+ @param token The token instance
+ @param datum The <datum> in module's PCD information
+ @param maxDatumSize The <maxDatumSize> in module's PCD information
+
+ @return Token
+ */
+ private Token updateDynamicInformation(String moduleName,
+ Token token,
+ String datum,
+ int maxDatumSize)
+ throws PlatformPcdPreprocessException {
+ int index = 0;
+ int offset;
+ String exceptionString = null;
+ SkuInstance skuInstance = null;
+ String temp;
+ boolean hasSkuId0 = false;
+ long tokenNumber = 0;
+ String hiiDefaultValue = null;
+ String variableGuidString = null;
+
+ List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> skuInfoList = null;
+ DynamicPcdBuildDefinitions.PcdBuildData dynamicInfo = null;
+
+ dynamicInfo = getDynamicInfoFromFpd(token, moduleName);
+ if (dynamicInfo == null) {
+ exceptionString = String.format("In the FPD file, the Dynamic PCD %s is used by module %s.\n" +
+ "However, there is no dynamic information in the <DynamicPcdBuildDefinitions> " +
+ "section of the FPD file. This section is required!",
+ token.cName,
+ moduleName);
+ putError(exceptionString);
+ return null;
+ }
+
+ token.datumSize = dynamicInfo.getMaxDatumSize();
+
+ exceptionString = verifyDatum(token.cName,
+ moduleName,
+ null,
+ token.datumType,
+ token.datumSize);
+ if (exceptionString != null) {
+ throw new PlatformPcdPreprocessException(exceptionString);
+ }
+
+ if ((maxDatumSize != 0) &&
+ (maxDatumSize != token.datumSize)) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the datum size in module %s is %d, but "+
+ "the datum size in <DynamicPcdBuildDefinitions> is %d, they do not match!",
+ token.cName,
+ moduleName,
+ maxDatumSize,
+ dynamicInfo.getMaxDatumSize());
+ putError(exceptionString);
+ return null;
+ }
+ tokenNumber = Long.decode(dynamicInfo.getToken().toString());
+ if (tokenNumber != token.tokenNumber) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the token number in module %s is 0x%x, but "+
+ "in the <DynamicPcdBuildDefinictions> section, the token number is 0x%x, they do not match!",
+ token.cName,
+ moduleName,
+ token.tokenNumber,
+ tokenNumber);
+ putError(exceptionString);
+ return null;
+ }
+
+ token.dynamicExTokenNumber = tokenNumber;
+
+ skuInfoList = dynamicInfo.getSkuInfoList();
+
+ //
+ // Loop all sku data
+ //
+ for (index = 0; index < skuInfoList.size(); index++) {
+ skuInstance = new SkuInstance();
+ //
+ // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.
+ //
+ temp = skuInfoList.get(index).getSkuId().toString();
+ skuInstance.id = Integer.decode(temp);
+ if (skuInstance.id == 0) {
+ hasSkuId0 = true;
+ }
+ //
+ // Judge whether is DefaultGroup at first, because most case is DefautlGroup.
+ //
+ if (skuInfoList.get(index).getValue() != null) {
+ skuInstance.value.setValue(skuInfoList.get(index).getValue().toString());
+ if ((exceptionString = verifyDatum(token.cName,
+ null,
+ skuInfoList.get(index).getValue().toString(),
+ token.datumType,
+ token.datumSize)) != null) {
+ putError(exceptionString);
+ return null;
+ }
+
+ token.skuData.add(skuInstance);
+
+ continue;
+ }
+
+ //
+ // Judge whether is HII group case.
+ //
+ if (skuInfoList.get(index).getVariableName() != null) {
+ exceptionString = null;
+ if (skuInfoList.get(index).getVariableGuid() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
+ "file, use of HII was defined, but there is no <VariableGuid> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ return null;
+ }
+
+ if (skuInfoList.get(index).getVariableOffset() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
+ "file, use of HII was defined, but there is no <VariableOffset> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ return null;
+ }
+
+ if (skuInfoList.get(index).getHiiDefaultValue() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
+ "file, use of HII was defined, but there is no <HiiDefaultValue> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ return null;
+ }
+
+ if (skuInfoList.get(index).getHiiDefaultValue() != null) {
+ hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString();
+ } else {
+ hiiDefaultValue = null;
+ }
+
+ if ((exceptionString = verifyDatum(token.cName,
+ null,
+ hiiDefaultValue,
+ token.datumType,
+ token.datumSize)) != null) {
+ throw new PlatformPcdPreprocessException(exceptionString);
+ }
+
+ offset = Integer.decode(skuInfoList.get(index).getVariableOffset());
+ if (offset > 0xFFFF) {
+ putError(String.format("In the FPD file, for dynamic PCD %s, the variable offset defined in SKU %d data "+
+ "exceeds 64K, which is not allowed!",
+ token.cName,
+ index));
+ return null;
+ }
+
+ //
+ // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.
+ //
+ variableGuidString = getGuidInfoFromSpd(skuInfoList.get(index).getVariableGuid().toString());
+ if (variableGuidString == null) {
+ putError(String.format("In the FPD file, for dynamic PCD %s, the variable guid: %s cannot be found in any SPD file!",
+ token.cName,
+ skuInfoList.get(index).getVariableGuid().toString()));
+ return null;
+ }
+ String variableStr = skuInfoList.get(index).getVariableName();
+ Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");
+ Matcher matcher = pattern.matcher(variableStr);
+ List<String> varNameList = new ArrayList<String>();
+ while (matcher.find()){
+ String str = variableStr.substring(matcher.start(),matcher.end());
+ varNameList.add(str);
+ }
+
+ skuInstance.value.setHiiData(varNameList,
+ translateSchemaStringToUUID(variableGuidString),
+ skuInfoList.get(index).getVariableOffset(),
+ skuInfoList.get(index).getHiiDefaultValue().toString());
+ token.skuData.add(skuInstance);
+ continue;
+ }
+
+ if (skuInfoList.get(index).getVpdOffset() != null) {
+ skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());
+ token.skuData.add(skuInstance);
+ continue;
+ }
+
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the dynamic info must "+
+ "be one of: 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",
+ token.cName);
+ putError(exceptionString);
+ return null;
+ }
+
+ if (!hasSkuId0) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in <DynamicPcdBuildDefinitions>, there is "+
+ "no SKU ID = 0 data, which is required for every dynamic PCD",
+ token.cName);
+ putError(exceptionString);
+ return null;
+ }
+
+ return token;
+ }
+
+ /**
+ Get all dynamic PCD defined in <DynamicPcdBuildDefinitions> which unreferenced by
+ any <ModuleSA> in FPD file.
+
+ @return List<Token> Return PCD token
+ **/
+ private List<Token> getUnreferencedDynamicPcd () throws PlatformPcdPreprocessException {
+ List<Token> tokenArray = new ArrayList<Token>();
+ Token token = null;
+ List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;
+ DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = null;
+ List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> skuInfoList = null;
+ Token.PCD_TYPE pcdType;
+ SkuInstance skuInstance = null;
+ String primaryKey = null;
+ boolean hasSkuId0 = false;
+ int index, offset, index2;
+ String temp;
+ String exceptionString;
+ String hiiDefaultValue;
+ String tokenSpaceStrRet;
+ String variableGuidString;
+
+ dynamicPcdBuildDataArray = getAllDynamicPcdInfoFromFpd();
+ if (dynamicPcdBuildDataArray == null) {
+ return null;
+ }
+
+ for (index2 = 0; index2 < dynamicPcdBuildDataArray.size(); index2++) {
+ pcdBuildData = dynamicPcdBuildDataArray.get(index2);
+ tokenSpaceStrRet = getGuidInfoFromSpd(pcdBuildData.getTokenSpaceGuidCName());
+
+ if (tokenSpaceStrRet == null) {
+ putError("Failed to get the Token Space Guid for token" + pcdBuildData.getCName());
+ continue;
+ }
+
+ primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),
+ tokenSpaceStrRet);
+
+ if (pcdDbManager.isTokenInDatabase(primaryKey)) {
+ continue;
+ }
+
+ pcdType = Token.getPcdTypeFromString(pcdBuildData.getItemType().toString());
+ if (pcdType != Token.PCD_TYPE.DYNAMIC_EX) {
+ putError(String.format("In the FPD file, it not allowed to define DYNAMIC PCD %s that is not used by any module",
+ pcdBuildData.getCName()));
+ continue;
+ }
+
+ //
+ // Create new token for unreference dynamic PCD token
+ //
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet);
+ token.datumSize = pcdBuildData.getMaxDatumSize();
+
+
+ token.datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());
+ token.tokenNumber = Long.decode(pcdBuildData.getToken().toString());
+ token.dynamicExTokenNumber = token.tokenNumber;
+ token.isDynamicPCD = true;
+ token.updateSupportPcdType(pcdType);
+
+ exceptionString = verifyDatum(token.cName,
+ null,
+ null,
+ token.datumType,
+ token.datumSize);
+ if (exceptionString != null) {
+ putError(exceptionString);
+ continue;
+ }
+
+ skuInfoList = pcdBuildData.getSkuInfoList();
+
+ //
+ // Loop all sku data
+ //
+ for (index = 0; index < skuInfoList.size(); index++) {
+ skuInstance = new SkuInstance();
+ //
+ // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.
+ //
+ temp = skuInfoList.get(index).getSkuId().toString();
+ skuInstance.id = Integer.decode(temp);
+ if (skuInstance.id == 0) {
+ hasSkuId0 = true;
+ }
+ //
+ // Judge whether is DefaultGroup at first, because most case is DefautlGroup.
+ //
+ if (skuInfoList.get(index).getValue() != null) {
+ skuInstance.value.setValue(skuInfoList.get(index).getValue().toString());
+ if ((exceptionString = verifyDatum(token.cName,
+ null,
+ skuInfoList.get(index).getValue().toString(),
+ token.datumType,
+ token.datumSize)) != null) {
+ putError(exceptionString);
+ continue;
+ }
+
+ token.skuData.add(skuInstance);
+
+ continue;
+ }
+
+ //
+ // Judge whether is HII group case.
+ //
+ if (skuInfoList.get(index).getVariableName() != null) {
+ exceptionString = null;
+ if (skuInfoList.get(index).getVariableGuid() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in the <DynamicPcdBuildDefinitions> section of the FPD "+
+ "file, use of HII is defined, but there is no <VariableGuid> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ continue;
+ }
+
+ if (skuInfoList.get(index).getVariableOffset() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in the <DynamicPcdBuildDefinitions> section of the FPD "+
+ "file, use of HII is defined, but there is no <VariableOffset> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ continue;
+ }
+
+ if (skuInfoList.get(index).getHiiDefaultValue() == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in the <DynamicPcdBuildDefinitions> section of the FPD "+
+ "file, use of HII is defined, but there is no <HiiDefaultValue> defined for SKU %d data!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ continue;
+ }
+
+ if (skuInfoList.get(index).getHiiDefaultValue() != null) {
+ hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString();
+ } else {
+ hiiDefaultValue = null;
+ }
+
+ if ((exceptionString = verifyDatum(token.cName,
+ null,
+ hiiDefaultValue,
+ token.datumType,
+ token.datumSize)) != null) {
+ putError(exceptionString);
+ continue;
+ }
+
+ offset = Integer.decode(skuInfoList.get(index).getVariableOffset());
+ if (offset > 0xFFFF) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the variable offset defined in SKU %d data "+
+ "exceeds 64K, which is not allowed!",
+ token.cName,
+ index);
+ putError(exceptionString);
+ continue;
+ }
+
+ //
+ // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.
+ //
+ variableGuidString = getGuidInfoFromSpd(skuInfoList.get(index).getVariableGuid().toString());
+ if (variableGuidString == null) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the variable guid %s cannot be found in any SPD file!",
+ token.cName,
+ skuInfoList.get(index).getVariableGuid().toString());
+ putError(exceptionString);
+ continue;
+ }
+ String variableStr = skuInfoList.get(index).getVariableName();
+ Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");
+ Matcher matcher = pattern.matcher(variableStr);
+ List<String> varNameList = new ArrayList<String>();
+ while (matcher.find()){
+ String str = variableStr.substring(matcher.start(),matcher.end());
+ varNameList.add(str);
+ }
+
+ skuInstance.value.setHiiData(varNameList,
+ translateSchemaStringToUUID(variableGuidString),
+ skuInfoList.get(index).getVariableOffset(),
+ skuInfoList.get(index).getHiiDefaultValue().toString());
+ token.skuData.add(skuInstance);
+ continue;
+ }
+
+ if (skuInfoList.get(index).getVpdOffset() != null) {
+ skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());
+ token.skuData.add(skuInstance);
+ continue;
+ }
+
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s, the dynamic info must "+
+ "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",
+ token.cName);
+ putError(exceptionString);
+ }
+
+ if (!hasSkuId0) {
+ exceptionString = String.format("In the FPD file, for dynamic PCD %s in <DynamicPcdBuildDefinitions>, there is "+
+ "no SKU ID = 0 data, which is required for every dynamic PCD",
+ token.cName);
+ putError(exceptionString);
+ continue;
+ }
+
+ tokenArray.add(token);
+ }
+
+ return tokenArray;
+ }
+
+ /**
+ Translate the schema string to UUID instance.
+
+ In schema, the string of UUID is defined as following two types string:
+ 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(
+ )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?
+
+ 2) GuidNamingConvention: pattern =
+ [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}
+
+ This function will convert string and create uuid instance.
+
+ @param uuidString UUID string in XML file
+
+ @return UUID UUID instance
+ **/
+ private UUID translateSchemaStringToUUID(String uuidString)
+ throws PlatformPcdPreprocessException {
+ String temp;
+ String[] splitStringArray;
+ int index;
+ int chIndex;
+ int chLen;
+
+ if (uuidString == null) {
+ return null;
+ }
+
+ if (uuidString.length() == 0) {
+ return null;
+ }
+
+ if (uuidString.equals("0") ||
+ uuidString.equalsIgnoreCase("0x0")) {
+ 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.
+ //
+ if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {
+ splitStringArray = uuidString.split("," );
+ if (splitStringArray.length != 11) {
+ throw new PlatformPcdPreprocessException ("Wrong format for GUID string: " + uuidString);
+ }
+
+ //
+ // Remove blank space from these string and remove header string "0x"
+ //
+ for (index = 0; index < 11; index++) {
+ splitStringArray[index] = splitStringArray[index].trim();
+ splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());
+ }
+
+ //
+ // Add heading '0' to normalize the string length
+ //
+ for (index = 3; index < 11; index++) {
+ chLen = splitStringArray[index].length();
+ for (chIndex = 0; chIndex < 2 - chLen; chIndex++) {
+ splitStringArray[index] = "0" + splitStringArray[index];
+ }
+ }
+
+ //
+ // construct the final GuidNamingConvention string
+ //
+ temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",
+ splitStringArray[0],
+ splitStringArray[1],
+ splitStringArray[2],
+ splitStringArray[3],
+ splitStringArray[4],
+ splitStringArray[5],
+ splitStringArray[6],
+ splitStringArray[7],
+ splitStringArray[8],
+ splitStringArray[9],
+ splitStringArray[10]);
+ uuidString = temp;
+ }
+
+ return UUID.fromString(uuidString);
+ }
+}
+
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java
new file mode 100644
index 0000000000..3cd272f719
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java
@@ -0,0 +1,353 @@
+/** @file
+ CommonDefinition class.
+
+ This class is to define some common marcos and funcions, which used by AutoGen.
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ **/
+package org.tianocore.pcd.entity;
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ CommonDefinition
+
+ This class is to define some common marcos, which used by AutoGen.
+
+**/
+public class CommonDefinition {
+ public final static String spdSuffix = ".spd";
+ public final static String mbdSuffix = ".mbd";
+ public final static String msaSuffix = ".msa";
+ public final static String LibraryStr = "LIBRARY";
+ public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";
+ public final static String include = "#include";
+ public final static String autoGenCLine1 = "\r\n";
+
+ public final static String autoGenCLine2 = "const UINT8 _gDebugPropertyMask "
+ + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"
+ + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"
+ + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";
+
+ public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"
+ + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";
+
+ public final static String autoGenHLine1 = "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";
+ public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";
+ public final static String autoGenHLine2 = "#define EDK_RELEASE_VERSION 0x00090000\r\n";
+ public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION 0x00000000\r\n";
+
+ public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;
+ public final static String marcDefineStr = "#define ";
+
+ public final static String gEfi = "gEfi";
+ public final static String protocolGuid = "ProtocolGuid";
+ public final static String ppiGuid = "PpiGuid";
+ public final static String guidGuid = "Guid";
+
+ public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";
+ public final static String flashMapH = "FlashMap.h";
+
+ //
+ // AutoGen.h and AutoGen.c file's header
+ //
+ public final static String autogenHNotation =
+ "/**\r\n" +
+ " DO NOT EDIT\r\n" +
+ " FILE auto-generated by GenBuild tasks\r\n" +
+ " Module name:\r\n" +
+ " AutoGen.h\r\n" +
+ " Abstract:" +
+ " Auto-generated AutoGen.h for building module or library.\r\n" +
+ "**/\r\n\r\n";
+
+ public final static String autogenCNotation =
+ "/**\r\n" +
+ " DO NOT EDIT\r\n" +
+ " FILE auto-generated by GenBuild tasks\r\n" +
+ " Module name:\r\n" +
+ " AutoGen.c\r\n" +
+ " Abstract:" +
+ " Auto-generated AutoGen.c for building module or library.\r\n" +
+ "**/\r\n\r\n";
+
+ //
+ // module type
+ //
+ public final static int ModuleTypeBase = 0;
+ public final static int ModuleTypeSec = 1;
+ public final static int ModuleTypePeiCore = 2;
+ public final static int ModuleTypePeim = 3;
+ public final static int ModuleTypeDxeCore = 4;
+ public final static int ModuleTypeDxeDriver = 5;
+ public final static int ModuleTypeDxeRuntimeDriver = 6;
+ public final static int ModuleTypeDxeSmmDriver = 7;
+ public final static int ModuleTypeDxeSalDriver = 8;
+ public final static int ModuleTypeUefiDriver = 9;
+ public final static int ModuleTypeUefiApplication = 10;
+ public final static int ModuleTypeUnknown = 11;
+
+
+ //
+ // component type
+ //
+ public final static int ComponentTypeNull = 0;
+ public final static int ComponentTypeApriori = 1;
+ public final static int ComponentTypeSec = 2;
+ public final static int ComponentTypeLibrary = 3;
+ public final static int ComponentTypeFvImageFile = 4;
+ public final static int ComponentTypeBsDriver = 5;
+ public final static int ComponentTypeRtDriver = 6;
+ public final static int ComponentTypeSalRtDriver =7;
+ public final static int ComponentTypePe32Peim = 8;
+ public final static int ComponentTypePicPeim =9;
+ public final static int ComponentTypeCombinedPeimDriver =10;
+ public final static int ComponentTypePeiCore = 11;
+ public final static int ComponentTypeDxeCore = 12;
+ public final static int ComponentTypeApplication = 13;
+ public final static int ComponentTypeBsDriverEfi = 14;
+ public final static int ComponentTypeShellApp = 15;
+ public final static int ComponentTypeBinary =16;
+ public final static int ComponentTypeLogo = 17;
+ public final static int ComponentTypeCustomBuild = 18;
+ public final static int ComponentTypeUnknown = 19;
+
+
+ //
+ // Usaged style
+ //
+ public final static String AlwaysConsumed = "ALWAYS_CONSUMED";
+ public final static String AlwaysProduced = "ALWAYS_PRODUCED";
+
+
+ public static class MyEnum {
+ String moduleTypeStr;
+ int type;
+
+ MyEnum (String str, int type) {
+ this.type = type;
+ this.moduleTypeStr = str;
+ }
+
+ int ForInt(String str) {
+ if (str.equals(this.moduleTypeStr)) {
+ return this.type;
+ } else
+ return -1;
+ }
+ }
+
+ //
+ // Module type
+ //
+ public static final MyEnum[] moduleEnum = new MyEnum[] {
+ new MyEnum("BASE", ModuleTypeBase),
+ new MyEnum("SEC", ModuleTypeSec),
+ new MyEnum("PEI_CORE", ModuleTypePeiCore),
+ new MyEnum("PEIM", ModuleTypePeim),
+ new MyEnum("DXE_CORE", ModuleTypeDxeCore),
+ new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),
+ new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),
+ new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),
+ new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),
+ new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),
+ new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };
+
+ //
+ // Component type
+ //
+ public static final MyEnum[] componentEnum = new MyEnum[]{
+ new MyEnum("APRIORI", ComponentTypeApriori),
+ new MyEnum("SEC", ComponentTypeSec),
+ new MyEnum("LIBRARY", ComponentTypeLibrary),
+ new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),
+ new MyEnum("BS_DRIVER", ComponentTypeBsDriver),
+ new MyEnum("RT_DRIVER", ComponentTypeRtDriver),
+ new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),
+ new MyEnum("PE32_PEIM", ComponentTypePe32Peim),
+ new MyEnum("PIC_PEIM", ComponentTypePicPeim),
+ new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),
+ new MyEnum("PEI_CORE", ComponentTypePeiCore),
+ new MyEnum("DXE_CORE", ComponentTypeDxeCore),
+ new MyEnum("APPLICATION", ComponentTypeApplication),
+ new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),
+ new MyEnum("SHELLAPP", ComponentTypeShellApp),
+ new MyEnum("BINARY", ComponentTypeBinary),
+ new MyEnum("LOGO", ComponentTypeLogo),
+ new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)
+ };
+
+ /**
+ getModuleType
+
+ This function get the module type value according module type string.
+
+ @param moduleTypeStr String of modlue type.
+ @return
+ **/
+ static public int getModuleType(String moduleTypeStr) {
+ int returnValue = -1;
+ for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {
+ returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);
+ if (returnValue != -1) {
+ return returnValue;
+ }
+ }
+ return CommonDefinition.ModuleTypeUnknown;
+ }
+
+ /**
+ getComponentType
+
+ This function get the component type value according commponet type
+ string.
+
+ @param componentTypeStr String of component type.
+ @return
+ **/
+ static public int getComponentType (String componentTypeStr){
+ int returnValue = -1;
+ for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {
+ returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);
+ if (returnValue != -1) {
+ return returnValue;
+ }
+ }
+ return CommonDefinition.ComponentTypeUnknown;
+ }
+
+ /**
+ getComponentTypeString
+
+ This function get the commponet type string according component type value.
+
+ @param componentType Integer value of component type.
+ @return
+ **/
+ static public String getComponentTypeString (int componentType) {
+ if ((componentType > CommonDefinition.ComponentTypeUnknown) ||
+ (componentType < CommonDefinition.ComponentTypeNull)) {
+ return null;
+ }
+ for (int index = 0; index < CommonDefinition.componentEnum.length; index++) {
+ if (componentType == CommonDefinition.componentEnum[index].type) {
+ return CommonDefinition.componentEnum[index].moduleTypeStr;
+ }
+ }
+ return null;
+ }
+
+ /**
+ isLibraryComponent
+
+ This function is to check does componet is library according to commponet
+ type value.
+
+ @param componentType Integer value of component type.
+ @return
+ **/
+ static public boolean isLibraryComponent (int componentType) {
+ if (ComponentTypeLibrary == componentType) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * formateGuidName
+ *
+ * This function is to formate GUID to ANSI c form.
+ *
+ * @param guidNameCon
+ * String of GUID.
+ * @return Formated GUID.
+ */
+ public static String formatGuidName(String guidNameConv) {
+ String[] strList;
+ String guid = "";
+ int index = 0;
+ if (guidNameConv
+ .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
+ strList = guidNameConv.split("-");
+ guid = "0x" + strList[0] + ", ";
+ guid = guid + "0x" + strList[1] + ", ";
+ guid = guid + "0x" + strList[2] + ", ";
+ guid = guid + "{";
+ guid = guid + "0x" + strList[3].substring(0, 2) + ", ";
+ guid = guid + "0x" + strList[3].substring(2, 4);
+
+ while (index < strList[4].length()) {
+ guid = guid + ", ";
+ guid = guid + "0x" + strList[4].substring(index, index + 2);
+ index = index + 2;
+ }
+ guid = guid + "}";
+ return guid;
+ } else if (guidNameConv
+ .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {
+ strList = guidNameConv.split(",");
+
+ //
+ // chang Microsoft specific form to ANSI c form
+ //
+ for (int i = 0; i < 3; i++) {
+ guid = guid + strList[i] + ",";
+ }
+ guid = guid + "{";
+
+ for (int i = 3; i < strList.length; i++) {
+ if (i == strList.length - 1) {
+ guid = guid + strList[i];
+ } else {
+ guid = guid + strList[i] + ",";
+ }
+ }
+ guid = guid + "}";
+ return guid;
+ } else {
+ System.out
+ .println("Check GUID Value, it doesn't conform to the registry format specified by the schema!!!");
+ return "0";
+
+ }
+ }
+
+ /**
+ * Remove deuplicat string in list
+ *
+ * This function is to duplicat string in list
+ *
+ * @param String[]
+ * String list.
+ * @return String[] String list which remove the duplicate string.
+ */
+ public static String[] remDupString (String[] orgList){
+ Set<String> strList = new LinkedHashSet<String>();
+ String[] desList ;
+ if (orgList == null){
+ return new String[0];
+ }
+ for (int i = 0; i < orgList.length; i++){
+ strList.add(orgList[i]);
+ }
+ desList = new String[strList.size()];
+ Iterator item = strList.iterator();
+ int index = 0;
+ while (item.hasNext()){
+ desList[index] = (String)item.next();
+ index++;
+ }
+ return desList;
+ }
+
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java
new file mode 100644
index 0000000000..15d003622c
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java
@@ -0,0 +1,162 @@
+/** @file
+ DynamicTokenValue class.
+
+ This module contains the value type of a dynamic token.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.tianocore.pcd.exception.EntityException;
+
+/**
+ This class is to descript a value type of dynamic PCD.
+ For a dynamic or dynamicEx type PCD data, the value type can be:
+ 1) Hii type: the value of dynamic or dynamicEx is stored into a variable.
+ 2) Vpd type: the value of dynamic or dynamicEx is stored into somewhere set
+ by OEM.
+ 3) Default type: the value of dynamic or dynamicEx is stored into PCD dynamic
+ database.
+**/
+public class DynamicTokenValue {
+ ///
+ /// Enumeration macro defintion for value type.
+ ///
+ public static enum VALUE_TYPE {HII_TYPE, VPD_TYPE, DEFAULT_TYPE}
+
+ ///
+ /// The value type maybe:
+ /// HII_TYPE: the value stored into variable area.
+ /// VPD_TYPE: the value stored into OEM specific area.
+ /// DEFAULT_TYPE: the value stored into PCD runtime database.
+ ///
+ public VALUE_TYPE type;
+
+ ///
+ /// ---------------------------------------------------------------------
+ /// Following member is for HII case. The value of HII case will be put
+ /// into variable area in flash.
+ /// ---------------------------------------------------------------------
+ ///
+
+ ///
+ /// 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 List variableName;
+
+ ///
+ /// variableGuid is the GUID this token associated with.
+ ///
+ public UUID variableGuid;
+
+ ///
+ /// Variable offset indicate the associated variable's offset in NV storage.
+ ///
+ public String variableOffset;
+
+ ///
+ /// The default value for HII case.
+ ///
+ public String hiiDefaultValue;
+
+ ///
+ /// ---------------------------------------------------------------------
+ /// Following member is for VPD case. The value of VPD case will be put into
+ /// some flash position pointed by OEM.
+ /// ---------------------------------------------------------------------
+ ///
+
+ public String vpdOffset;
+
+ /// ---------------------------------------------------------------------
+ /// Following member is for default case. The value of default type will
+ /// be put into PCD runtime database.
+ /// ---------------------------------------------------------------------
+
+ ///
+ /// The default value of this PCD in default case.
+ ///
+ public String value;
+
+ /**
+ Constructor function for DynamicTokenValue class.
+
+ **/
+ public DynamicTokenValue() {
+ type = VALUE_TYPE.DEFAULT_TYPE;
+ variableName = null;
+ variableGuid = null;
+ variableOffset = null;
+ hiiDefaultValue = null;
+ vpdOffset = null;
+ value = null;
+ }
+
+ /**
+ Set the HII case data.
+
+ @param variableName The variable name
+ @param variableGuid The variable guid
+ @param variableOffset The offset of value in this variable
+ @param hiiDefaultValue Default value for this PCD
+ **/
+ public void setHiiData(List variableName,
+ UUID variableGuid,
+ String variableOffset,
+ String hiiDefaultValue) {
+ this.type = VALUE_TYPE.HII_TYPE;
+
+ this.variableName = variableName;
+ this.variableGuid = variableGuid;
+ this.variableOffset = variableOffset;
+ this.hiiDefaultValue = hiiDefaultValue;
+ }
+
+ /**
+ Get the variable Name.
+
+ @return String
+ **/
+ public List getStringOfVariableName() {
+ return variableName;
+ }
+
+ /**
+ Set Vpd case data.
+
+ @param vpdOffset the value offset the start address of OEM specific.
+ **/
+ public void setVpdData(String vpdOffset) {
+ this.type = VALUE_TYPE.VPD_TYPE;
+
+ this.vpdOffset = vpdOffset;
+ }
+
+ /**
+ Set default case data.
+
+ @param value
+ **/
+ public void setValue(String value) {
+ this.type = VALUE_TYPE.DEFAULT_TYPE;
+
+ this.value = value;
+ }
+}
+
+
+
+
+
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java
new file mode 100644
index 0000000000..f7c08f5330
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java
@@ -0,0 +1,313 @@
+/** @file
+ MemoryDatabaseManager class.
+
+ Database hold all PCD information comes from SPD, MSA, FPD file in memory.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.tianocore.pcd.entity.UsageIdentification;
+import org.tianocore.pcd.exception.EntityException;
+
+/**
+ Database hold all PCD information comes from SPD, MSA, FPD file in memory.
+**/
+public class MemoryDatabaseManager {
+ ///
+ /// Memory database. The string "cName + SpaceNameGuid" is primary key.
+ /// memory database is in global scope, and it will be used for others PCD tools.
+ ///
+ private static Map<String, Token> memoryDatabase = null;
+
+ ///
+ /// Before build a module, the used libary will be build firstly, the PCD of these
+ /// library is inheritted by the module, so stored module's PCD information as PCD
+ /// context of building libary.
+ ///
+ public static List<UsageInstance> UsageInstanceContext = null;
+
+ ///
+ /// Current module name, if now is buiding library, this value indicate this library
+ /// is for building what module.
+ ///
+ public static String CurrentModuleName = null;
+
+ ///
+ /// String for PCD PEIM and DXE autogen file
+ ///
+ public static String PcdPeimHString = "";
+ public static String PcdPeimCString = "";
+ public static String PcdDxeHString = "";
+ public static String PcdDxeCString = "";
+
+ /**
+ Constructure function
+ **/
+ public MemoryDatabaseManager() {
+ //
+ // Allocate memory for new database in global scope.
+ //
+ if (memoryDatabase == null) {
+ memoryDatabase = new HashMap<String, Token>();
+ }
+ }
+
+ /**
+ Judege whether token exists in memory database
+
+ @param primaryKey the primaryKey for searching token
+
+ @retval TRUE - token already exist in database.
+ @retval FALSE - token does not exist in database.
+ **/
+ public boolean isTokenInDatabase(String primaryKey) {
+ return (memoryDatabase.get(primaryKey) != null);
+ }
+
+ /**
+ Add a pcd token into memory database.
+
+ @param primaryKey the primary key for searching token
+ @param token token instance
+ **/
+ public void addTokenToDatabase(String primaryKey, Token token) {
+ memoryDatabase.put(primaryKey, token);
+ }
+
+ /**
+ Get a token instance from memory database with primary key.
+
+ @param primaryKey the primary key for searching token
+
+ @return token instance.
+ **/
+ public Token getTokenByKey(String primaryKey) {
+ return memoryDatabase.get(primaryKey);
+ }
+
+ /**
+ Get the number of PCD token record in memory database.
+
+ @return the number of PCD token record in memory database.
+ **/
+ public int getDBSize() {
+ return memoryDatabase.size();
+ }
+
+ /**
+ Get the token record array contained all PCD token in memory database.
+
+ @return the token record array contained all PCD token in memory database.
+ **/
+ public Token[] getRecordArray() {
+ Token[] tokenArray = null;
+ Object[] dataArray = null;
+ Map.Entry entry = null;
+ int index = 0;
+ int size = 0;
+
+ if (memoryDatabase == null) {
+ return null;
+ }
+ dataArray = memoryDatabase.entrySet().toArray();
+ size = memoryDatabase.size();
+ tokenArray = new Token[memoryDatabase.size()];
+ for (index = 0; index < size; index++) {
+ entry =(Map.Entry) dataArray [index];
+ tokenArray[index] =(Token) entry.getValue();
+ }
+ return tokenArray;
+ }
+
+ /**
+ Get record array only contains DYNAMIC or DYNAMIC_EX type PCD.
+
+ @return ArrayList the array list contains all dynamic type PCD.
+ **/
+ private ArrayList getDynamicRecordArray() {
+ Token[] tokenArray = getRecordArray();
+ int index = 0;
+ ArrayList<Token> al = new ArrayList<Token>();
+
+ for (index = 0; index < tokenArray.length; index++) {
+ if (tokenArray[index].isDynamicPCD) {
+ al.add(tokenArray[index]);
+ }
+ }
+
+ return al;
+ }
+
+
+ /**
+ Get the token record array contained all PCD token referenced by PEI phase.
+ The output array is sorted based on descending order of the size of alignment for each feilds.
+
+ @return the token record array contained all PCD token referenced in PEI phase.
+ @throws EntityException
+ **/
+ public void getTwoPhaseDynamicRecordArray(ArrayList<Token> pei, ArrayList<Token> dxe)
+ throws EntityException {
+ int usageInstanceIndex = 0;
+ int index = 0;
+ ArrayList tokenArrayList = getDynamicRecordArray();
+ Object[] usageInstanceArray = null;
+ UsageInstance usageInstance = null;
+ int size = 0;
+ int consumerSize = 0;
+
+ size = tokenArrayList.size();
+ for (index = 0; index < size; index++) {
+ boolean found = false;
+ Token token = (Token) tokenArrayList.get(index);
+ if (token.consumers != null) {
+ usageInstanceArray = token.consumers.entrySet().toArray();
+ consumerSize = token.consumers.size();
+ for (usageInstanceIndex = 0; usageInstanceIndex < consumerSize; usageInstanceIndex++) {
+ usageInstance =(UsageInstance) (((Map.Entry)usageInstanceArray[usageInstanceIndex]).getValue());
+ if (usageInstance.isPeiPhaseComponent()) {
+ pei.add(token);
+ found = true;
+ break;
+ }
+ }
+ }
+
+ //
+ // If no PEI components reference the PCD entry,
+ // we check if it is referenced in DXE driver.
+ //
+ if (!found) {
+ if (token.consumers != null) {
+ usageInstanceArray = token.consumers.entrySet().toArray();
+ consumerSize = token.consumers.size();
+ for (usageInstanceIndex = 0; usageInstanceIndex < consumerSize; usageInstanceIndex++) {
+ usageInstance =(UsageInstance) (((Map.Entry)usageInstanceArray[usageInstanceIndex]).getValue());
+ if (usageInstance.isDxePhaseComponent()) {
+ dxe.add(token);
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if (!found) {
+ if (token.isDynamicPCD && token.consumers.size() == 0) {
+ dxe.add(token);
+ } else {
+ //
+ // We only support Dynamice(EX) type for PEI and DXE phase.
+ // If it is not referenced in either PEI or DXE, throw exception now.
+ //
+ throw new EntityException("[PCD Tool Internal Error] Dynamic(EX) PCD Entries are referenced in a module that is not used in either PEI or DXE phases.");
+ }
+ }
+ }
+ }
+ }
+
+ public void clearDatabase() {
+ memoryDatabase.clear();
+ }
+
+ /**
+ Get all PCD token for a usage instance according to primary key.
+
+ @param primaryKey the primary key of usage instance.
+
+ @return List<UsageInstance> the list contains all usage instances.
+ **/
+ public List<UsageInstance> getUsageInstanceArrayById(UsageIdentification usageId) {
+ Token[] tokenArray = null;
+ int recordIndex = 0;
+ UsageInstance usageInstance = null;
+ List<UsageInstance> returnArray = new ArrayList<UsageInstance>();
+ String primaryKey = usageId.toString();
+
+ tokenArray = getRecordArray();
+
+ //
+ // Loop to find all PCD record related to current module
+ //
+ for (recordIndex = 0; recordIndex < getDBSize(); recordIndex++) {
+ if (tokenArray[recordIndex].consumers.size() != 0) {
+ usageInstance = tokenArray[recordIndex].consumers.get(primaryKey);
+ if (usageInstance != null) {
+ returnArray.add(usageInstance);
+ }
+ }
+ }
+
+ return returnArray;
+ }
+
+ public List<Token> getPcdTokenListForModule(UsageIdentification usageId) {
+ List<UsageInstance> usageList = getUsageInstanceArrayById(usageId);
+ List<Token> tokenList = new ArrayList<Token>();
+
+ if (usageList == null) {
+ return null;
+ }
+
+ for (int usageIndex = 0; usageIndex < usageList.size(); usageIndex++) {
+ tokenList.add(usageList.get(usageIndex).parentToken);
+ }
+
+ return tokenList;
+ }
+
+ /**
+ Get all modules name who contains PCD information
+
+ @return Array for usage's identification
+ **/
+ public List<UsageIdentification> getAllModuleArray()
+ {
+ int tokenIndex = 0;
+ int usageIndex = 0;
+ int moduleIndex = 0;
+ Token[] tokenArray = null;
+ Object[] usageInstanceArray = null;
+ List<UsageIdentification> usageArray = new ArrayList<UsageIdentification>();
+ UsageInstance usageInstance = null;
+ boolean bFound = false;
+ String primaryKey = null;
+
+ tokenArray = getRecordArray();
+ //
+ // Find all consumer usage instance for retrieving module's name
+ //
+ for (tokenIndex = 0; tokenIndex < getDBSize(); tokenIndex++) {
+ usageInstanceArray = tokenArray[tokenIndex].consumers.entrySet().toArray();
+ for (usageIndex = 0; usageIndex < tokenArray[tokenIndex].consumers.size(); usageIndex++) {
+ usageInstance = (UsageInstance)((Map.Entry)usageInstanceArray[usageIndex]).getValue();
+ primaryKey = usageInstance.getPrimaryKey();
+ bFound = false;
+ for (moduleIndex = 0; moduleIndex < usageArray.size(); moduleIndex++) {
+ if (usageArray.get(moduleIndex).toString().equalsIgnoreCase(primaryKey)) {
+ bFound = true;
+ break;
+ }
+ }
+ if (!bFound) {
+ usageArray.add(usageInstance.usageId);
+ }
+ }
+ }
+ return usageArray;
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/ModulePcdInfoFromFpd.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/ModulePcdInfoFromFpd.java
new file mode 100644
index 0000000000..fe9f7ecabc
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/ModulePcdInfoFromFpd.java
@@ -0,0 +1,48 @@
+/** @file
+ ModulePcdInfoFromFpd class.
+
+ The interface parameter from <ModuleSA>'s Pcd information got from global data.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+import org.tianocore.PcdBuildDefinitionDocument;
+import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ PCD build information in <ModuleSA> in FPD file.
+**/
+public class ModulePcdInfoFromFpd {
+ ///
+ /// Usage identification for a module
+ ///
+ public UsageIdentification usageId;
+
+ ///
+ /// <ModuleSA>'s <PcdBuildDefinition> information.
+ ///
+ public PcdBuildDefinition pcdBuildDefinition;
+
+ /**
+ Construct function.
+
+ @param usageId The usage instance's identification
+ @param pcdBuildDefinition The <PcdBuildDefinition> information in <ModuleSA> in FPD file.
+
+ **/
+ public ModulePcdInfoFromFpd(UsageIdentification usageId,
+ PcdBuildDefinition pcdBuildDefinition) {
+ this.usageId = usageId;
+ this.pcdBuildDefinition = pcdBuildDefinition;
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java
new file mode 100644
index 0000000000..6e666ba84f
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java
@@ -0,0 +1,50 @@
+/** @file
+ SkuInstance class.
+
+ Sku instance contains ID and value, A pcd token maybe contains more than one Sku instance.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+/**
+ Sku instance contains ID and value, A pcd token maybe contains more than one Sku instance.
+**/
+public class SkuInstance {
+ ///
+ /// The id number of this SKU instance
+ ///
+ public int id;
+
+ ///
+ /// The value of this SKU instance
+ ///
+ public DynamicTokenValue value;
+
+ /**
+ Constructure function
+
+ @param id sku id
+ @param value sku value for this id.
+ **/
+ public SkuInstance(int id, DynamicTokenValue value) {
+ this.id = id;
+ this.value = value;
+ }
+
+ /**
+ Default constructor function.
+ **/
+ public SkuInstance() {
+ this.id = 0;
+ this.value = new DynamicTokenValue();
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/Token.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/Token.java
new file mode 100644
index 0000000000..74f55ddec3
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/Token.java
@@ -0,0 +1,960 @@
+/** @file
+ Token class.
+
+ This module contains all classes releted to PCD token.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ 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.
+**/
+public class Token {
+ ///
+ /// Enumeration macro defintion for PCD type.
+ ///
+ public static enum PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC,
+ DYNAMIC_EX, UNKNOWN}
+
+ ///
+ /// Enumeration macro definition for datum type. All type mainly comes from ProcessBind.h.
+ /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in
+ /// prompt dialog.
+ ///
+ public static enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN}
+
+ ///
+ /// Enumeration macor defintion for usage of PCD
+ ///
+ public static enum PCD_USAGE {ALWAYS_PRODUCED, ALWAYS_CONSUMED, SOMETIMES_PRODUCED,
+ SOMETIMES_CONSUMED, UNKNOWN}
+
+ ///
+ /// cName is to identify a PCD entry and will be used for generating autogen.h/autogen.c.
+ /// cName will be defined in MSA, SPD and FPD, can be regarded as primary key with token space guid.
+ ///
+ public String cName;
+
+ ///
+ /// Token space name is the guid defined by token itself in package or module level. This
+ /// name mainly for DynamicEx type. For other PCD type token, his token space name is the
+ /// assignedtokenSpaceName as follows.
+ /// tokenSpaceName is defined in MSA, SPD, FPD, can be regarded as primary key with cName.
+ ///
+ public String tokenSpaceName;
+
+ ///
+ /// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in
+ /// platform token space. For Dynamic, dynamicEx type, this number will be re-adjust by
+ /// PCD run-time database autogen tools.
+ ///
+ public long tokenNumber;
+
+ ///
+ /// This token number is retrieved from FPD file for DynamicEx type.
+ ///
+ public long dynamicExTokenNumber;
+
+ ///
+ /// 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<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.
+ /// datumSize is defined in SPD.
+ ///
+ public int datumSize;
+
+ ///
+ /// datum type is to descript what type can be expressed by a PCD token.
+ /// For same PCD used in different module, the datum type should be unique.
+ /// So it belong memeber to Token class.
+ ///
+ public DATUM_TYPE datumType;
+
+ ///
+ /// skuData contains all value for SkuNumber of token.
+ /// This field is for Dynamic or DynamicEx type PCD,
+ ///
+ public List<SkuInstance> skuData;
+
+ ///
+ /// consumers array record all module private information who consume this PCD token.
+ ///
+ public Map<String, UsageInstance> consumers;
+
+ /**
+ Constructure function for Token class
+
+ @param cName The name of token
+ @param tokenSpaceName The name of token space, it is a guid string
+ **/
+ public Token(String cName, String tokenSpaceName) {
+ this.cName = cName;
+ this.tokenSpaceName = tokenSpaceName;
+ this.tokenNumber = 0;
+ this.datumType = DATUM_TYPE.UNKNOWN;
+ this.datumSize = -1;
+ this.skuData = new ArrayList<SkuInstance>();
+
+ this.consumers = new HashMap<String, UsageInstance>();
+ this.supportedPcdType = new ArrayList<PCD_TYPE>();
+ }
+
+ /**
+ 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 size = supportedPcdType.size();
+ for (int index = 0; index < size; index++) {
+ if (supportedPcdType.get(index) == pcdType) {
+ return;
+ }
+ }
+
+ //
+ // If not found, add the pcd type to member variable supportedPcdType
+ //
+ supportedPcdType.add(pcdType);
+ }
+
+ /**
+ Judge whether pcdType is belong to dynamic type. Dynamic type includes
+ DYNAMIC and DYNAMIC_EX.
+
+ @param pcdType the judged pcd type
+
+ @return boolean
+ **/
+ public static boolean isDynamic(PCD_TYPE pcdType) {
+ if ((pcdType == PCD_TYPE.DYNAMIC ) ||
+ (pcdType == PCD_TYPE.DYNAMIC_EX)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ The pcd type is DynamicEx?
+
+ @retval true Is DynamicEx type
+ @retval false not DynamicEx type
+ **/
+ public boolean isDynamicEx() {
+ int size = supportedPcdType.size();
+ for (int i = 0; i < size; i++) {
+ if (supportedPcdType.get(i) == PCD_TYPE.DYNAMIC_EX) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database
+
+ @param cName Token name.
+ @param tokenSpaceName The token space guid string defined in MSA or SPD
+
+ @retval primary key for this token in token database.
+ **/
+ public static String getPrimaryKeyString(String cName, String tokenSpaceName) {
+ if (tokenSpaceName == null) {
+ return cName + "_nullTokenSpaceGuid";
+ } else {
+ return cName + "_" + tokenSpaceName.toString().replace('-', '_').toLowerCase();
+ }
+ }
+
+ /**
+ If skudata list contains more than one data, then Sku mechanism is enable.
+
+ @retval boolean if the number of sku data exceed to 1
+ **/
+ public boolean isSkuEnable() {
+ if (this.skuData.size() > 1) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ If Hii type for value of token
+
+ @return boolean
+ **/
+ public boolean isHiiEnable() {
+ if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ If Vpd type for value of token
+
+ @return boolean
+ **/
+ 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 Token.getPrimaryKeyString(cName, tokenSpaceName);
+ }
+
+ /**
+ Judge datumType is valid
+
+ @param type The datumType want to be judged.
+
+ @retval TRUE - The type is valid.
+ @retval FALSE - The type is invalid.
+ **/
+ public static boolean isValiddatumType(DATUM_TYPE type) {
+ if ((type.ordinal() < DATUM_TYPE.UINT8.ordinal() ) ||
+ (type.ordinal() > DATUM_TYPE.POINTER.ordinal())) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ Judge pcdType is valid
+
+ @param type The PCdType want to be judged.
+
+ @retval TRUE - The type is valid.
+ @retval FALSE - The type is invalid.
+ **/
+ public static boolean isValidpcdType(PCD_TYPE type) {
+ if ((type.ordinal() < PCD_TYPE.FEATURE_FLAG.ordinal() ) ||
+ (type.ordinal() > PCD_TYPE.DYNAMIC_EX.ordinal())) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ Add an usage instance for token
+
+ @param usageInstance The usage instance
+
+ @retval TRUE - Success to add usage instance.
+ @retval FALSE - Fail to add usage instance
+ **/
+ public boolean addUsageInstance(UsageInstance usageInstance) {
+ if (isUsageInstanceExist(usageInstance.usageId)) {
+ return false;
+ }
+
+ //
+ // Put usage instance into usage instance database of this PCD token.
+ //
+ consumers.put(usageInstance.getPrimaryKey(), usageInstance);
+
+ return true;
+ }
+
+ /**
+ Judge whether exist an usage instance for this token
+
+ @param usageId The UsageInstance identification for usage instance
+
+ @return boolean whether exist an usage instance for this token.
+ **/
+ public boolean isUsageInstanceExist(UsageIdentification usageId) {
+ String keyStr = UsageInstance.getPrimaryKey(usageId);
+
+ return (consumers.get(keyStr) != null);
+ }
+
+ /**
+ Get the PCD_TYPE according to the string of PCD_TYPE
+
+ @param pcdTypeStr The string of PCD_TYPE
+
+ @return PCD_TYPE
+ **/
+ public static PCD_TYPE getPcdTypeFromString(String pcdTypeStr) {
+ if (pcdTypeStr == null) {
+ return PCD_TYPE.UNKNOWN;
+ }
+
+ if (pcdTypeStr.equalsIgnoreCase("FEATURE_FLAG")) {
+ return PCD_TYPE.FEATURE_FLAG;
+ } else if (pcdTypeStr.equalsIgnoreCase("FIXED_AT_BUILD")) {
+ return PCD_TYPE.FIXED_AT_BUILD;
+ } else if (pcdTypeStr.equalsIgnoreCase("PATCHABLE_IN_MODULE")) {
+ return PCD_TYPE.PATCHABLE_IN_MODULE;
+ } else if (pcdTypeStr.equalsIgnoreCase("DYNAMIC")) {
+ return PCD_TYPE.DYNAMIC;
+ } else if (pcdTypeStr.equalsIgnoreCase("DYNAMIC_EX")) {
+ return PCD_TYPE.DYNAMIC_EX;
+ } else {
+ return PCD_TYPE.UNKNOWN;
+ }
+ }
+
+ /**
+ Get the string of given datumType. This string will be used for generating autogen files
+
+ @param datumType Given datumType
+
+ @return The string of datum type.
+ **/
+ public static String getStringOfdatumType(DATUM_TYPE datumType) {
+ return datumType.toString();
+ }
+
+ /**
+ Get the datumType according to a string.
+
+ @param datumTypeStr The string of datumType
+
+ @return DATUM_TYPE
+ **/
+ public static DATUM_TYPE getdatumTypeFromString(String datumTypeStr) {
+ if (datumTypeStr.equalsIgnoreCase("UINT8")) {
+ return DATUM_TYPE.UINT8;
+ } else if (datumTypeStr.equalsIgnoreCase("UINT16")) {
+ return DATUM_TYPE.UINT16;
+ } else if (datumTypeStr.equalsIgnoreCase("UINT32")) {
+ return DATUM_TYPE.UINT32;
+ } else if (datumTypeStr.equalsIgnoreCase("UINT64")) {
+ return DATUM_TYPE.UINT64;
+ } else if (datumTypeStr.equalsIgnoreCase("VOID*")) {
+ return DATUM_TYPE.POINTER;
+ } else if (datumTypeStr.equalsIgnoreCase("BOOLEAN")) {
+ return DATUM_TYPE.BOOLEAN;
+ }
+ return DATUM_TYPE.UNKNOWN;
+ }
+
+ /**
+ Get string of given pcdType
+
+ @param pcdType The given PcdType
+
+ @return The string of PCD_TYPE.
+ **/
+ public static String getStringOfpcdType(PCD_TYPE pcdType) {
+ return pcdType.toString();
+ }
+
+ /**
+ Get the PCD_USAGE according to a string
+
+ @param usageStr The string of PCD_USAGE
+
+ @return The PCD_USAGE
+ **/
+ public static PCD_USAGE getUsageFromString(String usageStr) {
+ if (usageStr == null) {
+ return PCD_USAGE.UNKNOWN;
+ }
+
+ if (usageStr.equalsIgnoreCase("ALWAYS_PRODUCED")) {
+ return PCD_USAGE.ALWAYS_PRODUCED;
+ } else if (usageStr.equalsIgnoreCase("SOMETIMES_PRODUCED")) {
+ return PCD_USAGE.SOMETIMES_PRODUCED;
+ } else if (usageStr.equalsIgnoreCase("ALWAYS_CONSUMED")) {
+ return PCD_USAGE.ALWAYS_CONSUMED;
+ } else if (usageStr.equalsIgnoreCase("SOMETIMES_CONSUMED")) {
+ return PCD_USAGE.SOMETIMES_CONSUMED;
+ }
+
+ return PCD_USAGE.UNKNOWN;
+ }
+
+ /**
+ Get the string of given PCD_USAGE
+
+ @param usage The given PCD_USAGE
+
+ @return The string of PDC_USAGE.
+ **/
+ public static String getStringOfUsage(PCD_USAGE usage) {
+ return usage.toString();
+ }
+
+ /**
+ Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h
+
+ @param datumType The given datumType
+
+ @return string of datum type for autogen.
+ **/
+ public static String GetAutogenDefinedatumTypeString(DATUM_TYPE datumType) {
+ switch (datumType) {
+
+ case UINT8:
+ return "8";
+ case UINT16:
+ return "16";
+ case BOOLEAN:
+ return "BOOL";
+ case POINTER:
+ return "PTR";
+ case UINT32:
+ return "32";
+ case UINT64:
+ return "64";
+ default:
+ return null;
+ }
+ }
+
+ /**
+ Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen
+
+ @param datumType The given datumType
+
+ @return string of datum type.
+ **/
+
+ public static String getAutogendatumTypeString(DATUM_TYPE datumType) {
+ switch (datumType) {
+ case UINT8:
+ return "UINT8";
+ case UINT16:
+ return "UINT16";
+ case UINT32:
+ return "UINT32";
+ case UINT64:
+ return "UINT64";
+ case POINTER:
+ return "VOID*";
+ case BOOLEAN:
+ return "BOOLEAN";
+ }
+ return null;
+ }
+
+ /**
+ Get the datumType string for generating some MACROs in autogen file of Library
+
+ @param datumType The given datumType
+
+ @return String of datum for genrating bit charater.
+ **/
+ public static String getAutogenLibrarydatumTypeString(DATUM_TYPE datumType) {
+ switch (datumType) {
+ case UINT8:
+ return "8";
+ case UINT16:
+ return "16";
+ case BOOLEAN:
+ return "Bool";
+ case POINTER:
+ return "Ptr";
+ case UINT32:
+ return "32";
+ case UINT64:
+ return "64";
+ default:
+ return null;
+ }
+ }
+
+ /**
+ Get the sku data who id is 0.
+
+ @retval DynamicTokenValue the value of this dyanmic token.
+ **/
+ public DynamicTokenValue getDefaultSku() {
+ int index;
+ int size = skuData.size();
+ for (index = 0; index < size; index++) {
+ if (skuData.get(index).id == 0) {
+ return skuData.get(index).value;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ Get the number of Sku data for this token
+
+ @retval int the number of sku data
+ **/
+ public int getSkuIdCount () {
+ return this.skuData.size();
+ }
+
+ /**
+ Get the size of PCD value, this PCD is POINTER type.
+
+ @param str the string of the value
+ @param al the array list for outer parameter.
+ **/
+ private void getCurrentSizeFromDefaultValue (String str, ArrayList<Integer> al) {
+ if (isValidNullValue(str)) {
+ al.add(new Integer(0));
+ } else {
+ //
+ // isValidNullValue has already make sure that str here
+ // always contain a valid default value of the following 3
+ // cases:
+ // 1) "Hello world" //Assci string
+ // 2) L"Hello" //Unicode string
+ // 3) {0x01, 0x02, 0x03} //Byte stream
+ //
+ if (str.startsWith("\"")) {
+ al.add(new Integer(str.length() - 2));
+ } else if (str.startsWith("L\"")){
+ //
+ // Unicode is 2 bytes each.
+ //
+ al.add(new Integer((str.length() - 3) * 2));
+ } else if (str.startsWith("{")) {
+ //
+ // We count the number of "," in the string.
+ // The number of byte is one plus the number of
+ // comma.
+ //
+ String str2 = str;
+
+ int cnt = 0;
+ int pos = 0;
+ pos = str2.indexOf(",", 0);
+ while (pos != -1) {
+ cnt++;
+ pos++;
+ pos = str2.indexOf(",", pos);
+ }
+ cnt++;
+ al.add(new Integer(cnt));
+ }
+ }
+ }
+
+ /**
+ This method can be used to get the MAX and current size
+ for pointer type dynamic(ex) PCD entry
+ **/
+ public ArrayList<Integer> getPointerTypeSize () {
+ ArrayList<Integer> al = new ArrayList<Integer>();
+
+ //
+ // For VPD_enabled and HII_enabled, we can only return the MAX size.
+ // For the default DATA type dynamic PCD entry, we will return
+ // the MAX size and current size for each SKU_ID.
+ //
+ al.add(new Integer(this.datumSize));
+
+ if (!this.isVpdEnable()) {
+ int idx;
+ if (this.isHiiEnable()){
+ for (idx = 0; idx < this.skuData.size(); idx++) {
+ String str = this.skuData.get(idx).value.hiiDefaultValue;
+ getCurrentSizeFromDefaultValue(str, al);
+ }
+ } else {
+ for (idx = 0; idx < this.skuData.size(); idx++) {
+ String str = this.skuData.get(idx).value.value;
+ getCurrentSizeFromDefaultValue(str, al);
+ }
+ }
+ }
+
+ return al;
+ }
+
+ /**
+ 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 get the default value for a DYNAMIC type PCD.
+ **/
+ public String getDynamicDefaultValue() {
+ DynamicTokenValue dynamicData = getDefaultSku();
+ if (hasDefaultValue()) {
+ switch (dynamicData.type) {
+ case DEFAULT_TYPE:
+ return dynamicData.value;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ Judge whether a DYNAMIC PCD has default value.
+
+ @return whether a DYNAMIC PCD has default value.
+ **/
+ public boolean hasDefaultValue () {
+ DynamicTokenValue dynamicValue = null;
+
+ 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);
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ Judge the value is NULL value. NULL value means the value is uninitialized value
+
+ @param judgedValue the want want to be judged
+
+ @return boolean whether the value of PCD is NULL.
+ **/
+ public boolean isValidNullValue(String judgedValue) {
+ 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("L\"\"") ||
+ (judgedValue.length() == 0)) {
+ return true;
+ } else if (judgedValue.trim().charAt(0) == '{') {
+ int start = judgedValue.indexOf('{');
+ int end = judgedValue.lastIndexOf('}');
+ String[] strValueArray = judgedValue.substring(start + 1, end).split(",");
+ if (strValueArray.length > 1) {
+ return false;
+ } else {
+ if (strValueArray[0].matches("(0x)?(0X)?0*")) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ Is the string value in Unicode
+
+ @return boolean the string value is UNICODE type string.
+ **/
+ public boolean isHiiDefaultValueUnicodeStringType() {
+ DynamicTokenValue dynamicData = getDefaultSku();
+
+ if (dynamicData == null)
+ return false;
+
+ return dynamicData.hiiDefaultValue.startsWith("L\"")
+ && dynamicData.hiiDefaultValue.endsWith("\"");
+ }
+
+ /**
+ Is the string value in ANSCI
+
+ @return boolean whether the dfault value for HII case is string type.
+ **/
+ public boolean isHiiDefaultValueASCIIStringType() {
+ DynamicTokenValue dynamicData = getDefaultSku();
+
+ if (dynamicData == null)
+ return false;
+
+ return dynamicData.hiiDefaultValue.startsWith("\"")
+ && dynamicData.hiiDefaultValue.endsWith("\"");
+ }
+
+ /**
+ Judege whether current value is UNICODE string type.
+
+ @return boolean whether the value is UNICODE string.
+ **/
+ public boolean isUnicodeStringType () {
+ String str = getDynamicDefaultValue();
+
+ if (str == null) {
+ return false;
+ }
+
+ if (datumType == Token.DATUM_TYPE.POINTER &&
+ str.startsWith("L\"") &&
+ str.endsWith("\"")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ Judge whether the string type is ANSIC string.
+
+ @return boolean whether the string type is ANSIC string
+ **/
+ public boolean isASCIIStringType () {
+ String str = getDynamicDefaultValue();
+
+ if (str == null) {
+ return false;
+ }
+
+ if (datumType == Token.DATUM_TYPE.POINTER &&
+ str.startsWith("\"") &&
+ str.endsWith("\"")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ Judge whether the string value is byte array.
+
+ @return boolean whether the string value is byte array.
+
+ **/
+ 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;
+
+ }
+
+ /**
+ Get string value for ANSIC string type
+
+ @return String the string value
+ **/
+ public String getStringTypeString () {
+ return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);
+ }
+
+ /**
+ Judge whether a datum string is byte array.
+
+ @param datum datum string
+
+ @return boolean true - is byte array, false - not byte array
+ **/
+ public static boolean isByteArrayDatum(String datum) {
+ if (datum == null) {
+ return false;
+ }
+
+ String trimedStr = datum.trim();
+
+ if (trimedStr.length() == 0) {
+ return false;
+ }
+
+ if (trimedStr.startsWith("{") &&
+ trimedStr.endsWith("}")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ Judge whether a datum string is unicode.
+
+ @param datum datum string
+
+ @return boolean true - is unicode, false - not unicode
+ **/
+ public static boolean isUnicodeDatum(String datum) {
+ if (datum == null) {
+ return false;
+ }
+
+ String trimedStr = datum.trim();
+ if (trimedStr.length() == 0) {
+ return false;
+ }
+
+ if (trimedStr.startsWith("L") &&
+ trimedStr.charAt(1) == '"' &&
+ trimedStr.endsWith("\"")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ Judge whether a datum string is ANSCI string.
+
+ @param datum datum string
+
+ @return boolean true - is ANSIC, false - not ANSIC
+ **/
+ public static boolean isAnsciDatum(String datum) {
+ if (datum == null) {
+ return false;
+ }
+
+ String trimedStr = datum.trim();
+
+ if (trimedStr.length() == 0) {
+ return false;
+ }
+
+ if (datum.startsWith("\"") &&
+ datum.endsWith("\"")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ Get byte array string for POINTER type Datum.
+
+ @param datum the datum whose type is POINTER
+
+ @return String the byte array string
+ **/
+ public String getByteArrayForPointerDatum(String datum) {
+ String byteArray = "{";
+
+ if (datumType != Token.DATUM_TYPE.POINTER) {
+ return null;
+ }
+
+ if (Token.isAnsciDatum(datum)) {
+ String trimedStr = datum.trim();
+ trimedStr = trimedStr.substring(1, trimedStr.length() - 1);
+ char charArray[] = trimedStr.toCharArray();
+ for (int index = 0; index < charArray.length; index++) {
+ byteArray += String.format("0x%02x ", (byte)charArray[index]);
+ if (index != (charArray.length - 1)) {
+ byteArray += ",";
+ }
+ }
+ } else if (Token.isUnicodeDatum(datum)) {
+ String trimedStr = datum.trim();
+ trimedStr = trimedStr.substring(2, trimedStr.length() - 1);
+ for (int index = 0; index < trimedStr.length(); index++) {
+ short unicodeVal = (short)trimedStr.codePointAt(index);
+ byteArray += String.format("0x%02x, 0x%02x",
+ (byte)unicodeVal,
+ (byte)((unicodeVal & 0xFF00) >> 8));
+ if (index != (trimedStr.length() - 1)) {
+ byteArray += " ,";
+ }
+ }
+ } else if (Token.isByteArrayDatum(datum)){
+ return datum;
+ } else {
+ return null;
+ }
+
+ byteArray += "}";
+
+ return byteArray;
+ }
+}
+
+
+
+
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java
new file mode 100644
index 0000000000..0c54525661
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java
@@ -0,0 +1,105 @@
+/** @file
+ UsageIdentification class.
+
+ This class an identification for a PCD UsageInstance.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+package org.tianocore.pcd.entity;
+
+/**
+ The identification for a UsageInstance.
+ It should be extend from ModuleIdentification in future.
+
+**/
+public class UsageIdentification {
+ ///
+ /// The module CName: one key of Identification
+ ///
+ public String moduleName;
+
+ ///
+ /// The module Guid String: one key of Identification
+ ///
+ public String moduleGuid;
+
+ ///
+ /// The package CName: one key of Identification
+ ///
+ public String packageName;
+
+ ///
+ /// The package Guid: one key of Identification
+ ///
+ public String packageGuid;
+
+ ///
+ /// Module's Arch: one key of Identification
+ ///
+ public String arch;
+
+ ///
+ /// Module's version: one key of Identification
+ ///
+ public String version;
+
+ ///
+ /// Module's type
+ ///
+ public String moduleType;
+
+ /**
+ Constructor function for UsageIdentification class.
+
+ @param moduleName The key of module's name
+ @param moduleGuid The key of module's GUID string
+ @param packageName The key of package's name
+ @param packageGuid The key of package's Guid
+ @param arch The architecture string
+ @param version The version String
+ @param moduleType The module type
+ **/
+ public UsageIdentification (String moduleName,
+ String moduleGuid,
+ String packageName,
+ String packageGuid,
+ String arch,
+ String version,
+ String moduleType) {
+ this.moduleName = moduleName;
+ this.moduleGuid = moduleGuid;
+ this.packageName = packageName;
+ this.packageGuid = packageGuid;
+ this.arch = arch;
+ this.version = version;
+ this.moduleType = moduleType;
+ }
+
+ /**
+ Generate the string for UsageIdentification
+
+ @return the string value for UsageIdentification
+ **/
+ public String toString() {
+ //
+ // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
+ // <ModuleSA> section, So currently no expect all paramter must be valid.
+ // BUGBUG: Because currently we can not get version from MSA, So ignore verison.
+ //
+ return(moduleName + "_" +
+ ((moduleGuid != null) ? moduleGuid.toLowerCase() : "NullModuleGuid") + "_" +
+ ((packageName != null) ? packageName : "NullPackageName") + "_" +
+ ((packageGuid != null) ? packageGuid.toLowerCase() : "NullPackageGuid") + "_" +
+ ((arch != null) ? arch : "NullArch") + "_" +
+ "NullVersion");
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java
new file mode 100644
index 0000000000..2484453149
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java
@@ -0,0 +1,512 @@
+/** @file
+ UsageInstance class.
+
+ This class indicate an usage instance for a PCD token. This instance maybe a module
+ or platform setting. When a module produce or cosume a PCD token, then this module
+ is an usage instance for this PCD token.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.entity;
+
+import org.tianocore.pcd.entity.CommonDefinition;
+import org.tianocore.pcd.entity.UsageIdentification;
+
+/**
+ This class indicate an usage instance for a PCD token. This instance maybe a module
+ or platform setting. When a module produce or cosume a PCD token, then this module
+ is an usage instance for this PCD token.
+**/
+public class UsageInstance {
+ ///
+ /// This parent that this usage instance belongs to.
+ ///
+ public Token parentToken;
+
+ ///
+ /// ModuleIdentification for Usage Instance
+ ///
+ public UsageIdentification usageId;
+
+ ///
+ /// Arch also is a key for a UsageInstance
+ ///
+ public String arch;
+
+ ///
+ /// The PCD type defined for module
+ ///
+ public Token.PCD_TYPE modulePcdType;
+
+ ///
+ /// The value of the PCD in this usage instance.
+ ///
+ public String datum;
+
+ ///
+ /// The maxDatumSize could be different for same PCD in different module
+ /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
+ /// type.
+ ///
+ public int maxDatumSize;
+
+ ///
+ /// Autogen string for header file.
+ ///
+ public String hAutogenStr;
+
+ ///
+ /// Auotgen string for C code file.
+ ///
+ public String cAutogenStr;
+
+ /**
+ Constructure function for UsageInstance
+
+ @param parentToken The token instance for this usgaInstance
+ @param usageId The identification for usage instance
+ @param modulePcdType The PCD type for this usage instance
+ @param value The value of this PCD in this usage instance
+ @param maxDatumSize The max datum size of this PCD in this usage
+ instance.
+ **/
+ public UsageInstance(Token parentToken,
+ UsageIdentification usageId,
+ Token.PCD_TYPE modulePcdType,
+ String value,
+ int maxDatumSize) {
+ this.parentToken = parentToken;
+ this.usageId = usageId;
+ this.modulePcdType = modulePcdType;
+ this.datum = value;
+ this.maxDatumSize = maxDatumSize;
+ }
+
+ /**
+ Get the primary key for usage instance array for every token.
+
+ @param usageId The identification of UsageInstance
+
+ @retval String The primary key for this usage instance
+ **/
+ public static String getPrimaryKey(UsageIdentification usageId) {
+ return usageId.toString();
+ }
+
+ /**
+ Get primary key string for this usage instance
+
+ @return String primary key string
+ **/
+ public String getPrimaryKey() {
+ return UsageInstance.getPrimaryKey(usageId);
+ }
+
+ /**
+ Judget whether current module is PEI driver
+
+ @return boolean whether current module is PEI driver
+ **/
+ public boolean isPeiPhaseComponent() {
+ int moduleType = CommonDefinition.getModuleType(usageId.moduleType);
+
+ if ((moduleType == CommonDefinition.ModuleTypePeiCore) ||
+ (moduleType == CommonDefinition.ModuleTypePeim)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ Judge whether current module is DXE driver.
+
+ @return boolean whether current module is DXE driver
+ **/
+ public boolean isDxePhaseComponent() {
+ int moduleType = CommonDefinition.getModuleType(usageId.moduleType);
+
+ if ((moduleType == CommonDefinition.ModuleTypeDxeDriver) ||
+ (moduleType == CommonDefinition.ModuleTypeDxeRuntimeDriver) ||
+ (moduleType == CommonDefinition.ModuleTypeDxeSalDriver) ||
+ (moduleType == CommonDefinition.ModuleTypeDxeSmmDriver) ||
+ (moduleType == CommonDefinition.ModuleTypeUefiDriver) ||
+ (moduleType == CommonDefinition.ModuleTypeUefiApplication)
+ ) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ Generate autogen string for header file and C code file.
+
+ @param isBuildUsedLibrary whether the autogen is for library.
+ **/
+ public void generateAutoGen(boolean isBuildUsedLibrary) {
+ String guidStringCName = null;
+ boolean isByteArray = false;
+ String printDatum = null;
+ String tokenNumberString = null;
+
+ hAutogenStr = "";
+ cAutogenStr = "";
+
+ if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {
+ //
+ // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen
+ //
+ tokenNumberString = Long.toString(parentToken.dynamicExTokenNumber, 16);
+ } else {
+ //
+ // For Others type PCD, use autogenerated token number to generate autogen
+ //
+ tokenNumberString = Long.toString(parentToken.tokenNumber, 16);
+ }
+
+ hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken.cName, tokenNumberString);
+
+ //
+ // Judge the value of this PCD is byte array type
+ //
+ if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {
+ if (datum.trim().charAt(0) == '{') {
+ isByteArray = true;
+ }
+ }
+
+ //
+ // "ULL" should be added to value's tail for UINT64 value
+ //
+ if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {
+ printDatum = this.datum + "ULL";
+ } else {
+ printDatum = this.datum;
+ }
+
+ switch (modulePcdType) {
+ case FEATURE_FLAG:
+ //
+ // Example autogen string for following generation:
+ // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";
+ //
+ hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) If is not allowed to set value for a FEATURE_FLAG PCD\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName);
+
+ if (!isBuildUsedLibrary) {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_VALUE_PcdSampleToken 0x1000"
+ //
+ hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
+ parentToken.cName,
+ printDatum);
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken = _PCD_VALUE_PcdSampleToken;"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
+ parentToken.cName,
+ parentToken.cName);
+ }
+ break;
+ case FIXED_AT_BUILD:
+ if (isByteArray) {
+ //
+ // Example autogen string for following generation:
+ // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "extern const UINT8 _gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
+ Token.getAutogendatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ }
+
+ //
+ // Example autogen string for following generation:
+ // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";
+ //
+ hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ if (!isBuildUsedLibrary) {
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ if (isByteArray) {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_VALUE_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken"
+ //
+ hAutogenStr += String.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",
+ parentToken.cName,
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = 'dfdf';"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n",
+ parentToken.cName,
+ printDatum);
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_VALUE_PcdSampleToken 0x222"
+ //
+ hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
+ parentToken.cName,
+ printDatum);
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
+ Token.getAutogendatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ }
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_VALUE_PcdSampleToken 0x222"
+ //
+ hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
+ parentToken.cName,
+ printDatum);
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
+ Token.getAutogendatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ }
+ }
+ break;
+ case PATCHABLE_IN_MODULE:
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ //
+ // Example autogen string for following generation:
+ // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken[];"
+ //
+ hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_BinaryPatch_PcdSampleToken"
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"
+ //
+ hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",
+ parentToken.cName,
+ parentToken.datumSize);
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+
+ "LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+
+ "(SizeOfBuffer), (Buffer))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName,
+ parentToken.cName);
+
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken;"
+ //
+ hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
+ Token.getAutogendatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_BinaryPatch_PcdSampleToken"
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) (_gPcd_BinaryPatch_PcdSampleToken = (Value))"
+ //
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ }
+
+ if (!isBuildUsedLibrary) {
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ printDatum = parentToken.getByteArrayForPointerDatum(printDatum);
+ }
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_VALUE_PcdSampleToken 0x111"
+ //
+ hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
+ parentToken.cName,
+ printDatum);
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[%d] = _PCD_VALUE_%s;\r\n",
+ parentToken.cName,
+ parentToken.datumSize,
+ parentToken.cName);
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
+ //
+ cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
+ Token.getAutogendatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ parentToken.cName);
+ }
+ }
+
+ break;
+ case DYNAMIC:
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGet%s(_PCD_TOKEN_PcdSampleToken)"
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"
+ //
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (Value))"
+ //
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ parentToken.cName);
+ }
+ break;
+ case DYNAMIC_EX:
+ guidStringCName = "_gPcd_TokenSpaceGuid_" +
+ parentToken.tokenSpaceName.toString().replaceAll("-", "_");
+
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken)"
+ //
+ hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ guidStringCName,
+ parentToken.cName);
+
+ if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"
+ //
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ guidStringCName,
+ parentToken.cName);
+ } else {
+ //
+ // Example autogen string for following generation:
+ // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (Value))"
+ //
+ hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",
+ Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
+ parentToken.cName,
+ Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
+ guidStringCName,
+ parentToken.cName);
+
+ }
+ break;
+ }
+ }
+
+ /**
+ Get the autogen string for header file.
+
+ @return The string of header file.
+ **/
+ public String getHAutogenStr() {
+ return hAutogenStr;
+ }
+
+ /**
+ Get the autogen string for C code file.
+
+ @return The string of C Code file.
+ **/
+ public String getCAutogenStr() {
+ return cAutogenStr;
+ }
+}
+
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java
new file mode 100644
index 0000000000..9cd4e63fef
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java
@@ -0,0 +1,33 @@
+/** @file
+ BuildActionException class.
+
+ BuildAction Exception deals with all build action exceptions.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.exception;
+
+import org.apache.tools.ant.BuildException;
+
+/**
+ BuildAction Exception deals with all build action exceptions.
+**/
+public class BuildActionException extends BuildException {
+ static final long serialVersionUID = -7034897190740066939L;
+ /**
+ Constructure function
+
+ @param reason exception message string.
+ **/
+ public BuildActionException(String reason) {
+ super(reason);
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java
new file mode 100644
index 0000000000..5316cba554
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java
@@ -0,0 +1,31 @@
+/** @file
+ EntityException class.
+
+ The class handle the exception throwed by entity class.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.exception;
+
+/**
+ The class handle the exception throwed by entity class.
+**/
+public class EntityException extends Exception {
+ static final long serialVersionUID = -8034897190740066939L;
+ /**
+ Constructure function
+
+ @param expStr exception message string.
+ **/
+ public EntityException(String expStr) {
+ super("[PCD Tool Internal Error]:" + expStr);
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/PlatformPcdPreprocessException.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/PlatformPcdPreprocessException.java
new file mode 100644
index 0000000000..69b50c8f2f
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/PlatformPcdPreprocessException.java
@@ -0,0 +1,36 @@
+/** @file
+ PlatformPcdPreprocessException class.
+
+ The class handle the exception throwed by PlatformPcdPreprocessAction class.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.exception;
+
+public class PlatformPcdPreprocessException extends Exception {
+ /**
+ serial version ID
+ **/
+ private static final long serialVersionUID = 2858398552845888282L;
+
+ /**
+ Constructure function
+
+ @param expStr exception message string.
+ **/
+ public PlatformPcdPreprocessException(String expStr) {
+ super("\r\n[PlatformPcdPreprocess Failure] #############################\r\n" + expStr);
+ }
+
+ public PlatformPcdPreprocessException() {
+ super();
+ }
+}
diff --git a/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/UIException.java b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/UIException.java
new file mode 100644
index 0000000000..377a8a4b1d
--- /dev/null
+++ b/Tools/Java/Source/PcdTools/org/tianocore/pcd/exception/UIException.java
@@ -0,0 +1,31 @@
+/** @file
+ UIException class.
+
+ The class handle the exception throwed by UI action class.
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+package org.tianocore.pcd.exception;
+
+/**
+ The class handle the exception throwed by UI action class.
+**/
+public class UIException extends Exception {
+ static final long serialVersionUID = -7034897190740066930L;
+ /**
+ Constructure function
+
+ @param reason exception message string.
+ **/
+ public UIException(String reason) {
+ super(reason);
+ }
+}