2 CollectPCDAction class.
4 This action class is to collect PCD information from MSA, SPD, FPD xml file.
5 This class will be used for wizard and build tools, So it can *not* inherit
6 from buildAction or wizardAction.
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.build
.pcd
.action
;
20 import java
.io
.BufferedReader
;
22 import java
.io
.FileReader
;
23 import java
.io
.IOException
;
24 import java
.math
.BigInteger
;
25 import java
.util
.ArrayList
;
26 import java
.util
.Collections
;
27 import java
.util
.Comparator
;
28 import java
.util
.HashMap
;
29 import java
.util
.Iterator
;
30 import java
.util
.List
;
33 import java
.util
.UUID
;
34 import java
.util
.regex
.Matcher
;
35 import java
.util
.regex
.Pattern
;
37 import org
.apache
.xmlbeans
.XmlException
;
38 import org
.apache
.xmlbeans
.XmlObject
;
39 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
40 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
;
41 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
;
42 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
;
43 import org
.tianocore
.FrameworkModulesDocument
;
44 import org
.tianocore
.PcdDeclarationsDocument
;
45 import org
.tianocore
.PlatformSurfaceAreaDocument
;
46 import org
.tianocore
.PcdBuildDefinitionDocument
;
47 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
48 import org
.tianocore
.ModuleSADocument
;
49 import org
.tianocore
.ModuleSADocument
.ModuleSA
;
50 import org
.tianocore
.PackageSurfaceAreaDocument
;
51 import org
.tianocore
.PcdBuildDefinitionDocument
.PcdBuildDefinition
;
52 import org
.tianocore
.build
.autogen
.CommonDefinition
;
53 import org
.tianocore
.build
.global
.GlobalData
;
54 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
55 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
56 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
57 import org
.tianocore
.build
.pcd
.entity
.DynamicTokenValue
;
58 import org
.tianocore
.build
.pcd
.entity
.MemoryDatabaseManager
;
59 import org
.tianocore
.build
.pcd
.entity
.SkuInstance
;
60 import org
.tianocore
.build
.pcd
.entity
.Token
;
61 import org
.tianocore
.build
.pcd
.entity
.UsageInstance
;
62 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
63 import org
.tianocore
.logger
.EdkLog
;
64 import org
.tianocore
.ModuleTypeDef
;
66 class CStructTypeDeclaration
{
72 public CStructTypeDeclaration (String key
, int alignmentSize
, String cCode
, boolean initTable
) {
74 this.alignmentSize
= alignmentSize
;
76 this.initTable
= initTable
;
81 private ArrayList
<String
> al
;
82 private ArrayList
<String
> alComments
;
86 public StringTable (String phase
) {
88 al
= new ArrayList
<String
>();
89 alComments
= new ArrayList
<String
>();
93 public String
getSizeMacro () {
94 return String
.format(PcdDatabase
.StringTableSizeMacro
, phase
, getSize());
97 private int getSize () {
99 // We have at least one Unicode Character in the table.
101 return len
== 0 ?
1 : len
;
104 public int getTableLen () {
105 return al
.size() == 0 ?
1 : al
.size();
108 public String
getExistanceMacro () {
109 return String
.format(PcdDatabase
.StringTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
112 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
) {
113 final String stringTable
= "StringTable";
114 final String tab
= "\t";
115 final String newLine
= "\r\n";
116 final String commaNewLine
= ",\r\n";
118 CStructTypeDeclaration decl
;
120 String cDeclCode
= "";
121 String cInstCode
= "";
124 // If we have a empty StringTable
126 if (al
.size() == 0) {
127 cDeclCode
+= String
.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable
) + newLine
;
128 decl
= new CStructTypeDeclaration (
136 cInstCode
= String
.format("/* %s */", stringTable
) + newLine
+ tab
+ "{ 0 }";
137 instTable
.put(stringTable
, cInstCode
);
141 // If there is any String in the StringTable
143 for (int i
= 0; i
< al
.size(); i
++) {
144 String str
= al
.get(i
);
145 String stringTableName
;
149 // StringTable is a well-known name in the PCD DXE driver
151 stringTableName
= stringTable
;
154 stringTableName
= String
.format("%s_%d", stringTable
, i
);
157 cDeclCode
+= String
.format("%-20s%s[%d]; /* %s */", "UINT16", stringTableName
, str
.length() + 1, alComments
.get(i
)) + newLine
;
160 cInstCode
= "/* StringTable */" + newLine
;
162 cInstCode
+= tab
+ String
.format("L\"%s\" /* %s */", al
.get(i
), alComments
.get(i
));
163 if (i
!= al
.size() - 1) {
164 cInstCode
+= commaNewLine
;
168 decl
= new CStructTypeDeclaration (
176 instTable
.put(stringTable
, cInstCode
);
180 public String
getTypeDeclaration () {
184 final String stringTable
= "StringTable";
185 final String tab
= "\t";
186 final String newLine
= ";\r\n";
188 output
= "/* StringTable */\r\n";
190 if (al
.size() == 0) {
191 output
+= tab
+ String
.format("UINT16 %s[1] /* StringTable is Empty */", stringTable
) + newLine
;
194 for (int i
= 0; i
< al
.size(); i
++) {
195 String str
= al
.get(i
);
199 // StringTable is a well-known name in the PCD DXE driver
201 output
+= tab
+ String
.format("UINT16 %s[%d] /* %s */", stringTable
, str
.length() + 1, alComments
.get(i
)) + newLine
;
203 output
+= tab
+ String
.format("UINT16 %s_%d[%d] /* %s */", stringTable
, i
, str
.length() + 1, alComments
.get(i
)) + newLine
;
211 public ArrayList
<String
> getInstantiation () {
212 ArrayList
<String
> output
= new ArrayList
<String
>();
214 output
.add("/* StringTable */");
216 if (al
.size() == 0) {
221 for (int i
= 0; i
< al
.size(); i
++) {
222 str
= String
.format("L\"%s\" /* %s */", al
.get(i
), alComments
.get(i
));
223 if (i
!= al
.size() - 1) {
233 public int add (String inputStr
, Token token
) {
237 String str
= inputStr
;
240 // The input can be two types:
241 // "L\"Bootmode\"" or "Bootmode".
242 // We drop the L\" and \" for the first type.
243 if (str
.startsWith("L\"") && str
.endsWith("\"")) {
244 str
= str
.substring(2, str
.length() - 1);
247 // Check if StringTable has this String already.
248 // If so, return the current pos.
250 for (i
= 0, pos
= 0; i
< al
.size(); i
++) {
251 String s
= al
.get(i
);;
256 pos
= s
.length() + 1;
262 // Include the NULL character at the end of String
264 len
+= str
.length() + 1;
266 alComments
.add(token
.getPrimaryKeyString());
273 private ArrayList
<Integer
> al
;
274 private ArrayList
<String
> alComments
;
275 private String phase
;
278 public SizeTable (String phase
) {
280 al
= new ArrayList
<Integer
>();
281 alComments
= new ArrayList
<String
>();
285 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) {
286 final String name
= "SizeTable";
288 CStructTypeDeclaration decl
;
291 cCode
= String
.format(PcdDatabase
.SizeTableDeclaration
, phase
);
292 decl
= new CStructTypeDeclaration (
301 cCode
= PcdDatabase
.genInstantiationStr(getInstantiation());
302 instTable
.put(name
, cCode
);
305 public String
getTypeDeclaration () {
306 return String
.format(PcdDatabase
.SizeTableDeclaration
, phase
);
309 public ArrayList
<String
> getInstantiation () {
310 ArrayList
<String
> Output
= new ArrayList
<String
>();
312 Output
.add("/* SizeTable */");
314 if (al
.size() == 0) {
317 for (int index
= 0; index
< al
.size(); index
++) {
318 Integer n
= al
.get(index
);
319 String str
= "\t" + n
.toString();
321 if (index
!= (al
.size() - 1)) {
325 str
+= " /* " + alComments
.get(index
) + " */";
335 public int add (Token token
) {
339 al
.add(token
.datumSize
);
340 alComments
.add(token
.getPrimaryKeyString());
345 public int getTableLen () {
346 return al
.size() == 0 ?
1 : al
.size();
352 private ArrayList
<UUID
> al
;
353 private ArrayList
<String
> alComments
;
354 private String phase
;
356 private int bodyLineNum
;
358 public GuidTable (String phase
) {
360 al
= new ArrayList
<UUID
>();
361 alComments
= new ArrayList
<String
>();
366 public String
getSizeMacro () {
367 return String
.format(PcdDatabase
.GuidTableSizeMacro
, phase
, getSize());
370 private int getSize () {
371 return (al
.size() == 0)?
1 : al
.size();
374 public String
getExistanceMacro () {
375 return String
.format(PcdDatabase
.GuidTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
378 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) {
379 final String name
= "GuidTable";
381 CStructTypeDeclaration decl
;
384 cCode
+= String
.format(PcdDatabase
.GuidTableDeclaration
, phase
);
385 decl
= new CStructTypeDeclaration (
394 cCode
= PcdDatabase
.genInstantiationStr(getInstantiation());
395 instTable
.put(name
, cCode
);
398 public String
getTypeDeclaration () {
399 return String
.format(PcdDatabase
.GuidTableDeclaration
, phase
);
402 private String
getUuidCString (UUID uuid
) {
403 String
[] guidStrArray
;
405 guidStrArray
=(uuid
.toString()).split("-");
407 return String
.format("{0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",
411 (guidStrArray
[3].substring(0, 2)),
412 (guidStrArray
[3].substring(2, 4)),
413 (guidStrArray
[4].substring(0, 2)),
414 (guidStrArray
[4].substring(2, 4)),
415 (guidStrArray
[4].substring(4, 6)),
416 (guidStrArray
[4].substring(6, 8)),
417 (guidStrArray
[4].substring(8, 10)),
418 (guidStrArray
[4].substring(10, 12))
422 public ArrayList
<String
> getInstantiation () {
423 ArrayList
<String
> Output
= new ArrayList
<String
>();
425 Output
.add("/* GuidTable */");
428 if (al
.size() == 0) {
429 Output
.add("\t" + getUuidCString(new UUID(0, 0)));
432 for (int i
= 0; i
< al
.size(); i
++) {
433 String str
= "\t" + getUuidCString(al
.get(i
));
435 str
+= "/* " + alComments
.get(i
) + " */";
436 if (i
!= (al
.size() - 1)) {
448 public int add (UUID uuid
, String name
) {
450 // Check if GuidTable has this entry already.
451 // If so, return the GuidTable index.
453 for (int i
= 0; i
< al
.size(); i
++) {
454 if (al
.get(i
).equals(uuid
)) {
461 alComments
.add(name
);
464 // Return the previous Table Index
469 public int getTableLen () {
470 return al
.size() == 0 ?
0 : al
.size();
476 private ArrayList
<Integer
[]> al
;
477 private ArrayList
<String
> alComment
;
478 private String phase
;
481 public SkuIdTable (String phase
) {
483 al
= new ArrayList
<Integer
[]>();
484 alComment
= new ArrayList
<String
>();
488 public String
getSizeMacro () {
489 return String
.format(PcdDatabase
.SkuIdTableSizeMacro
, phase
, getSize());
492 private int getSize () {
493 return (len
== 0)?
1 : len
;
496 public String
getExistanceMacro () {
497 return String
.format(PcdDatabase
.SkuTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
500 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) {
501 final String name
= "SkuIdTable";
503 CStructTypeDeclaration decl
;
506 cCode
+= String
.format(PcdDatabase
.SkuIdTableDeclaration
, phase
);
507 decl
= new CStructTypeDeclaration (
516 cCode
= PcdDatabase
.genInstantiationStr(getInstantiation());
517 instTable
.put(name
, cCode
);
520 // SystemSkuId is in PEI phase PCD Database
522 if (phase
.equalsIgnoreCase("PEI")) {
523 decl
= new CStructTypeDeclaration (
526 String
.format("%-20sSystemSkuId;\r\n", "SKU_ID"),
531 instTable
.put("SystemSkuId", "0");
536 public String
getTypeDeclaration () {
537 return String
.format(PcdDatabase
.SkuIdTableDeclaration
, phase
);
540 public ArrayList
<String
> getInstantiation () {
541 ArrayList
<String
> Output
= new ArrayList
<String
> ();
543 Output
.add("/* SkuIdTable */");
546 if (al
.size() == 0) {
550 for (int index
= 0; index
< al
.size(); index
++) {
553 str
= "/* " + alComment
.get(index
) + "*/ ";
554 str
+= "/* MaxSku */ ";
557 Integer
[] ia
= al
.get(index
);
559 str
+= "\t" + ia
[0].toString() + ", ";
560 for (int index2
= 1; index2
< ia
.length
; index2
++) {
561 str
+= ia
[index2
].toString();
562 if (!((index2
== ia
.length
- 1) && (index
== al
.size() - 1))) {
576 public int add (Token token
) {
582 // Check if this SKU_ID Array is already in the table
586 Integer
[] s
= (Integer
[]) o
;
587 boolean different
= false;
588 if (s
[0] == token
.getSkuIdCount()) {
589 for (index
= 1; index
< s
.length
; index
++) {
590 if (s
[index
] != token
.skuData
.get(index
-1).id
) {
605 Integer
[] skuIds
= new Integer
[token
.skuData
.size() + 1];
606 skuIds
[0] = new Integer(token
.skuData
.size());
607 for (index
= 1; index
< skuIds
.length
; index
++) {
608 skuIds
[index
] = new Integer(token
.skuData
.get(index
- 1).id
);
613 len
+= skuIds
.length
;
615 alComment
.add(token
.getPrimaryKeyString());
620 public int getTableLen () {
621 return al
.size() == 0 ?
1 : al
.size();
626 class LocalTokenNumberTable
{
627 private ArrayList
<String
> al
;
628 private ArrayList
<String
> alComment
;
629 private String phase
;
632 public LocalTokenNumberTable (String phase
) {
634 al
= new ArrayList
<String
>();
635 alComment
= new ArrayList
<String
>();
640 public String
getSizeMacro () {
641 return String
.format(PcdDatabase
.LocalTokenNumberTableSizeMacro
, phase
, getSize())
642 + String
.format(PcdDatabase
.LocalTokenNumberSizeMacro
, phase
, al
.size());
645 public int getSize () {
646 return (al
.size() == 0)?
1 : al
.size();
649 public String
getExistanceMacro () {
650 return String
.format(PcdDatabase
.DatabaseExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
653 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) {
654 final String name
= "LocalTokenNumberTable";
656 CStructTypeDeclaration decl
;
659 cCode
+= String
.format(PcdDatabase
.LocalTokenNumberTableDeclaration
, phase
);
660 decl
= new CStructTypeDeclaration (
668 cCode
= PcdDatabase
.genInstantiationStr(getInstantiation());
669 instTable
.put(name
, cCode
);
672 public String
getTypeDeclaration () {
673 return String
.format(PcdDatabase
.LocalTokenNumberTableDeclaration
, phase
);
676 public ArrayList
<String
> getInstantiation () {
677 ArrayList
<String
> output
= new ArrayList
<String
>();
679 output
.add("/* LocalTokenNumberTable */");
682 if (al
.size() == 0) {
686 for (int index
= 0; index
< al
.size(); index
++) {
689 str
= "\t" + (String
)al
.get(index
);
691 str
+= " /* " + alComment
.get(index
) + " */ ";
694 if (index
!= (al
.size() - 1)) {
707 public int add (Token token
) {
713 str
= String
.format(PcdDatabase
.offsetOfStrTemplate
, phase
, token
.hasDefaultValue() ?
"Init" : "Uninit", token
.getPrimaryKeyString());
715 if (token
.isUnicodeStringType()) {
716 str
+= " | PCD_TYPE_STRING";
719 if (token
.isSkuEnable()) {
720 str
+= " | PCD_TYPE_SKU_ENABLED";
723 if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.HII_TYPE
) {
724 str
+= " | PCD_TYPE_HII";
727 if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.VPD_TYPE
) {
728 str
+= " | PCD_TYPE_VPD";
732 alComment
.add(token
.getPrimaryKeyString());
741 public Integer guidTableIdx
;
742 public Long exTokenNumber
;
743 public Long localTokenIdx
;
745 public ExTriplet (int guidTableIdx
, long exTokenNumber
, long localTokenIdx
) {
746 this.guidTableIdx
= new Integer(guidTableIdx
);
747 this.exTokenNumber
= new Long(exTokenNumber
);
748 this.localTokenIdx
= new Long(localTokenIdx
);
752 private ArrayList
<ExTriplet
> al
;
753 private ArrayList
<String
> alComment
;
754 private String phase
;
756 private int bodyLineNum
;
758 public ExMapTable (String phase
) {
760 al
= new ArrayList
<ExTriplet
>();
761 alComment
= new ArrayList
<String
>();
766 public String
getSizeMacro () {
767 return String
.format(PcdDatabase
.ExMapTableSizeMacro
, phase
, getTableLen())
768 + String
.format(PcdDatabase
.ExTokenNumber
, phase
, al
.size());
771 public String
getExistanceMacro () {
772 return String
.format(PcdDatabase
.ExMapTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
775 public void genCodeNew (ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) {
776 final String exMapTableName
= "ExMapTable";
780 CStructTypeDeclaration decl
;
783 cCode
+= String
.format(PcdDatabase
.ExMapTableDeclaration
, phase
);
784 decl
= new CStructTypeDeclaration (
793 cCode
= PcdDatabase
.genInstantiationStr(getInstantiation());
794 instTable
.put(exMapTableName
, cCode
);
797 public String
getTypeDeclaration () {
798 return String
.format(PcdDatabase
.ExMapTableDeclaration
, phase
);
801 public ArrayList
<String
> getInstantiation () {
802 ArrayList
<String
> Output
= new ArrayList
<String
>();
804 Output
.add("/* ExMapTable */");
806 if (al
.size() == 0) {
807 Output
.add("\t{0, 0, 0}");
811 for (index
= 0; index
< al
.size(); index
++) {
814 ExTriplet e
= (ExTriplet
)al
.get(index
);
816 str
= "\t" + "{ " + String
.format("0x%08X", e
.exTokenNumber
) + ", ";
817 str
+= e
.localTokenIdx
.toString() + ", ";
818 str
+= e
.guidTableIdx
.toString();
820 str
+= "}" + " /* " + alComment
.get(index
) + " */" ;
822 if (index
!= al
.size() - 1) {
836 public int add (int localTokenIdx
, long exTokenNum
, int guidTableIdx
, String name
) {
840 al
.add(new ExTriplet(guidTableIdx
, exTokenNum
, localTokenIdx
));
846 public int getTableLen () {
847 return al
.size() == 0 ?
1 : al
.size();
851 // To simplify the algorithm for GetNextToken and GetNextTokenSpace in
852 // PCD PEIM/Driver, we need to sort the ExMapTable according to the
857 class ExTripletComp
implements Comparator
<ExTriplet
> {
858 public int compare (ExTriplet a
, ExTriplet b
) {
859 if (a
.guidTableIdx
== b
.guidTableIdx
) {
860 if (a
.exTokenNumber
> b
.exTokenNumber
) {
862 } else if (a
.exTokenNumber
> b
.exTokenNumber
) {
869 return a
.guidTableIdx
- b
.guidTableIdx
;
873 private void sortTable () {
874 java
.util
.Comparator
<ExTriplet
> comparator
= new ExTripletComp();
875 java
.util
.Collections
.sort(al
, comparator
);
881 private final static int SkuHeadAlignmentSize
= 4;
882 private final String newLine
= "\r\n";
883 private final String commaNewLine
= ",\r\n";
884 private final String tab
= "\t";
885 public final static String ExMapTableDeclaration
= "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";
886 public final static String GuidTableDeclaration
= "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";
887 public final static String LocalTokenNumberTableDeclaration
= "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";
888 public final static String StringTableDeclaration
= "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";
889 public final static String SizeTableDeclaration
= "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";
890 public final static String SkuIdTableDeclaration
= "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";
893 public final static String ExMapTableSizeMacro
= "#define %s_EXMAPPING_TABLE_SIZE %d\r\n";
894 public final static String ExTokenNumber
= "#define %s_EX_TOKEN_NUMBER %d\r\n";
895 public final static String GuidTableSizeMacro
= "#define %s_GUID_TABLE_SIZE %d\r\n";
896 public final static String LocalTokenNumberTableSizeMacro
= "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE %d\r\n";
897 public final static String LocalTokenNumberSizeMacro
= "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";
898 public final static String StringTableSizeMacro
= "#define %s_STRING_TABLE_SIZE %d\r\n";
899 public final static String SkuIdTableSizeMacro
= "#define %s_SKUID_TABLE_SIZE %d\r\n";
902 public final static String ExMapTableExistenceMacro
= "#define %s_EXMAP_TABLE_EMPTY %s\r\n";
903 public final static String GuidTableExistenceMacro
= "#define %s_GUID_TABLE_EMPTY %s\r\n";
904 public final static String DatabaseExistenceMacro
= "#define %s_DATABASE_EMPTY %s\r\n";
905 public final static String StringTableExistenceMacro
= "#define %s_STRING_TABLE_EMPTY %s\r\n";
906 public final static String SkuTableExistenceMacro
= "#define %s_SKUID_TABLE_EMPTY %s\r\n";
908 public final static String offsetOfSkuHeadStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";
909 public final static String offsetOfVariableEnabledDefault
= "offsetof(%s_PCD_DATABASE, %s.%s_VariableDefault_%d)";
910 public final static String offsetOfStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s)";
912 private final static String skuDataTableTemplate
= "SkuDataTable";
915 private StringTable stringTable
;
916 private GuidTable guidTable
;
917 private LocalTokenNumberTable localTokenNumberTable
;
918 private SkuIdTable skuIdTable
;
919 private SizeTable sizeTable
;
920 private ExMapTable exMapTable
;
922 private ArrayList
<Token
> alTokens
;
923 private String phase
;
924 private int assignedTokenNumber
;
927 // Use two class global variable to store
930 private String privateGlobalName
;
931 private String privateGlobalCCode
;
933 // After Major changes done to the PCD
934 // database generation class PcdDatabase
935 // Please increment the version and please
936 // also update the version number in PCD
937 // service PEIM and DXE driver accordingly.
939 private final int version
= 2;
941 private String hString
;
942 private String cString
;
945 class AlignmentSizeComp
implements Comparator
<Token
> {
946 public int compare (Token a
, Token b
) {
947 return getAlignmentSize(b
)
948 - getAlignmentSize(a
);
952 public PcdDatabase (ArrayList
<Token
> alTokens
, String exePhase
, int startLen
) {
955 stringTable
= new StringTable(phase
);
956 guidTable
= new GuidTable(phase
);
957 localTokenNumberTable
= new LocalTokenNumberTable(phase
);
958 skuIdTable
= new SkuIdTable(phase
);
959 sizeTable
= new SizeTable(phase
);
960 exMapTable
= new ExMapTable(phase
);
962 assignedTokenNumber
= startLen
+ 1;
963 this.alTokens
= alTokens
;
966 private void getNonExAndExTokens (ArrayList
<Token
> alTokens
, List
<Token
> nexTokens
, List
<Token
> exTokens
) {
967 for (int i
= 0; i
< alTokens
.size(); i
++) {
968 Token t
= (Token
)alTokens
.get(i
);
969 if (t
.isDynamicEx()) {
979 private void getTwoGroupsOfTokens (ArrayList
<Token
> alTokens
, List
<Token
> initTokens
, List
<Token
> uninitTokens
) {
980 for (int i
= 0; i
< alTokens
.size(); i
++) {
981 Token t
= (Token
)alTokens
.get(i
);
982 if (t
.hasDefaultValue()) {
992 private int getDataTypeAlignmentSize (Token token
) {
993 switch (token
.datumType
) {
1011 private int getAlignmentSize (Token token
) {
1012 if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.HII_TYPE
) {
1016 if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.VPD_TYPE
) {
1020 if (token
.isUnicodeStringType()) {
1024 return getDataTypeAlignmentSize(token
);
1027 public String
getCString () {
1031 public String
getHString () {
1035 private void genCodeWorker(Token t
,
1036 ArrayList
<CStructTypeDeclaration
> declaList
,
1037 HashMap
<String
, String
> instTable
, String phase
)
1038 throws EntityException
{
1040 CStructTypeDeclaration decl
;
1043 // Insert SKU_HEAD if isSkuEnable is true
1045 if (t
.isSkuEnable()) {
1047 tableIdx
= skuIdTable
.add(t
);
1048 decl
= new CStructTypeDeclaration(t
.getPrimaryKeyString(),
1049 SkuHeadAlignmentSize
, getSkuEnabledTypeDeclaration(t
), true);
1050 declaList
.add(decl
);
1051 instTable
.put(t
.getPrimaryKeyString(),
1052 getSkuEnabledTypeInstantiaion(t
, tableIdx
));
1056 // Insert PCD_ENTRY declaration and instantiation
1058 getCDeclarationString(t
);
1060 decl
= new CStructTypeDeclaration(privateGlobalName
,
1061 getAlignmentSize(t
), privateGlobalCCode
, t
.hasDefaultValue());
1062 declaList
.add(decl
);
1064 if (t
.hasDefaultValue()) {
1065 instTable
.put(privateGlobalName
,
1066 getTypeInstantiation(t
, declaList
, instTable
, phase
)
1072 private void ProcessTokensNew (List
<Token
> tokens
,
1073 ArrayList
<CStructTypeDeclaration
> cStructDeclList
,
1074 HashMap
<String
, String
> cStructInstTable
,
1077 throws EntityException
{
1079 for (int idx
= 0; idx
< tokens
.size(); idx
++) {
1080 Token t
= tokens
.get(idx
);
1082 genCodeWorker (t
, cStructDeclList
, cStructInstTable
, phase
);
1085 localTokenNumberTable
.add(t
);
1086 t
.tokenNumber
= assignedTokenNumber
++;
1089 // Add a mapping if this dynamic PCD entry is a EX type
1091 if (t
.isDynamicEx()) {
1092 exMapTable
.add((int)t
.tokenNumber
,
1093 t
.dynamicExTokenNumber
,
1094 guidTable
.add(t
.tokenSpaceName
, t
.getPrimaryKeyString()),
1095 t
.getPrimaryKeyString()
1102 public void genCodeNew () throws EntityException
{
1104 ArrayList
<CStructTypeDeclaration
> cStructDeclList
= new ArrayList
<CStructTypeDeclaration
>();
1105 HashMap
<String
, String
> cStructInstTable
= new HashMap
<String
, String
>();
1107 List
<Token
> nexTokens
= new ArrayList
<Token
> ();
1108 List
<Token
> exTokens
= new ArrayList
<Token
> ();
1110 getNonExAndExTokens (alTokens
, nexTokens
, exTokens
);
1113 // We have to process Non-Ex type PCD entry first. The reason is
1114 // that our optimization assumes that the Token Number of Non-Ex
1115 // PCD entry start from 1 (for PEI phase) and grows continously upwards.
1117 // EX type token number starts from the last Non-EX PCD entry and
1118 // grows continously upwards.
1120 ProcessTokensNew (nexTokens
, cStructDeclList
, cStructInstTable
, phase
);
1121 ProcessTokensNew (exTokens
, cStructDeclList
, cStructInstTable
, phase
);
1123 stringTable
.genCodeNew(cStructDeclList
, cStructInstTable
);
1124 skuIdTable
.genCodeNew(cStructDeclList
, cStructInstTable
, phase
);
1125 exMapTable
.genCodeNew(cStructDeclList
, cStructInstTable
, phase
);
1126 localTokenNumberTable
.genCodeNew(cStructDeclList
, cStructInstTable
, phase
);
1127 sizeTable
.genCodeNew(cStructDeclList
, cStructInstTable
, phase
);
1128 guidTable
.genCodeNew(cStructDeclList
, cStructInstTable
, phase
);
1130 hString
= genCMacroCode ();
1132 HashMap
<String
, String
> result
;
1134 result
= genCStructCode(cStructDeclList
,
1139 hString
+= result
.get("initDeclStr");
1140 hString
+= result
.get("uninitDeclStr");
1142 hString
+= String
.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase
, version
);
1144 cString
= newLine
+ newLine
+ result
.get("initInstStr");
1148 private String
genCMacroCode () {
1149 String macroStr
= "";
1152 // Generate size info Macro for all Tables
1154 macroStr
+= guidTable
.getSizeMacro();
1155 macroStr
+= stringTable
.getSizeMacro();
1156 macroStr
+= skuIdTable
.getSizeMacro();
1157 macroStr
+= localTokenNumberTable
.getSizeMacro();
1158 macroStr
+= exMapTable
.getSizeMacro();
1161 // Generate existance info Macro for all Tables
1163 macroStr
+= guidTable
.getExistanceMacro();
1164 macroStr
+= stringTable
.getExistanceMacro();
1165 macroStr
+= skuIdTable
.getExistanceMacro();
1166 macroStr
+= localTokenNumberTable
.getExistanceMacro();
1167 macroStr
+= exMapTable
.getExistanceMacro();
1169 macroStr
+= newLine
;
1174 private HashMap
<String
, String
> genCStructCode(
1175 ArrayList
<CStructTypeDeclaration
> declaList
,
1176 HashMap
<String
, String
> instTable
,
1181 HashMap
<String
, String
> result
= new HashMap
<String
, String
>();
1182 HashMap
<Integer
, ArrayList
<String
>> alignmentInitDecl
= new HashMap
<Integer
, ArrayList
<String
>>();
1183 HashMap
<Integer
, ArrayList
<String
>> alignmentUninitDecl
= new HashMap
<Integer
, ArrayList
<String
>>();
1184 HashMap
<Integer
, ArrayList
<String
>> alignmentInitInst
= new HashMap
<Integer
, ArrayList
<String
>>();
1187 // Initialize the storage for each alignment
1189 for (i
= 8; i
> 0; i
>>=1) {
1190 alignmentInitDecl
.put(new Integer(i
), new ArrayList
<String
>());
1191 alignmentInitInst
.put(new Integer(i
), new ArrayList
<String
>());
1192 alignmentUninitDecl
.put(new Integer(i
), new ArrayList
<String
>());
1195 String initDeclStr
= "typedef struct {" + newLine
;
1196 String initInstStr
= String
.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase
.toUpperCase(), phase
.toUpperCase()) + newLine
;
1197 String uninitDeclStr
= "typedef struct {" + newLine
;
1200 // Sort all C declaration and instantiation base on Alignment Size
1202 for (Object d
: declaList
) {
1203 CStructTypeDeclaration decl
= (CStructTypeDeclaration
) d
;
1205 if (decl
.initTable
) {
1206 alignmentInitDecl
.get(new Integer(decl
.alignmentSize
)).add(decl
.cCode
);
1207 alignmentInitInst
.get(new Integer(decl
.alignmentSize
)).add(instTable
.get(decl
.key
));
1209 alignmentUninitDecl
.get(new Integer(decl
.alignmentSize
)).add(decl
.cCode
);
1214 // Generate code for every alignment size
1216 boolean uinitDatabaseEmpty
= true;
1217 for (int align
= 8; align
> 0; align
>>= 1) {
1218 ArrayList
<String
> declaListBasedOnAlignment
= alignmentInitDecl
.get(new Integer(align
));
1219 ArrayList
<String
> instListBasedOnAlignment
= alignmentInitInst
.get(new Integer(align
));
1220 for (i
= 0; i
< declaListBasedOnAlignment
.size(); i
++) {
1221 initDeclStr
+= tab
+ declaListBasedOnAlignment
.get(i
);
1222 initInstStr
+= tab
+ instListBasedOnAlignment
.get(i
);
1225 // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE
1226 // has a least one data memember with alignment size of 1. So we can
1227 // remove the last "," in the C structure instantiation string. Luckily,
1228 // this is true as both data structure has SKUID_TABLE anyway.
1230 if ((align
== 1) && (i
== declaListBasedOnAlignment
.size() - 1)) {
1231 initInstStr
+= newLine
;
1233 initInstStr
+= commaNewLine
;
1237 declaListBasedOnAlignment
= alignmentUninitDecl
.get(new Integer(align
));
1239 if (declaListBasedOnAlignment
.size() != 0) {
1240 uinitDatabaseEmpty
= false;
1243 for (Object d
: declaListBasedOnAlignment
) {
1244 String s
= (String
)d
;
1245 uninitDeclStr
+= tab
+ s
;
1249 if (uinitDatabaseEmpty
) {
1250 uninitDeclStr
+= tab
+ String
.format("%-20sdummy; /* PCD_DATABASE_UNINIT is emptry */\r\n", "UINT8");
1253 initDeclStr
+= String
.format("} %s_PCD_DATABASE_INIT;", phase
) + newLine
+ newLine
;
1254 initInstStr
+= "};" + newLine
;
1255 uninitDeclStr
+= String
.format("} %s_PCD_DATABASE_UNINIT;", phase
) + newLine
+ newLine
;
1257 result
.put("initDeclStr", initDeclStr
);
1258 result
.put("initInstStr", initInstStr
);
1259 result
.put("uninitDeclStr", uninitDeclStr
);
1264 public void genCode ()
1265 throws EntityException
{
1267 final String newLine
= "\r\n";
1268 final String declNewLine
= ";\r\n";
1269 final String tab
= "\t";
1270 final String commaNewLine
= ", \r\n";
1273 ArrayList
<String
> decla
;
1274 ArrayList
<String
> inst
;
1276 String macroStr
= "";
1277 String initDeclStr
= "";
1278 String initInstStr
= "";
1279 String uninitDeclStr
= "";
1281 List
<Token
> initTokens
= new ArrayList
<Token
> ();
1282 List
<Token
> uninitTokens
= new ArrayList
<Token
> ();
1284 HashMap
<String
, ArrayList
<String
>> initCode
= new HashMap
<String
, ArrayList
<String
>> ();
1285 HashMap
<String
, ArrayList
<String
>> uninitCode
= new HashMap
<String
, ArrayList
<String
>> ();
1287 getTwoGroupsOfTokens (alTokens
, initTokens
, uninitTokens
);
1290 // Generate Structure Declaration for PcdTokens without Default Value
1291 // PEI_PCD_DATABASE_INIT
1293 java
.util
.Comparator
<Token
> comparator
= new AlignmentSizeComp();
1294 java
.util
.Collections
.sort(initTokens
, comparator
);
1295 initCode
= processTokens(initTokens
);
1298 // Generate Structure Declaration for PcdTokens without Default Value
1299 // PEI_PCD_DATABASE_UNINIT
1301 java
.util
.Collections
.sort(uninitTokens
, comparator
);
1302 uninitCode
= processTokens(uninitTokens
);
1305 // Generate size info Macro for all Tables
1307 macroStr
+= guidTable
.getSizeMacro();
1308 macroStr
+= stringTable
.getSizeMacro();
1309 macroStr
+= skuIdTable
.getSizeMacro();
1310 macroStr
+= localTokenNumberTable
.getSizeMacro();
1311 macroStr
+= exMapTable
.getSizeMacro();
1314 // Generate existance info Macro for all Tables
1316 macroStr
+= guidTable
.getExistanceMacro();
1317 macroStr
+= stringTable
.getExistanceMacro();
1318 macroStr
+= skuIdTable
.getExistanceMacro();
1319 macroStr
+= localTokenNumberTable
.getExistanceMacro();
1320 macroStr
+= exMapTable
.getExistanceMacro();
1323 // Generate Structure Declaration for PcdTokens with Default Value
1324 // for example PEI_PCD_DATABASE_INIT
1326 initDeclStr
+= "typedef struct {" + newLine
;
1328 initDeclStr
+= tab
+ exMapTable
.getTypeDeclaration();
1329 initDeclStr
+= tab
+ guidTable
.getTypeDeclaration();
1330 initDeclStr
+= tab
+ localTokenNumberTable
.getTypeDeclaration();
1331 initDeclStr
+= tab
+ stringTable
.getTypeDeclaration();
1332 initDeclStr
+= tab
+ sizeTable
.getTypeDeclaration();
1333 initDeclStr
+= tab
+ skuIdTable
.getTypeDeclaration();
1334 if (phase
.equalsIgnoreCase("PEI")) {
1335 initDeclStr
+= tab
+ "SKU_ID SystemSkuId;" + newLine
;
1338 decla
= initCode
.get(new String("Declaration"));
1339 for (i
= 0; i
< decla
.size(); i
++) {
1340 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
1344 // Generate Structure Declaration for PcdToken with SkuEnabled
1346 decla
= initCode
.get("DeclarationForSku");
1348 for (i
= 0; i
< decla
.size(); i
++) {
1349 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
1352 initDeclStr
+= String
.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase
);
1355 // Generate MACRO for structure intialization of PCDTokens with Default Value
1356 // The sequence must match the sequence of declaration of the memembers in the structure
1357 String tmp
= String
.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase
.toUpperCase(), phase
.toUpperCase());
1358 initInstStr
+= tmp
+ newLine
;
1359 initInstStr
+= tab
+ genInstantiationStr(exMapTable
.getInstantiation()) + commaNewLine
;
1360 initInstStr
+= tab
+ genInstantiationStr(guidTable
.getInstantiation()) + commaNewLine
;
1361 initInstStr
+= tab
+ genInstantiationStr(localTokenNumberTable
.getInstantiation()) + commaNewLine
;
1362 initInstStr
+= tab
+ genInstantiationStr(stringTable
.getInstantiation()) + commaNewLine
;
1363 initInstStr
+= tab
+ genInstantiationStr(sizeTable
.getInstantiation()) + commaNewLine
;
1364 initInstStr
+= tab
+ genInstantiationStr(skuIdTable
.getInstantiation()) + commaNewLine
;
1368 if (phase
.equalsIgnoreCase("PEI")) {
1369 initInstStr
+= tab
+ "0" + tab
+ "/* SystemSkuId */" + commaNewLine
;
1372 inst
= initCode
.get("Instantiation");
1373 for (i
= 0; i
< inst
.size(); i
++) {
1374 initInstStr
+= tab
+ inst
.get(i
) + commaNewLine
;
1377 inst
= initCode
.get("InstantiationForSku");
1378 for (i
= 0; i
< inst
.size(); i
++) {
1379 initInstStr
+= tab
+ inst
.get(i
);
1380 if (i
!= inst
.size() - 1) {
1381 initInstStr
+= commaNewLine
;
1385 initInstStr
+= "};";
1387 uninitDeclStr
+= "typedef struct {" + newLine
;
1389 decla
= uninitCode
.get("Declaration");
1390 if (decla
.size() == 0) {
1391 uninitDeclStr
+= "UINT8 dummy /* The UINT struct is empty */" + declNewLine
;
1394 for (i
= 0; i
< decla
.size(); i
++) {
1395 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
1398 decla
= uninitCode
.get("DeclarationForSku");
1400 for (i
= 0; i
< decla
.size(); i
++) {
1401 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
1405 uninitDeclStr
+= String
.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase
);
1407 cString
= initInstStr
+ newLine
;
1408 hString
= macroStr
+ newLine
1409 + initDeclStr
+ newLine
1410 + uninitDeclStr
+ newLine
1413 hString
+= String
.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase
, version
);
1417 public static String
genInstantiationStr (ArrayList
<String
> alStr
) {
1419 for (int i
= 0; i
< alStr
.size(); i
++) {
1423 str
+= alStr
.get(i
);
1424 if (i
!= alStr
.size() - 1) {
1432 private HashMap
<String
, ArrayList
<String
>> processTokens (List
<Token
> alToken
)
1433 throws EntityException
{
1435 HashMap
<String
, ArrayList
<String
>> map
= new HashMap
<String
, ArrayList
<String
>>();
1437 ArrayList
<String
> decl
= new ArrayList
<String
>();
1438 ArrayList
<String
> declForSkuEnableType
= new ArrayList
<String
>();
1439 ArrayList
<String
> inst
= new ArrayList
<String
>();
1440 ArrayList
<String
> instForSkuEnableType
= new ArrayList
<String
>();
1442 for (int index
= 0; index
< alToken
.size(); index
++) {
1443 Token token
= alToken
.get(index
);
1445 if (token
.isSkuEnable()) {
1447 // BugBug: Schema only support Data type now
1451 tableIdx
= skuIdTable
.add(token
);
1453 decl
.add(getSkuEnabledTypeDeclaration(token
));
1454 if (token
.hasDefaultValue()) {
1455 inst
.add(getSkuEnabledTypeInstantiaion(token
, tableIdx
));
1458 declForSkuEnableType
.add(getDataTypeDeclarationForSkuEnabled(token
));
1459 if (token
.hasDefaultValue()) {
1460 instForSkuEnableType
.add(getDataTypeInstantiationForSkuEnabled(token
));
1464 if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.HII_TYPE
) {
1465 decl
.add(getVariableEnableTypeDeclaration(token
));
1466 inst
.add(getVariableEnableInstantiation(token
));
1467 } else if (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.VPD_TYPE
) {
1468 decl
.add(getVpdEnableTypeDeclaration(token
));
1469 inst
.add(getVpdEnableTypeInstantiation(token
));
1470 } else if (token
.isUnicodeStringType()) {
1471 decl
.add(getStringTypeDeclaration(token
));
1472 inst
.add(getStringTypeInstantiation(stringTable
.add(token
.getStringTypeString(), token
), token
));
1475 decl
.add(getDataTypeDeclaration(token
));
1476 if (token
.hasDefaultValue()) {
1477 inst
.add(getDataTypeInstantiation(token
));
1482 sizeTable
.add(token
);
1483 localTokenNumberTable
.add(token
);
1484 token
.tokenNumber
= assignedTokenNumber
++;
1488 map
.put("Declaration", decl
);
1489 map
.put("DeclarationForSku", declForSkuEnableType
);
1490 map
.put("Instantiation", inst
);
1491 map
.put("InstantiationForSku", instForSkuEnableType
);
1496 private String
getSkuEnabledTypeDeclaration (Token token
) {
1497 return String
.format("%-20s%s;\r\n", "SKU_HEAD", token
.getPrimaryKeyString());
1500 private String
getSkuEnabledTypeInstantiaion (Token token
, int SkuTableIdx
) {
1502 String offsetof
= String
.format(PcdDatabase
.offsetOfSkuHeadStrTemplate
, phase
, token
.hasDefaultValue()?
"Init" : "Uninit", token
.getPrimaryKeyString());
1503 return String
.format("{ %s, %d } /* SKU_ENABLED: %s */", offsetof
, SkuTableIdx
, token
.getPrimaryKeyString());
1506 private String
getDataTypeDeclarationForSkuEnabled (Token token
) {
1507 String typeStr
= "";
1509 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1510 typeStr
= "UINT8 %s_%s[%d];\r\n";
1511 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1512 typeStr
= "UINT16 %s_%s[%d];\r\n";
1513 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1514 typeStr
= "UINT32 %s_%s[%d];\r\n";
1515 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1516 typeStr
= "UINT64 %s_%s[%d];\r\n";
1517 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1518 typeStr
= "BOOLEAN %s_%s[%d];\r\n";
1519 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1520 return String
.format("UINT8 %s_%s[%d];\r\n", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.skuData
.size());
1523 return String
.format(typeStr
, token
.getPrimaryKeyString(), "SkuDataTable", token
.skuData
.size());
1527 private String
getDataTypeInstantiationForSkuEnabled (Token token
) {
1530 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1531 return String
.format("UINT8 %s_%s[%d]", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.skuData
.size());
1534 for (int idx
= 0; idx
< token
.skuData
.size(); idx
++) {
1535 str
+= token
.skuData
.get(idx
).toString();
1536 if (idx
!= token
.skuData
.size() - 1) {
1547 private String
getDataTypeInstantiationForVariableDefault_new (Token token
, String cName
, int skuId
) {
1548 return String
.format("%s /* %s */", token
.skuData
.get(skuId
).value
.hiiDefaultValue
, cName
);
1551 private String
getDataTypeInstantiation (Token token
) {
1553 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1554 return String
.format("%s /* %s */", token
.getDefaultSku().value
, token
.getPrimaryKeyString());
1556 return String
.format("%s /* %s */", token
.getDefaultSku().value
, token
.getPrimaryKeyString());
1560 private String
getCType (Token t
)
1561 throws EntityException
{
1563 if (t
.isHiiEnable()) {
1564 return "VARIABLE_HEAD";
1567 if (t
.isVpdEnable()) {
1571 if (t
.isUnicodeStringType()) {
1572 return "STRING_HEAD";
1575 switch (t
.datumType
) {
1589 throw new EntityException("Unknown type in getDataTypeCDeclaration");
1593 private void getCDeclarationString(Token t
)
1594 throws EntityException
{
1596 if (t
.isSkuEnable()) {
1597 privateGlobalName
= String
.format("%s_%s", t
.getPrimaryKeyString(), skuDataTableTemplate
);
1599 privateGlobalName
= t
.getPrimaryKeyString();
1602 if (t
.isUnicodeStringType()) {
1603 privateGlobalCCode
= String
.format("%-20s%s[%d];\r\n", "STRING_HEAD", t
.getPrimaryKeyString(), t
.getSkuIdCount());
1605 String type
= getCType(t
);
1606 if (t
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1608 if (t
.isASCIIStringType()) {
1610 // Build tool will add a NULL string at the end of the ASCII string
1612 bufferSize
= t
.datumSize
+ 1;
1614 bufferSize
= t
.datumSize
;
1616 privateGlobalCCode
= String
.format("%-20s%s[%d][%d];\r\n", type
, privateGlobalName
, t
.getSkuIdCount(), bufferSize
);
1618 privateGlobalCCode
= String
.format("%-20s%s[%d];\r\n", type
, privateGlobalName
, t
.getSkuIdCount());
1623 private String
getDataTypeDeclarationForVariableDefault_new (Token token
, String cName
, int skuId
) {
1627 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1629 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1631 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1633 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1635 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1636 typeStr
= "BOOLEAN";
1637 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1638 return String
.format("%-20s%s[%d];\r\n", cName
, token
.datumSize
);
1643 return String
.format("%-20s%s;\r\n", typeStr
, cName
);
1646 private String
getDataTypeDeclaration (Token token
) {
1648 String typeStr
= "";
1650 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1652 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1654 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1656 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1658 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1659 typeStr
= "BOOLEAN";
1660 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1661 return String
.format("UINT8 %s[%d]", token
.getPrimaryKeyString(), token
.datumSize
);
1665 return String
.format("%s %s", typeStr
, token
.getPrimaryKeyString());
1668 private String
getVpdEnableTypeDeclaration (Token token
) {
1669 return String
.format("VPD_HEAD %s", token
.getPrimaryKeyString());
1672 private String
getTypeInstantiation (Token t
, ArrayList
<CStructTypeDeclaration
> declaList
, HashMap
<String
, String
> instTable
, String phase
) throws EntityException
{
1677 s
= String
.format("/* %s */", t
.getPrimaryKeyString()) + newLine
;
1678 s
+= tab
+ "{" + newLine
;
1680 for (i
= 0; i
< t
.skuData
.size(); i
++) {
1681 if (t
.isUnicodeStringType() && !t
.isHiiEnable()) {
1682 s
+= tab
+ tab
+ String
.format("{ %d }", stringTable
.add(t
.skuData
.get(i
).value
.value
, t
));
1683 } else if (t
.isHiiEnable()) {
1684 /* VPD_HEAD definition
1686 UINT16 GuidTableIndex; // Offset in Guid Table in units of GUID.
1687 UINT16 StringIndex; // Offset in String Table in units of UINT16.
1688 UINT16 Offset; // Offset in Variable
1691 String variableDefaultName
= String
.format("%s_VariableDefault_%d", t
.getPrimaryKeyString(), i
);
1693 s
+= tab
+ tab
+ String
.format("{ %d, %d, %s, %s }", guidTable
.add(t
.skuData
.get(i
).value
.variableGuid
, t
.getPrimaryKeyString()),
1694 stringTable
.add(t
.skuData
.get(i
).value
.getStringOfVariableName(), t
),
1695 t
.skuData
.get(i
).value
.variableOffset
,
1696 String
.format("offsetof(%s_PCD_DATABASE, Init.%s)", phase
, variableDefaultName
)
1699 // We need to support the default value, so we add the declaration and
1700 // the instantiation for the default value.
1702 CStructTypeDeclaration decl
= new CStructTypeDeclaration (variableDefaultName
,
1703 getDataTypeAlignmentSize(t
),
1704 getDataTypeDeclarationForVariableDefault_new(t
, variableDefaultName
, i
),
1707 declaList
.add(decl
);
1708 instTable
.put(variableDefaultName
, getDataTypeInstantiationForVariableDefault_new (t
, variableDefaultName
, i
));
1709 } else if (t
.isVpdEnable()) {
1714 s
+= tab
+ tab
+ String
.format("{ %s }", t
.skuData
.get(i
).value
.vpdOffset
);
1716 if (t
.isByteStreamType()) {
1718 // Byte stream type input has their own "{" "}", so we won't help to insert.
1720 s
+= tab
+ tab
+ String
.format(" %s ", t
.skuData
.get(i
).value
.value
);
1722 s
+= tab
+ tab
+ String
.format("{ %s }", t
.skuData
.get(i
).value
.value
);
1726 if (i
!= t
.skuData
.size() - 1) {
1739 private String
getVpdEnableTypeInstantiation (Token token
) {
1740 return String
.format("{ %s } /* %s */", token
.getDefaultSku().vpdOffset
,
1741 token
.getPrimaryKeyString());
1744 private String
getStringTypeDeclaration (Token token
) {
1745 return String
.format("UINT16 %s", token
.getPrimaryKeyString());
1748 private String
getStringTypeInstantiation (int StringTableIdx
, Token token
) {
1749 return String
.format ("%d /* %s */", StringTableIdx
,
1750 token
.getPrimaryKeyString());
1754 private String
getVariableEnableTypeDeclaration (Token token
) {
1755 return String
.format("VARIABLE_HEAD %s", token
.getPrimaryKeyString());
1758 private String
getVariableEnableInstantiation (Token token
)
1759 throws EntityException
{
1763 return String
.format("{ %d, %d, %s } /* %s */", guidTable
.add(token
.getDefaultSku().variableGuid
, token
.getPrimaryKeyString()),
1764 stringTable
.add(token
.getDefaultSku().getStringOfVariableName(), token
),
1765 token
.getDefaultSku().variableOffset
,
1766 token
.getPrimaryKeyString());
1769 public int getTotalTokenNumber () {
1770 return sizeTable
.getTableLen();
1773 public static String
getPcdDatabaseCommonDefinitions ()
1774 throws EntityException
{
1778 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1779 "Tools" + File
.separator
+
1780 "Conf" + File
.separator
+
1781 "Pcd" + File
.separator
+
1782 "PcdDatabaseCommonDefinitions.sample");
1783 FileReader reader
= new FileReader(file
);
1784 BufferedReader in
= new BufferedReader(reader
);
1786 while ((str
= in
.readLine()) != null) {
1787 retStr
= retStr
+"\r\n" + str
;
1789 } catch (Exception ex
) {
1790 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");
1796 public static String
getPcdDxeDatabaseDefinitions ()
1797 throws EntityException
{
1801 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1802 "Tools" + File
.separator
+
1803 "Conf" + File
.separator
+
1804 "Pcd" + File
.separator
+
1805 "PcdDatabaseDxeDefinitions.sample");
1806 FileReader reader
= new FileReader(file
);
1807 BufferedReader in
= new BufferedReader(reader
);
1809 while ((str
= in
.readLine()) != null) {
1810 retStr
= retStr
+"\r\n" + str
;
1812 } catch (Exception ex
) {
1813 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");
1819 public static String
getPcdPeiDatabaseDefinitions ()
1820 throws EntityException
{
1824 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1825 "Tools" + File
.separator
+
1826 "Conf" + File
.separator
+
1827 "Pcd" + File
.separator
+
1828 "PcdDatabasePeiDefinitions.sample");
1829 FileReader reader
= new FileReader(file
);
1830 BufferedReader in
= new BufferedReader(reader
);
1832 while ((str
= in
.readLine()) != null) {
1833 retStr
= retStr
+"\r\n" + str
;
1835 } catch (Exception ex
) {
1836 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");
1845 private String type
;
1846 private FpdModuleIdentification moduleId
;
1847 private PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
;
1851 public ModuleInfo (FpdModuleIdentification moduleId
, String type
, XmlObject pcdDef
) {
1852 this.moduleId
= moduleId
;
1854 this.pcdBuildDef
= ((PcdBuildDefinitionDocument
)pcdDef
).getPcdBuildDefinition();
1856 public String
getModuleType (){
1859 public FpdModuleIdentification
getModuleId (){
1860 return this.moduleId
;
1862 public PcdBuildDefinitionDocument
.PcdBuildDefinition
getPcdBuildDef(){
1863 return this.pcdBuildDef
;
1867 /** This action class is to collect PCD information from MSA, SPD, FPD xml file.
1868 This class will be used for wizard and build tools, So it can *not* inherit
1869 from buildAction or UIAction.
1871 public class CollectPCDAction
{
1872 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.
1873 private MemoryDatabaseManager dbManager
;
1875 /// Workspacepath hold the workspace information.
1876 private String workspacePath
;
1878 /// FPD file is the root file.
1879 private String fpdFilePath
;
1881 /// Message level for CollectPCDAction.
1882 private int originalMessageLevel
;
1884 /// Cache the fpd docment instance for private usage.
1885 private PlatformSurfaceAreaDocument fpdDocInstance
;
1888 private static String xmlObjectName
= "PcdBuildDefinition";
1891 Set WorkspacePath parameter for this action class.
1893 @param workspacePath parameter for this action
1895 public void setWorkspacePath(String workspacePath
) {
1896 this.workspacePath
= workspacePath
;
1900 Set action message level for CollectPcdAction tool.
1902 The message should be restored when this action exit.
1904 @param actionMessageLevel parameter for this action
1906 public void setActionMessageLevel(int actionMessageLevel
) {
1907 originalMessageLevel
= ActionMessage
.messageLevel
;
1908 ActionMessage
.messageLevel
= actionMessageLevel
;
1912 Set FPDFileName parameter for this action class.
1914 @param fpdFilePath fpd file path
1916 public void setFPDFilePath(String fpdFilePath
) {
1917 this.fpdFilePath
= fpdFilePath
;
1921 Common function interface for outer.
1923 @param workspacePath The path of workspace of current build or analysis.
1924 @param fpdFilePath The fpd file path of current build or analysis.
1925 @param messageLevel The message level for this Action.
1927 @throws Exception The exception of this function. Because it can *not* be predict
1928 where the action class will be used. So only Exception can be throw.
1931 public void perform(String workspacePath
, String fpdFilePath
,
1932 int messageLevel
) throws Exception
{
1933 setWorkspacePath(workspacePath
);
1934 setFPDFilePath(fpdFilePath
);
1935 setActionMessageLevel(messageLevel
);
1938 ActionMessage
.messageLevel
= originalMessageLevel
;
1942 Core execution function for this action class.
1944 This function work flows will be:
1945 1) Collect and prepocess PCD information from FPD file, all PCD
1946 information will be stored into memory database.
1947 2) Generate 3 strings for
1948 a) All modules using Dynamic(Ex) PCD entry.(Token Number)
1949 b) PEI PCDDatabase (C Structure) for PCD Service PEIM.
1950 c) DXE PCD Database (C structure) for PCD Service DXE.
1953 @throws EntityException Exception indicate failed to execute this action.
1956 public void execute() throws EntityException
{
1958 // Get memoryDatabaseManager instance from GlobalData.
1959 // The memoryDatabaseManager should be initialized for whatever build
1960 // tools or wizard tools
1962 if((dbManager
= GlobalData
.getPCDMemoryDBManager()) == null) {
1963 throw new EntityException("The instance of PCD memory database manager is null");
1967 // Collect all PCD information defined in FPD file.
1968 // Evenry token defind in FPD will be created as an token into
1971 createTokenInDBFromFPD();
1974 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver
1975 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.
1977 genPcdDatabaseSourceCode ();
1982 This function generates source code for PCD Database.
1985 @throws EntityException If the token does *not* exist in memory database.
1988 private void genPcdDatabaseSourceCode()
1989 throws EntityException
{
1990 String PcdCommonHeaderString
= PcdDatabase
.getPcdDatabaseCommonDefinitions ();
1992 ArrayList
<Token
> alPei
= new ArrayList
<Token
> ();
1993 ArrayList
<Token
> alDxe
= new ArrayList
<Token
> ();
1995 dbManager
.getTwoPhaseDynamicRecordArray(alPei
, alDxe
);
1996 PcdDatabase pcdPeiDatabase
= new PcdDatabase (alPei
, "PEI", 0);
1997 pcdPeiDatabase
.genCodeNew();
1998 MemoryDatabaseManager
.PcdPeimHString
= PcdCommonHeaderString
+ pcdPeiDatabase
.getHString()
1999 + PcdDatabase
.getPcdPeiDatabaseDefinitions();
2000 MemoryDatabaseManager
.PcdPeimCString
= pcdPeiDatabase
.getCString();
2002 PcdDatabase pcdDxeDatabase
= new PcdDatabase (alDxe
,
2006 pcdDxeDatabase
.genCodeNew();
2007 MemoryDatabaseManager
.PcdDxeHString
= MemoryDatabaseManager
.PcdPeimHString
+ pcdDxeDatabase
.getHString()
2008 + PcdDatabase
.getPcdDxeDatabaseDefinitions();
2009 MemoryDatabaseManager
.PcdDxeCString
= pcdDxeDatabase
.getCString();
2013 Get component array from FPD.
2015 This function maybe provided by some Global class.
2017 @return List<ModuleInfo> the component array.
2020 private List
<ModuleInfo
> getComponentsFromFPD()
2021 throws EntityException
{
2022 List
<ModuleInfo
> allModules
= new ArrayList
<ModuleInfo
>();
2023 ModuleInfo current
= null;
2025 FrameworkModulesDocument
.FrameworkModules fModules
= null;
2026 ModuleSADocument
.ModuleSA
[] modules
= null;
2027 HashMap
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
2029 if (fpdDocInstance
== null) {
2031 fpdDocInstance
= (PlatformSurfaceAreaDocument
)XmlObject
.Factory
.parse(new File(fpdFilePath
));
2032 } catch(IOException ioE
) {
2033 throw new EntityException("File IO error for xml file:" + fpdFilePath
+ "\n" + ioE
.getMessage());
2034 } catch(XmlException xmlE
) {
2035 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath
+ "\n" + xmlE
.getMessage());
2040 Map
<FpdModuleIdentification
,XmlObject
>pcdBuildDef
= GlobalData
.getFpdModuleSaXmlObject(CollectPCDAction
.xmlObjectName
);
2041 Set
<FpdModuleIdentification
> pcdBuildKeySet
= pcdBuildDef
.keySet();
2042 Iterator item
= pcdBuildKeySet
.iterator();
2043 while (item
.hasNext()){
2044 FpdModuleIdentification id
= (FpdModuleIdentification
)item
.next();
2045 allModules
.add(new ModuleInfo(id
, id
.getModule().getModuleType(),pcdBuildDef
.get(id
)));
2052 Create token instance object into memory database, the token information
2053 comes for FPD file. Normally, FPD file will contain all token platform
2056 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.
2058 @throws EntityException Failed to parse FPD xml file.
2061 private void createTokenInDBFromFPD()
2062 throws EntityException
{
2066 List
<PcdBuildDefinition
.PcdData
> pcdBuildDataArray
= new ArrayList
<PcdBuildDefinition
.PcdData
>();
2067 PcdBuildDefinition
.PcdData pcdBuildData
= null;
2069 SkuInstance skuInstance
= null;
2071 List
<ModuleInfo
> modules
= null;
2072 String primaryKey
= null;
2073 String exceptionString
= null;
2074 UsageInstance usageInstance
= null;
2075 String primaryKey1
= null;
2076 String primaryKey2
= null;
2077 boolean isDuplicate
= false;
2078 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
2079 Token
.DATUM_TYPE datumType
= Token
.DATUM_TYPE
.UNKNOWN
;
2080 long tokenNumber
= 0;
2081 String moduleName
= null;
2082 String datum
= null;
2083 int maxDatumSize
= 0;
2084 String
[] tokenSpaceStrRet
= null;
2087 // ----------------------------------------------
2088 // 1), Get all <ModuleSA> from FPD file.
2089 // ----------------------------------------------
2091 modules
= getComponentsFromFPD();
2093 if (modules
== null) {
2094 throw new EntityException("[FPD file error] No modules in FPD file, Please check whether there are elements in <FrameworkModules> in FPD file!");
2098 // -------------------------------------------------------------------
2099 // 2), Loop all modules to process <PcdBuildDeclarations> for each module.
2100 // -------------------------------------------------------------------
2102 for (index
= 0; index
< modules
.size(); index
++) {
2103 isDuplicate
= false;
2104 for (index2
= 0; index2
< index
; index2
++) {
2106 // BUGBUG: For transition schema, we can *not* get module's version from
2107 // <ModuleSAs>, It is work around code.
2109 primaryKey1
= UsageInstance
.getPrimaryKey(modules
.get(index
).getModuleId().getModule().getName(),
2113 modules
.get(index
).getModuleId().getArch(),
2115 primaryKey2
= UsageInstance
.getPrimaryKey(modules
.get(index2
).getModuleId().getModule().getName(),
2119 modules
.get(index2
).getModuleId().getArch(),
2121 if (primaryKey1
.equalsIgnoreCase(primaryKey2
)) {
2132 // It is legal for a module does not contains ANY pcd build definitions.
2134 if (modules
.get(index
).getPcdBuildDef() == null) {
2138 pcdBuildDataArray
= modules
.get(index
).getPcdBuildDef().getPcdDataList();
2140 moduleName
= modules
.get(index
).getModuleId().getModule().getName();
2143 // ----------------------------------------------------------------------
2144 // 2.1), Loop all Pcd entry for a module and add it into memory database.
2145 // ----------------------------------------------------------------------
2147 for (pcdIndex
= 0; pcdIndex
< pcdBuildDataArray
.size(); pcdIndex
++) {
2148 pcdBuildData
= pcdBuildDataArray
.get(pcdIndex
);
2151 tokenSpaceStrRet
= GlobalData
.getGuidInfoFromCname(pcdBuildData
.getTokenSpaceGuidCName());
2152 } catch ( Exception e
) {
2153 throw new EntityException ("Faile get Guid for token " + pcdBuildData
.getCName() + ":" + e
.getMessage());
2156 if (tokenSpaceStrRet
== null) {
2157 throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData
.getCName());
2160 primaryKey
= Token
.getPrimaryKeyString(pcdBuildData
.getCName(),
2161 translateSchemaStringToUUID(tokenSpaceStrRet
[1]));
2162 pcdType
= Token
.getpcdTypeFromString(pcdBuildData
.getItemType().toString());
2163 datumType
= Token
.getdatumTypeFromString(pcdBuildData
.getDatumType().toString());
2164 tokenNumber
= Long
.decode(pcdBuildData
.getToken().toString());
2165 if (pcdBuildData
.getValue() != null) {
2166 datum
= pcdBuildData
.getValue().toString();
2170 maxDatumSize
= pcdBuildData
.getMaxDatumSize();
2172 if ((pcdType
== Token
.PCD_TYPE
.FEATURE_FLAG
) &&
2173 (datumType
!= Token
.DATUM_TYPE
.BOOLEAN
)){
2174 exceptionString
= String
.format("[FPD file error] For PCD %s in module %s, the PCD type is FEATRUE_FLAG but "+
2175 "datum type of this PCD entry is not BOOLEAN!",
2176 pcdBuildData
.getCName(),
2178 throw new EntityException(exceptionString
);
2182 // -------------------------------------------------------------------------------------------
2183 // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule
2184 // -------------------------------------------------------------------------------------------
2186 if (!Token
.isDynamic(pcdType
)) {
2188 // Value is required.
2190 if (datum
== null) {
2191 exceptionString
= String
.format("[FPD file error] There is no value for PCD entry %s in module %s!",
2192 pcdBuildData
.getCName(),
2194 throw new EntityException(exceptionString
);
2198 // Check whether the datum size is matched datum type.
2200 if ((exceptionString
= verifyDatum(pcdBuildData
.getCName(),
2204 maxDatumSize
)) != null) {
2205 throw new EntityException(exceptionString
);
2210 // ---------------------------------------------------------------------------------
2211 // 2.1.2), Create token or update token information for current anaylized PCD data.
2212 // ---------------------------------------------------------------------------------
2214 if (dbManager
.isTokenInDatabase(primaryKey
)) {
2216 // If the token is already exist in database, do some necessary checking
2217 // and add a usage instance into this token in database
2219 token
= dbManager
.getTokenByKey(primaryKey
);
2222 // checking for DatumType, DatumType should be unique for one PCD used in different
2225 if (token
.datumType
!= datumType
) {
2226 exceptionString
= String
.format("[FPD file error] The datum type of PCD entry %s is %s, which is different with %s defined in before!",
2227 pcdBuildData
.getCName(),
2228 pcdBuildData
.getDatumType().toString(),
2229 Token
.getStringOfdatumType(token
.datumType
));
2230 throw new EntityException(exceptionString
);
2234 // Check token number is valid
2236 if (tokenNumber
!= token
.tokenNumber
) {
2237 exceptionString
= String
.format("[FPD file error] The token number of PCD entry %s in module %s is different with same PCD entry in other modules!",
2238 pcdBuildData
.getCName(),
2240 throw new EntityException(exceptionString
);
2244 // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.
2246 if (token
.isDynamicPCD
!= Token
.isDynamic(pcdType
)) {
2247 exceptionString
= String
.format("[FPD file error] For PCD entry %s in module %s, you define dynamic or non-dynamic PCD type which"+
2248 "is different with others module's",
2251 throw new EntityException(exceptionString
);
2254 if (token
.isDynamicPCD
) {
2256 // Check datum is equal the datum in dynamic information.
2257 // For dynamic PCD, you can do not write <Value> in sperated every <PcdBuildDefinition> in different <ModuleSA>,
2258 // But if you write, the <Value> must be same as the value in <DynamicPcdBuildDefinitions>.
2260 if (!token
.isSkuEnable() &&
2261 (token
.getDefaultSku().type
== DynamicTokenValue
.VALUE_TYPE
.DEFAULT_TYPE
) &&
2263 if (!datum
.equalsIgnoreCase(token
.getDefaultSku().value
)) {
2264 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in module %s, the datum in <ModuleSA> is "+
2265 "not equal to the datum in <DynamicPcdBuildDefinitions>, it is "+
2266 "illega! You could no set <Value> in <ModuleSA> for a dynamic PCD!",
2269 throw new EntityException(exceptionString
);
2273 if ((maxDatumSize
!= 0) &&
2274 (maxDatumSize
!= token
.datumSize
)){
2275 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in module %s, the max datum size is %d which "+
2276 "is different with <MaxDatumSize> %d defined in <DynamicPcdBuildDefinitions>!",
2281 throw new EntityException(exceptionString
);
2287 // If the token is not in database, create a new token instance and add
2288 // a usage instance into this token in database.
2291 tokenSpaceStrRet
= GlobalData
.getGuidInfoFromCname(pcdBuildData
.getTokenSpaceGuidCName());
2292 } catch (Exception e
) {
2293 throw new EntityException("Fail to get token space guid for token " + token
.cName
);
2296 if (tokenSpaceStrRet
== null) {
2297 throw new EntityException("Fail to get token space guid for token " + token
.cName
);
2300 token
= new Token(pcdBuildData
.getCName(),
2301 translateSchemaStringToUUID(tokenSpaceStrRet
[1]));
2303 token
.datumType
= datumType
;
2304 token
.tokenNumber
= tokenNumber
;
2305 token
.isDynamicPCD
= Token
.isDynamic(pcdType
);
2306 token
.datumSize
= maxDatumSize
;
2308 if (token
.isDynamicPCD
) {
2310 // For Dynamic and Dynamic Ex type, need find the dynamic information
2311 // in <DynamicPcdBuildDefinition> section in FPD file.
2313 updateDynamicInformation(moduleName
,
2319 dbManager
.addTokenToDatabase(primaryKey
, token
);
2323 // -----------------------------------------------------------------------------------
2324 // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.
2325 // -----------------------------------------------------------------------------------
2327 token
.updateSupportPcdType(pcdType
);
2330 // ------------------------------------------------
2331 // 2.1.4), Create an usage instance for this token.
2332 // ------------------------------------------------
2334 usageInstance
= new UsageInstance(token
,
2339 CommonDefinition
.getModuleType(modules
.get(index
).getModuleType()),
2341 modules
.get(index
).getModuleId().getArch(),
2345 token
.addUsageInstance(usageInstance
);
2351 Verify the datum value according its datum size and datum type, this
2352 function maybe moved to FPD verification tools in future.
2363 public String
verifyDatum(String cName
,
2366 Token
.DATUM_TYPE datumType
,
2368 String exceptionString
= null;
2374 if (moduleName
== null) {
2375 moduleName
= "section <DynamicPcdBuildDefinitions>";
2377 moduleName
= "module " + moduleName
;
2380 if (maxDatumSize
== 0) {
2381 exceptionString
= String
.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",
2384 return exceptionString
;
2387 switch (datumType
) {
2389 if (maxDatumSize
!= 1) {
2390 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2391 "is UINT8, but datum size is %d, they are not matched!",
2395 return exceptionString
;
2398 if (datum
!= null) {
2400 value
= Integer
.decode(datum
);
2401 } catch (NumberFormatException nfeExp
) {
2402 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is not valid "+
2403 "digital format of UINT8",
2406 return exceptionString
;
2409 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+
2410 " the max size of UINT8 - 0xFF",
2414 return exceptionString
;
2419 if (maxDatumSize
!= 2) {
2420 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2421 "is UINT16, but datum size is %d, they are not matched!",
2425 return exceptionString
;
2427 if (datum
!= null) {
2429 value
= Integer
.decode(datum
);
2430 } catch (NumberFormatException nfeExp
) {
2431 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is "+
2432 "not valid digital of UINT16",
2435 return exceptionString
;
2437 if (value
> 0xFFFF) {
2438 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is %s "+
2439 "which exceed the range of UINT16 - 0xFFFF",
2443 return exceptionString
;
2448 if (maxDatumSize
!= 4) {
2449 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2450 "is UINT32, but datum size is %d, they are not matched!",
2454 return exceptionString
;
2457 if (datum
!= null) {
2459 if (datum
.length() > 2) {
2460 if ((datum
.charAt(0) == '0') &&
2461 ((datum
.charAt(1) == 'x') || (datum
.charAt(1) == 'X'))){
2462 subStr
= datum
.substring(2, datum
.length());
2463 value64
= new BigInteger(subStr
, 16);
2465 value64
= new BigInteger(datum
);
2468 value64
= new BigInteger(datum
);
2470 } catch (NumberFormatException nfeExp
) {
2471 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is not "+
2472 "valid digital of UINT32",
2475 return exceptionString
;
2478 if (value64
.bitLength() > 32) {
2479 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is %s which "+
2480 "exceed the range of UINT32 - 0xFFFFFFFF",
2484 return exceptionString
;
2489 if (maxDatumSize
!= 8) {
2490 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2491 "is UINT64, but datum size is %d, they are not matched!",
2495 return exceptionString
;
2498 if (datum
!= null) {
2500 if (datum
.length() > 2) {
2501 if ((datum
.charAt(0) == '0') &&
2502 ((datum
.charAt(1) == 'x') || (datum
.charAt(1) == 'X'))){
2503 subStr
= datum
.substring(2, datum
.length());
2504 value64
= new BigInteger(subStr
, 16);
2506 value64
= new BigInteger(datum
);
2509 value64
= new BigInteger(datum
);
2511 } catch (NumberFormatException nfeExp
) {
2512 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is not valid"+
2513 " digital of UINT64",
2516 return exceptionString
;
2519 if (value64
.bitLength() > 64) {
2520 exceptionString
= String
.format("[FPD file error] The datum for PCD %s in %s is %s "+
2521 "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",
2525 return exceptionString
;
2530 if (maxDatumSize
!= 1) {
2531 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2532 "is BOOLEAN, but datum size is %d, they are not matched!",
2536 return exceptionString
;
2539 if (datum
!= null) {
2540 if (!(datum
.equalsIgnoreCase("TRUE") ||
2541 datum
.equalsIgnoreCase("FALSE"))) {
2542 exceptionString
= String
.format("[FPD file error] The datum type of PCD data %s in %s "+
2543 "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",
2546 return exceptionString
;
2552 if (datum
== null) {
2556 char ch
= datum
.charAt(0);
2560 // For void* type PCD, only three datum is support:
2561 // 1) Unicode: string with start char is "L"
2562 // 2) Ansci: String start char is ""
2563 // 3) byte array: String start char "{"
2566 start
= datum
.indexOf('\"');
2567 end
= datum
.lastIndexOf('\"');
2568 if ((start
> end
) ||
2569 (end
> datum
.length())||
2570 ((start
== end
) && (datum
.length() > 0))) {
2571 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+
2572 "a UNICODE string because start with L\", but format maybe"+
2573 "is not right, correct UNICODE string is L\"...\"!",
2576 return exceptionString
;
2579 strValue
= datum
.substring(start
+ 1, end
);
2580 if ((strValue
.length() * 2) > maxDatumSize
) {
2581 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+
2582 "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",
2585 strValue
.length() * 2,
2587 return exceptionString
;
2589 } else if (ch
== '\"'){
2590 start
= datum
.indexOf('\"');
2591 end
= datum
.lastIndexOf('\"');
2592 if ((start
> end
) ||
2593 (end
> datum
.length())||
2594 ((start
== end
) && (datum
.length() > 0))) {
2595 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+
2596 "a ANSCII string because start with \", but format maybe"+
2597 "is not right, correct ANSIC string is \"...\"!",
2600 return exceptionString
;
2602 strValue
= datum
.substring(start
+ 1, end
);
2603 if ((strValue
.length()) > maxDatumSize
) {
2604 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+
2605 "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",
2610 return exceptionString
;
2612 } else if (ch
=='{') {
2613 String
[] strValueArray
;
2615 start
= datum
.indexOf('{');
2616 end
= datum
.lastIndexOf('}');
2617 strValue
= datum
.substring(start
+ 1, end
);
2618 strValue
= strValue
.trim();
2619 if (strValue
.length() == 0) {
2622 strValueArray
= strValue
.split(",");
2623 for (index
= 0; index
< strValueArray
.length
; index
++) {
2625 value
= Integer
.decode(strValueArray
[index
].trim());
2626 } catch (NumberFormatException nfeEx
) {
2627 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+
2628 "it is byte array in fact. For every byte in array should be a valid"+
2629 "byte digital, but element %s is not a valid byte digital!",
2632 strValueArray
[index
]);
2633 return exceptionString
;
2636 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+
2637 "it is byte array in fact. But the element of %s exceed the byte range",
2640 strValueArray
[index
]);
2641 return exceptionString
;
2645 if (strValueArray
.length
> maxDatumSize
) {
2646 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+
2647 "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",
2650 strValueArray
.length
,
2652 return exceptionString
;
2655 exceptionString
= String
.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
2656 "1) UNICODE string: like L\"xxxx\";\r\n"+
2657 "2) ANSIC string: like \"xxx\";\r\n"+
2658 "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
2659 "But the datum in seems does not following above format!",
2662 return exceptionString
;
2666 exceptionString
= String
.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+
2667 "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",
2670 return exceptionString
;
2676 Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.
2678 This function should be implemented in GlobalData in future.
2680 @param token The token instance which has hold module's PCD information
2681 @param moduleName The name of module who will use this Dynamic PCD.
2683 @return DynamicPcdBuildDefinitions.PcdBuildData
2686 private DynamicPcdBuildDefinitions
.PcdBuildData
getDynamicInfoFromFPD(Token token
,
2688 throws EntityException
{
2690 String exceptionString
= null;
2691 String dynamicPrimaryKey
= null;
2692 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions
= null;
2693 List
<DynamicPcdBuildDefinitions
.PcdBuildData
> dynamicPcdBuildDataArray
= null;
2694 String
[] tokenSpaceStrRet
= null;
2697 // If FPD document is not be opened, open and initialize it.
2699 if (fpdDocInstance
== null) {
2701 fpdDocInstance
= (PlatformSurfaceAreaDocument
)XmlObject
.Factory
.parse(new File(fpdFilePath
));
2702 } catch(IOException ioE
) {
2703 throw new EntityException("File IO error for xml file:" + fpdFilePath
+ "\n" + ioE
.getMessage());
2704 } catch(XmlException xmlE
) {
2705 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath
+ "\n" + xmlE
.getMessage());
2709 dynamicPcdBuildDefinitions
= fpdDocInstance
.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();
2710 if (dynamicPcdBuildDefinitions
== null) {
2711 exceptionString
= String
.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+
2712 "PCD entry %s in module %s!",
2715 throw new EntityException(exceptionString
);
2718 dynamicPcdBuildDataArray
= dynamicPcdBuildDefinitions
.getPcdBuildDataList();
2719 for (index
= 0; index
< dynamicPcdBuildDataArray
.size(); index
++) {
2720 //String tokenSpaceGuidString = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName())[1];
2721 String tokenSpaceGuidString
= null;
2723 tokenSpaceStrRet
= GlobalData
.getGuidInfoFromCname(dynamicPcdBuildDataArray
.get(index
).getTokenSpaceGuidCName());
2724 } catch (Exception e
) {
2725 throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray
.get(index
).getCName());
2728 if (tokenSpaceStrRet
== null) {
2729 throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray
.get(index
).getCName());
2732 dynamicPrimaryKey
= Token
.getPrimaryKeyString(dynamicPcdBuildDataArray
.get(index
).getCName(),
2733 translateSchemaStringToUUID(tokenSpaceStrRet
[1]));
2734 if (dynamicPrimaryKey
.equalsIgnoreCase(token
.getPrimaryKeyString())) {
2735 return dynamicPcdBuildDataArray
.get(index
);
2743 Update dynamic information for PCD entry.
2745 Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in
2748 @param moduleName The name of the module who use this PCD
2749 @param token The token instance
2750 @param datum The <datum> in module's PCD information
2751 @param maxDatumSize The <maxDatumSize> in module's PCD information
2755 private Token
updateDynamicInformation(String moduleName
,
2759 throws EntityException
{
2762 String exceptionString
= null;
2763 DynamicTokenValue dynamicValue
;
2764 SkuInstance skuInstance
= null;
2766 boolean hasSkuId0
= false;
2767 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
2768 long tokenNumber
= 0;
2769 String hiiDefaultValue
= null;
2770 String
[] variableGuidString
= null;
2772 List
<DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> skuInfoList
= null;
2773 DynamicPcdBuildDefinitions
.PcdBuildData dynamicInfo
= null;
2775 dynamicInfo
= getDynamicInfoFromFPD(token
, moduleName
);
2776 if (dynamicInfo
== null) {
2777 exceptionString
= String
.format("[FPD file error] For Dynamic PCD %s used by module %s, "+
2778 "there is no dynamic information in <DynamicPcdBuildDefinitions> "+
2779 "in FPD file, but it is required!",
2782 throw new EntityException(exceptionString
);
2785 token
.datumSize
= dynamicInfo
.getMaxDatumSize();
2787 exceptionString
= verifyDatum(token
.cName
,
2792 if (exceptionString
!= null) {
2793 throw new EntityException(exceptionString
);
2796 if ((maxDatumSize
!= 0) &&
2797 (maxDatumSize
!= token
.datumSize
)) {
2798 exceptionString
= String
.format("FPD file error] For dynamic PCD %s, the datum size in module %s is %d, but "+
2799 "the datum size in <DynamicPcdBuildDefinitions> is %d, they are not match!",
2803 dynamicInfo
.getMaxDatumSize());
2804 throw new EntityException(exceptionString
);
2806 tokenNumber
= Long
.decode(dynamicInfo
.getToken().toString());
2807 if (tokenNumber
!= token
.tokenNumber
) {
2808 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s, the token number in module %s is 0x%x, but"+
2809 "in <DynamicPcdBuildDefinictions>, the token number is 0x%x, they are not match!",
2814 throw new EntityException(exceptionString
);
2817 pcdType
= Token
.getpcdTypeFromString(dynamicInfo
.getItemType().toString());
2818 if (pcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
2819 token
.dynamicExTokenNumber
= tokenNumber
;
2822 skuInfoList
= dynamicInfo
.getSkuInfoList();
2825 // Loop all sku data
2827 for (index
= 0; index
< skuInfoList
.size(); index
++) {
2828 skuInstance
= new SkuInstance();
2830 // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.
2832 temp
= skuInfoList
.get(index
).getSkuId().toString();
2833 skuInstance
.id
= Integer
.decode(temp
);
2834 if (skuInstance
.id
== 0) {
2838 // Judge whether is DefaultGroup at first, because most case is DefautlGroup.
2840 if (skuInfoList
.get(index
).getValue() != null) {
2841 skuInstance
.value
.setValue(skuInfoList
.get(index
).getValue().toString());
2842 if ((exceptionString
= verifyDatum(token
.cName
,
2844 skuInfoList
.get(index
).getValue().toString(),
2846 token
.datumSize
)) != null) {
2847 throw new EntityException(exceptionString
);
2850 token
.skuData
.add(skuInstance
);
2853 // Judege wether is same of datum between module's information
2854 // and dynamic information.
2856 if (datum
!= null) {
2857 if ((skuInstance
.id
== 0) &&
2858 !datum
.toString().equalsIgnoreCase(skuInfoList
.get(index
).getValue().toString())) {
2859 exceptionString
= "[FPD file error] For dynamic PCD " + token
.cName
+ ", the value in module " + moduleName
+ " is " + datum
.toString() + " but the "+
2860 "value of sku 0 data in <DynamicPcdBuildDefinition> is " + skuInstance
.value
.value
+ ". They are must be same!"+
2861 " or you could not define value for a dynamic PCD in every <ModuleSA>!";
2862 throw new EntityException(exceptionString
);
2869 // Judge whether is HII group case.
2871 if (skuInfoList
.get(index
).getVariableName() != null) {
2872 exceptionString
= null;
2873 if (skuInfoList
.get(index
).getVariableGuid() == null) {
2874 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
2875 "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",
2878 if (exceptionString
!= null) {
2879 throw new EntityException(exceptionString
);
2883 if (skuInfoList
.get(index
).getVariableOffset() == null) {
2884 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
2885 "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",
2888 if (exceptionString
!= null) {
2889 throw new EntityException(exceptionString
);
2893 if (skuInfoList
.get(index
).getHiiDefaultValue() == null) {
2894 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
2895 "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",
2898 if (exceptionString
!= null) {
2899 throw new EntityException(exceptionString
);
2903 if (skuInfoList
.get(index
).getHiiDefaultValue() != null) {
2904 hiiDefaultValue
= skuInfoList
.get(index
).getHiiDefaultValue().toString();
2906 hiiDefaultValue
= null;
2909 if ((exceptionString
= verifyDatum(token
.cName
,
2913 token
.datumSize
)) != null) {
2914 throw new EntityException(exceptionString
);
2917 offset
= Integer
.decode(skuInfoList
.get(index
).getVariableOffset());
2918 if (offset
> 0xFFFF) {
2919 throw new EntityException(String
.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+
2920 "exceed 64K, it is not allowed!",
2926 // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.
2928 variableGuidString
= GlobalData
.getGuidInfoFromCname(skuInfoList
.get(index
).getVariableGuid().toString());
2929 if (variableGuidString
== null) {
2930 throw new EntityException(String
.format("[GUID Error] For dynamic PCD %s, the variable guid %s can be found in all SPD file!",
2932 skuInfoList
.get(index
).getVariableGuid().toString()));
2934 String variableStr
= skuInfoList
.get(index
).getVariableName();
2935 Pattern pattern
= Pattern
.compile("0x([a-fA-F0-9]){4}");
2936 Matcher matcher
= pattern
.matcher(variableStr
);
2937 List
<String
> varNameList
= new ArrayList
<String
>();
2938 while (matcher
.find()){
2939 String str
= variableStr
.substring(matcher
.start(),matcher
.end());
2940 varNameList
.add(str
);
2943 skuInstance
.value
.setHiiData(varNameList
,
2944 translateSchemaStringToUUID(variableGuidString
[1]),
2945 skuInfoList
.get(index
).getVariableOffset(),
2946 skuInfoList
.get(index
).getHiiDefaultValue().toString());
2947 token
.skuData
.add(skuInstance
);
2951 if (skuInfoList
.get(index
).getVpdOffset() != null) {
2952 skuInstance
.value
.setVpdData(skuInfoList
.get(index
).getVpdOffset());
2953 token
.skuData
.add(skuInstance
);
2957 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+
2958 "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",
2960 throw new EntityException(exceptionString
);
2964 exceptionString
= String
.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+
2965 "no sku id = 0 data, which is required for every dynamic PCD",
2967 throw new EntityException(exceptionString
);
2974 Translate the schema string to UUID instance.
2976 In schema, the string of UUID is defined as following two types string:
2977 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(
2978 )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?
2980 2) GuidNamingConvention: pattern =
2981 [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}
2983 This function will convert string and create uuid instance.
2985 @param uuidString UUID string in XML file
2987 @return UUID UUID instance
2989 private UUID
translateSchemaStringToUUID(String uuidString
)
2990 throws EntityException
{
2992 String
[] splitStringArray
;
2997 if (uuidString
== null) {
3001 if (uuidString
.length() == 0) {
3005 if (uuidString
.equals("0") ||
3006 uuidString
.equalsIgnoreCase("0x0")) {
3007 return new UUID(0, 0);
3010 uuidString
= uuidString
.replaceAll("\\{", "");
3011 uuidString
= uuidString
.replaceAll("\\}", "");
3014 // If the UUID schema string is GuidArrayType type then need translate
3015 // to GuidNamingConvention type at first.
3017 if ((uuidString
.charAt(0) == '0') && ((uuidString
.charAt(1) == 'x') || (uuidString
.charAt(1) == 'X'))) {
3018 splitStringArray
= uuidString
.split("," );
3019 if (splitStringArray
.length
!= 11) {
3020 throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString
);
3024 // Remove blank space from these string and remove header string "0x"
3026 for (index
= 0; index
< 11; index
++) {
3027 splitStringArray
[index
] = splitStringArray
[index
].trim();
3028 splitStringArray
[index
] = splitStringArray
[index
].substring(2, splitStringArray
[index
].length());
3032 // Add heading '0' to normalize the string length
3034 for (index
= 3; index
< 11; index
++) {
3035 chLen
= splitStringArray
[index
].length();
3036 for (chIndex
= 0; chIndex
< 2 - chLen
; chIndex
++) {
3037 splitStringArray
[index
] = "0" + splitStringArray
[index
];
3042 // construct the final GuidNamingConvention string
3044 temp
= String
.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",
3045 splitStringArray
[0],
3046 splitStringArray
[1],
3047 splitStringArray
[2],
3048 splitStringArray
[3],
3049 splitStringArray
[4],
3050 splitStringArray
[5],
3051 splitStringArray
[6],
3052 splitStringArray
[7],
3053 splitStringArray
[8],
3054 splitStringArray
[9],
3055 splitStringArray
[10]);
3059 return UUID
.fromString(uuidString
);
3063 check parameter for this action.
3065 @throws EntityException Bad parameter.
3067 private void checkParameter() throws EntityException
{
3070 if((fpdFilePath
== null) ||(workspacePath
== null)) {
3071 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
3074 if(fpdFilePath
.length() == 0 || workspacePath
.length() == 0) {
3075 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
3078 file
= new File(workspacePath
);
3079 if(!file
.exists()) {
3080 throw new EntityException("WorkpacePath " + workspacePath
+ " does not exist!");
3083 file
= new File(fpdFilePath
);
3085 if(!file
.exists()) {
3086 throw new EntityException("FPD File " + fpdFilePath
+ " does not exist!");
3093 @param argv parameter from command line
3095 public static void main(String argv
[]) throws EntityException
{
3096 CollectPCDAction ca
= new CollectPCDAction();
3097 ca
.setWorkspacePath("m:/tianocore/edk2");
3098 ca
.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");
3099 ca
.setActionMessageLevel(ActionMessage
.MAX_MESSAGE_LEVEL
);
3100 // GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",
3101 // "m:/tianocore/edk2");