Fix some bugs in PCD tools:
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / CollectPCDAction.java
1 /** @file
2 CollectPCDAction class.
3
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.
7
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
13
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.
16
17 **/
18 package org.tianocore.build.pcd.action;
19
20 import java.io.BufferedReader;
21 import java.io.File;
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;
29 import java.util.Map;
30 import java.util.UUID;
31
32 import org.apache.xmlbeans.XmlException;
33 import org.apache.xmlbeans.XmlObject;
34 import org.tianocore.DynamicPcdBuildDefinitionsDocument;
35 import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;
36 import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo;
37 import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData;
38 import org.tianocore.FrameworkModulesDocument;
39 import org.tianocore.FrameworkPlatformDescriptionDocument;
40 import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription;
41 import org.tianocore.ModuleSADocument;
42 import org.tianocore.ModuleSADocument.ModuleSA;
43 import org.tianocore.PackageSurfaceAreaDocument;
44 import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;
45 import org.tianocore.build.global.GlobalData;
46 import org.tianocore.build.global.SurfaceAreaQuery;
47 import org.tianocore.build.pcd.action.ActionMessage;
48 import org.tianocore.build.pcd.entity.DynamicTokenValue;
49 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
50 import org.tianocore.build.pcd.entity.SkuInstance;
51 import org.tianocore.build.pcd.entity.Token;
52 import org.tianocore.build.pcd.entity.UsageInstance;
53 import org.tianocore.build.pcd.exception.EntityException;
54
55 class StringTable {
56 private ArrayList<String> al;
57 private ArrayList<String> alComments;
58 private String phase;
59 int len;
60 int bodyStart;
61 int bodyLineNum;
62
63 public StringTable (String phase) {
64 this.phase = phase;
65 al = new ArrayList<String>();
66 alComments = new ArrayList<String>();
67 len = 0;
68 bodyStart = 0;
69 bodyLineNum = 0;
70 }
71
72 public String getSizeMacro () {
73 return String.format(PcdDatabase.StringTableSizeMacro, phase, getSize());
74 }
75
76 private int getSize () {
77 //
78 // We have at least one Unicode Character in the table.
79 //
80 return len == 0 ? 1 : len;
81 }
82
83 public int getTableLen () {
84 return al.size() == 0 ? 1 : al.size();
85 }
86
87 public String getExistanceMacro () {
88 return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");
89 }
90
91 public String getTypeDeclaration () {
92
93 String output;
94
95 final String stringTable = "StringTable";
96 final String tab = "\t";
97 final String newLine = ";\r\n";
98
99 output = "/* StringTable */\r\n";
100
101 if (al.size() == 0) {
102 output += tab + String.format("UINT16 %s[1] /* StringTable is Empty */", stringTable) + newLine;
103 }
104
105 for (int i = 0; i < al.size(); i++) {
106 String str = al.get(i);
107
108 if (i == 0) {
109 //
110 // StringTable is a well-known name in the PCD DXE driver
111 //
112 output += tab + String.format("UINT16 %s[%d] /* %s */", stringTable, str.length() + 1, alComments.get(i)) + newLine;
113 } else {
114 output += tab + String.format("UINT16 %s_%d[%d] /* %s */", stringTable, i, str.length() + 1, alComments.get(i)) + newLine;
115 }
116 }
117
118 return output;
119
120 }
121
122 public ArrayList<String> getInstantiation () {
123 ArrayList<String> output = new ArrayList<String>();
124
125 output.add("/* StringTable */");
126
127 if (al.size() == 0) {
128 output.add("{ 0 }");
129 } else {
130 String str;
131
132 for (int i = 0; i < al.size(); i++) {
133 str = String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));
134 if (i != al.size() - 1) {
135 str += ",";
136 }
137 output.add(str);
138 }
139 }
140
141 return output;
142 }
143
144 public int add (String str, Token token) {
145 int i;
146
147 i = len;
148 //
149 // Include the NULL character at the end of String
150 //
151 len += str.length() + 1;
152 al.add(str);
153 alComments.add(token.getPrimaryKeyString());
154
155 return i;
156 }
157 }
158
159 class SizeTable {
160 private ArrayList<Integer> al;
161 private ArrayList<String> alComments;
162 private String phase;
163 private int len;
164 private int bodyStart;
165 private int bodyLineNum;
166
167 public SizeTable (String phase) {
168 this.phase = phase;
169 al = new ArrayList<Integer>();
170 alComments = new ArrayList<String>();
171 len = 0;
172 bodyStart = 0;
173 bodyLineNum = 0;
174 }
175
176 public String getTypeDeclaration () {
177 return String.format(PcdDatabase.SizeTableDeclaration, phase);
178 }
179
180 public ArrayList<String> getInstantiation () {
181 ArrayList<String> Output = new ArrayList<String>();
182
183 Output.add("/* SizeTable */");
184 Output.add("{");
185 bodyStart = 2;
186
187 if (al.size() == 0) {
188 Output.add("0");
189 } else {
190 for (int index = 0; index < al.size(); index++) {
191 Integer n = al.get(index);
192 String str = n.toString();
193
194 if (index != (al.size() - 1)) {
195 str += ",";
196 }
197
198 str += " /* " + alComments.get(index) + " */";
199 Output.add(str);
200 bodyLineNum++;
201
202 }
203 }
204 Output.add("}");
205
206 return Output;
207 }
208
209 public int getBodyStart() {
210 return bodyStart;
211 }
212
213 public int getBodyLineNum () {
214 return bodyLineNum;
215 }
216
217 public int add (Token token) {
218 int index = len;
219
220 len++;
221 al.add(token.datumSize);
222 alComments.add(token.getPrimaryKeyString());
223
224 return index;
225 }
226
227 private int getDatumSize(Token token) {
228 /*
229 switch (token.datumType) {
230 case Token.DATUM_TYPE.UINT8:
231 return 1;
232 default:
233 return 0;
234 }
235 */
236 return 0;
237 }
238
239 public int getTableLen () {
240 return al.size() == 0 ? 1 : al.size();
241 }
242
243 }
244
245 class GuidTable {
246 private ArrayList<UUID> al;
247 private ArrayList<String> alComments;
248 private String phase;
249 private int len;
250 private int bodyStart;
251 private int bodyLineNum;
252
253 public GuidTable (String phase) {
254 this.phase = phase;
255 al = new ArrayList<UUID>();
256 alComments = new ArrayList<String>();
257 len = 0;
258 bodyStart = 0;
259 bodyLineNum = 0;
260 }
261
262 public String getSizeMacro () {
263 return String.format(PcdDatabase.GuidTableSizeMacro, phase, getSize());
264 }
265
266 private int getSize () {
267 return (al.size() == 0)? 1 : al.size();
268 }
269
270 public String getExistanceMacro () {
271 return String.format(PcdDatabase.GuidTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");
272 }
273
274 public String getTypeDeclaration () {
275 return String.format(PcdDatabase.GuidTableDeclaration, phase);
276 }
277
278 private String getUuidCString (UUID uuid) {
279 String[] guidStrArray;
280
281 guidStrArray =(uuid.toString()).split("-");
282
283 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 } }",
284 guidStrArray[0],
285 guidStrArray[1],
286 guidStrArray[2],
287 (guidStrArray[3].substring(0, 2)),
288 (guidStrArray[3].substring(2, 4)),
289 (guidStrArray[4].substring(0, 2)),
290 (guidStrArray[4].substring(2, 4)),
291 (guidStrArray[4].substring(4, 6)),
292 (guidStrArray[4].substring(6, 8)),
293 (guidStrArray[4].substring(8, 10)),
294 (guidStrArray[4].substring(10, 12))
295 );
296 }
297
298 public ArrayList<String> getInstantiation () {
299 ArrayList<String> Output = new ArrayList<String>();
300
301 Output.add("/* GuidTable */");
302 Output.add("{");
303 bodyStart = 2;
304
305 if (al.size() == 0) {
306 Output.add(getUuidCString(new UUID(0, 0)));
307 }
308
309 for (Object u : al) {
310 UUID uuid = (UUID)u;
311 String str = getUuidCString(uuid);
312
313 if (al.indexOf(u) != (al.size() - 1)) {
314 str += ",";
315 }
316 Output.add(str);
317 bodyLineNum++;
318
319 }
320 Output.add("}");
321
322 return Output;
323 }
324
325 public int getBodyStart() {
326 return bodyStart;
327 }
328
329 public int getBodyLineNum () {
330 return bodyLineNum;
331 }
332
333 public int add (UUID uuid, String name) {
334 int index = len;
335 //
336 // Include the NULL character at the end of String
337 //
338 len++;
339 al.add(uuid);
340
341 return index;
342 }
343
344 public int getTableLen () {
345 return al.size() == 0 ? 0 : al.size();
346 }
347
348 }
349
350 class SkuIdTable {
351 private ArrayList<Integer[]> al;
352 private ArrayList<String> alComment;
353 private String phase;
354 private int len;
355 private int bodyStart;
356 private int bodyLineNum;
357
358 public SkuIdTable (String phase) {
359 this.phase = phase;
360 al = new ArrayList<Integer[]>();
361 alComment = new ArrayList<String>();
362 bodyStart = 0;
363 bodyLineNum = 0;
364 len = 0;
365 }
366
367 public String getSizeMacro () {
368 return String.format(PcdDatabase.SkuIdTableSizeMacro, phase, getSize());
369 }
370
371 private int getSize () {
372 return (al.size() == 0)? 1 : al.size();
373 }
374
375 public String getExistanceMacro () {
376 return String.format(PcdDatabase.SkuTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");
377 }
378
379 public String getTypeDeclaration () {
380 return String.format(PcdDatabase.SkuIdTableDeclaration, phase);
381 }
382
383 public ArrayList<String> getInstantiation () {
384 ArrayList<String> Output = new ArrayList<String> ();
385
386 Output.add("/* SkuIdTable */");
387 Output.add("{");
388 bodyStart = 2;
389
390 if (al.size() == 0) {
391 Output.add("0");
392 }
393
394 for (int index = 0; index < al.size(); index++) {
395 String str;
396
397 str = "/* " + alComment.get(index) + "*/ ";
398 str += "/* MaxSku */ ";
399
400
401 Integer[] ia = al.get(index);
402
403 str += ia[0].toString() + ", ";
404 for (int index2 = 1; index2 < ia.length; index2++) {
405 str += ia[index2].toString();
406 if (index != al.size() - 1) {
407 str += ", ";
408 }
409 }
410
411 Output.add(str);
412 bodyLineNum++;
413
414 }
415
416 Output.add("}");
417
418 return Output;
419 }
420
421 public int add (Token token) {
422
423 int index;
424
425 Integer [] skuIds = new Integer[token.skuData.size() + 1];
426 skuIds[0] = new Integer(token.skuData.size());
427 for (index = 1; index < skuIds.length; index++) {
428 skuIds[index] = new Integer(token.skuData.get(index - 1).id);
429 }
430
431 index = len;
432
433 len += skuIds.length;
434 al.add(skuIds);
435 alComment.add(token.getPrimaryKeyString());
436
437 return index;
438 }
439
440 public int getTableLen () {
441 return al.size() == 0 ? 1 : al.size();
442 }
443
444 }
445
446 class LocalTokenNumberTable {
447 private ArrayList<String> al;
448 private ArrayList<String> alComment;
449 private String phase;
450 private int len;
451
452 public LocalTokenNumberTable (String phase) {
453 this.phase = phase;
454 al = new ArrayList<String>();
455 alComment = new ArrayList<String>();
456
457 len = 0;
458 }
459
460 public String getSizeMacro () {
461 return String.format(PcdDatabase.LocalTokenNumberTableSizeMacro, phase, getSize())
462 + String.format(PcdDatabase.LocalTokenNumberSizeMacro, phase, al.size());
463 }
464
465 public int getSize () {
466 return (al.size() == 0)? 1 : al.size();
467 }
468
469 public String getExistanceMacro () {
470 return String.format(PcdDatabase.DatabaseExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");
471 }
472
473 public String getTypeDeclaration () {
474 return String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);
475 }
476
477 public ArrayList<String> getInstantiation () {
478 ArrayList<String> output = new ArrayList<String>();
479
480 output.add("/* LocalTokenNumberTable */");
481 output.add("{");
482
483 if (al.size() == 0) {
484 output.add("0");
485 }
486
487 for (int index = 0; index < al.size(); index++) {
488 String str;
489
490 str = (String)al.get(index);
491
492 str += " /* " + alComment.get(index) + " */ ";
493
494
495 if (index != (al.size() - 1)) {
496 str += ",";
497 }
498
499 output.add(str);
500
501 }
502
503 output.add("}");
504
505 return output;
506 }
507
508 public int add (Token token) {
509 int index = len;
510 String str;
511
512 len++;
513
514 str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());
515
516 if (token.isStringType()) {
517 str += " | PCD_TYPE_STRING";
518 }
519
520 if (token.isSkuEnable()) {
521 str += " | PCD_TYPE_SKU_ENABLED";
522 }
523
524 if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {
525 str += " | PCD_TYPE_HII";
526 }
527
528 if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
529 str += " | PCD_TYPE_VPD";
530 }
531
532 al.add(str);
533 alComment.add(token.getPrimaryKeyString());
534
535 return index;
536 }
537 }
538
539 class ExMapTable {
540
541 class ExTriplet {
542 public Integer guidTableIdx;
543 public Long exTokenNumber;
544 public Long localTokenIdx;
545
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);
550 }
551 }
552
553 private ArrayList<ExTriplet> al;
554 private ArrayList<String> alComment;
555 private String phase;
556 private int len;
557 private int bodyStart;
558 private int bodyLineNum;
559 private int base;
560
561 public ExMapTable (String phase) {
562 this.phase = phase;
563 al = new ArrayList<ExTriplet>();
564 alComment = new ArrayList<String>();
565 bodyStart = 0;
566 bodyLineNum = 0;
567 len = 0;
568 }
569
570 public String getSizeMacro () {
571 return String.format(PcdDatabase.ExMapTableSizeMacro, phase, getTableLen())
572 + String.format(PcdDatabase.ExTokenNumber, phase, al.size());
573 }
574
575 private int getSize () {
576 return (al.size() == 0)? 1 : al.size();
577 }
578
579 public String getExistanceMacro () {
580 return String.format(PcdDatabase.ExMapTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");
581 }
582
583 public String getTypeDeclaration () {
584 return String.format(PcdDatabase.ExMapTableDeclaration, phase);
585 }
586
587 public ArrayList<String> getInstantiation () {
588 ArrayList<String> Output = new ArrayList<String>();
589
590 Output.add("/* ExMapTable */");
591 Output.add("{");
592 bodyStart = 2;
593
594 if (al.size() == 0) {
595 Output.add("{0, 0, 0}");
596 }
597
598 int index;
599 for (index = 0; index < al.size(); index++) {
600 String str;
601
602 ExTriplet e = (ExTriplet)al.get(index);
603
604 str = "{ " + e.exTokenNumber.toString() + ", ";
605 str += e.localTokenIdx.toString() + ", ";
606 str += e.guidTableIdx.toString();
607
608 str += " /* " + alComment.get(index) + " */";
609
610 if (index != al.size() - 1) {
611 str += ",";
612 }
613
614 Output.add(str);
615 bodyLineNum++;
616
617 }
618
619 Output.add("}");
620
621 return Output;
622 }
623
624 public int add (int localTokenIdx, long exTokenNum, int guidTableIdx, String name) {
625 int index = len;
626
627 len++;
628 al.add(new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx));
629 alComment.add(name);
630
631 return index;
632 }
633
634 public int getTableLen () {
635 return al.size() == 0 ? 1 : al.size();
636 }
637
638 }
639
640 class PcdDatabase {
641
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_TABLE_SIZE];\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_TABLE_SIZE];\r\n";
647 public final static String SkuIdTableDeclaration = "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";
648
649
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_TABLE_SIZE %d\r\n";
654 public final static String LocalTokenNumberSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";
655 public final static String StringTableSizeMacro = "#define %s_STRING_TABLE_SIZE %d\r\n";
656 public final static String SkuIdTableSizeMacro = "#define %s_SKUID_TABLE_SIZE %d\r\n";
657
658
659 public final static String ExMapTableExistenceMacro = "#define %s_EXMAP_TABLE_EMPTY %s\r\n";
660 public final static String GuidTableExistenceMacro = "#define %s_GUID_TABLE_EMPTY %s\r\n";
661 public final static String DatabaseExistenceMacro = "#define %s_DATABASE_EMPTY %s\r\n";
662 public final static String StringTableExistenceMacro = "#define %s_STRING_TABLE_EMPTY %s\r\n";
663 public final static String SkuTableExistenceMacro = "#define %s_SKUID_TABLE_EMPTY %s\r\n";
664
665 public final static String offsetOfSkuHeadStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";
666 public final static String offsetOfStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s)";
667
668 private StringTable stringTable;
669 private GuidTable guidTable;
670 private LocalTokenNumberTable localTokenNumberTable;
671 private SkuIdTable skuIdTable;
672 private SizeTable sizeTable;
673 private ExMapTable exMapTable;
674
675 private ArrayList<Token> alTokens;
676 private String phase;
677 private int assignedTokenNumber;
678
679 //
680 // After Major changes done to the PCD
681 // database generation class PcdDatabase
682 // Please increment the version and please
683 // also update the version number in PCD
684 // service PEIM and DXE driver accordingly.
685 //
686 private final int version = 1;
687
688 private String hString;
689 private String cString;
690
691
692 class AlignmentSizeComp implements Comparator<Token> {
693 public int compare (Token a, Token b) {
694 return getAlignmentSize(b)
695 - getAlignmentSize(a);
696 }
697 }
698
699 public PcdDatabase (ArrayList<Token> alTokens, String exePhase, int startLen) {
700 phase = exePhase;
701
702 stringTable = new StringTable(phase);
703 guidTable = new GuidTable(phase);
704 localTokenNumberTable = new LocalTokenNumberTable(phase);
705 skuIdTable = new SkuIdTable(phase);
706 sizeTable = new SizeTable(phase);
707 exMapTable = new ExMapTable(phase);
708
709 assignedTokenNumber = startLen;
710 this.alTokens = alTokens;
711 }
712
713 private void getTwoGroupsOfTokens (ArrayList<Token> alTokens, List<Token> initTokens, List<Token> uninitTokens) {
714 for (int i = 0; i < alTokens.size(); i++) {
715 Token t = (Token)alTokens.get(i);
716 if (t.hasDefaultValue()) {
717 initTokens.add(t);
718 } else {
719 uninitTokens.add(t);
720 }
721 }
722
723 return;
724 }
725
726 private int getAlignmentSize (Token token) {
727 if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {
728 return 2;
729 }
730
731 if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
732 return 4;
733 }
734
735 if (token.isStringType()) {
736 return 2;
737 }
738
739 switch (token.datumType) {
740 case UINT8:
741 return 1;
742 case UINT16:
743 return 2;
744 case UINT32:
745 return 4;
746 case UINT64:
747 return 8;
748 case POINTER:
749 return 1;
750 case BOOLEAN:
751 return 1;
752 }
753 return 1;
754 }
755
756 public String getCString () {
757 return cString;
758 }
759
760 public String getHString () {
761 return hString;
762 }
763
764 public void genCode ()
765 throws EntityException {
766
767 final String newLine = "\r\n";
768 final String declNewLine = ";\r\n";
769 final String tab = "\t";
770 final String commaNewLine = ", \r\n";
771
772 int i;
773 ArrayList<String> decla;
774 ArrayList<String> inst;
775
776 String macroStr = "";
777 String initDeclStr = "";
778 String initInstStr = "";
779 String uninitDeclStr = "";
780
781 List<Token> initTokens = new ArrayList<Token> ();
782 List<Token> uninitTokens = new ArrayList<Token> ();
783
784 HashMap <String, ArrayList<String>> initCode = new HashMap<String, ArrayList<String>> ();
785 HashMap <String, ArrayList<String>> uninitCode = new HashMap<String, ArrayList<String>> ();
786
787 getTwoGroupsOfTokens (alTokens, initTokens, uninitTokens);
788
789 //
790 // Generate Structure Declaration for PcdTokens without Default Value
791 // PEI_PCD_DATABASE_INIT
792 //
793 java.util.Comparator<Token> comparator = new AlignmentSizeComp();
794 java.util.Collections.sort(initTokens, comparator);
795 initCode = processTokens(initTokens);
796
797 //
798 // Generate Structure Declaration for PcdTokens without Default Value
799 // PEI_PCD_DATABASE_UNINIT
800 //
801 java.util.Collections.sort(uninitTokens, comparator);
802 uninitCode = processTokens(uninitTokens);
803
804 //
805 // Generate size info Macro for all Tables
806 //
807 macroStr += guidTable.getSizeMacro();
808 macroStr += stringTable.getSizeMacro();
809 macroStr += skuIdTable.getSizeMacro();
810 macroStr += localTokenNumberTable.getSizeMacro();
811 macroStr += exMapTable.getSizeMacro();
812
813 //
814 // Generate existance info Macro for all Tables
815 //
816 macroStr += guidTable.getExistanceMacro();
817 macroStr += stringTable.getExistanceMacro();
818 macroStr += skuIdTable.getExistanceMacro();
819 macroStr += localTokenNumberTable.getExistanceMacro();
820 macroStr += exMapTable.getExistanceMacro();
821
822 //
823 // Generate Structure Declaration for PcdTokens with Default Value
824 // for example PEI_PCD_DATABASE_INIT
825 //
826 initDeclStr += "typedef struct {" + newLine;
827 {
828 initDeclStr += tab + exMapTable.getTypeDeclaration();
829 initDeclStr += tab + guidTable.getTypeDeclaration();
830 initDeclStr += tab + localTokenNumberTable.getTypeDeclaration();
831 initDeclStr += tab + stringTable.getTypeDeclaration();
832 initDeclStr += tab + sizeTable.getTypeDeclaration();
833 initDeclStr += tab + skuIdTable.getTypeDeclaration();
834 if (phase.equalsIgnoreCase("PEI")) {
835 initDeclStr += tab + "SKU_ID SystemSkuId;" + newLine;
836 }
837
838 decla = initCode.get(new String("Declaration"));
839 for (i = 0; i < decla.size(); i++) {
840 initDeclStr += tab + decla.get(i) + declNewLine;
841 }
842
843 //
844 // Generate Structure Declaration for PcdToken with SkuEnabled
845 //
846 decla = initCode.get("DeclarationForSku");
847
848 for (i = 0; i < decla.size(); i++) {
849 initDeclStr += tab + decla.get(i) + declNewLine;
850 }
851 }
852 initDeclStr += String.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase);
853
854 //
855 // Generate MACRO for structure intialization of PCDTokens with Default Value
856 // The sequence must match the sequence of declaration of the memembers in the structure
857 String tmp = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase());
858 initInstStr += tmp + newLine;
859 initInstStr += tab + genInstantiationStr(exMapTable.getInstantiation()) + commaNewLine;
860 initInstStr += tab + genInstantiationStr(guidTable.getInstantiation()) + commaNewLine;
861 initInstStr += tab + genInstantiationStr(localTokenNumberTable.getInstantiation()) + commaNewLine;
862 initInstStr += tab + genInstantiationStr(stringTable.getInstantiation()) + commaNewLine;
863 initInstStr += tab + genInstantiationStr(sizeTable.getInstantiation()) + commaNewLine;
864 initInstStr += tab + genInstantiationStr(skuIdTable.getInstantiation()) + commaNewLine;
865 //
866 // For SystemSkuId
867 //
868 if (phase.equalsIgnoreCase("PEI")) {
869 initInstStr += tab + "0" + tab + "/* SystemSkuId */" + commaNewLine;
870 }
871
872 inst = initCode.get("Instantiation");
873 for (i = 0; i < inst.size(); i++) {
874 initInstStr += tab + inst.get(i) + commaNewLine;
875 }
876
877 inst = initCode.get("InstantiationForSku");
878 for (i = 0; i < inst.size(); i++) {
879 initInstStr += tab + inst.get(i);
880 if (i != inst.size() - 1) {
881 initInstStr += commaNewLine;
882 }
883 }
884
885 initInstStr += "};";
886
887 uninitDeclStr += "typedef struct {" + newLine;
888 {
889 decla = uninitCode.get("Declaration");
890 if (decla.size() == 0) {
891 uninitDeclStr += "UINT8 dummy /* The UINT struct is empty */" + declNewLine;
892 } else {
893
894 for (i = 0; i < decla.size(); i++) {
895 uninitDeclStr += tab + decla.get(i) + declNewLine;
896 }
897
898 decla = uninitCode.get("DeclarationForSku");
899
900 for (i = 0; i < decla.size(); i++) {
901 uninitDeclStr += tab + decla.get(i) + declNewLine;
902 }
903 }
904 }
905 uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase);
906
907 cString = initInstStr + newLine;
908 hString = macroStr + newLine
909 + initDeclStr + newLine
910 + uninitDeclStr + newLine
911 + newLine;
912
913 hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase, version);
914
915 }
916
917 private String genInstantiationStr (ArrayList<String> alStr) {
918 String str = "";
919 for (int i = 0; i< alStr.size(); i++) {
920 str += "\t" + alStr.get(i);
921 if (i != alStr.size() - 1) {
922 str += "\r\n";
923 }
924 }
925
926 return str;
927 }
928
929 private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken)
930 throws EntityException {
931
932 HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
933
934 ArrayList<String> decl = new ArrayList<String>();
935 ArrayList<String> declForSkuEnableType = new ArrayList<String>();
936 ArrayList<String> inst = new ArrayList<String>();
937 ArrayList<String> instForSkuEnableType = new ArrayList<String>();
938
939 for (int index = 0; index < alToken.size(); index++) {
940 Token token = alToken.get(index);
941
942 if (token.isSkuEnable()) {
943 //
944 // BugBug: Schema only support Data type now
945 //
946 int tableIdx;
947
948 tableIdx = skuIdTable.add(token);
949
950 decl.add(getSkuEnabledTypeDeclaration(token));
951 if (token.hasDefaultValue()) {
952 inst.add(getSkuEnabledTypeInstantiaion(token, tableIdx));
953 }
954
955 declForSkuEnableType.add(getDataTypeDeclarationForSkuEnabled(token));
956 if (token.hasDefaultValue()) {
957 instForSkuEnableType.add(getDataTypeInstantiationForSkuEnabled(token));
958 }
959
960 } else {
961 if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {
962 decl.add(getVariableEnableTypeDeclaration(token));
963 inst.add(getVariableEnableInstantiation(token));
964 } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
965 decl.add(getVpdEnableTypeDeclaration(token));
966 inst.add(getVpdEnableTypeInstantiation(token));
967 } else if (token.isStringType()) {
968 decl.add(getStringTypeDeclaration(token));
969 inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));
970 }
971 else {
972 decl.add(getDataTypeDeclaration(token));
973 if (token.hasDefaultValue()) {
974 inst.add(getDataTypeInstantiation(token));
975 }
976 }
977 }
978
979 sizeTable.add(token);
980 localTokenNumberTable.add(token);
981 token.tokenNumber = assignedTokenNumber++;
982
983 }
984
985 map.put("Declaration", decl);
986 map.put("DeclarationForSku", declForSkuEnableType);
987 map.put("Instantiation", inst);
988 map.put("InstantiationForSku", instForSkuEnableType);
989
990 return map;
991 }
992
993 private String getSkuEnabledTypeDeclaration (Token token) {
994 return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());
995 }
996
997 private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {
998
999 String offsetof = String.format(PcdDatabase.offsetOfSkuHeadStrTemplate, phase, token.hasDefaultValue()? "Init" : "Uninit", token.getPrimaryKeyString());
1000 return String.format("{ %s, %d }", offsetof, SkuTableIdx);
1001 }
1002
1003 private String getDataTypeDeclarationForSkuEnabled (Token token) {
1004 String typeStr = "";
1005
1006 if (token.datumType == Token.DATUM_TYPE.UINT8) {
1007 typeStr = "UINT8 %s_%s[%d];\r\n";
1008 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {
1009 typeStr = "UINT16 %s_%s[%d];\r\n";
1010 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {
1011 typeStr = "UINT32 %s_%s[%d];\r\n";
1012 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {
1013 typeStr = "UINT64 %s_%s[%d];\r\n";
1014 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {
1015 typeStr = "BOOLEAN %s_%s[%d];\r\n";
1016 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {
1017 return String.format("UINT8 %s_%s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());
1018 }
1019
1020 return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.skuData.size());
1021
1022 }
1023
1024 private String getDataTypeInstantiationForSkuEnabled (Token token) {
1025 String str = "";
1026
1027 if (token.datumType == Token.DATUM_TYPE.POINTER) {
1028 return String.format("UINT8 %s_%s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.skuData.size());
1029 } else {
1030 str = "{ ";
1031 for (int idx = 0; idx < token.skuData.size(); idx++) {
1032 str += token.skuData.get(idx).toString();
1033 if (idx != token.skuData.size() - 1) {
1034 str += ", ";
1035 }
1036 }
1037 str += "}";
1038
1039 return str;
1040 }
1041
1042 }
1043
1044 private String getDataTypeInstantiation (Token token) {
1045
1046 if (token.datumType == Token.DATUM_TYPE.POINTER) {
1047 return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());
1048 } else {
1049 return String.format("%s /* %s */", token.getDefaultSku().value, token.getPrimaryKeyString());
1050 }
1051 }
1052
1053
1054 private String getDataTypeDeclaration (Token token) {
1055
1056 String typeStr = "";
1057
1058 if (token.datumType == Token.DATUM_TYPE.UINT8) {
1059 typeStr = "UINT8";
1060 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {
1061 typeStr = "UINT16";
1062 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {
1063 typeStr = "UINT32";
1064 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {
1065 typeStr = "UINT64";
1066 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {
1067 typeStr = "BOOLEAN";
1068 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {
1069 return String.format("UINT8 %s[%d]", token.getPrimaryKeyString(), token.datumSize);
1070 } else {
1071 }
1072
1073 return String.format("%s %s", typeStr, token.getPrimaryKeyString());
1074 }
1075
1076 private String getVpdEnableTypeDeclaration (Token token) {
1077 return String.format("VPD_HEAD %s", token.getPrimaryKeyString());
1078 }
1079
1080 private String getVpdEnableTypeInstantiation (Token token) {
1081 return String.format("{ %s } /* %s */", token.getDefaultSku().vpdOffset,
1082 token.getPrimaryKeyString());
1083 }
1084
1085 private String getStringTypeDeclaration (Token token) {
1086 return String.format("UINT16 %s", token.getPrimaryKeyString());
1087 }
1088
1089 private String getStringTypeInstantiation (int StringTableIdx, Token token) {
1090 return String.format ("%d /* %s */", StringTableIdx,
1091 token.getPrimaryKeyString());
1092 }
1093
1094
1095 private String getVariableEnableTypeDeclaration (Token token) {
1096 return String.format("VARIABLE_HEAD %s", token.getPrimaryKeyString());
1097 }
1098
1099 private String getVariableEnableInstantiation (Token token)
1100 throws EntityException {
1101 //
1102 // Need scott fix
1103 //
1104 return String.format("{ %d, %d, %s } /* %s */", guidTable.add(token.getDefaultSku().variableGuid, token.getPrimaryKeyString()),
1105 stringTable.add(token.getDefaultSku().getStringOfVariableName(), token),
1106 token.getDefaultSku().variableOffset,
1107 token.getPrimaryKeyString());
1108 }
1109
1110 public int getTotalTokenNumber () {
1111 return sizeTable.getTableLen();
1112 }
1113
1114 public static String getPcdDatabaseCommonDefinitions ()
1115 throws EntityException {
1116
1117 String retStr = "";
1118 try {
1119 File file = new File(GlobalData.getWorkspacePath() + File.separator +
1120 "Tools" + File.separator +
1121 "Conf" + File.separator +
1122 "Pcd" + File.separator +
1123 "PcdDatabaseCommonDefinitions.sample");
1124 FileReader reader = new FileReader(file);
1125 BufferedReader in = new BufferedReader(reader);
1126 String str;
1127 while ((str = in.readLine()) != null) {
1128 retStr = retStr +"\r\n" + str;
1129 }
1130 } catch (Exception ex) {
1131 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");
1132 }
1133
1134 return retStr;
1135 }
1136
1137 public static String getPcdDxeDatabaseDefinitions ()
1138 throws EntityException {
1139
1140 String retStr = "";
1141 try {
1142 File file = new File(GlobalData.getWorkspacePath() + File.separator +
1143 "Tools" + File.separator +
1144 "Conf" + File.separator +
1145 "Pcd" + File.separator +
1146 "PcdDatabaseDxeDefinitions.sample");
1147 FileReader reader = new FileReader(file);
1148 BufferedReader in = new BufferedReader(reader);
1149 String str;
1150 while ((str = in.readLine()) != null) {
1151 retStr = retStr +"\r\n" + str;
1152 }
1153 } catch (Exception ex) {
1154 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");
1155 }
1156
1157 return retStr;
1158 }
1159
1160 public static String getPcdPeiDatabaseDefinitions ()
1161 throws EntityException {
1162
1163 String retStr = "";
1164 try {
1165 File file = new File(GlobalData.getWorkspacePath() + File.separator +
1166 "Tools" + File.separator +
1167 "Conf" + File.separator +
1168 "Pcd" + File.separator +
1169 "PcdDatabasePeiDefinitions.sample");
1170 FileReader reader = new FileReader(file);
1171 BufferedReader in = new BufferedReader(reader);
1172 String str;
1173 while ((str = in.readLine()) != null) {
1174 retStr = retStr +"\r\n" + str;
1175 }
1176 } catch (Exception ex) {
1177 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");
1178 }
1179
1180 return retStr;
1181 }
1182
1183 }
1184
1185 class ModuleInfo {
1186 public ModuleSADocument.ModuleSA module;
1187 public UsageInstance.MODULE_TYPE type;
1188
1189 public ModuleInfo (ModuleSADocument.ModuleSA module, UsageInstance.MODULE_TYPE type) {
1190 this.module = module;
1191 this.type = type;
1192 }
1193 }
1194
1195 /** This action class is to collect PCD information from MSA, SPD, FPD xml file.
1196 This class will be used for wizard and build tools, So it can *not* inherit
1197 from buildAction or UIAction.
1198 **/
1199 public class CollectPCDAction {
1200 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.
1201 private MemoryDatabaseManager dbManager;
1202
1203 /// Workspacepath hold the workspace information.
1204 private String workspacePath;
1205
1206 /// FPD file is the root file.
1207 private String fpdFilePath;
1208
1209 /// Message level for CollectPCDAction.
1210 private int originalMessageLevel;
1211
1212 /// Cache the fpd docment instance for private usage.
1213 private FrameworkPlatformDescriptionDocument fpdDocInstance;
1214
1215 /**
1216 Set WorkspacePath parameter for this action class.
1217
1218 @param workspacePath parameter for this action
1219 **/
1220 public void setWorkspacePath(String workspacePath) {
1221 this.workspacePath = workspacePath;
1222 }
1223
1224 /**
1225 Set action message level for CollectPcdAction tool.
1226
1227 The message should be restored when this action exit.
1228
1229 @param actionMessageLevel parameter for this action
1230 **/
1231 public void setActionMessageLevel(int actionMessageLevel) {
1232 originalMessageLevel = ActionMessage.messageLevel;
1233 ActionMessage.messageLevel = actionMessageLevel;
1234 }
1235
1236 /**
1237 Set FPDFileName parameter for this action class.
1238
1239 @param fpdFilePath fpd file path
1240 **/
1241 public void setFPDFilePath(String fpdFilePath) {
1242 this.fpdFilePath = fpdFilePath;
1243 }
1244
1245 /**
1246 Common function interface for outer.
1247
1248 @param workspacePath The path of workspace of current build or analysis.
1249 @param fpdFilePath The fpd file path of current build or analysis.
1250 @param messageLevel The message level for this Action.
1251
1252 @throws Exception The exception of this function. Because it can *not* be predict
1253 where the action class will be used. So only Exception can be throw.
1254
1255 **/
1256 public void perform(String workspacePath, String fpdFilePath,
1257 int messageLevel) throws Exception {
1258 setWorkspacePath(workspacePath);
1259 setFPDFilePath(fpdFilePath);
1260 setActionMessageLevel(messageLevel);
1261 checkParameter();
1262 execute();
1263 ActionMessage.messageLevel = originalMessageLevel;
1264 }
1265
1266 /**
1267 Core execution function for this action class.
1268
1269 This function work flows will be:
1270 1) Collect and prepocess PCD information from FPD file, all PCD
1271 information will be stored into memory database.
1272 2) Generate 3 strings for
1273 a) All modules using Dynamic(Ex) PCD entry.(Token Number)
1274 b) PEI PCDDatabase (C Structure) for PCD Service PEIM.
1275 c) DXE PCD Database (C structure) for PCD Service DXE.
1276
1277
1278 @throws EntityException Exception indicate failed to execute this action.
1279
1280 **/
1281 private void execute() throws EntityException {
1282 //
1283 // Get memoryDatabaseManager instance from GlobalData.
1284 // The memoryDatabaseManager should be initialized for whatever build
1285 // tools or wizard tools
1286 //
1287 if((dbManager = GlobalData.getPCDMemoryDBManager()) == null) {
1288 throw new EntityException("The instance of PCD memory database manager is null");
1289 }
1290
1291 //
1292 // Collect all PCD information defined in FPD file.
1293 // Evenry token defind in FPD will be created as an token into
1294 // memory database.
1295 //
1296 createTokenInDBFromFPD();
1297
1298 //
1299 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver
1300 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.
1301 //
1302 genPcdDatabaseSourceCode ();
1303
1304 }
1305
1306 /**
1307 This function generates source code for PCD Database.
1308
1309 @param void
1310 @throws EntityException If the token does *not* exist in memory database.
1311
1312 **/
1313 private void genPcdDatabaseSourceCode()
1314 throws EntityException {
1315 String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();
1316
1317 ArrayList<Token> alPei = new ArrayList<Token> ();
1318 ArrayList<Token> alDxe = new ArrayList<Token> ();
1319
1320 dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);
1321 PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);
1322 pcdPeiDatabase.genCode();
1323 dbManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()
1324 + PcdDatabase.getPcdPeiDatabaseDefinitions();
1325 dbManager.PcdPeimCString = pcdPeiDatabase.getCString();
1326
1327 PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe,
1328 "DXE",
1329 alPei.size()
1330 );
1331 pcdDxeDatabase.genCode();
1332 dbManager.PcdDxeHString = dbManager.PcdPeimHString + pcdDxeDatabase.getHString()
1333 + PcdDatabase.getPcdDxeDatabaseDefinitions();
1334 dbManager.PcdDxeCString = pcdDxeDatabase.getCString();
1335 }
1336
1337 /**
1338 Get component array from FPD.
1339
1340 This function maybe provided by some Global class.
1341
1342 @return List<ModuleInfo> the component array.
1343
1344 */
1345 private List<ModuleInfo> getComponentsFromFPD()
1346 throws EntityException {
1347 HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();
1348 List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();
1349 ModuleInfo current = null;
1350 int index = 0;
1351 org.tianocore.Components components = null;
1352 FrameworkModulesDocument.FrameworkModules fModules = null;
1353 java.util.List<ModuleSADocument.ModuleSA> modules = null;
1354
1355
1356 if (fpdDocInstance == null) {
1357 try {
1358 fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));
1359 } catch(IOException ioE) {
1360 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());
1361 } catch(XmlException xmlE) {
1362 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());
1363 }
1364
1365 }
1366
1367 //
1368 // Check whether FPD contians <FramworkModules>
1369 //
1370 fModules = fpdDocInstance.getFrameworkPlatformDescription().getFrameworkModules();
1371 if (fModules == null) {
1372 return null;
1373 }
1374
1375 //
1376 // BUGBUG: The following is work around code, the final component type should be get from
1377 // GlobalData class.
1378 //
1379 components = fModules.getSEC();
1380 if (components != null) {
1381 modules = components.getModuleSAList();
1382 for (index = 0; index < modules.size(); index ++) {
1383 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.SEC));
1384 }
1385 }
1386
1387 components = fModules.getPEICORE();
1388 if (components != null) {
1389 modules = components.getModuleSAList();
1390 for (index = 0; index < modules.size(); index ++) {
1391 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEI_CORE));
1392 }
1393 }
1394
1395 components = fModules.getPEIM();
1396 if (components != null) {
1397 modules = components.getModuleSAList();
1398 for (index = 0; index < modules.size(); index ++) {
1399 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEIM));
1400 }
1401 }
1402
1403 components = fModules.getDXECORE();
1404 if (components != null) {
1405 modules = components.getModuleSAList();
1406 for (index = 0; index < modules.size(); index ++) {
1407 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_CORE));
1408 }
1409 }
1410
1411 components = fModules.getDXEDRIVERS();
1412 if (components != null) {
1413 modules = components.getModuleSAList();
1414 for (index = 0; index < modules.size(); index ++) {
1415 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_DRIVERS));
1416 }
1417 }
1418
1419 components = fModules.getOTHERCOMPONENTS();
1420 if (components != null) {
1421 modules = components.getModuleSAList();
1422 for (index = 0; index < modules.size(); index ++) {
1423 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.OTHER_COMPONENTS));
1424 }
1425 }
1426
1427 return allModules;
1428 }
1429
1430 /**
1431 Create token instance object into memory database, the token information
1432 comes for FPD file. Normally, FPD file will contain all token platform
1433 informations.
1434
1435 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.
1436
1437 @throws EntityException Failed to parse FPD xml file.
1438
1439 **/
1440 private void createTokenInDBFromFPD()
1441 throws EntityException {
1442 int index = 0;
1443 int index2 = 0;
1444 int pcdIndex = 0;
1445 List<PcdBuildDefinition.PcdData> pcdBuildDataArray = new ArrayList<PcdBuildDefinition.PcdData>();
1446 PcdBuildDefinition.PcdData pcdBuildData = null;
1447 Token token = null;
1448 SkuInstance skuInstance = null;
1449 int skuIndex = 0;
1450 List<ModuleInfo> modules = null;
1451 String primaryKey = null;
1452 String exceptionString = null;
1453 UsageInstance usageInstance = null;
1454 String primaryKey1 = null;
1455 String primaryKey2 = null;
1456 boolean isDuplicate = false;
1457 Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;
1458 Token.DATUM_TYPE datumType = Token.DATUM_TYPE.UNKNOWN;
1459 int tokenNumber = 0;
1460 String moduleName = null;
1461 String datum = null;
1462 int maxDatumSize = 0;
1463
1464 //
1465 // ----------------------------------------------
1466 // 1), Get all <ModuleSA> from FPD file.
1467 // ----------------------------------------------
1468 //
1469 modules = getComponentsFromFPD();
1470
1471 if (modules == null) {
1472 throw new EntityException("[FPD file error] No modules in FPD file, Please check whether there are elements in <FrameworkModules> in FPD file!");
1473 }
1474
1475 //
1476 // -------------------------------------------------------------------
1477 // 2), Loop all modules to process <PcdBuildDeclarations> for each module.
1478 // -------------------------------------------------------------------
1479 //
1480 for (index = 0; index < modules.size(); index ++) {
1481 isDuplicate = false;
1482 for (index2 = 0; index2 < index; index2 ++) {
1483 //
1484 // BUGBUG: For transition schema, we can *not* get module's version from
1485 // <ModuleSAs>, It is work around code.
1486 //
1487 primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).module.getModuleName(),
1488 translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()),
1489 modules.get(index).module.getPackageName(),
1490 translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()),
1491 modules.get(index).module.getArch().toString(),
1492 null);
1493 primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(),
1494 translateSchemaStringToUUID(modules.get(index2).module.getModuleGuid()),
1495 modules.get(index2).module.getPackageName(),
1496 translateSchemaStringToUUID(modules.get(index2).module.getPackageGuid()),
1497 modules.get(index2).module.getArch().toString(),
1498 null);
1499 if (primaryKey1.equalsIgnoreCase(primaryKey2)) {
1500 isDuplicate = true;
1501 break;
1502 }
1503 }
1504
1505 if (isDuplicate) {
1506 continue;
1507 }
1508
1509 //
1510 // It is legal for a module does not contains ANY pcd build definitions.
1511 //
1512 if (modules.get(index).module.getPcdBuildDefinition() == null) {
1513 continue;
1514 }
1515
1516 pcdBuildDataArray = modules.get(index).module.getPcdBuildDefinition().getPcdDataList();
1517
1518 moduleName = modules.get(index).module.getModuleName();
1519
1520 //
1521 // ----------------------------------------------------------------------
1522 // 2.1), Loop all Pcd entry for a module and add it into memory database.
1523 // ----------------------------------------------------------------------
1524 //
1525 for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {
1526 pcdBuildData = pcdBuildDataArray.get(pcdIndex);
1527 primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),
1528 translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));
1529 pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());
1530 datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());
1531 tokenNumber = Integer.decode(pcdBuildData.getToken().toString());
1532 datum = pcdBuildData.getValue();
1533 maxDatumSize = pcdBuildData.getMaxDatumSize();
1534
1535 //
1536 // -------------------------------------------------------------------------------------------
1537 // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule
1538 // -------------------------------------------------------------------------------------------
1539 //
1540 if (!Token.isDynamic(pcdType)) {
1541 //
1542 // Value is required.
1543 //
1544 if (datum == null) {
1545 exceptionString = String.format("[FPD file error] There is no value for PCD entry %s in module %s!",
1546 pcdBuildData.getCName(),
1547 moduleName);
1548 throw new EntityException(exceptionString);
1549 }
1550
1551 //
1552 // Check whether the datum size is matched datum type.
1553 //
1554 if ((exceptionString = verifyDatumSize(pcdBuildData.getCName(),
1555 moduleName,
1556 maxDatumSize,
1557 datumType)) != null) {
1558 throw new EntityException(exceptionString);
1559 }
1560 }
1561
1562 //
1563 // ---------------------------------------------------------------------------------
1564 // 2.1.2), Create token or update token information for current anaylized PCD data.
1565 // ---------------------------------------------------------------------------------
1566 //
1567 if (dbManager.isTokenInDatabase(primaryKey)) {
1568 //
1569 // If the token is already exist in database, do some necessary checking
1570 // and add a usage instance into this token in database
1571 //
1572 token = dbManager.getTokenByKey(primaryKey);
1573
1574 //
1575 // checking for DatumType, DatumType should be unique for one PCD used in different
1576 // modules.
1577 //
1578 if (token.datumType != datumType) {
1579 exceptionString = String.format("[FPD file error] The datum type of PCD entry %s is %s, which is different with %s defined in before!",
1580 pcdBuildData.getCName(),
1581 pcdBuildData.getDatumType().toString(),
1582 Token.getStringOfdatumType(token.datumType));
1583 throw new EntityException(exceptionString);
1584 }
1585
1586 //
1587 // Check token number is valid
1588 //
1589 if (tokenNumber != token.tokenNumber) {
1590 exceptionString = String.format("[FPD file error] The token number of PCD entry %s in module %s is different with same PCD entry in other modules!",
1591 pcdBuildData.getCName(),
1592 moduleName);
1593 throw new EntityException(exceptionString);
1594 }
1595
1596 //
1597 // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.
1598 //
1599 if (token.isDynamicPCD != Token.isDynamic(pcdType)) {
1600 exceptionString = String.format("[FPD file error] For PCD entry %s in module %s, you define dynamic or non-dynamic PCD type which"+
1601 "is different with others module's",
1602 token.cName,
1603 moduleName);
1604 throw new EntityException(exceptionString);
1605 }
1606
1607 if (token.isDynamicPCD) {
1608 //
1609 // Check datum is equal the datum in dynamic information.
1610 // For dynamic PCD, you can do not write <Value> in sperated every <PcdBuildDefinition> in different <ModuleSA>,
1611 // But if you write, the <Value> must be same as the value in <DynamicPcdBuildDefinitions>.
1612 //
1613 if (!token.isSkuEnable() &&
1614 (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.DEFAULT_TYPE) &&
1615 (datum != null)) {
1616 if (!datum.equalsIgnoreCase(token.getDefaultSku().value)) {
1617 exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the datum in <ModuleSA> is "+
1618 "not equal to the datum in <DynamicPcdBuildDefinitions>, it is "+
1619 "illega! You could no set <Value> in <ModuleSA> for a dynamic PCD!",
1620 token.cName,
1621 moduleName);
1622 throw new EntityException(exceptionString);
1623 }
1624 }
1625
1626 if ((maxDatumSize != 0) &&
1627 (maxDatumSize != token.datumSize)){
1628 exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the max datum size is %d which "+
1629 "is different with <MaxDatumSize> %d defined in <DynamicPcdBuildDefinitions>!",
1630 token.cName,
1631 moduleName,
1632 maxDatumSize,
1633 token.datumSize);
1634 throw new EntityException(exceptionString);
1635 }
1636 }
1637
1638 } else {
1639 //
1640 // If the token is not in database, create a new token instance and add
1641 // a usage instance into this token in database.
1642 //
1643 token = new Token(pcdBuildData.getCName(),
1644 translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));
1645
1646 token.datumType = datumType;
1647 token.tokenNumber = tokenNumber;
1648 token.isDynamicPCD = Token.isDynamic(pcdType);
1649 token.datumSize = maxDatumSize;
1650
1651 if (token.isDynamicPCD) {
1652 //
1653 // For Dynamic and Dynamic Ex type, need find the dynamic information
1654 // in <DynamicPcdBuildDefinition> section in FPD file.
1655 //
1656 updateDynamicInformation(moduleName,
1657 token,
1658 datum,
1659 maxDatumSize);
1660 }
1661
1662 dbManager.addTokenToDatabase(primaryKey, token);
1663 }
1664
1665 //
1666 // -----------------------------------------------------------------------------------
1667 // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.
1668 // -----------------------------------------------------------------------------------
1669 //
1670 token.updateSupportPcdType(pcdType);
1671
1672 //
1673 // ------------------------------------------------
1674 // 2.1.4), Create an usage instance for this token.
1675 // ------------------------------------------------
1676 //
1677 usageInstance = new UsageInstance(token,
1678 moduleName,
1679 translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()),
1680 modules.get(index).module.getPackageName(),
1681 translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()),
1682 modules.get(index).type,
1683 pcdType,
1684 modules.get(index).module.getArch().toString(),
1685 null,
1686 datum,
1687 maxDatumSize);
1688 token.addUsageInstance(usageInstance);
1689 }
1690 }
1691 }
1692
1693 /**
1694 Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.
1695
1696 This function should be implemented in GlobalData in future.
1697
1698 @param token The token instance which has hold module's PCD information
1699 @param moduleName The name of module who will use this Dynamic PCD.
1700
1701 @return DynamicPcdBuildDefinitions.PcdBuildData
1702 */
1703 /***/
1704 private DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFPD(Token token,
1705 String moduleName)
1706 throws EntityException {
1707 int index = 0;
1708 String exceptionString = null;
1709 String dynamicPrimaryKey = null;
1710 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;
1711 List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;
1712
1713 //
1714 // If FPD document is not be opened, open and initialize it.
1715 //
1716 if (fpdDocInstance == null) {
1717 try {
1718 fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));
1719 } catch(IOException ioE) {
1720 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());
1721 } catch(XmlException xmlE) {
1722 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());
1723 }
1724 }
1725
1726 dynamicPcdBuildDefinitions = fpdDocInstance.getFrameworkPlatformDescription().getDynamicPcdBuildDefinitions();
1727 if (dynamicPcdBuildDefinitions == null) {
1728 exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+
1729 "PCD entry %s in module %s!",
1730 token.cName,
1731 moduleName);
1732 throw new EntityException(exceptionString);
1733 }
1734
1735 dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();
1736 for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {
1737 dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),
1738 translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid()));
1739 if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {
1740 return dynamicPcdBuildDataArray.get(index);
1741 }
1742 }
1743
1744 return null;
1745 }
1746
1747 /**
1748 Verify the maxDatumSize for a PCD data is matched to Datum type.
1749
1750 @param token The token instance
1751 @param moduleName The module name who use this PCD data.
1752 @param maxDatumSize The value of max datum size in FPD file
1753 @param datumType The datum type
1754
1755 @return String if is unmatched, set the exception information
1756 as return value, otherwice is null.
1757 **/
1758 private String verifyDatumSize(String cName,
1759 String moduleName,
1760 int maxDatumSize,
1761 Token.DATUM_TYPE datumType) {
1762 String exceptionString = null;
1763
1764 if (maxDatumSize == 0) {
1765 exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in module %s",
1766 cName,
1767 moduleName);
1768 return exceptionString;
1769 }
1770
1771 switch (datumType) {
1772 case UINT8:
1773 if (maxDatumSize != 1) {
1774 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+
1775 "is UINT8, but datum size is %d, they are not matched!",
1776 cName,
1777 moduleName,
1778 maxDatumSize);
1779 }
1780 break;
1781 case UINT16:
1782 if (maxDatumSize != 2) {
1783 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+
1784 "is UINT16, but datum size is %d, they are not matched!",
1785 cName,
1786 moduleName,
1787 maxDatumSize);
1788 }
1789 break;
1790 case UINT32:
1791 if (maxDatumSize != 4) {
1792 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1793 "is UINT32, but datum size is %d, they are not matched!",
1794 cName,
1795 moduleName,
1796 maxDatumSize);
1797 }
1798 break;
1799 case UINT64:
1800 if (maxDatumSize != 8) {
1801 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1802 "is UINT64, but datum size is %d, they are not matched!",
1803 cName,
1804 moduleName,
1805 maxDatumSize);
1806 }
1807 break;
1808 case BOOLEAN:
1809 if (maxDatumSize != 1) {
1810 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1811 "is BOOLEAN, but datum size is %d, they are not matched!",
1812 cName,
1813 moduleName,
1814 maxDatumSize);
1815 }
1816 break;
1817 }
1818
1819 return exceptionString;
1820 }
1821
1822 /**
1823 Update dynamic information for PCD entry.
1824
1825 Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in
1826 FPD file.
1827
1828 @param moduleName The name of the module who use this PCD
1829 @param token The token instance
1830 @param datum The <datum> in module's PCD information
1831 @param maxDatumSize The <maxDatumSize> in module's PCD information
1832
1833 @return Token
1834 */
1835 private Token updateDynamicInformation(String moduleName,
1836 Token token,
1837 String datum,
1838 int maxDatumSize)
1839 throws EntityException {
1840 int index = 0;
1841 int offset;
1842 String exceptionString = null;
1843 DynamicTokenValue dynamicValue;
1844 SkuInstance skuInstance = null;
1845 String temp;
1846 boolean hasSkuId0 = false;
1847
1848 List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> skuInfoList = null;
1849 DynamicPcdBuildDefinitions.PcdBuildData dynamicInfo = null;
1850
1851 dynamicInfo = getDynamicInfoFromFPD(token, moduleName);
1852 if (dynamicInfo == null) {
1853 exceptionString = String.format("[FPD file error] For Dynamic PCD %s used by module %s, "+
1854 "there is no dynamic information in <DynamicPcdBuildDefinitions> "+
1855 "in FPD file, but it is required!",
1856 token.cName,
1857 moduleName);
1858 throw new EntityException(exceptionString);
1859 }
1860
1861 token.datumSize = dynamicInfo.getMaxDatumSize();
1862
1863 exceptionString = verifyDatumSize(token.cName, moduleName, token.datumSize, token.datumType);
1864 if (exceptionString != null) {
1865 throw new EntityException(exceptionString);
1866 }
1867
1868 if ((maxDatumSize != 0) &&
1869 (maxDatumSize != token.datumSize)) {
1870 exceptionString = String.format("FPD file error] For dynamic PCD %s, the datum size in module %s is %d, but "+
1871 "the datum size in <DynamicPcdBuildDefinitions> is %d, they are not match!",
1872 token.cName,
1873 moduleName,
1874 maxDatumSize,
1875 dynamicInfo.getMaxDatumSize());
1876 throw new EntityException(exceptionString);
1877 }
1878
1879 skuInfoList = dynamicInfo.getSkuInfoList();
1880
1881 //
1882 // Loop all sku data
1883 //
1884 for (index = 0; index < skuInfoList.size(); index ++) {
1885 skuInstance = new SkuInstance();
1886 //
1887 // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.
1888 //
1889 temp = skuInfoList.get(index).getSkuId().toString();
1890 skuInstance.id = Integer.decode(temp);
1891 if (skuInstance.id == 0) {
1892 hasSkuId0 = true;
1893 }
1894 //
1895 // Judge whether is DefaultGroup at first, because most case is DefautlGroup.
1896 //
1897 if (skuInfoList.get(index).getValue() != null) {
1898 skuInstance.value.setValue(skuInfoList.get(index).getValue());
1899 token.skuData.add(skuInstance);
1900
1901 //
1902 // Judege wether is same of datum between module's information
1903 // and dynamic information.
1904 //
1905 if (datum != null) {
1906 if ((skuInstance.id == 0) &&
1907 !datum.equalsIgnoreCase(skuInfoList.get(index).getValue())) {
1908 exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module is " + datum.toString() + " but the "+
1909 "value of sku 0 data in <DynamicPcdBuildDefinition> is " + skuInstance.value.value + ". They are must be same!"+
1910 " or you could not define value for a dynamic PCD in every <ModuleSA>!";
1911 throw new EntityException(exceptionString);
1912 }
1913 }
1914 continue;
1915 }
1916
1917 //
1918 // Judge whether is HII group case.
1919 //
1920 if (skuInfoList.get(index).getVariableName() != null) {
1921 exceptionString = null;
1922 if (skuInfoList.get(index).getVariableGuid() == null) {
1923 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1924 "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",
1925 token.cName,
1926 index);
1927
1928 }
1929
1930 if (skuInfoList.get(index).getVariableOffset() == null) {
1931 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1932 "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",
1933 token.cName,
1934 index);
1935 }
1936
1937 if (skuInfoList.get(index).getHiiDefaultValue() == null) {
1938 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1939 "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",
1940 token.cName,
1941 index);
1942 }
1943
1944 if (exceptionString != null) {
1945 throw new EntityException(exceptionString);
1946 }
1947 offset = Integer.decode(skuInfoList.get(index).getVariableOffset());
1948 if (offset > 0xFFFF) {
1949 throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+
1950 "exceed 64K, it is not allowed!",
1951 token.cName,
1952 index));
1953 }
1954
1955 skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(),
1956 translateSchemaStringToUUID(skuInfoList.get(index).getVariableGuid().toString()),
1957 skuInfoList.get(index).getVariableOffset(),
1958 skuInfoList.get(index).getHiiDefaultValue());
1959 token.skuData.add(skuInstance);
1960 continue;
1961 }
1962
1963 if (skuInfoList.get(index).getVpdOffset() != null) {
1964 skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());
1965 token.skuData.add(skuInstance);
1966 continue;
1967 }
1968
1969 exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+
1970 "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",
1971 token.cName);
1972 throw new EntityException(exceptionString);
1973 }
1974
1975 if (!hasSkuId0) {
1976 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+
1977 "no sku id = 0 data, which is required for every dynamic PCD",
1978 token.cName);
1979 throw new EntityException(exceptionString);
1980 }
1981
1982 return token;
1983 }
1984
1985 /**
1986 Translate the schema string to UUID instance.
1987
1988 In schema, the string of UUID is defined as following two types string:
1989 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(
1990 )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?
1991
1992 2) GuidNamingConvention: pattern =
1993 [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}
1994
1995 This function will convert string and create uuid instance.
1996
1997 @param uuidString UUID string in XML file
1998
1999 @return UUID UUID instance
2000 **/
2001 private UUID translateSchemaStringToUUID(String uuidString)
2002 throws EntityException {
2003 String temp;
2004 String[] splitStringArray;
2005 int index;
2006 int chIndex;
2007 int chLen;
2008
2009 if (uuidString == null) {
2010 return null;
2011 }
2012
2013 if (uuidString.length() == 0) {
2014 return null;
2015 }
2016
2017 if (uuidString.equals("0") ||
2018 uuidString.equalsIgnoreCase("0x0")) {
2019 return new UUID(0, 0);
2020 }
2021
2022 //
2023 // If the UUID schema string is GuidArrayType type then need translate
2024 // to GuidNamingConvention type at first.
2025 //
2026 if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {
2027 splitStringArray = uuidString.split("," );
2028 if (splitStringArray.length != 11) {
2029 throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);
2030 }
2031
2032 //
2033 // Remove blank space from these string and remove header string "0x"
2034 //
2035 for (index = 0; index < 11; index ++) {
2036 splitStringArray[index] = splitStringArray[index].trim();
2037 splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());
2038 }
2039
2040 //
2041 // Add heading '0' to normalize the string length
2042 //
2043 for (index = 3; index < 11; index ++) {
2044 chLen = splitStringArray[index].length();
2045 for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {
2046 splitStringArray[index] = "0" + splitStringArray[index];
2047 }
2048 }
2049
2050 //
2051 // construct the final GuidNamingConvention string
2052 //
2053 temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",
2054 splitStringArray[0],
2055 splitStringArray[1],
2056 splitStringArray[2],
2057 splitStringArray[3],
2058 splitStringArray[4],
2059 splitStringArray[5],
2060 splitStringArray[6],
2061 splitStringArray[7],
2062 splitStringArray[8],
2063 splitStringArray[9],
2064 splitStringArray[10]);
2065 uuidString = temp;
2066 }
2067
2068 return UUID.fromString(uuidString);
2069 }
2070
2071 /**
2072 check parameter for this action.
2073
2074 @throws EntityException Bad parameter.
2075 **/
2076 private void checkParameter() throws EntityException {
2077 File file = null;
2078
2079 if((fpdFilePath == null) ||(workspacePath == null)) {
2080 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
2081 }
2082
2083 if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {
2084 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
2085 }
2086
2087 file = new File(workspacePath);
2088 if(!file.exists()) {
2089 throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");
2090 }
2091
2092 file = new File(fpdFilePath);
2093
2094 if(!file.exists()) {
2095 throw new EntityException("FPD File " + fpdFilePath + " does not exist!");
2096 }
2097 }
2098
2099 /**
2100 Test case function
2101
2102 @param argv parameter from command line
2103 **/
2104 public static void main(String argv[]) throws EntityException {
2105 CollectPCDAction ca = new CollectPCDAction();
2106 ca.setWorkspacePath("m:/tianocore/edk2");
2107 ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");
2108 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);
2109 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",
2110 "m:/tianocore/edk2");
2111 ca.execute();
2112 }
2113 }