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