BaseTools: Fixed the issue of Multiple Skus are always disables
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenPcdDb.py
CommitLineData
e8a47801
LG
1## @file\r
2# Routines for generating Pcd Database\r
3#\r
763e8edf 4# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
e8a47801
LG
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13from StringIO import StringIO\r
14from Common.Misc import *\r
15from Common.String import StringToArray\r
16from struct import pack\r
82a6a960
BF
17from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER\r
18from ValidCheckingInfoObject import VAR_CHECK_PCD_VARIABLE_TAB\r
19from ValidCheckingInfoObject import VAR_VALID_OBJECT_FACTORY\r
20from Common.VariableAttributes import VariableAttributes\r
2b8a6c44
LG
21import copy\r
22from struct import unpack\r
e8a47801 23\r
2b8a6c44 24DATABASE_VERSION = 7\r
e8a47801
LG
25\r
26gPcdDatabaseAutoGenC = TemplateString("""\r
27//\r
28// External PCD database debug information\r
29//\r
30#if 0\r
31${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = {\r
a01f68bd
YZ
32 /* SkuIdTable */\r
33 { ${BEGIN}${SKUID_VALUE}, ${END} },\r
e8a47801
LG
34${BEGIN} { ${INIT_VALUE_UINT64} }, /* ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}] */\r
35${END}\r
36${BEGIN} ${VARDEF_VALUE_UINT64}, /* ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64} */\r
37${END}\r
38${BEGIN} { ${INIT_VALUE_UINT32} }, /* ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}] */\r
39${END}\r
40${BEGIN} ${VARDEF_VALUE_UINT32}, /* ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32} */\r
41${END}\r
42 /* VPD */\r
43${BEGIN} { ${VPD_HEAD_VALUE} }, /* ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}] */\r
44${END}\r
45 /* ExMapTable */\r
46 {\r
47${BEGIN} { ${EXMAPPING_TABLE_EXTOKEN}, ${EXMAPPING_TABLE_LOCAL_TOKEN}, ${EXMAPPING_TABLE_GUID_INDEX} },\r
48${END}\r
49 },\r
50 /* LocalTokenNumberTable */\r
51 {\r
52${BEGIN} offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}${VARDEF_HEADER}) | ${TOKEN_TYPE},\r
53${END}\r
54 },\r
55 /* GuidTable */\r
56 {\r
57${BEGIN} ${GUID_STRUCTURE},\r
58${END}\r
59 },\r
60${BEGIN} { ${STRING_HEAD_VALUE} }, /* ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}] */\r
61${END}\r
62${BEGIN} /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}] */\r
63 {\r
64 ${VARIABLE_HEAD_VALUE}\r
65 },\r
66${END}\r
67/* SkuHead */\r
68 {\r
69 ${BEGIN} offsetof (${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}${VARDEF_HEADER}) | ${TOKEN_TYPE}, /* */\r
70 offsetof (${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.SkuHead) /* */\r
71 ${END}\r
72 },\r
73 /* StringTable */\r
74${BEGIN} ${STRING_TABLE_VALUE}, /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */\r
75${END}\r
76 /* SizeTable */\r
77 {\r
78${BEGIN} ${SIZE_TABLE_MAXIMUM_LENGTH}, ${SIZE_TABLE_CURRENT_LENGTH}, /* ${SIZE_TABLE_CNAME}_${SIZE_TABLE_GUID} */\r
79${END}\r
80 },\r
81${BEGIN} { ${INIT_VALUE_UINT16} }, /* ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}] */\r
82${END}\r
83${BEGIN} ${VARDEF_VALUE_UINT16}, /* ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16} */\r
84${END}\r
85${BEGIN} { ${INIT_VALUE_UINT8} }, /* ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}] */\r
86${END}\r
87${BEGIN} ${VARDEF_VALUE_UINT8}, /* ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8} */\r
88${END}\r
89${BEGIN} { ${INIT_VALUE_BOOLEAN} }, /* ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}] */\r
90${END}\r
91${BEGIN} ${VARDEF_VALUE_BOOLEAN}, /* ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN} */\r
92${END}\r
e8a47801
LG
93 ${SYSTEM_SKU_ID_VALUE}\r
94};\r
95#endif\r
96""")\r
97\r
98## Mapping between PCD driver type and EFI phase\r
99gPcdPhaseMap = {\r
100 "PEI_PCD_DRIVER" : "PEI",\r
101 "DXE_PCD_DRIVER" : "DXE"\r
102}\r
103\r
104gPcdDatabaseAutoGenH = TemplateString("""\r
105#define PCD_${PHASE}_SERVICE_DRIVER_VERSION ${SERVICE_DRIVER_VERSION}\r
106\r
107//\r
108// External PCD database debug information\r
109//\r
110#if 0\r
111#define ${PHASE}_GUID_TABLE_SIZE ${GUID_TABLE_SIZE}\r
112#define ${PHASE}_STRING_TABLE_SIZE ${STRING_TABLE_SIZE}\r
113#define ${PHASE}_SKUID_TABLE_SIZE ${SKUID_TABLE_SIZE}\r
114#define ${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE ${LOCAL_TOKEN_NUMBER_TABLE_SIZE}\r
115#define ${PHASE}_LOCAL_TOKEN_NUMBER ${LOCAL_TOKEN_NUMBER}\r
116#define ${PHASE}_EXMAPPING_TABLE_SIZE ${EXMAPPING_TABLE_SIZE}\r
117#define ${PHASE}_EX_TOKEN_NUMBER ${EX_TOKEN_NUMBER}\r
118#define ${PHASE}_SIZE_TABLE_SIZE ${SIZE_TABLE_SIZE}\r
e8a47801
LG
119#define ${PHASE}_GUID_TABLE_EMPTY ${GUID_TABLE_EMPTY}\r
120#define ${PHASE}_STRING_TABLE_EMPTY ${STRING_TABLE_EMPTY}\r
121#define ${PHASE}_SKUID_TABLE_EMPTY ${SKUID_TABLE_EMPTY}\r
122#define ${PHASE}_DATABASE_EMPTY ${DATABASE_EMPTY}\r
123#define ${PHASE}_EXMAP_TABLE_EMPTY ${EXMAP_TABLE_EMPTY}\r
124\r
125typedef struct {\r
a01f68bd 126 UINT64 SkuIdTable[${PHASE}_SKUID_TABLE_SIZE];\r
e8a47801
LG
127${BEGIN} UINT64 ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}];\r
128${END}\r
129${BEGIN} UINT64 ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64};\r
130${END}\r
131${BEGIN} UINT32 ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}];\r
132${END}\r
133${BEGIN} UINT32 ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32};\r
134${END}\r
135${BEGIN} VPD_HEAD ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}];\r
136${END}\r
137 DYNAMICEX_MAPPING ExMapTable[${PHASE}_EXMAPPING_TABLE_SIZE];\r
138 UINT32 LocalTokenNumberTable[${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r
139 GUID GuidTable[${PHASE}_GUID_TABLE_SIZE];\r
140${BEGIN} STRING_HEAD ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}];\r
141${END}\r
142${BEGIN} VARIABLE_HEAD ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}];\r
e8a47801
LG
143${BEGIN} UINT8 StringTable${STRING_TABLE_INDEX}[${STRING_TABLE_LENGTH}]; /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */\r
144${END}\r
145 SIZE_INFO SizeTable[${PHASE}_SIZE_TABLE_SIZE];\r
146${BEGIN} UINT16 ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}];\r
147${END}\r
148${BEGIN} UINT16 ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16};\r
149${END}\r
150${BEGIN} UINT8 ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}];\r
151${END}\r
152${BEGIN} UINT8 ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8};\r
153${END}\r
154${BEGIN} BOOLEAN ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}];\r
155${END}\r
156${BEGIN} BOOLEAN ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN};\r
157${END}\r
e8a47801
LG
158${SYSTEM_SKU_ID}\r
159} ${PHASE}_PCD_DATABASE_INIT;\r
160\r
161typedef struct {\r
162${PCD_DATABASE_UNINIT_EMPTY}\r
163${BEGIN} UINT64 ${UNINIT_CNAME_DECL_UINT64}_${UNINIT_GUID_DECL_UINT64}[${UNINIT_NUMSKUS_DECL_UINT64}];\r
164${END}\r
165${BEGIN} UINT32 ${UNINIT_CNAME_DECL_UINT32}_${UNINIT_GUID_DECL_UINT32}[${UNINIT_NUMSKUS_DECL_UINT32}];\r
166${END}\r
167${BEGIN} UINT16 ${UNINIT_CNAME_DECL_UINT16}_${UNINIT_GUID_DECL_UINT16}[${UNINIT_NUMSKUS_DECL_UINT16}];\r
168${END}\r
169${BEGIN} UINT8 ${UNINIT_CNAME_DECL_UINT8}_${UNINIT_GUID_DECL_UINT8}[${UNINIT_NUMSKUS_DECL_UINT8}];\r
170${END}\r
171${BEGIN} BOOLEAN ${UNINIT_CNAME_DECL_BOOLEAN}_${UNINIT_GUID_DECL_BOOLEAN}[${UNINIT_NUMSKUS_DECL_BOOLEAN}];\r
172${END}\r
173} ${PHASE}_PCD_DATABASE_UNINIT;\r
174\r
175typedef struct {\r
176 //GUID Signature; // PcdDataBaseGuid\r
a01f68bd 177 //UINT32 BuildVersion;\r
e8a47801 178 //UINT32 Length;\r
7e6e459a
LG
179 //SKU_ID SystemSkuId; // Current SkuId value.\r
180 //UINT32 LengthForAllSkus; // Length of all SKU PCD DB\r
e8a47801
LG
181 //UINT32 UninitDataBaseSize;// Total size for PCD those default value with 0.\r
182 //TABLE_OFFSET LocalTokenNumberTableOffset;\r
183 //TABLE_OFFSET ExMapTableOffset;\r
184 //TABLE_OFFSET GuidTableOffset; \r
185 //TABLE_OFFSET StringTableOffset;\r
186 //TABLE_OFFSET SizeTableOffset;\r
187 //TABLE_OFFSET SkuIdTableOffset; \r
a01f68bd 188 //TABLE_OFFSET PcdNameTableOffset;\r
e8a47801
LG
189 //UINT16 LocalTokenCount; // LOCAL_TOKEN_NUMBER for all\r
190 //UINT16 ExTokenCount; // EX_TOKEN_NUMBER for DynamicEx\r
191 //UINT16 GuidTableCount; // The Number of Guid in GuidTable\r
7e6e459a 192 //UINT8 Pad[6];\r
e8a47801
LG
193 ${PHASE}_PCD_DATABASE_INIT Init;\r
194 ${PHASE}_PCD_DATABASE_UNINIT Uninit;\r
195} ${PHASE}_PCD_DATABASE;\r
196\r
197#define ${PHASE}_NEX_TOKEN_NUMBER (${PHASE}_LOCAL_TOKEN_NUMBER - ${PHASE}_EX_TOKEN_NUMBER)\r
198#endif\r
199""")\r
200\r
201\r
202gEmptyPcdDatabaseAutoGenC = TemplateString("""\r
203//\r
204// External PCD database debug information\r
205//\r
206#if 0\r
207${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = {\r
a01f68bd
YZ
208 /* SkuIdTable */\r
209 { 0 },\r
e8a47801
LG
210 /* ExMapTable */\r
211 {\r
212 {0, 0, 0}\r
213 },\r
214 /* LocalTokenNumberTable */\r
215 {\r
216 0\r
217 },\r
218 /* GuidTable */\r
219 {\r
220 {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}\r
221 },\r
222 /* StringTable */\r
223 { 0 },\r
224 /* SkuHead */\r
225 {\r
226 0, 0\r
227 },\r
228 /* SizeTable */\r
229 {\r
230 0, 0\r
231 },\r
e8a47801
LG
232 ${SYSTEM_SKU_ID_VALUE}\r
233};\r
234#endif\r
235""")\r
236\r
237## PackGuid\r
238#\r
239# Pack the GUID value in C structure format into data array\r
240#\r
241# @param GuidStructureValue: The GUID value in C structure format\r
242#\r
243# @retval Buffer: a data array contains the Guid\r
244#\r
245def PackGuid(GuidStructureValue):\r
246 GuidString = GuidStructureStringToGuidString(GuidStructureValue)\r
247 Guid = GuidString.split('-')\r
248 Buffer = pack('=LHHBBBBBBBB', \r
249 int(Guid[0], 16), \r
250 int(Guid[1], 16), \r
251 int(Guid[2], 16), \r
252 int(Guid[3][-4:-2], 16), \r
253 int(Guid[3][-2:], 16),\r
254 int(Guid[4][-12:-10], 16),\r
255 int(Guid[4][-10:-8], 16),\r
256 int(Guid[4][-8:-6], 16),\r
257 int(Guid[4][-6:-4], 16),\r
258 int(Guid[4][-4:-2], 16),\r
259 int(Guid[4][-2:], 16)\r
260 )\r
261 return Buffer\r
262\r
263def toHex(s):\r
264 lst = []\r
265 for ch in s:\r
266 hv = hex(ord(ch)).replace('0x', ' ')\r
267 if len(hv) == 1:\r
268 hv = '0'+hv\r
269 lst.append(hv)\r
270 if lst:\r
271 return reduce(lambda x,y:x+y, lst)\r
272 else:\r
273 return 'empty'\r
274## DbItemList\r
275#\r
276# The class holds the Pcd database items. ItemSize if not zero should match the item datum type in the C structure. \r
277# When the structure is changed, remember to check the ItemSize and the related PackStr in PackData()\r
278# RawDataList is the RawData that may need some kind of calculation or transformation, \r
279# the DataList corresponds to the data that need to be written to database. If DataList is not present, then RawDataList\r
280# will be written to the database. \r
281#\r
282class DbItemList:\r
283 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
284 if DataList is None:\r
285 DataList = []\r
286 if RawDataList is None:\r
287 RawDataList = []\r
288 self.ItemSize = ItemSize\r
289 self.DataList = DataList\r
290 self.RawDataList = RawDataList\r
291 self.ListSize = 0\r
292\r
293 def GetInterOffset(self, Index):\r
294 Offset = 0\r
295 if self.ItemSize == 0:\r
296 #\r
297 # Variable length, need to calculate one by one\r
298 #\r
299 assert(Index < len(self.RawDataList))\r
300 for ItemIndex in xrange(Index):\r
301 Offset += len(self.RawDataList[ItemIndex])\r
302 else:\r
303 for Datas in self.RawDataList:\r
304 Offset = self.ItemSize * Index\r
305\r
306 return Offset\r
307\r
308 def GetListSize(self):\r
309 if self.ListSize:\r
310 return self.ListSize\r
311 if len(self.RawDataList) == 0:\r
312 self.ListSize = 0\r
313 return self.ListSize\r
314 if self.ItemSize == 0:\r
315 self.ListSize = self.GetInterOffset(len(self.RawDataList) - 1) + len(self.RawDataList[len(self.RawDataList)-1])\r
316 else:\r
317 self.ListSize = self.ItemSize * len(self.RawDataList)\r
318 return self.ListSize\r
319\r
320 def PackData(self):\r
321 if self.ItemSize == 8:\r
322 PackStr = "=Q"\r
323 elif self.ItemSize == 4:\r
324 PackStr = "=L"\r
325 elif self.ItemSize == 2:\r
326 PackStr = "=H"\r
327 elif self.ItemSize == 1:\r
328 PackStr = "=B"\r
329 elif self.ItemSize == 0:\r
330 PackStr = "=B"\r
331 elif self.ItemSize == 16:\r
332 # pack Guid\r
333 PackStr = ''\r
334 else:\r
335 # should not reach here\r
336 assert(False)\r
337\r
338 Buffer = ''\r
339 for Datas in self.RawDataList:\r
340 if type(Datas) in (list, tuple):\r
341 for Data in Datas:\r
342 if PackStr:\r
343 Buffer += pack(PackStr, GetIntegerValue(Data))\r
344 else:\r
345 Buffer += PackGuid(Data)\r
346 else:\r
347 if PackStr:\r
348 Buffer += pack(PackStr, GetIntegerValue(Datas))\r
349 else:\r
350 Buffer += PackGuid(Datas)\r
351\r
352 return Buffer\r
353\r
354## DbExMapTblItemList\r
355#\r
356# The class holds the ExMap table \r
357#\r
358class DbExMapTblItemList (DbItemList):\r
359 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
360 if DataList is None:\r
361 DataList = []\r
362 if RawDataList is None:\r
363 RawDataList = []\r
364 DbItemList.__init__(self, ItemSize, DataList, RawDataList)\r
365 def PackData(self):\r
366 Buffer = ''\r
367 PackStr = "=LHH"\r
368 for Datas in self.RawDataList:\r
369 Buffer += pack(PackStr, \r
370 GetIntegerValue(Datas[0]),\r
371 GetIntegerValue(Datas[1]),\r
372 GetIntegerValue(Datas[2])) \r
373 return Buffer\r
374\r
375## DbComItemList\r
376#\r
377# The DbComItemList is a special kind of DbItemList in case that the size of the List can not be computed by the \r
378# ItemSize multiply the ItemCount.\r
379#\r
380class DbComItemList (DbItemList):\r
381 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
382 if DataList is None:\r
383 DataList = []\r
384 if RawDataList is None:\r
385 RawDataList = []\r
386 DbItemList.__init__(self, ItemSize, DataList, RawDataList)\r
387 def GetInterOffset(self, Index):\r
388 Offset = 0\r
389 if self.ItemSize == 0:\r
390 #\r
391 # Variable length, need to calculte one by one\r
392 # The only variable table is stringtable, it is not Composite item, should not reach here\r
393 #\r
394 assert(False)\r
395 else:\r
396 assert(Index < len(self.RawDataList))\r
397 for ItemIndex in xrange(Index):\r
398 Offset += len(self.RawDataList[ItemIndex]) * self.ItemSize \r
399\r
400 return Offset\r
401\r
402 def GetListSize(self):\r
403 if self.ListSize:\r
404 return self.ListSize\r
405 if self.ItemSize == 0:\r
406 assert(False)\r
407 else:\r
408 if len(self.RawDataList) == 0:\r
409 self.ListSize = 0\r
410 else:\r
411 self.ListSize = self.GetInterOffset(len(self.RawDataList) - 1) + len(self.RawDataList[len(self.RawDataList)-1]) * self.ItemSize\r
412\r
413 return self.ListSize\r
414\r
415 def PackData(self):\r
416 if self.ItemSize == 8:\r
417 PackStr = "=Q"\r
418 elif self.ItemSize == 4:\r
419 PackStr = "=L"\r
420 elif self.ItemSize == 2:\r
421 PackStr = "=H"\r
422 elif self.ItemSize == 1:\r
423 PackStr = "=B"\r
424 elif self.ItemSize == 0:\r
425 PackStr = "=B"\r
426 else:\r
427 assert(False)\r
428\r
429 Buffer = ''\r
430 for DataList in self.RawDataList:\r
431 for Data in DataList:\r
432 if type(Data) in (list, tuple):\r
433 for SingleData in Data:\r
434 Buffer += pack(PackStr, GetIntegerValue(SingleData))\r
435 else:\r
436 Buffer += pack(PackStr, GetIntegerValue(Data))\r
437 \r
438 return Buffer\r
439\r
440## DbVariableTableItemList\r
441#\r
442# The class holds the Variable header value table \r
443#\r
444class DbVariableTableItemList (DbComItemList):\r
445 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
446 if DataList is None:\r
447 DataList = []\r
448 if RawDataList is None:\r
449 RawDataList = []\r
450 DbComItemList.__init__(self, ItemSize, DataList, RawDataList)\r
451 def PackData(self):\r
82a6a960 452 PackStr = "=LLHHLHH"\r
e8a47801
LG
453 Buffer = ''\r
454 for DataList in self.RawDataList:\r
455 for Data in DataList:\r
456 Buffer += pack(PackStr, \r
457 GetIntegerValue(Data[0]),\r
458 GetIntegerValue(Data[1]),\r
459 GetIntegerValue(Data[2]),\r
82a6a960
BF
460 GetIntegerValue(Data[3]),\r
461 GetIntegerValue(Data[4]),\r
462 GetIntegerValue(Data[5]),\r
463 GetIntegerValue(0))\r
e8a47801
LG
464 return Buffer\r
465\r
466class DbStringHeadTableItemList(DbItemList):\r
467 def __init__(self,ItemSize,DataList=None,RawDataList=None):\r
468 if DataList is None:\r
469 DataList = []\r
470 if RawDataList is None:\r
471 RawDataList = [] \r
472 DbItemList.__init__(self, ItemSize, DataList, RawDataList)\r
473 \r
474 def GetInterOffset(self, Index):\r
475 Offset = 0\r
476 if self.ItemSize == 0:\r
477 #\r
478 # Variable length, need to calculate one by one\r
479 #\r
480 assert(Index < len(self.RawDataList))\r
481 for ItemIndex in xrange(Index):\r
482 Offset += len(self.RawDataList[ItemIndex])\r
483 else:\r
484 for innerIndex in range(Index):\r
485 if type(self.RawDataList[innerIndex]) in (list, tuple):\r
486 Offset += len(self.RawDataList[innerIndex]) * self.ItemSize\r
487 else:\r
488 Offset += self.ItemSize\r
489\r
490 return Offset\r
491\r
492 def GetListSize(self):\r
493 if self.ListSize:\r
494 return self.ListSize\r
495 if len(self.RawDataList) == 0:\r
496 self.ListSize = 0\r
497 return self.ListSize\r
498 if self.ItemSize == 0:\r
499 self.ListSize = self.GetInterOffset(len(self.RawDataList) - 1) + len(self.RawDataList[len(self.RawDataList)-1])\r
500 else:\r
501 for Datas in self.RawDataList:\r
502 if type(Datas) in (list, tuple):\r
503 self.ListSize += len(Datas) * self.ItemSize\r
504 else:\r
505 self.ListSize += self.ItemSize\r
506 return self.ListSize \r
507\r
508## DbSkuHeadTableItemList\r
509#\r
510# The class holds the Sku header value table \r
511#\r
512class DbSkuHeadTableItemList (DbItemList):\r
513 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
514 if DataList is None:\r
515 DataList = []\r
516 if RawDataList is None:\r
517 RawDataList = [] \r
518 DbItemList.__init__(self, ItemSize, DataList, RawDataList)\r
519 def PackData(self):\r
520 PackStr = "=LL"\r
521 Buffer = ''\r
522 for Data in self.RawDataList:\r
523 Buffer += pack(PackStr, \r
524 GetIntegerValue(Data[0]),\r
525 GetIntegerValue(Data[1]))\r
526 return Buffer\r
527\r
528## DbSizeTableItemList\r
529#\r
530# The class holds the size table \r
531#\r
532class DbSizeTableItemList (DbItemList):\r
533 def __init__(self, ItemSize, DataList=None, RawDataList=None):\r
534 if DataList is None:\r
535 DataList = []\r
536 if RawDataList is None:\r
537 RawDataList = [] \r
538 DbItemList.__init__(self, ItemSize, DataList, RawDataList)\r
2bc3256c
LG
539 def GetListSize(self):\r
540 length = 0\r
541 for Data in self.RawDataList:\r
542 length += (1 + len(Data[1]))\r
543 return length * self.ItemSize\r
e8a47801 544 def PackData(self):\r
2bc3256c 545 PackStr = "=H"\r
e8a47801
LG
546 Buffer = ''\r
547 for Data in self.RawDataList:\r
548 Buffer += pack(PackStr, \r
2bc3256c
LG
549 GetIntegerValue(Data[0]))\r
550 for subData in Data[1]:\r
551 Buffer += pack(PackStr, \r
552 GetIntegerValue(subData))\r
e8a47801
LG
553 return Buffer\r
554\r
555## DbStringItemList\r
556#\r
557# The class holds the string table \r
558#\r
559class DbStringItemList (DbComItemList):\r
560 def __init__(self, ItemSize, DataList=None, RawDataList=None, LenList=None):\r
561 if DataList is None:\r
562 DataList = []\r
563 if RawDataList is None:\r
564 RawDataList = []\r
565 if LenList is None:\r
566 LenList = []\r
567 \r
568 assert(len(RawDataList) == len(LenList))\r
569 DataList = []\r
570 # adjust DataList according to the LenList\r
571 for Index in xrange(len(RawDataList)):\r
572 Len = LenList[Index]\r
573 RawDatas = RawDataList[Index]\r
574 assert(Len >= len(RawDatas))\r
575 ActualDatas = []\r
576 for i in xrange(len(RawDatas)):\r
577 ActualDatas.append(RawDatas[i])\r
578 for i in xrange(len(RawDatas), Len):\r
579 ActualDatas.append(0)\r
580 DataList.append(ActualDatas)\r
581 self.LenList = LenList\r
582 DbComItemList.__init__(self, ItemSize, DataList, RawDataList)\r
583 def GetInterOffset(self, Index):\r
584 Offset = 0\r
585\r
586 assert(Index < len(self.LenList))\r
587 for ItemIndex in xrange(Index):\r
588 Offset += self.LenList[ItemIndex]\r
589\r
590 return Offset\r
591\r
592 def GetListSize(self):\r
593 if self.ListSize:\r
594 return self.ListSize\r
595\r
596 if len(self.LenList) == 0:\r
597 self.ListSize = 0\r
598 else:\r
599 self.ListSize = self.GetInterOffset(len(self.LenList) - 1) + self.LenList[len(self.LenList)-1]\r
600\r
601 return self.ListSize\r
602\r
603 def PackData(self):\r
604 self.RawDataList = self.DataList\r
605 return DbComItemList.PackData(self)\r
606\r
607\r
608\r
609## Find the index in two list where the item matches the key separately\r
610#\r
611# @param Key1 The key used to search the List1\r
612# @param List1 The list that Key1 will be searched\r
613# @param Key2 The key used to search the List2\r
614# @param List2 The list that Key2 will be searched\r
615#\r
616# @retval Index The position inside the list where list1[Index] == Key1 and list2[Index] == Key2\r
617#\r
618def GetMatchedIndex(Key1, List1, Key2, List2):\r
619 StartPos = 0\r
620 while StartPos < len(List1):\r
621 Index = List1.index(Key1, StartPos)\r
622 if List2[Index] == Key2:\r
623 return Index\r
624 else:\r
625 StartPos = Index + 1\r
626 \r
627 return -1\r
628\r
629\r
e8a47801
LG
630## convert StringArray like {0x36, 0x00, 0x34, 0x00, 0x21, 0x00, 0x36, 0x00, 0x34, 0x00, 0x00, 0x00}\r
631# to List like [0x36, 0x00, 0x34, 0x00, 0x21, 0x00, 0x36, 0x00, 0x34, 0x00, 0x00, 0x00]\r
632#\r
633# @param StringArray A string array like {0x36, 0x00, 0x34, 0x00, 0x21, 0x00, 0x36, 0x00, 0x34, 0x00, 0x00, 0x00}\r
634# \r
635# @retval A list object of integer items\r
636#\r
637def StringArrayToList(StringArray):\r
638 StringArray = StringArray[1:-1]\r
639 StringArray = '[' + StringArray + ']'\r
640 return eval(StringArray)\r
641\r
642\r
643## Convert TokenType String like "PCD_DATUM_TYPE_UINT32 | PCD_TYPE_HII" to TokenType value\r
644#\r
645# @param TokenType A TokenType string like "PCD_DATUM_TYPE_UINT32 | PCD_TYPE_HII"\r
646# \r
647# @retval A integer representation of the TokenType\r
648#\r
649def GetTokenTypeValue(TokenType):\r
650 TokenTypeDict = {\r
651 "PCD_TYPE_SHIFT":28,\r
652 "PCD_TYPE_DATA":(0x0 << 28),\r
653 "PCD_TYPE_HII":(0x8 << 28),\r
654 "PCD_TYPE_VPD":(0x4 << 28),\r
2b8a6c44 655# "PCD_TYPE_SKU_ENABLED":(0x2 << 28),\r
e8a47801
LG
656 "PCD_TYPE_STRING":(0x1 << 28),\r
657\r
658 "PCD_DATUM_TYPE_SHIFT":24,\r
659 "PCD_DATUM_TYPE_POINTER":(0x0 << 24),\r
660 "PCD_DATUM_TYPE_UINT8":(0x1 << 24),\r
661 "PCD_DATUM_TYPE_UINT16":(0x2 << 24),\r
662 "PCD_DATUM_TYPE_UINT32":(0x4 << 24),\r
663 "PCD_DATUM_TYPE_UINT64":(0x8 << 24),\r
664\r
665 "PCD_DATUM_TYPE_SHIFT2":20,\r
666 "PCD_DATUM_TYPE_UINT8_BOOLEAN":(0x1 << 20 | 0x1 << 24),\r
667 }\r
668 return eval(TokenType, TokenTypeDict)\r
669\r
670## construct the external Pcd database using data from Dict\r
671#\r
672# @param Dict A dictionary contains Pcd related tables\r
673# \r
674# @retval Buffer A byte stream of the Pcd database\r
675#\r
676def BuildExDataBase(Dict):\r
677 # init Db items\r
678 InitValueUint64 = Dict['INIT_DB_VALUE_UINT64']\r
679 DbInitValueUint64 = DbComItemList(8, RawDataList = InitValueUint64)\r
680 VardefValueUint64 = Dict['VARDEF_DB_VALUE_UINT64']\r
681 DbVardefValueUint64 = DbItemList(8, RawDataList = VardefValueUint64)\r
682 InitValueUint32 = Dict['INIT_DB_VALUE_UINT32']\r
683 DbInitValueUint32 = DbComItemList(4, RawDataList = InitValueUint32)\r
684 VardefValueUint32 = Dict['VARDEF_DB_VALUE_UINT32']\r
685 DbVardefValueUint32 = DbItemList(4, RawDataList = VardefValueUint32)\r
686 VpdHeadValue = Dict['VPD_DB_VALUE']\r
687 DbVpdHeadValue = DbComItemList(4, RawDataList = VpdHeadValue)\r
688 ExMapTable = zip(Dict['EXMAPPING_TABLE_EXTOKEN'], Dict['EXMAPPING_TABLE_LOCAL_TOKEN'], Dict['EXMAPPING_TABLE_GUID_INDEX'])\r
689 DbExMapTable = DbExMapTblItemList(8, RawDataList = ExMapTable)\r
690 LocalTokenNumberTable = Dict['LOCAL_TOKEN_NUMBER_DB_VALUE']\r
691 DbLocalTokenNumberTable = DbItemList(4, RawDataList = LocalTokenNumberTable)\r
692 GuidTable = Dict['GUID_STRUCTURE']\r
693 DbGuidTable = DbItemList(16, RawDataList = GuidTable)\r
694 StringHeadValue = Dict['STRING_DB_VALUE']\r
695 # DbItemList to DbStringHeadTableItemList\r
696 DbStringHeadValue = DbStringHeadTableItemList(4, RawDataList = StringHeadValue)\r
697 VariableTable = Dict['VARIABLE_DB_VALUE']\r
82a6a960 698 DbVariableTable = DbVariableTableItemList(20, RawDataList = VariableTable)\r
e8a47801 699 NumberOfSkuEnabledPcd = GetIntegerValue(Dict['SKU_HEAD_SIZE'])\r
2b8a6c44 700\r
e8a47801
LG
701 Dict['STRING_TABLE_DB_VALUE'] = [StringArrayToList(x) for x in Dict['STRING_TABLE_VALUE']]\r
702 \r
703 StringTableValue = Dict['STRING_TABLE_DB_VALUE']\r
704 # when calcute the offset, should use StringTableLen instead of StringTableValue, as string maxium len may be different with actual len\r
705 StringTableLen = Dict['STRING_TABLE_LENGTH']\r
706 DbStringTableLen = DbStringItemList(0, RawDataList = StringTableValue, LenList = StringTableLen)\r
707\r
708 \r
709 PcdTokenTable = Dict['PCD_TOKENSPACE']\r
710 PcdTokenLen = Dict['PCD_TOKENSPACE_LENGTH']\r
711 PcdTokenTableValue = [StringArrayToList(x) for x in Dict['PCD_TOKENSPACE']]\r
712 DbPcdTokenTable = DbStringItemList(0, RawDataList = PcdTokenTableValue, LenList = PcdTokenLen)\r
713 \r
714 PcdCNameTable = Dict['PCD_CNAME']\r
715 PcdCNameLen = Dict['PCD_CNAME_LENGTH']\r
716 PcdCNameTableValue = [StringArrayToList(x) for x in Dict['PCD_CNAME']]\r
717 DbPcdCNameTable = DbStringItemList(0, RawDataList = PcdCNameTableValue, LenList = PcdCNameLen)\r
718 \r
719 PcdNameOffsetTable = Dict['PCD_NAME_OFFSET']\r
720 DbPcdNameOffsetTable = DbItemList(4,RawDataList = PcdNameOffsetTable)\r
721 \r
722 SizeTableValue = zip(Dict['SIZE_TABLE_MAXIMUM_LENGTH'], Dict['SIZE_TABLE_CURRENT_LENGTH'])\r
2bc3256c 723 DbSizeTableValue = DbSizeTableItemList(2, RawDataList = SizeTableValue)\r
e8a47801
LG
724 InitValueUint16 = Dict['INIT_DB_VALUE_UINT16']\r
725 DbInitValueUint16 = DbComItemList(2, RawDataList = InitValueUint16)\r
726 VardefValueUint16 = Dict['VARDEF_DB_VALUE_UINT16']\r
727 DbVardefValueUint16 = DbItemList(2, RawDataList = VardefValueUint16)\r
728 InitValueUint8 = Dict['INIT_DB_VALUE_UINT8']\r
729 DbInitValueUint8 = DbComItemList(1, RawDataList = InitValueUint8)\r
730 VardefValueUint8 = Dict['VARDEF_DB_VALUE_UINT8']\r
731 DbVardefValueUint8 = DbItemList(1, RawDataList = VardefValueUint8)\r
732 InitValueBoolean = Dict['INIT_DB_VALUE_BOOLEAN']\r
733 DbInitValueBoolean = DbComItemList(1, RawDataList = InitValueBoolean)\r
734 VardefValueBoolean = Dict['VARDEF_DB_VALUE_BOOLEAN']\r
735 DbVardefValueBoolean = DbItemList(1, RawDataList = VardefValueBoolean)\r
736 SkuidValue = Dict['SKUID_VALUE']\r
a01f68bd 737 DbSkuidValue = DbItemList(8, RawDataList = SkuidValue)\r
2b8a6c44
LG
738\r
739\r
e8a47801
LG
740 \r
741 # Unit Db Items\r
742 UnInitValueUint64 = Dict['UNINIT_GUID_DECL_UINT64']\r
743 DbUnInitValueUint64 = DbItemList(8, RawDataList = UnInitValueUint64)\r
744 UnInitValueUint32 = Dict['UNINIT_GUID_DECL_UINT32']\r
745 DbUnInitValueUint32 = DbItemList(4, RawDataList = UnInitValueUint32)\r
746 UnInitValueUint16 = Dict['UNINIT_GUID_DECL_UINT16']\r
747 DbUnInitValueUint16 = DbItemList(2, RawDataList = UnInitValueUint16)\r
748 UnInitValueUint8 = Dict['UNINIT_GUID_DECL_UINT8']\r
749 DbUnInitValueUint8 = DbItemList(1, RawDataList = UnInitValueUint8)\r
750 UnInitValueBoolean = Dict['UNINIT_GUID_DECL_BOOLEAN']\r
751 DbUnInitValueBoolean = DbItemList(1, RawDataList = UnInitValueBoolean)\r
84cc912a 752 PcdTokenNumberMap = Dict['PCD_ORDER_TOKEN_NUMBER_MAP']\r
e8a47801 753 \r
2b8a6c44
LG
754 DbNameTotle = ["SkuidValue", "InitValueUint64", "VardefValueUint64", "InitValueUint32", "VardefValueUint32", "VpdHeadValue", "ExMapTable",\r
755 "LocalTokenNumberTable", "GuidTable", "StringHeadValue", "PcdNameOffsetTable","VariableTable", "StringTableLen", "PcdTokenTable", "PcdCNameTable",\r
e8a47801 756 "SizeTableValue", "InitValueUint16", "VardefValueUint16", "InitValueUint8", "VardefValueUint8", "InitValueBoolean",\r
a01f68bd 757 "VardefValueBoolean", "UnInitValueUint64", "UnInitValueUint32", "UnInitValueUint16", "UnInitValueUint8", "UnInitValueBoolean"]\r
e8a47801 758 \r
2b8a6c44
LG
759 DbTotal = [SkuidValue, InitValueUint64, VardefValueUint64, InitValueUint32, VardefValueUint32, VpdHeadValue, ExMapTable,\r
760 LocalTokenNumberTable, GuidTable, StringHeadValue, PcdNameOffsetTable,VariableTable, StringTableLen, PcdTokenTable,PcdCNameTable,\r
47fea6af 761 SizeTableValue, InitValueUint16, VardefValueUint16, InitValueUint8, VardefValueUint8, InitValueBoolean,\r
a01f68bd 762 VardefValueBoolean, UnInitValueUint64, UnInitValueUint32, UnInitValueUint16, UnInitValueUint8, UnInitValueBoolean]\r
2b8a6c44
LG
763 DbItemTotal = [DbSkuidValue, DbInitValueUint64, DbVardefValueUint64, DbInitValueUint32, DbVardefValueUint32, DbVpdHeadValue, DbExMapTable,\r
764 DbLocalTokenNumberTable, DbGuidTable, DbStringHeadValue, DbPcdNameOffsetTable,DbVariableTable, DbStringTableLen, DbPcdTokenTable, DbPcdCNameTable,\r
47fea6af 765 DbSizeTableValue, DbInitValueUint16, DbVardefValueUint16, DbInitValueUint8, DbVardefValueUint8, DbInitValueBoolean,\r
a01f68bd 766 DbVardefValueBoolean, DbUnInitValueUint64, DbUnInitValueUint32, DbUnInitValueUint16, DbUnInitValueUint8, DbUnInitValueBoolean]\r
e8a47801 767 \r
a01f68bd
YZ
768 # VardefValueBoolean is the last table in the init table items\r
769 InitTableNum = DbNameTotle.index("VardefValueBoolean") + 1\r
e8a47801 770 # The FixedHeader length of the PCD_DATABASE_INIT, from Signature to Pad\r
7e6e459a 771 FixedHeaderLen = 80\r
e8a47801
LG
772\r
773 # Get offset of SkuId table in the database \r
774 SkuIdTableOffset = FixedHeaderLen\r
775 for DbIndex in xrange(len(DbTotal)):\r
776 if DbTotal[DbIndex] is SkuidValue:\r
777 break\r
778 SkuIdTableOffset += DbItemTotal[DbIndex].GetListSize()\r
779 \r
780 \r
781 # Get offset of SkuValue table in the database \r
a01f68bd 782\r
e8a47801 783 # Fix up the LocalTokenNumberTable, SkuHeader table\r
e8a47801
LG
784 for (LocalTokenNumberTableIndex, (Offset, Table)) in enumerate(LocalTokenNumberTable):\r
785 DbIndex = 0\r
786 DbOffset = FixedHeaderLen\r
787 for DbIndex in xrange(len(DbTotal)):\r
788 if DbTotal[DbIndex] is Table:\r
789 DbOffset += DbItemTotal[DbIndex].GetInterOffset(Offset)\r
790 break\r
791 DbOffset += DbItemTotal[DbIndex].GetListSize()\r
c1b9129c
BF
792 if DbIndex + 1 == InitTableNum:\r
793 if DbOffset % 8:\r
794 DbOffset += (8 - DbOffset % 8)\r
e8a47801
LG
795 else:\r
796 assert(False)\r
797\r
798 TokenTypeValue = Dict['TOKEN_TYPE'][LocalTokenNumberTableIndex]\r
799 TokenTypeValue = GetTokenTypeValue(TokenTypeValue)\r
800 LocalTokenNumberTable[LocalTokenNumberTableIndex] = DbOffset|int(TokenTypeValue)\r
801 # if PCD_TYPE_SKU_ENABLED, then we need to fix up the SkuTable\r
802 \r
e8a47801
LG
803 \r
804 \r
e8a47801
LG
805\r
806 # resolve variable table offset \r
807 for VariableEntries in VariableTable:\r
2bc3256c 808 skuindex = 0\r
e8a47801 809 for VariableEntryPerSku in VariableEntries:\r
82a6a960 810 (VariableHeadGuidIndex, VariableHeadStringIndex, SKUVariableOffset, VariableOffset, VariableRefTable, VariableAttribute) = VariableEntryPerSku[:]\r
e8a47801
LG
811 DbIndex = 0\r
812 DbOffset = FixedHeaderLen\r
813 for DbIndex in xrange(len(DbTotal)):\r
814 if DbTotal[DbIndex] is VariableRefTable:\r
815 DbOffset += DbItemTotal[DbIndex].GetInterOffset(VariableOffset)\r
816 break\r
817 DbOffset += DbItemTotal[DbIndex].GetListSize()\r
c1b9129c
BF
818 if DbIndex + 1 == InitTableNum:\r
819 if DbOffset % 8:\r
820 DbOffset += (8 - DbOffset % 8)\r
e8a47801
LG
821 else:\r
822 assert(False)\r
2bc3256c
LG
823 if isinstance(VariableRefTable[0],list):\r
824 DbOffset += skuindex * 4 \r
825 skuindex += 1\r
e8a47801
LG
826 if DbIndex >= InitTableNum:\r
827 assert(False)\r
82a6a960
BF
828 VarAttr, VarProp = VariableAttributes.GetVarAttributes(VariableAttribute)\r
829 VariableEntryPerSku[:] = (VariableHeadStringIndex, DbOffset, VariableHeadGuidIndex, SKUVariableOffset, VarAttr, VarProp)\r
e8a47801
LG
830\r
831 # calculate various table offset now\r
832 DbTotalLength = FixedHeaderLen\r
833 for DbIndex in xrange(len(DbItemTotal)):\r
834 if DbItemTotal[DbIndex] is DbLocalTokenNumberTable:\r
835 LocalTokenNumberTableOffset = DbTotalLength\r
836 elif DbItemTotal[DbIndex] is DbExMapTable:\r
837 ExMapTableOffset = DbTotalLength\r
838 elif DbItemTotal[DbIndex] is DbGuidTable:\r
839 GuidTableOffset = DbTotalLength\r
840 elif DbItemTotal[DbIndex] is DbStringTableLen:\r
841 StringTableOffset = DbTotalLength\r
842 elif DbItemTotal[DbIndex] is DbSizeTableValue:\r
843 SizeTableOffset = DbTotalLength\r
844 elif DbItemTotal[DbIndex] is DbSkuidValue:\r
845 SkuIdTableOffset = DbTotalLength\r
846 elif DbItemTotal[DbIndex] is DbPcdNameOffsetTable:\r
847 DbPcdNameOffset = DbTotalLength\r
2b8a6c44 848\r
e8a47801
LG
849\r
850 DbTotalLength += DbItemTotal[DbIndex].GetListSize()\r
851 if not Dict['PCD_INFO_FLAG']:\r
852 DbPcdNameOffset = 0 \r
853 LocalTokenCount = GetIntegerValue(Dict['LOCAL_TOKEN_NUMBER'])\r
854 ExTokenCount = GetIntegerValue(Dict['EX_TOKEN_NUMBER'])\r
855 GuidTableCount = GetIntegerValue(Dict['GUID_TABLE_SIZE'])\r
856 SystemSkuId = GetIntegerValue(Dict['SYSTEM_SKU_ID_VALUE'])\r
857 Pad = 0xDA\r
858 \r
859 UninitDataBaseSize = 0\r
860 for Item in (DbUnInitValueUint64, DbUnInitValueUint32, DbUnInitValueUint16, DbUnInitValueUint8, DbUnInitValueBoolean):\r
861 UninitDataBaseSize += Item.GetListSize()\r
862 \r
c1b9129c
BF
863 if (DbTotalLength - UninitDataBaseSize) % 8:\r
864 DbTotalLength += (8 - (DbTotalLength - UninitDataBaseSize) % 8)\r
e8a47801
LG
865 # Construct the database buffer\r
866 Guid = "{0x3c7d193c, 0x682c, 0x4c14, 0xa6, 0x8f, 0x55, 0x2d, 0xea, 0x4f, 0x43, 0x7e}"\r
867 Guid = StringArrayToList(Guid)\r
868 Buffer = pack('=LHHBBBBBBBB', \r
869 Guid[0], \r
870 Guid[1], \r
871 Guid[2], \r
872 Guid[3], \r
873 Guid[4], \r
874 Guid[5],\r
875 Guid[6],\r
876 Guid[7],\r
877 Guid[8],\r
878 Guid[9],\r
879 Guid[10],\r
880 )\r
881\r
882 b = pack("=L", DATABASE_VERSION)\r
883 Buffer += b\r
884\r
885 b = pack('=L', DbTotalLength - UninitDataBaseSize)\r
886\r
a01f68bd
YZ
887 Buffer += b\r
888 b = pack('=Q', SystemSkuId)\r
889\r
2b8a6c44
LG
890 Buffer += b\r
891 b = pack('=L', 0)\r
892\r
e8a47801
LG
893 Buffer += b\r
894 b = pack('=L', UninitDataBaseSize)\r
895\r
896 Buffer += b\r
897 b = pack('=L', LocalTokenNumberTableOffset)\r
898\r
899 Buffer += b\r
900 b = pack('=L', ExMapTableOffset)\r
901 \r
902 Buffer += b\r
903 b = pack('=L', GuidTableOffset)\r
904\r
905 Buffer += b\r
906 b = pack('=L', StringTableOffset)\r
907\r
908 Buffer += b\r
909 b = pack('=L', SizeTableOffset)\r
910\r
911 Buffer += b\r
912 b = pack('=L', SkuIdTableOffset)\r
913\r
914 Buffer += b\r
915 b = pack('=L', DbPcdNameOffset)\r
916\r
917 Buffer += b\r
918 b = pack('=H', LocalTokenCount)\r
919\r
920 Buffer += b\r
921 b = pack('=H', ExTokenCount)\r
922\r
923 Buffer += b\r
924 b = pack('=H', GuidTableCount)\r
925 \r
926 Buffer += b\r
a01f68bd 927 b = pack('=B', Pad)\r
e8a47801 928 Buffer += b\r
7e6e459a
LG
929 Buffer += b\r
930 Buffer += b\r
931 Buffer += b\r
932 Buffer += b\r
e8a47801
LG
933 Buffer += b\r
934 \r
935 Index = 0\r
936 for Item in DbItemTotal:\r
937 Index +=1\r
938 b = Item.PackData()\r
939 Buffer += b \r
940 if Index == InitTableNum:\r
c1b9129c
BF
941 if len(Buffer) % 8:\r
942 for num in range(8 - len(Buffer) % 8):\r
943 b = pack('=B', Pad)\r
944 Buffer += b\r
e8a47801
LG
945 break \r
946 return Buffer\r
947\r
948## Create code for PCD database\r
949#\r
950# @param Info The ModuleAutoGen object\r
951# @param AutoGenC The TemplateString object for C code\r
952# @param AutoGenH The TemplateString object for header file\r
953#\r
954def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):\r
955 if Info.PcdIsDriver == "":\r
956 return\r
957 if Info.PcdIsDriver not in gPcdPhaseMap:\r
958 EdkLogger.error("build", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s" % Info.PcdIsDriver,\r
959 ExtraData="[%s]" % str(Info))\r
960\r
2b8a6c44 961 AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = NewCreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI')\r
e8a47801
LG
962 AutoGenH.Append(AdditionalAutoGenH.String)\r
963\r
964 Phase = gPcdPhaseMap[Info.PcdIsDriver]\r
965 if Phase == 'PEI':\r
966 AutoGenC.Append(AdditionalAutoGenC.String)\r
967\r
968 if Phase == 'DXE':\r
2b8a6c44 969 AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer = NewCreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase)\r
e8a47801
LG
970 AutoGenH.Append(AdditionalAutoGenH.String)\r
971 AutoGenC.Append(AdditionalAutoGenC.String)\r
972\r
973 if Info.IsBinaryModule:\r
974 DbFileName = os.path.join(Info.PlatformInfo.BuildDir, "FV", Phase + "PcdDataBase.raw")\r
975 else:\r
976 DbFileName = os.path.join(Info.OutputDir, Phase + "PcdDataBase.raw")\r
977 DbFile = StringIO()\r
978 DbFile.write(PcdDbBuffer)\r
979 Changed = SaveFileOnChange(DbFileName, DbFile.getvalue(), True)\r
2b8a6c44
LG
980def CreatePcdDataBase(PcdDBData):\r
981 delta = {}\r
982 basedata = {}\r
983 if not PcdDBData:\r
984 return ""\r
985 for skuname,skuid in PcdDBData:\r
986 if len(PcdDBData[(skuname,skuid)][1]) != len(PcdDBData[("DEFAULT","0")][1]):\r
987 EdkLogger.ERROR("The size of each sku in one pcd are not same")\r
988 for skuname,skuid in PcdDBData:\r
989 if skuname == "DEFAULT":\r
990 continue\r
991 delta[(skuname,skuid)] = [(index,data,hex(data)) for index,data in enumerate(PcdDBData[(skuname,skuid)][1]) if PcdDBData[(skuname,skuid)][1][index] != PcdDBData[("DEFAULT","0")][1][index]]\r
992 basedata[(skuname,skuid)] = [(index,PcdDBData[("DEFAULT","0")][1][index],hex(PcdDBData[("DEFAULT","0")][1][index])) for index,data in enumerate(PcdDBData[(skuname,skuid)][1]) if PcdDBData[(skuname,skuid)][1][index] != PcdDBData[("DEFAULT","0")][1][index]]\r
993 databasebuff = PcdDBData[("DEFAULT","0")][0]\r
994\r
995 for skuname,skuid in delta:\r
7e6e459a
LG
996 # 8 byte align\r
997 if len(databasebuff) % 8 > 0:\r
998 for i in range(8 - (len(databasebuff) % 8)):\r
999 databasebuff += pack("=B",0)\r
1000 databasebuff += pack('=Q', int(skuid))\r
1001 databasebuff += pack('=Q', 0)\r
1002 databasebuff += pack('=L', 8+8+4+4*len(delta[(skuname,skuid)]))\r
2b8a6c44
LG
1003 for item in delta[(skuname,skuid)]:\r
1004 databasebuff += pack("=L",item[0])\r
1005 databasebuff = databasebuff[:-1] + pack("=B",item[1])\r
1006 totallen = len(databasebuff)\r
1007 totallenbuff = pack("=L",totallen)\r
1008 newbuffer = databasebuff[:32]\r
1009 for i in range(4):\r
1010 newbuffer += totallenbuff[i]\r
1011 for i in range(36,totallen):\r
1012 newbuffer += databasebuff[i]\r
1013\r
1014 return newbuffer\r
1015def CreateVarCheckBin(VarCheckTab):\r
1016 return VarCheckTab[('DEFAULT',"0")]\r
1017def CreateAutoGen(PcdDriverAutoGenData):\r
1018 autogenC = TemplateString()\r
1019 for skuname,skuid in PcdDriverAutoGenData:\r
1020 autogenC.Append("//SKUID: %s" % skuname)\r
1021 autogenC.Append(PcdDriverAutoGenData[(skuname,skuid)][1].String)\r
1022 return (PcdDriverAutoGenData[(skuname,skuid)][0],autogenC)\r
1023def NewCreatePcdDatabasePhaseSpecificAutoGen(Platform,Phase):\r
1024 def prune_sku(pcd,skuname):\r
1025 new_pcd = copy.deepcopy(pcd)\r
1026 new_pcd.SkuInfoList = {skuname:pcd.SkuInfoList[skuname]}\r
1027 return new_pcd\r
1028 DynamicPcds = Platform.DynamicPcdList\r
1029 DynamicPcdSet_Sku = {(SkuName,skuobj.SkuId):[] for pcd in DynamicPcds for (SkuName,skuobj) in pcd.SkuInfoList.items() }\r
1030 for skuname,skuid in DynamicPcdSet_Sku:\r
1031 DynamicPcdSet_Sku[(skuname,skuid)] = [prune_sku(pcd,skuname) for pcd in DynamicPcds]\r
1032 PcdDBData = {}\r
1033 PcdDriverAutoGenData = {}\r
1034 VarCheckTableData = {}\r
1035 if DynamicPcdSet_Sku:\r
1036 for skuname,skuid in DynamicPcdSet_Sku:\r
1037 AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer,VarCheckTab = CreatePcdDatabasePhaseSpecificAutoGen (Platform,DynamicPcdSet_Sku[(skuname,skuid)], Phase)\r
1038 final_data = ()\r
1039 for item in PcdDbBuffer:\r
1040 final_data += unpack("B",item)\r
1041 PcdDBData[(skuname,skuid)] = (PcdDbBuffer, final_data)\r
1042 PcdDriverAutoGenData[(skuname,skuid)] = (AdditionalAutoGenH, AdditionalAutoGenC)\r
1043 VarCheckTableData[(skuname,skuid)] = VarCheckTab\r
1044 if Platform.Platform.VarCheckFlag:\r
1045 dest = os.path.join(Platform.BuildDir, 'FV')\r
1046 VarCheckTable = CreateVarCheckBin(VarCheckTableData)\r
1047 VarCheckTable.dump(dest, Phase)\r
1048 AdditionalAutoGenH, AdditionalAutoGenC = CreateAutoGen(PcdDriverAutoGenData)\r
1049 else:\r
1050 AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer,VarCheckTab = CreatePcdDatabasePhaseSpecificAutoGen (Platform,{}, Phase)\r
e8a47801 1051\r
2b8a6c44
LG
1052 PcdDbBuffer = CreatePcdDataBase(PcdDBData)\r
1053 return AdditionalAutoGenH, AdditionalAutoGenC, PcdDbBuffer\r
e8a47801
LG
1054## Create PCD database in DXE or PEI phase\r
1055#\r
1056# @param Platform The platform object\r
1057# @retval tuple Two TemplateString objects for C code and header file,\r
1058# respectively\r
1059#\r
2b8a6c44 1060def CreatePcdDatabasePhaseSpecificAutoGen (Platform, DynamicPcdList, Phase):\r
e8a47801
LG
1061 AutoGenC = TemplateString()\r
1062 AutoGenH = TemplateString()\r
1063\r
1064 Dict = {\r
1065 'PHASE' : Phase,\r
1066 'SERVICE_DRIVER_VERSION' : DATABASE_VERSION,\r
1067 'GUID_TABLE_SIZE' : '1U',\r
1068 'STRING_TABLE_SIZE' : '1U',\r
1069 'SKUID_TABLE_SIZE' : '1U',\r
1070 'LOCAL_TOKEN_NUMBER_TABLE_SIZE' : '0U',\r
1071 'LOCAL_TOKEN_NUMBER' : '0U',\r
1072 'EXMAPPING_TABLE_SIZE' : '1U',\r
1073 'EX_TOKEN_NUMBER' : '0U',\r
1074 'SIZE_TABLE_SIZE' : '2U',\r
1075 'SKU_HEAD_SIZE' : '1U',\r
1076 'GUID_TABLE_EMPTY' : 'TRUE',\r
1077 'STRING_TABLE_EMPTY' : 'TRUE',\r
1078 'SKUID_TABLE_EMPTY' : 'TRUE',\r
1079 'DATABASE_EMPTY' : 'TRUE',\r
1080 'EXMAP_TABLE_EMPTY' : 'TRUE',\r
1081 'PCD_DATABASE_UNINIT_EMPTY' : ' UINT8 dummy; /* PCD_DATABASE_UNINIT is emptry */',\r
1082 'SYSTEM_SKU_ID' : ' SKU_ID SystemSkuId;',\r
1083 'SYSTEM_SKU_ID_VALUE' : '0U'\r
1084 }\r
1085 \r
65eff519
LG
1086 SkuObj = Platform.Platform.SkuIdMgr\r
1087 Dict['SYSTEM_SKU_ID_VALUE'] = 0 if SkuObj.SkuUsageType == SkuObj.SINGLE else Platform.Platform.SkuIds[SkuObj.SystemSkuId][0]\r
e8a47801
LG
1088\r
1089 Dict['PCD_INFO_FLAG'] = Platform.Platform.PcdInfoFlag\r
1090\r
1091 for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN', "VOID*"]:\r
1092 Dict['VARDEF_CNAME_' + DatumType] = []\r
1093 Dict['VARDEF_GUID_' + DatumType] = []\r
1094 Dict['VARDEF_SKUID_' + DatumType] = []\r
1095 Dict['VARDEF_VALUE_' + DatumType] = []\r
1096 Dict['VARDEF_DB_VALUE_' + DatumType] = []\r
1097 for Init in ['INIT','UNINIT']:\r
1098 Dict[Init+'_CNAME_DECL_' + DatumType] = []\r
1099 Dict[Init+'_GUID_DECL_' + DatumType] = []\r
1100 Dict[Init+'_NUMSKUS_DECL_' + DatumType] = []\r
1101 Dict[Init+'_VALUE_' + DatumType] = []\r
1102 Dict[Init+'_DB_VALUE_'+DatumType] = []\r
1103 \r
1104 for Type in ['STRING_HEAD','VPD_HEAD','VARIABLE_HEAD']:\r
1105 Dict[Type + '_CNAME_DECL'] = []\r
1106 Dict[Type + '_GUID_DECL'] = []\r
1107 Dict[Type + '_NUMSKUS_DECL'] = []\r
1108 Dict[Type + '_VALUE'] = []\r
1109\r
1110 Dict['STRING_DB_VALUE'] = []\r
1111 Dict['VPD_DB_VALUE'] = []\r
1112 Dict['VARIABLE_DB_VALUE'] = []\r
1113 \r
1114 Dict['STRING_TABLE_INDEX'] = []\r
1115 Dict['STRING_TABLE_LENGTH'] = []\r
1116 Dict['STRING_TABLE_CNAME'] = []\r
1117 Dict['STRING_TABLE_GUID'] = []\r
1118 Dict['STRING_TABLE_VALUE'] = []\r
1119 Dict['STRING_TABLE_DB_VALUE'] = []\r
1120\r
1121 Dict['SIZE_TABLE_CNAME'] = []\r
1122 Dict['SIZE_TABLE_GUID'] = []\r
1123 Dict['SIZE_TABLE_CURRENT_LENGTH'] = []\r
1124 Dict['SIZE_TABLE_MAXIMUM_LENGTH'] = []\r
1125\r
1126 Dict['EXMAPPING_TABLE_EXTOKEN'] = []\r
1127 Dict['EXMAPPING_TABLE_LOCAL_TOKEN'] = []\r
1128 Dict['EXMAPPING_TABLE_GUID_INDEX'] = []\r
1129\r
1130 Dict['GUID_STRUCTURE'] = []\r
1131 Dict['SKUID_VALUE'] = [0] # init Dict length\r
1132 Dict['VARDEF_HEADER'] = []\r
1133\r
1134 Dict['LOCAL_TOKEN_NUMBER_DB_VALUE'] = []\r
1135 Dict['VARIABLE_DB_VALUE'] = []\r
e8a47801
LG
1136 \r
1137 Dict['PCD_TOKENSPACE'] = []\r
1138 Dict['PCD_CNAME'] = [] \r
1139 Dict['PCD_TOKENSPACE_LENGTH'] = []\r
1140 Dict['PCD_CNAME_LENGTH'] = []\r
1141 Dict['PCD_TOKENSPACE_OFFSET'] = []\r
1142 Dict['PCD_CNAME_OFFSET'] = []\r
1143 Dict['PCD_TOKENSPACE_MAP'] = []\r
1144 Dict['PCD_NAME_OFFSET'] = []\r
1145 \r
84cc912a 1146 Dict['PCD_ORDER_TOKEN_NUMBER_MAP'] = {}\r
2bc3256c
LG
1147 PCD_STRING_INDEX_MAP = {}\r
1148 \r
e8a47801
LG
1149 StringTableIndex = 0\r
1150 StringTableSize = 0\r
1151 NumberOfLocalTokens = 0\r
1152 NumberOfPeiLocalTokens = 0\r
1153 NumberOfDxeLocalTokens = 0\r
1154 NumberOfExTokens = 0\r
1155 NumberOfSizeItems = 0\r
1156 NumberOfSkuEnabledPcd = 0\r
1157 GuidList = []\r
82a6a960 1158 VarCheckTab = VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER()\r
e8a47801 1159 i = 0\r
2b8a6c44 1160 ReorderedDynPcdList = GetOrderedDynamicPcdList(DynamicPcdList, Platform.PcdTokenNumber)\r
ae7b6df8
LG
1161 for item in ReorderedDynPcdList:\r
1162 if item.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1163 item.DatumType = "VOID*"\r
84cc912a 1164 for Pcd in ReorderedDynPcdList:\r
2bc3256c 1165 VoidStarTypeCurrSize = []\r
e8a47801
LG
1166 i += 1\r
1167 CName = Pcd.TokenCName\r
1168 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1169\r
2a29017e
YZ
1170 for PcdItem in GlobalData.MixedPcd:\r
1171 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1172 CName = PcdItem[0]\r
1173\r
763e8edf
YZ
1174 if GlobalData.BuildOptionPcd:\r
1175 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 1176 if (Pcd.TokenSpaceGuidCName, CName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
1177 Pcd.DefaultValue = PcdItem[2]\r
1178 break\r
1179\r
e8a47801
LG
1180 EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase))\r
1181\r
1182 if Pcd.Phase == 'PEI':\r
1183 NumberOfPeiLocalTokens += 1\r
1184 if Pcd.Phase == 'DXE':\r
1185 NumberOfDxeLocalTokens += 1\r
1186 if Pcd.Phase != Phase:\r
1187 continue\r
1188\r
1189 #\r
1190 # TODO: need GetGuidValue() definition\r
1191 #\r
1192 TokenSpaceGuidStructure = Pcd.TokenSpaceGuidValue\r
1193 TokenSpaceGuid = GuidStructureStringToGuidValueName(TokenSpaceGuidStructure)\r
1194 if Pcd.Type in gDynamicExPcd:\r
1195 if TokenSpaceGuid not in GuidList:\r
1196 GuidList += [TokenSpaceGuid]\r
1197 Dict['GUID_STRUCTURE'].append(TokenSpaceGuidStructure)\r
1198 NumberOfExTokens += 1\r
1199\r
1200 ValueList = []\r
1201 DbValueList = []\r
1202 StringHeadOffsetList = []\r
1203 StringDbOffsetList = []\r
1204 VpdHeadOffsetList = []\r
1205 VpdDbOffsetList = []\r
1206 VariableHeadValueList = []\r
1207 VariableDbValueList = []\r
1208 Pcd.InitString = 'UNINIT'\r
1209\r
1210 if Pcd.DatumType == 'VOID*':\r
1211 if Pcd.Type not in ["DynamicVpd", "DynamicExVpd"]:\r
1212 Pcd.TokenTypeList = ['PCD_TYPE_STRING']\r
1213 else:\r
1214 Pcd.TokenTypeList = []\r
1215 elif Pcd.DatumType == 'BOOLEAN':\r
1216 Pcd.TokenTypeList = ['PCD_DATUM_TYPE_UINT8_BOOLEAN']\r
1217 else:\r
1218 Pcd.TokenTypeList = ['PCD_DATUM_TYPE_' + Pcd.DatumType]\r
1219\r
1220 if len(Pcd.SkuInfoList) > 1:\r
2b8a6c44 1221# Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED']\r
e8a47801
LG
1222 NumberOfSkuEnabledPcd += 1\r
1223 \r
e8a47801 1224 SkuIdIndex = 1 \r
2bc3256c 1225 VariableHeadList = []\r
e8a47801
LG
1226 for SkuName in Pcd.SkuInfoList:\r
1227 Sku = Pcd.SkuInfoList[SkuName]\r
1228 SkuId = Sku.SkuId\r
1229 if SkuId == None or SkuId == '':\r
1230 continue\r
1231\r
e8a47801 1232 \r
e8a47801
LG
1233 SkuIdIndex += 1\r
1234 \r
1235 if len(Sku.VariableName) > 0:\r
82a6a960
BF
1236 VariableGuidStructure = Sku.VariableGuidValue\r
1237 VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure)\r
1238 if Platform.Platform.VarCheckFlag:\r
1239 var_check_obj = VAR_CHECK_PCD_VARIABLE_TAB(VariableGuidStructure, StringToArray(Sku.VariableName))\r
1240 try:\r
1241 var_check_obj.push_back(VAR_VALID_OBJECT_FACTORY.Get_valid_object(Pcd, Sku.VariableOffset))\r
1242 VarAttr, _ = VariableAttributes.GetVarAttributes(Sku.VariableAttribute)\r
1243 var_check_obj.SetAttributes(VarAttr)\r
1244 var_check_obj.UpdateSize()\r
1245 VarCheckTab.push_back(var_check_obj)\r
1246 except Exception:\r
1247 ValidInfo = ''\r
1248 if Pcd.validateranges:\r
1249 ValidInfo = Pcd.validateranges[0]\r
1250 if Pcd.validlists:\r
1251 ValidInfo = Pcd.validlists[0]\r
1252 if ValidInfo:\r
1253 EdkLogger.error("build", PCD_VALIDATION_INFO_ERROR,\r
1254 "The PCD '%s.%s' Validation information defined in DEC file has incorrect format." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
1255 ExtraData = "[%s]" % str(ValidInfo))\r
1256 else:\r
1257 EdkLogger.error("build", PCD_VALIDATION_INFO_ERROR,\r
1258 "The PCD '%s.%s' Validation information defined in DEC file has incorrect format." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
e8a47801
LG
1259 Pcd.TokenTypeList += ['PCD_TYPE_HII']\r
1260 Pcd.InitString = 'INIT'\r
2bc3256c
LG
1261 # Store all variable names of one HII PCD under different SKU to stringTable\r
1262 # and calculate the VariableHeadStringIndex\r
2b8a6c44
LG
1263\r
1264 VariableNameStructure = StringToArray(Sku.VariableName)\r
1265 if VariableNameStructure not in Dict['STRING_TABLE_VALUE']:\r
1266 Dict['STRING_TABLE_CNAME'].append(CName)\r
1267 Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
1268 if StringTableIndex == 0:\r
1269 Dict['STRING_TABLE_INDEX'].append('')\r
1270 else:\r
1271 Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
1272 VarNameSize = len(VariableNameStructure.replace(',',' ').split())\r
1273 Dict['STRING_TABLE_LENGTH'].append(VarNameSize )\r
1274 Dict['STRING_TABLE_VALUE'].append(VariableNameStructure)\r
1275 StringHeadOffsetList.append(str(StringTableSize) + 'U')\r
1276 VarStringDbOffsetList = []\r
1277 VarStringDbOffsetList.append(StringTableSize)\r
1278 Dict['STRING_DB_VALUE'].append(VarStringDbOffsetList)\r
1279 StringTableIndex += 1\r
1280 StringTableSize += len(VariableNameStructure.replace(',',' ').split())\r
1281 VariableHeadStringIndex = 0\r
1282 for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)):\r
1283 VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index]\r
1284 VariableHeadList.append(VariableHeadStringIndex)\r
2bc3256c
LG
1285 \r
1286 VariableHeadStringIndex = VariableHeadList[SkuIdIndex - 2]\r
e8a47801 1287 # store VariableGuid to GuidTable and get the VariableHeadGuidIndex\r
e8a47801
LG
1288\r
1289 if VariableGuid not in GuidList:\r
1290 GuidList += [VariableGuid]\r
1291 Dict['GUID_STRUCTURE'].append(VariableGuidStructure)\r
1292 VariableHeadGuidIndex = GuidList.index(VariableGuid)\r
1293\r
1294 if "PCD_TYPE_STRING" in Pcd.TokenTypeList:\r
1295 VariableHeadValueList.append('%dU, offsetof(%s_PCD_DATABASE, Init.%s_%s), %dU, %sU' %\r
1296 (VariableHeadStringIndex, Phase, CName, TokenSpaceGuid, \r
1297 VariableHeadGuidIndex, Sku.VariableOffset))\r
1298 else:\r
1299 VariableHeadValueList.append('%dU, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s), %dU, %sU' %\r
1300 (VariableHeadStringIndex, Phase, CName, TokenSpaceGuid, SkuIdIndex, \r
1301 VariableHeadGuidIndex, Sku.VariableOffset))\r
1302 Dict['VARDEF_CNAME_'+Pcd.DatumType].append(CName)\r
1303 Dict['VARDEF_GUID_'+Pcd.DatumType].append(TokenSpaceGuid)\r
1304 Dict['VARDEF_SKUID_'+Pcd.DatumType].append(SkuIdIndex)\r
1305 if "PCD_TYPE_STRING" in Pcd.TokenTypeList:\r
1306 Dict['VARDEF_VALUE_' + Pcd.DatumType].append("%s_%s[%d]" % (Pcd.TokenCName, TokenSpaceGuid, SkuIdIndex))\r
1307 else:\r
1308 #\r
1309 # ULL (for UINT64) or U(other integer type) should be append to avoid\r
1310 # warning under linux building environment.\r
1311 #\r
1312 Dict['VARDEF_DB_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue)\r
1313 \r
1314 if Pcd.DatumType == "UINT64":\r
1315 Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue + "ULL")\r
1316 elif Pcd.DatumType in ("UINT32", "UINT16", "UINT8"):\r
1317 Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue + "U")\r
1318 elif Pcd.DatumType == "BOOLEAN":\r
1319 if eval(Sku.HiiDefaultValue) in [1,0]:\r
1320 Dict['VARDEF_VALUE_'+Pcd.DatumType].append(str(eval(Sku.HiiDefaultValue)) + "U")\r
1321 else:\r
1322 Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue)\r
1323\r
1324 # construct the VariableHeader value\r
1325 if "PCD_TYPE_STRING" in Pcd.TokenTypeList:\r
1326 VariableHeadValueList.append('%dU, %dU, %sU, offsetof(%s_PCD_DATABASE, Init.%s_%s)' %\r
1327 (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset,\r
1328 Phase, CName, TokenSpaceGuid))\r
1329 # the Pcd default value will be filled later on\r
1330 VariableOffset = len(Dict['STRING_DB_VALUE'])\r
1331 VariableRefTable = Dict['STRING_DB_VALUE']\r
1332 else:\r
1333 VariableHeadValueList.append('%dU, %dU, %sU, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' %\r
1334 (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset,\r
1335 Phase, CName, TokenSpaceGuid, SkuIdIndex))\r
1336 # the Pcd default value was filled before\r
1337 VariableOffset = len(Dict['VARDEF_DB_VALUE_' + Pcd.DatumType]) - 1\r
1338 VariableRefTable = Dict['VARDEF_DB_VALUE_' + Pcd.DatumType]\r
82a6a960 1339 VariableDbValueList.append([VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, VariableOffset, VariableRefTable, Sku.VariableAttribute])\r
e8a47801
LG
1340\r
1341 elif Sku.VpdOffset != '':\r
1342 Pcd.TokenTypeList += ['PCD_TYPE_VPD']\r
1343 Pcd.InitString = 'INIT'\r
1344 VpdHeadOffsetList.append(str(Sku.VpdOffset) + 'U')\r
1345 VpdDbOffsetList.append(Sku.VpdOffset)\r
1346 # Also add the VOID* string of VPD PCD to SizeTable \r
1347 if Pcd.DatumType == 'VOID*':\r
1348 NumberOfSizeItems += 1\r
e8a47801 1349 # For VPD type of PCD, its current size is equal to its MAX size.\r
2bc3256c 1350 VoidStarTypeCurrSize = [str(Pcd.MaxDatumSize) + 'U'] \r
e8a47801
LG
1351 continue\r
1352 \r
1353 if Pcd.DatumType == 'VOID*':\r
1354 Pcd.TokenTypeList += ['PCD_TYPE_STRING']\r
1355 Pcd.InitString = 'INIT'\r
1356 if Sku.HiiDefaultValue != '' and Sku.DefaultValue == '':\r
1357 Sku.DefaultValue = Sku.HiiDefaultValue\r
1358 if Sku.DefaultValue != '':\r
1359 NumberOfSizeItems += 1\r
1360 Dict['STRING_TABLE_CNAME'].append(CName)\r
1361 Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
1362\r
1363 if StringTableIndex == 0:\r
1364 Dict['STRING_TABLE_INDEX'].append('')\r
1365 else:\r
1366 Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
1367 if Sku.DefaultValue[0] == 'L':\r
2bc3256c
LG
1368 DefaultValueBinStructure = StringToArray(Sku.DefaultValue)\r
1369 Size = len(DefaultValueBinStructure.replace(',',' ').split())\r
1370 Dict['STRING_TABLE_VALUE'].append(DefaultValueBinStructure)\r
e8a47801 1371 elif Sku.DefaultValue[0] == '"':\r
2bc3256c 1372 DefaultValueBinStructure = StringToArray(Sku.DefaultValue)\r
47fea6af 1373 Size = len(Sku.DefaultValue) - 2 + 1\r
2bc3256c 1374 Dict['STRING_TABLE_VALUE'].append(DefaultValueBinStructure)\r
e8a47801 1375 elif Sku.DefaultValue[0] == '{':\r
2bc3256c
LG
1376 DefaultValueBinStructure = StringToArray(Sku.DefaultValue)\r
1377 Size = len(Sku.DefaultValue.split(","))\r
1378 Dict['STRING_TABLE_VALUE'].append(DefaultValueBinStructure)\r
e8a47801
LG
1379 \r
1380 StringHeadOffsetList.append(str(StringTableSize) + 'U')\r
1381 StringDbOffsetList.append(StringTableSize)\r
e8a47801
LG
1382 if Pcd.MaxDatumSize != '':\r
1383 MaxDatumSize = int(Pcd.MaxDatumSize, 0)\r
1384 if MaxDatumSize < Size:\r
2bc3256c
LG
1385 EdkLogger.error("build", AUTOGEN_ERROR,\r
1386 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
1387 ExtraData="[%s]" % str(Platform))\r
1388 else:\r
1389 MaxDatumSize = Size\r
1390 StringTabLen = MaxDatumSize\r
1391 if StringTabLen % 2:\r
1392 StringTabLen += 1\r
1393 if Sku.VpdOffset == '':\r
1394 VoidStarTypeCurrSize.append(str(Size) + 'U')\r
1395 Dict['STRING_TABLE_LENGTH'].append(StringTabLen)\r
e8a47801 1396 StringTableIndex += 1\r
2bc3256c 1397 StringTableSize += (StringTabLen)\r
e8a47801
LG
1398 else:\r
1399 if "PCD_TYPE_HII" not in Pcd.TokenTypeList:\r
1400 Pcd.TokenTypeList += ['PCD_TYPE_DATA']\r
1401 if Sku.DefaultValue == 'TRUE':\r
1402 Pcd.InitString = 'INIT'\r
1403 else:\r
1404 if int(Sku.DefaultValue, 0) != 0:\r
47fea6af 1405 Pcd.InitString = 'INIT'\r
e8a47801
LG
1406 #\r
1407 # For UNIT64 type PCD's value, ULL should be append to avoid\r
1408 # warning under linux building environment.\r
1409 #\r
1410 if Pcd.DatumType == "UINT64":\r
1411 ValueList.append(Sku.DefaultValue + "ULL")\r
1412 elif Pcd.DatumType in ("UINT32", "UINT16", "UINT8"):\r
1413 ValueList.append(Sku.DefaultValue + "U")\r
1414 elif Pcd.DatumType == "BOOLEAN":\r
1415 if Sku.DefaultValue in ["1", "0"]:\r
1416 ValueList.append(Sku.DefaultValue + "U") \r
1417 else:\r
1418 ValueList.append(Sku.DefaultValue)\r
1419 \r
1420 DbValueList.append(Sku.DefaultValue)\r
1421\r
1422 Pcd.TokenTypeList = list(set(Pcd.TokenTypeList))\r
2bc3256c
LG
1423 if Pcd.DatumType == 'VOID*': \r
1424 Dict['SIZE_TABLE_CNAME'].append(CName)\r
1425 Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid)\r
1426 Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(str(Pcd.MaxDatumSize) + 'U')\r
1427 Dict['SIZE_TABLE_CURRENT_LENGTH'].append(VoidStarTypeCurrSize)\r
1428 \r
e8a47801 1429 \r
e8a47801
LG
1430\r
1431 if 'PCD_TYPE_HII' in Pcd.TokenTypeList:\r
1432 Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName)\r
1433 Dict['VARIABLE_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1434 Dict['VARIABLE_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1435 Dict['VARIABLE_HEAD_VALUE'].append('{ %s }\n' % ' },\n { '.join(VariableHeadValueList))\r
1436 Dict['VARDEF_HEADER'].append('_Variable_Header')\r
1437 Dict['VARIABLE_DB_VALUE'].append(VariableDbValueList)\r
1438 else:\r
1439 Dict['VARDEF_HEADER'].append('')\r
1440 if 'PCD_TYPE_VPD' in Pcd.TokenTypeList:\r
1441 Dict['VPD_HEAD_CNAME_DECL'].append(CName)\r
1442 Dict['VPD_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1443 Dict['VPD_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1444 Dict['VPD_HEAD_VALUE'].append('{ %s }' % ' }, { '.join(VpdHeadOffsetList))\r
1445 Dict['VPD_DB_VALUE'].append(VpdDbOffsetList)\r
1446 if 'PCD_TYPE_STRING' in Pcd.TokenTypeList:\r
1447 Dict['STRING_HEAD_CNAME_DECL'].append(CName)\r
1448 Dict['STRING_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1449 Dict['STRING_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1450 Dict['STRING_HEAD_VALUE'].append(', '.join(StringHeadOffsetList))\r
1451 Dict['STRING_DB_VALUE'].append(StringDbOffsetList)\r
2bc3256c 1452 PCD_STRING_INDEX_MAP[len(Dict['STRING_HEAD_CNAME_DECL']) -1 ] = len(Dict['STRING_DB_VALUE']) -1\r
e8a47801
LG
1453 if 'PCD_TYPE_DATA' in Pcd.TokenTypeList:\r
1454 Dict[Pcd.InitString+'_CNAME_DECL_'+Pcd.DatumType].append(CName)\r
1455 Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType].append(TokenSpaceGuid)\r
1456 Dict[Pcd.InitString+'_NUMSKUS_DECL_'+Pcd.DatumType].append(len(Pcd.SkuInfoList))\r
1457 if Pcd.InitString == 'UNINIT':\r
1458 Dict['PCD_DATABASE_UNINIT_EMPTY'] = ''\r
1459 else:\r
1460 Dict[Pcd.InitString+'_VALUE_'+Pcd.DatumType].append(', '.join(ValueList))\r
1461 Dict[Pcd.InitString+'_DB_VALUE_'+Pcd.DatumType].append(DbValueList)\r
1462 \r
1463 if Phase == 'PEI':\r
1464 NumberOfLocalTokens = NumberOfPeiLocalTokens\r
1465 if Phase == 'DXE':\r
1466 NumberOfLocalTokens = NumberOfDxeLocalTokens\r
1467\r
1468 Dict['TOKEN_INIT'] = ['' for x in range(NumberOfLocalTokens)]\r
1469 Dict['TOKEN_CNAME'] = ['' for x in range(NumberOfLocalTokens)]\r
1470 Dict['TOKEN_GUID'] = ['' for x in range(NumberOfLocalTokens)]\r
1471 Dict['TOKEN_TYPE'] = ['' for x in range(NumberOfLocalTokens)]\r
1472 Dict['LOCAL_TOKEN_NUMBER_DB_VALUE'] = ['' for x in range(NumberOfLocalTokens)]\r
1473 Dict['PCD_CNAME'] = ['' for x in range(NumberOfLocalTokens)]\r
1474 Dict['PCD_TOKENSPACE_MAP'] = ['' for x in range(NumberOfLocalTokens)] \r
1475 Dict['PCD_CNAME_LENGTH'] = [0 for x in range(NumberOfLocalTokens)]\r
84cc912a
FB
1476 SkuEnablePcdIndex = 0\r
1477 for Pcd in ReorderedDynPcdList:\r
e8a47801
LG
1478 CName = Pcd.TokenCName\r
1479 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1480 if Pcd.Phase != Phase:\r
1481 continue\r
1482\r
1483 TokenSpaceGuid = GuidStructureStringToGuidValueName(Pcd.TokenSpaceGuidValue) #(Platform.PackageList, TokenSpaceGuidCName))\r
1484 GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1\r
1485 if Phase == 'DXE':\r
1486 GeneratedTokenNumber -= NumberOfPeiLocalTokens\r
1487\r
84cc912a
FB
1488 if len(Pcd.SkuInfoList) > 1:\r
1489 Dict['PCD_ORDER_TOKEN_NUMBER_MAP'][GeneratedTokenNumber] = SkuEnablePcdIndex\r
1490 SkuEnablePcdIndex += 1\r
2a29017e
YZ
1491\r
1492 for PcdItem in GlobalData.MixedPcd:\r
1493 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1494 CName = PcdItem[0]\r
1495\r
1496 if GlobalData.BuildOptionPcd:\r
1497 for PcdItem in GlobalData.BuildOptionPcd:\r
1498 if (Pcd.TokenSpaceGuidCName, CName) == (PcdItem[0], PcdItem[1]):\r
1499 Pcd.DefaultValue = PcdItem[2]\r
1500 break\r
1501\r
e8a47801
LG
1502 EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s.%s" % (CName, TokenSpaceGuidCName))\r
1503 EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % Phase)\r
1504 EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber))\r
1505 \r
1506 #\r
1507 # following four Dict items hold the information for LocalTokenNumberTable\r
1508 #\r
1509 Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Init'\r
1510 if Pcd.InitString == 'UNINIT':\r
1511 Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Uninit'\r
1512\r
1513 Dict['TOKEN_CNAME'][GeneratedTokenNumber] = CName\r
1514 Dict['TOKEN_GUID'][GeneratedTokenNumber] = TokenSpaceGuid\r
1515 Dict['TOKEN_TYPE'][GeneratedTokenNumber] = ' | '.join(Pcd.TokenTypeList)\r
1516 \r
1517 if Platform.Platform.PcdInfoFlag:\r
1518 TokenSpaceGuidCNameArray = StringToArray('"' + TokenSpaceGuidCName + '"' )\r
1519 if TokenSpaceGuidCNameArray not in Dict['PCD_TOKENSPACE']:\r
1520 Dict['PCD_TOKENSPACE'].append(TokenSpaceGuidCNameArray)\r
2bc3256c 1521 Dict['PCD_TOKENSPACE_LENGTH'].append( len(TokenSpaceGuidCNameArray.split(",")) )\r
e8a47801 1522 Dict['PCD_TOKENSPACE_MAP'][GeneratedTokenNumber] = Dict['PCD_TOKENSPACE'].index(TokenSpaceGuidCNameArray)\r
2bc3256c
LG
1523 CNameBinArray = StringToArray('"' + CName + '"' )\r
1524 Dict['PCD_CNAME'][GeneratedTokenNumber] = CNameBinArray\r
e8a47801 1525 \r
2bc3256c 1526 Dict['PCD_CNAME_LENGTH'][GeneratedTokenNumber] = len(CNameBinArray.split(","))\r
e8a47801
LG
1527 \r
1528 \r
1529 Pcd.TokenTypeList = list(set(Pcd.TokenTypeList))\r
1530\r
1531 # search the Offset and Table, used by LocalTokenNumberTableOffset\r
1532 if 'PCD_TYPE_HII' in Pcd.TokenTypeList:\r
1533 # Find index by CName, TokenSpaceGuid\r
1534 Offset = GetMatchedIndex(CName, Dict['VARIABLE_HEAD_CNAME_DECL'], TokenSpaceGuid, Dict['VARIABLE_HEAD_GUID_DECL'])\r
1535 assert(Offset != -1)\r
1536 Table = Dict['VARIABLE_DB_VALUE']\r
1537 if 'PCD_TYPE_VPD' in Pcd.TokenTypeList:\r
1538 Offset = GetMatchedIndex(CName, Dict['VPD_HEAD_CNAME_DECL'], TokenSpaceGuid, Dict['VPD_HEAD_GUID_DECL'])\r
1539 assert(Offset != -1)\r
1540 Table = Dict['VPD_DB_VALUE']\r
1541 if 'PCD_TYPE_STRING' in Pcd.TokenTypeList and 'PCD_TYPE_HII' not in Pcd.TokenTypeList:\r
1542 # Find index by CName, TokenSpaceGuid\r
1543 Offset = GetMatchedIndex(CName, Dict['STRING_HEAD_CNAME_DECL'], TokenSpaceGuid, Dict['STRING_HEAD_GUID_DECL'])\r
2bc3256c 1544 Offset = PCD_STRING_INDEX_MAP[Offset]\r
e8a47801
LG
1545 assert(Offset != -1)\r
1546 Table = Dict['STRING_DB_VALUE']\r
1547 if 'PCD_TYPE_DATA' in Pcd.TokenTypeList:\r
1548 # need to store whether it is in init table or not\r
1549 Offset = GetMatchedIndex(CName, Dict[Pcd.InitString+'_CNAME_DECL_'+Pcd.DatumType], TokenSpaceGuid, Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType])\r
1550 assert(Offset != -1)\r
1551 if Pcd.InitString == 'UNINIT':\r
1552 Table = Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType]\r
1553 else:\r
1554 Table = Dict[Pcd.InitString+'_DB_VALUE_'+Pcd.DatumType] \r
1555 Dict['LOCAL_TOKEN_NUMBER_DB_VALUE'][GeneratedTokenNumber] = (Offset, Table)\r
1556\r
1557 #\r
1558 # Update VARDEF_HEADER\r
1559 #\r
1560 if 'PCD_TYPE_HII' in Pcd.TokenTypeList:\r
1561 Dict['VARDEF_HEADER'][GeneratedTokenNumber] = '_Variable_Header'\r
1562 else:\r
1563 Dict['VARDEF_HEADER'][GeneratedTokenNumber] = ''\r
1564 \r
1565 \r
1566 if Pcd.Type in gDynamicExPcd:\r
1567 \r
1568 if Phase == 'DXE':\r
1569 GeneratedTokenNumber += NumberOfPeiLocalTokens\r
1570 #\r
1571 # Per, PCD architecture specification, PCD Token Number is 1 based and 0 is defined as invalid token number.\r
1572 # For each EX type PCD, a PCD Token Number is assigned. When the\r
1573 # PCD Driver/PEIM map EX_GUID and EX_TOKEN_NUMBER to the PCD Token Number,\r
1574 # the non-EX Protocol/PPI interface can be called to get/set the value. This assumption is made by\r
1575 # Pcd Driver/PEIM in MdeModulePkg.\r
1576 # Therefore, 1 is added to GeneratedTokenNumber to generate a PCD Token Number before being inserted\r
1577 # to the EXMAPPING_TABLE.\r
1578 #\r
1579 \r
1580\r
1581 Dict['EXMAPPING_TABLE_EXTOKEN'].append(str(Pcd.TokenValue) + 'U')\r
1582 Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(str(GeneratedTokenNumber + 1) + 'U')\r
1583 Dict['EXMAPPING_TABLE_GUID_INDEX'].append(str(GuidList.index(TokenSpaceGuid)) + 'U')\r
1584\r
1585 if Platform.Platform.PcdInfoFlag:\r
1586 for index in range(len(Dict['PCD_TOKENSPACE_MAP'])):\r
1587 TokenSpaceIndex = StringTableSize\r
1588 for i in range(Dict['PCD_TOKENSPACE_MAP'][index]):\r
1589 TokenSpaceIndex += Dict['PCD_TOKENSPACE_LENGTH'][i]\r
1590 Dict['PCD_TOKENSPACE_OFFSET'].append(TokenSpaceIndex) \r
1591 for index in range(len(Dict['PCD_TOKENSPACE'])):\r
1592 StringTableSize += Dict['PCD_TOKENSPACE_LENGTH'][index]\r
2bc3256c 1593 StringTableIndex += 1\r
e8a47801
LG
1594 for index in range(len(Dict['PCD_CNAME'])):\r
1595 Dict['PCD_CNAME_OFFSET'].append(StringTableSize) \r
1596 Dict['PCD_NAME_OFFSET'].append(Dict['PCD_TOKENSPACE_OFFSET'][index])\r
1597 Dict['PCD_NAME_OFFSET'].append(StringTableSize)\r
1598 StringTableSize += Dict['PCD_CNAME_LENGTH'][index]\r
2bc3256c 1599 StringTableIndex += 1\r
e8a47801
LG
1600 if GuidList != []:\r
1601 Dict['GUID_TABLE_EMPTY'] = 'FALSE'\r
1602 Dict['GUID_TABLE_SIZE'] = str(len(GuidList)) + 'U'\r
1603 else:\r
1604 Dict['GUID_STRUCTURE'] = [GuidStringToGuidStructureString('00000000-0000-0000-0000-000000000000')]\r
1605\r
1606 if StringTableIndex == 0:\r
1607 Dict['STRING_TABLE_INDEX'].append('')\r
1608 Dict['STRING_TABLE_LENGTH'].append(1)\r
1609 Dict['STRING_TABLE_CNAME'].append('')\r
1610 Dict['STRING_TABLE_GUID'].append('')\r
1611 Dict['STRING_TABLE_VALUE'].append('{ 0 }')\r
1612 else:\r
1613 Dict['STRING_TABLE_EMPTY'] = 'FALSE'\r
1614 Dict['STRING_TABLE_SIZE'] = str(StringTableSize) + 'U'\r
1615\r
1616 if Dict['SIZE_TABLE_CNAME'] == []:\r
1617 Dict['SIZE_TABLE_CNAME'].append('')\r
1618 Dict['SIZE_TABLE_GUID'].append('')\r
2bc3256c 1619 Dict['SIZE_TABLE_CURRENT_LENGTH'].append(['0U'])\r
e8a47801
LG
1620 Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append('0U')\r
1621\r
1622 if NumberOfLocalTokens != 0:\r
1623 Dict['DATABASE_EMPTY'] = 'FALSE'\r
1624 Dict['LOCAL_TOKEN_NUMBER_TABLE_SIZE'] = NumberOfLocalTokens\r
1625 Dict['LOCAL_TOKEN_NUMBER'] = NumberOfLocalTokens\r
1626\r
1627 if NumberOfExTokens != 0:\r
1628 Dict['EXMAP_TABLE_EMPTY'] = 'FALSE'\r
1629 Dict['EXMAPPING_TABLE_SIZE'] = str(NumberOfExTokens) + 'U'\r
1630 Dict['EX_TOKEN_NUMBER'] = str(NumberOfExTokens) + 'U'\r
1631 else:\r
1632 Dict['EXMAPPING_TABLE_EXTOKEN'].append('0U')\r
1633 Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append('0U')\r
1634 Dict['EXMAPPING_TABLE_GUID_INDEX'].append('0U')\r
1635\r
1636 if NumberOfSizeItems != 0:\r
1637 Dict['SIZE_TABLE_SIZE'] = str(NumberOfSizeItems * 2) + 'U'\r
1638 \r
1639 if NumberOfSkuEnabledPcd != 0: \r
1640 Dict['SKU_HEAD_SIZE'] = str(NumberOfSkuEnabledPcd) + 'U'\r
1641 \r
1ae469b9
BF
1642 for AvailableSkuNumber in SkuObj.SkuIdNumberSet:\r
1643 if AvailableSkuNumber not in Dict['SKUID_VALUE']:\r
1644 Dict['SKUID_VALUE'].append(AvailableSkuNumber)\r
2bc3256c 1645 Dict['SKUID_VALUE'][0] = len(Dict['SKUID_VALUE']) - 1\r
e8a47801
LG
1646 \r
1647 AutoGenH.Append(gPcdDatabaseAutoGenH.Replace(Dict))\r
1648 if NumberOfLocalTokens == 0:\r
1649 AutoGenC.Append(gEmptyPcdDatabaseAutoGenC.Replace(Dict))\r
1650 else:\r
1651 #\r
1652 # Update Size Table to the right order, it should be same with LocalTokenNumberTable\r
1653 #\r
1654 SizeCNameTempList = []\r
1655 SizeGuidTempList = []\r
1656 SizeCurLenTempList = []\r
1657 SizeMaxLenTempList = []\r
1658 ReOrderFlag = True\r
1659 \r
1660 if len(Dict['SIZE_TABLE_CNAME']) == 1:\r
1661 if not (Dict['SIZE_TABLE_CNAME'][0] and Dict['SIZE_TABLE_GUID'][0]):\r
1662 ReOrderFlag = False\r
1663 \r
1664 if ReOrderFlag:\r
1665 for Count in range(len(Dict['TOKEN_CNAME'])):\r
1666 for Count1 in range(len(Dict['SIZE_TABLE_CNAME'])):\r
1667 if Dict['TOKEN_CNAME'][Count] == Dict['SIZE_TABLE_CNAME'][Count1] and \\r
1668 Dict['TOKEN_GUID'][Count] == Dict['SIZE_TABLE_GUID'][Count1]:\r
1669 SizeCNameTempList.append(Dict['SIZE_TABLE_CNAME'][Count1])\r
1670 SizeGuidTempList.append(Dict['SIZE_TABLE_GUID'][Count1])\r
1671 SizeCurLenTempList.append(Dict['SIZE_TABLE_CURRENT_LENGTH'][Count1])\r
1672 SizeMaxLenTempList.append(Dict['SIZE_TABLE_MAXIMUM_LENGTH'][Count1])\r
1673 \r
1674 for Count in range(len(Dict['SIZE_TABLE_CNAME'])):\r
1675 Dict['SIZE_TABLE_CNAME'][Count] = SizeCNameTempList[Count]\r
1676 Dict['SIZE_TABLE_GUID'][Count] = SizeGuidTempList[Count]\r
1677 Dict['SIZE_TABLE_CURRENT_LENGTH'][Count] = SizeCurLenTempList[Count]\r
1678 Dict['SIZE_TABLE_MAXIMUM_LENGTH'][Count] = SizeMaxLenTempList[Count]\r
1679 \r
1680 AutoGenC.Append(gPcdDatabaseAutoGenC.Replace(Dict))\r
1681 \r
2b8a6c44
LG
1682\r
1683# print Phase\r
e8a47801 1684 Buffer = BuildExDataBase(Dict)\r
2b8a6c44 1685 return AutoGenH, AutoGenC, Buffer,VarCheckTab\r
e8a47801 1686\r
84cc912a
FB
1687def GetOrderedDynamicPcdList(DynamicPcdList, PcdTokenNumberList):\r
1688 ReorderedDyPcdList = [None for i in range(len(DynamicPcdList))]\r
1689 for Pcd in DynamicPcdList:\r
1690 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in PcdTokenNumberList:\r
1691 ReorderedDyPcdList[PcdTokenNumberList[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]-1] = Pcd\r
1692 return ReorderedDyPcdList\r
1693\r