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