]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
PCD tools update:
[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
8840ad58 34import org.tianocore.FrameworkModulesDocument;\r
878ddf1f 35import org.tianocore.FrameworkPlatformDescriptionDocument;\r
8840ad58 36import org.tianocore.FrameworkPlatformDescriptionDocument.FrameworkPlatformDescription;\r
878ddf1f 37import org.tianocore.ModuleSADocument;\r
8840ad58 38import org.tianocore.ModuleSADocument.ModuleSA;\r
878ddf1f 39import org.tianocore.PackageSurfaceAreaDocument;\r
40import org.tianocore.PcdBuildDeclarationsDocument.PcdBuildDeclarations.PcdBuildData;\r
8840ad58 41import org.tianocore.PcdBuildDeclarationsDocument.PcdBuildDeclarations.PcdBuildData.SkuData;\r
878ddf1f 42import org.tianocore.PcdDefinitionsDocument.PcdDefinitions;\r
8840ad58 43import org.tianocore.PcdDynamicBuildDeclarationsDocument.PcdDynamicBuildDeclarations;\r
878ddf1f 44import org.tianocore.build.autogen.CommonDefinition;\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.MemoryDatabaseManager;\r
49import org.tianocore.build.pcd.entity.SkuInstance;\r
50import org.tianocore.build.pcd.entity.Token;\r
51import org.tianocore.build.pcd.entity.UsageInstance;\r
52import org.tianocore.build.pcd.exception.EntityException;\r
53\r
99d2c3c4 54class StringTable {\r
55 private ArrayList<String> al; \r
32648c62 56 private ArrayList<String> alComments;\r
99d2c3c4 57 private String phase;\r
58 int len; \r
32648c62 59 int bodyStart;\r
60 int bodyLineNum;\r
99d2c3c4 61\r
62 public StringTable (String phase) {\r
63 this.phase = phase;\r
64 al = new ArrayList<String>();\r
32648c62 65 alComments = new ArrayList<String>();\r
99d2c3c4 66 len = 0;\r
32648c62 67 bodyStart = 0;\r
68 bodyLineNum = 0;\r
99d2c3c4 69 }\r
70\r
71 public String getSizeMacro () {\r
72 return String.format(PcdDatabase.StringTableSizeMacro, phase, getSize());\r
73 }\r
74\r
75 private int getSize () {\r
32648c62 76 //\r
77 // We have at least one Unicode Character in the table.\r
78 //\r
99d2c3c4 79 return len == 0 ? 1 : len;\r
80 }\r
81\r
32648c62 82 public int getTableLen () {\r
83 return al.size() == 0 ? 1 : al.size();\r
84 }\r
99d2c3c4 85\r
86 public String getExistanceMacro () {\r
87 return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
88 }\r
89\r
90 public String getTypeDeclaration () {\r
91\r
32648c62 92 String output;\r
99d2c3c4 93\r
32648c62 94 final String stringTable = "StringTable";\r
95 final String tab = "\t";\r
96 final String newLine = ";\r\n";\r
99d2c3c4 97\r
32648c62 98 output = "/* StringTable */\r\n";\r
99d2c3c4 99\r
32648c62 100 if (al.size() == 0) {\r
101 output += tab + String.format("UINT16 %s[1] /* StringTable is Empty */", stringTable) + newLine;\r
102 }\r
99d2c3c4 103\r
32648c62 104 for (int i = 0; i < al.size(); i++) {\r
105 String str = al.get(i);\r
99d2c3c4 106\r
32648c62 107 if (i == 0) {\r
108 //\r
109 // StringTable is a well-known name in the PCD DXE driver\r
110 //\r
111 output += tab + String.format("UINT16 %s[%d] /* %s */", stringTable, str.length() + 1, alComments.get(i)) + newLine;\r
112 } else {\r
113 output += tab + String.format("UINT16 %s_%d[%d] /* %s */", stringTable, i, str.length() + 1, alComments.get(i)) + newLine;\r
114 }\r
115 }\r
99d2c3c4 116\r
32648c62 117 return output;\r
99d2c3c4 118\r
119 }\r
120\r
121 public ArrayList<String> getInstantiation () {\r
32648c62 122 ArrayList<String> output = new ArrayList<String>();\r
99d2c3c4 123\r
32648c62 124 output.add("/* StringTable */"); \r
99d2c3c4 125\r
32648c62 126 if (al.size() == 0) {\r
127 output.add("{ 0 }");\r
128 } else {\r
129 String str;\r
99d2c3c4 130\r
32648c62 131 for (int i = 0; i < al.size(); i++) {\r
132 str = String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
133 if (i != al.size() - 1) {\r
134 str += ",";\r
135 }\r
136 output.add(str);\r
137 }\r
138 }\r
99d2c3c4 139\r
140 return output;\r
141 }\r
142\r
143 public int add (String str, Token token) {\r
144 int i;\r
145\r
146 i = len;\r
147 //\r
148 // Include the NULL character at the end of String\r
149 //\r
150 len += str.length() + 1; \r
151 al.add(str);\r
32648c62 152 alComments.add(token.getPrimaryKeyString());\r
99d2c3c4 153\r
154 return i;\r
155 }\r
156}\r
157\r
158class SizeTable {\r
159 private ArrayList<Integer> al;\r
32648c62 160 private ArrayList<String> alComments;\r
99d2c3c4 161 private String phase;\r
162 private int len;\r
32648c62 163 private int bodyStart;\r
164 private int bodyLineNum;\r
99d2c3c4 165\r
166 public SizeTable (String phase) {\r
167 this.phase = phase;\r
168 al = new ArrayList<Integer>();\r
32648c62 169 alComments = new ArrayList<String>();\r
99d2c3c4 170 len = 0;\r
32648c62 171 bodyStart = 0;\r
172 bodyLineNum = 0;\r
99d2c3c4 173 }\r
174\r
175 public String getTypeDeclaration () {\r
176 return String.format(PcdDatabase.SizeTableDeclaration, phase);\r
177 }\r
178\r
179 public ArrayList<String> getInstantiation () {\r
32648c62 180 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 181\r
182 Output.add("/* SizeTable */");\r
183 Output.add("{");\r
32648c62 184 bodyStart = 2;\r
185\r
186 if (al.size() == 0) {\r
187 Output.add("0");\r
188 } else {\r
189 for (int index = 0; index < al.size(); index++) {\r
190 Integer n = al.get(index);\r
191 String str = n.toString();\r
192\r
193 if (index != (al.size() - 1)) {\r
194 str += ",";\r
195 }\r
196\r
197 str += " /* " + alComments.get(index) + " */"; \r
198 Output.add(str);\r
199 bodyLineNum++;\r
200 \r
201 }\r
202 }\r
203 Output.add("}");\r
99d2c3c4 204\r
205 return Output;\r
206 }\r
207\r
32648c62 208 public int getBodyStart() {\r
209 return bodyStart;\r
210 }\r
99d2c3c4 211\r
32648c62 212 public int getBodyLineNum () {\r
213 return bodyLineNum;\r
214 }\r
99d2c3c4 215\r
216 public int add (Token token) {\r
217 int index = len;\r
218\r
219 len++; \r
220 al.add(token.datumSize);\r
32648c62 221 alComments.add(token.getPrimaryKeyString());\r
99d2c3c4 222\r
223 return index;\r
224 }\r
4acf8ce7 225 \r
32648c62 226 private int getDatumSize(Token token) {\r
227 /*\r
228 switch (token.datumType) {\r
229 case Token.DATUM_TYPE.UINT8:\r
230 return 1;\r
231 default:\r
232 return 0;\r
233 }\r
234 */\r
235 return 0;\r
236 }\r
99d2c3c4 237\r
32648c62 238 public int getTableLen () {\r
239 return al.size() == 0 ? 1 : al.size();\r
240 }\r
99d2c3c4 241\r
242}\r
243\r
244class GuidTable {\r
245 private ArrayList<UUID> al;\r
32648c62 246 private ArrayList<String> alComments;\r
99d2c3c4 247 private String phase;\r
248 private int len;\r
32648c62 249 private int bodyStart;\r
250 private int bodyLineNum;\r
99d2c3c4 251\r
252 public GuidTable (String phase) {\r
253 this.phase = phase;\r
254 al = new ArrayList<UUID>();\r
32648c62 255 alComments = new ArrayList<String>();\r
99d2c3c4 256 len = 0;\r
32648c62 257 bodyStart = 0;\r
258 bodyLineNum = 0;\r
99d2c3c4 259 }\r
260\r
261 public String getSizeMacro () {\r
262 return String.format(PcdDatabase.GuidTableSizeMacro, phase, getSize());\r
263 }\r
264\r
265 private int getSize () {\r
266 return (al.size() == 0)? 1 : al.size();\r
267 }\r
268\r
269 public String getExistanceMacro () {\r
270 return String.format(PcdDatabase.GuidTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
271 }\r
272\r
273 public String getTypeDeclaration () {\r
274 return String.format(PcdDatabase.GuidTableDeclaration, phase);\r
275 }\r
276\r
32648c62 277 private String getUuidCString (UUID uuid) {\r
278 String[] guidStrArray;\r
279\r
280 guidStrArray =(uuid.toString()).split("-");\r
281\r
282 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
283 guidStrArray[0],\r
284 guidStrArray[1],\r
285 guidStrArray[2],\r
286 (guidStrArray[3].substring(0, 2)),\r
287 (guidStrArray[3].substring(2, 4)),\r
288 (guidStrArray[4].substring(0, 2)),\r
289 (guidStrArray[4].substring(2, 4)),\r
290 (guidStrArray[4].substring(4, 6)),\r
291 (guidStrArray[4].substring(6, 8)),\r
292 (guidStrArray[4].substring(8, 10)),\r
293 (guidStrArray[4].substring(10, 12))\r
294 );\r
295 }\r
99d2c3c4 296\r
297 public ArrayList<String> getInstantiation () {\r
32648c62 298 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 299\r
300 Output.add("/* GuidTable */");\r
301 Output.add("{");\r
32648c62 302 bodyStart = 2;\r
99d2c3c4 303\r
32648c62 304 if (al.size() == 0) {\r
305 Output.add(getUuidCString(new UUID(0, 0)));\r
306 }\r
99d2c3c4 307 \r
308 for (Object u : al) {\r
309 UUID uuid = (UUID)u;\r
32648c62 310 String str = getUuidCString(uuid);\r
99d2c3c4 311\r
32648c62 312 if (al.indexOf(u) != (al.size() - 1)) {\r
313 str += ",";\r
314 }\r
99d2c3c4 315 Output.add(str);\r
32648c62 316 bodyLineNum++;\r
99d2c3c4 317\r
318 }\r
32648c62 319 Output.add("}");\r
99d2c3c4 320\r
321 return Output;\r
322 }\r
323\r
32648c62 324 public int getBodyStart() {\r
325 return bodyStart;\r
326 }\r
99d2c3c4 327\r
32648c62 328 public int getBodyLineNum () {\r
329 return bodyLineNum;\r
330 }\r
99d2c3c4 331\r
332 public int add (UUID uuid, String name) {\r
333 int index = len;\r
334 //\r
335 // Include the NULL character at the end of String\r
336 //\r
337 len++; \r
338 al.add(uuid);\r
339\r
340 return index;\r
341 }\r
342\r
32648c62 343 public int getTableLen () {\r
344 return al.size() == 0 ? 0 : al.size();\r
345 }\r
99d2c3c4 346\r
347}\r
348\r
349class SkuIdTable {\r
350 private ArrayList<Integer[]> al;\r
32648c62 351 private ArrayList<String> alComment;\r
99d2c3c4 352 private String phase;\r
353 private int len;\r
32648c62 354 private int bodyStart;\r
355 private int bodyLineNum;\r
99d2c3c4 356\r
357 public SkuIdTable (String phase) {\r
358 this.phase = phase;\r
359 al = new ArrayList<Integer[]>();\r
32648c62 360 alComment = new ArrayList<String>();\r
361 bodyStart = 0;\r
362 bodyLineNum = 0;\r
99d2c3c4 363 len = 0;\r
364 }\r
365\r
366 public String getSizeMacro () {\r
367 return String.format(PcdDatabase.SkuIdTableSizeMacro, phase, getSize());\r
368 }\r
369\r
370 private int getSize () {\r
371 return (al.size() == 0)? 1 : al.size();\r
372 }\r
373\r
374 public String getExistanceMacro () {\r
375 return String.format(PcdDatabase.SkuTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
376 }\r
377\r
378 public String getTypeDeclaration () {\r
379 return String.format(PcdDatabase.SkuIdTableDeclaration, phase);\r
380 }\r
381\r
382 public ArrayList<String> getInstantiation () {\r
32648c62 383 ArrayList<String> Output = new ArrayList<String> ();\r
99d2c3c4 384\r
385 Output.add("/* SkuIdTable */");\r
386 Output.add("{");\r
32648c62 387 bodyStart = 2;\r
99d2c3c4 388\r
32648c62 389 if (al.size() == 0) {\r
390 Output.add("0");\r
391 }\r
99d2c3c4 392 \r
393 for (int index = 0; index < al.size(); index++) {\r
32648c62 394 String str;\r
99d2c3c4 395\r
32648c62 396 str = "/* " + alComment.get(index) + "*/ ";\r
397 str += "/* MaxSku */ ";\r
99d2c3c4 398\r
399\r
32648c62 400 Integer[] ia = al.get(index);\r
99d2c3c4 401\r
32648c62 402 str += ia[0].toString() + ", ";\r
403 for (int index2 = 1; index2 < ia.length; index2++) {\r
404 str += ia[index2].toString();\r
405 if (index != al.size() - 1) {\r
406 str += ", ";\r
407 }\r
408 }\r
99d2c3c4 409\r
410 Output.add(str);\r
32648c62 411 bodyLineNum++;\r
99d2c3c4 412\r
413 }\r
414\r
32648c62 415 Output.add("}");\r
99d2c3c4 416\r
417 return Output;\r
418 }\r
419\r
420 public int add (Token token) {\r
421\r
32648c62 422 int index;\r
99d2c3c4 423\r
32648c62 424 Integer [] skuIds = new Integer[token.maxSkuCount + 1];\r
425 skuIds[0] = new Integer(token.maxSkuCount);\r
426 for (index = 1; index < skuIds.length; index++) {\r
427 skuIds[index] = new Integer(token.skuData.get(index - 1).id);\r
428 }\r
99d2c3c4 429\r
430 index = len;\r
431\r
432 len += skuIds.length; \r
433 al.add(skuIds);\r
32648c62 434 alComment.add(token.getPrimaryKeyString());\r
99d2c3c4 435\r
436 return index;\r
437 }\r
438\r
32648c62 439 public int getTableLen () {\r
440 return al.size() == 0 ? 1 : al.size();\r
441 }\r
99d2c3c4 442\r
443}\r
444\r
445class LocalTokenNumberTable {\r
446 private ArrayList<String> al;\r
32648c62 447 private ArrayList<String> alComment;\r
99d2c3c4 448 private String phase;\r
449 private int len;\r
99d2c3c4 450\r
451 public LocalTokenNumberTable (String phase) {\r
452 this.phase = phase;\r
453 al = new ArrayList<String>();\r
32648c62 454 alComment = new ArrayList<String>();\r
99d2c3c4 455\r
456 len = 0;\r
457 }\r
458\r
459 public String getSizeMacro () {\r
3496595d 460 return String.format(PcdDatabase.LocalTokenNumberTableSizeMacro, phase, getSize())\r
461 + String.format(PcdDatabase.LocalTokenNumberSizeMacro, phase, al.size());\r
99d2c3c4 462 }\r
463\r
464 public int getSize () {\r
465 return (al.size() == 0)? 1 : al.size();\r
466 }\r
467\r
468 public String getExistanceMacro () {\r
469 return String.format(PcdDatabase.DatabaseExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
470 }\r
471\r
472 public String getTypeDeclaration () {\r
473 return String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);\r
474 }\r
475\r
476 public ArrayList<String> getInstantiation () {\r
32648c62 477 ArrayList<String> output = new ArrayList<String>();\r
99d2c3c4 478\r
479 output.add("/* LocalTokenNumberTable */");\r
480 output.add("{");\r
99d2c3c4 481\r
32648c62 482 if (al.size() == 0) {\r
483 output.add("0");\r
484 }\r
99d2c3c4 485 \r
486 for (int index = 0; index < al.size(); index++) {\r
32648c62 487 String str;\r
99d2c3c4 488\r
32648c62 489 str = (String)al.get(index);\r
99d2c3c4 490\r
32648c62 491 str += " /* " + alComment.get(index) + " */ ";\r
99d2c3c4 492\r
493\r
32648c62 494 if (index != (al.size() - 1)) {\r
495 str += ",";\r
496 }\r
99d2c3c4 497\r
498 output.add(str);\r
499\r
500 }\r
501\r
32648c62 502 output.add("}");\r
99d2c3c4 503\r
504 return output;\r
505 }\r
506\r
507 public int add (Token token) {\r
508 int index = len;\r
32648c62 509 String str;\r
99d2c3c4 510\r
511 len++; \r
512\r
32648c62 513 str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());\r
99d2c3c4 514\r
32648c62 515 if (token.isStringType()) {\r
516 str += " | PCD_TYPE_STRING";\r
517 }\r
99d2c3c4 518\r
32648c62 519 if (token.skuEnabled) {\r
520 str += " | PCD_TYPE_SKU_ENABLED";\r
521 }\r
99d2c3c4 522\r
32648c62 523 if (token.hiiEnabled) {\r
524 str += " | PCD_TYPE_HII";\r
525 }\r
99d2c3c4 526\r
32648c62 527 if (token.vpdEnabled) {\r
528 str += " | PCD_TYPE_VPD";\r
529 }\r
530 \r
99d2c3c4 531 al.add(str);\r
32648c62 532 alComment.add(token.getPrimaryKeyString());\r
99d2c3c4 533\r
534 return index;\r
535 }\r
536}\r
537\r
538class ExMapTable {\r
539\r
32648c62 540 class ExTriplet {\r
541 public Integer guidTableIdx;\r
542 public Long exTokenNumber;\r
543 public Long localTokenIdx;\r
544 \r
545 public ExTriplet (int guidTableIdx, long exTokenNumber, long localTokenIdx) {\r
546 this.guidTableIdx = new Integer(guidTableIdx);\r
547 this.exTokenNumber = new Long(exTokenNumber);\r
548 this.localTokenIdx = new Long(localTokenIdx);\r
549 }\r
550 }\r
99d2c3c4 551\r
552 private ArrayList<ExTriplet> al;\r
32648c62 553 private ArrayList<String> alComment;\r
99d2c3c4 554 private String phase;\r
555 private int len;\r
32648c62 556 private int bodyStart;\r
557 private int bodyLineNum;\r
558 private int base;\r
99d2c3c4 559\r
560 public ExMapTable (String phase) {\r
561 this.phase = phase;\r
562 al = new ArrayList<ExTriplet>();\r
32648c62 563 alComment = new ArrayList<String>();\r
564 bodyStart = 0;\r
565 bodyLineNum = 0;\r
99d2c3c4 566 len = 0;\r
567 }\r
568\r
569 public String getSizeMacro () {\r
570 return String.format(PcdDatabase.ExMapTableSizeMacro, phase, getTableLen())\r
32648c62 571 + String.format(PcdDatabase.ExTokenNumber, phase, al.size());\r
99d2c3c4 572 }\r
573\r
574 private int getSize () {\r
575 return (al.size() == 0)? 1 : al.size();\r
576 }\r
577\r
578 public String getExistanceMacro () {\r
579 return String.format(PcdDatabase.ExMapTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
580 }\r
581\r
582 public String getTypeDeclaration () {\r
583 return String.format(PcdDatabase.ExMapTableDeclaration, phase);\r
584 }\r
585\r
586 public ArrayList<String> getInstantiation () {\r
32648c62 587 ArrayList<String> Output = new ArrayList<String>();\r
99d2c3c4 588\r
589 Output.add("/* ExMapTable */");\r
590 Output.add("{");\r
32648c62 591 bodyStart = 2;\r
99d2c3c4 592\r
32648c62 593 if (al.size() == 0) {\r
594 Output.add("{0, 0, 0}");\r
595 }\r
99d2c3c4 596 \r
32648c62 597 int index;\r
99d2c3c4 598 for (index = 0; index < al.size(); index++) {\r
32648c62 599 String str;\r
99d2c3c4 600\r
32648c62 601 ExTriplet e = (ExTriplet)al.get(index);\r
99d2c3c4 602\r
32648c62 603 str = "{ " + e.exTokenNumber.toString() + ", ";\r
604 str += e.localTokenIdx.toString() + ", ";\r
605 str += e.guidTableIdx.toString();\r
99d2c3c4 606\r
32648c62 607 str += " /* " + alComment.get(index) + " */";\r
99d2c3c4 608\r
32648c62 609 if (index != al.size() - 1) {\r
610 str += ",";\r
611 }\r
99d2c3c4 612\r
613 Output.add(str);\r
32648c62 614 bodyLineNum++;\r
99d2c3c4 615\r
616 }\r
617\r
32648c62 618 Output.add("}");\r
99d2c3c4 619\r
620 return Output;\r
621 }\r
622\r
623 public int add (int localTokenIdx, long exTokenNum, int guidTableIdx, String name) {\r
624 int index = len;\r
625\r
626 len++; \r
627 al.add(new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx));\r
32648c62 628 alComment.add(name);\r
99d2c3c4 629\r
630 return index;\r
631 }\r
632\r
32648c62 633 public int getTableLen () {\r
634 return al.size() == 0 ? 1 : al.size();\r
635 }\r
99d2c3c4 636\r
637}\r
638\r
639class PcdDatabase {\r
640\r
641 public final static String ExMapTableDeclaration = "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
642 public final static String GuidTableDeclaration = "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
3496595d 643 public final static String LocalTokenNumberTableDeclaration = "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
99d2c3c4 644 public final static String StringTableDeclaration = "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
3496595d 645 public final static String SizeTableDeclaration = "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
99d2c3c4 646 public final static String SkuIdTableDeclaration = "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
647\r
648\r
649 public final static String ExMapTableSizeMacro = "#define %s_EXMAPPING_TABLE_SIZE %d\r\n";\r
32648c62 650 public final static String ExTokenNumber = "#define %s_EX_TOKEN_NUMBER %d\r\n";\r
99d2c3c4 651 public final static String GuidTableSizeMacro = "#define %s_GUID_TABLE_SIZE %d\r\n";\r
3496595d 652 public final static String LocalTokenNumberTableSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE %d\r\n";\r
653 public final static String LocalTokenNumberSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER %d\r\n";\r
99d2c3c4 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
8840ad58 714 Token t = (Token)alTokens.get(i);\r
32648c62 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
4c114006 792 java.util.Collections.sort(initTokens, comparator);\r
32648c62 793 initCode = processTokens(initTokens);\r
794\r
795 //\r
796 // Generate Structure Declaration for PcdTokens without Default Value\r
797 // PEI_PCD_DATABASE_UNINIT\r
798 //\r
4c114006 799 java.util.Collections.sort(uninitTokens, comparator);\r
32648c62 800 uninitCode = processTokens(uninitTokens);\r
801\r
802 //\r
803 // Generate size info Macro for all Tables\r
804 //\r
805 macroStr += guidTable.getSizeMacro();\r
806 macroStr += stringTable.getSizeMacro();\r
807 macroStr += skuIdTable.getSizeMacro();\r
808 macroStr += localTokenNumberTable.getSizeMacro();\r
809 macroStr += exMapTable.getSizeMacro();\r
810\r
811 //\r
812 // Generate existance info Macro for all Tables\r
813 //\r
814 macroStr += guidTable.getExistanceMacro();\r
815 macroStr += stringTable.getExistanceMacro();\r
816 macroStr += skuIdTable.getExistanceMacro();\r
817 macroStr += localTokenNumberTable.getExistanceMacro();\r
818 macroStr += exMapTable.getExistanceMacro();\r
819\r
820 //\r
821 // Generate Structure Declaration for PcdTokens with Default Value\r
822 // for example PEI_PCD_DATABASE_INIT\r
823 //\r
824 initDeclStr += "typedef struct {" + newLine;\r
825 {\r
826 initDeclStr += tab + exMapTable.getTypeDeclaration();\r
827 initDeclStr += tab + guidTable.getTypeDeclaration();\r
828 initDeclStr += tab + localTokenNumberTable.getTypeDeclaration();\r
829 initDeclStr += tab + stringTable.getTypeDeclaration();\r
830 initDeclStr += tab + sizeTable.getTypeDeclaration();\r
831 initDeclStr += tab + skuIdTable.getTypeDeclaration();\r
832 if (phase.equalsIgnoreCase("PEI")) {\r
833 initDeclStr += tab + "SKU_ID SystemSkuId;" + newLine;\r
834 }\r
835\r
836 decla = initCode.get(new String("Declaration"));\r
837 for (i = 0; i < decla.size(); i++) {\r
838 initDeclStr += tab + decla.get(i) + declNewLine;\r
839 }\r
840\r
841 //\r
842 // Generate Structure Declaration for PcdToken with SkuEnabled\r
843 //\r
844 decla = initCode.get("DeclarationForSku");\r
845\r
846 for (i = 0; i < decla.size(); i++) {\r
847 initDeclStr += tab + decla.get(i) + declNewLine;\r
848 }\r
849 }\r
850 initDeclStr += String.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase);\r
851\r
852 //\r
853 // Generate MACRO for structure intialization of PCDTokens with Default Value\r
854 // The sequence must match the sequence of declaration of the memembers in the structure\r
855 String tmp = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase());\r
856 initInstStr += tmp + newLine;\r
857 initInstStr += tab + genInstantiationStr(exMapTable.getInstantiation()) + commaNewLine;\r
858 initInstStr += tab + genInstantiationStr(guidTable.getInstantiation()) + commaNewLine;\r
859 initInstStr += tab + genInstantiationStr(localTokenNumberTable.getInstantiation()) + commaNewLine; \r
32648c62 860 initInstStr += tab + genInstantiationStr(stringTable.getInstantiation()) + commaNewLine;\r
861 initInstStr += tab + genInstantiationStr(sizeTable.getInstantiation()) + commaNewLine;\r
862 initInstStr += tab + genInstantiationStr(skuIdTable.getInstantiation()) + commaNewLine;\r
863 //\r
864 // For SystemSkuId\r
865 //\r
866 if (phase.equalsIgnoreCase("PEI")) {\r
867 initInstStr += tab + "0" + tab + "/* SystemSkuId */" + commaNewLine;\r
868 }\r
869\r
870 inst = initCode.get("Instantiation");\r
871 for (i = 0; i < inst.size(); i++) {\r
872 initInstStr += tab + inst.get(i) + commaNewLine;\r
873 }\r
874\r
875 inst = initCode.get("InstantiationForSku");\r
876 for (i = 0; i < inst.size(); i++) {\r
877 initInstStr += tab + inst.get(i);\r
878 if (i != inst.size() - 1) {\r
879 initInstStr += commaNewLine;\r
880 }\r
881 }\r
882\r
883 initInstStr += "};";\r
884\r
885 uninitDeclStr += "typedef struct {" + newLine;\r
886 {\r
887 decla = uninitCode.get("Declaration");\r
888 if (decla.size() == 0) {\r
889 uninitDeclStr += "UINT8 dummy /* The UINT struct is empty */" + declNewLine;\r
890 } else {\r
891 \r
892 for (i = 0; i < decla.size(); i++) {\r
893 uninitDeclStr += tab + decla.get(i) + declNewLine;\r
894 }\r
895 \r
896 decla = uninitCode.get("DeclarationForSku");\r
897 \r
898 for (i = 0; i < decla.size(); i++) {\r
899 uninitDeclStr += tab + decla.get(i) + declNewLine;\r
900 }\r
901 }\r
902 }\r
903 uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase);\r
904\r
905 cString = initInstStr + newLine;\r
906 hString = macroStr + newLine \r
907 + initDeclStr + newLine\r
908 + uninitDeclStr + newLine\r
909 + newLine;\r
4acf8ce7 910 \r
911 hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION %d", phase, version);\r
32648c62 912\r
913 }\r
914\r
915 private String genInstantiationStr (ArrayList<String> alStr) {\r
916 String str = "";\r
917 for (int i = 0; i< alStr.size(); i++) {\r
918 str += "\t" + alStr.get(i);\r
919 if (i != alStr.size() - 1) {\r
920 str += "\r\n";\r
921 }\r
922 }\r
923\r
924 return str;\r
925 }\r
926\r
927 private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken) {\r
928\r
32648c62 929 HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();\r
930\r
931 ArrayList<String> decl = new ArrayList<String>();\r
932 ArrayList<String> declForSkuEnableType = new ArrayList<String>();\r
933 ArrayList<String> inst = new ArrayList<String>();\r
934 ArrayList<String> instForSkuEnableType = new ArrayList<String>();\r
935\r
936 for (int index = 0; index < alToken.size(); index++) {\r
937 Token token = alToken.get(index);\r
938\r
939 if (token.skuEnabled) {\r
940 //\r
941 // BugBug: Schema only support Data type now\r
942 //\r
943 int tableIdx;\r
944\r
945 tableIdx = skuIdTable.add(token);\r
946\r
947 decl.add(getSkuEnabledTypeDeclaration(token));\r
948 if (token.hasDefaultValue()) {\r
949 inst.add(getSkuEnabledTypeInstantiaion(token, tableIdx)); \r
950 }\r
951\r
952 declForSkuEnableType.add(getDataTypeDeclarationForSkuEnabled(token));\r
953 if (token.hasDefaultValue()) {\r
954 instForSkuEnableType.add(getDataTypeInstantiationForSkuEnabled(token));\r
955 }\r
956\r
957 } else {\r
958 if (token.hiiEnabled) {\r
959 decl.add(getVariableEnableTypeDeclaration(token));\r
960 inst.add(getVariableEnableInstantiation(token));\r
961 } else if (token.vpdEnabled) {\r
962 decl.add(getVpdEnableTypeDeclaration(token));\r
963 inst.add(getVpdEnableTypeInstantiation(token));\r
964 } else if (token.isStringType()) {\r
965 decl.add(getStringTypeDeclaration(token));\r
966 inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));\r
967 }\r
968 else {\r
969 decl.add(getDataTypeDeclaration(token));\r
970 if (token.hasDefaultValue()) {\r
971 inst.add(getDataTypeInstantiation(token));\r
972 }\r
973 }\r
974 }\r
975\r
976 sizeTable.add(token);\r
977 localTokenNumberTable.add(token);\r
8840ad58 978 token.tokenNumber = assignedTokenNumber++;\r
32648c62 979\r
980 }\r
981\r
982 map.put("Declaration", decl);\r
983 map.put("DeclarationForSku", declForSkuEnableType);\r
984 map.put("Instantiation", inst);\r
985 map.put("InstantiationForSku", instForSkuEnableType);\r
986\r
987 return map;\r
988 }\r
989\r
990 private String getSkuEnabledTypeDeclaration (Token token) {\r
991 return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());\r
992 }\r
993\r
994 private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
995\r
996 String offsetof = String.format(PcdDatabase.offsetOfSkuHeadStrTemplate, phase, token.hasDefaultValue()? "Init" : "Uninit", token.getPrimaryKeyString());\r
997 return String.format("{ %s, %d }", offsetof, SkuTableIdx);\r
998 }\r
999\r
1000 private String getDataTypeDeclarationForSkuEnabled (Token token) {\r
1001 String typeStr = "";\r
1002\r
1003 if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
1004 typeStr = "UINT8 %s_%s[%d];\r\n";\r
1005 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
1006 typeStr = "UINT16 %s_%s[%d];\r\n";\r
1007 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
1008 typeStr = "UINT32 %s_%s[%d];\r\n";\r
1009 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
1010 typeStr = "UINT64 %s_%s[%d];\r\n";\r
1011 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
1012 typeStr = "BOOLEAN %s_%s[%d];\r\n";\r
1013 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1014 return String.format("UINT8 %s_s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
1015 } \r
1016\r
1017 return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.maxSkuCount);\r
1018\r
1019 }\r
1020\r
1021 private String getDataTypeInstantiationForSkuEnabled (Token token) {\r
1022 String str = "";\r
1023\r
1024 if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1025 return String.format("UINT8 %s_s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
1026 } else {\r
1027 str = "{ ";\r
1028 for (int idx = 0; idx < token.maxSkuCount; idx++) {\r
1029 str += token.skuData.get(idx).toString();\r
1030 if (idx != token.maxSkuCount - 1) {\r
1031 str += ", ";\r
1032 }\r
1033 }\r
1034 str += "}";\r
1035\r
1036 return str;\r
1037 }\r
1038\r
1039 }\r
1040\r
1041 private String getDataTypeInstantiation (Token token) {\r
1042\r
32648c62 1043 if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1044 return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
1045 } else {\r
1046 return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
1047 }\r
1048 }\r
1049\r
1050\r
1051 private String getDataTypeDeclaration (Token token) {\r
1052\r
1053 String typeStr = "";\r
1054\r
1055 if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
1056 typeStr = "UINT8";\r
1057 } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
1058 typeStr = "UINT16";\r
1059 } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
1060 typeStr = "UINT32";\r
1061 } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
1062 typeStr = "UINT64";\r
1063 } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
1064 typeStr = "BOOLEAN";\r
1065 } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
1066 return String.format("UINT8 %s[%d]", token.getPrimaryKeyString(), token.datumSize);\r
1067 } else {\r
1068 }\r
1069\r
1070 return String.format("%s %s", typeStr, token.getPrimaryKeyString());\r
1071 }\r
1072\r
1073 private String getVpdEnableTypeDeclaration (Token token) {\r
1074 return String.format("VPD_HEAD %s", token.getPrimaryKeyString());\r
1075 }\r
1076\r
1077 private String getVpdEnableTypeInstantiation (Token token) {\r
1078 return String.format("{ %d } /* %s */", token.vpdOffset,\r
1079 token.getPrimaryKeyString());\r
1080 }\r
1081\r
1082 private String getStringTypeDeclaration (Token token) {\r
1083 return String.format("UINT16 %s", token.getPrimaryKeyString());\r
1084 }\r
1085\r
1086 private String getStringTypeInstantiation (int StringTableIdx, Token token) {\r
1087 return String.format ("%d /* %s */", StringTableIdx,\r
1088 token.getPrimaryKeyString()); \r
1089 }\r
1090\r
1091\r
1092 private String getVariableEnableTypeDeclaration (Token token) {\r
1093 return String.format("VARIABLE_HEAD %s", token.getPrimaryKeyString());\r
1094 }\r
1095\r
1096 private String getVariableEnableInstantiation (Token token) {\r
1097 return String.format("{ %d, %d, %d } /* %s */", guidTable.add(token.variableGuid, token.getPrimaryKeyString()),\r
1098 stringTable.add(token.variableName, token),\r
1099 token.variableOffset, \r
1100 token.getPrimaryKeyString());\r
1101 }\r
1102\r
1103 public int getTotalTokenNumber () {\r
1104 return sizeTable.getTableLen();\r
1105 }\r
99d2c3c4 1106\r
1107 public static String getPcdDatabaseCommonDefinitions () \r
1108 throws EntityException {\r
1109\r
1110 String retStr = "";\r
1111 try {\r
32648c62 1112 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1113 "Tools" + File.separator + \r
1114 "Conf" + File.separator +\r
1115 "Pcd" + File.separator +\r
1116 "PcdDatabaseCommonDefinitions.sample");\r
99d2c3c4 1117 FileReader reader = new FileReader(file);\r
1118 BufferedReader in = new BufferedReader(reader);\r
1119 String str;\r
1120 while ((str = in.readLine()) != null) {\r
1121 retStr = retStr +"\r\n" + str;\r
1122 }\r
1123 } catch (Exception ex) {\r
1124 throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");\r
1125 }\r
1126\r
1127 return retStr;\r
1128 }\r
1129\r
32648c62 1130 public static String getPcdDxeDatabaseDefinitions () \r
1131 throws EntityException {\r
1132\r
1133 String retStr = "";\r
1134 try {\r
1135 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1136 "Tools" + File.separator + \r
1137 "Conf" + File.separator +\r
1138 "Pcd" + File.separator +\r
1139 "PcdDatabaseDxeDefinitions.sample");\r
1140 FileReader reader = new FileReader(file);\r
1141 BufferedReader in = new BufferedReader(reader);\r
1142 String str;\r
1143 while ((str = in.readLine()) != null) {\r
1144 retStr = retStr +"\r\n" + str;\r
1145 }\r
1146 } catch (Exception ex) {\r
1147 throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");\r
1148 }\r
1149\r
1150 return retStr;\r
1151 }\r
1152\r
1153 public static String getPcdPeiDatabaseDefinitions () \r
1154 throws EntityException {\r
1155\r
1156 String retStr = "";\r
1157 try {\r
1158 File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
1159 "Tools" + File.separator + \r
1160 "Conf" + File.separator +\r
1161 "Pcd" + File.separator +\r
1162 "PcdDatabasePeiDefinitions.sample");\r
1163 FileReader reader = new FileReader(file);\r
1164 BufferedReader in = new BufferedReader(reader);\r
1165 String str;\r
1166 while ((str = in.readLine()) != null) {\r
1167 retStr = retStr +"\r\n" + str;\r
1168 }\r
1169 } catch (Exception ex) {\r
1170 throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");\r
1171 }\r
1172\r
1173 return retStr;\r
1174 }\r
99d2c3c4 1175\r
1176}\r
1177\r
8840ad58 1178class ModuleInfo {\r
1179 public ModuleSADocument.ModuleSA module;\r
1180 public UsageInstance.MODULE_TYPE type;\r
1181\r
1182 public ModuleInfo (ModuleSADocument.ModuleSA module, UsageInstance.MODULE_TYPE type) {\r
1183 this.module = module;\r
1184 this.type = type;\r
1185 }\r
1186}\r
1187\r
878ddf1f 1188/** This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
1189 This class will be used for wizard and build tools, So it can *not* inherit\r
1190 from buildAction or UIAction.\r
1191**/\r
1192public class CollectPCDAction {\r
1193 /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.\r
1194 private MemoryDatabaseManager dbManager;\r
1195\r
1196 /// Workspacepath hold the workspace information.\r
1197 private String workspacePath;\r
1198\r
1199 /// FPD file is the root file. \r
1200 private String fpdFilePath;\r
1201\r
1202 /// Message level for CollectPCDAction.\r
1203 private int originalMessageLevel;\r
1204\r
8840ad58 1205 /// Cache the fpd docment instance for private usage.\r
1206 private FrameworkPlatformDescriptionDocument fpdDocInstance;\r
1207\r
878ddf1f 1208 /**\r
1209 Set WorkspacePath parameter for this action class.\r
1210\r
1211 @param workspacePath parameter for this action\r
1212 **/\r
1213 public void setWorkspacePath(String workspacePath) {\r
1214 this.workspacePath = workspacePath;\r
1215 }\r
1216\r
1217 /**\r
1218 Set action message level for CollectPcdAction tool.\r
1219\r
1220 The message should be restored when this action exit.\r
1221\r
1222 @param actionMessageLevel parameter for this action\r
1223 **/\r
1224 public void setActionMessageLevel(int actionMessageLevel) {\r
1225 originalMessageLevel = ActionMessage.messageLevel;\r
1226 ActionMessage.messageLevel = actionMessageLevel;\r
1227 }\r
1228\r
1229 /**\r
1230 Set FPDFileName parameter for this action class.\r
1231\r
1232 @param fpdFilePath fpd file path\r
1233 **/\r
1234 public void setFPDFilePath(String fpdFilePath) {\r
1235 this.fpdFilePath = fpdFilePath;\r
1236 }\r
1237\r
1238 /**\r
1239 Common function interface for outer.\r
1240 \r
1241 @param workspacePath The path of workspace of current build or analysis.\r
1242 @param fpdFilePath The fpd file path of current build or analysis.\r
1243 @param messageLevel The message level for this Action.\r
1244 \r
1245 @throws Exception The exception of this function. Because it can *not* be predict\r
1246 where the action class will be used. So only Exception can be throw.\r
1247 \r
1248 **/\r
1249 public void perform(String workspacePath, String fpdFilePath, \r
1250 int messageLevel) throws Exception {\r
1251 setWorkspacePath(workspacePath);\r
1252 setFPDFilePath(fpdFilePath);\r
1253 setActionMessageLevel(messageLevel);\r
1254 checkParameter();\r
1255 execute();\r
1256 ActionMessage.messageLevel = originalMessageLevel;\r
1257 }\r
1258\r
1259 /**\r
1260 Core execution function for this action class.\r
1261 \r
1262 This function work flows will be:\r
8840ad58 1263 1) Collect and prepocess PCD information from FPD file, all PCD\r
1264 information will be stored into memory database.\r
1265 2) Generate 3 strings for\r
1266 a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r
1267 b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r
1268 c) DXE PCD Database (C structure) for PCD Service DXE.\r
99d2c3c4 1269 \r
878ddf1f 1270 \r
1271 @throws EntityException Exception indicate failed to execute this action.\r
1272 \r
1273 **/\r
1274 private void execute() throws EntityException {\r
8840ad58 1275 //\r
1276 // Get memoryDatabaseManager instance from GlobalData.\r
1277 // The memoryDatabaseManager should be initialized for whatever build\r
1278 // tools or wizard tools\r
1279 //\r
1280 if((dbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
1281 throw new EntityException("The instance of PCD memory database manager is null");\r
1282 }\r
878ddf1f 1283\r
1284 //\r
1285 // Collect all PCD information defined in FPD file.\r
1286 // Evenry token defind in FPD will be created as an token into \r
1287 // memory database.\r
1288 //\r
8840ad58 1289 createTokenInDBFromFPD();\r
878ddf1f 1290\r
99d2c3c4 1291 \r
1292 //\r
1293 // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
1294 // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
32648c62 1295 //\r
1296 genPcdDatabaseSourceCode ();\r
1297 \r
878ddf1f 1298 }\r
1299\r
32648c62 1300 /**\r
1301 This function generates source code for PCD Database.\r
1302 \r
1303 @param void\r
1304 @throws EntityException If the token does *not* exist in memory database.\r
99d2c3c4 1305\r
32648c62 1306 **/\r
8840ad58 1307 private void genPcdDatabaseSourceCode()\r
1308 throws EntityException {\r
32648c62 1309 String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();\r
99d2c3c4 1310\r
32648c62 1311 ArrayList<Token> alPei = new ArrayList<Token> ();\r
1312 ArrayList<Token> alDxe = new ArrayList<Token> ();\r
99d2c3c4 1313\r
32648c62 1314 dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
99d2c3c4 1315 PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
32648c62 1316 pcdPeiDatabase.genCode();\r
1317 dbManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
1318 + PcdDatabase.getPcdPeiDatabaseDefinitions();\r
1319 dbManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
99d2c3c4 1320\r
1321 PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
32648c62 1322 "DXE",\r
1323 alPei.size()\r
1324 );\r
1325 pcdDxeDatabase.genCode();\r
1326 dbManager.PcdDxeHString = dbManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
1327 + PcdDatabase.getPcdDxeDatabaseDefinitions();\r
1328 dbManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
1329 }\r
1330\r
1331 /**\r
8840ad58 1332 Get component array from FPD.\r
878ddf1f 1333 \r
8840ad58 1334 This function maybe provided by some Global class.\r
878ddf1f 1335 \r
8840ad58 1336 @return List<ModuleInfo> the component array.\r
878ddf1f 1337 \r
8840ad58 1338 */\r
1339 private List<ModuleInfo> getComponentsFromFPD() \r
878ddf1f 1340 throws EntityException {\r
8840ad58 1341 HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
1342 List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
1343 ModuleInfo current = null;\r
1344 int index = 0;\r
1345 org.tianocore.Components components = null;\r
1346 FrameworkModulesDocument.FrameworkModules fModules = null;\r
1347 java.util.List<ModuleSADocument.ModuleSA> modules = null;\r
1348 \r
878ddf1f 1349\r
8840ad58 1350 if (fpdDocInstance == null) {\r
1351 try {\r
1352 fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
1353 } catch(IOException ioE) {\r
1354 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
1355 } catch(XmlException xmlE) {\r
1356 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
1357 }\r
878ddf1f 1358\r
878ddf1f 1359 }\r
1360\r
8840ad58 1361 //\r
1362 // Check whether FPD contians <FramworkModules>\r
1363 // \r
1364 fModules = fpdDocInstance.getFrameworkPlatformDescription().getFrameworkModules();\r
1365 if (fModules == null) {\r
1366 return null;\r
1367 }\r
878ddf1f 1368\r
8840ad58 1369 //\r
1370 // BUGBUG: The following is work around code, the final component type should be get from\r
1371 // GlobalData class.\r
1372 // \r
1373 components = fModules.getSEC();\r
1374 if (components != null) {\r
1375 modules = components.getModuleSAList();\r
1376 for (index = 0; index < modules.size(); index ++) {\r
1377 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.SEC));\r
878ddf1f 1378 }\r
8840ad58 1379 }\r
878ddf1f 1380\r
8840ad58 1381 components = fModules.getPEICORE();\r
1382 if (components != null) {\r
1383 modules = components.getModuleSAList();\r
1384 for (index = 0; index < modules.size(); index ++) {\r
1385 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEI_CORE));\r
878ddf1f 1386 }\r
1387 }\r
878ddf1f 1388\r
8840ad58 1389 components = fModules.getPEIM();\r
1390 if (components != null) {\r
1391 modules = components.getModuleSAList();\r
1392 for (index = 0; index < modules.size(); index ++) {\r
1393 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.PEIM));\r
1394 }\r
878ddf1f 1395 }\r
878ddf1f 1396\r
8840ad58 1397 components = fModules.getDXECORE();\r
1398 if (components != null) {\r
1399 modules = components.getModuleSAList();\r
1400 for (index = 0; index < modules.size(); index ++) {\r
1401 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_CORE));\r
1402 }\r
878ddf1f 1403 }\r
1404\r
8840ad58 1405 components = fModules.getDXEDRIVERS();\r
1406 if (components != null) {\r
1407 modules = components.getModuleSAList();\r
1408 for (index = 0; index < modules.size(); index ++) {\r
1409 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.DXE_DRIVERS));\r
1410 }\r
878ddf1f 1411 }\r
1412\r
8840ad58 1413 components = fModules.getOTHERCOMPONENTS();\r
1414 if (components != null) {\r
1415 modules = components.getModuleSAList();\r
1416 for (index = 0; index < modules.size(); index ++) {\r
1417 allModules.add(new ModuleInfo(modules.get(index), UsageInstance.MODULE_TYPE.OTHER_COMPONENTS));\r
1418 }\r
1419 }\r
1420 \r
1421 return allModules;\r
878ddf1f 1422 }\r
1423\r
1424 /**\r
1425 Create token instance object into memory database, the token information\r
1426 comes for FPD file. Normally, FPD file will contain all token platform \r
1427 informations.\r
878ddf1f 1428 \r
1429 @return FrameworkPlatformDescriptionDocument The FPD document instance for furture usage.\r
1430 \r
1431 @throws EntityException Failed to parse FPD xml file.\r
1432 \r
1433 **/\r
8840ad58 1434 private void createTokenInDBFromFPD() \r
878ddf1f 1435 throws EntityException {\r
8840ad58 1436 int index = 0;\r
1437 int index2 = 0;\r
1438 int pcdIndex = 0;\r
1439 List<PcdBuildData> pcdBuildDataArray = new ArrayList<PcdBuildData>();\r
1440 PcdBuildData pcdBuildData = null;\r
1441 Token token = null;\r
1442 UUID nullUUID = new UUID(0,0);\r
1443 UUID platformTokenSpace= nullUUID;\r
1444 SkuInstance skuInstance = null;\r
1445 int skuIndex = 0;\r
1446 List<ModuleInfo> modules = null;\r
1447 String primaryKey = null;\r
1448 PcdBuildData.SkuData[] skuDataArray = null;\r
1449 String exceptionString = null;\r
1450 UsageInstance usageInstance = null;\r
1451 String primaryKey1 = null;\r
1452 String primaryKey2 = null;\r
1453 boolean isDuplicate = false;\r
1454 java.util.List<java.lang.String> tokenGuidStringArray = null;\r
878ddf1f 1455\r
1456 //\r
8840ad58 1457 // Get all <ModuleSA> from FPD file.\r
878ddf1f 1458 // \r
8840ad58 1459 modules = getComponentsFromFPD();\r
878ddf1f 1460\r
8840ad58 1461 if (modules == null) {\r
1462 throw new EntityException("No modules in FPD file, Please check whether there are elements in <FrameworkModules> in FPD file!");\r
878ddf1f 1463 }\r
1464\r
1465 //\r
8840ad58 1466 // Loop all modules to process <PcdBuildDeclarations> for each module.\r
1467 // \r
1468 for (index = 0; index < modules.size(); index ++) {\r
1469 isDuplicate = false;\r
1470 for (index2 = 0; index2 < index; index2 ++) {\r
1471 //\r
1472 // BUGBUG: For transition schema, we can *not* get module's version from \r
1473 // <ModuleSAs>, It is work around code.\r
1474 // \r
1475 primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).module.getModuleName(), \r
1476 translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()),\r
1477 modules.get(index).module.getPackageName(), \r
1478 translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()), \r
1479 modules.get(index).module.getArch().toString(),\r
1480 null);\r
1481 primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).module.getModuleName(), \r
1482 translateSchemaStringToUUID(modules.get(index2).module.getModuleGuid()), \r
1483 modules.get(index2).module.getPackageName(), \r
1484 translateSchemaStringToUUID(modules.get(index2).module.getPackageGuid()), \r
1485 modules.get(index2).module.getArch().toString(), \r
1486 null);\r
1487 if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
1488 isDuplicate = true;\r
1489 break;\r
1490 }\r
1491 }\r
878ddf1f 1492\r
8840ad58 1493 if (isDuplicate) {\r
1494 continue;\r
1495 }\r
878ddf1f 1496\r
8840ad58 1497 if (modules.get(index).module.getPcdBuildDeclarations() == null) {\r
1498 continue;\r
1499 }\r
1500 pcdBuildDataArray = modules.get(index).module.getPcdBuildDeclarations().getPcdBuildDataList();\r
1501 if (pcdBuildDataArray == null) {\r
1502 continue;\r
1503 }\r
1504 if (pcdBuildDataArray.size() == 0) {\r
1505 continue;\r
1506 }\r
878ddf1f 1507\r
878ddf1f 1508 //\r
8840ad58 1509 // Loop all Pcd entry for a module and add it into memory database.\r
1510 // \r
1511 for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
1512 pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
1513 primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
1514 translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
1515\r
1516\r
1517 if (dbManager.isTokenInDatabase(primaryKey)) {\r
1518 //\r
1519 // If the token is already exist in database, do some necessary checking\r
1520 // and add a usage instance into this token in database\r
1521 // \r
1522 token = dbManager.getTokenByKey(primaryKey);\r
1523\r
878ddf1f 1524 //\r
8840ad58 1525 // Checking for DatumSize\r
1526 // \r
1527 if (token.datumSize != pcdBuildData.getDatumSize()) {\r
1528 exceptionString = String.format("The datum size of PCD entry %s is %d, which is different with %d defined in before!",\r
1529 pcdBuildData.getCName(), pcdBuildData.getDatumSize(), token.datumSize);\r
1530 throw new EntityException(exceptionString);\r
1531 }\r
1532\r
878ddf1f 1533 //\r
8840ad58 1534 // checking for DatumType\r
1535 // \r
1536 if (token.datumType != Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString())) {\r
1537 exceptionString = String.format("The datum type of PCD entry %s is %s, which is different with %s defined in before!",\r
1538 pcdBuildData.getCName(), \r
1539 pcdBuildData.getDatumType().toString(), \r
1540 Token.getStringOfdatumType(token.datumType));\r
1541 throw new EntityException(exceptionString);\r
1542 }\r
1543 } else {\r
1544 //\r
1545 // If the token is not in database, create a new token instance and add\r
1546 // a usage instance into this token in database.\r
1547 // \r
1548 token = new Token(pcdBuildData.getCName(), \r
1549 translateSchemaStringToUUID(pcdBuildData.getTokenSpaceGuid()));\r
1550\r
1551 token.datum = pcdBuildData.getDefaultValue();\r
1552 token.pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
1553 token.datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
1554 token.datumSize = pcdBuildData.getDatumSize();\r
1555 token.skuId = Integer.decode(pcdBuildData.getSkuId());\r
1556\r
1557 if (pcdBuildData.getToken() == null) {\r
1558 exceptionString = String.format("In FPD file, No <TokenNumber> defined for PCD entry %s in module %s",\r
1559 token.cName,\r
1560 modules.get(index).module.getModuleName());\r
1561 throw new EntityException(exceptionString);\r
1562 }\r
1563 token.tokenNumber = Integer.decode(pcdBuildData.getToken().getStringValue());\r
1564\r
1565 if ((token.pcdType == Token.PCD_TYPE.DYNAMIC) ||\r
1566 (token.pcdType == Token.PCD_TYPE.DYNAMIC_EX)) {\r
1567 updateDynamicInformation(modules.get(index).module.getModuleName(), token);\r
1568 }\r
1569\r
1570 dbManager.addTokenToDatabase(primaryKey, token);\r
878ddf1f 1571 }\r
878ddf1f 1572\r
878ddf1f 1573 //\r
8840ad58 1574 // Create an usage instance for this token\r
1575 // \r
1576 usageInstance = new UsageInstance(token, \r
1577 Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()),\r
1578 modules.get(index).module.getModuleName(), \r
1579 translateSchemaStringToUUID(modules.get(index).module.getModuleGuid()),\r
1580 modules.get(index).module.getPackageName(),\r
1581 translateSchemaStringToUUID(modules.get(index).module.getPackageGuid()),\r
1582 modules.get(index).type, \r
1583 Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()),\r
1584 modules.get(index).module.getArch().toString(), \r
1585 null,\r
1586 pcdBuildData.getDefaultValue());\r
1587 token.addUsageInstance(usageInstance);\r
878ddf1f 1588 }\r
878ddf1f 1589 }\r
878ddf1f 1590 }\r
1591\r
1592 /**\r
8840ad58 1593 Update dynamic information for PCD entry.\r
1594 \r
1595 Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in\r
1596 FPD file.\r
1597 \r
1598 @param moduleName\r
1599 @param token\r
1600 \r
1601 @return Token\r
878ddf1f 1602 **/\r
8840ad58 1603 private Token updateDynamicInformation(String moduleName, Token token) \r
878ddf1f 1604 throws EntityException {\r
8840ad58 1605 PcdDynamicBuildDeclarations pcdDynamicBuildDescriptions = null;\r
1606 \r
1607 boolean isFound = false; \r
1608 int index = 0;\r
1609 String primaryKey = null;\r
1610 SkuInstance skuInstance = null;\r
1611 int skuIndex = 0;\r
1612 String exceptionString = null;\r
1613 PcdDynamicBuildDeclarations.PcdBuildData.SkuData[] skuDataArray = null;\r
1614 List<PcdDynamicBuildDeclarations.PcdBuildData> pcdDynamicBuildDataArray = null;\r
878ddf1f 1615\r
3d52de13 1616 //\r
8840ad58 1617 // If FPD document is not be opened, open and initialize it.\r
1618 // \r
1619 if (fpdDocInstance == null) {\r
1620 try {\r
1621 fpdDocInstance = (FrameworkPlatformDescriptionDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
1622 } catch(IOException ioE) {\r
1623 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
1624 } catch(XmlException xmlE) {\r
1625 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
1626 }\r
3d52de13 1627 }\r
878ddf1f 1628\r
8840ad58 1629 pcdDynamicBuildDescriptions = fpdDocInstance.getFrameworkPlatformDescription().getPcdDynamicBuildDeclarations();\r
1630 if (pcdDynamicBuildDescriptions == null) {\r
1631 throw new EntityException(String.format("There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
1632 "PCD entry %s in module %s!",\r
1633 token.cName,\r
1634 moduleName));\r
3d52de13 1635 }\r
8840ad58 1636\r
1637 pcdDynamicBuildDataArray = pcdDynamicBuildDescriptions.getPcdBuildDataList();\r
1638 if (pcdDynamicBuildDataArray == null) {\r
1639 throw new EntityException(String.format("There are no PcdDynamicBuildData in <PcdDynamicBuildDeclaration> section but contains Dynamic type"+\r
1640 "PCD entry %s in module %s.!",\r
1641 token.cName,\r
1642 moduleName));\r
1643 }\r
1644\r
1645 isFound = false;\r
1646 for (index = 0; index < pcdDynamicBuildDataArray.size(); index ++) {\r
1647 if (pcdDynamicBuildDataArray.get(index).getTokenSpaceGuidList().size() != 0) {\r
1648 primaryKey = Token.getPrimaryKeyString(pcdDynamicBuildDataArray.get(index).getCName(), \r
1649 translateSchemaStringToUUID(pcdDynamicBuildDataArray.get(index).getTokenSpaceGuidList().get(0)));\r
1650 } else {\r
1651 primaryKey = Token.getPrimaryKeyString(pcdDynamicBuildDataArray.get(index).getCName(), \r
1652 translateSchemaStringToUUID(null));\r
1653 }\r
1654\r
1655 if (primaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
1656 isFound = true;\r
1657\r
878ddf1f 1658 //\r
8840ad58 1659 // For Hii related value\r
1660 // \r
1661 token.hiiEnabled = pcdDynamicBuildDataArray.get(index).getHiiEnable();\r
1662 if (token.hiiEnabled) {\r
1663 token.variableGuid = Token.getGUIDFromSchemaObject(pcdDynamicBuildDataArray.get(index).getVariableGuid());\r
1664 if (token.variableGuid == null) {\r
1665 throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
1666 "but no <VariableGuid> is found! Please fix the FPD file!",\r
1667 token.cName));\r
878ddf1f 1668\r
8840ad58 1669 }\r
1670 token.variableName = pcdDynamicBuildDataArray.get(index).getVariableName();\r
1671 if (token.variableName == null) {\r
1672 throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
1673 "but no <VariableName> is found! Please fix the FPD file!",\r
1674 token.cName));\r
878ddf1f 1675 }\r
1676\r
8840ad58 1677 if (pcdDynamicBuildDataArray.get(index).getDataOffset() == null) {\r
1678 throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, HiiEnable is true" +\r
1679 "but no <DataOffset> is found! Please fix the FPD file!",\r
1680 token.cName));\r
1681 }\r
1682 token.variableOffset = Integer.decode(pcdDynamicBuildDataArray.get(index).getDataOffset());\r
878ddf1f 1683 }\r
1684\r
878ddf1f 1685 //\r
8840ad58 1686 // For Vpd related value\r
1687 // \r
1688 token.vpdEnabled = pcdDynamicBuildDataArray.get(index).getVpdEnable();\r
1689 if (token.vpdEnabled) {\r
1690 if (pcdDynamicBuildDataArray.get(index).getDataOffset() == null) {\r
1691 throw new EntityException(String.format("In <PcdDynamicBuildDeclarations> for PCD entry %s, VpdEnable is true" +\r
1692 "but no <DataOffset> is found! Please fix the FPD file!",\r
1693 token.cName));\r
1694 }\r
1695 token.vpdOffset = Integer.decode(pcdDynamicBuildDataArray.get(index).getDataOffset());\r
1696 }\r
1697\r
878ddf1f 1698 //\r
8840ad58 1699 // For SkuData\r
1700 // \r
1701 token.skuEnabled = pcdDynamicBuildDataArray.get(index).getSkuEnable();\r
1702 if (token.skuEnabled) {\r
1703 skuDataArray = (PcdDynamicBuildDeclarations.PcdBuildData.SkuData[])pcdDynamicBuildDataArray.get(index).getSkuDataList().toArray();\r
1704 token.maxSkuCount = Integer.decode(pcdDynamicBuildDataArray.get(index).getMaxSku());\r
1705 if (skuDataArray == null) {\r
1706 exceptionString = String.format("In FPD file, the <SkuEnable> is true for PCD entry %s in module %s, But no any sku data.",\r
1707 token.cName, moduleName);\r
1708 throw new EntityException(exceptionString);\r
1709 }\r
1710 if (token.maxSkuCount != pcdDynamicBuildDataArray.get(index).sizeOfSkuDataArray()) {\r
1711 exceptionString = String.format("In FPD file, <MaxSku> is not equal to the size of <SkuDataArray> for PCD entry %s in module %s",\r
1712 token.cName, moduleName);\r
1713 throw new EntityException(exceptionString);\r
1714 }\r
1715\r
1716 for (skuIndex = 0; skuIndex < pcdDynamicBuildDataArray.get(index).sizeOfSkuDataArray(); skuIndex ++) {\r
1717 skuInstance = new SkuInstance(skuDataArray[skuIndex].getId(),\r
1718 skuDataArray[skuIndex].getValue());\r
1719 token.skuData.add(skuInstance);\r
878ddf1f 1720 }\r
1721 }\r
8840ad58 1722 break;\r
878ddf1f 1723 }\r
1724 }\r
8840ad58 1725 if (!isFound) {\r
1726 exceptionString = String.format("In FPD file, No dynamic PCD data for PCD entry %s in module %s",\r
1727 token.cName,\r
1728 moduleName);\r
1729 throw new EntityException(exceptionString);\r
1730 }\r
1731\r
1732 return token;\r
1733 }\r
1734\r
1735 /**\r
1736 Translate the schema string to UUID instance.\r
1737 \r
1738 In schema, the string of UUID is defined as following two types string:\r
1739 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
1740 )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
1741 \r
1742 2) GuidNamingConvention: pattern =\r
1743 [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
1744 \r
1745 This function will convert string and create uuid instance.\r
1746 \r
1747 @param uuidString UUID string in XML file\r
1748 \r
1749 @return UUID UUID instance\r
1750 **/\r
1751 private UUID translateSchemaStringToUUID(String uuidString) \r
1752 throws EntityException {\r
1753 String temp;\r
1754 String[] splitStringArray;\r
1755 int index;\r
1756 int chIndex;\r
1757 int chLen;\r
1758\r
1759 if (uuidString == null) {\r
1760 return null;\r
1761 }\r
1762\r
1763 if (uuidString.length() == 0) {\r
1764 return null;\r
1765 }\r
1766\r
1767 //\r
1768 // If the UUID schema string is GuidArrayType type then need translate \r
1769 // to GuidNamingConvention type at first.\r
1770 // \r
1771 if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
1772 splitStringArray = uuidString.split("," );\r
1773 if (splitStringArray.length != 11) {\r
1774 throw new EntityException ("Wrong format for UUID string: " + uuidString);\r
1775 }\r
1776\r
1777 //\r
1778 // Remove blank space from these string and remove header string "0x"\r
1779 // \r
1780 for (index = 0; index < 11; index ++) {\r
1781 splitStringArray[index] = splitStringArray[index].trim();\r
1782 splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
1783 }\r
1784\r
1785 //\r
1786 // Add heading '0' to normalize the string length\r
1787 // \r
1788 for (index = 3; index < 11; index ++) {\r
1789 chLen = splitStringArray[index].length();\r
1790 for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
1791 splitStringArray[index] = "0" + splitStringArray[index];\r
1792 }\r
1793 }\r
1794\r
1795 //\r
1796 // construct the final GuidNamingConvention string\r
1797 // \r
1798 temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
1799 splitStringArray[0],\r
1800 splitStringArray[1],\r
1801 splitStringArray[2],\r
1802 splitStringArray[3],\r
1803 splitStringArray[4],\r
1804 splitStringArray[5],\r
1805 splitStringArray[6],\r
1806 splitStringArray[7],\r
1807 splitStringArray[8],\r
1808 splitStringArray[9],\r
1809 splitStringArray[10]);\r
1810 uuidString = temp;\r
1811 }\r
1812\r
1813 return UUID.fromString(uuidString);\r
878ddf1f 1814 }\r
1815\r
1816 /**\r
1817 check parameter for this action.\r
1818 \r
1819 @throws EntityException Bad parameter.\r
1820 **/\r
1821 private void checkParameter() throws EntityException {\r
1822 File file = null;\r
1823\r
1824 if((fpdFilePath == null) ||(workspacePath == null)) {\r
1825 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
1826 }\r
1827\r
1828 if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
1829 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
1830 }\r
1831\r
1832 file = new File(workspacePath);\r
1833 if(!file.exists()) {\r
1834 throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
1835 }\r
1836\r
1837 file = new File(fpdFilePath);\r
1838\r
1839 if(!file.exists()) {\r
1840 throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
1841 }\r
1842 }\r
1843\r
1844 /**\r
1845 Test case function\r
1846\r
1847 @param argv parameter from command line\r
1848 **/\r
1849 public static void main(String argv[]) throws EntityException {\r
1850 CollectPCDAction ca = new CollectPCDAction();\r
8840ad58 1851 ca.setWorkspacePath("M:/ForPcd/edk2");\r
1852 ca.setFPDFilePath("M:/ForPcd/edk2/EdkNt32Pkg/Nt32.fpd");\r
878ddf1f 1853 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
1854 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
8840ad58 1855 "M:/ForPcd/edk2");\r
878ddf1f 1856 ca.execute();\r
1857 }\r
1858}\r