2 # Routines for generating AutoGen.h and AutoGen.c
4 # Copyright (c) 2007 - 2018, 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
= {TAB_UINT8
:'8',TAB_UINT16
:'16',TAB_UINT32
:'32',TAB_UINT64
:'64','BOOLEAN':'BOOLEAN',TAB_VOID
:'8'}
52 gDatumSizeStringDatabaseH
= {TAB_UINT8
:'8',TAB_UINT16
:'16',TAB_UINT32
:'32',TAB_UINT64
:'64','BOOLEAN':'BOOL',TAB_VOID
:'PTR'}
53 gDatumSizeStringDatabaseLib
= {TAB_UINT8
:'8',TAB_UINT16
:'16',TAB_UINT32
:'32',TAB_UINT64
:'64','BOOLEAN':'Bool',TAB_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.
814 TokenCNameList
= set()
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
.add(TokenCName
)
839 TokenCNameList
= set()
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
.add(TokenCName
)
872 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
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
== TAB_UINT64
:
884 if Pcd
.DatumType
== TAB_UINT32
:
886 if Pcd
.DatumType
== TAB_UINT16
:
888 if Pcd
.DatumType
== TAB_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 PatchPcdMaxSizeVariable
= '_gPcd_BinaryPatch_MaxSize_' + TokenCName
918 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
919 FixedPcdSizeVariableName
= '_gPcd_FixedAtBuild_Size_' + TokenCName
921 if Pcd
.PcdValueFromComm
:
922 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
924 if Pcd
.Type
in gDynamicExPcd
:
925 TokenNumber
= int(Pcd
.TokenValue
, 0)
926 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
927 # different Guids but same TokenCName
928 PcdExTokenName
= '_PCD_TOKEN_' + Pcd
.TokenSpaceGuidCName
+ '_' + TokenCName
929 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
931 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
932 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
933 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
934 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
935 # report warning message notify the PI that they are attempting to build a module
936 # that must be included in a flash image in order to be functional. These Dynamic PCD
937 # will not be added into the Database unless it is used by other modules that are
938 # included in the FDF file.
939 # In this case, just assign an invalid token number to make it pass build.
940 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
943 EdkLogger
.error("build", AUTOGEN_ERROR
,
944 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
945 ExtraData
="[%s]" % str(Info
))
947 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
948 AutoGenH
.Append('\n#define %s %dU\n' % (PcdTokenName
, TokenNumber
))
950 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "Creating code for " + TokenCName
+ "." + Pcd
.TokenSpaceGuidCName
)
951 if Pcd
.Type
not in gItemTypeStringDatabase
:
952 EdkLogger
.error("build", AUTOGEN_ERROR
,
953 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
954 ExtraData
="[%s]" % str(Info
))
956 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
[TAB_VOID
]
957 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
[TAB_VOID
]
958 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_' + TokenCName
959 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_' + TokenCName
960 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_S_' + TokenCName
961 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
963 if Pcd
.Type
in gDynamicExPcd
:
965 PcdList
= Info
.LibraryPcdList
967 PcdList
= Info
.ModulePcdList
969 for PcdModule
in PcdList
:
970 if PcdModule
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== PcdModule
.TokenCName
:
972 # get out early once we found > 1...
973 if PcdExCNameTest
> 1:
975 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
976 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
977 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
978 if PcdExCNameTest
> 1:
979 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')
980 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
981 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
982 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
983 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
984 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
985 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
987 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
988 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
990 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
991 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
992 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
993 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
994 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
995 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
997 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
998 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
999 elif Pcd
.Type
in gDynamicPcd
:
1001 for PcdModule
in Info
.LibraryPcdList
+ Info
.ModulePcdList
:
1002 if PcdModule
.Type
in gDynamicPcd
and Pcd
.TokenCName
== PcdModule
.TokenCName
:
1004 # get out early once we found > 1...
1005 if PcdCNameTest
> 1:
1007 if PcdCNameTest
> 1:
1008 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
))
1010 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1011 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1012 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1013 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1014 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1016 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1017 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1019 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1021 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1025 Value
= Pcd
.DefaultValue
1029 if Pcd
.DatumType
== 'BOOLEAN':
1030 BoolValue
= Value
.upper()
1031 if BoolValue
== 'TRUE' or BoolValue
== '1':
1033 elif BoolValue
== 'FALSE' or BoolValue
== '0':
1036 if Pcd
.DatumType
in TAB_PCD_CLEAN_NUMERIC_TYPES
:
1038 if Value
.upper().endswith('L'):
1040 ValueNumber
= int (Value
, 0)
1042 EdkLogger
.error("build", AUTOGEN_ERROR
,
1043 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1044 ExtraData
="[%s]" % str(Info
))
1045 if Pcd
.DatumType
== TAB_UINT64
:
1047 EdkLogger
.error("build", AUTOGEN_ERROR
,
1048 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1049 ExtraData
="[%s]" % str(Info
))
1050 elif ValueNumber
>= 0x10000000000000000:
1051 EdkLogger
.error("build", AUTOGEN_ERROR
,
1052 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1053 ExtraData
="[%s]" % str(Info
))
1054 if not Value
.endswith('ULL'):
1056 elif Pcd
.DatumType
== TAB_UINT32
:
1058 EdkLogger
.error("build", AUTOGEN_ERROR
,
1059 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1060 ExtraData
="[%s]" % str(Info
))
1061 elif ValueNumber
>= 0x100000000:
1062 EdkLogger
.error("build", AUTOGEN_ERROR
,
1063 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1064 ExtraData
="[%s]" % str(Info
))
1065 if not Value
.endswith('U'):
1067 elif Pcd
.DatumType
== TAB_UINT16
:
1069 EdkLogger
.error("build", AUTOGEN_ERROR
,
1070 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1071 ExtraData
="[%s]" % str(Info
))
1072 elif ValueNumber
>= 0x10000:
1073 EdkLogger
.error("build", AUTOGEN_ERROR
,
1074 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1075 ExtraData
="[%s]" % str(Info
))
1076 if not Value
.endswith('U'):
1078 elif Pcd
.DatumType
== TAB_UINT8
:
1080 EdkLogger
.error("build", AUTOGEN_ERROR
,
1081 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1082 ExtraData
="[%s]" % str(Info
))
1083 elif ValueNumber
>= 0x100:
1084 EdkLogger
.error("build", AUTOGEN_ERROR
,
1085 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1086 ExtraData
="[%s]" % str(Info
))
1087 if not Value
.endswith('U'):
1089 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1090 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
1091 EdkLogger
.error("build", AUTOGEN_ERROR
,
1092 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1093 ExtraData
="[%s]" % str(Info
))
1095 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1101 Value
= Value
.lstrip('L') #.strip('"')
1102 Value
= eval(Value
) # translate escape character
1104 for Index
in range(0,len(Value
)):
1106 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ', '
1108 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ', '
1110 ArraySize
= ArraySize
/ 2;
1112 if ArraySize
< (len(Value
) + 1):
1113 if Pcd
.MaxSizeUserSet
:
1114 EdkLogger
.error("build", AUTOGEN_ERROR
,
1115 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1116 ExtraData
="[%s]" % str(Info
))
1118 ArraySize
= GetPcdSize(Pcd
)
1120 ArraySize
= ArraySize
/ 2
1121 Value
= NewValue
+ '0 }'
1122 Array
= '[%d]' % ArraySize
1124 # skip casting for fixed at build since it breaks ARM assembly.
1125 # Long term we need PCD macros that work in assembly
1127 elif Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
and Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES_VOID
:
1128 Value
= "((%s)%s)" % (Pcd
.DatumType
, Value
)
1130 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES_VOID
:
1131 # handle structure PCD
1132 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
1133 EdkLogger
.error("build", AUTOGEN_ERROR
,
1134 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1135 ExtraData
="[%s]" % str(Info
))
1137 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1138 Array
= '[%d]' % ArraySize
1140 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1141 PcdValueName
= '_PCD_PATCHABLE_VALUE_' + TokenCName
1143 PcdValueName
= '_PCD_VALUE_' + TokenCName
1145 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1147 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1149 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1151 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1152 AutoGenH
.Append('extern %s UINT16 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1154 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1155 AutoGenH
.Append('extern %s UINT8 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1156 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1158 PcdDataSize
= GetPcdSize(Pcd
)
1159 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
1160 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1161 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1162 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName
,PcdDataSize
))
1163 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1164 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1165 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1166 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1167 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1168 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable
,Pcd
.MaxDatumSize
))
1169 elif Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1170 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1171 AutoGenC
.Append('volatile %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1172 AutoGenH
.Append('extern volatile %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1173 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1175 PcdDataSize
= GetPcdSize(Pcd
)
1176 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1178 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1179 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1180 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1182 PcdDataSize
= GetPcdSize(Pcd
)
1183 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1184 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1186 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1187 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1188 AutoGenH
.Append('extern %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1189 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1191 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1192 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1193 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
))
1194 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
))
1196 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1197 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName
, PcdVariableName
))
1199 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1201 ## Create code for library module PCDs
1203 # @param Info The ModuleAutoGen object
1204 # @param AutoGenC The TemplateString object for C code
1205 # @param AutoGenH The TemplateString object for header file
1206 # @param Pcd The PCD object
1208 def CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
1209 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
1210 TokenSpaceGuidCName
= Pcd
.TokenSpaceGuidCName
1211 TokenCName
= Pcd
.TokenCName
1212 for PcdItem
in GlobalData
.MixedPcd
:
1213 if (TokenCName
, TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1214 TokenCName
= PcdItem
[0]
1216 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
1217 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
1218 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
1219 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
1220 PatchPcdMaxSizeVariable
= '_gPcd_BinaryPatch_MaxSize_' + TokenCName
1221 FixedPcdSizeVariableName
= '_gPcd_FixedAtBuild_Size_' + TokenCName
1223 if Pcd
.PcdValueFromComm
:
1224 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
1228 if Pcd
.Type
in gDynamicExPcd
:
1229 TokenNumber
= int(Pcd
.TokenValue
, 0)
1231 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
1232 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1233 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1234 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1235 # report warning message notify the PI that they are attempting to build a module
1236 # that must be included in a flash image in order to be functional. These Dynamic PCD
1237 # will not be added into the Database unless it is used by other modules that are
1238 # included in the FDF file.
1239 # In this case, just assign an invalid token number to make it pass build.
1240 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
1243 EdkLogger
.error("build", AUTOGEN_ERROR
,
1244 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1245 ExtraData
="[%s]" % str(Info
))
1247 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
1249 if Pcd
.Type
not in gItemTypeStringDatabase
:
1250 EdkLogger
.error("build", AUTOGEN_ERROR
,
1251 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1252 ExtraData
="[%s]" % str(Info
))
1254 DatumType
= Pcd
.DatumType
1255 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
[TAB_VOID
]
1256 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
[TAB_VOID
]
1257 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_' + TokenCName
1258 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_' + TokenCName
1259 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[TAB_VOID
] + '_S_' + TokenCName
1260 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1264 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1265 if Pcd
.DefaultValue
[0]== '{':
1268 PcdItemType
= Pcd
.Type
1269 if PcdItemType
in gDynamicExPcd
:
1270 PcdExTokenName
= '_PCD_TOKEN_' + TokenSpaceGuidCName
+ '_' + TokenCName
1271 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
1274 PcdList
= Info
.LibraryPcdList
1276 PcdList
= Info
.ModulePcdList
1278 for PcdModule
in PcdList
:
1279 if PcdModule
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== PcdModule
.TokenCName
:
1281 # get out early once we found > 1...
1282 if PcdExCNameTest
> 1:
1284 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1285 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1286 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1287 if PcdExCNameTest
> 1:
1288 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')
1289 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1290 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1291 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1292 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1293 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1294 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1296 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1297 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1299 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1300 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1301 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1302 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1303 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1304 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1306 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1307 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1309 AutoGenH
.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName
, TokenNumber
))
1310 if PcdItemType
in gDynamicPcd
:
1313 PcdList
.extend(Info
.LibraryPcdList
)
1314 PcdList
.extend(Info
.ModulePcdList
)
1315 for PcdModule
in PcdList
:
1316 if PcdModule
.Type
in gDynamicPcd
:
1317 PcdCNameList
.append(PcdModule
.TokenCName
)
1318 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1319 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
))
1321 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1322 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1323 if DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1324 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1325 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1327 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1328 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1329 if PcdItemType
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1330 GetModeMaxSizeName
= '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName
1331 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[TAB_PCDS_PATCHABLE_IN_MODULE
] + '_' + TokenCName
1332 if DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1333 if DatumType
== TAB_VOID
and Array
== '[]':
1334 DatumType
= [TAB_UINT8
, TAB_UINT16
][Pcd
.DefaultValue
[0] == 'L']
1336 DatumType
= TAB_UINT8
1337 AutoGenH
.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1339 AutoGenH
.Append('extern volatile %s %s%s;\n' % (DatumType
, PcdVariableName
, Array
))
1340 AutoGenH
.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName
, Type
, TokenCName
))
1341 PcdDataSize
= GetPcdSize(Pcd
)
1342 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1343 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, TokenCName
, PatchPcdSizeVariableName
, PatchPcdMaxSizeVariable
))
1344 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, TokenCName
, PatchPcdSizeVariableName
, PatchPcdMaxSizeVariable
))
1345 AutoGenH
.Append('#define %s %s\n' % (GetModeMaxSizeName
, PatchPcdMaxSizeVariable
))
1346 AutoGenH
.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable
)
1348 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1349 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName
, PcdVariableName
))
1350 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1352 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1353 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1355 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
or PcdItemType
== TAB_PCDS_FEATURE_FLAG
:
1356 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1357 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1358 if DatumType
== TAB_VOID
and Array
== '[]':
1359 DatumType
= [TAB_UINT8
, TAB_UINT16
][Pcd
.DefaultValue
[0] == 'L']
1360 if DatumType
not in TAB_PCD_NUMERIC_TYPES_VOID
:
1361 DatumType
= TAB_UINT8
1362 AutoGenH
.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1363 AutoGenH
.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName
, Type
, TokenCName
))
1364 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1366 ConstFixedPcd
= False
1367 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
and (key
in Info
.ConstPcd
or (Info
.IsLibrary
and not Info
._ReferenceModules
)):
1368 ConstFixedPcd
= True
1369 if key
in Info
.ConstPcd
:
1370 Pcd
.DefaultValue
= Info
.ConstPcd
[key
]
1371 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1372 AutoGenH
.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName
, Type
, PcdVariableName
))
1374 AutoGenH
.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName
, Pcd
.DefaultValue
))
1375 PcdDataSize
= GetPcdSize(Pcd
)
1376 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
:
1377 if Pcd
.DatumType
not in TAB_PCD_NUMERIC_TYPES
:
1379 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1380 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1382 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixedPcdSizeVariableName
))
1383 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
,FixedPcdSizeVariableName
))
1384 AutoGenH
.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName
)
1386 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1387 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1389 ## Create code for library constructor
1391 # @param Info The ModuleAutoGen object
1392 # @param AutoGenC The TemplateString object for C code
1393 # @param AutoGenH The TemplateString object for header file
1395 def CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
):
1397 # Library Constructors
1399 ConstructorPrototypeString
= TemplateString()
1400 ConstructorCallingString
= TemplateString()
1402 DependentLibraryList
= [Info
.Module
]
1404 DependentLibraryList
= Info
.DependentLibraryList
1405 for Lib
in DependentLibraryList
:
1406 if len(Lib
.ConstructorList
) <= 0:
1408 Dict
= {'Function':Lib
.ConstructorList
}
1409 if Lib
.ModuleType
in ['BASE', 'SEC']:
1410 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1411 ConstructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1412 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1413 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1414 ConstructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1415 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1416 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1417 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1418 ConstructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1419 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1420 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1421 ConstructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1423 if str(ConstructorPrototypeString
) == '':
1424 ConstructorPrototypeList
= []
1426 ConstructorPrototypeList
= [str(ConstructorPrototypeString
)]
1427 if str(ConstructorCallingString
) == '':
1428 ConstructorCallingList
= []
1430 ConstructorCallingList
= [str(ConstructorCallingString
)]
1433 'Type' : 'Constructor',
1434 'FunctionPrototype' : ConstructorPrototypeList
,
1435 'FunctionCall' : ConstructorCallingList
1438 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1440 if Info
.ModuleType
in ['BASE', 'SEC']:
1441 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1442 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1443 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1444 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1445 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1446 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1447 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1448 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1450 ## Create code for library destructor
1452 # @param Info The ModuleAutoGen object
1453 # @param AutoGenC The TemplateString object for C code
1454 # @param AutoGenH The TemplateString object for header file
1456 def CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
):
1458 # Library Destructors
1460 DestructorPrototypeString
= TemplateString()
1461 DestructorCallingString
= TemplateString()
1463 DependentLibraryList
= [Info
.Module
]
1465 DependentLibraryList
= Info
.DependentLibraryList
1466 for Index
in range(len(DependentLibraryList
)-1, -1, -1):
1467 Lib
= DependentLibraryList
[Index
]
1468 if len(Lib
.DestructorList
) <= 0:
1470 Dict
= {'Function':Lib
.DestructorList
}
1471 if Lib
.ModuleType
in ['BASE', 'SEC']:
1472 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1473 DestructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1474 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1475 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1476 DestructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1477 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1478 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1479 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1480 DestructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1481 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1482 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1483 DestructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1485 if str(DestructorPrototypeString
) == '':
1486 DestructorPrototypeList
= []
1488 DestructorPrototypeList
= [str(DestructorPrototypeString
)]
1489 if str(DestructorCallingString
) == '':
1490 DestructorCallingList
= []
1492 DestructorCallingList
= [str(DestructorCallingString
)]
1495 'Type' : 'Destructor',
1496 'FunctionPrototype' : DestructorPrototypeList
,
1497 'FunctionCall' : DestructorCallingList
1500 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1502 if Info
.ModuleType
in ['BASE', 'SEC']:
1503 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1504 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1505 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1506 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1507 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1508 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1509 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1510 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1513 ## Create code for ModuleEntryPoint
1515 # @param Info The ModuleAutoGen object
1516 # @param AutoGenC The TemplateString object for C code
1517 # @param AutoGenH The TemplateString object for header file
1519 def CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
):
1520 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1523 # Module Entry Points
1525 NumEntryPoints
= len(Info
.Module
.ModuleEntryPointList
)
1526 if 'PI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1527 PiSpecVersion
= Info
.Module
.Specification
['PI_SPECIFICATION_VERSION']
1529 PiSpecVersion
= '0x00000000'
1530 if 'UEFI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1531 UefiSpecVersion
= Info
.Module
.Specification
['UEFI_SPECIFICATION_VERSION']
1533 UefiSpecVersion
= '0x00000000'
1535 'Function' : Info
.Module
.ModuleEntryPointList
,
1536 'PiSpecVersion' : PiSpecVersion
+ 'U',
1537 'UefiSpecVersion': UefiSpecVersion
+ 'U'
1540 if Info
.ModuleType
in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE', 'MM_CORE_STANDALONE']:
1541 if Info
.SourceFileList
:
1542 if NumEntryPoints
!= 1:
1546 '%s must have exactly one entry point' % Info
.ModuleType
,
1548 ExtraData
= ", ".join(Info
.Module
.ModuleEntryPointList
)
1550 if Info
.ModuleType
== 'PEI_CORE':
1551 AutoGenC
.Append(gPeiCoreEntryPointString
.Replace(Dict
))
1552 AutoGenH
.Append(gPeiCoreEntryPointPrototype
.Replace(Dict
))
1553 elif Info
.ModuleType
== 'DXE_CORE':
1554 AutoGenC
.Append(gDxeCoreEntryPointString
.Replace(Dict
))
1555 AutoGenH
.Append(gDxeCoreEntryPointPrototype
.Replace(Dict
))
1556 elif Info
.ModuleType
== 'SMM_CORE':
1557 AutoGenC
.Append(gSmmCoreEntryPointString
.Replace(Dict
))
1558 AutoGenH
.Append(gSmmCoreEntryPointPrototype
.Replace(Dict
))
1559 elif Info
.ModuleType
== 'MM_CORE_STANDALONE':
1560 AutoGenC
.Append(gMmCoreStandaloneEntryPointString
.Replace(Dict
))
1561 AutoGenH
.Append(gMmCoreStandaloneEntryPointPrototype
.Replace(Dict
))
1562 elif Info
.ModuleType
== 'PEIM':
1563 if NumEntryPoints
< 2:
1564 AutoGenC
.Append(gPeimEntryPointString
[NumEntryPoints
].Replace(Dict
))
1566 AutoGenC
.Append(gPeimEntryPointString
[2].Replace(Dict
))
1567 AutoGenH
.Append(gPeimEntryPointPrototype
.Replace(Dict
))
1568 elif Info
.ModuleType
in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1569 if NumEntryPoints
< 2:
1570 AutoGenC
.Append(gUefiDriverEntryPointString
[NumEntryPoints
].Replace(Dict
))
1572 AutoGenC
.Append(gUefiDriverEntryPointString
[2].Replace(Dict
))
1573 AutoGenH
.Append(gUefiDriverEntryPointPrototype
.Replace(Dict
))
1574 elif Info
.ModuleType
== 'DXE_SMM_DRIVER':
1575 if NumEntryPoints
== 0:
1576 AutoGenC
.Append(gDxeSmmEntryPointString
[0].Replace(Dict
))
1578 AutoGenC
.Append(gDxeSmmEntryPointString
[1].Replace(Dict
))
1579 AutoGenH
.Append(gDxeSmmEntryPointPrototype
.Replace(Dict
))
1580 elif Info
.ModuleType
== 'MM_STANDALONE':
1581 if NumEntryPoints
< 2:
1582 AutoGenC
.Append(gMmStandaloneEntryPointString
[NumEntryPoints
].Replace(Dict
))
1584 AutoGenC
.Append(gMmStandaloneEntryPointString
[2].Replace(Dict
))
1585 AutoGenH
.Append(gMmStandaloneEntryPointPrototype
.Replace(Dict
))
1586 elif Info
.ModuleType
== 'UEFI_APPLICATION':
1587 if NumEntryPoints
< 2:
1588 AutoGenC
.Append(gUefiApplicationEntryPointString
[NumEntryPoints
].Replace(Dict
))
1590 AutoGenC
.Append(gUefiApplicationEntryPointString
[2].Replace(Dict
))
1591 AutoGenH
.Append(gUefiApplicationEntryPointPrototype
.Replace(Dict
))
1593 ## Create code for ModuleUnloadImage
1595 # @param Info The ModuleAutoGen object
1596 # @param AutoGenC The TemplateString object for C code
1597 # @param AutoGenH The TemplateString object for header file
1599 def CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
):
1600 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1603 # Unload Image Handlers
1605 NumUnloadImage
= len(Info
.Module
.ModuleUnloadImageList
)
1606 Dict
= {'Count':str(NumUnloadImage
) + 'U', 'Function':Info
.Module
.ModuleUnloadImageList
}
1607 if NumUnloadImage
< 2:
1608 AutoGenC
.Append(gUefiUnloadImageString
[NumUnloadImage
].Replace(Dict
))
1610 AutoGenC
.Append(gUefiUnloadImageString
[2].Replace(Dict
))
1611 AutoGenH
.Append(gUefiUnloadImagePrototype
.Replace(Dict
))
1613 ## Create code for GUID
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 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1620 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1623 GuidType
= "EFI_GUID"
1626 if not Info
.IsLibrary
:
1627 AutoGenC
.Append("\n// Guids\n")
1628 AutoGenH
.Append("\n// Guids\n")
1632 for Key
in Info
.GuidList
:
1633 if not Info
.IsLibrary
:
1634 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.GuidList
[Key
]))
1635 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1637 ## Create code for protocol
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 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1644 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1647 GuidType
= "EFI_GUID"
1649 if Info
.ProtocolList
:
1650 if not Info
.IsLibrary
:
1651 AutoGenC
.Append("\n// Protocols\n")
1652 AutoGenH
.Append("\n// Protocols\n")
1656 for Key
in Info
.ProtocolList
:
1657 if not Info
.IsLibrary
:
1658 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.ProtocolList
[Key
]))
1659 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1661 ## Create code for PPI
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 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1668 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1671 GuidType
= "EFI_GUID"
1674 if not Info
.IsLibrary
:
1675 AutoGenC
.Append("\n// PPIs\n")
1676 AutoGenH
.Append("\n// PPIs\n")
1680 for Key
in Info
.PpiList
:
1681 if not Info
.IsLibrary
:
1682 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.PpiList
[Key
]))
1683 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1685 ## Create code for PCD
1687 # @param Info The ModuleAutoGen object
1688 # @param AutoGenC The TemplateString object for C code
1689 # @param AutoGenH The TemplateString object for header file
1691 def CreatePcdCode(Info
, AutoGenC
, AutoGenH
):
1693 # Collect Token Space GUIDs used by DynamicEc PCDs
1695 for Pcd
in Info
.ModulePcdList
:
1696 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenSpaceGuidCName
not in TokenSpaceList
:
1697 TokenSpaceList
+= [Pcd
.TokenSpaceGuidCName
]
1699 SkuMgr
= Info
.Workspace
.Platform
.SkuIdMgr
1700 AutoGenH
.Append("\n// Definition of SkuId Array\n")
1701 AutoGenH
.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
1702 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1704 AutoGenH
.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1705 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1708 GuidType
= "EFI_GUID"
1709 for Item
in TokenSpaceList
:
1710 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Item
))
1713 if Info
.ModulePcdList
:
1714 AutoGenH
.Append("\n// PCD definitions\n")
1715 for Pcd
in Info
.ModulePcdList
:
1716 CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1717 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1719 AutoGenC
.Append("\n// Definition of SkuId Array\n")
1720 AutoGenC
.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr
.DumpSkuIdArrary())
1721 if Info
.ModulePcdList
:
1722 AutoGenH
.Append("\n// Definition of PCDs used in this module\n")
1723 AutoGenC
.Append("\n// Definition of PCDs used in this module\n")
1724 for Pcd
in Info
.ModulePcdList
:
1725 CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1726 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1727 if Info
.LibraryPcdList
:
1728 AutoGenH
.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1729 AutoGenC
.Append("\n// Definition of PCDs used in libraries\n")
1730 for Pcd
in Info
.LibraryPcdList
:
1731 CreateModulePcdCode(Info
, AutoGenC
, AutoGenC
, Pcd
)
1732 CreatePcdDatabaseCode(Info
, AutoGenC
, AutoGenH
)
1734 ## Create code for unicode string definition
1736 # @param Info The ModuleAutoGen object
1737 # @param AutoGenC The TemplateString object for C code
1738 # @param AutoGenH The TemplateString object for header file
1739 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1740 # @param UniGenBinBuffer Buffer to store uni string package data
1742 def CreateUnicodeStringCode(Info
, AutoGenC
, AutoGenH
, UniGenCFlag
, UniGenBinBuffer
):
1743 WorkingDir
= os
.getcwd()
1744 os
.chdir(Info
.WorkspaceDir
)
1746 IncList
= [Info
.MetaFile
.Dir
]
1747 # Get all files under [Sources] section in inf file for EDK-II module
1749 SrcList
= [F
for F
in Info
.SourceFileList
]
1750 if Info
.AutoGenVersion
< 0x00010005:
1752 # Get all files under the module directory for EDK-I module
1754 os
.chdir(Info
.MetaFile
.Dir
)
1755 for Root
, Dirs
, Files
in os
.walk("."):
1761 File
= PathClass(os
.path
.join(Root
, File
), Info
.MetaFile
.Dir
)
1764 SrcList
.append(File
)
1767 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-c') > -1:
1768 CompatibleMode
= True
1770 CompatibleMode
= False
1773 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1775 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-s') > -1:
1777 EdkLogger
.error("build", AUTOGEN_ERROR
,
1778 "-c and -s build options should be used exclusively",
1779 ExtraData
="[%s]" % str(Info
))
1784 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1786 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.RFCLanguages
]
1788 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.ISOLanguages
]
1789 Header
, Code
= GetStringFiles(Info
.UnicodeFileList
, SrcList
, IncList
, Info
.IncludePathList
, ['.uni', '.inf'], Info
.Name
, CompatibleMode
, ShellMode
, UniGenCFlag
, UniGenBinBuffer
, FilterInfo
)
1790 if CompatibleMode
or UniGenCFlag
:
1791 AutoGenC
.Append("\n//\n//Unicode String Pack Definition\n//\n")
1792 AutoGenC
.Append(Code
)
1793 AutoGenC
.Append("\n")
1794 AutoGenH
.Append("\n//\n//Unicode String ID\n//\n")
1795 AutoGenH
.Append(Header
)
1796 if CompatibleMode
or UniGenCFlag
:
1797 AutoGenH
.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info
.Name
)
1798 os
.chdir(WorkingDir
)
1800 def CreateIdfFileCode(Info
, AutoGenC
, StringH
, IdfGenCFlag
, IdfGenBinBuffer
):
1801 if len(Info
.IdfFileList
) > 0:
1802 ImageFiles
= IdfFileClassObject(sorted (Info
.IdfFileList
))
1803 if ImageFiles
.ImageFilesDict
:
1806 IncList
= [Info
.MetaFile
.Dir
]
1807 SrcList
= [F
for F
in Info
.SourceFileList
]
1808 SkipList
= ['.jpg', '.png', '.bmp', '.inf', '.idf']
1809 FileList
= GetFileList(SrcList
, IncList
, SkipList
)
1811 StringH
.Append("\n//\n//Image ID\n//\n")
1813 PaletteInfoOffset
= 0
1814 ImageBuffer
= pack('x')
1815 PaletteBuffer
= pack('x')
1819 for Idf
in ImageFiles
.ImageFilesDict
:
1820 if ImageFiles
.ImageFilesDict
[Idf
]:
1821 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1822 for sourcefile
in Info
.SourceFileList
:
1823 if FileObj
.FileName
== sourcefile
.File
:
1824 if not sourcefile
.Ext
.upper() in ['.PNG', '.BMP', '.JPG']:
1825 EdkLogger
.error("build", AUTOGEN_ERROR
, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj
.FileName
), ExtraData
="[%s]" % str(Info
))
1826 FileObj
.File
= sourcefile
1829 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
))
1831 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1832 ID
= FileObj
.ImageID
1834 if not os
.path
.exists(File
.Path
) or not os
.path
.isfile(File
.Path
):
1835 EdkLogger
.error("build", FILE_NOT_FOUND
, ExtraData
=File
.Path
)
1836 SearchImageID (FileObj
, FileList
)
1837 if FileObj
.Referenced
:
1838 if (ValueStartPtr
- len(DEFINE_STR
+ ID
)) <= 0:
1839 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' + DecToHexStr(Index
, 4) + '\n'
1841 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' * (ValueStartPtr
- len(DEFINE_STR
+ ID
)) + DecToHexStr(Index
, 4) + '\n'
1843 if File
not in FileDict
:
1844 FileDict
[File
] = Index
1846 DuplicateBlock
= pack('B', EFI_HII_IIBT_DUPLICATE
)
1847 DuplicateBlock
+= pack('H', FileDict
[File
])
1848 ImageBuffer
+= DuplicateBlock
1849 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1850 TempBufferList
= AscToHexList(DuplicateBlock
)
1851 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1852 StringH
.Append(Line
)
1856 TmpFile
= open(File
.Path
, 'rb')
1857 Buffer
= TmpFile
.read()
1859 if File
.Ext
.upper() == '.PNG':
1860 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_PNG
)
1861 TempBuffer
+= pack('I', len(Buffer
))
1862 TempBuffer
+= Buffer
1863 elif File
.Ext
.upper() == '.JPG':
1864 ImageType
, = struct
.unpack('4s', Buffer
[6:10])
1865 if ImageType
!= 'JFIF':
1866 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard JPG file." % File
.Path
)
1867 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_JPEG
)
1868 TempBuffer
+= pack('I', len(Buffer
))
1869 TempBuffer
+= Buffer
1870 elif File
.Ext
.upper() == '.BMP':
1871 TempBuffer
, TempPalette
= BmpImageDecoder(File
, Buffer
, PaletteIndex
, FileObj
.TransParent
)
1872 if len(TempPalette
) > 1:
1874 NewPalette
= pack('H', len(TempPalette
))
1875 NewPalette
+= TempPalette
1876 PaletteBuffer
+= NewPalette
1877 PaletteStr
= WriteLine(PaletteStr
, '// %s: %s: %s' % (DecToHexStr(PaletteIndex
- 1, 4), ID
, DecToHexStr(PaletteIndex
- 1, 4)))
1878 TempPaletteList
= AscToHexList(NewPalette
)
1879 PaletteStr
= WriteLine(PaletteStr
, CreateArrayItem(TempPaletteList
, 16) + '\n')
1880 ImageBuffer
+= TempBuffer
1881 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1882 TempBufferList
= AscToHexList(TempBuffer
)
1883 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1885 StringH
.Append(Line
)
1888 BufferStr
= WriteLine(BufferStr
, '// End of the Image Info')
1889 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END
, 2)) + '\n')
1890 ImageEnd
= pack('B', EFI_HII_IIBT_END
)
1891 ImageBuffer
+= ImageEnd
1893 if len(ImageBuffer
) > 1:
1894 ImageInfoOffset
= 12
1895 if len(PaletteBuffer
) > 1:
1896 PaletteInfoOffset
= 12 + len(ImageBuffer
) - 1 # -1 is for the first empty pad byte of ImageBuffer
1898 IMAGE_PACKAGE_HDR
= pack('=II', ImageInfoOffset
, PaletteInfoOffset
)
1899 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
1900 if len(PaletteBuffer
) > 1:
1901 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1 + 2 + len(PaletteBuffer
) - 1
1903 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1
1904 if PaletteIndex
> 1:
1905 PALETTE_INFO_HEADER
= pack('H', PaletteIndex
- 1)
1906 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
1907 Hex_Length
= '%06X' % PACKAGE_HEADER_Length
1908 if PACKAGE_HEADER_Length
> 0xFFFFFF:
1909 EdkLogger
.error("build", AUTOGEN_ERROR
, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData
="[%s]" % str(Info
))
1910 PACKAGE_HEADER
= pack('=HBB', int('0x' + Hex_Length
[2:], 16), int('0x' + Hex_Length
[0:2], 16), EFI_HII_PACKAGE_IMAGES
)
1912 IdfGenBinBuffer
.write(PACKAGE_HEADER
)
1913 IdfGenBinBuffer
.write(IMAGE_PACKAGE_HDR
)
1914 if len(ImageBuffer
) > 1 :
1915 IdfGenBinBuffer
.write(ImageBuffer
[1:])
1916 if PaletteIndex
> 1:
1917 IdfGenBinBuffer
.write(PALETTE_INFO_HEADER
)
1918 if len(PaletteBuffer
) > 1:
1919 IdfGenBinBuffer
.write(PaletteBuffer
[1:])
1922 TotalLength
= EFI_HII_ARRAY_SIZE_LENGTH
+ PACKAGE_HEADER_Length
1923 AutoGenC
.Append("\n//\n//Image Pack Definition\n//\n")
1924 AllStr
= WriteLine('', CHAR_ARRAY_DEFIN
+ ' ' + Info
.Module
.BaseName
+ 'Images' + '[] = {\n')
1925 AllStr
= WriteLine(AllStr
, '// STRGATHER_OUTPUT_HEADER')
1926 AllStr
= WriteLine(AllStr
, CreateArrayItem(DecToHexList(TotalLength
)) + '\n')
1927 AllStr
= WriteLine(AllStr
, '// Image PACKAGE HEADER\n')
1928 IMAGE_PACKAGE_HDR_List
= AscToHexList(PACKAGE_HEADER
)
1929 IMAGE_PACKAGE_HDR_List
+= AscToHexList(IMAGE_PACKAGE_HDR
)
1930 AllStr
= WriteLine(AllStr
, CreateArrayItem(IMAGE_PACKAGE_HDR_List
, 16) + '\n')
1931 AllStr
= WriteLine(AllStr
, '// Image DATA\n')
1933 AllStr
= WriteLine(AllStr
, BufferStr
)
1935 AllStr
= WriteLine(AllStr
, '// Palette Header\n')
1936 PALETTE_INFO_HEADER_List
= AscToHexList(PALETTE_INFO_HEADER
)
1937 AllStr
= WriteLine(AllStr
, CreateArrayItem(PALETTE_INFO_HEADER_List
, 16) + '\n')
1938 AllStr
= WriteLine(AllStr
, '// Palette Data\n')
1939 AllStr
= WriteLine(AllStr
, PaletteStr
)
1940 AllStr
= WriteLine(AllStr
, '};')
1941 AutoGenC
.Append(AllStr
)
1942 AutoGenC
.Append("\n")
1943 StringH
.Append('\nextern unsigned char ' + Info
.Module
.BaseName
+ 'Images[];\n')
1944 StringH
.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info
.Module
.BaseName
)
1946 # typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
1947 # EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
1948 # UINT32 ImageInfoOffset;
1949 # UINT32 PaletteInfoOffset;
1950 # } EFI_HII_IMAGE_PACKAGE_HDR;
1956 # } EFI_HII_PACKAGE_HEADER;
1958 # typedef struct _EFI_HII_IMAGE_BLOCK {
1960 # UINT8 BlockBody[];
1961 # } EFI_HII_IMAGE_BLOCK;
1963 def BmpImageDecoder(File
, Buffer
, PaletteIndex
, TransParent
):
1964 ImageType
, = struct
.unpack('2s', Buffer
[0:2])
1965 if ImageType
!= 'BM': # BMP file type is 'BM'
1966 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard BMP file." % File
.Path
)
1967 BMP_IMAGE_HEADER
= collections
.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])
1968 BMP_IMAGE_HEADER_STRUCT
= struct
.Struct('IHHIIIIHHIIIIII')
1969 BmpHeader
= BMP_IMAGE_HEADER
._make
(BMP_IMAGE_HEADER_STRUCT
.unpack_from(Buffer
[2:]))
1971 # Doesn't support compress.
1973 if BmpHeader
.biCompression
!= 0:
1974 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The compress BMP file %s is not support." % File
.Path
)
1976 # The Width and Height is UINT16 type in Image Package
1977 if BmpHeader
.biWidth
> 0xFFFF:
1978 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Width is exceed 0xFFFF." % File
.Path
)
1979 if BmpHeader
.biHeight
> 0xFFFF:
1980 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Height is exceed 0xFFFF." % File
.Path
)
1982 PaletteBuffer
= pack('x')
1983 if BmpHeader
.biBitCount
== 1:
1985 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS
)
1987 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT
)
1988 ImageBuffer
+= pack('B', PaletteIndex
)
1989 Width
= (BmpHeader
.biWidth
+ 7)/8
1990 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1991 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1992 elif BmpHeader
.biBitCount
== 4:
1994 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS
)
1996 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT
)
1997 ImageBuffer
+= pack('B', PaletteIndex
)
1998 Width
= (BmpHeader
.biWidth
+ 1)/2
1999 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
2000 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
2001 elif BmpHeader
.biBitCount
== 8:
2003 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS
)
2005 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT
)
2006 ImageBuffer
+= pack('B', PaletteIndex
)
2007 Width
= BmpHeader
.biWidth
2008 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
2009 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
2010 elif BmpHeader
.biBitCount
== 24:
2012 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS
)
2014 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT
)
2015 Width
= BmpHeader
.biWidth
* 3
2017 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData
="[%s]" % str(File
.Path
))
2019 ImageBuffer
+= pack('H', BmpHeader
.biWidth
)
2020 ImageBuffer
+= pack('H', BmpHeader
.biHeight
)
2021 Start
= BmpHeader
.bfOffBits
2022 End
= BmpHeader
.bfSize
- 1
2023 for Height
in range(0, BmpHeader
.biHeight
):
2025 Start
= End
+ (Width
% 4) - 4 - Width
2028 ImageBuffer
+= Buffer
[Start
+ 1 : Start
+ Width
+ 1]
2031 # 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
2032 if PaletteBuffer
and len(PaletteBuffer
) > 1:
2033 PaletteTemp
= pack('x')
2034 for Index
in range(0, len(PaletteBuffer
)):
2037 PaletteTemp
+= PaletteBuffer
[Index
]
2038 PaletteBuffer
= PaletteTemp
[1:]
2039 return ImageBuffer
, PaletteBuffer
2041 ## Create common code
2043 # @param Info The ModuleAutoGen object
2044 # @param AutoGenC The TemplateString object for C code
2045 # @param AutoGenH The TemplateString object for header file
2047 def CreateHeaderCode(Info
, AutoGenC
, AutoGenH
):
2049 AutoGenH
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.h'}))
2050 # header file Prologue
2051 AutoGenH
.Append(gAutoGenHPrologueString
.Replace({'File':'AUTOGENH','Guid':Info
.Guid
.replace('-','_')}))
2052 AutoGenH
.Append(gAutoGenHCppPrologueString
)
2053 if Info
.AutoGenVersion
>= 0x00010005:
2054 # header files includes
2055 AutoGenH
.Append("#include <%s>\n" % gBasicHeaderFile
)
2056 if Info
.ModuleType
in gModuleTypeHeaderFile \
2057 and gModuleTypeHeaderFile
[Info
.ModuleType
][0] != gBasicHeaderFile
:
2058 AutoGenH
.Append("#include <%s>\n" % gModuleTypeHeaderFile
[Info
.ModuleType
][0])
2060 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
2061 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
2063 if 'PcdLib' in Info
.Module
.LibraryClasses
or Info
.Module
.Pcds
:
2064 AutoGenH
.Append("#include <Library/PcdLib.h>\n")
2066 AutoGenH
.Append('\nextern GUID gEfiCallerIdGuid;')
2067 AutoGenH
.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
2072 AutoGenH
.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info
.Guid
))
2077 AutoGenC
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.c'}))
2078 if Info
.AutoGenVersion
>= 0x00010005:
2079 # C file header files includes
2080 if Info
.ModuleType
in gModuleTypeHeaderFile
:
2081 for Inc
in gModuleTypeHeaderFile
[Info
.ModuleType
]:
2082 AutoGenC
.Append("#include <%s>\n" % Inc
)
2084 AutoGenC
.Append("#include <%s>\n" % gBasicHeaderFile
)
2087 # Publish the CallerId Guid
2089 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info
.Guid
))
2090 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info
.Name
)
2092 ## Create common code for header file
2094 # @param Info The ModuleAutoGen object
2095 # @param AutoGenC The TemplateString object for C code
2096 # @param AutoGenH The TemplateString object for header file
2098 def CreateFooterCode(Info
, AutoGenC
, AutoGenH
):
2099 AutoGenH
.Append(gAutoGenHEpilogueString
)
2101 ## Create code for a module
2103 # @param Info The ModuleAutoGen object
2104 # @param AutoGenC The TemplateString object for C code
2105 # @param AutoGenH The TemplateString object for header file
2106 # @param StringH The TemplateString object for header file
2107 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
2108 # @param UniGenBinBuffer Buffer to store uni string package data
2109 # @param StringIdf The TemplateString object for header file
2110 # @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
2111 # @param IdfGenBinBuffer Buffer to store Idf string package data
2113 def CreateCode(Info
, AutoGenC
, AutoGenH
, StringH
, UniGenCFlag
, UniGenBinBuffer
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
):
2114 CreateHeaderCode(Info
, AutoGenC
, AutoGenH
)
2116 if Info
.AutoGenVersion
>= 0x00010005:
2117 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2118 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2119 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2120 CreatePcdCode(Info
, AutoGenC
, AutoGenH
)
2121 CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
)
2122 CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
)
2123 CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
)
2124 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
)
2126 if Info
.UnicodeFileList
:
2127 FileName
= "%sStrDefs.h" % Info
.Name
2128 StringH
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2129 StringH
.Append(gAutoGenHPrologueString
.Replace({'File':'STRDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2130 CreateUnicodeStringCode(Info
, AutoGenC
, StringH
, UniGenCFlag
, UniGenBinBuffer
)
2133 for Guid
in Info
.Module
.Guids
:
2134 if Guid
in Info
.Module
.GetGuidsUsedByPcd():
2136 GuidMacros
.append('#define %s %s' % (Guid
, Info
.Module
.Guids
[Guid
]))
2137 for Guid
, Value
in Info
.Module
.Protocols
.items() + Info
.Module
.Ppis
.items():
2138 GuidMacros
.append('#define %s %s' % (Guid
, Value
))
2139 # supports FixedAtBuild usage in VFR file
2140 if Info
.VfrFileList
and Info
.ModulePcdList
:
2141 GuidMacros
.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))
2142 GuidMacros
.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))
2143 GuidMacros
.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))
2144 GuidMacros
.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))
2145 GuidMacros
.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))
2146 for Pcd
in Info
.ModulePcdList
:
2147 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
2148 TokenCName
= Pcd
.TokenCName
2149 Value
= Pcd
.DefaultValue
2150 if Pcd
.DatumType
== 'BOOLEAN':
2151 BoolValue
= Value
.upper()
2152 if BoolValue
== 'TRUE':
2154 elif BoolValue
== 'FALSE':
2156 for PcdItem
in GlobalData
.MixedPcd
:
2157 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2158 TokenCName
= PcdItem
[0]
2160 GuidMacros
.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName
, Value
))
2162 if Info
.IdfFileList
:
2163 GuidMacros
.append('#include "%sImgDefs.h"' % Info
.Name
)
2166 StringH
.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros
))
2168 StringH
.Append("\n#endif\n")
2169 AutoGenH
.Append('#include "%s"\n' % FileName
)
2171 if Info
.IdfFileList
:
2172 FileName
= "%sImgDefs.h" % Info
.Name
2173 StringIdf
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2174 StringIdf
.Append(gAutoGenHPrologueString
.Replace({'File':'IMAGEDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2175 CreateIdfFileCode(Info
, AutoGenC
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
)
2177 StringIdf
.Append("\n#endif\n")
2178 AutoGenH
.Append('#include "%s"\n' % FileName
)
2180 CreateFooterCode(Info
, AutoGenC
, AutoGenH
)
2182 # no generation of AutoGen.c for Edk modules without unicode file
2183 if Info
.AutoGenVersion
< 0x00010005 and len(Info
.UnicodeFileList
) == 0:
2184 AutoGenC
.String
= ''
2186 ## Create the code file
2188 # @param FilePath The path of code file
2189 # @param Content The content of code file
2190 # @param IsBinaryFile The flag indicating if the file is binary file or not
2192 # @retval True If file content is changed or file doesn't exist
2193 # @retval False If the file exists and the content is not changed
2195 def Generate(FilePath
, Content
, IsBinaryFile
):
2196 return SaveFileOnChange(FilePath
, Content
, IsBinaryFile
)