]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Fix two transition issue:
[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 null,
1489 null,
1490 null,
1491 modules.get(index).module.getArch().toString(),
1492 null);
1493 primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(),
1494 null,
1495 null,
1496 null,
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 // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools
1537 // will check that, following checking code could be removed.
1538 //
1539 if (pcdBuildData.getTokenSpaceGuid() == null) {
1540 exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in module %s! This is required!",
1541 pcdBuildData.getCName(),
1542 moduleName);
1543 throw new EntityException(exceptionString);
1544 }
1545
1546 //
1547 // -------------------------------------------------------------------------------------------
1548 // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule
1549 // -------------------------------------------------------------------------------------------
1550 //
1551 if (!Token.isDynamic(pcdType)) {
1552 //
1553 // Value is required.
1554 //
1555 if (datum == null) {
1556 exceptionString = String.format("[FPD file error] There is no value for PCD entry %s in module %s!",
1557 pcdBuildData.getCName(),
1558 moduleName);
1559 throw new EntityException(exceptionString);
1560 }
1561
1562 //
1563 // Check whether the datum size is matched datum type.
1564 //
1565 if ((exceptionString = verifyDatumSize(pcdBuildData.getCName(),
1566 moduleName,
1567 maxDatumSize,
1568 datumType)) != null) {
1569 throw new EntityException(exceptionString);
1570 }
1571 }
1572
1573 //
1574 // ---------------------------------------------------------------------------------
1575 // 2.1.2), Create token or update token information for current anaylized PCD data.
1576 // ---------------------------------------------------------------------------------
1577 //
1578 if (dbManager.isTokenInDatabase(primaryKey)) {
1579 //
1580 // If the token is already exist in database, do some necessary checking
1581 // and add a usage instance into this token in database
1582 //
1583 token = dbManager.getTokenByKey(primaryKey);
1584
1585 //
1586 // checking for DatumType, DatumType should be unique for one PCD used in different
1587 // modules.
1588 //
1589 if (token.datumType != datumType) {
1590 exceptionString = String.format("[FPD file error] The datum type of PCD entry %s is %s, which is different with %s defined in before!",
1591 pcdBuildData.getCName(),
1592 pcdBuildData.getDatumType().toString(),
1593 Token.getStringOfdatumType(token.datumType));
1594 throw new EntityException(exceptionString);
1595 }
1596
1597 //
1598 // Check token number is valid
1599 //
1600 if (tokenNumber != token.tokenNumber) {
1601 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!",
1602 pcdBuildData.getCName(),
1603 moduleName);
1604 throw new EntityException(exceptionString);
1605 }
1606
1607 //
1608 // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.
1609 //
1610 if (token.isDynamicPCD != Token.isDynamic(pcdType)) {
1611 exceptionString = String.format("[FPD file error] For PCD entry %s in module %s, you define dynamic or non-dynamic PCD type which"+
1612 "is different with others module's",
1613 token.cName,
1614 moduleName);
1615 throw new EntityException(exceptionString);
1616 }
1617
1618 if (token.isDynamicPCD) {
1619 //
1620 // Check datum is equal the datum in dynamic information.
1621 // For dynamic PCD, you can do not write <Value> in sperated every <PcdBuildDefinition> in different <ModuleSA>,
1622 // But if you write, the <Value> must be same as the value in <DynamicPcdBuildDefinitions>.
1623 //
1624 if (!token.isSkuEnable() &&
1625 (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.DEFAULT_TYPE) &&
1626 (datum != null)) {
1627 if (!datum.equalsIgnoreCase(token.getDefaultSku().value)) {
1628 exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the datum in <ModuleSA> is "+
1629 "not equal to the datum in <DynamicPcdBuildDefinitions>, it is "+
1630 "illega! You could no set <Value> in <ModuleSA> for a dynamic PCD!",
1631 token.cName,
1632 moduleName);
1633 throw new EntityException(exceptionString);
1634 }
1635 }
1636
1637 if ((maxDatumSize != 0) &&
1638 (maxDatumSize != token.datumSize)){
1639 exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the max datum size is %d which "+
1640 "is different with <MaxDatumSize> %d defined in <DynamicPcdBuildDefinitions>!",
1641 token.cName,
1642 moduleName,
1643 maxDatumSize,
1644 token.datumSize);
1645 throw new EntityException(exceptionString);
1646 }
1647 }
1648
1649 } else {
1650 //
1651 // If the token is not in database, create a new token instance and add
1652 // a usage instance into this token in database.
1653 //
1654 token = new Token(pcdBuildData.getCName(),
1655 translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));
1656
1657 token.datumType = datumType;
1658 token.tokenNumber = tokenNumber;
1659 token.isDynamicPCD = Token.isDynamic(pcdType);
1660 token.datumSize = maxDatumSize;
1661
1662 if (token.isDynamicPCD) {
1663 //
1664 // For Dynamic and Dynamic Ex type, need find the dynamic information
1665 // in <DynamicPcdBuildDefinition> section in FPD file.
1666 //
1667 updateDynamicInformation(moduleName,
1668 token,
1669 datum,
1670 maxDatumSize);
1671 }
1672
1673 dbManager.addTokenToDatabase(primaryKey, token);
1674 }
1675
1676 //
1677 // -----------------------------------------------------------------------------------
1678 // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.
1679 // -----------------------------------------------------------------------------------
1680 //
1681 token.updateSupportPcdType(pcdType);
1682
1683 //
1684 // ------------------------------------------------
1685 // 2.1.4), Create an usage instance for this token.
1686 // ------------------------------------------------
1687 //
1688 usageInstance = new UsageInstance(token,
1689 moduleName,
1690 null,
1691 null,
1692 null,
1693 modules.get(index).type,
1694 pcdType,
1695 modules.get(index).module.getArch().toString(),
1696 null,
1697 datum,
1698 maxDatumSize);
1699 token.addUsageInstance(usageInstance);
1700 }
1701 }
1702 }
1703
1704 /**
1705 Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.
1706
1707 This function should be implemented in GlobalData in future.
1708
1709 @param token The token instance which has hold module's PCD information
1710 @param moduleName The name of module who will use this Dynamic PCD.
1711
1712 @return DynamicPcdBuildDefinitions.PcdBuildData
1713 */
1714 /***/
1715 private DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFPD(Token token,
1716 String moduleName)
1717 throws EntityException {
1718 int index = 0;
1719 String exceptionString = null;
1720 String dynamicPrimaryKey = null;
1721 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;
1722 List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;
1723
1724 //
1725 // If FPD document is not be opened, open and initialize it.
1726 //
1727 if (fpdDocInstance == null) {
1728 try {
1729 fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));
1730 } catch(IOException ioE) {
1731 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());
1732 } catch(XmlException xmlE) {
1733 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());
1734 }
1735 }
1736
1737 dynamicPcdBuildDefinitions = fpdDocInstance.getFrameworkPlatformDescription().getDynamicPcdBuildDefinitions();
1738 if (dynamicPcdBuildDefinitions == null) {
1739 exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+
1740 "PCD entry %s in module %s!",
1741 token.cName,
1742 moduleName);
1743 throw new EntityException(exceptionString);
1744 }
1745
1746 dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();
1747 for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {
1748 //
1749 // Check <TokenSpaceGuid> is exist? In future, because all schema verification will tools
1750 // will check that, following checking code could be removed.
1751 //
1752 if (dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid() == null) {
1753 exceptionString = String.format("[FPD file error] There is no <TokenSpaceGuid> for PCD %s in <DynamicPcdBuildDefinitions>! This is required!",
1754 dynamicPcdBuildDataArray.get(index).getCName());
1755 throw new EntityException(exceptionString);
1756 }
1757
1758 dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),
1759 translateSchemaStringToUUID(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuid()));
1760 if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {
1761 return dynamicPcdBuildDataArray.get(index);
1762 }
1763 }
1764
1765 return null;
1766 }
1767
1768 /**
1769 Verify the maxDatumSize for a PCD data is matched to Datum type.
1770
1771 @param token The token instance
1772 @param moduleName The module name who use this PCD data.
1773 @param maxDatumSize The value of max datum size in FPD file
1774 @param datumType The datum type
1775
1776 @return String if is unmatched, set the exception information
1777 as return value, otherwice is null.
1778 **/
1779 private String verifyDatumSize(String cName,
1780 String moduleName,
1781 int maxDatumSize,
1782 Token.DATUM_TYPE datumType) {
1783 String exceptionString = null;
1784
1785 if (maxDatumSize == 0) {
1786 exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in module %s",
1787 cName,
1788 moduleName);
1789 return exceptionString;
1790 }
1791
1792 switch (datumType) {
1793 case UINT8:
1794 if (maxDatumSize != 1) {
1795 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+
1796 "is UINT8, but datum size is %d, they are not matched!",
1797 cName,
1798 moduleName,
1799 maxDatumSize);
1800 }
1801 break;
1802 case UINT16:
1803 if (maxDatumSize != 2) {
1804 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in module %s "+
1805 "is UINT16, but datum size is %d, they are not matched!",
1806 cName,
1807 moduleName,
1808 maxDatumSize);
1809 }
1810 break;
1811 case UINT32:
1812 if (maxDatumSize != 4) {
1813 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1814 "is UINT32, but datum size is %d, they are not matched!",
1815 cName,
1816 moduleName,
1817 maxDatumSize);
1818 }
1819 break;
1820 case UINT64:
1821 if (maxDatumSize != 8) {
1822 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1823 "is UINT64, but datum size is %d, they are not matched!",
1824 cName,
1825 moduleName,
1826 maxDatumSize);
1827 }
1828 break;
1829 case BOOLEAN:
1830 if (maxDatumSize != 1) {
1831 exceptionString = String.format("[FPD file error] the datum type of PCD data %s in module %s "+
1832 "is BOOLEAN, but datum size is %d, they are not matched!",
1833 cName,
1834 moduleName,
1835 maxDatumSize);
1836 }
1837 break;
1838 }
1839
1840 return exceptionString;
1841 }
1842
1843 /**
1844 Update dynamic information for PCD entry.
1845
1846 Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in
1847 FPD file.
1848
1849 @param moduleName The name of the module who use this PCD
1850 @param token The token instance
1851 @param datum The <datum> in module's PCD information
1852 @param maxDatumSize The <maxDatumSize> in module's PCD information
1853
1854 @return Token
1855 */
1856 private Token updateDynamicInformation(String moduleName,
1857 Token token,
1858 String datum,
1859 int maxDatumSize)
1860 throws EntityException {
1861 int index = 0;
1862 int offset;
1863 String exceptionString = null;
1864 DynamicTokenValue dynamicValue;
1865 SkuInstance skuInstance = null;
1866 String temp;
1867 boolean hasSkuId0 = false;
1868
1869 List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> skuInfoList = null;
1870 DynamicPcdBuildDefinitions.PcdBuildData dynamicInfo = null;
1871
1872 dynamicInfo = getDynamicInfoFromFPD(token, moduleName);
1873 if (dynamicInfo == null) {
1874 exceptionString = String.format("[FPD file error] For Dynamic PCD %s used by module %s, "+
1875 "there is no dynamic information in <DynamicPcdBuildDefinitions> "+
1876 "in FPD file, but it is required!",
1877 token.cName,
1878 moduleName);
1879 throw new EntityException(exceptionString);
1880 }
1881
1882 token.datumSize = dynamicInfo.getMaxDatumSize();
1883
1884 exceptionString = verifyDatumSize(token.cName, moduleName, token.datumSize, token.datumType);
1885 if (exceptionString != null) {
1886 throw new EntityException(exceptionString);
1887 }
1888
1889 if ((maxDatumSize != 0) &&
1890 (maxDatumSize != token.datumSize)) {
1891 exceptionString = String.format("FPD file error] For dynamic PCD %s, the datum size in module %s is %d, but "+
1892 "the datum size in <DynamicPcdBuildDefinitions> is %d, they are not match!",
1893 token.cName,
1894 moduleName,
1895 maxDatumSize,
1896 dynamicInfo.getMaxDatumSize());
1897 throw new EntityException(exceptionString);
1898 }
1899
1900 skuInfoList = dynamicInfo.getSkuInfoList();
1901
1902 //
1903 // Loop all sku data
1904 //
1905 for (index = 0; index < skuInfoList.size(); index ++) {
1906 skuInstance = new SkuInstance();
1907 //
1908 // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.
1909 //
1910 temp = skuInfoList.get(index).getSkuId().toString();
1911 skuInstance.id = Integer.decode(temp);
1912 if (skuInstance.id == 0) {
1913 hasSkuId0 = true;
1914 }
1915 //
1916 // Judge whether is DefaultGroup at first, because most case is DefautlGroup.
1917 //
1918 if (skuInfoList.get(index).getValue() != null) {
1919 skuInstance.value.setValue(skuInfoList.get(index).getValue());
1920 token.skuData.add(skuInstance);
1921
1922 //
1923 // Judege wether is same of datum between module's information
1924 // and dynamic information.
1925 //
1926 if (datum != null) {
1927 if ((skuInstance.id == 0) &&
1928 !datum.equalsIgnoreCase(skuInfoList.get(index).getValue())) {
1929 exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module is " + datum.toString() + " but the "+
1930 "value of sku 0 data in <DynamicPcdBuildDefinition> is " + skuInstance.value.value + ". They are must be same!"+
1931 " or you could not define value for a dynamic PCD in every <ModuleSA>!";
1932 throw new EntityException(exceptionString);
1933 }
1934 }
1935 continue;
1936 }
1937
1938 //
1939 // Judge whether is HII group case.
1940 //
1941 if (skuInfoList.get(index).getVariableName() != null) {
1942 exceptionString = null;
1943 if (skuInfoList.get(index).getVariableGuid() == null) {
1944 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1945 "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",
1946 token.cName,
1947 index);
1948
1949 }
1950
1951 if (skuInfoList.get(index).getVariableOffset() == null) {
1952 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1953 "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",
1954 token.cName,
1955 index);
1956 }
1957
1958 if (skuInfoList.get(index).getHiiDefaultValue() == null) {
1959 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+
1960 "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",
1961 token.cName,
1962 index);
1963 }
1964
1965 if (exceptionString != null) {
1966 throw new EntityException(exceptionString);
1967 }
1968 offset = Integer.decode(skuInfoList.get(index).getVariableOffset());
1969 if (offset > 0xFFFF) {
1970 throw new EntityException(String.format("[FPD file error] For dynamic PCD %s , the variable offset defined in sku %d data "+
1971 "exceed 64K, it is not allowed!",
1972 token.cName,
1973 index));
1974 }
1975
1976 skuInstance.value.setHiiData(skuInfoList.get(index).getVariableName(),
1977 translateSchemaStringToUUID(skuInfoList.get(index).getVariableGuid().toString()),
1978 skuInfoList.get(index).getVariableOffset(),
1979 skuInfoList.get(index).getHiiDefaultValue());
1980 token.skuData.add(skuInstance);
1981 continue;
1982 }
1983
1984 if (skuInfoList.get(index).getVpdOffset() != null) {
1985 skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());
1986 token.skuData.add(skuInstance);
1987 continue;
1988 }
1989
1990 exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+
1991 "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",
1992 token.cName);
1993 throw new EntityException(exceptionString);
1994 }
1995
1996 if (!hasSkuId0) {
1997 exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+
1998 "no sku id = 0 data, which is required for every dynamic PCD",
1999 token.cName);
2000 throw new EntityException(exceptionString);
2001 }
2002
2003 return token;
2004 }
2005
2006 /**
2007 Translate the schema string to UUID instance.
2008
2009 In schema, the string of UUID is defined as following two types string:
2010 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(
2011 )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?
2012
2013 2) GuidNamingConvention: pattern =
2014 [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}
2015
2016 This function will convert string and create uuid instance.
2017
2018 @param uuidString UUID string in XML file
2019
2020 @return UUID UUID instance
2021 **/
2022 private UUID translateSchemaStringToUUID(String uuidString)
2023 throws EntityException {
2024 String temp;
2025 String[] splitStringArray;
2026 int index;
2027 int chIndex;
2028 int chLen;
2029
2030 if (uuidString == null) {
2031 return null;
2032 }
2033
2034 if (uuidString.length() == 0) {
2035 return null;
2036 }
2037
2038 if (uuidString.equals("0") ||
2039 uuidString.equalsIgnoreCase("0x0")) {
2040 return new UUID(0, 0);
2041 }
2042
2043 //
2044 // If the UUID schema string is GuidArrayType type then need translate
2045 // to GuidNamingConvention type at first.
2046 //
2047 if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {
2048 splitStringArray = uuidString.split("," );
2049 if (splitStringArray.length != 11) {
2050 throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);
2051 }
2052
2053 //
2054 // Remove blank space from these string and remove header string "0x"
2055 //
2056 for (index = 0; index < 11; index ++) {
2057 splitStringArray[index] = splitStringArray[index].trim();
2058 splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());
2059 }
2060
2061 //
2062 // Add heading '0' to normalize the string length
2063 //
2064 for (index = 3; index < 11; index ++) {
2065 chLen = splitStringArray[index].length();
2066 for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {
2067 splitStringArray[index] = "0" + splitStringArray[index];
2068 }
2069 }
2070
2071 //
2072 // construct the final GuidNamingConvention string
2073 //
2074 temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",
2075 splitStringArray[0],
2076 splitStringArray[1],
2077 splitStringArray[2],
2078 splitStringArray[3],
2079 splitStringArray[4],
2080 splitStringArray[5],
2081 splitStringArray[6],
2082 splitStringArray[7],
2083 splitStringArray[8],
2084 splitStringArray[9],
2085 splitStringArray[10]);
2086 uuidString = temp;
2087 }
2088
2089 return UUID.fromString(uuidString);
2090 }
2091
2092 /**
2093 check parameter for this action.
2094
2095 @throws EntityException Bad parameter.
2096 **/
2097 private void checkParameter() throws EntityException {
2098 File file = null;
2099
2100 if((fpdFilePath == null) ||(workspacePath == null)) {
2101 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
2102 }
2103
2104 if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {
2105 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");
2106 }
2107
2108 file = new File(workspacePath);
2109 if(!file.exists()) {
2110 throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");
2111 }
2112
2113 file = new File(fpdFilePath);
2114
2115 if(!file.exists()) {
2116 throw new EntityException("FPD File " + fpdFilePath + " does not exist!");
2117 }
2118 }
2119
2120 /**
2121 Test case function
2122
2123 @param argv parameter from command line
2124 **/
2125 public static void main(String argv[]) throws EntityException {
2126 CollectPCDAction ca = new CollectPCDAction();
2127 ca.setWorkspacePath("m:/tianocore/edk2");
2128 ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd");
2129 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);
2130 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",
2131 "m:/tianocore/edk2");
2132 ca.execute();
2133 }
2134 }