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