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