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
;
446 public LocalTokenNumberTable (String phase
) {
448 al
= new ArrayList
<String
>();
449 alComment
= new ArrayList
<String
>();
454 public String
getSizeMacro () {
455 return String
.format(PcdDatabase
.LocalTokenNumberTableSizeMacro
, phase
, getSize())
456 + String
.format(PcdDatabase
.LocalTokenNumberSizeMacro
, phase
, al
.size());
459 public int getSize () {
460 return (al
.size() == 0)?
1 : al
.size();
463 public String
getExistanceMacro () {
464 return String
.format(PcdDatabase
.DatabaseExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
467 public String
getTypeDeclaration () {
468 return String
.format(PcdDatabase
.LocalTokenNumberTableDeclaration
, phase
);
471 public ArrayList
<String
> getInstantiation () {
472 ArrayList
<String
> output
= new ArrayList
<String
>();
474 output
.add("/* LocalTokenNumberTable */");
477 if (al
.size() == 0) {
481 for (int index
= 0; index
< al
.size(); index
++) {
484 str
= (String
)al
.get(index
);
486 str
+= " /* " + alComment
.get(index
) + " */ ";
489 if (index
!= (al
.size() - 1)) {
502 public int add (Token token
) {
508 str
= String
.format(PcdDatabase
.offsetOfStrTemplate
, phase
, token
.hasDefaultValue() ?
"Init" : "Uninit", token
.getPrimaryKeyString());
510 if (token
.isStringType()) {
511 str
+= " | PCD_TYPE_STRING";
514 if (token
.skuEnabled
) {
515 str
+= " | PCD_TYPE_SKU_ENABLED";
518 if (token
.hiiEnabled
) {
519 str
+= " | PCD_TYPE_HII";
522 if (token
.vpdEnabled
) {
523 str
+= " | PCD_TYPE_VPD";
527 alComment
.add(token
.getPrimaryKeyString());
536 public Integer guidTableIdx
;
537 public Long exTokenNumber
;
538 public Long localTokenIdx
;
540 public ExTriplet (int guidTableIdx
, long exTokenNumber
, long localTokenIdx
) {
541 this.guidTableIdx
= new Integer(guidTableIdx
);
542 this.exTokenNumber
= new Long(exTokenNumber
);
543 this.localTokenIdx
= new Long(localTokenIdx
);
547 private ArrayList
<ExTriplet
> al
;
548 private ArrayList
<String
> alComment
;
549 private String phase
;
551 private int bodyStart
;
552 private int bodyLineNum
;
555 public ExMapTable (String phase
) {
557 al
= new ArrayList
<ExTriplet
>();
558 alComment
= new ArrayList
<String
>();
564 public String
getSizeMacro () {
565 return String
.format(PcdDatabase
.ExMapTableSizeMacro
, phase
, getTableLen())
566 + String
.format(PcdDatabase
.ExTokenNumber
, phase
, al
.size());
569 private int getSize () {
570 return (al
.size() == 0)?
1 : al
.size();
573 public String
getExistanceMacro () {
574 return String
.format(PcdDatabase
.ExMapTableExistenceMacro
, phase
, (al
.size() == 0)?
"TRUE":"FALSE");
577 public String
getTypeDeclaration () {
578 return String
.format(PcdDatabase
.ExMapTableDeclaration
, phase
);
581 public ArrayList
<String
> getInstantiation () {
582 ArrayList
<String
> Output
= new ArrayList
<String
>();
584 Output
.add("/* ExMapTable */");
588 if (al
.size() == 0) {
589 Output
.add("{0, 0, 0}");
593 for (index
= 0; index
< al
.size(); index
++) {
596 ExTriplet e
= (ExTriplet
)al
.get(index
);
598 str
= "{ " + e
.exTokenNumber
.toString() + ", ";
599 str
+= e
.localTokenIdx
.toString() + ", ";
600 str
+= e
.guidTableIdx
.toString();
602 str
+= " /* " + alComment
.get(index
) + " */";
604 if (index
!= al
.size() - 1) {
618 public int add (int localTokenIdx
, long exTokenNum
, int guidTableIdx
, String name
) {
622 al
.add(new ExTriplet(guidTableIdx
, exTokenNum
, localTokenIdx
));
628 public int getTableLen () {
629 return al
.size() == 0 ?
1 : al
.size();
636 public final static String ExMapTableDeclaration
= "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";
637 public final static String GuidTableDeclaration
= "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";
638 public final static String LocalTokenNumberTableDeclaration
= "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";
639 public final static String StringTableDeclaration
= "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";
640 public final static String SizeTableDeclaration
= "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";
641 public final static String SkuIdTableDeclaration
= "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";
644 public final static String ExMapTableSizeMacro
= "#define %s_EXMAPPING_TABLE_SIZE %d\r\n";
645 public final static String ExTokenNumber
= "#define %s_EX_TOKEN_NUMBER %d\r\n";
646 public final static String GuidTableSizeMacro
= "#define %s_GUID_TABLE_SIZE %d\r\n";
647 public final static String LocalTokenNumberTableSizeMacro
= "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE %d\r\n";
648 public final static String LocalTokenNumberSizeMacro
= "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";
649 public final static String StringTableSizeMacro
= "#define %s_STRING_TABLE_SIZE %d\r\n";
650 public final static String SkuIdTableSizeMacro
= "#define %s_SKUID_TABLE_SIZE %d\r\n";
653 public final static String ExMapTableExistenceMacro
= "#define %s_EXMAP_TABLE_EMPTY %s\r\n";
654 public final static String GuidTableExistenceMacro
= "#define %s_GUID_TABLE_EMPTY %s\r\n";
655 public final static String DatabaseExistenceMacro
= "#define %s_DATABASE_EMPTY %s\r\n";
656 public final static String StringTableExistenceMacro
= "#define %s_STRING_TABLE_EMPTY %s\r\n";
657 public final static String SkuTableExistenceMacro
= "#define %s_SKUID_TABLE_EMPTY %s\r\n";
659 public final static String offsetOfSkuHeadStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";
660 public final static String offsetOfStrTemplate
= "offsetof(%s_PCD_DATABASE, %s.%s)";
662 private StringTable stringTable
;
663 private GuidTable guidTable
;
664 private LocalTokenNumberTable localTokenNumberTable
;
665 private SkuIdTable skuIdTable
;
666 private SizeTable sizeTable
;
667 private ExMapTable exMapTable
;
669 private ArrayList
<Token
> alTokens
;
670 private String phase
;
671 private int assignedTokenNumber
;
674 // After Major changes done to the PCD
675 // database generation class PcdDatabase
676 // Please increment the version and please
677 // also update the version number in PCD
678 // service PEIM and DXE driver accordingly.
680 private final int version
= 1;
682 private String hString
;
683 private String cString
;
686 class AlignmentSizeComp
implements Comparator
<Token
> {
687 public int compare (Token a
, Token b
) {
688 return getAlignmentSize(b
)
689 - getAlignmentSize(a
);
693 public PcdDatabase (ArrayList
<Token
> alTokens
, String exePhase
, int startLen
) {
696 stringTable
= new StringTable(phase
);
697 guidTable
= new GuidTable(phase
);
698 localTokenNumberTable
= new LocalTokenNumberTable(phase
);
699 skuIdTable
= new SkuIdTable(phase
);
700 sizeTable
= new SizeTable(phase
);
701 exMapTable
= new ExMapTable(phase
);
703 assignedTokenNumber
= startLen
;
704 this.alTokens
= alTokens
;
707 private void getTwoGroupsOfTokens (ArrayList
<Token
> alTokens
, List
<Token
> initTokens
, List
<Token
> uninitTokens
) {
708 for (int i
= 0; i
< alTokens
.size(); i
++) {
709 Token t
= alTokens
.get(i
);
710 if (t
.hasDefaultValue()) {
720 private int getAlignmentSize (Token token
) {
721 if (token
.hiiEnabled
) {
725 if (token
.vpdEnabled
) {
729 if (token
.isStringType()) {
733 switch (token
.datumType
) {
750 public String
getCString () {
754 public String
getHString () {
758 public void genCode () {
760 final String newLine
= "\r\n";
761 final String declNewLine
= ";\r\n";
762 final String tab
= "\t";
763 final String commaNewLine
= ", \r\n";
766 ArrayList
<String
> decla
;
767 ArrayList
<String
> inst
;
769 String macroStr
= "";
770 String initDeclStr
= "";
771 String initInstStr
= "";
772 String uninitDeclStr
= "";
774 List
<Token
> initTokens
= new ArrayList
<Token
> ();
775 List
<Token
> uninitTokens
= new ArrayList
<Token
> ();
777 HashMap
<String
, ArrayList
<String
>> initCode
= new HashMap
<String
, ArrayList
<String
>> ();
778 HashMap
<String
, ArrayList
<String
>> uninitCode
= new HashMap
<String
, ArrayList
<String
>> ();
780 getTwoGroupsOfTokens (alTokens
, initTokens
, uninitTokens
);
783 // Generate Structure Declaration for PcdTokens without Default Value
784 // PEI_PCD_DATABASE_INIT
786 java
.util
.Comparator
<Token
> comparator
= new AlignmentSizeComp();
787 java
.util
.Collections
.sort(initTokens
, comparator
);
788 initCode
= processTokens(initTokens
);
791 // Generate Structure Declaration for PcdTokens without Default Value
792 // PEI_PCD_DATABASE_UNINIT
794 java
.util
.Collections
.sort(uninitTokens
, comparator
);
795 uninitCode
= processTokens(uninitTokens
);
798 // Generate size info Macro for all Tables
800 macroStr
+= guidTable
.getSizeMacro();
801 macroStr
+= stringTable
.getSizeMacro();
802 macroStr
+= skuIdTable
.getSizeMacro();
803 macroStr
+= localTokenNumberTable
.getSizeMacro();
804 macroStr
+= exMapTable
.getSizeMacro();
807 // Generate existance info Macro for all Tables
809 macroStr
+= guidTable
.getExistanceMacro();
810 macroStr
+= stringTable
.getExistanceMacro();
811 macroStr
+= skuIdTable
.getExistanceMacro();
812 macroStr
+= localTokenNumberTable
.getExistanceMacro();
813 macroStr
+= exMapTable
.getExistanceMacro();
816 // Generate Structure Declaration for PcdTokens with Default Value
817 // for example PEI_PCD_DATABASE_INIT
819 initDeclStr
+= "typedef struct {" + newLine
;
821 initDeclStr
+= tab
+ exMapTable
.getTypeDeclaration();
822 initDeclStr
+= tab
+ guidTable
.getTypeDeclaration();
823 initDeclStr
+= tab
+ localTokenNumberTable
.getTypeDeclaration();
824 initDeclStr
+= tab
+ stringTable
.getTypeDeclaration();
825 initDeclStr
+= tab
+ sizeTable
.getTypeDeclaration();
826 initDeclStr
+= tab
+ skuIdTable
.getTypeDeclaration();
827 if (phase
.equalsIgnoreCase("PEI")) {
828 initDeclStr
+= tab
+ "SKU_ID SystemSkuId;" + newLine
;
831 decla
= initCode
.get(new String("Declaration"));
832 for (i
= 0; i
< decla
.size(); i
++) {
833 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
837 // Generate Structure Declaration for PcdToken with SkuEnabled
839 decla
= initCode
.get("DeclarationForSku");
841 for (i
= 0; i
< decla
.size(); i
++) {
842 initDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
845 initDeclStr
+= String
.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase
);
848 // Generate MACRO for structure intialization of PCDTokens with Default Value
849 // The sequence must match the sequence of declaration of the memembers in the structure
850 String tmp
= String
.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase
.toUpperCase(), phase
.toUpperCase());
851 initInstStr
+= tmp
+ newLine
;
852 initInstStr
+= tab
+ genInstantiationStr(exMapTable
.getInstantiation()) + commaNewLine
;
853 initInstStr
+= tab
+ genInstantiationStr(guidTable
.getInstantiation()) + commaNewLine
;
854 initInstStr
+= tab
+ genInstantiationStr(localTokenNumberTable
.getInstantiation()) + commaNewLine
;
855 initInstStr
+= tab
+ genInstantiationStr(stringTable
.getInstantiation()) + commaNewLine
;
856 initInstStr
+= tab
+ genInstantiationStr(sizeTable
.getInstantiation()) + commaNewLine
;
857 initInstStr
+= tab
+ genInstantiationStr(skuIdTable
.getInstantiation()) + commaNewLine
;
861 if (phase
.equalsIgnoreCase("PEI")) {
862 initInstStr
+= tab
+ "0" + tab
+ "/* SystemSkuId */" + commaNewLine
;
865 inst
= initCode
.get("Instantiation");
866 for (i
= 0; i
< inst
.size(); i
++) {
867 initInstStr
+= tab
+ inst
.get(i
) + commaNewLine
;
870 inst
= initCode
.get("InstantiationForSku");
871 for (i
= 0; i
< inst
.size(); i
++) {
872 initInstStr
+= tab
+ inst
.get(i
);
873 if (i
!= inst
.size() - 1) {
874 initInstStr
+= commaNewLine
;
880 uninitDeclStr
+= "typedef struct {" + newLine
;
882 decla
= uninitCode
.get("Declaration");
883 if (decla
.size() == 0) {
884 uninitDeclStr
+= "UINT8 dummy /* The UINT struct is empty */" + declNewLine
;
887 for (i
= 0; i
< decla
.size(); i
++) {
888 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
891 decla
= uninitCode
.get("DeclarationForSku");
893 for (i
= 0; i
< decla
.size(); i
++) {
894 uninitDeclStr
+= tab
+ decla
.get(i
) + declNewLine
;
898 uninitDeclStr
+= String
.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase
);
900 cString
= initInstStr
+ newLine
;
901 hString
= macroStr
+ newLine
902 + initDeclStr
+ newLine
903 + uninitDeclStr
+ newLine
906 hString
+= String
.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase
, version
);
910 private String
genInstantiationStr (ArrayList
<String
> alStr
) {
912 for (int i
= 0; i
< alStr
.size(); i
++) {
913 str
+= "\t" + alStr
.get(i
);
914 if (i
!= alStr
.size() - 1) {
922 private HashMap
<String
, ArrayList
<String
>> processTokens (List
<Token
> alToken
) {
924 HashMap
<String
, ArrayList
<String
>> map
= new HashMap
<String
, ArrayList
<String
>>();
926 ArrayList
<String
> decl
= new ArrayList
<String
>();
927 ArrayList
<String
> declForSkuEnableType
= new ArrayList
<String
>();
928 ArrayList
<String
> inst
= new ArrayList
<String
>();
929 ArrayList
<String
> instForSkuEnableType
= new ArrayList
<String
>();
931 for (int index
= 0; index
< alToken
.size(); index
++) {
932 Token token
= alToken
.get(index
);
934 if (token
.skuEnabled
) {
936 // BugBug: Schema only support Data type now
940 tableIdx
= skuIdTable
.add(token
);
942 decl
.add(getSkuEnabledTypeDeclaration(token
));
943 if (token
.hasDefaultValue()) {
944 inst
.add(getSkuEnabledTypeInstantiaion(token
, tableIdx
));
947 declForSkuEnableType
.add(getDataTypeDeclarationForSkuEnabled(token
));
948 if (token
.hasDefaultValue()) {
949 instForSkuEnableType
.add(getDataTypeInstantiationForSkuEnabled(token
));
953 if (token
.hiiEnabled
) {
954 decl
.add(getVariableEnableTypeDeclaration(token
));
955 inst
.add(getVariableEnableInstantiation(token
));
956 } else if (token
.vpdEnabled
) {
957 decl
.add(getVpdEnableTypeDeclaration(token
));
958 inst
.add(getVpdEnableTypeInstantiation(token
));
959 } else if (token
.isStringType()) {
960 decl
.add(getStringTypeDeclaration(token
));
961 inst
.add(getStringTypeInstantiation(stringTable
.add(token
.getStringTypeString(), token
), token
));
964 decl
.add(getDataTypeDeclaration(token
));
965 if (token
.hasDefaultValue()) {
966 inst
.add(getDataTypeInstantiation(token
));
971 sizeTable
.add(token
);
972 localTokenNumberTable
.add(token
);
973 token
.assignedtokenNumber
= assignedTokenNumber
++;
977 map
.put("Declaration", decl
);
978 map
.put("DeclarationForSku", declForSkuEnableType
);
979 map
.put("Instantiation", inst
);
980 map
.put("InstantiationForSku", instForSkuEnableType
);
985 private String
getSkuEnabledTypeDeclaration (Token token
) {
986 return String
.format("SKU_HEAD %s;\r\n", token
.getPrimaryKeyString());
989 private String
getSkuEnabledTypeInstantiaion (Token token
, int SkuTableIdx
) {
991 String offsetof
= String
.format(PcdDatabase
.offsetOfSkuHeadStrTemplate
, phase
, token
.hasDefaultValue()?
"Init" : "Uninit", token
.getPrimaryKeyString());
992 return String
.format("{ %s, %d }", offsetof
, SkuTableIdx
);
995 private String
getDataTypeDeclarationForSkuEnabled (Token token
) {
998 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
999 typeStr
= "UINT8 %s_%s[%d];\r\n";
1000 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1001 typeStr
= "UINT16 %s_%s[%d];\r\n";
1002 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1003 typeStr
= "UINT32 %s_%s[%d];\r\n";
1004 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1005 typeStr
= "UINT64 %s_%s[%d];\r\n";
1006 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1007 typeStr
= "BOOLEAN %s_%s[%d];\r\n";
1008 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1009 return String
.format("UINT8 %s_s[%d];\r\n", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.maxSkuCount
);
1012 return String
.format(typeStr
, token
.getPrimaryKeyString(), "SkuDataTable", token
.maxSkuCount
);
1016 private String
getDataTypeInstantiationForSkuEnabled (Token token
) {
1019 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1020 return String
.format("UINT8 %s_s[%d]", token
.getPrimaryKeyString(), "SkuDataTable", token
.datumSize
* token
.maxSkuCount
);
1023 for (int idx
= 0; idx
< token
.maxSkuCount
; idx
++) {
1024 str
+= token
.skuData
.get(idx
).toString();
1025 if (idx
!= token
.maxSkuCount
- 1) {
1036 private String
getDataTypeInstantiation (Token token
) {
1038 if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1039 return String
.format("%s /* %s */", token
.datum
.toString(), token
.getPrimaryKeyString());
1041 return String
.format("%s /* %s */", token
.datum
.toString(), token
.getPrimaryKeyString());
1046 private String
getDataTypeDeclaration (Token token
) {
1048 String typeStr
= "";
1050 if (token
.datumType
== Token
.DATUM_TYPE
.UINT8
) {
1052 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT16
) {
1054 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT32
) {
1056 } else if (token
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
1058 } else if (token
.datumType
== Token
.DATUM_TYPE
.BOOLEAN
) {
1059 typeStr
= "BOOLEAN";
1060 } else if (token
.datumType
== Token
.DATUM_TYPE
.POINTER
) {
1061 return String
.format("UINT8 %s[%d]", token
.getPrimaryKeyString(), token
.datumSize
);
1065 return String
.format("%s %s", typeStr
, token
.getPrimaryKeyString());
1068 private String
getVpdEnableTypeDeclaration (Token token
) {
1069 return String
.format("VPD_HEAD %s", token
.getPrimaryKeyString());
1072 private String
getVpdEnableTypeInstantiation (Token token
) {
1073 return String
.format("{ %d } /* %s */", token
.vpdOffset
,
1074 token
.getPrimaryKeyString());
1077 private String
getStringTypeDeclaration (Token token
) {
1078 return String
.format("UINT16 %s", token
.getPrimaryKeyString());
1081 private String
getStringTypeInstantiation (int StringTableIdx
, Token token
) {
1082 return String
.format ("%d /* %s */", StringTableIdx
,
1083 token
.getPrimaryKeyString());
1087 private String
getVariableEnableTypeDeclaration (Token token
) {
1088 return String
.format("VARIABLE_HEAD %s", token
.getPrimaryKeyString());
1091 private String
getVariableEnableInstantiation (Token token
) {
1092 return String
.format("{ %d, %d, %d } /* %s */", guidTable
.add(token
.variableGuid
, token
.getPrimaryKeyString()),
1093 stringTable
.add(token
.variableName
, token
),
1094 token
.variableOffset
,
1095 token
.getPrimaryKeyString());
1098 public int getTotalTokenNumber () {
1099 return sizeTable
.getTableLen();
1102 public static String
getPcdDatabaseCommonDefinitions ()
1103 throws EntityException
{
1107 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1108 "Tools" + File
.separator
+
1109 "Conf" + File
.separator
+
1110 "Pcd" + File
.separator
+
1111 "PcdDatabaseCommonDefinitions.sample");
1112 System
.out
.println(GlobalData
.getWorkspacePath());
1113 FileReader reader
= new FileReader(file
);
1114 BufferedReader in
= new BufferedReader(reader
);
1116 while ((str
= in
.readLine()) != null) {
1117 retStr
= retStr
+"\r\n" + str
;
1119 } catch (Exception ex
) {
1120 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");
1126 public static String
getPcdDxeDatabaseDefinitions ()
1127 throws EntityException
{
1131 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1132 "Tools" + File
.separator
+
1133 "Conf" + File
.separator
+
1134 "Pcd" + File
.separator
+
1135 "PcdDatabaseDxeDefinitions.sample");
1136 FileReader reader
= new FileReader(file
);
1137 BufferedReader in
= new BufferedReader(reader
);
1139 while ((str
= in
.readLine()) != null) {
1140 retStr
= retStr
+"\r\n" + str
;
1142 } catch (Exception ex
) {
1143 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");
1149 public static String
getPcdPeiDatabaseDefinitions ()
1150 throws EntityException
{
1154 File file
= new File(GlobalData
.getWorkspacePath() + File
.separator
+
1155 "Tools" + File
.separator
+
1156 "Conf" + File
.separator
+
1157 "Pcd" + File
.separator
+
1158 "PcdDatabasePeiDefinitions.sample");
1159 FileReader reader
= new FileReader(file
);
1160 BufferedReader in
= new BufferedReader(reader
);
1162 while ((str
= in
.readLine()) != null) {
1163 retStr
= retStr
+"\r\n" + str
;
1165 } catch (Exception ex
) {
1166 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");
1174 /** This action class is to collect PCD information from MSA, SPD, FPD xml file.
1175 This class will be used for wizard and build tools, So it can *not* inherit
1176 from buildAction or UIAction.
1178 public class CollectPCDAction
{
1179 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.
1180 private MemoryDatabaseManager dbManager
;
1182 /// Workspacepath hold the workspace information.
1183 private String workspacePath
;
1185 /// FPD file is the root file.
1186 private String fpdFilePath
;
1188 /// Message level for CollectPCDAction.
1189 private int originalMessageLevel
;
1192 Set WorkspacePath parameter for this action class.
1194 @param workspacePath parameter for this action
1196 public void setWorkspacePath(String workspacePath
) {
1197 this.workspacePath
= workspacePath
;
1201 Set action message level for CollectPcdAction tool.
1203 The message should be restored when this action exit.
1205 @param actionMessageLevel parameter for this action
1207 public void setActionMessageLevel(int actionMessageLevel
) {
1208 originalMessageLevel
= ActionMessage
.messageLevel
;
1209 ActionMessage
.messageLevel
= actionMessageLevel
;
1213 Set FPDFileName parameter for this action class.
1215 @param fpdFilePath fpd file path
1217 public void setFPDFilePath(String fpdFilePath
) {
1218 this.fpdFilePath
= fpdFilePath
;
1222 Common function interface for outer.
1224 @param workspacePath The path of workspace of current build or analysis.
1225 @param fpdFilePath The fpd file path of current build or analysis.
1226 @param messageLevel The message level for this Action.
1228 @throws Exception The exception of this function. Because it can *not* be predict
1229 where the action class will be used. So only Exception can be throw.
1232 public void perform(String workspacePath
, String fpdFilePath
,
1233 int messageLevel
) throws Exception
{
1234 setWorkspacePath(workspacePath
);
1235 setFPDFilePath(fpdFilePath
);
1236 setActionMessageLevel(messageLevel
);
1239 ActionMessage
.messageLevel
= originalMessageLevel
;
1243 Core execution function for this action class.
1245 This function work flows will be:
1246 1) Get all token's platform information from FPD, and create token object into memory database.
1247 2) Get all token's module information from MSA, and create usage instance for every module's PCD entry.
1248 3) Get all token's inherited information from MSA's library, and create usage instance
1249 for module who consume this library and create usage instance for library for building.
1250 4) Collect token's package information from SPD, update these information for token in memory
1252 5) Generate 3 strings for a) All modules using Dynamic(Ex) PCD entry. (Token Number)
1253 b) PEI PCD Database (C Structure) for PCD Service PEIM
1254 c) DXE PCD Database (C structure) for PCD Service DXE
1257 @throws EntityException Exception indicate failed to execute this action.
1260 private void execute() throws EntityException
{
1261 FrameworkPlatformDescriptionDocument fpdDoc
= null;
1262 Object
[][] modulePCDArray
= null;
1263 Map
<String
, XmlObject
> docMap
= null;
1264 ModuleSADocument
.ModuleSA
[] moduleSAs
= null;
1265 UsageInstance usageInstance
= null;
1266 String packageName
= null;
1267 String packageFullPath
= null;
1269 int libraryIndex
= 0;
1270 int pcdArrayIndex
= 0;
1271 List
<String
> listLibraryInstance
= null;
1272 String componentTypeStr
= null;
1275 // Collect all PCD information defined in FPD file.
1276 // Evenry token defind in FPD will be created as an token into
1279 fpdDoc
= createTokenInDBFromFPD();
1282 // Searching MSA and SPD document.
1283 // The information of MSA will be used to create usage instance into database.
1284 // The information of SPD will be used to update the token information in database.
1287 HashMap
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
1288 map
.put("FrameworkPlatformDescription", fpdDoc
);
1289 SurfaceAreaQuery
.setDoc(map
);
1291 moduleSAs
= SurfaceAreaQuery
.getFpdModules();
1292 for(index
= 0; index
< moduleSAs
.length
; index
++) {
1294 // Get module document and use SurfaceAreaQuery to get PCD information
1296 docMap
= GlobalData
.getDoc(moduleSAs
[index
].getModuleName());
1297 SurfaceAreaQuery
.setDoc(docMap
);
1298 modulePCDArray
= SurfaceAreaQuery
.getModulePCDTokenArray();
1299 componentTypeStr
= SurfaceAreaQuery
.getComponentType();
1301 GlobalData
.getPackageNameForModule(moduleSAs
[index
].getModuleName());
1302 packageFullPath
= this.workspacePath
+ File
.separator
+
1303 GlobalData
.getPackagePath(packageName
) +
1304 packageName
+ ".spd";
1306 if(modulePCDArray
!= null) {
1308 // If current MSA contains <PCDs> information, then create usage
1309 // instance for PCD information from MSA
1311 for(pcdArrayIndex
= 0; pcdArrayIndex
< modulePCDArray
.length
;
1314 createUsageInstanceFromMSA(moduleSAs
[index
].getModuleName(),
1315 modulePCDArray
[pcdArrayIndex
]);
1317 if(usageInstance
== null) {
1321 // Get remaining PCD information from the package which this module belongs to
1323 updateTokenBySPD(usageInstance
, packageFullPath
);
1328 // Get inherit PCD information which inherit from library instance of this module.
1330 listLibraryInstance
=
1331 SurfaceAreaQuery
.getLibraryInstance(moduleSAs
[index
].getArch().toString(),
1332 CommonDefinition
.AlwaysConsumed
);
1333 if(listLibraryInstance
!= null) {
1334 for(libraryIndex
= 0; libraryIndex
< listLibraryInstance
.size();
1336 inheritPCDFromLibraryInstance(listLibraryInstance
.get(libraryIndex
),
1337 moduleSAs
[index
].getModuleName(),
1345 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver
1346 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.
1348 genPcdDatabaseSourceCode ();
1353 This function generates source code for PCD Database.
1356 @throws EntityException If the token does *not* exist in memory database.
1360 private void genPcdDatabaseSourceCode ()
1361 throws EntityException
{
1362 String PcdCommonHeaderString
= PcdDatabase
.getPcdDatabaseCommonDefinitions ();
1364 ArrayList
<Token
> alPei
= new ArrayList
<Token
> ();
1365 ArrayList
<Token
> alDxe
= new ArrayList
<Token
> ();
1367 dbManager
.getTwoPhaseDynamicRecordArray(alPei
, alDxe
);
1368 PcdDatabase pcdPeiDatabase
= new PcdDatabase (alPei
, "PEI", 0);
1369 pcdPeiDatabase
.genCode();
1370 dbManager
.PcdPeimHString
= PcdCommonHeaderString
+ pcdPeiDatabase
.getHString()
1371 + PcdDatabase
.getPcdPeiDatabaseDefinitions();
1372 dbManager
.PcdPeimCString
= pcdPeiDatabase
.getCString();
1374 PcdDatabase pcdDxeDatabase
= new PcdDatabase (alDxe
,
1378 pcdDxeDatabase
.genCode();
1379 dbManager
.PcdDxeHString
= dbManager
.PcdPeimHString
+ pcdDxeDatabase
.getHString()
1380 + PcdDatabase
.getPcdDxeDatabaseDefinitions();
1381 dbManager
.PcdDxeCString
= pcdDxeDatabase
.getCString();
1385 This function will collect inherit PCD information from library for a module.
1387 This function will create two usage instance for inherited PCD token, one is
1388 for module and another is for library.
1389 For module, if it inherited a PCD token from library, this PCD token's value
1390 should be instanced in module level, and belongs to module.
1391 For library, it also need a usage instance for build.
1393 @param libraryName The name of library instance.
1394 @param moduleName The name of module.
1395 @param packageName The name of package while module belongs to.
1396 @param parentcomponentType The component type of module.
1398 @throws EntityException If the token does *not* exist in memory database.
1401 private void inheritPCDFromLibraryInstance(String libraryName
,
1404 String parentcomponentType
)
1405 throws EntityException
{
1406 Map
<String
, XmlObject
> docMap
= null;
1407 String primaryKeyString
= null;
1408 Object
[][] libPcdDataArray
= null;
1409 UUID nullUUID
= new UUID(0,0);
1410 UUID platformUUID
= nullUUID
;
1411 UUID tokenSpaceGuid
= null;
1414 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
1415 UsageInstance usageInstance
= null;
1416 String packageFullPath
= null;
1419 // Query PCD information from library's document.
1421 docMap
= GlobalData
.getDoc(libraryName
);
1422 SurfaceAreaQuery
.setDoc(docMap
);
1423 libPcdDataArray
= SurfaceAreaQuery
.getModulePCDTokenArray();
1425 if(libPcdDataArray
== null) {
1429 for(tokenIndex
= 0; tokenIndex
< libPcdDataArray
.length
; tokenIndex
++) {
1430 tokenSpaceGuid
=((UUID
)libPcdDataArray
[tokenIndex
][2] == null) ?
1431 nullUUID
:(UUID
)libPcdDataArray
[tokenIndex
][2];
1434 // Get token from memory database. The token must be created from FPD already.
1436 primaryKeyString
= Token
.getPrimaryKeyString((String
)libPcdDataArray
[tokenIndex
][0],
1441 if(dbManager
.isTokenInDatabase(primaryKeyString
)) {
1442 token
= dbManager
.getTokenByKey(primaryKeyString
);
1444 throw new EntityException("The PCD token " + primaryKeyString
+
1445 " defined in module " + moduleName
+
1446 " does not exist in FPD file!");
1450 // Create usage instance for module.
1452 pcdType
= Token
.getpcdTypeFromString((String
)libPcdDataArray
[tokenIndex
][1]);
1453 usageInstance
= new UsageInstance(token
,
1454 Token
.PCD_USAGE
.ALWAYS_CONSUMED
,
1456 CommonDefinition
.getComponentType(parentcomponentType
),
1457 libPcdDataArray
[tokenIndex
][3],
1459 (String
) libPcdDataArray
[tokenIndex
][5],
1464 if(Token
.PCD_USAGE
.UNKNOWN
== token
.isUsageInstanceExist(moduleName
)) {
1465 token
.addUsageInstance(usageInstance
);
1467 packageFullPath
= this.workspacePath
+ File
.separator
+
1468 GlobalData
.getPackagePath(packageName
) +
1469 packageName
+ ".spd";
1470 updateTokenBySPD(usageInstance
, packageFullPath
);
1474 // We need create second usage instance for inherited case, which
1475 // add library as an usage instance, because when build a module, and
1476 // if module inherited from base library, then build process will build
1477 // library at first.
1479 if(Token
.PCD_USAGE
.UNKNOWN
== token
.isUsageInstanceExist(libraryName
)) {
1480 packageName
= GlobalData
.getPackageNameForModule(libraryName
);
1481 usageInstance
= new UsageInstance(token
,
1482 Token
.PCD_USAGE
.ALWAYS_CONSUMED
,
1484 CommonDefinition
.ComponentTypeLibrary
,
1485 libPcdDataArray
[tokenIndex
][3],
1487 (String
)libPcdDataArray
[tokenIndex
][5],
1492 token
.addUsageInstance(usageInstance
);
1498 Create usage instance for PCD token defined in MSA document
1500 A PCD token maybe used by many modules, and every module is one of usage
1501 instance of this token. For ALWAY_CONSUMED, SOMETIMES_CONSUMED, it is
1502 consumer type usage instance of this token, and for ALWAYS_PRODUCED,
1503 SOMETIMES_PRODUCED, it is produce type usage instance.
1505 @param moduleName The name of module
1506 @param tokenInfoInMsa The PCD token information array retrieved from MSA.
1508 @return UsageInstance The usage instance created in memroy database.
1510 @throws EntityException If token did not exist in database yet.
1513 private UsageInstance
createUsageInstanceFromMSA(String moduleName
,
1514 Object
[] tokenInfoInMsa
)
1515 throws EntityException
{
1516 String packageName
= null;
1517 UsageInstance usageInstance
= null;
1518 UUID tokenSpaceGuid
= null;
1519 UUID nullUUID
= new UUID(0,0);
1520 String primaryKeyString
= null;
1521 UUID platformTokenSpace
= nullUUID
;
1523 Token
.PCD_TYPE pcdType
= Token
.PCD_TYPE
.UNKNOWN
;
1524 Token
.PCD_USAGE pcdUsage
= Token
.PCD_USAGE
.UNKNOWN
;
1526 tokenSpaceGuid
=((UUID
)tokenInfoInMsa
[2] == null) ? nullUUID
:(UUID
)tokenInfoInMsa
[2];
1528 primaryKeyString
= Token
.getPrimaryKeyString((String
)tokenInfoInMsa
[0],
1530 platformTokenSpace
);
1533 // Get token object from memory database firstly.
1535 if(dbManager
.isTokenInDatabase(primaryKeyString
)) {
1536 token
= dbManager
.getTokenByKey(primaryKeyString
);
1538 throw new EntityException("The PCD token " + primaryKeyString
+ " defined in module " +
1539 moduleName
+ " does not exist in FPD file!" );
1541 pcdType
= Token
.getpcdTypeFromString((String
)tokenInfoInMsa
[1]);
1542 pcdUsage
= Token
.getUsageFromString((String
)tokenInfoInMsa
[4]);
1544 packageName
= GlobalData
.getPackageNameForModule(moduleName
);
1546 if(Token
.PCD_USAGE
.UNKNOWN
!= token
.isUsageInstanceExist(moduleName
)) {
1548 // BUGBUG: It is legal that same base name exist in one FPD file. In furture
1549 // we should use "Guid, Version, Package" and "Arch" to differ a module.
1550 // So currently, warning should be disabled.
1552 //ActionMessage.warning(this,
1553 // "In module " + moduleName + " exist more than one PCD token " + token.cName
1559 // BUGBUG: following code could be enabled at current schema. Because
1560 // current schema does not provide usage information.
1562 // For FEATRURE_FLAG, FIXED_AT_BUILD, PATCH_IN_MODULE type PCD token, his
1563 // usage is always ALWAYS_CONSUMED
1565 //if((pcdType != Token.PCD_TYPE.DYNAMIC) &&
1566 // (pcdType != Token.PCD_TYPE.DYNAMIC_EX)) {
1567 pcdUsage
= Token
.PCD_USAGE
.ALWAYS_CONSUMED
;
1570 usageInstance
= new UsageInstance(token
,
1573 CommonDefinition
.getComponentType(SurfaceAreaQuery
.getComponentType()),
1576 (String
) tokenInfoInMsa
[5],
1583 // Use default value defined in MSA to update datum of token,
1584 // if datum of token does not defined in FPD file.
1586 if((token
.datum
== null) &&(tokenInfoInMsa
[3] != null)) {
1587 token
.datum
= tokenInfoInMsa
[3];
1590 token
.addUsageInstance(usageInstance
);
1592 return usageInstance
;
1596 Create token instance object into memory database, the token information
1597 comes for FPD file. Normally, FPD file will contain all token platform
1600 This fucntion should be executed at firsly before others collection work
1601 such as searching token information from MSA, SPD.
1603 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.
1605 @throws EntityException Failed to parse FPD xml file.
1608 private FrameworkPlatformDescriptionDocument
createTokenInDBFromFPD()
1609 throws EntityException
{
1610 XmlObject doc
= null;
1611 FrameworkPlatformDescriptionDocument fpdDoc
= null;
1613 List
<PcdBuildData
> pcdBuildDataArray
= new ArrayList
<PcdBuildData
>();
1614 PcdBuildData pcdBuildData
= null;
1616 UUID nullUUID
= new UUID(0,0);
1617 UUID platformTokenSpace
= nullUUID
;
1618 List skuDataArray
= new ArrayList();
1619 SkuInstance skuInstance
= null;
1623 // Get all tokens from FPD file and create token into database.
1627 doc
= XmlObject
.Factory
.parse(new File(fpdFilePath
));
1628 } catch(IOException ioE
) {
1629 throw new EntityException("Can't find the FPD xml fle:" + fpdFilePath
);
1630 } catch(XmlException xmlE
) {
1631 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath
);
1635 // Get memoryDatabaseManager instance from GlobalData.
1637 if((dbManager
= GlobalData
.getPCDMemoryDBManager()) == null) {
1638 throw new EntityException("The instance of PCD memory database manager is null");
1641 dbManager
= new MemoryDatabaseManager();
1643 if(!(doc
instanceof FrameworkPlatformDescriptionDocument
)) {
1644 throw new EntityException("File " + fpdFilePath
+
1645 " is not a FrameworkPlatformDescriptionDocument");
1648 fpdDoc
=(FrameworkPlatformDescriptionDocument
)doc
;
1651 // Add all tokens in FPD into Memory Database.
1654 fpdDoc
.getFrameworkPlatformDescription().getPcdBuildDeclarations().getPcdBuildDataList();
1656 index
< fpdDoc
.getFrameworkPlatformDescription().getPcdBuildDeclarations().sizeOfPcdBuildDataArray();
1658 pcdBuildData
= pcdBuildDataArray
.get(index
);
1659 token
= new Token(pcdBuildData
.getCName(), new UUID(0, 0), new UUID(0, 0));
1661 // BUGBUG: in FPD, <defaultValue> should be defined as <Value>
1663 token
.datum
= pcdBuildData
.getDefaultValue();
1664 token
.tokenNumber
= Integer
.decode(pcdBuildData
.getToken().getStringValue());
1665 token
.hiiEnabled
= pcdBuildData
.getHiiEnable();
1666 token
.variableGuid
= Token
.getGUIDFromSchemaObject(pcdBuildData
.getVariableGuid());
1667 token
.variableName
= pcdBuildData
.getVariableName();
1668 token
.variableOffset
= Integer
.decode(pcdBuildData
.getDataOffset());
1669 token
.skuEnabled
= pcdBuildData
.getSkuEnable();
1670 token
.maxSkuCount
= Integer
.decode(pcdBuildData
.getMaxSku());
1671 token
.skuId
= Integer
.decode(pcdBuildData
.getSkuId());
1672 token
.skuDataArrayEnabled
= pcdBuildData
.getSkuDataArrayEnable();
1673 token
.assignedtokenNumber
= Integer
.decode(pcdBuildData
.getToken().getStringValue());
1674 skuDataArray
= pcdBuildData
.getSkuDataArray1();
1675 token
.datumType
= Token
.getdatumTypeFromString(pcdBuildData
.getDatumType().toString());
1676 token
.datumSize
= pcdBuildData
.getDatumSize();
1678 if(skuDataArray
!= null) {
1679 for(skuIndex
= 0; skuIndex
< skuDataArray
.size(); skuIndex
++) {
1681 // BUGBUG: Now in current schema, The value is defined as String type,
1682 // it is not correct, the type should be same as the datumType
1684 skuInstance
= new SkuInstance(((PcdBuildData
.SkuData
)skuDataArray
.get(skuIndex
)).getId(),
1685 ((PcdBuildData
.SkuData
)skuDataArray
.get(skuIndex
)).getValue());
1686 token
.skuData
.add(skuInstance
);
1690 if(dbManager
.isTokenInDatabase(Token
.getPrimaryKeyString(token
.cName
,
1691 token
.tokenSpaceName
,
1692 platformTokenSpace
))) {
1694 // If found duplicate token, Should tool be hold?
1696 ActionMessage
.warning(this,
1697 "Token " + token
.cName
+ " exists in token database");
1700 token
.pcdType
= Token
.getpcdTypeFromString(pcdBuildData
.getItemType().toString());
1701 dbManager
.addTokenToDatabase(Token
.getPrimaryKeyString(token
.cName
,
1702 token
.tokenSpaceName
,
1703 platformTokenSpace
),
1711 Update PCD token in memory database by help information in SPD.
1713 After create token from FPD and create usage instance from MSA, we should collect
1714 PCD package level information from SPD and update token information in memory
1717 @param usageInstance The usage instance defined in MSA and want to search in SPD.
1718 @param packageFullPath The SPD file path.
1720 @throws EntityException Failed to parse SPD xml file.
1723 private void updateTokenBySPD(UsageInstance usageInstance
,
1724 String packageFullPath
)
1725 throws EntityException
{
1726 PackageSurfaceAreaDocument pkgDoc
= null;
1727 PcdDefinitions pcdDefinitions
= null;
1728 List
<PcdDefinitions
.PcdEntry
> pcdEntryArray
= new ArrayList
<PcdDefinitions
.PcdEntry
>();
1730 boolean isFoundInSpd
= false;
1731 Token
.DATUM_TYPE datumType
= Token
.DATUM_TYPE
.UNKNOWN
;
1734 pkgDoc
=(PackageSurfaceAreaDocument
)XmlObject
.Factory
.parse(new File(packageFullPath
));
1735 } catch(IOException ioE
) {
1736 throw new EntityException("Can't find the FPD xml fle:" + packageFullPath
);
1737 } catch(XmlException xmlE
) {
1738 throw new EntityException("Can't parse the FPD xml fle:" + packageFullPath
);
1740 pcdDefinitions
= pkgDoc
.getPackageSurfaceArea().getPcdDefinitions();
1742 // It is illege for SPD file does not contains any PCD information.
1744 if (pcdDefinitions
== null) {
1748 pcdEntryArray
= pcdDefinitions
.getPcdEntryList();
1749 if (pcdEntryArray
== null) {
1752 for(index
= 0; index
< pcdEntryArray
.size(); index
++) {
1753 if(pcdEntryArray
.get(index
).getCName().equalsIgnoreCase(
1754 usageInstance
.parentToken
.cName
)) {
1755 isFoundInSpd
= true;
1757 // From SPD file , we can get following information.
1758 // Token: Token number defined in package level.
1759 // PcdItemType: This item does not single one. It means all supported item type.
1760 // datumType: UINT8, UNIT16, UNIT32, UINT64, VOID*, BOOLEAN
1761 // datumSize: The size of default value or maxmine size.
1762 // defaultValue: This value is defined in package level.
1763 // HelpText: The help text is provided in package level.
1766 usageInstance
.parentToken
.tokenNumber
= Integer
.decode(pcdEntryArray
.get(index
).getToken());
1768 if(pcdEntryArray
.get(index
).getDatumType() != null) {
1769 datumType
= Token
.getdatumTypeFromString(
1770 pcdEntryArray
.get(index
).getDatumType().toString());
1771 if(usageInstance
.parentToken
.datumType
== Token
.DATUM_TYPE
.UNKNOWN
) {
1772 usageInstance
.parentToken
.datumType
= datumType
;
1774 if(datumType
!= usageInstance
.parentToken
.datumType
) {
1775 throw new EntityException("Different datum types are defined for Token :" +
1776 usageInstance
.parentToken
.cName
);
1781 throw new EntityException("The datum type for token " + usageInstance
.parentToken
.cName
+
1782 " is not defind in SPD file " + packageFullPath
);
1785 usageInstance
.defaultValueInSPD
= pcdEntryArray
.get(index
).getDefaultValue();
1786 usageInstance
.helpTextInSPD
= "Help Text in SPD";
1789 // If token's datum is not valid, it indicate that datum is not provided
1790 // in FPD and defaultValue is not provided in MSA, then use defaultValue
1791 // in SPD as the datum of token.
1793 if(usageInstance
.parentToken
.datum
== null) {
1794 if(pcdEntryArray
.get(index
).getDefaultValue() != null) {
1795 usageInstance
.parentToken
.datum
= pcdEntryArray
.get(index
).getDefaultValue();
1797 throw new EntityException("FPD does not provide datum for token " + usageInstance
.parentToken
.cName
+
1798 ", MSA and SPD also does not provide <defaultValue> for this token!");
1806 check parameter for this action.
1808 @throws EntityException Bad parameter.
1810 private void checkParameter() throws EntityException
{
1813 if((fpdFilePath
== null) ||(workspacePath
== null)) {
1814 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
1817 if(fpdFilePath
.length() == 0 || workspacePath
.length() == 0) {
1818 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
1821 file
= new File(workspacePath
);
1822 if(!file
.exists()) {
1823 throw new EntityException("WorkpacePath " + workspacePath
+ " does not exist!");
1826 file
= new File(fpdFilePath
);
1828 if(!file
.exists()) {
1829 throw new EntityException("FPD File " + fpdFilePath
+ " does not exist!");
1836 @param argv parameter from command line
1838 public static void main(String argv
[]) throws EntityException
{
1839 CollectPCDAction ca
= new CollectPCDAction();
1840 ca
.setWorkspacePath("G:/mdk");
1841 ca
.setFPDFilePath("G:/mdk/EdkNt32Pkg/build/Nt32.fpd");
1842 ca
.setActionMessageLevel(ActionMessage
.MAX_MESSAGE_LEVEL
);
1843 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db",