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