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
.util
.ArrayList
;
25 import java
.util
.Collections
;
26 import java
.util
.Comparator
;
27 import java
.util
.HashMap
;
28 import java
.util
.List
;
30 import java
.util
.UUID
;
32 import org
.apache
.xmlbeans
.XmlException
;
33 import org
.apache
.xmlbeans
.XmlObject
;
34 import org
.tianocore
.FrameworkPlatformDescriptionDocument
;
35 import org
.tianocore
.ModuleSADocument
;
36 import org
.tianocore
.PackageSurfaceAreaDocument
;
37 import org
.tianocore
.PcdBuildDeclarationsDocument
.PcdBuildDeclarations
.PcdBuildData
;
38 import org
.tianocore
.PcdDefinitionsDocument
.PcdDefinitions
;
39 import org
.tianocore
.build
.autogen
.CommonDefinition
;
40 import org
.tianocore
.build
.global
.GlobalData
;
41 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
42 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
43 import org
.tianocore
.build
.pcd
.entity
.MemoryDatabaseManager
;
44 import org
.tianocore
.build
.pcd
.entity
.SkuInstance
;
45 import org
.tianocore
.build
.pcd
.entity
.Token
;
46 import org
.tianocore
.build
.pcd
.entity
.UsageInstance
;
47 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
50 private ArrayList
<String
> al
;
51 private ArrayList
<String
> alComments
;
57 public StringTable (String phase
) {
59 al
= new ArrayList
<String
>();
60 alComments
= new ArrayList
<String
>();
66 public String
getSizeMacro () {
67 return String
.format(PcdDatabase
.StringTableSizeMacro
, phase
, getSize());
70 private int getSize () {
72 // We have at least one Unicode Character in the table.
74 return len
== 0 ?
1 : len
;
77 public int getTableLen () {
78 return al
.size() == 0 ?
1 : al
.size();
81 public String
getExistanceMacro () {
82 return String
.format(PcdDatabase
.StringTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
85 public String
getTypeDeclaration () {
89 final String stringTable
= "StringTable";
90 final String tab
= "\t";
91 final String newLine
= ";\r\n";
93 output
= "/* StringTable */\r\n";
96 output
+= tab
+ String
.format("UINT16 %s[1] /* StringTable is Empty */", stringTable
) + newLine
;
99 for (int i
= 0; i
< al
.size(); i
++) {
100 String str
= al
.get(i
);
104 // StringTable is a well-known name in the PCD DXE driver
106 output
+= tab
+ String
.format("UINT16 %s[%d] /* %s */", stringTable
, str
.length() + 1, alComments
.get(i
)) + newLine
;
108 output
+= tab
+ String
.format("UINT16 %s_%d[%d] /* %s */", stringTable
, i
, str
.length() + 1, alComments
.get(i
)) + newLine
;
116 public ArrayList
<String
> getInstantiation () {
117 ArrayList
<String
> output
= new ArrayList
<String
>();
119 output
.add("/* StringTable */");
121 if (al
.size() == 0) {
126 for (int i
= 0; i
< al
.size(); i
++) {
127 str
= String
.format("L\"%s\" /* %s */", al
.get(i
), alComments
.get(i
));
128 if (i
!= al
.size() - 1) {
138 public int add (String str
, Token token
) {
143 // Include the NULL character at the end of String
145 len
+= str
.length() + 1;
147 alComments
.add(token
.getPrimaryKeyString());
154 private ArrayList
<Integer
> al
;
155 private ArrayList
<String
> alComments
;
156 private String phase
;
158 private int bodyStart
;
159 private int bodyLineNum
;
161 public SizeTable (String phase
) {
163 al
= new ArrayList
<Integer
>();
164 alComments
= new ArrayList
<String
>();
170 public String
getTypeDeclaration () {
171 return String
.format(PcdDatabase
.SizeTableDeclaration
, phase
);
174 public ArrayList
<String
> getInstantiation () {
175 ArrayList
<String
> Output
= new ArrayList
<String
>();
177 Output
.add("/* SizeTable */");
181 if (al
.size() == 0) {
184 for (int index
= 0; index
< al
.size(); index
++) {
185 Integer n
= al
.get(index
);
186 String str
= n
.toString();
188 if (index
!= (al
.size() - 1)) {
192 str
+= " /* " + alComments
.get(index
) + " */";
203 public int getBodyStart() {
207 public int getBodyLineNum () {
211 public int add (Token token
) {
215 al
.add(token
.datumSize
);
216 alComments
.add(token
.getPrimaryKeyString());
221 private int getDatumSize(Token token
) {
223 switch (token.datumType) {
224 case Token.DATUM_TYPE.UINT8:
233 public int getTableLen () {
234 return al
.size() == 0 ?
1 : al
.size();
240 private ArrayList
<UUID
> al
;
241 private ArrayList
<String
> alComments
;
242 private String phase
;
244 private int bodyStart
;
245 private int bodyLineNum
;
247 public GuidTable (String phase
) {
249 al
= new ArrayList
<UUID
>();
250 alComments
= new ArrayList
<String
>();
256 public String
getSizeMacro () {
257 return String
.format(PcdDatabase
.GuidTableSizeMacro
, phase
, getSize());
260 private int getSize () {
261 return (al
.size() == 0)?
1 : al
.size();
264 public String
getExistanceMacro () {
265 return String
.format(PcdDatabase
.GuidTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
268 public String
getTypeDeclaration () {
269 return String
.format(PcdDatabase
.GuidTableDeclaration
, phase
);
272 private String
getUuidCString (UUID uuid
) {
273 String
[] guidStrArray
;
275 guidStrArray
=(uuid
.toString()).split("-");
277 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 } }",
281 (guidStrArray
[3].substring(0, 2)),
282 (guidStrArray
[3].substring(2, 4)),
283 (guidStrArray
[4].substring(0, 2)),
284 (guidStrArray
[4].substring(2, 4)),
285 (guidStrArray
[4].substring(4, 6)),
286 (guidStrArray
[4].substring(6, 8)),
287 (guidStrArray
[4].substring(8, 10)),
288 (guidStrArray
[4].substring(10, 12))
292 public ArrayList
<String
> getInstantiation () {
293 ArrayList
<String
> Output
= new ArrayList
<String
>();
295 Output
.add("/* GuidTable */");
299 if (al
.size() == 0) {
300 Output
.add(getUuidCString(new UUID(0, 0)));
303 for (Object u
: al
) {
305 String str
= getUuidCString(uuid
);
307 if (al
.indexOf(u
) != (al
.size() - 1)) {
319 public int getBodyStart() {
323 public int getBodyLineNum () {
327 public int add (UUID uuid
, String name
) {
330 // Include the NULL character at the end of String
338 public int getTableLen () {
339 return al
.size() == 0 ?
0 : al
.size();
345 private ArrayList
<Integer
[]> al
;
346 private ArrayList
<String
> alComment
;
347 private String phase
;
349 private int bodyStart
;
350 private int bodyLineNum
;
352 public SkuIdTable (String phase
) {
354 al
= new ArrayList
<Integer
[]>();
355 alComment
= new ArrayList
<String
>();
361 public String
getSizeMacro () {
362 return String
.format(PcdDatabase
.SkuIdTableSizeMacro
, phase
, getSize());
365 private int getSize () {
366 return (al
.size() == 0)?
1 : al
.size();
369 public String
getExistanceMacro () {
370 return String
.format(PcdDatabase
.SkuTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
373 public String
getTypeDeclaration () {
374 return String
.format(PcdDatabase
.SkuIdTableDeclaration
, phase
);
377 public ArrayList
<String
> getInstantiation () {
378 ArrayList
<String
> Output
= new ArrayList
<String
> ();
380 Output
.add("/* SkuIdTable */");
384 if (al
.size() == 0) {
388 for (int index
= 0; index
< al
.size(); index
++) {
391 str
= "/* " + alComment
.get(index
) + "*/ ";
392 str
+= "/* MaxSku */ ";
395 Integer
[] ia
= al
.get(index
);
397 str
+= ia
[0].toString() + ", ";
398 for (int index2
= 1; index2
< ia
.length
; index2
++) {
399 str
+= ia
[index2
].toString();
400 if (index
!= al
.size() - 1) {
415 public int add (Token token
) {
419 Integer
[] skuIds
= new Integer
[token
.maxSkuCount
+ 1];
420 skuIds
[0] = new Integer(token
.maxSkuCount
);
421 for (index
= 1; index
< skuIds
.length
; index
++) {
422 skuIds
[index
] = new Integer(token
.skuData
.get(index
- 1).id
);
427 len
+= skuIds
.length
;
429 alComment
.add(token
.getPrimaryKeyString());
434 public int getTableLen () {
435 return al
.size() == 0 ?
1 : al
.size();
440 class LocalTokenNumberTable
{
441 private ArrayList
<String
> al
;
442 private ArrayList
<String
> alComment
;
443 private String phase
;
445 private int bodyStart
;
446 private int bodyLineNum
;
448 public LocalTokenNumberTable (String phase
) {
450 al
= new ArrayList
<String
>();
451 alComment
= new ArrayList
<String
>();
458 public String
getSizeMacro () {
459 return String
.format(PcdDatabase
.LocalTokenNumberTableSizeMacro
, phase
, getSize());
462 public int getSize () {
463 return (al
.size() == 0)?
1 : al
.size();
466 public String
getExistanceMacro () {
467 return String
.format(PcdDatabase
.DatabaseExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
470 public String
getTypeDeclaration () {
471 return String
.format(PcdDatabase
.LocalTokenNumberTableDeclaration
, phase
);
474 public ArrayList
<String
> getInstantiation () {
475 ArrayList
<String
> output
= new ArrayList
<String
>();
477 output
.add("/* LocalTokenNumberTable */");
481 if (al
.size() == 0) {
485 for (int index
= 0; index
< al
.size(); index
++) {
488 str
= (String
)al
.get(index
);
490 str
+= " /* " + alComment
.get(index
) + " */ ";
493 if (index
!= (al
.size() - 1)) {
501 bodyLineNum
= al
.size();
508 public int add (Token token
) {
514 str
= String
.format(PcdDatabase
.offsetOfStrTemplate
, phase
, token
.hasDefaultValue() ?
"Init" : "Uninit", token
.getPrimaryKeyString());
516 if (token
.isStringType()) {
517 str
+= " | PCD_TYPE_STRING";
520 if (token
.skuEnabled
) {
521 str
+= " | PCD_TYPE_SKU_ENABLED";
524 if (token
.hiiEnabled
) {
525 str
+= " | PCD_TYPE_HII";
528 if (token
.vpdEnabled
) {
529 str
+= " | PCD_TYPE_VPD";
533 alComment
.add(token
.getPrimaryKeyString());
542 public Integer guidTableIdx
;
543 public Long exTokenNumber
;
544 public Long localTokenIdx
;
546 public ExTriplet (int guidTableIdx
, long exTokenNumber
, long localTokenIdx
) {
547 this.guidTableIdx
= new Integer(guidTableIdx
);
548 this.exTokenNumber
= new Long(exTokenNumber
);
549 this.localTokenIdx
= new Long(localTokenIdx
);
553 private ArrayList
<ExTriplet
> al
;
554 private ArrayList
<String
> alComment
;
555 private String phase
;
557 private int bodyStart
;
558 private int bodyLineNum
;
561 public ExMapTable (String phase
) {
563 al
= new ArrayList
<ExTriplet
>();
564 alComment
= new ArrayList
<String
>();
570 public String
getSizeMacro () {
571 return String
.format(PcdDatabase
.ExMapTableSizeMacro
, phase
, getTableLen())
572 + String
.format(PcdDatabase
.ExTokenNumber
, phase
, al
.size());
575 private int getSize () {
576 return (al
.size() == 0)?
1 : al
.size();
579 public String
getExistanceMacro () {
580 return String
.format(PcdDatabase
.ExMapTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
583 public String
getTypeDeclaration () {
584 return String
.format(PcdDatabase
.ExMapTableDeclaration
, phase
);
587 public ArrayList
<String
> getInstantiation () {
588 ArrayList
<String
> Output
= new ArrayList
<String
>();
590 Output
.add("/* ExMapTable */");
594 if (al
.size() == 0) {
595 Output
.add("{0, 0, 0}");
599 for (index
= 0; index
< al
.size(); index
++) {
602 ExTriplet e
= (ExTriplet
)al
.get(index
);
604 str
= "{ " + e
.exTokenNumber
.toString() + ", ";
605 str
+= e
.localTokenIdx
.toString() + ", ";
606 str
+= e
.guidTableIdx
.toString();
608 str
+= " /* " + alComment
.get(index
) + " */";
610 if (index
!= al
.size() - 1) {
624 public int add (int localTokenIdx
, long exTokenNum
, int guidTableIdx
, String name
) {
628 al
.add(new ExTriplet(guidTableIdx
, exTokenNum
, localTokenIdx
));
634 public int getTableLen () {
635 return al
.size() == 0 ?
1 : al
.size();
642 public final static String ExMapTableDeclaration
= "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";
643 public final static String GuidTableDeclaration
= "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";
644 public final static String LocalTokenNumberTableDeclaration
= "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER];\r\n";
645 public final static String StringTableDeclaration
= "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";
646 public final static String SizeTableDeclaration
= "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER];\r\n";
647 public final static String SkuIdTableDeclaration
= "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";
650 public final static String ExMapTableSizeMacro
= "#define %s_EXMAPPING_TABLE_SIZE %d\r\n";
651 public final static String ExTokenNumber
= "#define %s_EX_TOKEN_NUMBER %d\r\n";
652 public final static String GuidTableSizeMacro
= "#define %s_GUID_TABLE_SIZE %d\r\n";
653 public final static String LocalTokenNumberTableSizeMacro
= "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";
654 public final static String StringTableSizeMacro
= "#define %s_STRING_TABLE_SIZE %d\r\n";
655 public final static String SkuIdTableSizeMacro
= "#define %s_SKUID_TABLE_SIZE %d\r\n";
658 public final static String ExMapTableExistenceMacro
= "#define %s_EXMAP_TABLE_EMPTY %s\r\n";
659 public final static String GuidTableExistenceMacro
= "#define %s_GUID_TABLE_EMPTY %s\r\n";
660 public final static String DatabaseExistenceMacro
= "#define %s_DATABASE_EMPTY %s\r\n";
661 public final static String StringTableExistenceMacro
= "#define %s_STRING_TABLE_EMPTY %s\r\n";
662 public final static String SkuTableExistenceMacro
= "#define %s_SKUID_TABLE_EMPTY %s\r\n";
664 public final static String offsetOfSkuHeadStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";
665 public final static String offsetOfStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s)";
667 private StringTable stringTable
;
668 private GuidTable guidTable
;
669 private LocalTokenNumberTable localTokenNumberTable
;
670 private SkuIdTable skuIdTable
;
671 private SizeTable sizeTable
;
672 private ExMapTable exMapTable
;
674 private ArrayList
<Token
> alTokens
;
675 private String phase
;
676 private int assignedTokenNumber
;
679 // After Major changes done to the PCD
680 // database generation class PcdDatabase
681 // Please increment the version and please
682 // also update the version number in PCD
683 // service PEIM and DXE driver accordingly.
685 private final int version
= 1;
687 private String hString
;
688 private String cString
;
691 class AlignmentSizeComp
implements Comparator
<Token
> {
692 public int compare (Token a
, Token b
) {
693 return getAlignmentSize(b
)
694 - getAlignmentSize(a
);
698 public PcdDatabase (ArrayList
<Token
> alTokens
, String exePhase
, int startLen
) {
701 stringTable
= new StringTable(phase
);
702 guidTable
= new GuidTable(phase
);
703 localTokenNumberTable
= new LocalTokenNumberTable(phase
);
704 skuIdTable
= new SkuIdTable(phase
);
705 sizeTable
= new SizeTable(phase
);
706 exMapTable
= new ExMapTable(phase
);
708 assignedTokenNumber
= startLen
;
709 this.alTokens
= alTokens
;
712 private void getTwoGroupsOfTokens (ArrayList
<Token
> alTokens
, List
<Token
> initTokens
, List
<Token
> uninitTokens
) {
713 for (int i
= 0; i
< alTokens
.size(); i
++) {
714 Token t
= alTokens
.get(i
);
715 if (t
.hasDefaultValue()) {
725 private int getAlignmentSize (Token token
) {
726 if (token
.hiiEnabled
) {
730 if (token
.vpdEnabled
) {
734 if (token
.isStringType()) {
738 switch (token
.datumType
) {
755 public String
getCString () {
759 public String
getHString () {
763 public void genCode () {
765 final String newLine
= "\r\n";
766 final String declNewLine
= ";\r\n";
767 final String tab
= "\t";
768 final String commaNewLine
= ", \r\n";
771 ArrayList
<String
> decla
;
772 ArrayList
<String
> inst
;
774 String macroStr
= "";
775 String initDeclStr
= "";
776 String initInstStr
= "";
777 String uninitDeclStr
= "";
779 List
<Token
> initTokens
= new ArrayList
<Token
> ();
780 List
<Token
> uninitTokens
= new ArrayList
<Token
> ();
782 HashMap
<String
, ArrayList
<String
>> initCode
= new HashMap
<String
, ArrayList
<String
>> ();
783 HashMap
<String
, ArrayList
<String
>> uninitCode
= new HashMap
<String
, ArrayList
<String
>> ();
785 getTwoGroupsOfTokens (alTokens
, initTokens
, uninitTokens
);
788 // Generate Structure Declaration for PcdTokens without Default Value
789 // PEI_PCD_DATABASE_INIT
791 java
.util
.Comparator
<Token
> comparator
= new AlignmentSizeComp();
792 java
.util
.Collections
.sort(initTokens
, comparator
);
793 initCode
= processTokens(initTokens
);
796 // Generate Structure Declaration for PcdTokens without Default Value
797 // PEI_PCD_DATABASE_UNINIT
799 java
.util
.Collections
.sort(uninitTokens
, comparator
);
800 uninitCode
= processTokens(uninitTokens
);
803 // Generate size info Macro for all Tables
805 macroStr
+= guidTable
.getSizeMacro();
806 macroStr
+= stringTable
.getSizeMacro();
807 macroStr
+= skuIdTable
.getSizeMacro();
808 macroStr
+= localTokenNumberTable
.getSizeMacro();
809 macroStr
+= exMapTable
.getSizeMacro();
812 // Generate existance info Macro for all Tables
814 macroStr
+= guidTable
.getExistanceMacro();
815 macroStr
+= stringTable
.getExistanceMacro();
816 macroStr
+= skuIdTable
.getExistanceMacro();
817 macroStr
+= localTokenNumberTable
.getExistanceMacro();
818 macroStr
+= exMapTable
.getExistanceMacro();
821 // Generate Structure Declaration for PcdTokens with Default Value
822 // for example PEI_PCD_DATABASE_INIT
824 initDeclStr
+= "typedef struct {" + newLine
;
826 initDeclStr
+= tab
+ exMapTable
.getTypeDeclaration();
827 initDeclStr
+= tab
+ guidTable
.getTypeDeclaration();
828 initDeclStr
+= tab
+ localTokenNumberTable
.getTypeDeclaration();
829 initDeclStr
+= tab
+ stringTable
.getTypeDeclaration();
830 initDeclStr
+= tab
+ sizeTable
.getTypeDeclaration();
831 initDeclStr
+= tab
+ skuIdTable
.getTypeDeclaration();
832 if (phase
.equalsIgnoreCase("PEI")) {
833 initDeclStr
+= tab
+ "SKU_ID SystemSkuId;" + newLine
;
836 decla
= initCode
.get(new String("Declaration"));
837 for (i
= 0; i
< decla
.size(); i
++) {
838 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
842 // Generate Structure Declaration for PcdToken with SkuEnabled
844 decla
= initCode
.get("DeclarationForSku");
846 for (i
= 0; i
< decla
.size(); i
++) {
847 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
850 initDeclStr
+= String
.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase
);
853 // Generate MACRO for structure intialization of PCDTokens with Default Value
854 // The sequence must match the sequence of declaration of the memembers in the structure
855 String tmp
= String
.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase
.toUpperCase(), phase
.toUpperCase());
856 initInstStr
+= tmp
+ newLine
;
857 initInstStr
+= tab
+ genInstantiationStr(exMapTable
.getInstantiation()) + commaNewLine
;
858 initInstStr
+= tab
+ genInstantiationStr(guidTable
.getInstantiation()) + commaNewLine
;
859 initInstStr
+= tab
+ genInstantiationStr(localTokenNumberTable
.getInstantiation()) + commaNewLine
;
860 initInstStr
+= tab
+ genInstantiationStr(stringTable
.getInstantiation()) + commaNewLine
;
861 initInstStr
+= tab
+ genInstantiationStr(sizeTable
.getInstantiation()) + commaNewLine
;
862 initInstStr
+= tab
+ genInstantiationStr(skuIdTable
.getInstantiation()) + commaNewLine
;
866 if (phase
.equalsIgnoreCase("PEI")) {
867 initInstStr
+= tab
+ "0" + tab
+ "/* SystemSkuId */" + commaNewLine
;
870 inst
= initCode
.get("Instantiation");
871 for (i
= 0; i
< inst
.size(); i
++) {
872 initInstStr
+= tab
+ inst
.get(i
) + commaNewLine
;
875 inst
= initCode
.get("InstantiationForSku");
876 for (i
= 0; i
< inst
.size(); i
++) {
877 initInstStr
+= tab
+ inst
.get(i
);
878 if (i
!= inst
.size() - 1) {
879 initInstStr
+= commaNewLine
;
885 uninitDeclStr
+= "typedef struct {" + newLine
;
887 decla
= uninitCode
.get("Declaration");
888 if (decla
.size() == 0) {
889 uninitDeclStr
+= "UINT8 dummy /* The UINT struct is empty */" + declNewLine
;
892 for (i
= 0; i
< decla
.size(); i
++) {
893 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
896 decla
= uninitCode
.get("DeclarationForSku");
898 for (i
= 0; i
< decla
.size(); i
++) {
899 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
903 uninitDeclStr
+= String
.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase
);
905 cString
= initInstStr
+ newLine
;
906 hString
= macroStr
+ newLine
907 + initDeclStr
+ newLine
908 + uninitDeclStr
+ newLine
911 hString
+= String
.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase
, version
);
915 private String
genInstantiationStr (ArrayList
<String
> alStr
) {
917 for (int i
= 0; i
< alStr
.size(); i
++) {
918 str
+= "\t" + alStr
.get(i
);
919 if (i
!= alStr
.size() - 1) {
927 private HashMap
<String
, ArrayList
<String
>> processTokens (List
<Token
> alToken
) {
929 HashMap
<String
, ArrayList
<String
>> map
= new HashMap
<String
, ArrayList
<String
>>();
931 ArrayList
<String
> decl
= new ArrayList
<String
>();
932 ArrayList
<String
> declForSkuEnableType
= new ArrayList
<String
>();
933 ArrayList
<String
> inst
= new ArrayList
<String
>();
934 ArrayList
<String
> instForSkuEnableType
= new ArrayList
<String
>();
936 for (int index
= 0; index
< alToken
.size(); index
++) {
937 Token token
= alToken
.get(index
);
939 if (token
.skuEnabled
) {
941 // BugBug: Schema only support Data type now
945 tableIdx
= skuIdTable
.add(token
);
947 decl
.add(getSkuEnabledTypeDeclaration(token
));
948 if (token
.hasDefaultValue()) {
949 inst
.add(getSkuEnabledTypeInstantiaion(token
, tableIdx
));
952 declForSkuEnableType
.add(getDataTypeDeclarationForSkuEnabled(token
));
953 if (token
.hasDefaultValue()) {
954 instForSkuEnableType
.add(getDataTypeInstantiationForSkuEnabled(token
));
958 if (token
.hiiEnabled
) {
959 decl
.add(getVariableEnableTypeDeclaration(token
));
960 inst
.add(getVariableEnableInstantiation(token
));
961 } else if (token
.vpdEnabled
) {
962 decl
.add(getVpdEnableTypeDeclaration(token
));
963 inst
.add(getVpdEnableTypeInstantiation(token
));
964 } else if (token
.isStringType()) {
965 decl
.add(getStringTypeDeclaration(token
));
966 inst
.add(getStringTypeInstantiation(stringTable
.add(token
.getStringTypeString(), token
), token
));
969 decl
.add(getDataTypeDeclaration(token
));
970 if (token
.hasDefaultValue()) {
971 inst
.add(getDataTypeInstantiation(token
));
976 sizeTable
.add(token
);
977 localTokenNumberTable
.add(token
);
978 token
.assignedtokenNumber
= assignedTokenNumber
++;
982 map
.put("Declaration", decl
);
983 map
.put("DeclarationForSku", declForSkuEnableType
);
984 map
.put("Instantiation", inst
);
985 map
.put("InstantiationForSku", instForSkuEnableType
);
990 private String
getSkuEnabledTypeDeclaration (Token token
) {
991 return String
.format("SKU_HEAD %s;\r\n", token
.getPrimaryKeyString());
994 private String
getSkuEnabledTypeInstantiaion (Token token
, int SkuTableIdx
) {
996 String offsetof
= String
.format(PcdDatabase
.offsetOfSkuHeadStrTemplate
, phase
, token
.hasDefaultValue()?
"Init" : "Uninit", token
.getPrimaryKeyString());
997 return String
.format("{ %s, %d }", offsetof
, SkuTableIdx
);
1000 private String
getDataTypeDeclarationForSkuEnabled (Token token
) {
1001 String typeStr
= "";
1003 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1004 typeStr
= "UINT8 %s_%s[%d];\r\n";
1005 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1006 typeStr
= "UINT16 %s_%s[%d];\r\n";
1007 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1008 typeStr
= "UINT32 %s_%s[%d];\r\n";
1009 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1010 typeStr
= "UINT64 %s_%s[%d];\r\n";
1011 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1012 typeStr
= "BOOLEAN %s_%s[%d];\r\n";
1013 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1014 return String
.format("UINT8 %s_s[%d];\r\n", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.maxSkuCount
);
1017 return String
.format(typeStr
, token
.getPrimaryKeyString(), "SkuDataTable", token
.maxSkuCount
);
1021 private String
getDataTypeInstantiationForSkuEnabled (Token token
) {
1024 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1025 return String
.format("UINT8 %s_s[%d]", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.maxSkuCount
);
1028 for (int idx
= 0; idx
< token
.maxSkuCount
; idx
++) {
1029 str
+= token
.skuData
.get(idx
).toString();
1030 if (idx
!= token
.maxSkuCount
- 1) {
1041 private String
getDataTypeInstantiation (Token token
) {
1043 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1044 return String
.format("%s /* %s */", token
.datum
.toString(), token
.getPrimaryKeyString());
1046 return String
.format("%s /* %s */", token
.datum
.toString(), token
.getPrimaryKeyString());
1051 private String
getDataTypeDeclaration (Token token
) {
1053 String typeStr
= "";
1055 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1057 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1059 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1061 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1063 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1064 typeStr
= "BOOLEAN";
1065 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1066 return String
.format("UINT8 %s[%d]", token
.getPrimaryKeyString(), token
.datumSize
);
1070 return String
.format("%s %s", typeStr
, token
.getPrimaryKeyString());
1073 private String
getVpdEnableTypeDeclaration (Token token
) {
1074 return String
.format("VPD_HEAD %s", token
.getPrimaryKeyString());
1077 private String
getVpdEnableTypeInstantiation (Token token
) {
1078 return String
.format("{ %d } /* %s */", token
.vpdOffset
,
1079 token
.getPrimaryKeyString());
1082 private String
getStringTypeDeclaration (Token token
) {
1083 return String
.format("UINT16 %s", token
.getPrimaryKeyString());
1086 private String
getStringTypeInstantiation (int StringTableIdx
, Token token
) {
1087 return String
.format ("%d /* %s */", StringTableIdx
,
1088 token
.getPrimaryKeyString());
1092 private String
getVariableEnableTypeDeclaration (Token token
) {
1093 return String
.format("VARIABLE_HEAD %s", token
.getPrimaryKeyString());
1096 private String
getVariableEnableInstantiation (Token token
) {
1097 return String
.format("{ %d, %d, %d } /* %s */", guidTable
.add(token
.variableGuid
, token
.getPrimaryKeyString()),
1098 stringTable
.add(token
.variableName
, token
),
1099 token
.variableOffset
,
1100 token
.getPrimaryKeyString());
1103 public int getTotalTokenNumber () {
1104 return sizeTable
.getTableLen();
1107 public static String
getPcdDatabaseCommonDefinitions ()
1108 throws EntityException
{
1112 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1113 "Tools" + File
.separator
+
1114 "Conf" + File
.separator
+
1115 "Pcd" + File
.separator
+
1116 "PcdDatabaseCommonDefinitions.sample");
1117 System
.out
.println(GlobalData
.getWorkspacePath());
1118 FileReader reader
= new FileReader(file
);
1119 BufferedReader in
= new BufferedReader(reader
);
1121 while ((str
= in
.readLine()) != null) {
1122 retStr
= retStr
+"\r\n" + str
;
1124 } catch (Exception ex
) {
1125 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");
1131 public static String
getPcdDxeDatabaseDefinitions ()
1132 throws EntityException
{
1136 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1137 "Tools" + File
.separator
+
1138 "Conf" + File
.separator
+
1139 "Pcd" + File
.separator
+
1140 "PcdDatabaseDxeDefinitions.sample");
1141 FileReader reader
= new FileReader(file
);
1142 BufferedReader in
= new BufferedReader(reader
);
1144 while ((str
= in
.readLine()) != null) {
1145 retStr
= retStr
+"\r\n" + str
;
1147 } catch (Exception ex
) {
1148 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");
1154 public static String
getPcdPeiDatabaseDefinitions ()
1155 throws EntityException
{
1159 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1160 "Tools" + File
.separator
+
1161 "Conf" + File
.separator
+
1162 "Pcd" + File
.separator
+
1163 "PcdDatabasePeiDefinitions.sample");
1164 FileReader reader
= new FileReader(file
);
1165 BufferedReader in
= new BufferedReader(reader
);
1167 while ((str
= in
.readLine()) != null) {
1168 retStr
= retStr
+"\r\n" + str
;
1170 } catch (Exception ex
) {
1171 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");
1179 /** This action class is to collect PCD information from MSA, SPD, FPD xml file.
1180 This class will be used for wizard and build tools, So it can *not* inherit
1181 from buildAction or UIAction.
1183 public class CollectPCDAction
{
1184 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.
1185 private MemoryDatabaseManager dbManager
;
1187 /// Workspacepath hold the workspace information.
1188 private String workspacePath
;
1190 /// FPD file is the root file.
1191 private String fpdFilePath
;
1193 /// Message level for CollectPCDAction.
1194 private int originalMessageLevel
;
1197 Set WorkspacePath parameter for this action class.
1199 @param workspacePath parameter for this action
1201 public void setWorkspacePath(String workspacePath
) {
1202 this.workspacePath
= workspacePath
;
1206 Set action message level for CollectPcdAction tool.
1208 The message should be restored when this action exit.
1210 @param actionMessageLevel parameter for this action
1212 public void setActionMessageLevel(int actionMessageLevel
) {
1213 originalMessageLevel
= ActionMessage
.messageLevel
;
1214 ActionMessage
.messageLevel
= actionMessageLevel
;
1218 Set FPDFileName parameter for this action class.
1220 @param fpdFilePath fpd file path
1222 public void setFPDFilePath(String fpdFilePath
) {
1223 this.fpdFilePath
= fpdFilePath
;
1227 Common function interface for outer.
1229 @param workspacePath The path of workspace of current build or analysis.
1230 @param fpdFilePath The fpd file path of current build or analysis.
1231 @param messageLevel The message level for this Action.
1233 @throws Exception The exception of this function. Because it can *not* be predict
1234 where the action class will be used. So only Exception can be throw.
1237 public void perform(String workspacePath
, String fpdFilePath
,
1238 int messageLevel
) throws Exception
{
1239 setWorkspacePath(workspacePath
);
1240 setFPDFilePath(fpdFilePath
);
1241 setActionMessageLevel(messageLevel
);
1244 ActionMessage
.messageLevel
= originalMessageLevel
;
1248 Core execution function for this action class.
1250 This function work flows will be:
1251 1) Get all token's platform information from FPD, and create token object into memory database.
1252 2) Get all token's module information from MSA, and create usage instance for every module's PCD entry.
1253 3) Get all token's inherited information from MSA's library, and create usage instance
1254 for module who consume this library and create usage instance for library for building.
1255 4) Collect token's package information from SPD, update these information for token in memory
1257 5) Generate 3 strings for a) All modules using Dynamic(Ex) PCD entry. (Token Number)
1258 b) PEI PCD Database (C Structure) for PCD Service PEIM
1259 c) DXE PCD Database (C structure) for PCD Service DXE
1262 @throws EntityException Exception indicate failed to execute this action.
1265 private void execute() throws EntityException
{
1266 FrameworkPlatformDescriptionDocument fpdDoc
= null;
1267 Object
[][] modulePCDArray
= null;
1268 Map
<String
, XmlObject
> docMap
= null;
1269 ModuleSADocument
.ModuleSA
[] moduleSAs
= null;
1270 UsageInstance usageInstance
= null;
1271 String packageName
= null;
1272 String packageFullPath
= null;
1274 int libraryIndex
= 0;
1275 int pcdArrayIndex
= 0;
1276 List
<String
> listLibraryInstance
= null;
1277 String componentTypeStr
= null;
1280 // Collect all PCD information defined in FPD file.
1281 // Evenry token defind in FPD will be created as an token into
1284 fpdDoc
= createTokenInDBFromFPD();
1287 // Searching MSA and SPD document.
1288 // The information of MSA will be used to create usage instance into database.
1289 // The information of SPD will be used to update the token information in database.
1292 HashMap
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
1293 map
.put("FrameworkPlatformDescription", fpdDoc
);
1294 SurfaceAreaQuery
.setDoc(map
);
1296 moduleSAs
= SurfaceAreaQuery
.getFpdModules();
1297 for(index
= 0; index
< moduleSAs
.length
; index
++) {
1299 // Get module document and use SurfaceAreaQuery to get PCD information
1301 docMap
= GlobalData
.getDoc(moduleSAs
[index
].getModuleName());
1302 SurfaceAreaQuery
.setDoc(docMap
);
1303 modulePCDArray
= SurfaceAreaQuery
.getModulePCDTokenArray();
1304 componentTypeStr
= SurfaceAreaQuery
.getComponentType();
1306 GlobalData
.getPackageNameForModule(moduleSAs
[index
].getModuleName());
1307 packageFullPath
= this.workspacePath
+ File
.separator
+
1308 GlobalData
.getPackagePath(packageName
) +
1309 packageName
+ ".spd";
1311 if(modulePCDArray
!= null) {
1313 // If current MSA contains <PCDs> information, then create usage
1314 // instance for PCD information from MSA
1316 for(pcdArrayIndex
= 0; pcdArrayIndex
< modulePCDArray
.length
;
1319 createUsageInstanceFromMSA(moduleSAs
[index
].getModuleName(),
1320 modulePCDArray
[pcdArrayIndex
]);
1322 if(usageInstance
== null) {
1326 // Get remaining PCD information from the package which this module belongs to
1328 updateTokenBySPD(usageInstance
, packageFullPath
);
1333 // Get inherit PCD information which inherit from library instance of this module.
1335 listLibraryInstance
=
1336 SurfaceAreaQuery
.getLibraryInstance(moduleSAs
[index
].getArch().toString(),
1337 CommonDefinition
.AlwaysConsumed
);
1338 if(listLibraryInstance
!= null) {
1339 for(libraryIndex
= 0; libraryIndex
< listLibraryInstance
.size();
1341 inheritPCDFromLibraryInstance(listLibraryInstance
.get(libraryIndex
),
1342 moduleSAs
[index
].getModuleName(),
1350 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver
1351 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.
1353 genPcdDatabaseSourceCode ();
1358 This function generates source code for PCD Database.
1361 @throws EntityException If the token does *not* exist in memory database.
1365 private void genPcdDatabaseSourceCode ()
1366 throws EntityException
{
1367 String PcdCommonHeaderString
= PcdDatabase
.getPcdDatabaseCommonDefinitions ();
1369 ArrayList
<Token
> alPei
= new ArrayList
<Token
> ();
1370 ArrayList
<Token
> alDxe
= new ArrayList
<Token
> ();
1372 dbManager
.getTwoPhaseDynamicRecordArray(alPei
, alDxe
);
1373 PcdDatabase pcdPeiDatabase
= new PcdDatabase (alPei
, "PEI", 0);
1374 pcdPeiDatabase
.genCode();
1375 dbManager
.PcdPeimHString
= PcdCommonHeaderString
+ pcdPeiDatabase
.getHString()
1376 + PcdDatabase
.getPcdPeiDatabaseDefinitions();
1377 dbManager
.PcdPeimCString
= pcdPeiDatabase
.getCString();
1379 PcdDatabase pcdDxeDatabase
= new PcdDatabase (alDxe
,
1383 pcdDxeDatabase
.genCode();
1384 dbManager
.PcdDxeHString
= dbManager
.PcdPeimHString
+ pcdDxeDatabase
.getHString()
1385 + PcdDatabase
.getPcdDxeDatabaseDefinitions();
1386 dbManager
.PcdDxeCString
= pcdDxeDatabase
.getCString();
1390 This function will collect inherit PCD information from library for a module.
1392 This function will create two usage instance for inherited PCD token, one is
1393 for module and another is for library.
1394 For module, if it inherited a PCD token from library, this PCD token's value
1395 should be instanced in module level, and belongs to module.
1396 For library, it also need a usage instance for build.
1398 @param libraryName The name of library instance.
1399 @param moduleName The name of module.
1400 @param packageName The name of package while module belongs to.
1401 @param parentcomponentType The component type of module.
1403 @throws EntityException If the token does *not* exist in memory database.
1406 private void inheritPCDFromLibraryInstance(String libraryName
,
1409 String parentcomponentType
)
1410 throws EntityException
{
1411 Map
<String
, XmlObject
> docMap
= null;
1412 String primaryKeyString
= null;
1413 Object
[][] libPcdDataArray
= null;
1414 UUID nullUUID
= new UUID(0,0);
1415 UUID platformUUID
= nullUUID
;
1416 UUID tokenSpaceGuid
= null;
1419 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
1420 UsageInstance usageInstance
= null;
1421 String packageFullPath
= null;
1424 // Query PCD information from library's document.
1426 docMap
= GlobalData
.getDoc(libraryName
);
1427 SurfaceAreaQuery
.setDoc(docMap
);
1428 libPcdDataArray
= SurfaceAreaQuery
.getModulePCDTokenArray();
1430 if(libPcdDataArray
== null) {
1434 for(tokenIndex
= 0; tokenIndex
< libPcdDataArray
.length
; tokenIndex
++) {
1435 tokenSpaceGuid
=((UUID
)libPcdDataArray
[tokenIndex
][2] == null) ?
1436 nullUUID
:(UUID
)libPcdDataArray
[tokenIndex
][2];
1439 // Get token from memory database. The token must be created from FPD already.
1441 primaryKeyString
= Token
.getPrimaryKeyString((String
)libPcdDataArray
[tokenIndex
][0],
1446 if(dbManager
.isTokenInDatabase(primaryKeyString
)) {
1447 token
= dbManager
.getTokenByKey(primaryKeyString
);
1449 throw new EntityException("The PCD token " + primaryKeyString
+
1450 " defined in module " + moduleName
+
1451 " does not exist in FPD file!");
1455 // Create usage instance for module.
1457 pcdType
= Token
.getpcdTypeFromString((String
)libPcdDataArray
[tokenIndex
][1]);
1458 usageInstance
= new UsageInstance(token
,
1459 Token
.PCD_USAGE
.ALWAYS_CONSUMED
,
1461 CommonDefinition
.getComponentType(parentcomponentType
),
1462 libPcdDataArray
[tokenIndex
][3],
1464 (String
) libPcdDataArray
[tokenIndex
][5],
1469 if(Token
.PCD_USAGE
.UNKNOWN
== token
.isUsageInstanceExist(moduleName
)) {
1470 token
.addUsageInstance(usageInstance
);
1472 packageFullPath
= this.workspacePath
+ File
.separator
+
1473 GlobalData
.getPackagePath(packageName
) +
1474 packageName
+ ".spd";
1475 updateTokenBySPD(usageInstance
, packageFullPath
);
1479 // We need create second usage instance for inherited case, which
1480 // add library as an usage instance, because when build a module, and
1481 // if module inherited from base library, then build process will build
1482 // library at first.
1484 if(Token
.PCD_USAGE
.UNKNOWN
== token
.isUsageInstanceExist(libraryName
)) {
1485 packageName
= GlobalData
.getPackageNameForModule(libraryName
);
1486 usageInstance
= new UsageInstance(token
,
1487 Token
.PCD_USAGE
.ALWAYS_CONSUMED
,
1489 CommonDefinition
.ComponentTypeLibrary
,
1490 libPcdDataArray
[tokenIndex
][3],
1492 (String
)libPcdDataArray
[tokenIndex
][5],
1497 token
.addUsageInstance(usageInstance
);
1503 Create usage instance for PCD token defined in MSA document
1505 A PCD token maybe used by many modules, and every module is one of usage
1506 instance of this token. For ALWAY_CONSUMED, SOMETIMES_CONSUMED, it is
1507 consumer type usage instance of this token, and for ALWAYS_PRODUCED,
1508 SOMETIMES_PRODUCED, it is produce type usage instance.
1510 @param moduleName The name of module
1511 @param tokenInfoInMsa The PCD token information array retrieved from MSA.
1513 @return UsageInstance The usage instance created in memroy database.
1515 @throws EntityException If token did not exist in database yet.
1518 private UsageInstance
createUsageInstanceFromMSA(String moduleName
,
1519 Object
[] tokenInfoInMsa
)
1520 throws EntityException
{
1521 String packageName
= null;
1522 UsageInstance usageInstance
= null;
1523 UUID tokenSpaceGuid
= null;
1524 UUID nullUUID
= new UUID(0,0);
1525 String primaryKeyString
= null;
1526 UUID platformTokenSpace
= nullUUID
;
1528 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
1529 Token
.PCD_USAGE pcdUsage
= Token
.PCD_USAGE
.UNKNOWN
;
1531 tokenSpaceGuid
=((UUID
)tokenInfoInMsa
[2] == null) ? nullUUID
:(UUID
)tokenInfoInMsa
[2];
1533 primaryKeyString
= Token
.getPrimaryKeyString((String
)tokenInfoInMsa
[0],
1535 platformTokenSpace
);
1538 // Get token object from memory database firstly.
1540 if(dbManager
.isTokenInDatabase(primaryKeyString
)) {
1541 token
= dbManager
.getTokenByKey(primaryKeyString
);
1543 throw new EntityException("The PCD token " + primaryKeyString
+ " defined in module " +
1544 moduleName
+ " does not exist in FPD file!" );
1546 pcdType
= Token
.getpcdTypeFromString((String
)tokenInfoInMsa
[1]);
1547 pcdUsage
= Token
.getUsageFromString((String
)tokenInfoInMsa
[4]);
1549 packageName
= GlobalData
.getPackageNameForModule(moduleName
);
1551 if(Token
.PCD_USAGE
.UNKNOWN
!= token
.isUsageInstanceExist(moduleName
)) {
1553 // BUGBUG: It is legal that same base name exist in one FPD file. In furture
1554 // we should use "Guid, Version, Package" and "Arch" to differ a module.
1555 // So currently, warning should be disabled.
1557 //ActionMessage.warning(this,
1558 // "In module " + moduleName + " exist more than one PCD token " + token.cName
1564 // BUGBUG: following code could be enabled at current schema. Because
1565 // current schema does not provide usage information.
1567 // For FEATRURE_FLAG, FIXED_AT_BUILD, PATCH_IN_MODULE type PCD token, his
1568 // usage is always ALWAYS_CONSUMED
1570 //if((pcdType != Token.PCD_TYPE.DYNAMIC) &&
1571 // (pcdType != Token.PCD_TYPE.DYNAMIC_EX)) {
1572 pcdUsage
= Token
.PCD_USAGE
.ALWAYS_CONSUMED
;
1575 usageInstance
= new UsageInstance(token
,
1578 CommonDefinition
.getComponentType(SurfaceAreaQuery
.getComponentType()),
1581 (String
) tokenInfoInMsa
[5],
1588 // Use default value defined in MSA to update datum of token,
1589 // if datum of token does not defined in FPD file.
1591 if((token
.datum
== null) &&(tokenInfoInMsa
[3] != null)) {
1592 token
.datum
= tokenInfoInMsa
[3];
1595 token
.addUsageInstance(usageInstance
);
1597 return usageInstance
;
1601 Create token instance object into memory database, the token information
1602 comes for FPD file. Normally, FPD file will contain all token platform
1605 This fucntion should be executed at firsly before others collection work
1606 such as searching token information from MSA, SPD.
1608 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.
1610 @throws EntityException Failed to parse FPD xml file.
1613 private FrameworkPlatformDescriptionDocument
createTokenInDBFromFPD()
1614 throws EntityException
{
1615 XmlObject doc
= null;
1616 FrameworkPlatformDescriptionDocument fpdDoc
= null;
1618 List
<PcdBuildData
> pcdBuildDataArray
= new ArrayList
<PcdBuildData
>();
1619 PcdBuildData pcdBuildData
= null;
1621 UUID nullUUID
= new UUID(0,0);
1622 UUID platformTokenSpace
= nullUUID
;
1623 List skuDataArray
= new ArrayList();
1624 SkuInstance skuInstance
= null;
1628 // Get all tokens from FPD file and create token into database.
1632 doc
= XmlObject
.Factory
.parse(new File(fpdFilePath
));
1633 } catch(IOException ioE
) {
1634 throw new EntityException("Can't find the FPD xml fle:" + fpdFilePath
);
1635 } catch(XmlException xmlE
) {
1636 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath
);
1640 // Get memoryDatabaseManager instance from GlobalData.
1642 if((dbManager
= GlobalData
.getPCDMemoryDBManager()) == null) {
1643 throw new EntityException("The instance of PCD memory database manager is null");
1646 dbManager
= new MemoryDatabaseManager();
1648 if(!(doc
instanceof FrameworkPlatformDescriptionDocument
)) {
1649 throw new EntityException("File " + fpdFilePath
+
1650 " is not a FrameworkPlatformDescriptionDocument");
1653 fpdDoc
=(FrameworkPlatformDescriptionDocument
)doc
;
1656 // Add all tokens in FPD into Memory Database.
1659 fpdDoc
.getFrameworkPlatformDescription().getPcdBuildDeclarations().getPcdBuildDataList();
1661 index
< fpdDoc
.getFrameworkPlatformDescription().getPcdBuildDeclarations().sizeOfPcdBuildDataArray();
1663 pcdBuildData
= pcdBuildDataArray
.get(index
);
1664 token
= new Token(pcdBuildData
.getCName(), new UUID(0, 0), new UUID(0, 0));
1666 // BUGBUG: in FPD, <defaultValue> should be defined as <Value>
1668 token
.datum
= pcdBuildData
.getDefaultValue();
1669 token
.tokenNumber
= Integer
.decode(pcdBuildData
.getToken().getStringValue());
1670 token
.hiiEnabled
= pcdBuildData
.getHiiEnable();
1671 token
.variableGuid
= Token
.getGUIDFromSchemaObject(pcdBuildData
.getVariableGuid());
1672 token
.variableName
= pcdBuildData
.getVariableName();
1673 token
.variableOffset
= Integer
.decode(pcdBuildData
.getDataOffset());
1674 token
.skuEnabled
= pcdBuildData
.getSkuEnable();
1675 token
.maxSkuCount
= Integer
.decode(pcdBuildData
.getMaxSku());
1676 token
.skuId
= Integer
.decode(pcdBuildData
.getSkuId());
1677 token
.skuDataArrayEnabled
= pcdBuildData
.getSkuDataArrayEnable();
1678 token
.assignedtokenNumber
= Integer
.decode(pcdBuildData
.getToken().getStringValue());
1679 skuDataArray
= pcdBuildData
.getSkuDataArray1();
1680 token
.datumType
= Token
.getdatumTypeFromString(pcdBuildData
.getDatumType().toString());
1681 token
.datumSize
= pcdBuildData
.getDatumSize();
1683 if(skuDataArray
!= null) {
1684 for(skuIndex
= 0; skuIndex
< skuDataArray
.size(); skuIndex
++) {
1686 // BUGBUG: Now in current schema, The value is defined as String type,
1687 // it is not correct, the type should be same as the datumType
1689 skuInstance
= new SkuInstance(((PcdBuildData
.SkuData
)skuDataArray
.get(skuIndex
)).getId(),
1690 ((PcdBuildData
.SkuData
)skuDataArray
.get(skuIndex
)).getValue());
1691 token
.skuData
.add(skuInstance
);
1695 if(dbManager
.isTokenInDatabase(Token
.getPrimaryKeyString(token
.cName
,
1696 token
.tokenSpaceName
,
1697 platformTokenSpace
))) {
1699 // If found duplicate token, Should tool be hold?
1701 ActionMessage
.warning(this,
1702 "Token " + token
.cName
+ " exists in token database");
1705 token
.pcdType
= Token
.getpcdTypeFromString(pcdBuildData
.getItemType().toString());
1706 dbManager
.addTokenToDatabase(Token
.getPrimaryKeyString(token
.cName
,
1707 token
.tokenSpaceName
,
1708 platformTokenSpace
),
1716 Update PCD token in memory database by help information in SPD.
1718 After create token from FPD and create usage instance from MSA, we should collect
1719 PCD package level information from SPD and update token information in memory
1722 @param usageInstance The usage instance defined in MSA and want to search in SPD.
1723 @param packageFullPath The SPD file path.
1725 @throws EntityException Failed to parse SPD xml file.
1728 private void updateTokenBySPD(UsageInstance usageInstance
,
1729 String packageFullPath
)
1730 throws EntityException
{
1731 PackageSurfaceAreaDocument pkgDoc
= null;
1732 PcdDefinitions pcdDefinitions
= null;
1733 List
<PcdDefinitions
.PcdEntry
> pcdEntryArray
= new ArrayList
<PcdDefinitions
.PcdEntry
>();
1735 boolean isFoundInSpd
= false;
1736 Token
.DATUM_TYPE datumType
= Token
.DATUM_TYPE
.UNKNOWN
;
1739 pkgDoc
=(PackageSurfaceAreaDocument
)XmlObject
.Factory
.parse(new File(packageFullPath
));
1740 } catch(IOException ioE
) {
1741 throw new EntityException("Can't find the FPD xml fle:" + packageFullPath
);
1742 } catch(XmlException xmlE
) {
1743 throw new EntityException("Can't parse the FPD xml fle:" + packageFullPath
);
1745 pcdDefinitions
= pkgDoc
.getPackageSurfaceArea().getPcdDefinitions();
1747 // It is illege for SPD file does not contains any PCD information.
1749 if (pcdDefinitions
== null) {
1753 pcdEntryArray
= pcdDefinitions
.getPcdEntryList();
1754 if (pcdEntryArray
== null) {
1757 for(index
= 0; index
< pcdEntryArray
.size(); index
++) {
1758 if(pcdEntryArray
.get(index
).getCName().equalsIgnoreCase(
1759 usageInstance
.parentToken
.cName
)) {
1760 isFoundInSpd
= true;
1762 // From SPD file , we can get following information.
1763 // Token: Token number defined in package level.
1764 // PcdItemType: This item does not single one. It means all supported item type.
1765 // datumType: UINT8, UNIT16, UNIT32, UINT64, VOID*, BOOLEAN
1766 // datumSize: The size of default value or maxmine size.
1767 // defaultValue: This value is defined in package level.
1768 // HelpText: The help text is provided in package level.
1771 usageInstance
.parentToken
.tokenNumber
= Integer
.decode(pcdEntryArray
.get(index
).getToken());
1773 if(pcdEntryArray
.get(index
).getDatumType() != null) {
1774 datumType
= Token
.getdatumTypeFromString(
1775 pcdEntryArray
.get(index
).getDatumType().toString());
1776 if(usageInstance
.parentToken
.datumType
== Token
.DATUM_TYPE
.UNKNOWN
) {
1777 usageInstance
.parentToken
.datumType
= datumType
;
1779 if(datumType
!= usageInstance
.parentToken
.datumType
) {
1780 throw new EntityException("Different datum types are defined for Token :" +
1781 usageInstance
.parentToken
.cName
);
1786 throw new EntityException("The datum type for token " + usageInstance
.parentToken
.cName
+
1787 " is not defind in SPD file " + packageFullPath
);
1790 usageInstance
.defaultValueInSPD
= pcdEntryArray
.get(index
).getDefaultValue();
1791 usageInstance
.helpTextInSPD
= "Help Text in SPD";
1794 // If token's datum is not valid, it indicate that datum is not provided
1795 // in FPD and defaultValue is not provided in MSA, then use defaultValue
1796 // in SPD as the datum of token.
1798 if(usageInstance
.parentToken
.datum
== null) {
1799 if(pcdEntryArray
.get(index
).getDefaultValue() != null) {
1800 usageInstance
.parentToken
.datum
= pcdEntryArray
.get(index
).getDefaultValue();
1802 throw new EntityException("FPD does not provide datum for token " + usageInstance
.parentToken
.cName
+
1803 ", MSA and SPD also does not provide <defaultValue> for this token!");
1811 check parameter for this action.
1813 @throws EntityException Bad parameter.
1815 private void checkParameter() throws EntityException
{
1818 if((fpdFilePath
== null) ||(workspacePath
== null)) {
1819 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
1822 if(fpdFilePath
.length() == 0 || workspacePath
.length() == 0) {
1823 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
1826 file
= new File(workspacePath
);
1827 if(!file
.exists()) {
1828 throw new EntityException("WorkpacePath " + workspacePath
+ " does not exist!");
1831 file
= new File(fpdFilePath
);
1833 if(!file
.exists()) {
1834 throw new EntityException("FPD File " + fpdFilePath
+ " does not exist!");
1841 @param argv parameter from command line
1843 public static void main(String argv
[]) throws EntityException
{
1844 CollectPCDAction ca
= new CollectPCDAction();
1845 ca
.setWorkspacePath("G:/mdk");
1846 ca
.setFPDFilePath("G:/mdk/EdkNt32Pkg/build/Nt32.fpd");
1847 ca
.setActionMessageLevel(ActionMessage
.MAX_MESSAGE_LEVEL
);
1848 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db",