From: klu2 Date: Mon, 31 Jul 2006 18:55:26 +0000 (+0000) Subject: Because Pcd entity, exception and some action package are shared by Building tools... X-Git-Tag: edk2-stable201903~24712 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=d14ebb43742f411f2a013996b8e76bcab2420552;hp=58d8da3cf9641a8d37d652ecd7aa06cb07895a4e Because Pcd entity, exception and some action package are shared by Building tools and Wizard Tools, so I move them to Tools/Source folder and generated PcdTools.jar, git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1160 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Source/GenBuild/GenBuild.msa b/Tools/Source/GenBuild/GenBuild.msa index 0fe46bb6cb..717550432d 100644 --- a/Tools/Source/GenBuild/GenBuild.msa +++ b/Tools/Source/GenBuild/GenBuild.msa @@ -66,21 +66,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. org/tianocore/build/id/PlatformIdentification.java org/tianocore/build/ModuleBuildFileGenerator.java org/tianocore/build/OutputDirSetup.java - org/tianocore/build/pcd/action/ActionMessage.java - org/tianocore/build/pcd/action/BuildAction.java org/tianocore/build/pcd/action/CollectPCDAction.java org/tianocore/build/pcd/action/PCDAutoGenAction.java - org/tianocore/build/pcd/action/ShowPCDDatabaseAction.java - org/tianocore/build/pcd/action/UIAction.java - org/tianocore/build/pcd/entity/DynamicTokenValue.java - org/tianocore/build/pcd/entity/MemoryDatabaseManager.java - org/tianocore/build/pcd/entity/SkuInstance.java - org/tianocore/build/pcd/entity/Token.java - org/tianocore/build/pcd/entity/UsageInstance.java - org/tianocore/build/pcd/exception/BuildActionException.java - org/tianocore/build/pcd/exception/EntityException.java - org/tianocore/build/pcd/exception/UIException.java - org/tianocore/build/pcd/ui/PCDDatabaseFrame.java org/tianocore/build/toolchain/ConfigReader.java org/tianocore/build/toolchain/ToolChainAttribute.java org/tianocore/build/toolchain/ToolChainConfig.java diff --git a/Tools/Source/GenBuild/build.xml b/Tools/Source/GenBuild/build.xml index e40e756aad..b61e2519c3 100644 --- a/Tools/Source/GenBuild/build.xml +++ b/Tools/Source/GenBuild/build.xml @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java index 39d4d6f2d4..bd87b6e0f2 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java @@ -39,7 +39,7 @@ import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PlatformIdentification; -import org.tianocore.build.pcd.action.ActionMessage; +import org.tianocore.pcd.action.ActionMessage; import org.tianocore.build.pcd.action.CollectPCDAction; import org.tianocore.build.toolchain.ToolChainAttribute; import org.tianocore.build.toolchain.ToolChainElement; diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java index a769816720..b02af3df66 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -35,7 +35,7 @@ import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PackageIdentification; import org.tianocore.build.id.PlatformIdentification; -import org.tianocore.build.pcd.entity.MemoryDatabaseManager; +import org.tianocore.pcd.entity.MemoryDatabaseManager; import org.tianocore.build.toolchain.ToolChainAttribute; import org.tianocore.build.toolchain.ToolChainConfig; import org.tianocore.build.toolchain.ToolChainElement; diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/ActionMessage.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/ActionMessage.java deleted file mode 100644 index d993fab6ec..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/ActionMessage.java +++ /dev/null @@ -1,122 +0,0 @@ -/** @file - ActionMessage class. - - ActionMessage class take over all message for loging and waning. This class should - dispatch message into different class according to instance class type. - -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.build.pcd.action; - -import org.apache.tools.ant.Task; -import org.tianocore.build.pcd.action.BuildAction; - -/** ActionMessage class take over all message for loging and waning. This class - should dispatch message into different Action class according to instance - class type. -**/ -public class ActionMessage { - /// - /// Macro definition for NULL messge level. - /// In this meessage level, all message will be hidden. - /// - public final static int NULL_MESSAGE_LEVEL = 0; - /// - /// Macro definition for Log messge level. - /// In this message level, Only log information will be shown. - /// - public final static int LOG_MESSAGE_LEVEL = 1; - /// - /// Macro definition for Warning message level. - /// In this message level, log and waning message will be shown. - /// - public final static int WARNING_MESSAGE_LEVEL = 2; - /// - /// Macro definition for Debug mesage level. - /// In this message level, log, warning, debug message will be shown. - /// - public final static int DEBUG_MESSAGE_LEVEL = 3; - /// - /// Macor definition for MAX message level. - /// In this message level, all message will be shown. - /// - public final static int MAX_MESSAGE_LEVEL = 4; - /// - /// Current message level. It will control all message output for PCD tool. - /// - public static int messageLevel = NULL_MESSAGE_LEVEL; - - /** - Log() function provide common log information functionality for all - PCD tool includes all function - - This function will dispatch message to special class such as BuildAction - Class, Entity Class etc. - - @param thisClass The class object who want log information. - @param logStr The string contains log information. - **/ - public static void log(Object thisClass, String logStr) { - if(messageLevel < LOG_MESSAGE_LEVEL) { - return; - } - - if(thisClass instanceof Task) { - BuildAction.logMsg(thisClass, "$$LOG$$:" + logStr); - } else { - System.out.println("$$LOG$$:" + logStr); - } - } - - /** - Warning() function provide common warning information functionality for all - PCD tool. - - This function will dispatch message to special class such as BuildAction - Class, Entity Class etc. - - @param thisClass The class object who want warn information. - @param warningStr The string contains warning information. - **/ - public static void warning(Object thisClass, String warningStr) { - if(messageLevel < WARNING_MESSAGE_LEVEL) { - return; - } - - if(thisClass instanceof Task) { - BuildAction.warningMsg(thisClass, "**WARNING**:" + warningStr); - } else { - System.out.println("**WARNING**:" + warningStr); - } - } - - /** - Debug() function provide common Debug information functionality for all - PCD tool. - - This function will dispatch message to special class such as BuildAction - Class, Entity Class etc. - - @param thisClass The class object who want Debug information. - @param debugStr The string contains Debug information. - **/ - public static void debug(Object thisClass, String debugStr) { - if(messageLevel < DEBUG_MESSAGE_LEVEL) { - return; - } - - if(thisClass instanceof Task) { - BuildAction.logMsg(thisClass, "%%DEBUG%%:" + debugStr); - } else { - System.out.println("%%DEBUG%%:" + debugStr); - } - } -} diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/BuildAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/BuildAction.java deleted file mode 100644 index 3614547e8d..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/BuildAction.java +++ /dev/null @@ -1,105 +0,0 @@ -/** @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.build.pcd.action; - -import org.apache.tools.ant.Task; -import org.apache.tools.ant.Project; -import org.tianocore.build.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. -**/ -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. - **/ - abstract void checkParameter() throws BuildActionException; - - /** - performAction is to execute the detail action. - - This function will be overrided by child class. - **/ - abstract void performAction() throws BuildActionException; - - /** - setMessageLevel function set current message for task instance object. - - The message should be restored when this action exit. - - @param messageLevel The message level for this action. - **/ - public void setMessageLevel(int messageLevel) { - originalMessageLevel = ActionMessage.messageLevel; - ActionMessage.messageLevel = messageLevel; - } - - /** - logMsg function provide common log information functionality for all - PCD tool extends from ANT task class. - - This function will use the log function in Ant task class. - - @param action The class object who want log information. - @param logStr The string contains log information. - **/ - public static void logMsg(Object action, String logStr) { - ((Task) action).log(logStr, Project.MSG_INFO); - } - - /** - warningMsg function provide common warning information functionality for all - PCD tool. - - This function will dispatch message to special class such as BuildAction - Class, Entity Class etc. - - @param action The class object who want warn information. - @param warningStr The string contains warning information. - **/ - public static void warningMsg(Object action, String warningStr) { - ((Task) action).log(warningStr, Project.MSG_WARN); - } - - /** - 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(); - - // - // Restore orignal message level when exist the action. - // - ActionMessage.messageLevel = originalMessageLevel; - } -} diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index 8242a4c87c..e0a3eb6fd3 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -41,17 +41,19 @@ import org.tianocore.ModuleSADocument; import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition; import org.tianocore.PlatformSurfaceAreaDocument; -import org.tianocore.build.autogen.CommonDefinition; import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.global.GlobalData; import org.tianocore.build.id.FpdModuleIdentification; -import org.tianocore.build.pcd.action.ActionMessage; -import org.tianocore.build.pcd.entity.DynamicTokenValue; -import org.tianocore.build.pcd.entity.MemoryDatabaseManager; -import org.tianocore.build.pcd.entity.SkuInstance; -import org.tianocore.build.pcd.entity.Token; -import org.tianocore.build.pcd.entity.UsageInstance; -import org.tianocore.build.pcd.exception.EntityException; +import org.tianocore.build.id.ModuleIdentification; +import org.tianocore.pcd.action.ActionMessage; +import org.tianocore.pcd.entity.CommonDefinition; +import org.tianocore.pcd.entity.DynamicTokenValue; +import org.tianocore.pcd.entity.MemoryDatabaseManager; +import org.tianocore.pcd.entity.SkuInstance; +import org.tianocore.pcd.entity.Token; +import org.tianocore.pcd.entity.UsageIdentification; +import org.tianocore.pcd.entity.UsageInstance; +import org.tianocore.pcd.exception.EntityException; /** CStructTypeDeclaration @@ -1893,6 +1895,8 @@ public class CollectPCDAction { String datum = null; int maxDatumSize = 0; String[] tokenSpaceStrRet = null; + UsageIdentification usageId = null; + ModuleIdentification moduleId = null; // // ---------------------------------------------- @@ -2112,10 +2116,17 @@ public class CollectPCDAction { // 2.1.4), Create an usage instance for this token. // ------------------------------------------------ // + moduleId = modules.get(index).getModuleId().getModule(); + usageId = new UsageIdentification (moduleId.getName(), + moduleId.getGuid(), + moduleId.getPackage().getName(), + moduleId.getPackage().getGuid(), + modules.get(index).getModuleId().getArch(), + moduleId.getVersion(), + moduleId.getModuleType()); usageInstance = new UsageInstance(token, - modules.get(index).getModuleId().getModule(), + usageId, pcdType, - modules.get(index).getModuleId().getArch(), datum, maxDatumSize); token.addUsageInstance(usageInstance); diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java index 2707c5d1a8..40d2b32a9b 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java @@ -29,11 +29,14 @@ import org.apache.xmlbeans.XmlObject; import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.ModuleIdentification; -import org.tianocore.build.pcd.entity.MemoryDatabaseManager; -import org.tianocore.build.pcd.entity.Token; -import org.tianocore.build.pcd.entity.UsageInstance; -import org.tianocore.build.pcd.exception.BuildActionException; -import org.tianocore.build.pcd.exception.EntityException; +import org.tianocore.pcd.entity.MemoryDatabaseManager; +import org.tianocore.pcd.entity.Token; +import org.tianocore.pcd.entity.UsageInstance; +import org.tianocore.pcd.exception.BuildActionException; +import org.tianocore.pcd.exception.EntityException; +import org.tianocore.pcd.entity.UsageIdentification; +import org.tianocore.pcd.action.BuildAction; +import org.tianocore.pcd.action.ActionMessage; /** This class is to manage how to generate the PCD information into Autogen.c and Autogen.h. @@ -44,9 +47,9 @@ public class PCDAutoGenAction extends BuildAction { /// private MemoryDatabaseManager dbManager; /// - /// The identification for a module. + /// The identification for a UsageInstance. /// - private ModuleIdentification moduleId; + private UsageIdentification usageId; /// /// The arch of current module /// @@ -72,17 +75,8 @@ public class PCDAutoGenAction extends BuildAction { @param moduleName the module name parameter. **/ - public void setModuleId(ModuleIdentification moduleId) { - this.moduleId = moduleId; - } - - /** - set Arch parameter. - - @param arch - **/ - public void setArch(String arch) { - this.arch = arch; + public void setUsageId(UsageIdentification usageId) { + this.usageId = usageId; } /** @@ -136,12 +130,18 @@ public class PCDAutoGenAction extends BuildAction { String arch, boolean isBuildUsedLibrary, String[] pcdNameArrayInMsa) { + UsageIdentification usageId = new UsageIdentification(moduleId.getName(), + moduleId.getGuid(), + moduleId.getPackage().getName(), + moduleId.getPackage().getGuid(), + arch, + moduleId.getVersion(), + moduleId.getModuleType()); dbManager = null; hAutoGenString = ""; cAutoGenString = ""; - setModuleId(moduleId); - setArch(arch); + setUsageId(usageId); setIsBuildUsedLibrary(isBuildUsedLibrary); setPcdNameArrayInMsa(pcdNameArrayInMsa); } @@ -151,7 +151,7 @@ public class PCDAutoGenAction extends BuildAction { @throws BuildActionException Bad parameter. **/ - void checkParameter() throws BuildActionException { + public void checkParameter() throws BuildActionException { } @@ -165,7 +165,7 @@ public class PCDAutoGenAction extends BuildAction { @throws BuildActionException Failed to execute this aciton class. **/ - void performAction() throws BuildActionException { + public void performAction() throws BuildActionException { ActionMessage.debug(this, "Starting PCDAutoGenAction to generate autogen.h and autogen.c!..."); // @@ -200,13 +200,13 @@ public class PCDAutoGenAction extends BuildAction { String[] guidStringArray = null; String guidStringCName = null; String guidString = null; - String moduleName = moduleId.getName(); + String moduleName = usageId.moduleName; UsageInstance usageInstance = null; boolean found = false; usageInstanceArray = null; if (!isBuildUsedLibrary) { - usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleId, arch); + usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(usageId); dbManager.UsageInstanceContext = usageInstanceArray; dbManager.CurrentModuleName = moduleName; } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) { @@ -216,7 +216,7 @@ public class PCDAutoGenAction extends BuildAction { // these library should be used to autogen. // if (usageContext == null) { - usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleId, arch); + usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(usageId); } else { usageInstanceArray = new ArrayList(); diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/DynamicTokenValue.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/DynamicTokenValue.java deleted file mode 100644 index 533bd51920..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/DynamicTokenValue.java +++ /dev/null @@ -1,162 +0,0 @@ -/** @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.build.pcd.entity; - -import java.util.List; -import java.util.UUID; - -import org.tianocore.build.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. - /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed - /// in coding review. - public enum VALUE_TYPE {HII_TYPE, VPD_TYPE, DEFAULT_TYPE} - - public VALUE_TYPE type; - - /// - /// --------------------------------------------------------------------- - /// Following member is for HII case. - /// --------------------------------------------------------------------- - /// - - /// - /// 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. - /// BUGBUG: Consider 64 bit integer by using java.math.BigInteger. - /// - public String vpdOffset; - - /// - /// Following member is for default case. - /// - public String value; - - public DynamicTokenValue() { - this.type = VALUE_TYPE.DEFAULT_TYPE; - this.variableName = null; - this.variableGuid = null; - this.variableOffset = null; - this.hiiDefaultValue = null; - - this.vpdOffset = null; - - this.value = null; - } - - /** - Set the HII case data. - - @param variableName - @param variableGuid - @param variableOffset - @param hiiDefaultValue - */ - 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 string like L"xxx" for a variable Name. - - BUGBUG: In fact, it is not correctly, variable name should be - treated as unicode UINT16 array. - - @return String - */ - public String getStringOfVariableName() - throws EntityException { - String str; - int index, num; - char ch; - - str = ""; - for (index = 0; index < variableName.size(); index ++) { - num = Integer.decode(variableName.get(index).toString()); - if ((num > 127 ) || (num < 0)) { - throw new EntityException(String.format("variable name contains >0x80 character, now is not support!")); - } - str += (char)num; - } - - return str; - } - - /** - Set Vpd case data. - - @param vpdOffset - */ - 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/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java deleted file mode 100644 index 636be3adaf..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java +++ /dev/null @@ -1,308 +0,0 @@ -/** @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.build.pcd.entity; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.tianocore.build.id.ModuleIdentification; -import org.tianocore.build.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 memoryDatabase = null; - - /// - /// Before build a module, the used libary will be build firstly, the PCD of these - /// libarry is inheritted by the module, so stored module's PCD information as PCD - /// context of building libary. - /// - public static List 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(); - } - } - - /** - 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; - - if (memoryDatabase == null) { - return null; - } - - dataArray = memoryDatabase.entrySet().toArray(); - tokenArray = new Token[memoryDatabase.size()]; - for (index = 0; index < memoryDatabase.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 - */ - private ArrayList getDynamicRecordArray() { - Token[] tokenArray = getRecordArray(); - int index = 0; - ArrayList al = new ArrayList(); - - 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 pei, ArrayList dxe) - throws EntityException { - int usageInstanceIndex = 0; - int index = 0; - ArrayList tokenArrayList = getDynamicRecordArray(); - Object[] usageInstanceArray = null; - UsageInstance usageInstance = null; - - //pei = new ArrayList(); - //dxe = new ArrayList(); - - for (index = 0; index < tokenArrayList.size(); index++) { - boolean found = false; - Token token = (Token) tokenArrayList.get(index); - if (token.consumers != null) { - usageInstanceArray = token.consumers.entrySet().toArray(); - for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); 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(); - for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); 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 module that is not in PEI phase nor in DXE phase."); - } - } - } - } - - return; - } - - /** - Get all PCD record for a module according to module's name, module's GUID, - package name, package GUID, arch, version information. - - @param moduleId the id of module. - @param arch the architecture - - @return all usage instance for this module in memory database. - **/ - public List getUsageInstanceArrayByModuleName(ModuleIdentification moduleId, - String arch) { - - String primaryKey = UsageInstance.getPrimaryKey(moduleId, arch); - - return getUsageInstanceArrayByKeyString(primaryKey); - } - - /** - Get all PCD token for a usage instance according to primary key. - - @param primaryKey the primary key of usage instance. - - @return List - */ - public List getUsageInstanceArrayByKeyString(String primaryKey) { - Token[] tokenArray = null; - int recordIndex = 0; - UsageInstance usageInstance = null; - List returnArray = new ArrayList(); - - 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; - } - - /** - Get all modules name who contains PCD information - - @return Array for module name - **/ - public List getAllModuleArray() - { - int indexToken = 0; - int usageIndex = 0; - int moduleIndex = 0; - Token[] tokenArray = null; - Object[] usageInstanceArray = null; - List moduleNames = new ArrayList(); - UsageInstance usageInstance = null; - boolean bFound = false; - - tokenArray = getRecordArray(); - // - // Find all consumer usage instance for retrieving module's name - // - for (indexToken = 0; indexToken < getDBSize(); indexToken ++) { - usageInstanceArray = tokenArray[indexToken].consumers.entrySet().toArray(); - for (usageIndex = 0; usageIndex < tokenArray[indexToken].consumers.size(); usageIndex ++) { - usageInstance = (UsageInstance)((Map.Entry)usageInstanceArray[usageIndex]).getValue(); - bFound = false; - for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) { - if (moduleNames.get(moduleIndex).equalsIgnoreCase(usageInstance.getPrimaryKey())) { - bFound = true; - break; - } - } - if (!bFound) { - moduleNames.add(usageInstance.getPrimaryKey()); - } - } - } - return moduleNames; - } -} diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/SkuInstance.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/SkuInstance.java deleted file mode 100644 index 6df155157c..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/SkuInstance.java +++ /dev/null @@ -1,45 +0,0 @@ -/** @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.build.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; - } - - public SkuInstance() { - this.id = 0; - this.value = new DynamicTokenValue(); - } -} diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java deleted file mode 100644 index 20b4f4e01a..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java +++ /dev/null @@ -1,854 +0,0 @@ -/** @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.build.pcd.entity; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.tianocore.build.id.ModuleIdentification; -import org.tianocore.build.pcd.exception.EntityException; - -/** This class is to descript a PCD token object. The information of a token mainly - comes from MSA, SPD and setting produced by platform developer. -**/ -public class Token { - /// - /// Enumeration macro defintion for PCD type. - /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed - /// in coding review. - public 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 enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN} - - /// - /// Enumeration macor defintion for usage of PCD - /// - public 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 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 skuData; - - /// - /// consumers array record all module private information who consume this PCD token. - /// - public Map 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) { - UUID nullUUID = new UUID(0, 0); - - this.cName = cName; - this.tokenSpaceName = tokenSpaceName; - this.tokenNumber = 0; - this.datumType = DATUM_TYPE.UNKNOWN; - this.datumSize = -1; - this.skuData = new ArrayList(); - - this.consumers = new HashMap(); - this.supportedPcdType = new ArrayList(); - } - - /** - updateSupportPcdType - - SupportPcdType should be gotten from SPD file actually, but now it just - record all PCD type for this token in FPD file. - - @param pcdType new PCD type found in FPD file for this token. - **/ - public void updateSupportPcdType(PCD_TYPE pcdType) { - for (int index = 0; index < this.supportedPcdType.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; - } - - public boolean isDynamicEx() { - for (int i = 0; i < supportedPcdType.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('-', '_'); - } - } - - /** - 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) throws EntityException { - String exceptionStr; - - if (isUsageInstanceExist(usageInstance.moduleId, usageInstance.arch)) { - exceptionStr = String.format("[PCD Collection Tool Exception] PCD %s for module %s has already exist in database, Please check all PCD build entries "+ - "in modules %s in to make sure no duplicated definitions in FPD file!", - usageInstance.parentToken.cName, - usageInstance.moduleId.getName(), - usageInstance.moduleId.getName()); - throw new EntityException(exceptionStr); - } - - // - // 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 moduleId The module identification for usage instance - @param arch the architecture string - - @return boolean whether exist an usage instance for this token. - */ - public boolean isUsageInstanceExist(ModuleIdentification moduleId, - String arch) { - String keyStr = UsageInstance.getPrimaryKey(moduleId, arch); - - 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) { - switch (datumType) { - case UINT8: - return "UINT8"; - case UINT16: - return "UINT16"; - case UINT32: - return "UINT32"; - case UINT64: - return "UINT64"; - case POINTER: - return "POINTER"; - case BOOLEAN: - return "BOOLEAN"; - } - return "UNKNOWN"; - } - - /** - 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) { - switch (pcdType) { - case FEATURE_FLAG: - return "FEATURE_FLAG"; - case FIXED_AT_BUILD: - return "FIXED_AT_BUILD"; - case PATCHABLE_IN_MODULE: - return "PATCHABLE_IN_MODULE"; - case DYNAMIC: - return "DYNAMIC"; - case DYNAMIC_EX: - return "DYNAMIC_EX"; - } - return "UNKNOWN"; - } - - /** - 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) { - switch (usage) { - case ALWAYS_PRODUCED: - return "ALWAYS_PRODUCED"; - case ALWAYS_CONSUMED: - return "ALWAYS_CONSUMED"; - case SOMETIMES_PRODUCED: - return "SOMETIMES_PRODUCED"; - case SOMETIMES_CONSUMED: - return "SOMETIMES_CONSUMED"; - } - return "UNKNOWN"; - } - - /** - 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() { - DynamicTokenValue dynamicData; - int index; - - for (index = 0; index < this.skuData.size(); index ++) { - if (skuData.get(index).id == 0) { - return skuData.get(index).value; - } - } - - return null; - } - - /** - 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 - **/ - private void getCurrentSizeFromDefaultValue (String str, ArrayList 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 getPointerTypeSize () { - ArrayList al = new ArrayList(); - - // - // 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 - */ - public String getDynamicDefaultValue() { - DynamicTokenValue dynamicData = getDefaultSku(); - if (hasDefaultValue()) { - switch (dynamicData.type) { - case DEFAULT_TYPE: - return dynamicData.value; - } - } - - return null; - } - - // - // BugBug: We need change this algorithm accordingly when schema is updated - // to support no default value. - // - public boolean hasDefaultValue () { - int value = 0; - boolean isInteger = true; - DynamicTokenValue dynamicValue = null; - - if (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 - - @return boolean - */ - 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("\"\"") || - judgedValue.equalsIgnoreCase("L\"\"") || - (judgedValue.length() == 0) || - judgedValue.equalsIgnoreCase("{0}")) { - return true; - } - } - return false; - } - - /** - Is the string value in Unicode - - @return boolean - **/ - 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 - **/ - 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 - */ - 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; - } - - 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; - } - - public boolean isByteStreamType () { - String str = getDynamicDefaultValue(); - - if (str == null) { - return false; - } - - if (datumType == Token.DATUM_TYPE.POINTER && - str.startsWith("{") && - str.endsWith("}")) { - return true; - } - - return false; - - } - - public String getStringTypeString () { - return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1); - } -} - - - - diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java deleted file mode 100644 index 2f7d5ae523..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java +++ /dev/null @@ -1,409 +0,0 @@ -/** @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.build.pcd.entity; - - -import java.util.UUID; - -import org.tianocore.ModuleTypeDef; -import org.tianocore.build.autogen.CommonDefinition; -import org.tianocore.build.id.ModuleIdentification; -import org.tianocore.build.pcd.exception.EntityException; - -/** - 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 ModuleIdentification moduleId; - - /// - /// 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 id 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, - ModuleIdentification moduleId, - Token.PCD_TYPE modulePcdType, - String arch, - String value, - int maxDatumSize) { - this.parentToken = parentToken; - this.moduleId = moduleId; - this.modulePcdType = modulePcdType; - this.arch = arch; - this.datum = value; - this.maxDatumSize = maxDatumSize; - } - - /** - Get the primary key for usage instance array for every token. - - @param moduleId The module Identification for generating primary key - @param arch Arch string - - @retval String The primary key for this usage instance - **/ - public static String getPrimaryKey(ModuleIdentification moduleId, - String arch) { - String moduleName = moduleId.getName(); - String moduleGuid = moduleId.getGuid(); - String packageName = moduleId.getPackage().getName(); - String packageGuid = moduleId.getPackage().getGuid(); - String version = moduleId.getVersion(); - - // - // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in - // 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"); - } - - /** - Get primary key string for this usage instance - - @return String primary key string - **/ - public String getPrimaryKey() { - return UsageInstance.getPrimaryKey(moduleId, arch); - } - - /** - Judget whether current module is PEI driver - - @return boolean whether current module is PEI driver - **/ - public boolean isPeiPhaseComponent() { - int moduleType = CommonDefinition.getModuleType(moduleId.getModuleType()); - - 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(moduleId.getModuleType()); - - 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: - hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", - parentToken.cName); - hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", - parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - 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", - parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName); - - if (!isBuildUsedLibrary) { - hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", - parentToken.cName, - printDatum); - 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) { - hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n", - parentToken.cName); - hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", - Token.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - } else { - hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n", - Token.getAutogendatumTypeString(parentToken.datumType), - parentToken.cName); - hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", - Token.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - } - - 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", - parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName); - if (!isBuildUsedLibrary) { - if (parentToken.datumType == Token.DATUM_TYPE.POINTER) { - if (isByteArray) { - hAutogenStr += String.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", - parentToken.cName, - parentToken.cName); - cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n", - parentToken.cName, - printDatum); - } else { - hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", - parentToken.cName, - printDatum); - 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 { - hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", - parentToken.cName, - printDatum); - 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 (isByteArray) { - hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n", - parentToken.cName); - hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n", - Token.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - } else { - hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n", - Token.getAutogendatumTypeString(parentToken.datumType), - parentToken.cName); - hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n", - Token.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - } - - // - // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro - // - if (parentToken.datumType == Token.DATUM_TYPE.POINTER) { - hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n", - Token.GetAutogenDefinedatumTypeString(parentToken.datumType), - parentToken.cName, - parentToken.cName); - } else { - 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) { - hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", - parentToken.cName, - printDatum); - if (isByteArray) { - cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n", - parentToken.cName, - parentToken.cName); - } else { - 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: - 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) { - 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 { - 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("-", "_"); - - 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) { - 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 { - 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/Source/GenBuild/org/tianocore/build/pcd/exception/BuildActionException.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/BuildActionException.java deleted file mode 100644 index 357ebf017a..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/BuildActionException.java +++ /dev/null @@ -1,33 +0,0 @@ -/** @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.build.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/Source/GenBuild/org/tianocore/build/pcd/exception/EntityException.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/EntityException.java deleted file mode 100644 index 070c2db5d7..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/EntityException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** @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.build.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 EntityException]:" + expStr); - } -} diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/UIException.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/UIException.java deleted file mode 100644 index 96575a1450..0000000000 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/exception/UIException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** @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.build.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); - } -} diff --git a/Tools/Source/PcdTools/PcdTools.msa b/Tools/Source/PcdTools/PcdTools.msa new file mode 100644 index 0000000000..3b47a92cbd --- /dev/null +++ b/Tools/Source/PcdTools/PcdTools.msa @@ -0,0 +1,45 @@ + + + + PcdTools + TOOL + 95506773-88f3-475a-91a1-14ce0c847353 + 2.0 + This is the EFI/Tiano PCD Tool Resources Module + + This Module provdes the entity, action and exception package for PCD + tools, This package will be shared for building tools or wizard tools. + + Copyright 2005-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. + + FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052 + + + IA32 X64 IPF EBC + false + NULL + + + build.xml + org/tianocore/pcd/action/ActionMessage.java + org/tianocore/pcd/action/BuildAction.java + org/tianocore/pcd/entity/DynamicTokenValue.java + org/tianocore/pcd/entity/MemoryDatabaseManager.java + org/tianocore/pcd/entity/SkuInstance.java + org/tianocore/pcd/entity/Token.java + org/tianocore/pcd/entity/UsageInstance.java + org/tianocore/pcd/exception/BuildActionException.java + org/tianocore/pcd/exception/EntityException.java + org/tianocore/pcd/exception/UIException.java + + diff --git a/Tools/Source/PcdTools/build.xml b/Tools/Source/PcdTools/build.xml new file mode 100644 index 0000000000..c47032e9f5 --- /dev/null +++ b/Tools/Source/PcdTools/build.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/action/ActionMessage.java b/Tools/Source/PcdTools/org/tianocore/pcd/action/ActionMessage.java new file mode 100644 index 0000000000..2b589e571a --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/action/ActionMessage.java @@ -0,0 +1,121 @@ +/** @file + ActionMessage class. + + ActionMessage class take over all message for loging and waning. This class should + dispatch message into different class according to instance class type. + +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; + +/** ActionMessage class take over all message for loging and waning. This class + should dispatch message into different Action class according to instance + class type. +**/ +public class ActionMessage { + /// + /// Macro definition for NULL messge level. + /// In this meessage level, all message will be hidden. + /// + public final static int NULL_MESSAGE_LEVEL = 0; + /// + /// Macro definition for Log messge level. + /// In this message level, Only log information will be shown. + /// + public final static int LOG_MESSAGE_LEVEL = 1; + /// + /// Macro definition for Warning message level. + /// In this message level, log and waning message will be shown. + /// + public final static int WARNING_MESSAGE_LEVEL = 2; + /// + /// Macro definition for Debug mesage level. + /// In this message level, log, warning, debug message will be shown. + /// + public final static int DEBUG_MESSAGE_LEVEL = 3; + /// + /// Macor definition for MAX message level. + /// In this message level, all message will be shown. + /// + public final static int MAX_MESSAGE_LEVEL = 4; + /// + /// Current message level. It will control all message output for PCD tool. + /// + public static int messageLevel = NULL_MESSAGE_LEVEL; + + /** + Log() function provide common log information functionality for all + PCD tool includes all function + + This function will dispatch message to special class such as BuildAction + Class, Entity Class etc. + + @param thisClass The class object who want log information. + @param logStr The string contains log information. + **/ + public static void log(Object thisClass, String logStr) { + if(messageLevel < LOG_MESSAGE_LEVEL) { + return; + } + + if(thisClass instanceof Task) { + BuildAction.logMsg(thisClass, "$$LOG$$:" + logStr); + } else { + System.out.println("$$LOG$$:" + logStr); + } + } + + /** + Warning() function provide common warning information functionality for all + PCD tool. + + This function will dispatch message to special class such as BuildAction + Class, Entity Class etc. + + @param thisClass The class object who want warn information. + @param warningStr The string contains warning information. + **/ + public static void warning(Object thisClass, String warningStr) { + if(messageLevel < WARNING_MESSAGE_LEVEL) { + return; + } + + if(thisClass instanceof Task) { + BuildAction.warningMsg(thisClass, "**WARNING**:" + warningStr); + } else { + System.out.println("**WARNING**:" + warningStr); + } + } + + /** + Debug() function provide common Debug information functionality for all + PCD tool. + + This function will dispatch message to special class such as BuildAction + Class, Entity Class etc. + + @param thisClass The class object who want Debug information. + @param debugStr The string contains Debug information. + **/ + public static void debug(Object thisClass, String debugStr) { + if(messageLevel < DEBUG_MESSAGE_LEVEL) { + return; + } + + if(thisClass instanceof Task) { + BuildAction.logMsg(thisClass, "%%DEBUG%%:" + debugStr); + } else { + System.out.println("%%DEBUG%%:" + debugStr); + } + } +} diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java b/Tools/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java new file mode 100644 index 0000000000..98068d97b9 --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java @@ -0,0 +1,105 @@ +/** @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; + + /** + setMessageLevel function set current message for task instance object. + + The message should be restored when this action exit. + + @param messageLevel The message level for this action. + **/ + public void setMessageLevel(int messageLevel) { + originalMessageLevel = ActionMessage.messageLevel; + ActionMessage.messageLevel = messageLevel; + } + + /** + logMsg function provide common log information functionality for all + PCD tool extends from ANT task class. + + This function will use the log function in Ant task class. + + @param action The class object who want log information. + @param logStr The string contains log information. + **/ + public static void logMsg(Object action, String logStr) { + ((Task) action).log(logStr, Project.MSG_INFO); + } + + /** + warningMsg function provide common warning information functionality for all + PCD tool. + + This function will dispatch message to special class such as BuildAction + Class, Entity Class etc. + + @param action The class object who want warn information. + @param warningStr The string contains warning information. + **/ + public static void warningMsg(Object action, String warningStr) { + ((Task) action).log(warningStr, Project.MSG_WARN); + } + + /** + 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(); + + // + // Restore orignal message level when exist the action. + // + ActionMessage.messageLevel = originalMessageLevel; + } +} diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java new file mode 100644 index 0000000000..c16bb04f10 --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java @@ -0,0 +1,354 @@ +/** @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.HashSet; +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 \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 don't conform to 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 strList = new LinkedHashSet(); + 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; + } + +} \ No newline at end of file diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/DynamicTokenValue.java new file mode 100644 index 0000000000..e8fb8e837d --- /dev/null +++ b/Tools/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. + /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed + /// in coding review. + public enum VALUE_TYPE {HII_TYPE, VPD_TYPE, DEFAULT_TYPE} + + public VALUE_TYPE type; + + /// + /// --------------------------------------------------------------------- + /// Following member is for HII case. + /// --------------------------------------------------------------------- + /// + + /// + /// 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. + /// BUGBUG: Consider 64 bit integer by using java.math.BigInteger. + /// + public String vpdOffset; + + /// + /// Following member is for default case. + /// + public String value; + + public DynamicTokenValue() { + this.type = VALUE_TYPE.DEFAULT_TYPE; + this.variableName = null; + this.variableGuid = null; + this.variableOffset = null; + this.hiiDefaultValue = null; + + this.vpdOffset = null; + + this.value = null; + } + + /** + Set the HII case data. + + @param variableName + @param variableGuid + @param variableOffset + @param hiiDefaultValue + */ + 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 string like L"xxx" for a variable Name. + + BUGBUG: In fact, it is not correctly, variable name should be + treated as unicode UINT16 array. + + @return String + */ + public String getStringOfVariableName() + throws EntityException { + String str; + int index, num; + char ch; + + str = ""; + for (index = 0; index < variableName.size(); index ++) { + num = Integer.decode(variableName.get(index).toString()); + if ((num > 127 ) || (num < 0)) { + throw new EntityException(String.format("variable name contains >0x80 character, now is not support!")); + } + str += (char)num; + } + + return str; + } + + /** + Set Vpd case data. + + @param vpdOffset + */ + 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/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java new file mode 100644 index 0000000000..7a87469967 --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/MemoryDatabaseManager.java @@ -0,0 +1,306 @@ +/** @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 java.util.UUID; + +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 memoryDatabase = null; + + /// + /// Before build a module, the used libary will be build firstly, the PCD of these + /// libarry is inheritted by the module, so stored module's PCD information as PCD + /// context of building libary. + /// + public static List 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(); + } + } + + /** + 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; + + if (memoryDatabase == null) { + return null; + } + + dataArray = memoryDatabase.entrySet().toArray(); + tokenArray = new Token[memoryDatabase.size()]; + for (index = 0; index < memoryDatabase.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 + */ + private ArrayList getDynamicRecordArray() { + Token[] tokenArray = getRecordArray(); + int index = 0; + ArrayList al = new ArrayList(); + + 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 pei, ArrayList dxe) + throws EntityException { + int usageInstanceIndex = 0; + int index = 0; + ArrayList tokenArrayList = getDynamicRecordArray(); + Object[] usageInstanceArray = null; + UsageInstance usageInstance = null; + + //pei = new ArrayList(); + //dxe = new ArrayList(); + + for (index = 0; index < tokenArrayList.size(); index++) { + boolean found = false; + Token token = (Token) tokenArrayList.get(index); + if (token.consumers != null) { + usageInstanceArray = token.consumers.entrySet().toArray(); + for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); 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(); + for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); 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 module that is not in PEI phase nor in DXE phase."); + } + } + } + } + + return; + } + + /** + Get all PCD record for a module according to module's name, module's GUID, + package name, package GUID, arch, version information. + + @param usageId the id of UsageInstance. + + @return all usage instance for this module in memory database. + **/ + public List getUsageInstanceArrayByModuleName(UsageIdentification usageId) { + + String primaryKey = UsageInstance.getPrimaryKey(usageId); + + return getUsageInstanceArrayByKeyString(primaryKey); + } + + /** + Get all PCD token for a usage instance according to primary key. + + @param primaryKey the primary key of usage instance. + + @return List + */ + public List getUsageInstanceArrayByKeyString(String primaryKey) { + Token[] tokenArray = null; + int recordIndex = 0; + UsageInstance usageInstance = null; + List returnArray = new ArrayList(); + + 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; + } + + /** + Get all modules name who contains PCD information + + @return Array for module name + **/ + public List getAllModuleArray() + { + int indexToken = 0; + int usageIndex = 0; + int moduleIndex = 0; + Token[] tokenArray = null; + Object[] usageInstanceArray = null; + List moduleNames = new ArrayList(); + UsageInstance usageInstance = null; + boolean bFound = false; + + tokenArray = getRecordArray(); + // + // Find all consumer usage instance for retrieving module's name + // + for (indexToken = 0; indexToken < getDBSize(); indexToken ++) { + usageInstanceArray = tokenArray[indexToken].consumers.entrySet().toArray(); + for (usageIndex = 0; usageIndex < tokenArray[indexToken].consumers.size(); usageIndex ++) { + usageInstance = (UsageInstance)((Map.Entry)usageInstanceArray[usageIndex]).getValue(); + bFound = false; + for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) { + if (moduleNames.get(moduleIndex).equalsIgnoreCase(usageInstance.getPrimaryKey())) { + bFound = true; + break; + } + } + if (!bFound) { + moduleNames.add(usageInstance.getPrimaryKey()); + } + } + } + return moduleNames; + } +} diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java new file mode 100644 index 0000000000..181e321b0a --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/SkuInstance.java @@ -0,0 +1,45 @@ +/** @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; + } + + public SkuInstance() { + this.id = 0; + this.value = new DynamicTokenValue(); + } +} diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java new file mode 100644 index 0000000000..2e2a297aa0 --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java @@ -0,0 +1,850 @@ +/** @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; +import java.util.UUID; + +import org.tianocore.pcd.entity.UsageIdentification; +import org.tianocore.pcd.exception.EntityException; + +/** This class is to descript a PCD token object. The information of a token mainly + comes from MSA, SPD and setting produced by platform developer. +**/ +public class Token { + /// + /// Enumeration macro defintion for PCD type. + /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed + /// in coding review. + public 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 enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN} + + /// + /// Enumeration macor defintion for usage of PCD + /// + public 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 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 skuData; + + /// + /// consumers array record all module private information who consume this PCD token. + /// + public Map 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(); + + this.consumers = new HashMap(); + this.supportedPcdType = new ArrayList(); + } + + /** + updateSupportPcdType + + SupportPcdType should be gotten from SPD file actually, but now it just + record all PCD type for this token in FPD file. + + @param pcdType new PCD type found in FPD file for this token. + **/ + public void updateSupportPcdType(PCD_TYPE pcdType) { + for (int index = 0; index < this.supportedPcdType.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; + } + + public boolean isDynamicEx() { + for (int i = 0; i < supportedPcdType.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('-', '_'); + } + } + + /** + 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) throws EntityException { + String exceptionStr; + + if (isUsageInstanceExist(usageInstance.usageId)) { + exceptionStr = String.format("[PCD Collection Tool Exception] PCD %s for module %s has already exist in database, Please check all PCD build entries "+ + "in modules %s in to make sure no duplicated definitions in FPD file!", + usageInstance.parentToken.cName, + usageInstance.usageId.moduleName, + usageInstance.usageId.moduleName); + throw new EntityException(exceptionStr); + } + + // + // 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) { + switch (datumType) { + case UINT8: + return "UINT8"; + case UINT16: + return "UINT16"; + case UINT32: + return "UINT32"; + case UINT64: + return "UINT64"; + case POINTER: + return "POINTER"; + case BOOLEAN: + return "BOOLEAN"; + } + return "UNKNOWN"; + } + + /** + 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) { + switch (pcdType) { + case FEATURE_FLAG: + return "FEATURE_FLAG"; + case FIXED_AT_BUILD: + return "FIXED_AT_BUILD"; + case PATCHABLE_IN_MODULE: + return "PATCHABLE_IN_MODULE"; + case DYNAMIC: + return "DYNAMIC"; + case DYNAMIC_EX: + return "DYNAMIC_EX"; + } + return "UNKNOWN"; + } + + /** + 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) { + switch (usage) { + case ALWAYS_PRODUCED: + return "ALWAYS_PRODUCED"; + case ALWAYS_CONSUMED: + return "ALWAYS_CONSUMED"; + case SOMETIMES_PRODUCED: + return "SOMETIMES_PRODUCED"; + case SOMETIMES_CONSUMED: + return "SOMETIMES_CONSUMED"; + } + return "UNKNOWN"; + } + + /** + 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() { + DynamicTokenValue dynamicData; + int index; + + for (index = 0; index < this.skuData.size(); index ++) { + if (skuData.get(index).id == 0) { + return skuData.get(index).value; + } + } + + return null; + } + + /** + 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 + **/ + private void getCurrentSizeFromDefaultValue (String str, ArrayList 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 getPointerTypeSize () { + ArrayList al = new ArrayList(); + + // + // 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 + */ + public String getDynamicDefaultValue() { + DynamicTokenValue dynamicData = getDefaultSku(); + if (hasDefaultValue()) { + switch (dynamicData.type) { + case DEFAULT_TYPE: + return dynamicData.value; + } + } + + return null; + } + + // + // BugBug: We need change this algorithm accordingly when schema is updated + // to support no default value. + // + public boolean hasDefaultValue () { + int value = 0; + boolean isInteger = true; + DynamicTokenValue dynamicValue = null; + + if (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 + + @return boolean + */ + 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("\"\"") || + judgedValue.equalsIgnoreCase("L\"\"") || + (judgedValue.length() == 0) || + judgedValue.equalsIgnoreCase("{0}")) { + return true; + } + } + return false; + } + + /** + Is the string value in Unicode + + @return boolean + **/ + 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 + **/ + 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 + */ + 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; + } + + 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; + } + + public boolean isByteStreamType () { + String str = getDynamicDefaultValue(); + + if (str == null) { + return false; + } + + if (datumType == Token.DATUM_TYPE.POINTER && + str.startsWith("{") && + str.endsWith("}")) { + return true; + } + + return false; + + } + + public String getStringTypeString () { + return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1); + } +} + + + + diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java new file mode 100644 index 0000000000..0f52b22d78 --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageIdentification.java @@ -0,0 +1,97 @@ +/** @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; + +/** + +**/ +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 + // 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/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java new file mode 100644 index 0000000000..a961d8807d --- /dev/null +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java @@ -0,0 +1,389 @@ +/** @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 java.util.UUID; + +import org.tianocore.ModuleTypeDef; +import org.tianocore.pcd.entity.CommonDefinition; +import org.tianocore.pcd.entity.UsageIdentification; +import org.tianocore.pcd.exception.EntityException; + +/** + 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 id 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: + hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", + parentToken.cName); + hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", + parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + 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", + parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName); + + if (!isBuildUsedLibrary) { + hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", + parentToken.cName, + printDatum); + 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) { + hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n", + parentToken.cName); + hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", + Token.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + } else { + hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n", + Token.getAutogendatumTypeString(parentToken.datumType), + parentToken.cName); + hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", + Token.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + } + + 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", + parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName); + if (!isBuildUsedLibrary) { + if (parentToken.datumType == Token.DATUM_TYPE.POINTER) { + if (isByteArray) { + hAutogenStr += String.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", + parentToken.cName, + parentToken.cName); + cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n", + parentToken.cName, + printDatum); + } else { + hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", + parentToken.cName, + printDatum); + 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 { + hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", + parentToken.cName, + printDatum); + 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 (isByteArray) { + hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n", + parentToken.cName); + hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n", + Token.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + } else { + hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n", + Token.getAutogendatumTypeString(parentToken.datumType), + parentToken.cName); + hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n", + Token.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + } + + // + // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro + // + if (parentToken.datumType == Token.DATUM_TYPE.POINTER) { + hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n", + Token.GetAutogenDefinedatumTypeString(parentToken.datumType), + parentToken.cName, + parentToken.cName); + } else { + 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) { + hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", + parentToken.cName, + printDatum); + if (isByteArray) { + cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n", + parentToken.cName, + parentToken.cName); + } else { + 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: + 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) { + 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 { + 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("-", "_"); + + 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) { + 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 { + 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/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java b/Tools/Source/PcdTools/org/tianocore/pcd/exception/BuildActionException.java new file mode 100644 index 0000000000..9cd4e63fef --- /dev/null +++ b/Tools/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/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java b/Tools/Source/PcdTools/org/tianocore/pcd/exception/EntityException.java new file mode 100644 index 0000000000..ca25810855 --- /dev/null +++ b/Tools/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 EntityException]:" + expStr); + } +} diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/exception/UIException.java b/Tools/Source/PcdTools/org/tianocore/pcd/exception/UIException.java new file mode 100644 index 0000000000..377a8a4b1d --- /dev/null +++ b/Tools/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); + } +} diff --git a/Tools/Tools.spd b/Tools/Tools.spd index c9bb0f3bab..ed78d1be8b 100644 --- a/Tools/Tools.spd +++ b/Tools/Tools.spd @@ -44,6 +44,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ToolResources.msa JavaResources.msa Source/Common/Common.msa + Source/PcdTools/PcdTools.msa Source/Cpptasks/CppTasks.msa Source/FrameworkTasks/FrameworkTasks.msa Source/FrameworkWizard/FrameworkWizard.msa diff --git a/Tools/build.xml b/Tools/build.xml index 1afe6edb0c..305dad848c 100644 --- a/Tools/build.xml +++ b/Tools/build.xml @@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -95,6 +97,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Source/Cpptasks/build.xml Source/FrameworkTasks/build.xml Source/GenBuild/build.xml + Source/PcdTools/build.xml Source/Common/build.xml Source/SurfaceArea/build.xml "/> diff --git a/edksetup.bat b/edksetup.bat index 4a5abcc586..90e92e6a76 100644 --- a/edksetup.bat +++ b/edksetup.bat @@ -172,6 +172,7 @@ call ant -f %WORKSPACE%\Tools\build.xml JavaCode @REM using the cpp-tasks to create our tools @REM set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\Common.jar +set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\PcdTools.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\GenBuild.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\cpptasks.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\frameworktasks.jar @@ -235,6 +236,7 @@ set CLASSPATH=%CLASSPATH%;%XMLBEANS_HOME%\lib\saxon8.jar set CLASSPATH=%CLASSPATH%;%XMLBEANS_HOME%\lib\resolver.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\SurfaceArea.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\Common.jar +set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\PcdTools.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\GenBuild.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\cpptasks.jar set CLASSPATH=%CLASSPATH%;%WORKSPACE%\Tools\Jars\frameworktasks.jar diff --git a/edksetup.sh b/edksetup.sh index 0c0265a378..08e62bc877 100644 --- a/edksetup.sh +++ b/edksetup.sh @@ -30,7 +30,7 @@ then else # These should be ok as they are. -export CLASSPATH=$WORKSPACE/Tools/Jars/SurfaceArea.jar:$WORKSPACE/Tools/Jars/frameworktasks.jar:$WORKSPACE/Tools/Jars/cpptasks.jar:$WORKSPACE/Tools/Jars/GenBuild.jar:$XMLBEANS_HOME/lib/resolver.jar:$XMLBEANS_HOME/lib/xbean.jar:$XMLBEANS_HOME/lib/xmlpublic.jar:$XMLBEANS_HOME/lib/jsr173_1.0_api.jar:$XMLBEANS_HOME/lib/saxon8.jar:$XMLBEANS_HOME/lib/xbean_xpath.jar +export CLASSPATH=$WORKSPACE/Tools/Jars/SurfaceArea.jar:$WORKSPACE/Tools/Jars/frameworktasks.jar:$WORKSPACE/Tools/Jars/cpptasks.jar:$WORKSPACE/Tools/Jars/PcdTools.jar:$WORKSPACE/Tools/Jars/GenBuild.jar:$XMLBEANS_HOME/lib/resolver.jar:$XMLBEANS_HOME/lib/xbean.jar:$XMLBEANS_HOME/lib/xmlpublic.jar:$XMLBEANS_HOME/lib/jsr173_1.0_api.jar:$XMLBEANS_HOME/lib/saxon8.jar:$XMLBEANS_HOME/lib/xbean_xpath.jar export CLASSPATH=$CLASSPATH:$WORKSPACE/Tools/Jars/Common.jar export CLASSPATH=$CLASSPATH:$WORKSPACE/Tools/Bin/FrameworkWizard.jar export FRAMEWORK_TOOLS_PATH=$WORKSPACE/Tools/bin @@ -54,6 +54,7 @@ if [ \ "$1" = Rebuild -o \ "$1" = ForceRebuild -o \ ! -e "$WORKSPACE/Tools/Jars/Common.jar" -o \ + ! -e "$WORKSPACE/Tools/Jars/PcdTools.jar" -o \ ! -e "$WORKSPACE/Tools/Jars/GenBuild.jar" -o \ ! -e "$WORKSPACE/Tools/Jars/SurfaceArea.jar" -o \ ! -e "$WORKSPACE/Tools/Jars/cpptasks.jar" -o \