2 # Routines for generating AutoGen.h and AutoGen.c
4 # Copyright (c) 2007 - 2017, 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.
19 from Common
import EdkLogger
21 from Common
.BuildToolError
import *
22 from Common
.DataType
import *
23 from Common
.Misc
import *
24 from Common
.String
import StringToArray
25 from StrGather
import *
26 from GenPcdDb
import CreatePcdDatabaseCode
27 from IdfClassObject
import *
30 gItemTypeStringDatabase
= {
31 TAB_PCDS_FEATURE_FLAG
: 'FixedAtBuild',
32 TAB_PCDS_FIXED_AT_BUILD
: 'FixedAtBuild',
33 TAB_PCDS_PATCHABLE_IN_MODULE
: 'BinaryPatch',
34 TAB_PCDS_DYNAMIC
: '',
35 TAB_PCDS_DYNAMIC_DEFAULT
: '',
36 TAB_PCDS_DYNAMIC_VPD
: '',
37 TAB_PCDS_DYNAMIC_HII
: '',
38 TAB_PCDS_DYNAMIC_EX
: '',
39 TAB_PCDS_DYNAMIC_EX_DEFAULT
: '',
40 TAB_PCDS_DYNAMIC_EX_VPD
: '',
41 TAB_PCDS_DYNAMIC_EX_HII
: '',
45 gDynamicPcd
= [TAB_PCDS_DYNAMIC
, TAB_PCDS_DYNAMIC_DEFAULT
, TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_HII
]
47 ## Dynamic-ex PCD types
48 gDynamicExPcd
= [TAB_PCDS_DYNAMIC_EX
, TAB_PCDS_DYNAMIC_EX_DEFAULT
, TAB_PCDS_DYNAMIC_EX_VPD
, TAB_PCDS_DYNAMIC_EX_HII
]
51 gDatumSizeStringDatabase
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}
52 gDatumSizeStringDatabaseH
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}
53 gDatumSizeStringDatabaseLib
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}
55 ## AutoGen File Header Templates
56 gAutoGenHeaderString
= TemplateString("""\
62 Abstract: Auto-generated ${FileName} for building module or library.
66 gAutoGenHPrologueString
= TemplateString("""
67 #ifndef _${File}_${Guid}
68 #define _${File}_${Guid}
72 gAutoGenHCppPrologueString
= """\
79 gAutoGenHEpilogueString
= """
88 ## PEI Core Entry Point Templates
89 gPeiCoreEntryPointPrototype
= TemplateString("""
94 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
95 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
101 gPeiCoreEntryPointString
= TemplateString("""
105 ProcessModuleEntryPointList (
106 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
107 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
112 ${Function} (SecCoreData, PpiList, Context);
118 ## DXE Core Entry Point Templates
119 gDxeCoreEntryPointPrototype
= TemplateString("""
129 gDxeCoreEntryPointString
= TemplateString("""
133 ProcessModuleEntryPointList (
138 ${Function} (HobStart);
143 ## PEIM Entry Point Templates
144 gPeimEntryPointPrototype
= TemplateString("""
149 IN EFI_PEI_FILE_HANDLE FileHandle,
150 IN CONST EFI_PEI_SERVICES **PeiServices
155 gPeimEntryPointString
= [
157 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
161 ProcessModuleEntryPointList (
162 IN EFI_PEI_FILE_HANDLE FileHandle,
163 IN CONST EFI_PEI_SERVICES **PeiServices
171 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
175 ProcessModuleEntryPointList (
176 IN EFI_PEI_FILE_HANDLE FileHandle,
177 IN CONST EFI_PEI_SERVICES **PeiServices
181 return ${Function} (FileHandle, PeiServices);
186 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
190 ProcessModuleEntryPointList (
191 IN EFI_PEI_FILE_HANDLE FileHandle,
192 IN CONST EFI_PEI_SERVICES **PeiServices
197 EFI_STATUS CombinedStatus;
199 CombinedStatus = EFI_LOAD_ERROR;
201 Status = ${Function} (FileHandle, PeiServices);
202 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
203 CombinedStatus = Status;
206 return CombinedStatus;
211 ## SMM_CORE Entry Point Templates
212 gSmmCoreEntryPointPrototype
= TemplateString("""
217 IN EFI_HANDLE ImageHandle,
218 IN EFI_SYSTEM_TABLE *SystemTable
223 gSmmCoreEntryPointString
= TemplateString("""
225 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
226 const UINT32 _gDxeRevision = ${PiSpecVersion};
230 ProcessModuleEntryPointList (
231 IN EFI_HANDLE ImageHandle,
232 IN EFI_SYSTEM_TABLE *SystemTable
235 return ${Function} (ImageHandle, SystemTable);
240 ## MM_CORE_STANDALONE Entry Point Templates
241 gMmCoreStandaloneEntryPointPrototype
= TemplateString("""
251 gMmCoreStandaloneEntryPointString
= TemplateString("""
253 const UINT32 _gMmRevision = ${PiSpecVersion};
257 ProcessModuleEntryPointList (
261 ${Function} (HobStart);
266 ## MM_STANDALONE Entry Point Templates
267 gMmStandaloneEntryPointPrototype
= TemplateString("""
272 IN EFI_HANDLE ImageHandle,
273 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
278 gMmStandaloneEntryPointString
= [
280 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
284 ProcessModuleEntryPointList (
285 IN EFI_HANDLE ImageHandle,
286 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
294 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
298 ProcessModuleEntryPointList (
299 IN EFI_HANDLE ImageHandle,
300 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
304 return ${Function} (ImageHandle, MmSystemTable);
309 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
313 ProcessModuleEntryPointList (
314 IN EFI_HANDLE ImageHandle,
315 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
320 EFI_STATUS CombinedStatus;
322 CombinedStatus = EFI_LOAD_ERROR;
324 Status = ${Function} (ImageHandle, MmSystemTable);
325 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
326 CombinedStatus = Status;
329 return CombinedStatus;
334 ## DXE SMM Entry Point Templates
335 gDxeSmmEntryPointPrototype
= TemplateString("""
340 IN EFI_HANDLE ImageHandle,
341 IN EFI_SYSTEM_TABLE *SystemTable
346 gDxeSmmEntryPointString
= [
348 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
349 const UINT32 _gDxeRevision = ${PiSpecVersion};
353 ProcessModuleEntryPointList (
354 IN EFI_HANDLE ImageHandle,
355 IN EFI_SYSTEM_TABLE *SystemTable
363 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
364 const UINT32 _gDxeRevision = ${PiSpecVersion};
366 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
367 static EFI_STATUS mDriverEntryPointStatus;
375 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
376 mDriverEntryPointStatus = Status;
378 LongJump (&mJumpContext, (UINTN)-1);
384 ProcessModuleEntryPointList (
385 IN EFI_HANDLE ImageHandle,
386 IN EFI_SYSTEM_TABLE *SystemTable
389 mDriverEntryPointStatus = EFI_LOAD_ERROR;
392 if (SetJump (&mJumpContext) == 0) {
393 ExitDriver (${Function} (ImageHandle, SystemTable));
398 return mDriverEntryPointStatus;
403 ## UEFI Driver Entry Point Templates
404 gUefiDriverEntryPointPrototype
= TemplateString("""
409 IN EFI_HANDLE ImageHandle,
410 IN EFI_SYSTEM_TABLE *SystemTable
415 gUefiDriverEntryPointString
= [
417 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
418 const UINT32 _gDxeRevision = ${PiSpecVersion};
422 ProcessModuleEntryPointList (
423 IN EFI_HANDLE ImageHandle,
424 IN EFI_SYSTEM_TABLE *SystemTable
431 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
432 const UINT32 _gDxeRevision = ${PiSpecVersion};
437 ProcessModuleEntryPointList (
438 IN EFI_HANDLE ImageHandle,
439 IN EFI_SYSTEM_TABLE *SystemTable
443 return ${Function} (ImageHandle, SystemTable);
452 if (EFI_ERROR (Status)) {
453 ProcessLibraryDestructorList (gImageHandle, gST);
455 gBS->Exit (gImageHandle, Status, 0, NULL);
459 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
460 const UINT32 _gDxeRevision = ${PiSpecVersion};
462 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
463 static EFI_STATUS mDriverEntryPointStatus;
467 ProcessModuleEntryPointList (
468 IN EFI_HANDLE ImageHandle,
469 IN EFI_SYSTEM_TABLE *SystemTable
472 mDriverEntryPointStatus = EFI_LOAD_ERROR;
474 if (SetJump (&mJumpContext) == 0) {
475 ExitDriver (${Function} (ImageHandle, SystemTable));
479 return mDriverEntryPointStatus;
488 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
489 mDriverEntryPointStatus = Status;
491 LongJump (&mJumpContext, (UINTN)-1);
498 ## UEFI Application Entry Point Templates
499 gUefiApplicationEntryPointPrototype
= TemplateString("""
504 IN EFI_HANDLE ImageHandle,
505 IN EFI_SYSTEM_TABLE *SystemTable
510 gUefiApplicationEntryPointString
= [
512 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
516 ProcessModuleEntryPointList (
517 IN EFI_HANDLE ImageHandle,
518 IN EFI_SYSTEM_TABLE *SystemTable
525 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
530 ProcessModuleEntryPointList (
531 IN EFI_HANDLE ImageHandle,
532 IN EFI_SYSTEM_TABLE *SystemTable
536 return ${Function} (ImageHandle, SystemTable);
545 if (EFI_ERROR (Status)) {
546 ProcessLibraryDestructorList (gImageHandle, gST);
548 gBS->Exit (gImageHandle, Status, 0, NULL);
552 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
556 ProcessModuleEntryPointList (
557 IN EFI_HANDLE ImageHandle,
558 IN EFI_SYSTEM_TABLE *SystemTable
563 if (SetJump (&mJumpContext) == 0) {
564 ExitDriver (${Function} (ImageHandle, SystemTable));
568 return mDriverEntryPointStatus;
571 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
572 static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
580 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
581 mDriverEntryPointStatus = Status;
583 LongJump (&mJumpContext, (UINTN)-1);
589 ## UEFI Unload Image Templates
590 gUefiUnloadImagePrototype
= TemplateString("""
595 IN EFI_HANDLE ImageHandle
600 gUefiUnloadImageString
= [
602 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
606 ProcessModuleUnloadList (
607 IN EFI_HANDLE ImageHandle
614 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
619 ProcessModuleUnloadList (
620 IN EFI_HANDLE ImageHandle
623 return ${Function} (ImageHandle);
628 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
632 ProcessModuleUnloadList (
633 IN EFI_HANDLE ImageHandle
638 Status = EFI_SUCCESS;
640 if (EFI_ERROR (Status)) {
641 ${Function} (ImageHandle);
643 Status = ${Function} (ImageHandle);
651 gLibraryStructorPrototype
= {
652 'BASE' : TemplateString("""${BEGIN}
660 'PEI' : TemplateString("""${BEGIN}
664 IN EFI_PEI_FILE_HANDLE FileHandle,
665 IN CONST EFI_PEI_SERVICES **PeiServices
669 'DXE' : TemplateString("""${BEGIN}
673 IN EFI_HANDLE ImageHandle,
674 IN EFI_SYSTEM_TABLE *SystemTable
678 'MM' : TemplateString("""${BEGIN}
682 IN EFI_HANDLE ImageHandle,
683 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
688 gLibraryStructorCall
= {
689 'BASE' : TemplateString("""${BEGIN}
690 Status = ${Function} ();
691 ASSERT_EFI_ERROR (Status);${END}
694 'PEI' : TemplateString("""${BEGIN}
695 Status = ${Function} (FileHandle, PeiServices);
696 ASSERT_EFI_ERROR (Status);${END}
699 'DXE' : TemplateString("""${BEGIN}
700 Status = ${Function} (ImageHandle, SystemTable);
701 ASSERT_EFI_ERROR (Status);${END}
704 'MM' : TemplateString("""${BEGIN}
705 Status = ${Function} (ImageHandle, MmSystemTable);
706 ASSERT_EFI_ERROR (Status);${END}
710 ## Library Constructor and Destructor Templates
712 'BASE' : TemplateString("""
713 ${BEGIN}${FunctionPrototype}${END}
717 ProcessLibrary${Type}List (
721 ${BEGIN} EFI_STATUS Status;
722 ${FunctionCall}${END}
726 'PEI' : TemplateString("""
727 ${BEGIN}${FunctionPrototype}${END}
731 ProcessLibrary${Type}List (
732 IN EFI_PEI_FILE_HANDLE FileHandle,
733 IN CONST EFI_PEI_SERVICES **PeiServices
736 ${BEGIN} EFI_STATUS Status;
737 ${FunctionCall}${END}
741 'DXE' : TemplateString("""
742 ${BEGIN}${FunctionPrototype}${END}
746 ProcessLibrary${Type}List (
747 IN EFI_HANDLE ImageHandle,
748 IN EFI_SYSTEM_TABLE *SystemTable
751 ${BEGIN} EFI_STATUS Status;
752 ${FunctionCall}${END}
756 'MM' : TemplateString("""
757 ${BEGIN}${FunctionPrototype}${END}
761 ProcessLibrary${Type}List (
762 IN EFI_HANDLE ImageHandle,
763 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
766 ${BEGIN} EFI_STATUS Status;
767 ${FunctionCall}${END}
772 gBasicHeaderFile
= "Base.h"
774 gModuleTypeHeaderFile
= {
775 "BASE" : [gBasicHeaderFile
],
776 "SEC" : ["PiPei.h", "Library/DebugLib.h"],
777 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],
778 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],
779 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],
780 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
781 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
782 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
783 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
784 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
785 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],
786 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],
787 "MM_STANDALONE" : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],
788 "MM_CORE_STANDALONE" : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],
789 "USER_DEFINED" : [gBasicHeaderFile
]
792 ## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
793 # the TokenName and Guid comparison to avoid define name collisions.
795 # @param Info The ModuleAutoGen object
796 # @param AutoGenH The TemplateString object for header file
799 def DynExPcdTokenNumberMapping(Info
, AutoGenH
):
800 ExTokenCNameList
= []
802 # Even it is the Library, the PCD is saved in the ModulePcdList
803 PcdList
= Info
.ModulePcdList
805 if Pcd
.Type
in gDynamicExPcd
:
806 ExTokenCNameList
.append(Pcd
.TokenCName
)
807 PcdExList
.append(Pcd
)
808 if len(ExTokenCNameList
) == 0:
810 AutoGenH
.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')
811 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
812 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
813 # Use the Guid pointer to see if it matches any of the token space GUIDs.
815 for TokenCName
in ExTokenCNameList
:
816 if TokenCName
in TokenCNameList
:
819 Count
= ExTokenCNameList
.count(TokenCName
)
820 for Pcd
in PcdExList
:
821 RealTokenCName
= Pcd
.TokenCName
822 for PcdItem
in GlobalData
.MixedPcd
:
823 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
824 RealTokenCName
= PcdItem
[0]
826 if Pcd
.TokenCName
== TokenCName
:
829 AutoGenH
.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName
))
830 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
831 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
833 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
834 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
836 AutoGenH
.Append('0 \\\n )\n')
837 TokenCNameList
.append(TokenCName
)
840 for TokenCName
in ExTokenCNameList
:
841 if TokenCName
in TokenCNameList
:
844 Count
= ExTokenCNameList
.count(TokenCName
)
845 for Pcd
in PcdExList
:
846 RealTokenCName
= Pcd
.TokenCName
847 for PcdItem
in GlobalData
.MixedPcd
:
848 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
849 RealTokenCName
= PcdItem
[0]
851 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== TokenCName
:
854 AutoGenH
.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName
))
855 AutoGenH
.Append('\\\n (GuidPtr == NULL) ? 0:')
856 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
857 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
859 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
860 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
862 AutoGenH
.Append('0 \\\n )\n')
863 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
864 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
865 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
866 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
867 AutoGenH
.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'
868 % (RealTokenCName
, RealTokenCName
, RealTokenCName
, RealTokenCName
))
869 TokenCNameList
.append(TokenCName
)
872 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
873 Value
= Pcd
.DefaultValue
874 if Value
in [None, '']:
876 elif Value
[0] == 'L':
877 return (len(Value
) - 2) * 2
878 elif Value
[0] == '{':
879 return len(Value
.split(','))
881 return len(Value
) - 1
882 if Pcd
.DatumType
== 'UINT64':
884 if Pcd
.DatumType
== 'UINT32':
886 if Pcd
.DatumType
== 'UINT16':
888 if Pcd
.DatumType
== 'UINT8':
890 if Pcd
.DatumType
== 'BOOLEAN':
893 return Pcd
.MaxDatumSize
896 ## Create code for module PCDs
898 # @param Info The ModuleAutoGen object
899 # @param AutoGenC The TemplateString object for C code
900 # @param AutoGenH The TemplateString object for header file
901 # @param Pcd The PCD object
903 def CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
904 TokenSpaceGuidValue
= Pcd
.TokenSpaceGuidValue
#Info.GuidList[Pcd.TokenSpaceGuidCName]
905 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
909 TokenCName
= Pcd
.TokenCName
910 for PcdItem
in GlobalData
.MixedPcd
:
911 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
912 TokenCName
= PcdItem
[0]
914 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
915 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
916 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
917 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
919 if Pcd
.PcdValueFromComm
:
920 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
922 if Pcd
.Type
in gDynamicExPcd
:
923 TokenNumber
= int(Pcd
.TokenValue
, 0)
924 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
925 # different Guids but same TokenCName
926 PcdExTokenName
= '_PCD_TOKEN_' + Pcd
.TokenSpaceGuidCName
+ '_' + TokenCName
927 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
929 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
930 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
931 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
932 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
933 # report warning message notify the PI that they are attempting to build a module
934 # that must be included in a flash image in order to be functional. These Dynamic PCD
935 # will not be added into the Database unless it is used by other modules that are
936 # included in the FDF file.
937 # In this case, just assign an invalid token number to make it pass build.
938 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
941 EdkLogger
.error("build", AUTOGEN_ERROR
,
942 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
943 ExtraData
="[%s]" % str(Info
))
945 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
946 AutoGenH
.Append('\n#define %s %dU\n' % (PcdTokenName
, TokenNumber
))
948 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "Creating code for " + TokenCName
+ "." + Pcd
.TokenSpaceGuidCName
)
949 if Pcd
.Type
not in gItemTypeStringDatabase
:
950 EdkLogger
.error("build", AUTOGEN_ERROR
,
951 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
952 ExtraData
="[%s]" % str(Info
))
954 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
['VOID*']
955 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
['VOID*']
956 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
957 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
958 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_S_' + TokenCName
959 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
962 if Pcd
.Type
in gDynamicExPcd
:
964 PcdList
= Info
.LibraryPcdList
966 PcdList
= Info
.ModulePcdList
967 for PcdModule
in PcdList
:
968 if PcdModule
.Type
in gDynamicExPcd
:
969 PcdExCNameList
.append(PcdModule
.TokenCName
)
970 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
971 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
972 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
973 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
974 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')
975 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
976 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
977 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
978 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
979 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
980 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
982 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
983 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
985 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
986 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
987 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
988 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
989 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
990 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
992 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
993 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
994 elif Pcd
.Type
in gDynamicPcd
:
997 PcdList
.extend(Info
.LibraryPcdList
)
998 PcdList
.extend(Info
.ModulePcdList
)
999 for PcdModule
in PcdList
:
1000 if PcdModule
.Type
in gDynamicPcd
:
1001 PcdCNameList
.append(PcdModule
.TokenCName
)
1002 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1003 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
))
1005 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1006 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1007 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1008 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1009 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1011 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1012 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1014 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1016 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1020 Value
= Pcd
.DefaultValue
1024 if Pcd
.DatumType
== 'BOOLEAN':
1025 BoolValue
= Value
.upper()
1026 if BoolValue
== 'TRUE' or BoolValue
== '1':
1028 elif BoolValue
== 'FALSE' or BoolValue
== '0':
1031 if Pcd
.DatumType
in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
1033 if Value
.upper().endswith('L'):
1035 if Value
.upper().startswith('0X'):
1036 ValueNumber
= int (Value
, 16)
1038 ValueNumber
= int (Value
)
1040 EdkLogger
.error("build", AUTOGEN_ERROR
,
1041 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1042 ExtraData
="[%s]" % str(Info
))
1043 if Pcd
.DatumType
== 'UINT64':
1045 EdkLogger
.error("build", AUTOGEN_ERROR
,
1046 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1047 ExtraData
="[%s]" % str(Info
))
1048 elif ValueNumber
>= 0x10000000000000000:
1049 EdkLogger
.error("build", AUTOGEN_ERROR
,
1050 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1051 ExtraData
="[%s]" % str(Info
))
1052 if not Value
.endswith('ULL'):
1054 elif Pcd
.DatumType
== 'UINT32':
1056 EdkLogger
.error("build", AUTOGEN_ERROR
,
1057 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1058 ExtraData
="[%s]" % str(Info
))
1059 elif ValueNumber
>= 0x100000000:
1060 EdkLogger
.error("build", AUTOGEN_ERROR
,
1061 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1062 ExtraData
="[%s]" % str(Info
))
1063 if not Value
.endswith('U'):
1065 elif Pcd
.DatumType
== 'UINT16':
1067 EdkLogger
.error("build", AUTOGEN_ERROR
,
1068 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1069 ExtraData
="[%s]" % str(Info
))
1070 elif ValueNumber
>= 0x10000:
1071 EdkLogger
.error("build", AUTOGEN_ERROR
,
1072 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1073 ExtraData
="[%s]" % str(Info
))
1074 if not Value
.endswith('U'):
1076 elif Pcd
.DatumType
== 'UINT8':
1078 EdkLogger
.error("build", AUTOGEN_ERROR
,
1079 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1080 ExtraData
="[%s]" % str(Info
))
1081 elif ValueNumber
>= 0x100:
1082 EdkLogger
.error("build", AUTOGEN_ERROR
,
1083 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1084 ExtraData
="[%s]" % str(Info
))
1085 if not Value
.endswith('U'):
1087 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1088 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
1089 EdkLogger
.error("build", AUTOGEN_ERROR
,
1090 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1091 ExtraData
="[%s]" % str(Info
))
1093 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1099 Value
= Value
.lstrip('L') #.strip('"')
1100 Value
= eval(Value
) # translate escape character
1102 for Index
in range(0,len(Value
)):
1104 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ', '
1106 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ', '
1108 ArraySize
= ArraySize
/ 2;
1110 if ArraySize
< (len(Value
) + 1):
1111 EdkLogger
.error("build", AUTOGEN_ERROR
,
1112 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1113 ExtraData
="[%s]" % str(Info
))
1114 Value
= NewValue
+ '0 }'
1115 Array
= '[%d]' % ArraySize
1117 # skip casting for fixed at build since it breaks ARM assembly.
1118 # Long term we need PCD macros that work in assembly
1120 elif Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
and Pcd
.DatumType
in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1121 Value
= "((%s)%s)" % (Pcd
.DatumType
, Value
)
1123 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1124 # handle structure PCD
1125 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
1126 EdkLogger
.error("build", AUTOGEN_ERROR
,
1127 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1128 ExtraData
="[%s]" % str(Info
))
1130 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1131 Array
= '[%d]' % ArraySize
1133 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1134 PcdValueName
= '_PCD_PATCHABLE_VALUE_' + TokenCName
1136 PcdValueName
= '_PCD_VALUE_' + TokenCName
1138 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1140 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1143 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1144 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1145 AutoGenH
.Append('extern %s UINT16 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1146 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1148 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1149 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1150 AutoGenH
.Append('extern %s UINT8 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1151 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1153 PcdDataSize
= GetPcdSize(Pcd
)
1154 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
1155 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1156 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1158 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1159 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1160 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1161 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1162 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1163 elif Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1164 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1165 AutoGenC
.Append('volatile %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1166 AutoGenH
.Append('extern volatile %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1167 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1169 PcdDataSize
= GetPcdSize(Pcd
)
1170 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1172 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1173 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1174 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1176 PcdDataSize
= GetPcdSize(Pcd
)
1177 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1178 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1180 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1181 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1182 AutoGenH
.Append('extern %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1183 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1185 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1186 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1187 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
))
1188 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
))
1190 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1191 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName
, PcdVariableName
))
1193 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1195 ## Create code for library module PCDs
1197 # @param Info The ModuleAutoGen object
1198 # @param AutoGenC The TemplateString object for C code
1199 # @param AutoGenH The TemplateString object for header file
1200 # @param Pcd The PCD object
1202 def CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
1203 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
1204 TokenSpaceGuidCName
= Pcd
.TokenSpaceGuidCName
1205 TokenCName
= Pcd
.TokenCName
1206 for PcdItem
in GlobalData
.MixedPcd
:
1207 if (TokenCName
, TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1208 TokenCName
= PcdItem
[0]
1210 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
1211 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
1212 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
1213 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
1215 if Pcd
.PcdValueFromComm
:
1216 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
1220 if Pcd
.Type
in gDynamicExPcd
:
1221 TokenNumber
= int(Pcd
.TokenValue
, 0)
1223 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
1224 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1225 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1226 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1227 # report warning message notify the PI that they are attempting to build a module
1228 # that must be included in a flash image in order to be functional. These Dynamic PCD
1229 # will not be added into the Database unless it is used by other modules that are
1230 # included in the FDF file.
1231 # In this case, just assign an invalid token number to make it pass build.
1232 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
1235 EdkLogger
.error("build", AUTOGEN_ERROR
,
1236 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1237 ExtraData
="[%s]" % str(Info
))
1239 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
1241 if Pcd
.Type
not in gItemTypeStringDatabase
:
1242 EdkLogger
.error("build", AUTOGEN_ERROR
,
1243 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1244 ExtraData
="[%s]" % str(Info
))
1246 DatumType
= Pcd
.DatumType
1247 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
['VOID*']
1248 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
['VOID*']
1249 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
1250 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
1251 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_S_' + TokenCName
1252 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1256 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1257 if Pcd
.DefaultValue
[0]== '{':
1260 PcdItemType
= Pcd
.Type
1262 if PcdItemType
in gDynamicExPcd
:
1263 PcdExTokenName
= '_PCD_TOKEN_' + TokenSpaceGuidCName
+ '_' + TokenCName
1264 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
1267 PcdList
= Info
.LibraryPcdList
1269 PcdList
= Info
.ModulePcdList
1270 for PcdModule
in PcdList
:
1271 if PcdModule
.Type
in gDynamicExPcd
:
1272 PcdExCNameList
.append(PcdModule
.TokenCName
)
1273 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1274 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1275 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1276 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
1277 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')
1278 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1279 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1280 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1281 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1282 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1283 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1285 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1286 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1288 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1289 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1290 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1291 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1292 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1293 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1295 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1296 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1298 AutoGenH
.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName
, TokenNumber
))
1299 if PcdItemType
in gDynamicPcd
:
1302 PcdList
.extend(Info
.LibraryPcdList
)
1303 PcdList
.extend(Info
.ModulePcdList
)
1304 for PcdModule
in PcdList
:
1305 if PcdModule
.Type
in gDynamicPcd
:
1306 PcdCNameList
.append(PcdModule
.TokenCName
)
1307 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1308 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
))
1310 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1311 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1312 if DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1313 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1314 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1316 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1317 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1318 if PcdItemType
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1319 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[TAB_PCDS_PATCHABLE_IN_MODULE
] + '_' + TokenCName
1320 if DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1321 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1322 if Pcd
.DefaultValue
[0] == 'L':
1323 ArraySize
= ArraySize
/ 2
1324 Array
= '[%d]' % ArraySize
1325 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1326 AutoGenH
.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1328 AutoGenH
.Append('extern volatile %s %s%s;\n' % (DatumType
, PcdVariableName
, Array
))
1329 AutoGenH
.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName
, Type
, TokenCName
))
1330 PcdDataSize
= GetPcdSize(Pcd
)
1331 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1332 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
))
1333 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
))
1334 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1336 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1337 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName
, PcdVariableName
))
1338 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1340 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1341 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1343 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
or PcdItemType
== TAB_PCDS_FEATURE_FLAG
:
1344 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1345 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1346 if DatumType
== 'VOID*' and Array
== '[]':
1347 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1348 if DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1350 AutoGenH
.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1351 AutoGenH
.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName
, Type
, TokenCName
))
1352 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1354 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
and (key
in Info
.ConstPcd
or (Info
.IsLibrary
and not Info
._ReferenceModules
)):
1355 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
1356 AutoGenH
.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName
, Type
, PcdVariableName
))
1358 AutoGenH
.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName
, Pcd
.DefaultValue
))
1360 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
:
1361 PcdDataSize
= GetPcdSize(Pcd
)
1362 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1363 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1365 ## Create code for library constructor
1367 # @param Info The ModuleAutoGen object
1368 # @param AutoGenC The TemplateString object for C code
1369 # @param AutoGenH The TemplateString object for header file
1371 def CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
):
1373 # Library Constructors
1375 ConstructorPrototypeString
= TemplateString()
1376 ConstructorCallingString
= TemplateString()
1378 DependentLibraryList
= [Info
.Module
]
1380 DependentLibraryList
= Info
.DependentLibraryList
1381 for Lib
in DependentLibraryList
:
1382 if len(Lib
.ConstructorList
) <= 0:
1384 Dict
= {'Function':Lib
.ConstructorList
}
1385 if Lib
.ModuleType
in ['BASE', 'SEC']:
1386 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1387 ConstructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1388 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1389 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1390 ConstructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1391 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1392 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1393 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1394 ConstructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1395 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1396 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1397 ConstructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1399 if str(ConstructorPrototypeString
) == '':
1400 ConstructorPrototypeList
= []
1402 ConstructorPrototypeList
= [str(ConstructorPrototypeString
)]
1403 if str(ConstructorCallingString
) == '':
1404 ConstructorCallingList
= []
1406 ConstructorCallingList
= [str(ConstructorCallingString
)]
1409 'Type' : 'Constructor',
1410 'FunctionPrototype' : ConstructorPrototypeList
,
1411 'FunctionCall' : ConstructorCallingList
1414 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1416 if Info
.ModuleType
in ['BASE', 'SEC']:
1417 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1418 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1419 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1420 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1421 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1422 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1423 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1424 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1426 ## Create code for library destructor
1428 # @param Info The ModuleAutoGen object
1429 # @param AutoGenC The TemplateString object for C code
1430 # @param AutoGenH The TemplateString object for header file
1432 def CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
):
1434 # Library Destructors
1436 DestructorPrototypeString
= TemplateString()
1437 DestructorCallingString
= TemplateString()
1439 DependentLibraryList
= [Info
.Module
]
1441 DependentLibraryList
= Info
.DependentLibraryList
1442 for Index
in range(len(DependentLibraryList
)-1, -1, -1):
1443 Lib
= DependentLibraryList
[Index
]
1444 if len(Lib
.DestructorList
) <= 0:
1446 Dict
= {'Function':Lib
.DestructorList
}
1447 if Lib
.ModuleType
in ['BASE', 'SEC']:
1448 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1449 DestructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1450 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1451 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1452 DestructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1453 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1454 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1455 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1456 DestructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1457 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1458 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1459 DestructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1461 if str(DestructorPrototypeString
) == '':
1462 DestructorPrototypeList
= []
1464 DestructorPrototypeList
= [str(DestructorPrototypeString
)]
1465 if str(DestructorCallingString
) == '':
1466 DestructorCallingList
= []
1468 DestructorCallingList
= [str(DestructorCallingString
)]
1471 'Type' : 'Destructor',
1472 'FunctionPrototype' : DestructorPrototypeList
,
1473 'FunctionCall' : DestructorCallingList
1476 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1478 if Info
.ModuleType
in ['BASE', 'SEC']:
1479 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1480 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1481 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1482 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1483 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1484 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1485 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1486 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1489 ## Create code for ModuleEntryPoint
1491 # @param Info The ModuleAutoGen object
1492 # @param AutoGenC The TemplateString object for C code
1493 # @param AutoGenH The TemplateString object for header file
1495 def CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
):
1496 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1499 # Module Entry Points
1501 NumEntryPoints
= len(Info
.Module
.ModuleEntryPointList
)
1502 if 'PI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1503 PiSpecVersion
= Info
.Module
.Specification
['PI_SPECIFICATION_VERSION']
1505 PiSpecVersion
= '0x00000000'
1506 if 'UEFI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1507 UefiSpecVersion
= Info
.Module
.Specification
['UEFI_SPECIFICATION_VERSION']
1509 UefiSpecVersion
= '0x00000000'
1511 'Function' : Info
.Module
.ModuleEntryPointList
,
1512 'PiSpecVersion' : PiSpecVersion
+ 'U',
1513 'UefiSpecVersion': UefiSpecVersion
+ 'U'
1516 if Info
.ModuleType
in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE', 'MM_CORE_STANDALONE']:
1517 if Info
.SourceFileList
<> None and Info
.SourceFileList
<> []:
1518 if NumEntryPoints
!= 1:
1522 '%s must have exactly one entry point' % Info
.ModuleType
,
1524 ExtraData
= ", ".join(Info
.Module
.ModuleEntryPointList
)
1526 if Info
.ModuleType
== 'PEI_CORE':
1527 AutoGenC
.Append(gPeiCoreEntryPointString
.Replace(Dict
))
1528 AutoGenH
.Append(gPeiCoreEntryPointPrototype
.Replace(Dict
))
1529 elif Info
.ModuleType
== 'DXE_CORE':
1530 AutoGenC
.Append(gDxeCoreEntryPointString
.Replace(Dict
))
1531 AutoGenH
.Append(gDxeCoreEntryPointPrototype
.Replace(Dict
))
1532 elif Info
.ModuleType
== 'SMM_CORE':
1533 AutoGenC
.Append(gSmmCoreEntryPointString
.Replace(Dict
))
1534 AutoGenH
.Append(gSmmCoreEntryPointPrototype
.Replace(Dict
))
1535 elif Info
.ModuleType
== 'MM_CORE_STANDALONE':
1536 AutoGenC
.Append(gMmCoreStandaloneEntryPointString
.Replace(Dict
))
1537 AutoGenH
.Append(gMmCoreStandaloneEntryPointPrototype
.Replace(Dict
))
1538 elif Info
.ModuleType
== 'PEIM':
1539 if NumEntryPoints
< 2:
1540 AutoGenC
.Append(gPeimEntryPointString
[NumEntryPoints
].Replace(Dict
))
1542 AutoGenC
.Append(gPeimEntryPointString
[2].Replace(Dict
))
1543 AutoGenH
.Append(gPeimEntryPointPrototype
.Replace(Dict
))
1544 elif Info
.ModuleType
in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1545 if NumEntryPoints
< 2:
1546 AutoGenC
.Append(gUefiDriverEntryPointString
[NumEntryPoints
].Replace(Dict
))
1548 AutoGenC
.Append(gUefiDriverEntryPointString
[2].Replace(Dict
))
1549 AutoGenH
.Append(gUefiDriverEntryPointPrototype
.Replace(Dict
))
1550 elif Info
.ModuleType
== 'DXE_SMM_DRIVER':
1551 if NumEntryPoints
== 0:
1552 AutoGenC
.Append(gDxeSmmEntryPointString
[0].Replace(Dict
))
1554 AutoGenC
.Append(gDxeSmmEntryPointString
[1].Replace(Dict
))
1555 AutoGenH
.Append(gDxeSmmEntryPointPrototype
.Replace(Dict
))
1556 elif Info
.ModuleType
== 'MM_STANDALONE':
1557 if NumEntryPoints
< 2:
1558 AutoGenC
.Append(gMmStandaloneEntryPointString
[NumEntryPoints
].Replace(Dict
))
1560 AutoGenC
.Append(gMmStandaloneEntryPointString
[2].Replace(Dict
))
1561 AutoGenH
.Append(gMmStandaloneEntryPointPrototype
.Replace(Dict
))
1562 elif Info
.ModuleType
== 'UEFI_APPLICATION':
1563 if NumEntryPoints
< 2:
1564 AutoGenC
.Append(gUefiApplicationEntryPointString
[NumEntryPoints
].Replace(Dict
))
1566 AutoGenC
.Append(gUefiApplicationEntryPointString
[2].Replace(Dict
))
1567 AutoGenH
.Append(gUefiApplicationEntryPointPrototype
.Replace(Dict
))
1569 ## Create code for ModuleUnloadImage
1571 # @param Info The ModuleAutoGen object
1572 # @param AutoGenC The TemplateString object for C code
1573 # @param AutoGenH The TemplateString object for header file
1575 def CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
):
1576 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1579 # Unload Image Handlers
1581 NumUnloadImage
= len(Info
.Module
.ModuleUnloadImageList
)
1582 Dict
= {'Count':str(NumUnloadImage
) + 'U', 'Function':Info
.Module
.ModuleUnloadImageList
}
1583 if NumUnloadImage
< 2:
1584 AutoGenC
.Append(gUefiUnloadImageString
[NumUnloadImage
].Replace(Dict
))
1586 AutoGenC
.Append(gUefiUnloadImageString
[2].Replace(Dict
))
1587 AutoGenH
.Append(gUefiUnloadImagePrototype
.Replace(Dict
))
1589 ## Create code for GUID
1591 # @param Info The ModuleAutoGen object
1592 # @param AutoGenC The TemplateString object for C code
1593 # @param AutoGenH The TemplateString object for header file
1595 def CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1596 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1599 GuidType
= "EFI_GUID"
1602 if not Info
.IsLibrary
:
1603 AutoGenC
.Append("\n// Guids\n")
1604 AutoGenH
.Append("\n// Guids\n")
1608 for Key
in Info
.GuidList
:
1609 if not Info
.IsLibrary
:
1610 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.GuidList
[Key
]))
1611 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1613 ## Create code for protocol
1615 # @param Info The ModuleAutoGen object
1616 # @param AutoGenC The TemplateString object for C code
1617 # @param AutoGenH The TemplateString object for header file
1619 def CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1620 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1623 GuidType
= "EFI_GUID"
1625 if Info
.ProtocolList
:
1626 if not Info
.IsLibrary
:
1627 AutoGenC
.Append("\n// Protocols\n")
1628 AutoGenH
.Append("\n// Protocols\n")
1632 for Key
in Info
.ProtocolList
:
1633 if not Info
.IsLibrary
:
1634 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.ProtocolList
[Key
]))
1635 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1637 ## Create code for PPI
1639 # @param Info The ModuleAutoGen object
1640 # @param AutoGenC The TemplateString object for C code
1641 # @param AutoGenH The TemplateString object for header file
1643 def CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1644 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1647 GuidType
= "EFI_GUID"
1650 if not Info
.IsLibrary
:
1651 AutoGenC
.Append("\n// PPIs\n")
1652 AutoGenH
.Append("\n// PPIs\n")
1656 for Key
in Info
.PpiList
:
1657 if not Info
.IsLibrary
:
1658 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.PpiList
[Key
]))
1659 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1661 ## Create code for PCD
1663 # @param Info The ModuleAutoGen object
1664 # @param AutoGenC The TemplateString object for C code
1665 # @param AutoGenH The TemplateString object for header file
1667 def CreatePcdCode(Info
, AutoGenC
, AutoGenH
):
1669 # Collect Token Space GUIDs used by DynamicEc PCDs
1671 for Pcd
in Info
.ModulePcdList
:
1672 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenSpaceGuidCName
not in TokenSpaceList
:
1673 TokenSpaceList
+= [Pcd
.TokenSpaceGuidCName
]
1675 SkuMgr
= Info
.Workspace
.Platform
.SkuIdMgr
1676 AutoGenH
.Append("\n// Definition of SkuId Array\n")
1677 AutoGenH
.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
1678 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1679 if TokenSpaceList
<> []:
1680 AutoGenH
.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1681 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1684 GuidType
= "EFI_GUID"
1685 for Item
in TokenSpaceList
:
1686 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Item
))
1689 if Info
.ModulePcdList
:
1690 AutoGenH
.Append("\n// PCD definitions\n")
1691 for Pcd
in Info
.ModulePcdList
:
1692 CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1693 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1695 AutoGenC
.Append("\n// Definition of SkuId Array\n")
1696 AutoGenC
.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr
.DumpSkuIdArrary())
1697 if Info
.ModulePcdList
:
1698 AutoGenH
.Append("\n// Definition of PCDs used in this module\n")
1699 AutoGenC
.Append("\n// Definition of PCDs used in this module\n")
1700 for Pcd
in Info
.ModulePcdList
:
1701 CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1702 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1703 if Info
.LibraryPcdList
:
1704 AutoGenH
.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1705 AutoGenC
.Append("\n// Definition of PCDs used in libraries\n")
1706 for Pcd
in Info
.LibraryPcdList
:
1707 CreateModulePcdCode(Info
, AutoGenC
, AutoGenC
, Pcd
)
1708 CreatePcdDatabaseCode(Info
, AutoGenC
, AutoGenH
)
1710 ## Create code for unicode string definition
1712 # @param Info The ModuleAutoGen object
1713 # @param AutoGenC The TemplateString object for C code
1714 # @param AutoGenH The TemplateString object for header file
1715 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1716 # @param UniGenBinBuffer Buffer to store uni string package data
1718 def CreateUnicodeStringCode(Info
, AutoGenC
, AutoGenH
, UniGenCFlag
, UniGenBinBuffer
):
1719 WorkingDir
= os
.getcwd()
1720 os
.chdir(Info
.WorkspaceDir
)
1722 IncList
= [Info
.MetaFile
.Dir
]
1723 # Get all files under [Sources] section in inf file for EDK-II module
1725 SrcList
= [F
for F
in Info
.SourceFileList
]
1726 if Info
.AutoGenVersion
< 0x00010005:
1728 # Get all files under the module directory for EDK-I module
1730 os
.chdir(Info
.MetaFile
.Dir
)
1731 for Root
, Dirs
, Files
in os
.walk("."):
1737 File
= PathClass(os
.path
.join(Root
, File
), Info
.MetaFile
.Dir
)
1740 SrcList
.append(File
)
1743 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-c') > -1:
1744 CompatibleMode
= True
1746 CompatibleMode
= False
1749 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1751 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-s') > -1:
1753 EdkLogger
.error("build", AUTOGEN_ERROR
,
1754 "-c and -s build options should be used exclusively",
1755 ExtraData
="[%s]" % str(Info
))
1760 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1762 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.RFCLanguages
]
1764 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.ISOLanguages
]
1765 Header
, Code
= GetStringFiles(Info
.UnicodeFileList
, SrcList
, IncList
, Info
.IncludePathList
, ['.uni', '.inf'], Info
.Name
, CompatibleMode
, ShellMode
, UniGenCFlag
, UniGenBinBuffer
, FilterInfo
)
1766 if CompatibleMode
or UniGenCFlag
:
1767 AutoGenC
.Append("\n//\n//Unicode String Pack Definition\n//\n")
1768 AutoGenC
.Append(Code
)
1769 AutoGenC
.Append("\n")
1770 AutoGenH
.Append("\n//\n//Unicode String ID\n//\n")
1771 AutoGenH
.Append(Header
)
1772 if CompatibleMode
or UniGenCFlag
:
1773 AutoGenH
.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info
.Name
)
1774 os
.chdir(WorkingDir
)
1776 def CreateIdfFileCode(Info
, AutoGenC
, StringH
, IdfGenCFlag
, IdfGenBinBuffer
):
1777 if len(Info
.IdfFileList
) > 0:
1778 ImageFiles
= IdfFileClassObject(sorted (Info
.IdfFileList
))
1779 if ImageFiles
.ImageFilesDict
:
1782 IncList
= [Info
.MetaFile
.Dir
]
1783 SrcList
= [F
for F
in Info
.SourceFileList
]
1784 SkipList
= ['.jpg', '.png', '.bmp', '.inf', '.idf']
1785 FileList
= GetFileList(SrcList
, IncList
, SkipList
)
1787 StringH
.Append("\n//\n//Image ID\n//\n")
1789 PaletteInfoOffset
= 0
1790 ImageBuffer
= pack('x')
1791 PaletteBuffer
= pack('x')
1795 for Idf
in ImageFiles
.ImageFilesDict
:
1796 if ImageFiles
.ImageFilesDict
[Idf
]:
1797 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1798 for sourcefile
in Info
.SourceFileList
:
1799 if FileObj
.FileName
== sourcefile
.File
:
1800 if not sourcefile
.Ext
.upper() in ['.PNG', '.BMP', '.JPG']:
1801 EdkLogger
.error("build", AUTOGEN_ERROR
, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj
.FileName
), ExtraData
="[%s]" % str(Info
))
1802 FileObj
.File
= sourcefile
1805 EdkLogger
.error("build", AUTOGEN_ERROR
, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj
.FileName
, Idf
), ExtraData
="[%s]" % str(Info
))
1807 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1808 ID
= FileObj
.ImageID
1810 if not os
.path
.exists(File
.Path
) or not os
.path
.isfile(File
.Path
):
1811 EdkLogger
.error("build", FILE_NOT_FOUND
, ExtraData
=File
.Path
)
1812 SearchImageID (FileObj
, FileList
)
1813 if FileObj
.Referenced
:
1814 if (ValueStartPtr
- len(DEFINE_STR
+ ID
)) <= 0:
1815 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' + DecToHexStr(Index
, 4) + '\n'
1817 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' * (ValueStartPtr
- len(DEFINE_STR
+ ID
)) + DecToHexStr(Index
, 4) + '\n'
1819 if File
not in FileDict
:
1820 FileDict
[File
] = Index
1822 DuplicateBlock
= pack('B', EFI_HII_IIBT_DUPLICATE
)
1823 DuplicateBlock
+= pack('H', FileDict
[File
])
1824 ImageBuffer
+= DuplicateBlock
1825 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1826 TempBufferList
= AscToHexList(DuplicateBlock
)
1827 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1828 StringH
.Append(Line
)
1832 TmpFile
= open(File
.Path
, 'rb')
1833 Buffer
= TmpFile
.read()
1835 if File
.Ext
.upper() == '.PNG':
1836 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_PNG
)
1837 TempBuffer
+= pack('I', len(Buffer
))
1838 TempBuffer
+= Buffer
1839 elif File
.Ext
.upper() == '.JPG':
1840 ImageType
, = struct
.unpack('4s', Buffer
[6:10])
1841 if ImageType
!= 'JFIF':
1842 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard JPG file." % File
.Path
)
1843 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_JPEG
)
1844 TempBuffer
+= pack('I', len(Buffer
))
1845 TempBuffer
+= Buffer
1846 elif File
.Ext
.upper() == '.BMP':
1847 TempBuffer
, TempPalette
= BmpImageDecoder(File
, Buffer
, PaletteIndex
, FileObj
.TransParent
)
1848 if len(TempPalette
) > 1:
1850 NewPalette
= pack('H', len(TempPalette
))
1851 NewPalette
+= TempPalette
1852 PaletteBuffer
+= NewPalette
1853 PaletteStr
= WriteLine(PaletteStr
, '// %s: %s: %s' % (DecToHexStr(PaletteIndex
- 1, 4), ID
, DecToHexStr(PaletteIndex
- 1, 4)))
1854 TempPaletteList
= AscToHexList(NewPalette
)
1855 PaletteStr
= WriteLine(PaletteStr
, CreateArrayItem(TempPaletteList
, 16) + '\n')
1856 ImageBuffer
+= TempBuffer
1857 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1858 TempBufferList
= AscToHexList(TempBuffer
)
1859 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1861 StringH
.Append(Line
)
1864 BufferStr
= WriteLine(BufferStr
, '// End of the Image Info')
1865 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END
, 2)) + '\n')
1866 ImageEnd
= pack('B', EFI_HII_IIBT_END
)
1867 ImageBuffer
+= ImageEnd
1869 if len(ImageBuffer
) > 1:
1870 ImageInfoOffset
= 12
1871 if len(PaletteBuffer
) > 1:
1872 PaletteInfoOffset
= 12 + len(ImageBuffer
) - 1 # -1 is for the first empty pad byte of ImageBuffer
1874 IMAGE_PACKAGE_HDR
= pack('=II', ImageInfoOffset
, PaletteInfoOffset
)
1875 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
1876 if len(PaletteBuffer
) > 1:
1877 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1 + 2 + len(PaletteBuffer
) - 1
1879 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1
1880 if PaletteIndex
> 1:
1881 PALETTE_INFO_HEADER
= pack('H', PaletteIndex
- 1)
1882 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
1883 Hex_Length
= '%06X' % PACKAGE_HEADER_Length
1884 if PACKAGE_HEADER_Length
> 0xFFFFFF:
1885 EdkLogger
.error("build", AUTOGEN_ERROR
, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData
="[%s]" % str(Info
))
1886 PACKAGE_HEADER
= pack('=HBB', int('0x' + Hex_Length
[2:], 16), int('0x' + Hex_Length
[0:2], 16), EFI_HII_PACKAGE_IMAGES
)
1888 IdfGenBinBuffer
.write(PACKAGE_HEADER
)
1889 IdfGenBinBuffer
.write(IMAGE_PACKAGE_HDR
)
1890 if len(ImageBuffer
) > 1 :
1891 IdfGenBinBuffer
.write(ImageBuffer
[1:])
1892 if PaletteIndex
> 1:
1893 IdfGenBinBuffer
.write(PALETTE_INFO_HEADER
)
1894 if len(PaletteBuffer
) > 1:
1895 IdfGenBinBuffer
.write(PaletteBuffer
[1:])
1898 TotalLength
= EFI_HII_ARRAY_SIZE_LENGTH
+ PACKAGE_HEADER_Length
1899 AutoGenC
.Append("\n//\n//Image Pack Definition\n//\n")
1900 AllStr
= WriteLine('', CHAR_ARRAY_DEFIN
+ ' ' + Info
.Module
.BaseName
+ 'Images' + '[] = {\n')
1901 AllStr
= WriteLine(AllStr
, '// STRGATHER_OUTPUT_HEADER')
1902 AllStr
= WriteLine(AllStr
, CreateArrayItem(DecToHexList(TotalLength
)) + '\n')
1903 AllStr
= WriteLine(AllStr
, '// Image PACKAGE HEADER\n')
1904 IMAGE_PACKAGE_HDR_List
= AscToHexList(PACKAGE_HEADER
)
1905 IMAGE_PACKAGE_HDR_List
+= AscToHexList(IMAGE_PACKAGE_HDR
)
1906 AllStr
= WriteLine(AllStr
, CreateArrayItem(IMAGE_PACKAGE_HDR_List
, 16) + '\n')
1907 AllStr
= WriteLine(AllStr
, '// Image DATA\n')
1909 AllStr
= WriteLine(AllStr
, BufferStr
)
1911 AllStr
= WriteLine(AllStr
, '// Palette Header\n')
1912 PALETTE_INFO_HEADER_List
= AscToHexList(PALETTE_INFO_HEADER
)
1913 AllStr
= WriteLine(AllStr
, CreateArrayItem(PALETTE_INFO_HEADER_List
, 16) + '\n')
1914 AllStr
= WriteLine(AllStr
, '// Palette Data\n')
1915 AllStr
= WriteLine(AllStr
, PaletteStr
)
1916 AllStr
= WriteLine(AllStr
, '};')
1917 AutoGenC
.Append(AllStr
)
1918 AutoGenC
.Append("\n")
1919 StringH
.Append('\nextern unsigned char ' + Info
.Module
.BaseName
+ 'Images[];\n')
1920 StringH
.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info
.Module
.BaseName
)
1922 # typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
1923 # EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
1924 # UINT32 ImageInfoOffset;
1925 # UINT32 PaletteInfoOffset;
1926 # } EFI_HII_IMAGE_PACKAGE_HDR;
1932 # } EFI_HII_PACKAGE_HEADER;
1934 # typedef struct _EFI_HII_IMAGE_BLOCK {
1936 # UINT8 BlockBody[];
1937 # } EFI_HII_IMAGE_BLOCK;
1939 def BmpImageDecoder(File
, Buffer
, PaletteIndex
, TransParent
):
1940 ImageType
, = struct
.unpack('2s', Buffer
[0:2])
1941 if ImageType
!= 'BM': # BMP file type is 'BM'
1942 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard BMP file." % File
.Path
)
1943 BMP_IMAGE_HEADER
= collections
.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])
1944 BMP_IMAGE_HEADER_STRUCT
= struct
.Struct('IHHIIIIHHIIIIII')
1945 BmpHeader
= BMP_IMAGE_HEADER
._make
(BMP_IMAGE_HEADER_STRUCT
.unpack_from(Buffer
[2:]))
1947 # Doesn't support compress.
1949 if BmpHeader
.biCompression
!= 0:
1950 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The compress BMP file %s is not support." % File
.Path
)
1952 # The Width and Height is UINT16 type in Image Package
1953 if BmpHeader
.biWidth
> 0xFFFF:
1954 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Width is exceed 0xFFFF." % File
.Path
)
1955 if BmpHeader
.biHeight
> 0xFFFF:
1956 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Height is exceed 0xFFFF." % File
.Path
)
1958 PaletteBuffer
= pack('x')
1959 if BmpHeader
.biBitCount
== 1:
1961 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS
)
1963 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT
)
1964 ImageBuffer
+= pack('B', PaletteIndex
)
1965 Width
= (BmpHeader
.biWidth
+ 7)/8
1966 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1967 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1968 elif BmpHeader
.biBitCount
== 4:
1970 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS
)
1972 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT
)
1973 ImageBuffer
+= pack('B', PaletteIndex
)
1974 Width
= (BmpHeader
.biWidth
+ 1)/2
1975 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1976 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1977 elif BmpHeader
.biBitCount
== 8:
1979 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS
)
1981 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT
)
1982 ImageBuffer
+= pack('B', PaletteIndex
)
1983 Width
= BmpHeader
.biWidth
1984 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1985 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1986 elif BmpHeader
.biBitCount
== 24:
1988 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS
)
1990 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT
)
1991 Width
= BmpHeader
.biWidth
* 3
1993 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData
="[%s]" % str(File
.Path
))
1995 ImageBuffer
+= pack('H', BmpHeader
.biWidth
)
1996 ImageBuffer
+= pack('H', BmpHeader
.biHeight
)
1997 Start
= BmpHeader
.bfOffBits
1998 End
= BmpHeader
.bfSize
- 1
1999 for Height
in range(0, BmpHeader
.biHeight
):
2001 Start
= End
+ (Width
% 4) - 4 - Width
2004 ImageBuffer
+= Buffer
[Start
+ 1 : Start
+ Width
+ 1]
2007 # handle the Palette info, BMP use 4 bytes for R, G, B and Reserved info while EFI_HII_RGB_PIXEL only have the R, G, B info
2008 if PaletteBuffer
and len(PaletteBuffer
) > 1:
2009 PaletteTemp
= pack('x')
2010 for Index
in range(0, len(PaletteBuffer
)):
2013 PaletteTemp
+= PaletteBuffer
[Index
]
2014 PaletteBuffer
= PaletteTemp
[1:]
2015 return ImageBuffer
, PaletteBuffer
2017 ## Create common code
2019 # @param Info The ModuleAutoGen object
2020 # @param AutoGenC The TemplateString object for C code
2021 # @param AutoGenH The TemplateString object for header file
2023 def CreateHeaderCode(Info
, AutoGenC
, AutoGenH
):
2025 AutoGenH
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.h'}))
2026 # header file Prologue
2027 AutoGenH
.Append(gAutoGenHPrologueString
.Replace({'File':'AUTOGENH','Guid':Info
.Guid
.replace('-','_')}))
2028 AutoGenH
.Append(gAutoGenHCppPrologueString
)
2029 if Info
.AutoGenVersion
>= 0x00010005:
2030 # header files includes
2031 AutoGenH
.Append("#include <%s>\n" % gBasicHeaderFile
)
2032 if Info
.ModuleType
in gModuleTypeHeaderFile \
2033 and gModuleTypeHeaderFile
[Info
.ModuleType
][0] != gBasicHeaderFile
:
2034 AutoGenH
.Append("#include <%s>\n" % gModuleTypeHeaderFile
[Info
.ModuleType
][0])
2036 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
2037 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
2039 if 'PcdLib' in Info
.Module
.LibraryClasses
or Info
.Module
.Pcds
:
2040 AutoGenH
.Append("#include <Library/PcdLib.h>\n")
2042 AutoGenH
.Append('\nextern GUID gEfiCallerIdGuid;')
2043 AutoGenH
.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
2048 AutoGenH
.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info
.Guid
))
2053 AutoGenC
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.c'}))
2054 if Info
.AutoGenVersion
>= 0x00010005:
2055 # C file header files includes
2056 if Info
.ModuleType
in gModuleTypeHeaderFile
:
2057 for Inc
in gModuleTypeHeaderFile
[Info
.ModuleType
]:
2058 AutoGenC
.Append("#include <%s>\n" % Inc
)
2060 AutoGenC
.Append("#include <%s>\n" % gBasicHeaderFile
)
2063 # Publish the CallerId Guid
2065 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info
.Guid
))
2066 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info
.Name
)
2068 ## Create common code for header file
2070 # @param Info The ModuleAutoGen object
2071 # @param AutoGenC The TemplateString object for C code
2072 # @param AutoGenH The TemplateString object for header file
2074 def CreateFooterCode(Info
, AutoGenC
, AutoGenH
):
2075 AutoGenH
.Append(gAutoGenHEpilogueString
)
2077 ## Create code for a module
2079 # @param Info The ModuleAutoGen object
2080 # @param AutoGenC The TemplateString object for C code
2081 # @param AutoGenH The TemplateString object for header file
2082 # @param StringH The TemplateString object for header file
2083 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
2084 # @param UniGenBinBuffer Buffer to store uni string package data
2085 # @param StringIdf The TemplateString object for header file
2086 # @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
2087 # @param IdfGenBinBuffer Buffer to store Idf string package data
2089 def CreateCode(Info
, AutoGenC
, AutoGenH
, StringH
, UniGenCFlag
, UniGenBinBuffer
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
):
2090 CreateHeaderCode(Info
, AutoGenC
, AutoGenH
)
2092 if Info
.AutoGenVersion
>= 0x00010005:
2093 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2094 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2095 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2096 CreatePcdCode(Info
, AutoGenC
, AutoGenH
)
2097 CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
)
2098 CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
)
2099 CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
)
2100 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
)
2102 if Info
.UnicodeFileList
:
2103 FileName
= "%sStrDefs.h" % Info
.Name
2104 StringH
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2105 StringH
.Append(gAutoGenHPrologueString
.Replace({'File':'STRDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2106 CreateUnicodeStringCode(Info
, AutoGenC
, StringH
, UniGenCFlag
, UniGenBinBuffer
)
2109 for Guid
in Info
.Module
.Guids
:
2110 if Guid
in Info
.Module
.GetGuidsUsedByPcd():
2112 GuidMacros
.append('#define %s %s' % (Guid
, Info
.Module
.Guids
[Guid
]))
2113 for Guid
, Value
in Info
.Module
.Protocols
.items() + Info
.Module
.Ppis
.items():
2114 GuidMacros
.append('#define %s %s' % (Guid
, Value
))
2115 # supports FixedAtBuild usage in VFR file
2116 if Info
.VfrFileList
and Info
.ModulePcdList
:
2117 GuidMacros
.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))
2118 GuidMacros
.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))
2119 GuidMacros
.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))
2120 GuidMacros
.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))
2121 GuidMacros
.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))
2122 for Pcd
in Info
.ModulePcdList
:
2123 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
2124 TokenCName
= Pcd
.TokenCName
2125 Value
= Pcd
.DefaultValue
2126 if Pcd
.DatumType
== 'BOOLEAN':
2127 BoolValue
= Value
.upper()
2128 if BoolValue
== 'TRUE':
2130 elif BoolValue
== 'FALSE':
2132 for PcdItem
in GlobalData
.MixedPcd
:
2133 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2134 TokenCName
= PcdItem
[0]
2136 GuidMacros
.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName
, Value
))
2138 if Info
.IdfFileList
:
2139 GuidMacros
.append('#include "%sImgDefs.h"' % Info
.Name
)
2142 StringH
.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros
))
2144 StringH
.Append("\n#endif\n")
2145 AutoGenH
.Append('#include "%s"\n' % FileName
)
2147 if Info
.IdfFileList
:
2148 FileName
= "%sImgDefs.h" % Info
.Name
2149 StringIdf
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2150 StringIdf
.Append(gAutoGenHPrologueString
.Replace({'File':'IMAGEDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2151 CreateIdfFileCode(Info
, AutoGenC
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
)
2153 StringIdf
.Append("\n#endif\n")
2154 AutoGenH
.Append('#include "%s"\n' % FileName
)
2156 CreateFooterCode(Info
, AutoGenC
, AutoGenH
)
2158 # no generation of AutoGen.c for Edk modules without unicode file
2159 if Info
.AutoGenVersion
< 0x00010005 and len(Info
.UnicodeFileList
) == 0:
2160 AutoGenC
.String
= ''
2162 ## Create the code file
2164 # @param FilePath The path of code file
2165 # @param Content The content of code file
2166 # @param IsBinaryFile The flag indicating if the file is binary file or not
2168 # @retval True If file content is changed or file doesn't exist
2169 # @retval False If the file exists and the content is not changed
2171 def Generate(FilePath
, Content
, IsBinaryFile
):
2172 return SaveFileOnChange(FilePath
, Content
, IsBinaryFile
)