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 if Pcd
.TokenCName
== TokenCName
:
699 AutoGenH
.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (Pcd
.TokenCName
))
700 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
701 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
703 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
704 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
706 AutoGenH
.Append('0 \\\n )\n')
707 TokenCNameList
.append(TokenCName
)
710 for TokenCName
in ExTokenCNameList
:
711 if TokenCName
in TokenCNameList
:
714 Count
= ExTokenCNameList
.count(TokenCName
)
715 for Pcd
in PcdExList
:
716 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== TokenCName
:
719 AutoGenH
.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (Pcd
.TokenCName
))
720 AutoGenH
.Append('\\\n (GuidPtr == NULL) ? 0:')
721 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
722 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
724 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
725 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
727 AutoGenH
.Append('0 \\\n )\n')
728 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
729 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
730 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
731 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
732 AutoGenH
.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'
733 % (Pcd
.TokenCName
, Pcd
.TokenCName
, Pcd
.TokenCName
, Pcd
.TokenCName
))
734 TokenCNameList
.append(TokenCName
)
737 if Pcd
.DatumType
== 'VOID*':
738 Value
= Pcd
.DefaultValue
739 if Value
in [None, '']:
741 elif Value
[0] == 'L':
742 return (len(Value
) - 2) * 2
743 elif Value
[0] == '{':
744 return len(Value
.split(','))
746 return len(Value
) - 1
747 if Pcd
.DatumType
== 'UINT64':
749 if Pcd
.DatumType
== 'UINT32':
751 if Pcd
.DatumType
== 'UINT16':
753 if Pcd
.DatumType
== 'UINT8':
755 if Pcd
.DatumType
== 'BOOLEAN':
759 ## Create code for module PCDs
761 # @param Info The ModuleAutoGen object
762 # @param AutoGenC The TemplateString object for C code
763 # @param AutoGenH The TemplateString object for header file
764 # @param Pcd The PCD object
766 def CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
767 TokenSpaceGuidValue
= Pcd
.TokenSpaceGuidValue
#Info.GuidList[Pcd.TokenSpaceGuidCName]
768 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
770 if GlobalData
.BuildOptionPcd
:
771 for PcdItem
in GlobalData
.BuildOptionPcd
:
772 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
773 Pcd
.DefaultValue
= PcdItem
[2]
779 PcdTokenName
= '_PCD_TOKEN_' + Pcd
.TokenCName
780 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + Pcd
.TokenCName
+'_SIZE'
781 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + Pcd
.TokenCName
782 FixPcdSizeTokenName
= '_PCD_SIZE_' + Pcd
.TokenCName
784 if Pcd
.Type
in gDynamicExPcd
:
785 TokenNumber
= int(Pcd
.TokenValue
, 0)
786 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
787 # different Guids but same TokenCName
788 PcdExTokenName
= '_PCD_TOKEN_' + Pcd
.TokenSpaceGuidCName
+ '_' + Pcd
.TokenCName
789 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
791 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
792 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
793 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
794 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
795 # report warning message notify the PI that they are attempting to build a module
796 # that must be included in a flash image in order to be functional. These Dynamic PCD
797 # will not be added into the Database unless it is used by other modules that are
798 # included in the FDF file.
799 # In this case, just assign an invalid token number to make it pass build.
800 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
803 EdkLogger
.error("build", AUTOGEN_ERROR
,
804 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
805 ExtraData
="[%s]" % str(Info
))
807 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
808 AutoGenH
.Append('\n#define %s %dU\n' % (PcdTokenName
, TokenNumber
))
810 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "Creating code for " + Pcd
.TokenCName
+ "." + Pcd
.TokenSpaceGuidCName
)
811 if Pcd
.Type
not in gItemTypeStringDatabase
:
812 EdkLogger
.error("build", AUTOGEN_ERROR
,
813 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
814 ExtraData
="[%s]" % str(Info
))
815 if Pcd
.DatumType
not in gDatumSizeStringDatabase
:
816 EdkLogger
.error("build", AUTOGEN_ERROR
,
817 "Unknown datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
818 ExtraData
="[%s]" % str(Info
))
820 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
]
821 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
]
822 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + Pcd
.TokenCName
823 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + Pcd
.TokenCName
824 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + Pcd
.TokenCName
825 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + Pcd
.TokenCName
828 if Pcd
.Type
in gDynamicExPcd
:
830 PcdList
= Info
.LibraryPcdList
832 PcdList
= Info
.ModulePcdList
833 for PcdModule
in PcdList
:
834 if PcdModule
.Type
in gDynamicExPcd
:
835 PcdExCNameList
.append(PcdModule
.TokenCName
)
836 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
837 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
838 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
839 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
840 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')
841 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
842 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
843 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
844 if Pcd
.DatumType
== 'VOID*':
845 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
846 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
848 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
849 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
851 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
852 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
853 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
854 if Pcd
.DatumType
== 'VOID*':
855 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
856 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
858 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
859 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
860 elif Pcd
.Type
in gDynamicPcd
:
863 PcdList
.extend(Info
.LibraryPcdList
)
864 PcdList
.extend(Info
.ModulePcdList
)
865 for PcdModule
in PcdList
:
866 if PcdModule
.Type
in gDynamicPcd
:
867 PcdCNameList
.append(PcdModule
.TokenCName
)
868 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
869 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" % (Pcd
.TokenCName
), ExtraData
="[%s]" % str(Info
.MetaFile
.Path
))
871 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
872 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
873 if Pcd
.DatumType
== 'VOID*':
874 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
875 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
877 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
878 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
880 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + Pcd
.TokenCName
882 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
886 Value
= Pcd
.DefaultValue
890 if Pcd
.DatumType
== 'BOOLEAN':
891 BoolValue
= Value
.upper()
892 if BoolValue
== 'TRUE' or BoolValue
== '1':
894 elif BoolValue
== 'FALSE' or BoolValue
== '0':
897 if Pcd
.DatumType
in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
899 if Value
.upper().startswith('0X'):
900 ValueNumber
= int (Value
, 16)
902 ValueNumber
= int (Value
)
904 EdkLogger
.error("build", AUTOGEN_ERROR
,
905 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
906 ExtraData
="[%s]" % str(Info
))
907 if Pcd
.DatumType
== 'UINT64':
909 EdkLogger
.error("build", AUTOGEN_ERROR
,
910 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
911 ExtraData
="[%s]" % str(Info
))
912 elif ValueNumber
>= 0x10000000000000000:
913 EdkLogger
.error("build", AUTOGEN_ERROR
,
914 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
915 ExtraData
="[%s]" % str(Info
))
916 if not Value
.endswith('ULL'):
918 elif Pcd
.DatumType
== 'UINT32':
920 EdkLogger
.error("build", AUTOGEN_ERROR
,
921 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
922 ExtraData
="[%s]" % str(Info
))
923 elif ValueNumber
>= 0x100000000:
924 EdkLogger
.error("build", AUTOGEN_ERROR
,
925 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
926 ExtraData
="[%s]" % str(Info
))
927 if not Value
.endswith('U'):
929 elif Pcd
.DatumType
== 'UINT16':
931 EdkLogger
.error("build", AUTOGEN_ERROR
,
932 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
933 ExtraData
="[%s]" % str(Info
))
934 elif ValueNumber
>= 0x10000:
935 EdkLogger
.error("build", AUTOGEN_ERROR
,
936 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
937 ExtraData
="[%s]" % str(Info
))
938 if not Value
.endswith('U'):
940 elif Pcd
.DatumType
== 'UINT8':
942 EdkLogger
.error("build", AUTOGEN_ERROR
,
943 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
944 ExtraData
="[%s]" % str(Info
))
945 elif ValueNumber
>= 0x100:
946 EdkLogger
.error("build", AUTOGEN_ERROR
,
947 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
948 ExtraData
="[%s]" % str(Info
))
949 if not Value
.endswith('U'):
951 if Pcd
.DatumType
== 'VOID*':
952 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
953 EdkLogger
.error("build", AUTOGEN_ERROR
,
954 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
955 ExtraData
="[%s]" % str(Info
))
957 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
963 Value
= Value
.lstrip('L') #.strip('"')
964 Value
= eval(Value
) # translate escape character
966 for Index
in range(0,len(Value
)):
968 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ', '
970 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ', '
972 ArraySize
= ArraySize
/ 2;
974 if ArraySize
< (len(Value
) + 1):
975 EdkLogger
.error("build", AUTOGEN_ERROR
,
976 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
977 ExtraData
="[%s]" % str(Info
))
978 Value
= NewValue
+ '0 }'
979 Array
= '[%d]' % ArraySize
981 # skip casting for fixed at build since it breaks ARM assembly.
982 # Long term we need PCD macros that work in assembly
984 elif Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
985 Value
= "((%s)%s)" % (Pcd
.DatumType
, Value
)
987 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
988 PcdValueName
= '_PCD_PATCHABLE_VALUE_' + Pcd
.TokenCName
990 PcdValueName
= '_PCD_VALUE_' + Pcd
.TokenCName
992 if Pcd
.DatumType
== 'VOID*':
994 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
997 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
998 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
999 AutoGenH
.Append('extern %s UINT16 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1000 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1002 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1003 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1004 AutoGenH
.Append('extern %s UINT8 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1005 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1007 PcdDataSize
= GetPcdSize(Pcd
)
1008 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
1009 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1010 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1012 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1013 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1014 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1015 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1016 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1017 elif Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1018 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1019 AutoGenC
.Append('volatile %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1020 AutoGenH
.Append('extern volatile %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1021 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1023 PcdDataSize
= GetPcdSize(Pcd
)
1024 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1026 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1027 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1028 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1030 PcdDataSize
= GetPcdSize(Pcd
)
1031 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1032 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1034 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1035 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1036 AutoGenH
.Append('extern %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1037 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1039 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1040 if Pcd
.DatumType
== 'VOID*':
1041 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
))
1042 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
))
1044 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1045 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName
, PcdVariableName
))
1047 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1049 ## Create code for library module PCDs
1051 # @param Info The ModuleAutoGen object
1052 # @param AutoGenC The TemplateString object for C code
1053 # @param AutoGenH The TemplateString object for header file
1054 # @param Pcd The PCD object
1056 def CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
1057 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
1058 TokenSpaceGuidCName
= Pcd
.TokenSpaceGuidCName
1059 TokenCName
= Pcd
.TokenCName
1060 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
1061 FixPcdSizeTokenName
= '_PCD_SIZE_' + Pcd
.TokenCName
1062 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + Pcd
.TokenCName
+'_SIZE'
1063 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + Pcd
.TokenCName
1065 if GlobalData
.BuildOptionPcd
:
1066 for PcdItem
in GlobalData
.BuildOptionPcd
:
1067 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1068 Pcd
.DefaultValue
= PcdItem
[2]
1074 if Pcd
.Type
in gDynamicExPcd
:
1075 TokenNumber
= int(Pcd
.TokenValue
, 0)
1077 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
1078 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1079 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1080 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1081 # report warning message notify the PI that they are attempting to build a module
1082 # that must be included in a flash image in order to be functional. These Dynamic PCD
1083 # will not be added into the Database unless it is used by other modules that are
1084 # included in the FDF file.
1085 # In this case, just assign an invalid token number to make it pass build.
1086 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
1089 EdkLogger
.error("build", AUTOGEN_ERROR
,
1090 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
1091 ExtraData
="[%s]" % str(Info
))
1093 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
1095 if Pcd
.Type
not in gItemTypeStringDatabase
:
1096 EdkLogger
.error("build", AUTOGEN_ERROR
,
1097 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
1098 ExtraData
="[%s]" % str(Info
))
1099 if Pcd
.DatumType
not in gDatumSizeStringDatabase
:
1100 EdkLogger
.error("build", AUTOGEN_ERROR
,
1101 "Unknown datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
),
1102 ExtraData
="[%s]" % str(Info
))
1104 DatumType
= Pcd
.DatumType
1105 DatumSize
= gDatumSizeStringDatabaseH
[DatumType
]
1106 DatumSizeLib
= gDatumSizeStringDatabaseLib
[DatumType
]
1107 GetModeName
= '_PCD_GET_MODE_' + DatumSize
+ '_' + TokenCName
1108 SetModeName
= '_PCD_SET_MODE_' + DatumSize
+ '_' + TokenCName
1109 SetModeStatusName
= '_PCD_SET_MODE_' + DatumSize
+ '_S_' + TokenCName
1110 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + Pcd
.TokenCName
1114 if Pcd
.DatumType
== 'VOID*':
1115 if Pcd
.DefaultValue
[0]== '{':
1118 PcdItemType
= Pcd
.Type
1120 if PcdItemType
in gDynamicExPcd
:
1121 PcdExTokenName
= '_PCD_TOKEN_' + TokenSpaceGuidCName
+ '_' + Pcd
.TokenCName
1122 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
1125 PcdList
= Info
.LibraryPcdList
1127 PcdList
= Info
.ModulePcdList
1128 for PcdModule
in PcdList
:
1129 if PcdModule
.Type
in gDynamicExPcd
:
1130 PcdExCNameList
.append(PcdModule
.TokenCName
)
1131 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1132 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1133 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1134 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
1135 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')
1136 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1137 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1138 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s \n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1139 if Pcd
.DatumType
== 'VOID*':
1140 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1141 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1143 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1144 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1146 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1147 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1148 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1149 if Pcd
.DatumType
== 'VOID*':
1150 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1151 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1153 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1154 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1156 AutoGenH
.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName
, TokenNumber
))
1157 if PcdItemType
in gDynamicPcd
:
1160 PcdList
.extend(Info
.LibraryPcdList
)
1161 PcdList
.extend(Info
.ModulePcdList
)
1162 for PcdModule
in PcdList
:
1163 if PcdModule
.Type
in gDynamicPcd
:
1164 PcdCNameList
.append(PcdModule
.TokenCName
)
1165 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1166 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" % (Pcd
.TokenCName
), ExtraData
="[%s]" % str(Info
.MetaFile
.Path
))
1168 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1169 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1170 if DatumType
== 'VOID*':
1171 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1172 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1174 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1175 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1176 if PcdItemType
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1177 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[TAB_PCDS_PATCHABLE_IN_MODULE
] + '_' + TokenCName
1178 if DatumType
== 'VOID*':
1179 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1180 if Pcd
.DefaultValue
[0] == 'L':
1181 ArraySize
= ArraySize
/ 2
1182 Array
= '[%d]' % ArraySize
1183 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1184 AutoGenH
.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1186 AutoGenH
.Append('extern volatile %s %s%s;\n' % (DatumType
, PcdVariableName
, Array
))
1187 AutoGenH
.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName
, Type
, TokenCName
))
1188 if Pcd
.DatumType
== 'VOID*':
1189 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
))
1190 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
))
1192 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1193 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName
, PcdVariableName
))
1195 PcdDataSize
= GetPcdSize(Pcd
)
1196 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1197 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1198 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1200 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
or PcdItemType
== TAB_PCDS_FEATURE_FLAG
:
1201 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1203 if DatumType
== 'VOID*' and Array
== '[]':
1204 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1205 AutoGenH
.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1206 AutoGenH
.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName
, Type
, TokenCName
))
1207 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1209 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
and key
in Info
.ConstPcd
:
1210 AutoGenH
.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName
, Pcd
.DefaultValue
))
1212 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
:
1213 PcdDataSize
= GetPcdSize(Pcd
)
1214 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1215 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1217 ## Create code for library constructor
1219 # @param Info The ModuleAutoGen object
1220 # @param AutoGenC The TemplateString object for C code
1221 # @param AutoGenH The TemplateString object for header file
1223 def CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
):
1225 # Library Constructors
1227 ConstructorPrototypeString
= TemplateString()
1228 ConstructorCallingString
= TemplateString()
1230 DependentLibraryList
= [Info
.Module
]
1232 DependentLibraryList
= Info
.DependentLibraryList
1233 for Lib
in DependentLibraryList
:
1234 if len(Lib
.ConstructorList
) <= 0:
1236 Dict
= {'Function':Lib
.ConstructorList
}
1237 if Lib
.ModuleType
in ['BASE', 'SEC']:
1238 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1239 ConstructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1240 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1241 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1242 ConstructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1243 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1244 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1245 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1246 ConstructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1248 if str(ConstructorPrototypeString
) == '':
1249 ConstructorPrototypeList
= []
1251 ConstructorPrototypeList
= [str(ConstructorPrototypeString
)]
1252 if str(ConstructorCallingString
) == '':
1253 ConstructorCallingList
= []
1255 ConstructorCallingList
= [str(ConstructorCallingString
)]
1258 'Type' : 'Constructor',
1259 'FunctionPrototype' : ConstructorPrototypeList
,
1260 'FunctionCall' : ConstructorCallingList
1263 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1265 if Info
.ModuleType
in ['BASE', 'SEC']:
1266 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1267 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1268 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1269 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1270 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1271 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1273 ## Create code for library destructor
1275 # @param Info The ModuleAutoGen object
1276 # @param AutoGenC The TemplateString object for C code
1277 # @param AutoGenH The TemplateString object for header file
1279 def CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
):
1281 # Library Destructors
1283 DestructorPrototypeString
= TemplateString()
1284 DestructorCallingString
= TemplateString()
1286 DependentLibraryList
= [Info
.Module
]
1288 DependentLibraryList
= Info
.DependentLibraryList
1289 for Index
in range(len(DependentLibraryList
)-1, -1, -1):
1290 Lib
= DependentLibraryList
[Index
]
1291 if len(Lib
.DestructorList
) <= 0:
1293 Dict
= {'Function':Lib
.DestructorList
}
1294 if Lib
.ModuleType
in ['BASE', 'SEC']:
1295 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1296 DestructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1297 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1298 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1299 DestructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1300 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1301 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1302 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1303 DestructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1305 if str(DestructorPrototypeString
) == '':
1306 DestructorPrototypeList
= []
1308 DestructorPrototypeList
= [str(DestructorPrototypeString
)]
1309 if str(DestructorCallingString
) == '':
1310 DestructorCallingList
= []
1312 DestructorCallingList
= [str(DestructorCallingString
)]
1315 'Type' : 'Destructor',
1316 'FunctionPrototype' : DestructorPrototypeList
,
1317 'FunctionCall' : DestructorCallingList
1320 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1322 if Info
.ModuleType
in ['BASE', 'SEC']:
1323 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1324 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1325 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1326 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1327 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1328 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1331 ## Create code for ModuleEntryPoint
1333 # @param Info The ModuleAutoGen object
1334 # @param AutoGenC The TemplateString object for C code
1335 # @param AutoGenH The TemplateString object for header file
1337 def CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
):
1338 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1341 # Module Entry Points
1343 NumEntryPoints
= len(Info
.Module
.ModuleEntryPointList
)
1344 if 'PI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1345 PiSpecVersion
= Info
.Module
.Specification
['PI_SPECIFICATION_VERSION']
1347 PiSpecVersion
= '0x00000000'
1348 if 'UEFI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1349 UefiSpecVersion
= Info
.Module
.Specification
['UEFI_SPECIFICATION_VERSION']
1351 UefiSpecVersion
= '0x00000000'
1353 'Function' : Info
.Module
.ModuleEntryPointList
,
1354 'PiSpecVersion' : PiSpecVersion
+ 'U',
1355 'UefiSpecVersion': UefiSpecVersion
+ 'U'
1358 if Info
.ModuleType
in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:
1359 if Info
.SourceFileList
<> None and Info
.SourceFileList
<> []:
1360 if NumEntryPoints
!= 1:
1364 '%s must have exactly one entry point' % Info
.ModuleType
,
1366 ExtraData
= ", ".join(Info
.Module
.ModuleEntryPointList
)
1368 if Info
.ModuleType
== 'PEI_CORE':
1369 AutoGenC
.Append(gPeiCoreEntryPointString
.Replace(Dict
))
1370 AutoGenH
.Append(gPeiCoreEntryPointPrototype
.Replace(Dict
))
1371 elif Info
.ModuleType
== 'DXE_CORE':
1372 AutoGenC
.Append(gDxeCoreEntryPointString
.Replace(Dict
))
1373 AutoGenH
.Append(gDxeCoreEntryPointPrototype
.Replace(Dict
))
1374 elif Info
.ModuleType
== 'SMM_CORE':
1375 AutoGenC
.Append(gSmmCoreEntryPointString
.Replace(Dict
))
1376 AutoGenH
.Append(gSmmCoreEntryPointPrototype
.Replace(Dict
))
1377 elif Info
.ModuleType
== 'PEIM':
1378 if NumEntryPoints
< 2:
1379 AutoGenC
.Append(gPeimEntryPointString
[NumEntryPoints
].Replace(Dict
))
1381 AutoGenC
.Append(gPeimEntryPointString
[2].Replace(Dict
))
1382 AutoGenH
.Append(gPeimEntryPointPrototype
.Replace(Dict
))
1383 elif Info
.ModuleType
in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1384 if NumEntryPoints
< 2:
1385 AutoGenC
.Append(gUefiDriverEntryPointString
[NumEntryPoints
].Replace(Dict
))
1387 AutoGenC
.Append(gUefiDriverEntryPointString
[2].Replace(Dict
))
1388 AutoGenH
.Append(gUefiDriverEntryPointPrototype
.Replace(Dict
))
1389 elif Info
.ModuleType
== 'DXE_SMM_DRIVER':
1390 if NumEntryPoints
== 0:
1391 AutoGenC
.Append(gDxeSmmEntryPointString
[0].Replace(Dict
))
1393 AutoGenC
.Append(gDxeSmmEntryPointString
[1].Replace(Dict
))
1394 AutoGenH
.Append(gDxeSmmEntryPointPrototype
.Replace(Dict
))
1395 elif Info
.ModuleType
== 'UEFI_APPLICATION':
1396 if NumEntryPoints
< 2:
1397 AutoGenC
.Append(gUefiApplicationEntryPointString
[NumEntryPoints
].Replace(Dict
))
1399 AutoGenC
.Append(gUefiApplicationEntryPointString
[2].Replace(Dict
))
1400 AutoGenH
.Append(gUefiApplicationEntryPointPrototype
.Replace(Dict
))
1402 ## Create code for ModuleUnloadImage
1404 # @param Info The ModuleAutoGen object
1405 # @param AutoGenC The TemplateString object for C code
1406 # @param AutoGenH The TemplateString object for header file
1408 def CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
):
1409 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1412 # Unload Image Handlers
1414 NumUnloadImage
= len(Info
.Module
.ModuleUnloadImageList
)
1415 Dict
= {'Count':str(NumUnloadImage
) + 'U', 'Function':Info
.Module
.ModuleUnloadImageList
}
1416 if NumUnloadImage
< 2:
1417 AutoGenC
.Append(gUefiUnloadImageString
[NumUnloadImage
].Replace(Dict
))
1419 AutoGenC
.Append(gUefiUnloadImageString
[2].Replace(Dict
))
1420 AutoGenH
.Append(gUefiUnloadImagePrototype
.Replace(Dict
))
1422 ## Create code for GUID
1424 # @param Info The ModuleAutoGen object
1425 # @param AutoGenC The TemplateString object for C code
1426 # @param AutoGenH The TemplateString object for header file
1428 def CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1429 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1432 GuidType
= "EFI_GUID"
1435 if not Info
.IsLibrary
:
1436 AutoGenC
.Append("\n// Guids\n")
1437 AutoGenH
.Append("\n// Guids\n")
1441 for Key
in Info
.GuidList
:
1442 if not Info
.IsLibrary
:
1443 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.GuidList
[Key
]))
1444 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1446 ## Create code for protocol
1448 # @param Info The ModuleAutoGen object
1449 # @param AutoGenC The TemplateString object for C code
1450 # @param AutoGenH The TemplateString object for header file
1452 def CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1453 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1456 GuidType
= "EFI_GUID"
1458 if Info
.ProtocolList
:
1459 if not Info
.IsLibrary
:
1460 AutoGenC
.Append("\n// Protocols\n")
1461 AutoGenH
.Append("\n// Protocols\n")
1465 for Key
in Info
.ProtocolList
:
1466 if not Info
.IsLibrary
:
1467 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.ProtocolList
[Key
]))
1468 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1470 ## Create code for PPI
1472 # @param Info The ModuleAutoGen object
1473 # @param AutoGenC The TemplateString object for C code
1474 # @param AutoGenH The TemplateString object for header file
1476 def CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1477 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1480 GuidType
= "EFI_GUID"
1483 if not Info
.IsLibrary
:
1484 AutoGenC
.Append("\n// PPIs\n")
1485 AutoGenH
.Append("\n// PPIs\n")
1489 for Key
in Info
.PpiList
:
1490 if not Info
.IsLibrary
:
1491 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.PpiList
[Key
]))
1492 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1494 ## Create code for PCD
1496 # @param Info The ModuleAutoGen object
1497 # @param AutoGenC The TemplateString object for C code
1498 # @param AutoGenH The TemplateString object for header file
1500 def CreatePcdCode(Info
, AutoGenC
, AutoGenH
):
1502 # Collect Token Space GUIDs used by DynamicEc PCDs
1504 for Pcd
in Info
.ModulePcdList
:
1505 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenSpaceGuidCName
not in TokenSpaceList
:
1506 TokenSpaceList
+= [Pcd
.TokenSpaceGuidCName
]
1508 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1509 if TokenSpaceList
<> []:
1510 AutoGenH
.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1511 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1514 GuidType
= "EFI_GUID"
1515 for Item
in TokenSpaceList
:
1516 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Item
))
1519 if Info
.ModulePcdList
:
1520 AutoGenH
.Append("\n// PCD definitions\n")
1521 for Pcd
in Info
.ModulePcdList
:
1522 CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1523 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1525 if Info
.ModulePcdList
:
1526 AutoGenH
.Append("\n// Definition of PCDs used in this module\n")
1527 AutoGenC
.Append("\n// Definition of PCDs used in this module\n")
1528 for Pcd
in Info
.ModulePcdList
:
1529 CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1530 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1531 if Info
.LibraryPcdList
:
1532 AutoGenH
.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1533 AutoGenC
.Append("\n// Definition of PCDs used in libraries\n")
1534 for Pcd
in Info
.LibraryPcdList
:
1535 CreateModulePcdCode(Info
, AutoGenC
, AutoGenC
, Pcd
)
1536 CreatePcdDatabaseCode(Info
, AutoGenC
, AutoGenH
)
1538 ## Create code for unicode string definition
1540 # @param Info The ModuleAutoGen object
1541 # @param AutoGenC The TemplateString object for C code
1542 # @param AutoGenH The TemplateString object for header file
1543 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1544 # @param UniGenBinBuffer Buffer to store uni string package data
1546 def CreateUnicodeStringCode(Info
, AutoGenC
, AutoGenH
, UniGenCFlag
, UniGenBinBuffer
):
1547 WorkingDir
= os
.getcwd()
1548 os
.chdir(Info
.WorkspaceDir
)
1550 IncList
= [Info
.MetaFile
.Dir
]
1551 # Get all files under [Sources] section in inf file for EDK-II module
1553 SrcList
= [F
for F
in Info
.SourceFileList
]
1554 if Info
.AutoGenVersion
< 0x00010005:
1556 # Get all files under the module directory for EDK-I module
1558 os
.chdir(Info
.MetaFile
.Dir
)
1559 for Root
, Dirs
, Files
in os
.walk("."):
1565 File
= PathClass(os
.path
.join(Root
, File
), Info
.MetaFile
.Dir
)
1568 SrcList
.append(File
)
1571 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-c') > -1:
1572 CompatibleMode
= True
1574 CompatibleMode
= False
1577 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1579 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-s') > -1:
1581 EdkLogger
.error("build", AUTOGEN_ERROR
,
1582 "-c and -s build options should be used exclusively",
1583 ExtraData
="[%s]" % str(Info
))
1588 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1590 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.RFCLanguages
]
1592 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.ISOLanguages
]
1593 Header
, Code
= GetStringFiles(Info
.UnicodeFileList
, SrcList
, IncList
, Info
.IncludePathList
, ['.uni', '.inf'], Info
.Name
, CompatibleMode
, ShellMode
, UniGenCFlag
, UniGenBinBuffer
, FilterInfo
)
1594 if CompatibleMode
or UniGenCFlag
:
1595 AutoGenC
.Append("\n//\n//Unicode String Pack Definition\n//\n")
1596 AutoGenC
.Append(Code
)
1597 AutoGenC
.Append("\n")
1598 AutoGenH
.Append("\n//\n//Unicode String ID\n//\n")
1599 AutoGenH
.Append(Header
)
1600 if CompatibleMode
or UniGenCFlag
:
1601 AutoGenH
.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info
.Name
)
1602 os
.chdir(WorkingDir
)
1604 ## Create common code
1606 # @param Info The ModuleAutoGen object
1607 # @param AutoGenC The TemplateString object for C code
1608 # @param AutoGenH The TemplateString object for header file
1610 def CreateHeaderCode(Info
, AutoGenC
, AutoGenH
):
1612 AutoGenH
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.h'}))
1613 # header file Prologue
1614 AutoGenH
.Append(gAutoGenHPrologueString
.Replace({'File':'AUTOGENH','Guid':Info
.Guid
.replace('-','_')}))
1615 AutoGenH
.Append(gAutoGenHCppPrologueString
)
1616 if Info
.AutoGenVersion
>= 0x00010005:
1617 # header files includes
1618 AutoGenH
.Append("#include <%s>\n" % gBasicHeaderFile
)
1619 if Info
.ModuleType
in gModuleTypeHeaderFile \
1620 and gModuleTypeHeaderFile
[Info
.ModuleType
][0] != gBasicHeaderFile
:
1621 AutoGenH
.Append("#include <%s>\n" % gModuleTypeHeaderFile
[Info
.ModuleType
][0])
1623 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
1624 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
1626 if 'PcdLib' in Info
.Module
.LibraryClasses
or Info
.Module
.Pcds
:
1627 AutoGenH
.Append("#include <Library/PcdLib.h>\n")
1629 AutoGenH
.Append('\nextern GUID gEfiCallerIdGuid;')
1630 AutoGenH
.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
1635 AutoGenH
.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info
.Guid
))
1640 AutoGenC
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.c'}))
1641 if Info
.AutoGenVersion
>= 0x00010005:
1642 # C file header files includes
1643 if Info
.ModuleType
in gModuleTypeHeaderFile
:
1644 for Inc
in gModuleTypeHeaderFile
[Info
.ModuleType
]:
1645 AutoGenC
.Append("#include <%s>\n" % Inc
)
1647 AutoGenC
.Append("#include <%s>\n" % gBasicHeaderFile
)
1650 # Publish the CallerId Guid
1652 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info
.Guid
))
1653 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info
.Name
)
1655 ## Create common code for header file
1657 # @param Info The ModuleAutoGen object
1658 # @param AutoGenC The TemplateString object for C code
1659 # @param AutoGenH The TemplateString object for header file
1661 def CreateFooterCode(Info
, AutoGenC
, AutoGenH
):
1662 AutoGenH
.Append(gAutoGenHEpilogueString
)
1664 ## Create code for a module
1666 # @param Info The ModuleAutoGen object
1667 # @param AutoGenC The TemplateString object for C code
1668 # @param AutoGenH The TemplateString object for header file
1669 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1670 # @param UniGenBinBuffer Buffer to store uni string package data
1672 def CreateCode(Info
, AutoGenC
, AutoGenH
, StringH
, UniGenCFlag
, UniGenBinBuffer
):
1673 CreateHeaderCode(Info
, AutoGenC
, AutoGenH
)
1675 if Info
.AutoGenVersion
>= 0x00010005:
1676 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1677 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1678 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
)
1679 CreatePcdCode(Info
, AutoGenC
, AutoGenH
)
1680 CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
)
1681 CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
)
1682 CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
)
1683 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
)
1685 if Info
.UnicodeFileList
:
1686 FileName
= "%sStrDefs.h" % Info
.Name
1687 StringH
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
1688 StringH
.Append(gAutoGenHPrologueString
.Replace({'File':'STRDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
1689 CreateUnicodeStringCode(Info
, AutoGenC
, StringH
, UniGenCFlag
, UniGenBinBuffer
)
1692 for Guid
in Info
.Module
.Guids
:
1693 if Guid
in Info
.Module
.GetGuidsUsedByPcd():
1695 GuidMacros
.append('#define %s %s' % (Guid
, Info
.Module
.Guids
[Guid
]))
1696 for Guid
, Value
in Info
.Module
.Protocols
.items() + Info
.Module
.Ppis
.items():
1697 GuidMacros
.append('#define %s %s' % (Guid
, Value
))
1699 StringH
.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros
))
1701 StringH
.Append("\n#endif\n")
1702 AutoGenH
.Append('#include "%s"\n' % FileName
)
1704 CreateFooterCode(Info
, AutoGenC
, AutoGenH
)
1706 # no generation of AutoGen.c for Edk modules without unicode file
1707 if Info
.AutoGenVersion
< 0x00010005 and len(Info
.UnicodeFileList
) == 0:
1708 AutoGenC
.String
= ''
1710 ## Create the code file
1712 # @param FilePath The path of code file
1713 # @param Content The content of code file
1714 # @param IsBinaryFile The flag indicating if the file is binary file or not
1716 # @retval True If file content is changed or file doesn't exist
1717 # @retval False If the file exists and the content is not changed
1719 def Generate(FilePath
, Content
, IsBinaryFile
):
1720 return SaveFileOnChange(FilePath
, Content
, IsBinaryFile
)