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