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