BaseTools/GenFw: recognize MM file types as EFI Boot Service Drivers.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
CommitLineData
f51461c8
LG
1## @file\r
2# Routines for generating AutoGen.h and AutoGen.c\r
3#\r
5b97eb4c 4# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
f51461c8
LG
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14## Import Modules\r
15#\r
16import string\r
333ba578
YZ
17import collections\r
18import struct\r
f51461c8
LG
19from Common import EdkLogger\r
20\r
21from Common.BuildToolError import *\r
22from Common.DataType import *\r
23from Common.Misc import *\r
24from Common.String import StringToArray\r
25from StrGather import *\r
26from GenPcdDb import CreatePcdDatabaseCode\r
333ba578 27from IdfClassObject import *\r
f51461c8
LG
28\r
29## PCD type string\r
30gItemTypeStringDatabase = {\r
31 TAB_PCDS_FEATURE_FLAG : 'FixedAtBuild',\r
32 TAB_PCDS_FIXED_AT_BUILD : 'FixedAtBuild',\r
33 TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch',\r
34 TAB_PCDS_DYNAMIC : '',\r
35 TAB_PCDS_DYNAMIC_DEFAULT : '',\r
36 TAB_PCDS_DYNAMIC_VPD : '',\r
37 TAB_PCDS_DYNAMIC_HII : '',\r
38 TAB_PCDS_DYNAMIC_EX : '',\r
39 TAB_PCDS_DYNAMIC_EX_DEFAULT : '',\r
40 TAB_PCDS_DYNAMIC_EX_VPD : '',\r
41 TAB_PCDS_DYNAMIC_EX_HII : '',\r
42}\r
43\r
44## Dynamic PCD types\r
45gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII]\r
46\r
47## Dynamic-ex PCD types\r
48gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII]\r
49\r
50## Datum size\r
51gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}\r
52gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}\r
53gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}\r
54\r
55## AutoGen File Header Templates\r
56gAutoGenHeaderString = TemplateString("""\\r
57/**\r
58 DO NOT EDIT\r
59 FILE auto-generated\r
60 Module name:\r
61 ${FileName}\r
62 Abstract: Auto-generated ${FileName} for building module or library.\r
63**/\r
64""")\r
65\r
66gAutoGenHPrologueString = TemplateString("""\r
67#ifndef _${File}_${Guid}\r
68#define _${File}_${Guid}\r
69\r
70""")\r
71\r
72gAutoGenHCppPrologueString = """\\r
73#ifdef __cplusplus\r
74extern "C" {\r
75#endif\r
76\r
77"""\r
78\r
79gAutoGenHEpilogueString = """\r
80\r
81#ifdef __cplusplus\r
82}\r
83#endif\r
84\r
85#endif\r
86"""\r
87\r
88## PEI Core Entry Point Templates\r
89gPeiCoreEntryPointPrototype = TemplateString("""\r
90${BEGIN}\r
91VOID\r
92EFIAPI\r
93${Function} (\r
94 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
95 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
96 IN VOID *Context\r
97 );\r
98${END}\r
99""")\r
100\r
101gPeiCoreEntryPointString = TemplateString("""\r
102${BEGIN}\r
103VOID\r
104EFIAPI\r
105ProcessModuleEntryPointList (\r
106 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
107 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
108 IN VOID *Context\r
109 )\r
110\r
111{\r
112 ${Function} (SecCoreData, PpiList, Context);\r
113}\r
114${END}\r
115""")\r
116\r
117\r
118## DXE Core Entry Point Templates\r
119gDxeCoreEntryPointPrototype = TemplateString("""\r
120${BEGIN}\r
121VOID\r
122EFIAPI\r
123${Function} (\r
124 IN VOID *HobStart\r
125 );\r
126${END}\r
127""")\r
128\r
129gDxeCoreEntryPointString = TemplateString("""\r
130${BEGIN}\r
131VOID\r
132EFIAPI\r
133ProcessModuleEntryPointList (\r
134 IN VOID *HobStart\r
135 )\r
136\r
137{\r
138 ${Function} (HobStart);\r
139}\r
140${END}\r
141""")\r
142\r
143## PEIM Entry Point Templates\r
144gPeimEntryPointPrototype = TemplateString("""\r
145${BEGIN}\r
146EFI_STATUS\r
147EFIAPI\r
148${Function} (\r
149 IN EFI_PEI_FILE_HANDLE FileHandle,\r
150 IN CONST EFI_PEI_SERVICES **PeiServices\r
151 );\r
152${END}\r
153""")\r
154\r
155gPeimEntryPointString = [\r
156TemplateString("""\r
157GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
158\r
159EFI_STATUS\r
160EFIAPI\r
161ProcessModuleEntryPointList (\r
162 IN EFI_PEI_FILE_HANDLE FileHandle,\r
163 IN CONST EFI_PEI_SERVICES **PeiServices\r
164 )\r
165\r
166{\r
167 return EFI_SUCCESS;\r
168}\r
169"""),\r
170TemplateString("""\r
171GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
172${BEGIN}\r
173EFI_STATUS\r
174EFIAPI\r
175ProcessModuleEntryPointList (\r
176 IN EFI_PEI_FILE_HANDLE FileHandle,\r
177 IN CONST EFI_PEI_SERVICES **PeiServices\r
178 )\r
179\r
180{\r
181 return ${Function} (FileHandle, PeiServices);\r
182}\r
183${END}\r
184"""),\r
185TemplateString("""\r
186GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
187\r
188EFI_STATUS\r
189EFIAPI\r
190ProcessModuleEntryPointList (\r
191 IN EFI_PEI_FILE_HANDLE FileHandle,\r
192 IN CONST EFI_PEI_SERVICES **PeiServices\r
193 )\r
194\r
195{\r
196 EFI_STATUS Status;\r
197 EFI_STATUS CombinedStatus;\r
198\r
199 CombinedStatus = EFI_LOAD_ERROR;\r
200${BEGIN}\r
201 Status = ${Function} (FileHandle, PeiServices);\r
202 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
203 CombinedStatus = Status;\r
204 }\r
205${END}\r
206 return CombinedStatus;\r
207}\r
208""")\r
209]\r
210\r
211## SMM_CORE Entry Point Templates\r
212gSmmCoreEntryPointPrototype = TemplateString("""\r
213${BEGIN}\r
214EFI_STATUS\r
215EFIAPI\r
216${Function} (\r
217 IN EFI_HANDLE ImageHandle,\r
218 IN EFI_SYSTEM_TABLE *SystemTable\r
219 );\r
220${END}\r
221""")\r
222\r
223gSmmCoreEntryPointString = TemplateString("""\r
224${BEGIN}\r
225const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
226const UINT32 _gDxeRevision = ${PiSpecVersion};\r
227\r
228EFI_STATUS\r
229EFIAPI\r
230ProcessModuleEntryPointList (\r
231 IN EFI_HANDLE ImageHandle,\r
232 IN EFI_SYSTEM_TABLE *SystemTable\r
233 )\r
234{\r
235 return ${Function} (ImageHandle, SystemTable);\r
236}\r
237${END}\r
238""")\r
239\r
240## DXE SMM Entry Point Templates\r
241gDxeSmmEntryPointPrototype = TemplateString("""\r
242${BEGIN}\r
243EFI_STATUS\r
244EFIAPI\r
245${Function} (\r
246 IN EFI_HANDLE ImageHandle,\r
247 IN EFI_SYSTEM_TABLE *SystemTable\r
248 );\r
249${END}\r
250""")\r
251\r
252gDxeSmmEntryPointString = [\r
253TemplateString("""\r
254const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
255const UINT32 _gDxeRevision = ${PiSpecVersion};\r
256\r
257EFI_STATUS\r
258EFIAPI\r
259ProcessModuleEntryPointList (\r
260 IN EFI_HANDLE ImageHandle,\r
261 IN EFI_SYSTEM_TABLE *SystemTable\r
262 )\r
263\r
264{\r
265 return EFI_SUCCESS;\r
266}\r
267"""),\r
268TemplateString("""\r
269const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
270const UINT32 _gDxeRevision = ${PiSpecVersion};\r
271\r
272static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
273static EFI_STATUS mDriverEntryPointStatus;\r
274\r
275VOID\r
276EFIAPI\r
277ExitDriver (\r
278 IN EFI_STATUS Status\r
279 )\r
280{\r
281 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
282 mDriverEntryPointStatus = Status;\r
283 }\r
284 LongJump (&mJumpContext, (UINTN)-1);\r
285 ASSERT (FALSE);\r
286}\r
287\r
288EFI_STATUS\r
289EFIAPI\r
290ProcessModuleEntryPointList (\r
291 IN EFI_HANDLE ImageHandle,\r
292 IN EFI_SYSTEM_TABLE *SystemTable\r
293 )\r
294{\r
295 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
296\r
297${BEGIN}\r
298 if (SetJump (&mJumpContext) == 0) {\r
299 ExitDriver (${Function} (ImageHandle, SystemTable));\r
300 ASSERT (FALSE);\r
301 }\r
302${END}\r
303\r
304 return mDriverEntryPointStatus;\r
305}\r
306""")\r
307]\r
308\r
309## UEFI Driver Entry Point Templates\r
310gUefiDriverEntryPointPrototype = TemplateString("""\r
311${BEGIN}\r
312EFI_STATUS\r
313EFIAPI\r
314${Function} (\r
315 IN EFI_HANDLE ImageHandle,\r
316 IN EFI_SYSTEM_TABLE *SystemTable\r
317 );\r
318${END}\r
319""")\r
320\r
321gUefiDriverEntryPointString = [\r
322TemplateString("""\r
323const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
324const UINT32 _gDxeRevision = ${PiSpecVersion};\r
325\r
326EFI_STATUS\r
327EFIAPI\r
328ProcessModuleEntryPointList (\r
329 IN EFI_HANDLE ImageHandle,\r
330 IN EFI_SYSTEM_TABLE *SystemTable\r
331 )\r
332{\r
333 return EFI_SUCCESS;\r
334}\r
335"""),\r
336TemplateString("""\r
337const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
338const UINT32 _gDxeRevision = ${PiSpecVersion};\r
339\r
340${BEGIN}\r
341EFI_STATUS\r
342EFIAPI\r
343ProcessModuleEntryPointList (\r
344 IN EFI_HANDLE ImageHandle,\r
345 IN EFI_SYSTEM_TABLE *SystemTable\r
346 )\r
347\r
348{\r
349 return ${Function} (ImageHandle, SystemTable);\r
350}\r
351${END}\r
352VOID\r
353EFIAPI\r
354ExitDriver (\r
355 IN EFI_STATUS Status\r
356 )\r
357{\r
358 if (EFI_ERROR (Status)) {\r
359 ProcessLibraryDestructorList (gImageHandle, gST);\r
360 }\r
361 gBS->Exit (gImageHandle, Status, 0, NULL);\r
362}\r
363"""),\r
364TemplateString("""\r
365const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
366const UINT32 _gDxeRevision = ${PiSpecVersion};\r
367\r
368static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
369static EFI_STATUS mDriverEntryPointStatus;\r
370\r
371EFI_STATUS\r
372EFIAPI\r
373ProcessModuleEntryPointList (\r
374 IN EFI_HANDLE ImageHandle,\r
375 IN EFI_SYSTEM_TABLE *SystemTable\r
376 )\r
377{\r
378 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
379 ${BEGIN}\r
380 if (SetJump (&mJumpContext) == 0) {\r
381 ExitDriver (${Function} (ImageHandle, SystemTable));\r
382 ASSERT (FALSE);\r
383 }\r
384 ${END}\r
385 return mDriverEntryPointStatus;\r
386}\r
387\r
388VOID\r
389EFIAPI\r
390ExitDriver (\r
391 IN EFI_STATUS Status\r
392 )\r
393{\r
394 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
395 mDriverEntryPointStatus = Status;\r
396 }\r
397 LongJump (&mJumpContext, (UINTN)-1);\r
398 ASSERT (FALSE);\r
399}\r
400""")\r
401]\r
402\r
403\r
404## UEFI Application Entry Point Templates\r
405gUefiApplicationEntryPointPrototype = TemplateString("""\r
406${BEGIN}\r
407EFI_STATUS\r
408EFIAPI\r
409${Function} (\r
410 IN EFI_HANDLE ImageHandle,\r
411 IN EFI_SYSTEM_TABLE *SystemTable\r
412 );\r
413${END}\r
414""")\r
415\r
416gUefiApplicationEntryPointString = [\r
417TemplateString("""\r
418const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
419\r
420EFI_STATUS\r
421EFIAPI\r
422ProcessModuleEntryPointList (\r
423 IN EFI_HANDLE ImageHandle,\r
424 IN EFI_SYSTEM_TABLE *SystemTable\r
425 )\r
426{\r
427 return EFI_SUCCESS;\r
428}\r
429"""),\r
430TemplateString("""\r
431const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
432\r
433${BEGIN}\r
434EFI_STATUS\r
435EFIAPI\r
436ProcessModuleEntryPointList (\r
437 IN EFI_HANDLE ImageHandle,\r
438 IN EFI_SYSTEM_TABLE *SystemTable\r
439 )\r
440\r
441{\r
442 return ${Function} (ImageHandle, SystemTable);\r
443}\r
444${END}\r
445VOID\r
446EFIAPI\r
447ExitDriver (\r
448 IN EFI_STATUS Status\r
449 )\r
450{\r
451 if (EFI_ERROR (Status)) {\r
452 ProcessLibraryDestructorList (gImageHandle, gST);\r
453 }\r
454 gBS->Exit (gImageHandle, Status, 0, NULL);\r
455}\r
456"""),\r
457TemplateString("""\r
458const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
459\r
460EFI_STATUS\r
461EFIAPI\r
462ProcessModuleEntryPointList (\r
463 IN EFI_HANDLE ImageHandle,\r
464 IN EFI_SYSTEM_TABLE *SystemTable\r
465 )\r
466\r
467{\r
468 ${BEGIN}\r
469 if (SetJump (&mJumpContext) == 0) {\r
470 ExitDriver (${Function} (ImageHandle, SystemTable));\r
471 ASSERT (FALSE);\r
472 }\r
473 ${END}\r
474 return mDriverEntryPointStatus;\r
475}\r
476\r
477static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
478static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
479\r
480VOID\r
481EFIAPI\r
482ExitDriver (\r
483 IN EFI_STATUS Status\r
484 )\r
485{\r
486 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
487 mDriverEntryPointStatus = Status;\r
488 }\r
489 LongJump (&mJumpContext, (UINTN)-1);\r
490 ASSERT (FALSE);\r
491}\r
492""")\r
493]\r
494\r
495## UEFI Unload Image Templates\r
496gUefiUnloadImagePrototype = TemplateString("""\r
497${BEGIN}\r
498EFI_STATUS\r
499EFIAPI\r
500${Function} (\r
501 IN EFI_HANDLE ImageHandle\r
502 );\r
503${END}\r
504""")\r
505\r
506gUefiUnloadImageString = [\r
507TemplateString("""\r
508GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
509\r
510EFI_STATUS\r
511EFIAPI\r
512ProcessModuleUnloadList (\r
513 IN EFI_HANDLE ImageHandle\r
514 )\r
515{\r
516 return EFI_SUCCESS;\r
517}\r
518"""),\r
519TemplateString("""\r
520GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
521\r
522${BEGIN}\r
523EFI_STATUS\r
524EFIAPI\r
525ProcessModuleUnloadList (\r
526 IN EFI_HANDLE ImageHandle\r
527 )\r
528{\r
529 return ${Function} (ImageHandle);\r
530}\r
531${END}\r
532"""),\r
533TemplateString("""\r
534GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
535\r
536EFI_STATUS\r
537EFIAPI\r
538ProcessModuleUnloadList (\r
539 IN EFI_HANDLE ImageHandle\r
540 )\r
541{\r
542 EFI_STATUS Status;\r
543\r
544 Status = EFI_SUCCESS;\r
545${BEGIN}\r
546 if (EFI_ERROR (Status)) {\r
547 ${Function} (ImageHandle);\r
548 } else {\r
549 Status = ${Function} (ImageHandle);\r
550 }\r
551${END}\r
552 return Status;\r
553}\r
554""")\r
555]\r
556\r
557gLibraryStructorPrototype = {\r
558'BASE' : TemplateString("""${BEGIN}\r
559RETURN_STATUS\r
560EFIAPI\r
561${Function} (\r
562 VOID\r
563 );${END}\r
564"""),\r
565\r
566'PEI' : TemplateString("""${BEGIN}\r
567EFI_STATUS\r
568EFIAPI\r
569${Function} (\r
570 IN EFI_PEI_FILE_HANDLE FileHandle,\r
571 IN CONST EFI_PEI_SERVICES **PeiServices\r
572 );${END}\r
573"""),\r
574\r
575'DXE' : TemplateString("""${BEGIN}\r
576EFI_STATUS\r
577EFIAPI\r
578${Function} (\r
579 IN EFI_HANDLE ImageHandle,\r
580 IN EFI_SYSTEM_TABLE *SystemTable\r
581 );${END}\r
582"""),\r
583}\r
584\r
585gLibraryStructorCall = {\r
586'BASE' : TemplateString("""${BEGIN}\r
587 Status = ${Function} ();\r
588 ASSERT_EFI_ERROR (Status);${END}\r
589"""),\r
590\r
591'PEI' : TemplateString("""${BEGIN}\r
592 Status = ${Function} (FileHandle, PeiServices);\r
593 ASSERT_EFI_ERROR (Status);${END}\r
594"""),\r
595\r
596'DXE' : TemplateString("""${BEGIN}\r
597 Status = ${Function} (ImageHandle, SystemTable);\r
598 ASSERT_EFI_ERROR (Status);${END}\r
599"""),\r
600}\r
601\r
602## Library Constructor and Destructor Templates\r
603gLibraryString = {\r
604'BASE' : TemplateString("""\r
605${BEGIN}${FunctionPrototype}${END}\r
606\r
607VOID\r
608EFIAPI\r
609ProcessLibrary${Type}List (\r
610 VOID\r
611 )\r
612{\r
613${BEGIN} EFI_STATUS Status;\r
614${FunctionCall}${END}\r
615}\r
616"""),\r
617\r
618'PEI' : TemplateString("""\r
619${BEGIN}${FunctionPrototype}${END}\r
620\r
621VOID\r
622EFIAPI\r
623ProcessLibrary${Type}List (\r
624 IN EFI_PEI_FILE_HANDLE FileHandle,\r
625 IN CONST EFI_PEI_SERVICES **PeiServices\r
626 )\r
627{\r
628${BEGIN} EFI_STATUS Status;\r
629${FunctionCall}${END}\r
630}\r
631"""),\r
632\r
633'DXE' : TemplateString("""\r
634${BEGIN}${FunctionPrototype}${END}\r
635\r
636VOID\r
637EFIAPI\r
638ProcessLibrary${Type}List (\r
639 IN EFI_HANDLE ImageHandle,\r
640 IN EFI_SYSTEM_TABLE *SystemTable\r
641 )\r
642{\r
643${BEGIN} EFI_STATUS Status;\r
644${FunctionCall}${END}\r
645}\r
646"""),\r
647}\r
648\r
649gBasicHeaderFile = "Base.h"\r
650\r
651gModuleTypeHeaderFile = {\r
652 "BASE" : [gBasicHeaderFile],\r
653 "SEC" : ["PiPei.h", "Library/DebugLib.h"],\r
654 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],\r
655 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],\r
656 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],\r
657 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
658 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
659 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
660 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
661 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
662 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
663 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
664 "USER_DEFINED" : [gBasicHeaderFile]\r
665}\r
666\r
667## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName \r
668# the TokenName and Guid comparison to avoid define name collisions.\r
669#\r
670# @param Info The ModuleAutoGen object\r
671# @param AutoGenH The TemplateString object for header file\r
672#\r
673#\r
674def DynExPcdTokenNumberMapping(Info, AutoGenH):\r
675 ExTokenCNameList = []\r
676 PcdExList = []\r
d590cce5
YZ
677 # Even it is the Library, the PCD is saved in the ModulePcdList\r
678 PcdList = Info.ModulePcdList\r
f51461c8
LG
679 for Pcd in PcdList:\r
680 if Pcd.Type in gDynamicExPcd:\r
681 ExTokenCNameList.append(Pcd.TokenCName)\r
682 PcdExList.append(Pcd)\r
683 if len(ExTokenCNameList) == 0:\r
684 return\r
685 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')\r
686 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
687 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter. \r
688 # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
689 TokenCNameList = []\r
690 for TokenCName in ExTokenCNameList:\r
691 if TokenCName in TokenCNameList:\r
692 continue\r
693 Index = 0\r
694 Count = ExTokenCNameList.count(TokenCName)\r
695 for Pcd in PcdExList:\r
2a29017e
YZ
696 RealTokenCName = Pcd.TokenCName\r
697 for PcdItem in GlobalData.MixedPcd:\r
698 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
699 RealTokenCName = PcdItem[0]\r
700 break\r
f51461c8
LG
701 if Pcd.TokenCName == TokenCName:\r
702 Index = Index + 1\r
703 if Index == 1:\r
2a29017e 704 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName))\r
f51461c8 705 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 706 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
707 else:\r
708 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 709 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
710 if Index == Count:\r
711 AutoGenH.Append('0 \\\n )\n')\r
712 TokenCNameList.append(TokenCName)\r
713 \r
714 TokenCNameList = []\r
715 for TokenCName in ExTokenCNameList:\r
716 if TokenCName in TokenCNameList:\r
717 continue\r
718 Index = 0\r
719 Count = ExTokenCNameList.count(TokenCName)\r
720 for Pcd in PcdExList:\r
2a29017e
YZ
721 RealTokenCName = Pcd.TokenCName\r
722 for PcdItem in GlobalData.MixedPcd:\r
723 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
724 RealTokenCName = PcdItem[0]\r
725 break\r
f51461c8
LG
726 if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:\r
727 Index = Index + 1\r
728 if Index == 1:\r
2a29017e 729 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName))\r
9023704f 730 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')\r
f51461c8 731 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 732 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
733 else:\r
734 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 735 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
736 if Index == Count:\r
737 AutoGenH.Append('0 \\\n )\n')\r
738 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID. \r
739 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
740 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
741 # COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
742 AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'\r
2a29017e 743 % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
f51461c8
LG
744 TokenCNameList.append(TokenCName)\r
745\r
2f5acc3b
BF
746def GetPcdSize(Pcd):\r
747 if Pcd.DatumType == 'VOID*':\r
748 Value = Pcd.DefaultValue\r
749 if Value in [None, '']:\r
750 return 1\r
751 elif Value[0] == 'L':\r
752 return (len(Value) - 2) * 2\r
753 elif Value[0] == '{':\r
754 return len(Value.split(','))\r
755 else:\r
756 return len(Value) - 1\r
757 if Pcd.DatumType == 'UINT64':\r
758 return 8\r
759 if Pcd.DatumType == 'UINT32':\r
760 return 4\r
761 if Pcd.DatumType == 'UINT16':\r
762 return 2\r
763 if Pcd.DatumType == 'UINT8':\r
764 return 1\r
765 if Pcd.DatumType == 'BOOLEAN':\r
766 return 1\r
767\r
768\r
f51461c8
LG
769## Create code for module PCDs\r
770#\r
771# @param Info The ModuleAutoGen object\r
772# @param AutoGenC The TemplateString object for C code\r
773# @param AutoGenH The TemplateString object for header file\r
774# @param Pcd The PCD object\r
775#\r
776def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
777 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
778 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
2a29017e
YZ
779 #\r
780 # Write PCDs\r
781 #\r
782 TokenCName = Pcd.TokenCName\r
783 for PcdItem in GlobalData.MixedPcd:\r
784 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
785 TokenCName = PcdItem[0]\r
786 break\r
787 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
788 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
789 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
790 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
763e8edf
YZ
791\r
792 if GlobalData.BuildOptionPcd:\r
793 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 794 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
795 Pcd.DefaultValue = PcdItem[2]\r
796 break\r
2f5acc3b 797 \r
f51461c8
LG
798 if Pcd.Type in gDynamicExPcd:\r
799 TokenNumber = int(Pcd.TokenValue, 0)\r
800 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
801 # different Guids but same TokenCName\r
2a29017e 802 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
803 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
804 else:\r
805 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
806 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
807 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
808 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
809 # report warning message notify the PI that they are attempting to build a module \r
810 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
811 # will not be added into the Database unless it is used by other modules that are \r
812 # included in the FDF file. \r
813 # In this case, just assign an invalid token number to make it pass build.\r
814 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
815 TokenNumber = 0\r
816 else:\r
817 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 818 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
819 ExtraData="[%s]" % str(Info))\r
820 else:\r
821 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
822 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))\r
823\r
2a29017e 824 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
f51461c8
LG
825 if Pcd.Type not in gItemTypeStringDatabase:\r
826 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 827 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
828 ExtraData="[%s]" % str(Info))\r
829 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
830 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 831 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
832 ExtraData="[%s]" % str(Info))\r
833\r
834 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
835 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
2a29017e
YZ
836 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
837 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
838 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName\r
839 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
2f5acc3b 840 \r
f51461c8
LG
841 PcdExCNameList = []\r
842 if Pcd.Type in gDynamicExPcd:\r
843 if Info.IsLibrary:\r
844 PcdList = Info.LibraryPcdList\r
845 else:\r
846 PcdList = Info.ModulePcdList\r
847 for PcdModule in PcdList:\r
848 if PcdModule.Type in gDynamicExPcd:\r
849 PcdExCNameList.append(PcdModule.TokenCName)\r
850 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
851 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
852 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
853 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
854 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
855 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
856 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 857 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
858 if Pcd.DatumType == 'VOID*':\r
859 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 860 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
861 else:\r
862 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 863 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
864 else:\r
865 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
866 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 867 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
868 if Pcd.DatumType == 'VOID*':\r
869 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 870 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
871 else:\r
872 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 873 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8 874 elif Pcd.Type in gDynamicPcd:\r
38b986e3
YZ
875 PcdList = []\r
876 PcdCNameList = []\r
877 PcdList.extend(Info.LibraryPcdList)\r
878 PcdList.extend(Info.ModulePcdList)\r
879 for PcdModule in PcdList:\r
880 if PcdModule.Type in gDynamicPcd:\r
881 PcdCNameList.append(PcdModule.TokenCName)\r
882 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 883 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 884 else:\r
38b986e3
YZ
885 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
886 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
887 if Pcd.DatumType == 'VOID*':\r
888 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
889 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
890 else:\r
891 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
892 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8 893 else:\r
2a29017e 894 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
f51461c8
LG
895 Const = 'const'\r
896 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
897 Const = ''\r
898 Type = ''\r
899 Array = ''\r
900 Value = Pcd.DefaultValue\r
901 Unicode = False\r
902 ValueNumber = 0\r
903\r
904 if Pcd.DatumType == 'BOOLEAN':\r
905 BoolValue = Value.upper()\r
906 if BoolValue == 'TRUE' or BoolValue == '1':\r
907 Value = '1U'\r
908 elif BoolValue == 'FALSE' or BoolValue == '0':\r
909 Value = '0U'\r
910\r
911 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:\r
912 try:\r
913 if Value.upper().startswith('0X'):\r
914 ValueNumber = int (Value, 16)\r
915 else:\r
916 ValueNumber = int (Value)\r
917 except:\r
918 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 919 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
920 ExtraData="[%s]" % str(Info))\r
921 if Pcd.DatumType == 'UINT64':\r
922 if ValueNumber < 0:\r
923 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 924 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
925 ExtraData="[%s]" % str(Info))\r
926 elif ValueNumber >= 0x10000000000000000:\r
927 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 928 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
929 ExtraData="[%s]" % str(Info))\r
930 if not Value.endswith('ULL'):\r
931 Value += 'ULL'\r
932 elif Pcd.DatumType == 'UINT32':\r
933 if ValueNumber < 0:\r
934 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 935 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
936 ExtraData="[%s]" % str(Info))\r
937 elif ValueNumber >= 0x100000000:\r
938 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 939 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
940 ExtraData="[%s]" % str(Info))\r
941 if not Value.endswith('U'):\r
942 Value += 'U'\r
943 elif Pcd.DatumType == 'UINT16':\r
944 if ValueNumber < 0:\r
945 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 946 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
947 ExtraData="[%s]" % str(Info))\r
948 elif ValueNumber >= 0x10000:\r
949 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 950 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
951 ExtraData="[%s]" % str(Info))\r
952 if not Value.endswith('U'):\r
953 Value += 'U' \r
954 elif Pcd.DatumType == 'UINT8':\r
955 if ValueNumber < 0:\r
956 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 957 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
958 ExtraData="[%s]" % str(Info))\r
959 elif ValueNumber >= 0x100:\r
960 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 961 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
962 ExtraData="[%s]" % str(Info))\r
963 if not Value.endswith('U'):\r
964 Value += 'U'\r
965 if Pcd.DatumType == 'VOID*':\r
966 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
967 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 968 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
969 ExtraData="[%s]" % str(Info))\r
970\r
971 ArraySize = int(Pcd.MaxDatumSize, 0)\r
972 if Value[0] == '{':\r
973 Type = '(VOID *)'\r
974 else:\r
975 if Value[0] == 'L':\r
976 Unicode = True\r
977 Value = Value.lstrip('L') #.strip('"')\r
978 Value = eval(Value) # translate escape character\r
979 NewValue = '{'\r
980 for Index in range(0,len(Value)):\r
981 if Unicode:\r
982 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
983 else:\r
984 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
985 if Unicode:\r
986 ArraySize = ArraySize / 2;\r
987\r
988 if ArraySize < (len(Value) + 1):\r
989 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 990 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
991 ExtraData="[%s]" % str(Info))\r
992 Value = NewValue + '0 }'\r
993 Array = '[%d]' % ArraySize\r
994 #\r
995 # skip casting for fixed at build since it breaks ARM assembly.\r
996 # Long term we need PCD macros that work in assembly\r
997 #\r
998 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
999 Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
1000\r
1001 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
2a29017e 1002 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
f51461c8 1003 else:\r
2a29017e 1004 PcdValueName = '_PCD_VALUE_' + TokenCName\r
f51461c8
LG
1005 \r
1006 if Pcd.DatumType == 'VOID*':\r
1007 #\r
1008 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
1009 #\r
1010 if Unicode:\r
f51461c8
LG
1011 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1012 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1013 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
1014 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
1015 else:\r
f51461c8
LG
1016 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1017 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1018 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
1019 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1020 \r
1021 PcdDataSize = GetPcdSize(Pcd)\r
1022 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1023 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1024 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1025 \r
1026 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1027 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
1028 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1029 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1030 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8
LG
1031 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1032 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1033 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1034 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1035 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1036 \r
1037 PcdDataSize = GetPcdSize(Pcd)\r
1038 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1039 \r
1040 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1041 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1042 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8 1043 else:\r
2f5acc3b
BF
1044 PcdDataSize = GetPcdSize(Pcd)\r
1045 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1046 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1047 \r
f51461c8
LG
1048 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1049 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1050 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1051 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
1052\r
1053 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1054 if Pcd.DatumType == 'VOID*':\r
e70504cd
LG
1055 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
1056 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
f51461c8
LG
1057 else:\r
1058 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
82a6a960 1059 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))\r
f51461c8
LG
1060 else:\r
1061 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1062\r
1063## Create code for library module PCDs\r
1064#\r
1065# @param Info The ModuleAutoGen object\r
1066# @param AutoGenC The TemplateString object for C code\r
1067# @param AutoGenH The TemplateString object for header file\r
1068# @param Pcd The PCD object\r
1069#\r
1070def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
1071 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
1072 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1073 TokenCName = Pcd.TokenCName\r
2a29017e
YZ
1074 for PcdItem in GlobalData.MixedPcd:\r
1075 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1076 TokenCName = PcdItem[0]\r
1077 break\r
f51461c8 1078 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
2a29017e
YZ
1079 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
1080 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
1081 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
763e8edf
YZ
1082\r
1083 if GlobalData.BuildOptionPcd:\r
1084 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 1085 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
1086 Pcd.DefaultValue = PcdItem[2]\r
1087 break\r
1088\r
f51461c8
LG
1089 #\r
1090 # Write PCDs\r
1091 #\r
1092 if Pcd.Type in gDynamicExPcd:\r
1093 TokenNumber = int(Pcd.TokenValue, 0)\r
1094 else:\r
1095 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
1096 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
1097 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
1098 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
1099 # report warning message notify the PI that they are attempting to build a module \r
1100 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
1101 # will not be added into the Database unless it is used by other modules that are \r
1102 # included in the FDF file. \r
1103 # In this case, just assign an invalid token number to make it pass build.\r
1104 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
1105 TokenNumber = 0\r
1106 else:\r
1107 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1108 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1109 ExtraData="[%s]" % str(Info))\r
1110 else:\r
1111 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
1112\r
1113 if Pcd.Type not in gItemTypeStringDatabase:\r
1114 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1115 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1116 ExtraData="[%s]" % str(Info))\r
1117 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
1118 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1119 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1120 ExtraData="[%s]" % str(Info))\r
1121\r
1122 DatumType = Pcd.DatumType\r
1123 DatumSize = gDatumSizeStringDatabaseH[DatumType]\r
1124 DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]\r
1125 GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
1126 SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
82a6a960 1127 SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName\r
2a29017e 1128 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
f51461c8
LG
1129\r
1130 Type = ''\r
1131 Array = ''\r
1132 if Pcd.DatumType == 'VOID*':\r
d66670f9
YZ
1133 if Pcd.DefaultValue[0]== '{':\r
1134 Type = '(VOID *)'\r
f51461c8
LG
1135 Array = '[]'\r
1136 PcdItemType = Pcd.Type\r
1137 PcdExCNameList = []\r
1138 if PcdItemType in gDynamicExPcd:\r
2a29017e 1139 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
1140 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
1141 \r
1142 if Info.IsLibrary:\r
1143 PcdList = Info.LibraryPcdList\r
1144 else:\r
1145 PcdList = Info.ModulePcdList\r
1146 for PcdModule in PcdList:\r
1147 if PcdModule.Type in gDynamicExPcd:\r
1148 PcdExCNameList.append(PcdModule.TokenCName)\r
1149 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
1150 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
1151 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
1152 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
1153 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
1154 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1155 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
d590cce5 1156 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1157 if Pcd.DatumType == 'VOID*':\r
1158 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1159 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1160 else:\r
1161 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1162 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1163 else:\r
1164 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1165 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 1166 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1167 if Pcd.DatumType == 'VOID*':\r
1168 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1169 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1170 else:\r
1171 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1172 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1173 else:\r
1174 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))\r
1175 if PcdItemType in gDynamicPcd:\r
38b986e3
YZ
1176 PcdList = []\r
1177 PcdCNameList = []\r
1178 PcdList.extend(Info.LibraryPcdList)\r
1179 PcdList.extend(Info.ModulePcdList)\r
1180 for PcdModule in PcdList:\r
1181 if PcdModule.Type in gDynamicPcd:\r
1182 PcdCNameList.append(PcdModule.TokenCName)\r
1183 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 1184 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName.They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 1185 else:\r
38b986e3
YZ
1186 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
1187 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
1188 if DatumType == 'VOID*':\r
1189 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
1190 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
1191 else:\r
1192 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
1193 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8
LG
1194 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1195 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
d66670f9
YZ
1196 if DatumType == 'VOID*':\r
1197 ArraySize = int(Pcd.MaxDatumSize, 0)\r
1198 if Pcd.DefaultValue[0] == 'L':\r
1199 ArraySize = ArraySize / 2\r
1200 Array = '[%d]' % ArraySize\r
1201 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
1202 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
1203 else:\r
1204 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))\r
f51461c8 1205 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
a6c31c6d 1206 PcdDataSize = GetPcdSize(Pcd)\r
27187d24 1207 if Pcd.DatumType == 'VOID*':\r
2a29017e
YZ
1208 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, TokenCName, TokenCName))\r
1209 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, TokenCName, TokenCName))\r
a6c31c6d 1210 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
27187d24
LG
1211 else:\r
1212 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
1213 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))\r
a6c31c6d
YZ
1214 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1215\r
2f5acc3b
BF
1216 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1217 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1218 \r
f51461c8
LG
1219 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
1220 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
7256bd55 1221 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
41ab153f 1222 if DatumType == 'VOID*' and Array == '[]':\r
2f5acc3b 1223 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
f51461c8
LG
1224 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
1225 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
1226 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1227 \r
c9da41b2 1228 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):\r
687bde9c 1229 if Pcd.DatumType == 'VOID*':\r
7256bd55
YZ
1230 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))\r
1231 else:\r
1232 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
f51461c8 1233 \r
2f5acc3b
BF
1234 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
1235 PcdDataSize = GetPcdSize(Pcd)\r
1236 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1237 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName))\r
f51461c8
LG
1238\r
1239## Create code for library constructor\r
1240#\r
1241# @param Info The ModuleAutoGen object\r
1242# @param AutoGenC The TemplateString object for C code\r
1243# @param AutoGenH The TemplateString object for header file\r
1244#\r
1245def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1246 #\r
1247 # Library Constructors\r
1248 #\r
1249 ConstructorPrototypeString = TemplateString()\r
1250 ConstructorCallingString = TemplateString()\r
1251 if Info.IsLibrary:\r
1252 DependentLibraryList = [Info.Module]\r
1253 else:\r
1254 DependentLibraryList = Info.DependentLibraryList\r
1255 for Lib in DependentLibraryList:\r
1256 if len(Lib.ConstructorList) <= 0:\r
1257 continue\r
1258 Dict = {'Function':Lib.ConstructorList}\r
1259 if Lib.ModuleType in ['BASE', 'SEC']:\r
1260 ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1261 ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1262 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1263 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1264 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1265 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1266 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1267 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1268 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1269\r
1270 if str(ConstructorPrototypeString) == '':\r
1271 ConstructorPrototypeList = []\r
1272 else:\r
1273 ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
1274 if str(ConstructorCallingString) == '':\r
1275 ConstructorCallingList = []\r
1276 else:\r
1277 ConstructorCallingList = [str(ConstructorCallingString)]\r
1278\r
1279 Dict = {\r
1280 'Type' : 'Constructor',\r
1281 'FunctionPrototype' : ConstructorPrototypeList,\r
1282 'FunctionCall' : ConstructorCallingList\r
1283 }\r
1284 if Info.IsLibrary:\r
1285 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1286 else:\r
1287 if Info.ModuleType in ['BASE', 'SEC']:\r
1288 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1289 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1290 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1291 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1292 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1293 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1294\r
1295## Create code for library destructor\r
1296#\r
1297# @param Info The ModuleAutoGen object\r
1298# @param AutoGenC The TemplateString object for C code\r
1299# @param AutoGenH The TemplateString object for header file\r
1300#\r
1301def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1302 #\r
1303 # Library Destructors\r
1304 #\r
1305 DestructorPrototypeString = TemplateString()\r
1306 DestructorCallingString = TemplateString()\r
1307 if Info.IsLibrary:\r
1308 DependentLibraryList = [Info.Module]\r
1309 else:\r
1310 DependentLibraryList = Info.DependentLibraryList\r
1311 for Index in range(len(DependentLibraryList)-1, -1, -1):\r
1312 Lib = DependentLibraryList[Index]\r
1313 if len(Lib.DestructorList) <= 0:\r
1314 continue\r
1315 Dict = {'Function':Lib.DestructorList}\r
1316 if Lib.ModuleType in ['BASE', 'SEC']:\r
1317 DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1318 DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1319 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1320 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1321 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1322 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1323 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
1324 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1325 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1326\r
1327 if str(DestructorPrototypeString) == '':\r
1328 DestructorPrototypeList = []\r
1329 else:\r
1330 DestructorPrototypeList = [str(DestructorPrototypeString)]\r
1331 if str(DestructorCallingString) == '':\r
1332 DestructorCallingList = []\r
1333 else:\r
1334 DestructorCallingList = [str(DestructorCallingString)]\r
1335\r
1336 Dict = {\r
1337 'Type' : 'Destructor',\r
1338 'FunctionPrototype' : DestructorPrototypeList,\r
1339 'FunctionCall' : DestructorCallingList\r
1340 }\r
1341 if Info.IsLibrary:\r
1342 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1343 else:\r
1344 if Info.ModuleType in ['BASE', 'SEC']:\r
1345 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1346 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1347 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1348 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1349 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1350 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1351\r
1352\r
1353## Create code for ModuleEntryPoint\r
1354#\r
1355# @param Info The ModuleAutoGen object\r
1356# @param AutoGenC The TemplateString object for C code\r
1357# @param AutoGenH The TemplateString object for header file\r
1358#\r
1359def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
1360 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1361 return\r
1362 #\r
1363 # Module Entry Points\r
1364 #\r
1365 NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1366 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1367 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']\r
1368 else:\r
1369 PiSpecVersion = '0x00000000'\r
1370 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1371 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']\r
1372 else:\r
1373 UefiSpecVersion = '0x00000000'\r
1374 Dict = {\r
1375 'Function' : Info.Module.ModuleEntryPointList,\r
1376 'PiSpecVersion' : PiSpecVersion + 'U',\r
1377 'UefiSpecVersion': UefiSpecVersion + 'U'\r
1378 }\r
1379\r
1380 if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:\r
1381 if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
1382 if NumEntryPoints != 1:\r
1383 EdkLogger.error(\r
1384 "build",\r
1385 AUTOGEN_ERROR,\r
1386 '%s must have exactly one entry point' % Info.ModuleType,\r
1387 File=str(Info),\r
1388 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
1389 )\r
1390 if Info.ModuleType == 'PEI_CORE':\r
1391 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
1392 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
1393 elif Info.ModuleType == 'DXE_CORE':\r
1394 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
1395 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
1396 elif Info.ModuleType == 'SMM_CORE':\r
1397 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
1398 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
1399 elif Info.ModuleType == 'PEIM':\r
1400 if NumEntryPoints < 2:\r
1401 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
1402 else:\r
1403 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
1404 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
1405 elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
1406 if NumEntryPoints < 2:\r
1407 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
1408 else:\r
1409 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
1410 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
1411 elif Info.ModuleType == 'DXE_SMM_DRIVER':\r
1412 if NumEntryPoints == 0:\r
1413 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
1414 else:\r
1415 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
1416 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) \r
1417 elif Info.ModuleType == 'UEFI_APPLICATION':\r
1418 if NumEntryPoints < 2:\r
1419 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
1420 else:\r
1421 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))\r
1422 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))\r
1423\r
1424## Create code for ModuleUnloadImage\r
1425#\r
1426# @param Info The ModuleAutoGen object\r
1427# @param AutoGenC The TemplateString object for C code\r
1428# @param AutoGenH The TemplateString object for header file\r
1429#\r
1430def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
1431 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1432 return\r
1433 #\r
1434 # Unload Image Handlers\r
1435 #\r
1436 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1437 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}\r
1438 if NumUnloadImage < 2:\r
1439 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))\r
1440 else:\r
1441 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))\r
1442 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))\r
1443\r
1444## Create code for GUID\r
1445#\r
1446# @param Info The ModuleAutoGen object\r
1447# @param AutoGenC The TemplateString object for C code\r
1448# @param AutoGenH The TemplateString object for header file\r
1449#\r
1450def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1451 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1452 GuidType = "GUID"\r
1453 else:\r
1454 GuidType = "EFI_GUID"\r
1455\r
1456 if Info.GuidList:\r
7beed8a3
YZ
1457 if not Info.IsLibrary:\r
1458 AutoGenC.Append("\n// Guids\n")\r
8262037f 1459 AutoGenH.Append("\n// Guids\n")\r
f51461c8
LG
1460 #\r
1461 # GUIDs\r
1462 #\r
1463 for Key in Info.GuidList:\r
7beed8a3
YZ
1464 if not Info.IsLibrary:\r
1465 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
8262037f 1466 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1467\r
1468## Create code for protocol\r
1469#\r
1470# @param Info The ModuleAutoGen object\r
1471# @param AutoGenC The TemplateString object for C code\r
1472# @param AutoGenH The TemplateString object for header file\r
1473#\r
1474def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1475 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1476 GuidType = "GUID"\r
1477 else:\r
1478 GuidType = "EFI_GUID"\r
1479\r
1480 if Info.ProtocolList:\r
7beed8a3
YZ
1481 if not Info.IsLibrary:\r
1482 AutoGenC.Append("\n// Protocols\n")\r
8262037f 1483 AutoGenH.Append("\n// Protocols\n")\r
f51461c8
LG
1484 #\r
1485 # Protocol GUIDs\r
1486 #\r
1487 for Key in Info.ProtocolList:\r
7beed8a3
YZ
1488 if not Info.IsLibrary:\r
1489 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
8262037f 1490 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1491\r
1492## Create code for PPI\r
1493#\r
1494# @param Info The ModuleAutoGen object\r
1495# @param AutoGenC The TemplateString object for C code\r
1496# @param AutoGenH The TemplateString object for header file\r
1497#\r
1498def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1499 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1500 GuidType = "GUID"\r
1501 else:\r
1502 GuidType = "EFI_GUID"\r
1503\r
1504 if Info.PpiList:\r
7beed8a3
YZ
1505 if not Info.IsLibrary:\r
1506 AutoGenC.Append("\n// PPIs\n")\r
8262037f 1507 AutoGenH.Append("\n// PPIs\n")\r
f51461c8
LG
1508 #\r
1509 # PPI GUIDs\r
1510 #\r
1511 for Key in Info.PpiList:\r
7beed8a3
YZ
1512 if not Info.IsLibrary:\r
1513 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
8262037f 1514 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1515\r
1516## Create code for PCD\r
1517#\r
1518# @param Info The ModuleAutoGen object\r
1519# @param AutoGenC The TemplateString object for C code\r
1520# @param AutoGenH The TemplateString object for header file\r
1521#\r
1522def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1523\r
1524 # Collect Token Space GUIDs used by DynamicEc PCDs\r
1525 TokenSpaceList = []\r
1526 for Pcd in Info.ModulePcdList:\r
1527 if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
1528 TokenSpaceList += [Pcd.TokenSpaceGuidCName]\r
1529 \r
1530 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
1531 if TokenSpaceList <> []: \r
1532 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
1533 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1534 GuidType = "GUID"\r
1535 else:\r
1536 GuidType = "EFI_GUID" \r
1537 for Item in TokenSpaceList:\r
1538 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
1539\r
1540 if Info.IsLibrary:\r
1541 if Info.ModulePcdList:\r
1542 AutoGenH.Append("\n// PCD definitions\n")\r
1543 for Pcd in Info.ModulePcdList:\r
1544 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1545 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1546 else:\r
1547 if Info.ModulePcdList:\r
1548 AutoGenH.Append("\n// Definition of PCDs used in this module\n")\r
1549 AutoGenC.Append("\n// Definition of PCDs used in this module\n")\r
1550 for Pcd in Info.ModulePcdList:\r
1551 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1552 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1553 if Info.LibraryPcdList:\r
1554 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")\r
1555 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")\r
1556 for Pcd in Info.LibraryPcdList:\r
1557 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)\r
1558 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1559\r
1560## Create code for unicode string definition\r
1561#\r
1562# @param Info The ModuleAutoGen object\r
1563# @param AutoGenC The TemplateString object for C code\r
1564# @param AutoGenH The TemplateString object for header file\r
1565# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1566# @param UniGenBinBuffer Buffer to store uni string package data\r
1567#\r
1568def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):\r
1569 WorkingDir = os.getcwd()\r
1570 os.chdir(Info.WorkspaceDir)\r
1571\r
1572 IncList = [Info.MetaFile.Dir]\r
1573 # Get all files under [Sources] section in inf file for EDK-II module\r
1574 EDK2Module = True\r
1575 SrcList = [F for F in Info.SourceFileList]\r
1576 if Info.AutoGenVersion < 0x00010005:\r
1577 EDK2Module = False\r
1578 # Get all files under the module directory for EDK-I module\r
1579 Cwd = os.getcwd()\r
1580 os.chdir(Info.MetaFile.Dir)\r
1581 for Root, Dirs, Files in os.walk("."):\r
1582 if 'CVS' in Dirs:\r
1583 Dirs.remove('CVS')\r
1584 if '.svn' in Dirs:\r
1585 Dirs.remove('.svn')\r
1586 for File in Files:\r
1587 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)\r
1588 if File in SrcList:\r
1589 continue\r
1590 SrcList.append(File)\r
1591 os.chdir(Cwd)\r
1592\r
1593 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:\r
1594 CompatibleMode = True\r
1595 else:\r
1596 CompatibleMode = False\r
1597\r
1598 #\r
1599 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2\r
1600 #\r
1601 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:\r
1602 if CompatibleMode:\r
1603 EdkLogger.error("build", AUTOGEN_ERROR,\r
1604 "-c and -s build options should be used exclusively",\r
1605 ExtraData="[%s]" % str(Info))\r
1606 ShellMode = True\r
1607 else:\r
1608 ShellMode = False\r
1609\r
1610 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules\r
1611 if EDK2Module:\r
1612 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]\r
1613 else:\r
1614 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]\r
1615 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)\r
1616 if CompatibleMode or UniGenCFlag:\r
1617 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1618 AutoGenC.Append(Code)\r
1619 AutoGenC.Append("\n")\r
1620 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1621 AutoGenH.Append(Header)\r
1622 if CompatibleMode or UniGenCFlag:\r
1623 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1624 os.chdir(WorkingDir)\r
1625\r
333ba578
YZ
1626def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):\r
1627 if len(Info.IdfFileList) > 0:\r
1628 ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList))\r
1629 if ImageFiles.ImageFilesDict:\r
1630 Index = 1\r
1631 PaletteIndex = 1\r
1632 IncList = [Info.MetaFile.Dir]\r
1633 SrcList = [F for F in Info.SourceFileList]\r
1634 SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf']\r
1635 FileList = GetFileList(SrcList, IncList, SkipList)\r
1636 ValueStartPtr = 60\r
1637 StringH.Append("\n//\n//Image ID\n//\n")\r
1638 ImageInfoOffset = 0\r
1639 PaletteInfoOffset = 0\r
1640 ImageBuffer = pack('x')\r
1641 PaletteBuffer = pack('x')\r
1642 BufferStr = ''\r
1643 PaletteStr = ''\r
6d034a2a 1644 FileDict = {}\r
333ba578
YZ
1645 for Idf in ImageFiles.ImageFilesDict:\r
1646 if ImageFiles.ImageFilesDict[Idf]:\r
1647 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1648 for sourcefile in Info.SourceFileList:\r
1649 if FileObj.FileName == sourcefile.File:\r
1650 if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']:\r
1651 EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info))\r
1652 FileObj.File = sourcefile\r
1653 break\r
1654 else:\r
1655 EdkLogger.error("build", AUTOGEN_ERROR, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj.FileName, Idf), ExtraData="[%s]" % str(Info))\r
1656\r
1657 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1658 ID = FileObj.ImageID\r
1659 File = FileObj.File\r
1660 if not os.path.exists(File.Path) or not os.path.isfile(File.Path):\r
1661 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path)\r
1662 SearchImageID (FileObj, FileList)\r
1663 if FileObj.Referenced:\r
1664 if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0:\r
1665 Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n'\r
1666 else:\r
1667 Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n'\r
1668\r
6d034a2a
YZ
1669 if File not in FileDict:\r
1670 FileDict[File] = Index\r
1671 else:\r
1672 DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE)\r
1673 DuplicateBlock += pack('H', FileDict[File])\r
1674 ImageBuffer += DuplicateBlock\r
1675 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1676 TempBufferList = AscToHexList(DuplicateBlock)\r
1677 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1678 StringH.Append(Line)\r
1679 Index += 1\r
1680 continue\r
1681\r
333ba578
YZ
1682 TmpFile = open(File.Path, 'rb')\r
1683 Buffer = TmpFile.read()\r
1684 TmpFile.close()\r
1685 if File.Ext.upper() == '.PNG':\r
1686 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG)\r
1687 TempBuffer += pack('I', len(Buffer))\r
1688 TempBuffer += Buffer\r
1689 elif File.Ext.upper() == '.JPG':\r
1690 ImageType, = struct.unpack('4s', Buffer[6:10])\r
1691 if ImageType != 'JFIF':\r
1692 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path)\r
1693 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG)\r
1694 TempBuffer += pack('I', len(Buffer))\r
1695 TempBuffer += Buffer\r
1696 elif File.Ext.upper() == '.BMP':\r
1697 TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent)\r
1698 if len(TempPalette) > 1:\r
1699 PaletteIndex += 1\r
e148e6e9
YZ
1700 NewPalette = pack('H', len(TempPalette))\r
1701 NewPalette += TempPalette\r
1702 PaletteBuffer += NewPalette\r
333ba578 1703 PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4)))\r
e148e6e9 1704 TempPaletteList = AscToHexList(NewPalette)\r
333ba578
YZ
1705 PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n')\r
1706 ImageBuffer += TempBuffer\r
1707 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1708 TempBufferList = AscToHexList(TempBuffer)\r
1709 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1710\r
1711 StringH.Append(Line)\r
1712 Index += 1\r
1713\r
1714 BufferStr = WriteLine(BufferStr, '// End of the Image Info')\r
1715 BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n')\r
1716 ImageEnd = pack('B', EFI_HII_IIBT_END)\r
1717 ImageBuffer += ImageEnd\r
1718\r
1719 if len(ImageBuffer) > 1:\r
1720 ImageInfoOffset = 12\r
1721 if len(PaletteBuffer) > 1:\r
1722 PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer\r
1723\r
1724 IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset)\r
1725 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length\r
1726 if len(PaletteBuffer) > 1:\r
1727 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1\r
1728 else:\r
1729 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1\r
1730 if PaletteIndex > 1:\r
1731 PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1)\r
1732 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF\r
1733 Hex_Length = '%06X' % PACKAGE_HEADER_Length\r
1734 if PACKAGE_HEADER_Length > 0xFFFFFF:\r
1735 EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info))\r
1736 PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES)\r
1737\r
1738 IdfGenBinBuffer.write(PACKAGE_HEADER)\r
1739 IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR)\r
1740 if len(ImageBuffer) > 1 :\r
1741 IdfGenBinBuffer.write(ImageBuffer[1:])\r
1742 if PaletteIndex > 1:\r
1743 IdfGenBinBuffer.write(PALETTE_INFO_HEADER)\r
1744 if len(PaletteBuffer) > 1:\r
1745 IdfGenBinBuffer.write(PaletteBuffer[1:])\r
1746\r
1747 if IdfGenCFlag:\r
1748 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length\r
1749 AutoGenC.Append("\n//\n//Image Pack Definition\n//\n")\r
1750 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n')\r
1751 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')\r
1752 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')\r
1753 AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n')\r
1754 IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER)\r
1755 IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR)\r
1756 AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n')\r
1757 AllStr = WriteLine(AllStr, '// Image DATA\n')\r
1758 if BufferStr:\r
1759 AllStr = WriteLine(AllStr, BufferStr)\r
1760 if PaletteStr:\r
1761 AllStr = WriteLine(AllStr, '// Palette Header\n')\r
1762 PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER)\r
1763 AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n')\r
1764 AllStr = WriteLine(AllStr, '// Palette Data\n')\r
1765 AllStr = WriteLine(AllStr, PaletteStr)\r
1766 AllStr = WriteLine(AllStr, '};')\r
1767 AutoGenC.Append(AllStr)\r
1768 AutoGenC.Append("\n")\r
1769 StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n')\r
1770 StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName)\r
1771\r
1772# typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {\r
1773# EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES\r
1774# UINT32 ImageInfoOffset;\r
1775# UINT32 PaletteInfoOffset;\r
1776# } EFI_HII_IMAGE_PACKAGE_HDR;\r
1777\r
1778# typedef struct {\r
1779# UINT32 Length:24;\r
1780# UINT32 Type:8;\r
1781# UINT8 Data[];\r
1782# } EFI_HII_PACKAGE_HEADER;\r
1783\r
1784# typedef struct _EFI_HII_IMAGE_BLOCK {\r
1785# UINT8 BlockType;\r
1786# UINT8 BlockBody[];\r
1787# } EFI_HII_IMAGE_BLOCK;\r
1788\r
1789def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):\r
1790 ImageType, = struct.unpack('2s', Buffer[0:2])\r
1791 if ImageType!= 'BM': # BMP file type is 'BM'\r
1792 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)\r
1793 BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])\r
1794 BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')\r
1795 BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))\r
1796 #\r
1797 # Doesn't support compress.\r
1798 #\r
1799 if BmpHeader.biCompression != 0:\r
1800 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path)\r
1801\r
1802 # The Width and Height is UINT16 type in Image Package\r
1803 if BmpHeader.biWidth > 0xFFFF:\r
1804 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path)\r
1805 if BmpHeader.biHeight > 0xFFFF:\r
1806 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path)\r
1807\r
1808 PaletteBuffer = pack('x')\r
1809 if BmpHeader.biBitCount == 1:\r
1810 if TransParent:\r
1811 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)\r
1812 else:\r
1813 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)\r
1814 ImageBuffer += pack('B', PaletteIndex)\r
1815 Width = (BmpHeader.biWidth + 7)/8\r
1816 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1817 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1818 elif BmpHeader.biBitCount == 4:\r
1819 if TransParent:\r
1820 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)\r
1821 else:\r
1822 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)\r
1823 ImageBuffer += pack('B', PaletteIndex)\r
1824 Width = (BmpHeader.biWidth + 1)/2\r
1825 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1826 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1827 elif BmpHeader.biBitCount == 8:\r
1828 if TransParent:\r
1829 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)\r
1830 else:\r
1831 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT)\r
1832 ImageBuffer += pack('B', PaletteIndex)\r
1833 Width = BmpHeader.biWidth\r
1834 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1835 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1836 elif BmpHeader.biBitCount == 24:\r
1837 if TransParent:\r
1838 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS)\r
1839 else:\r
1840 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT)\r
1841 Width = BmpHeader.biWidth * 3\r
1842 else:\r
1843 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path))\r
1844\r
1845 ImageBuffer += pack('H', BmpHeader.biWidth)\r
1846 ImageBuffer += pack('H', BmpHeader.biHeight)\r
1847 Start = BmpHeader.bfOffBits\r
1848 End = BmpHeader.bfSize - 1\r
1849 for Height in range(0, BmpHeader.biHeight):\r
1850 if Width % 4 != 0:\r
1851 Start = End + (Width % 4) - 4 - Width\r
1852 else:\r
1853 Start = End - Width\r
1854 ImageBuffer += Buffer[Start + 1 : Start + Width + 1]\r
1855 End = Start\r
1856\r
1857 # handle the Palette info, BMP use 4 bytes for R, G, B and Reserved info while EFI_HII_RGB_PIXEL only have the R, G, B info\r
1858 if PaletteBuffer and len(PaletteBuffer) > 1:\r
1859 PaletteTemp = pack('x')\r
1860 for Index in range(0, len(PaletteBuffer)):\r
1861 if Index % 4 == 3:\r
1862 continue\r
1863 PaletteTemp += PaletteBuffer[Index]\r
1864 PaletteBuffer = PaletteTemp[1:]\r
1865 return ImageBuffer, PaletteBuffer\r
1866\r
f51461c8
LG
1867## Create common code\r
1868#\r
1869# @param Info The ModuleAutoGen object\r
1870# @param AutoGenC The TemplateString object for C code\r
1871# @param AutoGenH The TemplateString object for header file\r
1872#\r
1873def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
1874 # file header\r
1875 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
1876 # header file Prologue\r
1877 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))\r
1878 AutoGenH.Append(gAutoGenHCppPrologueString)\r
1879 if Info.AutoGenVersion >= 0x00010005:\r
1880 # header files includes\r
1881 AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)\r
1882 if Info.ModuleType in gModuleTypeHeaderFile \\r
1883 and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:\r
1884 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
1885 #\r
1886 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h \r
1887 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
1888 #\r
1889 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
1890 AutoGenH.Append("#include <Library/PcdLib.h>\n")\r
1891\r
1892 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')\r
1893 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')\r
1894\r
1895 if Info.IsLibrary:\r
1896 return\r
1897\r
1898 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
1899\r
1900 if Info.IsLibrary:\r
1901 return\r
1902 # C file header\r
1903 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))\r
1904 if Info.AutoGenVersion >= 0x00010005:\r
1905 # C file header files includes\r
1906 if Info.ModuleType in gModuleTypeHeaderFile:\r
1907 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
1908 AutoGenC.Append("#include <%s>\n" % Inc)\r
1909 else:\r
1910 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)\r
1911\r
1912 #\r
1913 # Publish the CallerId Guid\r
1914 #\r
1915 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
1916 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)\r
1917\r
1918## Create common code for header file\r
1919#\r
1920# @param Info The ModuleAutoGen object\r
1921# @param AutoGenC The TemplateString object for C code\r
1922# @param AutoGenH The TemplateString object for header file\r
1923#\r
1924def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
1925 AutoGenH.Append(gAutoGenHEpilogueString)\r
1926\r
1927## Create code for a module\r
1928#\r
1929# @param Info The ModuleAutoGen object\r
1930# @param AutoGenC The TemplateString object for C code\r
1931# @param AutoGenH The TemplateString object for header file\r
333ba578 1932# @param StringH The TemplateString object for header file\r
f51461c8
LG
1933# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1934# @param UniGenBinBuffer Buffer to store uni string package data\r
333ba578
YZ
1935# @param StringIdf The TemplateString object for header file\r
1936# @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True\r
1937# @param IdfGenBinBuffer Buffer to store Idf string package data\r
f51461c8 1938#\r
333ba578 1939def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):\r
f51461c8
LG
1940 CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
1941\r
1942 if Info.AutoGenVersion >= 0x00010005:\r
1943 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
1944 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
1945 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
1946 CreatePcdCode(Info, AutoGenC, AutoGenH)\r
1947 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
1948 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
1949 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
1950 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
1951\r
1952 if Info.UnicodeFileList:\r
1953 FileName = "%sStrDefs.h" % Info.Name\r
1954 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
1955 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
1956 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
8200fcfe
YL
1957\r
1958 GuidMacros = []\r
1959 for Guid in Info.Module.Guids:\r
1960 if Guid in Info.Module.GetGuidsUsedByPcd():\r
1961 continue\r
1962 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
1963 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
1964 GuidMacros.append('#define %s %s' % (Guid, Value))\r
5b97eb4c
YZ
1965 # supports FixedAtBuild usage in VFR file\r
1966 if Info.VfrFileList and Info.ModulePcdList:\r
1967 GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))\r
1968 GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))\r
1969 GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))\r
1970 GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))\r
1971 GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))\r
1972 for Pcd in Info.ModulePcdList:\r
1973 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1974 TokenCName = Pcd.TokenCName\r
1975 Value = Pcd.DefaultValue\r
1976 if Pcd.DatumType == 'BOOLEAN':\r
1977 BoolValue = Value.upper()\r
1978 if BoolValue == 'TRUE':\r
1979 Value = '1'\r
1980 elif BoolValue == 'FALSE':\r
1981 Value = '0'\r
1982 for PcdItem in GlobalData.MixedPcd:\r
1983 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1984 TokenCName = PcdItem[0]\r
1985 break\r
1986 GuidMacros.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName, Value))\r
1987\r
bc7d95c0
YZ
1988 if Info.IdfFileList:\r
1989 GuidMacros.append('#include "%sImgDefs.h"' % Info.Name)\r
1990\r
8200fcfe
YL
1991 if GuidMacros:\r
1992 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))\r
1993\r
f51461c8
LG
1994 StringH.Append("\n#endif\n")\r
1995 AutoGenH.Append('#include "%s"\n' % FileName)\r
1996\r
333ba578
YZ
1997 if Info.IdfFileList:\r
1998 FileName = "%sImgDefs.h" % Info.Name\r
1999 StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
2000 StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
2001 CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)\r
2002\r
2003 StringIdf.Append("\n#endif\n")\r
2004 AutoGenH.Append('#include "%s"\n' % FileName)\r
2005\r
f51461c8
LG
2006 CreateFooterCode(Info, AutoGenC, AutoGenH)\r
2007\r
2008 # no generation of AutoGen.c for Edk modules without unicode file\r
2009 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:\r
2010 AutoGenC.String = ''\r
2011\r
2012## Create the code file\r
2013#\r
2014# @param FilePath The path of code file\r
2015# @param Content The content of code file\r
2016# @param IsBinaryFile The flag indicating if the file is binary file or not\r
2017#\r
2018# @retval True If file content is changed or file doesn't exist\r
2019# @retval False If the file exists and the content is not changed\r
2020#\r
2021def Generate(FilePath, Content, IsBinaryFile):\r
2022 return SaveFileOnChange(FilePath, Content, IsBinaryFile)\r
2023\r