4 This module contains all classes releted to PCD token.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.build
.pcd
.entity
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import java
.util
.HashMap
;
24 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
25 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
27 /** This class is to descript a PCD token object. The information of a token mainly
28 comes from MSA, SPD and setting produced by platform developer.
32 /// Enumeration macro defintion for PCD type.
33 /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed
35 public enum PCD_TYPE
{FEATURE_FLAG
, FIXED_AT_BUILD
, PATCHABLE_IN_MODULE
, DYNAMIC
,
39 /// Enumeration macro definition for datum type. All type mainly comes from ProcessBind.h.
40 /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in
43 public enum DATUM_TYPE
{UINT8
, UINT16
, UINT32
, UINT64
, BOOLEAN
, POINTER
, UNKNOWN
}
46 /// Enumeration macor defintion for usage of PCD
48 public enum PCD_USAGE
{ALWAYS_PRODUCED
, ALWAYS_CONSUMED
, SOMETIMES_PRODUCED
,
49 SOMETIMES_CONSUMED
, UNKNOWN
}
52 /// cName is to identify a PCD entry and will be used for generating autogen.h/autogen.c.
53 /// cName will be defined in MSA, SPD and FPD, can be regarded as primary key with token space guid.
58 /// Token space name is the guid defined by token itself in package or module level. This
59 /// name mainly for DynamicEx type. For other PCD type token, his token space name is the
60 /// assignedtokenSpaceName as follows.
61 /// tokenSpaceName is defined in MSA, SPD, FPD, can be regarded as primary key with cName.
63 public UUID tokenSpaceName
;
66 /// tokenNumber is allocated by platform. tokenNumber indicate an index for this token in
67 /// platform token space.
68 /// tokenNumber is defined in SPD, FPD.
70 public int tokenNumber
;
73 /// pcdType is the PCD item type defined by platform developer.
75 public PCD_TYPE pcdType
;
78 /// datumSize is to descript the fix size or max size for this token.
79 /// datumSize is defined in SPD.
84 /// datum type is to descript what type can be expressed by a PCD token.
85 /// datumType is defined in SPD.
87 public DATUM_TYPE datumType
;
90 /// hiiEnabled is to indicate whether the token support Hii functionality.
91 /// hiiEnabled is defined in FPD.
93 public boolean hiiEnabled
;
96 /// variableName is valid only when this token support Hii functionality. variableName
97 /// indicates the value of token is associated with what variable.
98 /// variableName is defined in FPD.
100 public String variableName
;
103 /// variableGuid is the GUID this token associated with.
104 /// variableGuid is defined in FPD.
106 public UUID variableGuid
;
109 /// Variable offset indicate the associated variable's offset in NV storage.
110 /// variableOffset is defined in FPD.
112 public int variableOffset
;
115 /// skuEnabled is to indicate whether the token support Sku functionality.
116 /// skuEnabled is defined in FPD.
118 public boolean skuEnabled
;
121 /// skuData contains all value for SkuNumber of token.
122 /// skuData is defined in FPD.
124 public List
<SkuInstance
> skuData
;
127 /// maxSkuCount indicate the max count of sku data.
128 /// maxSkuCount is defined in FPD.
130 public int maxSkuCount
;
133 /// SkuId is the id of current selected SKU.
134 /// SkuId is defined in FPD.
139 /// datum is the value set by platform developer.
140 /// datum is defined in FPD.
145 /// BUGBUG: fix comment
146 /// vpdEnabled is defined in FPD.
148 public boolean vpdEnabled
;
151 /// BUGBUG: fix comment
152 /// vpdOffset is defined in FPD.
154 public long vpdOffset
;
157 /// consumers array record all module private information who consume this PCD token.
159 public Map
<String
, UsageInstance
> consumers
;
161 public Token(String cName
, UUID tokenSpaceName
) {
162 UUID nullUUID
= new UUID(0, 0);
165 this.tokenSpaceName
= (tokenSpaceName
== null) ? nullUUID
: tokenSpaceName
;
166 this.tokenNumber
= 0;
167 this.pcdType
= PCD_TYPE
.UNKNOWN
;
168 this.datumType
= DATUM_TYPE
.UNKNOWN
;
171 this.hiiEnabled
= false;
172 this.variableGuid
= null;
173 this.variableName
= "";
174 this.variableOffset
= -1;
175 this.skuEnabled
= false;
177 this.maxSkuCount
= -1;
178 this.skuData
= new ArrayList
<SkuInstance
>();
179 this.vpdEnabled
= false;
182 this.consumers
= new HashMap
<String
, UsageInstance
>();
186 Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database
188 @param cName Token name.
189 @param tokenSpaceName The token space guid defined in MSA or SPD
190 @param platformtokenSpaceName The token space guid for current platform token space,
192 @return primary key for this token in token database.
194 public static String
getPrimaryKeyString(String cName
, UUID tokenSpaceName
) {
195 UUID nullUUID
= new UUID(0, 0);
197 if (tokenSpaceName
== null) {
198 return cName
+ "_" + nullUUID
.toString().replace('-', '_');
200 return cName
+ "_" + tokenSpaceName
.toString().replace('-', '_');
205 Get the token primary key in token database.
209 public String
getPrimaryKeyString () {
210 return Token
.getPrimaryKeyString(cName
, tokenSpaceName
);
214 Judge datumType is valid
216 @param type The datumType want to be judged.
218 @retval TRUE - The type is valid.
219 @retval FALSE - The type is invalid.
221 public static boolean isValiddatumType(DATUM_TYPE type
) {
222 if ((type
.ordinal() < DATUM_TYPE
.UINT8
.ordinal() ) ||
223 (type
.ordinal() > DATUM_TYPE
.POINTER
.ordinal())) {
230 Judge pcdType is valid
232 @param type The PCdType want to be judged.
234 @retval TRUE - The type is valid.
235 @retval FALSE - The type is invalid.
237 public static boolean isValidpcdType(PCD_TYPE type
) {
238 if ((type
.ordinal() < PCD_TYPE
.FEATURE_FLAG
.ordinal() ) ||
239 (type
.ordinal() > PCD_TYPE
.DYNAMIC_EX
.ordinal())) {
246 Add an usage instance for token
248 @param usageInstance The usage instance
250 @retval TRUE - Success to add usage instance.
251 @retval FALSE - Fail to add usage instance
253 public boolean addUsageInstance(UsageInstance usageInstance
)
254 throws EntityException
{
257 if (isUsageInstanceExist(usageInstance
.moduleName
,
258 usageInstance
.moduleGUID
,
259 usageInstance
.packageName
,
260 usageInstance
.packageGUID
,
262 usageInstance
.version
)) {
263 exceptionStr
= String
.format("PCD %s for module %s has already exist in database, Please check all PCD build entries "+
264 "in modules PcdPeim in <ModuleSA> to make sure no duplicated definitions!",
265 usageInstance
.parentToken
.cName
,
266 usageInstance
.moduleName
);
267 throw new EntityException(exceptionStr
);
270 consumers
.put(usageInstance
.getPrimaryKey(), usageInstance
);
275 Judge whether exist an usage instance for this token
277 @param moduleName the name of module
278 @param moduleGuid the GUID name of modules
279 @param packageName the name of package contains this module
280 @param packageGuid the GUID name of package contains this module
281 @param arch the architecture string
282 @param version the version string
284 @return boolean whether exist an usage instance for this token.
286 public boolean isUsageInstanceExist(String moduleName
,
292 String keyStr
= UsageInstance
.getPrimaryKey(moduleName
,
298 return (consumers
.get(keyStr
) != null);
302 Get the PCD_TYPE according to the string of PCD_TYPE
304 @param pcdTypeStr The string of PCD_TYPE
308 public static PCD_TYPE
getpcdTypeFromString(String pcdTypeStr
) {
309 if (pcdTypeStr
== null) {
310 return PCD_TYPE
.UNKNOWN
;
313 if (pcdTypeStr
.equalsIgnoreCase("FEATURE_FLAG")) {
314 return PCD_TYPE
.FEATURE_FLAG
;
315 } else if (pcdTypeStr
.equalsIgnoreCase("FIXED_AT_BUILD")) {
316 return PCD_TYPE
.FIXED_AT_BUILD
;
317 } else if (pcdTypeStr
.equalsIgnoreCase("PATCHABLE_IN_MODULE")) {
318 return PCD_TYPE
.PATCHABLE_IN_MODULE
;
319 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC")) {
320 return PCD_TYPE
.DYNAMIC
;
321 } else if (pcdTypeStr
.equalsIgnoreCase("DYNAMIC_EX")) {
322 return PCD_TYPE
.DYNAMIC_EX
;
324 return PCD_TYPE
.UNKNOWN
;
329 Get the string of given datumType. This string will be used for generating autogen files
331 @param datumType Given datumType
333 @return The string of datum type.
335 public static String
getStringOfdatumType(DATUM_TYPE datumType
) {
354 Get the datumType according to a string.
356 @param datumTypeStr The string of datumType
360 public static DATUM_TYPE
getdatumTypeFromString(String datumTypeStr
) {
361 if (datumTypeStr
.equalsIgnoreCase("UINT8")) {
362 return DATUM_TYPE
.UINT8
;
363 } else if (datumTypeStr
.equalsIgnoreCase("UINT16")) {
364 return DATUM_TYPE
.UINT16
;
365 } else if (datumTypeStr
.equalsIgnoreCase("UINT32")) {
366 return DATUM_TYPE
.UINT32
;
367 } else if (datumTypeStr
.equalsIgnoreCase("UINT64")) {
368 return DATUM_TYPE
.UINT64
;
369 } else if (datumTypeStr
.equalsIgnoreCase("VOID*")) {
370 return DATUM_TYPE
.POINTER
;
371 } else if (datumTypeStr
.equalsIgnoreCase("BOOLEAN")) {
372 return DATUM_TYPE
.BOOLEAN
;
374 return DATUM_TYPE
.UNKNOWN
;
378 Get string of given pcdType
380 @param pcdType The given PcdType
382 @return The string of PCD_TYPE.
384 public static String
getStringOfpcdType(PCD_TYPE pcdType
) {
387 return "FEATURE_FLAG";
389 return "FIXED_AT_BUILD";
390 case PATCHABLE_IN_MODULE
:
391 return "PATCHABLE_IN_MODULE";
401 Get the PCD_USAGE according to a string
403 @param usageStr The string of PCD_USAGE
405 @return The PCD_USAGE
407 public static PCD_USAGE
getUsageFromString(String usageStr
) {
408 if (usageStr
== null) {
409 return PCD_USAGE
.UNKNOWN
;
412 if (usageStr
.equalsIgnoreCase("ALWAYS_PRODUCED")) {
413 return PCD_USAGE
.ALWAYS_PRODUCED
;
414 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_PRODUCED")) {
415 return PCD_USAGE
.SOMETIMES_PRODUCED
;
416 } else if (usageStr
.equalsIgnoreCase("ALWAYS_CONSUMED")) {
417 return PCD_USAGE
.ALWAYS_CONSUMED
;
418 } else if (usageStr
.equalsIgnoreCase("SOMETIMES_CONSUMED")) {
419 return PCD_USAGE
.SOMETIMES_CONSUMED
;
422 return PCD_USAGE
.UNKNOWN
;
426 Get the string of given PCD_USAGE
428 @param usage The given PCD_USAGE
430 @return The string of PDC_USAGE.
432 public static String
getStringOfUsage(PCD_USAGE usage
) {
434 case ALWAYS_PRODUCED
:
435 return "ALWAYS_PRODUCED";
436 case ALWAYS_CONSUMED
:
437 return "ALWAYS_CONSUMED";
438 case SOMETIMES_PRODUCED
:
439 return "SOMETIMES_PRODUCED";
440 case SOMETIMES_CONSUMED
:
441 return "SOMETIMES_CONSUMED";
447 Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h
449 @param datumType The given datumType
451 @return string of datum type for autogen.
453 public static String
GetAutogenDefinedatumTypeString(DATUM_TYPE datumType
) {
474 Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen
476 @param datumType The given datumType
478 @return string of datum type.
480 public static String
getAutogendatumTypeString(DATUM_TYPE datumType
) {
499 Get the datumType string for generating some MACROs in autogen file of Library
501 @param datumType The given datumType
503 @return String of datum for genrating bit charater.
505 public static String
getAutogenLibrarydatumTypeString(DATUM_TYPE datumType
) {
525 UUID defined in Schems is object, this function is to tranlate this object
528 @param uuidObj The object comes from schema.
530 @return The traslated UUID instance.
532 public static UUID
getGUIDFromSchemaObject(Object uuidObj
) {
534 if (uuidObj
.toString().equalsIgnoreCase("0")) {
535 uuid
= new UUID(0,0);
537 uuid
= UUID
.fromString(uuidObj
.toString());
544 // BugBug: We need change this algorithm accordingly when schema is updated
545 // to support no default value.
547 public boolean hasDefaultValue () {
557 if (datum
.toString().compareTo("NoDefault") == 0) {
564 public boolean isStringType () {
565 String str
= datum
.toString();
567 if (datumType
== Token
.DATUM_TYPE
.POINTER
&&
568 str
.startsWith("L\"") &&
569 str
.endsWith("\"")) {
576 public String
getStringTypeString () {
577 return datum
.toString().substring(2, datum
.toString().length() - 1);