BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[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
677 if Info.IsLibrary:\r
678 PcdList = Info.LibraryPcdList\r
679 else:\r
680 PcdList = Info.ModulePcdList\r
681 for Pcd in PcdList:\r
682 if Pcd.Type in gDynamicExPcd:\r
683 ExTokenCNameList.append(Pcd.TokenCName)\r
684 PcdExList.append(Pcd)\r
685 if len(ExTokenCNameList) == 0:\r
686 return\r
687 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')\r
688 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
689 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter. \r
690 # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
691 TokenCNameList = []\r
692 for TokenCName in ExTokenCNameList:\r
693 if TokenCName in TokenCNameList:\r
694 continue\r
695 Index = 0\r
696 Count = ExTokenCNameList.count(TokenCName)\r
697 for Pcd in PcdExList:\r
2a29017e
YZ
698 RealTokenCName = Pcd.TokenCName\r
699 for PcdItem in GlobalData.MixedPcd:\r
700 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
701 RealTokenCName = PcdItem[0]\r
702 break\r
f51461c8
LG
703 if Pcd.TokenCName == TokenCName:\r
704 Index = Index + 1\r
705 if Index == 1:\r
2a29017e 706 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName))\r
f51461c8 707 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 708 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
709 else:\r
710 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 711 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
712 if Index == Count:\r
713 AutoGenH.Append('0 \\\n )\n')\r
714 TokenCNameList.append(TokenCName)\r
715 \r
716 TokenCNameList = []\r
717 for TokenCName in ExTokenCNameList:\r
718 if TokenCName in TokenCNameList:\r
719 continue\r
720 Index = 0\r
721 Count = ExTokenCNameList.count(TokenCName)\r
722 for Pcd in PcdExList:\r
2a29017e
YZ
723 RealTokenCName = Pcd.TokenCName\r
724 for PcdItem in GlobalData.MixedPcd:\r
725 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
726 RealTokenCName = PcdItem[0]\r
727 break\r
f51461c8
LG
728 if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:\r
729 Index = Index + 1\r
730 if Index == 1:\r
2a29017e 731 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName))\r
9023704f 732 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')\r
f51461c8 733 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 734 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
735 else:\r
736 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 737 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
738 if Index == Count:\r
739 AutoGenH.Append('0 \\\n )\n')\r
740 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID. \r
741 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
742 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
743 # COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
744 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 745 % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
f51461c8
LG
746 TokenCNameList.append(TokenCName)\r
747\r
2f5acc3b
BF
748def GetPcdSize(Pcd):\r
749 if Pcd.DatumType == 'VOID*':\r
750 Value = Pcd.DefaultValue\r
751 if Value in [None, '']:\r
752 return 1\r
753 elif Value[0] == 'L':\r
754 return (len(Value) - 2) * 2\r
755 elif Value[0] == '{':\r
756 return len(Value.split(','))\r
757 else:\r
758 return len(Value) - 1\r
759 if Pcd.DatumType == 'UINT64':\r
760 return 8\r
761 if Pcd.DatumType == 'UINT32':\r
762 return 4\r
763 if Pcd.DatumType == 'UINT16':\r
764 return 2\r
765 if Pcd.DatumType == 'UINT8':\r
766 return 1\r
767 if Pcd.DatumType == 'BOOLEAN':\r
768 return 1\r
769\r
770\r
f51461c8
LG
771## Create code for module PCDs\r
772#\r
773# @param Info The ModuleAutoGen object\r
774# @param AutoGenC The TemplateString object for C code\r
775# @param AutoGenH The TemplateString object for header file\r
776# @param Pcd The PCD object\r
777#\r
778def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
779 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
780 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
2a29017e
YZ
781 #\r
782 # Write PCDs\r
783 #\r
784 TokenCName = Pcd.TokenCName\r
785 for PcdItem in GlobalData.MixedPcd:\r
786 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
787 TokenCName = PcdItem[0]\r
788 break\r
789 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
790 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
791 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
792 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
763e8edf
YZ
793\r
794 if GlobalData.BuildOptionPcd:\r
795 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 796 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
797 Pcd.DefaultValue = PcdItem[2]\r
798 break\r
2f5acc3b 799 \r
f51461c8
LG
800 if Pcd.Type in gDynamicExPcd:\r
801 TokenNumber = int(Pcd.TokenValue, 0)\r
802 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
803 # different Guids but same TokenCName\r
2a29017e 804 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
805 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
806 else:\r
807 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
808 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
809 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
810 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
811 # report warning message notify the PI that they are attempting to build a module \r
812 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
813 # will not be added into the Database unless it is used by other modules that are \r
814 # included in the FDF file. \r
815 # In this case, just assign an invalid token number to make it pass build.\r
816 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
817 TokenNumber = 0\r
818 else:\r
819 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 820 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
821 ExtraData="[%s]" % str(Info))\r
822 else:\r
823 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
824 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))\r
825\r
2a29017e 826 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
f51461c8
LG
827 if Pcd.Type not in gItemTypeStringDatabase:\r
828 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 829 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
830 ExtraData="[%s]" % str(Info))\r
831 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
832 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 833 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
834 ExtraData="[%s]" % str(Info))\r
835\r
836 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
837 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
2a29017e
YZ
838 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
839 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
840 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName\r
841 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
2f5acc3b 842 \r
f51461c8
LG
843 PcdExCNameList = []\r
844 if Pcd.Type in gDynamicExPcd:\r
845 if Info.IsLibrary:\r
846 PcdList = Info.LibraryPcdList\r
847 else:\r
848 PcdList = Info.ModulePcdList\r
849 for PcdModule in PcdList:\r
850 if PcdModule.Type in gDynamicExPcd:\r
851 PcdExCNameList.append(PcdModule.TokenCName)\r
852 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
853 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
854 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
855 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
856 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
857 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
858 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 859 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
860 if Pcd.DatumType == 'VOID*':\r
861 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 862 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
863 else:\r
864 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 865 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
866 else:\r
867 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
868 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 869 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
870 if Pcd.DatumType == 'VOID*':\r
871 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 872 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
873 else:\r
874 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 875 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8 876 elif Pcd.Type in gDynamicPcd:\r
38b986e3
YZ
877 PcdList = []\r
878 PcdCNameList = []\r
879 PcdList.extend(Info.LibraryPcdList)\r
880 PcdList.extend(Info.ModulePcdList)\r
881 for PcdModule in PcdList:\r
882 if PcdModule.Type in gDynamicPcd:\r
883 PcdCNameList.append(PcdModule.TokenCName)\r
884 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 885 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 886 else:\r
38b986e3
YZ
887 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
888 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
889 if Pcd.DatumType == 'VOID*':\r
890 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
891 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
892 else:\r
893 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
894 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8 895 else:\r
2a29017e 896 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
f51461c8
LG
897 Const = 'const'\r
898 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
899 Const = ''\r
900 Type = ''\r
901 Array = ''\r
902 Value = Pcd.DefaultValue\r
903 Unicode = False\r
904 ValueNumber = 0\r
905\r
906 if Pcd.DatumType == 'BOOLEAN':\r
907 BoolValue = Value.upper()\r
908 if BoolValue == 'TRUE' or BoolValue == '1':\r
909 Value = '1U'\r
910 elif BoolValue == 'FALSE' or BoolValue == '0':\r
911 Value = '0U'\r
912\r
913 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:\r
914 try:\r
915 if Value.upper().startswith('0X'):\r
916 ValueNumber = int (Value, 16)\r
917 else:\r
918 ValueNumber = int (Value)\r
919 except:\r
920 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 921 "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
922 ExtraData="[%s]" % str(Info))\r
923 if Pcd.DatumType == 'UINT64':\r
924 if ValueNumber < 0:\r
925 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 926 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
927 ExtraData="[%s]" % str(Info))\r
928 elif ValueNumber >= 0x10000000000000000:\r
929 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 930 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
931 ExtraData="[%s]" % str(Info))\r
932 if not Value.endswith('ULL'):\r
933 Value += 'ULL'\r
934 elif Pcd.DatumType == 'UINT32':\r
935 if ValueNumber < 0:\r
936 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 937 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
938 ExtraData="[%s]" % str(Info))\r
939 elif ValueNumber >= 0x100000000:\r
940 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 941 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
942 ExtraData="[%s]" % str(Info))\r
943 if not Value.endswith('U'):\r
944 Value += 'U'\r
945 elif Pcd.DatumType == 'UINT16':\r
946 if ValueNumber < 0:\r
947 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 948 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
949 ExtraData="[%s]" % str(Info))\r
950 elif ValueNumber >= 0x10000:\r
951 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 952 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
953 ExtraData="[%s]" % str(Info))\r
954 if not Value.endswith('U'):\r
955 Value += 'U' \r
956 elif Pcd.DatumType == 'UINT8':\r
957 if ValueNumber < 0:\r
958 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 959 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
960 ExtraData="[%s]" % str(Info))\r
961 elif ValueNumber >= 0x100:\r
962 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 963 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
964 ExtraData="[%s]" % str(Info))\r
965 if not Value.endswith('U'):\r
966 Value += 'U'\r
967 if Pcd.DatumType == 'VOID*':\r
968 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
969 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 970 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
971 ExtraData="[%s]" % str(Info))\r
972\r
973 ArraySize = int(Pcd.MaxDatumSize, 0)\r
974 if Value[0] == '{':\r
975 Type = '(VOID *)'\r
976 else:\r
977 if Value[0] == 'L':\r
978 Unicode = True\r
979 Value = Value.lstrip('L') #.strip('"')\r
980 Value = eval(Value) # translate escape character\r
981 NewValue = '{'\r
982 for Index in range(0,len(Value)):\r
983 if Unicode:\r
984 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
985 else:\r
986 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
987 if Unicode:\r
988 ArraySize = ArraySize / 2;\r
989\r
990 if ArraySize < (len(Value) + 1):\r
991 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 992 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
993 ExtraData="[%s]" % str(Info))\r
994 Value = NewValue + '0 }'\r
995 Array = '[%d]' % ArraySize\r
996 #\r
997 # skip casting for fixed at build since it breaks ARM assembly.\r
998 # Long term we need PCD macros that work in assembly\r
999 #\r
1000 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
1001 Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
1002\r
1003 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
2a29017e 1004 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
f51461c8 1005 else:\r
2a29017e 1006 PcdValueName = '_PCD_VALUE_' + TokenCName\r
f51461c8
LG
1007 \r
1008 if Pcd.DatumType == 'VOID*':\r
1009 #\r
1010 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
1011 #\r
1012 if Unicode:\r
f51461c8
LG
1013 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1014 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1015 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
1016 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
1017 else:\r
f51461c8
LG
1018 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1019 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1020 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
1021 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1022 \r
1023 PcdDataSize = GetPcdSize(Pcd)\r
1024 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1025 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1026 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1027 \r
1028 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1029 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
1030 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1031 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1032 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8
LG
1033 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1034 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1035 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1036 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1037 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1038 \r
1039 PcdDataSize = GetPcdSize(Pcd)\r
1040 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1041 \r
1042 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1043 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1044 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8 1045 else:\r
2f5acc3b
BF
1046 PcdDataSize = GetPcdSize(Pcd)\r
1047 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1048 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1049 \r
f51461c8
LG
1050 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1051 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1052 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1053 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
1054\r
1055 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1056 if Pcd.DatumType == 'VOID*':\r
e70504cd
LG
1057 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
1058 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
1059 else:\r
1060 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
82a6a960 1061 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))\r
f51461c8
LG
1062 else:\r
1063 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1064\r
1065## Create code for library module PCDs\r
1066#\r
1067# @param Info The ModuleAutoGen object\r
1068# @param AutoGenC The TemplateString object for C code\r
1069# @param AutoGenH The TemplateString object for header file\r
1070# @param Pcd The PCD object\r
1071#\r
1072def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
1073 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
1074 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1075 TokenCName = Pcd.TokenCName\r
2a29017e
YZ
1076 for PcdItem in GlobalData.MixedPcd:\r
1077 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1078 TokenCName = PcdItem[0]\r
1079 break\r
f51461c8 1080 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
2a29017e
YZ
1081 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
1082 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
1083 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
763e8edf
YZ
1084\r
1085 if GlobalData.BuildOptionPcd:\r
1086 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 1087 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
1088 Pcd.DefaultValue = PcdItem[2]\r
1089 break\r
1090\r
f51461c8
LG
1091 #\r
1092 # Write PCDs\r
1093 #\r
1094 if Pcd.Type in gDynamicExPcd:\r
1095 TokenNumber = int(Pcd.TokenValue, 0)\r
1096 else:\r
1097 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
1098 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
1099 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
1100 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
1101 # report warning message notify the PI that they are attempting to build a module \r
1102 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
1103 # will not be added into the Database unless it is used by other modules that are \r
1104 # included in the FDF file. \r
1105 # In this case, just assign an invalid token number to make it pass build.\r
1106 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
1107 TokenNumber = 0\r
1108 else:\r
1109 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1110 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1111 ExtraData="[%s]" % str(Info))\r
1112 else:\r
1113 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
1114\r
1115 if Pcd.Type not in gItemTypeStringDatabase:\r
1116 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1117 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1118 ExtraData="[%s]" % str(Info))\r
1119 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
1120 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1121 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1122 ExtraData="[%s]" % str(Info))\r
1123\r
1124 DatumType = Pcd.DatumType\r
1125 DatumSize = gDatumSizeStringDatabaseH[DatumType]\r
1126 DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]\r
1127 GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
1128 SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
82a6a960 1129 SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName\r
2a29017e 1130 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
f51461c8
LG
1131\r
1132 Type = ''\r
1133 Array = ''\r
1134 if Pcd.DatumType == 'VOID*':\r
d66670f9
YZ
1135 if Pcd.DefaultValue[0]== '{':\r
1136 Type = '(VOID *)'\r
f51461c8
LG
1137 Array = '[]'\r
1138 PcdItemType = Pcd.Type\r
1139 PcdExCNameList = []\r
1140 if PcdItemType in gDynamicExPcd:\r
2a29017e 1141 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
1142 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
1143 \r
1144 if Info.IsLibrary:\r
1145 PcdList = Info.LibraryPcdList\r
1146 else:\r
1147 PcdList = Info.ModulePcdList\r
1148 for PcdModule in PcdList:\r
1149 if PcdModule.Type in gDynamicExPcd:\r
1150 PcdExCNameList.append(PcdModule.TokenCName)\r
1151 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
1152 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
1153 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
1154 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
1155 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
1156 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1157 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 1158 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s \n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1159 if Pcd.DatumType == 'VOID*':\r
1160 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1161 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1162 else:\r
1163 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1164 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1165 else:\r
1166 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1167 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 1168 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1169 if Pcd.DatumType == 'VOID*':\r
1170 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1171 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1172 else:\r
1173 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1174 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1175 else:\r
1176 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))\r
1177 if PcdItemType in gDynamicPcd:\r
38b986e3
YZ
1178 PcdList = []\r
1179 PcdCNameList = []\r
1180 PcdList.extend(Info.LibraryPcdList)\r
1181 PcdList.extend(Info.ModulePcdList)\r
1182 for PcdModule in PcdList:\r
1183 if PcdModule.Type in gDynamicPcd:\r
1184 PcdCNameList.append(PcdModule.TokenCName)\r
1185 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 1186 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 1187 else:\r
38b986e3
YZ
1188 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
1189 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
1190 if DatumType == 'VOID*':\r
1191 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
1192 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
1193 else:\r
1194 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
1195 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8
LG
1196 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1197 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
d66670f9
YZ
1198 if DatumType == 'VOID*':\r
1199 ArraySize = int(Pcd.MaxDatumSize, 0)\r
1200 if Pcd.DefaultValue[0] == 'L':\r
1201 ArraySize = ArraySize / 2\r
1202 Array = '[%d]' % ArraySize\r
1203 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
1204 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
1205 else:\r
1206 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))\r
f51461c8 1207 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
27187d24 1208 if Pcd.DatumType == 'VOID*':\r
2a29017e
YZ
1209 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
1210 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
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
2f5acc3b
BF
1214 \r
1215 PcdDataSize = GetPcdSize(Pcd)\r
1216 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1217 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1218 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1219 \r
f51461c8
LG
1220 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
1221 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1222 \r
41ab153f 1223 if DatumType == 'VOID*' and Array == '[]':\r
2f5acc3b 1224 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
f51461c8
LG
1225 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
1226 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
1227 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1228 \r
c9da41b2 1229 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):\r
f51461c8
LG
1230 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
1231 \r
2f5acc3b
BF
1232 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
1233 PcdDataSize = GetPcdSize(Pcd)\r
1234 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1235 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName))\r
f51461c8
LG
1236\r
1237## Create code for library constructor\r
1238#\r
1239# @param Info The ModuleAutoGen object\r
1240# @param AutoGenC The TemplateString object for C code\r
1241# @param AutoGenH The TemplateString object for header file\r
1242#\r
1243def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1244 #\r
1245 # Library Constructors\r
1246 #\r
1247 ConstructorPrototypeString = TemplateString()\r
1248 ConstructorCallingString = TemplateString()\r
1249 if Info.IsLibrary:\r
1250 DependentLibraryList = [Info.Module]\r
1251 else:\r
1252 DependentLibraryList = Info.DependentLibraryList\r
1253 for Lib in DependentLibraryList:\r
1254 if len(Lib.ConstructorList) <= 0:\r
1255 continue\r
1256 Dict = {'Function':Lib.ConstructorList}\r
1257 if Lib.ModuleType in ['BASE', 'SEC']:\r
1258 ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1259 ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1260 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1261 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1262 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1263 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1264 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1265 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1266 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1267\r
1268 if str(ConstructorPrototypeString) == '':\r
1269 ConstructorPrototypeList = []\r
1270 else:\r
1271 ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
1272 if str(ConstructorCallingString) == '':\r
1273 ConstructorCallingList = []\r
1274 else:\r
1275 ConstructorCallingList = [str(ConstructorCallingString)]\r
1276\r
1277 Dict = {\r
1278 'Type' : 'Constructor',\r
1279 'FunctionPrototype' : ConstructorPrototypeList,\r
1280 'FunctionCall' : ConstructorCallingList\r
1281 }\r
1282 if Info.IsLibrary:\r
1283 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1284 else:\r
1285 if Info.ModuleType in ['BASE', 'SEC']:\r
1286 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1287 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1288 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1289 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1290 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1291 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1292\r
1293## Create code for library destructor\r
1294#\r
1295# @param Info The ModuleAutoGen object\r
1296# @param AutoGenC The TemplateString object for C code\r
1297# @param AutoGenH The TemplateString object for header file\r
1298#\r
1299def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1300 #\r
1301 # Library Destructors\r
1302 #\r
1303 DestructorPrototypeString = TemplateString()\r
1304 DestructorCallingString = TemplateString()\r
1305 if Info.IsLibrary:\r
1306 DependentLibraryList = [Info.Module]\r
1307 else:\r
1308 DependentLibraryList = Info.DependentLibraryList\r
1309 for Index in range(len(DependentLibraryList)-1, -1, -1):\r
1310 Lib = DependentLibraryList[Index]\r
1311 if len(Lib.DestructorList) <= 0:\r
1312 continue\r
1313 Dict = {'Function':Lib.DestructorList}\r
1314 if Lib.ModuleType in ['BASE', 'SEC']:\r
1315 DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1316 DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1317 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1318 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1319 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1320 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1321 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
1322 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1323 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1324\r
1325 if str(DestructorPrototypeString) == '':\r
1326 DestructorPrototypeList = []\r
1327 else:\r
1328 DestructorPrototypeList = [str(DestructorPrototypeString)]\r
1329 if str(DestructorCallingString) == '':\r
1330 DestructorCallingList = []\r
1331 else:\r
1332 DestructorCallingList = [str(DestructorCallingString)]\r
1333\r
1334 Dict = {\r
1335 'Type' : 'Destructor',\r
1336 'FunctionPrototype' : DestructorPrototypeList,\r
1337 'FunctionCall' : DestructorCallingList\r
1338 }\r
1339 if Info.IsLibrary:\r
1340 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1341 else:\r
1342 if Info.ModuleType in ['BASE', 'SEC']:\r
1343 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1344 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1345 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1346 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1347 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1348 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1349\r
1350\r
1351## Create code for ModuleEntryPoint\r
1352#\r
1353# @param Info The ModuleAutoGen object\r
1354# @param AutoGenC The TemplateString object for C code\r
1355# @param AutoGenH The TemplateString object for header file\r
1356#\r
1357def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
1358 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1359 return\r
1360 #\r
1361 # Module Entry Points\r
1362 #\r
1363 NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1364 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1365 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']\r
1366 else:\r
1367 PiSpecVersion = '0x00000000'\r
1368 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1369 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']\r
1370 else:\r
1371 UefiSpecVersion = '0x00000000'\r
1372 Dict = {\r
1373 'Function' : Info.Module.ModuleEntryPointList,\r
1374 'PiSpecVersion' : PiSpecVersion + 'U',\r
1375 'UefiSpecVersion': UefiSpecVersion + 'U'\r
1376 }\r
1377\r
1378 if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:\r
1379 if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
1380 if NumEntryPoints != 1:\r
1381 EdkLogger.error(\r
1382 "build",\r
1383 AUTOGEN_ERROR,\r
1384 '%s must have exactly one entry point' % Info.ModuleType,\r
1385 File=str(Info),\r
1386 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
1387 )\r
1388 if Info.ModuleType == 'PEI_CORE':\r
1389 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
1390 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
1391 elif Info.ModuleType == 'DXE_CORE':\r
1392 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
1393 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
1394 elif Info.ModuleType == 'SMM_CORE':\r
1395 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
1396 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
1397 elif Info.ModuleType == 'PEIM':\r
1398 if NumEntryPoints < 2:\r
1399 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
1400 else:\r
1401 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
1402 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
1403 elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
1404 if NumEntryPoints < 2:\r
1405 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
1406 else:\r
1407 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
1408 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
1409 elif Info.ModuleType == 'DXE_SMM_DRIVER':\r
1410 if NumEntryPoints == 0:\r
1411 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
1412 else:\r
1413 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
1414 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) \r
1415 elif Info.ModuleType == 'UEFI_APPLICATION':\r
1416 if NumEntryPoints < 2:\r
1417 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
1418 else:\r
1419 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))\r
1420 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))\r
1421\r
1422## Create code for ModuleUnloadImage\r
1423#\r
1424# @param Info The ModuleAutoGen object\r
1425# @param AutoGenC The TemplateString object for C code\r
1426# @param AutoGenH The TemplateString object for header file\r
1427#\r
1428def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
1429 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1430 return\r
1431 #\r
1432 # Unload Image Handlers\r
1433 #\r
1434 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1435 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}\r
1436 if NumUnloadImage < 2:\r
1437 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))\r
1438 else:\r
1439 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))\r
1440 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))\r
1441\r
1442## Create code for GUID\r
1443#\r
1444# @param Info The ModuleAutoGen object\r
1445# @param AutoGenC The TemplateString object for C code\r
1446# @param AutoGenH The TemplateString object for header file\r
1447#\r
1448def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1449 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1450 GuidType = "GUID"\r
1451 else:\r
1452 GuidType = "EFI_GUID"\r
1453\r
1454 if Info.GuidList:\r
7beed8a3
YZ
1455 if not Info.IsLibrary:\r
1456 AutoGenC.Append("\n// Guids\n")\r
8262037f 1457 AutoGenH.Append("\n// Guids\n")\r
f51461c8
LG
1458 #\r
1459 # GUIDs\r
1460 #\r
1461 for Key in Info.GuidList:\r
7beed8a3
YZ
1462 if not Info.IsLibrary:\r
1463 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
8262037f 1464 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1465\r
1466## Create code for protocol\r
1467#\r
1468# @param Info The ModuleAutoGen object\r
1469# @param AutoGenC The TemplateString object for C code\r
1470# @param AutoGenH The TemplateString object for header file\r
1471#\r
1472def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1473 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1474 GuidType = "GUID"\r
1475 else:\r
1476 GuidType = "EFI_GUID"\r
1477\r
1478 if Info.ProtocolList:\r
7beed8a3
YZ
1479 if not Info.IsLibrary:\r
1480 AutoGenC.Append("\n// Protocols\n")\r
8262037f 1481 AutoGenH.Append("\n// Protocols\n")\r
f51461c8
LG
1482 #\r
1483 # Protocol GUIDs\r
1484 #\r
1485 for Key in Info.ProtocolList:\r
7beed8a3
YZ
1486 if not Info.IsLibrary:\r
1487 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
8262037f 1488 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1489\r
1490## Create code for PPI\r
1491#\r
1492# @param Info The ModuleAutoGen object\r
1493# @param AutoGenC The TemplateString object for C code\r
1494# @param AutoGenH The TemplateString object for header file\r
1495#\r
1496def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1497 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1498 GuidType = "GUID"\r
1499 else:\r
1500 GuidType = "EFI_GUID"\r
1501\r
1502 if Info.PpiList:\r
7beed8a3
YZ
1503 if not Info.IsLibrary:\r
1504 AutoGenC.Append("\n// PPIs\n")\r
8262037f 1505 AutoGenH.Append("\n// PPIs\n")\r
f51461c8
LG
1506 #\r
1507 # PPI GUIDs\r
1508 #\r
1509 for Key in Info.PpiList:\r
7beed8a3
YZ
1510 if not Info.IsLibrary:\r
1511 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
8262037f 1512 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1513\r
1514## Create code for PCD\r
1515#\r
1516# @param Info The ModuleAutoGen object\r
1517# @param AutoGenC The TemplateString object for C code\r
1518# @param AutoGenH The TemplateString object for header file\r
1519#\r
1520def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1521\r
1522 # Collect Token Space GUIDs used by DynamicEc PCDs\r
1523 TokenSpaceList = []\r
1524 for Pcd in Info.ModulePcdList:\r
1525 if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
1526 TokenSpaceList += [Pcd.TokenSpaceGuidCName]\r
1527 \r
1528 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
1529 if TokenSpaceList <> []: \r
1530 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
1531 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1532 GuidType = "GUID"\r
1533 else:\r
1534 GuidType = "EFI_GUID" \r
1535 for Item in TokenSpaceList:\r
1536 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
1537\r
1538 if Info.IsLibrary:\r
1539 if Info.ModulePcdList:\r
1540 AutoGenH.Append("\n// PCD definitions\n")\r
1541 for Pcd in Info.ModulePcdList:\r
1542 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1543 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1544 else:\r
1545 if Info.ModulePcdList:\r
1546 AutoGenH.Append("\n// Definition of PCDs used in this module\n")\r
1547 AutoGenC.Append("\n// Definition of PCDs used in this module\n")\r
1548 for Pcd in Info.ModulePcdList:\r
1549 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1550 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1551 if Info.LibraryPcdList:\r
1552 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")\r
1553 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")\r
1554 for Pcd in Info.LibraryPcdList:\r
1555 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)\r
1556 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1557\r
1558## Create code for unicode string definition\r
1559#\r
1560# @param Info The ModuleAutoGen object\r
1561# @param AutoGenC The TemplateString object for C code\r
1562# @param AutoGenH The TemplateString object for header file\r
1563# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1564# @param UniGenBinBuffer Buffer to store uni string package data\r
1565#\r
1566def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):\r
1567 WorkingDir = os.getcwd()\r
1568 os.chdir(Info.WorkspaceDir)\r
1569\r
1570 IncList = [Info.MetaFile.Dir]\r
1571 # Get all files under [Sources] section in inf file for EDK-II module\r
1572 EDK2Module = True\r
1573 SrcList = [F for F in Info.SourceFileList]\r
1574 if Info.AutoGenVersion < 0x00010005:\r
1575 EDK2Module = False\r
1576 # Get all files under the module directory for EDK-I module\r
1577 Cwd = os.getcwd()\r
1578 os.chdir(Info.MetaFile.Dir)\r
1579 for Root, Dirs, Files in os.walk("."):\r
1580 if 'CVS' in Dirs:\r
1581 Dirs.remove('CVS')\r
1582 if '.svn' in Dirs:\r
1583 Dirs.remove('.svn')\r
1584 for File in Files:\r
1585 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)\r
1586 if File in SrcList:\r
1587 continue\r
1588 SrcList.append(File)\r
1589 os.chdir(Cwd)\r
1590\r
1591 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:\r
1592 CompatibleMode = True\r
1593 else:\r
1594 CompatibleMode = False\r
1595\r
1596 #\r
1597 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2\r
1598 #\r
1599 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:\r
1600 if CompatibleMode:\r
1601 EdkLogger.error("build", AUTOGEN_ERROR,\r
1602 "-c and -s build options should be used exclusively",\r
1603 ExtraData="[%s]" % str(Info))\r
1604 ShellMode = True\r
1605 else:\r
1606 ShellMode = False\r
1607\r
1608 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules\r
1609 if EDK2Module:\r
1610 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]\r
1611 else:\r
1612 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]\r
1613 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)\r
1614 if CompatibleMode or UniGenCFlag:\r
1615 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1616 AutoGenC.Append(Code)\r
1617 AutoGenC.Append("\n")\r
1618 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1619 AutoGenH.Append(Header)\r
1620 if CompatibleMode or UniGenCFlag:\r
1621 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1622 os.chdir(WorkingDir)\r
1623\r
333ba578
YZ
1624def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):\r
1625 if len(Info.IdfFileList) > 0:\r
1626 ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList))\r
1627 if ImageFiles.ImageFilesDict:\r
1628 Index = 1\r
1629 PaletteIndex = 1\r
1630 IncList = [Info.MetaFile.Dir]\r
1631 SrcList = [F for F in Info.SourceFileList]\r
1632 SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf']\r
1633 FileList = GetFileList(SrcList, IncList, SkipList)\r
1634 ValueStartPtr = 60\r
1635 StringH.Append("\n//\n//Image ID\n//\n")\r
1636 ImageInfoOffset = 0\r
1637 PaletteInfoOffset = 0\r
1638 ImageBuffer = pack('x')\r
1639 PaletteBuffer = pack('x')\r
1640 BufferStr = ''\r
1641 PaletteStr = ''\r
6d034a2a 1642 FileDict = {}\r
333ba578
YZ
1643 for Idf in ImageFiles.ImageFilesDict:\r
1644 if ImageFiles.ImageFilesDict[Idf]:\r
1645 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1646 for sourcefile in Info.SourceFileList:\r
1647 if FileObj.FileName == sourcefile.File:\r
1648 if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']:\r
1649 EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info))\r
1650 FileObj.File = sourcefile\r
1651 break\r
1652 else:\r
1653 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
1654\r
1655 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1656 ID = FileObj.ImageID\r
1657 File = FileObj.File\r
1658 if not os.path.exists(File.Path) or not os.path.isfile(File.Path):\r
1659 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path)\r
1660 SearchImageID (FileObj, FileList)\r
1661 if FileObj.Referenced:\r
1662 if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0:\r
1663 Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n'\r
1664 else:\r
1665 Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n'\r
1666\r
6d034a2a
YZ
1667 if File not in FileDict:\r
1668 FileDict[File] = Index\r
1669 else:\r
1670 DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE)\r
1671 DuplicateBlock += pack('H', FileDict[File])\r
1672 ImageBuffer += DuplicateBlock\r
1673 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1674 TempBufferList = AscToHexList(DuplicateBlock)\r
1675 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1676 StringH.Append(Line)\r
1677 Index += 1\r
1678 continue\r
1679\r
333ba578
YZ
1680 TmpFile = open(File.Path, 'rb')\r
1681 Buffer = TmpFile.read()\r
1682 TmpFile.close()\r
1683 if File.Ext.upper() == '.PNG':\r
1684 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG)\r
1685 TempBuffer += pack('I', len(Buffer))\r
1686 TempBuffer += Buffer\r
1687 elif File.Ext.upper() == '.JPG':\r
1688 ImageType, = struct.unpack('4s', Buffer[6:10])\r
1689 if ImageType != 'JFIF':\r
1690 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path)\r
1691 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG)\r
1692 TempBuffer += pack('I', len(Buffer))\r
1693 TempBuffer += Buffer\r
1694 elif File.Ext.upper() == '.BMP':\r
1695 TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent)\r
1696 if len(TempPalette) > 1:\r
1697 PaletteIndex += 1\r
e148e6e9
YZ
1698 NewPalette = pack('H', len(TempPalette))\r
1699 NewPalette += TempPalette\r
1700 PaletteBuffer += NewPalette\r
333ba578 1701 PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4)))\r
e148e6e9 1702 TempPaletteList = AscToHexList(NewPalette)\r
333ba578
YZ
1703 PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n')\r
1704 ImageBuffer += TempBuffer\r
1705 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1706 TempBufferList = AscToHexList(TempBuffer)\r
1707 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1708\r
1709 StringH.Append(Line)\r
1710 Index += 1\r
1711\r
1712 BufferStr = WriteLine(BufferStr, '// End of the Image Info')\r
1713 BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n')\r
1714 ImageEnd = pack('B', EFI_HII_IIBT_END)\r
1715 ImageBuffer += ImageEnd\r
1716\r
1717 if len(ImageBuffer) > 1:\r
1718 ImageInfoOffset = 12\r
1719 if len(PaletteBuffer) > 1:\r
1720 PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer\r
1721\r
1722 IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset)\r
1723 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length\r
1724 if len(PaletteBuffer) > 1:\r
1725 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1\r
1726 else:\r
1727 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1\r
1728 if PaletteIndex > 1:\r
1729 PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1)\r
1730 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF\r
1731 Hex_Length = '%06X' % PACKAGE_HEADER_Length\r
1732 if PACKAGE_HEADER_Length > 0xFFFFFF:\r
1733 EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info))\r
1734 PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES)\r
1735\r
1736 IdfGenBinBuffer.write(PACKAGE_HEADER)\r
1737 IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR)\r
1738 if len(ImageBuffer) > 1 :\r
1739 IdfGenBinBuffer.write(ImageBuffer[1:])\r
1740 if PaletteIndex > 1:\r
1741 IdfGenBinBuffer.write(PALETTE_INFO_HEADER)\r
1742 if len(PaletteBuffer) > 1:\r
1743 IdfGenBinBuffer.write(PaletteBuffer[1:])\r
1744\r
1745 if IdfGenCFlag:\r
1746 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length\r
1747 AutoGenC.Append("\n//\n//Image Pack Definition\n//\n")\r
1748 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n')\r
1749 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')\r
1750 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')\r
1751 AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n')\r
1752 IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER)\r
1753 IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR)\r
1754 AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n')\r
1755 AllStr = WriteLine(AllStr, '// Image DATA\n')\r
1756 if BufferStr:\r
1757 AllStr = WriteLine(AllStr, BufferStr)\r
1758 if PaletteStr:\r
1759 AllStr = WriteLine(AllStr, '// Palette Header\n')\r
1760 PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER)\r
1761 AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n')\r
1762 AllStr = WriteLine(AllStr, '// Palette Data\n')\r
1763 AllStr = WriteLine(AllStr, PaletteStr)\r
1764 AllStr = WriteLine(AllStr, '};')\r
1765 AutoGenC.Append(AllStr)\r
1766 AutoGenC.Append("\n")\r
1767 StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n')\r
1768 StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName)\r
1769\r
1770# typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {\r
1771# EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES\r
1772# UINT32 ImageInfoOffset;\r
1773# UINT32 PaletteInfoOffset;\r
1774# } EFI_HII_IMAGE_PACKAGE_HDR;\r
1775\r
1776# typedef struct {\r
1777# UINT32 Length:24;\r
1778# UINT32 Type:8;\r
1779# UINT8 Data[];\r
1780# } EFI_HII_PACKAGE_HEADER;\r
1781\r
1782# typedef struct _EFI_HII_IMAGE_BLOCK {\r
1783# UINT8 BlockType;\r
1784# UINT8 BlockBody[];\r
1785# } EFI_HII_IMAGE_BLOCK;\r
1786\r
1787def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):\r
1788 ImageType, = struct.unpack('2s', Buffer[0:2])\r
1789 if ImageType!= 'BM': # BMP file type is 'BM'\r
1790 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)\r
1791 BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])\r
1792 BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')\r
1793 BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))\r
1794 #\r
1795 # Doesn't support compress.\r
1796 #\r
1797 if BmpHeader.biCompression != 0:\r
1798 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path)\r
1799\r
1800 # The Width and Height is UINT16 type in Image Package\r
1801 if BmpHeader.biWidth > 0xFFFF:\r
1802 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path)\r
1803 if BmpHeader.biHeight > 0xFFFF:\r
1804 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path)\r
1805\r
1806 PaletteBuffer = pack('x')\r
1807 if BmpHeader.biBitCount == 1:\r
1808 if TransParent:\r
1809 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)\r
1810 else:\r
1811 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)\r
1812 ImageBuffer += pack('B', PaletteIndex)\r
1813 Width = (BmpHeader.biWidth + 7)/8\r
1814 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1815 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1816 elif BmpHeader.biBitCount == 4:\r
1817 if TransParent:\r
1818 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)\r
1819 else:\r
1820 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)\r
1821 ImageBuffer += pack('B', PaletteIndex)\r
1822 Width = (BmpHeader.biWidth + 1)/2\r
1823 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1824 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1825 elif BmpHeader.biBitCount == 8:\r
1826 if TransParent:\r
1827 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)\r
1828 else:\r
1829 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT)\r
1830 ImageBuffer += pack('B', PaletteIndex)\r
1831 Width = BmpHeader.biWidth\r
1832 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1833 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1834 elif BmpHeader.biBitCount == 24:\r
1835 if TransParent:\r
1836 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS)\r
1837 else:\r
1838 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT)\r
1839 Width = BmpHeader.biWidth * 3\r
1840 else:\r
1841 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path))\r
1842\r
1843 ImageBuffer += pack('H', BmpHeader.biWidth)\r
1844 ImageBuffer += pack('H', BmpHeader.biHeight)\r
1845 Start = BmpHeader.bfOffBits\r
1846 End = BmpHeader.bfSize - 1\r
1847 for Height in range(0, BmpHeader.biHeight):\r
1848 if Width % 4 != 0:\r
1849 Start = End + (Width % 4) - 4 - Width\r
1850 else:\r
1851 Start = End - Width\r
1852 ImageBuffer += Buffer[Start + 1 : Start + Width + 1]\r
1853 End = Start\r
1854\r
1855 # 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
1856 if PaletteBuffer and len(PaletteBuffer) > 1:\r
1857 PaletteTemp = pack('x')\r
1858 for Index in range(0, len(PaletteBuffer)):\r
1859 if Index % 4 == 3:\r
1860 continue\r
1861 PaletteTemp += PaletteBuffer[Index]\r
1862 PaletteBuffer = PaletteTemp[1:]\r
1863 return ImageBuffer, PaletteBuffer\r
1864\r
f51461c8
LG
1865## Create common code\r
1866#\r
1867# @param Info The ModuleAutoGen object\r
1868# @param AutoGenC The TemplateString object for C code\r
1869# @param AutoGenH The TemplateString object for header file\r
1870#\r
1871def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
1872 # file header\r
1873 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
1874 # header file Prologue\r
1875 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))\r
1876 AutoGenH.Append(gAutoGenHCppPrologueString)\r
1877 if Info.AutoGenVersion >= 0x00010005:\r
1878 # header files includes\r
1879 AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)\r
1880 if Info.ModuleType in gModuleTypeHeaderFile \\r
1881 and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:\r
1882 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
1883 #\r
1884 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h \r
1885 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
1886 #\r
1887 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
1888 AutoGenH.Append("#include <Library/PcdLib.h>\n")\r
1889\r
1890 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')\r
1891 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')\r
1892\r
1893 if Info.IsLibrary:\r
1894 return\r
1895\r
1896 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
1897\r
1898 if Info.IsLibrary:\r
1899 return\r
1900 # C file header\r
1901 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))\r
1902 if Info.AutoGenVersion >= 0x00010005:\r
1903 # C file header files includes\r
1904 if Info.ModuleType in gModuleTypeHeaderFile:\r
1905 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
1906 AutoGenC.Append("#include <%s>\n" % Inc)\r
1907 else:\r
1908 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)\r
1909\r
1910 #\r
1911 # Publish the CallerId Guid\r
1912 #\r
1913 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
1914 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)\r
1915\r
1916## Create common code for header file\r
1917#\r
1918# @param Info The ModuleAutoGen object\r
1919# @param AutoGenC The TemplateString object for C code\r
1920# @param AutoGenH The TemplateString object for header file\r
1921#\r
1922def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
1923 AutoGenH.Append(gAutoGenHEpilogueString)\r
1924\r
1925## Create code for a module\r
1926#\r
1927# @param Info The ModuleAutoGen object\r
1928# @param AutoGenC The TemplateString object for C code\r
1929# @param AutoGenH The TemplateString object for header file\r
333ba578 1930# @param StringH The TemplateString object for header file\r
f51461c8
LG
1931# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1932# @param UniGenBinBuffer Buffer to store uni string package data\r
333ba578
YZ
1933# @param StringIdf The TemplateString object for header file\r
1934# @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True\r
1935# @param IdfGenBinBuffer Buffer to store Idf string package data\r
f51461c8 1936#\r
333ba578 1937def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):\r
f51461c8
LG
1938 CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
1939\r
1940 if Info.AutoGenVersion >= 0x00010005:\r
1941 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
1942 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
1943 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
1944 CreatePcdCode(Info, AutoGenC, AutoGenH)\r
1945 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
1946 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
1947 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
1948 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
1949\r
1950 if Info.UnicodeFileList:\r
1951 FileName = "%sStrDefs.h" % Info.Name\r
1952 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
1953 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
1954 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
8200fcfe
YL
1955\r
1956 GuidMacros = []\r
1957 for Guid in Info.Module.Guids:\r
1958 if Guid in Info.Module.GetGuidsUsedByPcd():\r
1959 continue\r
1960 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
1961 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
1962 GuidMacros.append('#define %s %s' % (Guid, Value))\r
5b97eb4c
YZ
1963 # supports FixedAtBuild usage in VFR file\r
1964 if Info.VfrFileList and Info.ModulePcdList:\r
1965 GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))\r
1966 GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))\r
1967 GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))\r
1968 GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))\r
1969 GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))\r
1970 for Pcd in Info.ModulePcdList:\r
1971 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1972 TokenCName = Pcd.TokenCName\r
1973 Value = Pcd.DefaultValue\r
1974 if Pcd.DatumType == 'BOOLEAN':\r
1975 BoolValue = Value.upper()\r
1976 if BoolValue == 'TRUE':\r
1977 Value = '1'\r
1978 elif BoolValue == 'FALSE':\r
1979 Value = '0'\r
1980 for PcdItem in GlobalData.MixedPcd:\r
1981 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1982 TokenCName = PcdItem[0]\r
1983 break\r
1984 GuidMacros.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName, Value))\r
1985\r
8200fcfe
YL
1986 if GuidMacros:\r
1987 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))\r
1988\r
f51461c8
LG
1989 StringH.Append("\n#endif\n")\r
1990 AutoGenH.Append('#include "%s"\n' % FileName)\r
1991\r
333ba578
YZ
1992 if Info.IdfFileList:\r
1993 FileName = "%sImgDefs.h" % Info.Name\r
1994 StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
1995 StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
1996 CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)\r
1997\r
1998 StringIdf.Append("\n#endif\n")\r
1999 AutoGenH.Append('#include "%s"\n' % FileName)\r
2000\r
f51461c8
LG
2001 CreateFooterCode(Info, AutoGenC, AutoGenH)\r
2002\r
2003 # no generation of AutoGen.c for Edk modules without unicode file\r
2004 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:\r
2005 AutoGenC.String = ''\r
2006\r
2007## Create the code file\r
2008#\r
2009# @param FilePath The path of code file\r
2010# @param Content The content of code file\r
2011# @param IsBinaryFile The flag indicating if the file is binary file or not\r
2012#\r
2013# @retval True If file content is changed or file doesn't exist\r
2014# @retval False If the file exists and the content is not changed\r
2015#\r
2016def Generate(FilePath, Content, IsBinaryFile):\r
2017 return SaveFileOnChange(FilePath, Content, IsBinaryFile)\r
2018\r