2 # Routines for generating AutoGen.h and AutoGen.c
4 # Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from Common
import EdkLogger
20 from Common
.BuildToolError
import *
21 from Common
.DataType
import *
22 from Common
.Misc
import *
23 from Common
.String
import StringToArray
24 from StrGather
import *
25 from GenPcdDb
import CreatePcdDatabaseCode
28 gItemTypeStringDatabase
= {
29 TAB_PCDS_FEATURE_FLAG
: 'FixedAtBuild',
30 TAB_PCDS_FIXED_AT_BUILD
: 'FixedAtBuild',
31 TAB_PCDS_PATCHABLE_IN_MODULE
: 'BinaryPatch',
32 TAB_PCDS_DYNAMIC
: '',
33 TAB_PCDS_DYNAMIC_DEFAULT
: '',
34 TAB_PCDS_DYNAMIC_VPD
: '',
35 TAB_PCDS_DYNAMIC_HII
: '',
36 TAB_PCDS_DYNAMIC_EX
: '',
37 TAB_PCDS_DYNAMIC_EX_DEFAULT
: '',
38 TAB_PCDS_DYNAMIC_EX_VPD
: '',
39 TAB_PCDS_DYNAMIC_EX_HII
: '',
43 gDynamicPcd
= [TAB_PCDS_DYNAMIC
, TAB_PCDS_DYNAMIC_DEFAULT
, TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_HII
]
45 ## Dynamic-ex PCD types
46 gDynamicExPcd
= [TAB_PCDS_DYNAMIC_EX
, TAB_PCDS_DYNAMIC_EX_DEFAULT
, TAB_PCDS_DYNAMIC_EX_VPD
, TAB_PCDS_DYNAMIC_EX_HII
]
49 gDatumSizeStringDatabase
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}
50 gDatumSizeStringDatabaseH
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}
51 gDatumSizeStringDatabaseLib
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}
53 ## AutoGen File Header Templates
54 gAutoGenHeaderString
= TemplateString("""\
60 Abstract: Auto-generated ${FileName} for building module or library.
64 gAutoGenHPrologueString
= TemplateString("""
65 #ifndef _${File}_${Guid}
66 #define _${File}_${Guid}
70 gAutoGenHCppPrologueString
= """\
77 gAutoGenHEpilogueString
= """
86 ## PEI Core Entry Point Templates
87 gPeiCoreEntryPointPrototype
= TemplateString("""
92 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
93 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
99 gPeiCoreEntryPointString
= TemplateString("""
103 ProcessModuleEntryPointList (
104 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
105 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
110 ${Function} (SecCoreData, PpiList, Context);
116 ## DXE Core Entry Point Templates
117 gDxeCoreEntryPointPrototype
= TemplateString("""
127 gDxeCoreEntryPointString
= TemplateString("""
131 ProcessModuleEntryPointList (
136 ${Function} (HobStart);
141 ## PEIM Entry Point Templates
142 gPeimEntryPointPrototype
= TemplateString("""
147 IN EFI_PEI_FILE_HANDLE FileHandle,
148 IN CONST EFI_PEI_SERVICES **PeiServices
153 gPeimEntryPointString
= [
155 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
159 ProcessModuleEntryPointList (
160 IN EFI_PEI_FILE_HANDLE FileHandle,
161 IN CONST EFI_PEI_SERVICES **PeiServices
169 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
173 ProcessModuleEntryPointList (
174 IN EFI_PEI_FILE_HANDLE FileHandle,
175 IN CONST EFI_PEI_SERVICES **PeiServices
179 return ${Function} (FileHandle, PeiServices);
184 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
188 ProcessModuleEntryPointList (
189 IN EFI_PEI_FILE_HANDLE FileHandle,
190 IN CONST EFI_PEI_SERVICES **PeiServices
195 EFI_STATUS CombinedStatus;
197 CombinedStatus = EFI_LOAD_ERROR;
199 Status = ${Function} (FileHandle, PeiServices);
200 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
201 CombinedStatus = Status;
204 return CombinedStatus;
209 ## SMM_CORE Entry Point Templates
210 gSmmCoreEntryPointPrototype
= TemplateString("""
215 IN EFI_HANDLE ImageHandle,
216 IN EFI_SYSTEM_TABLE *SystemTable
221 gSmmCoreEntryPointString
= TemplateString("""
223 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
224 const UINT32 _gDxeRevision = ${PiSpecVersion};
228 ProcessModuleEntryPointList (
229 IN EFI_HANDLE ImageHandle,
230 IN EFI_SYSTEM_TABLE *SystemTable
233 return ${Function} (ImageHandle, SystemTable);
238 ## DXE SMM Entry Point Templates
239 gDxeSmmEntryPointPrototype
= TemplateString("""
244 IN EFI_HANDLE ImageHandle,
245 IN EFI_SYSTEM_TABLE *SystemTable
250 gDxeSmmEntryPointString
= [
252 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
253 const UINT32 _gDxeRevision = ${PiSpecVersion};
257 ProcessModuleEntryPointList (
258 IN EFI_HANDLE ImageHandle,
259 IN EFI_SYSTEM_TABLE *SystemTable
267 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
268 const UINT32 _gDxeRevision = ${PiSpecVersion};
270 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
271 static EFI_STATUS mDriverEntryPointStatus;
279 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
280 mDriverEntryPointStatus = Status;
282 LongJump (&mJumpContext, (UINTN)-1);
288 ProcessModuleEntryPointList (
289 IN EFI_HANDLE ImageHandle,
290 IN EFI_SYSTEM_TABLE *SystemTable
293 mDriverEntryPointStatus = EFI_LOAD_ERROR;
296 if (SetJump (&mJumpContext) == 0) {
297 ExitDriver (${Function} (ImageHandle, SystemTable));
302 return mDriverEntryPointStatus;
307 ## UEFI Driver Entry Point Templates
308 gUefiDriverEntryPointPrototype
= TemplateString("""
313 IN EFI_HANDLE ImageHandle,
314 IN EFI_SYSTEM_TABLE *SystemTable
319 gUefiDriverEntryPointString
= [
321 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
322 const UINT32 _gDxeRevision = ${PiSpecVersion};
326 ProcessModuleEntryPointList (
327 IN EFI_HANDLE ImageHandle,
328 IN EFI_SYSTEM_TABLE *SystemTable
335 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
336 const UINT32 _gDxeRevision = ${PiSpecVersion};
341 ProcessModuleEntryPointList (
342 IN EFI_HANDLE ImageHandle,
343 IN EFI_SYSTEM_TABLE *SystemTable
347 return ${Function} (ImageHandle, SystemTable);
356 if (EFI_ERROR (Status)) {
357 ProcessLibraryDestructorList (gImageHandle, gST);
359 gBS->Exit (gImageHandle, Status, 0, NULL);
363 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
364 const UINT32 _gDxeRevision = ${PiSpecVersion};
366 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
367 static EFI_STATUS mDriverEntryPointStatus;
371 ProcessModuleEntryPointList (
372 IN EFI_HANDLE ImageHandle,
373 IN EFI_SYSTEM_TABLE *SystemTable
376 mDriverEntryPointStatus = EFI_LOAD_ERROR;
378 if (SetJump (&mJumpContext) == 0) {
379 ExitDriver (${Function} (ImageHandle, SystemTable));
383 return mDriverEntryPointStatus;
392 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
393 mDriverEntryPointStatus = Status;
395 LongJump (&mJumpContext, (UINTN)-1);
402 ## UEFI Application Entry Point Templates
403 gUefiApplicationEntryPointPrototype
= TemplateString("""
408 IN EFI_HANDLE ImageHandle,
409 IN EFI_SYSTEM_TABLE *SystemTable
414 gUefiApplicationEntryPointString
= [
416 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
420 ProcessModuleEntryPointList (
421 IN EFI_HANDLE ImageHandle,
422 IN EFI_SYSTEM_TABLE *SystemTable
429 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
434 ProcessModuleEntryPointList (
435 IN EFI_HANDLE ImageHandle,
436 IN EFI_SYSTEM_TABLE *SystemTable
440 return ${Function} (ImageHandle, SystemTable);
449 if (EFI_ERROR (Status)) {
450 ProcessLibraryDestructorList (gImageHandle, gST);
452 gBS->Exit (gImageHandle, Status, 0, NULL);
456 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
460 ProcessModuleEntryPointList (
461 IN EFI_HANDLE ImageHandle,
462 IN EFI_SYSTEM_TABLE *SystemTable
467 if (SetJump (&mJumpContext) == 0) {
468 ExitDriver (${Function} (ImageHandle, SystemTable));
472 return mDriverEntryPointStatus;
475 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
476 static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
484 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
485 mDriverEntryPointStatus = Status;
487 LongJump (&mJumpContext, (UINTN)-1);
493 ## UEFI Unload Image Templates
494 gUefiUnloadImagePrototype
= TemplateString("""
499 IN EFI_HANDLE ImageHandle
504 gUefiUnloadImageString
= [
506 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
510 ProcessModuleUnloadList (
511 IN EFI_HANDLE ImageHandle
518 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
523 ProcessModuleUnloadList (
524 IN EFI_HANDLE ImageHandle
527 return ${Function} (ImageHandle);
532 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
536 ProcessModuleUnloadList (
537 IN EFI_HANDLE ImageHandle
542 Status = EFI_SUCCESS;
544 if (EFI_ERROR (Status)) {
545 ${Function} (ImageHandle);
547 Status = ${Function} (ImageHandle);
555 gLibraryStructorPrototype
= {
556 'BASE' : TemplateString("""${BEGIN}
564 'PEI' : TemplateString("""${BEGIN}
568 IN EFI_PEI_FILE_HANDLE FileHandle,
569 IN CONST EFI_PEI_SERVICES **PeiServices
573 'DXE' : TemplateString("""${BEGIN}
577 IN EFI_HANDLE ImageHandle,
578 IN EFI_SYSTEM_TABLE *SystemTable
583 gLibraryStructorCall
= {
584 'BASE' : TemplateString("""${BEGIN}
585 Status = ${Function} ();
586 ASSERT_EFI_ERROR (Status);${END}
589 'PEI' : TemplateString("""${BEGIN}
590 Status = ${Function} (FileHandle, PeiServices);
591 ASSERT_EFI_ERROR (Status);${END}
594 'DXE' : TemplateString("""${BEGIN}
595 Status = ${Function} (ImageHandle, SystemTable);
596 ASSERT_EFI_ERROR (Status);${END}
600 ## Library Constructor and Destructor Templates
602 'BASE' : TemplateString("""
603 ${BEGIN}${FunctionPrototype}${END}
607 ProcessLibrary${Type}List (
611 ${BEGIN} EFI_STATUS Status;
612 ${FunctionCall}${END}
616 'PEI' : TemplateString("""
617 ${BEGIN}${FunctionPrototype}${END}
621 ProcessLibrary${Type}List (
622 IN EFI_PEI_FILE_HANDLE FileHandle,
623 IN CONST EFI_PEI_SERVICES **PeiServices
626 ${BEGIN} EFI_STATUS Status;
627 ${FunctionCall}${END}
631 'DXE' : TemplateString("""
632 ${BEGIN}${FunctionPrototype}${END}
636 ProcessLibrary${Type}List (
637 IN EFI_HANDLE ImageHandle,
638 IN EFI_SYSTEM_TABLE *SystemTable
641 ${BEGIN} EFI_STATUS Status;
642 ${FunctionCall}${END}
647 gBasicHeaderFile
= "Base.h"
649 gModuleTypeHeaderFile
= {
650 "BASE" : [gBasicHeaderFile
],
651 "SEC" : ["PiPei.h", "Library/DebugLib.h"],
652 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],
653 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],
654 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],
655 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
656 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
657 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
658 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
659 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
660 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],
661 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],
662 "USER_DEFINED" : [gBasicHeaderFile
]
665 ## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
666 # the TokenName and Guid comparison to avoid define name collisions.
668 # @param Info The ModuleAutoGen object
669 # @param AutoGenH The TemplateString object for header file
672 def DynExPcdTokenNumberMapping(Info
, AutoGenH
):
673 ExTokenCNameList
= []
676 PcdList
= Info
.LibraryPcdList
678 PcdList
= Info
.ModulePcdList
680 if Pcd
.Type
in gDynamicExPcd
:
681 ExTokenCNameList
.append(Pcd
.TokenCName
)
682 PcdExList
.append(Pcd
)
683 if len(ExTokenCNameList
) == 0:
685 AutoGenH
.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')
686 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
687 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
688 # Use the Guid pointer to see if it matches any of the token space GUIDs.
690 for TokenCName
in ExTokenCNameList
:
691 if TokenCName
in TokenCNameList
:
694 Count
= ExTokenCNameList
.count(TokenCName
)
695 for Pcd
in PcdExList
:
696 RealTokenCName
= Pcd
.TokenCName
697 for PcdItem
in GlobalData
.MixedPcd
:
698 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
699 RealTokenCName
= PcdItem
[0]
701 if Pcd
.TokenCName
== TokenCName
:
704 AutoGenH
.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName
))
705 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
706 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
708 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
709 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
711 AutoGenH
.Append('0 \\\n )\n')
712 TokenCNameList
.append(TokenCName
)
715 for TokenCName
in ExTokenCNameList
:
716 if TokenCName
in TokenCNameList
:
719 Count
= ExTokenCNameList
.count(TokenCName
)
720 for Pcd
in PcdExList
:
721 RealTokenCName
= Pcd
.TokenCName
722 for PcdItem
in GlobalData
.MixedPcd
:
723 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
724 RealTokenCName
= PcdItem
[0]
726 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== TokenCName
:
729 AutoGenH
.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName
))
730 AutoGenH
.Append('\\\n (GuidPtr == NULL) ? 0:')
731 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
732 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
734 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
735 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
737 AutoGenH
.Append('0 \\\n )\n')
738 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
739 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
740 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
741 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
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'
743 % (RealTokenCName
, RealTokenCName
, RealTokenCName
, RealTokenCName
))
744 TokenCNameList
.append(TokenCName
)
747 if Pcd
.DatumType
== 'VOID*':
748 Value
= Pcd
.DefaultValue
749 if Value
in [None, '']:
751 elif Value
[0] == 'L':
752 return (len(Value
) - 2) * 2
753 elif Value
[0] == '{':
754 return len(Value
.split(','))
756 return len(Value
) - 1
757 if Pcd
.DatumType
== 'UINT64':
759 if Pcd
.DatumType
== 'UINT32':
761 if Pcd
.DatumType
== 'UINT16':
763 if Pcd
.DatumType
== 'UINT8':
765 if Pcd
.DatumType
== 'BOOLEAN':
769 ## Create code for module PCDs
771 # @param Info The ModuleAutoGen object
772 # @param AutoGenC The TemplateString object for C code
773 # @param AutoGenH The TemplateString object for header file
774 # @param Pcd The PCD object
776 def CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
777 TokenSpaceGuidValue
= Pcd
.TokenSpaceGuidValue
#Info.GuidList[Pcd.TokenSpaceGuidCName]
778 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
782 TokenCName
= Pcd
.TokenCName
783 for PcdItem
in GlobalData
.MixedPcd
:
784 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
785 TokenCName
= PcdItem
[0]
787 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
788 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
789 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
790 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
792 if GlobalData
.BuildOptionPcd
:
793 for PcdItem
in GlobalData
.BuildOptionPcd
:
794 if (Pcd
.TokenSpaceGuidCName
, TokenCName
) == (PcdItem
[0], PcdItem
[1]):
795 Pcd
.DefaultValue
= PcdItem
[2]
798 if Pcd
.Type
in gDynamicExPcd
:
799 TokenNumber
= int(Pcd
.TokenValue
, 0)
800 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
801 # different Guids but same TokenCName
802 PcdExTokenName
= '_PCD_TOKEN_' + Pcd
.TokenSpaceGuidCName
+ '_' + TokenCName
803 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
805 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
806 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
807 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
808 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
809 # report warning message notify the PI that they are attempting to build a module
810 # that must be included in a flash image in order to be functional. These Dynamic PCD
811 # will not be added into the Database unless it is used by other modules that are
812 # included in the FDF file.
813 # In this case, just assign an invalid token number to make it pass build.
814 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
817 EdkLogger
.error("build", AUTOGEN_ERROR
,
818 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
819 ExtraData
="[%s]" % str(Info
))
821 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
822 AutoGenH
.Append('\n#define %s %dU\n' % (PcdTokenName
, TokenNumber
))
824 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "Creating code for " + TokenCName
+ "." + Pcd
.TokenSpaceGuidCName
)
825 if Pcd
.Type
not in gItemTypeStringDatabase
:
826 EdkLogger
.error("build", AUTOGEN_ERROR
,
827 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
828 ExtraData
="[%s]" % str(Info
))
829 if Pcd
.DatumType
not in gDatumSizeStringDatabase
:
830 EdkLogger
.error("build", AUTOGEN_ERROR
,
831 "Unknown datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
832 ExtraData
="[%s]" % str(Info
))
834 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
]
835 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
]
836 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
837 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
838 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
839 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
842 if Pcd
.Type
in gDynamicExPcd
:
844 PcdList
= Info
.LibraryPcdList
846 PcdList
= Info
.ModulePcdList
847 for PcdModule
in PcdList
:
848 if PcdModule
.Type
in gDynamicExPcd
:
849 PcdExCNameList
.append(PcdModule
.TokenCName
)
850 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
851 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
852 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
853 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
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')
855 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
856 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
857 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
858 if Pcd
.DatumType
== 'VOID*':
859 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
860 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
862 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
863 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
865 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
866 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
867 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
868 if Pcd
.DatumType
== 'VOID*':
869 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
870 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
872 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
873 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
874 elif Pcd
.Type
in gDynamicPcd
:
877 PcdList
.extend(Info
.LibraryPcdList
)
878 PcdList
.extend(Info
.ModulePcdList
)
879 for PcdModule
in PcdList
:
880 if PcdModule
.Type
in gDynamicPcd
:
881 PcdCNameList
.append(PcdModule
.TokenCName
)
882 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
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
))
885 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
886 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
887 if Pcd
.DatumType
== 'VOID*':
888 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
889 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
891 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
892 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
894 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
896 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
900 Value
= Pcd
.DefaultValue
904 if Pcd
.DatumType
== 'BOOLEAN':
905 BoolValue
= Value
.upper()
906 if BoolValue
== 'TRUE' or BoolValue
== '1':
908 elif BoolValue
== 'FALSE' or BoolValue
== '0':
911 if Pcd
.DatumType
in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
913 if Value
.upper().startswith('0X'):
914 ValueNumber
= int (Value
, 16)
916 ValueNumber
= int (Value
)
918 EdkLogger
.error("build", AUTOGEN_ERROR
,
919 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
920 ExtraData
="[%s]" % str(Info
))
921 if Pcd
.DatumType
== 'UINT64':
923 EdkLogger
.error("build", AUTOGEN_ERROR
,
924 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
925 ExtraData
="[%s]" % str(Info
))
926 elif ValueNumber
>= 0x10000000000000000:
927 EdkLogger
.error("build", AUTOGEN_ERROR
,
928 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
929 ExtraData
="[%s]" % str(Info
))
930 if not Value
.endswith('ULL'):
932 elif Pcd
.DatumType
== 'UINT32':
934 EdkLogger
.error("build", AUTOGEN_ERROR
,
935 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
936 ExtraData
="[%s]" % str(Info
))
937 elif ValueNumber
>= 0x100000000:
938 EdkLogger
.error("build", AUTOGEN_ERROR
,
939 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
940 ExtraData
="[%s]" % str(Info
))
941 if not Value
.endswith('U'):
943 elif Pcd
.DatumType
== 'UINT16':
945 EdkLogger
.error("build", AUTOGEN_ERROR
,
946 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
947 ExtraData
="[%s]" % str(Info
))
948 elif ValueNumber
>= 0x10000:
949 EdkLogger
.error("build", AUTOGEN_ERROR
,
950 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
951 ExtraData
="[%s]" % str(Info
))
952 if not Value
.endswith('U'):
954 elif Pcd
.DatumType
== 'UINT8':
956 EdkLogger
.error("build", AUTOGEN_ERROR
,
957 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
958 ExtraData
="[%s]" % str(Info
))
959 elif ValueNumber
>= 0x100:
960 EdkLogger
.error("build", AUTOGEN_ERROR
,
961 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
962 ExtraData
="[%s]" % str(Info
))
963 if not Value
.endswith('U'):
965 if Pcd
.DatumType
== 'VOID*':
966 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
967 EdkLogger
.error("build", AUTOGEN_ERROR
,
968 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
969 ExtraData
="[%s]" % str(Info
))
971 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
977 Value
= Value
.lstrip('L') #.strip('"')
978 Value
= eval(Value
) # translate escape character
980 for Index
in range(0,len(Value
)):
982 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ', '
984 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ', '
986 ArraySize
= ArraySize
/ 2;
988 if ArraySize
< (len(Value
) + 1):
989 EdkLogger
.error("build", AUTOGEN_ERROR
,
990 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
991 ExtraData
="[%s]" % str(Info
))
992 Value
= NewValue
+ '0 }'
993 Array
= '[%d]' % ArraySize
995 # skip casting for fixed at build since it breaks ARM assembly.
996 # Long term we need PCD macros that work in assembly
998 elif Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
999 Value
= "((%s)%s)" % (Pcd
.DatumType
, Value
)
1001 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1002 PcdValueName
= '_PCD_PATCHABLE_VALUE_' + TokenCName
1004 PcdValueName
= '_PCD_VALUE_' + TokenCName
1006 if Pcd
.DatumType
== 'VOID*':
1008 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1011 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1012 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1013 AutoGenH
.Append('extern %s UINT16 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1014 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1016 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1017 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1018 AutoGenH
.Append('extern %s UINT8 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1019 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1021 PcdDataSize
= GetPcdSize(Pcd
)
1022 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
1023 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1024 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1026 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1027 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1028 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1029 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1030 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1031 elif Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1032 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1033 AutoGenC
.Append('volatile %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1034 AutoGenH
.Append('extern volatile %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1035 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1037 PcdDataSize
= GetPcdSize(Pcd
)
1038 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1040 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1041 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1042 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1044 PcdDataSize
= GetPcdSize(Pcd
)
1045 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1046 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1048 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1049 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1050 AutoGenH
.Append('extern %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1051 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1053 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1054 if Pcd
.DatumType
== 'VOID*':
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
))
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
))
1058 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1059 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName
, PcdVariableName
))
1061 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1063 ## Create code for library module PCDs
1065 # @param Info The ModuleAutoGen object
1066 # @param AutoGenC The TemplateString object for C code
1067 # @param AutoGenH The TemplateString object for header file
1068 # @param Pcd The PCD object
1070 def CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
1071 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
1072 TokenSpaceGuidCName
= Pcd
.TokenSpaceGuidCName
1073 TokenCName
= Pcd
.TokenCName
1074 for PcdItem
in GlobalData
.MixedPcd
:
1075 if (TokenCName
, TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1076 TokenCName
= PcdItem
[0]
1078 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
1079 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
1080 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
1081 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
1083 if GlobalData
.BuildOptionPcd
:
1084 for PcdItem
in GlobalData
.BuildOptionPcd
:
1085 if (Pcd
.TokenSpaceGuidCName
, TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1086 Pcd
.DefaultValue
= PcdItem
[2]
1092 if Pcd
.Type
in gDynamicExPcd
:
1093 TokenNumber
= int(Pcd
.TokenValue
, 0)
1095 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
1096 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1097 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1098 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1099 # report warning message notify the PI that they are attempting to build a module
1100 # that must be included in a flash image in order to be functional. These Dynamic PCD
1101 # will not be added into the Database unless it is used by other modules that are
1102 # included in the FDF file.
1103 # In this case, just assign an invalid token number to make it pass build.
1104 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
1107 EdkLogger
.error("build", AUTOGEN_ERROR
,
1108 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1109 ExtraData
="[%s]" % str(Info
))
1111 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
1113 if Pcd
.Type
not in gItemTypeStringDatabase
:
1114 EdkLogger
.error("build", AUTOGEN_ERROR
,
1115 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1116 ExtraData
="[%s]" % str(Info
))
1117 if Pcd
.DatumType
not in gDatumSizeStringDatabase
:
1118 EdkLogger
.error("build", AUTOGEN_ERROR
,
1119 "Unknown datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1120 ExtraData
="[%s]" % str(Info
))
1122 DatumType
= Pcd
.DatumType
1123 DatumSize
= gDatumSizeStringDatabaseH
[DatumType
]
1124 DatumSizeLib
= gDatumSizeStringDatabaseLib
[DatumType
]
1125 GetModeName
= '_PCD_GET_MODE_' + DatumSize
+ '_' + TokenCName
1126 SetModeName
= '_PCD_SET_MODE_' + DatumSize
+ '_' + TokenCName
1127 SetModeStatusName
= '_PCD_SET_MODE_' + DatumSize
+ '_S_' + TokenCName
1128 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1132 if Pcd
.DatumType
== 'VOID*':
1133 if Pcd
.DefaultValue
[0]== '{':
1136 PcdItemType
= Pcd
.Type
1138 if PcdItemType
in gDynamicExPcd
:
1139 PcdExTokenName
= '_PCD_TOKEN_' + TokenSpaceGuidCName
+ '_' + TokenCName
1140 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
1143 PcdList
= Info
.LibraryPcdList
1145 PcdList
= Info
.ModulePcdList
1146 for PcdModule
in PcdList
:
1147 if PcdModule
.Type
in gDynamicExPcd
:
1148 PcdExCNameList
.append(PcdModule
.TokenCName
)
1149 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1150 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1151 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1152 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
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')
1154 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1155 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1156 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s \n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1157 if Pcd
.DatumType
== 'VOID*':
1158 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1159 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1161 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1162 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1164 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1165 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1166 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1167 if Pcd
.DatumType
== 'VOID*':
1168 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1169 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1171 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1172 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1174 AutoGenH
.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName
, TokenNumber
))
1175 if PcdItemType
in gDynamicPcd
:
1178 PcdList
.extend(Info
.LibraryPcdList
)
1179 PcdList
.extend(Info
.ModulePcdList
)
1180 for PcdModule
in PcdList
:
1181 if PcdModule
.Type
in gDynamicPcd
:
1182 PcdCNameList
.append(PcdModule
.TokenCName
)
1183 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
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
))
1186 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1187 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1188 if DatumType
== 'VOID*':
1189 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1190 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1192 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1193 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1194 if PcdItemType
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1195 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[TAB_PCDS_PATCHABLE_IN_MODULE
] + '_' + TokenCName
1196 if DatumType
== 'VOID*':
1197 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1198 if Pcd
.DefaultValue
[0] == 'L':
1199 ArraySize
= ArraySize
/ 2
1200 Array
= '[%d]' % ArraySize
1201 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1202 AutoGenH
.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1204 AutoGenH
.Append('extern volatile %s %s%s;\n' % (DatumType
, PcdVariableName
, Array
))
1205 AutoGenH
.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName
, Type
, TokenCName
))
1206 if Pcd
.DatumType
== 'VOID*':
1207 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
))
1208 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
))
1210 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1211 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName
, PcdVariableName
))
1213 PcdDataSize
= GetPcdSize(Pcd
)
1214 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1215 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1216 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1218 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
or PcdItemType
== TAB_PCDS_FEATURE_FLAG
:
1219 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1221 if DatumType
== 'VOID*' and Array
== '[]':
1222 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1223 AutoGenH
.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1224 AutoGenH
.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName
, Type
, TokenCName
))
1225 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1227 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
and key
in Info
.ConstPcd
:
1228 AutoGenH
.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName
, Pcd
.DefaultValue
))
1230 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
:
1231 PcdDataSize
= GetPcdSize(Pcd
)
1232 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1233 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1235 ## Create code for library constructor
1237 # @param Info The ModuleAutoGen object
1238 # @param AutoGenC The TemplateString object for C code
1239 # @param AutoGenH The TemplateString object for header file
1241 def CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
):
1243 # Library Constructors
1245 ConstructorPrototypeString
= TemplateString()
1246 ConstructorCallingString
= TemplateString()
1248 DependentLibraryList
= [Info
.Module
]
1250 DependentLibraryList
= Info
.DependentLibraryList
1251 for Lib
in DependentLibraryList
:
1252 if len(Lib
.ConstructorList
) <= 0:
1254 Dict
= {'Function':Lib
.ConstructorList
}
1255 if Lib
.ModuleType
in ['BASE', 'SEC']:
1256 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1257 ConstructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1258 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1259 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1260 ConstructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1261 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1262 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1263 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1264 ConstructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1266 if str(ConstructorPrototypeString
) == '':
1267 ConstructorPrototypeList
= []
1269 ConstructorPrototypeList
= [str(ConstructorPrototypeString
)]
1270 if str(ConstructorCallingString
) == '':
1271 ConstructorCallingList
= []
1273 ConstructorCallingList
= [str(ConstructorCallingString
)]
1276 'Type' : 'Constructor',
1277 'FunctionPrototype' : ConstructorPrototypeList
,
1278 'FunctionCall' : ConstructorCallingList
1281 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1283 if Info
.ModuleType
in ['BASE', 'SEC']:
1284 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1285 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1286 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1287 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1288 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1289 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1291 ## Create code for library destructor
1293 # @param Info The ModuleAutoGen object
1294 # @param AutoGenC The TemplateString object for C code
1295 # @param AutoGenH The TemplateString object for header file
1297 def CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
):
1299 # Library Destructors
1301 DestructorPrototypeString
= TemplateString()
1302 DestructorCallingString
= TemplateString()
1304 DependentLibraryList
= [Info
.Module
]
1306 DependentLibraryList
= Info
.DependentLibraryList
1307 for Index
in range(len(DependentLibraryList
)-1, -1, -1):
1308 Lib
= DependentLibraryList
[Index
]
1309 if len(Lib
.DestructorList
) <= 0:
1311 Dict
= {'Function':Lib
.DestructorList
}
1312 if Lib
.ModuleType
in ['BASE', 'SEC']:
1313 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1314 DestructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1315 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1316 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1317 DestructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1318 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1319 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1320 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1321 DestructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1323 if str(DestructorPrototypeString
) == '':
1324 DestructorPrototypeList
= []
1326 DestructorPrototypeList
= [str(DestructorPrototypeString
)]
1327 if str(DestructorCallingString
) == '':
1328 DestructorCallingList
= []
1330 DestructorCallingList
= [str(DestructorCallingString
)]
1333 'Type' : 'Destructor',
1334 'FunctionPrototype' : DestructorPrototypeList
,
1335 'FunctionCall' : DestructorCallingList
1338 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1340 if Info
.ModuleType
in ['BASE', 'SEC']:
1341 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1342 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1343 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1344 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1345 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1346 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1349 ## Create code for ModuleEntryPoint
1351 # @param Info The ModuleAutoGen object
1352 # @param AutoGenC The TemplateString object for C code
1353 # @param AutoGenH The TemplateString object for header file
1355 def CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
):
1356 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1359 # Module Entry Points
1361 NumEntryPoints
= len(Info
.Module
.ModuleEntryPointList
)
1362 if 'PI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1363 PiSpecVersion
= Info
.Module
.Specification
['PI_SPECIFICATION_VERSION']
1365 PiSpecVersion
= '0x00000000'
1366 if 'UEFI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1367 UefiSpecVersion
= Info
.Module
.Specification
['UEFI_SPECIFICATION_VERSION']
1369 UefiSpecVersion
= '0x00000000'
1371 'Function' : Info
.Module
.ModuleEntryPointList
,
1372 'PiSpecVersion' : PiSpecVersion
+ 'U',
1373 'UefiSpecVersion': UefiSpecVersion
+ 'U'
1376 if Info
.ModuleType
in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:
1377 if Info
.SourceFileList
<> None and Info
.SourceFileList
<> []:
1378 if NumEntryPoints
!= 1:
1382 '%s must have exactly one entry point' % Info
.ModuleType
,
1384 ExtraData
= ", ".join(Info
.Module
.ModuleEntryPointList
)
1386 if Info
.ModuleType
== 'PEI_CORE':
1387 AutoGenC
.Append(gPeiCoreEntryPointString
.Replace(Dict
))
1388 AutoGenH
.Append(gPeiCoreEntryPointPrototype
.Replace(Dict
))
1389 elif Info
.ModuleType
== 'DXE_CORE':
1390 AutoGenC
.Append(gDxeCoreEntryPointString
.Replace(Dict
))
1391 AutoGenH
.Append(gDxeCoreEntryPointPrototype
.Replace(Dict
))
1392 elif Info
.ModuleType
== 'SMM_CORE':
1393 AutoGenC
.Append(gSmmCoreEntryPointString
.Replace(Dict
))
1394 AutoGenH
.Append(gSmmCoreEntryPointPrototype
.Replace(Dict
))
1395 elif Info
.ModuleType
== 'PEIM':
1396 if NumEntryPoints
< 2:
1397 AutoGenC
.Append(gPeimEntryPointString
[NumEntryPoints
].Replace(Dict
))
1399 AutoGenC
.Append(gPeimEntryPointString
[2].Replace(Dict
))
1400 AutoGenH
.Append(gPeimEntryPointPrototype
.Replace(Dict
))
1401 elif Info
.ModuleType
in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1402 if NumEntryPoints
< 2:
1403 AutoGenC
.Append(gUefiDriverEntryPointString
[NumEntryPoints
].Replace(Dict
))
1405 AutoGenC
.Append(gUefiDriverEntryPointString
[2].Replace(Dict
))
1406 AutoGenH
.Append(gUefiDriverEntryPointPrototype
.Replace(Dict
))
1407 elif Info
.ModuleType
== 'DXE_SMM_DRIVER':
1408 if NumEntryPoints
== 0:
1409 AutoGenC
.Append(gDxeSmmEntryPointString
[0].Replace(Dict
))
1411 AutoGenC
.Append(gDxeSmmEntryPointString
[1].Replace(Dict
))
1412 AutoGenH
.Append(gDxeSmmEntryPointPrototype
.Replace(Dict
))
1413 elif Info
.ModuleType
== 'UEFI_APPLICATION':
1414 if NumEntryPoints
< 2:
1415 AutoGenC
.Append(gUefiApplicationEntryPointString
[NumEntryPoints
].Replace(Dict
))
1417 AutoGenC
.Append(gUefiApplicationEntryPointString
[2].Replace(Dict
))
1418 AutoGenH
.Append(gUefiApplicationEntryPointPrototype
.Replace(Dict
))
1420 ## Create code for ModuleUnloadImage
1422 # @param Info The ModuleAutoGen object
1423 # @param AutoGenC The TemplateString object for C code
1424 # @param AutoGenH The TemplateString object for header file
1426 def CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
):
1427 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1430 # Unload Image Handlers
1432 NumUnloadImage
= len(Info
.Module
.ModuleUnloadImageList
)
1433 Dict
= {'Count':str(NumUnloadImage
) + 'U', 'Function':Info
.Module
.ModuleUnloadImageList
}
1434 if NumUnloadImage
< 2:
1435 AutoGenC
.Append(gUefiUnloadImageString
[NumUnloadImage
].Replace(Dict
))
1437 AutoGenC
.Append(gUefiUnloadImageString
[2].Replace(Dict
))
1438 AutoGenH
.Append(gUefiUnloadImagePrototype
.Replace(Dict
))
1440 ## Create code for GUID
1442 # @param Info The ModuleAutoGen object
1443 # @param AutoGenC The TemplateString object for C code
1444 # @param AutoGenH The TemplateString object for header file
1446 def CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1447 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1450 GuidType
= "EFI_GUID"
1453 if not Info
.IsLibrary
:
1454 AutoGenC
.Append("\n// Guids\n")
1455 AutoGenH
.Append("\n// Guids\n")
1459 for Key
in Info
.GuidList
:
1460 if not Info
.IsLibrary
:
1461 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.GuidList
[Key
]))
1462 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1464 ## Create code for protocol
1466 # @param Info The ModuleAutoGen object
1467 # @param AutoGenC The TemplateString object for C code
1468 # @param AutoGenH The TemplateString object for header file
1470 def CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1471 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1474 GuidType
= "EFI_GUID"
1476 if Info
.ProtocolList
:
1477 if not Info
.IsLibrary
:
1478 AutoGenC
.Append("\n// Protocols\n")
1479 AutoGenH
.Append("\n// Protocols\n")
1483 for Key
in Info
.ProtocolList
:
1484 if not Info
.IsLibrary
:
1485 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.ProtocolList
[Key
]))
1486 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1488 ## Create code for PPI
1490 # @param Info The ModuleAutoGen object
1491 # @param AutoGenC The TemplateString object for C code
1492 # @param AutoGenH The TemplateString object for header file
1494 def CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1495 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1498 GuidType
= "EFI_GUID"
1501 if not Info
.IsLibrary
:
1502 AutoGenC
.Append("\n// PPIs\n")
1503 AutoGenH
.Append("\n// PPIs\n")
1507 for Key
in Info
.PpiList
:
1508 if not Info
.IsLibrary
:
1509 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.PpiList
[Key
]))
1510 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1512 ## Create code for PCD
1514 # @param Info The ModuleAutoGen object
1515 # @param AutoGenC The TemplateString object for C code
1516 # @param AutoGenH The TemplateString object for header file
1518 def CreatePcdCode(Info
, AutoGenC
, AutoGenH
):
1520 # Collect Token Space GUIDs used by DynamicEc PCDs
1522 for Pcd
in Info
.ModulePcdList
:
1523 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenSpaceGuidCName
not in TokenSpaceList
:
1524 TokenSpaceList
+= [Pcd
.TokenSpaceGuidCName
]
1526 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1527 if TokenSpaceList
<> []:
1528 AutoGenH
.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1529 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1532 GuidType
= "EFI_GUID"
1533 for Item
in TokenSpaceList
:
1534 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Item
))
1537 if Info
.ModulePcdList
:
1538 AutoGenH
.Append("\n// PCD definitions\n")
1539 for Pcd
in Info
.ModulePcdList
:
1540 CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1541 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1543 if Info
.ModulePcdList
:
1544 AutoGenH
.Append("\n// Definition of PCDs used in this module\n")
1545 AutoGenC
.Append("\n// Definition of PCDs used in this module\n")
1546 for Pcd
in Info
.ModulePcdList
:
1547 CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1548 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1549 if Info
.LibraryPcdList
:
1550 AutoGenH
.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1551 AutoGenC
.Append("\n// Definition of PCDs used in libraries\n")
1552 for Pcd
in Info
.LibraryPcdList
:
1553 CreateModulePcdCode(Info
, AutoGenC
, AutoGenC
, Pcd
)
1554 CreatePcdDatabaseCode(Info
, AutoGenC
, AutoGenH
)
1556 ## Create code for unicode string definition
1558 # @param Info The ModuleAutoGen object
1559 # @param AutoGenC The TemplateString object for C code
1560 # @param AutoGenH The TemplateString object for header file
1561 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1562 # @param UniGenBinBuffer Buffer to store uni string package data
1564 def CreateUnicodeStringCode(Info
, AutoGenC
, AutoGenH
, UniGenCFlag
, UniGenBinBuffer
):
1565 WorkingDir
= os
.getcwd()
1566 os
.chdir(Info
.WorkspaceDir
)
1568 IncList
= [Info
.MetaFile
.Dir
]
1569 # Get all files under [Sources] section in inf file for EDK-II module
1571 SrcList
= [F
for F
in Info
.SourceFileList
]
1572 if Info
.AutoGenVersion
< 0x00010005:
1574 # Get all files under the module directory for EDK-I module
1576 os
.chdir(Info
.MetaFile
.Dir
)
1577 for Root
, Dirs
, Files
in os
.walk("."):
1583 File
= PathClass(os
.path
.join(Root
, File
), Info
.MetaFile
.Dir
)
1586 SrcList
.append(File
)
1589 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-c') > -1:
1590 CompatibleMode
= True
1592 CompatibleMode
= False
1595 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1597 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-s') > -1:
1599 EdkLogger
.error("build", AUTOGEN_ERROR
,
1600 "-c and -s build options should be used exclusively",
1601 ExtraData
="[%s]" % str(Info
))
1606 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1608 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.RFCLanguages
]
1610 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.ISOLanguages
]
1611 Header
, Code
= GetStringFiles(Info
.UnicodeFileList
, SrcList
, IncList
, Info
.IncludePathList
, ['.uni', '.inf'], Info
.Name
, CompatibleMode
, ShellMode
, UniGenCFlag
, UniGenBinBuffer
, FilterInfo
)
1612 if CompatibleMode
or UniGenCFlag
:
1613 AutoGenC
.Append("\n//\n//Unicode String Pack Definition\n//\n")
1614 AutoGenC
.Append(Code
)
1615 AutoGenC
.Append("\n")
1616 AutoGenH
.Append("\n//\n//Unicode String ID\n//\n")
1617 AutoGenH
.Append(Header
)
1618 if CompatibleMode
or UniGenCFlag
:
1619 AutoGenH
.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info
.Name
)
1620 os
.chdir(WorkingDir
)
1622 ## Create common code
1624 # @param Info The ModuleAutoGen object
1625 # @param AutoGenC The TemplateString object for C code
1626 # @param AutoGenH The TemplateString object for header file
1628 def CreateHeaderCode(Info
, AutoGenC
, AutoGenH
):
1630 AutoGenH
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.h'}))
1631 # header file Prologue
1632 AutoGenH
.Append(gAutoGenHPrologueString
.Replace({'File':'AUTOGENH','Guid':Info
.Guid
.replace('-','_')}))
1633 AutoGenH
.Append(gAutoGenHCppPrologueString
)
1634 if Info
.AutoGenVersion
>= 0x00010005:
1635 # header files includes
1636 AutoGenH
.Append("#include <%s>\n" % gBasicHeaderFile
)
1637 if Info
.ModuleType
in gModuleTypeHeaderFile \
1638 and gModuleTypeHeaderFile
[Info
.ModuleType
][0] != gBasicHeaderFile
:
1639 AutoGenH
.Append("#include <%s>\n" % gModuleTypeHeaderFile
[Info
.ModuleType
][0])
1641 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
1642 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
1644 if 'PcdLib' in Info
.Module
.LibraryClasses
or Info
.Module
.Pcds
:
1645 AutoGenH
.Append("#include <Library/PcdLib.h>\n")
1647 AutoGenH
.Append('\nextern GUID gEfiCallerIdGuid;')
1648 AutoGenH
.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
1653 AutoGenH
.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info
.Guid
))
1658 AutoGenC
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.c'}))
1659 if Info
.AutoGenVersion
>= 0x00010005:
1660 # C file header files includes
1661 if Info
.ModuleType
in gModuleTypeHeaderFile
:
1662 for Inc
in gModuleTypeHeaderFile
[Info
.ModuleType
]:
1663 AutoGenC
.Append("#include <%s>\n" % Inc
)
1665 AutoGenC
.Append("#include <%s>\n" % gBasicHeaderFile
)
1668 # Publish the CallerId Guid
1670 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info
.Guid
))
1671 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info
.Name
)
1673 ## Create common code for header file
1675 # @param Info The ModuleAutoGen object
1676 # @param AutoGenC The TemplateString object for C code
1677 # @param AutoGenH The TemplateString object for header file
1679 def CreateFooterCode(Info
, AutoGenC
, AutoGenH
):
1680 AutoGenH
.Append(gAutoGenHEpilogueString
)
1682 ## Create code for a module
1684 # @param Info The ModuleAutoGen object
1685 # @param AutoGenC The TemplateString object for C code
1686 # @param AutoGenH The TemplateString object for header file
1687 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1688 # @param UniGenBinBuffer Buffer to store uni string package data
1690 def CreateCode(Info
, AutoGenC
, AutoGenH
, StringH
, UniGenCFlag
, UniGenBinBuffer
):
1691 CreateHeaderCode(Info
, AutoGenC
, AutoGenH
)
1693 if Info
.AutoGenVersion
>= 0x00010005:
1694 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1695 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1696 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1697 CreatePcdCode(Info
, AutoGenC
, AutoGenH
)
1698 CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
)
1699 CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
)
1700 CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
)
1701 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
)
1703 if Info
.UnicodeFileList
:
1704 FileName
= "%sStrDefs.h" % Info
.Name
1705 StringH
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
1706 StringH
.Append(gAutoGenHPrologueString
.Replace({'File':'STRDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
1707 CreateUnicodeStringCode(Info
, AutoGenC
, StringH
, UniGenCFlag
, UniGenBinBuffer
)
1710 for Guid
in Info
.Module
.Guids
:
1711 if Guid
in Info
.Module
.GetGuidsUsedByPcd():
1713 GuidMacros
.append('#define %s %s' % (Guid
, Info
.Module
.Guids
[Guid
]))
1714 for Guid
, Value
in Info
.Module
.Protocols
.items() + Info
.Module
.Ppis
.items():
1715 GuidMacros
.append('#define %s %s' % (Guid
, Value
))
1717 StringH
.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros
))
1719 StringH
.Append("\n#endif\n")
1720 AutoGenH
.Append('#include "%s"\n' % FileName
)
1722 CreateFooterCode(Info
, AutoGenC
, AutoGenH
)
1724 # no generation of AutoGen.c for Edk modules without unicode file
1725 if Info
.AutoGenVersion
< 0x00010005 and len(Info
.UnicodeFileList
) == 0:
1726 AutoGenC
.String
= ''
1728 ## Create the code file
1730 # @param FilePath The path of code file
1731 # @param Content The content of code file
1732 # @param IsBinaryFile The flag indicating if the file is binary file or not
1734 # @retval True If file content is changed or file doesn't exist
1735 # @retval False If the file exists and the content is not changed
1737 def Generate(FilePath
, Content
, IsBinaryFile
):
1738 return SaveFileOnChange(FilePath
, Content
, IsBinaryFile
)