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