]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Revise XML Schema to be valid.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / CollectPCDAction.java
CommitLineData
878ddf1f 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
99d2c3c4 20import java.io.BufferedReader;\r
878ddf1f 21import java.io.File;\r
99d2c3c4 22import java.io.FileReader;\r
878ddf1f 23import java.io.IOException;\r
24import java.util.ArrayList;\r
99d2c3c4 25import java.util.Collections;\r
26import java.util.Comparator;\r
878ddf1f 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.FrameworkPlatformDescriptionDocument;\r
35import org.tianocore.ModuleSADocument;\r
36import org.tianocore.PackageSurfaceAreaDocument;\r
37import org.tianocore.PcdBuildDeclarationsDocument.PcdBuildDeclarations.PcdBuildData;\r
38import org.tianocore.PcdDefinitionsDocument.PcdDefinitions;\r
39import org.tianocore.build.autogen.CommonDefinition;\r
40import org.tianocore.build.global.GlobalData;\r
41import org.tianocore.build.global.SurfaceAreaQuery;\r
42import org.tianocore.build.pcd.action.ActionMessage;\r
43import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
44import org.tianocore.build.pcd.entity.SkuInstance;\r
45import org.tianocore.build.pcd.entity.Token;\r
46import org.tianocore.build.pcd.entity.UsageInstance;\r
47import org.tianocore.build.pcd.exception.EntityException;\r
48\r
99d2c3c4 49class StringTable {\r
50 private ArrayList<String> al; \r
32648c62 51 private ArrayList<String> alComments;\r
99d2c3c4 52 private String phase;\r
53 int len; \r
32648c62 54 int bodyStart;\r
55 int bodyLineNum;\r
99d2c3c4 56\r
57 public StringTable (String phase) {\r
58 this.phase = phase;\r
59 al = new ArrayList<String>();\r
32648c62 60 alComments = new ArrayList<String>();\r
99d2c3c4 61 len = 0;\r
32648c62 62 bodyStart = 0;\r
63 bodyLineNum = 0;\r
99d2c3c4 64 }\r
65\r
66 public String getSizeMacro () {\r
67 return String.format(PcdDatabase.StringTableSizeMacro, phase, getSize());\r
68 }\r
69\r
70 private int getSize () {\r
32648c62 71 //\r
72 // We have at least one Unicode Character in the table.\r
73 //\r
99d2c3c4 74 return len == 0 ? 1 : len;\r
75 }\r
76\r
32648c62 77 public int getTableLen () {\r
78 return al.size() == 0 ? 1 : al.size();\r
79 }\r
99d2c3c4 80\r
81 public String getExistanceMacro () {\r
82 return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
83 }\r
84\r
85 public String getTypeDeclaration () {\r
86\r
32648c62 87 String output;\r
99d2c3c4 88\r
32648c62 89 final String stringTable = "StringTable";\r
90 final String tab = "\t";\r
91 final String newLine = ";\r\n";\r
99d2c3c4 92\r
32648c62 93 output = "/* StringTable */\r\n";\r
99d2c3c4 94\r
32648c62 95 if (al.size() == 0) {\r
96 output += tab + String.format("UINT16 %s[1] /* StringTable is Empty */", stringTable) + newLine;\r
97 }\r
99d2c3c4 98\r
32648c62 99 for (int i = 0; i < al.size(); i++) {\r
100 String str = al.get(i);\r
99d2c3c4 101\r
32648c62 102 if (i == 0) {\r
103 //\r
104 // StringTable is a well-known name in the PCD DXE driver\r
105 //\r
106 output += tab + String.format("UINT16 %s[%d] /* %s */", stringTable, str.length() + 1, alComments.get(i)) + newLine;\r
107 } else {\r
108 output += tab + String.format("UINT16 %s_%d[%d] /* %s */", stringTable, i, str.length() + 1, alComments.get(i)) + newLine;\r
109 }\r
110 }\r
99d2c3c4 111\r
32648c62 112 return output;\r
99d2c3c4 113\r
114 }\r
115\r
116 public ArrayList<String> getInstantiation () {\r
32648c62 117 ArrayList<String> output = new ArrayList<String>();\r
99d2c3c4 118\r
32648c62 119 output.add("/* StringTable */"); \r
99d2c3c4 120\r
32648c62 121 if (al.size() == 0) {\r
122 output.add("{ 0 }");\r
123 } else {\r
124 String str;\r
99d2c3c4 125\r
32648c62 126 for (int i = 0; i < al.size(); i++) {\r
127 str = String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
128 if (i != al.size() - 1) {\r
129 str += ",";\r
130 }\r
131 output.add(str);\r
132 }\r
133 }\r
99d2c3c4 134\r
135 return output;\r
136 }\r
137\r
138 public int add (String str, Token token) {\r
139 int i;\r
140\r
141 i = len;\r
142 //\r
143 // Include the NULL character at the end of String\r
144 //\r
145 len += str.length() + 1; \r
146 al.add(str);\r
32648c62 147 alComments.add(token.getPrimaryKeyString());\r
99d2c3c4 148\r
149 return i;\r
150 }\r
151}\r
152\r
153class SizeTable {\r
154 private ArrayList<Integer> al;\r
32648c62 155 private ArrayList<String> alComments;\r
99d2c3c4 156 private String phase;\r
157 private int len;\r
32648c62 158 private int bodyStart;\r
159 private int bodyLineNum;\r
99d2c3c4 160\r
161 public SizeTable (String phase) {\r
162 this.phase = phase;\r
163 al = new ArrayList<Integer>();\r
32648c62 164 alComments = new ArrayList<String>();\r
99d2c3c4 165 len = 0;\r
32648c62 166 bodyStart = 0;\r
167 bodyLineNum = 0;\r
99d2c3c4 168 }\r
169\r
170 public String getTypeDeclaration () {\r
171 return String.format(PcdDatabase.SizeTableDeclaration, phase);\r
172 }\r
173\r
174 public ArrayList<String> getInstantiation () {\r
32648c62 175 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 176\r
177 Output.add("/* SizeTable */");\r
178 Output.add("{");\r
32648c62 179 bodyStart = 2;\r
180\r
181 if (al.size() == 0) {\r
182 Output.add("0");\r
183 } else {\r
184 for (int index = 0; index < al.size(); index++) {\r
185 Integer n = al.get(index);\r
186 String str = n.toString();\r
187\r
188 if (index != (al.size() - 1)) {\r
189 str += ",";\r
190 }\r
191\r
192 str += " /* " + alComments.get(index) + " */"; \r
193 Output.add(str);\r
194 bodyLineNum++;\r
195 \r
196 }\r
197 }\r
198 Output.add("}");\r
99d2c3c4 199\r
200 return Output;\r
201 }\r
202\r
32648c62 203 public int getBodyStart() {\r
204 return bodyStart;\r
205 }\r
99d2c3c4 206\r
32648c62 207 public int getBodyLineNum () {\r
208 return bodyLineNum;\r
209 }\r
99d2c3c4 210\r
211 public int add (Token token) {\r
212 int index = len;\r
213\r
214 len++; \r
215 al.add(token.datumSize);\r
32648c62 216 alComments.add(token.getPrimaryKeyString());\r
99d2c3c4 217\r
218 return index;\r
219 }\r
4acf8ce7 220 \r
32648c62 221 private int getDatumSize(Token token) {\r
222 /*\r
223 switch (token.datumType) {\r
224 case Token.DATUM_TYPE.UINT8:\r
225 return 1;\r
226 default:\r
227 return 0;\r
228 }\r
229 */\r
230 return 0;\r
231 }\r
99d2c3c4 232\r
32648c62 233 public int getTableLen () {\r
234 return al.size() == 0 ? 1 : al.size();\r
235 }\r
99d2c3c4 236\r
237}\r
238\r
239class GuidTable {\r
240 private ArrayList<UUID> al;\r
32648c62 241 private ArrayList<String> alComments;\r
99d2c3c4 242 private String phase;\r
243 private int len;\r
32648c62 244 private int bodyStart;\r
245 private int bodyLineNum;\r
99d2c3c4 246\r
247 public GuidTable (String phase) {\r
248 this.phase = phase;\r
249 al = new ArrayList<UUID>();\r
32648c62 250 alComments = new ArrayList<String>();\r
99d2c3c4 251 len = 0;\r
32648c62 252 bodyStart = 0;\r
253 bodyLineNum = 0;\r
99d2c3c4 254 }\r
255\r
256 public String getSizeMacro () {\r
257 return String.format(PcdDatabase.GuidTableSizeMacro, phase, getSize());\r
258 }\r
259\r
260 private int getSize () {\r
261 return (al.size() == 0)? 1 : al.size();\r
262 }\r
263\r
264 public String getExistanceMacro () {\r
265 return String.format(PcdDatabase.GuidTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
266 }\r
267\r
268 public String getTypeDeclaration () {\r
269 return String.format(PcdDatabase.GuidTableDeclaration, phase);\r
270 }\r
271\r
32648c62 272 private String getUuidCString (UUID uuid) {\r
273 String[] guidStrArray;\r
274\r
275 guidStrArray =(uuid.toString()).split("-");\r
276\r
277 return String.format("{ 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } }",\r
278 guidStrArray[0],\r
279 guidStrArray[1],\r
280 guidStrArray[2],\r
281 (guidStrArray[3].substring(0, 2)),\r
282 (guidStrArray[3].substring(2, 4)),\r
283 (guidStrArray[4].substring(0, 2)),\r
284 (guidStrArray[4].substring(2, 4)),\r
285 (guidStrArray[4].substring(4, 6)),\r
286 (guidStrArray[4].substring(6, 8)),\r
287 (guidStrArray[4].substring(8, 10)),\r
288 (guidStrArray[4].substring(10, 12))\r
289 );\r
290 }\r
99d2c3c4 291\r
292 public ArrayList<String> getInstantiation () {\r
32648c62 293 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 294\r
295 Output.add("/* GuidTable */");\r
296 Output.add("{");\r
32648c62 297 bodyStart = 2;\r
99d2c3c4 298\r
32648c62 299 if (al.size() == 0) {\r
300 Output.add(getUuidCString(new UUID(0, 0)));\r
301 }\r
99d2c3c4 302 \r
303 for (Object u : al) {\r
304 UUID uuid = (UUID)u;\r
32648c62 305 String str = getUuidCString(uuid);\r
99d2c3c4 306\r
32648c62 307 if (al.indexOf(u) != (al.size() - 1)) {\r
308 str += ",";\r
309 }\r
99d2c3c4 310 Output.add(str);\r
32648c62 311 bodyLineNum++;\r
99d2c3c4 312\r
313 }\r
32648c62 314 Output.add("}");\r
99d2c3c4 315\r
316 return Output;\r
317 }\r
318\r
32648c62 319 public int getBodyStart() {\r
320 return bodyStart;\r
321 }\r
99d2c3c4 322\r
32648c62 323 public int getBodyLineNum () {\r
324 return bodyLineNum;\r
325 }\r
99d2c3c4 326\r
327 public int add (UUID uuid, String name) {\r
328 int index = len;\r
329 //\r
330 // Include the NULL character at the end of String\r
331 //\r
332 len++; \r
333 al.add(uuid);\r
334\r
335 return index;\r
336 }\r
337\r
32648c62 338 public int getTableLen () {\r
339 return al.size() == 0 ? 0 : al.size();\r
340 }\r
99d2c3c4 341\r
342}\r
343\r
344class SkuIdTable {\r
345 private ArrayList<Integer[]> al;\r
32648c62 346 private ArrayList<String> alComment;\r
99d2c3c4 347 private String phase;\r
348 private int len;\r
32648c62 349 private int bodyStart;\r
350 private int bodyLineNum;\r
99d2c3c4 351\r
352 public SkuIdTable (String phase) {\r
353 this.phase = phase;\r
354 al = new ArrayList<Integer[]>();\r
32648c62 355 alComment = new ArrayList<String>();\r
356 bodyStart = 0;\r
357 bodyLineNum = 0;\r
99d2c3c4 358 len = 0;\r
359 }\r
360\r
361 public String getSizeMacro () {\r
362 return String.format(PcdDatabase.SkuIdTableSizeMacro, phase, getSize());\r
363 }\r
364\r
365 private int getSize () {\r
366 return (al.size() == 0)? 1 : al.size();\r
367 }\r
368\r
369 public String getExistanceMacro () {\r
370 return String.format(PcdDatabase.SkuTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
371 }\r
372\r
373 public String getTypeDeclaration () {\r
374 return String.format(PcdDatabase.SkuIdTableDeclaration, phase);\r
375 }\r
376\r
377 public ArrayList<String> getInstantiation () {\r
32648c62 378 ArrayList<String> Output = new ArrayList<String> ();\r
99d2c3c4 379\r
380 Output.add("/* SkuIdTable */");\r
381 Output.add("{");\r
32648c62 382 bodyStart = 2;\r
99d2c3c4 383\r
32648c62 384 if (al.size() == 0) {\r
385 Output.add("0");\r
386 }\r
99d2c3c4 387 \r
388 for (int index = 0; index < al.size(); index++) {\r
32648c62 389 String str;\r
99d2c3c4 390\r
32648c62 391 str = "/* " + alComment.get(index) + "*/ ";\r
392 str += "/* MaxSku */ ";\r
99d2c3c4 393\r
394\r
32648c62 395 Integer[] ia = al.get(index);\r
99d2c3c4 396\r
32648c62 397 str += ia[0].toString() + ", ";\r
398 for (int index2 = 1; index2 < ia.length; index2++) {\r
399 str += ia[index2].toString();\r
400 if (index != al.size() - 1) {\r
401 str += ", ";\r
402 }\r
403 }\r
99d2c3c4 404\r
405 Output.add(str);\r
32648c62 406 bodyLineNum++;\r
99d2c3c4 407\r
408 }\r
409\r
32648c62 410 Output.add("}");\r
99d2c3c4 411\r
412 return Output;\r
413 }\r
414\r
415 public int add (Token token) {\r
416\r
32648c62 417 int index;\r
99d2c3c4 418\r
32648c62 419 Integer [] skuIds = new Integer[token.maxSkuCount + 1];\r
420 skuIds[0] = new Integer(token.maxSkuCount);\r
421 for (index = 1; index < skuIds.length; index++) {\r
422 skuIds[index] = new Integer(token.skuData.get(index - 1).id);\r
423 }\r
99d2c3c4 424\r
425 index = len;\r
426\r
427 len += skuIds.length; \r
428 al.add(skuIds);\r
32648c62 429 alComment.add(token.getPrimaryKeyString());\r
99d2c3c4 430\r
431 return index;\r
432 }\r
433\r
32648c62 434 public int getTableLen () {\r
435 return al.size() == 0 ? 1 : al.size();\r
436 }\r
99d2c3c4 437\r
438}\r
439\r
440class LocalTokenNumberTable {\r
441 private ArrayList<String> al;\r
32648c62 442 private ArrayList<String> alComment;\r
99d2c3c4 443 private String phase;\r
444 private int len;\r
32648c62 445 private int bodyStart;\r
446 private int bodyLineNum;\r
99d2c3c4 447\r
448 public LocalTokenNumberTable (String phase) {\r
449 this.phase = phase;\r
450 al = new ArrayList<String>();\r
32648c62 451 alComment = new ArrayList<String>();\r
452 bodyStart = 0;\r
453 bodyLineNum = 0;\r
99d2c3c4 454\r
455 len = 0;\r
456 }\r
457\r
458 public String getSizeMacro () {\r
459 return String.format(PcdDatabase.LocalTokenNumberTableSizeMacro, phase, getSize());\r
460 }\r
461\r
462 public int getSize () {\r
463 return (al.size() == 0)? 1 : al.size();\r
464 }\r
465\r
466 public String getExistanceMacro () {\r
467 return String.format(PcdDatabase.DatabaseExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
468 }\r
469\r
470 public String getTypeDeclaration () {\r
471 return String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);\r
472 }\r
473\r
474 public ArrayList<String> getInstantiation () {\r
32648c62 475 ArrayList<String> output = new ArrayList<String>();\r
99d2c3c4 476\r
477 output.add("/* LocalTokenNumberTable */");\r
478 output.add("{");\r
32648c62 479 bodyStart = 2;\r
99d2c3c4 480\r
32648c62 481 if (al.size() == 0) {\r
482 output.add("0");\r
483 }\r
99d2c3c4 484 \r
485 for (int index = 0; index < al.size(); index++) {\r
32648c62 486 String str;\r
99d2c3c4 487\r
32648c62 488 str = (String)al.get(index);\r
99d2c3c4 489\r
32648c62 490 str += " /* " + alComment.get(index) + " */ ";\r
99d2c3c4 491\r
492\r
32648c62 493 if (index != (al.size() - 1)) {\r
494 str += ",";\r
495 }\r
99d2c3c4 496\r
497 output.add(str);\r
498\r
499 }\r
500\r
32648c62 501 bodyLineNum = al.size();\r
99d2c3c4 502\r
32648c62 503 output.add("}");\r
99d2c3c4 504\r
505 return output;\r
506 }\r
507\r
508 public int add (Token token) {\r
509 int index = len;\r
32648c62 510 String str;\r
99d2c3c4 511\r
512 len++; \r
513\r
32648c62 514 str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());\r
99d2c3c4 515\r
32648c62 516 if (token.isStringType()) {\r
517 str += " | PCD_TYPE_STRING";\r
518 }\r
99d2c3c4 519\r
32648c62 520 if (token.skuEnabled) {\r
521 str += " | PCD_TYPE_SKU_ENABLED";\r
522 }\r
99d2c3c4 523\r
32648c62 524 if (token.hiiEnabled) {\r
525 str += " | PCD_TYPE_HII";\r
526 }\r
99d2c3c4 527\r
32648c62 528 if (token.vpdEnabled) {\r
529 str += " | PCD_TYPE_VPD";\r
530 }\r
531 \r
99d2c3c4 532 al.add(str);\r
32648c62 533 alComment.add(token.getPrimaryKeyString());\r
99d2c3c4 534\r
535 return index;\r
536 }\r
537}\r
538\r
539class ExMapTable {\r
540\r
32648c62 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
99d2c3c4 552\r
553 private ArrayList<ExTriplet> al;\r
32648c62 554 private ArrayList<String> alComment;\r
99d2c3c4 555 private String phase;\r
556 private int len;\r
32648c62 557 private int bodyStart;\r
558 private int bodyLineNum;\r
559 private int base;\r
99d2c3c4 560\r
561 public ExMapTable (String phase) {\r
562 this.phase = phase;\r
563 al = new ArrayList<ExTriplet>();\r
32648c62 564 alComment = new ArrayList<String>();\r
565 bodyStart = 0;\r
566 bodyLineNum = 0;\r
99d2c3c4 567 len = 0;\r
568 }\r
569\r
570 public String getSizeMacro () {\r
571 return String.format(PcdDatabase.ExMapTableSizeMacro, phase, getTableLen())\r
32648c62 572 + String.format(PcdDatabase.ExTokenNumber, phase, al.size());\r
99d2c3c4 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
32648c62 588 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 589\r
590 Output.add("/* ExMapTable */");\r
591 Output.add("{");\r
32648c62 592 bodyStart = 2;\r
99d2c3c4 593\r
32648c62 594 if (al.size() == 0) {\r
595 Output.add("{0, 0, 0}");\r
596 }\r
99d2c3c4 597 \r
32648c62 598 int index;\r
99d2c3c4 599 for (index = 0; index < al.size(); index++) {\r
32648c62 600 String str;\r
99d2c3c4 601\r
32648c62 602 ExTriplet e = (ExTriplet)al.get(index);\r
99d2c3c4 603\r
32648c62 604 str = "{ " + e.exTokenNumber.toString() + ", ";\r
605 str += e.localTokenIdx.toString() + ", ";\r
606 str += e.guidTableIdx.toString();\r
99d2c3c4 607\r
32648c62 608 str += " /* " + alComment.get(index) + " */";\r
99d2c3c4 609\r
32648c62 610 if (index != al.size() - 1) {\r
611 str += ",";\r
612 }\r
99d2c3c4 613\r
614 Output.add(str);\r
32648c62 615 bodyLineNum++;\r
99d2c3c4 616\r
617 }\r
618\r
32648c62 619 Output.add("}");\r
99d2c3c4 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
32648c62 629 alComment.add(name);\r
99d2c3c4 630\r
631 return index;\r
632 }\r
633\r
32648c62 634 public int getTableLen () {\r
635 return al.size() == 0 ? 1 : al.size();\r
636 }\r
99d2c3c4 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];\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];\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
32648c62 651 public final static String ExTokenNumber = "#define %s_EX_TOKEN_NUMBER %d\r\n";\r
99d2c3c4 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 %d\r\n";\r
654 public final static String StringTableSizeMacro = "#define %s_STRING_TABLE_SIZE %d\r\n";\r
655 public final static String SkuIdTableSizeMacro = "#define %s_SKUID_TABLE_SIZE %d\r\n";\r
656\r
657\r
658 public final static String ExMapTableExistenceMacro = "#define %s_EXMAP_TABLE_EMPTY %s\r\n"; \r
659 public final static String GuidTableExistenceMacro = "#define %s_GUID_TABLE_EMPTY %s\r\n";\r
660 public final static String DatabaseExistenceMacro = "#define %s_DATABASE_EMPTY %s\r\n";\r
661 public final static String StringTableExistenceMacro = "#define %s_STRING_TABLE_EMPTY %s\r\n";\r
662 public final static String SkuTableExistenceMacro = "#define %s_SKUID_TABLE_EMPTY %s\r\n";\r
663\r
32648c62 664 public final static String offsetOfSkuHeadStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";\r
665 public final static String offsetOfStrTemplate = "offsetof(%s_PCD_DATABASE, %s.%s)";\r
99d2c3c4 666\r
32648c62 667 private StringTable stringTable;\r
668 private GuidTable guidTable;\r
669 private LocalTokenNumberTable localTokenNumberTable;\r
670 private SkuIdTable skuIdTable;\r
671 private SizeTable sizeTable;\r
672 private ExMapTable exMapTable;\r
99d2c3c4 673\r
32648c62 674 private ArrayList<Token> alTokens;\r
675 private String phase;\r
676 private int assignedTokenNumber;\r
4acf8ce7 677 \r
678 //\r
679 // After Major changes done to the PCD\r
680 // database generation class PcdDatabase\r
681 // Please increment the version and please\r
682 // also update the version number in PCD\r
683 // service PEIM and DXE driver accordingly.\r
684 //\r
685 private final int version = 1;\r
99d2c3c4 686\r
32648c62 687 private String hString;\r
688 private String cString;\r
99d2c3c4 689\r
690\r
32648c62 691 class AlignmentSizeComp implements Comparator<Token> {\r
99d2c3c4 692 public int compare (Token a, Token b) {\r
32648c62 693 return getAlignmentSize(b) \r
694 - getAlignmentSize(a);\r
695 }\r
696 }\r
697\r
698 public PcdDatabase (ArrayList<Token> alTokens, String exePhase, int startLen) {\r
699 phase = exePhase;\r
700\r
701 stringTable = new StringTable(phase);\r
702 guidTable = new GuidTable(phase);\r
703 localTokenNumberTable = new LocalTokenNumberTable(phase);\r
704 skuIdTable = new SkuIdTable(phase);\r
705 sizeTable = new SizeTable(phase);\r
706 exMapTable = new ExMapTable(phase); \r
707\r
708 assignedTokenNumber = startLen;\r
709 this.alTokens = alTokens;\r
710 }\r
711\r
712 private void getTwoGroupsOfTokens (ArrayList<Token> alTokens, List<Token> initTokens, List<Token> uninitTokens) {\r
713 for (int i = 0; i < alTokens.size(); i++) {\r
714 Token t = (Token)alTokens.get(i);\r
715 if (t.hasDefaultValue()) {\r
716 initTokens.add(t);\r
717 } else {\r
718 uninitTokens.add(t);\r
719 }\r
720 }\r
721\r
722 return;\r
723 }\r
724\r
725 private int getAlignmentSize (Token token) {\r
726 if (token.hiiEnabled) {\r
727 return 2;\r
728 }\r
729\r
730 if (token.vpdEnabled) {\r
731 return 4;\r
732 }\r
733\r
734 if (token.isStringType()) {\r
735 return 2;\r
736 }\r
737\r
738 switch (token.datumType) {\r
739 case UINT8:\r
740 return 1;\r
741 case UINT16:\r
742 return 2;\r
743 case UINT32:\r
744 return 4;\r
745 case UINT64:\r
746 return 8;\r
747 case POINTER:\r
748 return 1;\r
749 case BOOLEAN:\r
750 return 1;\r
751 }\r
752 return 1;\r
753 }\r
754\r
755 public String getCString () {\r
756 return cString;\r
757 }\r
758\r
759 public String getHString () {\r
760 return hString;\r
761 }\r
99d2c3c4 762\r
763 public void genCode () {\r
764\r
32648c62 765 final String newLine = "\r\n";\r
32648c62 766 final String declNewLine = ";\r\n";\r
767 final String tab = "\t";\r
32648c62 768 final String commaNewLine = ", \r\n";\r
769\r
770 int i;\r
771 ArrayList<String> decla;\r
772 ArrayList<String> inst;\r
773\r
774 String macroStr = "";\r
775 String initDeclStr = "";\r
776 String initInstStr = "";\r
777 String uninitDeclStr = "";\r
778\r
779 List<Token> initTokens = new ArrayList<Token> ();\r
780 List<Token> uninitTokens = new ArrayList<Token> ();\r
781 \r
782 HashMap <String, ArrayList<String>> initCode = new HashMap<String, ArrayList<String>> ();\r
783 HashMap <String, ArrayList<String>> uninitCode = new HashMap<String, ArrayList<String>> ();\r
784\r
785 getTwoGroupsOfTokens (alTokens, initTokens, uninitTokens);\r
786\r
787 //\r
788 // Generate Structure Declaration for PcdTokens without Default Value\r
789 // PEI_PCD_DATABASE_INIT\r
790 //\r
6a4cae58 791 java.util.Comparator<Token> comparator = new AlignmentSizeComp();\r
32648c62 792 List<Token> list = initTokens;\r
793 java.util.Collections.sort(list, comparator);\r
794 initCode = processTokens(initTokens);\r
795\r
796 //\r
797 // Generate Structure Declaration for PcdTokens without Default Value\r
798 // PEI_PCD_DATABASE_UNINIT\r
799 //\r
4acf8ce7 800 list = uninitTokens;\r
801 java.util.Collections.sort(list, comparator);\r
32648c62 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
32648c62 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
4acf8ce7 912 \r
913 hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase, version);\r
32648c62 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\r
32648c62 931 HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();\r
932\r
933 ArrayList<String> decl = new ArrayList<String>();\r
934 ArrayList<String> declForSkuEnableType = new ArrayList<String>();\r
935 ArrayList<String> inst = new ArrayList<String>();\r
936 ArrayList<String> instForSkuEnableType = new ArrayList<String>();\r
937\r
938 for (int index = 0; index < alToken.size(); index++) {\r
939 Token token = alToken.get(index);\r
940\r
941 if (token.skuEnabled) {\r
942 //\r
943 // BugBug: Schema only support Data type now\r
944 //\r
945 int tableIdx;\r
946\r
947 tableIdx = skuIdTable.add(token);\r
948\r
949 decl.add(getSkuEnabledTypeDeclaration(token));\r
950 if (token.hasDefaultValue()) {\r
951 inst.add(getSkuEnabledTypeInstantiaion(token, tableIdx)); \r
952 }\r
953\r
954 declForSkuEnableType.add(getDataTypeDeclarationForSkuEnabled(token));\r
955 if (token.hasDefaultValue()) {\r
956 instForSkuEnableType.add(getDataTypeInstantiationForSkuEnabled(token));\r
957 }\r
958\r
959 } else {\r
960 if (token.hiiEnabled) {\r
961 decl.add(getVariableEnableTypeDeclaration(token));\r
962 inst.add(getVariableEnableInstantiation(token));\r
963 } else if (token.vpdEnabled) {\r
964 decl.add(getVpdEnableTypeDeclaration(token));\r
965 inst.add(getVpdEnableTypeInstantiation(token));\r
966 } else if (token.isStringType()) {\r
967 decl.add(getStringTypeDeclaration(token));\r
968 inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));\r
969 }\r
970 else {\r
971 decl.add(getDataTypeDeclaration(token));\r
972 if (token.hasDefaultValue()) {\r
973 inst.add(getDataTypeInstantiation(token));\r
974 }\r
975 }\r
976 }\r
977\r
978 sizeTable.add(token);\r
979 localTokenNumberTable.add(token);\r
980 token.assignedtokenNumber = assignedTokenNumber++;\r
981\r
982 }\r
983\r
984 map.put("Declaration", decl);\r
985 map.put("DeclarationForSku", declForSkuEnableType);\r
986 map.put("Instantiation", inst);\r
987 map.put("InstantiationForSku", instForSkuEnableType);\r
988\r
989 return map;\r
990 }\r
991\r
992 private String getSkuEnabledTypeDeclaration (Token token) {\r
993 return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());\r
994 }\r
995\r
996 private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
997\r
998 String offsetof = String.format(PcdDatabase.offsetOfSkuHeadStrTemplate, phase, token.hasDefaultValue()? "Init" : "Uninit", token.getPrimaryKeyString());\r
999 return String.format("{ %s, %d }", offsetof, SkuTableIdx);\r
1000 }\r
1001\r
1002 private String getDataTypeDeclarationForSkuEnabled (Token token) {\r
1003 String typeStr = "";\r
1004\r
1005 if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
1006 typeStr = "UINT8 %s_%s[%d];\r\n";\r
1007 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
1008 typeStr = "UINT16 %s_%s[%d];\r\n";\r
1009 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
1010 typeStr = "UINT32 %s_%s[%d];\r\n";\r
1011 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
1012 typeStr = "UINT64 %s_%s[%d];\r\n";\r
1013 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
1014 typeStr = "BOOLEAN %s_%s[%d];\r\n";\r
1015 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1016 return String.format("UINT8 %s_s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
1017 } \r
1018\r
1019 return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.maxSkuCount);\r
1020\r
1021 }\r
1022\r
1023 private String getDataTypeInstantiationForSkuEnabled (Token token) {\r
1024 String str = "";\r
1025\r
1026 if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1027 return String.format("UINT8 %s_s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
1028 } else {\r
1029 str = "{ ";\r
1030 for (int idx = 0; idx < token.maxSkuCount; idx++) {\r
1031 str += token.skuData.get(idx).toString();\r
1032 if (idx != token.maxSkuCount - 1) {\r
1033 str += ", ";\r
1034 }\r
1035 }\r
1036 str += "}";\r
1037\r
1038 return str;\r
1039 }\r
1040\r
1041 }\r
1042\r
1043 private String getDataTypeInstantiation (Token token) {\r
1044\r
32648c62 1045 if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1046 return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
1047 } else {\r
1048 return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
1049 }\r
1050 }\r
1051\r
1052\r
1053 private String getDataTypeDeclaration (Token token) {\r
1054\r
1055 String typeStr = "";\r
1056\r
1057 if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
1058 typeStr = "UINT8";\r
1059 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
1060 typeStr = "UINT16";\r
1061 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
1062 typeStr = "UINT32";\r
1063 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
1064 typeStr = "UINT64";\r
1065 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
1066 typeStr = "BOOLEAN";\r
1067 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1068 return String.format("UINT8 %s[%d]", token.getPrimaryKeyString(), token.datumSize);\r
1069 } else {\r
1070 }\r
1071\r
1072 return String.format("%s %s", typeStr, token.getPrimaryKeyString());\r
1073 }\r
1074\r
1075 private String getVpdEnableTypeDeclaration (Token token) {\r
1076 return String.format("VPD_HEAD %s", token.getPrimaryKeyString());\r
1077 }\r
1078\r
1079 private String getVpdEnableTypeInstantiation (Token token) {\r
1080 return String.format("{ %d } /* %s */", token.vpdOffset,\r
1081 token.getPrimaryKeyString());\r
1082 }\r
1083\r
1084 private String getStringTypeDeclaration (Token token) {\r
1085 return String.format("UINT16 %s", token.getPrimaryKeyString());\r
1086 }\r
1087\r
1088 private String getStringTypeInstantiation (int StringTableIdx, Token token) {\r
1089 return String.format ("%d /* %s */", StringTableIdx,\r
1090 token.getPrimaryKeyString()); \r
1091 }\r
1092\r
1093\r
1094 private String getVariableEnableTypeDeclaration (Token token) {\r
1095 return String.format("VARIABLE_HEAD %s", token.getPrimaryKeyString());\r
1096 }\r
1097\r
1098 private String getVariableEnableInstantiation (Token token) {\r
1099 return String.format("{ %d, %d, %d } /* %s */", guidTable.add(token.variableGuid, token.getPrimaryKeyString()),\r
1100 stringTable.add(token.variableName, token),\r
1101 token.variableOffset, \r
1102 token.getPrimaryKeyString());\r
1103 }\r
1104\r
1105 public int getTotalTokenNumber () {\r
1106 return sizeTable.getTableLen();\r
1107 }\r
99d2c3c4 1108\r
1109 public static String getPcdDatabaseCommonDefinitions () \r
1110 throws EntityException {\r
1111\r
1112 String retStr = "";\r
1113 try {\r
32648c62 1114 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1115 "Tools" + File.separator + \r
1116 "Conf" + File.separator +\r
1117 "Pcd" + File.separator +\r
1118 "PcdDatabaseCommonDefinitions.sample");\r
1119 System.out.println(GlobalData.getWorkspacePath());\r
99d2c3c4 1120 FileReader reader = new FileReader(file);\r
1121 BufferedReader in = new BufferedReader(reader);\r
1122 String str;\r
1123 while ((str = in.readLine()) != null) {\r
1124 retStr = retStr +"\r\n" + str;\r
1125 }\r
1126 } catch (Exception ex) {\r
1127 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");\r
1128 }\r
1129\r
1130 return retStr;\r
1131 }\r
1132\r
32648c62 1133 public static String getPcdDxeDatabaseDefinitions () \r
1134 throws EntityException {\r
1135\r
1136 String retStr = "";\r
1137 try {\r
1138 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1139 "Tools" + File.separator + \r
1140 "Conf" + File.separator +\r
1141 "Pcd" + File.separator +\r
1142 "PcdDatabaseDxeDefinitions.sample");\r
1143 FileReader reader = new FileReader(file);\r
1144 BufferedReader in = new BufferedReader(reader);\r
1145 String str;\r
1146 while ((str = in.readLine()) != null) {\r
1147 retStr = retStr +"\r\n" + str;\r
1148 }\r
1149 } catch (Exception ex) {\r
1150 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");\r
1151 }\r
1152\r
1153 return retStr;\r
1154 }\r
1155\r
1156 public static String getPcdPeiDatabaseDefinitions () \r
1157 throws EntityException {\r
1158\r
1159 String retStr = "";\r
1160 try {\r
1161 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1162 "Tools" + File.separator + \r
1163 "Conf" + File.separator +\r
1164 "Pcd" + File.separator +\r
1165 "PcdDatabasePeiDefinitions.sample");\r
1166 FileReader reader = new FileReader(file);\r
1167 BufferedReader in = new BufferedReader(reader);\r
1168 String str;\r
1169 while ((str = in.readLine()) != null) {\r
1170 retStr = retStr +"\r\n" + str;\r
1171 }\r
1172 } catch (Exception ex) {\r
1173 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");\r
1174 }\r
1175\r
1176 return retStr;\r
1177 }\r
99d2c3c4 1178\r
1179}\r
1180\r
878ddf1f 1181/** This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
1182 This class will be used for wizard and build tools, So it can *not* inherit\r
1183 from buildAction or UIAction.\r
1184**/\r
1185public class CollectPCDAction {\r
1186 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.\r
1187 private MemoryDatabaseManager dbManager;\r
1188\r
1189 /// Workspacepath hold the workspace information.\r
1190 private String workspacePath;\r
1191\r
1192 /// FPD file is the root file. \r
1193 private String fpdFilePath;\r
1194\r
1195 /// Message level for CollectPCDAction.\r
1196 private int originalMessageLevel;\r
1197\r
1198 /**\r
1199 Set WorkspacePath parameter for this action class.\r
1200\r
1201 @param workspacePath parameter for this action\r
1202 **/\r
1203 public void setWorkspacePath(String workspacePath) {\r
1204 this.workspacePath = workspacePath;\r
1205 }\r
1206\r
1207 /**\r
1208 Set action message level for CollectPcdAction tool.\r
1209\r
1210 The message should be restored when this action exit.\r
1211\r
1212 @param actionMessageLevel parameter for this action\r
1213 **/\r
1214 public void setActionMessageLevel(int actionMessageLevel) {\r
1215 originalMessageLevel = ActionMessage.messageLevel;\r
1216 ActionMessage.messageLevel = actionMessageLevel;\r
1217 }\r
1218\r
1219 /**\r
1220 Set FPDFileName parameter for this action class.\r
1221\r
1222 @param fpdFilePath fpd file path\r
1223 **/\r
1224 public void setFPDFilePath(String fpdFilePath) {\r
1225 this.fpdFilePath = fpdFilePath;\r
1226 }\r
1227\r
1228 /**\r
1229 Common function interface for outer.\r
1230 \r
1231 @param workspacePath The path of workspace of current build or analysis.\r
1232 @param fpdFilePath The fpd file path of current build or analysis.\r
1233 @param messageLevel The message level for this Action.\r
1234 \r
1235 @throws Exception The exception of this function. Because it can *not* be predict\r
1236 where the action class will be used. So only Exception can be throw.\r
1237 \r
1238 **/\r
1239 public void perform(String workspacePath, String fpdFilePath, \r
1240 int messageLevel) throws Exception {\r
1241 setWorkspacePath(workspacePath);\r
1242 setFPDFilePath(fpdFilePath);\r
1243 setActionMessageLevel(messageLevel);\r
1244 checkParameter();\r
1245 execute();\r
1246 ActionMessage.messageLevel = originalMessageLevel;\r
1247 }\r
1248\r
1249 /**\r
1250 Core execution function for this action class.\r
1251 \r
1252 This function work flows will be:\r
1253 1) Get all token's platform information from FPD, and create token object into memory database.\r
1254 2) Get all token's module information from MSA, and create usage instance for every module's PCD entry.\r
1255 3) Get all token's inherited information from MSA's library, and create usage instance \r
1256 for module who consume this library and create usage instance for library for building.\r
1257 4) Collect token's package information from SPD, update these information for token in memory\r
1258 database.\r
99d2c3c4 1259 5) Generate 3 strings for a) All modules using Dynamic(Ex) PCD entry. (Token Number)\r
1260 b) PEI PCD Database (C Structure) for PCD Service PEIM\r
1261 c) DXE PCD Database (C structure) for PCD Service DXE\r
1262 \r
878ddf1f 1263 \r
1264 @throws EntityException Exception indicate failed to execute this action.\r
1265 \r
1266 **/\r
1267 private void execute() throws EntityException {\r
1268 FrameworkPlatformDescriptionDocument fpdDoc = null;\r
1269 Object[][] modulePCDArray = null;\r
1270 Map<String, XmlObject> docMap = null;\r
1271 ModuleSADocument.ModuleSA[] moduleSAs = null;\r
1272 UsageInstance usageInstance = null;\r
1273 String packageName = null;\r
1274 String packageFullPath = null;\r
1275 int index = 0;\r
1276 int libraryIndex = 0;\r
1277 int pcdArrayIndex = 0;\r
1278 List<String> listLibraryInstance = null;\r
1279 String componentTypeStr = null;\r
1280\r
1281 //\r
1282 // Collect all PCD information defined in FPD file.\r
1283 // Evenry token defind in FPD will be created as an token into \r
1284 // memory database.\r
1285 //\r
1286 fpdDoc = createTokenInDBFromFPD();\r
1287\r
1288 //\r
1289 // Searching MSA and SPD document. \r
1290 // The information of MSA will be used to create usage instance into database.\r
1291 // The information of SPD will be used to update the token information in database.\r
1292 //\r
1293\r
1294 HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
1295 map.put("FrameworkPlatformDescription", fpdDoc);\r
1296 SurfaceAreaQuery.setDoc(map); \r
1297\r
1298 moduleSAs = SurfaceAreaQuery.getFpdModules();\r
1299 for(index = 0; index < moduleSAs.length; index ++) {\r
1300 //\r
1301 // Get module document and use SurfaceAreaQuery to get PCD information\r
1302 //\r
1303 docMap = GlobalData.getDoc(moduleSAs[index].getModuleName());\r
1304 SurfaceAreaQuery.setDoc(docMap);\r
1305 modulePCDArray = SurfaceAreaQuery.getModulePCDTokenArray();\r
1306 componentTypeStr = SurfaceAreaQuery.getComponentType();\r
1307 packageName = \r
1308 GlobalData.getPackageNameForModule(moduleSAs[index].getModuleName());\r
1309 packageFullPath = this.workspacePath + File.separator +\r
1310 GlobalData.getPackagePath(packageName) +\r
1311 packageName + ".spd";\r
1312\r
1313 if(modulePCDArray != null) {\r
1314 //\r
1315 // If current MSA contains <PCDs> information, then create usage\r
1316 // instance for PCD information from MSA\r
1317 //\r
1318 for(pcdArrayIndex = 0; pcdArrayIndex < modulePCDArray.length; \r
1319 pcdArrayIndex ++) {\r
1320 usageInstance = \r
1321 createUsageInstanceFromMSA(moduleSAs[index].getModuleName(),\r
1322 modulePCDArray[pcdArrayIndex]);\r
1323\r
1324 if(usageInstance == null) {\r
1325 continue;\r
1326 }\r
1327 //\r
1328 // Get remaining PCD information from the package which this module belongs to\r
1329 //\r
1330 updateTokenBySPD(usageInstance, packageFullPath);\r
1331 }\r
1332 }\r
1333\r
1334 //\r
1335 // Get inherit PCD information which inherit from library instance of this module.\r
1336 //\r
1337 listLibraryInstance = \r
1338 SurfaceAreaQuery.getLibraryInstance(moduleSAs[index].getArch().toString(),\r
1339 CommonDefinition.AlwaysConsumed);\r
1340 if(listLibraryInstance != null) {\r
1341 for(libraryIndex = 0; libraryIndex < listLibraryInstance.size(); \r
1342 libraryIndex ++) {\r
1343 inheritPCDFromLibraryInstance(listLibraryInstance.get(libraryIndex),\r
1344 moduleSAs[index].getModuleName(),\r
1345 packageName,\r
1346 componentTypeStr);\r
1347 }\r
1348 }\r
1349 }\r
99d2c3c4 1350 \r
1351 //\r
1352 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
1353 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
32648c62 1354 //\r
1355 genPcdDatabaseSourceCode ();\r
1356 \r
878ddf1f 1357 }\r
1358\r
32648c62 1359 /**\r
1360 This function generates source code for PCD Database.\r
1361 \r
1362 @param void\r
1363 @throws EntityException If the token does *not* exist in memory database.\r
99d2c3c4 1364\r
32648c62 1365 **/\r
99d2c3c4 1366\r
32648c62 1367 private void genPcdDatabaseSourceCode ()\r
1368 throws EntityException {\r
1369 String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();\r
99d2c3c4 1370\r
32648c62 1371 ArrayList<Token> alPei = new ArrayList<Token> ();\r
1372 ArrayList<Token> alDxe = new ArrayList<Token> ();\r
99d2c3c4 1373\r
32648c62 1374 dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
99d2c3c4 1375 PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
32648c62 1376 pcdPeiDatabase.genCode();\r
1377 dbManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
1378 + PcdDatabase.getPcdPeiDatabaseDefinitions();\r
1379 dbManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
99d2c3c4 1380\r
1381 PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
32648c62 1382 "DXE",\r
1383 alPei.size()\r
1384 );\r
1385 pcdDxeDatabase.genCode();\r
1386 dbManager.PcdDxeHString = dbManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
1387 + PcdDatabase.getPcdDxeDatabaseDefinitions();\r
1388 dbManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
1389 }\r
1390\r
1391 /**\r
878ddf1f 1392 This function will collect inherit PCD information from library for a module.\r
1393 \r
1394 This function will create two usage instance for inherited PCD token, one is \r
1395 for module and another is for library.\r
1396 For module, if it inherited a PCD token from library, this PCD token's value \r
1397 should be instanced in module level, and belongs to module.\r
1398 For library, it also need a usage instance for build.\r
1399 \r
1400 @param libraryName The name of library instance.\r
1401 @param moduleName The name of module.\r
1402 @param packageName The name of package while module belongs to.\r
1403 @param parentcomponentType The component type of module.\r
1404 \r
1405 @throws EntityException If the token does *not* exist in memory database.\r
1406 \r
1407 **/\r
1408 private void inheritPCDFromLibraryInstance(String libraryName,\r
1409 String moduleName,\r
1410 String packageName,\r
1411 String parentcomponentType) \r
1412 throws EntityException {\r
1413 Map<String, XmlObject> docMap = null;\r
1414 String primaryKeyString = null;\r
1415 Object[][] libPcdDataArray = null;\r
1416 UUID nullUUID = new UUID(0,0);\r
1417 UUID platformUUID = nullUUID;\r
1418 UUID tokenSpaceGuid = null;\r
1419 int tokenIndex = 0;\r
1420 Token token = null;\r
1421 Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;\r
1422 UsageInstance usageInstance = null;\r
1423 String packageFullPath = null;\r
1424\r
1425 //\r
1426 // Query PCD information from library's document.\r
1427 //\r
1428 docMap = GlobalData.getDoc(libraryName);\r
1429 SurfaceAreaQuery.setDoc(docMap);\r
1430 libPcdDataArray = SurfaceAreaQuery.getModulePCDTokenArray();\r
1431\r
1432 if(libPcdDataArray == null) {\r
1433 return;\r
1434 }\r
1435\r
1436 for(tokenIndex = 0; tokenIndex < libPcdDataArray.length; tokenIndex ++) {\r
1437 tokenSpaceGuid =((UUID)libPcdDataArray[tokenIndex][2] == null) ? \r
1438 nullUUID :(UUID)libPcdDataArray[tokenIndex][2];\r
1439\r
1440 //\r
1441 // Get token from memory database. The token must be created from FPD already.\r
1442 //\r
1443 primaryKeyString = Token.getPrimaryKeyString((String)libPcdDataArray[tokenIndex][0],\r
1444 tokenSpaceGuid,\r
1445 platformUUID\r
1446 );\r
1447\r
1448 if(dbManager.isTokenInDatabase(primaryKeyString)) {\r
1449 token = dbManager.getTokenByKey(primaryKeyString);\r
1450 } else {\r
1451 throw new EntityException("The PCD token " + primaryKeyString + \r
1452 " defined in module " + moduleName + \r
1453 " does not exist in FPD file!");\r
1454 } \r
1455\r
1456 //\r
1457 // Create usage instance for module.\r
1458 //\r
1459 pcdType = Token.getpcdTypeFromString((String)libPcdDataArray[tokenIndex][1]);\r
1460 usageInstance = new UsageInstance(token,\r
1461 Token.PCD_USAGE.ALWAYS_CONSUMED,\r
1462 pcdType,\r
1463 CommonDefinition.getComponentType(parentcomponentType),\r
1464 libPcdDataArray[tokenIndex][3],\r
1465 null,\r
1466 (String) libPcdDataArray[tokenIndex][5],\r
1467 "",\r
1468 moduleName,\r
1469 packageName,\r
1470 true);\r
1471 if(Token.PCD_USAGE.UNKNOWN == token.isUsageInstanceExist(moduleName)) {\r
1472 token.addUsageInstance(usageInstance);\r
1473\r
1474 packageFullPath = this.workspacePath + File.separator +\r
1475 GlobalData.getPackagePath(packageName) +\r
1476 packageName + ".spd";\r
1477 updateTokenBySPD(usageInstance, packageFullPath);\r
1478 }\r
1479\r
1480 //\r
1481 // We need create second usage instance for inherited case, which\r
1482 // add library as an usage instance, because when build a module, and \r
1483 // if module inherited from base library, then build process will build\r
1484 // library at first. \r
1485 //\r
1486 if(Token.PCD_USAGE.UNKNOWN == token.isUsageInstanceExist(libraryName)) {\r
1487 packageName = GlobalData.getPackageNameForModule(libraryName);\r
1488 usageInstance = new UsageInstance(token,\r
1489 Token.PCD_USAGE.ALWAYS_CONSUMED,\r
1490 pcdType,\r
1491 CommonDefinition.ComponentTypeLibrary,\r
1492 libPcdDataArray[tokenIndex][3],\r
1493 null,\r
1494 (String)libPcdDataArray[tokenIndex][5],\r
1495 "",\r
1496 libraryName,\r
1497 packageName,\r
1498 false);\r
1499 token.addUsageInstance(usageInstance);\r
1500 }\r
1501 }\r
1502 }\r
1503\r
1504 /**\r
1505 Create usage instance for PCD token defined in MSA document\r
1506\r
1507 A PCD token maybe used by many modules, and every module is one of usage\r
1508 instance of this token. For ALWAY_CONSUMED, SOMETIMES_CONSUMED, it is \r
1509 consumer type usage instance of this token, and for ALWAYS_PRODUCED, \r
1510 SOMETIMES_PRODUCED, it is produce type usage instance.\r
1511 \r
1512 @param moduleName The name of module \r
1513 @param tokenInfoInMsa The PCD token information array retrieved from MSA.\r
1514 \r
1515 @return UsageInstance The usage instance created in memroy database.\r
1516 \r
1517 @throws EntityException If token did not exist in database yet.\r
1518 \r
1519 **/\r
1520 private UsageInstance createUsageInstanceFromMSA(String moduleName,\r
1521 Object[] tokenInfoInMsa) \r
1522 throws EntityException {\r
1523 String packageName = null;\r
1524 UsageInstance usageInstance = null;\r
1525 UUID tokenSpaceGuid = null;\r
1526 UUID nullUUID = new UUID(0,0);\r
1527 String primaryKeyString = null;\r
1528 UUID platformTokenSpace = nullUUID;\r
1529 Token token = null;\r
1530 Token.PCD_TYPE pcdType = Token.PCD_TYPE.UNKNOWN;\r
1531 Token.PCD_USAGE pcdUsage = Token.PCD_USAGE.UNKNOWN;\r
1532\r
1533 tokenSpaceGuid =((UUID)tokenInfoInMsa[2] == null) ? nullUUID :(UUID)tokenInfoInMsa[2];\r
1534\r
1535 primaryKeyString = Token.getPrimaryKeyString((String)tokenInfoInMsa[0],\r
1536 tokenSpaceGuid,\r
1537 platformTokenSpace);\r
1538\r
1539 //\r
1540 // Get token object from memory database firstly.\r
1541 //\r
1542 if(dbManager.isTokenInDatabase(primaryKeyString)) {\r
1543 token = dbManager.getTokenByKey(primaryKeyString);\r
1544 } else {\r
1545 throw new EntityException("The PCD token " + primaryKeyString + " defined in module " + \r
1546 moduleName + " does not exist in FPD file!" );\r
1547 }\r
1548 pcdType = Token.getpcdTypeFromString((String)tokenInfoInMsa[1]);\r
1549 pcdUsage = Token.getUsageFromString((String)tokenInfoInMsa[4]);\r
1550\r
1551 packageName = GlobalData.getPackageNameForModule(moduleName);\r
1552\r
1553 if(Token.PCD_USAGE.UNKNOWN != token.isUsageInstanceExist(moduleName)) {\r
1554 //\r
19ce77c3 1555 // BUGBUG: It is legal that same base name exist in one FPD file. In furture\r
1556 // we should use "Guid, Version, Package" and "Arch" to differ a module.\r
1557 // So currently, warning should be disabled.\r
878ddf1f 1558 //\r
19ce77c3 1559 //ActionMessage.warning(this,\r
1560 // "In module " + moduleName + " exist more than one PCD token " + token.cName\r
1561 // );\r
878ddf1f 1562 return null;\r
1563 }\r
1564\r
1565 //\r
1566 // BUGBUG: following code could be enabled at current schema. Because \r
1567 // current schema does not provide usage information.\r
1568 // \r
1569 // For FEATRURE_FLAG, FIXED_AT_BUILD, PATCH_IN_MODULE type PCD token, his \r
1570 // usage is always ALWAYS_CONSUMED\r
1571 //\r
1572 //if((pcdType != Token.PCD_TYPE.DYNAMIC) &&\r
1573 // (pcdType != Token.PCD_TYPE.DYNAMIC_EX)) {\r
1574 pcdUsage = Token.PCD_USAGE.ALWAYS_CONSUMED;\r
1575 //}\r
1576\r
1577 usageInstance = new UsageInstance(token,\r
1578 pcdUsage,\r
1579 pcdType,\r
1580 CommonDefinition.getComponentType(SurfaceAreaQuery.getComponentType()),\r
1581 tokenInfoInMsa[3],\r
1582 null,\r
1583 (String) tokenInfoInMsa[5],\r
1584 "",\r
1585 moduleName,\r
1586 packageName,\r
1587 false);\r
1588\r
1589 //\r
1590 // Use default value defined in MSA to update datum of token,\r
1591 // if datum of token does not defined in FPD file.\r
1592 //\r
1593 if((token.datum == null) &&(tokenInfoInMsa[3] != null)) {\r
1594 token.datum = tokenInfoInMsa[3];\r
1595 }\r
1596\r
1597 token.addUsageInstance(usageInstance);\r
1598\r
1599 return usageInstance;\r
1600 }\r
1601\r
1602 /**\r
1603 Create token instance object into memory database, the token information\r
1604 comes for FPD file. Normally, FPD file will contain all token platform \r
1605 informations.\r
1606 \r
1607 This fucntion should be executed at firsly before others collection work\r
1608 such as searching token information from MSA, SPD.\r
1609 \r
1610 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.\r
1611 \r
1612 @throws EntityException Failed to parse FPD xml file.\r
1613 \r
1614 **/\r
1615 private FrameworkPlatformDescriptionDocument createTokenInDBFromFPD() \r
1616 throws EntityException {\r
1617 XmlObject doc = null;\r
1618 FrameworkPlatformDescriptionDocument fpdDoc = null;\r
1619 int index = 0;\r
1620 List<PcdBuildData> pcdBuildDataArray = new ArrayList<PcdBuildData>();\r
1621 PcdBuildData pcdBuildData = null;\r
1622 Token token = null;\r
1623 UUID nullUUID = new UUID(0,0);\r
1624 UUID platformTokenSpace= nullUUID;\r
1625 List skuDataArray = new ArrayList();\r
1626 SkuInstance skuInstance = null;\r
1627 int skuIndex = 0;\r
1628\r
1629 //\r
1630 // Get all tokens from FPD file and create token into database.\r
1631 // \r
1632\r
1633 try {\r
1634 doc = XmlObject.Factory.parse(new File(fpdFilePath));\r
1635 } catch(IOException ioE) {\r
1636 throw new EntityException("Can't find the FPD xml fle:" + fpdFilePath);\r
1637 } catch(XmlException xmlE) {\r
1638 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath);\r
1639 }\r
1640\r
1641 //\r
1642 // Get memoryDatabaseManager instance from GlobalData.\r
1643 //\r
1644 if((dbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
1645 throw new EntityException("The instance of PCD memory database manager is null");\r
1646 }\r
1647\r
1648 dbManager = new MemoryDatabaseManager();\r
1649\r
1650 if(!(doc instanceof FrameworkPlatformDescriptionDocument)) {\r
1651 throw new EntityException("File " + fpdFilePath + \r
1652 " is not a FrameworkPlatformDescriptionDocument");\r
1653 }\r
1654\r
1655 fpdDoc =(FrameworkPlatformDescriptionDocument)doc;\r
1656\r
1657 //\r
1658 // Add all tokens in FPD into Memory Database.\r
1659 //\r
1660 pcdBuildDataArray = \r
1661 fpdDoc.getFrameworkPlatformDescription().getPcdBuildDeclarations().getPcdBuildDataList();\r
1662 for(index = 0; \r
1663 index < fpdDoc.getFrameworkPlatformDescription().getPcdBuildDeclarations().sizeOfPcdBuildDataArray(); \r
1664 index ++) {\r
1665 pcdBuildData = pcdBuildDataArray.get(index);\r
1666 token = new Token(pcdBuildData.getCName(), new UUID(0, 0), new UUID(0, 0));\r
1667 //\r
1668 // BUGBUG: in FPD, <defaultValue> should be defined as <Value>\r
1669 //\r
1670 token.datum = pcdBuildData.getDefaultValue();\r
98fc92fc 1671 token.tokenNumber = Integer.decode(pcdBuildData.getToken().getStringValue());\r
878ddf1f 1672 token.hiiEnabled = pcdBuildData.getHiiEnable();\r
1673 token.variableGuid = Token.getGUIDFromSchemaObject(pcdBuildData.getVariableGuid());\r
1674 token.variableName = pcdBuildData.getVariableName();\r
1675 token.variableOffset = Integer.decode(pcdBuildData.getDataOffset());\r
1676 token.skuEnabled = pcdBuildData.getSkuEnable();\r
1677 token.maxSkuCount = Integer.decode(pcdBuildData.getMaxSku());\r
1678 token.skuId = Integer.decode(pcdBuildData.getSkuId());\r
1679 token.skuDataArrayEnabled = pcdBuildData.getSkuDataArrayEnable();\r
1680 token.assignedtokenNumber = Integer.decode(pcdBuildData.getToken().getStringValue());\r
1681 skuDataArray = pcdBuildData.getSkuDataArray1();\r
3d52de13 1682 token.datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
32648c62 1683 token.datumSize = pcdBuildData.getDatumSize();\r
3d52de13 1684\r
878ddf1f 1685 if(skuDataArray != null) {\r
1686 for(skuIndex = 0; skuIndex < skuDataArray.size(); skuIndex ++) {\r
1687 //\r
1688 // BUGBUG: Now in current schema, The value is defined as String type, \r
1689 // it is not correct, the type should be same as the datumType\r
1690 //\r
1691 skuInstance = new SkuInstance(((PcdBuildData.SkuData)skuDataArray.get(skuIndex)).getId(),\r
1692 ((PcdBuildData.SkuData)skuDataArray.get(skuIndex)).getValue());\r
1693 token.skuData.add(skuInstance);\r
1694 }\r
1695 }\r
1696\r
1697 if(dbManager.isTokenInDatabase(Token.getPrimaryKeyString(token.cName, \r
1698 token.tokenSpaceName, \r
1699 platformTokenSpace))) {\r
1700 //\r
1701 // If found duplicate token, Should tool be hold?\r
1702 //\r
1703 ActionMessage.warning(this, \r
1704 "Token " + token.cName + " exists in token database");\r
1705 continue;\r
1706 }\r
1707 token.pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
1708 dbManager.addTokenToDatabase(Token.getPrimaryKeyString(token.cName, \r
1709 token.tokenSpaceName, \r
1710 platformTokenSpace), \r
1711 token);\r
1712 }\r
1713\r
1714 return fpdDoc;\r
1715 }\r
1716\r
1717 /**\r
1718 Update PCD token in memory database by help information in SPD.\r
1719\r
1720 After create token from FPD and create usage instance from MSA, we should collect\r
1721 PCD package level information from SPD and update token information in memory \r
1722 database.\r
1723 \r
1724 @param usageInstance The usage instance defined in MSA and want to search in SPD.\r
1725 @param packageFullPath The SPD file path.\r
1726 \r
1727 @throws EntityException Failed to parse SPD xml file.\r
1728 \r
1729 **/\r
1730 private void updateTokenBySPD(UsageInstance usageInstance,\r
1731 String packageFullPath) \r
1732 throws EntityException {\r
3d52de13 1733 PackageSurfaceAreaDocument pkgDoc = null;\r
1734 PcdDefinitions pcdDefinitions = null;\r
1735 List<PcdDefinitions.PcdEntry> pcdEntryArray = new ArrayList<PcdDefinitions.PcdEntry>();\r
1736 int index = 0;\r
1737 boolean isFoundInSpd = false;\r
1738 Token.DATUM_TYPE datumType = Token.DATUM_TYPE.UNKNOWN;\r
878ddf1f 1739\r
1740 try {\r
1741 pkgDoc =(PackageSurfaceAreaDocument)XmlObject.Factory.parse(new File(packageFullPath));\r
1742 } catch(IOException ioE) {\r
1743 throw new EntityException("Can't find the FPD xml fle:" + packageFullPath);\r
1744 } catch(XmlException xmlE) {\r
1745 throw new EntityException("Can't parse the FPD xml fle:" + packageFullPath);\r
1746 }\r
3d52de13 1747 pcdDefinitions = pkgDoc.getPackageSurfaceArea().getPcdDefinitions();\r
1748 //\r
1749 // It is illege for SPD file does not contains any PCD information.\r
1750 //\r
1751 if (pcdDefinitions == null) {\r
1752 return;\r
1753 }\r
878ddf1f 1754\r
3d52de13 1755 pcdEntryArray = pcdDefinitions.getPcdEntryList();\r
1756 if (pcdEntryArray == null) {\r
1757 return;\r
1758 }\r
878ddf1f 1759 for(index = 0; index < pcdEntryArray.size(); index ++) {\r
1760 if(pcdEntryArray.get(index).getCName().equalsIgnoreCase(\r
1761 usageInstance.parentToken.cName)) {\r
1762 isFoundInSpd = true;\r
1763 //\r
1764 // From SPD file , we can get following information.\r
1765 // Token: Token number defined in package level.\r
1766 // PcdItemType: This item does not single one. It means all supported item type.\r
1767 // datumType: UINT8, UNIT16, UNIT32, UINT64, VOID*, BOOLEAN \r
1768 // datumSize: The size of default value or maxmine size.\r
1769 // defaultValue: This value is defined in package level.\r
1770 // HelpText: The help text is provided in package level.\r
1771 //\r
1772\r
1773 usageInstance.parentToken.tokenNumber = Integer.decode(pcdEntryArray.get(index).getToken());\r
1774\r
1775 if(pcdEntryArray.get(index).getDatumType() != null) {\r
1776 datumType = Token.getdatumTypeFromString(\r
1777 pcdEntryArray.get(index).getDatumType().toString());\r
1778 if(usageInstance.parentToken.datumType == Token.DATUM_TYPE.UNKNOWN) {\r
1779 usageInstance.parentToken.datumType = datumType;\r
1780 } else {\r
1781 if(datumType != usageInstance.parentToken.datumType) {\r
1782 throw new EntityException("Different datum types are defined for Token :" + \r
1783 usageInstance.parentToken.cName);\r
1784 }\r
1785 }\r
1786\r
1787 } else {\r
1788 throw new EntityException("The datum type for token " + usageInstance.parentToken.cName + \r
1789 " is not defind in SPD file " + packageFullPath);\r
1790 }\r
1791\r
1792 usageInstance.defaultValueInSPD = pcdEntryArray.get(index).getDefaultValue();\r
1793 usageInstance.helpTextInSPD = "Help Text in SPD";\r
1794\r
1795 //\r
1796 // If token's datum is not valid, it indicate that datum is not provided\r
1797 // in FPD and defaultValue is not provided in MSA, then use defaultValue\r
1798 // in SPD as the datum of token.\r
1799 //\r
1800 if(usageInstance.parentToken.datum == null) {\r
1801 if(pcdEntryArray.get(index).getDefaultValue() != null) {\r
1802 usageInstance.parentToken.datum = pcdEntryArray.get(index).getDefaultValue();\r
1803 } else {\r
1804 throw new EntityException("FPD does not provide datum for token " + usageInstance.parentToken.cName +\r
1805 ", MSA and SPD also does not provide <defaultValue> for this token!");\r
1806 }\r
1807 }\r
1808 }\r
1809 }\r
878ddf1f 1810 }\r
1811\r
1812 /**\r
1813 check parameter for this action.\r
1814 \r
1815 @throws EntityException Bad parameter.\r
1816 **/\r
1817 private void checkParameter() throws EntityException {\r
1818 File file = null;\r
1819\r
1820 if((fpdFilePath == null) ||(workspacePath == null)) {\r
1821 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
1822 }\r
1823\r
1824 if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
1825 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
1826 }\r
1827\r
1828 file = new File(workspacePath);\r
1829 if(!file.exists()) {\r
1830 throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
1831 }\r
1832\r
1833 file = new File(fpdFilePath);\r
1834\r
1835 if(!file.exists()) {\r
1836 throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
1837 }\r
1838 }\r
1839\r
1840 /**\r
1841 Test case function\r
1842\r
1843 @param argv parameter from command line\r
1844 **/\r
1845 public static void main(String argv[]) throws EntityException {\r
1846 CollectPCDAction ca = new CollectPCDAction();\r
1847 ca.setWorkspacePath("G:/mdk");\r
1848 ca.setFPDFilePath("G:/mdk/EdkNt32Pkg/build/Nt32.fpd");\r
1849 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
1850 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
1851 "G:/mdk");\r
1852 ca.execute();\r
1853 }\r
1854}\r