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